1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-11-11 08:40:44 -05:00

Websocket spectrum: server implementation

This commit is contained in:
f4exb 2020-05-06 09:50:43 +02:00
parent 37de6d4bb7
commit 7d076e5c9c
6 changed files with 197 additions and 5 deletions

View File

@ -20,6 +20,7 @@
#include "SWGGLSpectrum.h"
#include "SWGSpectrumServer.h"
#include "SWGSuccessResponse.h"
#include "glspectruminterface.h"
#include "dspcommands.h"
@ -816,6 +817,7 @@ int SpectrumVis::webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& respo
getMessageQueueToGUI()->push(msgToGui);
}
response.setMessage(new QString("Websocket spectrum server started"));
return 200;
}
@ -831,6 +833,7 @@ int SpectrumVis::webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& res
getMessageQueueToGUI()->push(msgToGui);
}
response.setMessage(new QString("Websocket spectrum server stopped"));
return 200;
}

View File

@ -19,6 +19,7 @@
#include "dsp/dspdevicesourceengine.h"
#include "dsp/dspdevicesinkengine.h"
#include "dsp/spectrumvis.h"
#include "plugin/pluginapi.h"
#include "plugin/plugininterface.h"
#include "settings/preset.h"
@ -34,17 +35,24 @@ DeviceSet::ChannelInstanceRegistration::ChannelInstanceRegistration(const QStrin
m_channelAPI(channelAPI)
{}
DeviceSet::DeviceSet(int tabIndex)
DeviceSet::DeviceSet(int tabIndex, int deviceType)
{
m_deviceAPI = nullptr;
m_deviceSourceEngine = nullptr;
m_deviceSinkEngine = nullptr;
m_deviceMIMOEngine = nullptr;
m_deviceTabIndex = tabIndex;
if ((deviceType == 0) || (deviceType == 2)) { // Single Rx or MIMO
m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF);
} else if (deviceType == 1) { // Single Tx
m_spectrumVis = new SpectrumVis(SDR_TX_SCALEF);
}
}
DeviceSet::~DeviceSet()
{
delete m_spectrumVis;
}
void DeviceSet::registerRxChannelInstance(const QString& channelName, ChannelAPI* channelAPI)
@ -466,3 +474,31 @@ bool DeviceSet::ChannelInstanceRegistration::operator<(const ChannelInstanceRegi
}
}
int DeviceSet::webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const
{
return m_spectrumVis->webapiSpectrumSettingsGet(response, errorMessage);
}
int DeviceSet::webapiSpectrumSettingsPutPatch(
bool force,
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response, // query + response
QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumSettingsPutPatch(force, spectrumSettingsKeys, response, errorMessage);
}
int DeviceSet::webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const
{
return m_spectrumVis->webapiSpectrumServerGet(response, errorMessage);
}
int DeviceSet::webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumServerPost(response, errorMessage);
}
int DeviceSet::webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumServerDelete(response, errorMessage);
}

View File

