From 90ddb543718e9a0b07ef33e0560885522723f2e5 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 14 Apr 2025 09:13:44 +0100 Subject: [PATCH] ChannelWebAPIUtils: Add double version of patchDeviceSetting. Fix #2428 --- sdrbase/channel/channelwebapiutils.cpp | 57 ++++++++++++++++++++++++++ sdrbase/channel/channelwebapiutils.h | 1 + 2 files changed, 58 insertions(+) diff --git a/sdrbase/channel/channelwebapiutils.cpp b/sdrbase/channel/channelwebapiutils.cpp index e5e09ee0a..73743a354 100644 --- a/sdrbase/channel/channelwebapiutils.cpp +++ b/sdrbase/channel/channelwebapiutils.cpp @@ -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) { diff --git a/sdrbase/channel/channelwebapiutils.h b/sdrbase/channel/channelwebapiutils.h index be11eb02b..d22773aa5 100644 --- a/sdrbase/channel/channelwebapiutils.h +++ b/sdrbase/channel/channelwebapiutils.h @@ -96,6 +96,7 @@ public: static bool getDeviceReportList(unsigned int deviceIndex, const QString &key, const QString &subKey, QList &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);