1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 17:28:50 -05:00

REST API: implemented GUI code for /sdrangel/deviceset/{deviceSetIndex}/spectrum/settings (PUT,PATCH) and /sdrangel/deviceset/{deviceSetIndex}/spectrum/server (POST,DELETE)

This commit is contained in:
f4exb 2020-05-06 01:38:23 +02:00
parent 327dd42ce2
commit e69818cc45
7 changed files with 229 additions and 39 deletions

View File

@ -790,8 +790,32 @@ int SpectrumVis::webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response,
return 200;
}
int SpectrumVis::webapiSpectrumSettingsPutPatch(
bool force,
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response, // query + response
QString& errorMessage)
{
(void) errorMessage;
GLSpectrumSettings settings = m_settings;
webapiUpdateSpectrumSettings(settings, spectrumSettingsKeys, response);
MsgConfigureSpectrumVis *msg = MsgConfigureSpectrumVis::create(settings, force);
m_inputMessageQueue.push(msg);
if (getMessageQueueToGUI()) // forward to GUI if any
{
MsgConfigureSpectrumVis *msgToGUI = MsgConfigureSpectrumVis::create(settings, force);
getMessageQueueToGUI()->push(msgToGUI);
}
webapiFormatSpectrumSettings(response, settings);
return 200;
}
int SpectrumVis::webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const
{
(void) errorMessage;
bool serverRunning = m_wsSpectrum.socketOpened();
QList<QHostAddress> peerHosts;
QList<quint16> peerPorts;
@ -810,6 +834,38 @@ int SpectrumVis::webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& respons
response.getClients()->back()->setPort(peerPorts.at(i));
}
}
return 200;
}
int SpectrumVis::webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage)
{
(void) errorMessage;
MsgConfigureWSpectrumOpenClose *msg = MsgConfigureWSpectrumOpenClose::create(true);
m_inputMessageQueue.push(msg);
if (getMessageQueueToGUI()) // forward to GUI if any
{
MsgConfigureWSpectrumOpenClose *msgToGui = MsgConfigureWSpectrumOpenClose::create(true);
getMessageQueueToGUI()->push(msgToGui);
}
return 200;
}
int SpectrumVis::webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage)
{
(void) errorMessage;
MsgConfigureWSpectrumOpenClose *msg = MsgConfigureWSpectrumOpenClose::create(false);
m_inputMessageQueue.push(msg);
if (getMessageQueueToGUI()) // forward to GUI if any
{
MsgConfigureWSpectrumOpenClose *msgToGui = MsgConfigureWSpectrumOpenClose::create(false);
getMessageQueueToGUI()->push(msgToGui);
}
return 200;
}
void SpectrumVis::webapiFormatSpectrumSettings(SWGSDRangel::SWGGLSpectrum& response, const GLSpectrumSettings& settings)
@ -832,7 +888,7 @@ void SpectrumVis::webapiFormatSpectrumSettings(SWGSDRangel::SWGGLSpectrum& respo
response.setDisplayHistogram(settings.m_displayHistogram ? 1 : 0);
response.setDisplayGrid(settings.m_displayGrid ? 1 : 0);
response.setAveragingMode((int) settings.m_averagingMode);
response.setAveragingValue(settings.m_averagingValue);
response.setAveragingValue(GLSpectrumSettings::getAveragingValue(settings.m_averagingIndex, settings.m_averagingMode));
response.setLinear(settings.m_linear ? 1 : 0);
response.setSsb(settings.m_ssb ? 1 : 0);
response.setUsb(settings.m_usb ? 1 : 0);
@ -844,3 +900,85 @@ void SpectrumVis::webapiFormatSpectrumSettings(SWGSDRangel::SWGGLSpectrum& respo
response.setWsSpectrumAddress(new QString(settings.m_wsSpectrumAddress));
}
}
void SpectrumVis::webapiUpdateSpectrumSettings(
GLSpectrumSettings& settings,
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response)
{
if (spectrumSettingsKeys.contains("fftSize")) {
settings.m_fftSize = response.getFftSize();
}
if (spectrumSettingsKeys.contains("fftOverlap")) {
settings.m_fftOverlap = response.getFftOverlap();
}
if (spectrumSettingsKeys.contains("fftWindow")) {
settings.m_fftWindow = (FFTWindow::Function) response.getFftWindow();
}
if (spectrumSettingsKeys.contains("refLevel")) {
settings.m_refLevel = response.getRefLevel();
}
if (spectrumSettingsKeys.contains("powerRange")) {
settings.m_powerRange = response.getPowerRange();
}
if (spectrumSettingsKeys.contains("decay")) {
settings.m_decay = response.getDecay();
}
if (spectrumSettingsKeys.contains("decayDivisor")) {
settings.m_decayDivisor = response.getDecayDivisor();
}
if (spectrumSettingsKeys.contains("histogramStroke")) {
settings.m_histogramStroke = response.getHistogramStroke();
}
if (spectrumSettingsKeys.contains("displayGridIntensity")) {
settings.m_displayGridIntensity = response.getDisplayGridIntensity();
}
if (spectrumSettingsKeys.contains("displayTraceIntensity")) {
settings.m_displayTraceIntensity = response.getDisplayTraceIntensity();
}
if (spectrumSettingsKeys.contains("displayWaterfall")) {
settings.m_displayWaterfall = response.getDisplayWaterfall() != 0;
}
if (spectrumSettingsKeys.contains("invertedWaterfall")) {
settings.m_invertedWaterfall = response.getInvertedWaterfall() != 0;
}
if (spectrumSettingsKeys.contains("waterfallShare")) {
settings.m_waterfallShare = response.getWaterfallShare();
}
if (spectrumSettingsKeys.contains("displayMaxHold")) {
settings.m_displayMaxHold = response.getDisplayMaxHold() != 0;
}
if (spectrumSettingsKeys.contains("displayCurrent")) {
settings.m_displayCurrent = response.getDisplayCurrent() != 0;
}
if (spectrumSettingsKeys.contains("displayHistogram")) {
settings.m_displayHistogram = response.getDisplayHistogram() != 0;
}
if (spectrumSettingsKeys.contains("displayGrid")) {
settings.m_displayGrid = response.getDisplayGrid() != 0;
}
if (spectrumSettingsKeys.contains("averagingMode")) {
settings.m_averagingMode = (GLSpectrumSettings::AveragingMode) response.getAveragingMode();
}
if (spectrumSettingsKeys.contains("averagingValue"))
{
qint32 tmp = response.getAveragingValue();
settings.m_averagingIndex = GLSpectrumSettings::getAveragingIndex(tmp, settings.m_averagingMode);
settings.m_averagingValue = GLSpectrumSettings::getAveragingValue(settings.m_averagingIndex, settings.m_averagingMode);
}
if (spectrumSettingsKeys.contains("linear")) {
settings.m_linear = response.getLinear() != 0;
}
if (spectrumSettingsKeys.contains("ssb")) {
settings.m_ssb = response.getSsb() != 0;
}
if (spectrumSettingsKeys.contains("usb")) {
settings.m_usb = response.getUsb() != 0;
}
if (spectrumSettingsKeys.contains("wsSpectrumAddress")) {
settings.m_wsSpectrumAddress = *response.getWsSpectrumAddress();
}
if (spectrumSettingsKeys.contains("wsSpectrumPort")) {
settings.m_wsSpectrumPort = response.getWsSpectrumPort();
}
}

