2014-11-16 17:39:50 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
|
|
|
// written by Christian Daniel //
|
|
|
|
// //
|
|
|
|
// 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 //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2014-11-16 17:39:50 -05:00
|
|
|
// //
|
|
|
|
// 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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-02 07:18:07 -04:00
|
|
|
|
2014-11-16 17:39:50 -05:00
|
|
|
#include <stdio.h>
|
2015-05-14 05:08:23 -04:00
|
|
|
#include <complex.h>
|
2017-10-07 21:29:33 -04:00
|
|
|
|
2018-12-24 08:46:15 -05:00
|
|
|
#include <QTime>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2019-12-03 12:49:52 -05:00
|
|
|
#include <QThread>
|
2018-12-24 08:46:15 -05:00
|
|
|
|
2018-05-25 04:08:47 -04:00
|
|
|
#include "SWGChannelSettings.h"
|
|
|
|
#include "SWGWFMDemodSettings.h"
|
|
|
|
#include "SWGChannelReport.h"
|
|
|
|
#include "SWGWFMDemodReport.h"
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2020-11-12 16:13:44 -05:00
|
|
|
#include "audio/audiooutputdevice.h"
|
2015-08-23 20:59:18 -04:00
|
|
|
#include "dsp/dspengine.h"
|
2018-02-14 14:11:36 -05:00
|
|
|
#include "dsp/dspcommands.h"
|
2019-09-22 19:25:17 -04:00
|
|
|
#include "dsp/devicesamplemimo.h"
|
|
|
|
#include "device/deviceapi.h"
|
2020-10-22 18:11:18 -04:00
|
|
|
#include "feature/feature.h"
|
2022-01-08 23:27:12 -05:00
|
|
|
#include "settings/serializable.h"
|
2018-05-25 04:08:47 -04:00
|
|
|
#include "util/db.h"
|
2020-10-22 18:11:18 -04:00
|
|
|
#include "maincore.h"
|
2015-05-14 05:08:23 -04:00
|
|
|
|
2017-10-07 21:29:33 -04:00
|
|
|
#include "wfmdemod.h"
|
|
|
|
|
2014-11-16 17:39:50 -05:00
|
|
|
MESSAGE_CLASS_DEFINITION(WFMDemod::MsgConfigureWFMDemod, Message)
|
|
|
|
|
2020-11-21 14:24:18 -05:00
|
|
|
const char* const WFMDemod::m_channelIdURI = "sdrangel.channel.wfmdemod";
|
|
|
|
const char* const WFMDemod::m_channelId = "WFMDemod";
|
2017-11-21 17:30:09 -05:00
|
|
|
const int WFMDemod::m_udpBlockSize = 512;
|
2017-11-08 08:23:49 -05:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
WFMDemod::WFMDemod(DeviceAPI* deviceAPI) :
|
2019-05-09 11:27:12 -04:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
2017-12-20 17:57:06 -05:00
|
|
|
m_deviceAPI(deviceAPI),
|
2019-12-03 12:49:52 -05:00
|
|
|
m_basebandSampleRate(0)
|
2014-11-16 17:39:50 -05:00
|
|
|
{
|
2017-11-22 19:19:32 -05:00
|
|
|
setObjectName(m_channelId);
|
2015-08-12 03:03:02 -04:00
|
|
|
|
2019-12-03 12:49:52 -05:00
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_basebandSink = new WFMDemodBaseband();
|
2020-12-20 20:30:29 -05:00
|
|
|
m_basebandSink->setChannel(this);
|
2019-12-03 12:49:52 -05:00
|
|
|
m_basebandSink->moveToThread(m_thread);
|
2014-11-16 17:39:50 -05:00
|
|
|
|
2018-03-16 05:24:19 -04:00
|
|
|
applySettings(m_settings, true);
|
|
|
|
|
2019-12-03 12:49:52 -05:00
|
|
|
m_deviceAPI->addChannelSink(this);
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
2018-12-24 08:46:15 -05:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2021-06-29 15:47:27 -04:00
|
|
|
connect(&m_channelMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleChannelMessages()));
|
2014-11-16 17:39:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
WFMDemod::~WFMDemod()
|
|
|
|
{
|
2018-12-24 08:46:15 -05:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
2017-10-07 21:29:33 -04:00
|
|
|
|
2019-12-03 12:49:52 -05:00
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
|
|
|
m_deviceAPI->removeChannelSink(this);
|
|
|
|
delete m_basebandSink;
|
|
|
|
delete m_thread;
|
2018-03-10 00:13:15 -05:00
|
|
|
}
|
2017-11-21 17:30:09 -05:00
|
|
|
|
2019-09-22 19:25:17 -04:00
|
|
|
uint32_t WFMDemod::getNumberOfDeviceStreams() const
|
|
|
|
{
|
|
|
|
return m_deviceAPI->getNbSourceStreams();
|
|
|
|
}
|
|
|
|
|
2018-11-12 18:45:03 -05:00
|
|
|
void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst)
|
2015-05-14 05:08:23 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) firstOfBurst;
|
2019-12-03 12:49:52 -05:00
|
|
|
m_basebandSink->feed(begin, end);
|
2014-11-16 17:39:50 -05:00
|
|
|
}
|
|
|
|
|
2015-05-14 05:08:23 -04:00
|
|
|
void WFMDemod::start()
|
|
|
|
{
|
2019-12-03 12:49:52 -05:00
|
|
|
qDebug() << "WFMDemod::start";
|
|
|
|
|
|
|
|
if (m_basebandSampleRate != 0) {
|
|
|
|
m_basebandSink->setBasebandSampleRate(m_basebandSampleRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_basebandSink->reset();
|
|
|
|
m_thread->start();
|
2015-05-14 05:08:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WFMDemod::stop()
|
|
|
|
{
|
2019-12-03 12:49:52 -05:00
|
|
|
qDebug() << "WFMDemod::stop";
|
|
|
|
m_thread->exit();
|
|
|
|
m_thread->wait();
|
2015-05-14 05:08:23 -04:00
|
|
|
}
|
2014-11-16 17:39:50 -05:00
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
bool WFMDemod::handleMessage(const Message& cmd)
|
2014-11-16 17:39:50 -05:00
|
|
|
{
|
2019-12-03 12:49:52 -05:00
|
|
|
if (MsgConfigureWFMDemod::match(cmd))
|
2017-10-07 21:17:13 -04:00
|
|
|
{
|
|
|
|
MsgConfigureWFMDemod& cfg = (MsgConfigureWFMDemod&) cmd;
|
2017-12-29 05:04:47 -05:00
|
|
|
qDebug("WFMDemod::handleMessage: MsgConfigureWFMDemod");
|
2017-10-07 21:17:13 -04:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
2017-10-07 21:17:13 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-14 14:11:36 -05:00
|
|
|
else if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
2019-12-03 12:49:52 -05:00
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
|
|
|
m_basebandSampleRate = notif.getSampleRate();
|
|
|
|
// Forward to the sink
|
|
|
|
DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
|
|
|
|
qDebug() << "WFMDemod::handleMessage: DSPSignalNotification";
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(rep);
|
|
|
|
|
2018-02-14 14:11:36 -05:00
|
|
|
return true;
|
|
|
|
}
|
2021-06-29 15:47:27 -04:00
|
|
|
else if (MainCore::MsgChannelDemodQuery::match(cmd))
|
|
|
|
{
|
|
|
|
qDebug() << "WFMDemod::handleMessage: MsgChannelDemodQuery";
|
|
|
|
sendSampleRateToDemodAnalyzer();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-17 02:29:34 -04:00
|
|
|
else
|
|
|
|
{
|
2018-02-14 14:11:36 -05:00
|
|
|
return false;
|
2014-11-16 17:39:50 -05:00
|
|
|
}
|
|
|
|
}
|
2015-05-14 05:08:23 -04:00
|
|
|
|
2022-01-06 16:47:41 -05:00
|
|
|
void WFMDemod::setCenterFrequency(qint64 frequency)
|
|
|
|
{
|
|
|
|
WFMDemodSettings settings = m_settings;
|
|
|
|
settings.m_inputFrequencyOffset = frequency;
|
|
|
|
applySettings(settings, false);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureWFMDemod *msgToGUI = MsgConfigureWFMDemod::create(settings, false);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
void WFMDemod::applySettings(const WFMDemodSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "WFMDemod::applySettings:"
|
|
|
|
<< " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset
|
|
|
|
<< " m_rfBandwidth: " << settings.m_rfBandwidth
|
|
|
|
<< " m_afBandwidth: " << settings.m_afBandwidth
|
|
|
|
<< " m_volume: " << settings.m_volume
|
|
|
|
<< " m_squelch: " << settings.m_squelch
|
2018-03-28 01:44:54 -04:00
|
|
|
<< " m_audioDeviceName: " << settings.m_audioDeviceName
|
2018-12-24 08:46:15 -05:00
|
|
|
<< " m_audioMute: " << settings.m_audioMute
|
2019-09-22 19:25:17 -04:00
|
|
|
<< " m_streamIndex: " << settings.m_streamIndex
|
2019-04-20 13:53:16 -04:00
|
|
|
<< " m_useReverseAPI: " << settings.m_useReverseAPI
|
|
|
|
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
|
|
|
|
<< " m_reverseAPIPort: " << settings.m_reverseAPIPort
|
|
|
|
<< " m_reverseAPIDeviceIndex: " << settings.m_reverseAPIDeviceIndex
|
|
|
|
<< " m_reverseAPIChannelIndex: " << settings.m_reverseAPIChannelIndex
|
2017-12-29 05:04:47 -05:00
|
|
|
<< " force: " << force;
|
|
|
|
|
2018-12-24 08:46:15 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
|
|
|
if((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) {
|
|
|
|
reverseAPIKeys.append("inputFrequencyOffset");
|
|
|
|
}
|
|
|
|
if((settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force) {
|
|
|
|
reverseAPIKeys.append("rfBandwidth");
|
|
|
|
}
|
|
|
|
if((settings.m_afBandwidth != m_settings.m_afBandwidth) || force) {
|
|
|
|
reverseAPIKeys.append("afBandwidth");
|
|
|
|
}
|
|
|
|
if((settings.m_volume != m_settings.m_volume) || force) {
|
|
|
|
reverseAPIKeys.append("volume");
|
|
|
|
}
|
|
|
|
if((settings.m_squelch != m_settings.m_squelch) || force) {
|
|
|
|
reverseAPIKeys.append("squelch");
|
|
|
|
}
|
|
|
|
if((settings.m_audioMute != m_settings.m_audioMute) || force) {
|
|
|
|
reverseAPIKeys.append("audioMute");
|
|
|
|
}
|
|
|
|
if((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force) {
|
|
|
|
reverseAPIKeys.append("audioDeviceName");
|
|
|
|
}
|
|
|
|
if((settings.m_title != m_settings.m_title) || force) {
|
|
|
|
reverseAPIKeys.append("title");
|
|
|
|
}
|
|
|
|
if((settings.m_rgbColor != m_settings.m_rgbColor) || force) {
|
|
|
|
reverseAPIKeys.append("rgbColor");
|
|
|
|
}
|
|
|
|
|
2019-09-22 19:25:17 -04:00
|
|
|
if (m_settings.m_streamIndex != settings.m_streamIndex)
|
|
|
|
{
|
|
|
|
if (m_deviceAPI->getSampleMIMO()) // change of stream is possible for MIMO devices only
|
|
|
|
{
|
2019-12-23 17:41:35 -05:00
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
2019-12-03 12:49:52 -05:00
|
|
|
m_deviceAPI->removeChannelSink(this, m_settings.m_streamIndex);
|
|
|
|
m_deviceAPI->addChannelSink(this, settings.m_streamIndex);
|
2019-12-23 17:41:35 -05:00
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
2019-09-22 19:25:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
reverseAPIKeys.append("streamIndex");
|
|
|
|
}
|
|
|
|
|
2019-12-03 12:49:52 -05:00
|
|
|
WFMDemodBaseband::MsgConfigureWFMDemodBaseband *msg = WFMDemodBaseband::MsgConfigureWFMDemodBaseband::create(settings, force);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
|
2018-12-24 08:46:15 -05:00
|
|
|
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_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) ||
|
|
|
|
(m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
2020-12-13 07:04:36 -05:00
|
|
|
QList<MessageQueue*> *messageQueues = MainCore::instance()->getMessagePipes().getMessageQueues(this, "settings");
|
|
|
|
|
|
|
|
if (messageQueues) {
|
|
|
|
sendChannelSettings(messageQueues, reverseAPIKeys, settings, force);
|
2020-10-22 18:11:18 -04:00
|
|
|
}
|
|
|
|
|
2017-10-07 21:17:13 -04:00
|
|
|
m_settings = settings;
|
2015-05-14 05:08:23 -04:00
|
|
|
}
|
2017-12-17 17:15:42 -05:00
|
|
|
|
|
|
|
QByteArray WFMDemod::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WFMDemod::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureWFMDemod *msg = MsgConfigureWFMDemod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureWFMDemod *msg = MsgConfigureWFMDemod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-29 15:47:27 -04:00
|
|
|
void WFMDemod::sendSampleRateToDemodAnalyzer()
|
|
|
|
{
|
2022-02-25 17:43:50 -05:00
|
|
|
QList<ObjectPipe*> pipes;
|
|
|
|
MainCore::instance()->getMessagePipes2().getMessagePipes(this, "reportdemod", pipes);
|
2021-06-29 15:47:27 -04:00
|
|
|
|
2022-02-25 17:43:50 -05:00
|
|
|
if (pipes.size() > 0)
|
2021-06-29 15:47:27 -04:00
|
|
|
{
|
2022-02-25 17:43:50 -05:00
|
|
|
for (const auto& pipe: pipes)
|
2021-06-29 15:47:27 -04:00
|
|
|
{
|
2022-02-25 17:43:50 -05:00
|
|
|
MessageQueue* messageQueue = qobject_cast<MessageQueue*>(pipe->m_element);
|
2021-06-29 15:47:27 -04:00
|
|
|
MainCore::MsgChannelDemodReport *msg = MainCore::MsgChannelDemodReport::create(
|
|
|
|
this,
|
|
|
|
getAudioSampleRate()
|
|
|
|
);
|
2022-02-25 17:43:50 -05:00
|
|
|
messageQueue->push(msg);
|
|
|
|
|
2021-06-29 15:47:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 04:08:47 -04:00
|
|
|
int WFMDemod::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-05-25 04:08:47 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2018-05-25 04:08:47 -04:00
|
|
|
response.setWfmDemodSettings(new SWGSDRangel::SWGWFMDemodSettings());
|
|
|
|
response.getWfmDemodSettings()->init();
|
|
|
|
webapiFormatChannelSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WFMDemod::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-05-25 04:08:47 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2018-05-25 04:08:47 -04:00
|
|
|
WFMDemodSettings settings = m_settings;
|
2019-08-01 17:21:57 -04:00
|
|
|
webapiUpdateChannelSettings(settings, channelSettingsKeys, response);
|
2018-05-25 04:08:47 -04:00
|
|
|
|
2019-08-01 17:21:57 -04:00
|
|
|
MsgConfigureWFMDemod *msg = MsgConfigureWFMDemod::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
qDebug("WFMDemod::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureWFMDemod *msgToGUI = MsgConfigureWFMDemod::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatChannelSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WFMDemod::webapiUpdateChannelSettings(
|
|
|
|
WFMDemodSettings& settings,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response)
|
|
|
|
{
|
|
|
|
if (channelSettingsKeys.contains("inputFrequencyOffset")) {
|
2018-05-25 04:08:47 -04:00
|
|
|
settings.m_inputFrequencyOffset = response.getWfmDemodSettings()->getInputFrequencyOffset();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rfBandwidth")) {
|
|
|
|
settings.m_rfBandwidth = response.getWfmDemodSettings()->getRfBandwidth();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("afBandwidth")) {
|
|
|
|
settings.m_afBandwidth = response.getWfmDemodSettings()->getAfBandwidth();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("volume")) {
|
|
|
|
settings.m_volume = response.getWfmDemodSettings()->getVolume();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("squelch")) {
|
|
|
|
settings.m_squelch = response.getWfmDemodSettings()->getSquelch();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioMute")) {
|
|
|
|
settings.m_audioMute = response.getWfmDemodSettings()->getAudioMute() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor")) {
|
|
|
|
settings.m_rgbColor = response.getWfmDemodSettings()->getRgbColor();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title")) {
|
|
|
|
settings.m_title = *response.getWfmDemodSettings()->getTitle();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioDeviceName")) {
|
|
|
|
settings.m_audioDeviceName = *response.getWfmDemodSettings()->getAudioDeviceName();
|
|
|
|
}
|
2019-09-22 19:25:17 -04:00
|
|
|
if (channelSettingsKeys.contains("streamIndex")) {
|
|
|
|
settings.m_streamIndex = response.getWfmDemodSettings()->getStreamIndex();
|
|
|
|
}
|
2019-04-20 13:53:16 -04:00
|
|
|
if (channelSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getWfmDemodSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIAddress")) {
|
|
|
|
settings.m_reverseAPIAddress = *response.getWfmDemodSettings()->getReverseApiAddress();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getWfmDemodSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getWfmDemodSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
|
|
|
|
settings.m_reverseAPIChannelIndex = response.getWfmDemodSettings()->getReverseApiChannelIndex();
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) {
|
|
|
|
settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getWfmDemodSettings()->getChannelMarker());
|
|
|
|
}
|
|
|
|
if (settings.m_rollupState && channelSettingsKeys.contains("rollupState")) {
|
|
|
|
settings.m_rollupState->updateFrom(channelSettingsKeys, response.getWfmDemodSettings()->getRollupState());
|
|
|
|
}
|
2018-05-25 04:08:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int WFMDemod::webapiReportGet(
|
|
|
|
SWGSDRangel::SWGChannelReport& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-05-25 04:08:47 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2018-05-25 04:08:47 -04:00
|
|
|
response.setWfmDemodReport(new SWGSDRangel::SWGWFMDemodReport());
|
|
|
|
response.getWfmDemodReport()->init();
|
|
|
|
webapiFormatChannelReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WFMDemod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const WFMDemodSettings& settings)
|
|
|
|
{
|
|
|
|
response.getWfmDemodSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
|
|
|
|
response.getWfmDemodSettings()->setRfBandwidth(settings.m_rfBandwidth);
|
|
|
|
response.getWfmDemodSettings()->setAfBandwidth(settings.m_afBandwidth);
|
|
|
|
response.getWfmDemodSettings()->setVolume(settings.m_volume);
|
|
|
|
response.getWfmDemodSettings()->setSquelch(settings.m_squelch);
|
|
|
|
response.getWfmDemodSettings()->setAudioMute(settings.m_audioMute ? 1 : 0);
|
|
|
|
response.getWfmDemodSettings()->setRgbColor(settings.m_rgbColor);
|
|
|
|
|
|
|
|
if (response.getWfmDemodSettings()->getTitle()) {
|
|
|
|
*response.getWfmDemodSettings()->getTitle() = settings.m_title;
|
|
|
|
} else {
|
|
|
|
response.getWfmDemodSettings()->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.getWfmDemodSettings()->getAudioDeviceName()) {
|
|
|
|
*response.getWfmDemodSettings()->getAudioDeviceName() = settings.m_audioDeviceName;
|
|
|
|
} else {
|
|
|
|
response.getWfmDemodSettings()->setAudioDeviceName(new QString(settings.m_audioDeviceName));
|
|
|
|
}
|
2019-04-20 13:53:16 -04:00
|
|
|
|
2019-09-22 19:25:17 -04:00
|
|
|
response.getWfmDemodSettings()->setStreamIndex(settings.m_streamIndex);
|
2019-04-20 13:53:16 -04:00
|
|
|
response.getWfmDemodSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getWfmDemodSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getWfmDemodSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getWfmDemodSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getWfmDemodSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getWfmDemodSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
|
|
|
response.getWfmDemodSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex);
|
2022-01-08 23:27:12 -05:00
|
|
|
|
|
|
|
if (settings.m_channelMarker)
|
|
|
|
{
|
|
|
|
if (response.getWfmDemodSettings()->getChannelMarker())
|
|
|
|
{
|
|
|
|
settings.m_channelMarker->formatTo(response.getWfmDemodSettings()->getChannelMarker());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker();
|
|
|
|
settings.m_channelMarker->formatTo(swgChannelMarker);
|
|
|
|
response.getWfmDemodSettings()->setChannelMarker(swgChannelMarker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.m_rollupState)
|
|
|
|
{
|
|
|
|
if (response.getWfmDemodSettings()->getRollupState())
|
|
|
|
{
|
|
|
|
settings.m_rollupState->formatTo(response.getWfmDemodSettings()->getRollupState());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
response.getWfmDemodSettings()->setRollupState(swgRollupState);
|
|
|
|
}
|
|
|
|
}
|
2018-05-25 04:08:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WFMDemod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response)
|
|
|
|
{
|
|
|
|
double magsqAvg, magsqPeak;
|
|
|
|
int nbMagsqSamples;
|
|
|
|
getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples);
|
|
|
|
|
|
|
|
response.getWfmDemodReport()->setChannelPowerDb(CalcDb::dbPower(magsqAvg));
|
2019-12-03 12:49:52 -05:00
|
|
|
response.getWfmDemodReport()->setSquelch(m_basebandSink->getSquelchState() > 0 ? 1 : 0);
|
|
|
|
response.getWfmDemodReport()->setAudioSampleRate(m_basebandSink->getAudioSampleRate());
|
|
|
|
response.getWfmDemodReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate());
|
2018-05-25 04:08:47 -04:00
|
|
|
}
|
|
|
|
|
2018-12-24 08:46:15 -05:00
|
|
|
void WFMDemod::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const WFMDemodSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
2020-10-22 18:11:18 -04:00
|
|
|
webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force);
|
|
|
|
|
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings")
|
|
|
|
.arg(settings.m_reverseAPIAddress)
|
|
|
|
.arg(settings.m_reverseAPIPort)
|
|
|
|
.arg(settings.m_reverseAPIDeviceIndex)
|
|
|
|
.arg(settings.m_reverseAPIChannelIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer = new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgChannelSettings->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 swgChannelSettings;
|
|
|
|
}
|
|
|
|
|
2020-12-13 07:04:36 -05:00
|
|
|
void WFMDemod::sendChannelSettings(
|
|
|
|
QList<MessageQueue*> *messageQueues,
|
|
|
|
QList<QString>& channelSettingsKeys,
|
|
|
|
const WFMDemodSettings& settings,
|
|
|
|
bool force)
|
2020-10-22 18:11:18 -04:00
|
|
|
{
|
2020-12-13 07:04:36 -05:00
|
|
|
QList<MessageQueue*>::iterator it = messageQueues->begin();
|
2020-10-22 18:11:18 -04:00
|
|
|
|
2020-12-13 07:04:36 -05:00
|
|
|
for (; it != messageQueues->end(); ++it)
|
2020-10-22 18:11:18 -04:00
|
|
|
{
|
2020-12-13 07:04:36 -05:00
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
|
|
|
webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force);
|
|
|
|
MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create(
|
|
|
|
this,
|
|
|
|
channelSettingsKeys,
|
|
|
|
swgChannelSettings,
|
|
|
|
force
|
|
|
|
);
|
|
|
|
(*it)->push(msg);
|
2020-10-22 18:11:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WFMDemod::webapiFormatChannelSettings(
|
|
|
|
QList<QString>& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings,
|
|
|
|
const WFMDemodSettings& settings,
|
|
|
|
bool force
|
|
|
|
)
|
|
|
|
{
|
|
|
|
swgChannelSettings->setDirection(0); // Single sink (Rx)
|
2019-03-25 08:53:48 -04:00
|
|
|
swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet());
|
|
|
|
swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex());
|
2020-10-22 18:11:18 -04:00
|
|
|
swgChannelSettings->setChannelType(new QString(m_channelId));
|
2018-12-24 08:46:15 -05:00
|
|
|
swgChannelSettings->setWfmDemodSettings(new SWGSDRangel::SWGWFMDemodSettings());
|
|
|
|
SWGSDRangel::SWGWFMDemodSettings *swgWFMDemodSettings = swgChannelSettings->getWfmDemodSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("inputFrequencyOffset") || force) {
|
|
|
|
swgWFMDemodSettings->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rfBandwidth") || force) {
|
|
|
|
swgWFMDemodSettings->setRfBandwidth(settings.m_rfBandwidth);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("afBandwidth") || force) {
|
|
|
|
swgWFMDemodSettings->setAfBandwidth(settings.m_afBandwidth);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("volume") || force) {
|
|
|
|
swgWFMDemodSettings->setVolume(settings.m_volume);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("squelch") || force) {
|
|
|
|
swgWFMDemodSettings->setSquelch(settings.m_squelch);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioMute") || force) {
|
|
|
|
swgWFMDemodSettings->setAudioMute(settings.m_audioMute ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor") || force) {
|
|
|
|
swgWFMDemodSettings->setRgbColor(settings.m_rgbColor);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title") || force) {
|
|
|
|
swgWFMDemodSettings->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioDeviceName") || force) {
|
|
|
|
swgWFMDemodSettings->setAudioDeviceName(new QString(settings.m_audioDeviceName));
|
|
|
|
}
|
2019-09-22 19:25:17 -04:00
|
|
|
if (channelSettingsKeys.contains("streamIndex") || force) {
|
|
|
|
swgWFMDemodSettings->setStreamIndex(settings.m_streamIndex);
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
|
|
|
|
if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker();
|
|
|
|
settings.m_channelMarker->formatTo(swgChannelMarker);
|
|
|
|
swgWFMDemodSettings->setChannelMarker(swgChannelMarker);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
swgWFMDemodSettings->setRollupState(swgRollupState);
|
|
|
|
}
|
2018-12-24 08:46:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void WFMDemod::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "WFMDemod::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
2019-11-12 12:46:21 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("WFMDemod::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2018-12-24 08:46:15 -05:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
reply->deleteLater();
|
2018-12-24 08:46:15 -05:00
|
|
|
}
|
2021-06-29 15:47:27 -04:00
|
|
|
|
|
|
|
void WFMDemod::handleChannelMessages()
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_channelMessageQueue.pop()) != nullptr)
|
|
|
|
{
|
|
|
|
if (handleMessage(*message)) {
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|