mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-14 03:38:41 -04:00
REST API: config: GET (3): mechanism to deal with channel settings API formatting without creating a complete channel object. Applied to AM demod
This commit is contained in:
@@ -3,13 +3,15 @@ project(am)
|
||||
set(am_SOURCES
|
||||
amdemod.cpp
|
||||
amdemodsettings.cpp
|
||||
amdemodplugin.cpp
|
||||
amdemodplugin.cpp
|
||||
amdemodwebapiadapter.cpp
|
||||
)
|
||||
|
||||
set(am_HEADERS
|
||||
amdemod.h
|
||||
amdemodsettings.h
|
||||
amdemodplugin.h
|
||||
amdemodplugin.h
|
||||
amdemodwebapiadapter.h
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -598,17 +598,41 @@ int AMDemod::webapiSettingsPutPatch(
|
||||
SWGSDRangel::SWGChannelSettings& response,
|
||||
QString& errorMessage)
|
||||
{
|
||||
(void) errorMessage;
|
||||
AMDemodSettings settings = m_settings;
|
||||
bool frequencyOffsetChanged = false;
|
||||
webapiUpdateChannelSettings(settings, channelSettingsKeys, response);
|
||||
|
||||
if (settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset)
|
||||
{
|
||||
MsgConfigureChannelizer* channelConfigMsg = MsgConfigureChannelizer::create(
|
||||
m_audioSampleRate, settings.m_inputFrequencyOffset);
|
||||
m_inputMessageQueue.push(channelConfigMsg);
|
||||
}
|
||||
|
||||
MsgConfigureAMDemod *msg = MsgConfigureAMDemod::create(settings, force);
|
||||
m_inputMessageQueue.push(msg);
|
||||
|
||||
qDebug("AMDemod::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
||||
if (m_guiMessageQueue) // forward to GUI if any
|
||||
{
|
||||
MsgConfigureAMDemod *msgToGUI = MsgConfigureAMDemod::create(settings, force);
|
||||
m_guiMessageQueue->push(msgToGUI);
|
||||
}
|
||||
|
||||
webapiFormatChannelSettings(response, settings);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
void AMDemod::webapiUpdateChannelSettings(
|
||||
AMDemodSettings& settings,
|
||||
const QStringList& channelSettingsKeys,
|
||||
SWGSDRangel::SWGChannelSettings& response)
|
||||
{
|
||||
if (channelSettingsKeys.contains("audioMute")) {
|
||||
settings.m_audioMute = response.getAmDemodSettings()->getAudioMute() != 0;
|
||||
}
|
||||
if (channelSettingsKeys.contains("inputFrequencyOffset"))
|
||||
{
|
||||
if (channelSettingsKeys.contains("inputFrequencyOffset")) {
|
||||
settings.m_inputFrequencyOffset = response.getAmDemodSettings()->getInputFrequencyOffset();
|
||||
frequencyOffsetChanged = true;
|
||||
}
|
||||
if (channelSettingsKeys.contains("rfBandwidth")) {
|
||||
settings.m_rfBandwidth = response.getAmDemodSettings()->getRfBandwidth();
|
||||
@@ -661,27 +685,6 @@ int AMDemod::webapiSettingsPutPatch(
|
||||
if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
|
||||
settings.m_reverseAPIChannelIndex = response.getAmDemodSettings()->getReverseApiChannelIndex();
|
||||
}
|
||||
|
||||
if (frequencyOffsetChanged)
|
||||
{
|
||||
MsgConfigureChannelizer* channelConfigMsg = MsgConfigureChannelizer::create(
|
||||
m_audioSampleRate, settings.m_inputFrequencyOffset);
|
||||
m_inputMessageQueue.push(channelConfigMsg);
|
||||
}
|
||||
|
||||
MsgConfigureAMDemod *msg = MsgConfigureAMDemod::create(settings, force);
|
||||
m_inputMessageQueue.push(msg);
|
||||
|
||||
qDebug("AMDemod::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
||||
if (m_guiMessageQueue) // forward to GUI if any
|
||||
{
|
||||
MsgConfigureAMDemod *msgToGUI = MsgConfigureAMDemod::create(settings, force);
|
||||
m_guiMessageQueue->push(msgToGUI);
|
||||
}
|
||||
|
||||
webapiFormatChannelSettings(response, settings);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
int AMDemod::webapiReportGet(
|
||||
@@ -718,8 +721,8 @@ void AMDemod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respo
|
||||
}
|
||||
|
||||
response.getAmDemodSettings()->setPll(settings.m_pll ? 1 : 0);
|
||||
response.getAmDemodSettings()->setSyncAmOperation((int) m_settings.m_syncAMOperation);
|
||||
response.getAmDemodSettings()->setStreamIndex(m_settings.m_streamIndex);
|
||||
response.getAmDemodSettings()->setSyncAmOperation((int) settings.m_syncAMOperation);
|
||||
response.getAmDemodSettings()->setStreamIndex(settings.m_streamIndex);
|
||||
response.getAmDemodSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
||||
|
||||
if (response.getAmDemodSettings()->getReverseApiAddress()) {
|
||||
|
||||
@@ -134,6 +134,15 @@ public:
|
||||
SWGSDRangel::SWGChannelReport& response,
|
||||
QString& errorMessage);
|
||||
|
||||
static void webapiFormatChannelSettings(
|
||||
SWGSDRangel::SWGChannelSettings& response,
|
||||
const AMDemodSettings& settings);
|
||||
|
||||
static void webapiUpdateChannelSettings(
|
||||
AMDemodSettings& settings,
|
||||
const QStringList& channelSettingsKeys,
|
||||
SWGSDRangel::SWGChannelSettings& response);
|
||||
|
||||
uint32_t getAudioSampleRate() const { return m_audioSampleRate; }
|
||||
double getMagSq() const { return m_magsq; }
|
||||
bool getSquelchOpen() const { return m_squelchOpen; }
|
||||
@@ -230,7 +239,6 @@ private:
|
||||
void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = false);
|
||||
void applySettings(const AMDemodSettings& settings, bool force = false);
|
||||
void applyAudioSampleRate(int sampleRate);
|
||||
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const AMDemodSettings& settings);
|
||||
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response);
|
||||
void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const AMDemodSettings& settings, bool force);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "amdemodgui.h"
|
||||
#endif
|
||||
#include "amdemod.h"
|
||||
#include "amdemodwebapiadapter.h"
|
||||
#include "amdemodplugin.h"
|
||||
|
||||
const PluginDescriptor AMDemodPlugin::m_pluginDescriptor = {
|
||||
@@ -59,3 +60,7 @@ ChannelAPI* AMDemodPlugin::createRxChannelCS(DeviceAPI *deviceAPI)
|
||||
return new AMDemod(deviceAPI);
|
||||
}
|
||||
|
||||
ChannelAPI* AMDemodPlugin::createChannelWebAPIAdapter() const
|
||||
{
|
||||
return new AMDemodWebAPIAdapter();
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
virtual PluginInstanceGUI* createRxChannelGUI(DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel);
|
||||
virtual BasebandSampleSink* createRxChannelBS(DeviceAPI *deviceAPI);
|
||||
virtual ChannelAPI* createRxChannelCS(DeviceAPI *deviceAPI);
|
||||
virtual ChannelAPI* createChannelWebAPIAdapter() const;
|
||||
|
||||
private:
|
||||
static const PluginDescriptor m_pluginDescriptor;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SWGChannelSettings.h"
|
||||
#include "amdemod.h"
|
||||
#include "amdemodwebapiadapter.h"
|
||||
|
||||
AMDemodWebAPIAdapter::AMDemodWebAPIAdapter() :
|
||||
ChannelAPI(AMDemod::m_channelIdURI, ChannelAPI::StreamSingleSink)
|
||||
{}
|
||||
|
||||
AMDemodWebAPIAdapter::~AMDemodWebAPIAdapter()
|
||||
{}
|
||||
|
||||
int AMDemodWebAPIAdapter::webapiSettingsGet(
|
||||
SWGSDRangel::SWGChannelSettings& response,
|
||||
QString& errorMessage)
|
||||
{
|
||||
(void) errorMessage;
|
||||
response.setAmDemodSettings(new SWGSDRangel::SWGAMDemodSettings());
|
||||
response.getAmDemodSettings()->init();
|
||||
AMDemod::webapiFormatChannelSettings(response, m_settings);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
int AMDemodWebAPIAdapter::webapiSettingsPutPatch(
|
||||
bool force,
|
||||
const QStringList& channelSettingsKeys,
|
||||
SWGSDRangel::SWGChannelSettings& response,
|
||||
QString& errorMessage)
|
||||
{
|
||||
(void) errorMessage;
|
||||
AMDemod::webapiUpdateChannelSettings(m_settings, channelSettingsKeys, response);
|
||||
|
||||
return 200;
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_AMDEMOD_WEBAPIADAPTER_H
|
||||
#define INCLUDE_AMDEMOD_WEBAPIADAPTER_H
|
||||
|
||||
#include "channel/channelapi.h"
|
||||
#include "amdemodsettings.h"
|
||||
|
||||
/**
|
||||
* Standalone API adapter only for the settings
|
||||
*/
|
||||
class AMDemodWebAPIAdapter : public ChannelAPI {
|
||||
public:
|
||||
AMDemodWebAPIAdapter();
|
||||
virtual ~AMDemodWebAPIAdapter();
|
||||
|
||||
// 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:
|
||||
AMDemodSettings m_settings;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_AMDEMOD_WEBAPIADAPTER_H
|
||||
Reference in New Issue
Block a user