diff --git a/sdrbase/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp index 330bd2fb7..9a89c774a 100644 --- a/sdrbase/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -18,6 +18,9 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// +#include "SWGGLSpectrum.h" +#include "SWGSpectrumServer.h" + #include "glspectruminterface.h" #include "dspcommands.h" #include "dspengine.h" @@ -778,3 +781,66 @@ void SpectrumVis::handleConfigureWSSpectrum(const QString& address, uint16_t por m_wsSpectrum.openSocket(); } } + +int SpectrumVis::webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const +{ + (void) errorMessage; + response.init(); + webapiFormatSpectrumSettings(response, m_settings); + return 200; +} + +int SpectrumVis::webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const +{ + bool serverRunning = m_wsSpectrum.socketOpened(); + QList peerHosts; + QList peerPorts; + m_wsSpectrum.getPeers(peerHosts, peerPorts); + response.init(); + response.setRun(serverRunning ? 1 : 0); + + if (peerHosts.size() > 0) + { + response.setClients(new QList); + + for (int i = 0; i < peerHosts.size(); i++) + { + response.getClients()->push_back(new SWGSDRangel::SWGSpectrumServer_clients); + response.getClients()->back()->setAddress(new QString(peerHosts.at(i).toString())); + response.getClients()->back()->setPort(peerPorts.at(i)); + } + } +} + +void SpectrumVis::webapiFormatSpectrumSettings(SWGSDRangel::SWGGLSpectrum& response, const GLSpectrumSettings& settings) +{ + response.setFftSize(settings.m_fftSize); + response.setFftOverlap(settings.m_fftOverlap); + response.setFftWindow((int) settings.m_fftWindow); + response.setRefLevel(settings.m_refLevel); + response.setPowerRange(settings.m_powerRange); + response.setDecay(settings.m_decay); + response.setDecayDivisor(settings.m_decayDivisor); + response.setHistogramStroke(settings.m_histogramStroke); + response.setDisplayGridIntensity(settings.m_displayGridIntensity); + response.setDisplayTraceIntensity(settings.m_displayTraceIntensity); + response.setDisplayWaterfall(settings.m_displayWaterfall ? 1 : 0); + response.setInvertedWaterfall(settings.m_invertedWaterfall ? 1 : 0); + response.setWaterfallShare(settings.m_waterfallShare); + response.setDisplayMaxHold(settings.m_displayMaxHold ? 1 : 0); + response.setDisplayCurrent(settings.m_displayCurrent ? 1 : 0); + 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.setLinear(settings.m_linear ? 1 : 0); + response.setSsb(settings.m_ssb ? 1 : 0); + response.setUsb(settings.m_usb ? 1 : 0); + response.setWsSpectrumPort(settings.m_wsSpectrumPort); + + if (response.getWsSpectrumAddress()) { + *response.getWsSpectrumAddress() = settings.m_wsSpectrumAddress; + } else { + response.setWsSpectrumAddress(new QString(settings.m_wsSpectrumAddress)); + } +} diff --git a/sdrbase/dsp/spectrumvis.h b/sdrbase/dsp/spectrumvis.h index 384926674..92b9cf684 100644 --- a/sdrbase/dsp/spectrumvis.h +++ b/sdrbase/dsp/spectrumvis.h @@ -37,7 +37,12 @@ class GLSpectrumInterface; class MessageQueue; -class SDRBASE_API SpectrumVis : public BasebandSampleSink { +namespace SWGSDRangel { + class SWGGLSpectrum; + class SWGSpectrumServer; +}; + +class SDRGUI_API SpectrumVis : public BasebandSampleSink { public: class SDRBASE_API MsgConfigureSpectrumVis : public Message { @@ -126,6 +131,9 @@ public: virtual void stop(); virtual bool handleMessage(const Message& message); + int webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const; + int webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const; + private: class MsgConfigureScalingFactor : public Message { @@ -199,6 +207,8 @@ private: void handleScalef(Real scalef); void handleWSOpenClose(bool openClose); void handleConfigureWSSpectrum(const QString& address, uint16_t port); + + static void webapiFormatSpectrumSettings(SWGSDRangel::SWGGLSpectrum& response, const GLSpectrumSettings& settings); }; #endif // INCLUDE_SPECTRUMVIS_H diff --git a/sdrbase/resources/webapi/doc/html2/index.html b/sdrbase/resources/webapi/doc/html2/index.html index b395b8c3d..e13223fa7 100644 --- a/sdrbase/resources/webapi/doc/html2/index.html +++ b/sdrbase/resources/webapi/doc/html2/index.html @@ -4753,6 +4753,10 @@ margin-bottom: 20px; "wsSpectrumAddress" : { "type" : "string", "description" : "IPv4 address of interface the websocket server is listening to" + }, + "wsSpectrumPort" : { + "type" : "integer", + "description" : "port on which the websocket server is listening" } }, "description" : "GLSpectrumGUI settings" @@ -44592,7 +44596,7 @@ except ApiException as e:
- Generated 2020-11-11T12:04:23.918+01:00 + Generated 2020-11-11T13:32:52.276+01:00
diff --git a/sdrbase/resources/webapi/doc/swagger/include/GLSpectrum.yaml b/sdrbase/resources/webapi/doc/swagger/include/GLSpectrum.yaml index 80baee044..6f96f7679 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/GLSpectrum.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/GLSpectrum.yaml @@ -64,4 +64,4 @@ GLSpectrum: type: string wsSpectrumPort: description: port on which the websocket server is listening - type: integer\ No newline at end of file + type: integer diff --git a/sdrbase/webapi/webapiadapterinterface.cpp b/sdrbase/webapi/webapiadapterinterface.cpp index 89ffce35d..67a71bf8c 100644 --- a/sdrbase/webapi/webapiadapterinterface.cpp +++ b/sdrbase/webapi/webapiadapterinterface.cpp @@ -44,6 +44,8 @@ QString WebAPIAdapterInterface::instanceDeviceSetURL = "/sdrangel/deviceset"; std::regex WebAPIAdapterInterface::devicesetURLRe("^/sdrangel/deviceset/([0-9]{1,2})$"); std::regex WebAPIAdapterInterface::devicesetFocusURLRe("^/sdrangel/deviceset/([0-9]{1,2})/focus$"); +std::regex WebAPIAdapterInterface::devicesetSpectrumSettingsURLRe("^/sdrangel/deviceset/([0-9]{1,2})/spectrum/settings$"); +std::regex WebAPIAdapterInterface::devicesetSpectrumServerURLRe("^/sdrangel/deviceset/([0-9]{1,2})/spectrum/server$"); std::regex WebAPIAdapterInterface::devicesetDeviceURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device$"); std::regex WebAPIAdapterInterface::devicesetDeviceSettingsURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device/settings$"); std::regex WebAPIAdapterInterface::devicesetDeviceRunURLRe("^/sdrangel/deviceset/([0-9]{1,2})/device/run$"); diff --git a/sdrbase/webapi/webapiadapterinterface.h b/sdrbase/webapi/webapiadapterinterface.h index bdef0205f..41628e875 100644 --- a/sdrbase/webapi/webapiadapterinterface.h +++ b/sdrbase/webapi/webapiadapterinterface.h @@ -67,6 +67,8 @@ namespace SWGSDRangel class SWGFeatureSettings; class SWGFeatureReport; class SWGFeatureActions; + class SWGGLSpectrum; + class SWGSpectrumServer; } class SDRBASE_API WebAPIAdapterInterface @@ -708,6 +710,90 @@ public: return 501; } + /** + * Handler of /sdrangel/deviceset/{devicesetIndex}/spectrum/settings (GET) + * returns the Http status code (default 501: not implemented) + */ + virtual int devicesetSpectrumSettingsGet( + int deviceSetIndex, + SWGSDRangel::SWGGLSpectrum& response, + SWGSDRangel::SWGErrorResponse& error) + { + (void) deviceSetIndex; + (void) response; + error.init(); + *error.getMessage() = QString("Function not implemented"); + return 501; + } + + /** + * Handler of /sdrangel/deviceset/{devicesetIndex}/spectrum/settings (PUT, PATCH) + * returns the Http status code (default 501: not implemented) + */ + virtual int devicesetSpectrumSettingsPutPatch( + int deviceSetIndex, + bool force, //!< true to force settings = put else patch + const QStringList& spectrumSettingsKeys, + SWGSDRangel::SWGGLSpectrum& response, + SWGSDRangel::SWGErrorResponse& error) + { + (void) deviceSetIndex; + (void) force; + (void) spectrumSettingsKeys; + (void) response; + error.init(); + *error.getMessage() = QString("Function not implemented"); + return 501; + } + + /** + * Handler of /sdrangel/deviceset/{devicesetIndex}/spectrum/server (GET) + * returns the Http status code (default 501: not implemented) + */ + virtual int devicesetSpectrumServerGet( + int deviceSetIndex, + SWGSDRangel::SWGSpectrumServer& response, + SWGSDRangel::SWGErrorResponse& error) + { + (void) deviceSetIndex; + (void) response; + error.init(); + *error.getMessage() = QString("Function not implemented"); + return 501; + } + + /** + * Handler of /sdrangel/deviceset/{devicesetIndex}/spectrum/server (POST) + * returns the Http status code (default 501: not implemented) + */ + virtual int devicesetSpectrumServerPost( + int deviceSetIndex, + SWGSDRangel::SWGSuccessResponse& response, + SWGSDRangel::SWGErrorResponse& error) + { + (void) deviceSetIndex; + (void) response; + error.init(); + *error.getMessage() = QString("Function not implemented"); + return 501; + } + + /** + * Handler of /sdrangel/deviceset/{devicesetIndex}/spectrum/server (DELETE) + * returns the Http status code (default 501: not implemented) + */ + virtual int devicesetSpectrumServerDelete( + int deviceSetIndex, + SWGSDRangel::SWGSuccessResponse& response, + SWGSDRangel::SWGErrorResponse& error) + { + (void) deviceSetIndex; + (void) response; + error.init(); + *error.getMessage() = QString("Function not implemented"); + return 501; + } + /** * Handler of /sdrangel/deviceset/{devicesetIndex}/device (PUT) swagger/sdrangel/code/html2/index.html#api-Default-instanceChannels * returns the Http status code (default 501: not implemented) @@ -1249,6 +1335,8 @@ public: static QString instanceDeviceSetURL; static std::regex devicesetURLRe; static std::regex devicesetFocusURLRe; + static std::regex devicesetSpectrumSettingsURLRe; + static std::regex devicesetSpectrumServerURLRe; static std::regex devicesetDeviceURLRe; static std::regex devicesetDeviceSettingsURLRe; static std::regex devicesetDeviceRunURLRe; diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index 54c51d8af..38c2c40c6 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -56,6 +56,8 @@ #include "SWGFeatureSettings.h" #include "SWGFeatureReport.h" #include "SWGFeatureActions.h" +#include "SWGGLSpectrum.h" +#include "SWGSpectrumServer.h" WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) : HttpRequestHandler(parent), @@ -161,6 +163,10 @@ void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::Http devicesetDeviceService(std::string(desc_match[1]), request, response); } else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetFocusURLRe)) { devicesetFocusService(std::string(desc_match[1]), request, response); + } else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetSpectrumSettingsURLRe)) { + devicesetSpectrumSettingsService(std::string(desc_match[1]), request, response); + } else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetSpectrumServerURLRe)) { + devicesetSpectrumServerService(std::string(desc_match[1]), request, response); } else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceSettingsURLRe)) { devicesetDeviceSettingsService(std::string(desc_match[1]), request, response); } else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceRunURLRe)) { @@ -1483,6 +1489,155 @@ void WebAPIRequestMapper::devicesetFocusService(const std::string& indexStr, qtw } } +void WebAPIRequestMapper::devicesetSpectrumSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response) +{ + SWGSDRangel::SWGErrorResponse errorResponse; + response.setHeader("Content-Type", "application/json"); + response.setHeader("Access-Control-Allow-Origin", "*"); + + try + { + int deviceSetIndex = boost::lexical_cast(indexStr); + + if ((request.getMethod() == "PUT") || (request.getMethod() == "PATCH")) + { + QString jsonStr = request.getBody(); + QJsonObject jsonObject; + + if (parseJsonBody(jsonStr, jsonObject, response)) + { + SWGSDRangel::SWGGLSpectrum normalResponse; + resetSpectrumSettings(normalResponse); + QStringList spectrumSettingsKeys; + + if (validateSpectrumSettings(normalResponse, jsonObject, spectrumSettingsKeys)) + { + int status = m_adapter->devicesetSpectrumSettingsPutPatch( + deviceSetIndex, + (request.getMethod() == "PUT"), // force settings on PUT + spectrumSettingsKeys, + normalResponse, + errorResponse); + response.setStatus(status); + + if (status/100 == 2) { + response.write(normalResponse.asJson().toUtf8()); + } else { + response.write(errorResponse.asJson().toUtf8()); + } + } + else + { + response.setStatus(400,"Invalid JSON request"); + errorResponse.init(); + *errorResponse.getMessage() = "Invalid JSON request"; + response.write(errorResponse.asJson().toUtf8()); + } + } + else + { + response.setStatus(400,"Invalid JSON format"); + errorResponse.init(); + *errorResponse.getMessage() = "Invalid JSON format"; + response.write(errorResponse.asJson().toUtf8()); + } + } + else if (request.getMethod() == "GET") + { + SWGSDRangel::SWGGLSpectrum normalResponse; + resetSpectrumSettings(normalResponse); + int status = m_adapter->devicesetSpectrumSettingsGet(deviceSetIndex, normalResponse, errorResponse); + response.setStatus(status); + + if (status/100 == 2) { + response.write(normalResponse.asJson().toUtf8()); + } else { + response.write(errorResponse.asJson().toUtf8()); + } + } + else + { + response.setStatus(405,"Invalid HTTP method"); + errorResponse.init(); + *errorResponse.getMessage() = "Invalid HTTP method"; + response.write(errorResponse.asJson().toUtf8()); + } + } + catch (const boost::bad_lexical_cast &e) + { + errorResponse.init(); + *errorResponse.getMessage() = "Wrong integer conversion on device set index"; + response.setStatus(400,"Invalid data"); + response.write(errorResponse.asJson().toUtf8()); + } +} + +void WebAPIRequestMapper::devicesetSpectrumServerService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response) +{ + SWGSDRangel::SWGErrorResponse errorResponse; + response.setHeader("Content-Type", "application/json"); + response.setHeader("Access-Control-Allow-Origin", "*"); + + try + { + int deviceSetIndex = boost::lexical_cast(indexStr); + + if (request.getMethod() == "GET") + { + SWGSDRangel::SWGSpectrumServer normalResponse; + int status = m_adapter->devicesetSpectrumServerGet(deviceSetIndex, normalResponse, errorResponse); + + response.setStatus(status); + + if (status/100 == 2) { + response.write(normalResponse.asJson().toUtf8()); + } else { + response.write(errorResponse.asJson().toUtf8()); + } + } + else if (request.getMethod() == "POST") + { + SWGSDRangel::SWGSuccessResponse normalResponse; + int status = m_adapter->devicesetSpectrumServerPost(deviceSetIndex, normalResponse, errorResponse); + + response.setStatus(status); + + if (status/100 == 2) { + response.write(normalResponse.asJson().toUtf8()); + } else { + response.write(errorResponse.asJson().toUtf8()); + } + } + else if (request.getMethod() == "DELETE") + { + SWGSDRangel::SWGSuccessResponse normalResponse; + int status = m_adapter->devicesetSpectrumServerDelete(deviceSetIndex, normalResponse, errorResponse); + + response.setStatus(status); + + if (status/100 == 2) { + response.write(normalResponse.asJson().toUtf8()); + } else { + response.write(errorResponse.asJson().toUtf8()); + } + } + else + { + response.setStatus(405,"Invalid HTTP method"); + errorResponse.init(); + *errorResponse.getMessage() = "Invalid HTTP method"; + response.write(errorResponse.asJson().toUtf8()); + } + } + catch (const boost::bad_lexical_cast &e) + { + errorResponse.init(); + *errorResponse.getMessage() = "Wrong integer conversion on device set index"; + response.setStatus(400,"Invalid data"); + response.write(errorResponse.asJson().toUtf8()); + } +} + void WebAPIRequestMapper::devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response) { SWGSDRangel::SWGErrorResponse errorResponse; @@ -3209,6 +3364,125 @@ bool WebAPIRequestMapper::validateLimeRFEConfig(SWGSDRangel::SWGLimeRFESettings& return true; } +bool WebAPIRequestMapper::validateSpectrumSettings(SWGSDRangel::SWGGLSpectrum& spectrumSettings, QJsonObject& jsonObject, QStringList& spectrumSettingsKeys) +{ + if (jsonObject.contains("fftSize")) + { + spectrumSettings.setFftSize(jsonObject["fftSize"].toInt(1024)); + spectrumSettingsKeys.append("fftSize"); + } + if (jsonObject.contains("fftOverlap")) + { + spectrumSettings.setFftOverlap(jsonObject["fftOverlap"].toInt(0)); + spectrumSettingsKeys.append("fftOverlap"); + } + if (jsonObject.contains("fftWindow")) + { + spectrumSettings.setFftWindow(jsonObject["fftWindow"].toInt(0)); + spectrumSettingsKeys.append("fftWindow"); + } + if (jsonObject.contains("refLevel")) + { + spectrumSettings.setRefLevel(jsonObject["refLevel"].toDouble(0.0)); + spectrumSettingsKeys.append("refLevel"); + } + if (jsonObject.contains("powerRange")) + { + spectrumSettings.setPowerRange(jsonObject["powerRange"].toDouble(100.0)); + spectrumSettingsKeys.append("powerRange"); + } + if (jsonObject.contains("displayWaterfall")) + { + spectrumSettings.setDisplayWaterfall(jsonObject["displayWaterfall"].toInt(0)); + spectrumSettingsKeys.append("displayWaterfall"); + } + if (jsonObject.contains("invertedWaterfall")) + { + spectrumSettings.setInvertedWaterfall(jsonObject["invertedWaterfall"].toInt(0)); + spectrumSettingsKeys.append("invertedWaterfall"); + } + if (jsonObject.contains("displayHistogram")) + { + spectrumSettings.setDisplayHistogram(jsonObject["displayHistogram"].toInt(0)); + spectrumSettingsKeys.append("displayHistogram"); + } + if (jsonObject.contains("decay")) + { + spectrumSettings.setDecay(jsonObject["decay"].toInt(1)); + spectrumSettingsKeys.append("decay"); + } + if (jsonObject.contains("displayGrid")) + { + spectrumSettings.setDisplayGrid(jsonObject["displayGrid"].toInt(0)); + spectrumSettingsKeys.append("displayGrid"); + } + if (jsonObject.contains("displayGridIntensity")) + { + spectrumSettings.setDisplayGridIntensity(jsonObject["displayGridIntensity"].toInt(30)); + spectrumSettingsKeys.append("displayGridIntensity"); + } + if (jsonObject.contains("decayDivisor")) + { + spectrumSettings.setDecayDivisor(jsonObject["decayDivisor"].toInt(1)); + spectrumSettingsKeys.append("decayDivisor"); + } + if (jsonObject.contains("histogramStroke")) + { + spectrumSettings.setHistogramStroke(jsonObject["histogramStroke"].toInt(10)); + spectrumSettingsKeys.append("histogramStroke"); + } + if (jsonObject.contains("displayCurrent")) + { + spectrumSettings.setDisplayCurrent(jsonObject["displayCurrent"].toInt(1)); + spectrumSettingsKeys.append("displayCurrent"); + } + if (jsonObject.contains("displayTraceIntensity")) + { + spectrumSettings.setDisplayTraceIntensity(jsonObject["displayTraceIntensity"].toInt(50)); + spectrumSettingsKeys.append("displayTraceIntensity"); + } + if (jsonObject.contains("waterfallShare")) + { + spectrumSettings.setWaterfallShare(jsonObject["waterfallShare"].toDouble(0.5)); + spectrumSettingsKeys.append("waterfallShare"); + } + if (jsonObject.contains("averagingMode")) + { + spectrumSettings.setAveragingMode(jsonObject["averagingMode"].toInt(0)); + spectrumSettingsKeys.append("averagingMode"); + } + if (jsonObject.contains("averagingValue")) + { + spectrumSettings.setAveragingValue(jsonObject["averagingValue"].toInt(0)); + spectrumSettingsKeys.append("averagingValue"); + } + if (jsonObject.contains("linear")) + { + spectrumSettings.setLinear(jsonObject["linear"].toInt(0)); + spectrumSettingsKeys.append("linear"); + } + if (jsonObject.contains("ssb")) + { + spectrumSettings.setSsb(jsonObject["ssb"].toInt(0)); + spectrumSettingsKeys.append("ssb"); + } + if (jsonObject.contains("usb")) + { + spectrumSettings.setUsb(jsonObject["usb"].toInt(1)); + spectrumSettingsKeys.append("usb"); + } + if (jsonObject.contains("wsSpectrumAddress") && jsonObject["wsSpectrumAddress"].isString()) + { + spectrumSettings.setWsSpectrumAddress(new QString(jsonObject["wsSpectrumAddress"].toString())); + spectrumSettingsKeys.append("wsSpectrumAddress"); + } + if (jsonObject.contains("wsSpectrumPort")) + { + spectrumSettings.setUsb(jsonObject["wsSpectrumPort"].toInt(8887)); + spectrumSettingsKeys.append("wsSpectrumPort"); + } +} + bool WebAPIRequestMapper::validateConfig( SWGSDRangel::SWGInstanceConfigResponse& config, QJsonObject& jsonObject, @@ -4182,6 +4456,11 @@ void WebAPIRequestMapper::appendSettingsArrayKeys( } } +void WebAPIRequestMapper::resetSpectrumSettings(SWGSDRangel::SWGGLSpectrum& spectrumSettings) +{ + spectrumSettings.cleanup(); +} + void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings) { deviceSettings.cleanup(); diff --git a/sdrbase/webapi/webapirequestmapper.h b/sdrbase/webapi/webapirequestmapper.h index fcd10246a..639d3d6c0 100644 --- a/sdrbase/webapi/webapirequestmapper.h +++ b/sdrbase/webapi/webapirequestmapper.h @@ -80,6 +80,8 @@ private: void devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void devicesetFocusService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); + void devicesetSpectrumSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); + void devicesetSpectrumServerService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void devicesetDeviceSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); void devicesetDeviceRunService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response); @@ -104,6 +106,7 @@ private: bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer); bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier); bool validatePresetExport(SWGSDRangel::SWGPresetExport& presetExport); + bool validateSpectrumSettings(SWGSDRangel::SWGGLSpectrum& spectrumSettings, QJsonObject& jsonObject, QStringList& spectrumSettingsKeys); bool validateDeviceListItem(SWGSDRangel::SWGDeviceListItem& deviceListItem, QJsonObject& jsonObject); bool validateDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings, QJsonObject& jsonObject, QStringList& deviceSettingsKeys); bool validateDeviceActions(SWGSDRangel::SWGDeviceActions& deviceActions, QJsonObject& jsonObject, QStringList& deviceActionsKeys); @@ -201,6 +204,7 @@ private: bool parseJsonBody(QString& jsonStr, QJsonObject& jsonObject, qtwebapp::HttpResponse& response); + void resetSpectrumSettings(SWGSDRangel::SWGGLSpectrum& spectrumSettings); void resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings); void resetDeviceReport(SWGSDRangel::SWGDeviceReport& deviceReport); void resetDeviceActions(SWGSDRangel::SWGDeviceActions& deviceActions); diff --git a/sdrbase/websockets/wsspectrum.cpp b/sdrbase/websockets/wsspectrum.cpp index 1b79abb4f..a1d44d9fc 100644 --- a/sdrbase/websockets/wsspectrum.cpp +++ b/sdrbase/websockets/wsspectrum.cpp @@ -73,11 +73,23 @@ void WSSpectrum::closeSocket() } } -bool WSSpectrum::socketOpened() +bool WSSpectrum::socketOpened() const { return m_webSocketServer && m_webSocketServer->isListening(); } +void WSSpectrum::getPeers(QList& hosts, QList& ports) const +{ + hosts.clear(); + ports.clear(); + + for (auto pSocket : m_clients) + { + hosts.push_back(pSocket->peerAddress()); + ports.push_back(pSocket->peerPort()); + } +} + QString WSSpectrum::getWebSocketIdentifier(QWebSocket *peer) { return QStringLiteral("%1:%2").arg(peer->peerAddress().toString(), QString::number(peer->peerPort())); diff --git a/sdrbase/websockets/wsspectrum.h b/sdrbase/websockets/wsspectrum.h index bcc092c2a..7b2409a5e 100644 --- a/sdrbase/websockets/wsspectrum.h +++ b/sdrbase/websockets/wsspectrum.h @@ -41,7 +41,8 @@ public: void openSocket(); void closeSocket(); - bool socketOpened(); + bool socketOpened() const; + void getPeers(QList& hosts, QList& ports) const; void setListeningAddress(const QString& address) { m_listeningAddress.setAddress(address); } void setPort(quint16 port) { m_port = port; } void newSpectrum( diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index 469901c39..2b79627ef 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -450,3 +450,13 @@ void DeviceUISet::handleChannelGUIClosing(ChannelGUI* channelGUI) } } } + +int DeviceUISet::webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const +{ + return m_spectrumVis->webapiSpectrumSettingsGet(response, errorMessage); +} + +int DeviceUISet::webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const +{ + return m_spectrumVis->webapiSpectrumServerGet(response, errorMessage); +} diff --git a/sdrgui/device/deviceuiset.h b/sdrgui/device/deviceuiset.h index d67219ad3..5eb0e69cc 100644 --- a/sdrgui/device/deviceuiset.h +++ b/sdrgui/device/deviceuiset.h @@ -40,6 +40,11 @@ class ChannelAPI; class ChannelGUI; class Preset; +namespace SWGSDRangel { + class SWGGLSpectrum; + class SWGSpectrumServer; +}; + class SDRGUI_API DeviceUISet : public QObject { Q_OBJECT @@ -84,6 +89,10 @@ public: int getNumberOfAvailableTxChannels() const { return m_nbAvailableTxChannels; } int getNumberOfAvailableMIMOChannels() const { return m_nbAvailableMIMOChannels; } + // REST API + int webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const; + int webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const; + private: struct ChannelInstanceRegistration { diff --git a/swagger/sdrangel/api/swagger/include/GLSpectrum.yaml b/swagger/sdrangel/api/swagger/include/GLSpectrum.yaml index 80baee044..6f96f7679 100644 --- a/swagger/sdrangel/api/swagger/include/GLSpectrum.yaml +++ b/swagger/sdrangel/api/swagger/include/GLSpectrum.yaml @@ -64,4 +64,4 @@ GLSpectrum: type: string wsSpectrumPort: description: port on which the websocket server is listening - type: integer\ No newline at end of file + type: integer diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index b395b8c3d..e13223fa7 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -4753,6 +4753,10 @@ margin-bottom: 20px; "wsSpectrumAddress" : { "type" : "string", "description" : "IPv4 address of interface the websocket server is listening to" + }, + "wsSpectrumPort" : { + "type" : "integer", + "description" : "port on which the websocket server is listening" } }, "description" : "GLSpectrumGUI settings" @@ -44592,7 +44596,7 @@ except ApiException as e:
- Generated 2020-11-11T12:04:23.918+01:00 + Generated 2020-11-11T13:32:52.276+01:00
diff --git a/swagger/sdrangel/code/qt5/client/SWGGLSpectrum.cpp b/swagger/sdrangel/code/qt5/client/SWGGLSpectrum.cpp index 0ea75bcf7..fb657963e 100644 --- a/swagger/sdrangel/code/qt5/client/SWGGLSpectrum.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGGLSpectrum.cpp @@ -74,6 +74,8 @@ SWGGLSpectrum::SWGGLSpectrum() { m_usb_isSet = false; ws_spectrum_address = nullptr; m_ws_spectrum_address_isSet = false; + ws_spectrum_port = 0; + m_ws_spectrum_port_isSet = false; } SWGGLSpectrum::~SWGGLSpectrum() { @@ -128,6 +130,8 @@ SWGGLSpectrum::init() { m_usb_isSet = false; ws_spectrum_address = new QString(""); m_ws_spectrum_address_isSet = false; + ws_spectrum_port = 0; + m_ws_spectrum_port_isSet = false; } void @@ -157,6 +161,7 @@ SWGGLSpectrum::cleanup() { if(ws_spectrum_address != nullptr) { delete ws_spectrum_address; } + } SWGGLSpectrum* @@ -216,6 +221,8 @@ SWGGLSpectrum::fromJsonObject(QJsonObject &pJson) { ::SWGSDRangel::setValue(&ws_spectrum_address, pJson["wsSpectrumAddress"], "QString", "QString"); + ::SWGSDRangel::setValue(&ws_spectrum_port, pJson["wsSpectrumPort"], "qint32", ""); + } QString @@ -301,6 +308,9 @@ SWGGLSpectrum::asJsonObject() { if(ws_spectrum_address != nullptr && *ws_spectrum_address != QString("")){ toJsonValue(QString("wsSpectrumAddress"), ws_spectrum_address, obj, QString("QString")); } + if(m_ws_spectrum_port_isSet){ + obj->insert("wsSpectrumPort", QJsonValue(ws_spectrum_port)); + } return obj; } @@ -535,6 +545,16 @@ SWGGLSpectrum::setWsSpectrumAddress(QString* ws_spectrum_address) { this->m_ws_spectrum_address_isSet = true; } +qint32 +SWGGLSpectrum::getWsSpectrumPort() { + return ws_spectrum_port; +} +void +SWGGLSpectrum::setWsSpectrumPort(qint32 ws_spectrum_port) { + this->ws_spectrum_port = ws_spectrum_port; + this->m_ws_spectrum_port_isSet = true; +} + bool SWGGLSpectrum::isSet(){ @@ -609,6 +629,9 @@ SWGGLSpectrum::isSet(){ if(ws_spectrum_address && *ws_spectrum_address != QString("")){ isObjectUpdated = true; break; } + if(m_ws_spectrum_port_isSet){ + isObjectUpdated = true; break; + } }while(false); return isObjectUpdated; } diff --git a/swagger/sdrangel/code/qt5/client/SWGGLSpectrum.h b/swagger/sdrangel/code/qt5/client/SWGGLSpectrum.h index ceb957c98..60ad20ef4 100644 --- a/swagger/sdrangel/code/qt5/client/SWGGLSpectrum.h +++ b/swagger/sdrangel/code/qt5/client/SWGGLSpectrum.h @@ -111,6 +111,9 @@ public: QString* getWsSpectrumAddress(); void setWsSpectrumAddress(QString* ws_spectrum_address); + qint32 getWsSpectrumPort(); + void setWsSpectrumPort(qint32 ws_spectrum_port); + virtual bool isSet() override; @@ -184,6 +187,9 @@ private: QString* ws_spectrum_address; bool m_ws_spectrum_address_isSet; + qint32 ws_spectrum_port; + bool m_ws_spectrum_port_isSet; + }; }