Using Activities -- Updated Microwave Oven

In the manual a simplified microwave oven is used to explain the generation of source code from state machine diagrams. This example was updated here to show how to generate code also from activity diagrams.

The extended state machine of the oven is shown below. For demonstration on how to use activities the oven performs a hardware selftest at startup. The hardware test happens on the incoming transition of the choice. Depending on the result of the selftest the machine enters an error state (marked in red) or the normal operation state (super). The hardware selftest routine was modelled as activity diagram.

The following code snipped shows the call of the hardware selftest. The selftest function itself was fully generated from the code generator

... uint8_t hwStatus; // selftest status void oven(OVEN_INSTANCEDATA_T *instanceVar){ OVEN_EV_CONSUMED_FLAG_T evConsumed = 0U; /*execute entry code of default state once to init machine */ if(instanceVar->superEntry==1U){ hwStatus = hardwareTest(); if(hwStatus>0){ instanceVar->stateVar = Error; }else{ instanceVar->stateVar = Super; } instanceVar->superEntry=0U; } switch (instanceVar->stateVar) { ...

The hardware selftest function was modelled in an own activity diagram. A class can have one or more activity diagrams. The code generator generates an own c-file/header per activity. The activity of the hardware test function is shown below. The single steps do not really do anything useful and only the most basic features of an activity diagram are used. But it shows the principles.

To generate code from the diagram call the code generator as follows. The -A enables the generation of code from activity diagrams. Without this flag state machine code is generated. To generate both call the generator twice.

java -jar codegen.jar -p EA -A -t "Model:Class Model:first_example_step3" -o oven first_example_step3.xml

The latest download contains the full model and code in the examples folder. The example is called microwave_handbook_enterpr_arch

In case of questions just send a mail.

Have fun!