Table of Contents
Getting started on Windows with Altova UModel and MinGW
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_umodel_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 Altova UModel. In the handbook you will find hints on how to draw state diagrams for all the supported tools. It is recommended to have a quick look into that section.
The oven controller should be able do the following things:
- Cooking time can be adjusted using a wheel between 0s and 60s.
- Cooking starts if the cooking time is larger than zero. And the door is closed.
- If the door is opened during cooking the microwave generator is switched off. 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.
Drawing the State Machine Diagram
To fulfil the requirements a hierarchical state machine was designed. Therefore events that should be handled from every state must only be modelled once on the outer (parent) state.
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.
It is assumed you have Java and the MinGW compiler is 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. Add the bin folder of MinGW to your path and check if the compiler can be called now.
C:\>path %path%;C:\MinGW\bin C:\>mingw32−gcc mingw32−gcc: fatal error: no input files compilation terminated .
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:
mingw32-make clean to first remove existing built results.
Then type in
mingw32-make to build everything.
mingw32-gcc.exe -Wall -g oven_hlp.c -c -o oven_hlp.o mingw32-gcc.exe -Wall -g oven_selftest.c -c -o oven_selftest.o java -cp "../../bin/*" codegen.Main -p UModel -l cx -t "MicrowaveOven:MachineClass" -doxygen -o oven oven.xmi Create inline doxygen of state machine function 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: /Y:/develop/sinelabore/statemachine generator/Cadifra CodeGen/distribution_folder/sinelaboreRT4.1/bin/License.txt Running in demo mode! java -cp "../../bin/*" codegen.Main -p UModel -A -l cx -t "MicrowaveOven:MachineClass" -o oven oven.xmi Checking nodes ... Checking for unique node names mingw32-gcc.exe -Wall -g oven.c -c -o oven.o mingw32-gcc.exe -Wall -g main.c -c -o main.o mingw32-gcc.exe -o oven oven_hlp.o oven_selftest.o oven.o main.o
oven exe should be built successfully now.
Start the program and type several times
+ ti increment the cooking timer.
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).