mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-05-01 11:53:58 -04:00
REST API: implemented GUI code for /sdrangel/deviceset/{deviceSetIndex}/spectrum/settings (GET) and /sdrangel/deviceset/{deviceSetIndex}/spectrum/server (GET)
This commit is contained in:
parent
0bfea9df22
commit
c633250fe5
@ -18,6 +18,9 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SWGGLSpectrum.h"
|
||||
#include "SWGSpectrumServer.h"
|
||||
|
||||
#include "glspectruminterface.h"
|
||||
#include "dspcommands.h"
|
||||
#include "dspengine.h"
|
||||
@ -743,4 +746,67 @@ void SpectrumVis::handleConfigureWSSpectrum(const QString& address, uint16_t por
|
||||
m_wsSpectrum.setPort(port);
|
||||
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<QHostAddress> peerHosts;
|
||||
QList<quint16> peerPorts;
|
||||
m_wsSpectrum.getPeers(peerHosts, peerPorts);
|
||||
response.init();
|
||||
response.setRun(serverRunning ? 1 : 0);
|
||||
|
||||
if (peerHosts.size() > 0)
|
||||
{
|
||||
response.setClients(new QList<SWGSDRangel::SWGSpectrumServer_clients*>);
|
||||
|
||||
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_averagingNb);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,6 +37,11 @@
|
||||
class GLSpectrumInterface;
|
||||
class MessageQueue;
|
||||
|
||||
namespace SWGSDRangel {
|
||||
class SWGGLSpectrum;
|
||||
class SWGSpectrumServer;
|
||||
};
|
||||
|
||||
class SDRGUI_API SpectrumVis : public BasebandSampleSink {
|
||||
|
||||
public:
|
||||
@ -105,6 +110,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
|
||||
{
|
||||
@ -175,6 +183,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
|
||||
|
||||
@ -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$");
|
||||
|
||||
@ -62,6 +62,8 @@ namespace SWGSDRangel
|
||||
class SWGChannelReport;
|
||||
class SWGChannelActions;
|
||||
class SWGSuccessResponse;
|
||||
class SWGGLSpectrum;
|
||||
class SWGSpectrumServer;
|
||||
}
|
||||
|
||||
class SDRBASE_API WebAPIAdapterInterface
|
||||
@ -690,6 +692,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)
|
||||
@ -1041,6 +1127,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;
|
||||
|
||||
@ -51,6 +51,8 @@
|
||||
#include "SWGChannelActions.h"
|
||||
#include "SWGSuccessResponse.h"
|
||||
#include "SWGErrorResponse.h"
|
||||
#include "SWGGLSpectrum.h"
|
||||
#include "SWGSpectrumServer.h"
|
||||
|
||||
const QMap<QString, QString> WebAPIRequestMapper::m_channelURIToSettingsKey = {
|
||||
{"sdrangel.channel.amdemod", "AMDemodSettings"},
|
||||
@ -338,6 +340,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)) {
|
||||
@ -1646,6 +1652,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<int>(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<int>(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;
|
||||
@ -2475,6 +2630,125 @@ bool WebAPIRequestMapper::validatePresetExport(SWGSDRangel::SWGPresetExport& pre
|
||||
return validatePresetIdentifer(*presetIdentifier);
|
||||
}
|
||||
|
||||
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::validateDeviceListItem(SWGSDRangel::SWGDeviceListItem& deviceListItem, QJsonObject& jsonObject)
|
||||
{
|
||||
if (jsonObject.contains("direction")) {
|
||||
@ -3681,6 +3955,11 @@ void WebAPIRequestMapper::appendSettingsArrayKeys(
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPIRequestMapper::resetSpectrumSettings(SWGSDRangel::SWGGLSpectrum& spectrumSettings)
|
||||
{
|
||||
spectrumSettings.cleanup();
|
||||
}
|
||||
|
||||
void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings)
|
||||
{
|
||||
deviceSettings.cleanup();
|
||||
|
||||
@ -77,6 +77,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);
|
||||
@ -93,6 +95,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);
|
||||
@ -162,6 +165,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);
|
||||
|
||||
@ -73,11 +73,23 @@ void WSSpectrum::closeSocket()
|
||||
}
|
||||
}
|
||||
|
||||
bool WSSpectrum::socketOpened()
|
||||
bool WSSpectrum::socketOpened() const
|
||||
{
|
||||
return m_webSocketServer && m_webSocketServer->isListening();
|
||||
}
|
||||
|
||||
void WSSpectrum::getPeers(QList<QHostAddress>& hosts, QList<quint16>& 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()));
|
||||
|
||||
@ -41,7 +41,8 @@ public:
|
||||
|
||||
void openSocket();
|
||||
void closeSocket();
|
||||
bool socketOpened();
|
||||
bool socketOpened() const;
|
||||
void getPeers(QList<QHostAddress>& hosts, QList<quint16>& ports) const;
|
||||
void setListeningAddress(const QString& address) { m_listeningAddress.setAddress(address); }
|
||||
void setPort(quint16 port) { m_port = port; }
|
||||
void newSpectrum(
|
||||
|
||||
@ -436,3 +436,12 @@ bool DeviceUISet::ChannelInstanceRegistration::operator<(const ChannelInstanceRe
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -37,6 +37,11 @@ class PluginAPI;
|
||||
class PluginInstanceGUI;
|
||||
class Preset;
|
||||
|
||||
namespace SWGSDRangel {
|
||||
class SWGGLSpectrum;
|
||||
class SWGSpectrumServer;
|
||||
};
|
||||
|
||||
class SDRGUI_API DeviceUISet
|
||||
{
|
||||
public:
|
||||
@ -83,6 +88,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
|
||||
{
|
||||
|
||||
@ -1415,6 +1415,46 @@ int WebAPIAdapterGUI::devicesetFocusPatch(
|
||||
}
|
||||
}
|
||||
|
||||
int WebAPIAdapterGUI::devicesetSpectrumSettingsGet(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGGLSpectrum& response,
|
||||
SWGSDRangel::SWGErrorResponse& error)
|
||||
{
|
||||
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
||||
{
|
||||
const DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[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 WebAPIAdapterGUI::devicesetSpectrumServerGet(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGSpectrumServer& response,
|
||||
SWGSDRangel::SWGErrorResponse& error)
|
||||
{
|
||||
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
||||
{
|
||||
const DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[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 WebAPIAdapterGUI::devicesetDevicePut(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGDeviceListItem& query,
|
||||
|
||||
@ -212,6 +212,16 @@ public:
|
||||
SWGSDRangel::SWGSuccessResponse& response,
|
||||
SWGSDRangel::SWGErrorResponse& error);
|
||||
|
||||
virtual int devicesetSpectrumSettingsGet(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGGLSpectrum& response,
|
||||
SWGSDRangel::SWGErrorResponse& error);
|
||||
|
||||
virtual int devicesetSpectrumServerGet(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGSpectrumServer& response,
|
||||
SWGSDRangel::SWGErrorResponse& error);
|
||||
|
||||
virtual int devicesetDevicePut(
|
||||
int deviceSetIndex,
|
||||
SWGSDRangel::SWGDeviceListItem& query,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user