2017-11-18 13:34:47 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 Edouard Griffiths, F4EXB. //
|
|
|
|
// //
|
|
|
|
// Swagger server adapter interface //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QApplication>
|
2017-11-22 12:57:35 -05:00
|
|
|
#include <QList>
|
2018-01-06 19:33:57 -05:00
|
|
|
#include <QSysInfo>
|
2017-11-18 13:34:47 -05:00
|
|
|
|
2017-11-25 16:52:24 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2017-11-18 13:34:47 -05:00
|
|
|
#include "mainwindow.h"
|
2017-11-30 16:53:28 -05:00
|
|
|
#include "ui_mainwindow.h"
|
2017-11-18 19:05:16 -05:00
|
|
|
#include "loggerwithfile.h"
|
|
|
|
#include "device/devicesourceapi.h"
|
|
|
|
#include "device/devicesinkapi.h"
|
|
|
|
#include "device/deviceuiset.h"
|
2017-11-22 12:57:35 -05:00
|
|
|
#include "device/deviceenumerator.h"
|
2017-11-18 19:05:16 -05:00
|
|
|
#include "dsp/devicesamplesource.h"
|
|
|
|
#include "dsp/devicesamplesink.h"
|
2017-11-24 11:12:53 -05:00
|
|
|
#include "dsp/dspengine.h"
|
2017-11-22 19:19:32 -05:00
|
|
|
#include "plugin/pluginapi.h"
|
|
|
|
#include "plugin/pluginmanager.h"
|
2017-11-18 21:38:07 -05:00
|
|
|
#include "channel/channelsinkapi.h"
|
|
|
|
#include "channel/channelsourceapi.h"
|
2017-11-18 19:05:16 -05:00
|
|
|
|
2017-11-18 13:34:47 -05:00
|
|
|
#include "SWGInstanceSummaryResponse.h"
|
2017-11-22 12:57:35 -05:00
|
|
|
#include "SWGInstanceDevicesResponse.h"
|
2017-11-22 19:19:32 -05:00
|
|
|
#include "SWGInstanceChannelsResponse.h"
|
2017-11-22 12:57:35 -05:00
|
|
|
#include "SWGDeviceListItem.h"
|
2017-11-24 02:46:12 -05:00
|
|
|
#include "SWGAudioDevices.h"
|
2017-11-24 22:02:11 -05:00
|
|
|
#include "SWGLocationInformation.h"
|
2017-11-24 22:43:22 -05:00
|
|
|
#include "SWGDVSeralDevices.h"
|
|
|
|
#include "SWGDVSerialDevice.h"
|
2017-11-25 05:14:52 -05:00
|
|
|
#include "SWGPresets.h"
|
|
|
|
#include "SWGPresetGroup.h"
|
|
|
|
#include "SWGPresetItem.h"
|
2017-11-25 10:08:18 -05:00
|
|
|
#include "SWGPresetTransfer.h"
|
|
|
|
#include "SWGPresetIdentifier.h"
|
2017-12-04 17:07:30 -05:00
|
|
|
#include "SWGDeviceSettings.h"
|
2017-12-08 11:12:33 -05:00
|
|
|
#include "SWGDeviceState.h"
|
2018-05-25 19:43:28 -04:00
|
|
|
#include "SWGDeviceReport.h"
|
2018-03-18 19:08:38 -04:00
|
|
|
#include "SWGChannelsDetail.h"
|
2017-12-10 14:27:08 -05:00
|
|
|
#include "SWGChannelSettings.h"
|
2018-03-18 15:17:11 -04:00
|
|
|
#include "SWGChannelReport.h"
|
2017-12-19 11:55:05 -05:00
|
|
|
#include "SWGSuccessResponse.h"
|
2017-11-18 13:34:47 -05:00
|
|
|
#include "SWGErrorResponse.h"
|
2018-02-13 19:42:35 -05:00
|
|
|
#include "SWGDeviceState.h"
|
2017-11-18 13:34:47 -05:00
|
|
|
|
2017-11-18 19:05:16 -05:00
|
|
|
#include "webapiadaptergui.h"
|
|
|
|
|
2017-11-18 13:34:47 -05:00
|
|
|
WebAPIAdapterGUI::WebAPIAdapterGUI(MainWindow& mainWindow) :
|
|
|
|
m_mainWindow(mainWindow)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WebAPIAdapterGUI::~WebAPIAdapterGUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceSummary(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGInstanceSummaryResponse& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-18 13:34:47 -05:00
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2018-01-06 19:33:57 -05:00
|
|
|
*response.getAppname() = qApp->applicationName();
|
2017-11-18 13:34:47 -05:00
|
|
|
*response.getVersion() = qApp->applicationVersion();
|
2017-12-18 07:19:20 -05:00
|
|
|
*response.getQtVersion() = QString(QT_VERSION_STR);
|
2018-01-22 17:29:09 -05:00
|
|
|
response.setDspRxBits(SDR_RX_SAMP_SZ);
|
|
|
|
response.setDspTxBits(SDR_TX_SAMP_SZ);
|
|
|
|
response.setPid(qApp->applicationPid());
|
2018-01-06 19:33:57 -05:00
|
|
|
#if QT_VERSION >= 0x050400
|
|
|
|
*response.getArchitecture() = QString(QSysInfo::currentCpuArchitecture());
|
|
|
|
*response.getOs() = QString(QSysInfo::prettyProductName());
|
|
|
|
#endif
|
2017-11-18 19:05:16 -05:00
|
|
|
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLoggingInfo *logging = response.getLogging();
|
2018-02-13 14:12:54 -05:00
|
|
|
logging->init();
|
2017-11-23 18:47:42 -05:00
|
|
|
logging->setDumpToFile(m_mainWindow.m_logger->getUseFileLogger() ? 1 : 0);
|
2017-11-25 14:14:16 -05:00
|
|
|
|
2017-11-18 19:05:16 -05:00
|
|
|
if (logging->getDumpToFile()) {
|
|
|
|
m_mainWindow.m_logger->getLogFileName(*logging->getFileName());
|
|
|
|
m_mainWindow.m_logger->getFileMinMessageLevelStr(*logging->getFileLevel());
|
|
|
|
}
|
2017-11-25 14:14:16 -05:00
|
|
|
|
2017-11-18 19:05:16 -05:00
|
|
|
m_mainWindow.m_logger->getConsoleMinMessageLevelStr(*logging->getConsoleLevel());
|
|
|
|
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDeviceSetList *deviceSetList = response.getDevicesetlist();
|
2017-11-25 14:14:16 -05:00
|
|
|
getDeviceSetList(deviceSetList);
|
2017-11-18 13:34:47 -05:00
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-01-05 21:46:53 -05:00
|
|
|
int WebAPIAdapterGUI::instanceDelete(
|
2018-03-03 04:06:47 -05:00
|
|
|
SWGSDRangel::SWGSuccessResponse& response __attribute__((unused)),
|
2018-01-05 21:46:53 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Not supported in GUI instance");
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
|
2017-11-22 12:57:35 -05:00
|
|
|
int WebAPIAdapterGUI::instanceDevices(
|
|
|
|
bool tx,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGInstanceDevicesResponse& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-22 12:57:35 -05:00
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-11-22 12:57:35 -05:00
|
|
|
int nbSamplingDevices = tx ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices();
|
|
|
|
response.setDevicecount(nbSamplingDevices);
|
2017-12-01 23:45:30 -05:00
|
|
|
QList<SWGSDRangel::SWGDeviceListItem*> *devices = response.getDevices();
|
2017-11-18 13:34:47 -05:00
|
|
|
|
2017-11-22 12:57:35 -05:00
|
|
|
for (int i = 0; i < nbSamplingDevices; i++)
|
|
|
|
{
|
|
|
|
PluginInterface::SamplingDevice samplingDevice = tx ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i);
|
2017-12-01 23:45:30 -05:00
|
|
|
devices->append(new SWGSDRangel::SWGDeviceListItem);
|
2018-02-13 19:42:35 -05:00
|
|
|
devices->back()->init();
|
2017-11-22 12:57:35 -05:00
|
|
|
*devices->back()->getDisplayedName() = samplingDevice.displayedName;
|
|
|
|
*devices->back()->getHwType() = samplingDevice.hardwareId;
|
|
|
|
*devices->back()->getSerial() = samplingDevice.serial;
|
|
|
|
devices->back()->setSequence(samplingDevice.sequence);
|
|
|
|
devices->back()->setTx(!samplingDevice.rxElseTx);
|
|
|
|
devices->back()->setNbStreams(samplingDevice.deviceNbItems);
|
|
|
|
devices->back()->setDeviceSetIndex(samplingDevice.claimed);
|
2017-11-22 16:16:57 -05:00
|
|
|
devices->back()->setIndex(i);
|
2017-11-22 12:57:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
2017-11-22 19:19:32 -05:00
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceChannels(
|
|
|
|
bool tx,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGInstanceChannelsResponse& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-22 19:19:32 -05:00
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-11-22 19:19:32 -05:00
|
|
|
PluginAPI::ChannelRegistrations *channelRegistrations = tx ? m_mainWindow.m_pluginManager->getTxChannelRegistrations() : m_mainWindow.m_pluginManager->getRxChannelRegistrations();
|
|
|
|
int nbChannelDevices = channelRegistrations->size();
|
|
|
|
response.setChannelcount(nbChannelDevices);
|
2017-12-01 23:45:30 -05:00
|
|
|
QList<SWGSDRangel::SWGChannelListItem*> *channels = response.getChannels();
|
2017-11-22 19:19:32 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < nbChannelDevices; i++)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
channels->append(new SWGSDRangel::SWGChannelListItem);
|
2018-02-13 19:42:35 -05:00
|
|
|
channels->back()->init();
|
2017-11-22 19:19:32 -05:00
|
|
|
PluginInterface *channelInterface = channelRegistrations->at(i).m_plugin;
|
|
|
|
const PluginDescriptor& pluginDescriptor = channelInterface->getPluginDescriptor();
|
|
|
|
*channels->back()->getVersion() = pluginDescriptor.version;
|
|
|
|
*channels->back()->getName() = pluginDescriptor.displayedName;
|
|
|
|
channels->back()->setTx(tx);
|
|
|
|
*channels->back()->getIdUri() = channelRegistrations->at(i).m_channelIdURI;
|
|
|
|
*channels->back()->getId() = channelRegistrations->at(i).m_channelId;
|
|
|
|
channels->back()->setIndex(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-11-23 12:43:01 -05:00
|
|
|
int WebAPIAdapterGUI::instanceLoggingGet(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLoggingInfo& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-23 12:43:01 -05:00
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-11-23 18:47:42 -05:00
|
|
|
response.setDumpToFile(m_mainWindow.m_logger->getUseFileLogger() ? 1 : 0);
|
2017-11-23 12:43:01 -05:00
|
|
|
|
|
|
|
if (response.getDumpToFile()) {
|
|
|
|
m_mainWindow.m_logger->getLogFileName(*response.getFileName());
|
|
|
|
m_mainWindow.m_logger->getFileMinMessageLevelStr(*response.getFileLevel());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.m_logger->getConsoleMinMessageLevelStr(*response.getConsoleLevel());
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceLoggingPut(
|
2018-02-13 19:42:35 -05:00
|
|
|
SWGSDRangel::SWGLoggingInfo& query,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLoggingInfo& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-23 12:43:01 -05:00
|
|
|
{
|
|
|
|
// response input is the query actually
|
2018-02-13 19:42:35 -05:00
|
|
|
bool dumpToFile = (query.getDumpToFile() != 0);
|
|
|
|
QString* consoleLevel = query.getConsoleLevel();
|
|
|
|
QString* fileLevel = query.getFileLevel();
|
|
|
|
QString* fileName = query.getFileName();
|
2017-11-23 12:43:01 -05:00
|
|
|
|
|
|
|
// perform actions
|
|
|
|
if (consoleLevel) {
|
|
|
|
m_mainWindow.m_settings.setConsoleMinLogLevel(getMsgTypeFromString(*consoleLevel));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileLevel) {
|
|
|
|
m_mainWindow.m_settings.setFileMinLogLevel(getMsgTypeFromString(*fileLevel));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.m_settings.setUseLogFile(dumpToFile);
|
|
|
|
|
|
|
|
if (fileName) {
|
2017-11-23 18:47:42 -05:00
|
|
|
m_mainWindow.m_settings.setLogFileName(*fileName);
|
2017-11-23 12:43:01 -05:00
|
|
|
}
|
|
|
|
|
2017-12-18 07:56:10 -05:00
|
|
|
m_mainWindow.setLoggingOptions();
|
2017-11-23 12:43:01 -05:00
|
|
|
|
|
|
|
// build response
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-11-23 12:43:01 -05:00
|
|
|
getMsgTypeString(m_mainWindow.m_settings.getConsoleMinLogLevel(), *response.getConsoleLevel());
|
2017-11-23 18:47:42 -05:00
|
|
|
response.setDumpToFile(m_mainWindow.m_settings.getUseLogFile() ? 1 : 0);
|
|
|
|
getMsgTypeString(m_mainWindow.m_settings.getFileMinLogLevel(), *response.getFileLevel());
|
|
|
|
*response.getFileName() = m_mainWindow.m_settings.getLogFileName();
|
2017-11-23 12:43:01 -05:00
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-11-24 02:46:12 -05:00
|
|
|
int WebAPIAdapterGUI::instanceAudioGet(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGAudioDevices& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-24 02:46:12 -05:00
|
|
|
{
|
2018-03-23 13:08:38 -04:00
|
|
|
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDevices();
|
|
|
|
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDevices();
|
2017-11-24 02:46:12 -05:00
|
|
|
int nbInputDevices = audioInputDevices.size();
|
|
|
|
int nbOutputDevices = audioOutputDevices.size();
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-11-24 02:46:12 -05:00
|
|
|
response.setNbInputDevices(nbInputDevices);
|
|
|
|
response.setNbOutputDevices(nbOutputDevices);
|
2018-03-28 18:38:01 -04: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();
|
|
|
|
bool found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, inputDeviceInfo);
|
|
|
|
*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 02:46:12 -05:00
|
|
|
for (int i = 0; i < nbInputDevices; i++)
|
|
|
|
{
|
2018-03-28 18:38:01 -04:00
|
|
|
inputDevices->append(new SWGSDRangel::SWGAudioInputDevice);
|
2018-02-13 19:42:35 -05:00
|
|
|
inputDevices->back()->init();
|
2018-03-28 18:38:01 -04:00
|
|
|
inputDeviceInfo.resetToDefaults();
|
|
|
|
found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(audioInputDevices.at(i).deviceName(), inputDeviceInfo);
|
2017-11-24 11:12:53 -05:00
|
|
|
*inputDevices->back()->getName() = audioInputDevices.at(i).deviceName();
|
2018-03-28 18:38:01 -04:00
|
|
|
inputDevices->back()->setIndex(i);
|
|
|
|
inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate);
|
|
|
|
inputDevices->back()->setIsSystemDefault(audioInputDevices.at(i).deviceName() == QAudioDeviceInfo::defaultInputDevice().deviceName() ? 1 : 0);
|
|
|
|
inputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
|
|
|
|
inputDevices->back()->setVolume(inputDeviceInfo.volume);
|
2017-11-24 02:46:12 -05:00
|
|
|
}
|
|
|
|
|
2018-03-28 18:38:01 -04:00
|
|
|
// system default output device
|
|
|
|
outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice);
|
|
|
|
outputDevices->back()->init();
|
|
|
|
found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, outputDeviceInfo);
|
|
|
|
*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);
|
|
|
|
*outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress;
|
|
|
|
outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort);
|
|
|
|
|
|
|
|
// real output devices
|
2017-11-24 02:46:12 -05:00
|
|
|
for (int i = 0; i < nbOutputDevices; i++)
|
|
|
|
{
|
2018-03-28 18:38:01 -04:00
|
|
|
outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice);
|
2018-02-13 19:42:35 -05:00
|
|
|
outputDevices->back()->init();
|
2018-03-28 18:38:01 -04:00
|
|
|
outputDeviceInfo.resetToDefaults();
|
|
|
|
found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(audioOutputDevices.at(i).deviceName(), outputDeviceInfo);
|
2017-11-24 11:12:53 -05:00
|
|
|
*outputDevices->back()->getName() = audioOutputDevices.at(i).deviceName();
|
2018-03-28 18:38:01 -04:00
|
|
|
outputDevices->back()->setIndex(i);
|
|
|
|
outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate);
|
|
|
|
outputDevices->back()->setIsSystemDefault(audioOutputDevices.at(i).deviceName() == QAudioDeviceInfo::defaultOutputDevice().deviceName() ? 1 : 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);
|
|
|
|
*outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress;
|
|
|
|
outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort);
|
2017-11-24 02:46:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-03-28 18:38:01 -04:00
|
|
|
int WebAPIAdapterGUI::instanceAudioInputPatch(
|
|
|
|
SWGSDRangel::SWGAudioInputDevice& response,
|
|
|
|
const QStringList& audioInputKeys,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-11-24 11:12:53 -05:00
|
|
|
{
|
2018-03-28 18:38:01 -04:00
|
|
|
// TODO
|
|
|
|
AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
|
|
|
|
QString deviceName;
|
|
|
|
int deviceIndex = response.getIndex();
|
2017-11-24 11:12:53 -05:00
|
|
|
|
2018-03-28 18:38:01 -04:00
|
|
|
if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName))
|
|
|
|
{
|
|
|
|
error.init();
|
|
|
|
*error.getMessage() = QString("There is no audio input device at index %1").arg(deviceIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
|
|
|
|
|
|
|
|
if (audioInputKeys.contains("sampleRate")) {
|
|
|
|
inputDeviceInfo.sampleRate = response.getSampleRate();
|
|
|
|
}
|
|
|
|
if (audioInputKeys.contains("volume")) {
|
|
|
|
inputDeviceInfo.volume = response.getVolume();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->setInputDeviceInfo(deviceIndex, inputDeviceInfo);
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
|
|
|
|
|
|
|
|
response.setSampleRate(inputDeviceInfo.sampleRate);
|
|
|
|
response.setVolume(inputDeviceInfo.volume);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceAudioOutputPatch(
|
|
|
|
SWGSDRangel::SWGAudioOutputDevice& response,
|
|
|
|
const QStringList& audioOutputKeys,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
|
|
|
|
QString deviceName;
|
|
|
|
int deviceIndex = response.getIndex();
|
|
|
|
|
|
|
|
if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName))
|
|
|
|
{
|
|
|
|
error.init();
|
|
|
|
*error.getMessage() = QString("There is no audio output device at index %1").arg(deviceIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
|
|
|
|
|
|
|
|
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")) {
|
|
|
|
outputDeviceInfo.udpChannelMode = static_cast<AudioOutput::UDPChannelMode>(response.getUdpChannelMode() % 4);
|
|
|
|
}
|
|
|
|
if (audioOutputKeys.contains("udpAddress")) {
|
|
|
|
outputDeviceInfo.udpAddress = *response.getUdpAddress();
|
|
|
|
}
|
|
|
|
if (audioOutputKeys.contains("udpPort")) {
|
|
|
|
outputDeviceInfo.udpPort = response.getUdpPort() % (1<<16);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->setOutputDeviceInfo(deviceIndex, outputDeviceInfo);
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
|
2017-11-24 11:12:53 -05:00
|
|
|
|
2018-03-28 18:38:01 -04:00
|
|
|
response.setSampleRate(outputDeviceInfo.sampleRate);
|
|
|
|
response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1);
|
|
|
|
response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1);
|
|
|
|
response.setUdpChannelMode(outputDeviceInfo.udpChannelMode % 4);
|
|
|
|
|
|
|
|
if (response.getUdpAddress()) {
|
|
|
|
*response.getUdpAddress() = outputDeviceInfo.udpAddress;
|
|
|
|
} else {
|
|
|
|
response.setUdpAddress(new QString(outputDeviceInfo.udpAddress));
|
|
|
|
}
|
2017-11-24 11:12:53 -05:00
|
|
|
|
2018-03-28 18:38:01 -04:00
|
|
|
response.setUdpPort(outputDeviceInfo.udpPort % (1<<16));
|
2017-11-24 11:12:53 -05:00
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-03-28 19:43:31 -04:00
|
|
|
int WebAPIAdapterGUI::instanceAudioInputDelete(
|
|
|
|
SWGSDRangel::SWGAudioInputDevice& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
|
|
|
|
QString deviceName;
|
|
|
|
int deviceIndex = response.getIndex();
|
|
|
|
|
|
|
|
if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName))
|
|
|
|
{
|
|
|
|
error.init();
|
|
|
|
*error.getMessage() = QString("There is no audio input device at index %1").arg(deviceIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->unsetInputDeviceInfo(deviceIndex);
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
|
|
|
|
|
|
|
|
response.setSampleRate(inputDeviceInfo.sampleRate);
|
|
|
|
response.setVolume(inputDeviceInfo.volume);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceAudioOutputDelete(
|
|
|
|
SWGSDRangel::SWGAudioOutputDevice& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
|
|
|
|
QString deviceName;
|
|
|
|
int deviceIndex = response.getIndex();
|
|
|
|
|
|
|
|
if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName))
|
|
|
|
{
|
|
|
|
error.init();
|
|
|
|
*error.getMessage() = QString("There is no audio output device at index %1").arg(deviceIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->unsetInputDeviceInfo(deviceIndex);
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
|
|
|
|
|
|
|
|
response.setSampleRate(outputDeviceInfo.sampleRate);
|
|
|
|
response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1);
|
|
|
|
response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1);
|
|
|
|
response.setUdpChannelMode(outputDeviceInfo.udpChannelMode % 4);
|
|
|
|
|
|
|
|
if (response.getUdpAddress()) {
|
|
|
|
*response.getUdpAddress() = outputDeviceInfo.udpAddress;
|
|
|
|
} else {
|
|
|
|
response.setUdpAddress(new QString(outputDeviceInfo.udpAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.setUdpPort(outputDeviceInfo.udpPort % (1<<16));
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceAudioInputCleanupPatch(
|
|
|
|
SWGSDRangel::SWGSuccessResponse& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
|
|
|
{
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->inputInfosCleanup();
|
|
|
|
|
|
|
|
response.init();
|
|
|
|
*response.getMessage() = QString("Unregistered parameters for devices not in list of available input devices for this instance");
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceAudioOutputCleanupPatch(
|
|
|
|
SWGSDRangel::SWGSuccessResponse& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
|
|
|
{
|
|
|
|
m_mainWindow.m_dspEngine->getAudioDeviceManager()->outputInfosCleanup();
|
|
|
|
|
|
|
|
response.init();
|
|
|
|
*response.getMessage() = QString("Unregistered parameters for devices not in list of available output devices for this instance");
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-11-24 22:02:11 -05:00
|
|
|
int WebAPIAdapterGUI::instanceLocationGet(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLocationInformation& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-24 22:02:11 -05:00
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-11-24 22:02:11 -05:00
|
|
|
response.setLatitude(m_mainWindow.m_settings.getLatitude());
|
|
|
|
response.setLongitude(m_mainWindow.m_settings.getLongitude());
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceLocationPut(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLocationInformation& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-24 22:02:11 -05: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;
|
|
|
|
|
|
|
|
m_mainWindow.m_settings.setLatitude(latitude);
|
|
|
|
m_mainWindow.m_settings.setLongitude(longitude);
|
|
|
|
|
|
|
|
response.setLatitude(m_mainWindow.m_settings.getLatitude());
|
|
|
|
response.setLongitude(m_mainWindow.m_settings.getLongitude());
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:05:53 -04:00
|
|
|
int WebAPIAdapterGUI::instanceDVSerialGet(
|
|
|
|
SWGSDRangel::SWGDVSeralDevices& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
|
|
|
{
|
|
|
|
response.init();
|
|
|
|
|
|
|
|
std::vector<std::string> deviceNames;
|
|
|
|
m_mainWindow.m_dspEngine->getDVSerialNames(deviceNames);
|
|
|
|
response.setNbDevices((int) deviceNames.size());
|
|
|
|
QList<SWGSDRangel::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
|
|
|
|
|
|
|
|
std::vector<std::string>::iterator it = deviceNames.begin();
|
|
|
|
|
|
|
|
while (it != deviceNames.end())
|
|
|
|
{
|
|
|
|
deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
|
|
|
|
deviceNamesList->back()->init();
|
|
|
|
*deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-11-24 22:43:22 -05:00
|
|
|
int WebAPIAdapterGUI::instanceDVSerialPatch(
|
|
|
|
bool dvserial,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDVSeralDevices& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-24 22:43:22 -05:00
|
|
|
{
|
|
|
|
m_mainWindow.m_dspEngine->setDVSerialSupport(dvserial);
|
2017-11-30 16:53:28 -05:00
|
|
|
m_mainWindow.ui->action_DV_Serial->setChecked(dvserial);
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-11-24 22:43:22 -05:00
|
|
|
|
|
|
|
if (dvserial)
|
|
|
|
{
|
|
|
|
std::vector<std::string> deviceNames;
|
|
|
|
m_mainWindow.m_dspEngine->getDVSerialNames(deviceNames);
|
|
|
|
response.setNbDevices((int) deviceNames.size());
|
2017-12-01 23:45:30 -05:00
|
|
|
QList<SWGSDRangel::SWGDVSerialDevice*> *deviceNamesList = response.getDvSerialDevices();
|
2017-11-24 22:43:22 -05:00
|
|
|
|
|
|
|
std::vector<std::string>::iterator it = deviceNames.begin();
|
|
|
|
|
|
|
|
while (it != deviceNames.end())
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
|
2018-02-13 19:42:35 -05:00
|
|
|
deviceNamesList->back()->init();
|
2017-11-24 22:43:22 -05:00
|
|
|
*deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setNbDevices(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-12-20 18:50:58 -05:00
|
|
|
int WebAPIAdapterGUI::instancePresetsGet(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresets& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-25 05:14:52 -05:00
|
|
|
{
|
|
|
|
int nbPresets = m_mainWindow.m_settings.getPresetCount();
|
|
|
|
int nbGroups = 0;
|
|
|
|
int nbPresetsThisGroup = 0;
|
|
|
|
QString groupName;
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-12-01 23:45:30 -05:00
|
|
|
QList<SWGSDRangel::SWGPresetGroup*> *groups = response.getGroups();
|
|
|
|
QList<SWGSDRangel::SWGPresetItem*> *swgPresets = 0;
|
2017-11-25 05:14:52 -05:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// Presets are sorted by group first
|
|
|
|
|
|
|
|
for (; i < nbPresets; i++)
|
|
|
|
{
|
|
|
|
const Preset *preset = m_mainWindow.m_settings.getPreset(i);
|
|
|
|
|
|
|
|
if ((i == 0) || (groupName != preset->getGroup())) // new group
|
|
|
|
{
|
|
|
|
if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
|
2017-12-01 23:45:30 -05:00
|
|
|
groups->append(new SWGSDRangel::SWGPresetGroup);
|
2018-02-13 14:12:54 -05:00
|
|
|
groups->back()->init();
|
2017-11-25 05:14:52 -05:00
|
|
|
groupName = preset->getGroup();
|
|
|
|
*groups->back()->getGroupName() = groupName;
|
|
|
|
swgPresets = groups->back()->getPresets();
|
|
|
|
nbGroups++;
|
|
|
|
nbPresetsThisGroup = 0;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:45:30 -05:00
|
|
|
swgPresets->append(new SWGSDRangel::SWGPresetItem);
|
2018-02-14 05:27:57 -05:00
|
|
|
swgPresets->back()->init();
|
2017-11-25 05:14:52 -05:00
|
|
|
swgPresets->back()->setCenterFrequency(preset->getCenterFrequency());
|
|
|
|
*swgPresets->back()->getType() = preset->isSourcePreset() ? "R" : "T";
|
|
|
|
*swgPresets->back()->getName() = preset->getDescription();
|
|
|
|
nbPresetsThisGroup++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > 0) { groups->back()->setNbPresets(nbPresetsThisGroup); }
|
|
|
|
response.setNbGroups(nbGroups);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-11-25 10:08:18 -05:00
|
|
|
int WebAPIAdapterGUI::instancePresetPatch(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetTransfer& query,
|
|
|
|
SWGSDRangel::SWGPresetIdentifier& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-11-25 10:08:18 -05:00
|
|
|
{
|
|
|
|
int deviceSetIndex = query.getDeviceSetIndex();
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
2017-11-25 10:08:18 -05:00
|
|
|
int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
|
|
|
|
|
2017-12-20 08:31:17 -05:00
|
|
|
if (deviceSetIndex >= nbDeviceSets)
|
2017-11-25 10:08:18 -05:00
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 10:08:18 -05:00
|
|
|
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
|
|
|
|
presetIdentifier->getCenterFrequency(),
|
|
|
|
*presetIdentifier->getName());
|
|
|
|
|
|
|
|
if (selectedPreset == 0)
|
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 10:08:18 -05:00
|
|
|
*error.getMessage() = QString("There is no preset [%1, %2, %3]")
|
|
|
|
.arg(*presetIdentifier->getGroupName())
|
|
|
|
.arg(presetIdentifier->getCenterFrequency())
|
|
|
|
.arg(*presetIdentifier->getName());
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceUISet *deviceUI = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceUI->m_deviceSourceEngine && !selectedPreset->isSourcePreset())
|
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 10:08:18 -05:00
|
|
|
*error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceUI->m_deviceSinkEngine && selectedPreset->isSourcePreset())
|
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 10:08:18 -05:00
|
|
|
*error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::MsgLoadPreset *msg = MainWindow::MsgLoadPreset::create(selectedPreset, deviceSetIndex);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-11-25 10:08:18 -05:00
|
|
|
response.setCenterFrequency(selectedPreset->getCenterFrequency());
|
|
|
|
*response.getGroupName() = selectedPreset->getGroup();
|
2017-11-25 10:47:13 -05:00
|
|
|
*response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
|
|
|
|
*response.getName() = selectedPreset->getDescription();
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-11-25 10:47:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instancePresetPut(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetTransfer& query,
|
|
|
|
SWGSDRangel::SWGPresetIdentifier& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-11-25 10:47:13 -05:00
|
|
|
{
|
|
|
|
int deviceSetIndex = query.getDeviceSetIndex();
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
2017-11-25 10:47:13 -05:00
|
|
|
int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
|
|
|
|
|
2017-12-20 18:23:36 -05:00
|
|
|
if (deviceSetIndex >= nbDeviceSets)
|
2017-11-25 10:47:13 -05:00
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 10:47:13 -05:00
|
|
|
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
|
|
|
|
presetIdentifier->getCenterFrequency(),
|
|
|
|
*presetIdentifier->getName());
|
|
|
|
|
2017-11-25 12:32:37 -05:00
|
|
|
if (selectedPreset == 0)
|
2017-11-25 10:47:13 -05:00
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 12:32:37 -05:00
|
|
|
*error.getMessage() = QString("There is no preset [%1, %2, %3]")
|
|
|
|
.arg(*presetIdentifier->getGroupName())
|
|
|
|
.arg(presetIdentifier->getCenterFrequency())
|
|
|
|
.arg(*presetIdentifier->getName());
|
|
|
|
return 404;
|
2017-11-25 10:47:13 -05:00
|
|
|
}
|
|
|
|
else // update existing preset
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceUI = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceUI->m_deviceSourceEngine && !selectedPreset->isSourcePreset())
|
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 10:47:13 -05:00
|
|
|
*error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceUI->m_deviceSinkEngine && selectedPreset->isSourcePreset())
|
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 10:47:13 -05:00
|
|
|
*error.getMessage() = QString("Preset type (R) and device set type (Tx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-25 12:32:37 -05:00
|
|
|
MainWindow::MsgSavePreset *msg = MainWindow::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, false);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-11-25 12:32:37 -05:00
|
|
|
response.setCenterFrequency(selectedPreset->getCenterFrequency());
|
|
|
|
*response.getGroupName() = selectedPreset->getGroup();
|
|
|
|
*response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
|
|
|
|
*response.getName() = selectedPreset->getDescription();
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-11-25 12:32:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instancePresetPost(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetTransfer& query,
|
|
|
|
SWGSDRangel::SWGPresetIdentifier& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-11-25 12:32:37 -05:00
|
|
|
{
|
|
|
|
int deviceSetIndex = query.getDeviceSetIndex();
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetIdentifier *presetIdentifier = query.getPreset();
|
2017-11-25 12:32:37 -05:00
|
|
|
int nbDeviceSets = m_mainWindow.m_deviceUIs.size();
|
|
|
|
|
2017-12-20 18:23:36 -05:00
|
|
|
if (deviceSetIndex >= nbDeviceSets)
|
2017-11-25 12:32:37 -05:00
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 12:32:37 -05:00
|
|
|
*error.getMessage() = QString("There is no device set at index %1. Number of device sets is %2").arg(deviceSetIndex).arg(nbDeviceSets);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
2018-02-14 05:27:57 -05:00
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
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();
|
|
|
|
} else {
|
|
|
|
error.init();
|
|
|
|
*error.getMessage() = QString("Device set error");
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
|
2017-11-25 12:32:37 -05:00
|
|
|
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*presetIdentifier->getGroupName(),
|
2018-02-14 05:27:57 -05:00
|
|
|
deviceCenterFrequency,
|
2017-11-25 12:32:37 -05:00
|
|
|
*presetIdentifier->getName());
|
|
|
|
|
|
|
|
if (selectedPreset == 0) // save on a new preset
|
|
|
|
{
|
|
|
|
selectedPreset = m_mainWindow.m_settings.newPreset(*presetIdentifier->getGroupName(), *presetIdentifier->getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
error.init();
|
2017-11-25 12:32:37 -05:00
|
|
|
*error.getMessage() = QString("Preset already exists [%1, %2, %3]")
|
|
|
|
.arg(*presetIdentifier->getGroupName())
|
2018-02-14 05:27:57 -05:00
|
|
|
.arg(deviceCenterFrequency)
|
2017-11-25 12:32:37 -05:00
|
|
|
.arg(*presetIdentifier->getName());
|
|
|
|
return 409;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::MsgSavePreset *msg = MainWindow::MsgSavePreset::create(const_cast<Preset*>(selectedPreset), deviceSetIndex, true);
|
2017-11-25 10:47:13 -05:00
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-11-25 10:47:13 -05:00
|
|
|
response.setCenterFrequency(selectedPreset->getCenterFrequency());
|
|
|
|
*response.getGroupName() = selectedPreset->getGroup();
|
2017-11-25 10:08:18 -05:00
|
|
|
*response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
|
|
|
|
*response.getName() = selectedPreset->getDescription();
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-11-25 10:08:18 -05:00
|
|
|
}
|
|
|
|
|
2017-11-25 13:42:56 -05:00
|
|
|
int WebAPIAdapterGUI::instancePresetDelete(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGPresetIdentifier& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-11-25 13:42:56 -05:00
|
|
|
{
|
|
|
|
const Preset *selectedPreset = m_mainWindow.m_settings.getPreset(*response.getGroupName(),
|
|
|
|
response.getCenterFrequency(),
|
|
|
|
*response.getName());
|
|
|
|
|
|
|
|
if (selectedPreset == 0)
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("There is no preset [%1, %2, %3]")
|
|
|
|
.arg(*response.getGroupName())
|
|
|
|
.arg(response.getCenterFrequency())
|
|
|
|
.arg(*response.getName());
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
response.setCenterFrequency(selectedPreset->getCenterFrequency());
|
|
|
|
*response.getGroupName() = selectedPreset->getGroup();
|
|
|
|
*response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
|
|
|
|
*response.getName() = selectedPreset->getDescription();
|
|
|
|
|
|
|
|
MainWindow::MsgDeletePreset *msg = MainWindow::MsgDeletePreset::create(const_cast<Preset*>(selectedPreset));
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-11-25 13:42:56 -05:00
|
|
|
}
|
|
|
|
|
2017-11-25 14:14:16 -05:00
|
|
|
int WebAPIAdapterGUI::instanceDeviceSetsGet(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDeviceSetList& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-25 14:14:16 -05:00
|
|
|
{
|
|
|
|
getDeviceSetList(&response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-12-21 19:07:03 -05:00
|
|
|
int WebAPIAdapterGUI::instanceDeviceSetPost(
|
2017-11-25 16:52:24 -05:00
|
|
|
bool tx,
|
2017-12-19 11:55:05 -05:00
|
|
|
SWGSDRangel::SWGSuccessResponse& response,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-25 16:52:24 -05:00
|
|
|
{
|
|
|
|
MainWindow::MsgAddDeviceSet *msg = MainWindow::MsgAddDeviceSet::create(tx);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-12-21 16:35:25 -05:00
|
|
|
*response.getMessage() = QString("Message to add a new device set (MsgAddDeviceSet) was submitted successfully");
|
2017-11-25 16:52:24 -05:00
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-11-25 16:52:24 -05:00
|
|
|
}
|
|
|
|
|
2017-12-21 19:07:03 -05:00
|
|
|
int WebAPIAdapterGUI::instanceDeviceSetDelete(
|
2017-12-19 11:55:05 -05:00
|
|
|
SWGSDRangel::SWGSuccessResponse& response,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-11-25 16:52:24 -05:00
|
|
|
{
|
|
|
|
if (m_mainWindow.m_deviceUIs.size() > 1)
|
|
|
|
{
|
|
|
|
MainWindow::MsgRemoveLastDeviceSet *msg = MainWindow::MsgRemoveLastDeviceSet::create();
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-12-21 16:35:25 -05:00
|
|
|
*response.getMessage() = QString("Message to remove last device set (MsgRemoveLastDeviceSet) was submitted successfully");
|
2017-11-25 16:52:24 -05:00
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-11-25 16:52:24 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-11-25 16:52:24 -05:00
|
|
|
*error.getMessage() = "No more device sets to be removed";
|
|
|
|
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 04:37:39 -05:00
|
|
|
int WebAPIAdapterGUI::devicesetGet(
|
|
|
|
int deviceSetIndex,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDeviceSet& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-11-26 04:37:39 -05:00
|
|
|
{
|
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
const DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
getDeviceSet(&response, deviceSet, deviceSetIndex);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-11-27 02:14:07 -05:00
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
|
2018-01-05 21:46:53 -05:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::devicesetFocusPatch(
|
|
|
|
int deviceSetIndex,
|
|
|
|
SWGSDRangel::SWGSuccessResponse& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
MainWindow::MsgDeviceSetFocus *msg = MainWindow::MsgDeviceSetFocus::create(deviceSetIndex);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2018-01-05 21:46:53 -05:00
|
|
|
*response.getMessage() = QString("Message to focus on device set (MsgDeviceSetFocus) was submitted successfully");
|
|
|
|
|
|
|
|
return 202;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2018-01-05 21:46:53 -05:00
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
|
2017-11-27 02:14:07 -05:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::devicesetDevicePut(
|
|
|
|
int deviceSetIndex,
|
2018-02-14 07:40:34 -05:00
|
|
|
SWGSDRangel::SWGDeviceListItem& query,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDeviceListItem& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-11-27 02:14:07 -05:00
|
|
|
{
|
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
if ((query.getTx() == 0) && (deviceSet->m_deviceSinkEngine))
|
2017-11-27 02:14:07 -05:00
|
|
|
{
|
2018-02-14 07:40:34 -05:00
|
|
|
error.init();
|
2017-11-27 02:14:07 -05:00
|
|
|
*error.getMessage() = QString("Device type (Rx) and device set type (Tx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
if ((query.getTx() != 0) && (deviceSet->m_deviceSourceEngine))
|
2017-11-27 02:14:07 -05:00
|
|
|
{
|
2018-02-14 07:40:34 -05:00
|
|
|
error.init();
|
2017-11-27 02:14:07 -05:00
|
|
|
*error.getMessage() = QString("Device type (Tx) and device set type (Rx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
int nbSamplingDevices = query.getTx() != 0 ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices();
|
|
|
|
int tx = query.getTx();
|
2017-11-27 02:14:07 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < nbSamplingDevices; i++)
|
|
|
|
{
|
2018-02-14 07:40:34 -05:00
|
|
|
PluginInterface::SamplingDevice samplingDevice = query.getTx() ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i);
|
2017-11-27 02:14:07 -05:00
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice.displayedName)) {
|
2017-11-27 02:14:07 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
if (query.getHwType() && (*query.getHwType() != samplingDevice.hardwareId)) {
|
2017-11-27 02:14:07 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice.sequence)) {
|
2017-11-27 02:14:07 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
if (query.getSerial() && (*query.getSerial() != samplingDevice.serial)) {
|
2017-11-27 02:14:07 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
if ((query.getStreamIndex() >= 0) && (query.getStreamIndex() != samplingDevice.deviceItemIndex)) {
|
2017-11-27 02:14:07 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
MainWindow::MsgSetDevice *msg = MainWindow::MsgSetDevice::create(deviceSetIndex, i, query.getTx() != 0);
|
2017-11-27 02:14:07 -05:00
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-11-27 02:14:07 -05:00
|
|
|
*response.getDisplayedName() = samplingDevice.displayedName;
|
|
|
|
*response.getHwType() = samplingDevice.hardwareId;
|
|
|
|
*response.getSerial() = samplingDevice.serial;
|
|
|
|
response.setSequence(samplingDevice.sequence);
|
|
|
|
response.setTx(tx);
|
|
|
|
response.setNbStreams(samplingDevice.deviceNbItems);
|
|
|
|
response.setStreamIndex(samplingDevice.deviceItemIndex);
|
|
|
|
response.setDeviceSetIndex(deviceSetIndex);
|
|
|
|
response.setIndex(i);
|
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-11-27 02:14:07 -05:00
|
|
|
}
|
|
|
|
|
2018-02-14 07:40:34 -05:00
|
|
|
error.init();
|
2017-11-27 02:14:07 -05:00
|
|
|
*error.getMessage() = QString("Device not found");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-11-26 04:37:39 -05:00
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
2017-12-04 12:22:25 -05:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 16:08:34 -05:00
|
|
|
int WebAPIAdapterGUI::devicesetDeviceSettingsGet(
|
2017-12-04 12:22:25 -05:00
|
|
|
int deviceSetIndex,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
2018-02-21 07:27:10 -05:00
|
|
|
error.init();
|
|
|
|
|
2017-12-04 17:07:30 -05:00
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
2017-12-04 12:22:25 -05:00
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
2017-12-04 17:07:30 -05:00
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
2017-12-04 12:22:25 -05:00
|
|
|
{
|
2017-12-06 13:23:42 -05:00
|
|
|
response.setDeviceHwType(new QString(deviceSet->m_deviceSourceAPI->getHardwareId()));
|
|
|
|
response.setTx(0);
|
2017-12-04 12:22:25 -05:00
|
|
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
2017-12-06 13:23:42 -05:00
|
|
|
return source->webapiSettingsGet(response, *error.getMessage());
|
2017-12-04 12:22:25 -05:00
|
|
|
}
|
2017-12-04 17:07:30 -05:00
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
2017-12-04 12:22:25 -05:00
|
|
|
{
|
2017-12-06 13:23:42 -05:00
|
|
|
response.setDeviceHwType(new QString(deviceSet->m_deviceSinkAPI->getHardwareId()));
|
|
|
|
response.setTx(1);
|
2017-12-04 12:22:25 -05:00
|
|
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
2017-12-06 13:23:42 -05:00
|
|
|
return sink->webapiSettingsGet(response, *error.getMessage());
|
2017-12-04 12:22:25 -05:00
|
|
|
}
|
2017-12-04 17:07:30 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("DeviceSet error");
|
|
|
|
return 500;
|
|
|
|
}
|
2017-12-04 12:22:25 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
2017-12-07 07:55:42 -05:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::devicesetDeviceSettingsPutPatch(
|
|
|
|
int deviceSetIndex,
|
|
|
|
bool force,
|
2017-12-26 19:46:33 -05:00
|
|
|
const QStringList& deviceSettingsKeys,
|
2017-12-07 07:55:42 -05:00
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
2018-02-21 07:27:10 -05:00
|
|
|
error.init();
|
|
|
|
|
2017-12-07 07:55:42 -05:00
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
2017-12-14 17:12:52 -05:00
|
|
|
if (response.getTx() != 0)
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Rx device found but Tx device requested");
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
if (deviceSet->m_deviceSourceAPI->getHardwareId() != *response.getDeviceHwType())
|
2017-12-07 07:55:42 -05:00
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Device mismatch. Found %1 input").arg(deviceSet->m_deviceSourceAPI->getHardwareId());
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
2017-12-26 19:46:33 -05:00
|
|
|
return source->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage());
|
2017-12-07 07:55:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
2017-12-14 17:12:52 -05:00
|
|
|
if (response.getTx() == 0)
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Tx device found but Rx device requested");
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkAPI->getHardwareId() != *response.getDeviceHwType())
|
2017-12-07 07:55:42 -05:00
|
|
|
{
|
2017-12-14 17:12:52 -05:00
|
|
|
*error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceSinkAPI->getHardwareId());
|
2017-12-07 07:55:42 -05:00
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
2017-12-26 19:46:33 -05:00
|
|
|
return sink->webapiSettingsPutPatch(force, deviceSettingsKeys, response, *error.getMessage());
|
2017-12-07 07:55:42 -05: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 04:37:39 -05:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 04:49:20 -05:00
|
|
|
int WebAPIAdapterGUI::devicesetDeviceRunGet(
|
|
|
|
int deviceSetIndex,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
error.init();
|
|
|
|
|
2017-12-09 04:49:20 -05:00
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
|
|
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-12-09 04:49:20 -05:00
|
|
|
return source->webapiRunGet(response, *error.getMessage());
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
|
|
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-12-09 04:49:20 -05:00
|
|
|
return sink->webapiRunGet(response, *error.getMessage());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("DeviceSet error");
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 11:12:33 -05:00
|
|
|
int WebAPIAdapterGUI::devicesetDeviceRunPost(
|
|
|
|
int deviceSetIndex,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
error.init();
|
|
|
|
|
2017-12-08 11:12:33 -05:00
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
|
|
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-12-08 11:12:33 -05:00
|
|
|
return source->webapiRun(true, response, *error.getMessage());
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
|
|
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-12-08 11:12:33 -05:00
|
|
|
return sink->webapiRun(true, response, *error.getMessage());
|
|
|
|
}
|
|
|
|
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 WebAPIAdapterGUI::devicesetDeviceRunDelete(
|
|
|
|
int deviceSetIndex,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
2018-02-13 19:42:35 -05:00
|
|
|
error.init();
|
|
|
|
|
2017-12-08 11:12:33 -05:00
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
|
|
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-12-08 11:12:33 -05:00
|
|
|
return source->webapiRun(false, response, *error.getMessage());
|
2018-02-13 19:42:35 -05:00
|
|
|
}
|
2017-12-08 11:12:33 -05:00
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
|
|
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
2018-02-13 19:42:35 -05:00
|
|
|
response.init();
|
2017-12-08 11:12:33 -05:00
|
|
|
return sink->webapiRun(false, response, *error.getMessage());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("DeviceSet error");
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 19:43:28 -04:00
|
|
|
|
|
|
|
int WebAPIAdapterGUI::devicesetDeviceReportGet(
|
|
|
|
int deviceSetIndex,
|
|
|
|
SWGSDRangel::SWGDeviceReport& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
error.init();
|
|
|
|
|
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
|
|
|
response.setDeviceHwType(new QString(deviceSet->m_deviceSourceAPI->getHardwareId()));
|
|
|
|
response.setTx(0);
|
|
|
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
|
|
|
return source->webapiReportGet(response, *error.getMessage());
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
|
|
|
response.setDeviceHwType(new QString(deviceSet->m_deviceSinkAPI->getHardwareId()));
|
|
|
|
response.setTx(1);
|
|
|
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
|
|
|
return sink->webapiReportGet(response, *error.getMessage());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("DeviceSet error");
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-18 19:08:38 -04:00
|
|
|
int WebAPIAdapterGUI::devicesetChannelsReportGet(
|
|
|
|
int deviceSetIndex,
|
|
|
|
SWGSDRangel::SWGChannelsDetail& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
const DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
getChannelsDetail(&response, deviceSet);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.init();
|
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 19:18:10 -05:00
|
|
|
int WebAPIAdapterGUI::devicesetChannelPost(
|
|
|
|
int deviceSetIndex,
|
2017-12-19 11:55:05 -05:00
|
|
|
SWGSDRangel::SWGChannelSettings& query,
|
|
|
|
SWGSDRangel::SWGSuccessResponse& response,
|
2017-12-10 19:18:10 -05:00
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
2017-12-19 11:55:05 -05:00
|
|
|
if (query.getTx() == 0) // Rx
|
2017-12-10 19:18:10 -05:00
|
|
|
{
|
|
|
|
if (deviceSet->m_deviceSourceEngine == 0)
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-10 19:18:10 -05:00
|
|
|
*error.getMessage() = QString("Device set at %1 is not a receive device set").arg(deviceSetIndex);
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginAPI::ChannelRegistrations *channelRegistrations = m_mainWindow.m_pluginManager->getRxChannelRegistrations();
|
|
|
|
int nbRegistrations = channelRegistrations->size();
|
|
|
|
int index = 0;
|
|
|
|
for (; index < nbRegistrations; index++)
|
|
|
|
{
|
2017-12-19 11:55:05 -05:00
|
|
|
if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) {
|
2017-12-10 19:18:10 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index < nbRegistrations)
|
|
|
|
{
|
|
|
|
MainWindow::MsgAddChannel *msg = MainWindow::MsgAddChannel::create(deviceSetIndex, index, false);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-12-21 16:35:25 -05:00
|
|
|
*response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully");
|
2017-12-19 11:55:05 -05:00
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-12-10 19:18:10 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-19 11:55:05 -05:00
|
|
|
*error.getMessage() = QString("There is no receive channel with id %1").arg(*query.getChannelType());
|
2017-12-10 19:18:10 -05:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Tx
|
|
|
|
{
|
|
|
|
if (deviceSet->m_deviceSinkEngine == 0)
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-10 19:18:10 -05:00
|
|
|
*error.getMessage() = QString("Device set at %1 is not a transmit device set").arg(deviceSetIndex);
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginAPI::ChannelRegistrations *channelRegistrations = m_mainWindow.m_pluginManager->getTxChannelRegistrations();
|
|
|
|
int nbRegistrations = channelRegistrations->size();
|
|
|
|
int index = 0;
|
|
|
|
for (; index < nbRegistrations; index++)
|
|
|
|
{
|
2017-12-19 11:55:05 -05:00
|
|
|
if (channelRegistrations->at(index).m_channelId == *query.getChannelType()) {
|
2017-12-10 19:18:10 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index < nbRegistrations)
|
|
|
|
{
|
|
|
|
MainWindow::MsgAddChannel *msg = MainWindow::MsgAddChannel::create(deviceSetIndex, index, true);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-12-21 16:35:25 -05:00
|
|
|
*response.getMessage() = QString("Message to add a channel (MsgAddChannel) was submitted successfully");
|
2017-12-19 11:55:05 -05:00
|
|
|
|
2017-12-21 12:10:43 -05:00
|
|
|
return 202;
|
2017-12-10 19:18:10 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-19 11:55:05 -05:00
|
|
|
*error.getMessage() = QString("There is no transmit channel with id %1").arg(*query.getChannelType());
|
2017-12-10 19:18:10 -05:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-10 19:18:10 -05:00
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-23 17:41:37 -05:00
|
|
|
int WebAPIAdapterGUI::devicesetChannelDelete(
|
|
|
|
int deviceSetIndex,
|
|
|
|
int channelIndex,
|
|
|
|
SWGSDRangel::SWGSuccessResponse& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
|
|
|
if (channelIndex < deviceSet->getNumberOfRxChannels())
|
|
|
|
{
|
|
|
|
MainWindow::MsgDeleteChannel *msg = MainWindow::MsgDeleteChannel::create(deviceSetIndex, channelIndex, false);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-12-23 17:41:37 -05:00
|
|
|
*response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully");
|
|
|
|
|
|
|
|
return 202;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-23 17:41:37 -05:00
|
|
|
*error.getMessage() = QString("There is no channel at index %1. There are %2 Rx channels")
|
|
|
|
.arg(channelIndex)
|
|
|
|
.arg(channelIndex < deviceSet->getNumberOfRxChannels());
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
|
|
|
if (channelIndex < deviceSet->getNumberOfTxChannels())
|
|
|
|
{
|
|
|
|
MainWindow::MsgDeleteChannel *msg = MainWindow::MsgDeleteChannel::create(deviceSetIndex, channelIndex, true);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
2018-02-13 14:12:54 -05:00
|
|
|
response.init();
|
2017-12-23 17:41:37 -05:00
|
|
|
*response.getMessage() = QString("Message to delete a channel (MsgDeleteChannel) was submitted successfully");
|
|
|
|
|
|
|
|
return 202;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-23 17:41:37 -05:00
|
|
|
*error.getMessage() = QString("There is no channel at index %1. There are %2 Tx channels")
|
|
|
|
.arg(channelIndex)
|
|
|
|
.arg(channelIndex < deviceSet->getNumberOfRxChannels());
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-23 17:41:37 -05:00
|
|
|
*error.getMessage() = QString("DeviceSet error");
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
error.init();
|
2017-12-23 17:41:37 -05:00
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 14:27:08 -05:00
|
|
|
int WebAPIAdapterGUI::devicesetChannelSettingsGet(
|
|
|
|
int deviceSetIndex,
|
|
|
|
int channelIndex,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
2018-02-21 07:50:05 -05:00
|
|
|
error.init();
|
|
|
|
|
2017-12-10 14:27:08 -05:00
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
|
|
|
ChannelSinkAPI *channelAPI = deviceSet->m_deviceSourceAPI->getChanelAPIAt(channelIndex);
|
|
|
|
|
|
|
|
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());
|
|
|
|
response.setTx(0);
|
|
|
|
return channelAPI->webapiSettingsGet(response, *error.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
|
|
|
ChannelSourceAPI *channelAPI = deviceSet->m_deviceSinkAPI->getChanelAPIAt(channelIndex);
|
|
|
|
|
|
|
|
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());
|
|
|
|
response.setTx(1);
|
|
|
|
return channelAPI->webapiSettingsGet(response, *error.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 15:17:11 -04:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::devicesetChannelReportGet(
|
|
|
|
int deviceSetIndex,
|
|
|
|
int channelIndex,
|
|
|
|
SWGSDRangel::SWGChannelReport& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
|
|
|
error.init();
|
|
|
|
|
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
|
|
|
ChannelSinkAPI *channelAPI = deviceSet->m_deviceSourceAPI->getChanelAPIAt(channelIndex);
|
|
|
|
|
|
|
|
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());
|
|
|
|
response.setTx(0);
|
|
|
|
return channelAPI->webapiReportGet(response, *error.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
|
|
|
ChannelSourceAPI *channelAPI = deviceSet->m_deviceSinkAPI->getChanelAPIAt(channelIndex);
|
|
|
|
|
|
|
|
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());
|
|
|
|
response.setTx(1);
|
|
|
|
return channelAPI->webapiReportGet(response, *error.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 14:27:08 -05:00
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 11:12:33 -05:00
|
|
|
|
2017-12-11 12:18:47 -05:00
|
|
|
int WebAPIAdapterGUI::devicesetChannelSettingsPutPatch(
|
2017-12-23 21:27:07 -05:00
|
|
|
int deviceSetIndex,
|
|
|
|
int channelIndex,
|
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
2017-12-11 12:18:47 -05:00
|
|
|
{
|
2018-02-21 07:50:05 -05:00
|
|
|
error.init();
|
|
|
|
|
2017-12-11 12:18:47 -05:00
|
|
|
if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size()))
|
|
|
|
{
|
|
|
|
DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex];
|
|
|
|
|
|
|
|
if (deviceSet->m_deviceSourceEngine) // Rx
|
|
|
|
{
|
|
|
|
ChannelSinkAPI *channelAPI = deviceSet->m_deviceSourceAPI->getChanelAPIAt(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 == *response.getChannelType())
|
|
|
|
{
|
2017-12-23 21:27:07 -05:00
|
|
|
return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage());
|
2017-12-11 12:18:47 -05: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
|
|
|
{
|
|
|
|
ChannelSourceAPI *channelAPI = deviceSet->m_deviceSinkAPI->getChanelAPIAt(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 == *response.getChannelType())
|
|
|
|
{
|
2017-12-23 21:27:07 -05:00
|
|
|
return channelAPI->webapiSettingsPutPatch(force, channelSettingsKeys, response, *error.getMessage());
|
2017-12-11 12:18:47 -05: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("DeviceSet error");
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:45:30 -05:00
|
|
|
void WebAPIAdapterGUI::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
2017-11-25 14:14:16 -05:00
|
|
|
{
|
2018-02-13 14:12:54 -05:00
|
|
|
deviceSetList->init();
|
2017-11-25 14:14:16 -05:00
|
|
|
deviceSetList->setDevicesetcount((int) m_mainWindow.m_deviceUIs.size());
|
|
|
|
|
2018-01-06 03:50:09 -05:00
|
|
|
if (m_mainWindow.m_deviceUIs.size() > 0) {
|
|
|
|
deviceSetList->setDevicesetfocus(m_mainWindow.ui->tabInputsView->currentIndex());
|
|
|
|
}
|
|
|
|
|
2017-11-25 14:14:16 -05:00
|
|
|
std::vector<DeviceUISet*>::const_iterator it = m_mainWindow.m_deviceUIs.begin();
|
|
|
|
|
|
|
|
for (int i = 0; it != m_mainWindow.m_deviceUIs.end(); ++it, i++)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
QList<SWGSDRangel::SWGDeviceSet*> *deviceSets = deviceSetList->getDeviceSets();
|
|
|
|
deviceSets->append(new SWGSDRangel::SWGDeviceSet());
|
2017-11-25 16:52:24 -05:00
|
|
|
|
|
|
|
getDeviceSet(deviceSets->back(), *it, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:45:30 -05:00
|
|
|
void WebAPIAdapterGUI::getDeviceSet(SWGSDRangel::SWGDeviceSet *deviceSet, const DeviceUISet* deviceUISet, int deviceUISetIndex)
|
2017-11-25 16:52:24 -05:00
|
|
|
{
|
2018-02-14 05:27:57 -05:00
|
|
|
deviceSet->init();
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGSamplingDevice *samplingDevice = deviceSet->getSamplingDevice();
|
2018-02-13 14:12:54 -05:00
|
|
|
samplingDevice->init();
|
2017-11-25 16:52:24 -05:00
|
|
|
samplingDevice->setIndex(deviceUISetIndex);
|
|
|
|
samplingDevice->setTx(deviceUISet->m_deviceSinkEngine != 0);
|
|
|
|
|
|
|
|
if (deviceUISet->m_deviceSinkEngine) // Tx data
|
|
|
|
{
|
|
|
|
*samplingDevice->getHwType() = deviceUISet->m_deviceSinkAPI->getHardwareId();
|
|
|
|
*samplingDevice->getSerial() = deviceUISet->m_deviceSinkAPI->getSampleSinkSerial();
|
|
|
|
samplingDevice->setSequence(deviceUISet->m_deviceSinkAPI->getSampleSinkSequence());
|
|
|
|
samplingDevice->setNbStreams(deviceUISet->m_deviceSinkAPI->getNbItems());
|
|
|
|
samplingDevice->setStreamIndex(deviceUISet->m_deviceSinkAPI->getItemIndex());
|
|
|
|
deviceUISet->m_deviceSinkAPI->getDeviceEngineStateStr(*samplingDevice->getState());
|
|
|
|
DeviceSampleSink *sampleSink = deviceUISet->m_deviceSinkEngine->getSink();
|
|
|
|
|
|
|
|
if (sampleSink) {
|
|
|
|
samplingDevice->setCenterFrequency(sampleSink->getCenterFrequency());
|
|
|
|
samplingDevice->setBandwidth(sampleSink->getSampleRate());
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceSet->setChannelcount(deviceUISet->m_deviceSinkAPI->getNbChannels());
|
2017-12-01 23:45:30 -05:00
|
|
|
QList<SWGSDRangel::SWGChannel*> *channels = deviceSet->getChannels();
|
2017-11-25 16:52:24 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < deviceSet->getChannelcount(); i++)
|
2017-11-25 14:14:16 -05:00
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
channels->append(new SWGSDRangel::SWGChannel);
|
2018-02-14 05:27:57 -05:00
|
|
|
channels->back()->init();
|
2017-11-25 16:52:24 -05:00
|
|
|
ChannelSourceAPI *channel = deviceUISet->m_deviceSinkAPI->getChanelAPIAt(i);
|
2017-12-28 23:22:26 -05:00
|
|
|
channels->back()->setDeltaFrequency(channel->getCenterFrequency());
|
2017-11-25 16:52:24 -05:00
|
|
|
channels->back()->setIndex(channel->getIndexInDeviceSet());
|
|
|
|
channels->back()->setUid(channel->getUID());
|
|
|
|
channel->getIdentifier(*channels->back()->getId());
|
|
|
|
channel->getTitle(*channels->back()->getTitle());
|
2017-11-25 14:14:16 -05:00
|
|
|
}
|
2017-11-25 16:52:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceUISet->m_deviceSourceEngine) // Rx data
|
|
|
|
{
|
|
|
|
*samplingDevice->getHwType() = deviceUISet->m_deviceSourceAPI->getHardwareId();
|
|
|
|
*samplingDevice->getSerial() = deviceUISet->m_deviceSourceAPI->getSampleSourceSerial();
|
|
|
|
samplingDevice->setSequence(deviceUISet->m_deviceSourceAPI->getSampleSourceSequence());
|
|
|
|
samplingDevice->setNbStreams(deviceUISet->m_deviceSourceAPI->getNbItems());
|
|
|
|
samplingDevice->setStreamIndex(deviceUISet->m_deviceSourceAPI->getItemIndex());
|
|
|
|
deviceUISet->m_deviceSourceAPI->getDeviceEngineStateStr(*samplingDevice->getState());
|
|
|
|
DeviceSampleSource *sampleSource = deviceUISet->m_deviceSourceEngine->getSource();
|
|
|
|
|
|
|
|
if (sampleSource) {
|
|
|
|
samplingDevice->setCenterFrequency(sampleSource->getCenterFrequency());
|
|
|
|
samplingDevice->setBandwidth(sampleSource->getSampleRate());
|
|
|
|
}
|
|
|
|
|
|
|
|
deviceSet->setChannelcount(deviceUISet->m_deviceSourceAPI->getNbChannels());
|
2017-12-01 23:45:30 -05:00
|
|
|
QList<SWGSDRangel::SWGChannel*> *channels = deviceSet->getChannels();
|
2017-11-25 14:14:16 -05:00
|
|
|
|
2017-11-25 16:52:24 -05:00
|
|
|
for (int i = 0; i < deviceSet->getChannelcount(); i++)
|
2017-11-25 14:14:16 -05:00
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
channels->append(new SWGSDRangel::SWGChannel);
|
2018-02-14 05:27:57 -05:00
|
|
|
channels->back()->init();
|
2017-11-25 16:52:24 -05:00
|
|
|
ChannelSinkAPI *channel = deviceUISet->m_deviceSourceAPI->getChanelAPIAt(i);
|
2017-12-28 23:22:26 -05:00
|
|
|
channels->back()->setDeltaFrequency(channel->getCenterFrequency());
|
2017-11-25 16:52:24 -05:00
|
|
|
channels->back()->setIndex(channel->getIndexInDeviceSet());
|
|
|
|
channels->back()->setUid(channel->getUID());
|
|
|
|
channel->getIdentifier(*channels->back()->getId());
|
|
|
|
channel->getTitle(*channels->back()->getTitle());
|
2017-11-25 14:14:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-18 19:08:38 -04:00
|
|
|
void WebAPIAdapterGUI::getChannelsDetail(SWGSDRangel::SWGChannelsDetail *channelsDetail, const DeviceUISet* deviceUISet)
|
|
|
|
{
|
|
|
|
channelsDetail->init();
|
|
|
|
SWGSDRangel::SWGChannelReport *channelReport;
|
|
|
|
QString channelReportError;
|
|
|
|
|
|
|
|
if (deviceUISet->m_deviceSinkEngine) // Tx data
|
|
|
|
{
|
|
|
|
channelsDetail->setChannelcount(deviceUISet->m_deviceSinkAPI->getNbChannels());
|
|
|
|
QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels();
|
|
|
|
|
|
|
|
for (int i = 0; i < channelsDetail->getChannelcount(); i++)
|
|
|
|
{
|
|
|
|
channels->append(new SWGSDRangel::SWGChannel);
|
|
|
|
channels->back()->init();
|
|
|
|
ChannelSourceAPI *channel = deviceUISet->m_deviceSinkAPI->getChanelAPIAt(i);
|
|
|
|
channels->back()->setDeltaFrequency(channel->getCenterFrequency());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceUISet->m_deviceSourceEngine) // Rx data
|
|
|
|
{
|
|
|
|
channelsDetail->setChannelcount(deviceUISet->m_deviceSourceAPI->getNbChannels());
|
|
|
|
QList<SWGSDRangel::SWGChannel*> *channels = channelsDetail->getChannels();
|
|
|
|
|
|
|
|
for (int i = 0; i < channelsDetail->getChannelcount(); i++)
|
|
|
|
{
|
|
|
|
channels->append(new SWGSDRangel::SWGChannel);
|
|
|
|
channels->back()->init();
|
|
|
|
ChannelSinkAPI *channel = deviceUISet->m_deviceSourceAPI->getChanelAPIAt(i);
|
|
|
|
channels->back()->setDeltaFrequency(channel->getCenterFrequency());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 12:43:01 -05:00
|
|
|
QtMsgType WebAPIAdapterGUI::getMsgTypeFromString(const QString& msgTypeString)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAPIAdapterGUI::getMsgTypeString(const QtMsgType& msgType, QString& levelStr)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|