SinelaboreRT Header Logo

SinelaboreRT

As simple as possible, but not any simpler!

User Tools

Site Tools


wiki:getting_started:astah_mac_clang

Getting started on macOS with Astah and Clang

This section guides you through the whole development process from designing a state machine to integrating it into an application. This will help you to get familiar with the code generator and its features.

All files for this tutorial are available in this folder: examples/microwave_handbook_astah_win32

A Microwave Oven

In this section we create the 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 model. To keep this example as simple and clear as possible the hardware interaction routines are excluded. The following figure 1 shows the hardware of our fictitious microwave oven. For this example we are using the Astah UML Modelling tool. If you use another supported UML tool the required steps are slightly different. But if you are familiar with your UML tool it should be no problem to follow the tutorial and create the model on your own. In the appendix you will find hints on how to draw state diagrams for all the supported tools. It is recommended to have a quick look over the section that covers your tool. In addition the examples folder of your installation contains models for all supported tools (e.g. Enterprise Architect, UModel . . . ).

Microwave Oven Image Figure 1: Fictitious microwave oven. With a wheel the cooking time can be adjusted between 0 – 60 seconds. The power can be set to high (II) or low (I).

The oven controller should be able do the following things:

  1. Cooking time can be adjusted using a wheel between 0s and 60s.
  2. Cooking starts if the cooking time is larger than zero. And the door is closed.
  3. If the door is opened during cooking the microwave generator is switched off. Cooking time stops.
  4. Cooking continuous if the cooking time is not over and the door is closed again
  5. Cooking stops if the cooking time is over or the time is adjusted to zero.
  6. Cooking time and power can be changed at any time.

Drawing the State Machine Diagram

This example shows several UML state machine elements that make up a state machine. It is enough to generate production ready code out of it. Please note that the design presented here is not the only possible solution for the given requirements. Also some functions of a real microwave oven – e.g. control of a lamp in the oven – are still missing.

Figure 2: Complete state machine design of the microwave oven. All necessary actions, guards, entry and exit code were added.

Creating Code

It is assumed you have Java and clang installed. For a check if everything is installed correctly open a command window and change the working directory to this folder. Then type in the following commands.

C:\>java −version
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 you have a compiler installed (call clang -v). Otherwise install the developer tools for macOS.

Your output should look similar. Details might differ depending on your installed program versions. Now change to the ready made example in the examples folder. Depending on your installation change to the following examples folder:

your path\sinelaboreRT4.1\examples\microwave_handbook_astah_win32

Type in make clean to first remove existing built results. Then type in make to build everything.

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.o

The oven binary should be built successfully now. Start the program and type several times + ti increment the cooking timer. Then press c to close the door. Watch what happens. Test the other events you can fire.

It is now recommended to start your UML editor again. And play with the state diagram. Look into the generated code to get familiar with the many possibilities the code generator offers.

Some additional notes:

  • The code generator can also generate code from activity diagrams. The example also contains an activity diagram for the self test algorithm (basic, just as example).
  • The code generator also supports the generation from the Astah SysML tool.
  • Astah is a very nice cross platform tool not only available for macOS. Try it out if you have not used it so far.
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
You could leave a comment if you were logged in.
wiki/getting_started/astah_mac_clang.txt · Last modified: 2023/07/16 11:55 by webmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki