/* * Function to set the sub state of state machine * * \param state Sub state to be set * \param arg arguments to be set as part of set sub state */ void peer_search_initiator_set_sub_state(uint8_t state, void *arg) { peer_search_initiator_state_t new_state = (peer_search_initiator_state_t)state; void (*handler_func_exit)(void); void (*handler_func_init)(void * arg); handler_func_exit = peer_search_initiator_state_table[node_info.sub_state].peer_state_exit; /* Exit the old state */ if (new_state && handler_func_exit) { handler_func_exit(); } /* Change and welcome to new sub state */ node_info.sub_state = new_state; handler_func_init = peer_search_initiator_state_table[new_state].peer_state_init; if (handler_func_init) { handler_func_init(arg); } }
/* * \brief Function to set the main state of state machine * * \param state main state to be set * \param arg argument passed in the state */ void set_main_state(main_state_t state, void *arg) { void (*handler_func_exit)(void); void (*handler_func_init)(void *arg); void (*handler_sub_state_set)(uint8_t state, void *arg); handler_func_exit = state_table[node_info.main_state].func_main_state_exit; /* Exit the old state if not init state */ if (handler_func_exit && state) { handler_func_exit(); } /* Nullify all the previous tx call backs. In case of change in main * state * TX call back prevention is taken care here. If the state has sub * states * TX call back during sub state change must be taken care during sub * state * set exclusively */ node_info.transmitting = false; /* Welcome to new state */ node_info.main_state = state; handler_func_init = state_table[state].func_main_state_init; /* Do init for new state and then change state */ if (handler_func_init) { handler_func_init(arg); } handler_sub_state_set = state_table[state].func_sub_state_set; if (handler_sub_state_set) { handler_sub_state_set(0, arg); } }