Skip to end of metadata
Go to start of metadata

When generating code for Statemachines such as in the example below one would wonder why the code generated (shown on the left) does not meet the users expectations (shown on the right).

This is due to the Completion transitions and completion events defined in the UML Superstructure 2.4.1 which states:

...A completion transition is a transition originating from a state or an exit point but which does not have an explicit trigger, although it may have a guard defined. .... If the state is a composite state or a submachine state, a completion event is generated if either the submachine or the contained region has reached a final state and the state’s internal activities have been completed. This event is the implicit trigger for a completion transition. ...

Therefore the Embedded Engineer will omit the generation of the "test == 1" Transition since State1 is still active since State3 was not deactivated/exited.

Generated code
switch (stm->mainState.activeSubState)
{
	case Class1_StateMachine_State1:
		switch (stm->State1.activeSubState)
		{
		case Class1_StateMachine_State3:
			break;
		default:
			break;
		}
		break;
	case Class1_StateMachine_State2:
		break;
	default:
		break;
}

Embedded Engineer will warn the user about this during code generation
(available since 3.1)

Expected code
switch (stm->mainState.activeSubState)
{
	case Class1_StateMachine_State1:
		switch (stm->State1.activeSubState)
		{
		case Class1_StateMachine_State3:
			break;
		default:
			break;
		}
		if (test == 1)
		{
			evConsumed = !0;
			/* From 'State1' to 'State2' */
			stm->mainState.activeSubState = Class1_StateMachine_State2;
		}
		break;
	case Class1_StateMachine_State2:
		break;
	default:
		break;
}

Solution

To resolve this we reccomend using one of the following solutions:

  • Change the Transition from State1 State2 to State3 State2

  • Add a Signal to the Transition to be triggered