View File

@ -40,6 +40,7 @@ class MessageQueue;
namespace SWGSDRangel {
class SWGGLSpectrum;
class SWGSpectrumServer;
class SWGSuccessResponse;
};
class SDRGUI_API SpectrumVis : public BasebandSampleSink {
@ -132,7 +133,14 @@ public:
virtual bool handleMessage(const Message& message);
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:
class MsgConfigureScalingFactor : public Message
@ -209,6 +217,10 @@ private:
void handleConfigureWSSpectrum(const QString& address, uint16_t port);
static void webapiFormatSpectrumSettings(SWGSDRangel::SWGGLSpectrum& response, const GLSpectrumSettings& settings);
static void webapiUpdateSpectrumSettings(
GLSpectrumSettings& settings,
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response);
};
#endif // INCLUDE_SPECTRUMVIS_H

View File

@ -456,7 +456,26 @@ int DeviceUISet::webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response,
return m_spectrumVis->webapiSpectrumSettingsGet(response, errorMessage);
}
int DeviceUISet::webapiSpectrumSettingsPutPatch(
bool force,
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response, // query + response
QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumSettingsPutPatch(force, spectrumSettingsKeys, response, errorMessage);
}
int DeviceUISet::webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const
{
return m_spectrumVis->webapiSpectrumServerGet(response, errorMessage);
}
int DeviceUISet::webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumServerPost(response, errorMessage);
}
int DeviceUISet::webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumServerDelete(response, errorMessage);
}

View File

@ -43,6 +43,7 @@ class Preset;
namespace SWGSDRangel {
class SWGGLSpectrum;
class SWGSpectrumServer;
class SWGSuccessResponse;
};
class SDRGUI_API DeviceUISet : public QObject
@ -91,7 +92,14 @@ public:
// 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

