1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-06-13 03:52:30 -04:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Edouard Griffiths
7e6342624c
Merge pull request #2432 from srcejon/fix_2428
ChannelWebAPIUtils: Add double version of patchDeviceSetting.
2025-04-14 16:56:53 +02:00
Jon Beniston
90ddb54371 ChannelWebAPIUtils: Add double version of patchDeviceSetting. Fix #2428 2025-04-14 09:13:44 +01:00
2 changed files with 58 additions and 0 deletions

View File

@ -1354,6 +1354,63 @@ bool ChannelWebAPIUtils::patchDeviceSetting(unsigned int deviceIndex, const QStr
}
}
bool ChannelWebAPIUtils::patchDeviceSetting(unsigned int deviceIndex, const QString &setting, double value)
{
SWGSDRangel::SWGDeviceSettings deviceSettingsResponse;
QString errorResponse;
int httpRC;
DeviceSet *deviceSet;
if (getDeviceSettings(deviceIndex, deviceSettingsResponse, deviceSet))
{
// Patch setting
QJsonObject *jsonObj = deviceSettingsResponse.asJsonObject();
double oldValue;
if (WebAPIUtils::getSubObjectDouble(*jsonObj, setting, oldValue))
{
WebAPIUtils::setSubObjectDouble(*jsonObj, setting, value);
QStringList deviceSettingsKeys;
deviceSettingsKeys.append(setting);
deviceSettingsResponse.init();
deviceSettingsResponse.fromJsonObject(*jsonObj);
SWGSDRangel::SWGErrorResponse errorResponse2;
delete jsonObj;
if (DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource()) {
httpRC = source->webapiSettingsPutPatch(false, deviceSettingsKeys, deviceSettingsResponse, *errorResponse2.getMessage());
} else if (DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink()) {
httpRC = sink->webapiSettingsPutPatch(false, deviceSettingsKeys, deviceSettingsResponse, *errorResponse2.getMessage());
} else if (DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO()) {
httpRC = mimo->webapiSettingsPutPatch(false, deviceSettingsKeys, deviceSettingsResponse, *errorResponse2.getMessage());
} else {
httpRC = 404;
}
if (httpRC/100 == 2)
{
qDebug("ChannelWebAPIUtils::patchDeviceSetting: set device setting %s OK", qPrintable(setting));
return true;
}
else
{
qWarning("ChannelWebAPIUtils::patchDeviceSetting: set device setting error %d: %s",
httpRC, qPrintable(*errorResponse2.getMessage()));
return false;
}
}
else
{
delete jsonObj;
qWarning("ChannelWebAPIUtils::patchDeviceSetting: no key %s in device settings", qPrintable(setting));
return false;
}
}
else
{
return false;
}
}
// Set feature setting
bool ChannelWebAPIUtils::patchFeatureSetting(unsigned int featureSetIndex, unsigned int featureIndex, const QString &setting, const QString &value)
{

View File

@ -96,6 +96,7 @@ public:
static bool getDeviceReportList(unsigned int deviceIndex, const QString &key, const QString &subKey, QList<int> &values);
static bool getDevicePosition(unsigned int deviceIndex, float& latitude, float& longitude, float& altitude);
static bool patchDeviceSetting(unsigned int deviceIndex, const QString &setting, int value);
static bool patchDeviceSetting(unsigned int deviceIndex, const QString &setting, double value);
static bool runFeature(unsigned int featureSetIndex, unsigned int featureIndex);
static bool stopFeature(unsigned int featureSetIndex, unsigned int featureIndex);
static bool patchFeatureSetting(unsigned int featureSetIndex, unsigned int featureIndex, const QString &setting, const QString &value);