This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Finite state machine Question

Hi all,

I may need some guidance on the finite state machine method which found an example in app_level.c (from nRF5 SDK for Mesh v3.1), please see my question on below:-

  1. What is event id use for? found the function generic_level_state_set_cb() will call this fsm_event_post(&p_server->fsm, E_SET, p_server) which meant it will trigger the fsm and start from state "FSM_ANY_STATE", am i right?
  2. from question 1, if the above assumption is correct, why we have 3 FSM_TRANSITION? which line will go for?  FSM_TRANSITION(E_SET, G_SET_DELAY, A_DELAY_START, S_IN_DELAY),
    FSM_TRANSITION(E_SET, G_SET_TRANSITION, A_TRANSITION_START, S_IN_TRANSITION),
    FSM_TRANSITION(E_SET, FSM_OTHERWISE, A_TRANSITION_COMPLETE,S_IDLE),

Thank you!

static const fsm_transition_t m_app_level_fsm_transition_table[] =
{
    FSM_STATE(S_IDLE),

    FSM_STATE(S_IN_DELAY),
    FSM_TRANSITION(E_TIMEOUT,        G_SET_TRANSITION,       A_TRANSITION_START,    S_IN_TRANSITION),
    FSM_TRANSITION(E_TIMEOUT,        FSM_OTHERWISE,          A_TRANSITION_COMPLETE, S_IDLE),

    FSM_STATE(S_IN_TRANSITION),
    FSM_TRANSITION(E_TIMEOUT,        G_TRANSITION_COMPLETE,  A_TRANSITION_COMPLETE, S_IDLE),
    FSM_TRANSITION(E_TIMEOUT,        FSM_ALWAYS,             A_TRANSITION_TICK,     S_IN_TRANSITION),

    FSM_STATE(FSM_ANY_STATE),
    FSM_TRANSITION(E_SET,             G_SET_DELAY,        A_DELAY_START,        S_IN_DELAY),
    FSM_TRANSITION(E_SET,             G_SET_TRANSITION,   A_TRANSITION_START,   S_IN_TRANSITION),
    FSM_TRANSITION(E_SET,             FSM_OTHERWISE,      A_TRANSITION_COMPLETE,S_IDLE),
    FSM_TRANSITION(E_DELTA_SET,       G_SET_DELAY,        A_DELAY_START,        S_IN_DELAY),
    FSM_TRANSITION(E_DELTA_SET,       G_SET_TRANSITION,   A_TRANSITION_START,   S_IN_TRANSITION),
    FSM_TRANSITION(E_DELTA_SET,       FSM_OTHERWISE,      A_TRANSITION_COMPLETE,S_IDLE),
    FSM_TRANSITION(E_MOVE_SET,        G_SET_DELAY,        A_DELAY_START,        S_IN_DELAY),
    FSM_TRANSITION(E_MOVE_SET,        G_SET_TRANSITION,   A_TRANSITION_START,   S_IN_TRANSITION),
    FSM_TRANSITION(E_MOVE_SET,        FSM_OTHERWISE,      FSM_NO_ACTION,        S_IDLE)
};

  • Hello,

    I have not seen this before. I see that it is in the SDK. What example are you referring to, and do you see an issue?

    I believe I don't understand your question. Can you please elaborate?

    Best regards,

    Edvin

  • Hi Edvin,

    I have one assignment that needs to support Generic default transition time server and using 

    • nRF52840 - DK board
    • nRF5 SDK v15.2 + nRF5 SDK for mesh v3.1

    From the below examples (i.e. nRF5 SDK for mesh v3.1), I try to copy the same coding style and then build into my Generic default time server example where it will base on a light-switch example 

    1. light-switch - refer to Server folder and using Generic On/OFF Server
    2. experimental_dimming - refer to the server folder and using Generic Level Server

    In the end, it will combine both Generic ON/OFF Server and Generic default transition time server into one project. 

    -----------------------------------------------------------------------------------------------------------------------------------------------------------

    In the nRF5 SDK for mesh source code, it already provides  some of the models 

    1. generic_dtt
    2. generic_level
    3. generic_onoff
    4. generic_ponoff

    light-switch example using generic_onoff models and build a code layer (i.e. app_onoff.c) between main.c and generic_onoff model. 

    experimental_dimming using generic_onoff models and build a code layer (i.e. app_level.c) between main.c and generic_level model.

    My example is based on example light-switch - Server,  and I try to build the Generic default transition time server on top of it. The same concept as the above examples, my example will have app_dtt.c between of main.c and generic_dff models. 

    If my understanding not correct, please correct here!!!

    ------------------------------------------------------------------------------------------------------------------------------------------------------------

    My question is generated after reviewing the example experimental_dimming - server folder, where it builds a finite state machine in app_level.c.

    In this finite state machine, 

    1. In the State "FSM_ANY_STATE" - The E_SET Event will trigger the FSM by fsm_event_post(&p_server->fsm, E_SET, p_server) but there is three event as shown in belowFSM_TRANSITION(E_SET, G_SET_DELAY, A_DELAY_START, S_IN_DELAY),
      FSM_TRANSITION(E_SET, G_SET_TRANSITION, A_TRANSITION_START, S_IN_TRANSITION),
      FSM_TRANSITION(E_SET, FSM_OTHERWISE, A_TRANSITION_COMPLETE,S_IDLE)

    May I know which line will go into first? 

    and if you found any wrong from my understanding, please correct me.

    Thanks. 

  • Hello,

    I suggest that you try to set #define FSM_DEBUG (1) in nrf_mesh_config_core.h on line 519. It will then post some finite state machine debug information in the log. 

    It seems a bit complicated. It looks like it depends on what state it was in before calling fsm_event_post(). My best tip for you is to try it out with the FSM_DEBUG = 1 and see what happens.

    BR,

    Edvin

  • Thanks Edvin, does Nordic provide doc to explain how FSM work?

  • Hello,

    I am sorry. We don't have any other documentation other than that in the code files (.c and .h files). 

    One of my colleagues sent me this photo, which they used when they wrote the code:

Related