D
UML State Diagrams
Fritz Bartlett 07-May-1999
JFB
29-Apr-99
D
Initial State State 1
A Simple State Machine
Final State Event Trigger Action
Event Trigger Action State 2
State 3 Event Trigger Action Self Transition
JFB
29-Apr-99
Definitions
State Machine
A state machine is a behavior which specifies the sequence of states an object visits during its lifetime in response to events, together with its responses to those events
JFB
29-Apr-99
D
State
Definitions
A state is a condition during the life of an object during which it satisfies some condition, performs some activity, or waits for some external event
Event
An event is the specification of a significant occurrence. For a state machine, an event is the occurrence of a stimulus that can trigger a state transition
JFB
29-Apr-99
D
Transition
Definitions
A transition is a relationship between two states indicating that an object in the first state will, when a specified set of events and conditions are satisfied, perform certain actions and enter the second state. A transition has:
Transition Components
a source state an event trigger an action a target state
29-Apr-99
JFB
Definitions
Self-Transition
A self-transition is a transition whose source and target states are the same
JFB
29-Apr-99
D
Action
Definitions
An action is an executable, atomic (with reference to the state machine) computation. Actions may include operations, the creation or destruction of other objects, or the sending of signals to other objects (events).
JFB
29-Apr-99
D
Initial State State 1
A Simple State Machine
Final State Event Trigger Action
Event Trigger Action State 2
State 3 Event Trigger Action Self Transition
JFB
29-Apr-99
Advanced States
Entry and Exit Actions
State Name
Entry | Entry Action Exit | Exit Action
JFB
29-Apr-99
D
Substates
Definitions
A substate is a state that is nested in another state A state that has substates is called a composite state A state that has no substates is called a simple state Substates may be nested to any level
JFB
29-Apr-99
Advanced Transitions
Transitions to a composite state
If a transition is to a composite state, the nested state machine must have an initial state If a transition is to a substate, the substate is entered after any entry action for the enclosing composite state is executed followed by any entry action for the substate
JFB
29-Apr-99
Advanced Transitions
Transitions from a composite state
If a transition is from a substate within the composite state, any exit action for the substate is executed followed by any exit action for the enclosing composite state A transition from the composite state may occur from any of the substates and takes precedence over any of the transitions for the current substate
JFB 29-Apr-99
Advanced State Machine
Sub-States
Transition to a composite state Transition from a composite state Transition from a substate
State Name
State 2
State 0
State 1
Transition to a substate Entry | Entry Action
State 3
Exit
| Exit Action
JFB
29-Apr-99
D
State
An Implementation
State Table
FirstIndex LastIndex EntryAction ExitAction
0 State 1 2
0 2 3
1 2 4
Act1 None None
Act2 Act3 None
Transition Table
Trans 1 Index 2 3 E1 E1 | E2 * None * 2 * Events E0 & E1
Mask
E0 | E1
Action Act0
NewState 1
JFB
29-Apr-99
D
/*+ typedef void *SsmId_t;
An Implementation
MODULE stateMachine - Sequential State Machine Package Declarations DESCRIPTION: The stateMachine.h header file contains definitions of external interfaces to the state machine package -*/ #define ssmMask(event) (1<<event) enum {SSM_TERMINAL_INDEX = (unsigned short int)-1}; enum {SSM_NULL_ACTION = NULL}; enum {SSM_MAX_EVENT = 31};
typedef int (*SsmAction_t)(const SsmId_t stateId, void const *context, const unsigned short int action); typedef void (*SsmDisplay_t)(char *text); typedef unsigned long int SsmEventSet_t; /* State table element */ typedef struct { unsigned short unsigned short unsigned short unsigned short } SsmState_t;
int int int int
firstIndex; lastIndex; inAction; outAction;
/* /* /* /*
First index in transition table */ Last index in transition table */ Entry action index */ Exit action index */
/* Transition table element */ typedef struct { SsmEventSet_t events; SsmEventSet_t mask; unsigned short int action; unsigned short int newState; } SsmTransition_t;
/* /* /* /*
Event value */ Event mask */ Action index */ New state */
extern SsmId_t ssmCreate(const unsigned short int initState, const unsigned short int termState, const unsigned short int maxIndex, const SsmEventSet_t initEvents, const SsmAction_t actionFunct, void const *context, SsmState_t (*stateTable)[], SsmTransition_t (*transTable)[]); extern int ssmDelete(const SsmId_t stateId); extern int ssmEventClear(const SsmId_t stateId, const unsigned int event); extern int ssmEventSet(const SsmId_t stateId, const unsigned int event); extern unsigned int ssmExecute(const SsmId_t stateId); extern unsigned short int ssmCurStateGet(const SsmId_t stateId);
JFB
29-Apr-99
D
Problems with UML notation
When more than one transition from a state is enabled there is no method for specifying precedence For nested states there is no method for specifying precedence of the enclosing or enclosed state
JFB
29-Apr-99
D
Ramp
Example: High Voltage Channel
Paused
Holding
Average
Tripped
On
Offline
Off
Disabled
JFB
29-Apr-99