2017-11-16 21:17:15 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 Edouard Griffiths, F4EXB. //
|
|
|
|
// //
|
|
|
|
// Swagger server adapter interface //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 08:32:15 -04:00
|
|
|
// (at your option) any later version. //
|
2017-11-16 21:17:15 -05:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-01-24 12:17:13 -05:00
|
|
|
#include <QDirIterator>
|
2017-11-23 18:47:42 -05:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonArray>
|
2017-11-21 18:28:26 -05:00
|
|
|
|
2017-11-26 04:37:39 -05:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
2017-11-20 12:38:26 -05:00
|
|
|
#include "httpdocrootsettings.h"
|
2017-11-16 21:17:15 -05:00
|
|
|
#include "webapirequestmapper.h"
|
2017-11-18 13:34:47 -05:00
|
|
|
#include "SWGInstanceSummaryResponse.h"
|
2019-07-31 20:16:56 -04:00
|
|
|
#include "SWGInstanceConfigResponse.h"
|
2017-11-22 12:57:35 -05:00
|
|
|
#include "SWGInstanceDevicesResponse.h"
|
2017-11-22 19:19:32 -05:00
|
|
|
#include "SWGInstanceChannelsResponse.h"
|
2017-11-24 02:46:12 -05:00
|
|
|
#include "SWGAudioDevices.h"
|
2017-11-24 22:02:11 -05:00
|
|
|
#include "SWGLocationInformation.h"
|
2019-07-21 03:47:11 -04:00
|
|
|
#include "SWGDVSerialDevices.h"
|
2019-07-20 19:57:51 -04:00
|
|
|
#include "SWGAMBEDevices.h"
|
2020-01-11 19:16:04 -05:00
|
|
|
#include "SWGLimeRFEDevices.h"
|
|
|
|
#include "SWGLimeRFESettings.h"
|
2020-01-14 09:26:49 -05:00
|
|
|
#include "SWGLimeRFEPower.h"
|
2017-11-25 05:14:52 -05:00
|
|
|
#include "SWGPresets.h"
|
2017-11-25 10:08:18 -05:00
|
|
|
#include "SWGPresetTransfer.h"
|
|
|
|
#include "SWGPresetIdentifier.h"
|
2017-12-18 19:11:34 -05:00
|
|
|
#include "SWGPresetImport.h"
|
|
|
|
#include "SWGPresetExport.h"
|
2017-12-04 17:07:30 -05:00
|
|
|
#include "SWGDeviceSettings.h"
|
2017-12-08 11:12:33 -05:00
|
|
|
#include "SWGDeviceState.h"
|
2018-05-25 19:43:28 -04:00
|
|
|
#include "SWGDeviceReport.h"
|
2018-03-18 19:08:38 -04:00
|
|
|
#include "SWGChannelsDetail.h"
|
2017-12-10 14:27:08 -05:00
|
|
|
#include "SWGChannelSettings.h"
|
2018-03-18 15:17:11 -04:00
|
|
|
#include "SWGChannelReport.h"
|
2017-12-19 11:55:05 -05:00
|
|
|
#include "SWGSuccessResponse.h"
|
2017-11-18 13:34:47 -05:00
|
|
|
#include "SWGErrorResponse.h"
|
2017-11-16 21:17:15 -05:00
|
|
|
|
2019-08-06 13:06:49 -04:00
|
|
|
const QMap<QString, QString> WebAPIRequestMapper::m_channelURIToSettingsKey = {
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.channel.amdemod", "AMDemodSettings"},
|
2019-08-08 20:41:17 -04:00
|
|
|
{"de.maintech.sdrangelove.channel.am", "AMDemodSettings"}, // remap
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.channeltx.modam", "AMModSettings"},
|
|
|
|
{"sdrangel.channeltx.modatv", "ATVModSettings"},
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.channel.bfm", "BFMDemodSettings"},
|
2019-08-08 12:42:17 -04:00
|
|
|
{"sdrangel.channel.chanalyzer", "ChannelAnalyzerSettings"},
|
2019-08-08 20:41:17 -04:00
|
|
|
{"sdrangel.channel.chanalyzerng", "ChannelAnalyzerSettings"}, // remap
|
2019-08-13 06:18:47 -04:00
|
|
|
{"org.f4exb.sdrangelove.channel.chanalyzer", "ChannelAnalyzerSettings"}, // remap
|
2019-08-11 05:35:53 -04:00
|
|
|
{"sdrangel.channel.demodatv", "ATVDemodSettings"},
|
2019-08-11 06:47:51 -04:00
|
|
|
{"sdrangel.channel.demoddatv", "DATVDemodSettings"},
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.channel.dsddemod", "DSDDemodSettings"},
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.channeltx.filesource", "FileSourceSettings"},
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.channel.freedvdemod", "FreeDVDemodSettings"},
|
|
|
|
{"sdrangel.channeltx.freedvmod", "FreeDVModSettings"},
|
|
|
|
{"sdrangel.channel.freqtracker", "FreqTrackerSettings"},
|
|
|
|
{"sdrangel.channel.nfmdemod", "NFMDemodSettings"},
|
2019-08-08 20:41:17 -04:00
|
|
|
{"de.maintech.sdrangelove.channel.nfm", "NFMDemodSettings"}, // remap
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.channeltx.modnfm", "NFMModSettings"},
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.demod.localsink", "LocalSinkSettings"},
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.channel.localsink", "LocalSinkSettings"}, // remap
|
|
|
|
{"sdrangel.channel.localsource", "LocalSourceSettings"},
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.demod.remotesink", "RemoteSinkSettings"},
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.channeltx.remotesource", "RemoteSourceSettings"},
|
|
|
|
{"sdrangel.channeltx.modssb", "SSBModSettings"},
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.channel.ssbdemod", "SSBDemodSettings"},
|
2019-08-08 20:41:17 -04:00
|
|
|
{"de.maintech.sdrangelove.channel.ssb", "SSBDemodSettings"}, // remap
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.channeltx.udpsource", "UDPSourceSettings"},
|
|
|
|
{"sdrangel.channeltx.udpsink", "UDPSourceSettings"}, // remap
|
|
|
|
{"sdrangel.channel.udpsink", "UDPSinkSettings"},
|
|
|
|
{"sdrangel.channel.udpsrc", "UDPSinkSettings"}, // remap
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.channel.wfmdemod", "WFMDemodSettings"},
|
2019-08-08 20:41:17 -04:00
|
|
|
{"de.maintech.sdrangelove.channel.wfm", "WFMDemodSettings"}, // remap
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.channeltx.modwfm", "WFMModSettings"}
|
2019-08-06 18:27:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const QMap<QString, QString> WebAPIRequestMapper::m_deviceIdToSettingsKey = {
|
|
|
|
{"sdrangel.samplesource.airspy", "airspySettings"},
|
|
|
|
{"sdrangel.samplesource.airspyhf", "airspyHFSettings"},
|
|
|
|
{"sdrangel.samplesource.bladerf1input", "bladeRF1InputSettings"},
|
|
|
|
{"sdrangel.samplesource.bladerf", "bladeRF1InputSettings"}, // remap
|
|
|
|
{"sdrangel.samplesink.bladerf1output", "bladeRF1OutputSettings"},
|
|
|
|
{"sdrangel.samplesource.bladerf1output", "bladeRF1OutputSettings"}, // remap
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.samplesource.bladerfoutput", "bladeRF1OutputSettings"}, // remap
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.samplesource.bladerf2input", "bladeRF2InputSettings"},
|
|
|
|
{"sdrangel.samplesink.bladerf2output", "bladeRF2OutputSettings"},
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.samplesource.bladerf2output", "bladeRF2OutputSettings"}, // remap
|
2019-08-06 18:27:34 -04:00
|
|
|
{"sdrangel.samplesource.fcdpro", "fcdProSettings"},
|
|
|
|
{"sdrangel.samplesource.fcdproplus", "fcdProPlusSettings"},
|
|
|
|
{"sdrangel.samplesource.fileinput", "fileInputSettings"},
|
|
|
|
{"sdrangel.samplesource.filesource", "fileInputSettings"}, // remap
|
|
|
|
{"sdrangel.samplesource.hackrf", "hackRFInputSettings"},
|
|
|
|
{"sdrangel.samplesink.hackrf", "hackRFOutputSettings"},
|
|
|
|
{"sdrangel.samplesource.hackrfoutput", "hackRFOutputSettings"}, // remap
|
|
|
|
{"sdrangel.samplesource.kiwisdrsource", "kiwiSDRSettings"},
|
|
|
|
{"sdrangel.samplesource.limesdr", "limeSdrInputSettings"},
|
|
|
|
{"sdrangel.samplesink.limesdr", "limeSdrOutputSettings"},
|
|
|
|
{"sdrangel.samplesource.localinput", "localInputSettings"},
|
|
|
|
{"sdrangel.samplesink.localoutput", "localOutputSettings"},
|
|
|
|
{"sdrangel.samplesource.localoutput", "localOutputSettings"}, // remap
|
|
|
|
{"sdrangel.samplesource.perseus", "perseusSettings"},
|
|
|
|
{"sdrangel.samplesource.plutosdr", "plutoSdrInputSettings"},
|
|
|
|
{"sdrangel.samplesink.plutosdr", "plutoSdrOutputSettings"},
|
|
|
|
{"sdrangel.samplesource.rtlsdr", "rtlSdrSettings"},
|
|
|
|
{"sdrangel.samplesource.remoteinput", "remoteInputSettings"},
|
|
|
|
{"sdrangel.samplesink.remoteoutput", "remoteOutputSettings"},
|
|
|
|
{"sdrangel.samplesource.sdrplay", "sdrPlaySettings"},
|
|
|
|
{"sdrangel.samplesource.soapysdrinput", "soapySDRInputSettings"},
|
|
|
|
{"sdrangel.samplesink.soapysdroutput", "soapySDROutputSettings"},
|
|
|
|
{"sdrangel.samplesource.testsource", "testSourceSettings"},
|
2019-08-13 06:18:47 -04:00
|
|
|
{"sdrangel.samplesource.xtrx", "XtrxInputSettings"},
|
|
|
|
{"sdrangel.samplesink.xtrx", "XtrxOutputSettings"}
|
2019-08-06 18:27:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const QMap<QString, QString> WebAPIRequestMapper::m_channelTypeToSettingsKey = {
|
|
|
|
{"AMDemod", "AMDemodSettings"},
|
|
|
|
{"AMMod", "AMModSettings"},
|
2019-08-11 05:35:53 -04:00
|
|
|
{"ATVDemod", "ATVDemodSettings"},
|
2019-08-06 18:27:34 -04:00
|
|
|
{"ATVMod", "ATVModSettings"},
|
|
|
|
{"BFMDemod", "BFMDemodSettings"},
|
2019-08-08 12:42:17 -04:00
|
|
|
{"ChannelAnalyzer", "ChannelAnalyzerSettings"},
|
2019-08-11 06:47:51 -04:00
|
|
|
{"DATVDemod", "DATVDemodSettings"},
|
2019-08-06 18:27:34 -04:00
|
|
|
{"DSDDemod", "DSDDemodSettings"},
|
|
|
|
{"FileSource", "FileSourceSettings"},
|
|
|
|
{"FreeDVDemod", "FreeDVDemodSettings"},
|
|
|
|
{"FreeDVMod", "FreeDVModSettings"},
|
|
|
|
{"FreqTracker", "FreqTrackerSettings"},
|
|
|
|
{"NFMDemod", "NFMDemodSettings"},
|
|
|
|
{"NFMMod", "NFMModSettings"},
|
|
|
|
{"LocalSink", "LocalSinkSettings"},
|
|
|
|
{"LocalSource", "LocalSourceSettings"},
|
|
|
|
{"RemoteSink", "RemoteSinkSettings"},
|
|
|
|
{"RemoteSource", "RemoteSourceSettings"},
|
|
|
|
{"SSBMod", "SSBModSettings"},
|
|
|
|
{"SSBDemod", "SSBDemodSettings"},
|
|
|
|
{"UDPSink", "UDPSourceSettings"},
|
|
|
|
{"UDPSource", "UDPSinkSettings"},
|
|
|
|
{"WFMDemod", "WFMDemodSettings"},
|
|
|
|
{"WFMMod", "WFMModSettings"}
|
|
|
|
};
|
|
|
|
|
|
|
|
const QMap<QString, QString> WebAPIRequestMapper::m_sourceDeviceHwIdToSettingsKey = {
|
|
|
|
{"Airspy", "airspySettings"},
|
|
|
|
{"AirspyHF", "airspyHFSettings"},
|
|
|
|
{"BladeRFI", "bladeRF1InputSettings"},
|
|
|
|
{"BladeRF2", "bladeRF2InputSettings"},
|
|
|
|
{"FCDPro", "fcdProSettings"},
|
|
|
|
{"FCDPro+", "fcdProPlusSettings"},
|
|
|
|
{"FileInput", "fileInputSettings"},
|
|
|
|
{"HackRF", "hackRFInputSettings"},
|
|
|
|
{"KiwiSDR", "kiwiSDRSettings"},
|
|
|
|
{"LimeSDR", "limeSdrInputSettings"},
|
|
|
|
{"LocalInput", "localInputSettings"},
|
|
|
|
{"Perseus", "perseusSettings"},
|
|
|
|
{"PlutoSDR", "plutoSdrInputSettings"},
|
|
|
|
{"RTLSDR", "rtlSdrSettings"},
|
|
|
|
{"RemoteInput", "remoteInputSettings"},
|
|
|
|
{"SDRplay1", "sdrPlaySettings"},
|
|
|
|
{"SoapySDR", "soapySDRInputSettings"},
|
|
|
|
{"TestSource", "testSourceSettings"},
|
2019-08-13 06:18:47 -04:00
|
|
|
{"XTRX", "XtrxInputSettings"}
|
2019-08-06 18:27:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const QMap<QString, QString> WebAPIRequestMapper::m_sinkDeviceHwIdToSettingsKey = {
|
|
|
|
{"BladeRF1", "bladeRF1OutputSettings"},
|
|
|
|
{"BladeRF2", "bladeRF2OutputSettings"},
|
|
|
|
{"HackRF", "hackRFOutputSettings"},
|
|
|
|
{"LimeSDR", "limeSdrOutputSettings"},
|
|
|
|
{"LocalOutput", "localOutputSettings"},
|
|
|
|
{"PlutoSDR", "plutoSdrOutputSettings"},
|
|
|
|
{"RemoteOutput", "remoteOutputSettings"},
|
|
|
|
{"SoapySDR", "soapySDROutputSettings"},
|
2019-08-13 06:18:47 -04:00
|
|
|
{"XTRX", "XtrxOutputSettings"}
|
2019-08-06 18:27:34 -04:00
|
|
|
};
|
|
|
|
|
2017-11-16 21:17:15 -05:00
|
|
|
WebAPIRequestMapper::WebAPIRequestMapper(QObject* parent) :
|
|
|
|
HttpRequestHandler(parent),
|
|
|
|
m_adapter(0)
|
2017-11-20 12:38:26 -05:00
|
|
|
{
|
2019-05-31 13:24:02 -04:00
|
|
|
#ifndef _MSC_VER
|
2019-05-31 04:14:10 -04:00
|
|
|
Q_INIT_RESOURCE(webapi);
|
2019-05-31 13:24:02 -04:00
|
|
|
#endif
|
2017-11-20 12:38:26 -05:00
|
|
|
qtwebapp::HttpDocrootSettings docrootSettings;
|
2018-01-24 12:17:13 -05:00
|
|
|
docrootSettings.path = ":/webapi";
|
2017-11-20 12:38:26 -05:00
|
|
|
m_staticFileController = new qtwebapp::StaticFileController(docrootSettings, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
WebAPIRequestMapper::~WebAPIRequestMapper()
|
|
|
|
{
|
|
|
|
delete m_staticFileController;
|
2019-05-31 13:24:02 -04:00
|
|
|
#ifndef _MSC_VER
|
2019-05-31 04:14:10 -04:00
|
|
|
Q_CLEANUP_RESOURCE(webapi);
|
2019-05-31 13:24:02 -04:00
|
|
|
#endif
|
2017-11-20 12:38:26 -05:00
|
|
|
}
|
2017-11-16 21:17:15 -05:00
|
|
|
|
2017-11-18 13:34:47 -05:00
|
|
|
void WebAPIRequestMapper::service(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
2017-11-16 21:17:15 -05:00
|
|
|
{
|
|
|
|
if (m_adapter == 0) // format service unavailable if adapter is null
|
|
|
|
{
|
2017-12-22 09:27:25 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-17 02:52:15 -05:00
|
|
|
response.setStatus(500,"Service not available");
|
2017-12-22 09:27:25 -05:00
|
|
|
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Service not available";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-16 21:17:15 -05:00
|
|
|
}
|
|
|
|
else // normal processing
|
|
|
|
{
|
|
|
|
QByteArray path=request.getPath();
|
|
|
|
|
2018-07-21 16:28:35 -04:00
|
|
|
// Handle pre-flight requests
|
|
|
|
if (request.getMethod() == "OPTIONS")
|
|
|
|
{
|
|
|
|
qDebug("WebAPIRequestMapper::service: method OPTIONS: assume pre-flight");
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
response.setHeader("Access-Control-Allow-Headers", "*");
|
|
|
|
response.setHeader("Access-Control-Allow-Methods", "*");
|
|
|
|
response.setStatus(200, "OK");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-24 11:12:53 -05:00
|
|
|
if (path == WebAPIAdapterInterface::instanceSummaryURL) {
|
|
|
|
instanceSummaryService(request, response);
|
2019-07-31 20:16:56 -04:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceConfigURL) {
|
|
|
|
instanceConfigService(request, response);
|
2017-11-24 11:12:53 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceDevicesURL) {
|
|
|
|
instanceDevicesService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceChannelsURL) {
|
|
|
|
instanceChannelsService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceLoggingURL) {
|
|
|
|
instanceLoggingService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceAudioURL) {
|
|
|
|
instanceAudioService(request, response);
|
2018-03-28 19:43:31 -04:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceAudioInputParametersURL) {
|
|
|
|
instanceAudioInputParametersService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceAudioOutputParametersURL) {
|
|
|
|
instanceAudioOutputParametersService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceAudioInputCleanupURL) {
|
|
|
|
instanceAudioInputCleanupService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceAudioOutputCleanupURL) {
|
|
|
|
instanceAudioOutputCleanupService(request, response);
|
2017-11-24 22:02:11 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceLocationURL) {
|
|
|
|
instanceLocationService(request, response);
|
2019-07-20 19:57:51 -04:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceAMBESerialURL) {
|
|
|
|
instanceAMBESerialService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceAMBEDevicesURL) {
|
|
|
|
instanceAMBEDevicesService(request, response);
|
2020-01-11 19:16:04 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceLimeRFESerialURL) {
|
|
|
|
instanceLimeRFESerialService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceLimeRFEConfigURL) {
|
|
|
|
instanceLimeRFEConfigService(request, response);
|
|
|
|
} else if (path == WebAPIAdapterInterface::instanceLimeRFERunURL) {
|
|
|
|
instanceLimeRFERunService(request, response);
|
2020-01-14 09:26:49 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceLimeRFEPowerURL) {
|
|
|
|
instanceLimeRFEPowerService(request, response);
|
2017-12-20 18:50:58 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instancePresetsURL) {
|
|
|
|
instancePresetsService(request, response);
|
2017-11-25 05:14:52 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instancePresetURL) {
|
|
|
|
instancePresetService(request, response);
|
2017-12-18 19:11:34 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instancePresetFileURL) {
|
|
|
|
instancePresetFileService(request, response);
|
2017-11-25 14:14:16 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceDeviceSetsURL) {
|
|
|
|
instanceDeviceSetsService(request, response);
|
2017-12-21 19:07:03 -05:00
|
|
|
} else if (path == WebAPIAdapterInterface::instanceDeviceSetURL) {
|
|
|
|
instanceDeviceSetService(request, response);
|
2017-11-16 21:17:15 -05:00
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
else
|
2017-11-22 12:57:35 -05:00
|
|
|
{
|
2017-11-26 04:37:39 -05:00
|
|
|
std::smatch desc_match;
|
|
|
|
std::string pathStr(path.constData(), path.length());
|
|
|
|
|
|
|
|
if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetURLRe)) {
|
2017-12-04 12:22:25 -05:00
|
|
|
devicesetService(std::string(desc_match[1]), request, response);
|
2017-11-27 02:14:07 -05:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceURLRe)) {
|
2017-12-04 12:22:25 -05:00
|
|
|
devicesetDeviceService(std::string(desc_match[1]), request, response);
|
2018-01-05 21:46:53 -05:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetFocusURLRe)) {
|
|
|
|
devicesetFocusService(std::string(desc_match[1]), request, response);
|
2017-12-06 16:08:34 -05:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceSettingsURLRe)) {
|
|
|
|
devicesetDeviceSettingsService(std::string(desc_match[1]), request, response);
|
2017-12-08 11:12:33 -05:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceRunURLRe)) {
|
|
|
|
devicesetDeviceRunService(std::string(desc_match[1]), request, response);
|
2019-12-24 13:08:11 -05:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceSubsystemRunURLRe)) {
|
|
|
|
devicesetDeviceSubsystemRunService(std::string(desc_match[1]), std::string(desc_match[2]), request, response);
|
2018-05-25 19:43:28 -04:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetDeviceReportURLRe)) {
|
|
|
|
devicesetDeviceReportService(std::string(desc_match[1]), request, response);
|
2018-03-18 19:08:38 -04:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetChannelsReportURLRe)) {
|
|
|
|
devicesetChannelsReportService(std::string(desc_match[1]), request, response);
|
2017-12-10 19:18:10 -05:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetChannelURLRe)) {
|
|
|
|
devicesetChannelService(std::string(desc_match[1]), request, response);
|
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetChannelIndexURLRe)) {
|
|
|
|
devicesetChannelIndexService(std::string(desc_match[1]), std::string(desc_match[2]), request, response);
|
2017-12-10 14:27:08 -05:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetChannelSettingsURLRe)) {
|
|
|
|
devicesetChannelSettingsService(std::string(desc_match[1]), std::string(desc_match[2]), request, response);
|
2018-03-18 15:17:11 -04:00
|
|
|
} else if (std::regex_match(pathStr, desc_match, WebAPIAdapterInterface::devicesetChannelReportURLRe)) {
|
|
|
|
devicesetChannelReportService(std::string(desc_match[1]), std::string(desc_match[2]), request, response);
|
2017-11-26 04:37:39 -05:00
|
|
|
}
|
2018-01-24 12:17:13 -05:00
|
|
|
else // serve static documentation pages
|
2017-11-26 04:37:39 -05:00
|
|
|
{
|
2018-01-24 12:17:13 -05:00
|
|
|
m_staticFileController->service(request, response);
|
2017-11-26 04:37:39 -05:00
|
|
|
}
|
|
|
|
|
2017-11-24 11:12:53 -05:00
|
|
|
// QDirIterator it(":", QDirIterator::Subdirectories);
|
|
|
|
// while (it.hasNext()) {
|
|
|
|
// qDebug() << "WebAPIRequestMapper::service: " << it.next();
|
|
|
|
// }
|
|
|
|
|
2017-11-22 12:57:35 -05:00
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceSummaryService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
2017-12-12 12:56:24 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-12 12:56:24 -05:00
|
|
|
|
2017-11-24 11:12:53 -05:00
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGInstanceSummaryResponse normalResponse;
|
2017-11-24 11:12:53 -05:00
|
|
|
|
|
|
|
int status = m_adapter->instanceSummary(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-24 11:12:53 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-17 17:15:42 -05:00
|
|
|
else if (request.getMethod() == "DELETE")
|
|
|
|
{
|
2017-12-21 12:10:43 -05:00
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
2017-12-17 17:15:42 -05:00
|
|
|
|
|
|
|
int status = m_adapter->instanceDelete(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-17 17:15:42 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 20:16:56 -04:00
|
|
|
void WebAPIRequestMapper::instanceConfigService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
2019-08-06 02:48:14 -04:00
|
|
|
SWGSDRangel::SWGInstanceConfigResponse query;
|
2019-07-31 20:16:56 -04:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGInstanceConfigResponse normalResponse;
|
|
|
|
int status = m_adapter->instanceConfigGet(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2019-08-10 19:27:19 -04:00
|
|
|
else if ((request.getMethod() == "PUT") || (request.getMethod() == "PATCH"))
|
2019-08-06 02:48:14 -04:00
|
|
|
{
|
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
WebAPIAdapterInterface::ConfigKeys configKeys;
|
|
|
|
SWGSDRangel::SWGInstanceConfigResponse query;
|
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
|
|
|
query.init();
|
|
|
|
|
|
|
|
if (validateConfig(query, jsonObject, configKeys))
|
|
|
|
{
|
2019-08-09 12:45:10 -04:00
|
|
|
int status = m_adapter->instanceConfigPutPatch(
|
2019-08-10 19:27:19 -04:00
|
|
|
request.getMethod() == "PUT",
|
2019-08-09 12:45:10 -04:00
|
|
|
query,
|
|
|
|
configKeys,
|
|
|
|
normalResponse,
|
|
|
|
errorResponse
|
|
|
|
);
|
2019-08-06 18:27:34 -04:00
|
|
|
response.setStatus(status);
|
2019-08-10 19:27:19 -04:00
|
|
|
qDebug("WebAPIRequestMapper::instanceConfigService: %s: %d",
|
|
|
|
request.getMethod() == "PUT" ? "PUT" : "PATCH", status);
|
2019-08-06 18:27:34 -04:00
|
|
|
|
2019-08-09 12:45:10 -04:00
|
|
|
if (status/100 == 2)
|
|
|
|
{
|
|
|
|
normalResponse.setMessage(new QString("Configuration updated successfully"));
|
2019-08-06 18:27:34 -04:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
2019-08-09 12:45:10 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
normalResponse.setMessage(new QString("Error occured while updating configuration"));
|
2019-08-06 18:27:34 -04:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
|
2019-08-06 02:48:14 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2019-07-31 20:16:56 -04:00
|
|
|
}
|
|
|
|
|
2017-11-24 11:12:53 -05:00
|
|
|
void WebAPIRequestMapper::instanceDevicesService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGInstanceDevicesResponse normalResponse;
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-24 11:12:53 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
2019-05-08 19:12:40 -04:00
|
|
|
QByteArray dirStr = request.getParameter("direction");
|
|
|
|
int direction = 0;
|
2017-11-24 22:43:22 -05:00
|
|
|
|
2019-05-08 19:12:40 -04:00
|
|
|
if (dirStr.length() != 0)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
int tmp = dirStr.toInt(&ok);
|
|
|
|
if (ok) {
|
|
|
|
direction = tmp;
|
|
|
|
}
|
2017-11-24 22:43:22 -05:00
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
|
2019-05-08 19:12:40 -04:00
|
|
|
int status = m_adapter->instanceDevices(direction, normalResponse, errorResponse);
|
2017-11-24 11:12:53 -05:00
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-24 11:12:53 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-22 19:19:32 -05:00
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceChannelsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGInstanceChannelsResponse normalResponse;
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-24 11:12:53 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
2019-05-08 19:12:40 -04:00
|
|
|
QByteArray dirStr = request.getParameter("direction");
|
|
|
|
int direction = 0;
|
2017-11-24 22:43:22 -05:00
|
|
|
|
2019-05-08 19:12:40 -04:00
|
|
|
if (dirStr.length() != 0)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
int tmp = dirStr.toInt(&ok);
|
|
|
|
if (ok) {
|
|
|
|
direction = tmp;
|
|
|
|
}
|
2017-11-24 22:43:22 -05:00
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
|
2019-05-08 19:12:40 -04:00
|
|
|
int status = m_adapter->instanceChannels(direction, normalResponse, errorResponse);
|
2017-11-24 11:12:53 -05:00
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-24 11:12:53 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceLoggingService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
SWGSDRangel::SWGLoggingInfo query;
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLoggingInfo normalResponse;
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-24 11:12:53 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
int status = m_adapter->instanceLoggingGet(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-24 11:12:53 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (request.getMethod() == "PUT")
|
|
|
|
{
|
|
|
|
QString jsonStr = request.getBody();
|
2017-12-07 12:50:36 -05:00
|
|
|
QJsonObject jsonObject;
|
2017-11-24 11:12:53 -05:00
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-11-23 12:43:01 -05:00
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
query.fromJson(jsonStr);
|
|
|
|
int status = m_adapter->instanceLoggingPut(query, normalResponse, errorResponse);
|
2017-11-24 11:12:53 -05:00
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-24 11:12:53 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-23 12:43:01 -05:00
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
}
|
2017-11-24 02:46:12 -05:00
|
|
|
|
2017-11-24 11:12:53 -05:00
|
|
|
void WebAPIRequestMapper::instanceAudioService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-24 02:46:12 -05:00
|
|
|
|
2017-11-24 11:12:53 -05:00
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGAudioDevices normalResponse;
|
2017-11-24 02:46:12 -05:00
|
|
|
|
2017-11-24 11:12:53 -05:00
|
|
|
int status = m_adapter->instanceAudioGet(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-24 11:12:53 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-24 02:46:12 -05:00
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
2018-03-28 18:38:01 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 19:43:31 -04:00
|
|
|
void WebAPIRequestMapper::instanceAudioInputParametersService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
2018-03-28 18:38:01 -04:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2018-03-28 18:38:01 -04:00
|
|
|
|
2018-03-28 19:43:31 -04:00
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-11-24 11:12:53 -05:00
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
SWGSDRangel::SWGAudioInputDevice normalResponse;
|
|
|
|
resetAudioInputDevice(normalResponse);
|
|
|
|
QStringList audioInputDeviceKeys;
|
2017-11-24 11:12:53 -05:00
|
|
|
|
2018-03-28 19:43:31 -04:00
|
|
|
if (validateAudioInputDevice(normalResponse, jsonObject, audioInputDeviceKeys))
|
2017-11-17 02:52:15 -05:00
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
if (request.getMethod() == "PATCH")
|
2018-03-28 18:38:01 -04:00
|
|
|
{
|
|
|
|
int status = m_adapter->instanceAudioInputPatch(
|
|
|
|
normalResponse,
|
|
|
|
audioInputDeviceKeys,
|
|
|
|
errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2018-03-28 19:43:31 -04:00
|
|
|
else if (request.getMethod() == "DELETE")
|
|
|
|
{
|
|
|
|
int status = m_adapter->instanceAudioInputDelete(
|
|
|
|
normalResponse,
|
|
|
|
errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2018-03-28 18:38:01 -04:00
|
|
|
else
|
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2018-03-28 18:38:01 -04:00
|
|
|
errorResponse.init();
|
2018-03-28 19:43:31 -04:00
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
2018-03-28 18:38:01 -04:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
response.setStatus(400,"Invalid JSON request");
|
2018-03-28 18:38:01 -04:00
|
|
|
errorResponse.init();
|
2018-03-28 19:43:31 -04:00
|
|
|
*errorResponse.getMessage() = "Invalid JSON request";
|
2018-03-28 18:38:01 -04:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
response.setStatus(400,"Invalid JSON format");
|
2018-03-28 18:38:01 -04:00
|
|
|
errorResponse.init();
|
2018-03-28 19:43:31 -04:00
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
2018-03-28 18:38:01 -04:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 19:43:31 -04:00
|
|
|
void WebAPIRequestMapper::instanceAudioOutputParametersService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
2018-03-28 18:38:01 -04:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2018-03-28 18:38:01 -04:00
|
|
|
|
2018-03-28 19:43:31 -04:00
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2018-03-28 18:38:01 -04:00
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
SWGSDRangel::SWGAudioOutputDevice normalResponse;
|
|
|
|
resetAudioOutputDevice(normalResponse);
|
|
|
|
QStringList audioOutputDeviceKeys;
|
2018-03-28 18:38:01 -04:00
|
|
|
|
2018-03-28 19:43:31 -04:00
|
|
|
if (validateAudioOutputDevice(normalResponse, jsonObject, audioOutputDeviceKeys))
|
2018-03-28 18:38:01 -04:00
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
if (request.getMethod() == "PATCH")
|
2018-03-28 18:38:01 -04:00
|
|
|
{
|
|
|
|
int status = m_adapter->instanceAudioOutputPatch(
|
|
|
|
normalResponse,
|
|
|
|
audioOutputDeviceKeys,
|
|
|
|
errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2018-03-28 19:43:31 -04:00
|
|
|
else if (request.getMethod() == "DELETE")
|
|
|
|
{
|
|
|
|
int status = m_adapter->instanceAudioOutputDelete(
|
|
|
|
normalResponse,
|
|
|
|
errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2018-03-28 18:38:01 -04:00
|
|
|
else
|
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2018-03-28 18:38:01 -04:00
|
|
|
errorResponse.init();
|
2018-03-28 19:43:31 -04:00
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
2017-11-24 11:12:53 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
2018-03-28 19:43:31 -04:00
|
|
|
response.setStatus(400,"Invalid JSON request");
|
2017-12-18 19:11:34 -05:00
|
|
|
errorResponse.init();
|
2018-03-28 19:43:31 -04:00
|
|
|
*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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceAudioInputCleanupService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2018-03-28 19:43:31 -04:00
|
|
|
|
|
|
|
if (request.getMethod() == "PATCH")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
|
|
|
|
|
|
|
int status = m_adapter->instanceAudioInputCleanupPatch(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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceAudioOutputCleanupService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2018-03-28 19:43:31 -04:00
|
|
|
|
|
|
|
if (request.getMethod() == "PATCH")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
|
|
|
|
|
|
|
int status = m_adapter->instanceAudioOutputCleanupPatch(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
2017-12-18 19:11:34 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-24 11:12:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 22:02:11 -05:00
|
|
|
void WebAPIRequestMapper::instanceLocationService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-24 22:02:11 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLocationInformation normalResponse;
|
2017-11-24 22:02:11 -05:00
|
|
|
|
|
|
|
int status = m_adapter->instanceLocationGet(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-24 22:02:11 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (request.getMethod() == "PUT")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLocationInformation normalResponse;
|
2017-11-24 22:02:11 -05:00
|
|
|
QString jsonStr = request.getBody();
|
2017-12-07 12:50:36 -05:00
|
|
|
QJsonObject jsonObject;
|
2017-11-24 22:02:11 -05:00
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-11-24 22:02:11 -05:00
|
|
|
{
|
|
|
|
normalResponse.fromJson(jsonStr);
|
|
|
|
int status = m_adapter->instanceLocationPut(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-24 22:02:11 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-11-24 22:02:11 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-24 22:02:11 -05:00
|
|
|
}
|
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
|
2019-07-20 19:57:51 -04:00
|
|
|
void WebAPIRequestMapper::instanceAMBESerialService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
2019-07-21 03:47:11 -04:00
|
|
|
SWGSDRangel::SWGDVSerialDevices normalResponse;
|
2019-07-20 19:57:51 -04:00
|
|
|
|
|
|
|
int status = m_adapter->instanceAMBESerialGet(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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceAMBEDevicesService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGAMBEDevices normalResponse;
|
|
|
|
|
|
|
|
int status = m_adapter->instanceAMBEDevicesGet(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((request.getMethod() == "PATCH") || (request.getMethod() == "PUT"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGAMBEDevices query;
|
|
|
|
SWGSDRangel::SWGAMBEDevices normalResponse;
|
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
|
|
|
{
|
|
|
|
if (validateAMBEDevices(query, jsonObject))
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (request.getMethod() == "PATCH") {
|
|
|
|
status = m_adapter->instanceAMBEDevicesPatch(query, normalResponse, errorResponse);
|
|
|
|
} else {
|
|
|
|
status = m_adapter->instanceAMBEDevicesPut(query, 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() == "DELETE")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
|
|
|
|
|
|
|
int status = m_adapter->instanceAMBEDevicesDelete(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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-11 19:16:04 -05:00
|
|
|
void WebAPIRequestMapper::instanceLimeRFESerialService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGLimeRFEDevices normalResponse;
|
|
|
|
|
|
|
|
int status = m_adapter->instanceLimeRFESerialGet(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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceLimeRFEConfigService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
QByteArray serialStr = request.getParameter("serial");
|
|
|
|
SWGSDRangel::SWGLimeRFESettings normalResponse;
|
|
|
|
|
|
|
|
int status = m_adapter->instanceLimeRFEConfigGet(serialStr, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (request.getMethod() == "PUT")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGLimeRFESettings query;
|
2020-01-13 19:11:31 -05:00
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
2020-01-11 19:16:04 -05:00
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
|
|
|
{
|
|
|
|
QStringList limeRFESettingsKeys;
|
|
|
|
|
|
|
|
if (validateLimeRFEConfig(query, jsonObject, limeRFESettingsKeys))
|
|
|
|
{
|
|
|
|
if (limeRFESettingsKeys.contains("devicePath"))
|
|
|
|
{
|
|
|
|
int status = m_adapter->instanceLimeRFEConfigPut(query, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"LimeRFE device path expected in JSON body");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid 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
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceLimeRFERunService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
|
|
|
if (request.getMethod() == "PUT")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGLimeRFESettings query;
|
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
|
|
|
{
|
|
|
|
QStringList limeRFESettingsKeys;
|
|
|
|
|
|
|
|
if (validateLimeRFEConfig(query, jsonObject, limeRFESettingsKeys))
|
|
|
|
{
|
|
|
|
if (limeRFESettingsKeys.contains("devicePath"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
|
|
|
int status = m_adapter->instanceLimeRFERunPut(query, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"LimeRFE device path expected in JSON body");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
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
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-14 09:26:49 -05:00
|
|
|
void WebAPIRequestMapper::instanceLimeRFEPowerService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
QByteArray serialStr = request.getParameter("serial");
|
|
|
|
SWGSDRangel::SWGLimeRFEPower normalResponse;
|
|
|
|
|
|
|
|
int status = m_adapter->instanceLimeRFEPowerGet(serialStr, 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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 18:50:58 -05:00
|
|
|
void WebAPIRequestMapper::instancePresetsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
2017-11-25 05:14:52 -05:00
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-25 05:14:52 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresets normalResponse;
|
2017-12-20 18:50:58 -05:00
|
|
|
int status = m_adapter->instancePresetsGet(normalResponse, errorResponse);
|
2017-11-25 05:14:52 -05:00
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-25 05:14:52 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-20 18:50:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instancePresetService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-20 18:50:58 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "PATCH")
|
2017-11-25 10:08:18 -05:00
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetTransfer query;
|
|
|
|
SWGSDRangel::SWGPresetIdentifier normalResponse;
|
2017-11-25 10:08:18 -05:00
|
|
|
QString jsonStr = request.getBody();
|
2017-12-07 12:50:36 -05:00
|
|
|
QJsonObject jsonObject;
|
2017-11-25 10:08:18 -05:00
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-11-25 10:08:18 -05:00
|
|
|
{
|
|
|
|
query.fromJson(jsonStr);
|
|
|
|
|
2017-11-25 13:42:56 -05:00
|
|
|
if (validatePresetTransfer(query))
|
|
|
|
{
|
|
|
|
int status = m_adapter->instancePresetPatch(query, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-25 13:42:56 -05:00
|
|
|
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";
|
2017-11-25 10:08:18 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-11-25 10:08:18 -05:00
|
|
|
}
|
2017-11-25 10:47:13 -05:00
|
|
|
else if (request.getMethod() == "PUT")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetTransfer query;
|
|
|
|
SWGSDRangel::SWGPresetIdentifier normalResponse;
|
2017-11-25 10:47:13 -05:00
|
|
|
QString jsonStr = request.getBody();
|
2017-12-07 12:50:36 -05:00
|
|
|
QJsonObject jsonObject;
|
2017-11-25 10:47:13 -05:00
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-11-25 10:47:13 -05:00
|
|
|
{
|
|
|
|
query.fromJson(jsonStr);
|
|
|
|
|
2017-11-25 13:42:56 -05:00
|
|
|
if (validatePresetTransfer(query))
|
|
|
|
{
|
|
|
|
int status = m_adapter->instancePresetPut(query, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-25 13:42:56 -05:00
|
|
|
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";
|
2017-11-25 10:47:13 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-11-25 10:47:13 -05:00
|
|
|
}
|
2017-11-25 12:32:37 -05:00
|
|
|
else if (request.getMethod() == "POST")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetTransfer query;
|
|
|
|
SWGSDRangel::SWGPresetIdentifier normalResponse;
|
2017-11-25 12:32:37 -05:00
|
|
|
QString jsonStr = request.getBody();
|
2017-12-07 12:50:36 -05:00
|
|
|
QJsonObject jsonObject;
|
2017-11-25 12:32:37 -05:00
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-11-25 12:32:37 -05:00
|
|
|
{
|
|
|
|
query.fromJson(jsonStr);
|
|
|
|
|
2017-11-25 13:42:56 -05:00
|
|
|
if (validatePresetTransfer(query))
|
|
|
|
{
|
|
|
|
int status = m_adapter->instancePresetPost(query, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-25 13:42:56 -05:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-11-25 13:42:56 -05:00
|
|
|
}
|
|
|
|
else if (request.getMethod() == "DELETE")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetIdentifier normalResponse;
|
2017-11-25 13:42:56 -05:00
|
|
|
QString jsonStr = request.getBody();
|
2017-12-07 12:50:36 -05:00
|
|
|
QJsonObject jsonObject;
|
2017-11-25 13:42:56 -05:00
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-11-25 13:42:56 -05:00
|
|
|
{
|
|
|
|
normalResponse.fromJson(jsonStr);
|
|
|
|
|
|
|
|
if (validatePresetIdentifer(normalResponse))
|
|
|
|
{
|
|
|
|
int status = m_adapter->instancePresetDelete(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-25 13:42:56 -05:00
|
|
|
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";
|
2017-11-25 12:32:37 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instancePresetFileService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-18 19:11:34 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "PUT")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGPresetImport query;
|
|
|
|
SWGSDRangel::SWGPresetIdentifier normalResponse;
|
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
|
|
|
{
|
|
|
|
query.fromJson(jsonStr);
|
|
|
|
|
|
|
|
if (query.getFilePath())
|
|
|
|
{
|
|
|
|
int status = m_adapter->instancePresetFilePut(query, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-18 19:11:34 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-28 20:44:35 -05:00
|
|
|
response.setStatus(400,"Invalid JSON request");
|
2017-12-18 19:11:34 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON request";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
2017-12-28 20:44:35 -05:00
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
2017-12-18 19:11:34 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (request.getMethod() == "POST")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGPresetExport query;
|
|
|
|
SWGSDRangel::SWGPresetIdentifier normalResponse;
|
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
|
|
|
{
|
|
|
|
query.fromJson(jsonStr);
|
|
|
|
|
|
|
|
if (validatePresetExport(query))
|
|
|
|
{
|
|
|
|
int status = m_adapter->instancePresetFilePost(query, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-18 19:11:34 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-28 20:44:35 -05:00
|
|
|
response.setStatus(400,"Invalid JSON request");
|
2017-12-18 19:11:34 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON request";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
2017-12-28 20:44:35 -05:00
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
2017-12-18 19:11:34 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-11-25 12:32:37 -05:00
|
|
|
}
|
2017-11-25 05:14:52 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-25 05:14:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-25 14:14:16 -05:00
|
|
|
void WebAPIRequestMapper::instanceDeviceSetsService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-25 14:14:16 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDeviceSetList normalResponse;
|
2017-11-25 14:14:16 -05:00
|
|
|
int status = m_adapter->instanceDeviceSetsGet(normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-25 14:14:16 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-21 19:07:03 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::instanceDeviceSetService(qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-21 19:07:03 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "POST")
|
2017-11-25 16:52:24 -05:00
|
|
|
{
|
2017-12-19 11:55:05 -05:00
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
2019-05-08 19:12:40 -04:00
|
|
|
QByteArray dirStr = request.getParameter("direction");
|
|
|
|
int direction = 0;
|
2017-11-25 16:52:24 -05:00
|
|
|
|
2019-05-08 19:12:40 -04:00
|
|
|
if (dirStr.length() != 0)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
int tmp = dirStr.toInt(&ok);
|
|
|
|
if (ok) {
|
|
|
|
direction = tmp;
|
|
|
|
}
|
2017-11-25 16:52:24 -05:00
|
|
|
}
|
|
|
|
|
2019-05-08 19:12:40 -04:00
|
|
|
int status = m_adapter->instanceDeviceSetPost(direction, normalResponse, errorResponse);
|
2017-11-25 16:52:24 -05:00
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-25 16:52:24 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (request.getMethod() == "DELETE")
|
|
|
|
{
|
2017-12-19 11:55:05 -05:00
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
2017-12-21 19:07:03 -05:00
|
|
|
int status = m_adapter->instanceDeviceSetDelete(normalResponse, errorResponse);
|
2017-11-25 16:52:24 -05:00
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-25 16:52:24 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-11-25 14:14:16 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-25 14:14:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 12:22:25 -05:00
|
|
|
void WebAPIRequestMapper::devicesetService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
2017-11-26 04:37:39 -05:00
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-26 04:37:39 -05:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDeviceSet normalResponse;
|
2017-11-26 04:37:39 -05:00
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
|
|
|
int status = m_adapter->devicesetGet(deviceSetIndex, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-11-26 04:37:39 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-26 04:37:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-05 21:46:53 -05:00
|
|
|
void WebAPIRequestMapper::devicesetFocusService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2018-01-05 21:46:53 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
|
|
|
|
|
|
|
if (request.getMethod() == "PATCH")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
|
|
|
int status = m_adapter->devicesetFocusPatch(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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 12:22:25 -05:00
|
|
|
void WebAPIRequestMapper::devicesetDeviceService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
2017-11-27 02:14:07 -05:00
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-11-27 02:14:07 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
|
|
|
|
|
|
|
if (request.getMethod() == "PUT")
|
|
|
|
{
|
|
|
|
QString jsonStr = request.getBody();
|
2017-12-07 12:50:36 -05:00
|
|
|
QJsonObject jsonObject;
|
2017-11-27 02:14:07 -05:00
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-11-27 02:14:07 -05:00
|
|
|
{
|
2018-02-14 07:40:34 -05:00
|
|
|
SWGSDRangel::SWGDeviceListItem query;
|
2017-12-23 01:28:02 -05:00
|
|
|
SWGSDRangel::SWGDeviceListItem normalResponse;
|
2017-11-27 02:14:07 -05:00
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
if (validateDeviceListItem(query, jsonObject))
|
2017-12-23 01:28:02 -05:00
|
|
|
{
|
2018-02-14 07:40:34 -05:00
|
|
|
int status = m_adapter->devicesetDevicePut(deviceSetIndex, query, normalResponse, errorResponse);
|
2017-12-23 01:28:02 -05:00
|
|
|
response.setStatus(status);
|
2017-11-27 02:14:07 -05:00
|
|
|
|
2017-12-23 01:28:02 -05:00
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Missing device identification");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Missing device identification";
|
2017-11-27 02:14:07 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-11-27 02:14:07 -05:00
|
|
|
}
|
2017-12-06 16:08:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-12-06 16:08:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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::devicesetDeviceSettingsService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-06 16:08:34 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
|
|
|
|
2017-12-07 07:55:42 -05:00
|
|
|
if ((request.getMethod() == "PUT") || (request.getMethod() == "PATCH"))
|
2017-12-06 16:08:34 -05:00
|
|
|
{
|
2017-12-07 07:55:42 -05:00
|
|
|
QString jsonStr = request.getBody();
|
2017-12-07 12:50:36 -05:00
|
|
|
QJsonObject jsonObject;
|
2017-12-07 07:55:42 -05:00
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
2017-12-07 07:55:42 -05:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings normalResponse;
|
2017-12-07 16:38:39 -05:00
|
|
|
resetDeviceSettings(normalResponse);
|
2017-12-26 19:46:33 -05:00
|
|
|
QStringList deviceSettingsKeys;
|
2017-12-07 07:55:42 -05:00
|
|
|
|
2017-12-26 19:46:33 -05:00
|
|
|
if (validateDeviceSettings(normalResponse, jsonObject, deviceSettingsKeys))
|
2017-12-07 07:55:42 -05:00
|
|
|
{
|
|
|
|
int status = m_adapter->devicesetDeviceSettingsPutPatch(
|
|
|
|
deviceSetIndex,
|
|
|
|
(request.getMethod() == "PUT"), // force settings on PUT
|
2017-12-26 19:46:33 -05:00
|
|
|
deviceSettingsKeys,
|
2017-12-07 07:55:42 -05:00
|
|
|
normalResponse,
|
|
|
|
errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-07 07:55:42 -05:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-12-06 16:08:34 -05:00
|
|
|
}
|
2017-12-04 12:22:25 -05:00
|
|
|
else if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings normalResponse;
|
2017-12-06 16:08:34 -05:00
|
|
|
resetDeviceSettings(normalResponse);
|
|
|
|
int status = m_adapter->devicesetDeviceSettingsGet(deviceSetIndex, normalResponse, errorResponse);
|
2017-12-04 12:22:25 -05:00
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-04 12:22:25 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-11-27 02:14:07 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-27 02:14:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Wrong integer conversion on device set index";
|
2017-12-08 11:12:33 -05:00
|
|
|
response.setStatus(400,"Invalid data");
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::devicesetDeviceRunService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-08 11:12:33 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
|
|
|
|
2017-12-09 04:49:20 -05:00
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceState normalResponse;
|
|
|
|
int status = m_adapter->devicesetDeviceRunGet(deviceSetIndex, normalResponse, errorResponse);
|
|
|
|
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-09 04:49:20 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (request.getMethod() == "POST")
|
2017-12-08 11:12:33 -05:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceState normalResponse;
|
|
|
|
int status = m_adapter->devicesetDeviceRunPost(deviceSetIndex, normalResponse, errorResponse);
|
|
|
|
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-08 11:12:33 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (request.getMethod() == "DELETE")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceState normalResponse;
|
|
|
|
int status = m_adapter->devicesetDeviceRunDelete(deviceSetIndex, normalResponse, errorResponse);
|
|
|
|
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-08 11:12:33 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
2019-12-24 13:08:11 -05:00
|
|
|
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::devicesetDeviceSubsystemRunService(const std::string& indexStr, const std::string& subsystemIndexStr, 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);
|
|
|
|
int subsystemIndex = boost::lexical_cast<int>(subsystemIndexStr);
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceState normalResponse;
|
|
|
|
int status = m_adapter->devicesetDeviceSubsystemRunGet(deviceSetIndex, subsystemIndex, 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::SWGDeviceState normalResponse;
|
|
|
|
int status = m_adapter->devicesetDeviceSubsystemRunPost(deviceSetIndex, subsystemIndex, 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::SWGDeviceState normalResponse;
|
|
|
|
int status = m_adapter->devicesetDeviceSubsystemRunDelete(deviceSetIndex, subsystemIndex, normalResponse, errorResponse);
|
|
|
|
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
2017-12-08 11:12:33 -05:00
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-12-08 11:12:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Wrong integer conversion on device set index";
|
2017-11-27 02:14:07 -05:00
|
|
|
response.setStatus(400,"Invalid data");
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 19:43:28 -04:00
|
|
|
void WebAPIRequestMapper::devicesetDeviceReportService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2018-05-25 19:43:28 -04:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceReport normalResponse;
|
2018-05-28 05:44:32 -04:00
|
|
|
resetDeviceReport(normalResponse);
|
2018-05-25 19:43:28 -04:00
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
|
|
|
int status = m_adapter->devicesetDeviceReportGet(deviceSetIndex, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-18 19:08:38 -04:00
|
|
|
void WebAPIRequestMapper::devicesetChannelsReportService(const std::string& indexStr, qtwebapp::HttpRequest& request, qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2018-03-18 19:08:38 -04:00
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelsDetail normalResponse;
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(indexStr);
|
|
|
|
int status = m_adapter->devicesetChannelsReportGet(deviceSetIndex, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 19:18:10 -05:00
|
|
|
void WebAPIRequestMapper::devicesetChannelService(
|
|
|
|
const std::string& deviceSetIndexStr,
|
|
|
|
qtwebapp::HttpRequest& request,
|
|
|
|
qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-10 19:18:10 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(deviceSetIndexStr);
|
|
|
|
|
|
|
|
if (request.getMethod() == "POST")
|
|
|
|
{
|
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
|
|
|
{
|
2017-12-19 11:55:05 -05:00
|
|
|
SWGSDRangel::SWGChannelSettings query;
|
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
|
|
|
resetChannelSettings(query);
|
2017-12-10 19:18:10 -05:00
|
|
|
|
2019-05-07 08:43:38 -04:00
|
|
|
if (jsonObject.contains("direction")) {
|
|
|
|
query.setDirection(jsonObject["direction"].toInt());
|
2017-12-10 19:18:10 -05:00
|
|
|
} else {
|
2019-05-07 08:43:38 -04:00
|
|
|
query.setDirection(0); // assume Rx
|
2017-12-10 19:18:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonObject.contains("channelType") && jsonObject["channelType"].isString())
|
|
|
|
{
|
2017-12-19 11:55:05 -05:00
|
|
|
query.setChannelType(new QString(jsonObject["channelType"].toString()));
|
2017-12-10 19:18:10 -05:00
|
|
|
|
2017-12-19 11:55:05 -05:00
|
|
|
int status = m_adapter->devicesetChannelPost(deviceSetIndex, query, normalResponse, errorResponse);
|
2017-12-10 19:18:10 -05:00
|
|
|
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-10 19:18:10 -05:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-12-10 19:18:10 -05:00
|
|
|
}
|
2017-12-12 12:56:24 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-12-10 19:18:10 -05:00
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Wrong integer conversion on index";
|
|
|
|
response.setStatus(400,"Invalid data");
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::devicesetChannelIndexService(
|
|
|
|
const std::string& deviceSetIndexStr,
|
|
|
|
const std::string& channelIndexStr,
|
|
|
|
qtwebapp::HttpRequest& request,
|
|
|
|
qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-10 19:18:10 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(deviceSetIndexStr);
|
|
|
|
int channelIndex = boost::lexical_cast<int>(channelIndexStr);
|
|
|
|
|
|
|
|
if (request.getMethod() == "DELETE")
|
|
|
|
{
|
2017-12-23 16:33:30 -05:00
|
|
|
SWGSDRangel::SWGSuccessResponse normalResponse;
|
|
|
|
int status = m_adapter->devicesetChannelDelete(deviceSetIndex, channelIndex, normalResponse, errorResponse);
|
2017-12-10 19:18:10 -05:00
|
|
|
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-10 19:18:10 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-12 12:56:24 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-12-10 19:18:10 -05:00
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Wrong integer conversion on index";
|
|
|
|
response.setStatus(400,"Invalid data");
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 14:27:08 -05:00
|
|
|
void WebAPIRequestMapper::devicesetChannelSettingsService(
|
|
|
|
const std::string& deviceSetIndexStr,
|
|
|
|
const std::string& channelIndexStr,
|
|
|
|
qtwebapp::HttpRequest& request,
|
|
|
|
qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-12-12 12:56:24 -05:00
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2017-12-10 14:27:08 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(deviceSetIndexStr);
|
|
|
|
int channelIndex = boost::lexical_cast<int>(channelIndexStr);
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings normalResponse;
|
|
|
|
resetChannelSettings(normalResponse);
|
|
|
|
int status = m_adapter->devicesetChannelSettingsGet(deviceSetIndex, channelIndex, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-10 14:27:08 -05:00
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
2017-12-11 12:18:47 -05:00
|
|
|
else if ((request.getMethod() == "PUT") || (request.getMethod() == "PATCH"))
|
|
|
|
{
|
|
|
|
QString jsonStr = request.getBody();
|
|
|
|
QJsonObject jsonObject;
|
|
|
|
|
|
|
|
if (parseJsonBody(jsonStr, jsonObject, response))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings normalResponse;
|
|
|
|
resetChannelSettings(normalResponse);
|
2017-12-23 21:27:07 -05:00
|
|
|
QStringList channelSettingsKeys;
|
2017-12-11 12:18:47 -05:00
|
|
|
|
2017-12-23 21:27:07 -05:00
|
|
|
if (validateChannelSettings(normalResponse, jsonObject, channelSettingsKeys))
|
2017-12-11 12:18:47 -05:00
|
|
|
{
|
|
|
|
int status = m_adapter->devicesetChannelSettingsPutPatch(
|
|
|
|
deviceSetIndex,
|
|
|
|
channelIndex,
|
|
|
|
(request.getMethod() == "PUT"), // force settings on PUT
|
2017-12-23 21:27:07 -05:00
|
|
|
channelSettingsKeys,
|
2017-12-11 12:18:47 -05:00
|
|
|
normalResponse,
|
|
|
|
errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
if (status/100 == 2) {
|
2017-12-11 12:18:47 -05:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 19:11:34 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(400,"Invalid JSON format");
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid JSON format";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
2017-12-11 12:18:47 -05:00
|
|
|
}
|
2017-12-10 14:27:08 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setStatus(405,"Invalid HTTP method");
|
2017-12-12 12:56:24 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Invalid HTTP method";
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-12-10 14:27:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Wrong integer conversion on index";
|
|
|
|
response.setStatus(400,"Invalid data");
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-18 15:17:11 -04:00
|
|
|
void WebAPIRequestMapper::devicesetChannelReportService(
|
|
|
|
const std::string& deviceSetIndexStr,
|
|
|
|
const std::string& channelIndexStr,
|
|
|
|
qtwebapp::HttpRequest& request,
|
|
|
|
qtwebapp::HttpResponse& response)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
|
|
|
response.setHeader("Content-Type", "application/json");
|
2018-07-16 19:50:32 -04:00
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
2018-03-18 15:17:11 -04:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int deviceSetIndex = boost::lexical_cast<int>(deviceSetIndexStr);
|
|
|
|
int channelIndex = boost::lexical_cast<int>(channelIndexStr);
|
|
|
|
|
|
|
|
if (request.getMethod() == "GET")
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelReport normalResponse;
|
|
|
|
resetChannelReport(normalResponse);
|
|
|
|
int status = m_adapter->devicesetChannelReportGet(deviceSetIndex, channelIndex, normalResponse, errorResponse);
|
|
|
|
response.setStatus(status);
|
|
|
|
|
|
|
|
if (status/100 == 2) {
|
|
|
|
response.write(normalResponse.asJson().toUtf8());
|
|
|
|
} else {
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const boost::bad_lexical_cast &e)
|
|
|
|
{
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = "Wrong integer conversion on index";
|
|
|
|
response.setStatus(400,"Invalid data");
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
bool WebAPIRequestMapper::parseJsonBody(QString& jsonStr, QJsonObject& jsonObject, qtwebapp::HttpResponse& response)
|
2017-11-24 11:12:53 -05:00
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse errorResponse;
|
2017-11-24 11:12:53 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QByteArray jsonBytes(jsonStr.toStdString().c_str());
|
|
|
|
QJsonParseError error;
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(jsonBytes, &error);
|
|
|
|
|
2017-12-07 12:50:36 -05:00
|
|
|
if (error.error == QJsonParseError::NoError)
|
|
|
|
{
|
|
|
|
jsonObject = doc.object();
|
|
|
|
}
|
|
|
|
else
|
2017-11-24 11:12:53 -05:00
|
|
|
{
|
2017-11-24 22:02:11 -05:00
|
|
|
QString errorMsg = QString("Input JSON error: ") + error.errorString() + QString(" at offset ") + QString::number(error.offset);
|
2017-11-24 11:12:53 -05:00
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = errorMsg;
|
|
|
|
response.setStatus(400, errorMsg.toUtf8());
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
2017-11-17 02:52:15 -05:00
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
|
|
|
|
return (error.error == QJsonParseError::NoError);
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
QString errorMsg = QString("Error parsing request: ") + ex.what();
|
|
|
|
errorResponse.init();
|
|
|
|
*errorResponse.getMessage() = errorMsg;
|
|
|
|
response.setStatus(500, errorMsg.toUtf8());
|
|
|
|
response.write(errorResponse.asJson().toUtf8());
|
|
|
|
|
|
|
|
return false;
|
2017-11-16 21:17:15 -05:00
|
|
|
}
|
|
|
|
}
|
2017-11-25 13:42:56 -05:00
|
|
|
|
2017-12-01 23:45:30 -05:00
|
|
|
bool WebAPIRequestMapper::validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer)
|
2017-11-25 13:42:56 -05:00
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = presetTransfer.getPreset();
|
2017-11-25 13:42:56 -05:00
|
|
|
|
|
|
|
if (presetIdentifier == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return validatePresetIdentifer(*presetIdentifier);
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:45:30 -05:00
|
|
|
bool WebAPIRequestMapper::validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier)
|
2017-11-25 13:42:56 -05:00
|
|
|
{
|
|
|
|
return (presetIdentifier.getGroupName() && presetIdentifier.getName() && presetIdentifier.getType());
|
|
|
|
}
|
|
|
|
|
2017-12-18 19:11:34 -05:00
|
|
|
bool WebAPIRequestMapper::validatePresetExport(SWGSDRangel::SWGPresetExport& presetExport)
|
|
|
|
{
|
|
|
|
if (presetExport.getFilePath() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = presetExport.getPreset();
|
|
|
|
|
|
|
|
if (presetIdentifier == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return validatePresetIdentifer(*presetIdentifier);
|
|
|
|
}
|
|
|
|
|
2017-12-23 01:28:02 -05:00
|
|
|
bool WebAPIRequestMapper::validateDeviceListItem(SWGSDRangel::SWGDeviceListItem& deviceListItem, QJsonObject& jsonObject)
|
|
|
|
{
|
2019-05-07 08:43:38 -04:00
|
|
|
if (jsonObject.contains("direction")) {
|
|
|
|
deviceListItem.setDirection(jsonObject["direction"].toInt());
|
2017-12-23 01:28:02 -05:00
|
|
|
} else {
|
2019-05-07 08:43:38 -04:00
|
|
|
deviceListItem.setDirection(0); // assume Rx
|
2017-12-23 01:28:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool identified = false;
|
|
|
|
|
|
|
|
if (jsonObject.contains("displayedName") && jsonObject["displayedName"].isString())
|
|
|
|
{
|
|
|
|
deviceListItem.setDisplayedName(new QString(jsonObject["displayedName"].toString()));
|
|
|
|
identified = true;
|
|
|
|
} else {
|
|
|
|
deviceListItem.setDisplayedName(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (jsonObject.contains("hwType") && jsonObject["hwType"].isString())
|
|
|
|
{
|
|
|
|
deviceListItem.setHwType(new QString(jsonObject["hwType"].toString()));
|
|
|
|
identified = true;
|
|
|
|
} else {
|
|
|
|
deviceListItem.setHwType(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonObject.contains("serial") && jsonObject["serial"].isString())
|
|
|
|
{
|
|
|
|
deviceListItem.setSerial(new QString(jsonObject["serial"].toString()));
|
|
|
|
identified = true;
|
|
|
|
} else {
|
|
|
|
deviceListItem.setSerial(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonObject.contains("index")) {
|
|
|
|
deviceListItem.setIndex(jsonObject["index"].toInt(-1));
|
|
|
|
} else {
|
|
|
|
deviceListItem.setIndex(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonObject.contains("sequence")){
|
|
|
|
deviceListItem.setSequence(jsonObject["sequence"].toInt(-1));
|
|
|
|
} else {
|
|
|
|
deviceListItem.setSequence(-1);
|
|
|
|
}
|
|
|
|
|
2019-05-07 09:25:20 -04:00
|
|
|
if (jsonObject.contains("deviceStreamIndex")) {
|
|
|
|
deviceListItem.setDeviceStreamIndex(jsonObject["deviceStreamIndex"].toInt(-1));
|
2017-12-23 01:28:02 -05:00
|
|
|
} else {
|
2019-05-07 09:25:20 -04:00
|
|
|
deviceListItem.setDeviceStreamIndex(-1);
|
2017-12-23 01:28:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return identified;
|
|
|
|
}
|
|
|
|
|
2017-12-26 19:46:33 -05:00
|
|
|
bool WebAPIRequestMapper::validateDeviceSettings(
|
|
|
|
SWGSDRangel::SWGDeviceSettings& deviceSettings,
|
|
|
|
QJsonObject& jsonObject,
|
|
|
|
QStringList& deviceSettingsKeys)
|
2017-12-07 07:55:42 -05:00
|
|
|
{
|
2019-05-07 08:43:38 -04:00
|
|
|
if (jsonObject.contains("direction")) {
|
|
|
|
deviceSettings.setDirection(jsonObject["direction"].toInt());
|
2017-12-07 16:38:39 -05:00
|
|
|
} else {
|
2019-05-07 08:43:38 -04:00
|
|
|
deviceSettings.setDirection(0); // assume single Rx
|
2017-12-07 16:38:39 -05:00
|
|
|
}
|
2017-12-07 07:55:42 -05:00
|
|
|
|
2017-12-07 18:56:29 -05:00
|
|
|
if (jsonObject.contains("deviceHwType") && jsonObject["deviceHwType"].isString()) {
|
2017-12-07 16:38:39 -05:00
|
|
|
deviceSettings.setDeviceHwType(new QString(jsonObject["deviceHwType"].toString()));
|
|
|
|
} else {
|
2017-12-07 07:55:42 -05:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-07 16:38:39 -05:00
|
|
|
|
|
|
|
QString *deviceHwType = deviceSettings.getDeviceHwType();
|
2019-08-06 18:27:34 -04:00
|
|
|
QString deviceSettingsKey;
|
2017-12-07 16:38:39 -05:00
|
|
|
|
2019-08-06 18:27:34 -04:00
|
|
|
if (deviceSettings.getDirection() == 0) // source
|
2018-05-25 16:39:38 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
if (m_sourceDeviceHwIdToSettingsKey.contains(*deviceHwType)) {
|
|
|
|
deviceSettingsKey = m_sourceDeviceHwIdToSettingsKey[*deviceHwType];
|
|
|
|
} else {
|
2018-05-25 16:39:38 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
else if (deviceSettings.getDirection() == 1) // sink
|
2018-03-22 01:34:51 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
if (m_sinkDeviceHwIdToSettingsKey.contains(*deviceHwType)) {
|
|
|
|
deviceSettingsKey = m_sinkDeviceHwIdToSettingsKey[*deviceHwType];
|
|
|
|
} else {
|
2018-03-22 01:34:51 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
else
|
2018-03-31 13:29:52 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
return false;
|
2019-01-01 12:28:53 -05:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
|
|
|
|
return getDevice(deviceSettingsKey, &deviceSettings, jsonObject, deviceSettingsKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::validateChannelSettings(
|
|
|
|
SWGSDRangel::SWGChannelSettings& channelSettings,
|
|
|
|
QJsonObject& jsonObject,
|
|
|
|
QStringList& channelSettingsKeys)
|
|
|
|
{
|
|
|
|
if (jsonObject.contains("direction")) {
|
|
|
|
channelSettings.setDirection(jsonObject["direction"].toInt());
|
|
|
|
} else {
|
|
|
|
channelSettings.setDirection(0); // assume single Rx
|
2019-01-01 12:28:53 -05:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
|
|
|
|
if (jsonObject.contains("channelType") && jsonObject["channelType"].isString()) {
|
|
|
|
channelSettings.setChannelType(new QString(jsonObject["channelType"].toString()));
|
|
|
|
} else {
|
|
|
|
return false;
|
2018-03-31 13:29:52 -04:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
|
|
|
|
QString *channelType = channelSettings.getChannelType();
|
|
|
|
|
|
|
|
if (m_channelTypeToSettingsKey.contains(*channelType)) {
|
|
|
|
return getChannel(m_channelTypeToSettingsKey[*channelType], &channelSettings, jsonObject, channelSettingsKeys);
|
|
|
|
} else {
|
|
|
|
return false;
|
2018-05-26 07:24:35 -04:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::validateAudioInputDevice(
|
|
|
|
SWGSDRangel::SWGAudioInputDevice& audioInputDevice,
|
|
|
|
QJsonObject& jsonObject,
|
|
|
|
QStringList& audioInputDeviceKeys)
|
|
|
|
{
|
|
|
|
if (jsonObject.contains("index")) {
|
|
|
|
audioInputDevice.setIndex(jsonObject["index"].toInt());
|
|
|
|
} else {
|
|
|
|
audioInputDevice.setIndex(-1); // assume systam default
|
2018-05-26 07:24:35 -04:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("sampleRate"))
|
2018-05-26 07:24:35 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioInputDevice.setSampleRate(jsonObject["sampleRate"].toInt());
|
|
|
|
audioInputDeviceKeys.append("sampleRate");
|
2018-05-26 07:24:35 -04:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("volume"))
|
2017-12-07 18:56:29 -05:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioInputDevice.setVolume(jsonObject["volume"].toDouble());
|
|
|
|
audioInputDeviceKeys.append("volume");
|
2017-12-28 19:40:34 -05:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::validateAudioOutputDevice(
|
|
|
|
SWGSDRangel::SWGAudioOutputDevice& audioOutputDevice,
|
|
|
|
QJsonObject& jsonObject,
|
|
|
|
QStringList& audioOutputDeviceKeys)
|
|
|
|
{
|
|
|
|
if (jsonObject.contains("index")) {
|
|
|
|
audioOutputDevice.setIndex(jsonObject["index"].toInt());
|
|
|
|
} else {
|
|
|
|
audioOutputDevice.setIndex(-1); // assume systam default
|
2017-12-07 07:55:42 -05:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("sampleRate"))
|
2019-06-08 15:25:08 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioOutputDevice.setSampleRate(jsonObject["sampleRate"].toInt());
|
|
|
|
audioOutputDeviceKeys.append("sampleRate");
|
2019-06-08 15:25:08 -04:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("copyToUDP"))
|
2017-12-07 18:56:29 -05:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioOutputDevice.setCopyToUdp(jsonObject["copyToUDP"].toInt() == 0 ? 0 : 1);
|
|
|
|
audioOutputDeviceKeys.append("copyToUDP");
|
2017-12-07 18:56:29 -05:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("udpUsesRTP"))
|
2017-12-07 18:56:29 -05:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioOutputDevice.setUdpUsesRtp(jsonObject["udpUsesRTP"].toInt() == 0 ? 0 : 1);
|
|
|
|
audioOutputDeviceKeys.append("udpUsesRTP");
|
2017-12-07 18:56:29 -05:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("udpChannelMode"))
|
2018-05-26 07:24:35 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioOutputDevice.setUdpChannelMode(jsonObject["udpChannelMode"].toInt());
|
|
|
|
audioOutputDeviceKeys.append("udpChannelMode");
|
2018-05-26 07:24:35 -04:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("udpChannelCodec"))
|
2018-05-26 12:07:21 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioOutputDevice.setUdpChannelCodec(jsonObject["udpChannelCodec"].toInt());
|
|
|
|
audioOutputDeviceKeys.append("udpChannelCodec");
|
2018-05-26 12:07:21 -04:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("udpDecimationFactor"))
|
2018-05-26 14:33:02 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioOutputDevice.setUdpDecimationFactor(jsonObject["udpDecimationFactor"].toInt());
|
|
|
|
audioOutputDeviceKeys.append("udpDecimationFactor");
|
2018-05-26 14:33:02 -04:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("udpAddress"))
|
2017-12-28 19:40:34 -05:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioOutputDevice.setUdpAddress(new QString(jsonObject["udpAddress"].toString()));
|
|
|
|
audioOutputDeviceKeys.append("udpAddress");
|
2017-12-28 19:40:34 -05:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
if (jsonObject.contains("udpPort"))
|
2019-01-16 19:01:59 -05:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
audioOutputDevice.setUdpPort(jsonObject["udpPort"].toInt());
|
|
|
|
audioOutputDeviceKeys.append("udpPort");
|
2019-01-16 19:01:59 -05:00
|
|
|
}
|
2019-08-06 18:27:34 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::validateAMBEDevices(SWGSDRangel::SWGAMBEDevices& ambeDevices, QJsonObject& jsonObject)
|
|
|
|
{
|
|
|
|
if (jsonObject.contains("nbDevices"))
|
2018-11-15 02:46:29 -05:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
int nbDevices = jsonObject["nbDevices"].toInt();
|
|
|
|
|
|
|
|
if (jsonObject.contains("ambeDevices"))
|
2019-07-20 19:57:51 -04:00
|
|
|
{
|
|
|
|
QJsonArray ambeDevicesJson = jsonObject["ambeDevices"].toArray();
|
|
|
|
|
|
|
|
if (nbDevices != ambeDevicesJson.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ambeDevices.init();
|
|
|
|
ambeDevices.setNbDevices(nbDevices);
|
|
|
|
QList<SWGSDRangel::SWGAMBEDevice *> *ambeList = ambeDevices.getAmbeDevices();
|
|
|
|
|
|
|
|
for (int i = 0; i < nbDevices; i++)
|
|
|
|
{
|
|
|
|
QJsonObject ambeDeviceJson = ambeDevicesJson.at(i).toObject();
|
|
|
|
if (ambeDeviceJson.contains("deviceRef") && ambeDeviceJson.contains("delete"))
|
|
|
|
{
|
|
|
|
ambeList->push_back(new SWGSDRangel::SWGAMBEDevice());
|
|
|
|
ambeList->back()->init();
|
|
|
|
ambeList->back()->setDeviceRef(new QString(ambeDeviceJson["deviceRef"].toString()));
|
|
|
|
ambeList->back()->setDelete(ambeDeviceJson["delete"].toInt());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-07-25 05:36:10 -04:00
|
|
|
|
|
|
|
return true;
|
2019-07-20 19:57:51 -04:00
|
|
|
}
|
|
|
|
}
|
2019-07-25 05:36:10 -04:00
|
|
|
|
|
|
|
return false;
|
2019-07-20 19:57:51 -04:00
|
|
|
}
|
|
|
|
|
2020-01-11 19:16:04 -05:00
|
|
|
bool WebAPIRequestMapper::validateLimeRFEConfig(SWGSDRangel::SWGLimeRFESettings& limeRFESettings, QJsonObject& jsonObject, QStringList& limeRFESettingsKeys)
|
|
|
|
{
|
|
|
|
if (jsonObject.contains("devicePath"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setDevicePath(new QString(jsonObject["devicePath"].toString()));
|
|
|
|
limeRFESettingsKeys.append("devicePath");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("rxChannels"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setRxChannels(jsonObject["rxChannels"].toInt());
|
|
|
|
limeRFESettingsKeys.append("rxChannels");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("rxWidebandChannel"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setRxWidebandChannel(jsonObject["rxWidebandChannel"].toInt());
|
|
|
|
limeRFESettingsKeys.append("rxWidebandChannel");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("rxHAMChannel"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setRxHamChannel(jsonObject["rxHAMChannel"].toInt());
|
|
|
|
limeRFESettingsKeys.append("rxHAMChannel");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("rxCellularChannel"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setRxCellularChannel(jsonObject["rxCellularChannel"].toInt());
|
|
|
|
limeRFESettingsKeys.append("rxCellularChannel");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("rxPort"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setRxPort(jsonObject["rxPort"].toInt());
|
|
|
|
limeRFESettingsKeys.append("rxPort");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("attenuationFactor"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setAttenuationFactor(jsonObject["attenuationFactor"].toInt());
|
|
|
|
limeRFESettingsKeys.append("attenuationFactor");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("amfmNotch"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setAmfmNotch(jsonObject["amfmNotch"].toInt());
|
|
|
|
limeRFESettingsKeys.append("amfmNotch");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("txChannels"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setTxChannels(jsonObject["txChannels"].toInt());
|
|
|
|
limeRFESettingsKeys.append("txChannels");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("txWidebandChannel"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setTxWidebandChannel(jsonObject["txWidebandChannel"].toInt());
|
|
|
|
limeRFESettingsKeys.append("txWidebandChannel");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("txHAMChannel"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setTxHamChannel(jsonObject["txHAMChannel"].toInt());
|
|
|
|
limeRFESettingsKeys.append("txHAMChannel");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("txCellularChannel"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setTxCellularChannel(jsonObject["txCellularChannel"].toInt());
|
|
|
|
limeRFESettingsKeys.append("txCellularChannel");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("txPort"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setTxPort(jsonObject["txPort"].toInt());
|
|
|
|
limeRFESettingsKeys.append("txPort");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("rxOn"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setRxOn(jsonObject["rxOn"].toInt());
|
|
|
|
limeRFESettingsKeys.append("rxOn");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("txOn"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setTxOn(jsonObject["txOn"].toInt());
|
|
|
|
limeRFESettingsKeys.append("txOn");
|
|
|
|
}
|
2020-01-14 18:28:25 -05:00
|
|
|
if (jsonObject.contains("swrEnable"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setSwrEnable(jsonObject["swrEnable"].toInt());
|
|
|
|
limeRFESettingsKeys.append("swrEnable");
|
|
|
|
}
|
|
|
|
if (jsonObject.contains("swrSource"))
|
|
|
|
{
|
|
|
|
limeRFESettings.setSwrSource(jsonObject["swrSource"].toInt());
|
|
|
|
limeRFESettingsKeys.append("swrSource");
|
|
|
|
}
|
2020-01-11 19:16:04 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-06 13:06:49 -04:00
|
|
|
bool WebAPIRequestMapper::validateConfig(SWGSDRangel::SWGInstanceConfigResponse& config, QJsonObject& jsonObject, WebAPIAdapterInterface::ConfigKeys& configKeys)
|
|
|
|
{
|
|
|
|
if (jsonObject.contains("preferences"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGPreferences *preferences = new SWGSDRangel::SWGPreferences();
|
|
|
|
config.setPreferences(preferences);
|
|
|
|
QJsonObject preferencesJson = jsonObject["preferences"].toObject();
|
|
|
|
configKeys.m_preferencesKeys = preferencesJson.keys();
|
|
|
|
preferences->fromJsonObject(preferencesJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonObject.contains("commands"))
|
|
|
|
{
|
|
|
|
QList<SWGSDRangel::SWGCommand *> *commands = new QList<SWGSDRangel::SWGCommand *>();
|
|
|
|
config.setCommands(commands);
|
|
|
|
QJsonArray commandsJson = jsonObject["commands"].toArray();
|
|
|
|
QJsonArray::const_iterator commandsIt = commandsJson.begin();
|
|
|
|
|
|
|
|
for (; commandsIt != commandsJson.end(); ++commandsIt)
|
|
|
|
{
|
|
|
|
QJsonObject commandJson = commandsIt->toObject();
|
|
|
|
commands->append(new SWGSDRangel::SWGCommand());
|
|
|
|
configKeys.m_commandKeys.append(WebAPIAdapterInterface::CommandKeys());
|
|
|
|
configKeys.m_commandKeys.back().m_keys = commandJson.keys();
|
|
|
|
commands->back()->fromJsonObject(commandJson);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 12:42:17 -04:00
|
|
|
if (jsonObject.contains("presets"))
|
|
|
|
{
|
2019-08-11 19:46:27 -04:00
|
|
|
QList<SWGSDRangel::SWGPreset *> *presets = new QList<SWGSDRangel::SWGPreset *>();
|
|
|
|
config.setPresets(presets);
|
2019-08-08 12:42:17 -04:00
|
|
|
QJsonArray presetsJson = jsonObject["presets"].toArray();
|
|
|
|
QJsonArray::const_iterator presetsIt = presetsJson.begin();
|
|
|
|
|
|
|
|
for (; presetsIt != presetsJson.end(); ++presetsIt)
|
|
|
|
{
|
|
|
|
QJsonObject presetJson = presetsIt->toObject();
|
2019-08-11 19:46:27 -04:00
|
|
|
SWGSDRangel::SWGPreset *preset = new SWGSDRangel::SWGPreset();
|
|
|
|
presets->append(preset);
|
2019-08-08 12:42:17 -04:00
|
|
|
configKeys.m_presetKeys.append(WebAPIAdapterInterface::PresetKeys());
|
|
|
|
appendPresetKeys(preset, presetJson, configKeys.m_presetKeys.back());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 13:06:49 -04:00
|
|
|
if (jsonObject.contains("workingPreset"))
|
|
|
|
{
|
2019-08-08 12:42:17 -04:00
|
|
|
SWGSDRangel::SWGPreset *preset = new SWGSDRangel::SWGPreset();
|
|
|
|
config.setWorkingPreset(preset);
|
2019-08-06 13:06:49 -04:00
|
|
|
QJsonObject presetJson = jsonObject["workingPreset"].toObject();
|
2019-08-08 12:42:17 -04:00
|
|
|
appendPresetKeys(preset, presetJson, configKeys.m_workingPresetKeys);
|
2019-08-06 13:06:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::appendPresetKeys(
|
|
|
|
SWGSDRangel::SWGPreset *preset,
|
|
|
|
const QJsonObject& presetJson,
|
|
|
|
WebAPIAdapterInterface::PresetKeys& presetKeys
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (presetJson.contains("centerFrequency"))
|
|
|
|
{
|
|
|
|
preset->setCenterFrequency(presetJson["centerFrequency"].toInt());
|
|
|
|
presetKeys.m_keys.append("centerFrequency");
|
|
|
|
}
|
|
|
|
if (presetJson.contains("dcOffsetCorrection"))
|
|
|
|
{
|
|
|
|
preset->setDcOffsetCorrection(presetJson["dcOffsetCorrection"].toInt());
|
|
|
|
presetKeys.m_keys.append("dcOffsetCorrection");
|
|
|
|
}
|
|
|
|
if (presetJson.contains("iqImbalanceCorrection"))
|
|
|
|
{
|
|
|
|
preset->setIqImbalanceCorrection(presetJson["iqImbalanceCorrection"].toInt());
|
|
|
|
presetKeys.m_keys.append("iqImbalanceCorrection");
|
|
|
|
}
|
|
|
|
if (presetJson.contains("iqImbalanceCorrection"))
|
|
|
|
{
|
2019-09-13 07:40:31 -04:00
|
|
|
preset->setPresetType(presetJson["presetType"].toInt());
|
|
|
|
presetKeys.m_keys.append("presetType");
|
2019-08-06 13:06:49 -04:00
|
|
|
}
|
|
|
|
if (presetJson.contains("description"))
|
|
|
|
{
|
|
|
|
preset->setDescription(new QString(presetJson["description"].toString()));
|
|
|
|
presetKeys.m_keys.append("description");
|
|
|
|
}
|
|
|
|
if (presetJson.contains("group"))
|
|
|
|
{
|
|
|
|
preset->setGroup(new QString(presetJson["group"].toString()));
|
|
|
|
presetKeys.m_keys.append("group");
|
|
|
|
}
|
2019-08-13 06:18:47 -04:00
|
|
|
if (presetJson.contains("layout"))
|
|
|
|
{
|
|
|
|
preset->setLayout(new QString(presetJson["layout"].toString()));
|
|
|
|
presetKeys.m_keys.append("layout");
|
|
|
|
}
|
2019-08-06 13:06:49 -04:00
|
|
|
|
|
|
|
if (presetJson.contains("spectrumConfig"))
|
|
|
|
{
|
|
|
|
QJsonObject spectrumJson = presetJson["spectrumConfig"].toObject();
|
|
|
|
presetKeys.m_spectrumKeys = spectrumJson.keys();
|
|
|
|
SWGSDRangel::SWGGLSpectrum *spectrum = new SWGSDRangel::SWGGLSpectrum();
|
|
|
|
preset->setSpectrumConfig(spectrum);
|
|
|
|
spectrum->fromJsonObject(spectrumJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (presetJson.contains("channelConfigs"))
|
|
|
|
{
|
|
|
|
QJsonArray channelsJson = presetJson["channelConfigs"].toArray();
|
|
|
|
QJsonArray::const_iterator channelsIt = channelsJson.begin();
|
|
|
|
QList<SWGSDRangel::SWGChannelConfig*> *channels = new QList<SWGSDRangel::SWGChannelConfig*>();
|
|
|
|
preset->setChannelConfigs(channels);
|
|
|
|
|
|
|
|
for (; channelsIt != channelsJson.end(); ++channelsIt)
|
|
|
|
{
|
|
|
|
QJsonObject channelJson = channelsIt->toObject();
|
2019-08-11 19:46:27 -04:00
|
|
|
SWGSDRangel::SWGChannelConfig *channelConfig = new SWGSDRangel::SWGChannelConfig();
|
2019-08-06 13:06:49 -04:00
|
|
|
presetKeys.m_channelsKeys.append(WebAPIAdapterInterface::ChannelKeys());
|
|
|
|
|
2019-08-11 19:46:27 -04:00
|
|
|
if (appendPresetChannelKeys(channelConfig, channelJson, presetKeys.m_channelsKeys.back()))
|
|
|
|
{
|
|
|
|
channels->append(channelConfig);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete channelConfig;
|
|
|
|
presetKeys.m_channelsKeys.takeLast(); // remove channel keys
|
2019-08-06 13:06:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (presetJson.contains("deviceConfigs"))
|
|
|
|
{
|
|
|
|
QJsonArray devicesJson = presetJson["deviceConfigs"].toArray();
|
|
|
|
QJsonArray::const_iterator devicesIt = devicesJson.begin();
|
|
|
|
QList<SWGSDRangel::SWGDeviceConfig*> *devices = new QList<SWGSDRangel::SWGDeviceConfig*>();
|
|
|
|
preset->setDeviceConfigs(devices);
|
|
|
|
|
|
|
|
for (; devicesIt != devicesJson.end(); ++devicesIt)
|
|
|
|
{
|
|
|
|
QJsonObject deviceJson = devicesIt->toObject();
|
2019-08-11 19:46:27 -04:00
|
|
|
SWGSDRangel::SWGDeviceConfig *deviceConfig = new SWGSDRangel::SWGDeviceConfig();
|
2019-08-06 13:06:49 -04:00
|
|
|
presetKeys.m_devicesKeys.append(WebAPIAdapterInterface::DeviceKeys());
|
|
|
|
|
2019-08-11 19:46:27 -04:00
|
|
|
if (appendPresetDeviceKeys(deviceConfig, deviceJson, presetKeys.m_devicesKeys.back()))
|
|
|
|
{
|
|
|
|
devices->append(deviceConfig);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete deviceConfig;
|
|
|
|
presetKeys.m_devicesKeys.takeLast(); // remove device keys
|
2019-08-06 13:06:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::appendPresetChannelKeys(
|
|
|
|
SWGSDRangel::SWGChannelConfig *channel,
|
2019-08-06 18:27:34 -04:00
|
|
|
const QJsonObject& channelSettingsJson,
|
2019-08-06 13:06:49 -04:00
|
|
|
WebAPIAdapterInterface::ChannelKeys& channelKeys
|
|
|
|
)
|
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
if (channelSettingsJson.contains("channelIdURI"))
|
2019-08-06 13:06:49 -04:00
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
QString *channelURI = new QString(channelSettingsJson["channelIdURI"].toString());
|
2019-08-06 13:06:49 -04:00
|
|
|
channel->setChannelIdUri(channelURI);
|
|
|
|
channelKeys.m_keys.append("channelIdURI");
|
|
|
|
|
2019-08-06 18:27:34 -04:00
|
|
|
if (channelSettingsJson.contains("config") && m_channelURIToSettingsKey.contains(*channelURI))
|
2019-08-06 13:06:49 -04:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *channelSettings = new SWGSDRangel::SWGChannelSettings();
|
2019-08-10 19:27:19 -04:00
|
|
|
channel->setConfig(channelSettings);
|
2019-08-06 18:27:34 -04:00
|
|
|
return getChannel(m_channelURIToSettingsKey[*channelURI], channelSettings, channelSettingsJson["config"].toObject(), channelKeys.m_channelKeys);
|
2019-08-06 13:06:49 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::getChannel(
|
|
|
|
const QString& channelSettingsKey,
|
|
|
|
SWGSDRangel::SWGChannelSettings *channelSettings,
|
|
|
|
const QJsonObject& channelSettingsJson,
|
|
|
|
QStringList& channelSettingsKeys
|
|
|
|
)
|
|
|
|
{
|
|
|
|
QStringList channelKeys = channelSettingsJson.keys();
|
|
|
|
|
|
|
|
if (channelKeys.contains(channelSettingsKey) && channelSettingsJson[channelSettingsKey].isObject())
|
|
|
|
{
|
|
|
|
QJsonObject settingsJsonObject = channelSettingsJson[channelSettingsKey].toObject();
|
|
|
|
channelSettingsKeys = settingsJsonObject.keys();
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
// get possible sub-keys
|
|
|
|
if (channelSettingsKeys.contains("cwKeyer"))
|
|
|
|
{
|
|
|
|
QJsonObject cwJson; // unused
|
|
|
|
appendSettingsSubKeys(settingsJsonObject, cwJson, "cwKeyer", channelSettingsKeys);
|
|
|
|
}
|
|
|
|
|
2019-08-06 13:06:49 -04:00
|
|
|
if (channelSettingsKey == "AMDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setAmDemodSettings(new SWGSDRangel::SWGAMDemodSettings());
|
|
|
|
channelSettings->getAmDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "AMModSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setAmModSettings(new SWGSDRangel::SWGAMModSettings());
|
|
|
|
channelSettings->getAmModSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
2019-08-11 05:35:53 -04:00
|
|
|
else if (channelSettingsKey == "ATVDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setAtvDemodSettings(new SWGSDRangel::SWGATVDemodSettings());
|
|
|
|
channelSettings->getAtvDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
2019-08-06 13:06:49 -04:00
|
|
|
else if (channelSettingsKey == "ATVModSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setAtvModSettings(new SWGSDRangel::SWGATVModSettings());
|
|
|
|
channelSettings->getAtvModSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "BFMDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setBfmDemodSettings(new SWGSDRangel::SWGBFMDemodSettings());
|
|
|
|
channelSettings->getBfmDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
2019-08-08 12:42:17 -04:00
|
|
|
else if (channelSettingsKey == "ChannelAnalyzerSettings")
|
|
|
|
{
|
2019-08-08 20:41:17 -04:00
|
|
|
processChannelAnalyzerSettings(channelSettings, settingsJsonObject, channelSettingsKeys);
|
2019-08-08 12:42:17 -04:00
|
|
|
}
|
2019-08-11 06:47:51 -04:00
|
|
|
else if (channelSettingsKey == "DATVDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setDatvDemodSettings(new SWGSDRangel::SWGDATVDemodSettings());
|
|
|
|
channelSettings->getDatvDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
2019-08-06 13:06:49 -04:00
|
|
|
else if (channelSettingsKey == "DSDDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setDsdDemodSettings(new SWGSDRangel::SWGDSDDemodSettings());
|
|
|
|
channelSettings->getDsdDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
2019-08-13 06:18:47 -04:00
|
|
|
else if (channelSettingsKey == "FileSourceSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setFileSourceSettings(new SWGSDRangel::SWGFileSourceSettings());
|
|
|
|
channelSettings->getFileSourceSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
2019-08-06 13:06:49 -04:00
|
|
|
else if (channelSettingsKey == "FreeDVDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setFreeDvDemodSettings(new SWGSDRangel::SWGFreeDVDemodSettings());
|
|
|
|
channelSettings->getFreeDvDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "FreeDVModSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setFreeDvModSettings(new SWGSDRangel::SWGFreeDVModSettings());
|
|
|
|
channelSettings->getFreeDvModSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "FreqTrackerSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setFreqTrackerSettings(new SWGSDRangel::SWGFreqTrackerSettings());
|
|
|
|
channelSettings->getFreqTrackerSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "NFMDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setNfmDemodSettings(new SWGSDRangel::SWGNFMDemodSettings());
|
|
|
|
channelSettings->getNfmDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "NFMModSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setNfmModSettings(new SWGSDRangel::SWGNFMModSettings());
|
|
|
|
channelSettings->getNfmModSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "LocalSinkSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setLocalSinkSettings(new SWGSDRangel::SWGLocalSinkSettings());
|
|
|
|
channelSettings->getLocalSinkSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "LocalSourceSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setLocalSourceSettings(new SWGSDRangel::SWGLocalSourceSettings());
|
|
|
|
channelSettings->getLocalSourceSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "RemoteSinkSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setRemoteSinkSettings(new SWGSDRangel::SWGRemoteSinkSettings());
|
|
|
|
channelSettings->getRemoteSinkSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "RemoteSourceSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setRemoteSourceSettings(new SWGSDRangel::SWGRemoteSourceSettings());
|
|
|
|
channelSettings->getRemoteSourceSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "SSBDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setSsbDemodSettings(new SWGSDRangel::SWGSSBDemodSettings());
|
|
|
|
channelSettings->getSsbDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "SSBModSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setSsbModSettings(new SWGSDRangel::SWGSSBModSettings());
|
|
|
|
channelSettings->getSsbModSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "UDPSourceSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setUdpSourceSettings(new SWGSDRangel::SWGUDPSourceSettings());
|
|
|
|
channelSettings->getUdpSourceSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "UDPSinkSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setUdpSinkSettings(new SWGSDRangel::SWGUDPSinkSettings());
|
|
|
|
channelSettings->getUdpSinkSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "WFMDemodSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setWfmDemodSettings(new SWGSDRangel::SWGWFMDemodSettings());
|
|
|
|
channelSettings->getWfmDemodSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (channelSettingsKey == "WFMModSettings")
|
|
|
|
{
|
|
|
|
channelSettings->setWfmModSettings(new SWGSDRangel::SWGWFMModSettings());
|
|
|
|
channelSettings->getWfmModSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::appendPresetDeviceKeys(
|
|
|
|
SWGSDRangel::SWGDeviceConfig *device,
|
2019-08-06 18:27:34 -04:00
|
|
|
const QJsonObject& deviceSettngsJson,
|
|
|
|
WebAPIAdapterInterface::DeviceKeys& devicelKeys
|
2019-08-06 13:06:49 -04:00
|
|
|
)
|
|
|
|
{
|
2019-08-06 18:27:34 -04:00
|
|
|
if (deviceSettngsJson.contains("deviceId"))
|
|
|
|
{
|
|
|
|
QString *deviceId = new QString(deviceSettngsJson["deviceId"].toString());
|
|
|
|
device->setDeviceId(deviceId);
|
|
|
|
devicelKeys.m_keys.append("deviceId");
|
|
|
|
|
|
|
|
if (deviceSettngsJson.contains("deviceSerial"))
|
|
|
|
{
|
|
|
|
device->setDeviceSerial(new QString(deviceSettngsJson["deviceSerial"].toString()));
|
|
|
|
devicelKeys.m_keys.append("deviceSerial");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceSettngsJson.contains("deviceSequence"))
|
|
|
|
{
|
|
|
|
device->setDeviceSequence(deviceSettngsJson["deviceSequence"].toInt());
|
|
|
|
devicelKeys.m_keys.append("deviceSequence");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceSettngsJson.contains("config") && m_deviceIdToSettingsKey.contains(*deviceId))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings *deviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-08-10 19:27:19 -04:00
|
|
|
device->setConfig(deviceSettings);
|
2019-08-06 18:27:34 -04:00
|
|
|
return getDevice(m_deviceIdToSettingsKey[*deviceId], deviceSettings, deviceSettngsJson["config"].toObject(), devicelKeys.m_deviceKeys);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAPIRequestMapper::getDevice(
|
|
|
|
const QString& deviceSettingsKey,
|
|
|
|
SWGSDRangel::SWGDeviceSettings *deviceSettings,
|
|
|
|
const QJsonObject& deviceSettingsJson,
|
|
|
|
QStringList& deviceSettingsKeys
|
|
|
|
)
|
|
|
|
{
|
|
|
|
QStringList deviceKeys = deviceSettingsJson.keys();
|
|
|
|
|
|
|
|
if (deviceKeys.contains(deviceSettingsKey) && deviceSettingsJson[deviceSettingsKey].isObject())
|
|
|
|
{
|
|
|
|
QJsonObject settingsJsonObject = deviceSettingsJson[deviceSettingsKey].toObject();
|
|
|
|
deviceSettingsKeys = settingsJsonObject.keys();
|
|
|
|
|
|
|
|
if (deviceSettingsKey == "airspySettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setAirspySettings(new SWGSDRangel::SWGAirspySettings());
|
|
|
|
deviceSettings->getAirspySettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "airspyHFSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setAirspyHfSettings(new SWGSDRangel::SWGAirspyHFSettings());
|
|
|
|
deviceSettings->getAirspyHfSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "bladeRF1InputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setBladeRf1InputSettings(new SWGSDRangel::SWGBladeRF1InputSettings());
|
|
|
|
deviceSettings->getBladeRf1InputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "bladeRF1OutputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setBladeRf1OutputSettings(new SWGSDRangel::SWGBladeRF1OutputSettings());
|
|
|
|
deviceSettings->getBladeRf1OutputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "bladeRF2InputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setBladeRf2InputSettings(new SWGSDRangel::SWGBladeRF2InputSettings());
|
|
|
|
deviceSettings->getBladeRf2InputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "bladeRF2InputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setBladeRf2OutputSettings(new SWGSDRangel::SWGBladeRF2OutputSettings());
|
|
|
|
deviceSettings->getBladeRf2OutputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "fcdProSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setFcdProSettings(new SWGSDRangel::SWGFCDProSettings());
|
|
|
|
deviceSettings->getFcdProSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "fcdProPlusSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setFcdProPlusSettings(new SWGSDRangel::SWGFCDProPlusSettings());
|
|
|
|
deviceSettings->getFcdProPlusSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "fileInputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setFileInputSettings(new SWGSDRangel::SWGFileInputSettings());
|
|
|
|
deviceSettings->getFileInputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "hackRFInputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setHackRfInputSettings(new SWGSDRangel::SWGHackRFInputSettings());
|
|
|
|
deviceSettings->getHackRfInputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "hackRFOutputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setHackRfOutputSettings(new SWGSDRangel::SWGHackRFOutputSettings());
|
|
|
|
deviceSettings->getHackRfOutputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "kiwiSDRSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setKiwiSdrSettings(new SWGSDRangel::SWGKiwiSDRSettings());
|
|
|
|
deviceSettings->getKiwiSdrSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "limeSdrInputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setLimeSdrInputSettings(new SWGSDRangel::SWGLimeSdrInputSettings());
|
|
|
|
deviceSettings->getLimeSdrInputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "limeSdrOutputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setLimeSdrOutputSettings(new SWGSDRangel::SWGLimeSdrOutputSettings());
|
|
|
|
deviceSettings->getLimeSdrOutputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "perseusSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setPerseusSettings(new SWGSDRangel::SWGPerseusSettings());
|
|
|
|
deviceSettings->getPerseusSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "plutoSdrInputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setPlutoSdrInputSettings(new SWGSDRangel::SWGPlutoSdrInputSettings());
|
|
|
|
deviceSettings->getPlutoSdrInputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "plutoSdrOutputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setPlutoSdrOutputSettings(new SWGSDRangel::SWGPlutoSdrOutputSettings());
|
|
|
|
deviceSettings->getPlutoSdrOutputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "rtlSdrSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setRtlSdrSettings(new SWGSDRangel::SWGRtlSdrSettings());
|
|
|
|
deviceSettings->getRtlSdrSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "sdrPlaySettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setSdrPlaySettings(new SWGSDRangel::SWGSDRPlaySettings());
|
|
|
|
deviceSettings->getSdrPlaySettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "soapySDRInputSettings")
|
|
|
|
{
|
2019-08-13 06:18:47 -04:00
|
|
|
processSoapySDRSettings(deviceSettings, settingsJsonObject, deviceSettingsKeys, true);
|
|
|
|
// deviceSettings->setSoapySdrInputSettings(new SWGSDRangel::SWGSoapySDRInputSettings());
|
|
|
|
// deviceSettings->getSoapySdrInputSettings()->init(); // contains complex objects
|
|
|
|
// deviceSettings->getSoapySdrInputSettings()->fromJsonObject(settingsJsonObject);
|
2019-08-06 18:27:34 -04:00
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "soapySDROutputSettings")
|
|
|
|
{
|
2019-08-13 06:18:47 -04:00
|
|
|
processSoapySDRSettings(deviceSettings, settingsJsonObject, deviceSettingsKeys, false);
|
|
|
|
// deviceSettings->setSoapySdrOutputSettings(new SWGSDRangel::SWGSoapySDROutputSettings());
|
|
|
|
// deviceSettings->getSoapySdrOutputSettings()->init(); // contains complex objects
|
|
|
|
// deviceSettings->getSoapySdrOutputSettings()->fromJsonObject(settingsJsonObject);
|
2019-08-06 18:27:34 -04:00
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "testSourceSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setTestSourceSettings(new SWGSDRangel::SWGTestSourceSettings());
|
|
|
|
deviceSettings->getTestSourceSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
2019-08-13 06:18:47 -04:00
|
|
|
else if (deviceSettingsKey == "XtrxInputSettings")
|
2019-08-06 18:27:34 -04:00
|
|
|
{
|
|
|
|
deviceSettings->setXtrxInputSettings(new SWGSDRangel::SWGXtrxInputSettings());
|
|
|
|
deviceSettings->getXtrxInputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
2019-08-13 06:18:47 -04:00
|
|
|
else if (deviceSettingsKey == "XtrxOutputSettings")
|
2019-08-06 18:27:34 -04:00
|
|
|
{
|
|
|
|
deviceSettings->setXtrxOutputSettings(new SWGSDRangel::SWGXtrxOutputSettings());
|
|
|
|
deviceSettings->getXtrxOutputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "remoteInputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setRemoteInputSettings(new SWGSDRangel::SWGRemoteInputSettings());
|
|
|
|
deviceSettings->getRemoteInputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "localInputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setLocalInputSettings(new SWGSDRangel::SWGLocalInputSettings());
|
|
|
|
deviceSettings->getLocalInputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "remoteOutputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setRemoteOutputSettings(new SWGSDRangel::SWGRemoteOutputSettings());
|
|
|
|
deviceSettings->getRemoteOutputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else if (deviceSettingsKey == "localOutputSettings")
|
|
|
|
{
|
|
|
|
deviceSettings->setLocalOutputSettings(new SWGSDRangel::SWGLocalOutputSettings());
|
|
|
|
deviceSettings->getLocalOutputSettings()->fromJsonObject(settingsJsonObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-06 13:06:49 -04:00
|
|
|
}
|
|
|
|
|
2017-12-23 22:19:44 -05:00
|
|
|
void WebAPIRequestMapper::appendSettingsSubKeys(
|
|
|
|
const QJsonObject& parentSettingsJsonObject,
|
|
|
|
QJsonObject& childSettingsJsonObject,
|
|
|
|
const QString& parentKey,
|
|
|
|
QStringList& keyList)
|
|
|
|
{
|
|
|
|
childSettingsJsonObject = parentSettingsJsonObject[parentKey].toObject();
|
|
|
|
QStringList childSettingsKeys = childSettingsJsonObject.keys();
|
|
|
|
|
|
|
|
for (int i = 0; i < childSettingsKeys.size(); i++) {
|
|
|
|
keyList.append(parentKey + QString(".") + childSettingsKeys.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 20:14:35 -04:00
|
|
|
void WebAPIRequestMapper::appendSettingsArrayKeys(
|
|
|
|
const QJsonObject& parentSettingsJsonObject,
|
|
|
|
const QString& parentKey,
|
|
|
|
QStringList& keyList)
|
|
|
|
{
|
2019-08-08 20:41:17 -04:00
|
|
|
QJsonArray arrayJson = parentSettingsJsonObject[parentKey].toArray();
|
2019-05-25 20:14:35 -04:00
|
|
|
|
2019-08-08 20:41:17 -04:00
|
|
|
for (int arrayIndex = 0; arrayIndex < arrayJson.count(); arrayIndex++)
|
2019-05-25 20:14:35 -04:00
|
|
|
{
|
2019-08-13 06:18:47 -04:00
|
|
|
QJsonValue v = arrayJson.at(arrayIndex);
|
2019-05-25 20:14:35 -04:00
|
|
|
|
|
|
|
if (v.isObject())
|
|
|
|
{
|
2019-08-08 20:41:17 -04:00
|
|
|
QJsonObject itemSettingsJsonObject = v.toObject();
|
|
|
|
QStringList itemSettingsKeys = itemSettingsJsonObject.keys();
|
|
|
|
keyList.append(tr("%1[%2]").arg(parentKey).arg(arrayIndex));
|
2019-05-25 20:14:35 -04:00
|
|
|
|
2019-08-08 20:41:17 -04:00
|
|
|
for (int i = 0; i < itemSettingsKeys.size(); i++) {
|
|
|
|
keyList.append(tr("%1[%2].%3").arg(parentKey).arg(arrayIndex).arg(itemSettingsKeys[i]));
|
2019-05-25 20:14:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 16:08:34 -05:00
|
|
|
void WebAPIRequestMapper::resetDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings)
|
|
|
|
{
|
|
|
|
deviceSettings.cleanup();
|
2019-08-06 02:48:14 -04:00
|
|
|
deviceSettings.setDeviceHwType(nullptr);
|
|
|
|
deviceSettings.setAirspySettings(nullptr);
|
|
|
|
deviceSettings.setAirspyHfSettings(nullptr);
|
|
|
|
deviceSettings.setBladeRf1InputSettings(nullptr);
|
|
|
|
deviceSettings.setBladeRf1OutputSettings(nullptr);
|
|
|
|
deviceSettings.setFcdProPlusSettings(nullptr);
|
|
|
|
deviceSettings.setFcdProSettings(nullptr);
|
|
|
|
deviceSettings.setFileInputSettings(nullptr);
|
|
|
|
deviceSettings.setHackRfInputSettings(nullptr);
|
|
|
|
deviceSettings.setHackRfOutputSettings(nullptr);
|
|
|
|
deviceSettings.setLimeSdrInputSettings(nullptr);
|
|
|
|
deviceSettings.setLimeSdrOutputSettings(nullptr);
|
|
|
|
deviceSettings.setPerseusSettings(nullptr);
|
|
|
|
deviceSettings.setPlutoSdrInputSettings(nullptr);
|
|
|
|
deviceSettings.setPlutoSdrOutputSettings(nullptr);
|
|
|
|
deviceSettings.setRtlSdrSettings(nullptr);
|
|
|
|
deviceSettings.setRemoteOutputSettings(nullptr);
|
|
|
|
deviceSettings.setRemoteInputSettings(nullptr);
|
|
|
|
deviceSettings.setSdrPlaySettings(nullptr);
|
|
|
|
deviceSettings.setTestSourceSettings(nullptr);
|
2018-05-28 05:44:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::resetDeviceReport(SWGSDRangel::SWGDeviceReport& deviceReport)
|
|
|
|
{
|
|
|
|
deviceReport.cleanup();
|
2019-08-06 02:48:14 -04:00
|
|
|
deviceReport.setDeviceHwType(nullptr);
|
|
|
|
deviceReport.setAirspyHfReport(nullptr);
|
|
|
|
deviceReport.setAirspyReport(nullptr);
|
|
|
|
deviceReport.setFileInputReport(nullptr);
|
|
|
|
deviceReport.setLimeSdrInputReport(nullptr);
|
|
|
|
deviceReport.setLimeSdrOutputReport(nullptr);
|
|
|
|
deviceReport.setPerseusReport(nullptr);
|
|
|
|
deviceReport.setPlutoSdrInputReport(nullptr);
|
|
|
|
deviceReport.setPlutoSdrOutputReport(nullptr);
|
|
|
|
deviceReport.setRtlSdrReport(nullptr);
|
|
|
|
deviceReport.setRemoteOutputReport(nullptr);
|
|
|
|
deviceReport.setRemoteInputReport(nullptr);
|
|
|
|
deviceReport.setSdrPlayReport(nullptr);
|
2017-12-06 16:08:34 -05:00
|
|
|
}
|
2017-11-25 13:42:56 -05:00
|
|
|
|
2017-12-10 14:27:08 -05:00
|
|
|
void WebAPIRequestMapper::resetChannelSettings(SWGSDRangel::SWGChannelSettings& channelSettings)
|
|
|
|
{
|
|
|
|
channelSettings.cleanup();
|
2019-08-06 02:48:14 -04:00
|
|
|
channelSettings.setChannelType(nullptr);
|
|
|
|
channelSettings.setAmDemodSettings(nullptr);
|
|
|
|
channelSettings.setAmModSettings(nullptr);
|
|
|
|
channelSettings.setAtvModSettings(nullptr);
|
|
|
|
channelSettings.setBfmDemodSettings(nullptr);
|
|
|
|
channelSettings.setDsdDemodSettings(nullptr);
|
|
|
|
channelSettings.setNfmDemodSettings(nullptr);
|
|
|
|
channelSettings.setNfmModSettings(nullptr);
|
|
|
|
channelSettings.setRemoteSinkSettings(nullptr);
|
|
|
|
channelSettings.setRemoteSourceSettings(nullptr);
|
|
|
|
channelSettings.setSsbDemodSettings(nullptr);
|
|
|
|
channelSettings.setSsbModSettings(nullptr);
|
|
|
|
channelSettings.setUdpSourceSettings(nullptr);
|
|
|
|
channelSettings.setUdpSinkSettings(nullptr);
|
|
|
|
channelSettings.setWfmDemodSettings(nullptr);
|
|
|
|
channelSettings.setWfmModSettings(nullptr);
|
2017-12-10 14:27:08 -05:00
|
|
|
}
|
|
|
|
|
2018-03-18 15:17:11 -04:00
|
|
|
void WebAPIRequestMapper::resetChannelReport(SWGSDRangel::SWGChannelReport& channelReport)
|
|
|
|
{
|
|
|
|
channelReport.cleanup();
|
2019-08-06 02:48:14 -04:00
|
|
|
channelReport.setChannelType(nullptr);
|
|
|
|
channelReport.setAmDemodReport(nullptr);
|
|
|
|
channelReport.setAmModReport(nullptr);
|
|
|
|
channelReport.setAtvModReport(nullptr);
|
|
|
|
channelReport.setBfmDemodReport(nullptr);
|
|
|
|
channelReport.setDsdDemodReport(nullptr);
|
|
|
|
channelReport.setNfmDemodReport(nullptr);
|
|
|
|
channelReport.setNfmModReport(nullptr);
|
|
|
|
channelReport.setRemoteSourceReport(nullptr);
|
|
|
|
channelReport.setSsbDemodReport(nullptr);
|
|
|
|
channelReport.setSsbModReport(nullptr);
|
|
|
|
channelReport.setUdpSourceReport(nullptr);
|
|
|
|
channelReport.setUdpSinkReport(nullptr);
|
|
|
|
channelReport.setWfmDemodReport(nullptr);
|
|
|
|
channelReport.setWfmModReport(nullptr);
|
2018-03-18 15:17:11 -04:00
|
|
|
}
|
2018-03-28 18:38:01 -04:00
|
|
|
|
|
|
|
void WebAPIRequestMapper::resetAudioInputDevice(SWGSDRangel::SWGAudioInputDevice& audioInputDevice)
|
|
|
|
{
|
|
|
|
audioInputDevice.cleanup();
|
2019-08-06 02:48:14 -04:00
|
|
|
audioInputDevice.setName(nullptr);
|
2018-03-28 18:38:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::resetAudioOutputDevice(SWGSDRangel::SWGAudioOutputDevice& audioOutputDevice)
|
|
|
|
{
|
|
|
|
audioOutputDevice.cleanup();
|
2019-08-06 02:48:14 -04:00
|
|
|
audioOutputDevice.setName(nullptr);
|
|
|
|
audioOutputDevice.setUdpAddress(nullptr);
|
2018-03-28 18:38:01 -04:00
|
|
|
}
|
2019-08-08 20:41:17 -04:00
|
|
|
|
|
|
|
void WebAPIRequestMapper::processChannelAnalyzerSettings(
|
|
|
|
SWGSDRangel::SWGChannelSettings *channelSettings,
|
|
|
|
const QJsonObject& channelSettingsJson,
|
|
|
|
QStringList& channelSettingsKeys
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelAnalyzerSettings *channelAnalyzerSettings = new SWGSDRangel::SWGChannelAnalyzerSettings();
|
|
|
|
channelSettings->setChannelAnalyzerSettings(channelAnalyzerSettings);
|
|
|
|
channelAnalyzerSettings->init();
|
|
|
|
|
|
|
|
if (channelSettingsJson.contains("bandwidth")) {
|
|
|
|
channelAnalyzerSettings->setBandwidth(channelSettingsJson["bandwidth"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("downSample")) {
|
|
|
|
channelAnalyzerSettings->setDownSample(channelSettingsJson["downSample"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("downSampleRate")) {
|
|
|
|
channelAnalyzerSettings->setDownSampleRate(channelSettingsJson["downSampleRate"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("fll")) {
|
|
|
|
channelAnalyzerSettings->setFll(channelSettingsJson["fll"].toInt());
|
|
|
|
}
|
2019-08-13 06:18:47 -04:00
|
|
|
if (channelSettingsJson.contains("frequency")) {
|
|
|
|
channelAnalyzerSettings->setFrequency(channelSettingsJson["frequency"].toInt());
|
|
|
|
}
|
2019-08-08 20:41:17 -04:00
|
|
|
if (channelSettingsJson.contains("inputType")) {
|
|
|
|
channelAnalyzerSettings->setInputType(channelSettingsJson["inputType"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("lowCutoff")) {
|
|
|
|
channelAnalyzerSettings->setLowCutoff(channelSettingsJson["lowCutoff"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("pll")) {
|
|
|
|
channelAnalyzerSettings->setPll(channelSettingsJson["pll"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("pllPskOrder")) {
|
|
|
|
channelAnalyzerSettings->setPllPskOrder(channelSettingsJson["pllPskOrder"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("rgbColor")) {
|
|
|
|
channelAnalyzerSettings->setRgbColor(channelSettingsJson["rgbColor"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("rrc")) {
|
|
|
|
channelAnalyzerSettings->setRrc(channelSettingsJson["rrc"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("rrcRolloff")) {
|
|
|
|
channelAnalyzerSettings->setRrcRolloff(channelSettingsJson["rrcRolloff"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("spanLog2")) {
|
|
|
|
channelAnalyzerSettings->setSpanLog2(channelSettingsJson["spanLog2"].toInt());
|
|
|
|
}
|
2019-08-13 06:18:47 -04:00
|
|
|
if (channelSettingsJson.contains("ssb")) {
|
|
|
|
channelAnalyzerSettings->setSsb(channelSettingsJson["ssb"].toInt());
|
|
|
|
}
|
|
|
|
if (channelSettingsJson.contains("title")) {
|
|
|
|
channelAnalyzerSettings->setTitle(new QString(channelSettingsJson["title"].toString()));
|
|
|
|
}
|
2019-08-08 20:41:17 -04:00
|
|
|
|
|
|
|
if (channelSettingsJson.contains("spectrumConfig"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGGLSpectrum *spectrum = new SWGSDRangel::SWGGLSpectrum();
|
|
|
|
spectrum->init();
|
|
|
|
channelAnalyzerSettings->setSpectrumConfig(spectrum);
|
|
|
|
QJsonObject spectrumJson;
|
|
|
|
appendSettingsSubKeys(channelSettingsJson, spectrumJson, "spectrumConfig", channelSettingsKeys);
|
|
|
|
spectrum->fromJsonObject(spectrumJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channelSettingsJson.contains("scopeConfig") && channelSettingsJson["scopeConfig"].isObject())
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGGLScope *scopeConfig = new SWGSDRangel::SWGGLScope();
|
|
|
|
scopeConfig->init();
|
|
|
|
channelAnalyzerSettings->setScopeConfig(scopeConfig);
|
|
|
|
QJsonObject scopeConfigJson;
|
|
|
|
appendSettingsSubKeys(channelSettingsJson, scopeConfigJson, "scopeConfig", channelSettingsKeys);
|
|
|
|
scopeConfig->fromJsonObject(scopeConfigJson);
|
|
|
|
|
|
|
|
if (scopeConfigJson.contains("tracesData") && scopeConfigJson["tracesData"].isArray())
|
|
|
|
{
|
|
|
|
QList<SWGSDRangel::SWGTraceData *> *tracesData = new QList<SWGSDRangel::SWGTraceData *>();
|
|
|
|
scopeConfig->setTracesData(tracesData);
|
|
|
|
QJsonArray tracesJson = scopeConfigJson["tracesData"].toArray();
|
|
|
|
|
|
|
|
for (int i = 0; i < tracesJson.size(); i++)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGTraceData *traceData = new SWGSDRangel::SWGTraceData();
|
|
|
|
tracesData->append(traceData);
|
|
|
|
QJsonObject traceJson = tracesJson.at(i).toObject();
|
|
|
|
traceData->fromJsonObject(traceJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList tracesDataKeys;
|
|
|
|
appendSettingsArrayKeys(scopeConfigJson, "tracesData", tracesDataKeys);
|
|
|
|
|
|
|
|
for (int i = 0; i < tracesDataKeys.size(); i++) {
|
|
|
|
channelSettingsKeys.append(QString("scopeConfig.") + tracesDataKeys.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scopeConfigJson.contains("triggersData") && scopeConfigJson["triggersData"].isArray())
|
|
|
|
{
|
|
|
|
QList<SWGSDRangel::SWGTriggerData *> *triggersData = new QList<SWGSDRangel::SWGTriggerData *>();
|
|
|
|
scopeConfig->setTriggersData(triggersData);
|
|
|
|
QJsonArray triggersJson = scopeConfigJson["triggersData"].toArray();
|
|
|
|
|
|
|
|
for (int i = 0; i < triggersJson.size(); i++)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGTriggerData *triggerData = new SWGSDRangel::SWGTriggerData();
|
|
|
|
triggersData->append(triggerData);
|
|
|
|
QJsonObject triggerJson = triggersJson.at(i).toObject();
|
|
|
|
triggerData->fromJsonObject(triggerJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList triggersDataKeys;
|
|
|
|
appendSettingsArrayKeys(scopeConfigJson, "triggersData", triggersDataKeys);
|
|
|
|
|
|
|
|
for (int i = 0; i < triggersDataKeys.size(); i++) {
|
|
|
|
channelSettingsKeys.append(QString("scopeConfig.") + triggersDataKeys.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-13 06:18:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIRequestMapper::processSoapySDRSettings(
|
|
|
|
SWGSDRangel::SWGDeviceSettings *deviceSettings,
|
|
|
|
QJsonObject& deviceSettingsJson,
|
|
|
|
QStringList& deviceSettingsKeys,
|
|
|
|
bool inputElseOutput
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (inputElseOutput)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGSoapySDRInputSettings *swgSoapySDRInputSettings = new SWGSDRangel::SWGSoapySDRInputSettings();
|
|
|
|
deviceSettings->setSoapySdrInputSettings(swgSoapySDRInputSettings);
|
|
|
|
swgSoapySDRInputSettings->init();
|
|
|
|
|
|
|
|
if (deviceSettingsJson.contains("centerFrequency")) {
|
|
|
|
swgSoapySDRInputSettings->setCenterFrequency(deviceSettingsJson["centerFrequency"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("LOppmTenths")) {
|
|
|
|
swgSoapySDRInputSettings->setLOppmTenths(deviceSettingsJson["LOppmTenths"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("devSampleRate")) {
|
|
|
|
swgSoapySDRInputSettings->setDevSampleRate(deviceSettingsJson["devSampleRate"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("log2Decim")) {
|
|
|
|
swgSoapySDRInputSettings->setLog2Decim(deviceSettingsJson["log2Decim"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("fcPos")) {
|
|
|
|
swgSoapySDRInputSettings->setFcPos(deviceSettingsJson["fcPos"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("softDCCorrection")) {
|
|
|
|
swgSoapySDRInputSettings->setSoftDcCorrection(deviceSettingsJson["softDCCorrection"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("softIQCorrection")) {
|
|
|
|
swgSoapySDRInputSettings->setSoftIqCorrection(deviceSettingsJson["softIQCorrection"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("transverterMode")) {
|
|
|
|
swgSoapySDRInputSettings->setTransverterMode(deviceSettingsJson["transverterMode"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("transverterDeltaFrequency")) {
|
|
|
|
swgSoapySDRInputSettings->setTransverterDeltaFrequency(deviceSettingsJson["transverterDeltaFrequency"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("fileRecordName")) {
|
|
|
|
swgSoapySDRInputSettings->setFileRecordName(new QString(deviceSettingsJson["fileRecordName"].toString()));
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("antenna")) {
|
|
|
|
swgSoapySDRInputSettings->setAntenna(new QString(deviceSettingsJson["antenna"].toString()));
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("bandwidth")) {
|
|
|
|
swgSoapySDRInputSettings->setBandwidth(deviceSettingsJson["bandwidth"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("globalGain")) {
|
|
|
|
swgSoapySDRInputSettings->setGlobalGain(deviceSettingsJson["globalGain"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("autoGain")) {
|
|
|
|
swgSoapySDRInputSettings->setAutoGain(deviceSettingsJson["autoGain"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("autoDCCorrection")) {
|
|
|
|
swgSoapySDRInputSettings->setAutoDcCorrection(deviceSettingsJson["autoDCCorrection"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("autoIQCorrection")) {
|
|
|
|
swgSoapySDRInputSettings->setAutoIqCorrection(deviceSettingsJson["autoIQCorrection"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("dcCorrection"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGComplex *swgComplex = new SWGSDRangel::SWGComplex;
|
|
|
|
swgSoapySDRInputSettings->setDcCorrection(swgComplex);
|
|
|
|
QJsonObject complexJson = deviceSettingsJson["dcCorrection"].toObject();
|
|
|
|
|
|
|
|
if (complexJson.contains("real")) {
|
|
|
|
swgComplex->setReal(complexJson["real"].toDouble());
|
|
|
|
}
|
|
|
|
if (complexJson.contains("imag")) {
|
|
|
|
swgComplex->setImag(complexJson["imag"].toDouble());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("iqCorrection"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGComplex *swgComplex = new SWGSDRangel::SWGComplex;
|
|
|
|
swgSoapySDRInputSettings->setIqCorrection(swgComplex);
|
|
|
|
QJsonObject complexJson = deviceSettingsJson["iqCorrection"].toObject();
|
|
|
|
|
|
|
|
if (complexJson.contains("real")) {
|
|
|
|
swgComplex->setReal(complexJson["real"].toDouble());
|
|
|
|
}
|
|
|
|
if (complexJson.contains("imag")) {
|
|
|
|
swgComplex->setImag(complexJson["imag"].toDouble());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("useReverseAPI")) {
|
|
|
|
swgSoapySDRInputSettings->setUseReverseApi(deviceSettingsJson["useReverseAPI"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("reverseAPIAddress")) {
|
|
|
|
swgSoapySDRInputSettings->setReverseApiAddress(new QString(deviceSettingsJson["reverseAPIAddress"].toString()));
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("reverseAPIPort")) {
|
|
|
|
swgSoapySDRInputSettings->setReverseApiPort(deviceSettingsJson["reverseAPIPort"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("reverseAPIDeviceIndex")) {
|
|
|
|
swgSoapySDRInputSettings->setReverseApiDeviceIndex(deviceSettingsJson["reverseAPIDeviceIndex"].toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGSoapySDROutputSettings *swgSoapySDROutputSettings = new SWGSDRangel::SWGSoapySDROutputSettings();
|
|
|
|
deviceSettings->setSoapySdrOutputSettings(swgSoapySDROutputSettings);
|
|
|
|
swgSoapySDROutputSettings->init();
|
|
|
|
|
|
|
|
if (deviceSettingsJson.contains("centerFrequency")) {
|
|
|
|
swgSoapySDROutputSettings->setCenterFrequency(deviceSettingsJson["centerFrequency"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("LOppmTenths")) {
|
|
|
|
swgSoapySDROutputSettings->setLOppmTenths(deviceSettingsJson["LOppmTenths"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("devSampleRate")) {
|
|
|
|
swgSoapySDROutputSettings->setDevSampleRate(deviceSettingsJson["devSampleRate"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("log2Interp")) {
|
|
|
|
swgSoapySDROutputSettings->setLog2Interp(deviceSettingsJson["log2Interp"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("transverterMode")) {
|
|
|
|
swgSoapySDROutputSettings->setTransverterMode(deviceSettingsJson["transverterMode"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("transverterDeltaFrequency")) {
|
|
|
|
swgSoapySDROutputSettings->setTransverterDeltaFrequency(deviceSettingsJson["transverterDeltaFrequency"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("antenna")) {
|
|
|
|
swgSoapySDROutputSettings->setAntenna(new QString(deviceSettingsJson["antenna"].toString()));
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("bandwidth")) {
|
|
|
|
swgSoapySDROutputSettings->setBandwidth(deviceSettingsJson["bandwidth"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("globalGain")) {
|
|
|
|
swgSoapySDROutputSettings->setGlobalGain(deviceSettingsJson["globalGain"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("autoGain")) {
|
|
|
|
swgSoapySDROutputSettings->setAutoGain(deviceSettingsJson["autoGain"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("autoDCCorrection")) {
|
|
|
|
swgSoapySDROutputSettings->setAutoDcCorrection(deviceSettingsJson["autoDCCorrection"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("autoIQCorrection")) {
|
|
|
|
swgSoapySDROutputSettings->setAutoIqCorrection(deviceSettingsJson["autoIQCorrection"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("dcCorrection"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGComplex *swgComplex = new SWGSDRangel::SWGComplex;
|
|
|
|
swgSoapySDROutputSettings->setDcCorrection(swgComplex);
|
|
|
|
QJsonObject complexJson = deviceSettingsJson["dcCorrection"].toObject();
|
|
|
|
|
|
|
|
if (complexJson.contains("real")) {
|
|
|
|
swgComplex->setReal(complexJson["real"].toDouble());
|
|
|
|
}
|
|
|
|
if (complexJson.contains("imag")) {
|
|
|
|
swgComplex->setImag(complexJson["imag"].toDouble());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("iqCorrection"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGComplex *swgComplex = new SWGSDRangel::SWGComplex;
|
|
|
|
swgSoapySDROutputSettings->setIqCorrection(swgComplex);
|
|
|
|
QJsonObject complexJson = deviceSettingsJson["iqCorrection"].toObject();
|
|
|
|
|
|
|
|
if (complexJson.contains("real")) {
|
|
|
|
swgComplex->setReal(complexJson["real"].toDouble());
|
|
|
|
}
|
|
|
|
if (complexJson.contains("imag")) {
|
|
|
|
swgComplex->setImag(complexJson["imag"].toDouble());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("useReverseAPI")) {
|
|
|
|
swgSoapySDROutputSettings->setUseReverseApi(deviceSettingsJson["useReverseAPI"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("reverseAPIAddress")) {
|
|
|
|
swgSoapySDROutputSettings->setReverseApiAddress(new QString(deviceSettingsJson["reverseAPIAddress"].toString()));
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("reverseAPIPort")) {
|
|
|
|
swgSoapySDROutputSettings->setReverseApiPort(deviceSettingsJson["reverseAPIPort"].toInt());
|
|
|
|
}
|
|
|
|
if (deviceSettingsJson.contains("reverseAPIDeviceIndex")) {
|
|
|
|
swgSoapySDROutputSettings->setReverseApiDeviceIndex(deviceSettingsJson["reverseAPIDeviceIndex"].toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("deviceArgSettings"))
|
|
|
|
{
|
|
|
|
QList<SWGSDRangel::SWGArgValue *> *swgArgSettings = new QList<SWGSDRangel::SWGArgValue *>;
|
|
|
|
QJsonArray argsJson = deviceSettingsJson["deviceArgSettings"].toArray();
|
|
|
|
|
|
|
|
if (inputElseOutput) {
|
|
|
|
deviceSettings->getSoapySdrInputSettings()->setDeviceArgSettings(swgArgSettings);
|
|
|
|
} else {
|
|
|
|
deviceSettings->getSoapySdrOutputSettings()->setDeviceArgSettings(swgArgSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < argsJson.count(); i++)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGArgValue *argValue = new SWGSDRangel::SWGArgValue();
|
|
|
|
swgArgSettings->append(argValue);
|
|
|
|
QJsonObject argValueJson = argsJson.at(i).toObject();
|
|
|
|
argValue->fromJsonObject(argValueJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
appendSettingsArrayKeys(deviceSettingsJson, "deviceArgSettings", deviceSettingsKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("individualGains"))
|
|
|
|
{
|
|
|
|
QList<SWGSDRangel::SWGArgValue *> *swgIndividualGains = new QList<SWGSDRangel::SWGArgValue *>;
|
|
|
|
QJsonArray argsJson = deviceSettingsJson["individualGains"].toArray();
|
|
|
|
|
|
|
|
if (inputElseOutput) {
|
|
|
|
deviceSettings->getSoapySdrInputSettings()->setIndividualGains(swgIndividualGains);
|
|
|
|
} else {
|
|
|
|
deviceSettings->getSoapySdrOutputSettings()->setIndividualGains(swgIndividualGains);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < argsJson.count(); i++)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGArgValue *argValue = new SWGSDRangel::SWGArgValue();
|
|
|
|
swgIndividualGains->append(argValue);
|
|
|
|
QJsonObject argValueJson = argsJson.at(i).toObject();
|
|
|
|
argValue->fromJsonObject(argValueJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
appendSettingsArrayKeys(deviceSettingsJson, "individualGains", deviceSettingsKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("streamArgSettings"))
|
|
|
|
{
|
|
|
|
QList<SWGSDRangel::SWGArgValue *> *swgStreamArgSettings = new QList<SWGSDRangel::SWGArgValue *>;
|
|
|
|
QJsonArray argsJson = deviceSettingsJson["streamArgSettings"].toArray();
|
|
|
|
|
|
|
|
if (inputElseOutput) {
|
|
|
|
deviceSettings->getSoapySdrInputSettings()->setStreamArgSettings(swgStreamArgSettings);
|
|
|
|
} else {
|
|
|
|
deviceSettings->getSoapySdrOutputSettings()->setStreamArgSettings(swgStreamArgSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < argsJson.count(); i++)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGArgValue *argValue = new SWGSDRangel::SWGArgValue();
|
|
|
|
swgStreamArgSettings->append(argValue);
|
|
|
|
QJsonObject argValueJson = argsJson.at(i).toObject();
|
|
|
|
argValue->fromJsonObject(argValueJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
appendSettingsArrayKeys(deviceSettingsJson, "streamArgSettings", deviceSettingsKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("tunableElements"))
|
|
|
|
{
|
|
|
|
QList<SWGSDRangel::SWGArgValue *> *swgTunableElements = new QList<SWGSDRangel::SWGArgValue *>;
|
|
|
|
QJsonArray argsJson = deviceSettingsJson["tunableElements"].toArray();
|
|
|
|
|
|
|
|
if (inputElseOutput) {
|
|
|
|
deviceSettings->getSoapySdrInputSettings()->setTunableElements(swgTunableElements);
|
|
|
|
} else {
|
|
|
|
deviceSettings->getSoapySdrOutputSettings()->setTunableElements(swgTunableElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < argsJson.count(); i++)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGArgValue *argValue = new SWGSDRangel::SWGArgValue();
|
|
|
|
swgTunableElements->append(argValue);
|
|
|
|
QJsonObject argValueJson = argsJson.at(i).toObject();
|
|
|
|
argValue->fromJsonObject(argValueJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
appendSettingsArrayKeys(deviceSettingsJson, "tunableElements", deviceSettingsKeys);
|
|
|
|
}
|
2019-08-08 20:41:17 -04:00
|
|
|
}
|