@ -165,7 +165,18 @@ void GLSpectrumGUI::applySettings()
return;
}
if (m_glSpectrum)
if (m_glSpectrum) {
applyGLSpectrumSettings();
}
if (m_spectrumVis)
{
SpectrumVis::MsgConfigureSpectrumVis *msg = SpectrumVis::MsgConfigureSpectrumVis::create(m_settings, false);
m_spectrumVis->getInputMessageQueue()->push(msg);
}
}
void GLSpectrumGUI::applyGLSpectrumSettings()
{
m_glSpectrum->setDisplayWaterfall(m_settings.m_displayWaterfall);
m_glSpectrum->setInvertedWaterfall(m_settings.m_invertedWaterfall);
@ -175,11 +186,9 @@ void GLSpectrumGUI::applySettings()
m_glSpectrum->setDecay(m_settings.m_decay);
m_glSpectrum->setDecayDivisor(m_settings.m_decayDivisor);
m_glSpectrum->setHistoStroke(m_settings.m_histogramStroke);
m_glSpectrum->setInvertedWaterfall(m_settings.m_invertedWaterfall);
m_glSpectrum->setDisplayGrid(m_settings.m_displayGrid);
m_glSpectrum->setDisplayGridIntensity(m_settings.m_displayGridIntensity);
m_glSpectrum->setDisplayTraceIntensity(m_settings.m_displayTraceIntensity);
m_glSpectrum->setWaterfallShare(m_settings.m_waterfallShare);
if ((m_settings.m_averagingMode == GLSpectrumSettings::AvgModeFixed) || (m_settings.m_averagingMode == GLSpectrumSettings::AvgModeMax)) {
m_glSpectrum->setTimingRate(getAveragingValue(m_settings.m_averagingIndex, m_settings.m_averagingMode) == 0 ?
@ -197,13 +206,6 @@ void GLSpectrumGUI::applySettings()
m_glSpectrum->setLinear(m_settings.m_linear);
}
if (m_spectrumVis)
{
SpectrumVis::MsgConfigureSpectrumVis *msg = SpectrumVis::MsgConfigureSpectrumVis::create(m_settings, false);
m_spectrumVis->getInputMessageQueue()->push(msg);
}
}
void GLSpectrumGUI::on_fftWindow_currentIndexChanged(int index)
{
qDebug("GLSpectrumGUI::on_fftWindow_currentIndexChanged: %d", index);
@ -505,17 +507,24 @@ bool GLSpectrumGUI::handleMessage(const Message& message)
setAveragingToolitp();
return true;
}
else if (GLSpectrum::MsgReportWaterfallShare::match(message))
else if (SpectrumVis::MsgConfigureSpectrumVis::match(message))
{
const GLSpectrum::MsgReportWaterfallShare& report = (const GLSpectrum::MsgReportWaterfallShare&) message;
m_settings.m_waterfallShare = report.getWaterfallShare();
SpectrumVis::MsgConfigureSpectrumVis& cfg = (SpectrumVis::MsgConfigureSpectrumVis&) message;
m_settings = cfg.getSettings();
displaySettings();
if (m_glSpectrum) {
applyGLSpectrumSettings();
}
else if (SpectrumVis::MsgStartStop::match(message))
return true;
}
else if (SpectrumVis::MsgConfigureWSpectrumOpenClose::match(message))
{
const SpectrumVis::MsgStartStop& msg = (SpectrumVis::MsgStartStop&) message;
ui->freeze->blockSignals(true);
ui->freeze->doToggle(!msg.getStartStop()); // this is a freeze so stop is true
ui->freeze->blockSignals(false);
SpectrumVis::MsgConfigureWSpectrumOpenClose& notif = (SpectrumVis::MsgConfigureWSpectrumOpenClose&) message;
ui->wsSpectrum->blockSignals(true);
ui->wsSpectrum->doToggle(notif.getOpenClose());
ui->wsSpectrum->blockSignals(false);
return true;
}

View File

@ -70,6 +70,7 @@ private:
void blockApplySettings(bool block);
void applySettings();
void applyGLSpectrumSettings();
void displaySettings();
static int getAveragingMaxScale(GLSpectrumSettings::AveragingMode averagingMode); //!< Max power of 10 multiplier to 2,5,10 base ex: 2 -> 2,5,10,20,50,100,200,500,1000
static int getAveragingIndex(int averaging, GLSpectrumSettings::AveragingMode averagingMode);

View File

@ -704,6 +704,9 @@
<normalon>:/stream.png</normalon>
</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>