...
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <condition_variable>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <stop_token>
|
||||
#include <thread>
|
||||
|
||||
#include "mcc_defaults.h"
|
||||
@@ -150,7 +151,7 @@ public:
|
||||
MccCelestialPoint hw_cp{.pair_kind = MccCoordPairKind::COORDS_KIND_XY};
|
||||
mcc_tp2tp(_data.time_point, hw_cp.time_point);
|
||||
|
||||
if (hw_coords) { // compute corresponded apparent coordinates
|
||||
if (hw_coords) { // compute corresponded observed coordinates
|
||||
hw_cp.X = _data.target.X;
|
||||
hw_cp.Y = _data.target.Y;
|
||||
|
||||
@@ -318,6 +319,7 @@ public:
|
||||
MccCelestialPoint pt{.pair_kind = MccCoordPairKind::COORDS_KIND_AZALT, .time_point = _data.time_point};
|
||||
|
||||
if constexpr (mccIsEquatorialMount(pcm_t::mountType)) {
|
||||
// NOTE: now it are OBSERVED (NOT APPARENT) RA, HA, DEC!!!
|
||||
_data.RA_APP =
|
||||
MccAngle((double)_data.LST - (double)_data.HA - eo).normalize<MccAngle::NORM_KIND_0_360>();
|
||||
// MccAngle((double)_data.LST - (double)_data.HA + eo).normalize<MccAngle::NORM_KIND_0_360>();
|
||||
@@ -367,18 +369,32 @@ public:
|
||||
|
||||
ccte_err = controls->refractionCorrection(_data, &_data.refCorr);
|
||||
if (!ccte_err) {
|
||||
// // compute APPARENT RA, HA and DEC from observer AZ, ZD
|
||||
// _data.Y += _data.refCorr; // zenithal distance corrected for the refraction
|
||||
|
||||
// pt.pair_kind = MccCoordPairKind::COORDS_KIND_HADEC_APP;
|
||||
|
||||
// ccte_err = controls->transformCoordinates(_data, &pt);
|
||||
// if (!ccte_err) {
|
||||
// _data.HA = pt.X;
|
||||
// _data.DEC_APP = pt.Y;
|
||||
// _data.RA_APP =
|
||||
// MccAngle((double)_data.LST - (double)_data.HA -
|
||||
// eo).normalize<MccAngle::NORM_KIND_0_360>();
|
||||
|
||||
|
||||
// restore hardware encoders coordinates
|
||||
_data.X = (double)hw_pos.X;
|
||||
_data.Y = (double)hw_pos.Y;
|
||||
|
||||
// update target (assuming target ICRS coordinates are already set)
|
||||
|
||||
// auto ret = _updateTargetFunc(false, stop_token);
|
||||
|
||||
// update target according to its .pair_kind!
|
||||
auto ret = _updateTargetFunc(stop_token);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,32 +423,35 @@ public:
|
||||
_dataUpdatingRequested->clear();
|
||||
_dataUpdatingStart->clear();
|
||||
|
||||
_updatingFuture = std::async(
|
||||
std::launch::async,
|
||||
[controls, this](std::stop_token stoken) {
|
||||
bool stop_flag = stoken.stop_requested();
|
||||
// controls->logTrace(std::format("stop_requested() = {}", stop_flag));
|
||||
// while (!stoken.stop_requested()) {
|
||||
while (!stop_flag) {
|
||||
_dataUpdatingRequested->wait(false);
|
||||
_updatingFuture =
|
||||
std::async(std::launch::async, &MccTelemetry::updateLoop, this, _internalUpdatingStopSource.get_token());
|
||||
|
||||
stop_flag = stoken.stop_requested();
|
||||
if (!stop_flag) {
|
||||
// if (!stoken.stop_requested()) {
|
||||
*_internalUpdating = true;
|
||||
std::lock_guard lock{*_timeoutMutex};
|
||||
// _updatingFuture = std::async(
|
||||
// std::launch::async,
|
||||
// [controls, this](std::stop_token stoken) {
|
||||
// bool stop_flag = stoken.stop_requested();
|
||||
// // controls->logTrace(std::format("stop_requested() = {}", stop_flag));
|
||||
// // while (!stoken.stop_requested()) {
|
||||
// while (!stop_flag) {
|
||||
// _dataUpdatingRequested->wait(false);
|
||||
|
||||
_dataUpdatingStart->test_and_set();
|
||||
_dataUpdatingStart->notify_all();
|
||||
// stop_flag = stoken.stop_requested();
|
||||
// if (!stop_flag) {
|
||||
// // if (!stoken.stop_requested()) {
|
||||
// *_internalUpdating = true;
|
||||
// std::lock_guard lock{*_timeoutMutex};
|
||||
|
||||
_lastUpdateError = _updateFunc(stoken);
|
||||
// _dataUpdatingStart->test_and_set();
|
||||
// _dataUpdatingStart->notify_all();
|
||||
|
||||
_dataUpdatingStart->clear();
|
||||
_dataUpdatingRequested->clear();
|
||||
}
|
||||
}
|
||||
},
|
||||
_internalUpdatingStopSource.get_token());
|
||||
// _lastUpdateError = _updateFunc(stoken);
|
||||
|
||||
// _dataUpdatingStart->clear();
|
||||
// _dataUpdatingRequested->clear();
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// _internalUpdatingStopSource.get_token());
|
||||
}
|
||||
|
||||
|
||||
@@ -511,11 +530,14 @@ public:
|
||||
_lastUpdateError = MccTelemetryErrorCode::ERROR_UPDATE_LOOP_WAIT;
|
||||
}
|
||||
|
||||
startInternalTelemetryDataUpdating();
|
||||
_updatingFuture = std::async(std::launch::async, &MccTelemetry::updateLoop, this,
|
||||
_internalUpdatingStopSource.get_token());
|
||||
|
||||
|
||||
*_internalUpdating = true;
|
||||
} else {
|
||||
startInternalTelemetryDataUpdating();
|
||||
_updatingFuture = std::async(std::launch::async, &MccTelemetry::updateLoop, this,
|
||||
_internalUpdatingStopSource.get_token());
|
||||
|
||||
*_internalUpdating = true;
|
||||
}
|
||||
@@ -728,6 +750,31 @@ protected:
|
||||
std::unique_ptr<std::timed_mutex> _timeoutMutex{new std::timed_mutex()};
|
||||
|
||||
error_t _lastUpdateError{MccTelemetryErrorCode::ERROR_OK};
|
||||
|
||||
void updateLoop(std::stop_token stoken)
|
||||
{
|
||||
bool stop_flag = stoken.stop_requested();
|
||||
// controls->logTrace(std::format("stop_requested() = {}", stop_flag));
|
||||
while (!stoken.stop_requested()) {
|
||||
// while (!stop_flag) {
|
||||
_dataUpdatingRequested->wait(false);
|
||||
|
||||
// stop_flag = stoken.stop_requested();
|
||||
// if (!stop_flag) {
|
||||
if (!stoken.stop_requested()) {
|
||||
*_internalUpdating = true;
|
||||
std::lock_guard lock{*_timeoutMutex};
|
||||
|
||||
_dataUpdatingStart->test_and_set();
|
||||
_dataUpdatingStart->notify_all();
|
||||
|
||||
_lastUpdateError = _updateFunc(stoken);
|
||||
|
||||
_dataUpdatingStart->clear();
|
||||
_dataUpdatingRequested->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user