diff --git a/include/mcc/mcc_generic_mount.h b/include/mcc/mcc_generic_mount.h index 91d0669..50e0ba9 100644 --- a/include/mcc/mcc_generic_mount.h +++ b/include/mcc/mcc_generic_mount.h @@ -183,10 +183,13 @@ public: virtual ~MccGenericMount() { - auto err = MOVE_CNTRL_T::stopMount(); - if (err) { - logError(formatError(err)); - } + // auto err = MOVE_CNTRL_T::stopMount(); + // if (err) { + // logError(formatError(err)); + // } + + // WARNING: it is assumed here that mount stopping is performed in a derived class or, it is more logicaly, + // in MOVE_CNTRL_T-class // logDebug(std::format("Delete MccGenericMount class instance (thread: {})", std::this_thread::get_id())); logDebug("Delete MccGenericMount class instance (thread: {})", std::this_thread::get_id()); diff --git a/include/mcc/mcc_generic_movecontrols.h b/include/mcc/mcc_generic_movecontrols.h index 4e86c8b..8cbb5f9 100644 --- a/include/mcc/mcc_generic_movecontrols.h +++ b/include/mcc/mcc_generic_movecontrols.h @@ -261,7 +261,15 @@ public: virtual ~MccGenericMovementControls() { - stopMount(); + // if constexpr (executePolicy == MccGenericMovementControlsPolicy::POLICY_ASYNC) { + // // if future is valid then stop is already called + // if (!_stopFuncFuture.valid()) { + // // stopMount(); + // _stopFunc(); + // } + // } else { + // stopMount(); + // } if constexpr (executePolicy == MccGenericMovementControlsPolicy::POLICY_ASYNC) { if (_slewFuncFuture.valid()) { @@ -283,7 +291,21 @@ public: *_stopMovementRequest = false; if constexpr (executePolicy == MccGenericMovementControlsPolicy::POLICY_ASYNC) { - _slewFuncFuture = std::async(std::launch::async, _slewFunc, slew_and_stop); + if (_slewFuncFuture.valid()) { // already slewing + _slewFuncFuture = std::async( + std::launch::async, + [this](bool st) { + auto err = _stopFunc(); // first, stop mount + if (!err) { + return _slewFunc(st); + } else { + return err; + } + }, + slew_and_stop); + } else { + _slewFuncFuture = std::async(std::launch::async, _slewFunc, slew_and_stop); + } return MccGenericMovementControlsErrorCode::ERROR_OK; } else if constexpr (executePolicy == MccGenericMovementControlsPolicy::POLICY_BLOCKING) { @@ -298,7 +320,9 @@ public: *_stopMovementRequest = false; if constexpr (executePolicy == MccGenericMovementControlsPolicy::POLICY_ASYNC) { - _trackFuncFuture = std::async(std::launch::async, _trackFunc); + if (!_trackFuncFuture.valid()) { + _trackFuncFuture = std::async(std::launch::async, _trackFunc); + } // already tracking return MccGenericMovementControlsErrorCode::ERROR_OK; } else if constexpr (executePolicy == MccGenericMovementControlsPolicy::POLICY_BLOCKING) { @@ -313,7 +337,10 @@ public: *_stopMovementRequest = true; if constexpr (executePolicy == MccGenericMovementControlsPolicy::POLICY_ASYNC) { - _stopFuncFuture = std::async(std::launch::async, _stopFunc); + // if future is valid then stop is already called + if (!_stopFuncFuture.valid()) { + _stopFuncFuture = std::async(std::launch::async, _stopFunc); + } return MccGenericMovementControlsErrorCode::ERROR_OK; } else if constexpr (executePolicy == MccGenericMovementControlsPolicy::POLICY_BLOCKING) { diff --git a/include/mcc/mcc_netserver.h b/include/mcc/mcc_netserver.h index 83a7a49..72d670b 100644 --- a/include/mcc/mcc_netserver.h +++ b/include/mcc/mcc_netserver.h @@ -967,9 +967,6 @@ public: return output_msg.template byteRepr(); }; - - // special functor (used in the destructor) - _stopMountFunc = [mount_ptr]() { mount_ptr->stopMount(); }; } virtual ~MccGenericMountNetworkServer() @@ -977,8 +974,6 @@ public: std::stringstream st; st << std::this_thread::get_id(); - _stopMountFunc(); - logInfo(std::format("Delete MccGenericMountNetworkServer class instance (thread ID = {})", st.str())); } @@ -987,8 +982,6 @@ protected: MccSerializedAngleFormatPrec _coordPrec{2, 1, 7}; - std::function _stopMountFunc{}; - template RESULT_MSG_T handleMessage(const INPUT_MSG_T& input_msg, MountT* mount_ptr) requires( diff --git a/include/mcc/mcc_telemetry.h b/include/mcc/mcc_telemetry.h index c240771..2b29f72 100644 --- a/include/mcc/mcc_telemetry.h +++ b/include/mcc/mcc_telemetry.h @@ -318,6 +318,8 @@ public: error_t setPointingTarget(mcc_skypoint_c auto const& sp) { + std::lock_guard lock{*_updateMutex}; + _enteredTargetPos = sp; return MccTelemetryErrorCode::ERROR_OK; @@ -326,6 +328,8 @@ public: auto getPointingTarget() const { + std::lock_guard lock{*_updateMutex}; + return _enteredTargetPos; }