...
This commit is contained in:
parent
b3a257fab6
commit
94fb4c6a48
@ -102,7 +102,7 @@ Asibfm700Mount::error_t Asibfm700Mount::initMount()
|
||||
logInfo("");
|
||||
logInfo("Setup slewing and tracking parameters ...");
|
||||
mpars.slewRateX = _mountConfig.getValue<mcc::MccAngle>("hwMaxRateHA").value_or(0.0);
|
||||
mpars.slewRateY = _mountConfig.getValue<mcc::MccAngle>("hwMaxRateDec").value_or(0.0);
|
||||
mpars.slewRateY = _mountConfig.getValue<mcc::MccAngle>("hwMaxRateDEC").value_or(0.0);
|
||||
auto st_err = setSlewingParams(mpars);
|
||||
if (st_err) {
|
||||
errorLogging(" An error occured while setting slewing parameters: ", st_err);
|
||||
|
||||
@ -22,6 +22,8 @@ Asibfm700MountNetServer::Asibfm700MountNetServer(asio::io_context& ctx,
|
||||
using output_msg_t = Asibfm700NetMessage<handle_message_func_result_t>;
|
||||
output_msg_t output_msg;
|
||||
|
||||
auto nn = std::this_thread::get_id();
|
||||
|
||||
auto ec = parseMessage(command, input_msg);
|
||||
|
||||
if (ec) {
|
||||
|
||||
@ -640,15 +640,18 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
bool slew_and_stop = event.eventData();
|
||||
|
||||
auto nn = std::this_thread::get_id();
|
||||
|
||||
// call base-class slewToTarget method!
|
||||
auto err = static_cast<MOUNT_T*>(mount_ptr)->slewToTarget();
|
||||
auto err = static_cast<MOUNT_T*>(mount_ptr)->slewToTarget(slew_and_stop);
|
||||
if (err) {
|
||||
mount_ptr->dispatchEvent(MccGenericFsmMountErrorEvent{mount_ptr, err});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool slew_and_stop = event.eventData();
|
||||
if (slew_and_stop) { // after slewing switch to IDLE state
|
||||
mount_ptr->dispatchEvent(MccGenericFsmMountIdleEvent{mount_ptr});
|
||||
} else { // after slewing switch to tracking state
|
||||
|
||||
@ -916,7 +916,7 @@ concept mcc_slewing_model_c = requires(T t) {
|
||||
// { t.setSlewingParams(std::declval<typename T::slewing_params_t>()) } -> std::same_as<typename T::error_t>;
|
||||
{ t.getSlewingParams() } -> std::same_as<typename T::slewing_params_t>;
|
||||
|
||||
{ t.slewingCurrentError() } -> mcc_error_c;
|
||||
// { t.slewingCurrentError() } -> mcc_error_c;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -362,6 +362,7 @@ public:
|
||||
auto sock = co_await acc.async_accept(asio::use_awaitable);
|
||||
// start new client session
|
||||
asio::co_spawn(_asioContext, startSession(std::move(sock)), asio::detached);
|
||||
logDebug(std::format("session was spawned, start accepting new connections ..."));
|
||||
}
|
||||
|
||||
|
||||
@ -883,6 +884,8 @@ protected:
|
||||
}
|
||||
|
||||
logInfo(std::format("Close client session: remote endpoint <{}> (thread ID = {})", r_epn, thr_id));
|
||||
|
||||
co_return;
|
||||
}
|
||||
};
|
||||
|
||||
@ -906,6 +909,8 @@ public:
|
||||
using mount_error_t = typename MountT::error_t;
|
||||
mount_error_t m_err;
|
||||
|
||||
auto nn = std::this_thread::get_id();
|
||||
|
||||
MccNetMessage input_msg;
|
||||
using output_msg_t = MccNetMessage<handle_message_func_result_t>;
|
||||
output_msg_t output_msg;
|
||||
|
||||
@ -53,7 +53,7 @@ struct MccSimpleSlewingModelCategory : public std::error_category {
|
||||
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "SIMPLE-TRACKING-MODEL";
|
||||
return "SIMPLE-SLEWING-MODEL";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
@ -214,7 +214,9 @@ public:
|
||||
start_slewing_tp = std::chrono::steady_clock::now();
|
||||
last_adjust_tp = start_slewing_tp;
|
||||
|
||||
while (true) {
|
||||
// main loop (simply monitors the current position taking into account the prohibited zones, as well as the
|
||||
// timeout of the entire process)
|
||||
while (!*_stopSlewing) {
|
||||
// wait for updated telemetry data
|
||||
{
|
||||
std::lock_guard lock{*_currentParamsMutex};
|
||||
@ -263,91 +265,115 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hw_err = controls->hardwareGetState(&hw_state);
|
||||
if (hw_err) {
|
||||
*_stopSlewing = true;
|
||||
return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_GETSTATE);
|
||||
}
|
||||
|
||||
t_err = controls->targetToMountDist(&dist);
|
||||
if (t_err) {
|
||||
*_stopSlewing = true;
|
||||
return mcc_deduce_error_code(t_err, MccSimpleSlewingModelErrorCode::ERROR_DIST_TELEMETRY);
|
||||
}
|
||||
|
||||
if (*_stopSlewing) {
|
||||
return MccSimpleSlewingModelErrorCode::ERROR_STOPPED;
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard lock{*_currentParamsMutex};
|
||||
|
||||
// if (adjust_mode && !_currentParams.slewAndStop) {
|
||||
if (adjust_mode && !slew_and_stop) {
|
||||
// do not allow mount speed fall below sideral
|
||||
if constexpr (mccIsEquatorialMount(CONTROLS_T::mountType)) {
|
||||
// turn on sideral rate only if the current position point catches up with the target
|
||||
if ((tdata.target.HA - tdata.HA) <= 0.0 && tdata.speedX < slewing_params_t::sideralRate) {
|
||||
hw_state.X = (double)tdata.target.X;
|
||||
hw_state.Y = (double)tdata.target.Y;
|
||||
|
||||
hw_state.speedX = slewing_params_t::sideralRate;
|
||||
|
||||
hw_state.moving_state = CONTROLS_T::hardware_moving_state_t::HW_MOVE_TRACKING;
|
||||
|
||||
hw_err = controls->hardwareSetState(hw_state);
|
||||
if (hw_err) {
|
||||
*_stopSlewing = true;
|
||||
return mcc_deduce_error_code(hw_err,
|
||||
MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
|
||||
}
|
||||
}
|
||||
} else if constexpr (mccIsAltAzMount(CONTROLS_T::mountType)) {
|
||||
} else {
|
||||
static_assert(false, "UNKNOWN MOUNT TYPE!!");
|
||||
}
|
||||
if (slew_and_stop) {
|
||||
if (hw_state.moving_state == CONTROLS_T::hardware_moving_state_t::HW_MOVE_STOPPED) {
|
||||
break;
|
||||
}
|
||||
} else { // just wait for mount to be stopped
|
||||
t_err = controls->targetToMountDist(&dist);
|
||||
if (t_err) {
|
||||
*_stopSlewing = true;
|
||||
return mcc_deduce_error_code(t_err, MccSimpleSlewingModelErrorCode::ERROR_DIST_TELEMETRY);
|
||||
}
|
||||
|
||||
if (dist <= _currentParams.slewToleranceRadius) { // stop slewing and exit from cycle
|
||||
if (hw_state.moving_state ==
|
||||
CONTROLS_T::hardware_moving_state_t::HW_MOVE_STOPPED) { // mount was stopped
|
||||
*_stopSlewing = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (dist <= _currentParams.adjustCoordDiff) { // adjust mount pointing
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if ((now - last_adjust_tp) < _currentParams.adjustCycleInterval) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hw_state.X = (double)tdata.target.X;
|
||||
hw_state.Y = (double)tdata.target.Y;
|
||||
// resend new position since target coordinates are changed in time
|
||||
hw_state.X = (double)tdata.target.X;
|
||||
hw_state.Y = (double)tdata.target.Y;
|
||||
|
||||
hw_state.speedX = _currentParams.adjustRateX;
|
||||
hw_state.speedY = _currentParams.adjustRateY;
|
||||
|
||||
hw_state.moving_state = CONTROLS_T::hardware_moving_state_t::HW_MOVE_ADJUSTING;
|
||||
|
||||
hw_err = controls->hardwareSetState(hw_state);
|
||||
if (hw_err) {
|
||||
*_stopSlewing = true;
|
||||
return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
|
||||
}
|
||||
|
||||
last_adjust_tp = now;
|
||||
|
||||
adjust_mode = true;
|
||||
|
||||
} else {
|
||||
adjust_mode = false;
|
||||
hw_err = controls->hardwareSetState(hw_state);
|
||||
if (hw_err) {
|
||||
*_stopSlewing = true;
|
||||
return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
|
||||
}
|
||||
}
|
||||
|
||||
if (*_stopSlewing) {
|
||||
return MccSimpleSlewingModelErrorCode::ERROR_STOPPED;
|
||||
}
|
||||
|
||||
|
||||
// if (*_stopSlewing) {
|
||||
// return MccSimpleSlewingModelErrorCode::ERROR_STOPPED;
|
||||
// }
|
||||
|
||||
// {
|
||||
// std::lock_guard lock{*_currentParamsMutex};
|
||||
|
||||
// // if (adjust_mode && !_currentParams.slewAndStop) {
|
||||
// if (adjust_mode && !slew_and_stop) {
|
||||
// // do not allow mount speed fall below sideral
|
||||
// if constexpr (mccIsEquatorialMount(CONTROLS_T::mountType)) {
|
||||
// // turn on sideral rate only if the current position point catches up with the target
|
||||
// if ((tdata.target.HA - tdata.HA) <= 0.0 && tdata.speedX < slewing_params_t::sideralRate)
|
||||
// {
|
||||
// hw_state.X = (double)tdata.target.X;
|
||||
// hw_state.Y = (double)tdata.target.Y;
|
||||
|
||||
// hw_state.speedX = slewing_params_t::sideralRate;
|
||||
|
||||
// hw_state.moving_state = CONTROLS_T::hardware_moving_state_t::HW_MOVE_TRACKING;
|
||||
|
||||
// hw_err = controls->hardwareSetState(hw_state);
|
||||
// if (hw_err) {
|
||||
// *_stopSlewing = true;
|
||||
// return mcc_deduce_error_code(hw_err,
|
||||
// MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
|
||||
// }
|
||||
// }
|
||||
// } else if constexpr (mccIsAltAzMount(CONTROLS_T::mountType)) {
|
||||
// } else {
|
||||
// static_assert(false, "UNKNOWN MOUNT TYPE!!");
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (dist <= _currentParams.slewToleranceRadius) { // stop slewing and exit from cycle
|
||||
// if (hw_state.moving_state ==
|
||||
// CONTROLS_T::hardware_moving_state_t::HW_MOVE_STOPPED) { // mount was stopped
|
||||
// *_stopSlewing = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (dist <= _currentParams.adjustCoordDiff) { // adjust mount pointing
|
||||
// auto now = std::chrono::steady_clock::now();
|
||||
// if ((now - last_adjust_tp) < _currentParams.adjustCycleInterval) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// hw_state.X = (double)tdata.target.X;
|
||||
// hw_state.Y = (double)tdata.target.Y;
|
||||
|
||||
// hw_state.speedX = _currentParams.adjustRateX;
|
||||
// hw_state.speedY = _currentParams.adjustRateY;
|
||||
|
||||
// hw_state.moving_state = CONTROLS_T::hardware_moving_state_t::HW_MOVE_ADJUSTING;
|
||||
|
||||
// hw_err = controls->hardwareSetState(hw_state);
|
||||
// if (hw_err) {
|
||||
// *_stopSlewing = true;
|
||||
// return mcc_deduce_error_code(hw_err, MccSimpleSlewingModelErrorCode::ERROR_HW_SETSTATE);
|
||||
// }
|
||||
|
||||
// last_adjust_tp = now;
|
||||
|
||||
// adjust_mode = true;
|
||||
|
||||
// } else {
|
||||
// adjust_mode = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (*_stopSlewing) {
|
||||
// return MccSimpleSlewingModelErrorCode::ERROR_STOPPED;
|
||||
// }
|
||||
}
|
||||
|
||||
return MccSimpleSlewingModelErrorCode::ERROR_OK;
|
||||
|
||||
@ -51,7 +51,7 @@ struct MccTelemetryCategory : public std::error_category {
|
||||
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "ALTITUDE-LIMIT-PZ";
|
||||
return "MCC-TELEMETRY";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
@ -160,6 +160,20 @@ public:
|
||||
if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
||||
_data.target.X = _data.target.RA_ICRS;
|
||||
_data.target.Y = _data.target.DEC_ICRS;
|
||||
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZZD) {
|
||||
_data.target.X = _data.target.AZ;
|
||||
_data.target.Y = _data.target.ZD;
|
||||
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZALT) {
|
||||
_data.target.X = _data.target.AZ;
|
||||
_data.target.Y = _data.target.ALT;
|
||||
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_HADEC_APP) {
|
||||
_data.target.X = _data.target.HA;
|
||||
_data.target.Y = _data.target.DEC_APP;
|
||||
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_APP) {
|
||||
_data.target.X = _data.target.RA_APP;
|
||||
_data.target.Y = _data.target.DEC_APP;
|
||||
} else {
|
||||
return MccTelemetryErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
||||
}
|
||||
|
||||
auto ccte_err = controls->transformCoordinates(_data.target, &_data.target);
|
||||
@ -178,21 +192,24 @@ public:
|
||||
if (_data.target.pair_kind != MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
|
||||
// fixed apparent coordinates (AZZD or HADEC)
|
||||
// needs to compute ICRS
|
||||
if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZZD) {
|
||||
_data.target.X = _data.target.AZ;
|
||||
_data.target.Y = _data.target.ZD;
|
||||
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZALT) {
|
||||
_data.target.X = _data.target.AZ;
|
||||
_data.target.Y = _data.target.ALT;
|
||||
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_HADEC_APP) {
|
||||
_data.target.X = _data.target.HA;
|
||||
_data.target.Y = _data.target.DEC_APP;
|
||||
} else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_APP) {
|
||||
_data.target.X = _data.target.RA_APP;
|
||||
_data.target.Y = _data.target.DEC_APP;
|
||||
} else {
|
||||
return MccTelemetryErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
||||
}
|
||||
// (.X and .Y are already assigned above!)
|
||||
|
||||
|
||||
// if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZZD) {
|
||||
// _data.target.X = _data.target.AZ;
|
||||
// _data.target.Y = _data.target.ZD;
|
||||
// } else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_AZALT) {
|
||||
// _data.target.X = _data.target.AZ;
|
||||
// _data.target.Y = _data.target.ALT;
|
||||
// } else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_HADEC_APP) {
|
||||
// _data.target.X = _data.target.HA;
|
||||
// _data.target.Y = _data.target.DEC_APP;
|
||||
// } else if (_data.target.pair_kind == MccCoordPairKind::COORDS_KIND_RADEC_APP) {
|
||||
// _data.target.X = _data.target.RA_APP;
|
||||
// _data.target.Y = _data.target.DEC_APP;
|
||||
// } else {
|
||||
// return MccTelemetryErrorCode::ERROR_UNSUPPORTED_COORD_PAIR;
|
||||
// }
|
||||
|
||||
MccCelestialPoint pt{.pair_kind = MccCoordPairKind::COORDS_KIND_RADEC_ICRS};
|
||||
ccte_err = controls->transformCoordinates(_data.target, &pt);
|
||||
@ -228,76 +245,6 @@ public:
|
||||
return MccTelemetryErrorCode::ERROR_OK;
|
||||
};
|
||||
|
||||
/*
|
||||
_updateTargetFunc = [controls, this](bool only_hw, std::stop_token stop_token) -> error_t {
|
||||
if (!only_hw) {
|
||||
//
|
||||
// compute apparent coordinates
|
||||
// ICRS coordinates of the taget must be already set
|
||||
//
|
||||
_data.target.time_point =
|
||||
std::chrono::time_point_cast<typename decltype(_data.target.time_point)::duration>(
|
||||
_data.time_point);
|
||||
|
||||
_data.target.pair_kind = MccCoordPairKind::COORDS_KIND_RADEC_ICRS;
|
||||
_data.target.X = _data.target.RA_ICRS;
|
||||
_data.target.Y = _data.target.DEC_ICRS;
|
||||
|
||||
// update apparent cordinates
|
||||
auto ccte_err = controls->transformCoordinates(_data.target, &_data.target);
|
||||
if (ccte_err) {
|
||||
return mcc_deduce_error_code(ccte_err, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM);
|
||||
}
|
||||
}
|
||||
|
||||
if (stop_token.stop_requested()) {
|
||||
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
}
|
||||
|
||||
|
||||
typename pcm_t::error_t pcm_err;
|
||||
|
||||
MccPCMResult pcm_res;
|
||||
|
||||
// MccCelestialPoint pt;
|
||||
// pt.time_point =
|
||||
// std::chrono::time_point_cast<typename decltype(pt.time_point)::duration>(_data.target.time_point);
|
||||
|
||||
pcm_err = controls->computeInversePCM(_data, &pcm_res, &_data);
|
||||
|
||||
// if constexpr (mccIsEquatorialMount(pcm_t::mountType)) {
|
||||
// pcm_err = pcm->computeInversePCM(_data, &pcm_res, &_data);
|
||||
|
||||
// pt.pair_kind = MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||
// pt.X = _data.target.HA;
|
||||
// pt.Y = _data.target.DEC_APP;
|
||||
// pcm_err = pcm->computeInversePCM(std::move(pt), &pcm_res);
|
||||
// if (!pcm_err) {
|
||||
// _data.target.X = _data.target.HA - pcm_res.pcmX;
|
||||
// _data.target.Y = _data.target.DEC_APP - pcm_res.pcmY;
|
||||
// }
|
||||
// } else if constexpr (mccIsAltAzMount(pcm_t::mountType)) {
|
||||
// pt.pair_kind = MccCoordPairKind::COORDS_KIND_AZALT;
|
||||
// pt.X = _data.target.AZ;
|
||||
// pt.Y = _data.target.ALT;
|
||||
// pcm_err = pcm->computeInversePCM(std::move(pt), &pcm_res);
|
||||
// if (!pcm_err) {
|
||||
// _data.target.X = _data.target.AZ - pcm_res.pcmX;
|
||||
// _data.target.Y = _data.target.ALT - pcm_res.pcmY;
|
||||
// }
|
||||
// } else {
|
||||
// static_assert(false, "UNKNOWN MOUNT TYPE!");
|
||||
// }
|
||||
|
||||
if (pcm_err) {
|
||||
return mcc_deduce_error_code(pcm_err, MccTelemetryErrorCode::ERROR_PCM_COMP);
|
||||
}
|
||||
|
||||
|
||||
return MccTelemetryErrorCode::ERROR_OK;
|
||||
};
|
||||
*/
|
||||
|
||||
_updateFunc = [controls, this](std::stop_token stop_token) -> std::error_code {
|
||||
// first, update mount quantities
|
||||
typename hardware_t::hardware_state_t hw_pos;
|
||||
@ -306,9 +253,9 @@ public:
|
||||
return mcc_deduce_error_code(hw_err, MccTelemetryErrorCode::ERROR_HARDWARE_GETPOS);
|
||||
}
|
||||
|
||||
if (stop_token.stop_requested()) {
|
||||
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
}
|
||||
// if (stop_token.stop_requested()) {
|
||||
// return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
// }
|
||||
|
||||
double eo;
|
||||
|
||||
@ -323,10 +270,6 @@ public:
|
||||
|
||||
ccte_err = controls->juldayToAppSideral(_data.JD, &_data.LST, true);
|
||||
if (!ccte_err) {
|
||||
if (stop_token.stop_requested()) {
|
||||
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
}
|
||||
|
||||
ccte_err = controls->equationOrigins(_data.JD, &eo);
|
||||
}
|
||||
}
|
||||
@ -335,9 +278,9 @@ public:
|
||||
return mcc_deduce_error_code(ccte_err, MccTelemetryErrorCode::ERROR_COORD_TRANSFORM);
|
||||
}
|
||||
|
||||
if (stop_token.stop_requested()) {
|
||||
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
}
|
||||
// if (stop_token.stop_requested()) {
|
||||
// return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
// }
|
||||
|
||||
_data.X = (double)hw_pos.X;
|
||||
_data.Y = (double)hw_pos.Y;
|
||||
@ -350,9 +293,9 @@ public:
|
||||
return mcc_deduce_error_code(pcm_err, MccTelemetryErrorCode::ERROR_PCM_COMP);
|
||||
}
|
||||
|
||||
if (stop_token.stop_requested()) {
|
||||
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
}
|
||||
// if (stop_token.stop_requested()) {
|
||||
// return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
// }
|
||||
|
||||
MccCelestialPoint pt{.pair_kind = MccCoordPairKind::COORDS_KIND_AZALT, .time_point = _data.time_point};
|
||||
|
||||
@ -391,9 +334,9 @@ public:
|
||||
}
|
||||
|
||||
if (!ccte_err) {
|
||||
if (stop_token.stop_requested()) {
|
||||
return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
}
|
||||
// if (stop_token.stop_requested()) {
|
||||
// return MccTelemetryErrorCode::ERROR_UPDATE_STOPPED;
|
||||
// }
|
||||
|
||||
// to compute refraction coefficients
|
||||
_data.pair_kind = MccCoordPairKind::COORDS_KIND_AZZD;
|
||||
@ -530,14 +473,18 @@ public:
|
||||
_internalUpdatingFuture = std::async(
|
||||
std::launch::async,
|
||||
[this](std::stop_token stop_token) -> error_t {
|
||||
// while (!stop_token.stop_requested()) {
|
||||
while (true) {
|
||||
while (!stop_token.stop_requested()) {
|
||||
// while (true) {
|
||||
_lastUpdateError = updateTelemetryData(defaultInternalUpdateTimeout);
|
||||
if (_lastUpdateError) {
|
||||
*_internalUpdating = false;
|
||||
return _lastUpdateError;
|
||||
}
|
||||
|
||||
// auto nn = std::this_thread::get_id();
|
||||
|
||||
// std::this_thread::sleep_for(_currentUpdateInterval);
|
||||
|
||||
{
|
||||
std::lock_guard lock{*_currentUpdateIntervalMutex};
|
||||
|
||||
@ -592,28 +539,30 @@ public:
|
||||
|
||||
error_t updateTelemetryData(traits::mcc_time_duration_c auto const& timeout)
|
||||
{
|
||||
std::lock_guard thread_lock{*_updateMutex};
|
||||
{
|
||||
std::lock_guard thread_lock{*_updateMutex};
|
||||
|
||||
std::stop_source stop_source;
|
||||
std::stop_source stop_source;
|
||||
|
||||
*_isDataUpdated = false;
|
||||
*_isDataUpdated = false;
|
||||
|
||||
std::future<error_t> update_ft = std::async(std::launch::async, _updateFunc, stop_source.get_token());
|
||||
// std::future<error_t> update_ft =
|
||||
// std::async(std::launch::async, _updateFunc, _internalUpdatingStopSource.get_token());
|
||||
auto status = update_ft.wait_for(timeout);
|
||||
std::future<error_t> update_ft = std::async(std::launch::async, _updateFunc, stop_source.get_token());
|
||||
// std::future<error_t> update_ft =
|
||||
// std::async(std::launch::async, _updateFunc, _internalUpdatingStopSource.get_token());
|
||||
auto status = update_ft.wait_for(timeout);
|
||||
|
||||
if (status == std::future_status::ready) {
|
||||
*_isDataUpdated = true;
|
||||
_lastUpdateError = update_ft.get();
|
||||
} else if (status == std::future_status::deferred) { // std::async was invoked in this thread, get result
|
||||
_lastUpdateError = update_ft.get();
|
||||
if (!_lastUpdateError) {
|
||||
if (status == std::future_status::ready) {
|
||||
*_isDataUpdated = true;
|
||||
_lastUpdateError = update_ft.get();
|
||||
} else if (status == std::future_status::deferred) { // std::async was invoked in this thread, get result
|
||||
_lastUpdateError = update_ft.get();
|
||||
if (!_lastUpdateError) {
|
||||
*_isDataUpdated = true;
|
||||
}
|
||||
} else { // timeout
|
||||
stop_source.request_stop();
|
||||
_lastUpdateError = MccTelemetryErrorCode::ERROR_DATA_TIMEOUT;
|
||||
}
|
||||
} else { // timeout
|
||||
stop_source.request_stop();
|
||||
_lastUpdateError = MccTelemetryErrorCode::ERROR_DATA_TIMEOUT;
|
||||
}
|
||||
|
||||
// unblock waiting threads even in the case of timeout!
|
||||
@ -631,7 +580,7 @@ public:
|
||||
|
||||
std::unique_lock ulock(*_updateMutex);
|
||||
|
||||
auto res = _updateCondVar->wait_for(ulock, timeout, [this]() -> bool { return _isDataUpdated.get(); });
|
||||
auto res = _updateCondVar->wait_for(ulock, timeout, [this]() -> bool { return *_isDataUpdated; });
|
||||
if (!res) {
|
||||
return MccTelemetryErrorCode::ERROR_DATA_TIMEOUT;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user