| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:04:34 +02:00
										 |  |  | // Copyright (C) 2017-2020 Edouard Griffiths, F4EXB.                             //
 | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 14:43:33 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01: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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | #include <QCoreApplication>
 | 
					
						
							| 
									
										
										
										
											2017-11-22 18:57:35 +01:00
										 |  |  | #include <QList>
 | 
					
						
							| 
									
										
										
										
											2018-01-07 01:33:57 +01:00
										 |  |  | #include <QSysInfo>
 | 
					
						
							| 
									
										
										
										
											2022-05-09 21:43:30 +02:00
										 |  |  | #include <QTextStream>
 | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  | #include "maincore.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-19 01:05:16 +01:00
										 |  |  | #include "loggerwithfile.h"
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #include "audio/audiodeviceinfo.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | #include "device/deviceapi.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  | #include "device/deviceset.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-22 18:57:35 +01:00
										 |  |  | #include "device/deviceenumerator.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  | #include "feature/featureset.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | #include "feature/feature.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-19 01:05:16 +01:00
										 |  |  | #include "dsp/devicesamplesource.h"
 | 
					
						
							|  |  |  | #include "dsp/devicesamplesink.h"
 | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  | #include "dsp/devicesamplemimo.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | #include "dsp/dspdevicesourceengine.h"
 | 
					
						
							|  |  |  | #include "dsp/dspdevicesinkengine.h"
 | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  | #include "dsp/dspdevicemimoengine.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  | #include "dsp/dspengine.h"
 | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  | #include "dsp/spectrumvis.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  | #include "plugin/pluginapi.h"
 | 
					
						
							|  |  |  | #include "plugin/pluginmanager.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  | #include "channel/channelapi.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  | #include "webapi/webapiadapterbase.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-13 01:57:39 +01:00
										 |  |  | #include "util/serialutil.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-19 01:05:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | #include "SWGInstanceSummaryResponse.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  | #include "SWGInstanceConfigResponse.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-22 18:57:35 +01:00
										 |  |  | #include "SWGInstanceDevicesResponse.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  | #include "SWGInstanceChannelsResponse.h"
 | 
					
						
							| 
									
										
										
										
											2021-08-29 00:48:35 +02:00
										 |  |  | #include "SWGInstanceFeaturesResponse.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-22 18:57:35 +01:00
										 |  |  | #include "SWGDeviceListItem.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-24 08:46:12 +01:00
										 |  |  | #include "SWGAudioDevices.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-25 04:02:11 +01:00
										 |  |  | #include "SWGLocationInformation.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-25 11:14:52 +01:00
										 |  |  | #include "SWGPresets.h"
 | 
					
						
							|  |  |  | #include "SWGPresetGroup.h"
 | 
					
						
							|  |  |  | #include "SWGPresetItem.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  | #include "SWGPresetTransfer.h"
 | 
					
						
							|  |  |  | #include "SWGPresetIdentifier.h"
 | 
					
						
							| 
									
										
										
										
											2022-05-08 19:33:10 +02:00
										 |  |  | #include "SWGPresetExport.h"
 | 
					
						
							|  |  |  | #include "SWGConfigurations.h"
 | 
					
						
							|  |  |  | #include "SWGConfigurationIdentifier.h"
 | 
					
						
							|  |  |  | #include "SWGConfigurationImportExport.h"
 | 
					
						
							|  |  |  | #include "SWGBase64Blob.h"
 | 
					
						
							|  |  |  | #include "SWGFilePath.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-04 23:07:30 +01:00
										 |  |  | #include "SWGDeviceSettings.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  | #include "SWGDeviceState.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  | #include "SWGDeviceReport.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | #include "SWGDeviceActions.h"
 | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  | #include "SWGWorkspaceInfo.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  | #include "SWGChannelsDetail.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  | #include "SWGChannelSettings.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  | #include "SWGChannelReport.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | #include "SWGChannelActions.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  | #include "SWGSuccessResponse.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | #include "SWGErrorResponse.h"
 | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  | #include "SWGDeviceState.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-13 01:57:39 +01:00
										 |  |  | #include "SWGLimeRFEDevices.h"
 | 
					
						
							|  |  |  | #include "SWGLimeRFESettings.h"
 | 
					
						
							| 
									
										
										
										
											2021-09-04 05:58:06 +02:00
										 |  |  | #include "SWGFeaturePresets.h"
 | 
					
						
							|  |  |  | #include "SWGFeaturePresetGroup.h"
 | 
					
						
							|  |  |  | #include "SWGFeaturePresetItem.h"
 | 
					
						
							|  |  |  | #include "SWGFeaturePresetIdentifier.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | #include "SWGFeatureSettings.h"
 | 
					
						
							|  |  |  | #include "SWGFeatureReport.h"
 | 
					
						
							|  |  |  | #include "SWGFeatureActions.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-13 01:57:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | #include "webapiadapter.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-19 01:05:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | WebAPIAdapter::WebAPIAdapter() | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     m_mainCore = MainCore::instance(); | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | WebAPIAdapter::~WebAPIAdapter() | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceSummary( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGInstanceSummaryResponse& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2018-01-07 01:33:57 +01:00
										 |  |  |     *response.getAppname() = qApp->applicationName(); | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  |     *response.getVersion() = qApp->applicationVersion(); | 
					
						
							| 
									
										
										
										
											2017-12-18 13:19:20 +01:00
										 |  |  |     *response.getQtVersion() = QString(QT_VERSION_STR); | 
					
						
							| 
									
										
										
										
											2018-01-22 23:29:09 +01:00
										 |  |  |     response.setDspRxBits(SDR_RX_SAMP_SZ); | 
					
						
							|  |  |  |     response.setDspTxBits(SDR_TX_SAMP_SZ); | 
					
						
							|  |  |  |     response.setPid(qApp->applicationPid()); | 
					
						
							| 
									
										
										
										
											2020-11-04 22:52:15 +01:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
 | 
					
						
							| 
									
										
										
										
											2018-01-07 01:33:57 +01:00
										 |  |  |     *response.getArchitecture() = QString(QSysInfo::currentCpuArchitecture()); | 
					
						
							|  |  |  |     *response.getOs() = QString(QSysInfo::prettyProductName()); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-11-19 01:05:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |     SWGSDRangel::SWGLoggingInfo *logging = response.getLogging(); | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     logging->init(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     logging->setDumpToFile(m_mainCore->m_logger->getUseFileLogger() ? 1 : 0); | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 01:05:16 +01:00
										 |  |  |     if (logging->getDumpToFile()) { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         m_mainCore->m_logger->getLogFileName(*logging->getFileName()); | 
					
						
							|  |  |  |         m_mainCore->m_logger->getFileMinMessageLevelStr(*logging->getFileLevel()); | 
					
						
							| 
									
										
										
										
											2017-11-19 01:05:16 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     m_mainCore->m_logger->getConsoleMinMessageLevelStr(*logging->getConsoleLevel()); | 
					
						
							| 
									
										
										
										
											2017-11-19 01:05:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |     SWGSDRangel::SWGDeviceSetList *deviceSetList = response.getDevicesetlist(); | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  |     getDeviceSetList(deviceSetList); | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-03 04:55:35 +02:00
										 |  |  |     SWGSDRangel::SWGFeatureSet *featureSet = response.getFeatureset(); | 
					
						
							| 
									
										
										
										
											2022-05-04 13:27:13 +02:00
										 |  |  |     getFeatureSet(featureSet, m_mainCore->m_featureSets.back()); | 
					
						
							| 
									
										
										
										
											2021-08-31 23:53:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceDelete( | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							| 
									
										
										
										
											2018-01-06 03:46:53 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) response; | 
					
						
							| 
									
										
										
										
											2018-01-06 03:46:53 +01:00
										 |  |  |     *error.getMessage() = QString("Not supported in GUI instance"); | 
					
						
							|  |  |  |     return 400; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceConfigGet( | 
					
						
							| 
									
										
										
										
											2019-08-06 19:06:49 +02:00
										 |  |  |         SWGSDRangel::SWGInstanceConfigResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2019-08-01 18:50:21 +02:00
										 |  |  |     WebAPIAdapterBase webAPIAdapterBase; | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     webAPIAdapterBase.setPluginManager(m_mainCore->getPluginManager()); | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  |     SWGSDRangel::SWGPreferences *preferences = response.getPreferences(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     WebAPIAdapterBase::webapiFormatPreferences(preferences, m_mainCore->m_settings.getPreferences()); | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  |     SWGSDRangel::SWGPreset *workingPreset = response.getWorkingPreset(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     webAPIAdapterBase.webapiFormatPreset(workingPreset, m_mainCore->m_settings.getWorkingPresetConst()); | 
					
						
							| 
									
										
										
										
											2020-09-24 05:38:05 +02:00
										 |  |  |     SWGSDRangel::SWGFeatureSetPreset *workingFeatureSetPreset = response.getWorkingFeatureSetPreset(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     webAPIAdapterBase.webapiFormatFeatureSetPreset(workingFeatureSetPreset, m_mainCore->m_settings.getWorkingFeatureSetPresetConst()); | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     int nbPresets = m_mainCore->m_settings.getPresetCount(); | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  |     QList<SWGSDRangel::SWGPreset*> *swgPresets = response.getPresets(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < nbPresets; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         const Preset *preset = m_mainCore->m_settings.getPreset(i); | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  |         swgPresets->append(new SWGSDRangel::SWGPreset); | 
					
						
							| 
									
										
										
										
											2019-08-01 18:50:21 +02:00
										 |  |  |         webAPIAdapterBase.webapiFormatPreset(swgPresets->back(), *preset); | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     int nbCommands = m_mainCore->m_settings.getCommandCount(); | 
					
						
							| 
									
										
										
										
											2019-08-01 10:54:45 +02:00
										 |  |  |     QList<SWGSDRangel::SWGCommand*> *swgCommands = response.getCommands(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < nbCommands; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         const Command *command = m_mainCore->m_settings.getCommand(i); | 
					
						
							| 
									
										
										
										
											2019-08-01 10:54:45 +02:00
										 |  |  |         swgCommands->append(new SWGSDRangel::SWGCommand); | 
					
						
							|  |  |  |         WebAPIAdapterBase::webapiFormatCommand(swgCommands->back(), *command); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     int nbFeatureSetPresets = m_mainCore->m_settings.getFeatureSetPresetCount(); | 
					
						
							| 
									
										
										
										
											2020-09-24 05:38:05 +02:00
										 |  |  |     QList<SWGSDRangel::SWGFeatureSetPreset*> *swgFeatureSetPresets = response.getFeaturesetpresets(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < nbFeatureSetPresets; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         const FeatureSetPreset *preset = m_mainCore->m_settings.getFeatureSetPreset(i); | 
					
						
							| 
									
										
										
										
											2020-09-24 05:38:05 +02:00
										 |  |  |         swgFeatureSetPresets->append(new SWGSDRangel::SWGFeatureSetPreset); | 
					
						
							|  |  |  |         webAPIAdapterBase.webapiFormatFeatureSetPreset(swgFeatureSetPresets->back(), *preset); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceConfigPutPatch( | 
					
						
							| 
									
										
										
										
											2019-08-06 19:06:49 +02:00
										 |  |  |         bool force, // PUT else PATCH
 | 
					
						
							|  |  |  |         SWGSDRangel::SWGInstanceConfigResponse& query, | 
					
						
							|  |  |  |         const ConfigKeys& configKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2019-08-06 08:48:14 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |     (void) response; | 
					
						
							|  |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2019-08-06 08:48:14 +02:00
										 |  |  |     WebAPIAdapterBase webAPIAdapterBase; | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     webAPIAdapterBase.setPluginManager(m_mainCore->getPluginManager()); | 
					
						
							| 
									
										
										
										
											2019-08-06 19:06:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (force) { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         webAPIAdapterBase.webapiInitConfig(m_mainCore->m_settings); | 
					
						
							| 
									
										
										
										
											2019-08-06 19:06:49 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-07 00:27:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     Preferences newPreferences = m_mainCore->m_settings.getPreferences(); | 
					
						
							| 
									
										
										
										
											2019-08-09 18:45:10 +02:00
										 |  |  |     webAPIAdapterBase.webapiUpdatePreferences(query.getPreferences(), configKeys.m_preferencesKeys, newPreferences); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     m_mainCore->m_settings.setPreferences(newPreferences); | 
					
						
							| 
									
										
										
										
											2019-08-09 18:45:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     Preset *workingPreset = m_mainCore->m_settings.getWorkingPreset(); | 
					
						
							| 
									
										
										
										
											2019-08-11 01:27:19 +02:00
										 |  |  |     webAPIAdapterBase.webapiUpdatePreset(force, query.getWorkingPreset(), configKeys.m_workingPresetKeys, workingPreset); | 
					
						
							| 
									
										
										
										
											2019-08-09 18:45:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     FeatureSetPreset *workingFeatureSetPreset = m_mainCore->m_settings.getWorkingFeatureSetPreset(); | 
					
						
							| 
									
										
										
										
											2020-09-24 05:38:05 +02:00
										 |  |  |     webAPIAdapterBase.webapiUpdateFeatureSetPreset(force, query.getWorkingFeatureSetPreset(), configKeys.m_workingFeatureSetPresetKeys, workingFeatureSetPreset); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 18:45:10 +02:00
										 |  |  |     QList<PresetKeys>::const_iterator presetKeysIt = configKeys.m_presetKeys.begin(); | 
					
						
							|  |  |  |     int i = 0; | 
					
						
							|  |  |  |     for (; presetKeysIt != configKeys.m_presetKeys.end(); ++presetKeysIt, i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Preset *newPreset = new Preset(); // created with default values
 | 
					
						
							|  |  |  |         SWGSDRangel::SWGPreset *swgPreset = query.getPresets()->at(i); | 
					
						
							| 
									
										
										
										
											2019-08-11 01:27:19 +02:00
										 |  |  |         webAPIAdapterBase.webapiUpdatePreset(force, swgPreset, *presetKeysIt, newPreset); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         m_mainCore->m_settings.addPreset(newPreset); | 
					
						
							| 
									
										
										
										
											2019-08-09 18:45:10 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QList<CommandKeys>::const_iterator commandKeysIt = configKeys.m_commandKeys.begin(); | 
					
						
							|  |  |  |     i = 0; | 
					
						
							|  |  |  |     for (; commandKeysIt != configKeys.m_commandKeys.end(); ++commandKeysIt, i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Command *newCommand = new Command(); // created with default values
 | 
					
						
							|  |  |  |         SWGSDRangel::SWGCommand *swgCommand = query.getCommands()->at(i); | 
					
						
							|  |  |  |         webAPIAdapterBase.webapiUpdateCommand(swgCommand, *commandKeysIt, *newCommand); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         m_mainCore->m_settings.addCommand(newCommand); | 
					
						
							| 
									
										
										
										
											2019-08-09 18:45:10 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-11 01:27:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-24 05:38:05 +02:00
										 |  |  |     QList<FeatureSetPresetKeys>::const_iterator featureSetPresetKeysIt = configKeys.m_featureSetPresetKeys.begin(); | 
					
						
							|  |  |  |     i = 0; | 
					
						
							|  |  |  |     for (; featureSetPresetKeysIt != configKeys.m_featureSetPresetKeys.end(); ++featureSetPresetKeysIt, i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         FeatureSetPreset *newPreset = new FeatureSetPreset(); // created with default values
 | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeatureSetPreset *swgPreset = query.getFeaturesetpresets()->at(i); | 
					
						
							|  |  |  |         webAPIAdapterBase.webapiUpdateFeatureSetPreset(force, swgPreset, *featureSetPresetKeysIt, newPreset); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         m_mainCore->m_settings.addFeatureSetPreset(newPreset); | 
					
						
							| 
									
										
										
										
											2020-09-24 05:38:05 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     MainCore::MsgApplySettings *msg = MainCore::MsgApplySettings::create(); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2019-08-11 01:27:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							| 
									
										
										
										
											2019-08-06 08:48:14 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceDevices( | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             int direction, | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |             SWGSDRangel::SWGInstanceDevicesResponse& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-22 18:57:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     int nbSamplingDevices; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (direction == 0) { // Single Rx stream device
 | 
					
						
							|  |  |  |         nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices(); | 
					
						
							|  |  |  |     } else if (direction == 1) { // Single Tx stream device
 | 
					
						
							|  |  |  |         nbSamplingDevices = DeviceEnumerator::instance()->getNbTxSamplingDevices(); | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |     } else if (direction == 2) { // MIMO device
 | 
					
						
							|  |  |  |         nbSamplingDevices = DeviceEnumerator::instance()->getNbMIMOSamplingDevices(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |     } else { // not supported
 | 
					
						
							|  |  |  |         nbSamplingDevices = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 18:57:35 +01:00
										 |  |  |     response.setDevicecount(nbSamplingDevices); | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |     QList<SWGSDRangel::SWGDeviceListItem*> *devices = response.getDevices(); | 
					
						
							| 
									
										
										
										
											2017-11-18 19:34:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 18:57:35 +01:00
										 |  |  |     for (int i = 0; i < nbSamplingDevices; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         const PluginInterface::SamplingDevice *samplingDevice = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (direction == 0) { | 
					
						
							|  |  |  |             samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i); | 
					
						
							|  |  |  |         } else if (direction == 1) { | 
					
						
							|  |  |  |             samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i); | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |         } else if (direction == 2) { | 
					
						
							|  |  |  |             samplingDevice = DeviceEnumerator::instance()->getMIMOSamplingDevice(i); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         devices->append(new SWGSDRangel::SWGDeviceListItem); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |         devices->back()->init(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         *devices->back()->getDisplayedName() = samplingDevice->displayedName; | 
					
						
							|  |  |  |         *devices->back()->getHwType() = samplingDevice->hardwareId; | 
					
						
							|  |  |  |         *devices->back()->getSerial() = samplingDevice->serial; | 
					
						
							|  |  |  |         devices->back()->setSequence(samplingDevice->sequence); | 
					
						
							|  |  |  |         devices->back()->setDirection((int) samplingDevice->streamType); | 
					
						
							|  |  |  |         devices->back()->setDeviceNbStreams(samplingDevice->deviceNbItems); | 
					
						
							|  |  |  |         devices->back()->setDeviceSetIndex(samplingDevice->claimed); | 
					
						
							| 
									
										
										
										
											2017-11-22 22:16:57 +01:00
										 |  |  |         devices->back()->setIndex(i); | 
					
						
							| 
									
										
										
										
											2017-11-22 18:57:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceChannels( | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             int direction, | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |             SWGSDRangel::SWGInstanceChannelsResponse& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |     PluginAPI::ChannelRegistrations *channelRegistrations; | 
					
						
							|  |  |  |     int nbChannelDevices; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (direction == 0) // Single sink (Rx) channel
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         channelRegistrations = m_mainCore->m_pluginManager->getRxChannelRegistrations(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         nbChannelDevices = channelRegistrations->size(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (direction == 1) // Single source (Tx) channel
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         channelRegistrations = m_mainCore->m_pluginManager->getTxChannelRegistrations(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         nbChannelDevices = channelRegistrations->size(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-12-23 23:00:11 +01:00
										 |  |  |     else if (direction == 2) // MIMO channel
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         channelRegistrations = m_mainCore->m_pluginManager->getMIMOChannelRegistrations(); | 
					
						
							| 
									
										
										
										
											2019-12-23 23:00:11 +01:00
										 |  |  |         nbChannelDevices = channelRegistrations->size(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |     else // not supported
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         channelRegistrations = nullptr; | 
					
						
							|  |  |  |         nbChannelDevices = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  |     response.setChannelcount(nbChannelDevices); | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |     QList<SWGSDRangel::SWGChannelListItem*> *channels = response.getChannels(); | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < nbChannelDevices; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         channels->append(new SWGSDRangel::SWGChannelListItem); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |         channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  |         PluginInterface *channelInterface = channelRegistrations->at(i).m_plugin; | 
					
						
							|  |  |  |         const PluginDescriptor& pluginDescriptor = channelInterface->getPluginDescriptor(); | 
					
						
							|  |  |  |         *channels->back()->getVersion() = pluginDescriptor.version; | 
					
						
							|  |  |  |         *channels->back()->getName() = pluginDescriptor.displayedName; | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         channels->back()->setDirection(direction); | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  |         *channels->back()->getIdUri() = channelRegistrations->at(i).m_channelIdURI; | 
					
						
							|  |  |  |         *channels->back()->getId() = channelRegistrations->at(i).m_channelId; | 
					
						
							|  |  |  |         channels->back()->setIndex(i); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-29 00:48:35 +02:00
										 |  |  | int WebAPIAdapter::instanceFeatures( | 
					
						
							|  |  |  |             SWGSDRangel::SWGInstanceFeaturesResponse& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) error; | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     PluginAPI::FeatureRegistrations *featureRegistrations; | 
					
						
							|  |  |  |     int nbFeatureDevices; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     featureRegistrations = m_mainCore->m_pluginManager->getFeatureRegistrations(); | 
					
						
							|  |  |  |     nbFeatureDevices = featureRegistrations->size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.setFeaturecount(nbFeatureDevices); | 
					
						
							|  |  |  |     QList<SWGSDRangel::SWGFeatureListItem*> *features = response.getFeatures(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < nbFeatureDevices; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         features->append(new SWGSDRangel::SWGFeatureListItem); | 
					
						
							|  |  |  |         features->back()->init(); | 
					
						
							|  |  |  |         PluginInterface *featureInterface = featureRegistrations->at(i).m_plugin; | 
					
						
							|  |  |  |         const PluginDescriptor& pluginDescriptor = featureInterface->getPluginDescriptor(); | 
					
						
							|  |  |  |         *features->back()->getVersion() = pluginDescriptor.version; | 
					
						
							|  |  |  |         *features->back()->getName() = pluginDescriptor.displayedName; | 
					
						
							|  |  |  |         *features->back()->getIdUri() = featureRegistrations->at(i).m_featureIdURI; | 
					
						
							|  |  |  |         *features->back()->getId() = featureRegistrations->at(i).m_featureId; | 
					
						
							|  |  |  |         features->back()->setIndex(i); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceLoggingGet( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGLoggingInfo& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     response.setDumpToFile(m_mainCore->m_logger->getUseFileLogger() ? 1 : 0); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (response.getDumpToFile()) { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         m_mainCore->m_logger->getLogFileName(*response.getFileName()); | 
					
						
							|  |  |  |         m_mainCore->m_logger->getFileMinMessageLevelStr(*response.getFileLevel()); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     m_mainCore->m_logger->getConsoleMinMessageLevelStr(*response.getConsoleLevel()); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceLoggingPut( | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |         SWGSDRangel::SWGLoggingInfo& query, | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGLoggingInfo& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  |     // response input is the query actually
 | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     bool dumpToFile = (query.getDumpToFile() != 0); | 
					
						
							|  |  |  |     QString* consoleLevel = query.getConsoleLevel(); | 
					
						
							|  |  |  |     QString* fileLevel = query.getFileLevel(); | 
					
						
							|  |  |  |     QString* fileName = query.getFileName(); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // perform actions
 | 
					
						
							|  |  |  |     if (consoleLevel) { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         m_mainCore->m_settings.setConsoleMinLogLevel(getMsgTypeFromString(*consoleLevel)); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (fileLevel) { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         m_mainCore->m_settings.setFileMinLogLevel(getMsgTypeFromString(*fileLevel)); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     m_mainCore->m_settings.setUseLogFile(dumpToFile); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (fileName) { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         m_mainCore->m_settings.setLogFileName(*fileName); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     m_mainCore->setLoggingOptions(); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // build response
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     getMsgTypeString(m_mainCore->m_settings.getConsoleMinLogLevel(), *response.getConsoleLevel()); | 
					
						
							|  |  |  |     response.setDumpToFile(m_mainCore->m_settings.getUseLogFile() ? 1 : 0); | 
					
						
							|  |  |  |     getMsgTypeString(m_mainCore->m_settings.getFileMinLogLevel(), *response.getFileLevel()); | 
					
						
							|  |  |  |     *response.getFileName() = m_mainCore->m_settings.getLogFileName(); | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceAudioGet( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGAudioDevices& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-24 08:46:12 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DSPEngine *dspEngine = DSPEngine::instance(); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |     const QList<AudioDeviceInfo>& audioInputDevices = dspEngine->getAudioDeviceManager()->getInputDevices(); | 
					
						
							|  |  |  |     const QList<AudioDeviceInfo>& audioOutputDevices = dspEngine->getAudioDeviceManager()->getOutputDevices(); | 
					
						
							| 
									
										
										
										
											2017-11-24 08:46:12 +01:00
										 |  |  |     int nbInputDevices = audioInputDevices.size(); | 
					
						
							|  |  |  |     int nbOutputDevices = audioOutputDevices.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2017-11-24 08:46:12 +01:00
										 |  |  |     response.setNbInputDevices(nbInputDevices); | 
					
						
							|  |  |  |     response.setNbOutputDevices(nbOutputDevices); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     QList<SWGSDRangel::SWGAudioInputDevice*> *inputDevices = response.getInputDevices(); | 
					
						
							|  |  |  |     QList<SWGSDRangel::SWGAudioOutputDevice*> *outputDevices = response.getOutputDevices(); | 
					
						
							|  |  |  |     AudioDeviceManager::InputDeviceInfo inputDeviceInfo; | 
					
						
							|  |  |  |     AudioDeviceManager::OutputDeviceInfo outputDeviceInfo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // system default input device
 | 
					
						
							|  |  |  |     inputDevices->append(new SWGSDRangel::SWGAudioInputDevice); | 
					
						
							|  |  |  |     inputDevices->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     bool found = dspEngine->getAudioDeviceManager()->getInputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, inputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     *inputDevices->back()->getName() = AudioDeviceManager::m_defaultDeviceName; | 
					
						
							|  |  |  |     inputDevices->back()->setIndex(-1); | 
					
						
							|  |  |  |     inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate); | 
					
						
							|  |  |  |     inputDevices->back()->setIsSystemDefault(0); | 
					
						
							|  |  |  |     inputDevices->back()->setDefaultUnregistered(found ? 0 : 1); | 
					
						
							|  |  |  |     inputDevices->back()->setVolume(inputDeviceInfo.volume); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // real input devices
 | 
					
						
							| 
									
										
										
										
											2017-11-24 08:46:12 +01:00
										 |  |  |     for (int i = 0; i < nbInputDevices; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         inputDevices->append(new SWGSDRangel::SWGAudioInputDevice); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |         inputDevices->back()->init(); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         inputDeviceInfo.resetToDefaults(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         found = dspEngine->getAudioDeviceManager()->getInputDeviceInfo(audioInputDevices.at(i).deviceName(), inputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  |         *inputDevices->back()->getName() = audioInputDevices.at(i).deviceName(); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         inputDevices->back()->setIndex(i); | 
					
						
							|  |  |  |         inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |         inputDevices->back()->setIsSystemDefault(audioInputDevices.at(i).deviceName() == AudioDeviceInfo::defaultInputDevice().deviceName() ? 1 : 0); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         inputDevices->back()->setDefaultUnregistered(found ? 0 : 1); | 
					
						
							|  |  |  |         inputDevices->back()->setVolume(inputDeviceInfo.volume); | 
					
						
							| 
									
										
										
										
											2017-11-24 08:46:12 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     // system default output device
 | 
					
						
							|  |  |  |     outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice); | 
					
						
							|  |  |  |     outputDevices->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     found = dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, outputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     *outputDevices->back()->getName() = AudioDeviceManager::m_defaultDeviceName; | 
					
						
							|  |  |  |     outputDevices->back()->setIndex(-1); | 
					
						
							|  |  |  |     outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate); | 
					
						
							|  |  |  |     inputDevices->back()->setIsSystemDefault(0); | 
					
						
							|  |  |  |     outputDevices->back()->setDefaultUnregistered(found ? 0 : 1); | 
					
						
							|  |  |  |     outputDevices->back()->setCopyToUdp(outputDeviceInfo.copyToUDP ? 1 : 0); | 
					
						
							|  |  |  |     outputDevices->back()->setUdpUsesRtp(outputDeviceInfo.udpUseRTP ? 1 : 0); | 
					
						
							|  |  |  |     outputDevices->back()->setUdpChannelMode((int) outputDeviceInfo.udpChannelMode); | 
					
						
							| 
									
										
										
										
											2019-02-15 12:10:01 +01:00
										 |  |  |     outputDevices->back()->setUdpChannelCodec((int) outputDeviceInfo.udpChannelCodec); | 
					
						
							|  |  |  |     outputDevices->back()->setUdpDecimationFactor((int) outputDeviceInfo.udpDecimationFactor); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     *outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress; | 
					
						
							|  |  |  |     outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort); | 
					
						
							| 
									
										
										
										
											2022-11-12 11:25:45 +01:00
										 |  |  |     *outputDevices->back()->getFileRecordName() = outputDeviceInfo.fileRecordName; | 
					
						
							|  |  |  |     outputDevices->back()->setRecordToFile(outputDeviceInfo.recordToFile ? 1 : 0); | 
					
						
							|  |  |  |     outputDevices->back()->setRecordSilenceTime(outputDeviceInfo.recordSilenceTime); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // real output devices
 | 
					
						
							| 
									
										
										
										
											2017-11-24 08:46:12 +01:00
										 |  |  |     for (int i = 0; i < nbOutputDevices; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |         outputDevices->back()->init(); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         outputDeviceInfo.resetToDefaults(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         found = dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(audioOutputDevices.at(i).deviceName(), outputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  |         *outputDevices->back()->getName() = audioOutputDevices.at(i).deviceName(); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         outputDevices->back()->setIndex(i); | 
					
						
							|  |  |  |         outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |         outputDevices->back()->setIsSystemDefault(audioOutputDevices.at(i).deviceName() == AudioDeviceInfo::defaultOutputDevice().deviceName() ? 1 : 0); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         outputDevices->back()->setDefaultUnregistered(found ? 0 : 1); | 
					
						
							|  |  |  |         outputDevices->back()->setCopyToUdp(outputDeviceInfo.copyToUDP ? 1 : 0); | 
					
						
							|  |  |  |         outputDevices->back()->setUdpUsesRtp(outputDeviceInfo.udpUseRTP ? 1 : 0); | 
					
						
							|  |  |  |         outputDevices->back()->setUdpChannelMode((int) outputDeviceInfo.udpChannelMode); | 
					
						
							| 
									
										
										
										
											2019-02-15 12:10:01 +01:00
										 |  |  |         outputDevices->back()->setUdpChannelCodec((int) outputDeviceInfo.udpChannelCodec); | 
					
						
							|  |  |  |         outputDevices->back()->setUdpDecimationFactor((int) outputDeviceInfo.udpDecimationFactor); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         *outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress; | 
					
						
							|  |  |  |         outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort); | 
					
						
							| 
									
										
										
										
											2022-11-12 11:25:45 +01:00
										 |  |  |         *outputDevices->back()->getFileRecordName() = outputDeviceInfo.fileRecordName; | 
					
						
							|  |  |  |         outputDevices->back()->setRecordToFile(outputDeviceInfo.recordToFile ? 1 : 0); | 
					
						
							|  |  |  |         outputDevices->back()->setRecordSilenceTime(outputDeviceInfo.recordSilenceTime); | 
					
						
							| 
									
										
										
										
											2017-11-24 08:46:12 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceAudioInputPatch( | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         SWGSDRangel::SWGAudioInputDevice& response, | 
					
						
							|  |  |  |         const QStringList& audioInputKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DSPEngine *dspEngine = DSPEngine::instance(); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     AudioDeviceManager::InputDeviceInfo inputDeviceInfo; | 
					
						
							|  |  |  |     QString deviceName; | 
					
						
							|  |  |  |     int deviceIndex = response.getIndex(); | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if (!dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName)) | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no audio input device at index %1").arg(deviceIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (audioInputKeys.contains("sampleRate")) { | 
					
						
							|  |  |  |         inputDeviceInfo.sampleRate = response.getSampleRate(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (audioInputKeys.contains("volume")) { | 
					
						
							|  |  |  |         inputDeviceInfo.volume = response.getVolume(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     dspEngine->getAudioDeviceManager()->setInputDeviceInfo(deviceIndex, inputDeviceInfo); | 
					
						
							|  |  |  |     dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.setSampleRate(inputDeviceInfo.sampleRate); | 
					
						
							|  |  |  |     response.setVolume(inputDeviceInfo.volume); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceAudioOutputPatch( | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |         SWGSDRangel::SWGAudioOutputDevice& response, | 
					
						
							|  |  |  |         const QStringList& audioOutputKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DSPEngine *dspEngine = DSPEngine::instance(); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     AudioDeviceManager::OutputDeviceInfo outputDeviceInfo; | 
					
						
							|  |  |  |     QString deviceName; | 
					
						
							|  |  |  |     int deviceIndex = response.getIndex(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if (!dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName)) | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no audio output device at index %1").arg(deviceIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("sampleRate")) { | 
					
						
							|  |  |  |         outputDeviceInfo.sampleRate = response.getSampleRate(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("copyToUDP")) { | 
					
						
							|  |  |  |         outputDeviceInfo.copyToUDP = response.getCopyToUdp() == 0 ? 0 : 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("udpUsesRTP")) { | 
					
						
							|  |  |  |         outputDeviceInfo.udpUseRTP = response.getUdpUsesRtp() == 0 ? 0 : 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("udpChannelMode")) { | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |         outputDeviceInfo.udpChannelMode = static_cast<AudioOutputDevice::UDPChannelMode>(response.getUdpChannelMode()); | 
					
						
							| 
									
										
										
										
											2019-02-15 12:10:01 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("udpChannelCodec")) { | 
					
						
							| 
									
										
										
										
											2020-11-12 22:13:44 +01:00
										 |  |  |         outputDeviceInfo.udpChannelCodec = static_cast<AudioOutputDevice::UDPChannelCodec>(response.getUdpChannelCodec()); | 
					
						
							| 
									
										
										
										
											2019-02-15 12:10:01 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-05-23 15:10:23 +02:00
										 |  |  |     if (audioOutputKeys.contains("udpDecimationFactor")) { | 
					
						
							| 
									
										
										
										
											2019-02-15 12:10:01 +01:00
										 |  |  |         outputDeviceInfo.udpDecimationFactor = response.getUdpDecimationFactor(); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("udpAddress")) { | 
					
						
							|  |  |  |         outputDeviceInfo.udpAddress = *response.getUdpAddress(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("udpPort")) { | 
					
						
							|  |  |  |         outputDeviceInfo.udpPort = response.getUdpPort() % (1<<16); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-11-12 11:25:45 +01:00
										 |  |  |     if (audioOutputKeys.contains("fileRecordName")) { | 
					
						
							|  |  |  |         outputDeviceInfo.fileRecordName = *response.getFileRecordName(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("recordToFile")) { | 
					
						
							|  |  |  |         outputDeviceInfo.recordToFile = response.getRecordToFile() == 0 ? 0 : 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (audioOutputKeys.contains("recordSilenceTime")) { | 
					
						
							|  |  |  |         outputDeviceInfo.recordSilenceTime = response.getRecordSilenceTime(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     dspEngine->getAudioDeviceManager()->setOutputDeviceInfo(deviceIndex, outputDeviceInfo); | 
					
						
							|  |  |  |     dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     response.setSampleRate(outputDeviceInfo.sampleRate); | 
					
						
							|  |  |  |     response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1); | 
					
						
							|  |  |  |     response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1); | 
					
						
							| 
									
										
										
										
											2019-02-15 12:10:01 +01:00
										 |  |  |     response.setUdpChannelMode(outputDeviceInfo.udpChannelMode); | 
					
						
							|  |  |  |     response.setUdpChannelCodec(outputDeviceInfo.udpChannelCodec); | 
					
						
							|  |  |  |     response.setUdpDecimationFactor(outputDeviceInfo.udpDecimationFactor); | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (response.getUdpAddress()) { | 
					
						
							|  |  |  |         *response.getUdpAddress() = outputDeviceInfo.udpAddress; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.setUdpAddress(new QString(outputDeviceInfo.udpAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 00:38:01 +02:00
										 |  |  |     response.setUdpPort(outputDeviceInfo.udpPort % (1<<16)); | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-12 11:25:45 +01:00
										 |  |  |     if (response.getFileRecordName()) { | 
					
						
							|  |  |  |         *response.getFileRecordName() = outputDeviceInfo.fileRecordName; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.setFileRecordName(new QString(outputDeviceInfo.fileRecordName)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.setRecordToFile(outputDeviceInfo.recordToFile == 0 ? 0 : 1); | 
					
						
							|  |  |  |     response.setRecordSilenceTime(outputDeviceInfo.recordSilenceTime); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-24 17:12:53 +01:00
										 |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceAudioInputDelete( | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  |             SWGSDRangel::SWGAudioInputDevice& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DSPEngine *dspEngine = DSPEngine::instance(); | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  |     AudioDeviceManager::InputDeviceInfo inputDeviceInfo; | 
					
						
							|  |  |  |     QString deviceName; | 
					
						
							|  |  |  |     int deviceIndex = response.getIndex(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if (!dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName)) | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no audio input device at index %1").arg(deviceIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     dspEngine->getAudioDeviceManager()->unsetInputDeviceInfo(deviceIndex); | 
					
						
							|  |  |  |     dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.setSampleRate(inputDeviceInfo.sampleRate); | 
					
						
							|  |  |  |     response.setVolume(inputDeviceInfo.volume); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceAudioOutputDelete( | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  |             SWGSDRangel::SWGAudioOutputDevice& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DSPEngine *dspEngine = DSPEngine::instance(); | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  |     AudioDeviceManager::OutputDeviceInfo outputDeviceInfo; | 
					
						
							|  |  |  |     QString deviceName; | 
					
						
							|  |  |  |     int deviceIndex = response.getIndex(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if (!dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName)) | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no audio output device at index %1").arg(deviceIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     dspEngine->getAudioDeviceManager()->unsetInputDeviceInfo(deviceIndex); | 
					
						
							|  |  |  |     dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo); | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.setSampleRate(outputDeviceInfo.sampleRate); | 
					
						
							|  |  |  |     response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1); | 
					
						
							|  |  |  |     response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1); | 
					
						
							| 
									
										
										
										
											2019-02-15 12:10:01 +01:00
										 |  |  |     response.setUdpChannelMode(outputDeviceInfo.udpChannelMode); | 
					
						
							|  |  |  |     response.setUdpChannelCodec(outputDeviceInfo.udpChannelCodec); | 
					
						
							|  |  |  |     response.setUdpDecimationFactor(outputDeviceInfo.udpDecimationFactor); | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (response.getUdpAddress()) { | 
					
						
							|  |  |  |         *response.getUdpAddress() = outputDeviceInfo.udpAddress; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         response.setUdpAddress(new QString(outputDeviceInfo.udpAddress)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.setUdpPort(outputDeviceInfo.udpPort % (1<<16)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceAudioInputCleanupPatch( | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  |             SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DSPEngine *dspEngine = DSPEngine::instance(); | 
					
						
							|  |  |  |     dspEngine->getAudioDeviceManager()->inputInfosCleanup(); | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     *response.getMessage() = QString("Unregistered parameters for devices not in list of available input devices for this instance"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceAudioOutputCleanupPatch( | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  |             SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DSPEngine *dspEngine = DSPEngine::instance(); | 
					
						
							|  |  |  |     dspEngine->getAudioDeviceManager()->outputInfosCleanup(); | 
					
						
							| 
									
										
										
										
											2018-03-29 01:43:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     *response.getMessage() = QString("Unregistered parameters for devices not in list of available output devices for this instance"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceLocationGet( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGLocationInformation& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 04:02:11 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     response.setLatitude(m_mainCore->m_settings.getLatitude()); | 
					
						
							|  |  |  |     response.setLongitude(m_mainCore->m_settings.getLongitude()); | 
					
						
							| 
									
										
										
										
											2017-11-25 04:02:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceLocationPut( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGLocationInformation& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 04:02:11 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2017-11-25 04:02:11 +01:00
										 |  |  |     float latitude = response.getLatitude(); | 
					
						
							|  |  |  |     float longitude = response.getLongitude(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     latitude = latitude < -90.0 ? -90.0 : latitude > 90.0 ? 90.0 : latitude; | 
					
						
							|  |  |  |     longitude = longitude < -180.0 ? -180.0 : longitude > 180.0 ? 180.0 : longitude; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     m_mainCore->m_settings.setLatitude(latitude); | 
					
						
							|  |  |  |     m_mainCore->m_settings.setLongitude(longitude); | 
					
						
							| 
									
										
										
										
											2017-11-25 04:02:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     response.setLatitude(m_mainCore->m_settings.getLatitude()); | 
					
						
							|  |  |  |     response.setLongitude(m_mainCore->m_settings.getLongitude()); | 
					
						
							| 
									
										
										
										
											2017-11-25 04:02:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instancePresetsGet( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGPresets& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 11:14:52 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     int nbPresets = m_mainCore->m_settings.getPresetCount(); | 
					
						
							| 
									
										
										
										
											2017-11-25 11:14:52 +01:00
										 |  |  |     int nbGroups = 0; | 
					
						
							|  |  |  |     int nbPresetsThisGroup = 0; | 
					
						
							|  |  |  |     QString groupName; | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |     QList<SWGSDRangel::SWGPresetGroup*> *groups = response.getGroups(); | 
					
						
							|  |  |  |     QList<SWGSDRangel::SWGPresetItem*> *swgPresets = 0; | 
					
						
							| 
									
										
										
										
											2017-11-25 11:14:52 +01:00
										 |  |  |     int i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Presets are sorted by group first
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (; i < nbPresets; i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         const Preset *preset = m_mainCore->m_settings.getPreset(i); | 
					
						
							| 
									
										
										
										
											2017-11-25 11:14:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ((i == 0) || (groupName != preset->getGroup())) // new group
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); } | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |             groups->append(new SWGSDRangel::SWGPresetGroup); | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |             groups->back()->init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 11:14:52 +01:00
										 |  |  |             groupName = preset->getGroup(); | 
					
						
							|  |  |  |             *groups->back()->getGroupName() = groupName; | 
					
						
							|  |  |  |             swgPresets = groups->back()->getPresets(); | 
					
						
							|  |  |  |             nbGroups++; | 
					
						
							|  |  |  |             nbPresetsThisGroup = 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         swgPresets->append(new SWGSDRangel::SWGPresetItem); | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         swgPresets->back()->init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 11:14:52 +01:00
										 |  |  |         swgPresets->back()->setCenterFrequency(preset->getCenterFrequency()); | 
					
						
							| 
									
										
										
										
											2022-05-08 19:33:10 +02:00
										 |  |  |         *swgPresets->back()->getType() = Preset::getPresetTypeChar(preset->getPresetType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 11:14:52 +01:00
										 |  |  |         *swgPresets->back()->getName() = preset->getDescription(); | 
					
						
							|  |  |  |         nbPresetsThisGroup++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); } | 
					
						
							|  |  |  |     response.setNbGroups(nbGroups); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instancePresetPatch( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGPresetTransfer& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     int deviceSetIndex = query.getDeviceSetIndex(); | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |     SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     int nbDeviceSets = m_mainCore->m_deviceSets.size(); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-20 14:31:17 +01:00
										 |  |  |     if (deviceSetIndex >= nbDeviceSets) | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |         *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     const Preset *selectedPreset = m_mainCore->m_settings.getPreset(*presetIdentifier->getGroupName(), | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |             presetIdentifier->getCenterFrequency(), | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             *presetIdentifier->getName(), | 
					
						
							|  |  |  |             *presetIdentifier->getType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (selectedPreset == 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]") | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |                 .arg(*presetIdentifier->getGroupName()) | 
					
						
							|  |  |  |                 .arg(presetIdentifier->getCenterFrequency()) | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |                 .arg(*presetIdentifier->getName()) | 
					
						
							|  |  |  |                 .arg(*presetIdentifier->getType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DeviceSet *deviceUI = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (deviceUI->m_deviceSourceEngine && !selectedPreset->isSourcePreset()) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  |         *error.getMessage() = QString("Preset type and device set type (Rx) mismatch"); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  |     if (deviceUI->m_deviceSinkEngine && !selectedPreset->isSinkPreset()) | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  |         *error.getMessage() = QString("Preset type and device set type (Tx) mismatch"); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceUI->m_deviceMIMOEngine && !selectedPreset->isMIMOPreset()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("Preset type and device set type (MIMO) mismatch"); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     MainCore::MsgLoadPreset *msg = MainCore::MsgLoadPreset::create(selectedPreset, deviceSetIndex); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |     response.setCenterFrequency(selectedPreset->getCenterFrequency()); | 
					
						
							|  |  |  |     *response.getGroupName() = selectedPreset->getGroup(); | 
					
						
							| 
									
										
										
										
											2022-05-08 19:33:10 +02:00
										 |  |  |     *response.getType() = Preset::getPresetTypeChar(selectedPreset->getPresetType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |     *response.getName() = selectedPreset->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |     return 202; | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instancePresetPut( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGPresetTransfer& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     int deviceSetIndex = query.getDeviceSetIndex(); | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |     SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     int nbDeviceSets = m_mainCore->m_deviceSets.size(); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 00:23:36 +01:00
										 |  |  |     if (deviceSetIndex >= nbDeviceSets) | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |         *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     const Preset *selectedPreset = m_mainCore->m_settings.getPreset(*presetIdentifier->getGroupName(), | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |             presetIdentifier->getCenterFrequency(), | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             *presetIdentifier->getName(), | 
					
						
							|  |  |  |             *presetIdentifier->getType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |     if (selectedPreset == 0) | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]") | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |                 .arg(*presetIdentifier->getGroupName()) | 
					
						
							|  |  |  |                 .arg(presetIdentifier->getCenterFrequency()) | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |                 .arg(*presetIdentifier->getName()) | 
					
						
							|  |  |  |                 .arg(*presetIdentifier->getType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |         return 404; | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else // update existing preset
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceUI = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceUI->m_deviceSourceEngine && !selectedPreset->isSourcePreset()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |             error.init(); | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  |             *error.getMessage() = QString("Preset type and device set type (Rx) mismatch"); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (deviceUI->m_deviceSinkEngine && !selectedPreset->isSinkPreset()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("Preset type and device set type (Tx) mismatch"); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  |         if (deviceUI->m_deviceMIMOEngine && !selectedPreset->isMIMOPreset()) | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |             error.init(); | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  |             *error.getMessage() = QString("Preset type and device set type (MIMO) mismatch"); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     MainCore::MsgSavePreset *msg = MainCore::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, false); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |     response.setCenterFrequency(selectedPreset->getCenterFrequency()); | 
					
						
							|  |  |  |     *response.getGroupName() = selectedPreset->getGroup(); | 
					
						
							| 
									
										
										
										
											2022-05-08 19:33:10 +02:00
										 |  |  |     *response.getType() = Preset::getPresetTypeChar(selectedPreset->getPresetType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |     *response.getName() = selectedPreset->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |     return 202; | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instancePresetPost( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGPresetTransfer& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     int deviceSetIndex = query.getDeviceSetIndex(); | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |     SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     int nbDeviceSets = m_mainCore->m_deviceSets.size(); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 00:23:36 +01:00
										 |  |  |     if (deviceSetIndex >= nbDeviceSets) | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |         *error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |     int deviceCenterFrequency = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceSet->m_deviceSourceEngine) { // Rx
 | 
					
						
							|  |  |  |         deviceCenterFrequency = deviceSet->m_deviceSourceEngine->getSource()->getCenterFrequency(); | 
					
						
							|  |  |  |     } else if (deviceSet->m_deviceSinkEngine) { // Tx
 | 
					
						
							|  |  |  |         deviceCenterFrequency = deviceSet->m_deviceSinkEngine->getSink()->getCenterFrequency(); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |     } else if (deviceSet->m_deviceMIMOEngine) { // MIMO
 | 
					
						
							|  |  |  |         deviceCenterFrequency = deviceSet->m_deviceMIMOEngine->getMIMO()->getMIMOCenterFrequency(); | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("Device set error"); | 
					
						
							|  |  |  |         return 500; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     const Preset *selectedPreset = m_mainCore->m_settings.getPreset(*presetIdentifier->getGroupName(), | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |             deviceCenterFrequency, | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             *presetIdentifier->getName(), | 
					
						
							|  |  |  |             *presetIdentifier->getType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (selectedPreset == 0) // save on a new preset
 | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         selectedPreset = m_mainCore->m_settings.newPreset(*presetIdentifier->getGroupName(), *presetIdentifier->getName()); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         *error.getMessage() = QString("Preset already exists [%1, %2, %3 %4]") | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |                 .arg(*presetIdentifier->getGroupName()) | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |                 .arg(deviceCenterFrequency) | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |                 .arg(*presetIdentifier->getName()) | 
					
						
							|  |  |  |                 .arg(*presetIdentifier->getType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 18:32:37 +01:00
										 |  |  |         return 409; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     MainCore::MsgSavePreset *msg = MainCore::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, true); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:47:13 +01:00
										 |  |  |     response.setCenterFrequency(selectedPreset->getCenterFrequency()); | 
					
						
							|  |  |  |     *response.getGroupName() = selectedPreset->getGroup(); | 
					
						
							| 
									
										
										
										
											2022-05-08 19:33:10 +02:00
										 |  |  |     *response.getType() = Preset::getPresetTypeChar(selectedPreset->getPresetType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  |     *response.getName() = selectedPreset->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |     return 202; | 
					
						
							| 
									
										
										
										
											2017-11-25 16:08:18 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instancePresetDelete( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGPresetIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 19:42:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     const Preset *selectedPreset = m_mainCore->m_settings.getPreset(*response.getGroupName(), | 
					
						
							| 
									
										
										
										
											2017-11-25 19:42:56 +01:00
										 |  |  |             response.getCenterFrequency(), | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             *response.getName(), | 
					
						
							|  |  |  |             *response.getType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 19:42:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (selectedPreset == 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-08 19:33:10 +02:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         *error.getMessage() = QString("There is no preset [%1, %2, %3 %4]") | 
					
						
							| 
									
										
										
										
											2017-11-25 19:42:56 +01:00
										 |  |  |                 .arg(*response.getGroupName()) | 
					
						
							|  |  |  |                 .arg(response.getCenterFrequency()) | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |                 .arg(*response.getName()) | 
					
						
							|  |  |  |                 .arg(*response.getType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 19:42:56 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.setCenterFrequency(selectedPreset->getCenterFrequency()); | 
					
						
							|  |  |  |     *response.getGroupName() = selectedPreset->getGroup(); | 
					
						
							| 
									
										
										
										
											2022-05-08 19:33:10 +02:00
										 |  |  |     *response.getType() = Preset::getPresetTypeChar(selectedPreset->getPresetType()); | 
					
						
							| 
									
										
										
										
											2017-11-25 19:42:56 +01:00
										 |  |  |     *response.getName() = selectedPreset->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     MainCore::MsgDeletePreset *msg = MainCore::MsgDeletePreset::create(const_cast<Preset*>(selectedPreset)); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2021-09-04 05:58:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-08 19:33:10 +02:00
										 |  |  | int WebAPIAdapter::instancePresetFilePut( | 
					
						
							|  |  |  |         SWGSDRangel::SWGFilePath& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString filePath = *query.getFilePath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (QFileInfo::exists(filePath)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QFile file(filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (file.open(QIODevice::ReadOnly | QIODevice::Text)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QByteArray base64Str; | 
					
						
							|  |  |  |             QTextStream instream(&file); | 
					
						
							|  |  |  |             instream >> base64Str; | 
					
						
							|  |  |  |             file.close(); | 
					
						
							|  |  |  |             Preset *newPreset = m_mainCore->m_settings.newPreset("TBD", "TBD"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (newPreset->deserialize(QByteArray::fromBase64(base64Str))) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.init(); | 
					
						
							|  |  |  |                 *response.getGroupName() = newPreset->getGroup(); | 
					
						
							|  |  |  |                 response.setCenterFrequency(newPreset->getCenterFrequency()); | 
					
						
							|  |  |  |                 *response.getName() = newPreset->getDescription(); | 
					
						
							|  |  |  |                 *response.getType() = Preset::getPresetTypeChar(newPreset->getPresetType()); | 
					
						
							|  |  |  |                 return 202; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 error.init(); | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Cannot deserialize preset from file %1").arg(filePath); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("Cannot read file %1").arg(filePath); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("File %1 is not found").arg(filePath); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instancePresetFilePost( | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetExport& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString filePath = *query.getFilePath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (QFileInfo(filePath).absoluteDir().exists()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetIdentifier *presetId = query.getPreset(); | 
					
						
							|  |  |  |         const Preset *selectedPreset = m_mainCore->m_settings.getPreset( | 
					
						
							|  |  |  |             *presetId->getGroupName(), | 
					
						
							|  |  |  |             presetId->getCenterFrequency(), | 
					
						
							|  |  |  |             *presetId->getName(), | 
					
						
							|  |  |  |             *presetId->getType()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (selectedPreset) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QString base64Str = selectedPreset->serialize().toBase64(); | 
					
						
							|  |  |  |             QFileInfo fileInfo(filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (fileInfo.suffix() != "prex") { | 
					
						
							|  |  |  |                 filePath += ".prex"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             QFile file(filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (file.open(QIODevice::ReadWrite | QIODevice::Text)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QTextStream outstream(&file); | 
					
						
							|  |  |  |                 outstream << base64Str; | 
					
						
							|  |  |  |                 file.close(); | 
					
						
							|  |  |  |                 response.init(); | 
					
						
							|  |  |  |                 *response.getGroupName() = selectedPreset->getGroup(); | 
					
						
							|  |  |  |                 response.setCenterFrequency(selectedPreset->getCenterFrequency()); | 
					
						
							|  |  |  |                 *response.getName() = selectedPreset->getDescription(); | 
					
						
							|  |  |  |                 *response.getType() = Preset::getPresetTypeChar(selectedPreset->getPresetType()); | 
					
						
							|  |  |  |                 return 200; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 error.init(); | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Cannot open %1 for writing").arg(filePath); | 
					
						
							|  |  |  |                 return 500; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no preset [%1, %2, %3, %4]") | 
					
						
							|  |  |  |                 .arg(*presetId->getGroupName()) | 
					
						
							|  |  |  |                 .arg(presetId->getCenterFrequency()) | 
					
						
							|  |  |  |                 .arg(*presetId->getName()) | 
					
						
							|  |  |  |                 .arg(*presetId->getType()); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("File %1 directory does not exist").arg(filePath); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instancePresetBlobPut( | 
					
						
							|  |  |  |         SWGSDRangel::SWGBase64Blob& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString *base64Str = query.getBlob(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (base64Str) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Preset *newPreset = m_mainCore->m_settings.newPreset("TBD", "TBD"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (newPreset) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QByteArray blob = QByteArray::fromBase64(base64Str->toUtf8()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (newPreset->deserialize(blob)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.init(); | 
					
						
							|  |  |  |                 *response.getGroupName() = newPreset->getGroup(); | 
					
						
							|  |  |  |                 response.setCenterFrequency(newPreset->getCenterFrequency()); | 
					
						
							|  |  |  |                 *response.getName() = newPreset->getDescription(); | 
					
						
							|  |  |  |                 *response.getType() = Preset::getPresetTypeChar(newPreset->getPresetType()); | 
					
						
							|  |  |  |                 return 202; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 m_mainCore->m_settings.deletePreset(newPreset); | 
					
						
							|  |  |  |                 error.init(); | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Could not deserialize blob to preset"); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("Cannot create new preset"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("Blob not specified"); | 
					
						
							|  |  |  |         return 400; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instancePresetBlobPost( | 
					
						
							|  |  |  |         SWGSDRangel::SWGPresetIdentifier& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGBase64Blob& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const Preset *selectedPreset = m_mainCore->m_settings.getPreset( | 
					
						
							|  |  |  |         *query.getGroupName(), | 
					
						
							|  |  |  |         query.getCenterFrequency(), | 
					
						
							|  |  |  |         *query.getName(), | 
					
						
							|  |  |  |         *query.getType()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedPreset) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString base64Str = selectedPreset->serialize().toBase64(); | 
					
						
							|  |  |  |         response.init(); | 
					
						
							|  |  |  |         *response.getBlob() = base64Str; | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no preset [%1, %2, %3, %4]") | 
					
						
							|  |  |  |             .arg(*query.getGroupName()) | 
					
						
							|  |  |  |             .arg(query.getCenterFrequency()) | 
					
						
							|  |  |  |             .arg(*query.getName()) | 
					
						
							|  |  |  |             .arg(*query.getType()); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationsGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurations& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) error; | 
					
						
							|  |  |  |     int nbConfigurations = m_mainCore->m_settings.getConfigurationCount(); | 
					
						
							|  |  |  |     int nbGroups = 0; | 
					
						
							|  |  |  |     int nbConfigurationsThisGroup = 0; | 
					
						
							|  |  |  |     QString groupName; | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     QList<SWGSDRangel::SWGConfigurationGroup*> *groups = response.getGroups(); | 
					
						
							|  |  |  |     QList<SWGSDRangel::SWGConfigurationItem*> *swgConfigurations = nullptr; | 
					
						
							|  |  |  |     int i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Configurations are sorted by group first
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (; i < nbConfigurations; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const Configuration *configuration = m_mainCore->m_settings.getConfiguration(i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((i == 0) || (groupName != configuration->getGroup())) // new group
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (i > 0) { | 
					
						
							|  |  |  |                 groups->back()->setNbConfigurations(nbConfigurationsThisGroup); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             groups->append(new SWGSDRangel::SWGConfigurationGroup); | 
					
						
							|  |  |  |             groups->back()->init(); | 
					
						
							|  |  |  |             groupName = configuration->getGroup(); | 
					
						
							|  |  |  |             *groups->back()->getGroupName() = groupName; | 
					
						
							|  |  |  |             swgConfigurations = groups->back()->getConfigurations(); | 
					
						
							|  |  |  |             nbGroups++; | 
					
						
							|  |  |  |             nbConfigurationsThisGroup = 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         swgConfigurations->append(new SWGSDRangel::SWGConfigurationItem); | 
					
						
							|  |  |  |         swgConfigurations->back()->init(); | 
					
						
							|  |  |  |         *swgConfigurations->back()->getName() = configuration->getDescription(); | 
					
						
							|  |  |  |         nbConfigurationsThisGroup++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (i > 0) { | 
					
						
							|  |  |  |         groups->back()->setNbConfigurations(nbConfigurationsThisGroup); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.setNbGroups(nbGroups); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationPatch( | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SWGSDRangel::SWGConfigurationIdentifier *configurationIdentifier = &response; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const Configuration *selectedConfiguration = m_mainCore->m_settings.getConfiguration( | 
					
						
							|  |  |  |         *configurationIdentifier->getGroupName(), | 
					
						
							|  |  |  |         *configurationIdentifier->getName() | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedConfiguration == nullptr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no configuration [%1, %2]") | 
					
						
							|  |  |  |                 .arg(*configurationIdentifier->getGroupName()) | 
					
						
							|  |  |  |                 .arg(*configurationIdentifier->getName()); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MainCore::MsgLoadConfiguration *msg = MainCore::MsgLoadConfiguration::create(selectedConfiguration); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     *response.getGroupName() = selectedConfiguration->getGroup(); | 
					
						
							|  |  |  |     *response.getName() = selectedConfiguration->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationPut( | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SWGSDRangel::SWGConfigurationIdentifier *configurationIdentifier = &response; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const Configuration *selectedConfiguration = m_mainCore->m_settings.getConfiguration( | 
					
						
							|  |  |  |         *configurationIdentifier->getGroupName(), | 
					
						
							|  |  |  |         *configurationIdentifier->getName() | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedConfiguration == nullptr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no configuration [%1, %2]") | 
					
						
							|  |  |  |                 .arg(*configurationIdentifier->getGroupName()) | 
					
						
							|  |  |  |                 .arg(*configurationIdentifier->getName()); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MainCore::MsgSaveConfiguration *msg = MainCore::MsgSaveConfiguration::create(const_cast<Configuration*>(selectedConfiguration), false); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     *response.getGroupName() = selectedConfiguration->getGroup(); | 
					
						
							|  |  |  |     *response.getName() = selectedConfiguration->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationPost( | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     SWGSDRangel::SWGConfigurationIdentifier *configurationIdentifier = &response; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const Configuration *selectedConfiguration = m_mainCore->m_settings.getConfiguration( | 
					
						
							|  |  |  |         *configurationIdentifier->getGroupName(), | 
					
						
							|  |  |  |         *configurationIdentifier->getName() | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedConfiguration == nullptr) // save on a new preset
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         selectedConfiguration = m_mainCore->m_settings.newConfiguration( | 
					
						
							|  |  |  |             *configurationIdentifier->getGroupName(), | 
					
						
							|  |  |  |             *configurationIdentifier->getName() | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("Preset already exists [%1, %2]") | 
					
						
							|  |  |  |             .arg(*configurationIdentifier->getGroupName()) | 
					
						
							|  |  |  |             .arg(*configurationIdentifier->getName()); | 
					
						
							|  |  |  |         return 409; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MainCore::MsgSaveConfiguration *msg = MainCore::MsgSaveConfiguration::create(const_cast<Configuration*>(selectedConfiguration), true); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     *response.getGroupName() = selectedConfiguration->getGroup(); | 
					
						
							|  |  |  |     *response.getName() = selectedConfiguration->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationDelete( | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const Configuration *selectedConfiguration = m_mainCore->m_settings.getConfiguration( | 
					
						
							|  |  |  |         *response.getGroupName(), | 
					
						
							|  |  |  |         *response.getName()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedConfiguration == nullptr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no configuration [%1, %2]") | 
					
						
							|  |  |  |             .arg(*response.getGroupName()) | 
					
						
							|  |  |  |             .arg(*response.getName()); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     *response.getGroupName() = selectedConfiguration->getGroup(); | 
					
						
							|  |  |  |     *response.getName() = selectedConfiguration->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MainCore::MsgDeleteConfiguration *msg = MainCore::MsgDeleteConfiguration::create(const_cast<Configuration*>(selectedConfiguration)); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationFilePut( | 
					
						
							|  |  |  |         SWGSDRangel::SWGFilePath& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString filePath = *query.getFilePath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (QFileInfo::exists(filePath)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QFile file(filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (file.open(QIODevice::ReadOnly | QIODevice::Text)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QByteArray base64Str; | 
					
						
							|  |  |  |             QTextStream instream(&file); | 
					
						
							|  |  |  |             instream >> base64Str; | 
					
						
							|  |  |  |             file.close(); | 
					
						
							|  |  |  |             Configuration *newConfiguration = m_mainCore->m_settings.newConfiguration("TBD", "TBD"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (newConfiguration->deserialize(QByteArray::fromBase64(base64Str))) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.init(); | 
					
						
							|  |  |  |                 *response.getGroupName() = newConfiguration->getGroup(); | 
					
						
							|  |  |  |                 *response.getName() = newConfiguration->getDescription(); | 
					
						
							|  |  |  |                 return 202; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 error.init(); | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Cannot deserialize configuration from file %1").arg(filePath); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("Cannot read file %1").arg(filePath); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("File %1 is not found").arg(filePath); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationFilePost( | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationImportExport& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString filePath = *query.getFilePath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (QFileInfo(filePath).absoluteDir().exists()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier *configurationId = query.getConfiguration(); | 
					
						
							|  |  |  |         const Configuration *selectedConfiguration = m_mainCore->m_settings.getConfiguration( | 
					
						
							|  |  |  |             *configurationId->getGroupName(), | 
					
						
							|  |  |  |             *configurationId->getName()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (selectedConfiguration) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QString base64Str = selectedConfiguration->serialize().toBase64(); | 
					
						
							|  |  |  |             QFileInfo fileInfo(filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (fileInfo.suffix() != "cfgx") { | 
					
						
							|  |  |  |                 filePath += ".cfgx"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             QFile file(filePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (file.open(QIODevice::ReadWrite | QIODevice::Text)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QTextStream outstream(&file); | 
					
						
							|  |  |  |                 outstream << base64Str; | 
					
						
							|  |  |  |                 file.close(); | 
					
						
							|  |  |  |                 response.init(); | 
					
						
							|  |  |  |                 *response.getGroupName() = selectedConfiguration->getGroup(); | 
					
						
							|  |  |  |                 *response.getName() = selectedConfiguration->getDescription(); | 
					
						
							|  |  |  |                 return 200; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 error.init(); | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Cannot open file %1 for writing").arg(filePath); | 
					
						
							|  |  |  |                 return 500; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no configuration [%1, %2]") | 
					
						
							|  |  |  |                 .arg(*configurationId->getGroupName()) | 
					
						
							|  |  |  |                 .arg(*configurationId->getName()); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("File %1 directory does not exist").arg(filePath); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationBlobPut( | 
					
						
							|  |  |  |         SWGSDRangel::SWGBase64Blob& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString *base64Str = query.getBlob(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (base64Str) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Configuration *newConfiguration = m_mainCore->m_settings.newConfiguration("TBD", "TBD"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (newConfiguration) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QByteArray blob = QByteArray::fromBase64(base64Str->toUtf8()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (newConfiguration->deserialize(blob)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.init(); | 
					
						
							|  |  |  |                 *response.getGroupName() = newConfiguration->getGroup(); | 
					
						
							|  |  |  |                 *response.getName() = newConfiguration->getDescription(); | 
					
						
							|  |  |  |                 return 202; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 m_mainCore->m_settings.deleteConfiguration(newConfiguration); | 
					
						
							|  |  |  |                 error.init(); | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Could not deserialize blob"); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("Cannot create new configuration"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("Blob not specified"); | 
					
						
							|  |  |  |         return 400; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceConfigurationBlobPost( | 
					
						
							|  |  |  |         SWGSDRangel::SWGConfigurationIdentifier& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGBase64Blob& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const Configuration *selectedConfiguration = m_mainCore->m_settings.getConfiguration( | 
					
						
							|  |  |  |         *query.getGroupName(), | 
					
						
							|  |  |  |         *query.getName()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedConfiguration) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QString base64Str = selectedConfiguration->serialize().toBase64(); | 
					
						
							|  |  |  |         response.init(); | 
					
						
							|  |  |  |         *response.getBlob() = base64Str; | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no configuration [%1, %2]") | 
					
						
							|  |  |  |             .arg(*query.getGroupName()) | 
					
						
							|  |  |  |             .arg(*query.getName()); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-04 05:58:06 +02:00
										 |  |  | int WebAPIAdapter::instanceFeaturePresetsGet( | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeaturePresets& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) error; | 
					
						
							|  |  |  |     int nbPresets = m_mainCore->m_settings.getFeatureSetPresetCount(); | 
					
						
							|  |  |  |     int nbGroups = 0; | 
					
						
							|  |  |  |     int nbPresetsThisGroup = 0; | 
					
						
							|  |  |  |     QString groupName; | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     QList<SWGSDRangel::SWGFeaturePresetGroup*> *groups = response.getGroups(); | 
					
						
							|  |  |  |     QList<SWGSDRangel::SWGFeaturePresetItem*> *swgPresets = 0; | 
					
						
							|  |  |  |     int i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Presets are sorted by group first
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (; i < nbPresets; i++) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const FeatureSetPreset *preset = m_mainCore->m_settings.getFeatureSetPreset(i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((i == 0) || (groupName != preset->getGroup())) // new group
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); } | 
					
						
							|  |  |  |             groups->append(new SWGSDRangel::SWGFeaturePresetGroup); | 
					
						
							|  |  |  |             groups->back()->init(); | 
					
						
							|  |  |  |             groupName = preset->getGroup(); | 
					
						
							|  |  |  |             *groups->back()->getGroupName() = groupName; | 
					
						
							|  |  |  |             swgPresets = groups->back()->getPresets(); | 
					
						
							|  |  |  |             nbGroups++; | 
					
						
							|  |  |  |             nbPresetsThisGroup = 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         swgPresets->append(new SWGSDRangel::SWGFeaturePresetItem); | 
					
						
							|  |  |  |         swgPresets->back()->init(); | 
					
						
							|  |  |  |         *swgPresets->back()->getDescription() = preset->getDescription(); | 
					
						
							|  |  |  |         nbPresetsThisGroup++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); } | 
					
						
							|  |  |  |     response.setNbGroups(nbGroups); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceFeaturePresetDelete( | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeaturePresetIdentifier& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const FeatureSetPreset *selectedPreset = m_mainCore->m_settings.getFeatureSetPreset(*response.getGroupName(), | 
					
						
							|  |  |  |             *response.getDescription()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedPreset == nullptr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature preset [%1, %2]") | 
					
						
							|  |  |  |             .arg(*response.getGroupName()) | 
					
						
							|  |  |  |             .arg(*response.getDescription()); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     *response.getGroupName() = selectedPreset->getGroup(); | 
					
						
							|  |  |  |     *response.getDescription() = selectedPreset->getDescription(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MainCore::MsgDeleteFeatureSetPreset *msg = MainCore::MsgDeleteFeatureSetPreset::create(const_cast<FeatureSetPreset*>(selectedPreset)); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-11-25 19:42:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |     return 202; | 
					
						
							| 
									
										
										
										
											2017-11-25 19:42:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceDeviceSetsGet( | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceSetList& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  |     getDeviceSetList(&response); | 
					
						
							|  |  |  |     return 200; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceDeviceSetPost( | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |         int direction, | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 18:36:27 +01:00
										 |  |  |     (void) error; | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     MainCore::MsgAddDeviceSet *msg = MainCore::MsgAddDeviceSet::create(direction); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-21 22:35:25 +01:00
										 |  |  |     *response.getMessage() = QString("Message to add a new device set (MsgAddDeviceSet) was submitted successfully"); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |     return 202; | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::instanceDeviceSetDelete( | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-05-16 20:51:15 +02:00
										 |  |  |     if (m_mainCore->m_deviceSets.size() > 0) | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         MainCore::MsgRemoveLastDeviceSet *msg = MainCore::MsgRemoveLastDeviceSet::create(); | 
					
						
							|  |  |  |         m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |         response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-21 22:35:25 +01:00
										 |  |  |         *response.getMessage() = QString("Message to remove last device set (MsgRemoveLastDeviceSet) was submitted successfully"); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |         return 202; | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  |         *error.getMessage() = "No more device sets to be removed"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-09 21:31:14 +02:00
										 |  |  | int WebAPIAdapter::instanceWorkspacePost( | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) error; | 
					
						
							|  |  |  |     MainCore::MsgAddWorkspace *msg = MainCore::MsgAddWorkspace::create(); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     *response.getMessage() = QString("Message to add a new workspace (MsgAddWorkspace) was submitted successfully"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::instanceWorkspaceDelete( | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) error; | 
					
						
							|  |  |  |     MainCore::MsgDeleteEmptyWorkspaces *msg = MainCore::MsgDeleteEmptyWorkspaces::create(); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.init(); | 
					
						
							|  |  |  |     *response.getMessage() = QString("Message to delete empty workspaces (MsgDeleteEmptyWorkspaces) was submitted successfully"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetGet( | 
					
						
							| 
									
										
										
										
											2017-11-26 10:37:39 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceSet& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-26 10:37:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-11-26 10:37:39 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         const DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-11-26 10:37:39 +01:00
										 |  |  |         getDeviceSet(&response, deviceSet, deviceSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-06 03:46:53 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-01-06 03:46:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 01:22:48 +01:00
										 |  |  | int WebAPIAdapter::devicesetSpectrumSettingsGet( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGGLSpectrum& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							|  |  |  |         return deviceSet->webapiSpectrumSettingsGet(response, *error.getMessage()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::devicesetSpectrumSettingsPutPatch( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         bool force, //!< true to force settings = put else patch
 | 
					
						
							|  |  |  |         const QStringList& spectrumSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGGLSpectrum& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							|  |  |  |         return deviceSet->webapiSpectrumSettingsPutPatch(force, spectrumSettingsKeys, response, *error.getMessage()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::devicesetSpectrumServerGet( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSpectrumServer& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							|  |  |  |         deviceSet->webapiSpectrumServerGet(response, *error.getMessage()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::devicesetSpectrumServerPost( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							|  |  |  |         deviceSet->webapiSpectrumServerPost(response, *error.getMessage()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::devicesetSpectrumServerDelete( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							|  |  |  |         deviceSet->webapiSpectrumServerDelete(response, *error.getMessage()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  | int WebAPIAdapter::devicesetSpectrumWorkspaceGet( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGWorkspaceInfo& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							|  |  |  |         response.setIndex(deviceSet->m_spectrumVis->getWorkspaceIndex()); | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::devicesetSpectrumWorkspacePut( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGWorkspaceInfo& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int workspaceIndex = query.getIndex(); | 
					
						
							|  |  |  |         MainCore::MsgMoveMainSpectrumUIToWorkspace *msg = MainCore::MsgMoveMainSpectrumUIToWorkspace::create(deviceSetIndex, workspaceIndex); | 
					
						
							|  |  |  |         m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  |         response.init(); | 
					
						
							|  |  |  |         *response.getMessage() = QString("Message to move a main spectrum to workspace (MsgMoveMainSpectrumUIToWorkspace) was submitted successfully"); | 
					
						
							|  |  |  |         return 202; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDevicePut( | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							| 
									
										
										
										
											2018-02-14 13:40:34 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceListItem& query, | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceListItem& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if ((query.getDirection() != 1) && (deviceSet->m_deviceSinkEngine)) | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-02-14 13:40:34 +01:00
										 |  |  |             error.init(); | 
					
						
							| 
									
										
										
										
											2019-05-07 15:25:20 +02:00
										 |  |  |             *error.getMessage() = QString("Device type and device set type (Tx) mismatch"); | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if ((query.getDirection() != 0) && (deviceSet->m_deviceSourceEngine)) | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-02-14 13:40:34 +01:00
										 |  |  |             error.init(); | 
					
						
							| 
									
										
										
										
											2019-05-07 15:25:20 +02:00
										 |  |  |             *error.getMessage() = QString("Device type and device set type (Rx) mismatch"); | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         if ((query.getDirection() != 2) && (deviceSet->m_deviceMIMOEngine)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("Device type and device set type (MIMO) mismatch"); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         int nbSamplingDevices; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (query.getDirection() == 0) { | 
					
						
							|  |  |  |             nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices(); | 
					
						
							|  |  |  |         } else if (query.getDirection() == 1) { | 
					
						
							|  |  |  |             nbSamplingDevices = DeviceEnumerator::instance()->getNbTxSamplingDevices(); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         } else if (query.getDirection() == 2) { | 
					
						
							|  |  |  |             nbSamplingDevices = DeviceEnumerator::instance()->getNbMIMOSamplingDevices(); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             nbSamplingDevices = 0; // TODO: not implemented yet
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i < nbSamplingDevices; i++) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             const PluginInterface::SamplingDevice *samplingDevice; | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-29 06:01:14 +01:00
										 |  |  |             if (query.getDirection() == 0) { | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |                 samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i); | 
					
						
							| 
									
										
										
										
											2019-12-29 06:01:14 +01:00
										 |  |  |             } else if (query.getDirection() == 1) { | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |                 samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(i); | 
					
						
							| 
									
										
										
										
											2019-12-29 06:01:14 +01:00
										 |  |  |             } else if (query.getDirection() == 2) { | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |                 samplingDevice = DeviceEnumerator::instance()->getMIMOSamplingDevice(i); | 
					
						
							| 
									
										
										
										
											2019-12-29 06:01:14 +01:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |                 continue; // device not supported
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice->displayedName)) { | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             if (query.getHwType() && (*query.getHwType() != samplingDevice->hardwareId)) { | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice->sequence)) { | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             if (query.getSerial() && (*query.getSerial() != samplingDevice->serial)) { | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             if ((query.getDeviceStreamIndex() >= 0) && (query.getDeviceStreamIndex() != samplingDevice->deviceItemIndex)) { | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |             MainCore::MsgSetDevice *msg = MainCore::MsgSetDevice::create(deviceSetIndex, i, query.getDirection()); | 
					
						
							|  |  |  |             m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             *response.getDisplayedName() = samplingDevice->displayedName; | 
					
						
							|  |  |  |             *response.getHwType() = samplingDevice->hardwareId; | 
					
						
							|  |  |  |             *response.getSerial() = samplingDevice->serial; | 
					
						
							|  |  |  |             response.setSequence(samplingDevice->sequence); | 
					
						
							| 
									
										
										
										
											2019-12-29 06:01:14 +01:00
										 |  |  |             response.setDirection(query.getDirection()); | 
					
						
							| 
									
										
										
										
											2019-05-09 01:12:40 +02:00
										 |  |  |             response.setDeviceNbStreams(samplingDevice->deviceNbItems); | 
					
						
							|  |  |  |             response.setDeviceStreamIndex(samplingDevice->deviceItemIndex); | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |             response.setDeviceSetIndex(deviceSetIndex); | 
					
						
							|  |  |  |             response.setIndex(i); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |             return 202; | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 13:40:34 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-11-27 08:14:07 +01:00
										 |  |  |         *error.getMessage() = QString("Device not found"); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-11-26 10:37:39 +01:00
										 |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceSettingsGet( | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-21 13:27:10 +01:00
										 |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |             response.setDirection(0); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); | 
					
						
							| 
									
										
										
										
											2017-12-06 19:23:42 +01:00
										 |  |  |             return source->webapiSettingsGet(response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |             response.setDirection(1); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink(); | 
					
						
							| 
									
										
										
										
											2017-12-06 19:23:42 +01:00
										 |  |  |             return sink->webapiSettingsGet(response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); | 
					
						
							|  |  |  |             response.setDirection(2); | 
					
						
							|  |  |  |             DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO(); | 
					
						
							|  |  |  |             return mimo->webapiSettingsGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-04 23:07:30 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-04 18:22:25 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceActionsPost( | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							| 
									
										
										
										
											2020-03-09 19:56:09 +01:00
										 |  |  |         const QStringList& deviceActionsKeys, | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceActions& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (query.getDirection() != 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Single Rx device found but other type of device requested"); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (deviceSet->m_deviceAPI->getHardwareId() != *query.getDeviceHwType()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Device mismatch. Found %1 input").arg(deviceSet->m_deviceAPI->getHardwareId()); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); | 
					
						
							| 
									
										
										
										
											2020-03-09 19:56:09 +01:00
										 |  |  |                 int res = source->webapiActionsPost(deviceActionsKeys, query, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if (res/100 == 2) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     response.init(); | 
					
						
							|  |  |  |                     *response.getMessage() = QString("Message to post action was submitted successfully"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return res; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (query.getDirection() != 1) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Single Tx device found but other type of device requested"); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (deviceSet->m_deviceAPI->getHardwareId() != *query.getDeviceHwType()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceAPI->getHardwareId()); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink(); | 
					
						
							| 
									
										
										
										
											2020-03-09 19:56:09 +01:00
										 |  |  |                 int res = sink->webapiActionsPost(deviceActionsKeys, query, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if (res/100 == 2) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     response.init(); | 
					
						
							|  |  |  |                     *response.getMessage() = QString("Message to post action was submitted successfully"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return res; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (query.getDirection() != 2) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("MIMO device found but other type of device requested"); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (deviceSet->m_deviceAPI->getHardwareId() != *query.getDeviceHwType()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceAPI->getHardwareId()); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO(); | 
					
						
							| 
									
										
										
										
											2020-03-09 19:56:09 +01:00
										 |  |  |                 int res = mimo->webapiActionsPost(deviceActionsKeys, query, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 if (res/100 == 2) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     response.init(); | 
					
						
							|  |  |  |                     *response.getMessage() = QString("Message to post action was submitted successfully"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return res; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceWorkspaceGet( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGWorkspaceInfo& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         response.setIndex(m_mainCore->m_deviceSets[deviceSetIndex]->m_deviceAPI->getWorkspaceIndex()); | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::devicesetDeviceWorkspacePut( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGWorkspaceInfo& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int workspaceIndex = query.getIndex(); | 
					
						
							|  |  |  |         MainCore::MsgMoveDeviceUIToWorkspace *msg = MainCore::MsgMoveDeviceUIToWorkspace::create(deviceSetIndex, workspaceIndex); | 
					
						
							|  |  |  |         m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  |         response.init(); | 
					
						
							|  |  |  |         *response.getMessage() = QString("Message to move a device UI to workspace (MsgMoveDeviceUIToWorkspace) was submitted successfully"); | 
					
						
							|  |  |  |         return 202; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceSettingsPutPatch( | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         bool force, | 
					
						
							| 
									
										
										
										
											2017-12-27 01:46:33 +01:00
										 |  |  |         const QStringList& deviceSettingsKeys, | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |         SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-21 13:27:10 +01:00
										 |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |             if (response.getDirection() != 0) | 
					
						
							| 
									
										
										
										
											2017-12-14 23:12:52 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |                 *error.getMessage() = QString("Single Rx device found but other type of device requested"); | 
					
						
							| 
									
										
										
										
											2017-12-14 23:12:52 +01:00
										 |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             if (deviceSet->m_deviceAPI->getHardwareId() != *response.getDeviceHwType()) | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 *error.getMessage() = QString("Device mismatch. Found %1 input").arg(deviceSet->m_deviceAPI->getHardwareId()); | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); | 
					
						
							| 
									
										
										
										
											2017-12-27 01:46:33 +01:00
										 |  |  |                 return source->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-07 15:25:20 +02:00
										 |  |  |             if (response.getDirection() != 1) | 
					
						
							| 
									
										
										
										
											2017-12-14 23:12:52 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |                 *error.getMessage() = QString("Single Tx device found but other type of device requested"); | 
					
						
							| 
									
										
										
										
											2017-12-14 23:12:52 +01:00
										 |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             else if (deviceSet->m_deviceAPI->getHardwareId() != *response.getDeviceHwType()) | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 *error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceAPI->getHardwareId()); | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |                 DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink(); | 
					
						
							| 
									
										
										
										
											2017-12-27 01:46:33 +01:00
										 |  |  |                 return sink->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (response.getDirection() != 2) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("MIMO device found but other type of device requested"); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (deviceSet->m_deviceAPI->getHardwareId() != *response.getDeviceHwType()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceAPI->getHardwareId()); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO(); | 
					
						
							|  |  |  |                 return mimo->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-07 13:55:42 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							| 
									
										
										
										
											2017-11-26 10:37:39 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceRunGet( | 
					
						
							| 
									
										
										
										
											2017-12-09 10:49:20 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-09 10:49:20 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-09 10:49:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceSourceEngine) // Rx
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-09 10:49:20 +01:00
										 |  |  |             return source->webapiRunGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (deviceSet->m_deviceSinkEngine) // Tx
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink(); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-09 10:49:20 +01:00
										 |  |  |             return sink->webapiRunGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceSubsystemRunGet( | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         int subsystemIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO(); | 
					
						
							|  |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |             return mimo->webapiRunGet(subsystemIndex, response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-09 10:49:20 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceRunPost( | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceSourceEngine) // Rx
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |             return source->webapiRun(true, response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (deviceSet->m_deviceSinkEngine) // Tx
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink(); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |             return sink->webapiRun(true, response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceSubsystemRunPost( | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         int subsystemIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO(); | 
					
						
							|  |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |             return mimo->webapiRun(true, subsystemIndex, response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceRunDelete( | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceSourceEngine) // Rx
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |             return source->webapiRun(false, response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |         else if (deviceSet->m_deviceSinkEngine) // Tx
 | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink(); | 
					
						
							| 
									
										
										
										
											2018-02-14 01:42:35 +01:00
										 |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |             return sink->webapiRun(false, response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceSubsystemRunDelete( | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         int subsystemIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO(); | 
					
						
							|  |  |  |             response.init(); | 
					
						
							| 
									
										
										
										
											2019-12-24 19:08:11 +01:00
										 |  |  |             return mimo->webapiRun(false, subsystemIndex, response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetDeviceReportGet( | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGDeviceReport& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |             response.setDirection(0); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  |             return source->webapiReportGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |             response.setDirection(1); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |             DeviceSampleSink *sink = deviceSet->m_deviceAPI->getSampleSink(); | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  |             return sink->webapiReportGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             response.setDeviceHwType(new QString(deviceSet->m_deviceAPI->getHardwareId())); | 
					
						
							|  |  |  |             response.setDirection(2); | 
					
						
							|  |  |  |             DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getSampleMIMO(); | 
					
						
							|  |  |  |             return mimo->webapiReportGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-05-26 01:43:28 +02:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetChannelsReportGet( | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelsDetail& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         const DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |         getChannelsDetail(&response, deviceSet); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetChannelPost( | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |             int deviceSetIndex, | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  |             SWGSDRangel::SWGChannelSettings& query, | 
					
						
							|  |  |  | 			SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if (query.getDirection() == 0) // Single Rx
 | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2020-01-02 20:10:01 +01:00
										 |  |  |             if (!deviceSet->m_deviceSourceEngine && !deviceSet->m_deviceMIMOEngine) | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |                 error.init(); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |                 *error.getMessage() = QString("Device set at %1 is not a receive capable device set").arg(deviceSetIndex); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |             PluginAPI::ChannelRegistrations *channelRegistrations = m_mainCore->m_pluginManager->getRxChannelRegistrations(); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |             int nbRegistrations = channelRegistrations->size(); | 
					
						
							|  |  |  |             int index = 0; | 
					
						
							|  |  |  |             for (; index < nbRegistrations; index++) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  |                 if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) { | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (index < nbRegistrations) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-01-13 02:45:25 +01:00
										 |  |  |                 MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, 0); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |                 m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |                 response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-21 22:35:25 +01:00
										 |  |  |                 *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully"); | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |                 return 202; | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |                 error.init(); | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  |                 *error.getMessage() = QString("There is no receive channel with id %1").arg(*query.getChannelType()); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         else if (query.getDirection() == 1) // single Tx
 | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2020-01-02 20:10:01 +01:00
										 |  |  |             if (!deviceSet->m_deviceSinkEngine && !deviceSet->m_deviceMIMOEngine) | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |                 error.init(); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |                 *error.getMessage() = QString("Device set at %1 is not a transmit capable device set").arg(deviceSetIndex); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |             PluginAPI::ChannelRegistrations *channelRegistrations = m_mainCore->m_pluginManager->getTxChannelRegistrations(); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |             int nbRegistrations = channelRegistrations->size(); | 
					
						
							|  |  |  |             int index = 0; | 
					
						
							|  |  |  |             for (; index < nbRegistrations; index++) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  |                 if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) { | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (index < nbRegistrations) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-01-13 02:45:25 +01:00
										 |  |  |                 MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, 1); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |                 m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |                 response.init(); | 
					
						
							| 
									
										
										
										
											2017-12-21 22:35:25 +01:00
										 |  |  |                 *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully"); | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-21 18:10:43 +01:00
										 |  |  |                 return 202; | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |                 error.init(); | 
					
						
							| 
									
										
										
										
											2017-12-19 17:55:05 +01:00
										 |  |  |                 *error.getMessage() = QString("There is no transmit channel with id %1").arg(*query.getChannelType()); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |         else if (query.getDirection() == 2) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (!deviceSet->m_deviceMIMOEngine) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 error.init(); | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Device set at %1 is not a MIMO capable device set").arg(deviceSetIndex); | 
					
						
							|  |  |  |                 return 400; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |             PluginAPI::ChannelRegistrations *channelRegistrations = m_mainCore->m_pluginManager->getMIMOChannelRegistrations(); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  |             int nbRegistrations = channelRegistrations->size(); | 
					
						
							|  |  |  |             int index = 0; | 
					
						
							|  |  |  |             for (; index < nbRegistrations; index++) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) { | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (index < nbRegistrations) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-01-13 02:45:25 +01:00
										 |  |  |             	MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, 2); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |                 m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2019-12-23 20:06:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 response.init(); | 
					
						
							|  |  |  |                 *response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return 202; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 error.init(); | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no MIMO channel with id %1").arg(*query.getChannelType()); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("This type of device is not implemented yet"); | 
					
						
							|  |  |  |             return 400; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-12-11 01:18:10 +01:00
										 |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetChannelDelete( | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  |             int deviceSetIndex, | 
					
						
							|  |  |  |             int channelIndex, | 
					
						
							|  |  |  |             SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 00:44:56 +02:00
										 |  |  |         if (channelIndex < deviceSet->getNumberOfChannels()) | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |             MainCore::MsgDeleteChannel *msg = MainCore::MsgDeleteChannel::create(deviceSetIndex, channelIndex); | 
					
						
							|  |  |  |             m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 00:44:56 +02:00
										 |  |  |             response.init(); | 
					
						
							|  |  |  |             *response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully"); | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 00:44:56 +02:00
										 |  |  |             return 202; | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |             error.init(); | 
					
						
							| 
									
										
										
										
											2020-09-10 22:42:36 +02:00
										 |  |  |             *error.getMessage() = QString("There is no channel at index %1. %2 channel(s) left") | 
					
						
							| 
									
										
										
										
											2019-09-08 00:44:56 +02:00
										 |  |  |                     .arg(channelIndex) | 
					
						
							| 
									
										
										
										
											2020-09-10 22:42:36 +02:00
										 |  |  |                     .arg(deviceSet->getNumberOfChannels()); | 
					
						
							| 
									
										
										
										
											2019-09-08 00:44:56 +02:00
										 |  |  |             return 400; | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2017-12-23 23:41:37 +01:00
										 |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetChannelSettingsGet( | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  |             int deviceSetIndex, | 
					
						
							|  |  |  |             int channelIndex, | 
					
						
							|  |  |  |             SWGSDRangel::SWGChannelSettings& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-21 13:50:05 +01:00
										 |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.setChannelType(new QString()); | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(*response.getChannelType()); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |                 response.setDirection(0); | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  |                 return channelAPI->webapiSettingsGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex); | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.setChannelType(new QString()); | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(*response.getChannelType()); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |                 response.setDirection(1); | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  |                 return channelAPI->webapiSettingsGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-23 23:00:11 +01:00
										 |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             int nbSinkChannels = deviceSet->m_deviceAPI->getNbSinkChannels(); | 
					
						
							|  |  |  |             int nbSourceChannels = deviceSet->m_deviceAPI->getNbSourceChannels(); | 
					
						
							|  |  |  |             int nbMIMOChannels = deviceSet->m_deviceAPI->getNbMIMOChannels(); | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelIndex < nbSinkChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							|  |  |  |                 response.setDirection(0); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (channelIndex < nbSinkChannels + nbSourceChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex - nbSinkChannels); | 
					
						
							|  |  |  |                 response.setDirection(1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (channelIndex < nbSinkChannels + nbSourceChannels + nbMIMOChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getMIMOChannelAPIAt(channelIndex - nbSinkChannels - nbSourceChannels); | 
					
						
							|  |  |  |                 response.setDirection(2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Ther is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.setChannelType(new QString()); | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(*response.getChannelType()); | 
					
						
							|  |  |  |                 return channelAPI->webapiSettingsGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("Ther is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetChannelReportGet( | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  |             int deviceSetIndex, | 
					
						
							|  |  |  |             int channelIndex, | 
					
						
							|  |  |  |             SWGSDRangel::SWGChannelReport& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.setChannelType(new QString()); | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(*response.getChannelType()); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |                 response.setDirection(0); | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  |                 return channelAPI->webapiReportGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex); | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.setChannelType(new QString()); | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(*response.getChannelType()); | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |                 response.setDirection(1); | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  |                 return channelAPI->webapiReportGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-23 23:00:11 +01:00
										 |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             int nbSinkChannels = deviceSet->m_deviceAPI->getNbSinkChannels(); | 
					
						
							|  |  |  |             int nbSourceChannels = deviceSet->m_deviceAPI->getNbSourceChannels(); | 
					
						
							|  |  |  |             int nbMIMOChannels = deviceSet->m_deviceAPI->getNbMIMOChannels(); | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelIndex < nbSinkChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							|  |  |  |                 response.setDirection(0); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (channelIndex < nbSinkChannels + nbSourceChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex - nbSinkChannels); | 
					
						
							|  |  |  |                 response.setDirection(1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (channelIndex < nbSinkChannels + nbSourceChannels + nbMIMOChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getMIMOChannelAPIAt(channelIndex - nbSinkChannels - nbSourceChannels); | 
					
						
							|  |  |  |                 response.setDirection(2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 response.setChannelType(new QString()); | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(*response.getChannelType()); | 
					
						
							|  |  |  |                 return channelAPI->webapiReportGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-18 20:17:11 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							| 
									
										
										
										
											2017-12-10 20:27:08 +01:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetChannelActionsPost( | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         int channelIndex, | 
					
						
							| 
									
										
										
										
											2020-03-09 19:56:09 +01:00
										 |  |  |         const QStringList& channelActionsKeys, | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  |         SWGSDRangel::SWGChannelActions& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QString channelType; | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(channelType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (channelType == *query.getChannelType()) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2020-03-09 19:56:09 +01:00
										 |  |  |                     int res = channelAPI->webapiActionsPost(channelActionsKeys, query, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     if (res/100 == 2) | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         response.init(); | 
					
						
							|  |  |  |                         *response.getMessage() = QString("Message to post action was submitted successfully"); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     return res; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.") | 
					
						
							|  |  |  |                             .arg(*query.getChannelType()) | 
					
						
							|  |  |  |                             .arg(channelIndex) | 
					
						
							|  |  |  |                             .arg(channelType); | 
					
						
							|  |  |  |                     return 404; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QString channelType; | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(channelType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (channelType == *query.getChannelType()) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2020-03-09 19:56:09 +01:00
										 |  |  |                     int res = channelAPI->webapiActionsPost(channelActionsKeys, query, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     if (res/100 == 2) | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         response.init(); | 
					
						
							|  |  |  |                         *response.getMessage() = QString("Message to post action was submitted successfully"); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     return res; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.") | 
					
						
							|  |  |  |                             .arg(*query.getChannelType()) | 
					
						
							|  |  |  |                             .arg(channelIndex) | 
					
						
							|  |  |  |                             .arg(channelType); | 
					
						
							|  |  |  |                     return 404; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             int nbSinkChannels = deviceSet->m_deviceAPI->getNbSinkChannels(); | 
					
						
							|  |  |  |             int nbSourceChannels = deviceSet->m_deviceAPI->getNbSourceChannels(); | 
					
						
							|  |  |  |             int nbMIMOChannels = deviceSet->m_deviceAPI->getNbMIMOChannels(); | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ((query.getDirection() == 0) && (channelIndex < nbSinkChannels)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if ((query.getDirection() == 1) && (channelIndex < nbSinkChannels + nbSourceChannels)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex - nbSinkChannels); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if ((query.getDirection() == 2) && (channelIndex < nbSinkChannels + nbSourceChannels + nbMIMOChannels)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getMIMOChannelAPIAt(channelIndex - nbSinkChannels - nbSourceChannels); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("here is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QString channelType; | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(channelType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (channelType == *query.getChannelType()) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2020-03-09 19:56:09 +01:00
										 |  |  |                     int res = channelAPI->webapiActionsPost(channelActionsKeys, query, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2020-03-09 04:01:23 +01:00
										 |  |  |                     if (res/100 == 2) | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         response.init(); | 
					
						
							|  |  |  |                         *response.getMessage() = QString("Message to post action was submitted successfully"); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     return res; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.") | 
					
						
							|  |  |  |                             .arg(*query.getChannelType()) | 
					
						
							|  |  |  |                             .arg(channelIndex) | 
					
						
							|  |  |  |                             .arg(channelType); | 
					
						
							|  |  |  |                     return 404; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  | int WebAPIAdapter::devicesetChannelWorkspaceGet( | 
					
						
							|  |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         int channelIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGWorkspaceInfo& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == nullptr) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return channelAPI->webapiWorkspaceGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return channelAPI->webapiWorkspaceGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             int nbSinkChannels = deviceSet->m_deviceAPI->getNbSinkChannels(); | 
					
						
							|  |  |  |             int nbSourceChannels = deviceSet->m_deviceAPI->getNbSourceChannels(); | 
					
						
							|  |  |  |             int nbMIMOChannels = deviceSet->m_deviceAPI->getNbMIMOChannels(); | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelIndex < nbSinkChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (channelIndex < nbSinkChannels + nbSourceChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex - nbSinkChannels); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (channelIndex < nbSinkChannels + nbSourceChannels + nbMIMOChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getMIMOChannelAPIAt(channelIndex - nbSinkChannels - nbSourceChannels); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return channelAPI->webapiWorkspaceGet(response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::devicesetChannelWorkspacePut( | 
					
						
							|  |  |  |             int deviceSetIndex, | 
					
						
							|  |  |  |             int channelIndex, | 
					
						
							|  |  |  |             SWGSDRangel::SWGWorkspaceInfo& query, | 
					
						
							|  |  |  |             SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((channelIndex >= 0) && (channelIndex < deviceSet->getNumberOfChannels())) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             int workspaceIndex = query.getIndex(); | 
					
						
							|  |  |  |             MainCore::MsgMoveChannelUIToWorkspace *msg = MainCore::MsgMoveChannelUIToWorkspace::create(deviceSetIndex, channelIndex, workspaceIndex); | 
					
						
							|  |  |  |             m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  |             response.init(); | 
					
						
							|  |  |  |             *response.getMessage() = QString("Message to move a channel UI to workspace (MsgMoveChannelUIToWorkspace) was submitted successfully"); | 
					
						
							|  |  |  |             return 202; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no channel with index %1 in device set %2").arg(channelIndex).arg(deviceSetIndex); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::devicesetChannelSettingsPutPatch( | 
					
						
							| 
									
										
										
										
											2017-12-24 03:27:07 +01:00
										 |  |  |         int deviceSetIndex, | 
					
						
							|  |  |  |         int channelIndex, | 
					
						
							|  |  |  |         bool force, | 
					
						
							|  |  |  |         const QStringList& channelSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-21 13:50:05 +01:00
										 |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore->m_deviceSets.size())) | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         DeviceSet *deviceSet = m_mainCore->m_deviceSets[deviceSetIndex]; | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         if (deviceSet->m_deviceSourceEngine) // Single Rx
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QString channelType; | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(channelType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (channelType == *response.getChannelType()) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2017-12-24 03:27:07 +01:00
										 |  |  |                     return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.") | 
					
						
							|  |  |  |                             .arg(*response.getChannelType()) | 
					
						
							|  |  |  |                             .arg(channelIndex) | 
					
						
							|  |  |  |                             .arg(channelType); | 
					
						
							|  |  |  |                     return 404; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         else if (deviceSet->m_deviceSinkEngine) // Single Tx
 | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  |             ChannelAPI *channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex); | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI == 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QString channelType; | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(channelType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (channelType == *response.getChannelType()) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2017-12-24 03:27:07 +01:00
										 |  |  |                     return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage()); | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.") | 
					
						
							|  |  |  |                             .arg(*response.getChannelType()) | 
					
						
							|  |  |  |                             .arg(channelIndex) | 
					
						
							|  |  |  |                             .arg(channelType); | 
					
						
							|  |  |  |                     return 404; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-12-23 23:00:11 +01:00
										 |  |  |         else if (deviceSet->m_deviceMIMOEngine) // MIMO
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             int nbSinkChannels = deviceSet->m_deviceAPI->getNbSinkChannels(); | 
					
						
							|  |  |  |             int nbSourceChannels = deviceSet->m_deviceAPI->getNbSourceChannels(); | 
					
						
							|  |  |  |             int nbMIMOChannels = deviceSet->m_deviceAPI->getNbMIMOChannels(); | 
					
						
							|  |  |  |             ChannelAPI *channelAPI = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelIndex < nbSinkChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); | 
					
						
							|  |  |  |                 response.setDirection(0); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (channelIndex < nbSinkChannels + nbSourceChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getChanelSourceAPIAt(channelIndex - nbSinkChannels); | 
					
						
							|  |  |  |                 response.setDirection(1); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (channelIndex < nbSinkChannels + nbSourceChannels + nbMIMOChannels) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 channelAPI = deviceSet->m_deviceAPI->getMIMOChannelAPIAt(channelIndex - nbSinkChannels - nbSourceChannels); | 
					
						
							|  |  |  |                 response.setDirection(2); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("here is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channelAPI) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 QString channelType; | 
					
						
							|  |  |  |                 channelAPI->getIdentifier(channelType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (channelType == *response.getChannelType()) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage()); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     *error.getMessage() = QString("There is no channel type %1 at index %2. Found %3.") | 
					
						
							|  |  |  |                             .arg(*response.getChannelType()) | 
					
						
							|  |  |  |                             .arg(channelIndex) | 
					
						
							|  |  |  |                             .arg(channelType); | 
					
						
							|  |  |  |                     return 404; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no channel with index %1").arg(channelIndex); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-11 18:18:47 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("DeviceSet error"); | 
					
						
							|  |  |  |             return 500; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeaturePost( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |             int featureSetIndex, | 
					
						
							|  |  |  |             SWGSDRangel::SWGFeatureSettings& query, | 
					
						
							|  |  |  | 			SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         PluginAPI::FeatureRegistrations *featureRegistrations = m_mainCore->m_pluginManager->getFeatureRegistrations(); | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         int nbRegistrations = featureRegistrations->size(); | 
					
						
							|  |  |  |         int index = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (; index < nbRegistrations; index++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (featureRegistrations->at(index).m_featureId == *query.getFeatureType()) { | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (index < nbRegistrations) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |             MainCore::MsgAddFeature *msg = MainCore::MsgAddFeature::create(featureSetIndex, index); | 
					
						
							|  |  |  |             m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             response.init(); | 
					
						
							|  |  |  |             *response.getMessage() = QString("Message to add a feature (MsgAddFeature) was submitted successfully"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return 202; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature with id %1").arg(*query.getFeatureType()); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureDelete( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |             int featureSetIndex, | 
					
						
							|  |  |  |             int featureIndex, | 
					
						
							|  |  |  |             SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (featureIndex < featureSet->getNumberOfFeatures()) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |             MainCore::MsgDeleteFeature *msg = MainCore::MsgDeleteFeature::create(featureSetIndex, featureIndex); | 
					
						
							|  |  |  |             m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             response.init(); | 
					
						
							|  |  |  |             *response.getMessage() = QString("Message to delete a feature (MsgDeleteFeature) was submitted successfully"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return 202; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature at index %1. %2 feature(s) left") | 
					
						
							|  |  |  |                     .arg(featureIndex) | 
					
						
							|  |  |  |                     .arg(featureSet->getNumberOfFeatures()); | 
					
						
							|  |  |  |             return 400; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							| 
									
										
										
										
											2021-11-26 08:41:42 +01:00
										 |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureSetIndex); | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureRunGet( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     int featureSetIndex, | 
					
						
							|  |  |  |     int featureIndex, | 
					
						
							|  |  |  |     SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |     SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (featureIndex < featureSet->getNumberOfFeatures()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             response.init(); | 
					
						
							|  |  |  |             const Feature *feature = featureSet->getFeatureAt(featureIndex); | 
					
						
							|  |  |  |             return feature->webapiRunGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature at index %1. %2 feature(s) left") | 
					
						
							|  |  |  |                     .arg(featureIndex) | 
					
						
							|  |  |  |                     .arg(featureSet->getNumberOfFeatures()); | 
					
						
							|  |  |  |             return 400; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureRunPost( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     int featureSetIndex, | 
					
						
							|  |  |  |     int featureIndex, | 
					
						
							|  |  |  |     SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |     SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (featureIndex < featureSet->getNumberOfFeatures()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             response.init(); | 
					
						
							|  |  |  |             Feature *feature = featureSet->getFeatureAt(featureIndex); | 
					
						
							|  |  |  |             return feature->webapiRun(true, response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature at index %1. %2 feature(s) left") | 
					
						
							|  |  |  |                     .arg(featureIndex) | 
					
						
							|  |  |  |                     .arg(featureSet->getNumberOfFeatures()); | 
					
						
							|  |  |  |             return 400; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureRunDelete( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     int featureSetIndex, | 
					
						
							|  |  |  |     int featureIndex, | 
					
						
							|  |  |  |     SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |     SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (featureIndex < featureSet->getNumberOfFeatures()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             response.init(); | 
					
						
							|  |  |  |             Feature *feature = featureSet->getFeatureAt(featureIndex); | 
					
						
							|  |  |  |             return feature->webapiRun(false, response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             error.init(); | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature at index %1. %2 feature(s) left") | 
					
						
							|  |  |  |                     .arg(featureIndex) | 
					
						
							|  |  |  |                     .arg(featureSet->getNumberOfFeatures()); | 
					
						
							|  |  |  |             return 400; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 22:12:26 +02:00
										 |  |  | int WebAPIAdapter::featuresetPresetPatch( | 
					
						
							|  |  |  |         int featureSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeaturePresetIdentifier& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int nbFeatureSets = m_mainCore->m_featureSets.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (featureSetIndex >= nbFeatureSets) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set at index %1. Number of device sets is %2").arg(featureSetIndex).arg(nbFeatureSets); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const FeatureSetPreset *selectedPreset = m_mainCore->m_settings.getFeatureSetPreset( | 
					
						
							|  |  |  |             *query.getGroupName(), | 
					
						
							|  |  |  |             *query.getDescription()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedPreset == 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no preset [%1, %2]") | 
					
						
							|  |  |  |                 .arg(*query.getGroupName()) | 
					
						
							|  |  |  |                 .arg(*query.getDescription()); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MainCore::MsgLoadFeatureSetPreset *msg = MainCore::MsgLoadFeatureSetPreset::create(selectedPreset, featureSetIndex); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::featuresetPresetPut( | 
					
						
							|  |  |  |         int featureSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeaturePresetIdentifier& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int nbFeatureSets = m_mainCore->m_featureSets.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (featureSetIndex >= nbFeatureSets) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set at index %1. Number of feature sets is %2").arg(featureSetIndex).arg(nbFeatureSets); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const FeatureSetPreset *selectedPreset = m_mainCore->m_settings.getFeatureSetPreset( | 
					
						
							|  |  |  |             *query.getGroupName(), | 
					
						
							|  |  |  |             *query.getDescription()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedPreset == 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no preset [%1, %2]") | 
					
						
							|  |  |  |                 .arg(*query.getGroupName()) | 
					
						
							|  |  |  |                 .arg(*query.getDescription()); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MainCore::MsgSaveFeatureSetPreset *msg = MainCore::MsgSaveFeatureSetPreset::create(const_cast<FeatureSetPreset*>(selectedPreset), featureSetIndex, false); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::featuresetPresetPost( | 
					
						
							|  |  |  |         int featureSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeaturePresetIdentifier& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int nbFeatureSets = m_mainCore->m_featureSets.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (featureSetIndex >= nbFeatureSets) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set at index %1. Number of feature sets is %2").arg(featureSetIndex).arg(nbFeatureSets); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const FeatureSetPreset *selectedPreset = m_mainCore->m_settings.getFeatureSetPreset( | 
					
						
							|  |  |  |             *query.getGroupName(), | 
					
						
							|  |  |  |             *query.getDescription()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (selectedPreset == 0) // save on a new preset
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         selectedPreset = m_mainCore->m_settings.newFeatureSetPreset(*query.getGroupName(), *query.getDescription()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("Preset already exists [%1, %2]") | 
					
						
							|  |  |  |                 .arg(*query.getGroupName()) | 
					
						
							|  |  |  |                 .arg(*query.getDescription()); | 
					
						
							|  |  |  |         return 409; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MainCore::MsgSaveFeatureSetPreset *msg = MainCore::MsgSaveFeatureSetPreset::create(const_cast<FeatureSetPreset*>(selectedPreset), featureSetIndex, true); | 
					
						
							|  |  |  |     m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 202; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureSettingsGet( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |             int featureSetIndex, | 
					
						
							|  |  |  |             int featureIndex, | 
					
						
							|  |  |  |             SWGSDRangel::SWGFeatureSettings& response, | 
					
						
							|  |  |  |             SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 00:22:42 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         Feature *feature = featureSet->getFeatureAt(featureIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (feature) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             response.setFeatureType(new QString()); | 
					
						
							|  |  |  |             feature->getIdentifier(*response.getFeatureType()); | 
					
						
							|  |  |  |             return feature->webapiSettingsGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature with index %1").arg(featureIndex); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureSettingsPutPatch( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         int featureSetIndex, | 
					
						
							|  |  |  |         int featureIndex, | 
					
						
							|  |  |  |         bool force, | 
					
						
							|  |  |  |         const QStringList& featureSettingsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeatureSettings& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         Feature *feature = featureSet->getFeatureAt(featureIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (feature) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QString featureType; | 
					
						
							|  |  |  |             feature->getIdentifier(featureType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (featureType == *response.getFeatureType()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return feature->webapiSettingsPutPatch(force, featureSettingsKeys, response, *error.getMessage()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no feature type %1 at index %2. Found %3.") | 
					
						
							|  |  |  |                         .arg(*response.getFeatureType()) | 
					
						
							|  |  |  |                         .arg(featureIndex) | 
					
						
							|  |  |  |                         .arg(featureType); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature with index %1").arg(featureIndex); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureSetIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureReportGet( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     int featureSetIndex, | 
					
						
							|  |  |  |     int featureIndex, | 
					
						
							|  |  |  |     SWGSDRangel::SWGFeatureReport& response, | 
					
						
							|  |  |  |     SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         Feature *feature = featureSet->getFeatureAt(featureIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (feature) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             response.setFeatureType(new QString()); | 
					
						
							|  |  |  |             feature->getIdentifier(*response.getFeatureType()); | 
					
						
							|  |  |  |             return feature->webapiReportGet(response, *error.getMessage()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature with index %1").arg(featureIndex); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureActionsPost( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         int featureSetIndex, | 
					
						
							|  |  |  |         int featureIndex, | 
					
						
							|  |  |  |         const QStringList& featureActionsKeys, | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeatureActions& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     error.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         Feature *feature = featureSet->getFeatureAt(featureIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (feature) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             QString featureType; | 
					
						
							|  |  |  |             feature->getIdentifier(featureType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (featureType == *query.getFeatureType()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 int res = feature->webapiActionsPost(featureActionsKeys, query, *error.getMessage()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (res/100 == 2) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     response.init(); | 
					
						
							|  |  |  |                     *response.getMessage() = QString("Message to post action was submitted successfully"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return res; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 *error.getMessage() = QString("There is no feature type %1 at index %2. Found %3.") | 
					
						
							|  |  |  |                         .arg(*query.getFeatureType()) | 
					
						
							|  |  |  |                         .arg(featureIndex) | 
					
						
							|  |  |  |                         .arg(featureType); | 
					
						
							|  |  |  |                 return 404; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             *error.getMessage() = QString("There is no feature with index %1").arg(featureIndex); | 
					
						
							|  |  |  |             return 404; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-13 22:24:48 +02:00
										 |  |  | int WebAPIAdapter::featuresetFeatureWorkspaceGet( | 
					
						
							|  |  |  |         int featureIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGWorkspaceInfo& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((featureIndex >= 0) && (featureIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         FeatureSet *featureSet = m_mainCore->m_featureSets[0]; | 
					
						
							|  |  |  |         Feature *feature = featureSet->getFeatureAt(featureIndex); | 
					
						
							|  |  |  |         response.setIndex(feature->getWorkspaceIndex()); | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature with index %1").arg(featureIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int WebAPIAdapter::featuresetFeatureWorkspacePut( | 
					
						
							|  |  |  |         int featureIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGWorkspaceInfo& query, | 
					
						
							|  |  |  |         SWGSDRangel::SWGSuccessResponse& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((featureIndex >= 0) && (featureIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int workspaceIndex = query.getIndex(); | 
					
						
							|  |  |  |         MainCore::MsgMoveFeatureUIToWorkspace *msg = MainCore::MsgMoveFeatureUIToWorkspace::create(featureIndex, workspaceIndex); | 
					
						
							|  |  |  |         m_mainCore->m_mainMessageQueue->push(msg); | 
					
						
							|  |  |  |         response.init(); | 
					
						
							|  |  |  |         *response.getMessage() = QString("Message to move a feature UI to workspace (MsgMoveFeatureUIToWorkspace) was submitted successfully"); | 
					
						
							|  |  |  |         return 202; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature with index %1").arg(featureIndex); | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | void WebAPIAdapter::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList) | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     deviceSetList->init(); | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     deviceSetList->setDevicesetcount((int) m_mainCore->m_deviceSets.size()); | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if (m_mainCore->m_deviceSets.size() > 0) { | 
					
						
							|  |  |  |         deviceSetList->setDevicesetfocus(m_mainCore->m_masterTabIndex); | 
					
						
							| 
									
										
										
										
											2018-01-06 09:50:09 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     std::vector<DeviceSet*>::const_iterator it = m_mainCore->m_deviceSets.begin(); | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     for (int i = 0; it != m_mainCore->m_deviceSets.end(); ++it, i++) | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |         QList<SWGSDRangel::SWGDeviceSet*> *deviceSets = deviceSetList->getDeviceSets(); | 
					
						
							|  |  |  |         deviceSets->append(new SWGSDRangel::SWGDeviceSet()); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         getDeviceSet(deviceSets->back(), *it, i); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  | void WebAPIAdapter::getDeviceSet(SWGSDRangel::SWGDeviceSet *swgDeviceSet, const DeviceSet* deviceSet, int deviceSetIndex) | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     swgDeviceSet->init(); | 
					
						
							|  |  |  |     SWGSDRangel::SWGSamplingDevice *samplingDevice = swgDeviceSet->getSamplingDevice(); | 
					
						
							| 
									
										
										
										
											2018-02-13 20:12:54 +01:00
										 |  |  |     samplingDevice->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     samplingDevice->setIndex(deviceSetIndex); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     if (deviceSet->m_deviceSinkEngine) // Single Tx data
 | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         samplingDevice->setDirection(1); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         *samplingDevice->getHwType() = deviceSet->m_deviceAPI->getHardwareId(); | 
					
						
							|  |  |  |         *samplingDevice->getSerial() = deviceSet->m_deviceAPI->getSamplingDeviceSerial(); | 
					
						
							|  |  |  |         samplingDevice->setSequence(deviceSet->m_deviceAPI->getSamplingDeviceSequence()); | 
					
						
							|  |  |  |         samplingDevice->setDeviceNbStreams(deviceSet->m_deviceAPI->getDeviceNbItems()); | 
					
						
							|  |  |  |         samplingDevice->setDeviceStreamIndex(deviceSet->m_deviceAPI->getDeviceItemIndex()); | 
					
						
							|  |  |  |         deviceSet->m_deviceAPI->getDeviceEngineStateStr(*samplingDevice->getState()); | 
					
						
							|  |  |  |         DeviceSampleSink *sampleSink = deviceSet->m_deviceSinkEngine->getSink(); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (sampleSink) { | 
					
						
							|  |  |  |             samplingDevice->setCenterFrequency(sampleSink->getCenterFrequency()); | 
					
						
							|  |  |  |             samplingDevice->setBandwidth(sampleSink->getSampleRate()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         swgDeviceSet->setChannelcount(deviceSet->m_deviceAPI->getNbSourceChannels()); | 
					
						
							|  |  |  |         QList<SWGSDRangel::SWGChannel*> *channels = swgDeviceSet->getChannels(); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         for (int i = 0; i <  swgDeviceSet->getChannelcount(); i++) | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSourceAPIAt(i); | 
					
						
							| 
									
										
										
										
											2017-12-29 05:22:26 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDirection(1); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     if (deviceSet->m_deviceSourceEngine) // Rx data
 | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-05-07 14:43:38 +02:00
										 |  |  |         samplingDevice->setDirection(0); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         *samplingDevice->getHwType() = deviceSet->m_deviceAPI->getHardwareId(); | 
					
						
							|  |  |  |         *samplingDevice->getSerial() = deviceSet->m_deviceAPI->getSamplingDeviceSerial(); | 
					
						
							|  |  |  |         samplingDevice->setSequence(deviceSet->m_deviceAPI->getSamplingDeviceSequence()); | 
					
						
							|  |  |  |         samplingDevice->setDeviceNbStreams(deviceSet->m_deviceAPI->getDeviceNbItems()); | 
					
						
							|  |  |  |         samplingDevice->setDeviceStreamIndex(deviceSet->m_deviceAPI->getDeviceItemIndex()); | 
					
						
							|  |  |  |         deviceSet->m_deviceAPI->getDeviceEngineStateStr(*samplingDevice->getState()); | 
					
						
							|  |  |  |         DeviceSampleSource *sampleSource = deviceSet->m_deviceSourceEngine->getSource(); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (sampleSource) { | 
					
						
							|  |  |  |             samplingDevice->setCenterFrequency(sampleSource->getCenterFrequency()); | 
					
						
							|  |  |  |             samplingDevice->setBandwidth(sampleSource->getSampleRate()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         swgDeviceSet->setChannelcount(deviceSet->m_deviceAPI->getNbSinkChannels()); | 
					
						
							|  |  |  |         QList<SWGSDRangel::SWGChannel*> *channels = swgDeviceSet->getChannels(); | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         for (int i = 0; i <  swgDeviceSet->getChannelcount(); i++) | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-12-02 05:45:30 +01:00
										 |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							| 
									
										
										
										
											2018-02-14 11:27:57 +01:00
										 |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSinkAPIAt(i); | 
					
						
							| 
									
										
										
										
											2017-12-29 05:22:26 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDirection(0); | 
					
						
							|  |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     if (deviceSet->m_deviceMIMOEngine) // MIMO data
 | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         samplingDevice->setDirection(2); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         *samplingDevice->getHwType() = deviceSet->m_deviceAPI->getHardwareId(); | 
					
						
							|  |  |  |         *samplingDevice->getSerial() = deviceSet->m_deviceAPI->getSamplingDeviceSerial(); | 
					
						
							|  |  |  |         samplingDevice->setSequence(deviceSet->m_deviceAPI->getSamplingDeviceSequence()); | 
					
						
							|  |  |  |         samplingDevice->setDeviceNbStreams(deviceSet->m_deviceAPI->getDeviceNbItems()); | 
					
						
							|  |  |  |         samplingDevice->setDeviceStreamIndex(deviceSet->m_deviceAPI->getDeviceItemIndex()); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |         samplingDevice->setState(new QString("notStarted")); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         deviceSet->m_deviceAPI->getDeviceEngineStateStr(*samplingDevice->getStateRx(), 0); | 
					
						
							|  |  |  |         deviceSet->m_deviceAPI->getDeviceEngineStateStr(*samplingDevice->getStateTx(), 1); | 
					
						
							|  |  |  |         DeviceSampleMIMO *sampleMIMO = deviceSet->m_deviceMIMOEngine->getMIMO(); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (sampleMIMO) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             samplingDevice->setCenterFrequency(sampleMIMO->getMIMOCenterFrequency()); | 
					
						
							|  |  |  |             samplingDevice->setBandwidth(sampleMIMO->getMIMOSampleRate()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         int nbSinkChannels = deviceSet->m_deviceAPI->getNbSinkChannels(); | 
					
						
							|  |  |  |         int nbSourceChannels = deviceSet->m_deviceAPI->getNbSourceChannels(); | 
					
						
							|  |  |  |         int nbMIMOChannels = deviceSet->m_deviceAPI->getNbMIMOChannels(); | 
					
						
							|  |  |  |         swgDeviceSet->setChannelcount(nbSinkChannels + nbSourceChannels + nbMIMOChannels); | 
					
						
							|  |  |  |         QList<SWGSDRangel::SWGChannel*> *channels = swgDeviceSet->getChannels(); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i < nbSinkChannels; i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							|  |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSinkAPIAt(i); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							|  |  |  |             channels->back()->setDirection(0); | 
					
						
							|  |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i < nbSourceChannels; i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							|  |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSourceAPIAt(i); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							|  |  |  |             channels->back()->setDirection(1); | 
					
						
							|  |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i < nbMIMOChannels; i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							|  |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getMIMOChannelAPIAt(i); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							|  |  |  |             channels->back()->setDirection(2); | 
					
						
							| 
									
										
										
										
											2017-11-25 22:52:24 +01:00
										 |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							| 
									
										
										
										
											2017-11-25 20:14:16 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  | void WebAPIAdapter::getChannelsDetail(SWGSDRangel::SWGChannelsDetail *channelsDetail, const DeviceSet* deviceSet) | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     channelsDetail->init(); | 
					
						
							|  |  |  |     SWGSDRangel::SWGChannelReport *channelReport; | 
					
						
							|  |  |  |     QString channelReportError; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     if (deviceSet->m_deviceSinkEngine) // Tx data
 | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         channelsDetail->setChannelcount(deviceSet->m_deviceAPI->getNbSourceChannels()); | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |         QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i <  channelsDetail->getChannelcount(); i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							|  |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSourceAPIAt(i); | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDirection(1); | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             channelReport = new SWGSDRangel::SWGChannelReport(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channel->webapiReportGet(*channelReport, channelReportError) != 501) { | 
					
						
							|  |  |  |                 channels->back()->setReport(channelReport); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 delete channelReport; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     if (deviceSet->m_deviceSourceEngine) // Rx data
 | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         channelsDetail->setChannelcount(deviceSet->m_deviceAPI->getNbSinkChannels()); | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |         QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i <  channelsDetail->getChannelcount(); i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							|  |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSinkAPIAt(i); | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDirection(0); | 
					
						
							|  |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             channelReport = new SWGSDRangel::SWGChannelReport(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channel->webapiReportGet(*channelReport, channelReportError) != 501) { | 
					
						
							|  |  |  |                 channels->back()->setReport(channelReport); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 delete channelReport; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     if (deviceSet->m_deviceMIMOEngine) // MIMO data
 | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         int nbSinkChannels = deviceSet->m_deviceAPI->getNbSinkChannels(); | 
					
						
							|  |  |  |         int nbSourceChannels = deviceSet->m_deviceAPI->getNbSourceChannels(); | 
					
						
							|  |  |  |         int nbMIMOChannels = deviceSet->m_deviceAPI->getNbMIMOChannels(); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |         QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels(); | 
					
						
							|  |  |  |         channelsDetail->setChannelcount(nbSinkChannels + nbSourceChannels + nbMIMOChannels); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i < nbSinkChannels; i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							|  |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSinkAPIAt(i); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							|  |  |  |             channels->back()->setDirection(0); | 
					
						
							|  |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             channelReport = new SWGSDRangel::SWGChannelReport(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channel->webapiReportGet(*channelReport, channelReportError) != 501) { | 
					
						
							|  |  |  |                 channels->back()->setReport(channelReport); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 delete channelReport; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i <  nbSourceChannels; i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							|  |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getChanelSourceAPIAt(i); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							|  |  |  |             channels->back()->setDirection(1); | 
					
						
							|  |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             channelReport = new SWGSDRangel::SWGChannelReport(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channel->webapiReportGet(*channelReport, channelReportError) != 501) { | 
					
						
							|  |  |  |                 channels->back()->setReport(channelReport); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 delete channelReport; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i <  nbMIMOChannels; i++) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             channels->append(new SWGSDRangel::SWGChannel); | 
					
						
							|  |  |  |             channels->back()->init(); | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |             ChannelAPI *channel = deviceSet->m_deviceAPI->getMIMOChannelAPIAt(i); | 
					
						
							| 
									
										
										
										
											2019-12-23 18:49:06 +01:00
										 |  |  |             channels->back()->setDeltaFrequency(channel->getCenterFrequency()); | 
					
						
							|  |  |  |             channels->back()->setDirection(2); | 
					
						
							| 
									
										
										
										
											2018-03-19 00:08:38 +01:00
										 |  |  |             channels->back()->setIndex(channel->getIndexInDeviceSet()); | 
					
						
							|  |  |  |             channels->back()->setUid(channel->getUID()); | 
					
						
							|  |  |  |             channel->getIdentifier(*channels->back()->getId()); | 
					
						
							|  |  |  |             channel->getTitle(*channels->back()->getTitle()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             channelReport = new SWGSDRangel::SWGChannelReport(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (channel->webapiReportGet(*channelReport, channelReportError) != 501) { | 
					
						
							|  |  |  |                 channels->back()->setReport(channelReport); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 delete channelReport; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | int WebAPIAdapter::featuresetGet( | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         int featureSetIndex, | 
					
						
							|  |  |  |         SWGSDRangel::SWGFeatureSet& response, | 
					
						
							|  |  |  |         SWGSDRangel::SWGErrorResponse& error) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |     if ((featureSetIndex >= 0) && (featureSetIndex < (int) m_mainCore->m_featureSets.size())) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 20:08:11 +02:00
										 |  |  |         const FeatureSet *featureSet = m_mainCore->m_featureSets[featureSetIndex]; | 
					
						
							| 
									
										
										
										
											2022-05-04 13:27:13 +02:00
										 |  |  |         getFeatureSet(&response, featureSet); | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return 200; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         error.init(); | 
					
						
							|  |  |  |         *error.getMessage() = QString("There is no feature set with index %1").arg(featureSetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return 404; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-04 13:27:13 +02:00
										 |  |  | void WebAPIAdapter::getFeatureSet(SWGSDRangel::SWGFeatureSet *swgFeatureSet, const FeatureSet* featureSet) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     swgFeatureSet->init(); | 
					
						
							|  |  |  |     swgFeatureSet->setFeaturecount(featureSet->getNumberOfFeatures()); | 
					
						
							|  |  |  |     QList<SWGSDRangel::SWGFeature*> *features = swgFeatureSet->getFeatures(); | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |     for (int i = 0; i < featureSet->getNumberOfFeatures(); i++) | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-11 13:05:43 +02:00
										 |  |  |         const Feature *feature = featureSet->getFeatureAt(i); | 
					
						
							| 
									
										
										
										
											2020-09-21 03:13:36 +02:00
										 |  |  |         features->append(new SWGSDRangel::SWGFeature); | 
					
						
							|  |  |  |         features->back()->setIndex(i); | 
					
						
							|  |  |  |         QString s; | 
					
						
							|  |  |  |         feature->getTitle(s); | 
					
						
							|  |  |  |         features->back()->setTitle(new QString(s)); | 
					
						
							|  |  |  |         feature->getIdentifier(s); | 
					
						
							|  |  |  |         features->back()->setId(new QString(s)); | 
					
						
							|  |  |  |         features->back()->setUid(feature->getUID()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | QtMsgType WebAPIAdapter::getMsgTypeFromString(const QString& msgTypeString) | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     if (msgTypeString == "debug") { | 
					
						
							|  |  |  |         return QtDebugMsg; | 
					
						
							|  |  |  |     } else if (msgTypeString == "info") { | 
					
						
							|  |  |  |         return QtInfoMsg; | 
					
						
							|  |  |  |     } else if (msgTypeString == "warning") { | 
					
						
							|  |  |  |         return QtWarningMsg; | 
					
						
							|  |  |  |     } else if (msgTypeString == "error") { | 
					
						
							|  |  |  |         return QtCriticalMsg; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return QtDebugMsg; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-11 12:39:30 +02:00
										 |  |  | void WebAPIAdapter::getMsgTypeString(const QtMsgType& msgType, QString& levelStr) | 
					
						
							| 
									
										
										
										
											2017-11-23 18:43:01 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     switch (msgType) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     case QtDebugMsg: | 
					
						
							|  |  |  |         levelStr = "debug"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case QtInfoMsg: | 
					
						
							|  |  |  |         levelStr = "info"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case QtWarningMsg: | 
					
						
							|  |  |  |         levelStr = "warning"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case QtCriticalMsg: | 
					
						
							|  |  |  |     case QtFatalMsg: | 
					
						
							|  |  |  |         levelStr = "error"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         levelStr = "debug"; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |