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-09-04 19:32:29 -04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <boost/crc.hpp>
|
|
|
|
#include <boost/cstdint.hpp>
|
|
|
|
|
2018-12-21 11:39:04 -05:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
|
|
|
|
2018-09-04 19:32:29 -04:00
|
|
|
#include "SWGChannelSettings.h"
|
|
|
|
|
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
#include "dsp/threadedbasebandsamplesink.h"
|
|
|
|
#include "dsp/downchannelizer.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "device/devicesourceapi.h"
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
#include "../remotesink/remotesinkthread.h"
|
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteSink::MsgConfigureRemoteSink, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteSink::MsgSampleRateNotification, 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-01-22 17:39:12 -05:00
|
|
|
RemoteSink::RemoteSink(DeviceSourceAPI *deviceAPI) :
|
2018-09-04 19:32:29 -04:00
|
|
|
ChannelSinkAPI(m_channelIdURI),
|
|
|
|
m_deviceAPI(deviceAPI),
|
|
|
|
m_running(false),
|
|
|
|
m_sinkThread(0),
|
|
|
|
m_txBlockIndex(0),
|
|
|
|
m_frameCount(0),
|
|
|
|
m_sampleIndex(0),
|
|
|
|
m_dataBlock(0),
|
|
|
|
m_centerFrequency(0),
|
|
|
|
m_sampleRate(48000),
|
|
|
|
m_nbBlocksFEC(0),
|
2018-09-05 22:36:56 -04:00
|
|
|
m_txDelay(35),
|
2018-09-04 19:32:29 -04:00
|
|
|
m_dataAddress("127.0.0.1"),
|
|
|
|
m_dataPort(9090)
|
|
|
|
{
|
|
|
|
setObjectName(m_channelId);
|
|
|
|
|
|
|
|
m_channelizer = new DownChannelizer(this);
|
|
|
|
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
|
|
|
|
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
|
|
|
m_deviceAPI->addChannelAPI(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;
|
2018-09-04 19:32:29 -04:00
|
|
|
m_dataBlockMutex.lock();
|
2018-12-21 11:39:04 -05:00
|
|
|
|
2018-09-04 19:32:29 -04:00
|
|
|
if (m_dataBlock && !m_dataBlock->m_txControlBlock.m_complete) {
|
|
|
|
delete m_dataBlock;
|
|
|
|
}
|
2018-12-21 11:39:04 -05:00
|
|
|
|
2018-09-04 19:32:29 -04:00
|
|
|
m_dataBlockMutex.unlock();
|
|
|
|
m_deviceAPI->removeChannelAPI(this);
|
|
|
|
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
|
|
|
delete m_threadedChannelizer;
|
|
|
|
delete m_channelizer;
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::setTxDelay(int txDelay, int nbBlocksFEC)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2018-09-05 12:25:58 -04:00
|
|
|
double txDelayRatio = txDelay / 100.0;
|
2019-02-02 16:58:42 -05:00
|
|
|
int samplesPerBlock = RemoteNbBytesPerBlock / sizeof(Sample);
|
2018-09-10 12:52:40 -04:00
|
|
|
double delay = m_sampleRate == 0 ? 1.0 : (127*samplesPerBlock*txDelayRatio) / m_sampleRate;
|
2018-09-05 22:23:27 -04:00
|
|
|
delay /= 128 + nbBlocksFEC;
|
2018-09-05 12:25:58 -04:00
|
|
|
m_txDelay = roundf(delay*1e6); // microseconds
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug() << "RemoteSink::setTxDelay:"
|
2018-09-05 22:23:27 -04:00
|
|
|
<< " " << txDelay
|
|
|
|
<< "% m_txDelay: " << m_txDelay << "us"
|
|
|
|
<< " m_sampleRate: " << m_sampleRate << "S/s";
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::setNbBlocksFEC(int nbBlocksFEC)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug() << "RemoteSink::setNbBlocksFEC: nbBlocksFEC: " << nbBlocksFEC;
|
2018-09-04 19:32:29 -04:00
|
|
|
m_nbBlocksFEC = nbBlocksFEC;
|
|
|
|
}
|
|
|
|
|
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;
|
2018-09-04 19:32:29 -04:00
|
|
|
SampleVector::const_iterator it = begin;
|
|
|
|
|
|
|
|
while (it != end)
|
|
|
|
{
|
|
|
|
int inSamplesIndex = it - begin;
|
|
|
|
int inRemainingSamples = end - it;
|
|
|
|
|
|
|
|
if (m_txBlockIndex == 0)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
2019-02-02 16:58:42 -05:00
|
|
|
RemoteMetaDataFEC metaData;
|
2018-09-04 19:32:29 -04:00
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
|
|
|
|
metaData.m_centerFrequency = m_centerFrequency;
|
|
|
|
metaData.m_sampleRate = m_sampleRate;
|
2018-09-12 18:31:49 -04:00
|
|
|
metaData.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
|
2018-09-09 11:39:36 -04:00
|
|
|
metaData.m_sampleBits = SDR_RX_SAMP_SZ;
|
2019-02-02 16:58:42 -05:00
|
|
|
metaData.m_nbOriginalBlocks = RemoteNbOrginalBlocks;
|
2018-09-04 19:32:29 -04:00
|
|
|
metaData.m_nbFECBlocks = m_nbBlocksFEC;
|
|
|
|
metaData.m_tv_sec = tv.tv_sec;
|
|
|
|
metaData.m_tv_usec = tv.tv_usec;
|
|
|
|
|
|
|
|
if (!m_dataBlock) { // on the very first cycle there is no data block allocated
|
2019-02-02 16:58:42 -05:00
|
|
|
m_dataBlock = new RemoteDataBlock();
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::crc_32_type crc32;
|
|
|
|
crc32.process_bytes(&metaData, 20);
|
|
|
|
metaData.m_crc32 = crc32.checksum();
|
2019-02-02 16:58:42 -05:00
|
|
|
RemoteSuperBlock& superBlock = m_dataBlock->m_superBlocks[0]; // first block
|
2018-09-04 19:32:29 -04:00
|
|
|
superBlock.init();
|
|
|
|
superBlock.m_header.m_frameIndex = m_frameCount;
|
|
|
|
superBlock.m_header.m_blockIndex = m_txBlockIndex;
|
2018-09-12 18:31:49 -04:00
|
|
|
superBlock.m_header.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
|
|
|
|
superBlock.m_header.m_sampleBits = SDR_RX_SAMP_SZ;
|
2018-11-18 05:06:41 -05:00
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
RemoteMetaDataFEC *destMeta = (RemoteMetaDataFEC *) &superBlock.m_protectedBlock;
|
2018-11-18 05:06:41 -05:00
|
|
|
*destMeta = metaData;
|
2018-09-04 19:32:29 -04:00
|
|
|
|
|
|
|
if (!(metaData == m_currentMetaFEC))
|
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug() << "RemoteSink::feed: meta: "
|
2018-09-04 19:32:29 -04:00
|
|
|
<< "|" << metaData.m_centerFrequency
|
|
|
|
<< ":" << metaData.m_sampleRate
|
|
|
|
<< ":" << (int) (metaData.m_sampleBytes & 0xF)
|
|
|
|
<< ":" << (int) metaData.m_sampleBits
|
|
|
|
<< "|" << (int) metaData.m_nbOriginalBlocks
|
|
|
|
<< ":" << (int) metaData.m_nbFECBlocks
|
|
|
|
<< "|" << metaData.m_tv_sec
|
|
|
|
<< ":" << metaData.m_tv_usec;
|
|
|
|
|
|
|
|
m_currentMetaFEC = metaData;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_txBlockIndex = 1; // next Tx block with data
|
|
|
|
} // block zero
|
|
|
|
|
2018-09-10 12:52:40 -04:00
|
|
|
// handle different sample sizes...
|
2019-02-02 16:58:42 -05:00
|
|
|
int samplesPerBlock = RemoteNbBytesPerBlock / (SDR_RX_SAMP_SZ <= 16 ? 4 : 8); // two I or Q samples
|
2018-09-10 12:52:40 -04:00
|
|
|
if (m_sampleIndex + inRemainingSamples < samplesPerBlock) // there is still room in the current super block
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2018-09-10 12:52:40 -04:00
|
|
|
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
|
2018-09-04 19:32:29 -04:00
|
|
|
(const void *) &(*(begin+inSamplesIndex)),
|
|
|
|
inRemainingSamples * sizeof(Sample));
|
|
|
|
m_sampleIndex += inRemainingSamples;
|
|
|
|
it = end; // all input samples are consumed
|
|
|
|
}
|
|
|
|
else // complete super block and initiate the next if not end of frame
|
|
|
|
{
|
2018-09-10 12:52:40 -04:00
|
|
|
memcpy((void *) &m_superBlock.m_protectedBlock.buf[m_sampleIndex*sizeof(Sample)],
|
2018-09-04 19:32:29 -04:00
|
|
|
(const void *) &(*(begin+inSamplesIndex)),
|
2018-09-10 12:52:40 -04:00
|
|
|
(samplesPerBlock - m_sampleIndex) * sizeof(Sample));
|
|
|
|
it += samplesPerBlock - m_sampleIndex;
|
2018-09-04 19:32:29 -04:00
|
|
|
m_sampleIndex = 0;
|
|
|
|
|
|
|
|
m_superBlock.m_header.m_frameIndex = m_frameCount;
|
|
|
|
m_superBlock.m_header.m_blockIndex = m_txBlockIndex;
|
2018-09-12 18:31:49 -04:00
|
|
|
m_superBlock.m_header.m_sampleBytes = (SDR_RX_SAMP_SZ <= 16 ? 2 : 4);
|
|
|
|
m_superBlock.m_header.m_sampleBits = SDR_RX_SAMP_SZ;
|
2018-09-04 19:32:29 -04:00
|
|
|
m_dataBlock->m_superBlocks[m_txBlockIndex] = m_superBlock;
|
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
if (m_txBlockIndex == RemoteNbOrginalBlocks - 1) // frame complete
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
|
|
|
m_dataBlockMutex.lock();
|
|
|
|
m_dataBlock->m_txControlBlock.m_frameIndex = m_frameCount;
|
|
|
|
m_dataBlock->m_txControlBlock.m_processed = false;
|
|
|
|
m_dataBlock->m_txControlBlock.m_complete = true;
|
|
|
|
m_dataBlock->m_txControlBlock.m_nbBlocksFEC = m_nbBlocksFEC;
|
|
|
|
m_dataBlock->m_txControlBlock.m_txDelay = m_txDelay;
|
|
|
|
m_dataBlock->m_txControlBlock.m_dataAddress = m_dataAddress;
|
|
|
|
m_dataBlock->m_txControlBlock.m_dataPort = m_dataPort;
|
|
|
|
|
2018-09-05 23:21:43 -04:00
|
|
|
emit dataBlockAvailable(m_dataBlock);
|
2019-02-02 16:58:42 -05:00
|
|
|
m_dataBlock = new RemoteDataBlock(); // create a new one immediately
|
2018-09-04 19:32:29 -04:00
|
|
|
m_dataBlockMutex.unlock();
|
|
|
|
|
|
|
|
m_txBlockIndex = 0;
|
|
|
|
m_frameCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_txBlockIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
void RemoteSink::start()
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug("RemoteSink::start");
|
2018-09-04 19:32:29 -04:00
|
|
|
|
2019-02-02 16:58:42 -05:00
|
|
|
memset((void *) &m_currentMetaFEC, 0, sizeof(RemoteMetaDataFEC));
|
2018-09-04 19:32:29 -04:00
|
|
|
|
|
|
|
if (m_running) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
m_sinkThread = new RemoteSinkThread();
|
2018-09-05 23:21:43 -04:00
|
|
|
connect(this,
|
2019-02-02 16:58:42 -05:00
|
|
|
SIGNAL(dataBlockAvailable(RemoteDataBlock *)),
|
2018-09-05 23:21:43 -04:00
|
|
|
m_sinkThread,
|
2019-02-02 16:58:42 -05:00
|
|
|
SLOT(processDataBlock(RemoteDataBlock *)),
|
2018-09-05 23:21:43 -04:00
|
|
|
Qt::QueuedConnection);
|
2018-09-04 19:32:29 -04:00
|
|
|
m_sinkThread->startStop(true);
|
|
|
|
m_running = true;
|
|
|
|
}
|
|
|
|
|
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");
|
2018-09-04 19:32:29 -04:00
|
|
|
|
|
|
|
if (m_sinkThread != 0)
|
|
|
|
{
|
|
|
|
m_sinkThread->startStop(false);
|
|
|
|
m_sinkThread->deleteLater();
|
|
|
|
m_sinkThread = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
bool RemoteSink::handleMessage(const Message& cmd)
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) cmd;
|
2018-09-04 19:32:29 -04:00
|
|
|
if (DownChannelizer::MsgChannelizerNotification::match(cmd))
|
|
|
|
{
|
|
|
|
DownChannelizer::MsgChannelizerNotification& notif = (DownChannelizer::MsgChannelizerNotification&) cmd;
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug() << "RemoteSink::handleMessage: MsgChannelizerNotification:"
|
2018-09-04 19:32:29 -04:00
|
|
|
<< " channelSampleRate: " << notif.getSampleRate()
|
|
|
|
<< " offsetFrequency: " << notif.getFrequencyOffset();
|
|
|
|
|
|
|
|
if (notif.getSampleRate() > 0) {
|
|
|
|
setSampleRate(notif.getSampleRate());
|
|
|
|
}
|
|
|
|
|
2018-09-05 22:23:27 -04:00
|
|
|
setTxDelay(m_settings.m_txDelay, m_settings.m_nbFECBlocks);
|
|
|
|
|
2018-09-05 02:44:14 -04:00
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
|
|
|
MsgSampleRateNotification *msg = MsgSampleRateNotification::create(notif.getSampleRate());
|
|
|
|
m_guiMessageQueue->push(msg);
|
|
|
|
}
|
|
|
|
|
2018-09-04 19:32:29 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug() << "RemoteSink::handleMessage: DSPSignalNotification:"
|
2018-09-04 19:32:29 -04:00
|
|
|
<< " inputSampleRate: " << notif.getSampleRate()
|
|
|
|
<< " centerFrequency: " << notif.getCenterFrequency();
|
|
|
|
|
|
|
|
setCenterFrequency(notif.getCenterFrequency());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-22 17:39:12 -05:00
|
|
|
else if (MsgConfigureRemoteSink::match(cmd))
|
2018-09-04 19:32:29 -04:00
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
MsgConfigureRemoteSink& cfg = (MsgConfigureRemoteSink&) cmd;
|
|
|
|
qDebug() << "RemoteSink::handleMessage: MsgConfigureRemoteSink";
|
2018-09-04 19:32:29 -04:00
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
<< " force: " << force;
|
|
|
|
|
2018-12-21 11:39:04 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
|
|
|
if ((m_settings.m_nbFECBlocks != settings.m_nbFECBlocks) || force)
|
|
|
|
{
|
|
|
|
reverseAPIKeys.append("nbFECBlocks");
|
2018-09-05 12:25:58 -04:00
|
|
|
setNbBlocksFEC(settings.m_nbFECBlocks);
|
2018-09-05 22:23:27 -04:00
|
|
|
setTxDelay(settings.m_txDelay, settings.m_nbFECBlocks);
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:39:04 -05:00
|
|
|
if ((m_settings.m_txDelay != settings.m_txDelay) || force)
|
|
|
|
{
|
|
|
|
reverseAPIKeys.append("txDelay");
|
2018-09-05 22:23:27 -04:00
|
|
|
setTxDelay(settings.m_txDelay, settings.m_nbFECBlocks);
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:39:04 -05:00
|
|
|
if ((m_settings.m_dataAddress != settings.m_dataAddress) || force)
|
|
|
|
{
|
|
|
|
reverseAPIKeys.append("dataAddress");
|
2018-09-04 19:32:29 -04:00
|
|
|
m_dataAddress = settings.m_dataAddress;
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:39:04 -05:00
|
|
|
if ((m_settings.m_dataPort != settings.m_dataPort) || force)
|
|
|
|
{
|
|
|
|
reverseAPIKeys.append("dataPort");
|
2018-09-04 19:32:29 -04:00
|
|
|
m_dataPort = settings.m_dataPort;
|
|
|
|
}
|
|
|
|
|
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-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;
|
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
|
|
|
}
|
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-08 13:24:38 -04:00
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
MsgConfigureRemoteSink *msg = MsgConfigureRemoteSink::create(settings, force);
|
2018-09-04 19:32:29 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug("RemoteSink::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
2018-09-04 19:32:29 -04:00
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2019-01-22 17:39:12 -05:00
|
|
|
MsgConfigureRemoteSink *msgToGUI = MsgConfigureRemoteSink::create(settings, force);
|
2018-09-04 19:32:29 -04:00
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatChannelSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
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-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();
|
|
|
|
swgChannelSettings->setTx(0);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
|
|
|
|
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();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
2019-01-22 17:39:12 -05:00
|
|
|
qDebug("RemoteSink::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2018-09-04 19:32:29 -04:00
|
|
|
}
|