1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00

Add Web API wrappers to get map date and time and a device report

This commit is contained in:
Jon Beniston 2022-02-04 18:21:56 +00:00
parent 613a5b0f1d
commit 70c99d54c7
4 changed files with 105 additions and 2 deletions

View File

@ -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<DeviceSet*> 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<DeviceSet*> 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;

View File

@ -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);

View File

@ -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<FeatureSet*>& featureSets = MainCore::instance()->getFeatureeSets();

View File

@ -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);