From 1d968e9efa6222a53ba5831f882ada2605571811 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 19 Aug 2018 19:58:14 +0200 Subject: [PATCH] SDRdaemon: Web API: implemented daemonSettingsPutPatch --- sdrdaemon/webapi/webapiadapterdaemon.cpp | 49 ++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/sdrdaemon/webapi/webapiadapterdaemon.cpp b/sdrdaemon/webapi/webapiadapterdaemon.cpp index b70f3bea0..35fda8ab5 100644 --- a/sdrdaemon/webapi/webapiadapterdaemon.cpp +++ b/sdrdaemon/webapi/webapiadapterdaemon.cpp @@ -202,12 +202,55 @@ int WebAPIAdapterDaemon::daemonSettingsGet( } int WebAPIAdapterDaemon::daemonSettingsPutPatch( - bool force __attribute__((unused)), - const QStringList& deviceSettingsKeys __attribute__((unused)), - SWGSDRangel::SWGDeviceSettings& response __attribute__((unused)), + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, SWGSDRangel::SWGErrorResponse& error) { error.init(); + + if (m_sdrDaemonMain.m_deviceSourceEngine) // Rx + { + if (response.getTx() != 0) + { + *error.getMessage() = QString("Rx device found but Tx device requested"); + return 400; + } + if (m_sdrDaemonMain.m_deviceSourceAPI->getHardwareId() != *response.getDeviceHwType()) + { + *error.getMessage() = QString("Device mismatch. Found %1 input").arg(m_sdrDaemonMain.m_deviceSourceAPI->getHardwareId()); + return 400; + } + else + { + DeviceSampleSource *source = m_sdrDaemonMain.m_deviceSourceAPI->getSampleSource(); + return source->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage()); + } + } + else if (m_sdrDaemonMain.m_deviceSinkEngine) // Tx + { + if (response.getTx() == 0) + { + *error.getMessage() = QString("Tx device found but Rx device requested"); + return 400; + } + else if (m_sdrDaemonMain.m_deviceSinkAPI->getHardwareId() != *response.getDeviceHwType()) + { + *error.getMessage() = QString("Device mismatch. Found %1 output").arg(m_sdrDaemonMain.m_deviceSinkAPI->getHardwareId()); + return 400; + } + else + { + DeviceSampleSink *sink = m_sdrDaemonMain.m_deviceSinkAPI->getSampleSink(); + return sink->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage()); + } + } + else + { + *error.getMessage() = QString("DeviceSet error"); + return 500; + } + *error.getMessage() = "Not implemented"; return 501; }