...
This commit is contained in:
parent
b2c27a6f5c
commit
e529265a63
@ -255,11 +255,11 @@ Asibfm700Mount::error_t Asibfm700Mount::initMount()
|
||||
|
||||
setStateERFA(std::move(ccte_state));
|
||||
|
||||
setTelemetryDataUpdateInterval(_mountConfig.hardwarePollingPeriod());
|
||||
// setTelemetryDataUpdateInterval(_mountConfig.hardwarePollingPeriod());
|
||||
setTelemetryUpdateTimeout(_mountConfig.movingModelParams().telemetryTimeout);
|
||||
startInternalTelemetryDataUpdating();
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
bool ok = isInternalTelemetryDataUpdating();
|
||||
if (ok) {
|
||||
|
||||
@ -1100,7 +1100,8 @@ protected:
|
||||
} else if (input_msg.withKey(MCC_COMMPROTO_KEYWORD_TELEMETRY_STR)) {
|
||||
MccTelemetryData tdata;
|
||||
|
||||
auto t_err = mount_ptr->telemetryData(&tdata);
|
||||
// auto t_err = mount_ptr->telemetryData(&tdata);
|
||||
auto t_err = mount_ptr->waitForTelemetryData(&tdata);
|
||||
if (t_err) {
|
||||
err = mcc_deduce_error_code(t_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_GET_TELEMETRY);
|
||||
} else {
|
||||
@ -1150,7 +1151,8 @@ protected:
|
||||
{
|
||||
MccTelemetryData tdata;
|
||||
|
||||
auto t_err = mount.telemetryData(&tdata);
|
||||
auto t_err = mount.waitForTelemetryData(&tdata);
|
||||
// auto t_err = mount.telemetryData(&tdata);
|
||||
if (t_err) {
|
||||
return mcc_deduce_error_code(t_err, MccGenericMountNetworkServerErrorCode::ERROR_MOUNT_GET_TELEMETRY);
|
||||
}
|
||||
|
||||
@ -50,7 +50,10 @@ namespace mcc
|
||||
struct MccTelemetryCategory : public std::error_category {
|
||||
MccTelemetryCategory() : std::error_category() {}
|
||||
|
||||
const char* name() const noexcept { return "MCC-TELEMETRY"; }
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "MCC-TELEMETRY";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
{
|
||||
@ -104,6 +107,8 @@ public:
|
||||
static constexpr auto defaultUpdateInterval = std::chrono::milliseconds(100);
|
||||
static constexpr auto defaultInternalUpdateTimeout = defaultUpdateInterval * 5;
|
||||
|
||||
static constexpr auto defaultUpdatingTimeout = std::chrono::milliseconds(500);
|
||||
|
||||
typedef std::error_code error_t;
|
||||
|
||||
|
||||
@ -396,16 +401,25 @@ public:
|
||||
|
||||
|
||||
// update thread
|
||||
_internalUpdatingStopSource = std::stop_source{};
|
||||
*_internalUpdating = false;
|
||||
|
||||
_dataUpdatingRequested->clear();
|
||||
_dataUpdatingStart->clear();
|
||||
|
||||
_updatingFuture = std::async(
|
||||
std::launch::async,
|
||||
[this](std::stop_token stoken) {
|
||||
while (!stoken.stop_requested()) {
|
||||
[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);
|
||||
|
||||
if (!stoken.stop_requested()) {
|
||||
stop_flag = stoken.stop_requested();
|
||||
if (!stop_flag) {
|
||||
// if (!stoken.stop_requested()) {
|
||||
*_internalUpdating = true;
|
||||
std::lock_guard lock{*_timeoutMutex};
|
||||
|
||||
_dataUpdatingStart->test_and_set();
|
||||
@ -473,7 +487,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
auto getTelemetryUpdateTimeout() const { return _currentUpdateTimeout; }
|
||||
auto getTelemetryUpdateTimeout() const
|
||||
{
|
||||
return _currentUpdateTimeout;
|
||||
}
|
||||
|
||||
// asynchronuosly periodicaly update telemetry data (internal synchronization)
|
||||
void startInternalTelemetryDataUpdating()
|
||||
@ -508,10 +525,16 @@ public:
|
||||
|
||||
void stopInternalTelemetryDataUpdating()
|
||||
{
|
||||
// reset all possible locks
|
||||
_internalUpdatingStopSource.request_stop();
|
||||
|
||||
_dataUpdatingRequested->test_and_set();
|
||||
_dataUpdatingRequested->notify_one();
|
||||
|
||||
_dataUpdatingStart->test_and_set();
|
||||
_dataUpdatingStart->notify_all();
|
||||
|
||||
|
||||
auto status = _updatingFuture.wait_for(std::chrono::milliseconds(500));
|
||||
if (status == std::future_status::ready) { // OK!
|
||||
|
||||
@ -522,12 +545,16 @@ public:
|
||||
}
|
||||
|
||||
_dataUpdatingRequested->clear();
|
||||
_dataUpdatingStart->clear();
|
||||
|
||||
*_internalUpdating = false;
|
||||
}
|
||||
|
||||
|
||||
bool isInternalTelemetryDataUpdating() const { return *_internalUpdating; }
|
||||
bool isInternalTelemetryDataUpdating() const
|
||||
{
|
||||
return *_internalUpdating;
|
||||
}
|
||||
|
||||
|
||||
error_t updateTelemetryData(traits::mcc_time_duration_c auto const& timeout)
|
||||
@ -548,7 +575,9 @@ public:
|
||||
}
|
||||
|
||||
// block the thread and wait for data to be ready (internal synchronization)
|
||||
error_t waitForTelemetryData(mcc_telemetry_data_c auto* tdata, traits::mcc_time_duration_c auto const& timeout)
|
||||
template <traits::mcc_time_duration_c DT = decltype(MccTelemetry::defaultUpdatingTimeout)>
|
||||
error_t waitForTelemetryData(mcc_telemetry_data_c auto* tdata,
|
||||
const DT& timeout = MccTelemetry::defaultUpdatingTimeout)
|
||||
{
|
||||
if (tdata == nullptr) {
|
||||
return MccTelemetryErrorCode::ERROR_NULLPTR;
|
||||
@ -580,7 +609,10 @@ public:
|
||||
return MccTelemetryErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
error_t lastUpdateError() const { return _lastUpdateError; }
|
||||
error_t lastUpdateError() const
|
||||
{
|
||||
return _lastUpdateError;
|
||||
}
|
||||
|
||||
error_t setPointingTarget(mcc_celestial_point_c auto pt)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user