...
This commit is contained in:
@@ -3,12 +3,13 @@
|
||||
/* MOUNT CONTROL COMPONENTS LIBRARY */
|
||||
|
||||
/*
|
||||
* BASIC EVENTS AND MOUNT STATES DEFINITIONS (REFERENCE IMPLEMENTATION)
|
||||
* BASIC EVENTS AND MOUNT STATES DEFINITIONS (POSSIBLE IMPLEMENTATION)
|
||||
*
|
||||
*/
|
||||
|
||||
#include <format>
|
||||
|
||||
#include "mcc_mount.h"
|
||||
#include "mcc_mount_concepts.h"
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace mcc
|
||||
|
||||
// a base class for mount state machine events
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
class MccMountEventBase
|
||||
{
|
||||
public:
|
||||
@@ -41,7 +42,7 @@ protected:
|
||||
|
||||
// transit to IDLE state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountEventIDLE : public MccMountEventBase<MountT> {
|
||||
typedef MccMountEventBase<MountT> base_t;
|
||||
|
||||
@@ -55,7 +56,7 @@ struct MccMountEventIDLE : public MccMountEventBase<MountT> {
|
||||
|
||||
// transit to initialization state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountEventInit : public MccMountEventBase<MountT> {
|
||||
typedef MccMountEventBase<MountT> base_t;
|
||||
|
||||
@@ -69,7 +70,7 @@ struct MccMountEventInit : public MccMountEventBase<MountT> {
|
||||
|
||||
// transit to error state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountEventError : public MccMountEventBase<MountT> {
|
||||
typedef MccMountEventBase<MountT> base_t;
|
||||
|
||||
@@ -91,7 +92,7 @@ protected:
|
||||
|
||||
// transit to slew state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountEventSlew : public MccMountEventBase<MountT> {
|
||||
typedef MccMountEventBase<MountT> base_t;
|
||||
|
||||
@@ -113,7 +114,7 @@ protected:
|
||||
|
||||
// transit to guiding state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountEventGuiding : public MccMountEventBase<MountT> {
|
||||
typedef MccMountEventBase<MountT> base_t;
|
||||
|
||||
@@ -127,7 +128,7 @@ struct MccMountEventGuiding : public MccMountEventBase<MountT> {
|
||||
|
||||
// transit to stop state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountEventStop : public MccMountEventBase<MountT> {
|
||||
typedef MccMountEventBase<MountT> base_t;
|
||||
|
||||
@@ -159,7 +160,7 @@ protected:
|
||||
|
||||
// transit to shutdown state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountEventShutdown : public MccMountEventBase<MountT> {
|
||||
typedef MccMountEventBase<MountT> base_t;
|
||||
|
||||
@@ -173,7 +174,7 @@ struct MccMountEventShutdown : public MccMountEventBase<MountT> {
|
||||
|
||||
/* MOUNT STATE MACHINE STATES */
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateBase {
|
||||
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
// void exit(this auto&& self, EvT& event)
|
||||
@@ -214,45 +215,46 @@ protected:
|
||||
void exitLog(this auto&& self, EvT& event)
|
||||
{
|
||||
using self_t = std::remove_cvref_t<decltype(self)>;
|
||||
event.mount().logDebug("Exit from '{}' state due to '{}' event ...", self_t::ID, EvT::ID);
|
||||
|
||||
event.mount().logDebug(std::format("Exit from '{}' state due to '{}' event ...", self_t::ID, EvT::ID));
|
||||
}
|
||||
|
||||
template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
void enterLog(this auto&& self, EvT& event)
|
||||
{
|
||||
using self_t = std::remove_cvref_t<decltype(self)>;
|
||||
event.mount().logDebug("Enter to '{}' state due to '{}' event ...", self_t::ID, EvT::ID);
|
||||
event.mount().logDebug(std::format("Enter to '{}' state due to '{}' event ...", self_t::ID, EvT::ID));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// just forward declarations
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateIDLE;
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateInit;
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateError;
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateSlew;
|
||||
|
||||
template <traits::mcc_mount_c MountT, fsm::traits::fsm_event_c TrEvT = MccMountEventStop<MountT>>
|
||||
template <traits::mcc_fsm_log_mount_c MountT, fsm::traits::fsm_event_c TrEvT = MccMountEventStop<MountT>>
|
||||
struct MccMountStateStop;
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateGuiding;
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateShutdown;
|
||||
|
||||
|
||||
// stop state
|
||||
|
||||
template <traits::mcc_mount_c MountT, fsm::traits::fsm_event_c TrEvT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT, fsm::traits::fsm_event_c TrEvT>
|
||||
struct MccMountStateStop : MccMountStateBase<MountT> {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-STOP-STATE";
|
||||
|
||||
@@ -287,7 +289,7 @@ struct MccMountStateStop : MccMountStateBase<MountT> {
|
||||
mount.stopMount();
|
||||
|
||||
if constexpr (std::same_as<EvT, MccMountEventStop<MountT>>) {
|
||||
mount.logInfo("Stop reason: {}", event.reason());
|
||||
mount.logInfo(std::format("Stop reason: {}", event.reason()));
|
||||
|
||||
// normal behavior (transit to IDLE state after stopping)
|
||||
mount.template dispatchEvent<MccMountEventIDLE<MountT>>({mount});
|
||||
@@ -300,7 +302,7 @@ struct MccMountStateStop : MccMountStateBase<MountT> {
|
||||
|
||||
// initialization state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateInit : MccMountStateBase<MountT> {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-INIT-STATE";
|
||||
|
||||
@@ -329,7 +331,7 @@ struct MccMountStateInit : MccMountStateBase<MountT> {
|
||||
|
||||
// error state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateError : MccMountStateBase<MountT> {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-ERROR-STATE";
|
||||
|
||||
@@ -348,9 +350,9 @@ struct MccMountStateError : MccMountStateBase<MountT> {
|
||||
{
|
||||
this->exitLog(event);
|
||||
|
||||
event.mount().logWarn(
|
||||
event.mount().logWarn(std::format(
|
||||
"The mount is in the error state!!! One must correct it before transit to any states! Event type is '{}'",
|
||||
EvT::ID);
|
||||
EvT::ID));
|
||||
}
|
||||
|
||||
void exit(MccMountEventIDLE<MountT>& event)
|
||||
@@ -372,8 +374,8 @@ struct MccMountStateError : MccMountStateBase<MountT> {
|
||||
|
||||
auto err = event.eventData();
|
||||
|
||||
event.mount().logError("The mount is in the error state: code = {}, category = {}, message = '{}'", err.value(),
|
||||
err.category().name(), err.message());
|
||||
event.mount().logError(std::format("The mount is in the error state: code = {}, category = {}, message = '{}'",
|
||||
err.value(), err.category().name(), err.message()));
|
||||
}
|
||||
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
|
||||
// void enter(EvT& event)
|
||||
@@ -391,7 +393,7 @@ struct MccMountStateError : MccMountStateBase<MountT> {
|
||||
|
||||
// IDLE state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateIDLE : MccMountStateBase<MountT> {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-IDLE-STATE";
|
||||
|
||||
@@ -419,7 +421,7 @@ struct MccMountStateIDLE : MccMountStateBase<MountT> {
|
||||
|
||||
// shutdown state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateShutdown : MccMountStateBase<MountT> {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-SHUTDOWN-STATE";
|
||||
|
||||
@@ -445,7 +447,7 @@ struct MccMountStateShutdown : MccMountStateBase<MountT> {
|
||||
|
||||
// slew state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateSlew : MccMountStateBase<MountT> {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-SLEW-STATE";
|
||||
|
||||
@@ -478,7 +480,7 @@ struct MccMountStateSlew : MccMountStateBase<MountT> {
|
||||
|
||||
// guiding state
|
||||
|
||||
template <traits::mcc_mount_c MountT>
|
||||
template <traits::mcc_fsm_log_mount_c MountT>
|
||||
struct MccMountStateGuiding : MccMountStateBase<MountT> {
|
||||
static constexpr std::string_view ID = "MCC-MOUNT-GUIDING-STATE";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user