From 70c99d54c754b8cc73f40d413e3b15e942729295 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Fri, 4 Feb 2022 18:21:56 +0000 Subject: [PATCH] Add Web API wrappers to get map date and time and a device report --- sdrbase/channel/channelwebapiutils.cpp | 72 +++++++++++++++++++++++++- sdrbase/channel/channelwebapiutils.h | 3 +- sdrbase/feature/featurewebapiutils.cpp | 31 +++++++++++ sdrbase/feature/featurewebapiutils.h | 1 + 4 files changed, 105 insertions(+), 2 deletions(-) diff --git a/sdrbase/channel/channelwebapiutils.cpp b/sdrbase/channel/channelwebapiutils.cpp index 58cb39c42..551f73e9b 100644 --- a/sdrbase/channel/channelwebapiutils.cpp +++ b/sdrbase/channel/channelwebapiutils.cpp @@ -23,6 +23,7 @@ #include "SWGSuccessResponse.h" #include "SWGErrorResponse.h" #include "SWGDeviceSettings.h" +#include "SWGDeviceReport.h" #include "SWGChannelSettings.h" #include "SWGDeviceSet.h" #include "SWGChannelActions.h" @@ -403,7 +404,8 @@ bool ChannelWebAPIUtils::startStopFileSinks(unsigned int deviceIndex, bool start } // Send AOS actions to all channels that support it -bool ChannelWebAPIUtils::satelliteAOS(const QString name, bool northToSouthPass) +// See also: FeatureWebAPIUtils::satelliteAOS +bool ChannelWebAPIUtils::satelliteAOS(const QString name, bool northToSouthPass, const QString &tle, QDateTime dateTime) { MainCore *mainCore = MainCore::instance(); std::vector deviceSets = mainCore->getDeviceSets(); @@ -424,6 +426,8 @@ bool ChannelWebAPIUtils::satelliteAOS(const QString name, bool northToSouthPass) aosAction->setSatelliteName(new QString(name)); aosAction->setNorthToSouthPass(northToSouthPass); + aosAction->setTle(new QString(tle)); + aosAction->setDateTime(new QString(dateTime.toString(Qt::ISODateWithMs))); aptDemodAction->setAos(aosAction); channelActions.setAptDemodActions(aptDemodAction); @@ -495,6 +499,72 @@ bool ChannelWebAPIUtils::getDeviceSetting(unsigned int deviceIndex, const QStrin } } +bool ChannelWebAPIUtils::getDeviceReportValue(unsigned int deviceIndex, const QString &key, QString &value) +{ + SWGSDRangel::SWGDeviceReport deviceReport; + QString errorResponse; + int httpRC; + DeviceSet *deviceSet; + + // Get device report + std::vector deviceSets = MainCore::instance()->getDeviceSets(); + if (deviceIndex < deviceSets.size()) + { + deviceSet = deviceSets[deviceIndex]; + if (deviceSet->m_deviceSourceEngine) + { + deviceReport.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); + deviceReport.setDirection(0); + DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); + httpRC = source->webapiReportGet(deviceReport, errorResponse); + } + else if (deviceSet->m_deviceSinkEngine) + { + deviceReport.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); + deviceReport.setDirection(1); + DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink(); + httpRC = sink->webapiReportGet(deviceReport, errorResponse); + } + else if (deviceSet->m_deviceMIMOEngine) + { + deviceReport.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); + deviceReport.setDirection(2); + DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO(); + httpRC = mimo->webapiReportGet(deviceReport, errorResponse); + } + else + { + qDebug() << "ChannelWebAPIUtils::getDeviceReportValue: unknown device type " << deviceIndex; + return false; + } + } + else + { + qDebug() << "ChannelWebAPIUtils::getDeviceReportValue: no device " << deviceIndex; + return false; + } + + if (httpRC/100 != 2) + { + qWarning("ChannelWebAPIUtils::getDeviceReportValue: get device report error %d: %s", + httpRC, qPrintable(errorResponse)); + return false; + } + + // Get value of requested key + QJsonObject *jsonObj = deviceReport.asJsonObject(); + if (WebAPIUtils::getSubObjectString(*jsonObj, key, value)) + { + // Done + return true; + } + else + { + qWarning("ChannelWebAPIUtils::getDeviceReportValue: no key %s in device report", qPrintable(key)); + return false; + } +} + bool ChannelWebAPIUtils::patchDeviceSetting(unsigned int deviceIndex, const QString &setting, int value) { SWGSDRangel::SWGDeviceSettings deviceSettingsResponse; diff --git a/sdrbase/channel/channelwebapiutils.h b/sdrbase/channel/channelwebapiutils.h index 50bbe0cbe..80639cbce 100644 --- a/sdrbase/channel/channelwebapiutils.h +++ b/sdrbase/channel/channelwebapiutils.h @@ -38,9 +38,10 @@ public: static bool getFrequencyOffset(unsigned int deviceIndex, int channelIndex, int& offset); static bool setFrequencyOffset(unsigned int deviceIndex, int channelIndex, int offset); static bool startStopFileSinks(unsigned int deviceIndex, bool start); - static bool satelliteAOS(const QString name, bool northToSouthPass); + static bool satelliteAOS(const QString name, bool northToSouthPass, const QString &tle, QDateTime dateTime); static bool satelliteLOS(const QString name); static bool getDeviceSetting(unsigned int deviceIndex, const QString &setting, int &value); + static bool getDeviceReportValue(unsigned int deviceIndex, const QString &key, QString &value); static bool patchDeviceSetting(unsigned int deviceIndex, const QString &setting, int value); static bool patchFeatureSetting(unsigned int featureSetIndex, unsigned int featureIndex, const QString &setting, const QString &value); static bool patchFeatureSetting(unsigned int featureSetIndex, unsigned int featureIndex, const QString &setting, double value); diff --git a/sdrbase/feature/featurewebapiutils.cpp b/sdrbase/feature/featurewebapiutils.cpp index 61fa02782..56141692d 100644 --- a/sdrbase/feature/featurewebapiutils.cpp +++ b/sdrbase/feature/featurewebapiutils.cpp @@ -56,6 +56,36 @@ bool FeatureWebAPIUtils::mapFind(const QString& target, int featureSetIndex, int } } +// Set the date and time the map uses for display +bool FeatureWebAPIUtils::mapSetDateTime(const QDateTime& dateTime, int featureSetIndex, int featureIndex) +{ + Feature *feature = FeatureWebAPIUtils::getFeature(featureSetIndex, featureIndex, "sdrangel.feature.map"); + if (feature != nullptr) + { + QString errorMessage; + QStringList featureActionKeys = {"setDateTime"}; + SWGSDRangel::SWGFeatureActions query; + SWGSDRangel::SWGMapActions *mapActions = new SWGSDRangel::SWGMapActions(); + + mapActions->setSetDateTime(new QString(dateTime.toString(Qt::ISODateWithMs))); + query.setMapActions(mapActions); + + int httpRC = feature->webapiActionsPost(featureActionKeys, query, errorMessage); + if (httpRC/100 != 2) + { + qWarning() << "FeatureWebAPIUtils::mapSetDateTime: error " << httpRC << ":" << errorMessage; + return false; + } + + return true; + } + else + { + qWarning("FeatureWebAPIUtils::mapSetDateTime: no Map feature"); + return false; + } +} + // Get first feature with the given URI Feature* FeatureWebAPIUtils::getFeature(int featureSetIndex, int featureIndex, const QString& uri) { @@ -102,6 +132,7 @@ Feature* FeatureWebAPIUtils::getFeature(int featureSetIndex, int featureIndex, c } // Send AOS actions to all features that support it +// See also: ChannelWebAPIUtils::satelliteAOS bool FeatureWebAPIUtils::satelliteAOS(const QString name, const QDateTime aos, const QDateTime los) { std::vector& featureSets = MainCore::instance()->getFeatureeSets(); diff --git a/sdrbase/feature/featurewebapiutils.h b/sdrbase/feature/featurewebapiutils.h index caf1d459a..c72e6342b 100644 --- a/sdrbase/feature/featurewebapiutils.h +++ b/sdrbase/feature/featurewebapiutils.h @@ -28,6 +28,7 @@ class SDRBASE_API FeatureWebAPIUtils { public: static bool mapFind(const QString& target, int featureSetIndex=-1, int featureIndex=-1); + static bool mapSetDateTime(const QDateTime& dateTime, 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);