1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-19 06:41:47 -05:00

SDRDaemon: Web API: implemented channel sink settings getter and setter

This commit is contained in:
f4exb 2018-08-23 18:17:15 +02:00
parent 5bf657cd9a
commit 4f43e51178
3 changed files with 171 additions and 4 deletions

View File

@ -25,6 +25,8 @@
#include <boost/crc.hpp> #include <boost/crc.hpp>
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
#include "SWGChannelSettings.h"
#include "util/simpleserializer.h" #include "util/simpleserializer.h"
#include "dsp/threadedbasebandsamplesink.h" #include "dsp/threadedbasebandsamplesink.h"
#include "dsp/downchannelizer.h" #include "dsp/downchannelizer.h"
@ -312,3 +314,63 @@ void SDRDaemonChannelSink::applySettings(const SDRDaemonChannelSinkSettings& set
m_settings = settings; m_settings = settings;
} }
int SDRDaemonChannelSink::webapiSettingsGet(
SWGSDRangel::SWGChannelSettings& response,
QString& errorMessage __attribute__((unused)))
{
response.setSdrDaemonChannelSinkSettings(new SWGSDRangel::SWGSDRDaemonChannelSinkSettings());
response.getSdrDaemonChannelSinkSettings()->init();
webapiFormatChannelSettings(response, m_settings);
return 200;
}
int SDRDaemonChannelSink::webapiSettingsPutPatch(
bool force,
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings& response,
QString& errorMessage __attribute__((unused)))
{
SDRDaemonChannelSinkSettings settings = m_settings;
if (channelSettingsKeys.contains("nbFECBlocks")) {
settings.m_nbFECBlocks = response.getSdrDaemonChannelSinkSettings()->getNbFecBlocks();
}
if (channelSettingsKeys.contains("txDelay")) {
settings.m_txDelay = response.getSdrDaemonChannelSinkSettings()->getTxDelay();
}
if (channelSettingsKeys.contains("dataAddress")) {
settings.m_dataAddress = *response.getSdrDaemonChannelSinkSettings()->getDataAddress();
}
if (channelSettingsKeys.contains("dataPort")) {
settings.m_dataPort = response.getSdrDaemonChannelSinkSettings()->getDataPort();
}
MsgConfigureSDRDaemonChannelSink *msg = MsgConfigureSDRDaemonChannelSink::create(settings, force);
m_inputMessageQueue.push(msg);
qDebug("SDRDaemonChannelSink::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureSDRDaemonChannelSink *msgToGUI = MsgConfigureSDRDaemonChannelSink::create(settings, force);
m_guiMessageQueue->push(msgToGUI);
}
webapiFormatChannelSettings(response, settings);
return 200;
}
void SDRDaemonChannelSink::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const SDRDaemonChannelSinkSettings& settings)
{
response.getSdrDaemonChannelSinkSettings()->setNbFecBlocks(settings.m_nbFECBlocks);
response.getSdrDaemonChannelSinkSettings()->setTxDelay(settings.m_txDelay);
if (response.getSdrDaemonChannelSinkSettings()->getDataAddress()) {
*response.getSdrDaemonChannelSinkSettings()->getDataAddress() = settings.m_dataAddress;
} else {
response.getSdrDaemonChannelSinkSettings()->setDataAddress(new QString(settings.m_dataAddress));
}
response.getSdrDaemonChannelSinkSettings()->setDataPort(settings.m_dataPort);
}

View File

@ -80,6 +80,16 @@ public:
virtual QByteArray serialize() const; virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data); virtual bool deserialize(const QByteArray& data);
virtual int webapiSettingsGet(
SWGSDRangel::SWGChannelSettings& response,
QString& errorMessage);
virtual int webapiSettingsPutPatch(
bool force,
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings& response,
QString& errorMessage);
/** Set center frequency given in Hz */ /** Set center frequency given in Hz */
void setCenterFrequency(uint64_t centerFrequency) { m_centerFrequency = centerFrequency / 1000; } void setCenterFrequency(uint64_t centerFrequency) { m_centerFrequency = centerFrequency / 1000; }
@ -123,6 +133,7 @@ private:
uint16_t m_dataPort; uint16_t m_dataPort;
void applySettings(const SDRDaemonChannelSinkSettings& settings, bool force = false); void applySettings(const SDRDaemonChannelSinkSettings& settings, bool force = false);
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const SDRDaemonChannelSinkSettings& settings);
}; };
#endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ */ #endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSINK_H_ */

