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"
|
2022-05-13 16:24:48 -04:00
|
|
|
#include "SWGWorkspaceInfo.h"
|
2019-05-01 22:02:40 -04:00
|
|
|
|
|
|
|
#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"
|
2021-12-02 17:54:39 -05:00
|
|
|
#include "settings/serializable.h"
|
2020-10-22 18:11:18 -04:00
|
|
|
#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)
|
|
|
|
|
2020-11-21 14:24:18 -05:00
|
|
|
const char* const LocalSink::m_channelIdURI = "sdrangel.channel.localsink";
|
|
|
|
const char* const LocalSink::m_channelId = "LocalSink";
|
2019-05-01 22:02:40 -04:00
|
|
|
|
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),
|
2022-10-13 18:03:57 -04:00
|
|
|
m_thread(nullptr),
|
|
|
|
m_basebandSink(nullptr),
|
|
|
|
m_running(false),
|
2019-05-01 22:02:40 -04:00
|
|
|
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
|
|
|
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();
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::connect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&LocalSink::networkManagerFinished
|
|
|
|
);
|
2022-03-18 12:08:04 -04:00
|
|
|
QObject::connect(
|
|
|
|
this,
|
|
|
|
&ChannelAPI::indexInDeviceSetChanged,
|
|
|
|
this,
|
|
|
|
&LocalSink::handleIndexInDeviceSetChanged
|
|
|
|
);
|
2022-10-13 18:03:57 -04:00
|
|
|
start();
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
LocalSink::~LocalSink()
|
|
|
|
{
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::disconnect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&LocalSink::networkManagerFinished
|
|
|
|
);
|
2019-05-01 22:02:40 -04:00
|
|
|
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);
|
2022-10-13 18:03:57 -04:00
|
|
|
stop();
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
2022-04-16 10:45:53 -04:00
|
|
|
void LocalSink::setDeviceAPI(DeviceAPI *deviceAPI)
|
|
|
|
{
|
|
|
|
if (deviceAPI != m_deviceAPI)
|
|
|
|
{
|
|
|
|
m_deviceAPI->removeChannelSinkAPI(this);
|
|
|
|
m_deviceAPI->removeChannelSink(this);
|
|
|
|
m_deviceAPI = deviceAPI;
|
|
|
|
m_deviceAPI->addChannelSink(this);
|
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2022-10-13 18:03:57 -04:00
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
m_basebandSink->feed(begin, end);
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::start()
|
|
|
|
{
|
2022-10-13 18:03:57 -04:00
|
|
|
if (m_running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
qDebug("LocalSink::start");
|
2022-10-13 18:03:57 -04:00
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_basebandSink = new LocalSinkBaseband();
|
|
|
|
m_basebandSink->moveToThread(m_thread);
|
|
|
|
|
|
|
|
QObject::connect(m_thread, &QThread::finished, m_basebandSink, &QObject::deleteLater);
|
|
|
|
QObject::connect(m_thread, &QThread::finished, m_thread, &QThread::deleteLater);
|
|
|
|
|
2019-12-08 04:09:24 -05:00
|
|
|
m_basebandSink->reset();
|
|
|
|
m_thread->start();
|
2022-10-13 18:03:57 -04:00
|
|
|
|
|
|
|
LocalSinkBaseband::MsgConfigureLocalSinkBaseband *msg = LocalSinkBaseband::MsgConfigureLocalSinkBaseband::create(m_settings, true);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
|
|
|
|
m_running = true;
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void LocalSink::stop()
|
|
|
|
{
|
2022-10-13 18:03:57 -04:00
|
|
|
if (!m_running) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:02:40 -04:00
|
|
|
qDebug("LocalSink::stop");
|
2022-10-13 18:03:57 -04:00
|
|
|
m_running = false;
|
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
|
|
|
|
2022-10-13 18:03:57 -04:00
|
|
|
if (m_running)
|
|
|
|
{
|
|
|
|
DSPSignalNotification *msg = new DSPSignalNotification(notif.getSampleRate(), notif.getCenterFrequency());
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
|
2022-04-13 05:08:21 -04:00
|
|
|
if (getMessageQueueToGUI()) {
|
|
|
|
getMessageQueueToGUI()->push(new DSPSignalNotification(notif));
|
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);
|
2022-10-13 18:03:57 -04:00
|
|
|
|
|
|
|
if (m_running)
|
|
|
|
{
|
|
|
|
DeviceSampleSource *deviceSource = getLocalDevice(settings.m_localDeviceIndex);
|
|
|
|
LocalSinkBaseband::MsgConfigureLocalDeviceSampleSource *msg =
|
|
|
|
LocalSinkBaseband::MsgConfigureLocalDeviceSampleSource::create(deviceSource);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2019-12-08 04:09:24 -05:00
|
|
|
}
|
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");
|
2022-10-13 18:03:57 -04:00
|
|
|
|
|
|
|
if (m_running)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2022-10-13 18:03:57 -04:00
|
|
|
if (m_running)
|
|
|
|
{
|
|
|
|
LocalSinkBaseband::MsgConfigureLocalSinkBaseband *msg = LocalSinkBaseband::MsgConfigureLocalSinkBaseband::create(settings, force);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
}
|
2019-12-08 04:09:24 -05:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-03-02 17:07:15 -05:00
|
|
|
QList<ObjectPipe*> pipes;
|
2022-03-02 17:57:35 -05:00
|
|
|
MainCore::instance()->getMessagePipes().getMessagePipes(this, "settings", pipes);
|
2020-12-13 07:04:36 -05:00
|
|
|
|
2022-03-02 17:07:15 -05:00
|
|
|
if (pipes.size() > 0) {
|
|
|
|
sendChannelSettings(pipes, reverseAPIKeys, settings, force);
|
2020-10-22 18:11:18 -04:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-05-13 16:24:48 -04:00
|
|
|
int LocalSink::webapiWorkspaceGet(
|
|
|
|
SWGSDRangel::SWGWorkspaceInfo& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
response.setIndex(m_settings.m_workspaceIndex);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:02:40 -04:00
|
|
|
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();
|
|
|
|
}
|
2021-12-02 17:54:39 -05:00
|
|
|
if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) {
|
|
|
|
settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getLocalSinkSettings()->getChannelMarker());
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
if (settings.m_rollupState && channelSettingsKeys.contains("rollupState")) {
|
|
|
|
settings.m_rollupState->updateFrom(channelSettingsKeys, response.getLocalSinkSettings()->getRollupState());
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-12-02 17:54:39 -05:00
|
|
|
|
|
|
|
if (settings.m_channelMarker)
|
|
|
|
{
|
|
|
|
if (response.getLocalSinkSettings()->getChannelMarker())
|
|
|
|
{
|
|
|
|
settings.m_channelMarker->formatTo(response.getLocalSinkSettings()->getChannelMarker());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker();
|
|
|
|
settings.m_channelMarker->formatTo(swgChannelMarker);
|
|
|
|
response.getLocalSinkSettings()->setChannelMarker(swgChannelMarker);
|
|
|
|
}
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
|
|
|
|
if (settings.m_rollupState)
|
|
|
|
{
|
|
|
|
if (response.getLocalSinkSettings()->getRollupState())
|
|
|
|
{
|
|
|
|
settings.m_rollupState->formatTo(response.getLocalSinkSettings()->getRollupState());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
response.getLocalSinkSettings()->setRollupState(swgRollupState);
|
|
|
|
}
|
|
|
|
}
|
2019-05-01 22:02:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-13 07:04:36 -05:00
|
|
|
void LocalSink::sendChannelSettings(
|
2022-03-02 17:07:15 -05:00
|
|
|
const QList<ObjectPipe*>& pipes,
|
2020-12-13 07:04:36 -05:00
|
|
|
QList<QString>& channelSettingsKeys,
|
|
|
|
const LocalSinkSettings& settings,
|
|
|
|
bool force)
|
2020-10-22 18:11:18 -04:00
|
|
|
{
|
2022-03-02 17:07:15 -05:00
|
|
|
for (const auto& pipe : pipes)
|
2020-10-22 18:11:18 -04:00
|
|
|
{
|
2022-03-02 17:07:15 -05:00
|
|
|
MessageQueue *messageQueue = qobject_cast<MessageQueue*>(pipe->m_element);
|
|
|
|
|
|
|
|
if (messageQueue)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
|
|
|
webapiFormatChannelSettings(channelSettingsKeys, swgChannelSettings, settings, force);
|
|
|
|
MainCore::MsgChannelSettings *msg = MainCore::MsgChannelSettings::create(
|
|
|
|
this,
|
|
|
|
channelSettingsKeys,
|
|
|
|
swgChannelSettings,
|
|
|
|
force
|
|
|
|
);
|
|
|
|
messageQueue->push(msg);
|
|
|
|
}
|
2020-10-22 18:11:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2021-12-02 17:54:39 -05:00
|
|
|
|
|
|
|
if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker();
|
|
|
|
settings.m_channelMarker->formatTo(swgChannelMarker);
|
|
|
|
swgLocalSinkSettings->setChannelMarker(swgChannelMarker);
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
|
|
|
|
if (settings.m_rollupState && (channelSettingsKeys.contains("rollupState") || force))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
swgLocalSinkSettings->setRollupState(swgRollupState);
|
|
|
|
}
|
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
|
|
|
}
|
2022-03-18 12:08:04 -04:00
|
|
|
|
|
|
|
void LocalSink::handleIndexInDeviceSetChanged(int index)
|
|
|
|
{
|
2022-10-13 18:03:57 -04:00
|
|
|
if (!m_running || (index < 0)) {
|
2022-03-18 12:08:04 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString fifoLabel = QString("%1 [%2:%3]")
|
|
|
|
.arg(m_channelId)
|
|
|
|
.arg(m_deviceAPI->getDeviceSetIndex())
|
|
|
|
.arg(index);
|
|
|
|
m_basebandSink->setFifoLabel(fifoLabel);
|
|
|
|
}
|