mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-08-14 23:43:43 -04: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:
@@ -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})
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user