Generate production quality code from state diagrams created with Magic Draw
SinelaboreRT generates readable and maintainable code from hierarchical UML state machines. With its unique features and the C code generator the tool covers well the requirements of embedded real-time and low power application developers. With its C++, Python and Java backend it is also a perfect tool for developers of server or desktop applications.
- Automated robustness checks before code generation
- No run-time environment needed
- Can be used with any CPU and with or without OS/RTOS
- Code generation especially for embedded real-time and high availability systems.
- Fits well in different system designs (foreground/background, RTOS-based …)
- No gap between design and code
- Support for automatic test-case generation
- Simulation in interactive or batch mode.
- Optionally generating trace code
- Generated code creates no trouble when using static code checkers
Watch the code generator in action
The following example shows how the code generator works by means of a simple microwave oven.
- Cooking time can be adjusted from 0s and 60s.
- Cooking starts if the cooking time is > 0s and the door is closed.
- If the door is opened during cooking the microwave generator is switched off. The cooking time stops.
- Cooking continuous if the cooking time is not over and the door is closed again
- Cooking stops if the cooking time is over or the time is adjusted to zero.
- Cooking time and power can be changed at any time.
The sate machine and the class diagram below shows a possible solution.
To generate for example C code call the code generator as follows:
java -cp "../../bin/*" codegen.Main-l cx -p md -t "Model:oven_package:oven" -o oven oven.xmi.xml
After checking the model against a set of well-formedness rules (e.g. no double state names) the complete state machine code is generated.
Look into the generated files:
In the examples folder you will find the complete code ready to be tested and expanded by you.
Supported State Machine Elements
The code-generator supports a relevant subset of the design elements provided by Magic Draw. The supported elements are:
- Hierarchical states
- (Signal-)Events with event name, guard and action
- Initial and final pseudo-states
- History states (deep, flat)
Find out more about the code generator
- How sinelabore supports model based testing of state diagrams
- How to interactively simulate your state diagram and generating trace code
- Read section “Drawing State-Charts with Magic Draw” in the manual
- How easy it is to add attributes and operations to the stateful class like shown below. Operations are mapped to C-functions. Attributes to members of the instance data of the state machine. This allows to add entry/exit code functions or other helper functions. Even the body code can be easily added with EA if you want. Presently attributes and operations are only generated in the C-backend.
Download the demo version and try it right now. It includes many other examples.
Magic Draw HowTo
I don't see the on-entry/on-exit/do code in my state diagram
Since MD version 19 (at least recognised it there) it is necessary to copy your code to the body text. See example below:
Is it necessary to specify an action name for on-entry/on-exit/do code?
If there is text in the name fieled (as shown above) it will be considered for code generation. If the name field is left empty the body part is used for code generation. The body text can be longer than one line. An example is shown below.