2018-09-04 19:32:29 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 Edouard Griffiths, F4EXB. //
|
|
|
|
// //
|
2019-01-22 17:39:12 -05:00
|
|
|
// Remote sink channel (Rx) UDP sender thread //
|
2018-09-04 19:32:29 -04:00
|
|
|
// //
|
2019-01-22 17:39:12 -05:00
|
|
|
// SDRangel can work as a detached SDR front end. With this plugin it can //
|
|
|
|
// sends the I/Q samples stream to another SDRangel instance via UDP. //
|
|
|
|
// It is controlled via a Web REST API. //
|
2018-09-04 19:32:29 -04: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 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2018-09-04 19:32:29 -04: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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
#include "remotesink.h"
|
|
|
|
|
2018-12-21 11:39:04 -05:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2019-12-10 02:26:53 -05:00
|
|
|
#include <QThread>
|
2018-12-21 11:39:04 -05:00
|
|
|
|
2018-09-04 19:32:29 -04:00
|
|
|
#include "SWGChannelSettings.h"
|
|
|
|
|
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
2019-04-26 19:19:17 -04:00
|
|
|
#include "dsp/hbfilterchainconverter.h"
|
2019-09-22 19:25:17 -04:00
|
|
|
#include "dsp/devicesamplemimo.h"
|
2019-12-11 17:19:22 -05:00
|
|
|
#include "dsp/dspdevicesourceengine.h"
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2018-09-04 19:32:29 -04:00
|
|
|
|
2019-12-10 02:26:53 -05:00
|
|
|
#include "remotesinkbaseband.h"
|
2019-01-22 17:39:12 -05:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteSink::MsgConfigureRemoteSink, Message)
|
2018-09-04 19:32:29 -04:00
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
const QString RemoteSink::m_channelIdURI = "sdrangel.channel.remotesink";
|
|
|
|
const QString RemoteSink::m_channelId = "RemoteSink";
|
2018-09-04 19:32:29 -04:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
RemoteSink::RemoteSink(DeviceAPI *deviceAPI) :
|
2019-05-09 11:27:12 -04:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink),
|
2018-09-04 19:32:29 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
2019-04-25 19:27:36 -04:00
|
|
|
m_frequencyOffset(0),
|
2019-12-10 21:03:36 -05:00
|
|
|
m_basebandSampleRate(0)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
|
|
|
setObjectName(m_channelId);
|
|
|
|
|
2019-12-10 02:26:53 -05:00
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_basebandSink = new RemoteSinkBaseband();
|
|
|
|
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);
|
2018-12-21 11:39:04 -05:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
RemoteSink::~RemoteSink()
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2018-12-21 11:39:04 -05:00
|
|
|
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-10 02:26:53 -05:00
|
|
|
m_deviceAPI->removeChannelSink(this);
|
|
|
|
delete m_basebandSink;
|
|
|
|
delete m_thread;
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-09-22 19:25:17 -04:00
|
|
|
uint32_t RemoteSink::getNumberOfDeviceStreams() const
|
|
|
|
{
|
|
|
|
return m_deviceAPI->getNbSourceStreams();
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) firstOfBurst;
|
2019-12-10 02:26:53 -05:00
|
|
|
m_basebandSink->feed(begin, end);
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::start()
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-12-10 21:03:36 -05:00
|
|
|
qDebug("RemoteSink::start: m_basebandSampleRate: %d", m_basebandSampleRate);
|
2019-12-10 02:26:53 -05:00
|
|
|
m_basebandSink->reset();
|
2019-12-10 21:03:36 -05:00
|
|
|
|
|
|
|
if (m_basebandSampleRate != 0) {
|
|
|
|
m_basebandSink->setBasebandSampleRate(m_basebandSampleRate);
|
|
|
|
}
|
|
|
|
|
2019-12-10 02:26:53 -05:00
|
|
|
m_thread->start();
|
2019-12-11 17:19:22 -05:00
|
|
|
m_basebandSink->startSender();
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::stop()
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug("RemoteSink::stop");
|
2019-12-11 17:19:22 -05:00
|
|
|
m_basebandSink->stopSender();
|
2019-12-10 02:26:53 -05:00
|
|
|
m_thread->exit();
|
|
|
|
m_thread->wait();
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
bool RemoteSink::handleMessage(const Message& cmd)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-12-10 21:03:36 -05:00
|
|
|
if (MsgConfigureRemoteSink::match(cmd))
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-12-10 21:03:36 -05:00
|
|
|
MsgConfigureRemoteSink& cfg = (MsgConfigureRemoteSink&) cmd;
|
|
|
|
qDebug() << "RemoteSink::handleMessage: MsgConfigureRemoteSink";
|
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
2018-09-04 19:32:29 -04:00
|
|
|
|
2019-12-10 21:03:36 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
2019-12-10 02:26:53 -05:00
|
|
|
m_basebandSampleRate = notif.getSampleRate();
|
2019-12-10 21:03:36 -05:00
|
|
|
qDebug() << "RemoteSink::handleMessage: DSPSignalNotification: m_basebandSampleRate:" << m_basebandSampleRate;
|
2019-12-12 17:49:19 -05:00
|
|
|
calculateFrequencyOffset();
|
2018-09-04 19:32:29 -04:00
|
|
|
|
2019-12-10 21:03:36 -05:00
|
|
|
// Forward to the sink
|
|
|
|
DSPSignalNotification* msgToBaseband = new DSPSignalNotification(notif); // make a copy
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msgToBaseband);
|
2019-04-26 06:06:36 -04:00
|
|
|
|
2019-12-10 21:03:36 -05:00
|
|
|
// Forward to the GUI
|
|
|
|
if (getMessageQueueToGUI())
|
2019-04-25 19:27:36 -04:00
|
|
|
{
|
2019-12-10 21:03:36 -05:00
|
|
|
DSPSignalNotification* msgToGUI = new DSPSignalNotification(notif); // make a copy
|
2019-12-11 17:19:22 -05:00
|
|
|
getMessageQueueToGUI()->push(msgToGUI);
|
2019-04-25 19:27:36 -04:00
|
|
|
}
|
|
|
|
|
2019-12-10 21:03:36 -05:00
|
|
|
return true;
|
2019-04-25 19:27:36 -04:00
|
|
|
}
|
2018-09-04 19:32:29 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
QByteArray RemoteSink::serialize() const
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
bool RemoteSink::deserialize(const QByteArray& data)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) data;
|
2018-09-04 19:32:29 -04:00
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
MsgConfigureRemoteSink *msg = MsgConfigureRemoteSink::create(m_settings, true);
|
2018-09-04 19:32:29 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
2019-01-22 17:39:12 -05:00
|
|
|
MsgConfigureRemoteSink *msg = MsgConfigureRemoteSink::create(m_settings, true);
|
2018-09-04 19:32:29 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::applySettings(const RemoteSinkSettings& settings, bool force)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug() << "RemoteSink::applySettings:"
|
2018-09-04 19:32:29 -04:00
|
|
|
<< " m_nbFECBlocks: " << settings.m_nbFECBlocks
|
|
|
|
<< " m_txDelay: " << settings.m_txDelay
|
|
|
|
<< " m_dataAddress: " << settings.m_dataAddress
|
|
|
|
<< " m_dataPort: " << settings.m_dataPort
|
2019-09-22 19:25:17 -04:00
|
|
|
<< " m_streamIndex: " << settings.m_streamIndex
|
2018-09-04 19:32:29 -04:00
|
|
|
<< " force: " << force;
|
|
|
|
|
2018-12-21 11:39:04 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
2019-12-12 17:49:19 -05:00
|
|
|
bool frequencyOffsetChange = false;
|
2018-12-21 11:39:04 -05:00
|
|
|
|
2019-12-10 02:26:53 -05:00
|
|
|
if ((m_settings.m_nbFECBlocks != settings.m_nbFECBlocks) || force) {
|
2018-12-21 11:39:04 -05:00
|
|
|
reverseAPIKeys.append("nbFECBlocks");
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
2019-12-10 02:26:53 -05:00
|
|
|
if ((m_settings.m_txDelay != settings.m_txDelay) || force) {
|
2018-12-21 11:39:04 -05:00
|
|
|
reverseAPIKeys.append("txDelay");
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
2019-12-10 02:26:53 -05:00
|
|
|
if ((m_settings.m_dataAddress != settings.m_dataAddress) || force) {
|
2018-12-21 11:39:04 -05:00
|
|
|
reverseAPIKeys.append("dataAddress");
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
2019-12-10 02:26:53 -05:00
|
|
|
if ((m_settings.m_dataPort != settings.m_dataPort) || force) {
|
2018-12-21 11:39:04 -05:00
|
|
|
reverseAPIKeys.append("dataPort");
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
2019-12-12 17:49:19 -05:00
|
|
|
if ((m_settings.m_rgbColor != settings.m_rgbColor) || force) {
|
|
|
|
reverseAPIKeys.append("rgbColor");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_title != settings.m_title) || force) {
|
|
|
|
reverseAPIKeys.append("title");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
|
|
|
|
{
|
|
|
|
reverseAPIKeys.append("log2Decim");
|
|
|
|
frequencyOffsetChange = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_filterChainHash != settings.m_filterChainHash) || force)
|
|
|
|
{
|
|
|
|
reverseAPIKeys.append("filterChainHash");
|
|
|
|
frequencyOffsetChange = true;
|
|
|
|
}
|
2018-09-04 19:32:29 -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-10 02:26:53 -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-10 02:26:53 -05:00
|
|
|
RemoteSinkBaseband::MsgConfigureRemoteSinkBaseband *msg = RemoteSinkBaseband::MsgConfigureRemoteSinkBaseband::create(settings, force);
|
|
|
|
m_basebandSink->getInputMessageQueue()->push(msg);
|
|
|
|
|
2018-12-21 11:39:04 -05: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);
|
|
|
|
}
|
|
|
|
|
2018-09-04 19:32:29 -04:00
|
|
|
m_settings = settings;
|
2019-12-12 17:49:19 -05:00
|
|
|
|
|
|
|
if (frequencyOffsetChange) {
|
|
|
|
calculateFrequencyOffset();
|
|
|
|
}
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-04-26 08:34:01 -04:00
|
|
|
void RemoteSink::validateFilterChainHash(RemoteSinkSettings& 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-04-26 19:19:17 -04:00
|
|
|
void RemoteSink::calculateFrequencyOffset()
|
|
|
|
{
|
|
|
|
double shiftFactor = HBFilterChainConverter::getShiftFactor(m_settings.m_log2Decim, m_settings.m_filterChainHash);
|
2019-12-10 02:26:53 -05:00
|
|
|
m_frequencyOffset = m_basebandSampleRate * shiftFactor;
|
2019-04-26 19:19:17 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
int RemoteSink::webapiSettingsGet(
|
2018-09-04 19:32:29 -04:00
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2019-01-22 17:39:12 -05:00
|
|
|
response.setRemoteSinkSettings(new SWGSDRangel::SWGRemoteSinkSettings());
|
|
|
|
response.getRemoteSinkSettings()->init();
|
2018-09-04 19:32:29 -04:00
|
|
|
webapiFormatChannelSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
int RemoteSink::webapiSettingsPutPatch(
|
2018-09-04 19:32:29 -04:00
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2019-01-22 17:39:12 -05:00
|
|
|
RemoteSinkSettings settings = m_settings;
|
2019-08-01 17:21:57 -04:00
|
|
|
webapiUpdateChannelSettings(settings, channelSettingsKeys, response);
|
2018-09-04 19:32:29 -04:00
|
|
|
|
2019-08-01 17:21:57 -04:00
|
|
|
MsgConfigureRemoteSink *msg = MsgConfigureRemoteSink::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
qDebug("RemoteSink::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
2019-12-10 02:26:53 -05:00
|
|
|
|
2019-08-01 17:21:57 -04:00
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureRemoteSink *msgToGUI = MsgConfigureRemoteSink::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatChannelSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSink::webapiUpdateChannelSettings(
|
|
|
|
RemoteSinkSettings& settings,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response)
|
|
|
|
{
|
2018-09-04 19:32:29 -04:00
|
|
|
if (channelSettingsKeys.contains("nbFECBlocks"))
|
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
int nbFECBlocks = response.getRemoteSinkSettings()->getNbFecBlocks();
|
2018-09-04 19:32:29 -04:00
|
|
|
|
|
|
|
if ((nbFECBlocks < 0) || (nbFECBlocks > 127)) {
|
|
|
|
settings.m_nbFECBlocks = 8;
|
|
|
|
} else {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_nbFECBlocks = response.getRemoteSinkSettings()->getNbFecBlocks();
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("txDelay"))
|
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
int txDelay = response.getRemoteSinkSettings()->getTxDelay();
|
2018-09-04 19:32:29 -04:00
|
|
|
|
|
|
|
if (txDelay < 0) {
|
2018-09-05 22:36:56 -04:00
|
|
|
settings.m_txDelay = 35;
|
2018-09-04 19:32:29 -04:00
|
|
|
} else {
|
|
|
|
settings.m_txDelay = txDelay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("dataAddress")) {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_dataAddress = *response.getRemoteSinkSettings()->getDataAddress();
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("dataPort"))
|
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
int dataPort = response.getRemoteSinkSettings()->getDataPort();
|
2018-09-04 19:32:29 -04:00
|
|
|
|
|
|
|
if ((dataPort < 1024) || (dataPort > 65535)) {
|
|
|
|
settings.m_dataPort = 9090;
|
|
|
|
} else {
|
|
|
|
settings.m_dataPort = dataPort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-08 13:24:38 -04:00
|
|
|
if (channelSettingsKeys.contains("rgbColor")) {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_rgbColor = response.getRemoteSinkSettings()->getRgbColor();
|
2018-09-08 13:24:38 -04:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title")) {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_title = *response.getRemoteSinkSettings()->getTitle();
|
2018-09-08 13:24:38 -04:00
|
|
|
}
|
2019-04-26 08:34:01 -04:00
|
|
|
if (channelSettingsKeys.contains("log2Decim")) {
|
|
|
|
settings.m_log2Decim = response.getRemoteSinkSettings()->getLog2Decim();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("filterChainHash"))
|
|
|
|
{
|
|
|
|
settings.m_filterChainHash = response.getRemoteSinkSettings()->getFilterChainHash();
|
|
|
|
validateFilterChainHash(settings);
|
|
|
|
}
|
|
|
|
|
2019-09-22 19:25:17 -04:00
|
|
|
if (channelSettingsKeys.contains("streamIndex")) {
|
|
|
|
settings.m_streamIndex = response.getRemoteSinkSettings()->getStreamIndex();
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:39:04 -05:00
|
|
|
if (channelSettingsKeys.contains("useReverseAPI")) {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_useReverseAPI = response.getRemoteSinkSettings()->getUseReverseApi() != 0;
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIAddress")) {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_reverseAPIAddress = *response.getRemoteSinkSettings()->getReverseApiAddress();
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIPort")) {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_reverseAPIPort = response.getRemoteSinkSettings()->getReverseApiPort();
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_reverseAPIDeviceIndex = response.getRemoteSinkSettings()->getReverseApiDeviceIndex();
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
|
2019-01-22 17:39:12 -05:00
|
|
|
settings.m_reverseAPIChannelIndex = response.getRemoteSinkSettings()->getReverseApiChannelIndex();
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const RemoteSinkSettings& settings)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
response.getRemoteSinkSettings()->setNbFecBlocks(settings.m_nbFECBlocks);
|
|
|
|
response.getRemoteSinkSettings()->setTxDelay(settings.m_txDelay);
|
2018-09-04 19:32:29 -04:00
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
if (response.getRemoteSinkSettings()->getDataAddress()) {
|
|
|
|
*response.getRemoteSinkSettings()->getDataAddress() = settings.m_dataAddress;
|
2018-09-04 19:32:29 -04:00
|
|
|
} else {
|
2019-01-22 17:39:12 -05:00
|
|
|
response.getRemoteSinkSettings()->setDataAddress(new QString(settings.m_dataAddress));
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
response.getRemoteSinkSettings()->setDataPort(settings.m_dataPort);
|
|
|
|
response.getRemoteSinkSettings()->setRgbColor(settings.m_rgbColor);
|
2018-09-08 13:24:38 -04:00
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
if (response.getRemoteSinkSettings()->getTitle()) {
|
|
|
|
*response.getRemoteSinkSettings()->getTitle() = settings.m_title;
|
2018-09-08 13:24:38 -04:00
|
|
|
} else {
|
2019-01-22 17:39:12 -05:00
|
|
|
response.getRemoteSinkSettings()->setTitle(new QString(settings.m_title));
|
2018-09-08 13:24:38 -04:00
|
|
|
}
|
|
|
|
|
2019-04-26 08:34:01 -04:00
|
|
|
response.getRemoteSinkSettings()->setLog2Decim(settings.m_log2Decim);
|
|
|
|
response.getRemoteSinkSettings()->setFilterChainHash(settings.m_filterChainHash);
|
2019-09-22 19:25:17 -04:00
|
|
|
response.getRemoteSinkSettings()->setStreamIndex(settings.m_streamIndex);
|
2019-01-22 17:39:12 -05:00
|
|
|
response.getRemoteSinkSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
2018-12-21 11:39:04 -05:00
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
if (response.getRemoteSinkSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getRemoteSinkSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
2018-12-21 11:39:04 -05:00
|
|
|
} else {
|
2019-01-22 17:39:12 -05:00
|
|
|
response.getRemoteSinkSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
response.getRemoteSinkSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getRemoteSinkSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
|
|
|
response.getRemoteSinkSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex);
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const RemoteSinkSettings& settings, bool force)
|
2018-12-21 11:39:04 -05:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgChannelSettings->setDirection(0); // single sink (Rx)
|
2019-03-25 08:53:48 -04:00
|
|
|
swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet());
|
|
|
|
swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex());
|
2019-01-22 17:39:12 -05:00
|
|
|
swgChannelSettings->setChannelType(new QString("RemoteSink"));
|
|
|
|
swgChannelSettings->setRemoteSinkSettings(new SWGSDRangel::SWGRemoteSinkSettings());
|
|
|
|
SWGSDRangel::SWGRemoteSinkSettings *swgRemoteSinkSettings = swgChannelSettings->getRemoteSinkSettings();
|
2018-12-21 11:39:04 -05:00
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("nbFECBlocks") || force) {
|
2019-01-22 17:39:12 -05:00
|
|
|
swgRemoteSinkSettings->setNbFecBlocks(settings.m_nbFECBlocks);
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("txDelay") || force)
|
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
swgRemoteSinkSettings->setTxDelay(settings.m_txDelay);
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("dataAddress") || force) {
|
2019-01-22 17:39:12 -05:00
|
|
|
swgRemoteSinkSettings->setDataAddress(new QString(settings.m_dataAddress));
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("dataPort") || force) {
|
2019-01-22 17:39:12 -05:00
|
|
|
swgRemoteSinkSettings->setDataPort(settings.m_dataPort);
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor") || force) {
|
2019-01-22 17:39:12 -05:00
|
|
|
swgRemoteSinkSettings->setRgbColor(settings.m_rgbColor);
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title") || force) {
|
2019-01-22 17:39:12 -05:00
|
|
|
swgRemoteSinkSettings->setTitle(new QString(settings.m_title));
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
2019-04-26 08:34:01 -04:00
|
|
|
if (channelSettingsKeys.contains("log2Decim") || force) {
|
|
|
|
swgRemoteSinkSettings->setLog2Decim(settings.m_log2Decim);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("filterChainHash") || force) {
|
|
|
|
swgRemoteSinkSettings->setFilterChainHash(settings.m_filterChainHash);
|
|
|
|
}
|
2019-09-22 19:25:17 -04:00
|
|
|
if (channelSettingsKeys.contains("streamIndex") || force) {
|
|
|
|
swgRemoteSinkSettings->setStreamIndex(settings.m_streamIndex);
|
|
|
|
}
|
2018-12-21 11:39:04 -05:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
QBuffer *buffer = new QBuffer();
|
2018-12-21 11:39:04 -05:00
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgChannelSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
2019-11-12 12:46:21 -05:00
|
|
|
QNetworkReply *reply = m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
buffer->setParent(reply);
|
2018-12-21 11:39:04 -05:00
|
|
|
|
|
|
|
delete swgChannelSettings;
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::networkManagerFinished(QNetworkReply *reply)
|
2018-12-21 11:39:04 -05:00
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
qWarning() << "RemoteSink::networkManagerFinished:"
|
2018-12-21 11:39:04 -05:00
|
|
|
<< " 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("RemoteSink::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2018-12-21 11:39:04 -05:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
reply->deleteLater();
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|