|
| 1 | +The REAME file attempts to explain how the Controller & SM operate. |
| 2 | +Please review the UML included in this folder for further details. |
| 3 | + |
| 4 | +Setup phase: |
| 5 | + |
| 6 | +1. Create a SM: sm = new SDtateMachine(); |
| 7 | +2. Create state/s: st = new State**(); |
| 8 | +3. Configure the SM with initial state: |
| 9 | +sm->setBaseState(stateNA); |
| 10 | +4. Configure the SM by mapping actions/results |
| 11 | +to the next state (per state): |
| 12 | +sm->mapStateResult2NextState(stateNA, State::RET_SUCCESS, stateInit); |
| 13 | +The above can be described as follows: |
| 14 | +An event received while in stateNA, triggers the event method on that state, |
| 15 | +and if it returns RET_SUCCESS, the SM current state is moved to stateInit. |
| 16 | +Any other result value, by default keeps the current state unchanged. |
| 17 | + |
| 18 | +5. Create a controller: controller = new CardController(); |
| 19 | +6. Create a card/device and bind to controller: card = new Device(controller); |
| 20 | +7. Register the card & the SM it needs to work with to the controller: |
| 21 | +card.devID = controller->regCard(sm); |
| 22 | +The devID is used to identify the card in the controller. |
| 23 | +When notifications arrive from the card, they include the devID and event, |
| 24 | +and the controller can map the devID to its SM. |
| 25 | + |
| 26 | +Runtime: |
| 27 | +1. Start the controller so it will listen to inclomming messages: |
| 28 | +controller->run(); |
| 29 | +Usually such a controller will run on a seperated thread, blocking on |
| 30 | +msg_recv(); |
| 31 | +2. The card/device sends notifications to the controllen it is bind to: |
| 32 | +card.sendEvent(CardController::EV_EXIST); |
| 33 | +It is usually done through a message service service: msg_send(msg); |
| 34 | +The information sent includes the card devID and the event ID. |
| 35 | +3. The controller receives the message, using the devID determine the SM |
| 36 | +it belongs to and run on it the event. |
| 37 | +(it actually executes the event method on the current state) |
| 38 | + |
0 commit comments