From 3524e5856bfc9c1b6b1c992861066f4d8b28be98 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Wed, 28 Jul 2021 14:10:23 +0100 Subject: [PATCH] Satellite Tracker: Ensure LOS is signalled if new AOS is calculated within a second of LOS --- .../satellitetracker/satellitetracker.cpp | 16 +++++ .../satellitetracker/satellitetracker.h | 3 + .../satellitetracker/satellitetrackergui.cpp | 8 +-- .../satellitetrackerworker.cpp | 65 +++++-------------- .../satellitetracker/satellitetrackerworker.h | 6 +- 5 files changed, 40 insertions(+), 58 deletions(-) diff --git a/plugins/feature/satellitetracker/satellitetracker.cpp b/plugins/feature/satellitetracker/satellitetracker.cpp index c382e372b..5ee6b268b 100644 --- a/plugins/feature/satellitetracker/satellitetracker.cpp +++ b/plugins/feature/satellitetracker/satellitetracker.cpp @@ -990,3 +990,19 @@ void SatelliteTracker::updateSatData() else qDebug() << "SatelliteTracker::updateSatData: update in progress"; } + +// Redirect requests for current time via these methods, so it can be adjusted when testing + +QDateTime SatelliteTracker::currentDateTimeUtc() +{ + QDateTime now = QDateTime::currentDateTimeUtc(); + //now = now.addSecs(26*60); + return now; +} + +QDateTime SatelliteTracker::currentDateTime() +{ + QDateTime now = QDateTime::currentDateTime(); + //now = now.addSecs(26*60); + return now; +} diff --git a/plugins/feature/satellitetracker/satellitetracker.h b/plugins/feature/satellitetracker/satellitetracker.h index 4309f3805..b952fddfb 100644 --- a/plugins/feature/satellitetracker/satellitetracker.h +++ b/plugins/feature/satellitetracker/satellitetracker.h @@ -153,6 +153,9 @@ public: const QStringList& featureSettingsKeys, SWGSDRangel::SWGFeatureSettings& response); + static QDateTime currentDateTimeUtc(); + static QDateTime currentDateTime(); + static const char* const m_featureIdURI; static const char* const m_featureId; diff --git a/plugins/feature/satellitetracker/satellitetrackergui.cpp b/plugins/feature/satellitetracker/satellitetrackergui.cpp index a9de7f70a..c56c747fd 100644 --- a/plugins/feature/satellitetracker/satellitetrackergui.cpp +++ b/plugins/feature/satellitetracker/satellitetrackergui.cpp @@ -263,7 +263,7 @@ SatelliteTrackerGUI::SatelliteTrackerGUI(PluginAPI* pluginAPI, FeatureUISet *fea ui->passChart->setChart(&m_emptyChart); ui->passChart->setRenderHint(QPainter::Antialiasing); - ui->dateTime->setDateTime(QDateTime::currentDateTime()); + ui->dateTime->setDateTime(SatelliteTracker::currentDateTime()); // Use My Position from preferences, if none set if ((m_settings.m_latitude == 0.0) && (m_settings.m_longitude == 0.0)) @@ -595,7 +595,7 @@ void SatelliteTrackerGUI::updateTimeToAOS() ui->aos->setText("Now"); else if (m_nextTargetAOS.isValid()) { - QDateTime currentTime = QDateTime::currentDateTime(); + QDateTime currentTime = SatelliteTracker::currentDateTime(); int secondsToAOS = m_nextTargetAOS.toSecsSinceEpoch() - currentTime.toSecsSinceEpoch(); if (secondsToAOS > 0) { @@ -824,7 +824,7 @@ void SatelliteTrackerGUI::plotPolarChart() QDateTime currentTime; if (m_settings.m_dateTime == "") - currentTime = QDateTime::currentDateTimeUtc(); + currentTime = SatelliteTracker::currentDateTimeUtc(); else if (m_settings.m_utc) currentTime = QDateTime::fromString(m_settings.m_dateTime, Qt::ISODateWithMs); else @@ -854,7 +854,7 @@ void SatelliteTrackerGUI::plotPolarChart() // Possibly geostationary, just plot current position QDateTime currentTime; if (m_settings.m_dateTime == "") - currentTime = QDateTime::currentDateTimeUtc(); + currentTime = SatelliteTracker::currentDateTimeUtc(); else if (m_settings.m_utc) currentTime = QDateTime::fromString(m_settings.m_dateTime, Qt::ISODateWithMs); else diff --git a/plugins/feature/satellitetracker/satellitetrackerworker.cpp b/plugins/feature/satellitetracker/satellitetrackerworker.cpp index eb342cf55..16695cb75 100644 --- a/plugins/feature/satellitetracker/satellitetrackerworker.cpp +++ b/plugins/feature/satellitetracker/satellitetrackerworker.cpp @@ -283,7 +283,7 @@ void SatelliteTrackerWorker::update() // Get date and time to calculate position at QDateTime qdt; if (m_settings.m_dateTime == "") - qdt = QDateTime::currentDateTimeUtc(); + qdt = SatelliteTracker::currentDateTimeUtc(); else if (m_settings.m_utc) qdt = QDateTime::fromString(m_settings.m_dateTime, Qt::ISODateWithMs); else @@ -316,54 +316,11 @@ void SatelliteTrackerWorker::update() // Update AOS/LOS (only set timers if using real time) if ((m_settings.m_dateTime == "") && (satWorkerState->m_satState.m_passes.size() > 0)) { - /*int min = 8; - QDateTime p1a = QDateTime(QDateTime::currentDateTime().date(), QTime(16, min, 0)); - QDateTime p1s = QDateTime(QDateTime::currentDateTime().date(), QTime(16, min, 30)); - - QDateTime p2a = QDateTime(QDateTime::currentDateTime().date(), QTime(16, min+1, 0)); - QDateTime p2s = QDateTime(QDateTime::currentDateTime().date(), QTime(16, min+1, 30)); - - if (qdt > p1a) - { - satWorkerState->m_satState.m_passes[0]->m_aos = p2a; - satWorkerState->m_satState.m_passes[0]->m_los = p2s; - } - else - { - satWorkerState->m_satState.m_passes[0]->m_aos = p1a; - satWorkerState->m_satState.m_passes[0]->m_los = p1s; - } */ - - - /* if (name == "NOAA 18") - { - satWorkerState->m_satState.m_passes[0]->m_aos = QDateTime(QDateTime::currentDateTime().date(), QTime(11, 10, 0)); - satWorkerState->m_satState.m_passes[0]->m_los = QDateTime(QDateTime::currentDateTime().date(), QTime(11, 10, 30)); - } */ - - - /*if (name == "ISS") - { - if (m_settings.m_minAOSElevation == 5) - { - qDebug() << "*********** seting first AOS"; - satWorkerState->m_satState.m_passes[0]->m_aos = QDateTime(QDateTime::currentDateTime().date(), QTime(14, 10, 0)); - satWorkerState->m_satState.m_passes[0]->m_los = QDateTime(QDateTime::currentDateTime().date(), QTime(14, 10, 30)); - } - else - { - qDebug() << "*********** seting second AOS"; - satWorkerState->m_satState.m_passes[0]->m_aos = QDateTime(QDateTime::currentDateTime().date(), QTime(14, 11, 0)); - satWorkerState->m_satState.m_passes[0]->m_los = QDateTime(QDateTime::currentDateTime().date(), QTime(14, 11, 30)); - } - }*/ - - // Do we have a new AOS? if ((satWorkerState->m_aos != satWorkerState->m_satState.m_passes[0]->m_aos) || (satWorkerState->m_los != satWorkerState->m_satState.m_passes[0]->m_los)) { - qDebug() << "New AOS: " << name << " new: " << satWorkerState->m_satState.m_passes[0]->m_aos << " old: " << satWorkerState->m_aos; - qDebug() << "New LOS: " << name << " new: " << satWorkerState->m_satState.m_passes[0]->m_los << " old: " << satWorkerState->m_los; + qDebug() << "SatelliteTrackerWorker: New AOS: " << name << " new: " << satWorkerState->m_satState.m_passes[0]->m_aos << " old: " << satWorkerState->m_aos; + qDebug() << "SatelliteTrackerWorker: New LOS: " << name << " new: " << satWorkerState->m_satState.m_passes[0]->m_los << " old: " << satWorkerState->m_los; satWorkerState->m_aos = satWorkerState->m_satState.m_passes[0]->m_aos; satWorkerState->m_los = satWorkerState->m_satState.m_passes[0]->m_los; if (satWorkerState->m_aos.isValid()) @@ -382,10 +339,14 @@ void SatelliteTrackerWorker::update() } if (satWorkerState->m_los.isValid() && (satWorkerState->m_los > qdt)) { - if (satWorkerState->m_losTimer.isActive() && (satWorkerState->m_losTimer.remainingTime() == 0)) + if (satWorkerState->m_losTimer.isActive()) { + qDebug() << "SatelliteTrackerWorker::update m_losTimer.remainingTime: " << satWorkerState->m_losTimer.remainingTime(); + } + // We can detect a new AOS for a satellite, a little bit before the LOS has occured, presumably + // because the calculations aren't accurate to fractions of a second. Allow for 1s here + if (satWorkerState->m_losTimer.isActive() && (satWorkerState->m_losTimer.remainingTime() <= 1000)) { - qDebug() << "****** m_losTimer.remainingTime: " << satWorkerState->m_losTimer.remainingTime(); - qDebug() << "****** m_losTimer.active: " << satWorkerState->m_losTimer.isActive(); + satWorkerState->m_losTimer.stop(); // LOS hasn't been called yet - do so, before we reset timer los(satWorkerState); } @@ -844,3 +805,9 @@ void SatelliteTrackerWorker::los(SatWorkerState *satWorkerState) m_recalculatePasses = true; } + +bool SatWorkerState::hasAOS() +{ + QDateTime currentTime = SatelliteTracker::currentDateTimeUtc(); + return (m_aos <= currentTime) && (m_los > currentTime); +} diff --git a/plugins/feature/satellitetracker/satellitetrackerworker.h b/plugins/feature/satellitetracker/satellitetrackerworker.h index 9009359ba..e75a0f655 100644 --- a/plugins/feature/satellitetracker/satellitetrackerworker.h +++ b/plugins/feature/satellitetracker/satellitetrackerworker.h @@ -48,11 +48,7 @@ public: m_satState.m_name = name; } - bool hasAOS() - { - QDateTime currentTime = QDateTime::currentDateTime(); - return (m_aos <= currentTime) && (m_los > currentTime); - } + bool hasAOS(); protected: QString m_name; // Name of the satellite