2019-05-01 22:02:40 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2019 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 <boost/crc.hpp>
|
|
|
|
#include <boost/cstdint.hpp>
|
|
|
|
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
|
|
|
|
|
|
|
#include "SWGChannelSettings.h"
|
|
|
|
|
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "dsp/dspdevicesourceengine.h"
|
2019-05-01 22:02:40 -04:00
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
#include "dsp/devicesamplesource.h"
|
|
|
|
#include "dsp/hbfilterchainconverter.h"
|
2019-09-22 19:25:17 -04:00
|
|
|
#include "dsp/devicesamplemimo.h"
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2020-10-22 18:11:18 -04:00
|
|
|
#include "feature/feature.h"
|
|
|
|
#include "maincore.h"
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
#include "localsinkbaseband.h"
|
|
|
|
#include "localsink.h"
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(LocalSink::MsgConfigureLocalSink, Message)
|
2019-12-08 04:09:24 -05:00
|
|
|
MESSAGE_CLASS_DEFINITION(LocalSink::MsgBasebandSampleRateNotification, Message)
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
const QString LocalSink::m_channelIdURI = "sdrangel.channel.localsink";
|
|
|
|
const QString LocalSink::m_channelId = "LocalSink";
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
LocalSink::LocalSink(DeviceAPI *deviceAPI) :
|
2019-05-09 11:27:12 -04:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
2019-05-01 22:02:40 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
|
|
|
m_centerFrequency(0),
|
|
|
|
m_frequencyOffset(0),
|
2019-12-08 04:09:24 -05:00
|
|
|
m_basebandSampleRate(48000)
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
|
|
|
setObjectName(m_channelId);
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_basebandSink = new LocalSinkBaseband();
|
|
|
|
m_basebandSink->moveToThread(m_thread);
|
|
|
|
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
|
|
|
|
m_deviceAPI->addChannelSink(this);
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalSink::~LocalSink()
|
|
|
|
{
|
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
2019-12-08 04:09:24 -05:00
|
|
|
m_deviceAPI->removeChannelSink(this);
|
|
|
|
delete m_basebandSink;
|
|
|
|
delete m_thread;
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
2019-09-22 19:25:17 -04:00
|
|
|
uint32_t LocalSink::getNumberOfDeviceStreams() const
|
|
|
|
{
|
|
|
|
return m_deviceAPI->getNbSourceStreams();
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:02:40 -04:00
|
|
|
void LocalSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst)
|
|
|
|
{
|
|
|
|
(void) firstOfBurst;
|
2019-12-08 04:09:24 -05:00
|
|
|
m_basebandSink->feed(begin, end);
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::start()
|
|
|
|
{
|
2019-12-08 04:09:24 -05:00
|
|
|
qDebug("LocalSink::start");
|
|
|
|
m_basebandSink->reset();
|
|
|
|
m_thread->start();
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::stop()
|
|
|
|
{
|
|
|
|
qDebug("LocalSink::stop");
|
2019-12-08 04:09:24 -05:00
|
|
|
m_thread->exit();
|
|
|
|
m_thread->wait();
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LocalSink::handleMessage(const Message& cmd)
|
|
|
|
{
|
2019-12-08 04:09:24 -05:00
|
|
|
if (DSPSignalNotification::match(cmd))
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
|
|
|
|
|
|
|
qDebug() << "LocalSink::handleMessage: DSPSignalNotification:"
|
|
|
|
<< " inputSampleRate: " << notif.getSampleRate()
|
|
|
|
<< " centerFrequency: " << notif.getCenterFrequency();
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
m_basebandSampleRate = notif.getSampleRate();
|
|
|
|
m_centerFrequency = notif.getCenterFrequency();
|
|
|
|
|
|
|
|
calculateFrequencyOffset(m_settings.m_log2Decim, m_settings.m_filterChainHash); // This is when device sample rate changes
|
|
|
|
propagateSampleRateAndFrequency(m_settings.m_localDeviceIndex, m_settings.m_log2Decim);
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2020-06-26 22:59:40 -04:00
|
|
|
DSPSignalNotification *msg = new DSPSignalNotification(notif.getSampleRate(), notif.getCenterFrequency());
|
2019-12-08 04:09:24 -05:00
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
if (getMessageQueueToGUI())
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
2019-12-08 04:09:24 -05:00
|
|
|
MsgBasebandSampleRateNotification *msg = MsgBasebandSampleRateNotification::create(notif.getSampleRate());
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureLocalSink::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureLocalSink& cfg = (MsgConfigureLocalSink&) cmd;
|
|
|
|
qDebug() << "LocalSink::handleMessage: MsgConfigureLocalSink";
|
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray LocalSink::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LocalSink::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
(void) data;
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureLocalSink *msg = MsgConfigureLocalSink::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureLocalSink *msg = MsgConfigureLocalSink::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::getLocalDevices(std::vector<uint32_t>& indexes)
|
|
|
|
{
|
|
|
|
indexes.clear();
|
|
|
|
DSPEngine *dspEngine = DSPEngine::instance();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < dspEngine->getDeviceSourceEnginesNumber(); i++)
|
|
|
|
{
|
|
|
|
DSPDeviceSourceEngine *deviceSourceEngine = dspEngine->getDeviceSourceEngineByIndex(i);
|
|
|
|
DeviceSampleSource *deviceSource = deviceSourceEngine->getSource();
|
|
|
|
|
|
|
|
if (deviceSource->getDeviceDescription() == "LocalInput") {
|
|
|
|
indexes.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceSampleSource *LocalSink::getLocalDevice(uint32_t index)
|
|
|
|
{
|
|
|
|
DSPEngine *dspEngine = DSPEngine::instance();
|
|
|
|
|
|
|
|
if (index < dspEngine->getDeviceSourceEnginesNumber())
|
|
|
|
{
|
|
|
|
DSPDeviceSourceEngine *deviceSourceEngine = dspEngine->getDeviceSourceEngineByIndex(index);
|
|
|
|
DeviceSampleSource *deviceSource = deviceSourceEngine->getSource();
|
|
|
|
|
|
|
|
if (deviceSource->getDeviceDescription() == "LocalInput")
|
|
|
|
{
|
2019-05-09 11:27:12 -04:00
|
|
|
if (!getDeviceAPI()) {
|
2019-05-01 22:02:40 -04:00
|
|
|
qDebug("LocalSink::getLocalDevice: the parent device is unset");
|
2019-05-09 11:27:12 -04:00
|
|
|
} else if (getDeviceAPI()->getDeviceUID() == deviceSourceEngine->getUID()) {
|
2019-05-01 22:02:40 -04:00
|
|
|
qDebug("LocalSink::getLocalDevice: source device at index %u is the parent device", index);
|
|
|
|
} else {
|
|
|
|
return deviceSource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("LocalSink::getLocalDevice: source device at index %u is not a Local Input source", index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("LocalSink::getLocalDevice: non existent source device index: %u", index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
void LocalSink::propagateSampleRateAndFrequency(uint32_t index, uint32_t log2Decim)
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
2019-12-08 04:09:24 -05:00
|
|
|
qDebug() << "LocalSink::propagateSampleRateAndFrequency:"
|
|
|
|
<< " index: " << index
|
|
|
|
<< " baseband_freq: " << m_basebandSampleRate
|
|
|
|
<< " log2Decim: " << log2Decim
|
|
|
|
<< " frequency: " << m_centerFrequency + m_frequencyOffset;
|
|
|
|
|
2019-05-01 22:02:40 -04:00
|
|
|
DeviceSampleSource *deviceSource = getLocalDevice(index);
|
|
|
|
|
|
|
|
if (deviceSource)
|
|
|
|
{
|
2019-12-08 04:09:24 -05:00
|
|
|
deviceSource->setSampleRate(m_basebandSampleRate / (1 << log2Decim));
|
2019-05-01 22:02:40 -04:00
|
|
|
deviceSource->setCenterFrequency(m_centerFrequency + m_frequencyOffset);
|
|
|
|
}
|
2019-12-08 04:09:24 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("LocalSink::propagateSampleRateAndFrequency: no suitable device at index %u", index);
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::applySettings(const LocalSinkSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "LocalSink::applySettings:"
|
2019-12-08 04:09:24 -05:00
|
|
|
<< "m_localDeviceIndex: " << settings.m_localDeviceIndex
|
|
|
|
<< "m_streamIndex: " << settings.m_streamIndex
|
|
|
|
<< "m_play:" << settings.m_play
|
|
|
|
<< "force: " << force;
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
if ((settings.m_log2Decim != m_settings.m_log2Decim) || force) {
|
|
|
|
reverseAPIKeys.append("log2Decim");
|
|
|
|
}
|
|
|
|
if ((settings.m_filterChainHash != m_settings.m_filterChainHash) || force) {
|
|
|
|
reverseAPIKeys.append("filterChainHash");
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:02:40 -04:00
|
|
|
if ((settings.m_localDeviceIndex != m_settings.m_localDeviceIndex) || force)
|
|
|
|
{
|
|
|
|
reverseAPIKeys.append("localDeviceIndex");
|
2019-12-08 04:09:24 -05:00
|
|
|
propagateSampleRateAndFrequency(settings.m_localDeviceIndex, settings.m_log2Decim);
|
2019-05-01 22:02:40 -04:00
|
|
|
DeviceSampleSource *deviceSource = getLocalDevice(settings.m_localDeviceIndex);
|
2019-12-08 04:09:24 -05:00
|
|
|
LocalSinkBaseband::MsgConfigureLocalDeviceSampleSource *msg =
|
|
|
|
LocalSinkBaseband::MsgConfigureLocalDeviceSampleSource::create(deviceSource);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
if ((settings.m_log2Decim != m_settings.m_log2Decim)
|
|
|
|
|| (settings.m_filterChainHash != m_settings.m_filterChainHash) || force)
|
|
|
|
{
|
|
|
|
calculateFrequencyOffset(settings.m_log2Decim, settings.m_filterChainHash);
|
|
|
|
propagateSampleRateAndFrequency(m_settings.m_localDeviceIndex, settings.m_log2Decim);
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
if ((settings.m_play != m_settings.m_play) || force)
|
|
|
|
{
|
|
|
|
reverseAPIKeys.append("play");
|
|
|
|
LocalSinkBaseband::MsgConfigureLocalSinkWork *msg = LocalSinkBaseband::MsgConfigureLocalSinkWork::create(
|
|
|
|
settings.m_play
|
|
|
|
);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
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-08 04:09:24 -05:00
|
|
|
m_deviceAPI->removeChannelSink(this, m_settings.m_streamIndex);
|
2019-12-23 17:41:35 -05:00
|
|
|
m_deviceAPI->addChannelSink(this, settings.m_streamIndex);
|
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
2019-09-22 19:25:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
reverseAPIKeys.append("streamIndex");
|
|
|
|
}
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
LocalSinkBaseband::MsgConfigureLocalSinkBaseband *msg = LocalSinkBaseband::MsgConfigureLocalSinkBaseband::create(settings, force);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
|
2019-05-01 22:02:40 -04:00
|
|
|
if ((settings.m_useReverseAPI) && (reverseAPIKeys.size() != 0))
|
|
|
|
{
|
|
|
|
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-10-22 18:11:18 -04:00
|
|
|
if (m_featuresSettingsFeedback.size() > 0) {
|
|
|
|
featuresSendSettings(reverseAPIKeys, settings, force);
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:02:40 -04:00
|
|
|
m_settings = settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::validateFilterChainHash(LocalSinkSettings& settings)
|
|
|
|
{
|
|
|
|
unsigned int s = 1;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < settings.m_log2Decim; i++) {
|
|
|
|
s *= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.m_filterChainHash = settings.m_filterChainHash >= s ? s-1 : settings.m_filterChainHash;
|
|
|
|
}
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
void LocalSink::calculateFrequencyOffset(uint32_t log2Decim, uint32_t filterChainHash)
|
2019-05-01 22:02:40 -04:00
|
|
|
{
|
2019-12-08 04:09:24 -05:00
|
|
|
double shiftFactor = HBFilterChainConverter::getShiftFactor(log2Decim, filterChainHash);
|
|
|
|
m_frequencyOffset = m_basebandSampleRate * shiftFactor;
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int LocalSink::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
2019-05-02 03:54:08 -04:00
|
|
|
response.setLocalSinkSettings(new SWGSDRangel::SWGLocalSinkSettings());
|
|
|
|
response.getLocalSinkSettings()->init();
|
2019-05-01 22:02:40 -04:00
|
|
|
webapiFormatChannelSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LocalSink::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
LocalSinkSettings settings = m_settings;
|
2019-08-01 17:21:57 -04:00
|
|
|
webapiUpdateChannelSettings(settings, channelSettingsKeys, response);
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2019-08-01 17:21:57 -04:00
|
|
|
MsgConfigureLocalSink *msg = MsgConfigureLocalSink::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
qDebug("LocalSink::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureLocalSink *msgToGUI = MsgConfigureLocalSink::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatChannelSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::webapiUpdateChannelSettings(
|
|
|
|
LocalSinkSettings& settings,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response)
|
|
|
|
{
|
2019-05-01 22:02:40 -04:00
|
|
|
if (channelSettingsKeys.contains("localDeviceIndex")) {
|
|
|
|
settings.m_localDeviceIndex = response.getLocalSinkSettings()->getLocalDeviceIndex();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor")) {
|
|
|
|
settings.m_rgbColor = response.getLocalSinkSettings()->getRgbColor();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title")) {
|
|
|
|
settings.m_title = *response.getLocalSinkSettings()->getTitle();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("log2Decim")) {
|
|
|
|
settings.m_log2Decim = response.getLocalSinkSettings()->getLog2Decim();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("filterChainHash"))
|
|
|
|
{
|
|
|
|
settings.m_filterChainHash = response.getLocalSinkSettings()->getFilterChainHash();
|
|
|
|
validateFilterChainHash(settings);
|
|
|
|
}
|
|
|
|
|
2019-12-09 04:35:21 -05:00
|
|
|
if (channelSettingsKeys.contains("play")) {
|
|
|
|
settings.m_play = response.getLocalSinkSettings()->getPlay() != 0;
|
|
|
|
}
|
2019-09-22 19:25:17 -04:00
|
|
|
if (channelSettingsKeys.contains("streamIndex")) {
|
|
|
|
settings.m_streamIndex = response.getLocalSinkSettings()->getStreamIndex();
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
if (channelSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getLocalSinkSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIAddress")) {
|
|
|
|
settings.m_reverseAPIAddress = *response.getLocalSinkSettings()->getReverseApiAddress();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getLocalSinkSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getLocalSinkSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
|
|
|
|
settings.m_reverseAPIChannelIndex = response.getLocalSinkSettings()->getReverseApiChannelIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const LocalSinkSettings& settings)
|
|
|
|
{
|
|
|
|
response.getLocalSinkSettings()->setLocalDeviceIndex(settings.m_localDeviceIndex);
|
|
|
|
response.getLocalSinkSettings()->setRgbColor(settings.m_rgbColor);
|
|
|
|
|
|
|
|
if (response.getLocalSinkSettings()->getTitle()) {
|
|
|
|
*response.getLocalSinkSettings()->getTitle() = settings.m_title;
|
|
|
|
} else {
|
|
|
|
response.getLocalSinkSettings()->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getLocalSinkSettings()->setLog2Decim(settings.m_log2Decim);
|
|
|
|
response.getLocalSinkSettings()->setFilterChainHash(settings.m_filterChainHash);
|
2019-12-09 04:35:21 -05:00
|
|
|
response.getLocalSinkSettings()->setPlay(settings.m_play ? 1 : 0);
|
2019-09-22 19:25:17 -04:00
|
|
|
response.getLocalSinkSettings()->setStreamIndex(settings.m_streamIndex);
|
2019-05-01 22:02:40 -04:00
|
|
|
response.getLocalSinkSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getLocalSinkSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getLocalSinkSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getLocalSinkSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getLocalSinkSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getLocalSinkSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
|
|
|
response.getLocalSinkSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const LocalSinkSettings& 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::featuresSendSettings(QList<QString>& channelSettingsKeys, const LocalSinkSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
QList<Feature*>::iterator it = m_featuresSettingsFeedback.begin();
|
|
|
|
MainCore *mainCore = MainCore::instance();
|
|
|
|
|
|
|
|
for (; it != m_featuresSettingsFeedback.end(); ++it)
|
|
|
|
{
|
|
|
|
if (mainCore->existsFeature(*it))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
|
|
|
webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force);
|
|
|
|
|
|
|
|
Feature::MsgChannelSettings *msg = Feature::MsgChannelSettings::create(
|
|
|
|
this,
|
|
|
|
channelSettingsKeys,
|
|
|
|
swgChannelSettings,
|
|
|
|
force
|
|
|
|
);
|
|
|
|
|
|
|
|
(*it)->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_featuresSettingsFeedback.removeOne(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::webapiFormatChannelSettings(
|
|
|
|
QList<QString>& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings,
|
|
|
|
const LocalSinkSettings& settings,
|
|
|
|
bool force
|
|
|
|
)
|
|
|
|
{
|
|
|
|
swgChannelSettings->setDirection(0); // Single sink (Rx)
|
2019-05-01 22:02:40 -04:00
|
|
|
swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet());
|
|
|
|
swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex());
|
2020-10-22 18:11:18 -04:00
|
|
|
swgChannelSettings->setChannelType(new QString(m_channelId));
|
2019-05-01 22:02:40 -04:00
|
|
|
swgChannelSettings->setLocalSinkSettings(new SWGSDRangel::SWGLocalSinkSettings());
|
|
|
|
SWGSDRangel::SWGLocalSinkSettings *swgLocalSinkSettings = swgChannelSettings->getLocalSinkSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("localDeviceIndex") || force) {
|
|
|
|
swgLocalSinkSettings->setLocalDeviceIndex(settings.m_localDeviceIndex);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor") || force) {
|
|
|
|
swgLocalSinkSettings->setRgbColor(settings.m_rgbColor);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title") || force) {
|
|
|
|
swgLocalSinkSettings->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("log2Decim") || force) {
|
|
|
|
swgLocalSinkSettings->setLog2Decim(settings.m_log2Decim);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("filterChainHash") || force) {
|
|
|
|
swgLocalSinkSettings->setFilterChainHash(settings.m_filterChainHash);
|
|
|
|
}
|
2019-12-09 04:35:21 -05:00
|
|
|
if (channelSettingsKeys.contains("play") || force) {
|
|
|
|
swgLocalSinkSettings->setPlay(settings.m_play ? 1 : 0);
|
|
|
|
}
|
2019-09-22 19:25:17 -04:00
|
|
|
if (channelSettingsKeys.contains("streamIndex") || force) {
|
|
|
|
swgLocalSinkSettings->setStreamIndex(settings.m_streamIndex);
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "LocalSink::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("LocalSink::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
reply->deleteLater();
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|