View File

@ -31,6 +31,8 @@
#include "dsp/dspdevicesinkengine.h" #include "dsp/dspdevicesinkengine.h"
#include "device/devicesourceapi.h" #include "device/devicesourceapi.h"
#include "device/devicesinkapi.h" #include "device/devicesinkapi.h"
#include "channel/channelsourceapi.h"
#include "channel/channelsinkapi.h"
#include "dsp/devicesamplesink.h" #include "dsp/devicesamplesink.h"
#include "dsp/devicesamplesource.h" #include "dsp/devicesamplesource.h"
#include "webapiadapterdaemon.h" #include "webapiadapterdaemon.h"
@ -181,8 +183,46 @@ int WebAPIAdapterDaemon::daemonChannelSettingsGet(
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)
{ {
error.init(); error.init();
*error.getMessage() = "Not implemented";
return 501; if (m_sdrDaemonMain.m_deviceSourceEngine) // Rx
{
ChannelSinkAPI *channelAPI = m_sdrDaemonMain.m_deviceSourceAPI->getChanelAPIAt(0);
if (channelAPI == 0)
{
*error.getMessage() = QString("There is no channel");
return 500; // a SDRDaemon sink channel should have been created so this is a server error
}
else
{
response.setChannelType(new QString());
channelAPI->getIdentifier(*response.getChannelType());
response.setTx(0);
return channelAPI->webapiSettingsGet(response, *error.getMessage());
}
}
else if (m_sdrDaemonMain.m_deviceSinkEngine) // Tx
{
ChannelSourceAPI *channelAPI = m_sdrDaemonMain.m_deviceSinkAPI->getChanelAPIAt(0);
if (channelAPI == 0)
{
*error.getMessage() = QString("There is no channel");
return 500; // a SDRDaemon source channel should have been created so this is a server error
}
else
{
response.setChannelType(new QString());
channelAPI->getIdentifier(*response.getChannelType());
response.setTx(1);
return channelAPI->webapiSettingsGet(response, *error.getMessage());
}
}
else
{
*error.getMessage() = QString("Device not created error");
return 500;
}
} }
int WebAPIAdapterDaemon::daemonChannelSettingsPutPatch( int WebAPIAdapterDaemon::daemonChannelSettingsPutPatch(
@ -192,8 +232,62 @@ int WebAPIAdapterDaemon::daemonChannelSettingsPutPatch(
SWGSDRangel::SWGErrorResponse& error) SWGSDRangel::SWGErrorResponse& error)
{ {
error.init(); error.init();
*error.getMessage() = "Not implemented";
return 501; if (m_sdrDaemonMain.m_deviceSourceEngine) // Rx
{
ChannelSinkAPI *channelAPI = m_sdrDaemonMain.m_deviceSourceAPI->getChanelAPIAt(0);
if (channelAPI == 0)
{
*error.getMessage() = QString("There is no channel");
return 500;
}
else
{
QString channelType;
channelAPI->getIdentifier(channelType);
if (channelType == *response.getChannelType())
{
return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage());
}
else
{
*error.getMessage() = QString("Channel has wrong type. Found %1.").arg(channelType);
return 500;
}
}
}
else if (m_sdrDaemonMain.m_deviceSinkEngine) // Tx
{
ChannelSourceAPI *channelAPI = m_sdrDaemonMain.m_deviceSinkAPI->getChanelAPIAt(0);
if (channelAPI == 0)
{
*error.getMessage() = QString("There is no channel");
return 500;
}
else
{
QString channelType;
channelAPI->getIdentifier(channelType);
if (channelType == *response.getChannelType())
{
return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage());
}
else
{
*error.getMessage() = QString("Channel has wrong type. Found %3.").arg(channelType);
return 500;
}
}
}
else
{
*error.getMessage() = QString("DeviceSet error");
return 500;
}
} }
int WebAPIAdapterDaemon::daemonDeviceSettingsGet( int WebAPIAdapterDaemon::daemonDeviceSettingsGet(