2020-12-19 19:53:03 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2020 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 <QDebug>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
|
|
|
|
|
|
|
#include "SWGFeatureSettings.h"
|
|
|
|
#include "SWGFeatureActions.h"
|
|
|
|
#include "SWGDeviceState.h"
|
|
|
|
|
2021-06-29 15:47:27 -04:00
|
|
|
#include "dsp/dspcommands.h"
|
2020-12-19 19:53:03 -05:00
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
#include "dsp/datafifo.h"
|
|
|
|
#include "dsp/dspdevicesourceengine.h"
|
|
|
|
#include "dsp/devicesamplesource.h"
|
|
|
|
#include "device/deviceset.h"
|
|
|
|
#include "channel/channelapi.h"
|
|
|
|
#include "maincore.h"
|
|
|
|
|
|
|
|
#include "demodanalyzerworker.h"
|
|
|
|
#include "demodanalyzer.h"
|
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(DemodAnalyzer::MsgConfigureDemodAnalyzer, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(DemodAnalyzer::MsgStartStop, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(DemodAnalyzer::MsgRefreshChannels, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(DemodAnalyzer::MsgReportChannels, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(DemodAnalyzer::MsgSelectChannel, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(DemodAnalyzer::MsgReportSampleRate, Message)
|
|
|
|
|
|
|
|
const char* const DemodAnalyzer::m_featureIdURI = "sdrangel.feature.demodanalyzer";
|
|
|
|
const char* const DemodAnalyzer::m_featureId = "DemodAnalyzer";
|
|
|
|
|
|
|
|
DemodAnalyzer::DemodAnalyzer(WebAPIAdapterInterface *webAPIAdapterInterface) :
|
|
|
|
Feature(m_featureIdURI, webAPIAdapterInterface),
|
|
|
|
m_spectrumVis(SDR_RX_SCALEF),
|
|
|
|
m_selectedChannel(nullptr),
|
2022-02-20 16:08:49 -05:00
|
|
|
m_dataPipe(nullptr)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
|
|
|
qDebug("DemodAnalyzer::DemodAnalyzer: webAPIAdapterInterface: %p", webAPIAdapterInterface);
|
|
|
|
setObjectName(m_featureId);
|
|
|
|
m_worker = new DemodAnalyzerWorker();
|
2021-11-25 04:28:59 -05:00
|
|
|
m_worker->moveToThread(&m_thread);
|
2021-06-05 13:26:26 -04:00
|
|
|
m_worker->setScopeVis(&m_scopeVis);
|
2020-12-19 19:53:03 -05:00
|
|
|
m_state = StIdle;
|
|
|
|
m_errorMessage = "DemodAnalyzer error";
|
2021-01-15 06:24:21 -05:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
DemodAnalyzer::~DemodAnalyzer()
|
|
|
|
{
|
2021-01-15 06:24:21 -05:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
2020-12-19 19:53:03 -05:00
|
|
|
if (m_worker->isRunning()) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete m_worker;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::start()
|
|
|
|
{
|
|
|
|
qDebug("DemodAnalyzer::start");
|
|
|
|
|
|
|
|
m_worker->setMessageQueueToFeature(getInputMessageQueue());
|
|
|
|
m_worker->reset();
|
|
|
|
bool ok = m_worker->startWork();
|
|
|
|
m_state = ok ? StRunning : StError;
|
|
|
|
m_thread.start();
|
|
|
|
|
|
|
|
DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker *msg
|
|
|
|
= DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker::create(m_settings, true);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
|
2022-02-20 16:08:49 -05:00
|
|
|
if (m_dataPipe)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
2022-02-20 16:08:49 -05:00
|
|
|
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
|
|
|
|
|
|
|
|
if (fifo)
|
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, true);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::stop()
|
|
|
|
{
|
|
|
|
qDebug("DemodAnalyzer::stop");
|
|
|
|
|
2022-02-20 16:08:49 -05:00
|
|
|
if (m_dataPipe)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
2022-02-20 16:08:49 -05:00
|
|
|
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
|
|
|
|
|
|
|
|
if (fifo)
|
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, false);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_worker->stopWork();
|
|
|
|
m_state = StIdle;
|
|
|
|
m_thread.quit();
|
|
|
|
m_thread.wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
double DemodAnalyzer::getMagSqAvg() const
|
|
|
|
{
|
|
|
|
return m_worker->getMagSqAvg();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DemodAnalyzer::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
if (MsgConfigureDemodAnalyzer::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureDemodAnalyzer& cfg = (MsgConfigureDemodAnalyzer&) cmd;
|
|
|
|
qDebug() << "DemodAnalyzer::handleMessage: MsgConfigureDemodAnalyzer";
|
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgStartStop::match(cmd))
|
|
|
|
{
|
|
|
|
MsgStartStop& cfg = (MsgStartStop&) cmd;
|
|
|
|
qDebug() << "DemodAnalyzer::handleMessage: MsgStartStop: start:" << cfg.getStartStop();
|
|
|
|
|
|
|
|
if (cfg.getStartStop()) {
|
|
|
|
start();
|
|
|
|
} else {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgRefreshChannels::match(cmd))
|
|
|
|
{
|
|
|
|
qDebug() << "DemodAnalyzer::handleMessage: MsgRefreshChannels";
|
|
|
|
updateChannels();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgSelectChannel::match(cmd))
|
|
|
|
{
|
|
|
|
qDebug() << "DemodAnalyzer::handleMessage: MsgSelectChannel";
|
|
|
|
MsgSelectChannel& cfg = (MsgSelectChannel&) cmd;
|
|
|
|
ChannelAPI *selectedChannel = cfg.getChannel();
|
|
|
|
setChannel(selectedChannel);
|
2021-06-29 15:47:27 -04:00
|
|
|
MainCore::MsgChannelDemodQuery *msg = MainCore::MsgChannelDemodQuery::create();
|
|
|
|
selectedChannel->getChannelMessageQueue()->push(msg);
|
2020-12-19 19:53:03 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MainCore::MsgChannelDemodReport::match(cmd))
|
|
|
|
{
|
|
|
|
qDebug() << "DemodAnalyzer::handleMessage: MainCore::MsgChannelDemodReport";
|
|
|
|
MainCore::MsgChannelDemodReport& report = (MainCore::MsgChannelDemodReport&) cmd;
|
|
|
|
|
|
|
|
if (report.getChannelAPI() == m_selectedChannel)
|
|
|
|
{
|
|
|
|
m_sampleRate = report.getSampleRate();
|
2021-06-29 15:47:27 -04:00
|
|
|
m_scopeVis.setLiveRate(m_sampleRate);
|
|
|
|
|
|
|
|
DSPSignalNotification *msg = new DSPSignalNotification(0, m_sampleRate);
|
|
|
|
m_spectrumVis.getInputMessageQueue()->push(msg);
|
2020-12-19 19:53:03 -05:00
|
|
|
|
2022-02-20 16:08:49 -05:00
|
|
|
if (m_dataPipe)
|
|
|
|
{
|
|
|
|
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
|
|
|
|
|
|
|
|
if (fifo) {
|
|
|
|
fifo->setSize(2*m_sampleRate);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgReportSampleRate *msg = MsgReportSampleRate::create(m_sampleRate);
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray DemodAnalyzer::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DemodAnalyzer::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::applySettings(const DemodAnalyzerSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "DemodAnalyzer::applySettings:"
|
2022-01-06 16:47:41 -05:00
|
|
|
<< " m_log2Decim: " << settings.m_log2Decim
|
2020-12-19 19:53:03 -05:00
|
|
|
<< " m_title: " << settings.m_title
|
|
|
|
<< " m_rgbColor: " << settings.m_rgbColor
|
|
|
|
<< " m_useReverseAPI: " << settings.m_useReverseAPI
|
|
|
|
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
|
|
|
|
<< " m_reverseAPIPort: " << settings.m_reverseAPIPort
|
|
|
|
<< " m_reverseAPIFeatureSetIndex: " << settings.m_reverseAPIFeatureSetIndex
|
|
|
|
<< " m_reverseAPIFeatureIndex: " << settings.m_reverseAPIFeatureIndex
|
|
|
|
<< " force: " << force;
|
|
|
|
|
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
2020-12-20 05:51:38 -05:00
|
|
|
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force) {
|
|
|
|
reverseAPIKeys.append("log2Decim");
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
if ((m_settings.m_title != settings.m_title) || force) {
|
|
|
|
reverseAPIKeys.append("title");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) {
|
|
|
|
reverseAPIKeys.append("rgbColor");
|
|
|
|
}
|
|
|
|
|
|
|
|
DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker *msg = DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker::create(
|
|
|
|
settings, force
|
|
|
|
);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
|
|
|
|
if (settings.m_useReverseAPI)
|
|
|
|
{
|
|
|
|
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
|
|
|
|
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
|
|
|
|
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
|
|
|
|
(m_settings.m_reverseAPIFeatureSetIndex != settings.m_reverseAPIFeatureSetIndex) ||
|
|
|
|
(m_settings.m_reverseAPIFeatureIndex != settings.m_reverseAPIFeatureIndex);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_settings = settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::updateChannels()
|
|
|
|
{
|
|
|
|
MainCore *mainCore = MainCore::instance();
|
|
|
|
// MessagePipes& messagePipes = mainCore->getMessagePipes();
|
|
|
|
std::vector<DeviceSet*>& deviceSets = mainCore->getDeviceSets();
|
|
|
|
std::vector<DeviceSet*>::const_iterator it = deviceSets.begin();
|
|
|
|
m_availableChannels.clear();
|
|
|
|
|
|
|
|
int deviceIndex = 0;
|
|
|
|
|
|
|
|
for (; it != deviceSets.end(); ++it, deviceIndex++)
|
|
|
|
{
|
|
|
|
DSPDeviceSourceEngine *deviceSourceEngine = (*it)->m_deviceSourceEngine;
|
|
|
|
DSPDeviceSinkEngine *deviceSinkEngine = (*it)->m_deviceSinkEngine;
|
|
|
|
|
|
|
|
if (deviceSourceEngine || deviceSinkEngine)
|
|
|
|
{
|
|
|
|
// DeviceSampleSource *deviceSource = deviceSourceEngine->getSource();
|
|
|
|
// quint64 deviceCenterFrequency = deviceSource->getCenterFrequency();
|
|
|
|
// int basebandSampleRate = deviceSource->getSampleRate();
|
|
|
|
|
|
|
|
for (int chi = 0; chi < (*it)->getNumberOfChannels(); chi++)
|
|
|
|
{
|
|
|
|
ChannelAPI *channel = (*it)->getChannelAt(chi);
|
|
|
|
int i = DemodAnalyzerSettings::m_channelURIs.indexOf(channel->getURI());
|
|
|
|
|
|
|
|
if (i >= 0)
|
|
|
|
{
|
|
|
|
DemodAnalyzerSettings::AvailableChannel availableChannel =
|
|
|
|
DemodAnalyzerSettings::AvailableChannel{
|
|
|
|
deviceSinkEngine != nullptr,
|
|
|
|
deviceIndex,
|
|
|
|
chi,
|
|
|
|
channel,
|
|
|
|
DemodAnalyzerSettings::m_channelTypes.at(i)
|
|
|
|
};
|
|
|
|
m_availableChannels[channel] = availableChannel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgReportChannels *msgToGUI = MsgReportChannels::create();
|
|
|
|
QList<DemodAnalyzerSettings::AvailableChannel>& msgAvailableChannels = msgToGUI->getAvailableChannels();
|
|
|
|
QHash<ChannelAPI*, DemodAnalyzerSettings::AvailableChannel>::iterator it = m_availableChannels.begin();
|
|
|
|
|
|
|
|
for (; it != m_availableChannels.end(); ++it) {
|
|
|
|
msgAvailableChannels.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
getMessageQueueToGUI()->push(msgToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::setChannel(ChannelAPI *selectedChannel)
|
|
|
|
{
|
|
|
|
if ((selectedChannel == m_selectedChannel) || !m_availableChannels.contains(selectedChannel)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainCore *mainCore = MainCore::instance();
|
|
|
|
|
|
|
|
if (m_selectedChannel)
|
|
|
|
{
|
2022-02-20 16:08:49 -05:00
|
|
|
ObjectPipe *pipe = mainCore->getDataPipes().unregisterProducerToConsumer(m_selectedChannel, this, "demod");
|
|
|
|
DataFifo *fifo = qobject_cast<DataFifo*>(pipe->m_element);
|
2020-12-19 19:53:03 -05:00
|
|
|
|
|
|
|
if ((fifo) && m_worker->isRunning())
|
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, false);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueue *messageQueue = mainCore->getMessagePipes().unregisterChannelToFeature(m_selectedChannel, this, "reportdemod");
|
|
|
|
disconnect(messageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleChannelMessageQueue(MessageQueue*)));
|
|
|
|
}
|
|
|
|
|
2022-02-20 16:08:49 -05:00
|
|
|
m_dataPipe = mainCore->getDataPipes().registerProducerToConsumer(selectedChannel, this, "demod");
|
2022-02-20 20:18:51 -05:00
|
|
|
connect(m_dataPipe, SIGNAL(toBeDeleted(int, QObject*)), this, SLOT(handleDataPipeToBeDeleted(int, QObject*)));
|
2022-02-20 16:08:49 -05:00
|
|
|
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
|
2020-12-19 19:53:03 -05:00
|
|
|
|
2022-02-20 16:08:49 -05:00
|
|
|
if (fifo)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
2022-02-20 16:08:49 -05:00
|
|
|
fifo->setSize(96000);
|
|
|
|
|
|
|
|
if (m_worker->isRunning())
|
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, true);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueue *messageQueue = mainCore->getMessagePipes().registerChannelToFeature(selectedChannel, this, "reportdemod");
|
|
|
|
|
|
|
|
QObject::connect(
|
|
|
|
messageQueue,
|
|
|
|
&MessageQueue::messageEnqueued,
|
|
|
|
this,
|
|
|
|
[=](){ this->handleChannelMessageQueue(messageQueue); },
|
|
|
|
Qt::QueuedConnection
|
|
|
|
);
|
|
|
|
|
|
|
|
m_selectedChannel = selectedChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DemodAnalyzer::webapiRun(bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
getFeatureStateStr(*response.getState());
|
|
|
|
MsgStartStop *msg = MsgStartStop::create(run);
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
return 202;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DemodAnalyzer::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
response.setDemodAnalyzerSettings(new SWGSDRangel::SWGDemodAnalyzerSettings());
|
|
|
|
response.getDemodAnalyzerSettings()->init();
|
|
|
|
webapiFormatFeatureSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DemodAnalyzer::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& featureSettingsKeys,
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
DemodAnalyzerSettings settings = m_settings;
|
|
|
|
webapiUpdateFeatureSettings(settings, featureSettingsKeys, response);
|
|
|
|
|
|
|
|
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
qDebug("DemodAnalyzer::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureDemodAnalyzer *msgToGUI = MsgConfigureDemodAnalyzer::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatFeatureSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::webapiFormatFeatureSettings(
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response,
|
|
|
|
const DemodAnalyzerSettings& settings)
|
|
|
|
{
|
|
|
|
if (response.getDemodAnalyzerSettings()->getTitle()) {
|
|
|
|
*response.getDemodAnalyzerSettings()->getTitle() = settings.m_title;
|
|
|
|
} else {
|
|
|
|
response.getDemodAnalyzerSettings()->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
|
2020-12-20 13:01:54 -05:00
|
|
|
response.getDemodAnalyzerSettings()->setLog2Decim(settings.m_log2Decim);
|
2020-12-19 19:53:03 -05:00
|
|
|
response.getDemodAnalyzerSettings()->setRgbColor(settings.m_rgbColor);
|
|
|
|
response.getDemodAnalyzerSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getDemodAnalyzerSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getDemodAnalyzerSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getDemodAnalyzerSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getDemodAnalyzerSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
2021-09-16 18:52:08 -04:00
|
|
|
response.getDemodAnalyzerSettings()->setReverseApiFeatureSetIndex(settings.m_reverseAPIFeatureSetIndex);
|
|
|
|
response.getDemodAnalyzerSettings()->setReverseApiFeatureIndex(settings.m_reverseAPIFeatureIndex);
|
2021-11-30 18:20:14 -05:00
|
|
|
|
|
|
|
if (settings.m_spectrumGUI)
|
|
|
|
{
|
|
|
|
if (response.getDemodAnalyzerSettings()->getSpectrumConfig())
|
|
|
|
{
|
|
|
|
settings.m_spectrumGUI->formatTo(response.getDemodAnalyzerSettings()->getSpectrumConfig());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGGLSpectrum *swgGLSpectrum = new SWGSDRangel::SWGGLSpectrum();
|
|
|
|
settings.m_spectrumGUI->formatTo(swgGLSpectrum);
|
|
|
|
response.getDemodAnalyzerSettings()->setSpectrumConfig(swgGLSpectrum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.m_scopeGUI)
|
|
|
|
{
|
|
|
|
if (response.getDemodAnalyzerSettings()->getScopeConfig())
|
|
|
|
{
|
|
|
|
settings.m_scopeGUI->formatTo(response.getDemodAnalyzerSettings()->getScopeConfig());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGGLScope *swgGLScope = new SWGSDRangel::SWGGLScope();
|
|
|
|
settings.m_scopeGUI->formatTo(swgGLScope);
|
|
|
|
response.getDemodAnalyzerSettings()->setScopeConfig(swgGLScope);
|
|
|
|
}
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
|
|
|
|
if (settings.m_rollupState)
|
|
|
|
{
|
|
|
|
if (response.getDemodAnalyzerSettings()->getRollupState())
|
|
|
|
{
|
|
|
|
settings.m_rollupState->formatTo(response.getDemodAnalyzerSettings()->getRollupState());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
response.getDemodAnalyzerSettings()->setRollupState(swgRollupState);
|
|
|
|
}
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::webapiUpdateFeatureSettings(
|
|
|
|
DemodAnalyzerSettings& settings,
|
|
|
|
const QStringList& featureSettingsKeys,
|
|
|
|
SWGSDRangel::SWGFeatureSettings& response)
|
|
|
|
{
|
2020-12-20 13:01:54 -05:00
|
|
|
if (featureSettingsKeys.contains("log2Decim")) {
|
|
|
|
settings.m_log2Decim = response.getDemodAnalyzerSettings()->getLog2Decim();
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
if (featureSettingsKeys.contains("title")) {
|
|
|
|
settings.m_title = *response.getDemodAnalyzerSettings()->getTitle();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("rgbColor")) {
|
|
|
|
settings.m_rgbColor = response.getDemodAnalyzerSettings()->getRgbColor();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getDemodAnalyzerSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("reverseAPIAddress")) {
|
|
|
|
settings.m_reverseAPIAddress = *response.getDemodAnalyzerSettings()->getReverseApiAddress();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getDemodAnalyzerSettings()->getReverseApiPort();
|
|
|
|
}
|
2021-09-16 18:52:08 -04:00
|
|
|
if (featureSettingsKeys.contains("reverseAPIFeatureSetIndex")) {
|
|
|
|
settings.m_reverseAPIFeatureSetIndex = response.getDemodAnalyzerSettings()->getReverseApiFeatureSetIndex();
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
2021-09-16 18:52:08 -04:00
|
|
|
if (featureSettingsKeys.contains("reverseAPIFeatureIndex")) {
|
|
|
|
settings.m_reverseAPIFeatureIndex = response.getDemodAnalyzerSettings()->getReverseApiFeatureIndex();
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
2021-11-30 18:20:14 -05:00
|
|
|
if (settings.m_spectrumGUI && featureSettingsKeys.contains("spectrumConfig")) {
|
|
|
|
settings.m_spectrumGUI->updateFrom(featureSettingsKeys, response.getDemodAnalyzerSettings()->getSpectrumConfig());
|
|
|
|
}
|
|
|
|
if (settings.m_scopeGUI && featureSettingsKeys.contains("scopeConfig")) {
|
|
|
|
settings.m_scopeGUI->updateFrom(featureSettingsKeys, response.getDemodAnalyzerSettings()->getScopeConfig());
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
if (settings.m_rollupState && featureSettingsKeys.contains("rollupState")) {
|
|
|
|
settings.m_rollupState->updateFrom(featureSettingsKeys, response.getDemodAnalyzerSettings()->getRollupState());
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const DemodAnalyzerSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings();
|
|
|
|
// swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet());
|
|
|
|
// swgFeatureSettings->setOriginatorFeatureSetIndex(getDeviceSetIndex());
|
|
|
|
swgFeatureSettings->setFeatureType(new QString("DemodAnalyzer"));
|
|
|
|
swgFeatureSettings->setDemodAnalyzerSettings(new SWGSDRangel::SWGDemodAnalyzerSettings());
|
|
|
|
SWGSDRangel::SWGDemodAnalyzerSettings *swgDemodAnalyzerSettings = swgFeatureSettings->getDemodAnalyzerSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
2020-12-20 13:01:54 -05:00
|
|
|
if (featureSettingsKeys.contains("log2Decim") || force) {
|
|
|
|
swgDemodAnalyzerSettings->setLog2Decim(settings.m_log2Decim);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
if (featureSettingsKeys.contains("title") || force) {
|
|
|
|
swgDemodAnalyzerSettings->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("rgbColor") || force) {
|
|
|
|
swgDemodAnalyzerSettings->setRgbColor(settings.m_rgbColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/featureset/%3/feature/%4/settings")
|
|
|
|
.arg(settings.m_reverseAPIAddress)
|
|
|
|
.arg(settings.m_reverseAPIPort)
|
|
|
|
.arg(settings.m_reverseAPIFeatureSetIndex)
|
|
|
|
.arg(settings.m_reverseAPIFeatureIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer = new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgFeatureSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
|
|
|
QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
buffer->setParent(reply);
|
|
|
|
|
|
|
|
delete swgFeatureSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "DemodAnalyzer::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("DemodAnalyzer::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
reply->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::handleChannelMessageQueue(MessageQueue* messageQueue)
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = messageQueue->pop()) != nullptr)
|
|
|
|
{
|
|
|
|
if (handleMessage(*message)) {
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-20 20:18:51 -05:00
|
|
|
|
|
|
|
void DemodAnalyzer::handleDataPipeToBeDeleted(int reason, QObject *object)
|
|
|
|
{
|
|
|
|
qDebug("DemodAnalyzer::handleDataPipeToBeDeleted: %d %p", reason, object);
|
|
|
|
|
|
|
|
if ((reason == 0) && (m_selectedChannel == object))
|
|
|
|
{
|
|
|
|
DataFifo *fifo = qobject_cast<DataFifo*>(m_dataPipe->m_element);
|
|
|
|
|
|
|
|
if (fifo && m_worker->isRunning())
|
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, false);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateChannels();
|
|
|
|
m_selectedChannel = nullptr;
|
|
|
|
}
|
|
|
|
}
|