Note that there are some explanatory texts on larger screens.

plurals
  1. PObig vs. nested statemachines
    primarykey
    data
    text
    <p>I have a statemachine in a real-time system with very few (3) states.</p> <pre><code>typedef enum { STATE1, STATE2, STATE3 } state_t; </code></pre> <p>However, the transitions between those states need considerable time and have their own subdivisions. So I have two choices, either I extend the main statemachine such that all the intermediate states are represented:</p> <pre><code>typedef enum { STATE1, STATE1_PREPARE_TRANSITION_TO_STATE2, STATE1_DO_TRANSITION_TO_STATE2, STATE1_PREPARE_TRANSITION_TO_STATE3, STATE1_DO_TRANSITION_TO_STATE3, STATE2, ... } state_t; </code></pre> <p>or I create a nested statemachine for the relevant main states:</p> <pre><code>typedef enum { STATE1_NOT_ACTIVE, STATE1_NORMAL, STATE1_PREPARE_TRANSITION_TO_STATE2, STATE1_DO_TRANSITION_TO_STATE2, STATE1_PREPARE_TRANSITION_TO_STATE3, STATE1_DO_TRANSITION_TO_STATE3 } sub_state1_t; ... </code></pre> <p>Both possibilities have their advantages and drawbacks. The big statemachine gets messy and complicated very easily. However, having all the states consistent in the second case isn't trivial either and many functions would need information about both the global state and the substates.</p> <p>I'd like to avoid complicated code which has to handle several parallel states, like:</p> <pre><code>if ((global_state == STATE1) &amp;&amp; (sub_state_1 == STATE1_DO_TRANSITION_TO_STATE2)) { ... if (transition_xy_done(...)) { global_state = STATE2; sub_state_1 = STATE1_NOT_ACTIVE; sub_state_2 = STATE2_NORMAL; } } </code></pre> <p>What is the general best approach for such a problem: many small and nested statemachines (with many invalid combinations), one big statemachine or anything else?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload