2016-05-15 19:12:55 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2016 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 //
|
|
|
|
// //
|
|
|
|
// 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 "device/deviceapi.h"
|
2016-05-16 10:37:07 -04:00
|
|
|
#include "plugin/plugingui.h"
|
2016-05-16 12:53:01 -04:00
|
|
|
#include "plugin/pluginapi.h"
|
|
|
|
#include "plugin/plugininterface.h"
|
2016-05-15 21:21:21 -04:00
|
|
|
#include "gui/glspectrum.h"
|
|
|
|
#include "gui/channelwindow.h"
|
2016-05-16 10:02:55 -04:00
|
|
|
#include "mainwindow.h"
|
2016-05-16 11:47:22 -04:00
|
|
|
#include "settings/preset.h"
|
2016-05-16 10:02:55 -04:00
|
|
|
|
|
|
|
DeviceAPI::DeviceAPI(MainWindow *mainWindow,
|
|
|
|
int deviceTabIndex,
|
|
|
|
DSPDeviceEngine *deviceEngine,
|
|
|
|
GLSpectrum *glSpectrum,
|
|
|
|
ChannelWindow *channelWindow) :
|
|
|
|
m_mainWindow(mainWindow),
|
|
|
|
m_deviceTabIndex(deviceTabIndex),
|
2016-05-15 19:12:55 -04:00
|
|
|
m_deviceEngine(deviceEngine),
|
2016-05-15 21:21:21 -04:00
|
|
|
m_spectrum(glSpectrum),
|
2016-05-16 10:37:07 -04:00
|
|
|
m_channelWindow(channelWindow),
|
|
|
|
m_sampleSourceSequence(0),
|
|
|
|
m_sampleSourcePluginGUI(0)
|
2016-05-15 19:12:55 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceAPI::~DeviceAPI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-02 16:29:04 -04:00
|
|
|
void DeviceAPI::addSink(BasebandSampleSink *sink)
|
2016-05-15 19:12:55 -04:00
|
|
|
{
|
|
|
|
m_deviceEngine->addSink(sink);
|
|
|
|
}
|
|
|
|
|
2016-10-02 16:29:04 -04:00
|
|
|
void DeviceAPI::removeSink(BasebandSampleSink* sink)
|
2016-05-15 19:12:55 -04:00
|
|
|
{
|
|
|
|
m_deviceEngine->removeSink(sink);
|
|
|
|
}
|
|
|
|
|
2016-10-03 09:55:16 -04:00
|
|
|
void DeviceAPI::addThreadedSink(ThreadedBasebandSampleSink* sink)
|
2016-05-15 19:12:55 -04:00
|
|
|
{
|
|
|
|
m_deviceEngine->addThreadedSink(sink);
|
|
|
|
}
|
|
|
|
|
2016-10-03 09:55:16 -04:00
|
|
|
void DeviceAPI::removeThreadedSink(ThreadedBasebandSampleSink* sink)
|
2016-05-15 19:12:55 -04:00
|
|
|
{
|
|
|
|
m_deviceEngine->removeThreadedSink(sink);
|
|
|
|
}
|
|
|
|
|
2016-10-02 17:16:40 -04:00
|
|
|
void DeviceAPI::setSource(DeviceSampleSource* source)
|
2016-05-15 19:12:55 -04:00
|
|
|
{
|
|
|
|
m_deviceEngine->setSource(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeviceAPI::initAcquisition()
|
|
|
|
{
|
|
|
|
return m_deviceEngine->initAcquisition();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeviceAPI::startAcquisition()
|
|
|
|
{
|
|
|
|
return m_deviceEngine->startAcquisition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::stopAcquisition()
|
|
|
|
{
|
|
|
|
m_deviceEngine->stopAcquistion();
|
|
|
|
}
|
|
|
|
|
|
|
|
DSPDeviceEngine::State DeviceAPI::state() const
|
|
|
|
{
|
|
|
|
return m_deviceEngine->state();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DeviceAPI::errorMessage()
|
|
|
|
{
|
|
|
|
return m_deviceEngine->errorMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint DeviceAPI::getDeviceUID() const
|
|
|
|
{
|
|
|
|
return m_deviceEngine->getUID();
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueue *DeviceAPI::getDeviceInputMessageQueue()
|
|
|
|
{
|
|
|
|
return m_deviceEngine->getInputMessageQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueue *DeviceAPI::getDeviceOutputMessageQueue()
|
|
|
|
{
|
|
|
|
return m_deviceEngine->getOutputMessageQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection)
|
|
|
|
{
|
|
|
|
m_deviceEngine->configureCorrections(dcOffsetCorrection, iqImbalanceCorrection);
|
|
|
|
}
|
|
|
|
|
|
|
|
GLSpectrum *DeviceAPI::getSpectrum()
|
|
|
|
{
|
|
|
|
return m_spectrum;
|
|
|
|
}
|
2016-05-15 21:21:21 -04:00
|
|
|
|
|
|
|
void DeviceAPI::addChannelMarker(ChannelMarker* channelMarker)
|
|
|
|
{
|
|
|
|
m_spectrum->addChannelMarker(channelMarker);
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelWindow *DeviceAPI::getChannelWindow()
|
|
|
|
{
|
|
|
|
return m_channelWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::addRollupWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
m_channelWindow->addRollupWidget(widget);
|
|
|
|
}
|
|
|
|
|
2016-05-16 10:02:55 -04:00
|
|
|
void DeviceAPI::setInputGUI(QWidget* inputGUI, const QString& sourceDisplayName)
|
|
|
|
{
|
|
|
|
m_mainWindow->setInputGUI(m_deviceTabIndex, inputGUI, sourceDisplayName);
|
|
|
|
}
|
2016-05-16 10:37:07 -04:00
|
|
|
|
|
|
|
void DeviceAPI::setSampleSourceId(const QString& id)
|
|
|
|
{
|
|
|
|
m_sampleSourceId = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::setSampleSourceSerial(const QString& serial)
|
|
|
|
{
|
|
|
|
m_sampleSourceSerial = serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::setSampleSourceSequence(int sequence)
|
|
|
|
{
|
|
|
|
m_sampleSourceSequence = sequence;
|
2016-05-16 11:47:22 -04:00
|
|
|
m_deviceEngine->setSourceSequence(sequence);
|
2016-05-16 10:37:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::setSampleSourcePluginGUI(PluginGUI *gui)
|
|
|
|
{
|
2016-05-17 05:06:56 -04:00
|
|
|
if (m_sampleSourcePluginGUI != 0)
|
|
|
|
{
|
|
|
|
m_sampleSourcePluginGUI->destroy();
|
|
|
|
m_sampleSourceId.clear();
|
|
|
|
}
|
|
|
|
|
2016-05-16 10:37:07 -04:00
|
|
|
m_sampleSourcePluginGUI = gui;
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:53:01 -04:00
|
|
|
void DeviceAPI::registerChannelInstance(const QString& channelName, PluginGUI* pluginGUI)
|
|
|
|
{
|
|
|
|
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI));
|
|
|
|
renameChannelInstances();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::removeChannelInstance(PluginGUI* pluginGUI)
|
|
|
|
{
|
|
|
|
for(ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it)
|
|
|
|
{
|
|
|
|
if(it->m_gui == pluginGUI)
|
|
|
|
{
|
|
|
|
m_channelInstanceRegistrations.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renameChannelInstances();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::renameChannelInstances()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
|
|
|
|
{
|
|
|
|
m_channelInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_channelInstanceRegistrations[i].m_channelName).arg(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 10:37:07 -04:00
|
|
|
void DeviceAPI::freeAll()
|
|
|
|
{
|
2016-05-16 15:51:53 -04:00
|
|
|
// while(!m_channelInstanceRegistrations.isEmpty())
|
|
|
|
// {
|
|
|
|
// ChannelInstanceRegistration reg(m_channelInstanceRegistrations.takeLast());
|
|
|
|
// reg.m_gui->destroy();
|
|
|
|
// }
|
2016-05-16 10:37:07 -04:00
|
|
|
|
2016-05-16 15:51:53 -04:00
|
|
|
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
|
2016-05-16 12:53:01 -04:00
|
|
|
{
|
2016-05-16 18:04:27 -04:00
|
|
|
qDebug("DeviceAPI::freeAll: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
|
2016-05-16 15:51:53 -04:00
|
|
|
m_channelInstanceRegistrations[i].m_gui->destroy();
|
2016-05-16 12:53:01 -04:00
|
|
|
}
|
|
|
|
|
2016-05-16 15:51:53 -04:00
|
|
|
|
2016-05-16 18:04:27 -04:00
|
|
|
if(m_sampleSourcePluginGUI != 0)
|
|
|
|
{
|
|
|
|
qDebug("DeviceAPI::freeAll: destroying m_sampleSourcePluginGUI");
|
|
|
|
m_deviceEngine->setSource(0);
|
|
|
|
m_sampleSourcePluginGUI->destroy();
|
|
|
|
m_sampleSourcePluginGUI = 0;
|
|
|
|
m_sampleSourceId.clear();
|
|
|
|
}
|
2016-05-16 10:37:07 -04:00
|
|
|
}
|
2016-05-16 11:47:22 -04:00
|
|
|
|
|
|
|
void DeviceAPI::loadSourceSettings(const Preset* preset)
|
|
|
|
{
|
|
|
|
qDebug("DeviceAPI::loadSourceSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
|
|
|
|
|
|
|
|
if(m_sampleSourcePluginGUI != 0)
|
|
|
|
{
|
|
|
|
const QByteArray* sourceConfig = preset->findBestSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence);
|
|
|
|
|
|
|
|
if (sourceConfig != 0)
|
|
|
|
{
|
|
|
|
qDebug() << "DeviceAPI::loadSettings: deserializing source " << qPrintable(m_sampleSourceId);
|
|
|
|
m_sampleSourcePluginGUI->deserialize(*sourceConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 centerFrequency = preset->getCenterFrequency();
|
|
|
|
m_sampleSourcePluginGUI->setCenterFrequency(centerFrequency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceAPI::saveSourceSettings(Preset* preset)
|
|
|
|
{
|
|
|
|
qDebug("DeviceAPI::saveSourceSettings");
|
|
|
|
|
|
|
|
if(m_sampleSourcePluginGUI != NULL)
|
|
|
|
{
|
|
|
|
preset->addOrUpdateSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
|
|
|
|
preset->setCenterFrequency(m_sampleSourcePluginGUI->getCenterFrequency());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:53:01 -04:00
|
|
|
void DeviceAPI::loadChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
|
|
|
|
{
|
|
|
|
qDebug("DeviceAPI::loadChannelSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
|
|
|
|
|
|
|
|
// Available channel plugins
|
|
|
|
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getChannelRegistrations();
|
|
|
|
|
|
|
|
// copy currently open channels and clear list
|
|
|
|
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
|
|
|
|
m_channelInstanceRegistrations.clear();
|
|
|
|
|
|
|
|
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("PluginManager::loadSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel));
|
|
|
|
|
|
|
|
if(openChannels[i].m_channelName == channelConfig.m_channel)
|
|
|
|
{
|
|
|
|
qDebug("PluginManager::loadSettings: 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_gui == NULL)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < channelRegistrations->count(); i++)
|
|
|
|
{
|
|
|
|
if((*channelRegistrations)[i].m_channelName == channelConfig.m_channel)
|
|
|
|
{
|
|
|
|
qDebug("PluginManager::loadSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel));
|
|
|
|
reg = ChannelInstanceRegistration(channelConfig.m_channel, (*channelRegistrations)[i].m_plugin->createChannel(channelConfig.m_channel, this));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(reg.m_gui != NULL)
|
|
|
|
{
|
|
|
|
qDebug("PluginManager::loadSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channel));
|
|
|
|
reg.m_gui->deserialize(channelConfig.m_config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything, that is still "available" is not needed anymore
|
|
|
|
for(int i = 0; i < openChannels.count(); i++)
|
|
|
|
{
|
|
|
|
qDebug("PluginManager::loadSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName));
|
|
|
|
openChannels[i].m_gui->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
renameChannelInstances();
|
|
|
|
}
|
|
|
|
|
2016-05-16 12:34:23 -04:00
|
|
|
void DeviceAPI::saveChannelSettings(Preset *preset)
|
|
|
|
{
|
|
|
|
qDebug("DeviceAPI::saveChannelSettings");
|
|
|
|
|
|
|
|
qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
|
|
|
|
|
|
|
|
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
|
|
|
|
{
|
|
|
|
preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 11:47:22 -04:00
|
|
|
// sort by increasing delta frequency and type (i.e. name)
|
|
|
|
bool DeviceAPI::ChannelInstanceRegistration::operator<(const ChannelInstanceRegistration& other) const
|
|
|
|
{
|
|
|
|
if (m_gui && other.m_gui)
|
|
|
|
{
|
|
|
|
if (m_gui->getCenterFrequency() == other.m_gui->getCenterFrequency())
|
|
|
|
{
|
|
|
|
return m_gui->getName() < other.m_gui->getName();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_gui->getCenterFrequency() < other.m_gui->getCenterFrequency();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|