diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.cpp b/sdrdaemon/channel/sdrdaemonchannelsink.cpp index 62d6c5d8d..730572525 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsink.cpp +++ b/sdrdaemon/channel/sdrdaemonchannelsink.cpp @@ -25,6 +25,8 @@ #include #include +#include "SWGChannelSettings.h" + #include "util/simpleserializer.h" #include "dsp/threadedbasebandsamplesink.h" #include "dsp/downchannelizer.h" @@ -312,3 +314,63 @@ void SDRDaemonChannelSink::applySettings(const SDRDaemonChannelSinkSettings& set m_settings = settings; } + +int SDRDaemonChannelSink::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage __attribute__((unused))) +{ + response.setSdrDaemonChannelSinkSettings(new SWGSDRangel::SWGSDRDaemonChannelSinkSettings()); + response.getSdrDaemonChannelSinkSettings()->init(); + webapiFormatChannelSettings(response, m_settings); + return 200; +} + +int SDRDaemonChannelSink::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage __attribute__((unused))) +{ + SDRDaemonChannelSinkSettings settings = m_settings; + + if (channelSettingsKeys.contains("nbFECBlocks")) { + settings.m_nbFECBlocks = response.getSdrDaemonChannelSinkSettings()->getNbFecBlocks(); + } + if (channelSettingsKeys.contains("txDelay")) { + settings.m_txDelay = response.getSdrDaemonChannelSinkSettings()->getTxDelay(); + } + if (channelSettingsKeys.contains("dataAddress")) { + settings.m_dataAddress = *response.getSdrDaemonChannelSinkSettings()->getDataAddress(); + } + if (channelSettingsKeys.contains("dataPort")) { + settings.m_dataPort = response.getSdrDaemonChannelSinkSettings()->getDataPort(); + } + + MsgConfigureSDRDaemonChannelSink *msg = MsgConfigureSDRDaemonChannelSink::create(settings, force); + m_inputMessageQueue.push(msg); + + qDebug("SDRDaemonChannelSink::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue); + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigureSDRDaemonChannelSink *msgToGUI = MsgConfigureSDRDaemonChannelSink::create(settings, force); + m_guiMessageQueue->push(msgToGUI); + } + + webapiFormatChannelSettings(response, settings); + + return 200; +} + +void SDRDaemonChannelSink::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const SDRDaemonChannelSinkSettings& settings) +{ + response.getSdrDaemonChannelSinkSettings()->setNbFecBlocks(settings.m_nbFECBlocks); + response.getSdrDaemonChannelSinkSettings()->setTxDelay(settings.m_txDelay); + + if (response.getSdrDaemonChannelSinkSettings()->getDataAddress()) { + *response.getSdrDaemonChannelSinkSettings()->getDataAddress() = settings.m_dataAddress; + } else { + response.getSdrDaemonChannelSinkSettings()->setDataAddress(new QString(settings.m_dataAddress)); + } + + response.getSdrDaemonChannelSinkSettings()->setDataPort(settings.m_dataPort); +} diff --git a/sdrdaemon/channel/sdrdaemonchannelsink.h b/sdrdaemon/channel/sdrdaemonchannelsink.h index 06b8ebbe4..2bf2cd754 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsink.h +++ b/sdrdaemon/channel/sdrdaemonchannelsink.h @@ -80,6 +80,16 @@ public: virtual QByteArray serialize() const; virtual bool deserialize(const QByteArray& data); + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + /** Set center frequency given in Hz */ void setCenterFrequency(uint64_t centerFrequency) { m_centerFrequency = centerFrequency / 1000; } @@ -123,6 +133,7 @@ private: uint16_t m_dataPort; void applySettings(const SDRDaemonChannelSinkSettings& settings, bool force = false); + void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const SDRDaemonChannelSinkSettings& settings); }; #endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ */ diff --git a/sdrdaemon/webapi/webapiadapterdaemon.cpp b/sdrdaemon/webapi/webapiadapterdaemon.cpp index 2eae164f2..c89704648 100644 --- a/sdrdaemon/webapi/webapiadapterdaemon.cpp +++ b/sdrdaemon/webapi/webapiadapterdaemon.cpp @@ -31,6 +31,8 @@ #include "dsp/dspdevicesinkengine.h" #include "device/devicesourceapi.h" #include "device/devicesinkapi.h" +#include "channel/channelsourceapi.h" +#include "channel/channelsinkapi.h" #include "dsp/devicesamplesink.h" #include "dsp/devicesamplesource.h" #include "webapiadapterdaemon.h" @@ -181,8 +183,46 @@ int WebAPIAdapterDaemon::daemonChannelSettingsGet( SWGSDRangel::SWGErrorResponse& error) { error.init(); - *error.getMessage() = "Not implemented"; - return 501; + + if (m_sdrDaemonMain.m_deviceSourceEngine) // Rx + { + ChannelSinkAPI *channelAPI = m_sdrDaemonMain.m_deviceSourceAPI->getChanelAPIAt(0); + + if (channelAPI == 0) + { + *error.getMessage() = QString("There is no channel"); + return 500; // a SDRDaemon sink channel should have been created so this is a server error + } + else + { + response.setChannelType(new QString()); + channelAPI->getIdentifier(*response.getChannelType()); + response.setTx(0); + return channelAPI->webapiSettingsGet(response, *error.getMessage()); + } + } + else if (m_sdrDaemonMain.m_deviceSinkEngine) // Tx + { + ChannelSourceAPI *channelAPI = m_sdrDaemonMain.m_deviceSinkAPI->getChanelAPIAt(0); + + if (channelAPI == 0) + { + *error.getMessage() = QString("There is no channel"); + return 500; // a SDRDaemon source channel should have been created so this is a server error + } + else + { + response.setChannelType(new QString()); + channelAPI->getIdentifier(*response.getChannelType()); + response.setTx(1); + return channelAPI->webapiSettingsGet(response, *error.getMessage()); + } + } + else + { + *error.getMessage() = QString("Device not created error"); + return 500; + } } int WebAPIAdapterDaemon::daemonChannelSettingsPutPatch( @@ -192,8 +232,62 @@ int WebAPIAdapterDaemon::daemonChannelSettingsPutPatch( SWGSDRangel::SWGErrorResponse& error) { error.init(); - *error.getMessage() = "Not implemented"; - return 501; + + if (m_sdrDaemonMain.m_deviceSourceEngine) // Rx + { + ChannelSinkAPI *channelAPI = m_sdrDaemonMain.m_deviceSourceAPI->getChanelAPIAt(0); + + if (channelAPI == 0) + { + *error.getMessage() = QString("There is no channel"); + return 500; + } + else + { + QString channelType; + channelAPI->getIdentifier(channelType); + + if (channelType == *response.getChannelType()) + { + return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage()); + } + else + { + *error.getMessage() = QString("Channel has wrong type. Found %1.").arg(channelType); + return 500; + } + } + } + else if (m_sdrDaemonMain.m_deviceSinkEngine) // Tx + { + ChannelSourceAPI *channelAPI = m_sdrDaemonMain.m_deviceSinkAPI->getChanelAPIAt(0); + + if (channelAPI == 0) + { + *error.getMessage() = QString("There is no channel"); + return 500; + } + else + { + QString channelType; + channelAPI->getIdentifier(channelType); + + if (channelType == *response.getChannelType()) + { + return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage()); + } + else + { + *error.getMessage() = QString("Channel has wrong type. Found %3.").arg(channelType); + return 500; + } + } + } + else + { + *error.getMessage() = QString("DeviceSet error"); + return 500; + } } int WebAPIAdapterDaemon::daemonDeviceSettingsGet(