2020-12-19 19:53:03 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-18 07:12:18 -05:00
|
|
|
// Copyright (C) 2020-2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
|
|
|
// Copyright (C) 2021 Jon Beniston, M7RCE <jon@beniston.com> //
|
2020-12-19 19:53:03 -05:00
|
|
|
// //
|
|
|
|
// 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/datafifo.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::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),
|
2022-09-21 15:54:01 -04:00
|
|
|
m_thread(nullptr),
|
|
|
|
m_running(false),
|
|
|
|
m_worker(nullptr),
|
2020-12-19 19:53:03 -05:00
|
|
|
m_spectrumVis(SDR_RX_SCALEF),
|
2024-03-05 06:02:10 -05:00
|
|
|
m_availableChannelOrFeatureHandler(DemodAnalyzerSettings::m_channelURIs),
|
2020-12-19 19:53:03 -05:00
|
|
|
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_state = StIdle;
|
|
|
|
m_errorMessage = "DemodAnalyzer error";
|
2021-01-15 06:24:21 -05:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::connect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&DemodAnalyzer::networkManagerFinished
|
|
|
|
);
|
2024-03-05 05:28:01 -05:00
|
|
|
QObject::connect(
|
|
|
|
&m_availableChannelOrFeatureHandler,
|
|
|
|
&AvailableChannelOrFeatureHandler::channelsOrFeaturesChanged,
|
|
|
|
this,
|
|
|
|
&DemodAnalyzer::channelsOrFeaturesChanged
|
|
|
|
);
|
|
|
|
m_availableChannelOrFeatureHandler.scanAvailableChannelsAndFeatures();
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
DemodAnalyzer::~DemodAnalyzer()
|
|
|
|
{
|
2024-03-05 05:28:01 -05:00
|
|
|
QObject::disconnect(
|
|
|
|
&m_availableChannelOrFeatureHandler,
|
|
|
|
&AvailableChannelOrFeatureHandler::channelsOrFeaturesChanged,
|
|
|
|
this,
|
|
|
|
&DemodAnalyzer::channelsOrFeaturesChanged
|
|
|
|
);
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::disconnect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&DemodAnalyzer::networkManagerFinished
|
|
|
|
);
|
2021-01-15 06:24:21 -05:00
|
|
|
delete m_networkManager;
|
2022-09-21 15:54:01 -04:00
|
|
|
stop();
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::start()
|
|
|
|
{
|
2022-09-21 15:54:01 -04:00
|
|
|
QMutexLocker m_lock(&m_mutex);
|
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-19 19:53:03 -05:00
|
|
|
qDebug("DemodAnalyzer::start");
|
2022-09-21 15:54:01 -04:00
|
|
|
m_thread = new QThread();
|
|
|
|
m_worker = new DemodAnalyzerWorker();
|
|
|
|
m_worker->moveToThread(m_thread);
|
2020-12-19 19:53:03 -05:00
|
|
|
|
2022-09-21 15:54:01 -04:00
|
|
|
QObject::connect(
|
|
|
|
m_thread,
|
|
|
|
&QThread::started,
|
|
|
|
m_worker,
|
|
|
|
&DemodAnalyzerWorker::startWork
|
|
|
|
);
|
|
|
|
QObject::connect(
|
|
|
|
m_thread,
|
|
|
|
&QThread::finished,
|
|
|
|
m_worker,
|
|
|
|
&QObject::deleteLater
|
|
|
|
);
|
|
|
|
QObject::connect(
|
|
|
|
m_thread,
|
|
|
|
&QThread::finished,
|
|
|
|
m_thread,
|
|
|
|
&QThread::deleteLater
|
|
|
|
);
|
|
|
|
|
|
|
|
m_worker->setScopeVis(&m_scopeVis);
|
2020-12-19 19:53:03 -05:00
|
|
|
m_worker->setMessageQueueToFeature(getInputMessageQueue());
|
2022-09-21 15:54:01 -04:00
|
|
|
m_worker->startWork();
|
|
|
|
m_state = StRunning;
|
|
|
|
m_thread->start();
|
2020-12-19 19:53:03 -05:00
|
|
|
|
|
|
|
DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker *msg
|
2022-11-23 17:08:41 -05:00
|
|
|
= DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker::create(m_settings, QList<QString>(), true);
|
2020-12-19 19:53:03 -05:00
|
|
|
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
|
|
|
}
|
2022-09-21 15:54:01 -04:00
|
|
|
|
|
|
|
m_running = true;
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void DemodAnalyzer::stop()
|
|
|
|
{
|
2022-09-21 15:54:01 -04:00
|
|
|
QMutexLocker m_lock(&m_mutex);
|
|
|
|
|
|
|
|
if (!m_running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-19 19:53:03 -05:00
|
|
|
qDebug("DemodAnalyzer::stop");
|
2022-09-21 15:54:01 -04:00
|
|
|
m_running = false;
|
2020-12-19 19:53:03 -05:00
|
|
|
|
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;
|
2022-09-21 15:54:01 -04:00
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double DemodAnalyzer::getMagSqAvg() const
|
|
|
|
{
|
2022-09-21 15:54:01 -04:00
|
|
|
return m_running ? m_worker->getMagSqAvg() : 0.0;
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DemodAnalyzer::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
if (MsgConfigureDemodAnalyzer::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureDemodAnalyzer& cfg = (MsgConfigureDemodAnalyzer&) cmd;
|
|
|
|
qDebug() << "DemodAnalyzer::handleMessage: MsgConfigureDemodAnalyzer";
|
2022-11-23 17:08:41 -05:00
|
|
|
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());
|
2020-12-19 19:53:03 -05:00
|
|
|
|
|
|
|
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 (MsgSelectChannel::match(cmd))
|
|
|
|
{
|
|
|
|
MsgSelectChannel& cfg = (MsgSelectChannel&) cmd;
|
|
|
|
ChannelAPI *selectedChannel = cfg.getChannel();
|
2022-02-25 17:43:50 -05:00
|
|
|
qDebug("DemodAnalyzer::handleMessage: MsgSelectChannel: %p %s",
|
|
|
|
selectedChannel, qPrintable(selectedChannel->objectName()));
|
2020-12-19 19:53:03 -05:00
|
|
|
setChannel(selectedChannel);
|
2021-06-29 15:47:27 -04:00
|
|
|
MainCore::MsgChannelDemodQuery *msg = MainCore::MsgChannelDemodQuery::create();
|
2022-02-25 17:43:50 -05:00
|
|
|
selectedChannel->getInputMessageQueue()->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);
|
|
|
|
|
2022-11-13 13:53:22 -05:00
|
|
|
if (m_running) {
|
|
|
|
m_worker->applySampleRate(m_sampleRate);
|
|
|
|
}
|
|
|
|
|
2021-06-29 15:47:27 -04:00
|
|
|
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))
|
|
|
|
{
|
2022-11-23 17:08:41 -05:00
|
|
|
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(m_settings, QList<QString>(), true);
|
2020-12-19 19:53:03 -05:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
2022-11-23 17:08:41 -05:00
|
|
|
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(m_settings, QList<QString>(), true);
|
2020-12-19 19:53:03 -05:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 17:08:41 -05:00
|
|
|
void DemodAnalyzer::applySettings(const DemodAnalyzerSettings& settings, const QList<QString>& settingsKeys, bool force)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
2022-11-23 17:08:41 -05:00
|
|
|
qDebug() << "DemodAnalyzer::applySettings:" << settings.getDebugString(settingsKeys, force) << " force: " << force;
|
2020-12-19 19:53:03 -05:00
|
|
|
|
2022-09-21 15:54:01 -04:00
|
|
|
if (m_running)
|
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker *msg = DemodAnalyzerWorker::MsgConfigureDemodAnalyzerWorker::create(
|
2022-11-23 17:08:41 -05:00
|
|
|
settings, settingsKeys, force
|
2022-09-21 15:54:01 -04:00
|
|
|
);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
2020-12-19 19:53:03 -05:00
|
|
|
|
2024-04-14 12:58:12 -04:00
|
|
|
if (settings.m_useReverseAPI)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
2022-11-23 17:08:41 -05:00
|
|
|
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
|
|
|
|
settingsKeys.contains("reverseAPIAddress") ||
|
|
|
|
settingsKeys.contains("reverseAPIPort") ||
|
|
|
|
settingsKeys.contains("reverseAPIFeatureSetIndex") ||
|
|
|
|
settingsKeys.contains("m_reverseAPIFeatureIndex");
|
|
|
|
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
2022-11-23 17:08:41 -05:00
|
|
|
if (force) {
|
|
|
|
m_settings = settings;
|
|
|
|
} else {
|
|
|
|
m_settings.applySettings(settingsKeys, settings);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
2024-03-05 05:28:01 -05:00
|
|
|
void DemodAnalyzer::channelsOrFeaturesChanged(const QStringList& renameFrom, const QStringList& renameTo)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
2024-03-05 05:28:01 -05:00
|
|
|
m_availableChannels = m_availableChannelOrFeatureHandler.getAvailableChannelOrFeatureList();
|
|
|
|
notifyUpdate(renameFrom, renameTo);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
|
2024-03-05 05:28:01 -05:00
|
|
|
void DemodAnalyzer::notifyUpdate(const QStringList& renameFrom, const QStringList& renameTo)
|
|
|
|
{
|
2020-12-19 19:53:03 -05:00
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
2024-03-05 05:28:01 -05:00
|
|
|
MsgReportChannels *msg = MsgReportChannels::create(renameFrom, renameTo);
|
|
|
|
msg->getAvailableChannels() = m_availableChannels;
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-05 11:13:03 -04:00
|
|
|
void DemodAnalyzer::getAvailableChannelsReport()
|
|
|
|
{
|
|
|
|
notifyUpdate(QStringList{}, QStringList{});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-19 19:53:03 -05:00
|
|
|
void DemodAnalyzer::setChannel(ChannelAPI *selectedChannel)
|
|
|
|
{
|
2024-03-05 05:28:01 -05:00
|
|
|
if ((selectedChannel == m_selectedChannel) || (m_availableChannels.indexOfObject(selectedChannel) == -1)) {
|
2020-12-19 19:53:03 -05:00
|
|
|
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
|
|
|
|
2022-09-21 15:54:01 -04:00
|
|
|
if ((fifo) && m_running)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, false);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
2022-03-02 17:57:35 -05:00
|
|
|
ObjectPipe *messagePipe = mainCore->getMessagePipes().unregisterProducerToConsumer(m_selectedChannel, this, "reportdemod");
|
2022-02-25 17:43:50 -05:00
|
|
|
|
|
|
|
if (messagePipe)
|
|
|
|
{
|
|
|
|
MessageQueue *messageQueue = qobject_cast<MessageQueue*>(messagePipe->m_element);
|
|
|
|
|
|
|
|
if (messageQueue) {
|
2023-04-01 23:04:18 -04:00
|
|
|
disconnect(messageQueue, &MessageQueue::messageEnqueued, this, nullptr); // Have to use nullptr, as slot is a lambda.
|
2022-02-25 17:43:50 -05:00
|
|
|
}
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2022-09-21 15:54:01 -04:00
|
|
|
if (m_running)
|
2022-02-20 16:08:49 -05:00
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, true);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
2022-03-02 17:57:35 -05:00
|
|
|
ObjectPipe *messagePipe = mainCore->getMessagePipes().registerProducerToConsumer(selectedChannel, this, "reportdemod");
|
2020-12-19 19:53:03 -05:00
|
|
|
|
2022-02-25 17:43:50 -05:00
|
|
|
if (messagePipe)
|
|
|
|
{
|
|
|
|
MessageQueue *messageQueue = qobject_cast<MessageQueue*>(messagePipe->m_element);
|
|
|
|
|
|
|
|
if (messageQueue)
|
|
|
|
{
|
|
|
|
QObject::connect(
|
|
|
|
messageQueue,
|
|
|
|
&MessageQueue::messageEnqueued,
|
|
|
|
this,
|
|
|
|
[=](){ this->handleChannelMessageQueue(messageQueue); },
|
|
|
|
Qt::QueuedConnection
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2022-11-23 17:08:41 -05:00
|
|
|
MsgConfigureDemodAnalyzer *msg = MsgConfigureDemodAnalyzer::create(settings, featureSettingsKeys, force);
|
2020-12-19 19:53:03 -05:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
qDebug("DemodAnalyzer::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2022-11-23 17:08:41 -05:00
|
|
|
MsgConfigureDemodAnalyzer *msgToGUI = MsgConfigureDemodAnalyzer::create(settings, featureSettingsKeys, force);
|
2020-12-19 19:53:03 -05:00
|
|
|
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
|
|
|
|
2022-11-13 16:24:03 -05:00
|
|
|
if (response.getDemodAnalyzerSettings()->getFileRecordName()) {
|
|
|
|
*response.getDemodAnalyzerSettings()->getFileRecordName() = settings.m_fileRecordName;
|
|
|
|
} else {
|
|
|
|
response.getDemodAnalyzerSettings()->setFileRecordName(new QString(settings.m_fileRecordName));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getDemodAnalyzerSettings()->setRecordToFile(settings.m_recordToFile ? 1 : 0);
|
|
|
|
response.getDemodAnalyzerSettings()->setRecordSilenceTime(settings.m_recordSilenceTime);
|
|
|
|
|
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());
|
|
|
|
}
|
2022-11-13 16:24:03 -05:00
|
|
|
if (featureSettingsKeys.contains("fileRecordName")) {
|
|
|
|
settings.m_fileRecordName = *response.getDemodAnalyzerSettings()->getFileRecordName();
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("recordToFile")) {
|
|
|
|
settings.m_recordToFile = response.getDemodAnalyzerSettings()->getRecordToFile() != 0;
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("recordSilenceTime")) {
|
|
|
|
settings.m_recordSilenceTime = response.getDemodAnalyzerSettings()->getRecordSilenceTime();
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
}
|
|
|
|
|
2022-11-23 17:08:41 -05:00
|
|
|
void DemodAnalyzer::webapiReverseSendSettings(const QList<QString>& featureSettingsKeys, const DemodAnalyzerSettings& settings, bool force)
|
2020-12-19 19:53:03 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2022-11-13 16:24:03 -05:00
|
|
|
if (featureSettingsKeys.contains("fileRecordName")) {
|
|
|
|
swgDemodAnalyzerSettings->setFileRecordName(new QString(settings.m_fileRecordName));
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("recordToFile")) {
|
|
|
|
swgDemodAnalyzerSettings->setRecordToFile(settings.m_recordToFile ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (featureSettingsKeys.contains("recordSilenceTime") || force) {
|
|
|
|
swgDemodAnalyzerSettings->setRecordSilenceTime(settings.m_recordSilenceTime);
|
|
|
|
}
|
2020-12-19 19:53:03 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2022-09-21 15:54:01 -04:00
|
|
|
if ((fifo) && m_running)
|
2022-02-20 20:18:51 -05:00
|
|
|
{
|
|
|
|
DemodAnalyzerWorker::MsgConnectFifo *msg = DemodAnalyzerWorker::MsgConnectFifo::create(fifo, false);
|
|
|
|
m_worker->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_selectedChannel = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2024-01-21 07:47:07 -05:00
|
|
|
|
|
|
|
int DemodAnalyzer::webapiActionsPost(
|
2024-03-04 17:15:01 -05:00
|
|
|
const QStringList&,
|
2024-01-21 07:47:07 -05:00
|
|
|
SWGSDRangel::SWGFeatureActions& query,
|
|
|
|
QString& errorMessage) {
|
|
|
|
|
|
|
|
MainCore* m_core = MainCore::instance();
|
|
|
|
auto action = query.getDemodAnalyzerActions();
|
|
|
|
if (action == nullptr) {
|
|
|
|
errorMessage = QString("missing DemodAnalyzerActions in request");
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto deviceId = action->getDeviceId();
|
|
|
|
auto chanId = action->getChannelId();
|
|
|
|
|
|
|
|
ChannelAPI * chan = m_core->getChannel(deviceId, chanId);
|
|
|
|
if (chan == nullptr) {
|
|
|
|
errorMessage = QString("device(%1) or channel (%2) on the device does not exist").arg(deviceId).arg(chanId);
|
|
|
|
return 404;
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgSelectChannel *msg = MsgSelectChannel::create(chan);
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
return 200;
|
|
|
|
}
|