2018-08-31 17:29:53 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2019-01-22 18:44:13 -05:00
|
|
|
// Copyright (C) 2018-2019 Edouard Griffiths, F4EXB //
|
2018-08-31 17:29:53 -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-08-31 17:29:53 -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 18:44:13 -05:00
|
|
|
#include "remotesource.h"
|
|
|
|
|
2018-08-31 18:18:35 -04:00
|
|
|
#include <QDebug>
|
2018-12-20 17:20:21 -05:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2019-11-14 19:04:24 -05:00
|
|
|
#include <QThread>
|
2018-08-31 18:18:35 -04:00
|
|
|
|
2018-08-31 22:37:23 -04:00
|
|
|
#include "SWGChannelSettings.h"
|
2022-05-13 16:24:48 -04:00
|
|
|
#include "SWGWorkspaceInfo.h"
|
2018-08-31 22:37:23 -04:00
|
|
|
#include "SWGChannelReport.h"
|
2019-01-22 18:44:13 -05:00
|
|
|
#include "SWGRemoteSourceReport.h"
|
2018-08-31 22:37:23 -04:00
|
|
|
|
2018-08-31 22:43:15 -04:00
|
|
|
#include "dsp/devicesamplesink.h"
|
2021-12-14 01:56:02 -05:00
|
|
|
#include "dsp/hbfilterchainconverter.h"
|
|
|
|
#include "dsp/dspcommands.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-03 16:32:54 -05:00
|
|
|
#include "settings/serializable.h"
|
2019-11-14 19:04:24 -05:00
|
|
|
#include "util/timeutil.h"
|
2020-10-22 18:11:18 -04:00
|
|
|
#include "util/db.h"
|
|
|
|
#include "maincore.h"
|
2018-08-31 17:29:53 -04:00
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
#include "remotesourcebaseband.h"
|
2018-08-31 17:29:53 -04:00
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteSource::MsgConfigureRemoteSource, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteSource::MsgQueryStreamData, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteSource::MsgReportStreamData, Message)
|
2018-08-31 18:18:35 -04:00
|
|
|
|
2020-11-21 14:24:18 -05:00
|
|
|
const char* const RemoteSource::m_channelIdURI = "sdrangel.channeltx.remotesource";
|
|
|
|
const char* const RemoteSource::m_channelId ="RemoteSource";
|
2018-08-31 17:29:53 -04:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
RemoteSource::RemoteSource(DeviceAPI *deviceAPI) :
|
2019-05-09 11:27:12 -04:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource),
|
2021-12-14 01:56:02 -05:00
|
|
|
m_deviceAPI(deviceAPI),
|
|
|
|
m_centerFrequency(0),
|
|
|
|
m_frequencyOffset(0),
|
|
|
|
m_basebandSampleRate(48000)
|
2018-08-31 17:29:53 -04:00
|
|
|
{
|
|
|
|
setObjectName(m_channelId);
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_basebandSource = new RemoteSourceBaseband();
|
|
|
|
m_basebandSource->moveToThread(m_thread);
|
|
|
|
|
|
|
|
applySettings(m_settings, true);
|
2018-09-11 02:41:37 -04:00
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
m_deviceAPI->addChannelSource(this);
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->addChannelSourceAPI(this);
|
2018-12-20 17:20:21 -05:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::connect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&RemoteSource::networkManagerFinished
|
|
|
|
);
|
2018-08-31 17:29:53 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
RemoteSource::~RemoteSource()
|
2018-08-31 17:29:53 -04:00
|
|
|
{
|
2022-03-23 17:32:23 -04:00
|
|
|
QObject::disconnect(
|
|
|
|
m_networkManager,
|
|
|
|
&QNetworkAccessManager::finished,
|
|
|
|
this,
|
|
|
|
&RemoteSource::networkManagerFinished
|
|
|
|
);
|
2018-12-20 17:20:21 -05:00
|
|
|
delete m_networkManager;
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->removeChannelSourceAPI(this);
|
2019-11-14 19:04:24 -05:00
|
|
|
m_deviceAPI->removeChannelSource(this);
|
|
|
|
delete m_basebandSource;
|
|
|
|
delete m_thread;
|
2018-08-31 17:29:53 -04:00
|
|
|
}
|
|
|
|
|
2022-04-16 10:45:53 -04:00
|
|
|
void RemoteSource::setDeviceAPI(DeviceAPI *deviceAPI)
|
|
|
|
{
|
|
|
|
if (deviceAPI != m_deviceAPI)
|
|
|
|
{
|
|
|
|
m_deviceAPI->removeChannelSourceAPI(this);
|
|
|
|
m_deviceAPI->removeChannelSource(this);
|
|
|
|
m_deviceAPI = deviceAPI;
|
|
|
|
m_deviceAPI->addChannelSource(this);
|
|
|
|
m_deviceAPI->addChannelSinkAPI(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
void RemoteSource::start()
|
2018-08-31 17:29:53 -04:00
|
|
|
{
|
2019-01-22 18:44:13 -05:00
|
|
|
qDebug("RemoteSource::start");
|
2019-11-14 19:04:24 -05:00
|
|
|
m_basebandSource->reset();
|
|
|
|
m_thread->start();
|
|
|
|
RemoteSourceBaseband::MsgConfigureRemoteSourceWork *msg = RemoteSourceBaseband::MsgConfigureRemoteSourceWork::create(true);
|
|
|
|
m_basebandSource->getInputMessageQueue()->push(msg);
|
2018-08-31 17:29:53 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
void RemoteSource::stop()
|
2018-08-31 17:29:53 -04:00
|
|
|
{
|
2019-01-22 18:44:13 -05:00
|
|
|
qDebug("RemoteSource::stop");
|
2019-11-14 19:04:24 -05:00
|
|
|
m_thread->exit();
|
|
|
|
m_thread->wait();
|
2018-08-31 22:37:23 -04:00
|
|
|
}
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
void RemoteSource::pull(SampleVector::iterator& begin, unsigned int nbSamples)
|
2018-08-31 22:37:23 -04:00
|
|
|
{
|
2019-11-14 19:04:24 -05:00
|
|
|
m_basebandSource->pull(begin, nbSamples);
|
2018-08-31 17:29:53 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
bool RemoteSource::handleMessage(const Message& cmd)
|
2018-08-31 17:29:53 -04:00
|
|
|
{
|
2021-12-14 01:56:02 -05:00
|
|
|
if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
|
|
|
|
|
|
|
qDebug() << "RemoteSource::handleMessage: DSPSignalNotification:"
|
|
|
|
<< " inputSampleRate: " << notif.getSampleRate()
|
|
|
|
<< " centerFrequency: " << notif.getCenterFrequency();
|
|
|
|
|
|
|
|
m_basebandSampleRate = notif.getSampleRate();
|
|
|
|
calculateFrequencyOffset(m_settings.m_log2Interp, m_settings.m_filterChainHash); // This is when device sample rate changes
|
|
|
|
m_centerFrequency = notif.getCenterFrequency();
|
|
|
|
|
2022-04-13 05:08:21 -04:00
|
|
|
if (m_guiMessageQueue) {
|
|
|
|
m_guiMessageQueue->push(new DSPSignalNotification(notif));
|
2021-12-14 01:56:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureRemoteSource::match(cmd))
|
2018-08-31 22:37:23 -04:00
|
|
|
{
|
2019-01-22 18:44:13 -05:00
|
|
|
MsgConfigureRemoteSource& cfg = (MsgConfigureRemoteSource&) cmd;
|
|
|
|
qDebug() << "MsgConfigureRemoteSource::handleMessage: MsgConfigureRemoteSource";
|
2018-08-31 22:37:23 -04:00
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-02 13:12:03 -04:00
|
|
|
else if (MsgQueryStreamData::match(cmd))
|
|
|
|
{
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
2019-11-14 19:04:24 -05:00
|
|
|
uint64_t nowus = TimeUtil::nowus();
|
|
|
|
RemoteDataReadQueue& dataReadQueue = m_basebandSource->getDataQueue();
|
|
|
|
const RemoteMetaDataFEC& currentMeta = m_basebandSource->getRemoteMetaDataFEC();
|
2018-09-02 13:12:03 -04:00
|
|
|
|
|
|
|
MsgReportStreamData *msg = MsgReportStreamData::create(
|
2019-11-14 19:04:24 -05:00
|
|
|
nowus / 1000000U,
|
|
|
|
nowus % 1000000U,
|
|
|
|
dataReadQueue.size(),
|
|
|
|
dataReadQueue.length(),
|
|
|
|
dataReadQueue.readSampleCount(),
|
|
|
|
m_basebandSource->getNbCorrectableErrors(),
|
|
|
|
m_basebandSource->getNbUncorrectableErrors(),
|
|
|
|
currentMeta.m_nbOriginalBlocks,
|
|
|
|
currentMeta.m_nbFECBlocks,
|
|
|
|
currentMeta.m_centerFrequency,
|
|
|
|
currentMeta.m_sampleRate);
|
2018-09-02 13:12:03 -04:00
|
|
|
m_guiMessageQueue->push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-31 17:29:53 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
QByteArray RemoteSource::serialize() const
|
2018-08-31 17:29:53 -04:00
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
bool RemoteSource::deserialize(const QByteArray& data)
|
2018-08-31 17:29:53 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) data;
|
2018-08-31 17:29:53 -04:00
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
2019-01-22 18:44:13 -05:00
|
|
|
MsgConfigureRemoteSource *msg = MsgConfigureRemoteSource::create(m_settings, true);
|
2018-08-31 22:37:23 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
2018-08-31 17:29:53 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
2019-01-22 18:44:13 -05:00
|
|
|
MsgConfigureRemoteSource *msg = MsgConfigureRemoteSource::create(m_settings, true);
|
2018-08-31 22:37:23 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
2018-08-31 17:29:53 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 22:37:23 -04:00
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
void RemoteSource::applySettings(const RemoteSourceSettings& settings, bool force)
|
2018-08-31 22:37:23 -04:00
|
|
|
{
|
2019-01-22 18:44:13 -05:00
|
|
|
qDebug() << "RemoteSource::applySettings:"
|
2021-12-14 01:56:02 -05:00
|
|
|
<< "m_log2Interp:" << settings.m_log2Interp
|
|
|
|
<< "m_filterChainHash:" << settings.m_filterChainHash
|
|
|
|
<< "m_dataAddress:" << settings.m_dataAddress
|
|
|
|
<< "m_dataPort:" << settings.m_dataPort
|
|
|
|
<< "m_rgbColor:" << settings.m_rgbColor
|
|
|
|
<< "m_title:" << settings.m_title
|
|
|
|
<< "m_useReverseAPI:" << settings.m_useReverseAPI
|
|
|
|
<< "m_reverseAPIAddress:" << settings.m_reverseAPIAddress
|
|
|
|
<< "m_reverseAPIChannelIndex:" << settings.m_reverseAPIChannelIndex
|
|
|
|
<< "m_reverseAPIDeviceIndex:" << settings.m_reverseAPIDeviceIndex
|
|
|
|
<< "m_reverseAPIPort:" << settings.m_reverseAPIPort
|
|
|
|
<< "force:" << force;
|
2018-08-31 22:37:23 -04:00
|
|
|
|
2018-12-20 17:20:21 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
2018-08-31 22:37:23 -04:00
|
|
|
|
2021-12-14 01:56:02 -05:00
|
|
|
if ((m_settings.m_log2Interp != settings.m_log2Interp) || force) {
|
|
|
|
reverseAPIKeys.append("log2Interp");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_filterChainHash != settings.m_filterChainHash) || force) {
|
|
|
|
reverseAPIKeys.append("filterChainHash");
|
|
|
|
}
|
2019-11-14 19:04:24 -05:00
|
|
|
if ((m_settings.m_dataAddress != settings.m_dataAddress) || force) {
|
2018-12-20 17:20:21 -05:00
|
|
|
reverseAPIKeys.append("dataAddress");
|
2018-08-31 22:37:23 -04:00
|
|
|
}
|
2019-11-14 19:04:24 -05:00
|
|
|
if ((m_settings.m_dataPort != settings.m_dataPort) || force) {
|
2018-12-20 17:20:21 -05:00
|
|
|
reverseAPIKeys.append("dataPort");
|
2018-08-31 22:37:23 -04:00
|
|
|
}
|
|
|
|
|
2021-12-14 01:56:02 -05:00
|
|
|
if ((m_settings.m_log2Interp != settings.m_log2Interp)
|
|
|
|
|| (m_settings.m_filterChainHash != settings.m_filterChainHash) || force) {
|
|
|
|
calculateFrequencyOffset(settings.m_log2Interp, settings.m_filterChainHash);
|
|
|
|
}
|
|
|
|
|
2019-11-18 19:22:55 -05: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->removeChannelSourceAPI(this);
|
2019-11-18 19:22:55 -05:00
|
|
|
m_deviceAPI->removeChannelSource(this, m_settings.m_streamIndex);
|
|
|
|
m_deviceAPI->addChannelSource(this, settings.m_streamIndex);
|
2019-12-23 17:41:35 -05:00
|
|
|
m_deviceAPI->addChannelSourceAPI(this);
|
2019-11-18 19:22:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
reverseAPIKeys.append("streamIndex");
|
|
|
|
}
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
RemoteSourceBaseband::MsgConfigureRemoteSourceBaseband *msg = RemoteSourceBaseband::MsgConfigureRemoteSourceBaseband::create(settings, force);
|
|
|
|
m_basebandSource->getInputMessageQueue()->push(msg);
|
2018-08-31 22:37:23 -04:00
|
|
|
|
2018-12-20 17:20:21 -05:00
|
|
|
if (settings.m_useReverseAPI)
|
|
|
|
{
|
|
|
|
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
|
|
|
|
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
|
|
|
|
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
|
|
|
|
(m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) ||
|
|
|
|
(m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-08-31 22:37:23 -04:00
|
|
|
m_settings = settings;
|
|
|
|
}
|
|
|
|
|
2021-12-14 01:56:02 -05:00
|
|
|
void RemoteSource::validateFilterChainHash(RemoteSourceSettings& settings)
|
|
|
|
{
|
|
|
|
unsigned int s = 1;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < settings.m_log2Interp; i++) {
|
|
|
|
s *= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.m_filterChainHash = settings.m_filterChainHash >= s ? s-1 : settings.m_filterChainHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSource::calculateFrequencyOffset(uint32_t log2Interp, uint32_t filterChainHash)
|
|
|
|
{
|
|
|
|
double shiftFactor = HBFilterChainConverter::getShiftFactor(log2Interp, filterChainHash);
|
|
|
|
m_frequencyOffset = m_basebandSampleRate * shiftFactor;
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
int RemoteSource::webapiSettingsGet(
|
2018-08-31 22:37:23 -04:00
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-08-31 22:37:23 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2019-01-22 18:44:13 -05:00
|
|
|
response.setRemoteSourceSettings(new SWGSDRangel::SWGRemoteSourceSettings());
|
|
|
|
response.getRemoteSourceSettings()->init();
|
2018-08-31 22:37:23 -04:00
|
|
|
webapiFormatChannelSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2022-05-13 16:24:48 -04:00
|
|
|
int RemoteSource::webapiWorkspaceGet(
|
|
|
|
SWGSDRangel::SWGWorkspaceInfo& response,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
(void) errorMessage;
|
|
|
|
response.setIndex(m_settings.m_workspaceIndex);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
int RemoteSource::webapiSettingsPutPatch(
|
2018-08-31 22:37:23 -04:00
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-08-31 22:37:23 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2019-01-22 18:44:13 -05:00
|
|
|
RemoteSourceSettings settings = m_settings;
|
2019-08-01 17:21:57 -04:00
|
|
|
webapiUpdateChannelSettings(settings, channelSettingsKeys, response);
|
2018-08-31 22:37:23 -04:00
|
|
|
|
2019-08-01 17:21:57 -04:00
|
|
|
MsgConfigureRemoteSource *msg = MsgConfigureRemoteSource::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
qDebug("RemoteSource::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureRemoteSource *msgToGUI = MsgConfigureRemoteSource::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatChannelSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteSource::webapiUpdateChannelSettings(
|
|
|
|
RemoteSourceSettings& settings,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response)
|
|
|
|
{
|
2018-08-31 22:37:23 -04:00
|
|
|
if (channelSettingsKeys.contains("dataAddress")) {
|
2019-01-22 18:44:13 -05:00
|
|
|
settings.m_dataAddress = *response.getRemoteSourceSettings()->getDataAddress();
|
2018-08-31 22:37:23 -04:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("dataPort"))
|
|
|
|
{
|
2019-01-22 18:44:13 -05:00
|
|
|
int dataPort = response.getRemoteSourceSettings()->getDataPort();
|
2018-08-31 22:37:23 -04:00
|
|
|
|
|
|
|
if ((dataPort < 1024) || (dataPort > 65535)) {
|
|
|
|
settings.m_dataPort = 9090;
|
|
|
|
} else {
|
|
|
|
settings.m_dataPort = dataPort;
|
|
|
|
}
|
|
|
|
}
|
2018-09-01 03:53:16 -04:00
|
|
|
if (channelSettingsKeys.contains("rgbColor")) {
|
2019-01-22 18:44:13 -05:00
|
|
|
settings.m_rgbColor = response.getRemoteSourceSettings()->getRgbColor();
|
2018-09-01 03:53:16 -04:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title")) {
|
2019-01-22 18:44:13 -05:00
|
|
|
settings.m_title = *response.getRemoteSourceSettings()->getTitle();
|
2018-09-01 03:53:16 -04:00
|
|
|
}
|
2021-12-14 01:56:02 -05:00
|
|
|
if (channelSettingsKeys.contains("log2Interp")) {
|
|
|
|
settings.m_log2Interp = response.getRemoteSourceSettings()->getLog2Interp();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("filterChainHash")) {
|
|
|
|
settings.m_filterChainHash = response.getRemoteSourceSettings()->getFilterChainHash();
|
|
|
|
}
|
2019-11-17 05:09:07 -05:00
|
|
|
if (channelSettingsKeys.contains("streamIndex")) {
|
|
|
|
settings.m_streamIndex = response.getRemoteSourceSettings()->getStreamIndex();
|
|
|
|
}
|
2018-12-20 17:20:21 -05:00
|
|
|
if (channelSettingsKeys.contains("useReverseAPI")) {
|
2019-01-22 18:44:13 -05:00
|
|
|
settings.m_useReverseAPI = response.getRemoteSourceSettings()->getUseReverseApi() != 0;
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIAddress")) {
|
2019-04-20 13:53:16 -04:00
|
|
|
settings.m_reverseAPIAddress = *response.getRemoteSourceSettings()->getReverseApiAddress();
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIPort")) {
|
2019-01-22 18:44:13 -05:00
|
|
|
settings.m_reverseAPIPort = response.getRemoteSourceSettings()->getReverseApiPort();
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
2019-01-22 18:44:13 -05:00
|
|
|
settings.m_reverseAPIDeviceIndex = response.getRemoteSourceSettings()->getReverseApiDeviceIndex();
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
|
2019-01-22 18:44:13 -05:00
|
|
|
settings.m_reverseAPIChannelIndex = response.getRemoteSourceSettings()->getReverseApiChannelIndex();
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
2021-12-03 16:32:54 -05:00
|
|
|
if (settings.m_channelMarker && channelSettingsKeys.contains("channelMarker")) {
|
|
|
|
settings.m_channelMarker->updateFrom(channelSettingsKeys, response.getRemoteSourceSettings()->getChannelMarker());
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
if (settings.m_rollupState && channelSettingsKeys.contains("rollupState")) {
|
|
|
|
settings.m_rollupState->updateFrom(channelSettingsKeys, response.getRemoteSourceSettings()->getRollupState());
|
|
|
|
}
|
2018-08-31 22:37:23 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
int RemoteSource::webapiReportGet(
|
2018-08-31 22:37:23 -04:00
|
|
|
SWGSDRangel::SWGChannelReport& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-08-31 22:37:23 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2019-01-22 18:44:13 -05:00
|
|
|
response.setRemoteSourceReport(new SWGSDRangel::SWGRemoteSourceReport());
|
|
|
|
response.getRemoteSourceReport()->init();
|
2018-08-31 22:37:23 -04:00
|
|
|
webapiFormatChannelReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
void RemoteSource::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const RemoteSourceSettings& settings)
|
2018-08-31 22:37:23 -04:00
|
|
|
{
|
2019-01-22 18:44:13 -05:00
|
|
|
if (response.getRemoteSourceSettings()->getDataAddress()) {
|
|
|
|
*response.getRemoteSourceSettings()->getDataAddress() = settings.m_dataAddress;
|
2018-08-31 22:37:23 -04:00
|
|
|
} else {
|
2019-01-22 18:44:13 -05:00
|
|
|
response.getRemoteSourceSettings()->setDataAddress(new QString(settings.m_dataAddress));
|
2018-08-31 22:37:23 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
response.getRemoteSourceSettings()->setDataPort(settings.m_dataPort);
|
|
|
|
response.getRemoteSourceSettings()->setRgbColor(settings.m_rgbColor);
|
2018-09-01 03:53:16 -04:00
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
if (response.getRemoteSourceSettings()->getTitle()) {
|
|
|
|
*response.getRemoteSourceSettings()->getTitle() = settings.m_title;
|
2018-09-01 03:53:16 -04:00
|
|
|
} else {
|
2019-01-22 18:44:13 -05:00
|
|
|
response.getRemoteSourceSettings()->setTitle(new QString(settings.m_title));
|
2018-09-01 03:53:16 -04:00
|
|
|
}
|
2018-12-20 17:20:21 -05:00
|
|
|
|
2021-12-14 01:56:02 -05:00
|
|
|
response.getRemoteSourceSettings()->setLog2Interp(settings.m_log2Interp);
|
|
|
|
response.getRemoteSourceSettings()->setFilterChainHash(settings.m_filterChainHash);
|
2019-01-22 18:44:13 -05:00
|
|
|
response.getRemoteSourceSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
2018-12-20 17:20:21 -05:00
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
if (response.getRemoteSourceSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getRemoteSourceSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
2018-12-20 17:20:21 -05:00
|
|
|
} else {
|
2019-01-22 18:44:13 -05:00
|
|
|
response.getRemoteSourceSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
response.getRemoteSourceSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getRemoteSourceSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
|
|
|
response.getRemoteSourceSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex);
|
2021-12-03 16:32:54 -05:00
|
|
|
|
|
|
|
if (settings.m_channelMarker)
|
|
|
|
{
|
|
|
|
if (response.getRemoteSourceSettings()->getChannelMarker())
|
|
|
|
{
|
|
|
|
settings.m_channelMarker->formatTo(response.getRemoteSourceSettings()->getChannelMarker());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker();
|
|
|
|
settings.m_channelMarker->formatTo(swgChannelMarker);
|
|
|
|
response.getRemoteSourceSettings()->setChannelMarker(swgChannelMarker);
|
|
|
|
}
|
|
|
|
}
|
2022-01-08 23:27:12 -05:00
|
|
|
|
|
|
|
if (settings.m_rollupState)
|
|
|
|
{
|
|
|
|
if (response.getRemoteSourceSettings()->getRollupState())
|
|
|
|
{
|
|
|
|
settings.m_rollupState->formatTo(response.getRemoteSourceSettings()->getRollupState());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
|
|
|
|
settings.m_rollupState->formatTo(swgRollupState);
|
|
|
|
response.getRemoteSourceSettings()->setRollupState(swgRollupState);
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 22:37:23 -04:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
void RemoteSource::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response)
|
2018-08-31 22:37:23 -04:00
|
|
|
{
|
2019-11-14 19:04:24 -05:00
|
|
|
uint64_t nowus = TimeUtil::nowus();
|
|
|
|
RemoteDataReadQueue& dataReadQueue = m_basebandSource->getDataQueue();
|
|
|
|
const RemoteMetaDataFEC& currentMeta = m_basebandSource->getRemoteMetaDataFEC();
|
|
|
|
|
|
|
|
response.getRemoteSourceReport()->setTvSec(nowus / 1000000U);
|
|
|
|
response.getRemoteSourceReport()->setTvUSec(nowus % 1000000U);
|
|
|
|
response.getRemoteSourceReport()->setQueueSize(dataReadQueue.size());
|
|
|
|
response.getRemoteSourceReport()->setQueueLength(dataReadQueue.length());
|
|
|
|
response.getRemoteSourceReport()->setSamplesCount(dataReadQueue.readSampleCount());
|
|
|
|
response.getRemoteSourceReport()->setCorrectableErrorsCount(m_basebandSource->getNbCorrectableErrors());
|
|
|
|
response.getRemoteSourceReport()->setUncorrectableErrorsCount(m_basebandSource->getNbUncorrectableErrors());
|
|
|
|
response.getRemoteSourceReport()->setNbOriginalBlocks(currentMeta.m_nbOriginalBlocks);
|
|
|
|
response.getRemoteSourceReport()->setNbFecBlocks(currentMeta.m_nbFECBlocks);
|
2021-12-14 01:56:02 -05:00
|
|
|
response.getRemoteSourceReport()->setCenterFreq(m_frequencyOffset);
|
|
|
|
double channelSampleRate = ((double) m_basebandSampleRate) / (1<<m_settings.m_log2Interp);
|
|
|
|
response.getRemoteSourceReport()->setSampleRate(channelSampleRate);
|
2021-12-12 07:45:14 -05:00
|
|
|
response.getRemoteSourceReport()->setDeviceCenterFreq(m_deviceAPI->getSampleSink()->getCenterFrequency());
|
2019-01-22 18:44:13 -05:00
|
|
|
response.getRemoteSourceReport()->setDeviceSampleRate(m_deviceAPI->getSampleSink()->getSampleRate());
|
2018-08-31 22:37:23 -04:00
|
|
|
}
|
2018-09-02 13:12:03 -04:00
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
void RemoteSource::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const RemoteSourceSettings& settings, bool force)
|
2018-12-20 17:20:21 -05:00
|
|
|
{
|
|
|
|
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 RemoteSource::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 RemoteSourceSettings& 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 RemoteSource::webapiFormatChannelSettings(
|
|
|
|
QList<QString>& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings,
|
|
|
|
const RemoteSourceSettings& settings,
|
|
|
|
bool force
|
|
|
|
)
|
|
|
|
{
|
2019-05-07 08:43:38 -04:00
|
|
|
swgChannelSettings->setDirection(1); // single source (Tx)
|
2019-03-25 08:57:59 -04:00
|
|
|
swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet());
|
|
|
|
swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex());
|
2020-10-22 18:11:18 -04:00
|
|
|
swgChannelSettings->setChannelType(new QString(m_channelId));
|
2019-01-22 18:44:13 -05:00
|
|
|
swgChannelSettings->setRemoteSourceSettings(new SWGSDRangel::SWGRemoteSourceSettings());
|
|
|
|
SWGSDRangel::SWGRemoteSourceSettings *swgRemoteSourceSettings = swgChannelSettings->getRemoteSourceSettings();
|
2018-12-20 17:20:21 -05:00
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("dataAddress") || force) {
|
2019-01-22 18:44:13 -05:00
|
|
|
swgRemoteSourceSettings->setDataAddress(new QString(settings.m_dataAddress));
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("dataPort") || force) {
|
2019-01-22 18:44:13 -05:00
|
|
|
swgRemoteSourceSettings->setDataPort(settings.m_dataPort);
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor") || force) {
|
2019-01-22 18:44:13 -05:00
|
|
|
swgRemoteSourceSettings->setRgbColor(settings.m_rgbColor);
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
2021-12-14 01:56:02 -05:00
|
|
|
if (channelSettingsKeys.contains("log2Interp") || force) {
|
|
|
|
swgRemoteSourceSettings->setLog2Interp(settings.m_log2Interp);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("filterChainHash") || force) {
|
|
|
|
swgRemoteSourceSettings->setFilterChainHash(settings.m_filterChainHash);
|
|
|
|
}
|
2018-12-20 17:20:21 -05:00
|
|
|
if (channelSettingsKeys.contains("title") || force) {
|
2019-01-22 18:44:13 -05:00
|
|
|
swgRemoteSourceSettings->setTitle(new QString(settings.m_title));
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
2019-11-17 05:09:07 -05:00
|
|
|
if (channelSettingsKeys.contains("streamIndex") || force) {
|
|
|
|
swgRemoteSourceSettings->setStreamIndex(settings.m_streamIndex);
|
|
|
|
}
|
2021-12-03 16:32:54 -05:00
|
|
|
|
|
|
|
if (settings.m_channelMarker && (channelSettingsKeys.contains("channelMarker") || force))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelMarker *swgChannelMarker = new SWGSDRangel::SWGChannelMarker();
|
|
|
|
settings.m_channelMarker->formatTo(swgChannelMarker);
|
|
|
|
swgRemoteSourceSettings->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);
|
|
|
|
swgRemoteSourceSettings->setRollupState(swgRollupState);
|
|
|
|
}
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
|
2019-01-22 18:44:13 -05:00
|
|
|
void RemoteSource::networkManagerFinished(QNetworkReply *reply)
|
2018-12-20 17:20:21 -05:00
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
2019-01-22 18:44:13 -05:00
|
|
|
qWarning() << "RemoteSource::networkManagerFinished:"
|
2018-12-20 17:20:21 -05:00
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("RemoteSource::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
reply->deleteLater();
|
2018-12-20 17:20:21 -05:00
|
|
|
}
|
2019-11-17 05:09:07 -05:00
|
|
|
|
|
|
|
uint32_t RemoteSource::getNumberOfDeviceStreams() const
|
|
|
|
{
|
|
|
|
return m_deviceAPI->getNbSinkStreams();
|
2020-10-22 18:11:18 -04:00
|
|
|
}
|