This commit is contained in:
2025-06-16 18:00:53 +03:00
parent 5a5854ccdd
commit 64a3544bd8
4 changed files with 132 additions and 79 deletions

View File

@@ -175,37 +175,53 @@ struct MccMountEventShutdown : public MccMountEventBase<MountT> {
template <traits::mcc_mount_c MountT>
struct MccMountStateBase {
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
// void exit(this auto&& self, EvT& event)
// {
// using self_t = std::remove_cvref_t<decltype(self)>;
// std::forward<decltype(self)>(self).exitImpl(event);
// event.mount().logDebug("Exit from '{}' state due to '{}' event ...", self_t::ID, EvT::ID);
// }
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
// void enter(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);
// std::forward<decltype(self)>(self).enterImpl(event);
// }
protected:
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
// void exitImpl(EvT& event)
// {
// event.mount().logWarn("Call an empty MccMountStateBase::exitImpl method!!! Event type is '{}'", EvT::ID);
// }
// template <std::derived_from<MccMountEventBase<MountT>> EvT>
// void enterImpl(EvT& event)
// {
// event.mount().logWarn("Call an empty MccMountStateBase::enterImpl method!!! Event type is '{}'", EvT::ID);
// }
// MccMountStateBase() = default;
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void exit(this auto&& self, EvT& event)
void exitLog(this auto&& self, EvT& event)
{
using self_t = std::remove_cvref_t<decltype(self)>;
std::forward<decltype(self)>(self).exitImpl(event);
event.mount().logDebug("Exit from '{}' state due to '{}' event ...", self_t::ID, EvT::ID);
}
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void enter(this auto&& self, EvT& event)
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);
std::forward<decltype(self)>(self).enterImpl(event);
}
protected:
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void exitImpl(EvT& event)
{
event.mount().logWarn("Call an empty MccMountStateBase::exitImpl method!!! Event type is '{}'", EvT::ID);
}
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void enterImpl(EvT& event)
{
event.mount().logWarn("Call an empty MccMountStateBase::enterImpl method!!! Event type is '{}'", EvT::ID);
}
};
@@ -242,25 +258,30 @@ struct MccMountStateStop : MccMountStateBase<MountT> {
using transition_t = fsm::fsm_transition_table_t<std::pair<MccMountEventIDLE<MountT>, MccMountStateIDLE<MountT>>>;
protected:
void exitImpl(MccMountEventIDLE<MountT>& event)
// protected:
void exit(MccMountEventIDLE<MountT>& event)
{
// normal exit from the state
this->exitLog(event);
}
// normal bihavior (transit to IDLE state after stopping)
void enterImpl(MccMountEventStop<MountT>& event)
{
auto mount = event.mount();
mount.stopMount();
// normal behavior (transit to IDLE state after stopping)
// void enter(MccMountEventStop<MountT>& event)
// {
// this->enterLog(event);
// switch to IDLE state
mount.template dispatchEvent<MccMountEventIDLE<MountT>>({mount});
}
// auto mount = event.mount();
// mount.stopMount();
// // switch to IDLE state
// mount.template dispatchEvent<MccMountEventIDLE<MountT>>({mount});
// }
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void enterImpl(EvT& event)
void enter(EvT& event)
{
this->enterLog(event);
auto mount = event.mount();
mount.stopMount();
@@ -268,7 +289,7 @@ protected:
if constexpr (std::same_as<EvT, MccMountEventStop<MountT>>) {
mount.logInfo("Stop reason: {}", event.reason());
// normal bihavior (transit to IDLE state after stopping)
// normal behavior (transit to IDLE state after stopping)
mount.template dispatchEvent<MccMountEventIDLE<MountT>>({mount});
} else {
mount.logInfo("Stop reason: special state");
@@ -285,15 +306,18 @@ struct MccMountStateInit : MccMountStateBase<MountT> {
using transition_t = fsm::fsm_transition_table_t<std::pair<MccMountEventIDLE<MountT>, MccMountStateIDLE<MountT>>>;
protected:
void exitImpl(MccMountEventIDLE<MountT>& event)
// protected:
void exit(MccMountEventIDLE<MountT>& event)
{
// normal exit from the state
this->exitLog(event);
}
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void enterImpl(EvT& event)
void enter(EvT& event)
{
this->enterLog(event);
auto mount = event.mount();
mount.initMount();
@@ -318,33 +342,50 @@ struct MccMountStateError : MccMountStateBase<MountT> {
std::pair<MccMountEventStop<MountT>, MccMountStateError<MountT>>,
std::pair<MccMountEventShutdown<MountT>, MccMountStateShutdown<MountT>>>;
protected:
// protected:
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void exitImpl(EvT& event)
void exit(EvT& event)
{
this->exitLog(event);
event.mount().logWarn(
"The mount is in the error state!!! One must correct it before transit to any states! Event type is '{}'",
EvT::ID);
}
void exitImpl(MccMountEventIDLE<MountT>& event)
void exit(MccMountEventIDLE<MountT>& event)
{
event.mount().logWarning("Suppose the error was corrected!");
this->exitLog(event);
event.mount().logWarn("Suppose the error was corrected!");
}
void exitImpl(MccMountEventInit<MountT>& event)
void exit(MccMountEventInit<MountT>& event)
{
// normal exit from the state
this->exitLog(event);
}
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void enterImpl(EvT& event)
void enter(MccMountEventError<MountT>& event)
{
this->enterLog(event);
auto err = event.eventData();
event.mount().logError("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)
// {
// this->enterLog(event);
// auto err = event.eventData();
// event.mount().logError("The mount is in the error state: code = {}, category = {}, message = '{}'",
// err.value(),
// err.category().name(), err.message());
// }
};
@@ -361,6 +402,18 @@ struct MccMountStateIDLE : MccMountStateBase<MountT> {
std::pair<MccMountEventGuiding<MountT>, MccMountStateGuiding<MountT>>,
std::pair<MccMountEventStop<MountT>, MccMountStateIDLE<MountT>>,
std::pair<MccMountEventShutdown<MountT>, MccMountStateShutdown<MountT>>>;
template <std::derived_from<MccMountStateBase<MountT>> EvT>
void exit(EvT& event)
{
this->exitLog(event);
}
template <std::derived_from<MccMountStateBase<MountT>> EvT>
void enter(EvT& event)
{
this->enterLog(event);
}
};
@@ -373,15 +426,18 @@ struct MccMountStateShutdown : MccMountStateBase<MountT> {
// only initialization
using transition_t = fsm::fsm_transition_table_t<std::pair<MccMountEventInit<MountT>, MccMountStateInit<MountT>>>;
protected:
void exitImpl(MccMountEventInit<MountT>& event)
// protected:
void exit(MccMountEventInit<MountT>& event)
{
// normal exit from the state
this->exitLog(event);
}
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void enterImpl(EvT& event)
void enter(EvT& event)
{
this->enterLog(event);
event.mount().shutdownMount();
}
};
@@ -402,16 +458,19 @@ struct MccMountStateSlew : MccMountStateBase<MountT> {
std::pair<MccMountEventStop<MountT>, MccMountStateStop<MountT>>,
std::pair<MccMountEventShutdown<MountT>, MccMountStateStop<MountT>>>;
protected:
// protected:
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void exitImpl(EvT& event)
void exit(EvT& event)
{
this->exitLog(event);
}
template <std::derived_from<MccMountEventSlew<MountT>> EvT>
void enterImpl(EvT& event)
void enter(EvT& event)
{
event.mount().slewMount(/* params here ...*/);
this->enterLog(event);
event.mount().slewMount(event.eventData());
}
};
@@ -432,16 +491,19 @@ struct MccMountStateGuiding : MccMountStateBase<MountT> {
std::pair<MccMountEventStop<MountT>, MccMountStateStop<MountT>>,
std::pair<MccMountEventShutdown<MountT>, MccMountStateStop<MountT>>>;
protected:
// protected:
template <std::derived_from<MccMountEventBase<MountT>> EvT>
void exitImpl(EvT& event)
void exit(EvT& event)
{
this->exitLog(event);
}
template <std::derived_from<MccMountEventSlew<MountT>> EvT>
void enterImpl(EvT& event)
void enter(EvT& event)
{
event.mount().slewMount(/* params here ...*/);
this->enterLog(event);
event.mount().startGuiding();
}
};