@ -27,6 +27,13 @@ class DSPDeviceMIMOEngine;
class PluginAPI;
class ChannelAPI;
class Preset;
class SpectrumVis;
namespace SWGSDRangel {
class SWGGLSpectrum;
class SWGSpectrumServer;
class SWGSuccessResponse;
};
class DeviceSet
{
@ -35,8 +42,9 @@ public:
DSPDeviceSourceEngine *m_deviceSourceEngine;
DSPDeviceSinkEngine *m_deviceSinkEngine;
DSPDeviceMIMOEngine *m_deviceMIMOEngine;
SpectrumVis *m_spectrumVis;
DeviceSet(int tabIndex);
DeviceSet(int tabIndex, int deviceType);
~DeviceSet();
int getNumberOfChannels() const { return m_channelInstanceRegistrations.size(); }
@ -58,6 +66,17 @@ public:
void loadMIMOChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
void saveMIMOChannelSettings(Preset* preset);
// REST API
int webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const;
int webapiSpectrumSettingsPutPatch(
bool force,
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response, // query + response
QString& errorMessage);
int webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const;
int webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage);
int webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage);
private:
struct ChannelInstanceRegistration
{

View File

@ -25,6 +25,7 @@
#include "dsp/dspdevicesourceengine.h"
#include "dsp/dspdevicesinkengine.h"
#include "dsp/dspdevicemimoengine.h"
#include "dsp/spectrumvis.h"
#include "device/deviceapi.h"
#include "device/deviceset.h"
#include "device/deviceenumerator.h"
@ -287,10 +288,11 @@ void MainCore::addSinkDevice()
sprintf(uidCStr, "UID:%d", dspDeviceSinkEngineUID);
int deviceTabIndex = m_deviceSets.size();
m_deviceSets.push_back(new DeviceSet(deviceTabIndex));
m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 1));
m_deviceSets.back()->m_deviceSourceEngine = nullptr;
m_deviceSets.back()->m_deviceSinkEngine = dspDeviceSinkEngine;
m_deviceSets.back()->m_deviceMIMOEngine = nullptr;
dspDeviceSinkEngine->addSpectrumSink(m_deviceSets.back()->m_spectrumVis);
char tabNameCStr[16];
sprintf(tabNameCStr, "T%d", deviceTabIndex);
@ -333,10 +335,11 @@ void MainCore::addSourceDevice()
sprintf(uidCStr, "UID:%d", dspDeviceSourceEngineUID);
int deviceTabIndex = m_deviceSets.size();
m_deviceSets.push_back(new DeviceSet(deviceTabIndex));
m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 0));
m_deviceSets.back()->m_deviceSourceEngine = dspDeviceSourceEngine;
m_deviceSets.back()->m_deviceSinkEngine = nullptr;
m_deviceSets.back()->m_deviceMIMOEngine = nullptr;
dspDeviceSourceEngine->addSink(m_deviceSets.back()->m_spectrumVis);
char tabNameCStr[16];
sprintf(tabNameCStr, "R%d", deviceTabIndex);
@ -378,10 +381,11 @@ void MainCore::addMIMODevice()
sprintf(uidCStr, "UID:%d", dspDeviceMIMOEngineUID);
int deviceTabIndex = m_deviceSets.size();
m_deviceSets.push_back(new DeviceSet(deviceTabIndex));
m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 2));
m_deviceSets.back()->m_deviceSourceEngine = nullptr;
m_deviceSets.back()->m_deviceSinkEngine = nullptr;
m_deviceSets.back()->m_deviceMIMOEngine = dspDeviceMIMOEngine;
dspDeviceMIMOEngine->addSpectrumSink(m_deviceSets.back()->m_spectrumVis);
char tabNameCStr[16];
sprintf(tabNameCStr, "M%d", deviceTabIndex);

View File

@ -1619,6 +1619,109 @@ int WebAPIAdapterSrv::devicesetDevicePut(
}
}
int WebAPIAdapterSrv::devicesetSpectrumSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGGLSpectrum& response,
SWGSDRangel::SWGErrorResponse& error)
{
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
{
const DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
return deviceSet->webapiSpectrumSettingsGet(response, *error.getMessage());
}
else
{
error.init();
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
return 404;
}
}
int WebAPIAdapterSrv::devicesetSpectrumSettingsPutPatch(
int deviceSetIndex,
bool force, //!< true to force settings = put else patch
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response,
SWGSDRangel::SWGErrorResponse& error)
{
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
{
DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
return deviceSet->webapiSpectrumSettingsPutPatch(force, spectrumSettingsKeys, response, *error.getMessage());
}
else
{
error.init();
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
return 404;
}
}
int WebAPIAdapterSrv::devicesetSpectrumServerGet(
int deviceSetIndex,
SWGSDRangel::SWGSpectrumServer& response,
SWGSDRangel::SWGErrorResponse& error)
{
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
{
const DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
deviceSet->webapiSpectrumServerGet(response, *error.getMessage());
return 200;
}
else
{
error.init();
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
return 404;
}
}
int WebAPIAdapterSrv::devicesetSpectrumServerPost(
int deviceSetIndex,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error)
{
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
{
DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
deviceSet->webapiSpectrumServerPost(response, *error.getMessage());
return 200;
}
else
{
error.init();
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
return 404;
}
}
int WebAPIAdapterSrv::devicesetSpectrumServerDelete(
int deviceSetIndex,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error)
{
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size()))
{
DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex];
deviceSet->webapiSpectrumServerDelete(response, *error.getMessage());
return 200;
}
else
{
error.init();
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
return 404;
}
}
int WebAPIAdapterSrv::devicesetDeviceSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response,

View File

@ -228,6 +228,33 @@ public:
SWGSDRangel::SWGDeviceListItem& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGGLSpectrum& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumSettingsPutPatch(
int deviceSetIndex,
bool force, //!< true to force settings = put else patch
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumServerGet(
int deviceSetIndex,
SWGSDRangel::SWGSpectrumServer& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumServerPost(
int deviceSetIndex,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumServerDelete(
int deviceSetIndex,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response,