Author Topic: generate C code from state machine diagrams  (Read 3948 times)

Shara.El

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
generate C code from state machine diagrams
« on: April 05, 2022, 06:19:19 pm »
I am working on an “EA custom C code generator” that generates .c and .h codes from EA state machine diagrams correctly.
I'm using an Ultimate Edition of Enterprise Architect. And I have been investigating two approaches, modifying the FSM_C auto code generation templates and creating an add-in for the purpose.
Is there anyone that knows which approach is more efficient?
Is it even possible to succeed by only modifying the FSM_C?
Has anyone ever tried this before, and can guide me?
I would appreciate any help in this regard.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: generate C code from state machine diagrams
« Reply #1 on: April 05, 2022, 06:30:37 pm »
I have done it with a script some time ago and it was near as trivial. An add-in is not really needed except that the call might be a bit more handy. You should keep your fingers off that awkward macro for creating code.

OTOH: creating code from a model seems odd. That makes sense if you change the model every day. If that's the case you're doing something wrong.

q.
« Last Edit: April 05, 2022, 06:32:19 pm by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13227
  • Karma: +550/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: generate C code from state machine diagrams
« Reply #2 on: April 05, 2022, 09:09:19 pm »
I would go for the add-in route.
The code templates are really hard to understand, and they will only get you so far. At a certain point you'll bump into the limitations of a template based approach.
Using an add-in you are free to code the logic you need.

It's going to be more work to setup, as you'll need to build the framework code as well, but it will pay off in the long term.

Geert

Shara.El

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: generate C code from state machine diagrams
« Reply #3 on: April 06, 2022, 04:22:52 pm »
I have done it with a script some time ago and it was near as trivial. An add-in is not really needed except that the call might be a bit handier. You should keep your fingers off that awkward macro for creating code.

OTOH: creating code from a model seems odd. That makes sense if you change the model every day. If that's the case you're doing something wrong.

q.

Thanks for your answer qwerty. I managed to modify the C generation templates according to our team's coding guidelines a while ago, and I should admit that was pretty annoying! :D
What I'm trying to do is part of a bigger project. The purpose of it is to save time for a team of designers that work on a large-scoped project, by auto-generating the code.

Shara.El

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: generate C code from state machine diagrams
« Reply #4 on: April 06, 2022, 04:26:46 pm »
I would go for the add-in route.
The code templates are really hard to understand, and they will only get you so far. At a certain point you'll bump into the limitations of a template based approach.
Using an add-in you are free to code the logic you need.

It's going to be more work to setup, as you'll need to build the framework code as well, but it will pay off in the long term.

Geert

Thank you very much for your guidance, Geert. Then I guess I need to continue working on the add-in.  :)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: generate C code from state machine diagrams
« Reply #5 on: April 06, 2022, 06:34:45 pm »
I guesses what you are trying to do. However, code generation is a fata morgana. EA (and most other UML tools) can create stubs only. And the meat must be done by coders. Now, once you have some meat in you hardly convince your coders to redo that because you have generated a new state. Well, you need to experience it for yourself. You only know that the plate is hot once you touched it...

q.