diff --git a/cxx/mcc_mount_events_states.h b/cxx/mcc_mount_events_states.h index 60f7375..5d80837 100644 --- a/cxx/mcc_mount_events_states.h +++ b/cxx/mcc_mount_events_states.h @@ -162,6 +162,13 @@ struct MccMountEventStop : public MccMountEventBase { return _reason; } + std::string_view reason() const + { + return _reason == EVENT_STOP_BUTTON ? "Hardware stop-button" + : _reason == EVENT_STOP_CLIENT ? "Stop from client" + : "UNKNOWN"; + } + MccMountEventStop(MountT& mount, event_data_t reason) : base_t(mount), _reason(reason) {} protected: @@ -236,7 +243,7 @@ struct MccMountStateError; template struct MccMountStateSlew; -template +template > struct MccMountStateStop; template @@ -246,6 +253,49 @@ template struct MccMountStateShutdown; +// stop state + +template +struct MccMountStateStop : MccMountStateBase { + static constexpr std::string_view ID = "MCC-MOUNT-STOP-STATE"; + + using transition_t = fsm::fsm_transition_table_t, MccMountStateIDLE>>; + +protected: + void exitImpl(MccMountEventIDLE& event) + { + // normal exit from the state + } + + // normal bihavior (transit to IDLE state after stopping) + void enterImpl(MccMountEventStop& event) + { + auto mount = event.mount(); + mount.stopMount(); + + // switch to IDLE state + mount.template dispatchEvent>({mount}); + } + + template > EvT> + void enterImpl(EvT& event) + { + auto mount = event.mount(); + + mount.stopMount(); + + if constexpr (std::same_as>) { + mount.logInfo("Stop reason: {}", event.reason()); + + // normal bihavior (transit to IDLE state after stopping) + mount.template dispatchEvent>({mount}); + } else { + mount.logInfo("Stop reason: special state"); + mount.dispatchEvent(event); + } + } +}; + // initialization state template @@ -263,14 +313,17 @@ protected: template > EvT> void enterImpl(EvT& event) { - event.mount().initMount(); + auto mount = event.mount(); + mount.initMount(); // switch to IDLE state - event.mount().template dispatchEvent>(); + mount.template dispatchEvent>({mount}); } }; +// error state + template struct MccMountStateError : MccMountStateBase { static constexpr std::string_view ID = "MCC-MOUNT-ERROR-STATE"; @@ -288,7 +341,7 @@ protected: template > EvT> void exitImpl(EvT& event) { - event.mount().logWarning( + event.mount().logWarn( "The mount is in the error state!!! One must correct it before transit to any states! Event type is '{}'", EvT::ID); } @@ -314,6 +367,8 @@ protected: }; +// IDLE state + template struct MccMountStateIDLE : MccMountStateBase { static constexpr std::string_view ID = "MCC-MOUNT-IDLE-STATE"; @@ -328,17 +383,55 @@ struct MccMountStateIDLE : MccMountStateBase { }; +// shutdown state + template struct MccMountStateShutdown : MccMountStateBase { static constexpr std::string_view ID = "MCC-MOUNT-SHUTDOWN-STATE"; + // only initialization + using transition_t = fsm::fsm_transition_table_t, MccMountStateInit>>; + +protected: + void exitImpl(MccMountEventInit& event) + { + // normal exit from the state + } + + template > EvT> + void enterImpl(EvT& event) + { + event.mount().shutdownMount(); + } +}; + + +// slew state + +template +struct MccMountStateSlew : MccMountStateBase { + static constexpr std::string_view ID = "MCC-MOUNT-SLEW-STATE"; + + // only initialization using transition_t = fsm::fsm_transition_table_t, MccMountStateInit>, - std::pair, MccMountStateError>, - std::pair, MccMountStateSlew>, - std::pair, MccMountStateGuiding>, - std::pair, MccMountStateIDLE>, - std::pair, MccMountStateShutdown>>; + std::pair, MccMountStateStop>, + // std::pair, MccMountStateSlew>, + std::pair, MccMountStateStop>, + std::pair, MccMountStateStop>, + std::pair, MccMountStateStop>>; + +protected: + template > EvT> + void exitImpl(EvT& event) + { + } + + template > EvT> + void enterImpl(EvT& event) + { + event.mount().startSlew(/* params here ...*/); + } }; } // namespace mcc