This commit is contained in:
Timur A. Fatkhullin 2025-11-01 11:57:49 +03:00
parent 8a202bd38c
commit a7fbae47f0
5 changed files with 56 additions and 19 deletions

View File

@ -13,7 +13,10 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# ******* C++ PART OF THE PROJECT ******* # ******* C++ PART OF THE PROJECT *******
set(EXAMPLES OFF CACHE BOOL "" FORCE) set(EXAMPLES OFF CACHE BOOL "" FORCE)
set(CMAKE_BUILD_TYPE "Release")
add_subdirectory(LibSidServo) add_subdirectory(LibSidServo)
set(CMAKE_BUILD_TYPE "Debug")
# add_subdirectory(cxx) # add_subdirectory(cxx)
add_subdirectory(mcc) add_subdirectory(mcc)
add_subdirectory(asibfm700) add_subdirectory(asibfm700)

View File

@ -200,7 +200,8 @@ Asibfm700Mount::error_t Asibfm700Mount::initMount()
if (ok) { if (ok) {
logInfo("Start updating telemetry data"); logInfo("Start updating telemetry data");
} else { } else {
logError("Cannot update telemetry data!"); auto err = lastUpdateError();
logError("Cannot update telemetry data (err = {} [{}])!", err.message(), err.category().name());
} }
return mcc::MccGenericMountErrorCode::ERROR_OK; return mcc::MccGenericMountErrorCode::ERROR_OK;

View File

@ -317,6 +317,7 @@ protected:
std::vector<std::function<void(const MccFiniteStateMachine*)>> _destroyFunc{}; std::vector<std::function<void(const MccFiniteStateMachine*)>> _destroyFunc{};
std::string_view _currentStateID; std::string_view _currentStateID;
std::string_view _previousStateID;
std::vector<std::string_view> _stateID{}; std::vector<std::string_view> _stateID{};
std::vector<std::string_view> _eventID{}; std::vector<std::string_view> _eventID{};
@ -367,7 +368,7 @@ protected:
public: public:
template <traits::fsm_state_c InitStateT> template <traits::fsm_state_c InitStateT>
constexpr MccFiniteStateMachine(InitStateT) : _currentStateID(InitStateT::ID) constexpr MccFiniteStateMachine(InitStateT) : _currentStateID(InitStateT::ID), _previousStateID(InitStateT::ID)
{ {
using states_t = deduce_states_t<InitStateT>; using states_t = deduce_states_t<InitStateT>;
auto states = std::make_shared<states_t>(); auto states = std::make_shared<states_t>();
@ -417,6 +418,7 @@ public:
p_event->onTransit(); p_event->onTransit();
} }
_previousStateID = curr_state_t::ID;
*currentState = &std::get<to_state_t>(*states); *currentState = &std::get<to_state_t>(*states);
_currentStateID = to_state_t::ID; _currentStateID = to_state_t::ID;
@ -525,6 +527,11 @@ public:
return _currentStateID; return _currentStateID;
} }
std::string_view previousStateID() const
{
return _previousStateID;
}
// returns IDs of all deduced unique states // returns IDs of all deduced unique states

View File

@ -469,6 +469,16 @@ protected:
// only initialization is allowed here // only initialization is allowed here
using transition_t = fsm::fsm_transition_table_t< using transition_t = fsm::fsm_transition_table_t<
std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState<ERROR_STATE_T>>>; std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState<ERROR_STATE_T>>>;
void exit(fsm::traits::fsm_event_c auto& event)
{
this->exitLog(event);
}
void enter(fsm::traits::fsm_event_c auto& event)
{
this->enterLog(event);
}
}; };
// template <fsm::traits::fsm_state_c ERROR_STATE_T> // template <fsm::traits::fsm_state_c ERROR_STATE_T>
@ -510,22 +520,23 @@ protected:
std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState>>; std::pair<MccGenericFsmMountInitEvent, MccGenericFsmMountInitState>>;
void exit(MccGenericFsmMountInitEvent& 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& 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(
"It seems a re-entering to the initializing state was asked! Ignore the event and wait for the " // "It seems a re-entering to the initializing state was asked! Ignore the event and wait for the "
"mount " // "mount "
"to initialize!"); // "to initialize!");
} // }
} // }
void exit(fsm::traits::fsm_event_c auto& event) void exit(fsm::traits::fsm_event_c auto& event)
{ {
@ -534,14 +545,25 @@ protected:
void enter(fsm::traits::fsm_event_c auto& event) void enter(fsm::traits::fsm_event_c auto& event)
{ {
enterLog(event); this->enterLog(event);
event.mount()->logDebug(
std::format("Current ID: '{}', previous ID: '{}'", ID, event.mount()->previousStateID()));
if (event.mount()->previousStateID() == ID) {
event.mount()->logWarn(
"It seems a re-entering to the initializing state was asked! Ignore the event and wait for the "
"mount "
"to initialize!");
return;
}
auto* mount_ptr = event.mount(); auto* mount_ptr = event.mount();
// call base-class initMount method! // call base-class initMount method!
auto err = static_cast<MOUNT_T*>(mount_ptr)->initMount(); auto err = static_cast<MOUNT_T*>(mount_ptr)->initMount();
if (err) { if (err) {
mount_ptr->dispatchEvent(MccGenericFsmMountErrorEvent{mount_ptr}); mount_ptr->dispatchEvent(MccGenericFsmMountErrorEvent{mount_ptr, err});
return; return;
} }

View File

@ -652,6 +652,10 @@ public:
return MccTelemetryErrorCode::ERROR_OK; return MccTelemetryErrorCode::ERROR_OK;
} }
error_t lastUpdateError() const
{
return _lastUpdateError;
}
error_t setPointingTarget(mcc_celestial_point_c auto pt) error_t setPointingTarget(mcc_celestial_point_c auto pt)
{ {