From 8ac583f36c43102ff2064e9270d2a87c1819858f Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Wed, 7 Apr 2021 21:23:02 +0100 Subject: [PATCH] Send AOS to features. Support AOS/LOS in local time on map. --- .../satellitetrackerworker.cpp | 26 +++++++++-- sdrbase/feature/featurewebapiutils.cpp | 46 +++++++++++++++++++ sdrbase/feature/featurewebapiutils.h | 4 ++ 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/plugins/feature/satellitetracker/satellitetrackerworker.cpp b/plugins/feature/satellitetracker/satellitetrackerworker.cpp index 17e4f2426..eb342cf55 100644 --- a/plugins/feature/satellitetracker/satellitetrackerworker.cpp +++ b/plugins/feature/satellitetracker/satellitetrackerworker.cpp @@ -36,6 +36,7 @@ #include "device/deviceset.h" #include "device/deviceapi.h" #include "channel/channelwebapiutils.h" +#include "feature/featurewebapiutils.h" #include "maincore.h" #include "satellitetracker.h" @@ -460,10 +461,22 @@ void SatelliteTrackerWorker::update() text = text.append("\nSatellite is visible"); else text = text.append("\nAOS in: %1 mins").arg((int)round((satWorkerState->m_satState.m_passes[0]->m_aos.toSecsSinceEpoch() - qdt.toSecsSinceEpoch())/60.0)); + QString aosDateTime; + QString losDateTime; + if (m_settings.m_utc) + { + aosDateTime = satWorkerState->m_satState.m_passes[0]->m_aos.toString(m_settings.m_dateFormat + " hh:mm"); + losDateTime = satWorkerState->m_satState.m_passes[0]->m_los.toString(m_settings.m_dateFormat + " hh:mm"); + } + else + { + aosDateTime = satWorkerState->m_satState.m_passes[0]->m_aos.toLocalTime().toString(m_settings.m_dateFormat + " hh:mm"); + losDateTime = satWorkerState->m_satState.m_passes[0]->m_los.toLocalTime().toString(m_settings.m_dateFormat + " hh:mm"); + } text = QString("%1\nAOS: %2\nLOS: %3\nMax El: %4%5") .arg(text) - .arg(satWorkerState->m_satState.m_passes[0]->m_aos.toString(m_settings.m_dateFormat + " hh:mm")) - .arg(satWorkerState->m_satState.m_passes[0]->m_los.toString(m_settings.m_dateFormat + " hh:mm")) + .arg(aosDateTime) + .arg(losDateTime) .arg((int)round(satWorkerState->m_satState.m_passes[0]->m_maxElevation)) .arg(QChar(0xb0)); } @@ -631,9 +644,10 @@ void SatelliteTrackerWorker::applyDeviceAOSSettings(const QString& name) } } - // Send AOS message to channels + // Send AOS message to channels/features SatWorkerState *satWorkerState = m_workerState.value(name); ChannelWebAPIUtils::satelliteAOS(name, satWorkerState->m_satState.m_passes[0]->m_northToSouth); + FeatureWebAPIUtils::satelliteAOS(name, satWorkerState->m_aos, satWorkerState->m_los); // Start Doppler correction, if needed satWorkerState->m_initFrequencyOffset.clear(); @@ -690,9 +704,10 @@ void SatelliteTrackerWorker::applyDeviceAOSSettings(const QString& name) } else { - // Send AOS message to channels + // Send AOS message to channels/features SatWorkerState *satWorkerState = m_workerState.value(name); ChannelWebAPIUtils::satelliteAOS(name, satWorkerState->m_satState.m_passes[0]->m_northToSouth); + FeatureWebAPIUtils::satelliteAOS(name, satWorkerState->m_aos, satWorkerState->m_los); } } @@ -775,8 +790,9 @@ void SatelliteTrackerWorker::los(SatWorkerState *satWorkerState) } } - // Send LOS message to channels + // Send LOS message to channels/features ChannelWebAPIUtils::satelliteLOS(satWorkerState->m_name); + FeatureWebAPIUtils::satelliteLOS(satWorkerState->m_name); // Stop acquisition for (int i = 0; i < m_deviceSettingsList->size(); i++) diff --git a/sdrbase/feature/featurewebapiutils.cpp b/sdrbase/feature/featurewebapiutils.cpp index ec8e09bd7..340e314ec 100644 --- a/sdrbase/feature/featurewebapiutils.cpp +++ b/sdrbase/feature/featurewebapiutils.cpp @@ -19,6 +19,7 @@ #include "SWGFeatureActions.h" #include "SWGMapActions.h" +#include "SWGPERTesterActions.h" #include "maincore.h" #include "feature/featureset.h" @@ -99,3 +100,48 @@ Feature* FeatureWebAPIUtils::getFeature(int featureSetIndex, int featureIndex, c return nullptr; } } + +// Send AOS actions to all features that support it +bool FeatureWebAPIUtils::satelliteAOS(const QString name, const QDateTime aos, const QDateTime los) +{ + std::vector& featureSets = MainCore::instance()->getFeatureeSets(); + + for (std::vector::const_iterator it = featureSets.begin(); it != featureSets.end(); ++it) + { + for (int fi = 0; fi < (*it)->getNumberOfFeatures(); fi++) + { + Feature *feature = (*it)->getFeatureAt(fi); + if (feature->getURI() == "sdrangel.feature.pertester") + { + QStringList featureActionKeys = {"aos"}; + SWGSDRangel::SWGFeatureActions featureActions; + SWGSDRangel::SWGPERTesterActions *perTesterFeatureAction = new SWGSDRangel::SWGPERTesterActions(); + SWGSDRangel::SWGPERTesterActions_aos *aosAction = new SWGSDRangel::SWGPERTesterActions_aos(); + QString errorResponse; + int httpRC; + + aosAction->setSatelliteName(new QString(name)); + aosAction->setAosTime(new QString(aos.toString(Qt::ISODate))); + aosAction->setLosTime(new QString(los.toString(Qt::ISODate))); + perTesterFeatureAction->setAos(aosAction); + + featureActions.setPerTesterActions(perTesterFeatureAction); + httpRC = feature->webapiActionsPost(featureActionKeys, featureActions, errorResponse); + if (httpRC/100 != 2) + { + qWarning("FeatureWebAPIUtils::satelliteAOS: webapiActionsPost error %d: %s", + httpRC, qPrintable(errorResponse)); + return false; + } + } + } + } + return true; +} + +// Send LOS actions to all features that support it +bool FeatureWebAPIUtils::satelliteLOS(const QString name) +{ + // Not currently required by any features + return true; +} diff --git a/sdrbase/feature/featurewebapiutils.h b/sdrbase/feature/featurewebapiutils.h index 808ac6665..caf1d459a 100644 --- a/sdrbase/feature/featurewebapiutils.h +++ b/sdrbase/feature/featurewebapiutils.h @@ -18,6 +18,8 @@ #ifndef SDRBASE_FEATURE_FEATUREWEBAPIUTILS_H_ #define SDRBASE_FEATURE_FEATUREWEBAPIUTILS_H_ +#include + #include "export.h" class Feature; @@ -27,6 +29,8 @@ class SDRBASE_API FeatureWebAPIUtils public: static bool mapFind(const QString& target, int featureSetIndex=-1, int featureIndex=-1); static Feature *getFeature(int featureSetIndex, int featureIndex, const QString& uri); + static bool satelliteAOS(const QString name, const QDateTime aos, const QDateTime los); + static bool satelliteLOS(const QString name); }; #endif // SDRBASE_FEATURE_FEATUREWEBAPIUTILS_H_