2016-06-19 03:56:49 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2016 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. //
|
2016-06-19 03:56:49 -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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2018-12-26 11:08:21 -05:00
|
|
|
|
2016-06-19 03:56:49 -04:00
|
|
|
#include <QDebug>
|
2018-12-26 11:08:21 -05:00
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2016-06-19 03:56:49 -04:00
|
|
|
|
2017-12-09 06:41:42 -05:00
|
|
|
#include "SWGDeviceSettings.h"
|
|
|
|
#include "SWGDeviceState.h"
|
2018-05-27 05:07:24 -04:00
|
|
|
#include "SWGDeviceReport.h"
|
2019-02-02 18:49:57 -05:00
|
|
|
#include "SWGRemoteInputReport.h"
|
2017-12-09 06:41:42 -05:00
|
|
|
|
2016-06-19 03:56:49 -04:00
|
|
|
#include "util/simpleserializer.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "dsp/dspengine.h"
|
2018-12-26 11:08:21 -05:00
|
|
|
#include "device/devicesourceapi.h"
|
|
|
|
#include "dsp/filerecord.h"
|
2016-10-02 04:30:58 -04:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
#include "remoteinput.h"
|
|
|
|
#include "remoteinputudphandler.h"
|
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgConfigureRemoteInput, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgConfigureRemoteInputTiming, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteInputAcquisition, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteInputStreamData, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgReportRemoteInputStreamTiming, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgFileRecord, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(RemoteInput::MsgStartStop, Message)
|
|
|
|
|
|
|
|
RemoteInput::RemoteInput(DeviceSourceAPI *deviceAPI) :
|
2016-06-19 03:56:49 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
2017-12-25 20:18:30 -05:00
|
|
|
m_settings(),
|
2019-02-02 18:26:26 -05:00
|
|
|
m_remoteInputUDPHandler(0),
|
2016-06-19 03:56:49 -04:00
|
|
|
m_deviceDescription(),
|
2018-03-03 19:47:51 -05:00
|
|
|
m_startingTimeStamp(0)
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
m_sampleFifo.setSize(96000 * 4);
|
2019-02-02 18:26:26 -05:00
|
|
|
m_remoteInputUDPHandler = new RemoteInputUDPHandler(&m_sampleFifo, m_deviceAPI);
|
2017-09-04 18:31:45 -04:00
|
|
|
|
2018-05-08 05:03:09 -04:00
|
|
|
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
|
2017-09-04 18:31:45 -04:00
|
|
|
m_deviceAPI->addSink(m_fileSink);
|
2018-12-26 11:08:21 -05:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
RemoteInput::~RemoteInput()
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2018-12-26 11:08:21 -05:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
2016-06-19 03:56:49 -04:00
|
|
|
stop();
|
2017-09-04 18:31:45 -04:00
|
|
|
m_deviceAPI->removeSink(m_fileSink);
|
|
|
|
delete m_fileSink;
|
2019-02-02 18:26:26 -05:00
|
|
|
delete m_remoteInputUDPHandler;
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::destroy()
|
2017-09-14 20:32:30 -04:00
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::init()
|
2017-12-25 03:10:19 -05:00
|
|
|
{
|
2017-12-25 20:18:30 -05:00
|
|
|
applySettings(m_settings, true);
|
2017-12-25 03:10:19 -05:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
bool RemoteInput::start()
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
qDebug() << "RemoteInput::start";
|
|
|
|
m_remoteInputUDPHandler->start();
|
2016-06-19 03:56:49 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::stop()
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
qDebug() << "RemoteInput::stop";
|
|
|
|
m_remoteInputUDPHandler->stop();
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
QByteArray RemoteInput::serialize() const
|
2017-12-27 21:21:48 -05:00
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
bool RemoteInput::deserialize(const QByteArray& data)
|
2017-12-27 21:21:48 -05:00
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if (!m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgConfigureRemoteInput* message = MsgConfigureRemoteInput::create(m_settings, true);
|
2017-12-27 21:21:48 -05:00
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue)
|
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgConfigureRemoteInput* messageToGUI = MsgConfigureRemoteInput::create(m_settings, true);
|
2017-12-27 21:21:48 -05:00
|
|
|
m_guiMessageQueue->push(messageToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::setMessageQueueToGUI(MessageQueue *queue)
|
2017-12-24 13:58:26 -05:00
|
|
|
{
|
|
|
|
m_guiMessageQueue = queue;
|
2019-02-02 18:26:26 -05:00
|
|
|
m_remoteInputUDPHandler->setMessageQueueToGUI(queue);
|
2017-12-24 13:58:26 -05:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
const QString& RemoteInput::getDeviceDescription() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
return m_deviceDescription;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
int RemoteInput::getSampleRate() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
return m_remoteInputUDPHandler->getSampleRate();
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
quint64 RemoteInput::getCenterFrequency() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
return m_remoteInputUDPHandler->getCenterFrequency();
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::setCenterFrequency(qint64 centerFrequency)
|
2017-12-27 21:21:48 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) centerFrequency;
|
2017-12-27 21:21:48 -05:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
std::time_t RemoteInput::getStartingTimeStamp() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
|
|
|
return m_startingTimeStamp;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
bool RemoteInput::isStreaming() const
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
return m_remoteInputUDPHandler->isStreaming();
|
2016-06-19 03:56:49 -04:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
bool RemoteInput::handleMessage(const Message& message)
|
2016-06-19 03:56:49 -04:00
|
|
|
{
|
2017-09-04 18:31:45 -04:00
|
|
|
if (DSPSignalNotification::match(message))
|
|
|
|
{
|
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) message;
|
|
|
|
return m_fileSink->handleMessage(notif); // forward to file sink
|
|
|
|
}
|
|
|
|
else if (MsgFileRecord::match(message))
|
|
|
|
{
|
|
|
|
MsgFileRecord& conf = (MsgFileRecord&) message;
|
2019-02-02 18:26:26 -05:00
|
|
|
qDebug() << "RemoteInput::handleMessage: MsgFileRecord: " << conf.getStartStop();
|
2017-09-04 18:31:45 -04: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
|
|
|
}
|
|
|
|
|
2017-09-04 18:31:45 -04:00
|
|
|
m_fileSink->startRecording();
|
2018-05-09 11:39:48 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-04 18:31:45 -04:00
|
|
|
m_fileSink->stopRecording();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-13 18:19:59 -05:00
|
|
|
else if (MsgStartStop::match(message))
|
|
|
|
{
|
|
|
|
MsgStartStop& cmd = (MsgStartStop&) message;
|
2019-02-02 18:26:26 -05:00
|
|
|
qDebug() << "RemoteInput::handleMessage: MsgStartStop: " << (cmd.getStartStop() ? "start" : "stop");
|
2017-12-13 18:19:59 -05:00
|
|
|
|
|
|
|
if (cmd.getStartStop())
|
|
|
|
{
|
|
|
|
if (m_deviceAPI->initAcquisition())
|
|
|
|
{
|
|
|
|
m_deviceAPI->startAcquisition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_deviceAPI->stopAcquisition();
|
|
|
|
}
|
|
|
|
|
2018-12-26 11:08:21 -05:00
|
|
|
if (m_settings.m_useReverseAPI) {
|
|
|
|
webapiReverseSendStartStop(cmd.getStartStop());
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:19:59 -05:00
|
|
|
return true;
|
|
|
|
}
|
2019-02-02 18:26:26 -05:00
|
|
|
else if (MsgConfigureRemoteInput::match(message))
|
2017-06-08 02:40:21 -04:00
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
qDebug() << "RemoteInput::handleMessage:" << message.getIdentifier();
|
|
|
|
MsgConfigureRemoteInput& conf = (MsgConfigureRemoteInput&) message;
|
2017-12-25 20:18:30 -05:00
|
|
|
applySettings(conf.getSettings(), conf.getForce());
|
2017-06-08 02:40:21 -04:00
|
|
|
return true;
|
|
|
|
}
|
2016-06-19 03:56:49 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::applySettings(const RemoteInputSettings& settings, bool force)
|
2017-12-25 20:18:30 -05:00
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_mutex);
|
|
|
|
std::ostringstream os;
|
|
|
|
QString remoteAddress;
|
2019-02-02 18:26:26 -05:00
|
|
|
m_remoteInputUDPHandler->getRemoteAddress(remoteAddress);
|
2018-12-26 11:08:21 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
|
|
|
if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) {
|
|
|
|
reverseAPIKeys.append("dcBlock");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force) {
|
|
|
|
reverseAPIKeys.append("iqCorrection");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_dataAddress != settings.m_dataAddress) || force) {
|
|
|
|
reverseAPIKeys.append("dataAddress");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_dataPort != settings.m_dataPort) || force) {
|
|
|
|
reverseAPIKeys.append("dataPort");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_apiAddress != settings.m_apiAddress) || force) {
|
|
|
|
reverseAPIKeys.append("apiAddress");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_apiPort != settings.m_apiPort) || force) {
|
|
|
|
reverseAPIKeys.append("apiPort");
|
|
|
|
}
|
|
|
|
if ((m_settings.m_fileRecordName != settings.m_fileRecordName) || force) {
|
|
|
|
reverseAPIKeys.append("fileRecordName");
|
|
|
|
}
|
2017-12-25 20:18:30 -05:00
|
|
|
|
|
|
|
if ((m_settings.m_dcBlock != settings.m_dcBlock) || (m_settings.m_iqCorrection != settings.m_iqCorrection) || force)
|
|
|
|
{
|
|
|
|
m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection);
|
2019-02-02 18:26:26 -05:00
|
|
|
qDebug("RemoteInput::applySettings: corrections: DC block: %s IQ imbalance: %s",
|
2018-09-08 17:30:22 -04:00
|
|
|
settings.m_dcBlock ? "true" : "false",
|
|
|
|
settings.m_iqCorrection ? "true" : "false");
|
2017-12-25 20:18:30 -05:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
m_remoteInputUDPHandler->configureUDPLink(settings.m_dataAddress, settings.m_dataPort);
|
|
|
|
m_remoteInputUDPHandler->getRemoteAddress(remoteAddress);
|
2017-12-25 20:18:30 -05:00
|
|
|
|
|
|
|
mutexLocker.unlock();
|
2018-12-26 11:08: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);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
2017-12-25 20:18:30 -05:00
|
|
|
m_settings = settings;
|
|
|
|
m_remoteAddress = remoteAddress;
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
qDebug() << "RemoteInput::applySettings: "
|
2018-09-08 17:30:22 -04:00
|
|
|
<< " m_dataAddress: " << m_settings.m_dataAddress
|
2017-12-25 20:18:30 -05:00
|
|
|
<< " m_dataPort: " << m_settings.m_dataPort
|
2018-09-08 17:30:22 -04:00
|
|
|
<< " m_apiAddress: " << m_settings.m_apiAddress
|
|
|
|
<< " m_apiPort: " << m_settings.m_apiPort
|
|
|
|
<< " m_remoteAddress: " << m_remoteAddress;
|
2017-12-25 20:18:30 -05:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
int RemoteInput::webapiRunGet(
|
2017-12-09 06:41:42 -05:00
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2017-12-09 06:41:42 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2017-12-09 06:41:42 -05:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
int RemoteInput::webapiRun(
|
2017-12-09 06:41:42 -05:00
|
|
|
bool run,
|
|
|
|
SWGSDRangel::SWGDeviceState& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2017-12-09 06:41:42 -05:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2017-12-14 17:29:12 -05:00
|
|
|
m_deviceAPI->getDeviceEngineStateStr(*response.getState());
|
2017-12-13 18:19:59 -05:00
|
|
|
MsgStartStop *message = MsgStartStop::create(run);
|
|
|
|
m_inputMessageQueue.push(message);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
2017-12-09 06:41:42 -05:00
|
|
|
{
|
2017-12-13 18:19:59 -05:00
|
|
|
MsgStartStop *msgToGUI = MsgStartStop::create(run);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
2017-12-09 06:41:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
int RemoteInput::webapiSettingsGet(
|
2018-05-27 05:07:24 -04:00
|
|
|
SWGSDRangel::SWGDeviceSettings& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-05-27 05:07:24 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2019-02-02 18:49:57 -05:00
|
|
|
response.setRemoteInputSettings(new SWGSDRangel::SWGRemoteInputSettings());
|
|
|
|
response.getRemoteInputSettings()->init();
|
2018-05-27 05:07:24 -04:00
|
|
|
webapiFormatDeviceSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
int RemoteInput::webapiSettingsPutPatch(
|
2018-05-27 05:07:24 -04:00
|
|
|
bool force,
|
|
|
|
const QStringList& deviceSettingsKeys,
|
|
|
|
SWGSDRangel::SWGDeviceSettings& response, // query + response
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-05-27 05:07:24 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2019-02-02 18:26:26 -05:00
|
|
|
RemoteInputSettings settings = m_settings;
|
2018-05-27 05:07:24 -04:00
|
|
|
|
2018-09-08 17:30:22 -04:00
|
|
|
if (deviceSettingsKeys.contains("apiAddress")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_apiAddress = *response.getRemoteInputSettings()->getApiAddress();
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
2018-09-08 17:30:22 -04:00
|
|
|
if (deviceSettingsKeys.contains("apiPort")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_apiPort = response.getRemoteInputSettings()->getApiPort();
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
2018-09-08 17:30:22 -04:00
|
|
|
if (deviceSettingsKeys.contains("dataAddress")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_dataAddress = *response.getRemoteInputSettings()->getDataAddress();
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("dataPort")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_dataPort = response.getRemoteInputSettings()->getDataPort();
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("dcBlock")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_dcBlock = response.getRemoteInputSettings()->getDcBlock() != 0;
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("iqCorrection")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_iqCorrection = response.getRemoteInputSettings()->getIqCorrection() != 0;
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("fileRecordName")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_fileRecordName = *response.getRemoteInputSettings()->getFileRecordName();
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
2019-01-11 08:45:00 -05:00
|
|
|
if (deviceSettingsKeys.contains("useReverseAPI")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_useReverseAPI = response.getRemoteInputSettings()->getUseReverseApi() != 0;
|
2019-01-11 08:45:00 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIAddress")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_reverseAPIAddress = *response.getRemoteInputSettings()->getReverseApiAddress();
|
2019-01-11 08:45:00 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIPort")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_reverseAPIPort = response.getRemoteInputSettings()->getReverseApiPort();
|
2019-01-11 08:45:00 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
2019-02-02 18:49:57 -05:00
|
|
|
settings.m_reverseAPIDeviceIndex = response.getRemoteInputSettings()->getReverseApiDeviceIndex();
|
2019-01-11 08:45:00 -05:00
|
|
|
}
|
2018-05-27 05:07:24 -04:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgConfigureRemoteInput *msg = MsgConfigureRemoteInput::create(settings, force);
|
2018-05-27 05:07:24 -04:00
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
MsgConfigureRemoteInput *msgToGUI = MsgConfigureRemoteInput::create(settings, force);
|
2018-05-27 05:07:24 -04:00
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatDeviceSettings(response, settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const RemoteInputSettings& settings)
|
2018-05-27 05:07:24 -04:00
|
|
|
{
|
2019-02-02 18:49:57 -05:00
|
|
|
response.getRemoteInputSettings()->setApiAddress(new QString(settings.m_apiAddress));
|
|
|
|
response.getRemoteInputSettings()->setApiPort(settings.m_apiPort);
|
|
|
|
response.getRemoteInputSettings()->setDataAddress(new QString(settings.m_dataAddress));
|
|
|
|
response.getRemoteInputSettings()->setDataPort(settings.m_dataPort);
|
|
|
|
response.getRemoteInputSettings()->setDcBlock(settings.m_dcBlock ? 1 : 0);
|
|
|
|
response.getRemoteInputSettings()->setIqCorrection(settings.m_iqCorrection);
|
|
|
|
|
|
|
|
if (response.getRemoteInputSettings()->getFileRecordName()) {
|
|
|
|
*response.getRemoteInputSettings()->getFileRecordName() = settings.m_fileRecordName;
|
2018-05-27 05:07:24 -04:00
|
|
|
} else {
|
2019-02-02 18:49:57 -05:00
|
|
|
response.getRemoteInputSettings()->setFileRecordName(new QString(settings.m_fileRecordName));
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
2019-01-11 08:45:00 -05:00
|
|
|
|
2019-02-02 18:49:57 -05:00
|
|
|
response.getRemoteInputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
2019-01-11 08:45:00 -05:00
|
|
|
|
2019-02-02 18:49:57 -05:00
|
|
|
if (response.getRemoteInputSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getRemoteInputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
2019-01-11 08:45:00 -05:00
|
|
|
} else {
|
2019-02-02 18:49:57 -05:00
|
|
|
response.getRemoteInputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
2019-01-11 08:45:00 -05:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:49:57 -05:00
|
|
|
response.getRemoteInputSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getRemoteInputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
int RemoteInput::webapiReportGet(
|
2018-05-27 05:07:24 -04:00
|
|
|
SWGSDRangel::SWGDeviceReport& response,
|
2018-11-13 02:51:14 -05:00
|
|
|
QString& errorMessage)
|
2018-05-27 05:07:24 -04:00
|
|
|
{
|
2018-11-13 02:51:14 -05:00
|
|
|
(void) errorMessage;
|
2019-02-02 18:49:57 -05:00
|
|
|
response.setRemoteInputReport(new SWGSDRangel::SWGRemoteInputReport());
|
|
|
|
response.getRemoteInputReport()->init();
|
2018-05-27 05:07:24 -04:00
|
|
|
webapiFormatDeviceReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
|
2018-05-27 05:07:24 -04:00
|
|
|
{
|
2019-02-02 18:49:57 -05:00
|
|
|
response.getRemoteInputReport()->setCenterFrequency(m_remoteInputUDPHandler->getCenterFrequency());
|
|
|
|
response.getRemoteInputReport()->setSampleRate(m_remoteInputUDPHandler->getSampleRate());
|
|
|
|
response.getRemoteInputReport()->setBufferRwBalance(m_remoteInputUDPHandler->getBufferGauge());
|
2018-05-27 05:07:24 -04:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
QDateTime dt = QDateTime::fromMSecsSinceEpoch(m_remoteInputUDPHandler->getTVmSec());
|
2019-02-02 18:49:57 -05:00
|
|
|
response.getRemoteInputReport()->setRemoteTimestamp(new QString(dt.toString("yyyy-MM-dd HH:mm:ss.zzz")));
|
2018-05-27 05:07:24 -04:00
|
|
|
|
2019-02-02 18:49:57 -05:00
|
|
|
response.getRemoteInputReport()->setMinNbBlocks(m_remoteInputUDPHandler->getMinNbBlocks());
|
|
|
|
response.getRemoteInputReport()->setMaxNbRecovery(m_remoteInputUDPHandler->getMaxNbRecovery());
|
2018-05-27 05:07:24 -04:00
|
|
|
}
|
2018-12-26 11:08:21 -05:00
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const RemoteInputSettings& settings, bool force)
|
2018-12-26 11:08:21 -05:00
|
|
|
{
|
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
|
|
|
swgDeviceSettings->setTx(0);
|
2019-03-25 08:41:38 -04:00
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
2019-02-02 18:49:57 -05:00
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("RemoteInput"));
|
|
|
|
swgDeviceSettings->setRemoteInputSettings(new SWGSDRangel::SWGRemoteInputSettings());
|
|
|
|
SWGSDRangel::SWGRemoteInputSettings *swgRemoteInputSettings = swgDeviceSettings->getRemoteInputSettings();
|
2018-12-26 11:08:21 -05:00
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (deviceSettingsKeys.contains("apiAddress") || force) {
|
2019-02-02 18:49:57 -05:00
|
|
|
swgRemoteInputSettings->setApiAddress(new QString(settings.m_apiAddress));
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("apiPort") || force) {
|
2019-02-02 18:49:57 -05:00
|
|
|
swgRemoteInputSettings->setApiPort(settings.m_apiPort);
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("dataAddress") || force) {
|
2019-02-02 18:49:57 -05:00
|
|
|
swgRemoteInputSettings->setDataAddress(new QString(settings.m_dataAddress));
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("dataPort") || force) {
|
2019-02-02 18:49:57 -05:00
|
|
|
swgRemoteInputSettings->setDataPort(settings.m_dataPort);
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("dcBlock") || force) {
|
2019-02-02 18:49:57 -05:00
|
|
|
swgRemoteInputSettings->setDcBlock(settings.m_dcBlock ? 1 : 0);
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("iqCorrection") || force) {
|
2019-02-02 18:49:57 -05:00
|
|
|
swgRemoteInputSettings->setIqCorrection(settings.m_iqCorrection ? 1 : 0);
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|
|
|
|
if (deviceSettingsKeys.contains("fileRecordName") || force) {
|
2019-02-02 18:49:57 -05:00
|
|
|
swgRemoteInputSettings->setFileRecordName(new QString(settings.m_fileRecordName));
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString deviceSettingsURL = 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(deviceSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer=new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
|
|
|
|
delete swgDeviceSettings;
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::webapiReverseSendStartStop(bool start)
|
2018-12-26 11:08:21 -05:00
|
|
|
{
|
2019-03-25 10:21:17 -04:00
|
|
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
|
|
|
swgDeviceSettings->setTx(0);
|
|
|
|
swgDeviceSettings->setOriginatorIndex(m_deviceAPI->getDeviceSetIndex());
|
|
|
|
swgDeviceSettings->setDeviceHwType(new QString("RemoteInput"));
|
|
|
|
|
2018-12-26 11:08:21 -05:00
|
|
|
QString deviceSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/device/run")
|
|
|
|
.arg(m_settings.m_reverseAPIAddress)
|
|
|
|
.arg(m_settings.m_reverseAPIPort)
|
|
|
|
.arg(m_settings.m_reverseAPIDeviceIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(deviceSettingsURL));
|
2019-03-25 10:21:17 -04:00
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer=new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
2018-12-26 11:08:21 -05:00
|
|
|
|
|
|
|
if (start) {
|
2019-03-25 10:21:17 -04:00
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "POST", buffer);
|
2018-12-26 11:08:21 -05:00
|
|
|
} else {
|
2019-03-25 10:21:17 -04:00
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "DELETE", buffer);
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 18:26:26 -05:00
|
|
|
void RemoteInput::networkManagerFinished(QNetworkReply *reply)
|
2018-12-26 11:08:21 -05:00
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
2019-02-02 18:26:26 -05:00
|
|
|
qWarning() << "RemoteInput::networkManagerFinished:"
|
2018-12-26 11:08:21 -05:00
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
2019-02-02 18:49:57 -05:00
|
|
|
qDebug("RemoteInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
2018-12-26 11:08:21 -05:00
|
|
|
}
|