#include "ExampleSimpleData.h" #include <stdio.h> #ifndef __StateDef__ extern struct State_Fwc_t Off, Work, Work_History, Ready; #endif #ifdef __StateDef__ //: Name all arguments of a state entry-, exit- and trans-method as static variable here. //: In generated code there will be given in the argument list. static struct ExampleSimpleData_t* thiz; static int event; //Helper should be defined. void switchTo(void* ...); class States { inline void variables() { char* StateSubStruct = "State_ExampleSimpleData"; char* StateMethodSuffix = "_ExampleSimpleData"; char* StateInstance = "thiz->state"; } //void args(ExampleSimpleData* thiz); /**It is the off-state. This part contains a documentation of the state */ class Off { int statenr_1; /**Comment for entry-action. Note: If nothing is specified on entry, you can remove the entry method too.*/ void entry(){ thiz->work = 0; }//. /**Comment for exit-action. Note: If nothing is specified on exit, you can remove the exit method too.*/ void exit(){ }//. /**Comment for this transition. */ void trans(bool cond = thiz->on_ready) { if(thiz->on_cont){ switchTo(new Work::History); } else { thiz->work = 1; switchTo(new Work::Ready()); } } /**Comment for the other transition. */ void trans1(bool cond = thiz->on_cont){ switchTo(new Work::History); } #endif struct State_Fwc_t* checkTrans(ExampleSimpleData* thiz, int ev) { if(thiz->on_ready) { if(thiz->on_cont){ return &Work_History; } else { thiz->work = 1; return &Ready; } } else return null; } #ifdef __StateDef__ /**The method which should be done in the state, if the statemachine is invoked cyclically. */ void inState(){ thiz->counter +=1; }//. }; /**It is a composite state. But that is seen on the inner states only. */ public: class Work { int statenr_2; /**If this marker exist, a history state can be used as destination inside this class. * The code generation uses and extra variable for the state value. */ public: class History{}; void entry(){ thiz->work = 1; }//. void exit(){ thiz->work = 0; }//. void trans(bool cond = thiz->off){ switchTo(new Off()); } /**This state is an inner state of Work. Formally it extends Work. */ class Ready : protected ExampleSimpleData { int statenr_0x21; void trans(bool cond = event == kStart_Event_ExampleSimple) { switchTo( new Active::Active1::Running::Running2::Running21() , new Active::Active2::RemainOn()); } }; /**An second inner state of Work. */ class Active : protected ExampleSimpleData { int statenr_0x22; int parallel; /**Name of parallel Parts in the State Active. */ class Active1 : protected ExampleSimpleData { int statenr_0xa100; class Running : protected ExampleSimpleData { int statenr_0x40; void entry(){ thiz->out = 3; }//. void exit(){ thiz->out = 5; }//. void trans(int time = thiz->delay){ switchTo(new Finit); } class Running1: protected ExampleSimpleData { int statenr_0x41; }; class Running2: protected ExampleSimpleData { int statenr_0x44; class Running21: protected ExampleSimpleData { int statenr_0x45; }; }; }; class Finit : protected ExampleSimpleData { int statenr_0x50; }; }; class Active2 { int statenr_0xa200; class RemainOn : protected ExampleSimpleData { int statenr_0x100; void trans(bool cond = thiz->offAfterRunning){ switchTo(new ShouldOff); } /**This is one of the working states. It toogles between On_a and On_b. */ class On_a : protected ExampleSimpleData { int statenr_0x300; void trans(bool cond = thiz->bit_a){ switchTo(new On_b); } }; /**See On_a, working state. */ class On_b : protected ExampleSimpleData { int statenr_0x400; void trans(bool cond = thiz->bit_b){ switchTo(new On_a); } }; }; class ShouldOff : protected ExampleSimpleData { int statenr_0x700; void trans(class Finit* join){ switchTo(new Off); } void trans2(bool cond = thiz->abort){ switchTo(new Off); } }; }; /**join of 2 states of the underlying parallel states. * Syntax note: It should be declared after the classes, because elsewhere there are unknown. * The body contains new declaration of the destination class(es). */ void join(class Active::Active1::Finit*, class Active::Active2::ShouldOff*){ switchTo(new Off); } }; }; }; #endif //__StateDef__