From e69818cc454bcf746c1bcc63714e197ad8dd6fb0 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 6 May 2020 01:38:23 +0200 Subject: [PATCH] REST API: implemented GUI code for /sdrangel/deviceset/{deviceSetIndex}/spectrum/settings (PUT,PATCH) and /sdrangel/deviceset/{deviceSetIndex}/spectrum/server (POST,DELETE) --- sdrbase/dsp/spectrumvis.cpp | 140 +++++++++++++++++++++++++++++++++- sdrbase/dsp/spectrumvis.h | 12 +++ sdrgui/device/deviceuiset.cpp | 19 +++++ sdrgui/device/deviceuiset.h | 8 ++ sdrgui/gui/glspectrumgui.cpp | 85 ++++++++++++--------- sdrgui/gui/glspectrumgui.h | 1 + sdrgui/gui/glspectrumgui.ui | 3 + 7 files changed, 229 insertions(+), 39 deletions(-) diff --git a/sdrbase/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp index 9a89c774a..f0bc08d13 100644 --- a/sdrbase/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -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 peerHosts; QList 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(); + } +} diff --git a/sdrbase/dsp/spectrumvis.h b/sdrbase/dsp/spectrumvis.h index 92b9cf684..b9a439eb6 100644 --- a/sdrbase/dsp/spectrumvis.h +++ b/sdrbase/dsp/spectrumvis.h @@ -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 diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index 2b79627ef..56a8c5d53 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -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); +} diff --git a/sdrgui/device/deviceuiset.h b/sdrgui/device/deviceuiset.h index 5eb0e69cc..525e8331e 100644 --- a/sdrgui/device/deviceuiset.h +++ b/sdrgui/device/deviceuiset.h @@ -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 diff --git a/sdrgui/gui/glspectrumgui.cpp b/sdrgui/gui/glspectrumgui.cpp index f93876fb6..3d70a1050 100644 --- a/sdrgui/gui/glspectrumgui.cpp +++ b/sdrgui/gui/glspectrumgui.cpp @@ -165,36 +165,8 @@ void GLSpectrumGUI::applySettings() return; } - if (m_glSpectrum) - { - m_glSpectrum->setDisplayWaterfall(m_settings.m_displayWaterfall); - m_glSpectrum->setInvertedWaterfall(m_settings.m_invertedWaterfall); - m_glSpectrum->setDisplayMaxHold(m_settings.m_displayMaxHold); - m_glSpectrum->setDisplayCurrent(m_settings.m_displayCurrent); - m_glSpectrum->setDisplayHistogram(m_settings.m_displayHistogram); - 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 ? - 1 : - getAveragingValue(m_settings.m_averagingIndex, m_settings.m_averagingMode)); - } else { - m_glSpectrum->setTimingRate(1); - } - - Real refLevel = m_settings.m_linear ? pow(10.0, m_settings.m_refLevel/10.0) : m_settings.m_refLevel; - Real powerRange = m_settings.m_linear ? pow(10.0, m_settings.m_refLevel/10.0) : m_settings.m_powerRange; - qDebug("GLSpectrumGUI::applySettings: refLevel: %e powerRange: %e", refLevel, powerRange); - m_glSpectrum->setReferenceLevel(refLevel); - m_glSpectrum->setPowerRange(powerRange); - m_glSpectrum->setLinear(m_settings.m_linear); + if (m_glSpectrum) { + applyGLSpectrumSettings(); } if (m_spectrumVis) @@ -204,6 +176,36 @@ void GLSpectrumGUI::applySettings() } } +void GLSpectrumGUI::applyGLSpectrumSettings() +{ + m_glSpectrum->setDisplayWaterfall(m_settings.m_displayWaterfall); + m_glSpectrum->setInvertedWaterfall(m_settings.m_invertedWaterfall); + m_glSpectrum->setDisplayMaxHold(m_settings.m_displayMaxHold); + m_glSpectrum->setDisplayCurrent(m_settings.m_displayCurrent); + m_glSpectrum->setDisplayHistogram(m_settings.m_displayHistogram); + m_glSpectrum->setDecay(m_settings.m_decay); + m_glSpectrum->setDecayDivisor(m_settings.m_decayDivisor); + m_glSpectrum->setHistoStroke(m_settings.m_histogramStroke); + m_glSpectrum->setDisplayGrid(m_settings.m_displayGrid); + m_glSpectrum->setDisplayGridIntensity(m_settings.m_displayGridIntensity); + m_glSpectrum->setDisplayTraceIntensity(m_settings.m_displayTraceIntensity); + + 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 ? + 1 : + getAveragingValue(m_settings.m_averagingIndex, m_settings.m_averagingMode)); + } else { + m_glSpectrum->setTimingRate(1); + } + + Real refLevel = m_settings.m_linear ? pow(10.0, m_settings.m_refLevel/10.0) : m_settings.m_refLevel; + Real powerRange = m_settings.m_linear ? pow(10.0, m_settings.m_refLevel/10.0) : m_settings.m_powerRange; + qDebug("GLSpectrumGUI::applySettings: refLevel: %e powerRange: %e", refLevel, powerRange); + m_glSpectrum->setReferenceLevel(refLevel); + m_glSpectrum->setPowerRange(powerRange); + m_glSpectrum->setLinear(m_settings.m_linear); +} + 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(); + } + + return true; } - else if (SpectrumVis::MsgStartStop::match(message)) + 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; } diff --git a/sdrgui/gui/glspectrumgui.h b/sdrgui/gui/glspectrumgui.h index 88d7dfa7c..41309ef89 100644 --- a/sdrgui/gui/glspectrumgui.h +++ b/sdrgui/gui/glspectrumgui.h @@ -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); diff --git a/sdrgui/gui/glspectrumgui.ui b/sdrgui/gui/glspectrumgui.ui index bd12bb3ba..233bb22d9 100644 --- a/sdrgui/gui/glspectrumgui.ui +++ b/sdrgui/gui/glspectrumgui.ui @@ -704,6 +704,9 @@ :/stream.png + + true +