From 2d3a80e2b75119eb5d4c80f3c09fe82e5642f0c8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 27 May 2025 16:47:27 +0100 Subject: [PATCH] Refactored hfsm receive function --- include/etl/hfsm.h | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/include/etl/hfsm.h b/include/etl/hfsm.h index 1a1cfcd0..eab44f55 100644 --- a/include/etl/hfsm.h +++ b/include/etl/hfsm.h @@ -101,33 +101,24 @@ namespace etl if (is_started()) { etl::fsm_state_id_t next_state_id = p_state->process_event(message); + + if (have_changed_state(next_state_id)) + { + ETL_ASSERT_OR_RETURN(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception)); - if (next_state_id != ifsm_state::No_State_Change) - { - if (have_changed_state(next_state_id)) - { - ETL_ASSERT_OR_RETURN(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception)); + etl::ifsm_state* p_next_state = state_list[next_state_id]; + etl::ifsm_state* p_root = common_ancestor(p_state, p_next_state); + + do_exits(p_root, p_state); + next_state_id = do_enters(p_root, p_next_state, true); - etl::ifsm_state* p_next_state = state_list[next_state_id]; - - etl::ifsm_state* p_root = common_ancestor(p_state, p_next_state); - do_exits(p_root, p_state); - - p_state = p_next_state; - - next_state_id = do_enters(p_root, p_next_state, true); - - if (next_state_id != ifsm_state::No_State_Change) - { - ETL_ASSERT_OR_RETURN(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception)); - p_state = state_list[next_state_id]; - } - } - else if (is_self_transition(next_state_id)) - { - p_state->on_exit_state(); - p_state->on_enter_state(); - } + ETL_ASSERT_OR_RETURN(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception)); + p_state = state_list[next_state_id]; + } + else if (is_self_transition(next_state_id)) + { + p_state->on_exit_state(); + p_state->on_enter_state(); } } else