diff --git a/plugins/samplesource/airspy/CMakeLists.txt b/plugins/samplesource/airspy/CMakeLists.txt index caabd900a..8525ce5d8 100644 --- a/plugins/samplesource/airspy/CMakeLists.txt +++ b/plugins/samplesource/airspy/CMakeLists.txt @@ -4,6 +4,7 @@ set(airspy_SOURCES airspyinput.cpp airspyplugin.cpp airspysettings.cpp + airspywebapiadapter.cpp airspythread.cpp ) @@ -11,6 +12,7 @@ set(airspy_HEADERS airspyinput.h airspyplugin.h airspysettings.h + airspywebapiadapter.h airspythread.h ) @@ -23,7 +25,6 @@ if(NOT SERVER_MODE) set(airspy_SOURCES ${airspy_SOURCES} airspygui.cpp - airspygui.ui ) set(airspy_HEADERS @@ -51,12 +52,12 @@ if(ENABLE_EXTERNAL_LIBRARIES AND NOT LINUX) endif() target_link_libraries(${TARGET_NAME} - Qt5::Core - ${TARGET_LIB} + Qt5::Core + ${TARGET_LIB} sdrbase ${TARGET_LIB_GUI} - swagger - ${LIBAIRSPY_LIBRARIES} + swagger + ${LIBAIRSPY_LIBRARIES} ) install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER}) diff --git a/plugins/samplesource/airspy/airspyinput.cpp b/plugins/samplesource/airspy/airspyinput.cpp index 156186acf..a4083dcd3 100644 --- a/plugins/samplesource/airspy/airspyinput.cpp +++ b/plugins/samplesource/airspy/airspyinput.cpp @@ -656,7 +656,26 @@ int AirspyInput::webapiSettingsPutPatch( { (void) errorMessage; AirspySettings settings = m_settings; + webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response); + MsgConfigureAirspy *msg = MsgConfigureAirspy::create(settings, force); + m_inputMessageQueue.push(msg); + + if (m_guiMessageQueue) // forward to GUI if any + { + MsgConfigureAirspy *msgToGUI = MsgConfigureAirspy::create(settings, force); + m_guiMessageQueue->push(msgToGUI); + } + + webapiFormatDeviceSettings(response, settings); + return 200; +} + +void webapiUpdateDeviceSettings( + AirspySettings& settings, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response) +{ if (deviceSettingsKeys.contains("centerFrequency")) { settings.m_centerFrequency = response.getAirspySettings()->getCenterFrequency(); } @@ -719,18 +738,6 @@ int AirspyInput::webapiSettingsPutPatch( if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) { settings.m_reverseAPIDeviceIndex = response.getAirspySettings()->getReverseApiDeviceIndex(); } - - MsgConfigureAirspy *msg = MsgConfigureAirspy::create(settings, force); - m_inputMessageQueue.push(msg); - - if (m_guiMessageQueue) // forward to GUI if any - { - MsgConfigureAirspy *msgToGUI = MsgConfigureAirspy::create(settings, force); - m_guiMessageQueue->push(msgToGUI); - } - - webapiFormatDeviceSettings(response, settings); - return 200; } int AirspyInput::webapiReportGet( diff --git a/plugins/samplesource/airspy/airspyinput.h b/plugins/samplesource/airspy/airspyinput.h index f4b3c2a47..6c8a02562 100644 --- a/plugins/samplesource/airspy/airspyinput.h +++ b/plugins/samplesource/airspy/airspyinput.h @@ -140,6 +140,15 @@ public: SWGSDRangel::SWGDeviceReport& response, QString& errorMessage); + static void webapiFormatDeviceSettings( + SWGSDRangel::SWGDeviceSettings& response, + const AirspySettings& settings); + + static void webapiUpdateDeviceSettings( + AirspySettings& settings, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response); + static const qint64 loLowLimitFreq; static const qint64 loHighLimitFreq; @@ -161,7 +170,6 @@ private: bool applySettings(const AirspySettings& settings, bool force); struct airspy_device *open_airspy_from_sequence(int sequence); void setDeviceCenterFrequency(quint64 freq); - void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const AirspySettings& settings); void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response); void webapiReverseSendSettings(QList& deviceSettingsKeys, const AirspySettings& settings, bool force); void webapiReverseSendStartStop(bool start); diff --git a/plugins/samplesource/airspy/airspyplugin.cpp b/plugins/samplesource/airspy/airspyplugin.cpp index 5b5f25de3..9a2e220eb 100644 --- a/plugins/samplesource/airspy/airspyplugin.cpp +++ b/plugins/samplesource/airspy/airspyplugin.cpp @@ -23,6 +23,7 @@ #else #include "airspygui.h" #endif +#include "airspywebapiadapter.h" #include "airspyplugin.h" #include "plugin/pluginapi.h" @@ -32,7 +33,7 @@ const int AirspyPlugin::m_maxDevices = 32; const PluginDescriptor AirspyPlugin::m_pluginDescriptor = { QString("Airspy Input"), - QString("4.5.2"), + QString("4.11.6"), QString("(c) Edouard Griffiths, F4EXB"), QString("https://github.com/f4exb/sdrangel"), true, @@ -137,7 +138,7 @@ PluginInstanceGUI* AirspyPlugin::createSampleSourcePluginInstanceGUI( (void) sourceId; (void) widget; (void) deviceUISet; - return 0; + return nullptr; } #else PluginInstanceGUI* AirspyPlugin::createSampleSourcePluginInstanceGUI( @@ -153,7 +154,7 @@ PluginInstanceGUI* AirspyPlugin::createSampleSourcePluginInstanceGUI( } else { - return 0; + return nullptr; } } #endif @@ -167,6 +168,11 @@ DeviceSampleSource *AirspyPlugin::createSampleSourcePluginInstance(const QString } else { - return 0; + return nullptr; } } + +DeviceWebAPIAdapter *AirspyPlugin::createDeviceWebAPIAdapter() const +{ + return new AirspyWebAPIAdapter(); +} \ No newline at end of file diff --git a/plugins/samplesource/airspy/airspyplugin.h b/plugins/samplesource/airspy/airspyplugin.h index 842bfeeb1..ce268d4d9 100644 --- a/plugins/samplesource/airspy/airspyplugin.h +++ b/plugins/samplesource/airspy/airspyplugin.h @@ -42,6 +42,7 @@ public: QWidget **widget, DeviceUISet *deviceUISet); virtual DeviceSampleSource* createSampleSourcePluginInstance(const QString& sourceId, DeviceAPI *deviceAPI); + virtual DeviceWebAPIAdapter* createDeviceWebAPIAdapter() const; static const QString m_hardwareID; static const QString m_deviceTypeID; diff --git a/plugins/samplesource/airspy/airspywebapiadapter.cpp b/plugins/samplesource/airspy/airspywebapiadapter.cpp new file mode 100644 index 000000000..0495d596a --- /dev/null +++ b/plugins/samplesource/airspy/airspywebapiadapter.cpp @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB // +// // +// Implementation of static web API adapters used for preset serialization and // +// deserialization // +// // +// 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 "SWGDeviceSettings.h" +#include "airspyinput.h" +#include "airspywebapiadapter.h" + +AirspyWebAPIAdapter::AirspyWebAPIAdapter() +{} + +AirspyWebAPIAdapter::~AirspyWebAPIAdapter() +{} + +int AirspyWebAPIAdapter::webapiSettingsGet( + SWGSDRangel::SWGDeviceSettings& response, + QString& errorMessage) +{ + (void) errorMessage; + response.setAirspySettings(new SWGSDRangel::SWGAirspySettings()); + response.getAirspySettings()->init(); + AirspyInput::webapiFormatDeviceSettings(response, m_settings); + return 200; +} + +int AirspyWebAPIAdapter::webapiSettingsPutPatch( + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, // query + response + QString& errorMessage) +{ + (void) errorMessage; + AirspyInput::webapiUpdateDeviceSettings(m_settings, deviceSettingsKeys, response); + return 200; +} diff --git a/plugins/samplesource/airspy/airspywebapiadapter.h b/plugins/samplesource/airspy/airspywebapiadapter.h new file mode 100644 index 000000000..8d803f869 --- /dev/null +++ b/plugins/samplesource/airspy/airspywebapiadapter.h @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB // +// // +// Implementation of static web API adapters used for preset serialization and // +// deserialization // +// // +// 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 "device/devicewebapiadapter.h" +#include "airspysettings.h" + +class AirspyWebAPIAdapter : public DeviceWebAPIAdapter +{ +public: + AirspyWebAPIAdapter(); + virtual ~AirspyWebAPIAdapter(); + virtual QByteArray serialize() { return m_settings.serialize(); } + virtual bool deserialize(const QByteArray& data) { return m_settings.deserialize(data); } + + virtual int webapiSettingsGet( + SWGSDRangel::SWGDeviceSettings& response, + QString& errorMessage); + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, // query + response + QString& errorMessage); + +private: + AirspySettings m_settings; +}; \ No newline at end of file diff --git a/sdrbase/channel/channelapi.h b/sdrbase/channel/channelapi.h index 5d48895e4..98f231c56 100644 --- a/sdrbase/channel/channelapi.h +++ b/sdrbase/channel/channelapi.h @@ -1,7 +1,7 @@ /////////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2019 Edouard Griffiths, F4EXB // // // -// API for Rx channels // +// API for channels // // // // 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 // diff --git a/sdrbase/device/devicewebapiadapter.h b/sdrbase/device/devicewebapiadapter.h new file mode 100644 index 000000000..0fb232e05 --- /dev/null +++ b/sdrbase/device/devicewebapiadapter.h @@ -0,0 +1,54 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2019 Edouard Griffiths, F4EXB // +// // +// Interface for static web API adapters used for preset serialization and // +// deserialization // +// // +// 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 SDRBASE_DEVICE_DEVICEWEBAPIADAPER_H_ +#define SDRBASE_DEVICE_DEVICEWEBAPIADAPER_H_ + +#include +#include + +#include "export.h" + +namespace SWGSDRangel +{ + class SWGDeviceSettings; +} + +class SDRBASE_API DeviceWebAPIAdapter +{ +public: + DeviceWebAPIAdapter() {} + virtual ~DeviceWebAPIAdapter() {} + virtual QByteArray serialize() = 0; + virtual bool deserialize(const QByteArray& data) = 0; + + virtual int webapiSettingsGet( + SWGSDRangel::SWGDeviceSettings& response, + QString& errorMessage) = 0; + + virtual int webapiSettingsPutPatch( + bool force, + const QStringList& deviceSettingsKeys, + SWGSDRangel::SWGDeviceSettings& response, // query + response + QString& errorMessage) = 0; +}; + + +#endif // SDRBASE_DEVICE_DEVICEWEBAPIADAPER_H_ \ No newline at end of file diff --git a/sdrbase/plugin/plugininterface.h b/sdrbase/plugin/plugininterface.h index 9aa133a3a..d597062af 100644 --- a/sdrbase/plugin/plugininterface.h +++ b/sdrbase/plugin/plugininterface.h @@ -27,6 +27,7 @@ class DeviceSampleMIMO; class BasebandSampleSink; class BasebandSampleSource; class ChannelAPI; +class DeviceWebAPIAdapter; class SDRBASE_API PluginInterface { public: @@ -217,6 +218,11 @@ public: virtual void deleteSampleMIMOPluginInstanceGUI(PluginInstanceGUI *ui); virtual void deleteSampleMIMOPluginInstanceMIMO(DeviceSampleMIMO *mimo); + // all devices + + virtual DeviceWebAPIAdapter* createDeviceWebAPIAdapter() const { + return nullptr; + } }; Q_DECLARE_INTERFACE(PluginInterface, "SDRangel.PluginInterface/0.1"); diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index 6f59ad01b..8b308a883 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -240,14 +240,14 @@ void PluginManager::createTxChannelInstance(int channelPluginIndex, DeviceUISet const PluginInterface *PluginManager::getChannelPluginInterface(const QString& channelIdURI) const { - for(PluginAPI::ChannelRegistrations::const_iterator it = m_rxChannelRegistrations.begin(); it != m_rxChannelRegistrations.end(); ++it) + for (PluginAPI::ChannelRegistrations::const_iterator it = m_rxChannelRegistrations.begin(); it != m_rxChannelRegistrations.end(); ++it) { if (it->m_channelIdURI == channelIdURI) { return it->m_plugin; } } - for(PluginAPI::ChannelRegistrations::const_iterator it = m_txChannelRegistrations.begin(); it != m_txChannelRegistrations.end(); ++it) + for (PluginAPI::ChannelRegistrations::const_iterator it = m_txChannelRegistrations.begin(); it != m_txChannelRegistrations.end(); ++it) { if (it->m_channelIdURI == channelIdURI) { return it->m_plugin; @@ -256,3 +256,29 @@ const PluginInterface *PluginManager::getChannelPluginInterface(const QString& c return nullptr; } + +const PluginInterface *PluginManager::getDevicePluginInterface(const QString& deviceId) const +{ + for (PluginAPI::SamplingDeviceRegistrations::const_iterator it = m_sampleSourceRegistrations.begin(); it != m_sampleSourceRegistrations.end(); ++it) + { + if (it->m_deviceId == deviceId) { + return it->m_plugin; + } + } + + for (PluginAPI::SamplingDeviceRegistrations::const_iterator it = m_sampleSinkRegistrations.begin(); it != m_sampleSinkRegistrations.end(); ++it) + { + if (it->m_deviceId == deviceId) { + return it->m_plugin; + } + } + + for (PluginAPI::SamplingDeviceRegistrations::const_iterator it = m_sampleMIMORegistrations.begin(); it != m_sampleMIMORegistrations.end(); ++it) + { + if (it->m_deviceId == deviceId) { + return it->m_plugin; + } + } + + return nullptr; +} \ No newline at end of file diff --git a/sdrbase/plugin/pluginmanager.h b/sdrbase/plugin/pluginmanager.h index aab37ef17..77deb7ad0 100644 --- a/sdrbase/plugin/pluginmanager.h +++ b/sdrbase/plugin/pluginmanager.h @@ -81,6 +81,7 @@ public: void listTxChannels(QList& list); const PluginInterface *getChannelPluginInterface(const QString& channelIdURI) const; + const PluginInterface *getDevicePluginInterface(const QString& deviceId) const; static const QString& getFileInputDeviceId() { return m_fileInputDeviceTypeID; } static const QString& getFileSinkDeviceId() { return m_fileSinkDeviceTypeID; } diff --git a/sdrbase/webapi/webapiadapterbase.cpp b/sdrbase/webapi/webapiadapterbase.cpp index afc058e8d..f84f9b49d 100644 --- a/sdrbase/webapi/webapiadapterbase.cpp +++ b/sdrbase/webapi/webapiadapterbase.cpp @@ -20,6 +20,7 @@ #include "plugin/pluginmanager.h" #include "channel/channelapi.h" #include "channel/channelutils.h" +#include "device/devicewebapiadapter.h" #include "webapiadapterbase.h" WebAPIAdapterBase::WebAPIAdapterBase() @@ -93,9 +94,17 @@ void WebAPIAdapterBase::webapiFormatPreset( swgdeviceConfigs->back()->setDeviceId(new QString(deviceConfig.m_deviceId)); swgdeviceConfigs->back()->setDeviceSerial(new QString(deviceConfig.m_deviceSerial)); swgdeviceConfigs->back()->setDeviceSequence(deviceConfig.m_deviceSequence); - // const QByteArray& deviceSettings = deviceConfig.m_config; - // SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = swgdeviceConfigs->back()->getConfig(); - // swgDeviceSettings->init(); + const QByteArray& deviceSettings = deviceConfig.m_config; + SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = swgdeviceConfigs->back()->getConfig(); + swgDeviceSettings->init(); + DeviceWebAPIAdapter *deviceWebAPIAdapter = m_webAPIDeviceAdapters.getDeviceWebAPIAdapter(deviceConfig.m_deviceId, m_pluginManager); + + if (deviceWebAPIAdapter) + { + deviceWebAPIAdapter->deserialize(deviceSettings); + QString errorMessage; + deviceWebAPIAdapter->webapiSettingsGet(*swgDeviceSettings, errorMessage); + } } } @@ -144,9 +153,44 @@ ChannelAPI *WebAPIAdapterBase::WebAPIChannelAdapters::getChannelAPI(const QStrin void WebAPIAdapterBase::WebAPIChannelAdapters::flush() { - foreach(ChannelAPI *ChannelAPI, m_webAPIChannelAdapters) { - delete ChannelAPI; + foreach(ChannelAPI *channelAPI, m_webAPIChannelAdapters) { + delete channelAPI; } m_webAPIChannelAdapters.clear(); -} \ No newline at end of file +} + +DeviceWebAPIAdapter *WebAPIAdapterBase::WebAPIDeviceAdapters::getDeviceWebAPIAdapter(const QString& deviceId, const PluginManager *pluginManager) +{ + QMap::iterator it = m_webAPIDeviceAdapters.find(deviceId); + + if (it == m_webAPIDeviceAdapters.end()) + { + const PluginInterface *pluginInterface = pluginManager->getDevicePluginInterface(deviceId); + + if (pluginInterface) + { + DeviceWebAPIAdapter *deviceWebAPIAdapter = pluginInterface->createDeviceWebAPIAdapter(); + m_webAPIDeviceAdapters.insert(deviceId, deviceWebAPIAdapter); + return deviceWebAPIAdapter; + } + else + { + m_webAPIDeviceAdapters.insert(deviceId, nullptr); + return nullptr; + } + } + else + { + return *it; + } +} + +void WebAPIAdapterBase::WebAPIDeviceAdapters::flush() +{ + foreach(DeviceWebAPIAdapter *deviceWebAPIAdapter, m_webAPIDeviceAdapters) { + delete deviceWebAPIAdapter; + } + + m_webAPIDeviceAdapters.clear(); +} diff --git a/sdrbase/webapi/webapiadapterbase.h b/sdrbase/webapi/webapiadapterbase.h index a013d8bf4..7a3cfd502 100644 --- a/sdrbase/webapi/webapiadapterbase.h +++ b/sdrbase/webapi/webapiadapterbase.h @@ -31,6 +31,7 @@ class PluginManager; class ChannelAPI; +class DeviceWebAPIAdapter; /** * Adapter between API and objects in sdrbase library @@ -66,8 +67,18 @@ private: QMap m_webAPIChannelAdapters; }; + class WebAPIDeviceAdapters + { + public: + DeviceWebAPIAdapter *getDeviceWebAPIAdapter(const QString& deviceId, const PluginManager *pluginManager); + void flush(); + private: + QMap m_webAPIDeviceAdapters; + }; + const PluginManager *m_pluginManager; WebAPIChannelAdapters m_webAPIChannelAdapters; + WebAPIDeviceAdapters m_webAPIDeviceAdapters; }; #endif // SDRBASE_WEBAPI_WEBAPIADAPTERBASE_H_ \ No newline at end of file