1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 10:05:46 -05:00

REST API: config: GET (10): mechanism to deal with device settings API formatting without creating a complete device object. Applied to Airspy input

This commit is contained in:
f4exb 2019-08-03 11:21:46 +02:00
parent ae49f17484
commit 4b493da226
14 changed files with 291 additions and 31 deletions

View File

@ -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})

View File

@ -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(

View File

@ -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<QString>& deviceSettingsKeys, const AirspySettings& settings, bool force);
void webapiReverseSendStartStop(bool start);

View File

@ -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();
}

View File

@ -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;

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#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;
}

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#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;
};

View File

@ -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 //

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_DEVICE_DEVICEWEBAPIADAPER_H_
#define SDRBASE_DEVICE_DEVICEWEBAPIADAPER_H_
#include <QByteArray>
#include <QStringList>
#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_

View File

@ -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");

View File

@ -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;
}

View File

@ -81,6 +81,7 @@ public:
void listTxChannels(QList<QString>& 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; }

View File

@ -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();
}
}
DeviceWebAPIAdapter *WebAPIAdapterBase::WebAPIDeviceAdapters::getDeviceWebAPIAdapter(const QString& deviceId, const PluginManager *pluginManager)
{
QMap<QString, DeviceWebAPIAdapter*>::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();
}

View File

@ -31,6 +31,7 @@
class PluginManager;
class ChannelAPI;
class DeviceWebAPIAdapter;
/**
* Adapter between API and objects in sdrbase library
@ -66,8 +67,18 @@ private:
QMap<QString, ChannelAPI*> m_webAPIChannelAdapters;
};
class WebAPIDeviceAdapters
{
public:
DeviceWebAPIAdapter *getDeviceWebAPIAdapter(const QString& deviceId, const PluginManager *pluginManager);
void flush();
private:
QMap<QString, DeviceWebAPIAdapter*> m_webAPIDeviceAdapters;
};
const PluginManager *m_pluginManager;
WebAPIChannelAdapters m_webAPIChannelAdapters;
WebAPIDeviceAdapters m_webAPIDeviceAdapters;
};
#endif // SDRBASE_WEBAPI_WEBAPIADAPTERBASE_H_