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>
|
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 11:12:53 -05:00
|
|
|
#include "SWGAudioDevicesSelect.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-11-18 13:34:47 -05:00
|
|
|
#include "SWGErrorResponse.h"
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
|
|
|
*response.getVersion() = qApp->applicationVersion();
|
2017-11-18 19:05:16 -05:00
|
|
|
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGLoggingInfo *logging = response.getLogging();
|
2017-11-18 19:05:16 -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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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);
|
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
|
|
|
{
|
|
|
|
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);
|
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
|
|
|
{
|
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(
|
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
|
2017-11-23 18:47:42 -05:00
|
|
|
bool dumpToFile = (response.getDumpToFile() != 0);
|
2017-11-23 12:43:01 -05:00
|
|
|
QString* consoleLevel = response.getConsoleLevel();
|
|
|
|
QString* fileLevel = response.getFileLevel();
|
|
|
|
QString* fileName = response.getFileName();
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
m_mainWindow.setLoggingOpions();
|
|
|
|
|
|
|
|
// build response
|
2017-11-23 18:47:42 -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
|
|
|
{
|
|
|
|
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_audioDeviceInfo.getInputDevices();
|
|
|
|
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_audioDeviceInfo.getOutputDevices();
|
|
|
|
int nbInputDevices = audioInputDevices.size();
|
|
|
|
int nbOutputDevices = audioOutputDevices.size();
|
|
|
|
|
|
|
|
response.init();
|
|
|
|
response.setNbInputDevices(nbInputDevices);
|
|
|
|
response.setInputDeviceSelectedIndex(m_mainWindow.m_audioDeviceInfo.getInputDeviceIndex());
|
|
|
|
response.setNbOutputDevices(nbOutputDevices);
|
|
|
|
response.setOutputDeviceSelectedIndex(m_mainWindow.m_audioDeviceInfo.getOutputDeviceIndex());
|
2017-11-24 11:12:53 -05:00
|
|
|
response.setInputVolume(m_mainWindow.m_audioDeviceInfo.getInputVolume());
|
2017-12-01 23:45:30 -05:00
|
|
|
QList<SWGSDRangel::SWGAudioDevice*> *inputDevices = response.getInputDevices();
|
|
|
|
QList<SWGSDRangel::SWGAudioDevice*> *outputDevices = response.getOutputDevices();
|
2017-11-24 02:46:12 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < nbInputDevices; i++)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
inputDevices->append(new SWGSDRangel::SWGAudioDevice);
|
2017-11-24 11:12:53 -05:00
|
|
|
*inputDevices->back()->getName() = audioInputDevices.at(i).deviceName();
|
2017-11-24 02:46:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < nbOutputDevices; i++)
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
outputDevices->append(new SWGSDRangel::SWGAudioDevice);
|
2017-11-24 11:12:53 -05:00
|
|
|
*outputDevices->back()->getName() = audioOutputDevices.at(i).deviceName();
|
2017-11-24 02:46:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-11-24 11:12:53 -05:00
|
|
|
int WebAPIAdapterGUI::instanceAudioPatch(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGAudioDevicesSelect& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
|
2017-11-24 11:12:53 -05:00
|
|
|
{
|
|
|
|
// response input is the query actually
|
|
|
|
float inputVolume = response.getInputVolume();
|
|
|
|
int inputIndex = response.getInputIndex();
|
|
|
|
int outputIndex = response.getOutputIndex();
|
|
|
|
|
|
|
|
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_audioDeviceInfo.getInputDevices();
|
|
|
|
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_audioDeviceInfo.getOutputDevices();
|
|
|
|
int nbInputDevices = audioInputDevices.size();
|
|
|
|
int nbOutputDevices = audioOutputDevices.size();
|
|
|
|
|
|
|
|
inputVolume = inputVolume < 0.0 ? 0.0 : inputVolume > 1.0 ? 1.0 : inputVolume;
|
|
|
|
inputIndex = inputIndex < -1 ? -1 : inputIndex > nbInputDevices ? nbInputDevices-1 : inputIndex;
|
|
|
|
outputIndex = outputIndex < -1 ? -1 : outputIndex > nbOutputDevices ? nbOutputDevices-1 : outputIndex;
|
|
|
|
|
|
|
|
m_mainWindow.m_audioDeviceInfo.setInputVolume(inputVolume);
|
|
|
|
m_mainWindow.m_audioDeviceInfo.setInputDeviceIndex(inputIndex);
|
|
|
|
m_mainWindow.m_audioDeviceInfo.setOutputDeviceIndex(outputIndex);
|
|
|
|
|
|
|
|
m_mainWindow.m_dspEngine->setAudioInputVolume(inputVolume);
|
|
|
|
m_mainWindow.m_dspEngine->setAudioInputDeviceIndex(inputIndex);
|
|
|
|
m_mainWindow.m_dspEngine->setAudioOutputDeviceIndex(outputIndex);
|
|
|
|
|
|
|
|
response.setInputVolume(m_mainWindow.m_audioDeviceInfo.getInputVolume());
|
|
|
|
response.setInputIndex(m_mainWindow.m_audioDeviceInfo.getInputDeviceIndex());
|
|
|
|
response.setOutputIndex(m_mainWindow.m_audioDeviceInfo.getOutputDeviceIndex());
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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);
|
2017-11-24 22:43:22 -05:00
|
|
|
response.init();
|
|
|
|
|
|
|
|
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();
|
|
|
|
std::string deviceNamesStr = "DV Serial devices found: ";
|
|
|
|
|
|
|
|
while (it != deviceNames.end())
|
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
deviceNamesList->append(new SWGSDRangel::SWGDVSerialDevice);
|
2017-11-24 22:43:22 -05:00
|
|
|
*deviceNamesList->back()->getDeviceName() = QString::fromStdString(*it);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
response.setNbDevices(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2017-11-25 05:14:52 -05:00
|
|
|
int WebAPIAdapterGUI::instancePresetGet(
|
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;
|
|
|
|
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);
|
2017-11-25 05:14:52 -05:00
|
|
|
groups->back()->init();
|
|
|
|
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);
|
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();
|
|
|
|
|
|
|
|
if (deviceSetIndex > nbDeviceSets)
|
|
|
|
{
|
|
|
|
*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)
|
|
|
|
{
|
|
|
|
*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())
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceUI->m_deviceSinkEngine && selectedPreset->isSourcePreset())
|
|
|
|
{
|
|
|
|
*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);
|
|
|
|
|
|
|
|
response.init();
|
|
|
|
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();
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (deviceSetIndex > nbDeviceSets)
|
|
|
|
{
|
|
|
|
*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
|
|
|
{
|
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())
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Preset type (T) and device set type (Rx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceUI->m_deviceSinkEngine && selectedPreset->isSourcePreset())
|
|
|
|
{
|
|
|
|
*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);
|
|
|
|
|
|
|
|
response.init();
|
|
|
|
response.setCenterFrequency(selectedPreset->getCenterFrequency());
|
|
|
|
*response.getGroupName() = selectedPreset->getGroup();
|
|
|
|
*response.getType() = selectedPreset->isSourcePreset() ? "R" : "T";
|
|
|
|
*response.getName() = selectedPreset->getDescription();
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (deviceSetIndex > nbDeviceSets)
|
|
|
|
{
|
|
|
|
*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) // save on a new preset
|
|
|
|
{
|
|
|
|
selectedPreset = m_mainWindow.m_settings.newPreset(*presetIdentifier->getGroupName(), *presetIdentifier->getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Preset already exists [%1, %2, %3]")
|
|
|
|
.arg(*presetIdentifier->getGroupName())
|
|
|
|
.arg(presetIdentifier->getCenterFrequency())
|
|
|
|
.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);
|
|
|
|
|
|
|
|
response.init();
|
|
|
|
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();
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
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-11-25 16:52:24 -05:00
|
|
|
int WebAPIAdapterGUI::instanceDeviceSetsPost(
|
|
|
|
bool tx,
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDeviceSet& response,
|
|
|
|
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);
|
|
|
|
|
|
|
|
usleep(100000);
|
|
|
|
|
|
|
|
const DeviceUISet *lastDeviceSet = m_mainWindow.m_deviceUIs.back();
|
|
|
|
getDeviceSet(&response,lastDeviceSet, (int) m_mainWindow.m_deviceUIs.size() - 1);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::instanceDeviceSetsDelete(
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGDeviceSetList& response,
|
|
|
|
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);
|
|
|
|
|
|
|
|
usleep(100000);
|
|
|
|
|
|
|
|
getDeviceSetList(&response);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error.init();
|
|
|
|
*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
|
|
|
|
{
|
|
|
|
error.init();
|
2017-11-27 02:14:07 -05:00
|
|
|
*error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex);
|
|
|
|
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::devicesetDevicePut(
|
|
|
|
int deviceSetIndex,
|
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];
|
|
|
|
|
|
|
|
if ((response.getTx() == 0) && (deviceSet->m_deviceSinkEngine))
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Device type (Rx) and device set type (Tx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((response.getTx() != 0) && (deviceSet->m_deviceSourceEngine))
|
|
|
|
{
|
|
|
|
*error.getMessage() = QString("Device type (Tx) and device set type (Rx) mismatch");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nbSamplingDevices = response.getTx() != 0 ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices();
|
|
|
|
int tx = response.getTx();
|
|
|
|
|
|
|
|
for (int i = 0; i < nbSamplingDevices; i++)
|
|
|
|
{
|
|
|
|
PluginInterface::SamplingDevice samplingDevice = response.getTx() ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i);
|
|
|
|
|
|
|
|
if (response.getDisplayedName() && (*response.getDisplayedName() != samplingDevice.displayedName)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.getHwType() && (*response.getHwType() != samplingDevice.hardwareId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((response.getSequence() >= 0) && (response.getSequence() != samplingDevice.sequence)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.getSerial() && (*response.getSerial() != samplingDevice.serial)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((response.getStreamIndex() >= 0) && (response.getStreamIndex() != samplingDevice.deviceItemIndex)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::MsgSetDevice *msg = MainWindow::MsgSetDevice::create(deviceSetIndex, i, response.getTx() != 0);
|
|
|
|
m_mainWindow.m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
response.init();
|
|
|
|
*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);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
*error.getMessage() = QString("Device not found");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int WebAPIAdapterGUI::devicesetDeviceGet(
|
|
|
|
int deviceSetIndex,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
|
|
|
SWGSDRangel::SWGErrorResponse& error)
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
DeviceSampleSource *source = deviceSet->m_deviceSourceAPI->getSampleSource();
|
|
|
|
return source->webapiSettingsGet(response.getData(), *error.getMessage());
|
|
|
|
}
|
2017-12-04 17:07:30 -05:00
|
|
|
else if (deviceSet->m_deviceSinkEngine) // Tx
|
2017-12-04 12:22:25 -05:00
|
|
|
{
|
|
|
|
DeviceSampleSink *sink = deviceSet->m_deviceSinkAPI->getSampleSink();
|
|
|
|
return sink->webapiSettingsGet(response.getData(), *error.getMessage());
|
|
|
|
}
|
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.init();
|
|
|
|
*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-01 23:45:30 -05:00
|
|
|
void WebAPIAdapterGUI::getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList)
|
2017-11-25 14:14:16 -05:00
|
|
|
{
|
|
|
|
deviceSetList->init();
|
|
|
|
deviceSetList->setDevicesetcount((int) m_mainWindow.m_deviceUIs.size());
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2017-12-01 23:45:30 -05:00
|
|
|
SWGSDRangel::SWGSamplingDevice *samplingDevice = deviceSet->getSamplingDevice();
|
2017-11-25 16:52:24 -05:00
|
|
|
samplingDevice->init();
|
|
|
|
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);
|
2017-11-25 16:52:24 -05:00
|
|
|
ChannelSourceAPI *channel = deviceUISet->m_deviceSinkAPI->getChanelAPIAt(i);
|
|
|
|
channels->back()->setDeltaFrequency(channel->getDeltaFrequency());
|
|
|
|
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);
|
2017-11-25 16:52:24 -05:00
|
|
|
ChannelSinkAPI *channel = deviceUISet->m_deviceSourceAPI->getChanelAPIAt(i);
|
|
|
|
channels->back()->setDeltaFrequency(channel->getDeltaFrequency());
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
}
|