...
This commit is contained in:
parent
c7dd816481
commit
3ae2d41fc8
@ -127,175 +127,83 @@ public:
|
|||||||
/* GENERIC FINITE-STATE-MACHINE MOUNT REFERENCE IMPLEMENTATION */
|
/* GENERIC FINITE-STATE-MACHINE MOUNT REFERENCE IMPLEMENTATION */
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
concept mcc_generic_fsm_mount_event_c =
|
|
||||||
fsm::traits::fsm_event_c<T> && std::constructible_from<typename T::mount_t*> && requires(T t) {
|
|
||||||
{ t.mount() } -> std::same_as<typename T::mount_t*>;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template <mcc_generic_mount_c MOUNT_T>
|
template <mcc_generic_mount_c MOUNT_T>
|
||||||
struct MccGenericFsmMountBaseEvent {
|
|
||||||
typedef MOUNT_T mount_t;
|
|
||||||
|
|
||||||
// static constexpr std::string_view ID{""};
|
|
||||||
virtual ~MccGenericFsmMountBaseEvent() = default;
|
|
||||||
|
|
||||||
MOUNT_T* mount() const
|
|
||||||
{
|
|
||||||
return _mount;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
MOUNT_T* _mount;
|
|
||||||
|
|
||||||
MccGenericFsmMountBaseEvent(MOUNT_T* mount) : _mount(mount) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
struct MccGenericFsmMountInitEvent;
|
|
||||||
|
|
||||||
template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
struct MccGenericFsmMountIdleEvent;
|
|
||||||
|
|
||||||
template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
struct MccGenericFsmMountStopEvent;
|
|
||||||
|
|
||||||
template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
struct MccGenericFsmMountErrorEvent : MccGenericFsmMountBaseEvent<MOUNT_T> {
|
|
||||||
static constexpr std::string_view ID{"GENERIC-MOUNT-ERROR-EVENT"};
|
|
||||||
|
|
||||||
typedef typename MOUNT_T::error_t mount_error_t;
|
|
||||||
|
|
||||||
MccGenericFsmMountErrorEvent(MOUNT_T* mount, const mount_error_t& err)
|
|
||||||
: MccGenericFsmMountBaseEvent<MOUNT_T>(mount), _err(err)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
mount_error_t eventData() const noexcept
|
|
||||||
{
|
|
||||||
return _err;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
mount_error_t _err;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
struct MccGenericFsmMountSlewEvent;
|
|
||||||
|
|
||||||
template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
struct MccGenericFsmMountTrackEvent;
|
|
||||||
|
|
||||||
// template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
// struct MccGenericFsmMountBaseState {
|
|
||||||
// typedef MOUNT_T mount_t;
|
|
||||||
|
|
||||||
// virtual ~MccGenericFsmMountBaseState() = default;
|
|
||||||
|
|
||||||
// protected:
|
|
||||||
// MccGenericFsmMountBaseState() = default;
|
|
||||||
|
|
||||||
// template <fsm::traits::fsm_event_c EvT>
|
|
||||||
// void exitLog(this auto&& self, EvT& event)
|
|
||||||
// {
|
|
||||||
// using self_t = std::remove_cvref_t<decltype(self)>;
|
|
||||||
|
|
||||||
// if constexpr (mcc_generic_log_mount_c<MOUNT_T> &&
|
|
||||||
// std::derived_from<EvT, MccGenericFsmMountBaseEvent<MOUNT_T>>) {
|
|
||||||
// event.mount()->logDebug(std::format("Exit from '{}' state due to '{}' event ...", self_t::ID, EvT::ID));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// template <fsm::traits::fsm_event_c EvT>
|
|
||||||
// void enterLog(this auto&& self, EvT& event)
|
|
||||||
// {
|
|
||||||
// using self_t = std::remove_cvref_t<decltype(self)>;
|
|
||||||
|
|
||||||
// if constexpr (mcc_generic_log_mount_c<MOUNT_T> &&
|
|
||||||
// std::derived_from<EvT, MccGenericFsmMountBaseEvent<MOUNT_T>>) {
|
|
||||||
// event.mount()->logDebug(std::format("Enter to '{}' state due to '{}' event ...", self_t::ID, EvT::ID));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
// struct MccGenericFsmMountStartState;
|
|
||||||
|
|
||||||
// template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
// struct MccGenericFsmMountIdleState;
|
|
||||||
|
|
||||||
// template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
// struct MccGenericFsmMountStopState;
|
|
||||||
|
|
||||||
// template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
// struct MccGenericFsmMountErrorState;
|
|
||||||
|
|
||||||
// template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
// struct MccGenericFsmMountSlewState;
|
|
||||||
|
|
||||||
// template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
// struct MccGenericFsmMountTrackState;
|
|
||||||
|
|
||||||
// template <mcc_generic_mount_c MOUNT_T>
|
|
||||||
// struct MccGenericFsmMountInitState : MccGenericFsmMountBaseState<MOUNT_T> {
|
|
||||||
// static constexpr std::string_view ID{"GENERIC-MOUNT-INIT-STATE"};
|
|
||||||
|
|
||||||
// using transition_t = fsm::fsm_transition_table_t<
|
|
||||||
// std::pair<MccGenericFsmMountIdleEvent<MOUNT_T>, MccGenericFsmMountIdleState<MOUNT_T>>,
|
|
||||||
// std::pair<MccGenericFsmMountErrorEvent<MOUNT_T>, MccGenericFsmMountErrorState<MOUNT_T>>,
|
|
||||||
// std::pair<MccGenericFsmMountInitEvent<MOUNT_T>, MccGenericFsmMountInitState<MOUNT_T>>>;
|
|
||||||
|
|
||||||
|
|
||||||
// void exit(MccGenericFsmMountInitEvent<MOUNT_T>& event)
|
|
||||||
// {
|
|
||||||
// if constexpr (mcc_generic_log_mount_c<MOUNT_T>) {
|
|
||||||
// event.mount()->logWarn("It seems a re-entering to the initializing state was asked! Ignore the event!");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void enter(MccGenericFsmMountInitEvent<MOUNT_T>& event)
|
|
||||||
// {
|
|
||||||
// if constexpr (mcc_generic_log_mount_c<MOUNT_T>) {
|
|
||||||
// event.mount()->logWarn(
|
|
||||||
// "It seems a re-entering to the initializing state was asked! Ignore the event and wait for the mount
|
|
||||||
// " "to initialize!");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void exit(fsm::traits::fsm_event_c auto& event)
|
|
||||||
// {
|
|
||||||
// exitLog(event);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void enter(fsm::traits::fsm_event_c auto& event)
|
|
||||||
// {
|
|
||||||
// enterLog(event);
|
|
||||||
// auto err = event.mount()->initMount();
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <mcc_generic_mount_c MOUNT_T,
|
|
||||||
mcc_generic_fsm_mount_event_c INIT_EVENT_T = MccGenericFsmMountInitEvent<MOUNT_T>,
|
|
||||||
mcc_generic_fsm_mount_event_c STOP_EVENT_T = MccGenericFsmMountStopEvent<MOUNT_T>,
|
|
||||||
mcc_generic_fsm_mount_event_c SLEW_EVENT_T = MccGenericFsmMountSlewEvent<MOUNT_T>,
|
|
||||||
mcc_generic_fsm_mount_event_c TRACK_EVENT_T = MccGenericFsmMountTrackEvent<MOUNT_T>>
|
|
||||||
class MccGenericFsmMount : public MOUNT_T, protected fsm::MccFiniteStateMachine
|
class MccGenericFsmMount : public MOUNT_T, protected fsm::MccFiniteStateMachine
|
||||||
{
|
{
|
||||||
// to prevent infinite recursion!
|
|
||||||
static_assert(!std::derived_from<MOUNT_T, MccGenericFsmMount>, "!!!!!!!!!");
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::error_code error_t;
|
typedef std::error_code error_t;
|
||||||
|
|
||||||
|
using fsm::MccFiniteStateMachine::currentStateID;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/* default events implementation */
|
||||||
|
|
||||||
|
struct MccGenericFsmMountBaseEvent {
|
||||||
|
virtual ~MccGenericFsmMountBaseEvent() = default;
|
||||||
|
|
||||||
|
MccGenericFsmMount* mount() const
|
||||||
|
{
|
||||||
|
return _mount;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MccGenericFsmMount* _mount;
|
||||||
|
|
||||||
|
MccGenericFsmMountBaseEvent(MccGenericFsmMount* mount) : _mount(mount) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct MccGenericFsmMountInitEvent : MccGenericFsmMountBaseEvent {
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-INIT-EVENT"};
|
||||||
|
|
||||||
|
MccGenericFsmMountInitEvent(MccGenericFsmMount* mount) : MccGenericFsmMountBaseEvent(mount) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MccGenericFsmMountIdleEvent : MccGenericFsmMountBaseEvent {
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-IDLE-EVENT"};
|
||||||
|
|
||||||
|
MccGenericFsmMountIdleEvent(MccGenericFsmMount* mount) : MccGenericFsmMountBaseEvent(mount) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MccGenericFsmMountStopEvent : MccGenericFsmMountBaseEvent {
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-STOP-EVENT"};
|
||||||
|
|
||||||
|
MccGenericFsmMountStopEvent(MccGenericFsmMount* mount) : MccGenericFsmMountBaseEvent(mount) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MccGenericFsmMountErrorEvent : MccGenericFsmMountBaseEvent {
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-ERROR-EVENT"};
|
||||||
|
|
||||||
|
MccGenericFsmMountErrorEvent(MccGenericFsmMount* mount, const MccGenericFsmMount::error_t& err)
|
||||||
|
: MccGenericFsmMountBaseEvent(mount), _err(err)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MccGenericFsmMount::error_t eventData() const noexcept
|
||||||
|
{
|
||||||
|
return _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MccGenericFsmMount::error_t _err;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MccGenericFsmMountSlewEvent : MccGenericFsmMountBaseEvent {
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-SLEW-EVENT"};
|
||||||
|
|
||||||
|
MccGenericFsmMountSlewEvent(MccGenericFsmMount* mount) : MccGenericFsmMountBaseEvent(mount) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MccGenericFsmMountTrackEvent : MccGenericFsmMountBaseEvent {
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-TRACK-EVENT"};
|
||||||
|
|
||||||
|
MccGenericFsmMountTrackEvent(MccGenericFsmMount* mount) : MccGenericFsmMountBaseEvent(mount) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* default states implementation */
|
/* default states implementation */
|
||||||
|
|
||||||
|
|
||||||
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
|
||||||
struct MccGenericFsmMountBaseState {
|
struct MccGenericFsmMountBaseState {
|
||||||
virtual ~MccGenericFsmMountBaseState() = default;
|
virtual ~MccGenericFsmMountBaseState() = default;
|
||||||
|
|
||||||
@ -307,8 +215,7 @@ protected:
|
|||||||
{
|
{
|
||||||
using self_t = std::remove_cvref_t<decltype(self)>;
|
using self_t = std::remove_cvref_t<decltype(self)>;
|
||||||
|
|
||||||
if constexpr (mcc_generic_log_mount_c<MOUNT_T> &&
|
if constexpr (mcc_generic_log_mount_c<MOUNT_T> && std::derived_from<EvT, MccGenericFsmMountBaseEvent>) {
|
||||||
std::derived_from<EvT, MccGenericFsmMountBaseEvent<MOUNT_T>>) {
|
|
||||||
event.mount()->logDebug(std::format("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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,19 +225,16 @@ protected:
|
|||||||
{
|
{
|
||||||
using self_t = std::remove_cvref_t<decltype(self)>;
|
using self_t = std::remove_cvref_t<decltype(self)>;
|
||||||
|
|
||||||
if constexpr (mcc_generic_log_mount_c<MOUNT_T> &&
|
if constexpr (mcc_generic_log_mount_c<MOUNT_T> && std::derived_from<EvT, MccGenericFsmMountBaseEvent>) {
|
||||||
std::derived_from<EvT, MccGenericFsmMountBaseEvent<MOUNT_T>>) {
|
|
||||||
event.mount()->logDebug(std::format("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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MccGenericFsmMountErrorState;
|
struct MccGenericFsmMountErrorState; // default error-state class implementation (forward declaration)
|
||||||
|
|
||||||
struct MccGenericFsmMountStartState;
|
|
||||||
|
|
||||||
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
||||||
struct MccGenericFsmMountIdleState;
|
struct MccGenericFsmMountInitState;
|
||||||
|
|
||||||
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
||||||
struct MccGenericFsmMountStopState;
|
struct MccGenericFsmMountStopState;
|
||||||
@ -341,24 +245,61 @@ protected:
|
|||||||
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
||||||
struct MccGenericFsmMountTrackState;
|
struct MccGenericFsmMountTrackState;
|
||||||
|
|
||||||
|
|
||||||
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
||||||
struct MccGenericFsmMountInitState : MccGenericFsmMountBaseState<ERROR_STATE_T> {
|
struct MccGenericFsmMountStartState
|
||||||
|
: MccGenericFsmMountBaseState // initial state after mount-class creation (uninitialized state)
|
||||||
|
{
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-START-STATE"};
|
||||||
|
|
||||||
|
// only initialization is allowed here
|
||||||
|
using transition_t = fsm::fsm_transition_table_t<
|
||||||
|
std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState<ERROR_STATE_T>>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
||||||
|
struct MccGenericFsmMountIdleState
|
||||||
|
: MccGenericFsmMountBaseState // IDLE state: mount is stopped, wait for client commands
|
||||||
|
{
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-IDLDE-STATE"};
|
||||||
|
|
||||||
|
using transition_t = fsm::fsm_transition_table_t<
|
||||||
|
std::pair<MccGenericFsmMountIdleEvent, MccGenericFsmMountIdleState<ERROR_STATE_T>>,
|
||||||
|
std::pair<MccGenericFsmMountErrorEvent, ERROR_STATE_T>,
|
||||||
|
std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState<ERROR_STATE_T>>,
|
||||||
|
std::pair<MccGenericFsmMountSlewEvent, MccGenericFsmMountSlewState<ERROR_STATE_T>>,
|
||||||
|
std::pair<MccGenericFsmMountTrackEvent, MccGenericFsmMountTrackState<ERROR_STATE_T>>,
|
||||||
|
std::pair<MccGenericFsmMountStopEvent, MccGenericFsmMountStopState<ERROR_STATE_T>>>;
|
||||||
|
|
||||||
|
void exit(fsm::traits::fsm_event_c auto& event)
|
||||||
|
{
|
||||||
|
exitLog(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void enter(fsm::traits::fsm_event_c auto& event)
|
||||||
|
{
|
||||||
|
enterLog(event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
||||||
|
struct MccGenericFsmMountInitState : MccGenericFsmMountBaseState {
|
||||||
static constexpr std::string_view ID{"GENERIC-MOUNT-INIT-STATE"};
|
static constexpr std::string_view ID{"GENERIC-MOUNT-INIT-STATE"};
|
||||||
|
|
||||||
using transition_t = fsm::fsm_transition_table_t<
|
using transition_t = fsm::fsm_transition_table_t<
|
||||||
std::pair<MccGenericFsmMountIdleEvent<MOUNT_T>, MccGenericFsmMountIdleState<MccGenericFsmMountErrorState>>,
|
std::pair<MccGenericFsmMountIdleEvent, MccGenericFsmMountIdleState<ERROR_STATE_T>>,
|
||||||
std::pair<MccGenericFsmMountErrorEvent<MOUNT_T>, MccGenericFsmMountErrorState>,
|
std::pair<MccGenericFsmMountErrorEvent, ERROR_STATE_T>,
|
||||||
std::pair<MccGenericFsmMountInitEvent<MOUNT_T>, MccGenericFsmMountInitState>>;
|
std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState>>;
|
||||||
|
|
||||||
|
|
||||||
void exit(MccGenericFsmMountInitEvent<MOUNT_T>& event)
|
void exit(MccGenericFsmMountInitEvent& event)
|
||||||
{
|
{
|
||||||
if constexpr (mcc_generic_log_mount_c<MOUNT_T>) {
|
if constexpr (mcc_generic_log_mount_c<MOUNT_T>) {
|
||||||
event.mount()->logWarn("It seems a re-entering to the initializing state was asked! Ignore the event!");
|
event.mount()->logWarn("It seems a re-entering to the initializing state was asked! Ignore the event!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void enter(MccGenericFsmMountInitEvent<MOUNT_T>& event)
|
void enter(MccGenericFsmMountInitEvent& event)
|
||||||
{
|
{
|
||||||
if constexpr (mcc_generic_log_mount_c<MOUNT_T>) {
|
if constexpr (mcc_generic_log_mount_c<MOUNT_T>) {
|
||||||
event.mount()->logWarn(
|
event.mount()->logWarn(
|
||||||
@ -376,18 +317,81 @@ protected:
|
|||||||
void enter(fsm::traits::fsm_event_c auto& event)
|
void enter(fsm::traits::fsm_event_c auto& event)
|
||||||
{
|
{
|
||||||
enterLog(event);
|
enterLog(event);
|
||||||
auto err = event.mount()->initMount();
|
|
||||||
|
auto* mount_ptr = event.mount();
|
||||||
|
|
||||||
|
// call base-class initMount method!
|
||||||
|
auto err = static_cast<MOUNT_T*>(mount_ptr)->initMount();
|
||||||
|
if (err) {
|
||||||
|
mount_ptr->dispatchEvent(MccGenericFsmMountErrorEvent{mount_ptr});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// after initialization switch to IDLE state
|
||||||
|
mount_ptr->dispatchEvent(MccGenericFsmMountIdleEvent{mount_ptr});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MccGenericFsmMountErrorState // default implementation (just log error)
|
|
||||||
|
template <fsm::traits::fsm_state_c ERROR_STATE_T>
|
||||||
|
struct MccGenericFsmMountStopState : MccGenericFsmMountBaseState {
|
||||||
|
static constexpr std::string_view ID{"GENERIC-MOUNT-STOP-STATE"};
|
||||||
|
|
||||||
|
using transition_t = fsm::fsm_transition_table_t<
|
||||||
|
std::pair<MccGenericFsmMountIdleEvent, MccGenericFsmMountIdleState<ERROR_STATE_T>>,
|
||||||
|
std::pair<MccGenericFsmMountErrorEvent, ERROR_STATE_T>,
|
||||||
|
std::pair<MccGenericFsmMountStopEvent, MccGenericFsmMountStopState>>;
|
||||||
|
|
||||||
|
|
||||||
|
void exit(MccGenericFsmMountStopEvent& event)
|
||||||
|
{
|
||||||
|
if constexpr (mcc_generic_log_mount_c<MOUNT_T>) {
|
||||||
|
event.mount()->logWarn("It seems a re-entering to the stop state was asked! Ignore the event!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void enter(MccGenericFsmMountStopEvent& event)
|
||||||
|
{
|
||||||
|
if constexpr (mcc_generic_log_mount_c<MOUNT_T>) {
|
||||||
|
event.mount()->logWarn(
|
||||||
|
"It seems a re-entering to the stop state was asked! Ignore the event and wait for the mount to "
|
||||||
|
"stop!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void exit(fsm::traits::fsm_event_c auto& event)
|
||||||
|
{
|
||||||
|
exitLog(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void enter(fsm::traits::fsm_event_c auto& event)
|
||||||
|
{
|
||||||
|
enterLog(event);
|
||||||
|
|
||||||
|
auto* mount_ptr = event.mount();
|
||||||
|
|
||||||
|
// call base-class stopMount method!
|
||||||
|
auto err = static_cast<MOUNT_T*>(mount_ptr)->stopMount();
|
||||||
|
if (err) {
|
||||||
|
mount_ptr->dispatchEvent(MccGenericFsmMountErrorEvent{mount_ptr});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// after stopping switch to IDLE state
|
||||||
|
mount_ptr->dispatchEvent(MccGenericFsmMountIdleEvent{mount_ptr});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct MccGenericFsmMountErrorState : MccGenericFsmMountBaseState // default error-state class implementation
|
||||||
|
// (just log error)
|
||||||
{
|
{
|
||||||
static constexpr std::string_view ID{"GENERIC-MOUNT-ERROR-STATE"};
|
static constexpr std::string_view ID{"GENERIC-MOUNT-ERROR-STATE"};
|
||||||
|
|
||||||
using transition_t = fsm::fsm_transition_table_t<
|
using transition_t = fsm::fsm_transition_table_t<
|
||||||
std::pair<MccGenericFsmMountErrorEvent<MOUNT_T>, MccGenericFsmMountErrorState>,
|
std::pair<MccGenericFsmMountErrorEvent, MccGenericFsmMountErrorState>,
|
||||||
std::pair<MccGenericFsmMountIdleEvent<MOUNT_T>, MccGenericFsmMountIdleState<MccGenericFsmMountErrorState>>,
|
std::pair<MccGenericFsmMountIdleEvent, MccGenericFsmMountIdleState<MccGenericFsmMountErrorState>>,
|
||||||
std::pair<MccGenericFsmMountInitEvent<MOUNT_T>, MccGenericFsmMountInitState<MccGenericFsmMountErrorState>>>;
|
std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState<MccGenericFsmMountErrorState>>>;
|
||||||
|
|
||||||
void exit(fsm::traits::fsm_event_c auto& event)
|
void exit(fsm::traits::fsm_event_c auto& event)
|
||||||
{
|
{
|
||||||
@ -416,7 +420,9 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MccGenericFsmMount(MOUNT_T mount, fsm::traits::fsm_state_c auto start_state)
|
MccGenericFsmMount(
|
||||||
|
MOUNT_T mount,
|
||||||
|
fsm::traits::fsm_state_c auto start_state = MccGenericFsmMountStartState<MccGenericFsmMountErrorState>{})
|
||||||
: MOUNT_T(std::move(mount)), fsm::MccFiniteStateMachine(std::move(start_state))
|
: MOUNT_T(std::move(mount)), fsm::MccFiniteStateMachine(std::move(start_state))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -426,7 +432,7 @@ public:
|
|||||||
auto initMount()
|
auto initMount()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
this->dispatchEvent(INIT_EVENT_T{this});
|
this->dispatchEvent(MccGenericFsmMountInitEvent{this});
|
||||||
} catch (std::system_error const& exc) {
|
} catch (std::system_error const& exc) {
|
||||||
return exc.code();
|
return exc.code();
|
||||||
}
|
}
|
||||||
@ -437,7 +443,7 @@ public:
|
|||||||
auto stopMount()
|
auto stopMount()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
this->dispatchEvent(STOP_EVENT_T{this});
|
this->dispatchEvent(MccGenericFsmMountStopEvent{this});
|
||||||
} catch (std::system_error const& exc) {
|
} catch (std::system_error const& exc) {
|
||||||
return exc.code();
|
return exc.code();
|
||||||
}
|
}
|
||||||
@ -448,7 +454,7 @@ public:
|
|||||||
auto slewToTarget()
|
auto slewToTarget()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
this->dispatchEvent(SLEW_EVENT_T{this});
|
this->dispatchEvent(MccGenericFsmMountSlewEvent{this});
|
||||||
} catch (std::system_error const& exc) {
|
} catch (std::system_error const& exc) {
|
||||||
return exc.code();
|
return exc.code();
|
||||||
}
|
}
|
||||||
@ -459,7 +465,7 @@ public:
|
|||||||
auto stopSlewing()
|
auto stopSlewing()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
this->dispatchEvent(STOP_EVENT_T{this});
|
this->dispatchEvent(MccGenericFsmMountStopEvent{this});
|
||||||
} catch (std::system_error const& exc) {
|
} catch (std::system_error const& exc) {
|
||||||
return exc.code();
|
return exc.code();
|
||||||
}
|
}
|
||||||
@ -470,7 +476,7 @@ public:
|
|||||||
auto trackTarget()
|
auto trackTarget()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
this->dispatchEvent(TRACK_EVENT_T{this});
|
this->dispatchEvent(MccGenericFsmMountTrackEvent{this});
|
||||||
} catch (std::system_error const& exc) {
|
} catch (std::system_error const& exc) {
|
||||||
return exc.code();
|
return exc.code();
|
||||||
}
|
}
|
||||||
@ -482,7 +488,7 @@ public:
|
|||||||
auto stopTracking()
|
auto stopTracking()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
this->dispatchEvent(STOP_EVENT_T{this});
|
this->dispatchEvent(MccGenericFsmMountStopEvent{this});
|
||||||
} catch (std::system_error const& exc) {
|
} catch (std::system_error const& exc) {
|
||||||
return exc.code();
|
return exc.code();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user