2018-01-13 20:25:24 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 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 //
|
2019-04-11 00:57:41 -04:00
|
|
|
// (at your option) any later version. //
|
2018-01-13 20:25:24 -05: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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2018-12-17 12:39:09 -05:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QBuffer>
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
#include "SWGDeviceSettings.h"
|
|
|
|
#include "SWGDeviceState.h"
|
2020-03-10 00:23:19 -04:00
|
|
|
#include "SWGDeviceActions.h"
|
|
|
|
#include "SWGTestSourceActions.h"
|
2018-01-13 20:25:24 -05:00
|
|
|
|
|
|
|
#include "testsourceinput.h"
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2018-01-13 20:25:24 -05:00
|
|
|
#include "testsourcethread.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
#include "dsp/filerecord.h"
|
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(TestSourceInput::MsgConfigureTestSource, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(TestSourceInput::MsgFileRecord, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(TestSourceInput::MsgStartStop, Message)
|
|
|
|
|
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
TestSourceInput::TestSourceInput(DeviceAPI *deviceAPI) :
|
2018-01-13 20:25:24 -05:00
|
|
|
m_deviceAPI(deviceAPI),
|
|
|
|
m_settings(),
|
|
|
|
m_testSourceThread(0),
|
|
|
|
m_deviceDescription(),
|
|
|
|
m_running(false),
|
|
|
|
m_masterTimer(deviceAPI->getMasterTimer())
|
|
|
|
{
|
2018-05-08 05:03:09 -04:00
|
|
|
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
|
2019-05-20 18:27:08 -04:00
|
|
|
m_deviceAPI->setNbSourceStreams(1);
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->addAncillarySink(m_fileSink);
|
2018-01-13 20:25:24 -05:00
|
|
|
|
|
|
|
if (!m_sampleFifo.setSize(96000 * 4)) {
|
|
|
|
qCritical("TestSourceInput::TestSourceInput: Could not allocate SampleFifo");
|
|
|
|
}
|
2018-12-17 12:39:09 -05:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
2018-12-18 00:14:18 -05:00
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2018-01-13 20:25:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TestSourceInput::~TestSourceInput()
|
|
|
|
{
|
2018-12-17 12:39:09 -05:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
|
|
|
|
2018-12-18 00:14:18 -05:00
|
|
|
if (m_running) {
|
|
|
|
stop();
|
2018-12-17 12:39:09 -05:00
|
|
|
}
|
2018-12-18 00:14:18 -05:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->removeAncillarySink(m_fileSink);
|
2018-01-13 20:25:24 -05:00
|
|
|
delete m_fileSink;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestSourceInput::destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestSourceInput::init()
|
|
|
|
{
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestSourceInput::start()
|
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
|
|
if (m_running) stop();
|
|
|
|
|
2018-02-24 04:29:27 -05:00
|
|
|
m_testSourceThread = new TestSourceThread(&m_sampleFifo);
|
2018-01-13 20:25:24 -05:00
|
|
|
m_testSourceThread->setSamplerate(m_settings.m_sampleRate);
|
2018-09-06 08:29:14 -04:00
|
|
|
m_testSourceThread->startStop(true);
|
2018-01-13 20:25:24 -05:00
|
|
|
|
|
|
|
mutexLocker.unlock();
|
|
|
|
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
m_running = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestSourceInput::stop()
|
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
|
|
|
|
if (m_testSourceThread != 0)
|
|
|
|
{
|
2018-09-06 08:29:14 -04:00
|
|
|
m_testSourceThread->startStop(false);
|
|
|
|
m_testSourceThread->deleteLater();
|
2018-01-13 20:25:24 -05:00
|
|
|
m_testSourceThread = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray TestSourceInput::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestSourceInput::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if (!m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgConfigureTestSource* message = MsgConfigureTestSource::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
|
|
|
MsgConfigureTestSource* messageToGUI = MsgConfigureTestSource::create(m_settings, true);
|
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString& TestSourceInput::getDeviceDescription() const
|
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestSourceInput::getSampleRate() const
|
|
|
|
{
|
2018-08-06 16:46:48 -04:00
|
|
|
return m_settings.m_sampleRate/(1<<m_settings.m_log2Decim);
|
2018-01-13 20:25:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
quint64 TestSourceInput::getCenterFrequency() const
|
|
|
|
{
|
|
|
|
return m_settings.m_centerFrequency;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestSourceInput::setCenterFrequency(qint64 centerFrequency)
|
|
|
|
{
|
|
|
|
TestSourceSettings settings = m_settings;
|
|
|
|
settings.m_centerFrequency = centerFrequency;
|
|
|
|
|
|
|
|
MsgConfigureTestSource* message = MsgConfigureTestSource::create(settings, false);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
|
|
|
MsgConfigureTestSource* messageToGUI = MsgConfigureTestSource::create(settings, false);
|
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestSourceInput::handleMessage(const Message& message)
|
|
|
|
{
|
|
|
|
if (MsgConfigureTestSource::match(message))
|
|
|
|
{
|
|
|
|
MsgConfigureTestSource& conf = (MsgConfigureTestSource&) message;
|
|
|
|
qDebug() << "TestSourceInput::handleMessage: MsgConfigureTestSource";
|
|
|
|
|
|
|
|
bool success = applySettings(conf.getSettings(), conf.getForce());
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
qDebug("TestSourceInput::handleMessage: config error");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgFileRecord::match(message))
|
|
|
|
{
|
|
|
|
MsgFileRecord& conf = (MsgFileRecord&) message;
|
2018-08-21 18:40:01 -04:00
|
|
|
qDebug() << "TestSourceInput::handleMessage: MsgFileRecord: " << conf.getStartStop();
|
2018-01-13 20:25:24 -05:00
|
|
|
|
2018-05-09 11:39:48 -04:00
|
|
|
if (conf.getStartStop())
|
|
|
|
{
|
|
|
|
if (m_settings.m_fileRecordName.size() != 0) {
|
|
|
|
m_fileSink->setFileName(m_settings.m_fileRecordName);
|
|
|
|
} else {
|
2018-05-11 03:08:20 -04:00
|
|
|
m_fileSink->genUniqueFileName(m_deviceAPI->getDeviceUID());
|
2018-05-09 11:39:48 -04:00
|
|
|
}
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
m_fileSink->startRecording();
|
2018-05-09 11:39:48 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-13 20:25:24 -05:00
|
|
|
m_fileSink->stopRecording();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgStartStop::match(message))
|
|
|
|
{
|
|
|
|
MsgStartStop& cmd = (MsgStartStop&) message;
|
2018-08-21 18:40:01 -04:00
|
|
|
qDebug() << "TestSourceInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
2018-01-13 20:25:24 -05:00
|
|
|
|
|
|
|
if (cmd.getStartStop())
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
if (m_deviceAPI->initDeviceEngine())
|
2018-01-13 20:25:24 -05:00
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->startDeviceEngine();
|
2018-01-13 20:25:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->stopDeviceEngine();
|
2018-01-13 20:25:24 -05:00
|
|
|
}
|
|
|
|
|
2018-12-17 12:39:09 -05:00
|
|
|
if (m_settings.m_useReverseAPI) {
|
|
|
|
webapiReverseSendStartStop(cmd.getStartStop());
|
2018-12-18 00:14:18 -05:00
|
|
|
}
|
2018-12-17 12:39:09 -05:00
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool force)
|
|
|
|
{
|
2018-12-17 12:39:09 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
2018-02-04 12:46:22 -05:00
|
|
|
if ((m_settings.m_autoCorrOptions != settings.m_autoCorrOptions) || force)
|
2018-01-14 05:58:36 -05:00
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("autoCorrOptions");
|
|
|
|
|
2018-02-04 12:46:22 -05:00
|
|
|
switch(settings.m_autoCorrOptions)
|
|
|
|
{
|
|
|
|
case TestSourceSettings::AutoCorrDC:
|
|
|
|
m_deviceAPI->configureCorrections(true, false);
|
|
|
|
break;
|
|
|
|
case TestSourceSettings::AutoCorrDCAndIQ:
|
|
|
|
m_deviceAPI->configureCorrections(true, true);
|
|
|
|
break;
|
|
|
|
case TestSourceSettings::AutoCorrNone:
|
|
|
|
default:
|
|
|
|
m_deviceAPI->configureCorrections(false, false);
|
|
|
|
break;
|
|
|
|
}
|
2018-01-14 05:58:36 -05:00
|
|
|
}
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
if ((m_settings.m_sampleRate != settings.m_sampleRate) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("sampleRate");
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
if (m_testSourceThread != 0)
|
|
|
|
{
|
|
|
|
m_testSourceThread->setSamplerate(settings.m_sampleRate);
|
|
|
|
qDebug("TestSourceInput::applySettings: sample rate set to %d", settings.m_sampleRate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("log2Decim");
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
if (m_testSourceThread != 0)
|
|
|
|
{
|
|
|
|
m_testSourceThread->setLog2Decimation(settings.m_log2Decim);
|
|
|
|
qDebug() << "TestSourceInput::applySettings: set decimation to " << (1<<settings.m_log2Decim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 21:04:42 -05:00
|
|
|
if ((m_settings.m_centerFrequency != settings.m_centerFrequency)
|
|
|
|
|| (m_settings.m_fcPos != settings.m_fcPos)
|
|
|
|
|| (m_settings.m_frequencyShift != settings.m_frequencyShift)
|
2018-05-10 07:16:27 -04:00
|
|
|
|| (m_settings.m_sampleRate != settings.m_sampleRate)
|
2018-02-21 21:04:42 -05:00
|
|
|
|| (m_settings.m_log2Decim != settings.m_log2Decim) || force)
|
2018-01-13 20:25:24 -05:00
|
|
|
{
|
2018-12-17 12:39:09 -05:00
|
|
|
reverseAPIKeys.append("centerFrequency");
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("fcPos");
|
|
|
|
reverseAPIKeys.append("frequencyShift");
|
2018-12-17 12:39:09 -05:00
|
|
|
|
2018-05-10 07:16:27 -04:00
|
|
|
qint64 deviceCenterFrequency = DeviceSampleSource::calculateDeviceCenterFrequency(
|
|
|
|
settings.m_centerFrequency,
|
|
|
|
0, // no transverter mode
|
|
|
|
settings.m_log2Decim,
|
|
|
|
(DeviceSampleSource::fcPos_t) settings.m_fcPos,
|
2019-04-01 19:10:03 -04:00
|
|
|
settings.m_sampleRate,
|
|
|
|
DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
|
|
|
|
false);
|
2018-05-10 07:16:27 -04:00
|
|
|
|
2018-01-19 21:44:44 -05:00
|
|
|
int frequencyShift = settings.m_frequencyShift;
|
2018-01-13 20:25:24 -05:00
|
|
|
quint32 devSampleRate = settings.m_sampleRate;
|
|
|
|
|
2018-01-19 21:28:30 -05:00
|
|
|
if (settings.m_log2Decim != 0)
|
2018-01-13 20:25:24 -05:00
|
|
|
{
|
2018-05-10 16:17:39 -04:00
|
|
|
frequencyShift += DeviceSampleSource::calculateFrequencyShift(
|
|
|
|
settings.m_log2Decim,
|
|
|
|
(DeviceSampleSource::fcPos_t) settings.m_fcPos,
|
2019-04-01 19:10:03 -04:00
|
|
|
settings.m_sampleRate,
|
|
|
|
DeviceSampleSource::FSHIFT_STD);
|
2018-01-13 20:25:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_testSourceThread != 0)
|
|
|
|
{
|
|
|
|
m_testSourceThread->setFcPos((int) settings.m_fcPos);
|
2018-01-19 21:44:44 -05:00
|
|
|
m_testSourceThread->setFrequencyShift(frequencyShift);
|
2018-01-19 21:28:30 -05:00
|
|
|
qDebug() << "TestSourceInput::applySettings:"
|
|
|
|
<< " center freq: " << settings.m_centerFrequency << " Hz"
|
2018-01-13 20:25:24 -05:00
|
|
|
<< " device center freq: " << deviceCenterFrequency << " Hz"
|
|
|
|
<< " device sample rate: " << devSampleRate << "Hz"
|
|
|
|
<< " Actual sample rate: " << devSampleRate/(1<<m_settings.m_log2Decim) << "Hz"
|
|
|
|
<< " f shift: " << settings.m_frequencyShift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_amplitudeBits != settings.m_amplitudeBits) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("amplitudeBits");
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setAmplitudeBits(settings.m_amplitudeBits);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-14 05:58:36 -05:00
|
|
|
if ((m_settings.m_dcFactor != settings.m_dcFactor) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("dcFactor");
|
|
|
|
|
2018-01-14 05:58:36 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setDCFactor(settings.m_dcFactor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_iFactor != settings.m_iFactor) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("iFactor");
|
|
|
|
|
2018-01-14 05:58:36 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setIFactor(settings.m_iFactor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_qFactor != settings.m_qFactor) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("qFactor");
|
|
|
|
|
2018-01-14 05:58:36 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setQFactor(settings.m_qFactor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-31 16:34:55 -05:00
|
|
|
if ((m_settings.m_phaseImbalance != settings.m_phaseImbalance) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("phaseImbalance");
|
|
|
|
|
2018-01-31 16:34:55 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setPhaseImbalance(settings.m_phaseImbalance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
if ((m_settings.m_sampleSizeIndex != settings.m_sampleSizeIndex) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("sampleSizeIndex");
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setBitSize(settings.m_sampleSizeIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_sampleRate != settings.m_sampleRate)
|
|
|
|
|| (m_settings.m_centerFrequency != settings.m_centerFrequency)
|
|
|
|
|| (m_settings.m_log2Decim != settings.m_log2Decim)
|
|
|
|
|| (m_settings.m_fcPos != settings.m_fcPos) || force)
|
|
|
|
{
|
|
|
|
int sampleRate = settings.m_sampleRate/(1<<settings.m_log2Decim);
|
|
|
|
DSPSignalNotification *notif = new DSPSignalNotification(sampleRate, settings.m_centerFrequency);
|
|
|
|
m_fileSink->handleMessage(*notif); // forward to file sink
|
|
|
|
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
|
|
|
|
}
|
|
|
|
|
2018-02-11 07:48:17 -05:00
|
|
|
if ((m_settings.m_modulationTone != settings.m_modulationTone) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("modulationTone");
|
|
|
|
|
2018-02-11 07:48:17 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setToneFrequency(settings.m_modulationTone * 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_modulation != settings.m_modulation) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("modulation");
|
|
|
|
|
2018-10-23 18:10:12 -04:00
|
|
|
if (m_testSourceThread != 0)
|
|
|
|
{
|
2018-02-11 07:48:17 -05:00
|
|
|
m_testSourceThread->setModulation(settings.m_modulation);
|
2018-10-23 18:10:12 -04:00
|
|
|
|
|
|
|
if (settings.m_modulation == TestSourceSettings::ModulationPattern0) {
|
|
|
|
m_testSourceThread->setPattern0();
|
|
|
|
} else if (settings.m_modulation == TestSourceSettings::ModulationPattern1) {
|
|
|
|
m_testSourceThread->setPattern1();
|
2018-10-25 07:53:58 -04:00
|
|
|
} else if (settings.m_modulation == TestSourceSettings::ModulationPattern2) {
|
|
|
|
m_testSourceThread->setPattern2();
|
2018-10-23 18:10:12 -04:00
|
|
|
}
|
2018-02-11 07:48:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_amModulation != settings.m_amModulation) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("amModulation");
|
|
|
|
|
2018-02-11 07:48:17 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setAMModulation(settings.m_amModulation / 100.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_settings.m_fmDeviation != settings.m_fmDeviation) || force)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
reverseAPIKeys.append("fmDeviation");
|
|
|
|
|
2018-02-11 07:48:17 -05:00
|
|
|
if (m_testSourceThread != 0) {
|
|
|
|
m_testSourceThread->setFMDeviation(settings.m_fmDeviation * 100.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 12:39:09 -05:00
|
|
|
if (settings.m_useReverseAPI)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
qDebug("TestSourceInput::applySettings: call webapiReverseSendSettings");
|
2018-12-17 12:39:09 -05:00
|
|
|
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);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
2018-01-13 20:25:24 -05:00
|
|
|
m_settings = settings;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestSourceInput::webapiRunGet(
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-01-13 20:25:24 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-01-13 20:25:24 -05:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestSourceInput::webapiRun(
|
|
|
|
bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-01-13 20:25:24 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-01-13 20:25:24 -05:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
|
|
|
MsgStartStop *message = MsgStartStop::create(run);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgStartStop *msgToGUI = MsgStartStop::create(run);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
2018-05-27 16:25:01 -04:00
|
|
|
|
|
|
|
int TestSourceInput::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-05-27 16:25:01 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-05-27 16:25:01 -04:00
|
|
|
response.setTestSourceSettings(new SWGSDRangel::SWGTestSourceSettings());
|
|
|
|
response.getTestSourceSettings()->init();
|
|
|
|
webapiFormatDeviceSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TestSourceInput::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-05-27 16:25:01 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2018-05-27 16:25:01 -04:00
|
|
|
TestSourceSettings settings = m_settings;
|
2019-08-04 14:24:44 -04:00
|
|
|
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
2018-05-27 16:25:01 -04:00
|
|
|
|
2019-08-04 14:24:44 -04:00
|
|
|
MsgConfigureTestSource *msg = MsgConfigureTestSource::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureTestSource *msgToGUI = MsgConfigureTestSource::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatDeviceSettings(response, settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:23:19 -04:00
|
|
|
int TestSourceInput::webapiActionsPost(
|
|
|
|
const QStringList& deviceActionsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceActions& query,
|
|
|
|
QString& errorMessage)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGTestSourceActions *swgTestSourceActions = query.getTestSourceActions();
|
|
|
|
|
|
|
|
if (swgTestSourceActions)
|
|
|
|
{
|
|
|
|
if (deviceActionsKeys.contains("record"))
|
|
|
|
{
|
|
|
|
bool record = swgTestSourceActions->getRecord() != 0;
|
|
|
|
MsgFileRecord *msg = MsgFileRecord::create(record);
|
|
|
|
getInputMessageQueue()->push(msg);
|
|
|
|
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgFileRecord *msgToGUI = MsgFileRecord::create(record);
|
|
|
|
getMessageQueueToGUI()->push(msgToGUI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 202;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errorMessage = "Missing TestSourceActions in query";
|
|
|
|
return 400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-04 14:24:44 -04:00
|
|
|
void TestSourceInput::webapiUpdateDeviceSettings(
|
|
|
|
TestSourceSettings& settings,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response)
|
|
|
|
{
|
2018-05-27 16:25:01 -04:00
|
|
|
if (deviceSettingsKeys.contains("centerFrequency")) {
|
|
|
|
settings.m_centerFrequency = response.getTestSourceSettings()->getCenterFrequency();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("frequencyShift")) {
|
|
|
|
settings.m_frequencyShift = response.getTestSourceSettings()->getFrequencyShift();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("sampleRate")) {
|
|
|
|
settings.m_sampleRate = response.getTestSourceSettings()->getSampleRate();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("log2Decim")) {
|
|
|
|
settings.m_log2Decim = response.getTestSourceSettings()->getLog2Decim();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("fcPos")) {
|
|
|
|
int fcPos = response.getTestSourceSettings()->getFcPos();
|
|
|
|
fcPos = fcPos < 0 ? 0 : fcPos > 2 ? 2 : fcPos;
|
|
|
|
settings.m_fcPos = (TestSourceSettings::fcPos_t) fcPos;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("sampleSizeIndex")) {
|
|
|
|
int sampleSizeIndex = response.getTestSourceSettings()->getSampleSizeIndex();
|
|
|
|
sampleSizeIndex = sampleSizeIndex < 0 ? 0 : sampleSizeIndex > 1 ? 2 : sampleSizeIndex;
|
|
|
|
settings.m_sampleSizeIndex = sampleSizeIndex;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("amplitudeBits")) {
|
|
|
|
settings.m_amplitudeBits = response.getTestSourceSettings()->getAmplitudeBits();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("autoCorrOptions")) {
|
|
|
|
int autoCorrOptions = response.getTestSourceSettings()->getAutoCorrOptions();
|
|
|
|
autoCorrOptions = autoCorrOptions < 0 ? 0 : autoCorrOptions >= TestSourceSettings::AutoCorrLast ? TestSourceSettings::AutoCorrLast-1 : autoCorrOptions;
|
|
|
|
settings.m_sampleSizeIndex = (TestSourceSettings::AutoCorrOptions) autoCorrOptions;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("modulation")) {
|
|
|
|
int modulation = response.getTestSourceSettings()->getModulation();
|
|
|
|
modulation = modulation < 0 ? 0 : modulation >= TestSourceSettings::ModulationLast ? TestSourceSettings::ModulationLast-1 : modulation;
|
|
|
|
settings.m_modulation = (TestSourceSettings::Modulation) modulation;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("modulationTone")) {
|
|
|
|
settings.m_modulationTone = response.getTestSourceSettings()->getModulationTone();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("amModulation")) {
|
|
|
|
settings.m_amModulation = response.getTestSourceSettings()->getAmModulation();
|
|
|
|
};
|
|
|
|
if (deviceSettingsKeys.contains("fmDeviation")) {
|
|
|
|
settings.m_fmDeviation = response.getTestSourceSettings()->getFmDeviation();
|
|
|
|
};
|
|
|
|
if (deviceSettingsKeys.contains("dcFactor")) {
|
|
|
|
settings.m_dcFactor = response.getTestSourceSettings()->getDcFactor();
|
|
|
|
};
|
|
|
|
if (deviceSettingsKeys.contains("iFactor")) {
|
|
|
|
settings.m_iFactor = response.getTestSourceSettings()->getIFactor();
|
|
|
|
};
|
|
|
|
if (deviceSettingsKeys.contains("qFactor")) {
|
|
|
|
settings.m_qFactor = response.getTestSourceSettings()->getQFactor();
|
|
|
|
};
|
|
|
|
if (deviceSettingsKeys.contains("phaseImbalance")) {
|
|
|
|
settings.m_phaseImbalance = response.getTestSourceSettings()->getPhaseImbalance();
|
|
|
|
};
|
|
|
|
if (deviceSettingsKeys.contains("fileRecordName")) {
|
|
|
|
settings.m_fileRecordName = *response.getTestSourceSettings()->getFileRecordName();
|
|
|
|
}
|
2018-12-18 15:46:03 -05:00
|
|
|
if (deviceSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getTestSourceSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIAddress")) {
|
2019-01-10 09:45:03 -05:00
|
|
|
settings.m_reverseAPIAddress = *response.getTestSourceSettings()->getReverseApiAddress();
|
2018-12-18 15:46:03 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getTestSourceSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getTestSourceSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
2018-05-27 16:25:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSourceInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const TestSourceSettings& settings)
|
|
|
|
{
|
|
|
|
response.getTestSourceSettings()->setCenterFrequency(settings.m_centerFrequency);
|
|
|
|
response.getTestSourceSettings()->setFrequencyShift(settings.m_frequencyShift);
|
|
|
|
response.getTestSourceSettings()->setSampleRate(settings.m_sampleRate);
|
|
|
|
response.getTestSourceSettings()->setLog2Decim(settings.m_log2Decim);
|
|
|
|
response.getTestSourceSettings()->setFcPos((int) settings.m_fcPos);
|
|
|
|
response.getTestSourceSettings()->setSampleSizeIndex((int) settings.m_sampleSizeIndex);
|
|
|
|
response.getTestSourceSettings()->setAmplitudeBits(settings.m_amplitudeBits);
|
|
|
|
response.getTestSourceSettings()->setAutoCorrOptions((int) settings.m_autoCorrOptions);
|
|
|
|
response.getTestSourceSettings()->setModulation((int) settings.m_modulation);
|
|
|
|
response.getTestSourceSettings()->setModulationTone(settings.m_modulationTone);
|
|
|
|
response.getTestSourceSettings()->setAmModulation(settings.m_amModulation);
|
|
|
|
response.getTestSourceSettings()->setFmDeviation(settings.m_fmDeviation);
|
|
|
|
response.getTestSourceSettings()->setDcFactor(settings.m_dcFactor);
|
|
|
|
response.getTestSourceSettings()->setIFactor(settings.m_iFactor);
|
|
|
|
response.getTestSourceSettings()->setQFactor(settings.m_qFactor);
|
|
|
|
response.getTestSourceSettings()->setPhaseImbalance(settings.m_phaseImbalance);
|
|
|
|
|
|
|
|
if (response.getTestSourceSettings()->getFileRecordName()) {
|
|
|
|
*response.getTestSourceSettings()->getFileRecordName() = settings.m_fileRecordName;
|
|
|
|
} else {
|
|
|
|
response.getTestSourceSettings()->setFileRecordName(new QString(settings.m_fileRecordName));
|
|
|
|
}
|
2018-12-18 15:46:03 -05:00
|
|
|
|
|
|
|
response.getTestSourceSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
|
|
|
|
|
|
|
if (response.getTestSourceSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getTestSourceSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
|
|
|
} else {
|
|
|
|
response.getTestSourceSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getTestSourceSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getTestSourceSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
2018-05-27 16:25:01 -04:00
|
|
|
}
|
|
|
|
|
2018-12-17 12:39:09 -05:00
|
|
|
void TestSourceInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const TestSourceSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgDeviceSettings->setDirection(0); // single Rx
|
2019-03-25 08:41:38 -04:00
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
2018-12-17 12:39:09 -05:00
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("TestSource"));
|
|
|
|
swgDeviceSettings->setTestSourceSettings(new SWGSDRangel::SWGTestSourceSettings());
|
|
|
|
SWGSDRangel::SWGTestSourceSettings *swgTestSourceSettings = swgDeviceSettings->getTestSourceSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("centerFrequency") || force) {
|
|
|
|
swgTestSourceSettings->setCenterFrequency(settings.m_centerFrequency);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("frequencyShift") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setFrequencyShift(settings.m_frequencyShift);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("sampleRate") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setSampleRate(settings.m_sampleRate);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("log2Decim") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setLog2Decim(settings.m_log2Decim);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("fcPos") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setFcPos((int) settings.m_fcPos);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("sampleSizeIndex") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setSampleSizeIndex(settings.m_sampleSizeIndex);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("amplitudeBits") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setAmplitudeBits(settings.m_amplitudeBits);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("autoCorrOptions") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setAutoCorrOptions((int) settings.m_sampleSizeIndex);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("modulation") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setModulation((int) settings.m_modulation);
|
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("modulationTone")) {
|
|
|
|
swgTestSourceSettings->setModulationTone(settings.m_modulationTone);
|
|
|
|
}
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("amModulation") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setAmModulation(settings.m_amModulation);
|
|
|
|
};
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("fmDeviation") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setFmDeviation(settings.m_fmDeviation);
|
|
|
|
};
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("dcFactor") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setDcFactor(settings.m_dcFactor);
|
|
|
|
};
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("iFactor") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setIFactor(settings.m_iFactor);
|
|
|
|
};
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("qFactor") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setQFactor(settings.m_qFactor);
|
|
|
|
};
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("phaseImbalance") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setPhaseImbalance(settings.m_phaseImbalance);
|
|
|
|
};
|
2018-12-19 16:01:26 -05:00
|
|
|
if (deviceSettingsKeys.contains("fileRecordName") || force) {
|
2018-12-17 12:39:09 -05:00
|
|
|
swgTestSourceSettings->setFileRecordName(new QString(settings.m_fileRecordName));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/settings")
|
|
|
|
.arg(settings.m_reverseAPIAddress)
|
|
|
|
.arg(settings.m_reverseAPIPort)
|
|
|
|
.arg(settings.m_reverseAPIDeviceIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
2018-12-19 02:52:50 -05:00
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
2018-12-17 12:39:09 -05:00
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
QBuffer *buffer = new QBuffer();
|
2018-12-17 12:39:09 -05:00
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
2018-12-18 00:14:18 -05:00
|
|
|
// qDebug("TestSourceInput::webapiReverseSendSettings: %s", channelSettingsURL.toStdString().c_str());
|
|
|
|
// qDebug("TestSourceInput::webapiReverseSendSettings: query:\n%s", swgDeviceSettings->asJson().toStdString().c_str());
|
2018-12-17 12:39:09 -05:00
|
|
|
|
|
|
|
// 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-17 12:39:09 -05:00
|
|
|
|
2018-12-18 00:14:18 -05:00
|
|
|
delete swgDeviceSettings;
|
2018-12-17 12:39:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSourceInput::webapiReverseSendStartStop(bool start)
|
|
|
|
{
|
2019-03-25 10:10:31 -04:00
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgDeviceSettings->setDirection(0); // single Rx
|
2019-03-25 10:10:31 -04:00
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("TestSource"));
|
|
|
|
|
2018-12-17 12:39:09 -05:00
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/run")
|
|
|
|
.arg(m_settings.m_reverseAPIAddress)
|
|
|
|
.arg(m_settings.m_reverseAPIPort)
|
|
|
|
.arg(m_settings.m_reverseAPIDeviceIndex);
|
2018-12-18 00:14:18 -05:00
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
2019-03-25 10:10:31 -04:00
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
QBuffer *buffer = new QBuffer();
|
2019-03-25 10:10:31 -04:00
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
2019-11-12 12:46:21 -05:00
|
|
|
QNetworkReply *reply;
|
2018-12-17 12:39:09 -05:00
|
|
|
|
|
|
|
if (start) {
|
2019-11-12 12:46:21 -05:00
|
|
|
reply = m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer);
|
2018-12-17 12:39:09 -05:00
|
|
|
} else {
|
2019-11-12 12:46:21 -05:00
|
|
|
reply = m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer);
|
2018-12-17 12:39:09 -05:00
|
|
|
}
|
2019-06-14 10:58:09 -04:00
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
buffer->setParent(reply);
|
2019-06-14 10:58:09 -04:00
|
|
|
delete swgDeviceSettings;
|
2018-12-17 12:39:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSourceInput::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
2018-12-17 12:39:09 -05:00
|
|
|
{
|
2018-12-18 00:14:18 -05:00
|
|
|
qWarning() << "TestSourceInput::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("TestSourceInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2018-12-17 12:39:09 -05:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:46:21 -05:00
|
|
|
reply->deleteLater();
|
2018-12-17 12:39:09 -05:00
|
|
|
}
|