From 60e55535e2ade59e5ad0c046c9bb3608b0695d40 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 25 Nov 2018 16:20:52 +0000 Subject: [PATCH] Merge remote-tracking branch 'origin/development' # Conflicts: # include/etl/version.h # support/Release notes.txt --- include/etl/state_chart.h | 21 ++++++++++++++++--- include/etl/version.h | 2 +- support/Release notes.txt | 4 ++++ test/test_state_chart.cpp | 43 +++++++++++++++++++++++++++++++++------ 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/include/etl/state_chart.h b/include/etl/state_chart.h index ba8badfa..e3a33e29 100644 --- a/include/etl/state_chart.h +++ b/include/etl/state_chart.h @@ -93,7 +93,8 @@ namespace etl const state_id_t next_state_id_, void (TObject::* const action_)() = nullptr, bool (TObject::* const guard_)() = nullptr) - : current_state_id(current_state_id_), + : from_any_state(false), + current_state_id(current_state_id_), event_id(event_id_), next_state_id(next_state_id_), action(action_), @@ -101,6 +102,20 @@ namespace etl { } + transition(const event_id_t event_id_, + const state_id_t next_state_id_, + void (TObject::* const action_)() = nullptr, + bool (TObject::* const guard_)() = nullptr) + : from_any_state(true), + current_state_id(0), + event_id(event_id_), + next_state_id(next_state_id_), + action(action_), + guard(guard_) + { + } + + const bool from_any_state; const state_id_t current_state_id; const event_id_t event_id; const state_id_t next_state_id; @@ -227,7 +242,7 @@ namespace etl } //************************************************************************* - /// + /// //************************************************************************* void start(const bool on_entry_initial = true) { @@ -335,7 +350,7 @@ namespace etl bool operator()(const transition& t) const { - return (t.event_id == event_id) && (t.current_state_id == state_id); + return (t.event_id == event_id) && (t.from_any_state || (t.current_state_id == state_id)); } const event_id_t event_id; diff --git a/include/etl/version.h b/include/etl/version.h index 58924e6b..a2603dde 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 14 -#define ETL_VERSION_MINOR 1 +#define ETL_VERSION_MINOR 2 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/support/Release notes.txt b/support/Release notes.txt index d611ac55..f7eab330 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.2.0 +Added 'don't care current state' transition entry option. + =============================================================================== 14.1.0 Added hash based random number generator diff --git a/test/test_state_chart.cpp b/test/test_state_chart.cpp index 2760afd0..504cf4e2 100644 --- a/test/test_state_chart.cpp +++ b/test/test_state_chart.cpp @@ -47,7 +47,8 @@ namespace STOP, EMERGENCY_STOP, STOPPED, - SET_SPEED + SET_SPEED, + ABORT }; ETL_DECLARE_ENUM_TYPE(EventId, etl::istate_chart::event_id_t) @@ -56,6 +57,7 @@ namespace ETL_ENUM_TYPE(EMERGENCY_STOP, "Emergency Stop") ETL_ENUM_TYPE(STOPPED, "Stopped") ETL_ENUM_TYPE(SET_SPEED, "Set Speed") + ETL_ENUM_TYPE(ABORT, "Abort") ETL_END_ENUM_TYPE }; @@ -204,19 +206,20 @@ namespace bool guard; - static const etl::array transitionTable; + static const etl::array transitionTable; static const etl::array stateTable; }; //*************************************************************************** - const etl::array MotorControl::transitionTable = + const etl::array MotorControl::transitionTable = { MotorControl::transition(StateId::IDLE, EventId::START, StateId::RUNNING, &MotorControl::OnStart, &MotorControl::Guard), MotorControl::transition(StateId::IDLE, EventId::START, StateId::IDLE, &MotorControl::Null, &MotorControl::NotGuard), MotorControl::transition(StateId::RUNNING, EventId::STOP, StateId::WINDING_DOWN, &MotorControl::OnStop), MotorControl::transition(StateId::RUNNING, EventId::EMERGENCY_STOP, StateId::IDLE, &MotorControl::OnStop), MotorControl::transition(StateId::RUNNING, EventId::SET_SPEED, StateId::RUNNING, &MotorControl::OnSetSpeed), - MotorControl::transition(StateId::WINDING_DOWN, EventId::STOPPED, StateId::IDLE, &MotorControl::OnStopped) + MotorControl::transition(StateId::WINDING_DOWN, EventId::STOPPED, StateId::IDLE, &MotorControl::OnStopped), + MotorControl::transition( EventId::ABORT, StateId::IDLE) }; //*************************************************************************** @@ -282,7 +285,7 @@ namespace CHECK_EQUAL(0, motorControl.stopCount); CHECK_EQUAL(0, motorControl.stoppedCount); CHECK_EQUAL(0, motorControl.windingDown); - + // Send Start event. motorControl.guard = false; motorControl.process_event(EventId::START); @@ -399,7 +402,7 @@ namespace TEST(test_fsm_emergency_stop) { motorControl.ClearStatistics(); - + // Now in Idle state. // Send Start event. @@ -431,5 +434,33 @@ namespace CHECK_EQUAL(0, motorControl.stoppedCount); CHECK_EQUAL(0, motorControl.windingDown); } + + //************************************************************************* + TEST(test_fsm_abort) + { + motorControl.ClearStatistics(); + + // Now in Idle state. + + // Send Start event. + motorControl.process_event(EventId::START); + + // Now in Running state. + + motorControl.process_event(EventId::ABORT); + CHECK_EQUAL(StateId::IDLE, int(motorControl.get_state_id())); + + // Send Start event. + motorControl.process_event(EventId::START); + + // Now in Running state. + + // Send Stop event. + motorControl.process_event(EventId::STOP); + + // Now in WindingDown state. + motorControl.process_event(EventId::ABORT); + CHECK_EQUAL(StateId::IDLE, int(motorControl.get_state_id())); + } }; }