2015-05-12 00:53:35 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2018-12-15 23:51:41 +00:00
|
|
|
// Copyright (C) 2015-2018 Edouard Griffiths, F4EXB. //
|
2015-05-12 00:53:35 +00: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 //
|
2019-04-11 04:39:30 +00:00
|
|
|
// (at your option) any later version. //
|
2015-05-12 00:53:35 +00: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-20 16:04:15 +00:00
|
|
|
#include "amdemod.h"
|
2015-05-12 00:53:35 +00:00
|
|
|
|
|
|
|
#include <QTime>
|
2015-08-17 06:29:34 +00:00
|
|
|
#include <QDebug>
|
2018-12-15 23:51:41 +00:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2019-11-23 06:39:57 +00:00
|
|
|
#include <QThread>
|
2017-08-26 03:32:01 +00:00
|
|
|
|
2015-05-12 00:53:35 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <complex.h>
|
2017-08-26 03:32:01 +00:00
|
|
|
|
2018-03-21 22:49:16 +00:00
|
|
|
#include "SWGChannelSettings.h"
|
|
|
|
#include "SWGAMDemodSettings.h"
|
|
|
|
#include "SWGChannelReport.h"
|
|
|
|
#include "SWGAMDemodReport.h"
|
|
|
|
|
2015-08-23 22:51:27 +00:00
|
|
|
#include "dsp/dspengine.h"
|
2018-02-14 19:11:36 +00:00
|
|
|
#include "dsp/dspcommands.h"
|
2019-05-08 20:11:53 +00:00
|
|
|
#include "device/deviceapi.h"
|
2020-10-22 22:11:18 +00:00
|
|
|
#include "feature/feature.h"
|
2021-12-02 22:54:39 +00:00
|
|
|
#include "settings/serializable.h"
|
2018-03-21 22:49:16 +00:00
|
|
|
#include "util/db.h"
|
2020-10-22 22:11:18 +00:00
|
|
|
#include "maincore.h"
|
2015-05-12 00:53:35 +00:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(AMDemod::MsgConfigureAMDemod, Message)
|
|
|
|
|
2020-11-21 19:24:18 +00:00
|
|
|
const char* const AMDemod::m_channelIdURI = "sdrangel.channel.amdemod";
|
|
|
|
const char* const AMDemod::m_channelId = "AMDemod";
|
2017-08-26 03:32:01 +00:00
|
|
|
const int AMDemod::m_udpBlockSize = 512;
|
|
|
|
|
2019-05-08 20:11:53 +00:00
|
|
|
AMDemod::AMDemod(DeviceAPI *deviceAPI) :
|
2019-05-09 15:27:12 +00:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
2017-12-20 22:57:06 +00:00
|
|
|
m_deviceAPI(deviceAPI),
|
2019-11-23 06:39:57 +00:00
|
|
|
m_basebandSampleRate(0)
|
2015-05-12 00:53:35 +00:00
|
|
|
{
|
2017-11-23 00:19:32 +00:00
|
|
|
setObjectName(m_channelId);
|
2017-09-27 22:24:03 +00:00
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
m_basebandSink = new AMDemodBaseband();
|
2020-12-20 00:53:03 +00:00
|
|
|
m_basebandSink->setChannel(this);
|
2020-07-13 08:15:27 +00:00
|
|
|
m_basebandSink->moveToThread(&m_thread);
|
2015-05-12 00:53:35 +00:00
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
applySettings(m_settings, true);
|
2015-08-23 22:51:27 +00:00
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
m_deviceAPI->addChannelSink(this);
|
2019-05-08 20:11:53 +00:00
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
2018-05-13 15:27:24 +00:00
|
|
|
|
2018-12-15 23:51:41 +00:00
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2021-06-29 19:47:27 +00:00
|
|
|
connect(&m_channelMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleChannelMessages()));
|
2015-05-12 00:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AMDemod::~AMDemod()
|
|
|
|
{
|
2020-10-04 17:07:42 +00:00
|
|
|
qDebug("AMDemod::~AMDemod");
|
2018-12-15 23:51:41 +00:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
2019-11-23 06:39:57 +00:00
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
|
|
|
m_deviceAPI->removeChannelSink(this);
|
2020-07-13 08:15:27 +00:00
|
|
|
|
|
|
|
if (m_basebandSink->isRunning()) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
delete m_basebandSink;
|
2015-05-12 00:53:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 23:52:13 +00:00
|
|
|
uint32_t AMDemod::getNumberOfDeviceStreams() const
|
|
|
|
{
|
|
|
|
return m_deviceAPI->getNbSourceStreams();
|
|
|
|
}
|
|
|
|
|
2018-11-12 23:45:03 +00:00
|
|
|
void AMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst)
|
2015-05-12 00:53:35 +00:00
|
|
|
{
|
2018-11-12 23:45:03 +00:00
|
|
|
(void) firstOfBurst;
|
2019-11-23 06:39:57 +00:00
|
|
|
m_basebandSink->feed(begin, end);
|
2015-05-12 00:53:35 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
void AMDemod::start()
|
2018-05-13 22:44:43 +00:00
|
|
|
{
|
2019-11-23 06:39:57 +00:00
|
|
|
qDebug("AMDemod::start");
|
2018-05-13 22:44:43 +00:00
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
m_basebandSink->reset();
|
2020-07-13 08:15:27 +00:00
|
|
|
m_basebandSink->startWork();
|
|
|
|
m_thread.start();
|
|
|
|
|
|
|
|
DSPSignalNotification *dspMsg = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(dspMsg);
|
|
|
|
|
|
|
|
AMDemodBaseband::MsgConfigureAMDemodBaseband *msg = AMDemodBaseband::MsgConfigureAMDemodBaseband::create(m_settings, true);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
2015-05-12 00:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDemod::stop()
|
|
|
|
{
|
2018-02-18 13:46:36 +00:00
|
|
|
qDebug("AMDemod::stop");
|
2020-07-13 08:15:27 +00:00
|
|
|
m_basebandSink->stopWork();
|
|
|
|
m_thread.quit();
|
|
|
|
m_thread.wait();
|
2015-05-12 00:53:35 +00:00
|
|
|
}
|
|
|
|
|
2015-08-17 06:29:34 +00:00
|
|
|
bool AMDemod::handleMessage(const Message& cmd)
|
2015-05-12 00:53:35 +00:00
|
|
|
{
|
2019-11-23 06:39:57 +00:00
|
|
|
if (MsgConfigureAMDemod::match(cmd))
|
2015-08-17 06:29:34 +00:00
|
|
|
{
|
2017-09-26 21:19:49 +00:00
|
|
|
MsgConfigureAMDemod& cfg = (MsgConfigureAMDemod&) cmd;
|
2017-12-29 10:04:47 +00:00
|
|
|
qDebug() << "AMDemod::handleMessage: MsgConfigureAMDemod";
|
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
2015-08-17 06:29:34 +00:00
|
|
|
|
2015-05-12 00:53:35 +00:00
|
|
|
return true;
|
2015-08-17 06:29:34 +00:00
|
|
|
}
|
2018-02-14 19:11:36 +00:00
|
|
|
else if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
2019-11-23 06:39:57 +00:00
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
|
|
|
m_basebandSampleRate = notif.getSampleRate();
|
2020-07-13 08:15:27 +00:00
|
|
|
m_centerFrequency = notif.getCenterFrequency();
|
2019-11-23 06:39:57 +00:00
|
|
|
// Forward to the sink
|
|
|
|
DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
|
|
|
|
qDebug() << "AMDemod::handleMessage: DSPSignalNotification";
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(rep);
|
2018-03-26 09:55:45 +00:00
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
return true;
|
2021-06-29 19:47:27 +00:00
|
|
|
}
|
|
|
|
else if (MainCore::MsgChannelDemodQuery::match(cmd))
|
|
|
|
{
|
|
|
|
qDebug() << "AMDemod::handleMessage: MsgChannelDemodQuery";
|
|
|
|
sendSampleRateToDemodAnalyzer();
|
|
|
|
|
|
|
|
return true;
|
2018-03-26 09:55:45 +00:00
|
|
|
}
|
2015-08-17 06:29:34 +00:00
|
|
|
else
|
|
|
|
{
|
2015-08-23 22:58:54 +00:00
|
|
|
return false;
|
2015-05-12 00:53:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-06 21:47:41 +00:00
|
|
|
void AMDemod::setCenterFrequency(qint64 frequency)
|
|
|
|
{
|
|
|
|
AMDemodSettings settings = m_settings;
|
|
|
|
settings.m_inputFrequencyOffset = frequency;
|
|
|
|
applySettings(settings, false);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureAMDemod *msgToGUI = MsgConfigureAMDemod::create(settings, false);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-29 10:04:47 +00:00
|
|
|
void AMDemod::applySettings(const AMDemodSettings& settings, bool force)
|
|
|
|
{
|
2018-01-05 17:39:12 +00:00
|
|
|
qDebug() << "AMDemod::applySettings:"
|
|
|
|
<< " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset
|
2017-12-29 10:04:47 +00:00
|
|
|
<< " m_rfBandwidth: " << settings.m_rfBandwidth
|
|
|
|
<< " m_volume: " << settings.m_volume
|
|
|
|
<< " m_squelch: " << settings.m_squelch
|
|
|
|
<< " m_audioMute: " << settings.m_audioMute
|
|
|
|
<< " m_bandpassEnable: " << settings.m_bandpassEnable
|
2018-03-26 16:41:09 +00:00
|
|
|
<< " m_audioDeviceName: " << settings.m_audioDeviceName
|
2018-05-13 15:27:24 +00:00
|
|
|
<< " m_pll: " << settings.m_pll
|
2018-05-13 20:30:50 +00:00
|
|
|
<< " m_syncAMOperation: " << (int) settings.m_syncAMOperation
|
2019-05-20 14:31:15 +00:00
|
|
|
<< " m_streamIndex: " << settings.m_streamIndex
|
2018-12-16 19:41:21 +00:00
|
|
|
<< " m_useReverseAPI: " << settings.m_useReverseAPI
|
|
|
|
<< " m_reverseAPIAddress: " << settings.m_reverseAPIAddress
|
2019-04-20 17:11:58 +00:00
|
|
|
<< " m_reverseAPIPort: " << settings.m_reverseAPIPort
|
2018-12-16 19:41:21 +00:00
|
|
|
<< " m_reverseAPIDeviceIndex: " << settings.m_reverseAPIDeviceIndex
|
|
|
|
<< " m_reverseAPIChannelIndex: " << settings.m_reverseAPIChannelIndex
|
2017-12-29 10:04:47 +00:00
|
|
|
<< " force: " << force;
|
|
|
|
|
2018-12-14 07:51:01 +00:00
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
if ((m_settings.m_rfBandwidth != settings.m_rfBandwidth) || force) {
|
|
|
|
reverseAPIKeys.append("rfBandwidth");
|
2017-09-26 21:19:49 +00:00
|
|
|
}
|
2019-11-23 06:39:57 +00:00
|
|
|
if ((m_settings.m_bandpassEnable != settings.m_bandpassEnable) || force) {
|
|
|
|
reverseAPIKeys.append("bandpassEnable");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_squelch != settings.m_squelch) || force) {
|
2018-12-15 02:42:58 +00:00
|
|
|
reverseAPIKeys.append("squelch");
|
2017-09-26 21:19:49 +00:00
|
|
|
}
|
2019-11-23 06:39:57 +00:00
|
|
|
if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force) {
|
2018-12-14 07:51:01 +00:00
|
|
|
reverseAPIKeys.append("audioDeviceName");
|
2018-03-26 16:41:09 +00:00
|
|
|
}
|
|
|
|
|
2018-05-13 20:30:50 +00:00
|
|
|
if ((m_settings.m_pll != settings.m_pll) || force)
|
|
|
|
{
|
2018-12-14 07:51:01 +00:00
|
|
|
reverseAPIKeys.append("pll");
|
2018-12-16 19:41:21 +00:00
|
|
|
reverseAPIKeys.append("syncAMOperation");
|
2018-05-13 20:30:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-14 07:51:01 +00:00
|
|
|
if ((m_settings.m_syncAMOperation != settings.m_syncAMOperation) || force)
|
|
|
|
{
|
2018-12-16 19:41:21 +00:00
|
|
|
reverseAPIKeys.append("pll");
|
2018-12-14 07:51:01 +00:00
|
|
|
reverseAPIKeys.append("syncAMOperation");
|
2018-05-13 20:30:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 02:42:58 +00:00
|
|
|
if ((m_settings.m_inputFrequencyOffset != settings.m_inputFrequencyOffset) || force) {
|
|
|
|
reverseAPIKeys.append("inputFrequencyOffset");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_audioMute != settings.m_audioMute) || force) {
|
|
|
|
reverseAPIKeys.append("audioMute");
|
|
|
|
}
|
2018-12-14 07:51:01 +00:00
|
|
|
|
2018-12-15 02:42:58 +00:00
|
|
|
if ((m_settings.m_volume != settings.m_volume) || force) {
|
|
|
|
reverseAPIKeys.append("volume");
|
|
|
|
}
|
|
|
|
|
2019-05-27 00:52:33 +00: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 22:41:35 +00:00
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
2019-11-23 06:39:57 +00:00
|
|
|
m_deviceAPI->removeChannelSink(this, m_settings.m_streamIndex);
|
|
|
|
m_deviceAPI->addChannelSink(this, settings.m_streamIndex);
|
2019-12-23 22:41:35 +00:00
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
2019-05-27 00:52:33 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 14:31:15 +00:00
|
|
|
reverseAPIKeys.append("streamIndex");
|
|
|
|
}
|
|
|
|
|
2019-11-23 06:39:57 +00:00
|
|
|
AMDemodBaseband::MsgConfigureAMDemodBaseband *msg = AMDemodBaseband::MsgConfigureAMDemodBaseband::create(settings, force);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
|
2018-12-16 19:41:21 +00: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);
|
2018-12-14 07:51:01 +00:00
|
|
|
}
|
2018-12-15 02:42:58 +00:00
|
|
|
|
2020-12-13 12:04:36 +00:00
|
|
|
QList<MessageQueue*> *messageQueues = MainCore::instance()->getMessagePipes().getMessageQueues(this, "settings");
|
|
|
|
|
|
|
|
if (messageQueues) {
|
|
|
|
sendChannelSettings(messageQueues, reverseAPIKeys, settings, force);
|
2020-10-22 22:11:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 02:42:58 +00:00
|
|
|
m_settings = settings;
|
2015-05-12 00:53:35 +00:00
|
|
|
}
|
2017-12-17 22:15:42 +00:00
|
|
|
|
|
|
|
QByteArray AMDemod::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDemod::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureAMDemod *msg = MsgConfigureAMDemod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureAMDemod *msg = MsgConfigureAMDemod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-29 19:47:27 +00:00
|
|
|
void AMDemod::sendSampleRateToDemodAnalyzer()
|
|
|
|
{
|
|
|
|
QList<MessageQueue*> *messageQueues = MainCore::instance()->getMessagePipes().getMessageQueues(this, "reportdemod");
|
|
|
|
|
|
|
|
if (messageQueues)
|
|
|
|
{
|
|
|
|
QList<MessageQueue*>::iterator it = messageQueues->begin();
|
|
|
|
|
|
|
|
for (; it != messageQueues->end(); ++it)
|
|
|
|
{
|
|
|
|
MainCore::MsgChannelDemodReport *msg = MainCore::MsgChannelDemodReport::create(
|
|
|
|
this,
|
|
|
|
getAudioSampleRate()
|
|
|
|
);
|
|
|
|
(*it)->push(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 22:49:16 +00:00
|
|
|
int AMDemod::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 23:45:03 +00:00
|
|
|
QString& errorMessage)
|
2018-03-21 22:49:16 +00:00
|
|
|
{
|
2018-11-12 23:45:03 +00:00
|
|
|
(void) errorMessage;
|
2018-03-21 22:49:16 +00:00
|
|
|
response.setAmDemodSettings(new SWGSDRangel::SWGAMDemodSettings());
|
|
|
|
response.getAmDemodSettings()->init();
|
|
|
|
webapiFormatChannelSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AMDemod::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 23:45:03 +00:00
|
|
|
QString& errorMessage)
|
2018-03-21 22:49:16 +00:00
|
|
|
{
|
2019-08-01 21:21:57 +00:00
|
|
|
(void) errorMessage;
|
2018-03-21 22:49:16 +00:00
|
|
|
AMDemodSettings settings = m_settings;
|
2019-08-01 16:50:21 +00:00
|
|
|
webapiUpdateChannelSettings(settings, channelSettingsKeys, response);
|
|
|
|
|
|
|
|
MsgConfigureAMDemod *msg = MsgConfigureAMDemod::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
2018-03-21 22:49:16 +00:00
|
|
|
|
2019-08-01 16:50:21 +00:00
|
|
|
qDebug("AMDemod::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureAMDemod *msgToGUI = MsgConfigureAMDemod::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatChannelSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDemod::webapiUpdateChannelSettings(
|
|
|
|
AMDemodSettings& settings,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response)
|
|
|
|
{
|
2018-03-21 22:49:16 +00:00
|
|
|
if (channelSettingsKeys.contains("audioMute")) {
|
|
|
|
settings.m_audioMute = response.getAmDemodSettings()->getAudioMute() != 0;
|
|
|
|
}
|
2019-08-01 16:50:21 +00:00
|
|
|
if (channelSettingsKeys.contains("inputFrequencyOffset")) {
|
2018-03-21 22:49:16 +00:00
|
|
|
settings.m_inputFrequencyOffset = response.getAmDemodSettings()->getInputFrequencyOffset();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rfBandwidth")) {
|
|
|
|
settings.m_rfBandwidth = response.getAmDemodSettings()->getRfBandwidth();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor")) {
|
|
|
|
settings.m_rgbColor = response.getAmDemodSettings()->getRgbColor();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("squelch")) {
|
|
|
|
settings.m_squelch = response.getAmDemodSettings()->getSquelch();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title")) {
|
|
|
|
settings.m_title = *response.getAmDemodSettings()->getTitle();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("volume")) {
|
|
|
|
settings.m_volume = response.getAmDemodSettings()->getVolume();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("bandpassEnable")) {
|
|
|
|
settings.m_bandpassEnable = response.getAmDemodSettings()->getBandpassEnable() != 0;
|
|
|
|
}
|
2018-03-29 05:55:51 +00:00
|
|
|
if (channelSettingsKeys.contains("audioDeviceName")) {
|
|
|
|
settings.m_audioDeviceName = *response.getAmDemodSettings()->getAudioDeviceName();
|
|
|
|
}
|
2018-03-21 22:49:16 +00:00
|
|
|
|
2018-08-02 21:27:22 +00:00
|
|
|
if (channelSettingsKeys.contains("pll")) {
|
|
|
|
settings.m_pll = response.getAmDemodSettings()->getPll();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("syncAMOperation")) {
|
|
|
|
qint32 syncAMOperationCode = response.getAmDemodSettings()->getSyncAmOperation();
|
|
|
|
settings.m_syncAMOperation = syncAMOperationCode < 0 ?
|
|
|
|
AMDemodSettings::SyncAMDSB : syncAMOperationCode > 2 ?
|
2018-12-16 19:41:21 +00:00
|
|
|
AMDemodSettings::SyncAMLSB : (AMDemodSettings::SyncAMOperation) syncAMOperationCode;
|
|
|
|
}
|
|
|
|
|
2019-05-20 14:31:15 +00:00
|
|
|
if (channelSettingsKeys.contains("streamIndex")) {
|
|
|
|
settings.m_streamIndex = response.getAmDemodSettings()->getStreamIndex();
|
|
|
|
}
|
2018-12-16 19:41:21 +00:00
|
|
|
if (channelSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getAmDemodSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIAddress")) {
|
2019-04-20 17:11:58 +00:00
|
|
|
settings.m_reverseAPIAddress = *response.getAmDemodSettings()->getReverseApiAddress();
|
2018-12-16 19:41:21 +00:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getAmDemodSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getAmDemodSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
|
|
|
|
settings.m_reverseAPIChannelIndex = response.getAmDemodSettings()->getReverseApiChannelIndex();
|
2018-08-02 21:27:22 +00:00
|
|
|
}
|
2021-12-02 22:54:39 +00:00
|
|
|
if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) {
|
|
|
|
settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getAmDemodSettings()->getChannelMarker());
|
|
|
|
}
|
2022-01-09 04:27:12 +00:00
|
|
|
if (settings.m_rollupState && channelSettingsKeys.contains("rollupState")) {
|
|
|
|
settings.m_rollupState->updateFrom(channelSettingsKeys, response.getAmDemodSettings()->getRollupState());
|
|
|
|
}
|
2018-03-21 22:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AMDemod::webapiReportGet(
|
|
|
|
SWGSDRangel::SWGChannelReport& response,
|
2018-11-12 23:45:03 +00:00
|
|
|
QString& errorMessage)
|
2018-03-21 22:49:16 +00:00
|
|
|
{
|
2018-11-12 23:45:03 +00:00
|
|
|
(void) errorMessage;
|
2018-03-21 22:49:16 +00:00
|
|
|
response.setAmDemodReport(new SWGSDRangel::SWGAMDemodReport());
|
|
|
|
response.getAmDemodReport()->init();
|
|
|
|
webapiFormatChannelReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDemod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const AMDemodSettings& settings)
|
|
|
|
{
|
|
|
|
response.getAmDemodSettings()->setAudioMute(settings.m_audioMute ? 1 : 0);
|
|
|
|
response.getAmDemodSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
|
|
|
|
response.getAmDemodSettings()->setRfBandwidth(settings.m_rfBandwidth);
|
|
|
|
response.getAmDemodSettings()->setRgbColor(settings.m_rgbColor);
|
|
|
|
response.getAmDemodSettings()->setSquelch(settings.m_squelch);
|
|
|
|
response.getAmDemodSettings()->setVolume(settings.m_volume);
|
|
|
|
response.getAmDemodSettings()->setBandpassEnable(settings.m_bandpassEnable ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getAmDemodSettings()->getTitle()) {
|
|
|
|
*response.getAmDemodSettings()->getTitle() = settings.m_title;
|
|
|
|
} else {
|
|
|
|
response.getAmDemodSettings()->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
2018-03-29 05:55:51 +00:00
|
|
|
|
|
|
|
if (response.getAmDemodSettings()->getAudioDeviceName()) {
|
|
|
|
*response.getAmDemodSettings()->getAudioDeviceName() = settings.m_audioDeviceName;
|
|
|
|
} else {
|
|
|
|
response.getAmDemodSettings()->setAudioDeviceName(new QString(settings.m_audioDeviceName));
|
|
|
|
}
|
2018-08-02 21:27:22 +00:00
|
|
|
|
|
|
|
response.getAmDemodSettings()->setPll(settings.m_pll ? 1 : 0);
|
2019-08-01 16:50:21 +00:00
|
|
|
response.getAmDemodSettings()->setSyncAmOperation((int) settings.m_syncAMOperation);
|
|
|
|
response.getAmDemodSettings()->setStreamIndex(settings.m_streamIndex);
|
2018-12-16 19:41:21 +00:00
|
|
|
response.getAmDemodSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getAmDemodSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getAmDemodSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getAmDemodSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getAmDemodSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getAmDemodSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
|
|
|
response.getAmDemodSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex);
|
2021-12-02 22:54:39 +00:00
|
|
|
|
|
|
|
if (settings.m_channelMarker)
|
|
|
|
{
|
|
|
|
if (response.getAmDemodSettings()->getChannelMarker())
|
|
|
|
{
|
|
|
|
settings.m_channelMarker->formatTo(response.getAmDemodSettings()->getChannelMarker());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker();
|
|
|
|
settings.m_channelMarker->formatTo(swgChannelMarker);
|
|
|
|
response.getAmDemodSettings()->setChannelMarker(swgChannelMarker);
|
|
|
|
}
|
|
|
|
}
|
2022-01-09 04:27:12 +00:00
|
|
|
|
|
|
|
if (settings.m_rollupState)
|
|
|
|
{
|
|
|
|
if (response.getAmDemodSettings()->getRollupState())
|
|
|
|
{
|
|
|
|
settings.m_rollupState->formatTo(response.getAmDemodSettings()->getRollupState());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
response.getAmDemodSettings()->setRollupState(swgRollupState);
|
|
|
|
}
|
|
|
|
}
|
2018-03-21 22:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDemod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response)
|
|
|
|
{
|
|
|
|
double magsqAvg, magsqPeak;
|
|
|
|
int nbMagsqSamples;
|
|
|
|
getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples);
|
|
|
|
|
|
|
|
response.getAmDemodReport()->setChannelPowerDb(CalcDb::dbPower(magsqAvg));
|
2019-11-23 06:39:57 +00:00
|
|
|
response.getAmDemodReport()->setSquelch(m_basebandSink->getSquelchOpen() ? 1 : 0);
|
|
|
|
response.getAmDemodReport()->setAudioSampleRate(m_basebandSink->getAudioSampleRate());
|
|
|
|
response.getAmDemodReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate());
|
2018-03-21 22:49:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 02:42:58 +00:00
|
|
|
void AMDemod::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const AMDemodSettings& settings, bool force)
|
2018-12-14 07:51:01 +00:00
|
|
|
{
|
2018-12-15 02:42:58 +00:00
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
2020-10-22 22:11:18 +00: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 12:04:36 +00:00
|
|
|
void AMDemod::sendChannelSettings(
|
|
|
|
QList<MessageQueue*> *messageQueues,
|
|
|
|
QList<QString>& channelSettingsKeys,
|
|
|
|
const AMDemodSettings& settings,
|
|
|
|
bool force)
|
2020-10-22 22:11:18 +00:00
|
|
|
{
|
2020-12-13 12:04:36 +00:00
|
|
|
QList<MessageQueue*>::iterator it = messageQueues->begin();
|
2020-10-22 22:11:18 +00:00
|
|
|
|
2020-12-13 12:04:36 +00:00
|
|
|
for (; it != messageQueues->end(); ++it)
|
2020-10-22 22:11:18 +00:00
|
|
|
{
|
2020-12-13 12:04:36 +00: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 22:11:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDemod::webapiFormatChannelSettings(
|
|
|
|
QList<QString>& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings,
|
|
|
|
const AMDemodSettings& settings,
|
|
|
|
bool force
|
|
|
|
)
|
|
|
|
{
|
2019-05-07 12:43:38 +00:00
|
|
|
swgChannelSettings->setDirection(0); // Single sink (Rx)
|
2019-03-25 00:15:27 +00:00
|
|
|
swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet());
|
|
|
|
swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex());
|
2018-12-15 02:42:58 +00:00
|
|
|
swgChannelSettings->setChannelType(new QString("AMDemod"));
|
|
|
|
swgChannelSettings->setAmDemodSettings(new SWGSDRangel::SWGAMDemodSettings());
|
|
|
|
SWGSDRangel::SWGAMDemodSettings *swgAMDemodSettings = swgChannelSettings->getAmDemodSettings();
|
|
|
|
|
2018-12-16 19:41:21 +00:00
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
2018-12-15 23:51:41 +00:00
|
|
|
|
2018-12-15 02:42:58 +00:00
|
|
|
if (channelSettingsKeys.contains("audioMute") || force) {
|
|
|
|
swgAMDemodSettings->setAudioMute(settings.m_audioMute ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("inputFrequencyOffset") || force) {
|
|
|
|
swgAMDemodSettings->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rfBandwidth") || force) {
|
|
|
|
swgAMDemodSettings->setRfBandwidth(settings.m_rfBandwidth);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor") || force) {
|
|
|
|
swgAMDemodSettings->setRgbColor(settings.m_rgbColor);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("squelch") || force) {
|
|
|
|
swgAMDemodSettings->setSquelch(settings.m_squelch);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title") || force) {
|
|
|
|
swgAMDemodSettings->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("volume") || force) {
|
|
|
|
swgAMDemodSettings->setVolume(settings.m_volume);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("bandpassEnable") || force) {
|
|
|
|
swgAMDemodSettings->setBandpassEnable(settings.m_bandpassEnable ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioDeviceName") || force) {
|
|
|
|
swgAMDemodSettings->setAudioDeviceName(new QString(settings.m_audioDeviceName));
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("pll") || force) {
|
|
|
|
swgAMDemodSettings->setPll(settings.m_pll);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("syncAMOperation") || force) {
|
|
|
|
swgAMDemodSettings->setSyncAmOperation((int) settings.m_syncAMOperation);
|
|
|
|
}
|
2019-05-20 14:31:15 +00:00
|
|
|
if (channelSettingsKeys.contains("streamIndex") || force) {
|
|
|
|
swgAMDemodSettings->setStreamIndex(settings.m_streamIndex);
|
|
|
|
}
|
2021-12-02 22:54:39 +00:00
|
|
|
|
|
|
|
if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker();
|
|
|
|
settings.m_channelMarker->formatTo(swgChannelMarker);
|
|
|
|
swgAMDemodSettings->setChannelMarker(swgChannelMarker);
|
|
|
|
}
|
2022-01-09 04:27:12 +00:00
|
|
|
|
|
|
|
if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
swgAMDemodSettings->setRollupState(swgRollupState);
|
|
|
|
}
|
2018-12-14 07:51:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 23:51:41 +00:00
|
|
|
void AMDemod::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
2018-12-18 05:14:18 +00:00
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
2018-12-15 23:51:41 +00:00
|
|
|
{
|
2018-12-18 05:14:18 +00:00
|
|
|
qWarning() << "AMDemod::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
2019-11-12 17:46:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("AMDemod::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2018-12-15 23:51:41 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 17:46:21 +00:00
|
|
|
reply->deleteLater();
|
2018-12-15 23:51:41 +00:00
|
|
|
}
|
2021-06-29 19:47:27 +00:00
|
|
|
|
|
|
|
void AMDemod::handleChannelMessages()
|
|
|
|
{
|
|
|
|
Message* message;
|
|
|
|
|
|
|
|
while ((message = m_channelMessageQueue.pop()) != nullptr)
|
|
|
|
{
|
|
|
|
if (handleMessage(*message)) {
|
|
|
|
delete message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|