SinelaboreRT Header Logo

SinelaboreRT

It's better when it's simple!

User Tools

Site Tools


Sidebar

Tool Landing Pages

Examples

Designers Toolbox

How-To

Integrated state-chart editor with auto-layout

Focus on modeling and not on moving states around to create a nice looking diagram! Syntax aware text fields offer a comfortable way to specify actions, guards etc. When the diagram passed the model checker it can be directly simulated. Connect the diagram to the real hardware to monitor the state machine in action.

There are better ways to model state machines than using spread sheets!

In the past different μC manufacturers have published application notes about the benefit of using state machines for the design of embedded software. An example is the application note SLAA402 from Texas Instruments (TI). It suggests to generate source code based on a spread sheet table. Nowadays several affordable UML modeling tools are available supporting the efficient design of state machines in a graphical way. SinelaboreRT generates production quality source code from state diagrams created with many different UML tools. Give it a try!

Latest Changes

PageDateUserTags
Generate efficient source code from UML state diagrams and activity diagrams! 2017/04/23 11:02 Peter Mueller  
Navigation 2017/04/23 10:55 Peter Mueller  
wiki:news:12may2014

New version 3.6 has support for activity diagrams

There are two diagrams that can be used to express dynamic behaviour in the UML. State machine diagrams express the states of an object and the events and transitions to change the state. In contrast activity diagrams (aka flow diagrams) describe the control flow of an algorithm. The great thing of both types of diagrams is that they allow to generate 100% code out of the model description.

The latest version of the sinelabore code generator can now also generate code from activity diagrams. Activity diagrams consist of the following elements:

  • Black circle to indicate the begin of the activity
  • Circled black circle to indicate the end of the activity (return)
  • Rounded rectangles representing actions
  • Diamonds representing decisions and merge
  • Arrows connect the other elements and represent the flow throughout the diagram. Arrows might have a guard expression. If the guard expression is true the control flow follows this arrow to the next action.
  • Activity diagrams might contain sub-activities

In addition to this basic elements UML activity diagrams also allow to model loops and decisions.

To generate code from an activity diagram just call the code generator with the new command line parameter -A. The other command line parameters are still the same. Use the -t parameter to define the path in the model file to the class containing the activity. And -l for the target language.

Presently the code generator only supports XMI files exported from Enterprise Architect models and can only generate C code.

The following figure shows a fictitious activity diagram with all the elements presently supported from the code generator.

The code generator supports several configuration parameters that can be specified in the codegen.cfg file. The parameters are:

  • ActivityFileNamePostfix: By default the c/h file with the activity are based on the name specified by -o and the activity name in the model file. But for specific reasons it might be necessary to provide an additional postfix to the file names.
  • ActivityFunctionParameterDefinition: Allows to define the parameters for the activity function in the c file
  • ActivityFunctionPrefixHeader: Same as above but for the header file
  • ActivityFunctionPrefixCFile: Allows to define the type of the return value if the activity returns something
  • ActivityFunctionReturnCode: Defines the code snipped that is used at the end of the activity to actually return something.

To generate code from the above example diagram call the code generator the following way:

java -jar codegen.jar -A -p EA -o testcase -t “Model:test:class_with_activities” testcase.xml

The generated c-file can be found here. Due the way the algorithm is generated (based on a while loop with switch / case statements) all kinds of loops including back links can be generated without problem. For the shown diagram the generated code contains just 180 lines of code including empty lines and some documentation.

⇒The activity generator backend is still under development. Error handling and parser robustness must be increased. Additionally sections about the activity generator must be added to the manual.

Nevertheless the generator can already be used for real word applications. Please give it a try! Your feedback is very welcome.


Beside the activity generator backend the new version also contains several improvements in the state machine generator. In addition support for transitions from initial states to choice states in Java was added.

Have fun!

wiki/news/12may2014.txt · Last modified: 2014/05/13 18:45 by pmueller