??? 03/06/09 15:49 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#163167 - no struct + transactions Responding to: ???'s previous message |
Walter Adrián Quiroga said:
by the way there is some posibilities to do this without struct? Of course. A struct is basically a way to group things together. Just use a variable on its own, for example obj_fsm_state or state. Walter Adrián Quiroga said:
in this case what would be the right mode to write the Switch if for instance I have 3 events or states to check? Imagine the events are three variables which are set outside your file and out is the output of FSM: extern char ev1, ev2, ev3; // events enum OBJ_STATES obj_fsm_state; char obj_fsm_out; /// initialize object void init_obj (void) { obj_fsm_state = OBJ_STATE_INIT; obj_fsm_out = 0; } /// update object FSM state void update_obj (void) { switch (obj_fsm_state) { case OBJ_STATE_1: if (ev2) { obj_fsm_state = OBJ_STATE_2; obj_fsm_out = 2; } else if (ev3) { obj_fsm_state = OBJ_STATE_3; obj_fsm_out = 3; } break; case OBJ_STATE_2: if (ev1) { obj_fsm_state = OBJ_STATE_1; obj_fsm_out = 1; } else if (ev3) { obj_fsm_state = OBJ_STATE_3; obj_fsm_out = 3; } break; case OBJ_STATE_3: if (ev1) { obj_fsm_state = OBJ_STATE_1; obj_fsm_out = 1; } else if (ev2) { obj_fsm_state = OBJ_STATE_2; obj_fsm_out = 2; } break; } } This is a basic deterministic automata. I normally uses transaction actions only, but you can also have other types of transactions. |
Topic | Author | Date |
FSM Finite State Machine | 01/01/70 00:00 | |
Clarify | 01/01/70 00:00 | |
FSM Finite State Machine | 01/01/70 00:00 | |
enum + switch() ... case ... break | 01/01/70 00:00 | |
FSM | 01/01/70 00:00 | |
no struct + transactions | 01/01/70 00:00 | |
Thank you So Much![]() | 01/01/70 00:00 | |
SMC - The State Machine Compiler | 01/01/70 00:00 |