1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 23:55:13 -05:00

Websocket spectrum: server implementation

This commit is contained in:
f4exb 2020-05-06 09:50:43 +02:00
parent e69818cc45
commit 270fd955ae
6 changed files with 4902 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include "SWGGLSpectrum.h"
#include "SWGSpectrumServer.h"
#include "SWGSuccessResponse.h"
#include "glspectruminterface.h"
#include "dspcommands.h"
@ -850,6 +851,7 @@ int SpectrumVis::webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& respo
getMessageQueueToGUI()->push(msgToGui);
}
response.setMessage(new QString("Websocket spectrum server started"));
return 200;
}
@ -865,6 +867,7 @@ int SpectrumVis::webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& res
getMessageQueueToGUI()->push(msgToGui);
}
response.setMessage(new QString("Websocket spectrum server stopped"));
return 200;
}

504
sdrsrv/device/deviceset.cpp Normal file
View File

@ -0,0 +1,504 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// 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 //
// (at your option) any later version. //
// //
// 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 <algorithm>
#include "dsp/dspdevicesourceengine.h"
#include "dsp/dspdevicesinkengine.h"
#include "dsp/spectrumvis.h"
#include "plugin/pluginapi.h"
#include "plugin/plugininterface.h"
#include "settings/preset.h"
#include "channel/channelapi.h"
#include "channel/channelutils.h"
#include "settings/preset.h"
#include "deviceset.h"
DeviceSet::ChannelInstanceRegistration::ChannelInstanceRegistration(const QString& channelName, ChannelAPI* channelAPI) :
m_channelName(channelName),
m_channelAPI(channelAPI)
{}
DeviceSet::DeviceSet(int tabIndex, int deviceType)
{
m_deviceAPI = nullptr;
m_deviceSourceEngine = nullptr;
m_deviceSinkEngine = nullptr;
m_deviceMIMOEngine = nullptr;
m_deviceTabIndex = tabIndex;
if ((deviceType == 0) || (deviceType == 2)) { // Single Rx or MIMO
m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF);
} else if (deviceType == 1) { // Single Tx
m_spectrumVis = new SpectrumVis(SDR_TX_SCALEF);
}
}
DeviceSet::~DeviceSet()
{
delete m_spectrumVis;
}
void DeviceSet::registerRxChannelInstance(const QString& channelName, ChannelAPI* channelAPI)
{
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI));
renameChannelInstances();
}
void DeviceSet::registerTxChannelInstance(const QString& channelName, ChannelAPI* channelAPI)
{
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI));
renameChannelInstances();
}
void DeviceSet::registerChannelInstance(const QString& channelName, ChannelAPI* channelAPI)
{
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI));
renameChannelInstances();
}
void DeviceSet::removeRxChannelInstance(ChannelAPI* channelAPI)
{
for (ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it)
{
if (it->m_channelAPI == channelAPI)
{
m_channelInstanceRegistrations.erase(it);
break;
}
}
renameChannelInstances();
}
void DeviceSet::removeTxChannelInstance(ChannelAPI* channelAPI)
{
for(ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it)
{
if(it->m_channelAPI == channelAPI)
{
m_channelInstanceRegistrations.erase(it);
break;
}
}
renameChannelInstances();
}
void DeviceSet::removeChannelInstance(ChannelAPI* channelAPI)
{
for(ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it)
{
if(it->m_channelAPI == channelAPI)
{
m_channelInstanceRegistrations.erase(it);
break;
}
}
renameChannelInstances();
}
void DeviceSet::freeChannels()
{
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
qDebug("DeviceSet::freeChannels: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
m_channelInstanceRegistrations[i].m_channelAPI->destroy();
}
}
void DeviceSet::deleteChannel(int channelIndex)
{
if (channelIndex < m_channelInstanceRegistrations.count())
{
m_channelInstanceRegistrations[channelIndex].m_channelAPI->destroy();
m_channelInstanceRegistrations.removeAt(channelIndex);
renameChannelInstances();
}
}
void DeviceSet::addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
{
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations(); // Available channel plugins
ChannelAPI *rxChannel =(*channelRegistrations)[selectedChannelIndex].m_plugin->createRxChannelCS(m_deviceAPI);
ChannelInstanceRegistration reg = ChannelInstanceRegistration(rxChannel->getName(), rxChannel);
m_channelInstanceRegistrations.append(reg);
qDebug("DeviceSet::addRxChannel: %s", qPrintable(rxChannel->getName()));
}
void DeviceSet::addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
{
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations(); // Available channel plugins
ChannelAPI *txChannel = (*channelRegistrations)[selectedChannelIndex].m_plugin->createTxChannelCS(m_deviceAPI);
ChannelInstanceRegistration reg = ChannelInstanceRegistration(txChannel->getName(), txChannel);
m_channelInstanceRegistrations.append(reg);
qDebug("DeviceSet::addTxChannel: %s", qPrintable(txChannel->getName()));
}
void DeviceSet::addMIMOChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
{
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getMIMOChannelRegistrations(); // Available channel plugins
ChannelAPI *mimoChannel = (*channelRegistrations)[selectedChannelIndex].m_plugin->createMIMOChannelCS(m_deviceAPI);
ChannelInstanceRegistration reg = ChannelInstanceRegistration(mimoChannel->getName(), mimoChannel);
m_channelInstanceRegistrations.append(reg);
qDebug("DeviceSet::addMIMOChannel: %s", qPrintable(mimoChannel->getName()));
}
void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
{
if (preset->isSourcePreset())
{
qDebug("DeviceSet::loadChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
// Available channel plugins
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations();
// copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
m_channelInstanceRegistrations.clear();
qDebug("DeviceSet::loadChannelSettings: %d channel(s) in preset", preset->getChannelCount());
for (int i = 0; i < preset->getChannelCount(); i++)
{
const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i);
ChannelInstanceRegistration reg;
// if we have one instance available already, use it
for (int i = 0; i < openChannels.count(); i++)
{
qDebug("DeviceSet::loadChannelSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channelIdURI));
//if(openChannels[i].m_channelName == channelConfig.m_channelIdURI)
if (ChannelUtils::compareChannelURIs(openChannels[i].m_channelName, channelConfig.m_channelIdURI))
{
qDebug("DeviceSet::loadChannelSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName));
reg = openChannels.takeAt(i);
m_channelInstanceRegistrations.append(reg);
break;
}
}
// if we haven't one already, create one
if (reg.m_channelAPI == nullptr)
{
for (int i = 0; i < channelRegistrations->count(); i++)
{
//if((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI)
if (ChannelUtils::compareChannelURIs((*channelRegistrations)[i].m_channelIdURI, channelConfig.m_channelIdURI))
{
qDebug("DeviceSet::loadChannelSettings: creating new channel [%s] from config [%s]",
qPrintable((*channelRegistrations)[i].m_channelIdURI),
qPrintable(channelConfig.m_channelIdURI));
ChannelAPI *rxChannel = (*channelRegistrations)[i].m_plugin->createRxChannelCS(m_deviceAPI);
reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, rxChannel);
m_channelInstanceRegistrations.append(reg);
break;
}
}
}
if (reg.m_channelAPI != nullptr)
{
qDebug("DeviceSet::loadChannelSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channelIdURI));
reg.m_channelAPI->deserialize(channelConfig.m_config);
}
}
// everything, that is still "available" is not needed anymore
for (int i = 0; i < openChannels.count(); i++)
{
qDebug("DeviceSet::loadChannelSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName));
openChannels[i].m_channelAPI->destroy();
}
renameChannelInstances();
}
else
{
qDebug("DeviceSet::loadChannelSettings: Loading preset [%s | %s] not a source preset", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
}
}
void DeviceSet::saveRxChannelSettings(Preset *preset)
{
if (preset->isSourcePreset())
{
std::sort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
for (int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
qDebug("DeviceSet::saveChannelSettings: channel [%s] saved", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_channelAPI->serialize());
}
}
else
{
qDebug("DeviceSet::saveChannelSettings: not a source preset");
}
}
void DeviceSet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
{
if (preset->isSinkPreset())
{
qDebug("DeviceSet::loadTxChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
// Available channel plugins
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations();
// copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
m_channelInstanceRegistrations.clear();
qDebug("DeviceSet::loadTxChannelSettings: %d channel(s) in preset", preset->getChannelCount());
for (int i = 0; i < preset->getChannelCount(); i++)
{
const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i);
ChannelInstanceRegistration reg;
// if we have one instance available already, use it
for (int i = 0; i < openChannels.count(); i++)
{
qDebug("DeviceSet::loadTxChannelSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channelIdURI));
if (openChannels[i].m_channelName == channelConfig.m_channelIdURI)
{
qDebug("DeviceSet::loadTxChannelSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName));
reg = openChannels.takeAt(i);
m_channelInstanceRegistrations.append(reg);
break;
}
}
// if we haven't one already, create one
if (reg.m_channelAPI == nullptr)
{
for (int i = 0; i < channelRegistrations->count(); i++)
{
if ((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI)
{
qDebug("DeviceSet::loadTxChannelSettings: creating new channel [%s]", qPrintable(channelConfig.m_channelIdURI));
ChannelAPI *txChannel = (*channelRegistrations)[i].m_plugin->createTxChannelCS(m_deviceAPI);
reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, txChannel);
m_channelInstanceRegistrations.append(reg);
break;
}
}
}
if (reg.m_channelAPI != nullptr)
{
qDebug("DeviceSet::loadTxChannelSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channelIdURI));
reg.m_channelAPI->deserialize(channelConfig.m_config);
}
}
// everything, that is still "available" is not needed anymore
for (int i = 0; i < openChannels.count(); i++)
{
qDebug("DeviceSet::loadTxChannelSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName));
openChannels[i].m_channelAPI->destroy();
}
renameChannelInstances();
}
else
{
qDebug("DeviceSet::loadTxChannelSettings: Loading preset [%s | %s] not a sink preset", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
}
}
void DeviceSet::saveTxChannelSettings(Preset *preset)
{
if (preset->isSinkPreset())
{
std::sort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
for (int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
qDebug("DeviceSet::saveTxChannelSettings: channel [%s] saved", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_channelAPI->serialize());
}
}
else
{
qDebug("DeviceSet::saveTxChannelSettings: not a sink preset");
}
}
void DeviceSet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
{
if (preset->isMIMOPreset())
{
qDebug("DeviceSet::loadMIMOChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
// Available channel plugins
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getMIMOChannelRegistrations();
// copy currently open channels and clear list
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
m_channelInstanceRegistrations.clear();
qDebug("DeviceSet::loadMIMOChannelSettings: %d channel(s) in preset", preset->getChannelCount());
for (int i = 0; i < preset->getChannelCount(); i++)
{
const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i);
ChannelInstanceRegistration reg;
// if we have one instance available already, use it
for (int i = 0; i < openChannels.count(); i++)
{
qDebug("DeviceSet::loadMIMOChannelSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channelIdURI));
//if(openChannels[i].m_channelName == channelConfig.m_channelIdURI)
if (ChannelUtils::compareChannelURIs(openChannels[i].m_channelName, channelConfig.m_channelIdURI))
{
qDebug("DeviceSet::loadMIMOChannelSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName));
reg = openChannels.takeAt(i);
m_channelInstanceRegistrations.append(reg);
break;
}
}
// if we haven't one already, create one
if (reg.m_channelAPI == nullptr)
{
for (int i = 0; i < channelRegistrations->count(); i++)
{
//if((*channelRegistrations)[i].m_channelIdURI == channelConfig.m_channelIdURI)
if (ChannelUtils::compareChannelURIs((*channelRegistrations)[i].m_channelIdURI, channelConfig.m_channelIdURI))
{
qDebug("DeviceSet::loadMIMOChannelSettings: creating new channel [%s] from config [%s]",
qPrintable((*channelRegistrations)[i].m_channelIdURI),
qPrintable(channelConfig.m_channelIdURI));
ChannelAPI *mimoChannel = (*channelRegistrations)[i].m_plugin->createMIMOChannelCS(m_deviceAPI);
reg = ChannelInstanceRegistration(channelConfig.m_channelIdURI, mimoChannel);
m_channelInstanceRegistrations.append(reg);
break;
}
}
}
if (reg.m_channelAPI != nullptr)
{
qDebug("DeviceSet::loadMIMOChannelSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channelIdURI));
reg.m_channelAPI->deserialize(channelConfig.m_config);
}
}
// everything, that is still "available" is not needed anymore
for (int i = 0; i < openChannels.count(); i++)
{
qDebug("DeviceSet::loadMIMOChannelSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName));
openChannels[i].m_channelAPI->destroy();
}
renameChannelInstances();
}
else
{
qDebug("DeviceSet::loadChannelSettings: Loading preset [%s | %s] not a MIMO preset", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
}
}
void DeviceSet::saveMIMOChannelSettings(Preset *preset)
{
if (preset->isMIMOPreset())
{
std::sort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
for (int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
qDebug("DeviceSet::saveMIMOChannelSettings: channel [%s] saved", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_channelAPI->serialize());
}
}
else
{
qDebug("DeviceSet::saveMIMOChannelSettings: not a MIMO preset");
}
}
void DeviceSet::renameChannelInstances()
{
for (int i = 0; i < m_channelInstanceRegistrations.count(); i++)
{
m_channelInstanceRegistrations[i].m_channelAPI->setName(QString("%1:%2").arg(m_channelInstanceRegistrations[i].m_channelName).arg(i));
}
}
// sort by increasing delta frequency and type (i.e. name)
bool DeviceSet::ChannelInstanceRegistration::operator<(const ChannelInstanceRegistration& other) const
{
if (m_channelAPI && other.m_channelAPI)
{
if (m_channelAPI->getCenterFrequency() == other.m_channelAPI->getCenterFrequency())
{
return m_channelAPI->getName() < other.m_channelAPI->getName();
}
else
{
return m_channelAPI->getCenterFrequency() < other.m_channelAPI->getCenterFrequency();
}
}
else
{
return false;
}
}
int DeviceSet::webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const
{
return m_spectrumVis->webapiSpectrumSettingsGet(response, errorMessage);
}
int DeviceSet::webapiSpectrumSettingsPutPatch(
bool force,
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response, // query + response
QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumSettingsPutPatch(force, spectrumSettingsKeys, response, errorMessage);
}
int DeviceSet::webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const
{
return m_spectrumVis->webapiSpectrumServerGet(response, errorMessage);
}
int DeviceSet::webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumServerPost(response, errorMessage);
}
int DeviceSet::webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage)
{
return m_spectrumVis->webapiSpectrumServerDelete(response, errorMessage);
}

104
sdrsrv/device/deviceset.h Normal file
View File

@ -0,0 +1,104 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
// //
// 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 //
// (at your option) any later version. //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRSRV_DEVICE_DEVICESET_H_
#define SDRSRV_DEVICE_DEVICESET_H_
#include <QTimer>
class DeviceAPI;
class DSPDeviceSourceEngine;
class DSPDeviceSinkEngine;
class DSPDeviceMIMOEngine;
class PluginAPI;
class ChannelAPI;
class Preset;
class SpectrumVis;
namespace SWGSDRangel {
class SWGGLSpectrum;
class SWGSpectrumServer;
class SWGSuccessResponse;
};
class DeviceSet
{
public:
DeviceAPI *m_deviceAPI;
DSPDeviceSourceEngine *m_deviceSourceEngine;
DSPDeviceSinkEngine *m_deviceSinkEngine;
DSPDeviceMIMOEngine *m_deviceMIMOEngine;
SpectrumVis *m_spectrumVis;
DeviceSet(int tabIndex, int deviceType);
~DeviceSet();
int getNumberOfChannels() const { return m_channelInstanceRegistrations.size(); }
void addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
void addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
void addMIMOChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
void deleteChannel(int channelIndex);
void registerRxChannelInstance(const QString& channelName, ChannelAPI* channelAPI);
void registerTxChannelInstance(const QString& channelName, ChannelAPI* channelAPI);
void registerChannelInstance(const QString& channelName, ChannelAPI* channelAPI);
void removeRxChannelInstance(ChannelAPI* channelAPI);
void removeTxChannelInstance(ChannelAPI* channelAPI);
void removeChannelInstance(ChannelAPI* channelAPI);
void freeChannels();
void loadRxChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
void saveRxChannelSettings(Preset* preset);
void loadTxChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
void saveTxChannelSettings(Preset* preset);
void loadMIMOChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
void saveMIMOChannelSettings(Preset* preset);
// REST API
int webapiSpectrumSettingsGet(SWGSDRangel::SWGGLSpectrum& response, QString& errorMessage) const;
int webapiSpectrumSettingsPutPatch(
bool force,
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response, // query + response
QString& errorMessage);
int webapiSpectrumServerGet(SWGSDRangel::SWGSpectrumServer& response, QString& errorMessage) const;
int webapiSpectrumServerPost(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage);
int webapiSpectrumServerDelete(SWGSDRangel::SWGSuccessResponse& response, QString& errorMessage);
private:
struct ChannelInstanceRegistration
{
QString m_channelName;
ChannelAPI *m_channelAPI;
ChannelInstanceRegistration() :
m_channelName(),
m_channelAPI(nullptr)
{ }
ChannelInstanceRegistration(const QString& channelName, ChannelAPI* channelAPI);
bool operator<(const ChannelInstanceRegistration& other) const;
};
typedef QList<ChannelInstanceRegistration> ChannelInstanceRegistrations;
ChannelInstanceRegistrations m_channelInstanceRegistrations;
int m_deviceTabIndex;
void renameChannelInstances();
};
#endif /* SDRSRV_DEVICE_DEVICESET_H_ */

718
sdrsrv/maincore.cpp Normal file
View File

@ -0,0 +1,718 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 //
// (at your option) any later version. //
// //
// 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 <QDebug>
#include <QSysInfo>
#include <QResource>
#include "dsp/dspengine.h"
#include "dsp/dspdevicesourceengine.h"
#include "dsp/dspdevicesinkengine.h"
#include "dsp/dspdevicemimoengine.h"
#include "dsp/spectrumvis.h"
#include "device/deviceapi.h"
#include "device/deviceset.h"
#include "device/deviceenumerator.h"
#include "plugin/pluginmanager.h"
#include "loggerwithfile.h"
#include "webapi/webapirequestmapper.h"
#include "webapi/webapiserver.h"
#include "webapi/webapiadaptersrv.h"
#include "maincore.h"
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteInstance, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgLoadPreset, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgSavePreset, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeletePreset, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgAddDeviceSet, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgRemoveLastDeviceSet, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgSetDevice, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgAddChannel, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgDeleteChannel, Message)
MESSAGE_CLASS_DEFINITION(MainCore::MsgApplySettings, Message)
MainCore *MainCore::m_instance = 0;
MainCore::MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QObject *parent) :
QObject(parent),
m_settings(),
m_masterTabIndex(-1),
m_dspEngine(DSPEngine::instance()),
m_lastEngineState(DSPDeviceSourceEngine::StNotStarted),
m_logger(logger)
{
qDebug() << "MainCore::MainCore: start";
m_instance = this;
m_settings.setAudioDeviceManager(m_dspEngine->getAudioDeviceManager());
m_settings.setAMBEEngine(m_dspEngine->getAMBEEngine());
qDebug() << "MainCore::MainCore: create FFT factory...";
m_dspEngine->createFFTFactory(parser.getFFTWFWisdomFileName());
qDebug() << "MainCore::MainCore: load plugins...";
m_pluginManager = new PluginManager(this);
m_pluginManager->loadPlugins(QString("pluginssrv"));
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleMessages()), Qt::QueuedConnection);
m_masterTimer.start(50);
qDebug() << "MainCore::MainCore: load setings...";
loadSettings();
qDebug() << "MainCore::MainCore: finishing...";
QString applicationDirPath = QCoreApplication::instance()->applicationDirPath();
m_apiAdapter = new WebAPIAdapterSrv(*this);
m_requestMapper = new WebAPIRequestMapper(this);
m_requestMapper->setAdapter(m_apiAdapter);
m_apiServer = new WebAPIServer(parser.getServerAddress(), parser.getServerPort(), m_requestMapper);
m_apiServer->start();
m_dspEngine->setMIMOSupport(parser.getMIMOSupport());
qDebug() << "MainCore::MainCore: end";
}
MainCore::~MainCore()
{
while (m_deviceSets.size() > 0) {
removeLastDevice();
}
m_apiServer->stop();
m_settings.save();
delete m_apiServer;
delete m_requestMapper;
delete m_apiAdapter;
delete m_pluginManager;
qDebug() << "MainCore::~MainCore: end";
delete m_logger;
}
bool MainCore::handleMessage(const Message& cmd)
{
if (MsgDeleteInstance::match(cmd))
{
while (m_deviceSets.size() > 0)
{
removeLastDevice();
}
emit finished();
return true;
}
else if (MsgLoadPreset::match(cmd))
{
MsgLoadPreset& notif = (MsgLoadPreset&) cmd;
loadPresetSettings(notif.getPreset(), notif.getDeviceSetIndex());
return true;
}
else if (MsgSavePreset::match(cmd))
{
MsgSavePreset& notif = (MsgSavePreset&) cmd;
savePresetSettings(notif.getPreset(), notif.getDeviceSetIndex());
m_settings.sortPresets();
m_settings.save();
return true;
}
else if (MsgDeletePreset::match(cmd))
{
MsgDeletePreset& notif = (MsgDeletePreset&) cmd;
const Preset *presetToDelete = notif.getPreset();
// remove preset from settings
m_settings.deletePreset(presetToDelete);
return true;
}
else if (MsgAddDeviceSet::match(cmd))
{
MsgAddDeviceSet& notif = (MsgAddDeviceSet&) cmd;
int direction = notif.getDirection();
if (direction == 1) { // Single stream Tx
addSinkDevice();
} else if (direction == 0) { // Single stream Rx
addSourceDevice();
} else if (direction == 2) { // MIMO
addMIMODevice();
}
return true;
}
else if (MsgRemoveLastDeviceSet::match(cmd))
{
if (m_deviceSets.size() > 0) {
removeLastDevice();
}
return true;
}
else if (MsgSetDevice::match(cmd))
{
MsgSetDevice& notif = (MsgSetDevice&) cmd;
if (notif.getDeviceType() == 1) {
changeSampleSink(notif.getDeviceSetIndex(), notif.getDeviceIndex());
} else if (notif.getDeviceType() == 0) {
changeSampleSource(notif.getDeviceSetIndex(), notif.getDeviceIndex());
} else if (notif.getDeviceType() == 2) {
changeSampleMIMO(notif.getDeviceSetIndex(), notif.getDeviceIndex());
}
return true;
}
else if (MsgAddChannel::match(cmd))
{
MsgAddChannel& notif = (MsgAddChannel&) cmd;
addChannel(notif.getDeviceSetIndex(), notif.getChannelRegistrationIndex());
return true;
}
else if (MsgDeleteChannel::match(cmd))
{
MsgDeleteChannel& notif = (MsgDeleteChannel&) cmd;
deleteChannel(notif.getDeviceSetIndex(), notif.getChannelIndex());
return true;
}
else if (MsgApplySettings::match(cmd))
{
applySettings();
return true;
}
else
{
return false;
}
}
void MainCore::handleMessages()
{
Message* message;
while ((message = m_inputMessageQueue.pop()) != 0)
{
qDebug("MainCore::handleMessages: message: %s", message->getIdentifier());
handleMessage(*message);
delete message;
}
}
void MainCore::loadSettings()
{
qDebug() << "MainCore::loadSettings";
m_settings.load();
m_settings.sortPresets();
setLoggingOptions();
}
void MainCore::applySettings()
{
m_settings.sortPresets();
setLoggingOptions();
}
void MainCore::setLoggingOptions()
{
m_logger->setConsoleMinMessageLevel(m_settings.getConsoleMinLogLevel());
if (m_settings.getUseLogFile())
{
qtwebapp::FileLoggerSettings fileLoggerSettings; // default values
if (m_logger->hasFileLogger()) {
fileLoggerSettings = m_logger->getFileLoggerSettings(); // values from file logger if it exists
}
fileLoggerSettings.fileName = m_settings.getLogFileName(); // put new values
m_logger->createOrSetFileLogger(fileLoggerSettings, 2000); // create file logger if it does not exist and apply settings in any case
}
if (m_logger->hasFileLogger()) {
m_logger->setFileMinMessageLevel(m_settings.getFileMinLogLevel());
}
m_logger->setUseFileLogger(m_settings.getUseLogFile());
if (m_settings.getUseLogFile())
{
#if QT_VERSION >= 0x050400
QString appInfoStr(tr("%1 %2 Qt %3 %4b %5 %6 DSP Rx:%7b Tx:%8b PID %9")
.arg(QCoreApplication::applicationName())
.arg(QCoreApplication::applicationVersion())
.arg(QT_VERSION_STR)
.arg(QT_POINTER_SIZE*8)
.arg(QSysInfo::currentCpuArchitecture())
.arg(QSysInfo::prettyProductName())
.arg(SDR_RX_SAMP_SZ)
.arg(SDR_TX_SAMP_SZ)
.arg(QCoreApplication::applicationPid()));
#else
QString appInfoStr(tr("%1 %2 Qt %3 %4b DSP Rx:%5b Tx:%6b PID %7")
.arg(QCoreApplication::applicationName())
.arg(QCoreApplication::applicationVersion())
.arg(QT_VERSION_STR)
.arg(QT_POINTER_SIZE*8)
.arg(SDR_RX_SAMP_SZ)
.arg(SDR_RX_SAMP_SZ)
.arg(QCoreApplication::applicationPid());
#endif
m_logger->logToFile(QtInfoMsg, appInfoStr);
}
}
void MainCore::addSinkDevice()
{
DSPDeviceSinkEngine *dspDeviceSinkEngine = m_dspEngine->addDeviceSinkEngine();
dspDeviceSinkEngine->start();
uint dspDeviceSinkEngineUID = dspDeviceSinkEngine->getUID();
char uidCStr[16];
sprintf(uidCStr, "UID:%d", dspDeviceSinkEngineUID);
int deviceTabIndex = m_deviceSets.size();
m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 1));
m_deviceSets.back()->m_deviceSourceEngine = nullptr;
m_deviceSets.back()->m_deviceSinkEngine = dspDeviceSinkEngine;
m_deviceSets.back()->m_deviceMIMOEngine = nullptr;
dspDeviceSinkEngine->addSpectrumSink(m_deviceSets.back()->m_spectrumVis);
char tabNameCStr[16];
sprintf(tabNameCStr, "T%d", deviceTabIndex);
DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleTx, deviceTabIndex, nullptr, dspDeviceSinkEngine, nullptr);
m_deviceSets.back()->m_deviceAPI = deviceAPI;
QList<QString> channelNames;
// create a file sink by default
int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileSinkDeviceIndex();
const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceSets.back()->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
m_deviceSets.back()->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex));
QString userArgs = m_settings.getDeviceUserArgs().findUserArgs(samplingDevice->hardwareId, samplingDevice->sequence);
if (userArgs.size() > 0) {
m_deviceSets.back()->m_deviceAPI->setHardwareUserArguments(userArgs);
}
DeviceSampleSink *sink = m_deviceSets.back()->m_deviceAPI->getPluginInterface()->createSampleSinkPluginInstance(
m_deviceSets.back()->m_deviceAPI->getSamplingDeviceId(), m_deviceSets.back()->m_deviceAPI);
m_deviceSets.back()->m_deviceAPI->setSampleSink(sink);
}
void MainCore::addSourceDevice()
{
DSPDeviceSourceEngine *dspDeviceSourceEngine = m_dspEngine->addDeviceSourceEngine();
dspDeviceSourceEngine->start();
uint dspDeviceSourceEngineUID = dspDeviceSourceEngine->getUID();
char uidCStr[16];
sprintf(uidCStr, "UID:%d", dspDeviceSourceEngineUID);
int deviceTabIndex = m_deviceSets.size();
m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 0));
m_deviceSets.back()->m_deviceSourceEngine = dspDeviceSourceEngine;
m_deviceSets.back()->m_deviceSinkEngine = nullptr;
m_deviceSets.back()->m_deviceMIMOEngine = nullptr;
dspDeviceSourceEngine->addSink(m_deviceSets.back()->m_spectrumVis);
char tabNameCStr[16];
sprintf(tabNameCStr, "R%d", deviceTabIndex);
DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleRx, deviceTabIndex, dspDeviceSourceEngine, nullptr, nullptr);
m_deviceSets.back()->m_deviceAPI = deviceAPI;
// Create a file source instance by default
int fileSourceDeviceIndex = DeviceEnumerator::instance()->getFileInputDeviceIndex();
const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(fileSourceDeviceIndex);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceSets.back()->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
m_deviceSets.back()->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(fileSourceDeviceIndex));
QString userArgs = m_settings.getDeviceUserArgs().findUserArgs(samplingDevice->hardwareId, samplingDevice->sequence);
if (userArgs.size() > 0) {
m_deviceSets.back()->m_deviceAPI->setHardwareUserArguments(userArgs);
}
DeviceSampleSource *source = m_deviceSets.back()->m_deviceAPI->getPluginInterface()->createSampleSourcePluginInstance(
m_deviceSets.back()->m_deviceAPI->getSamplingDeviceId(), m_deviceSets.back()->m_deviceAPI);
m_deviceSets.back()->m_deviceAPI->setSampleSource(source);
}
void MainCore::addMIMODevice()
{
DSPDeviceMIMOEngine *dspDeviceMIMOEngine = m_dspEngine->addDeviceMIMOEngine();
dspDeviceMIMOEngine->start();
uint dspDeviceMIMOEngineUID = dspDeviceMIMOEngine->getUID();
char uidCStr[16];
sprintf(uidCStr, "UID:%d", dspDeviceMIMOEngineUID);
int deviceTabIndex = m_deviceSets.size();
m_deviceSets.push_back(new DeviceSet(deviceTabIndex, 2));
m_deviceSets.back()->m_deviceSourceEngine = nullptr;
m_deviceSets.back()->m_deviceSinkEngine = nullptr;
m_deviceSets.back()->m_deviceMIMOEngine = dspDeviceMIMOEngine;
dspDeviceMIMOEngine->addSpectrumSink(m_deviceSets.back()->m_spectrumVis);
char tabNameCStr[16];
sprintf(tabNameCStr, "M%d", deviceTabIndex);
DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamMIMO, deviceTabIndex, nullptr, nullptr, dspDeviceMIMOEngine);
// create a test MIMO by default
int testMIMODeviceIndex = DeviceEnumerator::instance()->getTestMIMODeviceIndex();
const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getMIMOSamplingDevice(testMIMODeviceIndex);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceSets.back()->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
m_deviceSets.back()->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
m_deviceSets.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceSets.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceSets.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getMIMOPluginInterface(testMIMODeviceIndex));
QString userArgs = m_settings.getDeviceUserArgs().findUserArgs(samplingDevice->hardwareId, samplingDevice->sequence);
if (userArgs.size() > 0) {
m_deviceSets.back()->m_deviceAPI->setHardwareUserArguments(userArgs);
}
DeviceSampleMIMO *mimo = m_deviceSets.back()->m_deviceAPI->getPluginInterface()->createSampleMIMOPluginInstance(
m_deviceSets.back()->m_deviceAPI->getSamplingDeviceId(), m_deviceSets.back()->m_deviceAPI);
m_deviceSets.back()->m_deviceAPI->setSampleMIMO(mimo);
}
void MainCore::removeLastDevice()
{
if (m_deviceSets.back()->m_deviceSourceEngine) // source set
{
DSPDeviceSourceEngine *lastDeviceEngine = m_deviceSets.back()->m_deviceSourceEngine;
lastDeviceEngine->stopAcquistion();
// deletes old UI and input object
m_deviceSets.back()->freeChannels(); // destroys the channel instances
m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId();
m_deviceSets.back()->m_deviceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput(
m_deviceSets.back()->m_deviceAPI->getSampleSource());
m_deviceSets.back()->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
DeviceAPI *sourceAPI = m_deviceSets.back()->m_deviceAPI;
delete m_deviceSets.back();
lastDeviceEngine->stop();
m_dspEngine->removeLastDeviceSourceEngine();
delete sourceAPI;
}
else if (m_deviceSets.back()->m_deviceSinkEngine) // sink set
{
DSPDeviceSinkEngine *lastDeviceEngine = m_deviceSets.back()->m_deviceSinkEngine;
lastDeviceEngine->stopGeneration();
// deletes old UI and output object
m_deviceSets.back()->freeChannels();
m_deviceSets.back()->m_deviceAPI->resetSamplingDeviceId();
m_deviceSets.back()->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput(
m_deviceSets.back()->m_deviceAPI->getSampleSink());
m_deviceSets.back()->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
DeviceAPI *sinkAPI = m_deviceSets.back()->m_deviceAPI;
delete m_deviceSets.back();
lastDeviceEngine->stop();
m_dspEngine->removeLastDeviceSinkEngine();
delete sinkAPI;
}
m_deviceSets.pop_back();
}
void MainCore::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex)
{
if (deviceSetIndex >= 0)
{
qDebug("MainCore::changeSampleSource: deviceSet at %d", deviceSetIndex);
DeviceSet *deviceSet = m_deviceSets[deviceSetIndex];
deviceSet->m_deviceAPI->saveSamplingDeviceSettings(m_settings.getWorkingPreset()); // save old API settings
deviceSet->m_deviceAPI->stopDeviceEngine();
// deletes old UI and input object
deviceSet->m_deviceAPI->resetSamplingDeviceId();
deviceSet->m_deviceAPI->getPluginInterface()->deleteSampleSourcePluginInstanceInput(
deviceSet->m_deviceAPI->getSampleSource());
deviceSet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(selectedDeviceIndex);
deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceSet->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
deviceSet->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
deviceSet->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceSet->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceSet->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceSet->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceSet->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(selectedDeviceIndex));
// add to buddies list
std::vector<DeviceSet*>::iterator it = m_deviceSets.begin();
int nbOfBuddies = 0;
for (; it != m_deviceSets.end(); ++it)
{
if (*it != deviceSet) // do not add to itself
{
if ((*it)->m_deviceSourceEngine) // it is a source device
{
if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) &&
(deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial()))
{
(*it)->m_deviceAPI->addSourceBuddy(deviceSet->m_deviceAPI);
nbOfBuddies++;
}
}
if ((*it)->m_deviceSinkEngine) // it is a sink device
{
if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) &&
(deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial()))
{
(*it)->m_deviceAPI->addSourceBuddy(deviceSet->m_deviceAPI);
nbOfBuddies++;
}
}
}
}
if (nbOfBuddies == 0) {
deviceSet->m_deviceAPI->setBuddyLeader(true);
}
// constructs new GUI and input object
DeviceSampleSource *source = deviceSet->m_deviceAPI->getPluginInterface()->createSampleSourcePluginInstance(
deviceSet->m_deviceAPI->getSamplingDeviceId(), deviceSet->m_deviceAPI);
deviceSet->m_deviceAPI->setSampleSource(source);
deviceSet->m_deviceAPI->loadSamplingDeviceSettings(m_settings.getWorkingPreset()); // load new API settings
}
}
void MainCore::changeSampleSink(int deviceSetIndex, int selectedDeviceIndex)
{
if (deviceSetIndex >= 0)
{
qDebug("MainCore::changeSampleSink: device set at %d", deviceSetIndex);
DeviceSet *deviceSet = m_deviceSets[deviceSetIndex];
deviceSet->m_deviceAPI->saveSamplingDeviceSettings(m_settings.getWorkingPreset()); // save old API settings
deviceSet->m_deviceAPI->stopDeviceEngine();
// deletes old UI and output object
deviceSet->m_deviceAPI->resetSamplingDeviceId();
deviceSet->m_deviceAPI->getPluginInterface()->deleteSampleSinkPluginInstanceOutput(
deviceSet->m_deviceAPI->getSampleSink());
deviceSet->m_deviceAPI->clearBuddiesLists(); // clear old API buddies lists
const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(selectedDeviceIndex);
deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceSet->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
deviceSet->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
deviceSet->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceSet->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceSet->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceSet->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceSet->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(selectedDeviceIndex));
// add to buddies list
std::vector<DeviceSet*>::iterator it = m_deviceSets.begin();
int nbOfBuddies = 0;
for (; it != m_deviceSets.end(); ++it)
{
if (*it != deviceSet) // do not add to itself
{
if ((*it)->m_deviceSourceEngine) // it is a source device
{
if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) &&
(deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial()))
{
(*it)->m_deviceAPI->addSinkBuddy(deviceSet->m_deviceAPI);
nbOfBuddies++;
}
}
if ((*it)->m_deviceSinkEngine) // it is a sink device
{
if ((deviceSet->m_deviceAPI->getHardwareId() == (*it)->m_deviceAPI->getHardwareId()) &&
(deviceSet->m_deviceAPI->getSamplingDeviceSerial() == (*it)->m_deviceAPI->getSamplingDeviceSerial()))
{
(*it)->m_deviceAPI->addSinkBuddy(deviceSet->m_deviceAPI);
nbOfBuddies++;
}
}
}
}
if (nbOfBuddies == 0) {
deviceSet->m_deviceAPI->setBuddyLeader(true);
}
// constructs new GUI and output object
DeviceSampleSink *sink = deviceSet->m_deviceAPI->getPluginInterface()->createSampleSinkPluginInstance(
deviceSet->m_deviceAPI->getSamplingDeviceId(), deviceSet->m_deviceAPI);
deviceSet->m_deviceAPI->setSampleSink(sink);
deviceSet->m_deviceAPI->loadSamplingDeviceSettings(m_settings.getWorkingPreset()); // load new API settings
}
}
void MainCore::changeSampleMIMO(int deviceSetIndex, int selectedDeviceIndex)
{
if (deviceSetIndex >= 0)
{
qDebug("MainCore::changeSampleMIMO: device set at %d", deviceSetIndex);
DeviceSet *deviceSet = m_deviceSets[deviceSetIndex];
deviceSet->m_deviceAPI->saveSamplingDeviceSettings(m_settings.getWorkingPreset()); // save old API settings
deviceSet->m_deviceAPI->stopDeviceEngine();
// deletes old UI and output object
deviceSet->m_deviceAPI->resetSamplingDeviceId();
deviceSet->m_deviceAPI->getPluginInterface()->deleteSampleMIMOPluginInstanceMIMO(
deviceSet->m_deviceAPI->getSampleMIMO());
const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getMIMOSamplingDevice(selectedDeviceIndex);
deviceSet->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceSet->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
deviceSet->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
deviceSet->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceSet->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceSet->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceSet->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceSet->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getMIMOPluginInterface(selectedDeviceIndex));
QString userArgs = m_settings.getDeviceUserArgs().findUserArgs(samplingDevice->hardwareId, samplingDevice->sequence);
if (userArgs.size() > 0) {
deviceSet->m_deviceAPI->setHardwareUserArguments(userArgs);
}
// constructs new GUI and MIMO object
DeviceSampleMIMO *mimo = deviceSet->m_deviceAPI->getPluginInterface()->createSampleMIMOPluginInstance(
deviceSet->m_deviceAPI->getSamplingDeviceId(), deviceSet->m_deviceAPI);
deviceSet->m_deviceAPI->setSampleMIMO(mimo);
deviceSet->m_deviceAPI->loadSamplingDeviceSettings(m_settings.getWorkingPreset()); // load new API settings
}
}
void MainCore::addChannel(int deviceSetIndex, int selectedChannelIndex)
{
if (deviceSetIndex >= 0)
{
DeviceSet *deviceSet = m_deviceSets[deviceSetIndex];
if (deviceSet->m_deviceSourceEngine) // source device => Rx channels
{
deviceSet->addRxChannel(selectedChannelIndex, m_pluginManager->getPluginAPI());
}
else if (deviceSet->m_deviceSinkEngine) // sink device => Tx channels
{
deviceSet->addTxChannel(selectedChannelIndex, m_pluginManager->getPluginAPI());
}
}
}
void MainCore::deleteChannel(int deviceSetIndex, int channelIndex)
{
if (deviceSetIndex >= 0)
{
DeviceSet *deviceSet = m_deviceSets[deviceSetIndex];
deviceSet->deleteChannel(channelIndex);
}
}
void MainCore::loadPresetSettings(const Preset* preset, int tabIndex)
{
qDebug("MainCore::loadPresetSettings: preset [%s | %s]",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()));
if (tabIndex >= 0)
{
DeviceSet *deviceSet = m_deviceSets[tabIndex];
deviceSet->m_deviceAPI->loadSamplingDeviceSettings(preset);
if (deviceSet->m_deviceSourceEngine) { // source device
deviceSet->loadRxChannelSettings(preset, m_pluginManager->getPluginAPI());
} else if (deviceSet->m_deviceSinkEngine) { // sink device
deviceSet->loadTxChannelSettings(preset, m_pluginManager->getPluginAPI());
} else if (deviceSet->m_deviceMIMOEngine) { // MIMO device
deviceSet->loadMIMOChannelSettings(preset, m_pluginManager->getPluginAPI());
}
}
}
void MainCore::savePresetSettings(Preset* preset, int tabIndex)
{
qDebug("MainCore::savePresetSettings: preset [%s | %s]",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()));
// Save from currently selected source tab
//int currentSourceTabIndex = ui->tabInputsView->currentIndex();
DeviceSet *deviceSet = m_deviceSets[tabIndex];
if (deviceSet->m_deviceSourceEngine) // source device
{
preset->clearChannels();
preset->setSourcePreset();
deviceSet->saveRxChannelSettings(preset);
deviceSet->m_deviceAPI->saveSamplingDeviceSettings(preset);
}
else if (deviceSet->m_deviceSinkEngine) // sink device
{
preset->clearChannels();
preset->setSinkPreset();
deviceSet->saveTxChannelSettings(preset);
deviceSet->m_deviceAPI->saveSamplingDeviceSettings(preset);
}
else if (deviceSet->m_deviceMIMOEngine) // MIMO device
{
preset->clearChannels();
preset->setMIMOPreset();
deviceSet->saveMIMOChannelSettings(preset);
deviceSet->m_deviceAPI->saveSamplingDeviceSettings(preset);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,370 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 //
// (at your option) any later version. //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRSRV_WEBAPI_WEBAPIADAPTERSRV_H_
#define SDRSRV_WEBAPI_WEBAPIADAPTERSRV_H_
#include <QtGlobal>
#include "webapi/webapiadapterinterface.h"
class MainCore;
class DeviceSet;
class WebAPIAdapterSrv: public WebAPIAdapterInterface
{
public:
WebAPIAdapterSrv(MainCore& mainCore);
virtual ~WebAPIAdapterSrv();
virtual int instanceSummary(
SWGSDRangel::SWGInstanceSummaryResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDelete(
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceConfigGet(
SWGSDRangel::SWGInstanceConfigResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceConfigPutPatch(
bool force, // PUT else PATCH
SWGSDRangel::SWGInstanceConfigResponse& query,
const ConfigKeys& configKeys,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDevices(
int direction,
SWGSDRangel::SWGInstanceDevicesResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceChannels(
int direction,
SWGSDRangel::SWGInstanceChannelsResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLoggingGet(
SWGSDRangel::SWGLoggingInfo& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLoggingPut(
SWGSDRangel::SWGLoggingInfo& query,
SWGSDRangel::SWGLoggingInfo& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAudioGet(
SWGSDRangel::SWGAudioDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAudioInputPatch(
SWGSDRangel::SWGAudioInputDevice& response,
const QStringList& audioInputKeys,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAudioOutputPatch(
SWGSDRangel::SWGAudioOutputDevice& response,
const QStringList& audioOutputKeys,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAudioInputDelete(
SWGSDRangel::SWGAudioInputDevice& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAudioOutputDelete(
SWGSDRangel::SWGAudioOutputDevice& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAudioInputCleanupPatch(
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAudioOutputCleanupPatch(
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLocationGet(
SWGSDRangel::SWGLocationInformation& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLocationPut(
SWGSDRangel::SWGLocationInformation& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDVSerialGet(
SWGSDRangel::SWGDVSerialDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDVSerialPatch(
bool dvserial,
SWGSDRangel::SWGDVSerialDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAMBESerialGet(
SWGSDRangel::SWGDVSerialDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAMBEDevicesGet(
SWGSDRangel::SWGAMBEDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAMBEDevicesPut(
SWGSDRangel::SWGAMBEDevices& query,
SWGSDRangel::SWGAMBEDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAMBEDevicesPatch(
SWGSDRangel::SWGAMBEDevices& query,
SWGSDRangel::SWGAMBEDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceAMBEDevicesDelete(
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
#ifdef HAS_LIMERFEUSB
virtual int instanceLimeRFESerialGet(
SWGSDRangel::SWGLimeRFEDevices& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFEConfigGet(
const QString& serial,
SWGSDRangel::SWGLimeRFESettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFEConfigPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFERunPut(
SWGSDRangel::SWGLimeRFESettings& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceLimeRFEPowerGet(
const QString& serial,
SWGSDRangel::SWGLimeRFEPower& response,
SWGSDRangel::SWGErrorResponse& error);
#endif
virtual int instancePresetFilePut(
SWGSDRangel::SWGPresetImport& query,
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instancePresetFilePost(
SWGSDRangel::SWGPresetExport& query,
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instancePresetsGet(
SWGSDRangel::SWGPresets& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instancePresetPatch(
SWGSDRangel::SWGPresetTransfer& query,
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instancePresetPut(
SWGSDRangel::SWGPresetTransfer& query,
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instancePresetPost(
SWGSDRangel::SWGPresetTransfer& query,
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instancePresetDelete(
SWGSDRangel::SWGPresetIdentifier& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDeviceSetsGet(
SWGSDRangel::SWGDeviceSetList& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDeviceSetPost(
int direction,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int instanceDeviceSetDelete(
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceSet& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetFocusPatch(
int deviceSetIndex,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDevicePut(
int deviceSetIndex,
SWGSDRangel::SWGDeviceListItem& query,
SWGSDRangel::SWGDeviceListItem& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGGLSpectrum& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumSettingsPutPatch(
int deviceSetIndex,
bool force, //!< true to force settings = put else patch
const QStringList& spectrumSettingsKeys,
SWGSDRangel::SWGGLSpectrum& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumServerGet(
int deviceSetIndex,
SWGSDRangel::SWGSpectrumServer& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumServerPost(
int deviceSetIndex,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetSpectrumServerDelete(
int deviceSetIndex,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceSettingsGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceActionsPost(
int deviceSetIndex,
const QStringList& deviceActionsKeys,
SWGSDRangel::SWGDeviceActions& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceSettingsPutPatch(
int deviceSetIndex,
bool force,
const QStringList& deviceSettingsKeys,
SWGSDRangel::SWGDeviceSettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceRunGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceState& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceRunPost(
int deviceSetIndex,
SWGSDRangel::SWGDeviceState& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceRunDelete(
int deviceSetIndex,
SWGSDRangel::SWGDeviceState& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceSubsystemRunGet(
int deviceSetIndex,
int subsystemIndex,
SWGSDRangel::SWGDeviceState& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceSubsystemRunPost(
int deviceSetIndex,
int subsystemIndex,
SWGSDRangel::SWGDeviceState& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceSubsystemRunDelete(
int deviceSetIndex,
int subsystemIndex,
SWGSDRangel::SWGDeviceState& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetDeviceReportGet(
int deviceSetIndex,
SWGSDRangel::SWGDeviceReport& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetChannelsReportGet(
int deviceSetIndex,
SWGSDRangel::SWGChannelsDetail& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetChannelPost(
int deviceSetIndex,
SWGSDRangel::SWGChannelSettings& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetChannelDelete(
int deviceSetIndex,
int channelIndex,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetChannelSettingsGet(
int deviceSetIndex,
int channelIndex,
SWGSDRangel::SWGChannelSettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetChannelActionsPost(
int deviceSetIndex,
int channelIndex,
const QStringList& channelActionsKeys,
SWGSDRangel::SWGChannelActions& query,
SWGSDRangel::SWGSuccessResponse& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetChannelSettingsPutPatch(
int deviceSetIndex,
int channelIndex,
bool force,
const QStringList& channelSettingsKeys,
SWGSDRangel::SWGChannelSettings& response,
SWGSDRangel::SWGErrorResponse& error);
virtual int devicesetChannelReportGet(
int deviceSetIndex,
int channelIndex,
SWGSDRangel::SWGChannelReport& response,
SWGSDRangel::SWGErrorResponse& error);
private:
MainCore& m_mainCore;
void getDeviceSetList(SWGSDRangel::SWGDeviceSetList* deviceSetList);
void getDeviceSet(SWGSDRangel::SWGDeviceSet *swgDeviceSet, const DeviceSet* deviceSet, int deviceUISetIndex);
void getChannelsDetail(SWGSDRangel::SWGChannelsDetail *channelsDetail, const DeviceSet* deviceSet);
static QtMsgType getMsgTypeFromString(const QString& msgTypeString);
static void getMsgTypeString(const QtMsgType& msgType, QString& level);
};
#endif /* SDRSRV_WEBAPI_WEBAPIADAPTERSRV_H_ */