Getting started on macOS with Astah and Clang#
This section guides you through the complete development process from designing a state machine to integrating it into an application. It helps you get familiar with the code generator and its features.
All files for this tutorial are available on GitHub.
A Microwave Oven#
In this section we create a model of a simple microwave oven using a state machine diagram. A microwave oven was chosen because it is self-explanatory and not too complex. To keep the example focused, hardware interaction routines are excluded.
For this example we use the Astah UML modeling tool. If you use another supported UML tool, the required steps are slightly different. If you are familiar with your UML tool, you should be able to follow this tutorial and build the model on your own.

Figure 1: Fictitious microwave oven. With a wheel, cooking time can be adjusted between 0 and 60 seconds. Power can be set to high (II) or low (I).
The oven controller should support:
- Cooking time can be adjusted between 0 s and 60 s.
- Cooking starts if cooking time is greater than zero and the door is closed.
- If the door is opened during cooking, the microwave generator switches off and cooking time stops.
- Cooking continues if time is not over and the door is closed again.
- Cooking stops if time is over or adjusted to zero.
- Cooking time and power can be changed at any time.
Drawing the State Machine Diagram#
This example includes several UML state machine elements and is sufficient to generate production-ready code. The design shown is one possible solution; other valid designs are possible.

Figure 2: Complete state machine design of the microwave oven. Actions, guards, entry and exit code are included. The model was created with Astah.
Creating Code#
It is assumed Java and clang are installed.
To verify your setup:
C:\>java -version
java version "13.0.2" 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)Check that a compiler is available (clang -v). If not, install Xcode developer tools on macOS.
Then switch to your example folder, run make clean, then make.
make
java -cp ../../bin/*:../*:/Applications/astahprofessional/astahprofessional.app/Contents/Java/* codegen.Main -l cx -v -p ASTAH -o oven -t "final:oven:machine" oven_model.asta
Verbose mode on
Command line parsing success!
Open project: oven_model.asta
Starting robustness tests of state machine ...
State names: ..............
Machine hierarchy: ........
Machine height = 2
Transitions: ..............
Default states: ...........
Final states: .............
Choices: ..................
No. of children in composites: ...
Connectivity of states: ...
M1054: State Error has no outgoing transitions which indicates a dead end -> check your design.
Can't find the License.txt file or invalid file. Codegen is running in demo mode
Expected license file location: /Users/pmueller/develop/sinelabore/statemachine generator/Cadifra CodeGen/distribution_folder/sinelaboreRT4.1/bin/License.txt
Running in demo mode!
gcc -Wall -g -I. main.c -c -o main.o
java -cp ../../bin/*:../*:/Applications/astahprofessional/astahprofessional.app/Contents/Java/* codegen.Main -A -l cx -v -p ASTAH -o oven -t "final:oven:selftest" oven_model.asta
Verbose mode on
Command line parsing success!
Parsing successfully finished.
Checking nodes ...
Checking for unique node names
Merging actions TestMicrowave and TestLamp
Merging actions a75992a1_3417_452d_8b54_1302dc8128b7 and TestSomethingElse
gcc -Wall -g -I. oven.c -c -o oven.o
gcc -Wall -g -I. oven_hlp.c -c -o oven_hlp.o
gcc -Wall -g -I. oven_selftest.c -c -o oven_selftest.o
gcc -o oven.exe main.o oven.o oven_hlp.o oven_selftest.oThe oven binary should now build successfully.
Start the program, press + several times to increment cooking time, then press c to close the door. Observe behavior and test additional events.
It is recommended to reopen your UML editor, modify the state diagram, regenerate code, and inspect generated output to explore available options.

Some additional notes:
- Code generation from activity diagrams is also supported (the example includes a basic self-test activity diagram).
- Generation from Astah SysML models is also supported.
- Astah is a cross-platform tool and is not limited to macOS.