From 68a4e23fb0a4920be826735e41b2cc54948a1c3a Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 2 Aug 2019 18:16:37 +0200 Subject: [PATCH] REST API: config (8): preset channel Tx adapters where there is CW keyer. AM mod working only --- plugins/channeltx/modam/CMakeLists.txt | 6 +- plugins/channeltx/modam/ammodplugin.cpp | 7 +- plugins/channeltx/modam/ammodplugin.h | 1 + plugins/channeltx/modam/ammodsettings.cpp | 5 +- plugins/channeltx/modam/ammodsettings.h | 6 ++ .../channeltx/modam/ammodwebapiadapter.cpp | 66 +++++++++++++++ plugins/channeltx/modam/ammodwebapiadapter.h | 66 +++++++++++++++ plugins/channeltx/modfreedv/CMakeLists.txt | 2 + .../channeltx/modfreedv/freedvmodplugin.cpp | 8 +- plugins/channeltx/modfreedv/freedvmodplugin.h | 1 + .../modfreedv/freedvmodwebapiadapter.cpp | 81 +++++++++++++++++++ .../modfreedv/freedvmodwebapiadapter.h | 65 +++++++++++++++ plugins/channeltx/modnfm/CMakeLists.txt | 6 +- plugins/channeltx/modnfm/nfmmodplugin.cpp | 8 +- plugins/channeltx/modnfm/nfmmodplugin.h | 1 + .../channeltx/modnfm/nfmmodwebapiadapter.cpp | 81 +++++++++++++++++++ .../channeltx/modnfm/nfmmodwebapiadapter.h | 65 +++++++++++++++ plugins/channeltx/modssb/CMakeLists.txt | 2 + plugins/channeltx/modssb/ssbmodplugin.cpp | 7 +- plugins/channeltx/modssb/ssbmodplugin.h | 1 + .../channeltx/modssb/ssbmodwebapiadapter.cpp | 81 +++++++++++++++++++ .../channeltx/modssb/ssbmodwebapiadapter.h | 65 +++++++++++++++ plugins/channeltx/modwfm/CMakeLists.txt | 6 +- plugins/channeltx/modwfm/wfmmodplugin.cpp | 8 +- plugins/channeltx/modwfm/wfmmodplugin.h | 1 + .../channeltx/modwfm/wfmmodwebapiadapter.cpp | 81 +++++++++++++++++++ .../channeltx/modwfm/wfmmodwebapiadapter.h | 65 +++++++++++++++ 27 files changed, 777 insertions(+), 15 deletions(-) create mode 100644 plugins/channeltx/modam/ammodwebapiadapter.cpp create mode 100644 plugins/channeltx/modam/ammodwebapiadapter.h create mode 100644 plugins/channeltx/modfreedv/freedvmodwebapiadapter.cpp create mode 100644 plugins/channeltx/modfreedv/freedvmodwebapiadapter.h create mode 100644 plugins/channeltx/modnfm/nfmmodwebapiadapter.cpp create mode 100644 plugins/channeltx/modnfm/nfmmodwebapiadapter.h create mode 100644 plugins/channeltx/modssb/ssbmodwebapiadapter.cpp create mode 100644 plugins/channeltx/modssb/ssbmodwebapiadapter.h create mode 100644 plugins/channeltx/modwfm/wfmmodwebapiadapter.cpp create mode 100644 plugins/channeltx/modwfm/wfmmodwebapiadapter.h diff --git a/plugins/channeltx/modam/CMakeLists.txt b/plugins/channeltx/modam/CMakeLists.txt index 71a367929..c7a0efd5b 100644 --- a/plugins/channeltx/modam/CMakeLists.txt +++ b/plugins/channeltx/modam/CMakeLists.txt @@ -3,13 +3,15 @@ project(modam) set(modam_SOURCES ammod.cpp ammodplugin.cpp - ammodsettings.cpp + ammodsettings.cpp + ammodwebapiadapter.cpp ) set(modam_HEADERS ammod.h ammodplugin.h - ammodsettings.h + ammodsettings.h + ammodwebapiadapter.h ) include_directories( diff --git a/plugins/channeltx/modam/ammodplugin.cpp b/plugins/channeltx/modam/ammodplugin.cpp index 40d8dad49..3423154e3 100644 --- a/plugins/channeltx/modam/ammodplugin.cpp +++ b/plugins/channeltx/modam/ammodplugin.cpp @@ -22,11 +22,12 @@ #include "ammodgui.h" #endif #include "ammod.h" +#include "ammodwebapiadapter.h" #include "ammodplugin.h" const PluginDescriptor AMModPlugin::m_pluginDescriptor = { QString("AM Modulator"), - QString("4.11.5"), + QString("4.11.6"), QString("(c) Edouard Griffiths, F4EXB"), QString("https://github.com/f4exb/sdrangel"), true, @@ -76,3 +77,7 @@ ChannelAPI* AMModPlugin::createTxChannelCS(DeviceAPI *deviceAPI) const return new AMMod(deviceAPI); } +ChannelAPI* AMModPlugin::createChannelWebAPIAdapter() const +{ + return new AMModWebAPIAdapter(); +} diff --git a/plugins/channeltx/modam/ammodplugin.h b/plugins/channeltx/modam/ammodplugin.h index cd54992e3..ab225862d 100644 --- a/plugins/channeltx/modam/ammodplugin.h +++ b/plugins/channeltx/modam/ammodplugin.h @@ -38,6 +38,7 @@ public: virtual PluginInstanceGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const; virtual BasebandSampleSource* createTxChannelBS(DeviceAPI *deviceAPI) const; virtual ChannelAPI* createTxChannelCS(DeviceAPI *deviceAPI) const; + virtual ChannelAPI* createChannelWebAPIAdapter() const; private: static const PluginDescriptor m_pluginDescriptor; diff --git a/plugins/channeltx/modam/ammodsettings.cpp b/plugins/channeltx/modam/ammodsettings.cpp index 8ed84cb8c..4750b66d6 100644 --- a/plugins/channeltx/modam/ammodsettings.cpp +++ b/plugins/channeltx/modam/ammodsettings.cpp @@ -65,6 +65,8 @@ QByteArray AMModSettings::serialize() const if (m_cwKeyerGUI) { s.writeBlob(7, m_cwKeyerGUI->serialize()); + } else { // standalone operation with presets + s.writeBlob(7, m_cwKeyerSettings.serialize()); } if (m_channelMarker) { @@ -109,9 +111,10 @@ bool AMModSettings::deserialize(const QByteArray& data) d.readReal(4, &m_modFactor, 0.2f); d.readU32(5, &m_rgbColor); d.readReal(6, &m_volumeFactor, 1.0); + d.readBlob(7, &bytetmp); + m_cwKeyerSettings.deserialize(bytetmp); if (m_cwKeyerGUI) { - d.readBlob(7, &bytetmp); m_cwKeyerGUI->deserialize(bytetmp); } diff --git a/plugins/channeltx/modam/ammodsettings.h b/plugins/channeltx/modam/ammodsettings.h index 3b9c4cd6a..627a400da 100644 --- a/plugins/channeltx/modam/ammodsettings.h +++ b/plugins/channeltx/modam/ammodsettings.h @@ -20,6 +20,8 @@ #include +#include "dsp/cwkeyersettings.h" + class Serializable; struct AMModSettings @@ -56,12 +58,16 @@ struct AMModSettings Serializable *m_channelMarker; Serializable *m_cwKeyerGUI; + CWKeyerSettings m_cwKeyerSettings; //!< For standalone deserialize operation (without m_cwKeyerGUI) + AMModSettings(); void resetToDefaults(); void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; } void setCWKeyerGUI(Serializable *cwKeyerGUI) { m_cwKeyerGUI = cwKeyerGUI; } QByteArray serialize() const; bool deserialize(const QByteArray& data); + const CWKeyerSettings& getCWKeyerSettings() const { return m_cwKeyerSettings; } + void setCWKeyerSettings(const CWKeyerSettings& cwKeyerSettings) { m_cwKeyerSettings = cwKeyerSettings; } }; diff --git a/plugins/channeltx/modam/ammodwebapiadapter.cpp b/plugins/channeltx/modam/ammodwebapiadapter.cpp new file mode 100644 index 000000000..a640a4ddf --- /dev/null +++ b/plugins/channeltx/modam/ammodwebapiadapter.cpp @@ -0,0 +1,66 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "SWGChannelSettings.h" +#include "ammod.h" +#include "ammodwebapiadapter.h" + +AMModWebAPIAdapter::AMModWebAPIAdapter() : + ChannelAPI(AMMod::m_channelIdURI, ChannelAPI::StreamSingleSource) +{} + +AMModWebAPIAdapter::~AMModWebAPIAdapter() +{} + +int AMModWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setAmModSettings(new SWGSDRangel::SWGAMModSettings()); + response.getAmModSettings()->init(); + AMMod::webapiFormatChannelSettings(response, m_settings); + + const CWKeyerSettings& cwKeyerSettings = m_settings.getCWKeyerSettings(); + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getAmModSettings()->getCwKeyer(); + apiCwKeyerSettings->init(); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + + return 200; +} + +int AMModWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + AMMod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response); + + if (channelSettingsKeys.contains("cwKeyer")) + { + CWKeyerSettings newCWKeyerSettings; + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getAmModSettings()->getCwKeyer(); + CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, newCWKeyerSettings, apiCwKeyerSettings); + m_settings.setCWKeyerSettings(newCWKeyerSettings); + const QByteArray& serializedNewSettings = m_settings.serialize(); // effectively update CW keyer settings + } + + AMMod::webapiFormatChannelSettings(response, m_settings); + return 200; +} diff --git a/plugins/channeltx/modam/ammodwebapiadapter.h b/plugins/channeltx/modam/ammodwebapiadapter.h new file mode 100644 index 000000000..e56a01f50 --- /dev/null +++ b/plugins/channeltx/modam/ammodwebapiadapter.h @@ -0,0 +1,66 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_AMMOD_WEBAPIADAPTER_H +#define INCLUDE_AMMOD_WEBAPIADAPTER_H + +#include "channel/channelapi.h" +#include "dsp/cwkeyersettings.h" +#include "ammodsettings.h" + +/** + * Standalone API adapter only for the settings + */ +class AMModWebAPIAdapter : public ChannelAPI { +public: + AMModWebAPIAdapter(); + virtual ~AMModWebAPIAdapter(); + + // unused pure virtual methods + virtual void destroy() {} + virtual void getIdentifier(QString& id) {} + virtual void getTitle(QString& title) {} + virtual qint64 getCenterFrequency() const { return 0; } + virtual int getNbSinkStreams() const { return 1; } + virtual int getNbSourceStreams() const { return 0; } + + virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + { + (void) streamIndex; + (void) sinkElseSource; + return 0; + } + + // virtual methods actually implemented + virtual QByteArray serialize() const { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data) { m_settings.deserialize(data); } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + +private: + AMModSettings m_settings; +}; + +#endif // INCLUDE_AMMOD_WEBAPIADAPTER_H diff --git a/plugins/channeltx/modfreedv/CMakeLists.txt b/plugins/channeltx/modfreedv/CMakeLists.txt index 3609d89f4..49738672a 100644 --- a/plugins/channeltx/modfreedv/CMakeLists.txt +++ b/plugins/channeltx/modfreedv/CMakeLists.txt @@ -4,12 +4,14 @@ set(modfreedv_SOURCES freedvmod.cpp freedvmodplugin.cpp freedvmodsettings.cpp + freedvmodwebapiadapter.cpp ) set(modfreedv_HEADERS freedvmod.h freedvmodplugin.h freedvmodsettings.h + freedvmodwebapiadapter.h ) include_directories( diff --git a/plugins/channeltx/modfreedv/freedvmodplugin.cpp b/plugins/channeltx/modfreedv/freedvmodplugin.cpp index 4921101f0..b31daafa9 100644 --- a/plugins/channeltx/modfreedv/freedvmodplugin.cpp +++ b/plugins/channeltx/modfreedv/freedvmodplugin.cpp @@ -22,11 +22,12 @@ #include "freedvmodgui.h" #endif #include "freedvmod.h" +#include "freedvmodwebapiadapter.h" #include "freedvmodplugin.h" const PluginDescriptor FreeDVModPlugin::m_pluginDescriptor = { QString("FreeDV Modulator"), - QString("4.11.5"), + QString("4.11.6"), QString("(c) Edouard Griffiths, F4EXB"), QString("https://github.com/f4exb/sdrangel"), true, @@ -76,4 +77,7 @@ ChannelAPI* FreeDVModPlugin::createTxChannelCS(DeviceAPI *deviceAPI) const return new FreeDVMod(deviceAPI); } - +ChannelAPI* FreeDVModPlugin::createChannelWebAPIAdapter() const +{ + return new FreeDVModWebAPIAdapter(); +} diff --git a/plugins/channeltx/modfreedv/freedvmodplugin.h b/plugins/channeltx/modfreedv/freedvmodplugin.h index d84411bc6..30e71a0ac 100644 --- a/plugins/channeltx/modfreedv/freedvmodplugin.h +++ b/plugins/channeltx/modfreedv/freedvmodplugin.h @@ -38,6 +38,7 @@ public: virtual PluginInstanceGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const; virtual BasebandSampleSource* createTxChannelBS(DeviceAPI *deviceAPI) const; virtual ChannelAPI* createTxChannelCS(DeviceAPI *deviceAPI) const; + virtual ChannelAPI* createChannelWebAPIAdapter() const; private: static const PluginDescriptor m_pluginDescriptor; diff --git a/plugins/channeltx/modfreedv/freedvmodwebapiadapter.cpp b/plugins/channeltx/modfreedv/freedvmodwebapiadapter.cpp new file mode 100644 index 000000000..b1379ca04 --- /dev/null +++ b/plugins/channeltx/modfreedv/freedvmodwebapiadapter.cpp @@ -0,0 +1,81 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "SWGChannelSettings.h" +#include "settings/serializable.h" +#include "freedvmod.h" +#include "freedvmodwebapiadapter.h" + +FreeDVModWebAPIAdapter::FreeDVModWebAPIAdapter() : + ChannelAPI(FreeDVMod::m_channelIdURI, ChannelAPI::StreamSingleSource) +{} + +FreeDVModWebAPIAdapter::~FreeDVModWebAPIAdapter() +{} + +int FreeDVModWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setFreeDvModSettings(new SWGSDRangel::SWGFreeDVModSettings()); + response.getFreeDvModSettings()->init(); + FreeDVMod::webapiFormatChannelSettings(response, m_settings); + Serializable *cwKeyerGUI = m_settings.m_cwKeyerGUI; + + if (cwKeyerGUI) + { + const QByteArray& serializedCWKeyerSettings = cwKeyerGUI->serialize(); + CWKeyerSettings cwKeyerSettings; + + if (cwKeyerSettings.deserialize(serializedCWKeyerSettings)) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getFreeDvModSettings()->getCwKeyer(); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + } + } + + return 200; +} + +int FreeDVModWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + FreeDVMod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response); + Serializable *cwKeyerGUI = m_settings.m_cwKeyerGUI; + + if (channelSettingsKeys.contains("cwKeyer") && cwKeyerGUI) + { + const QByteArray& serializedCWKeyerSettings = cwKeyerGUI->serialize(); + CWKeyerSettings cwKeyerSettings; + + if (cwKeyerSettings.deserialize(serializedCWKeyerSettings)) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getFreeDvModSettings()->getCwKeyer(); + CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); + const QByteArray& serializedNewCWKeyerSettings = cwKeyerSettings.serialize(); + cwKeyerGUI->deserialize(serializedNewCWKeyerSettings); + } + } + + FreeDVMod::webapiFormatChannelSettings(response, m_settings); + return 200; +} diff --git a/plugins/channeltx/modfreedv/freedvmodwebapiadapter.h b/plugins/channeltx/modfreedv/freedvmodwebapiadapter.h new file mode 100644 index 000000000..7472e5ebb --- /dev/null +++ b/plugins/channeltx/modfreedv/freedvmodwebapiadapter.h @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_FREEDVMOD_WEBAPIADAPTER_H +#define INCLUDE_FREEDVMOD_WEBAPIADAPTER_H + +#include "channel/channelapi.h" +#include "freedvmodsettings.h" + +/** + * Standalone API adapter only for the settings + */ +class FreeDVModWebAPIAdapter : public ChannelAPI { +public: + FreeDVModWebAPIAdapter(); + virtual ~FreeDVModWebAPIAdapter(); + + // unused pure virtual methods + virtual void destroy() {} + virtual void getIdentifier(QString& id) {} + virtual void getTitle(QString& title) {} + virtual qint64 getCenterFrequency() const { return 0; } + virtual int getNbSinkStreams() const { return 1; } + virtual int getNbSourceStreams() const { return 0; } + + virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + { + (void) streamIndex; + (void) sinkElseSource; + return 0; + } + + // virtual methods actually implemented + virtual QByteArray serialize() const { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data) { m_settings.deserialize(data); } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + +private: + FreeDVModSettings m_settings; +}; + +#endif // INCLUDE_FREEDVMOD_WEBAPIADAPTER_H diff --git a/plugins/channeltx/modnfm/CMakeLists.txt b/plugins/channeltx/modnfm/CMakeLists.txt index 0dac385e3..6281c05d4 100644 --- a/plugins/channeltx/modnfm/CMakeLists.txt +++ b/plugins/channeltx/modnfm/CMakeLists.txt @@ -3,13 +3,15 @@ project(modnfm) set(modnfm_SOURCES nfmmod.cpp nfmmodplugin.cpp - nfmmodsettings.cpp + nfmmodsettings.cpp + nfmmodwebapiadapter.cpp ) set(modnfm_HEADERS nfmmod.h nfmmodplugin.h - nfmmodsettings.h + nfmmodsettings.h + nfmmodwebapiadapter.h ) include_directories( diff --git a/plugins/channeltx/modnfm/nfmmodplugin.cpp b/plugins/channeltx/modnfm/nfmmodplugin.cpp index 770c2b5fa..550491d2b 100644 --- a/plugins/channeltx/modnfm/nfmmodplugin.cpp +++ b/plugins/channeltx/modnfm/nfmmodplugin.cpp @@ -22,11 +22,12 @@ #include "nfmmodgui.h" #endif #include "nfmmod.h" +#include "nfmmodwebapiadapter.h" #include "nfmmodplugin.h" const PluginDescriptor NFMModPlugin::m_pluginDescriptor = { QString("NFM Modulator"), - QString("4.11.5"), + QString("4.11.6"), QString("(c) Edouard Griffiths, F4EXB"), QString("https://github.com/f4exb/sdrangel"), true, @@ -76,4 +77,7 @@ ChannelAPI* NFMModPlugin::createTxChannelCS(DeviceAPI *deviceAPI) const return new NFMMod(deviceAPI); } - +ChannelAPI* NFMModPlugin::createChannelWebAPIAdapter() const +{ + return new NFMModWebAPIAdapter(); +} diff --git a/plugins/channeltx/modnfm/nfmmodplugin.h b/plugins/channeltx/modnfm/nfmmodplugin.h index bb3f51317..9bbe97ccb 100644 --- a/plugins/channeltx/modnfm/nfmmodplugin.h +++ b/plugins/channeltx/modnfm/nfmmodplugin.h @@ -38,6 +38,7 @@ public: virtual PluginInstanceGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *rxChannel) const; virtual BasebandSampleSource* createTxChannelBS(DeviceAPI *deviceAPI) const; virtual ChannelAPI* createTxChannelCS(DeviceAPI *deviceAPI) const; + virtual ChannelAPI* createChannelWebAPIAdapter() const; private: static const PluginDescriptor m_pluginDescriptor; diff --git a/plugins/channeltx/modnfm/nfmmodwebapiadapter.cpp b/plugins/channeltx/modnfm/nfmmodwebapiadapter.cpp new file mode 100644 index 000000000..04468562d --- /dev/null +++ b/plugins/channeltx/modnfm/nfmmodwebapiadapter.cpp @@ -0,0 +1,81 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "SWGChannelSettings.h" +#include "settings/serializable.h" +#include "nfmmod.h" +#include "nfmmodwebapiadapter.h" + +NFMModWebAPIAdapter::NFMModWebAPIAdapter() : + ChannelAPI(NFMMod::m_channelIdURI, ChannelAPI::StreamSingleSource) +{} + +NFMModWebAPIAdapter::~NFMModWebAPIAdapter() +{} + +int NFMModWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setNfmModSettings(new SWGSDRangel::SWGNFMModSettings()); + response.getNfmModSettings()->init(); + NFMMod::webapiFormatChannelSettings(response, m_settings); + Serializable *cwKeyerGUI = m_settings.m_cwKeyerGUI; + + if (cwKeyerGUI) + { + const QByteArray& serializedCWKeyerSettings = cwKeyerGUI->serialize(); + CWKeyerSettings cwKeyerSettings; + + if (cwKeyerSettings.deserialize(serializedCWKeyerSettings)) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getNfmModSettings()->getCwKeyer(); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + } + } + + return 200; +} + +int NFMModWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + NFMMod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response); + Serializable *cwKeyerGUI = m_settings.m_cwKeyerGUI; + + if (channelSettingsKeys.contains("cwKeyer") && cwKeyerGUI) + { + const QByteArray& serializedCWKeyerSettings = cwKeyerGUI->serialize(); + CWKeyerSettings cwKeyerSettings; + + if (cwKeyerSettings.deserialize(serializedCWKeyerSettings)) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getNfmModSettings()->getCwKeyer(); + CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); + const QByteArray& serializedNewCWKeyerSettings = cwKeyerSettings.serialize(); + cwKeyerGUI->deserialize(serializedNewCWKeyerSettings); + } + } + + NFMMod::webapiFormatChannelSettings(response, m_settings); + return 200; +} diff --git a/plugins/channeltx/modnfm/nfmmodwebapiadapter.h b/plugins/channeltx/modnfm/nfmmodwebapiadapter.h new file mode 100644 index 000000000..3178eef81 --- /dev/null +++ b/plugins/channeltx/modnfm/nfmmodwebapiadapter.h @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_NFMMOD_WEBAPIADAPTER_H +#define INCLUDE_NFMMOD_WEBAPIADAPTER_H + +#include "channel/channelapi.h" +#include "nfmmodsettings.h" + +/** + * Standalone API adapter only for the settings + */ +class NFMModWebAPIAdapter : public ChannelAPI { +public: + NFMModWebAPIAdapter(); + virtual ~NFMModWebAPIAdapter(); + + // unused pure virtual methods + virtual void destroy() {} + virtual void getIdentifier(QString& id) {} + virtual void getTitle(QString& title) {} + virtual qint64 getCenterFrequency() const { return 0; } + virtual int getNbSinkStreams() const { return 1; } + virtual int getNbSourceStreams() const { return 0; } + + virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + { + (void) streamIndex; + (void) sinkElseSource; + return 0; + } + + // virtual methods actually implemented + virtual QByteArray serialize() const { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data) { m_settings.deserialize(data); } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + +private: + NFMModSettings m_settings; +}; + +#endif // INCLUDE_NFMMOD_WEBAPIADAPTER_H diff --git a/plugins/channeltx/modssb/CMakeLists.txt b/plugins/channeltx/modssb/CMakeLists.txt index c75586093..a010be184 100644 --- a/plugins/channeltx/modssb/CMakeLists.txt +++ b/plugins/channeltx/modssb/CMakeLists.txt @@ -4,12 +4,14 @@ set(modssb_SOURCES ssbmod.cpp ssbmodplugin.cpp ssbmodsettings.cpp + ssbmodwebapiadapter.cpp ) set(modssb_HEADERS ssbmod.h ssbmodplugin.h ssbmodsettings.h + ssbmodwebapiadapter.h ) include_directories( diff --git a/plugins/channeltx/modssb/ssbmodplugin.cpp b/plugins/channeltx/modssb/ssbmodplugin.cpp index 2db53fadf..37adaca2b 100644 --- a/plugins/channeltx/modssb/ssbmodplugin.cpp +++ b/plugins/channeltx/modssb/ssbmodplugin.cpp @@ -22,11 +22,12 @@ #include "ssbmodgui.h" #endif #include "ssbmod.h" +#include "ssbmodwebapiadapter.h" #include "ssbmodplugin.h" const PluginDescriptor SSBModPlugin::m_pluginDescriptor = { QString("SSB Modulator"), - QString("4.11.5"), + QString("4.11.6"), QString("(c) Edouard Griffiths, F4EXB"), QString("https://github.com/f4exb/sdrangel"), true, @@ -76,4 +77,8 @@ ChannelAPI* SSBModPlugin::createTxChannelCS(DeviceAPI *deviceAPI) const return new SSBMod(deviceAPI); } +ChannelAPI* SSBModPlugin::createChannelWebAPIAdapter() const +{ + return new SSBModWebAPIAdapter(); +} diff --git a/plugins/channeltx/modssb/ssbmodplugin.h b/plugins/channeltx/modssb/ssbmodplugin.h index 82ba8c956..ec002a421 100644 --- a/plugins/channeltx/modssb/ssbmodplugin.h +++ b/plugins/channeltx/modssb/ssbmodplugin.h @@ -38,6 +38,7 @@ public: virtual PluginInstanceGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const; virtual BasebandSampleSource* createTxChannelBS(DeviceAPI *deviceAPI) const; virtual ChannelAPI* createTxChannelCS(DeviceAPI *deviceAPI) const; + virtual ChannelAPI* createChannelWebAPIAdapter() const; private: static const PluginDescriptor m_pluginDescriptor; diff --git a/plugins/channeltx/modssb/ssbmodwebapiadapter.cpp b/plugins/channeltx/modssb/ssbmodwebapiadapter.cpp new file mode 100644 index 000000000..8885ed817 --- /dev/null +++ b/plugins/channeltx/modssb/ssbmodwebapiadapter.cpp @@ -0,0 +1,81 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "SWGChannelSettings.h" +#include "settings/serializable.h" +#include "ssbmod.h" +#include "ssbmodwebapiadapter.h" + +SSBModWebAPIAdapter::SSBModWebAPIAdapter() : + ChannelAPI(SSBMod::m_channelIdURI, ChannelAPI::StreamSingleSource) +{} + +SSBModWebAPIAdapter::~SSBModWebAPIAdapter() +{} + +int SSBModWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setSsbModSettings(new SWGSDRangel::SWGSSBModSettings()); + response.getSsbModSettings()->init(); + SSBMod::webapiFormatChannelSettings(response, m_settings); + Serializable *cwKeyerGUI = m_settings.m_cwKeyerGUI; + + if (cwKeyerGUI) + { + const QByteArray& serializedCWKeyerSettings = cwKeyerGUI->serialize(); + CWKeyerSettings cwKeyerSettings; + + if (cwKeyerSettings.deserialize(serializedCWKeyerSettings)) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getSsbModSettings()->getCwKeyer(); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + } + } + + return 200; +} + +int SSBModWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + SSBMod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response); + Serializable *cwKeyerGUI = m_settings.m_cwKeyerGUI; + + if (channelSettingsKeys.contains("cwKeyer") && cwKeyerGUI) + { + const QByteArray& serializedCWKeyerSettings = cwKeyerGUI->serialize(); + CWKeyerSettings cwKeyerSettings; + + if (cwKeyerSettings.deserialize(serializedCWKeyerSettings)) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getSsbModSettings()->getCwKeyer(); + CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); + const QByteArray& serializedNewCWKeyerSettings = cwKeyerSettings.serialize(); + cwKeyerGUI->deserialize(serializedNewCWKeyerSettings); + } + } + + SSBMod::webapiFormatChannelSettings(response, m_settings); + return 200; +} diff --git a/plugins/channeltx/modssb/ssbmodwebapiadapter.h b/plugins/channeltx/modssb/ssbmodwebapiadapter.h new file mode 100644 index 000000000..b36f941f5 --- /dev/null +++ b/plugins/channeltx/modssb/ssbmodwebapiadapter.h @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_SSBMOD_WEBAPIADAPTER_H +#define INCLUDE_SSBMOD_WEBAPIADAPTER_H + +#include "channel/channelapi.h" +#include "ssbmodsettings.h" + +/** + * Standalone API adapter only for the settings + */ +class SSBModWebAPIAdapter : public ChannelAPI { +public: + SSBModWebAPIAdapter(); + virtual ~SSBModWebAPIAdapter(); + + // unused pure virtual methods + virtual void destroy() {} + virtual void getIdentifier(QString& id) {} + virtual void getTitle(QString& title) {} + virtual qint64 getCenterFrequency() const { return 0; } + virtual int getNbSinkStreams() const { return 1; } + virtual int getNbSourceStreams() const { return 0; } + + virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + { + (void) streamIndex; + (void) sinkElseSource; + return 0; + } + + // virtual methods actually implemented + virtual QByteArray serialize() const { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data) { m_settings.deserialize(data); } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + +private: + SSBModSettings m_settings; +}; + +#endif // INCLUDE_SSBMOD_WEBAPIADAPTER_H diff --git a/plugins/channeltx/modwfm/CMakeLists.txt b/plugins/channeltx/modwfm/CMakeLists.txt index cbca303ff..0bac9ed41 100644 --- a/plugins/channeltx/modwfm/CMakeLists.txt +++ b/plugins/channeltx/modwfm/CMakeLists.txt @@ -3,13 +3,15 @@ project(modwfm) set(modwfm_SOURCES wfmmod.cpp wfmmodplugin.cpp - wfmmodsettings.cpp + wfmmodsettings.cpp + wfmmodwebapiadapter.cpp ) set(modwfm_HEADERS wfmmod.h wfmmodplugin.h - wfmmodsettings.h + wfmmodsettings.h + wfmmodwebapiadapter.h ) include_directories( diff --git a/plugins/channeltx/modwfm/wfmmodplugin.cpp b/plugins/channeltx/modwfm/wfmmodplugin.cpp index 23421654b..e081b5c59 100644 --- a/plugins/channeltx/modwfm/wfmmodplugin.cpp +++ b/plugins/channeltx/modwfm/wfmmodplugin.cpp @@ -22,11 +22,12 @@ #include "wfmmodgui.h" #endif #include "wfmmod.h" +#include "wfmmodwebapiadapter.h" #include "wfmmodplugin.h" const PluginDescriptor WFMModPlugin::m_pluginDescriptor = { QString("WFM Modulator"), - QString("4.11.5"), + QString("4.11.6"), QString("(c) Edouard Griffiths, F4EXB"), QString("https://github.com/f4exb/sdrangel"), true, @@ -76,4 +77,7 @@ ChannelAPI* WFMModPlugin::createTxChannelCS(DeviceAPI *deviceAPI) const return new WFMMod(deviceAPI); } - +ChannelAPI* WFMModPlugin::createChannelWebAPIAdapter() const +{ + return new WFMModWebAPIAdapter(); +} diff --git a/plugins/channeltx/modwfm/wfmmodplugin.h b/plugins/channeltx/modwfm/wfmmodplugin.h index 2d9647e50..fb2445153 100644 --- a/plugins/channeltx/modwfm/wfmmodplugin.h +++ b/plugins/channeltx/modwfm/wfmmodplugin.h @@ -37,6 +37,7 @@ public: virtual PluginInstanceGUI* createTxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSource *txChannel) const; virtual BasebandSampleSource* createTxChannelBS(DeviceAPI *deviceAPI) const; virtual ChannelAPI* createTxChannelCS(DeviceAPI *deviceAPI) const; + virtual ChannelAPI* createChannelWebAPIAdapter() const; private: static const PluginDescriptor m_pluginDescriptor; diff --git a/plugins/channeltx/modwfm/wfmmodwebapiadapter.cpp b/plugins/channeltx/modwfm/wfmmodwebapiadapter.cpp new file mode 100644 index 000000000..734f536e2 --- /dev/null +++ b/plugins/channeltx/modwfm/wfmmodwebapiadapter.cpp @@ -0,0 +1,81 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include "SWGChannelSettings.h" +#include "settings/serializable.h" +#include "wfmmod.h" +#include "wfmmodwebapiadapter.h" + +WFMModWebAPIAdapter::WFMModWebAPIAdapter() : + ChannelAPI(WFMMod::m_channelIdURI, ChannelAPI::StreamSingleSource) +{} + +WFMModWebAPIAdapter::~WFMModWebAPIAdapter() +{} + +int WFMModWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setWfmModSettings(new SWGSDRangel::SWGWFMModSettings()); + response.getWfmModSettings()->init(); + WFMMod::webapiFormatChannelSettings(response, m_settings); + Serializable *cwKeyerGUI = m_settings.m_cwKeyerGUI; + + if (cwKeyerGUI) + { + const QByteArray& serializedCWKeyerSettings = cwKeyerGUI->serialize(); + CWKeyerSettings cwKeyerSettings; + + if (cwKeyerSettings.deserialize(serializedCWKeyerSettings)) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getWfmModSettings()->getCwKeyer(); + CWKeyer::webapiFormatChannelSettings(apiCwKeyerSettings, cwKeyerSettings); + } + } + + return 200; +} + +int WFMModWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + WFMMod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response); + Serializable *cwKeyerGUI = m_settings.m_cwKeyerGUI; + + if (channelSettingsKeys.contains("cwKeyer") && cwKeyerGUI) + { + const QByteArray& serializedCWKeyerSettings = cwKeyerGUI->serialize(); + CWKeyerSettings cwKeyerSettings; + + if (cwKeyerSettings.deserialize(serializedCWKeyerSettings)) + { + SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getWfmModSettings()->getCwKeyer(); + CWKeyer::webapiSettingsPutPatch(channelSettingsKeys, cwKeyerSettings, apiCwKeyerSettings); + const QByteArray& serializedNewCWKeyerSettings = cwKeyerSettings.serialize(); + cwKeyerGUI->deserialize(serializedNewCWKeyerSettings); + } + } + + WFMMod::webapiFormatChannelSettings(response, m_settings); + return 200; +} diff --git a/plugins/channeltx/modwfm/wfmmodwebapiadapter.h b/plugins/channeltx/modwfm/wfmmodwebapiadapter.h new file mode 100644 index 000000000..0fd43538e --- /dev/null +++ b/plugins/channeltx/modwfm/wfmmodwebapiadapter.h @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB. // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// (at your option) any later version. // +// // +// This program is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY; without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_WFMMOD_WEBAPIADAPTER_H +#define INCLUDE_WFMMOD_WEBAPIADAPTER_H + +#include "channel/channelapi.h" +#include "wfmmodsettings.h" + +/** + * Standalone API adapter only for the settings + */ +class WFMModWebAPIAdapter : public ChannelAPI { +public: + WFMModWebAPIAdapter(); + virtual ~WFMModWebAPIAdapter(); + + // unused pure virtual methods + virtual void destroy() {} + virtual void getIdentifier(QString& id) {} + virtual void getTitle(QString& title) {} + virtual qint64 getCenterFrequency() const { return 0; } + virtual int getNbSinkStreams() const { return 1; } + virtual int getNbSourceStreams() const { return 0; } + + virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const + { + (void) streamIndex; + (void) sinkElseSource; + return 0; + } + + // virtual methods actually implemented + virtual QByteArray serialize() const { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data) { m_settings.deserialize(data); } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& channelSettingsKeys, + SWGSDRangel::SWGChannelSettings& response, + QString& errorMessage); + +private: + WFMModSettings m_settings; +}; + +#endif // INCLUDE_WFMMOD_WEBAPIADAPTER_H