mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-02-03 09:44:01 -05:00
Reverse API: SDRDaemon source
This commit is contained in:
parent
fc3f6d1711
commit
82fe8455cc
@ -32,6 +32,8 @@
|
||||
#include "ui_sdrdaemonsourcegui.h"
|
||||
#include "gui/colormapper.h"
|
||||
#include "gui/glspectrum.h"
|
||||
#include "gui/crightclickenabler.h"
|
||||
#include "gui/basicdevicesettingsdialog.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "mainwindow.h"
|
||||
@ -77,6 +79,9 @@ SDRdaemonSourceGui::SDRdaemonSourceGui(DeviceUISet *deviceUISet, QWidget* parent
|
||||
ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
|
||||
ui->centerFrequency->setValueRange(7, 0, 9999999U);
|
||||
|
||||
CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
|
||||
connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
|
||||
|
||||
displaySettings();
|
||||
|
||||
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
||||
@ -631,3 +636,22 @@ void SDRdaemonSourceGui::analyzeApiReply(const QJsonObject& jsonObject)
|
||||
ui->infoText->setText(infoLine);
|
||||
}
|
||||
}
|
||||
|
||||
void SDRdaemonSourceGui::openDeviceSettingsDialog(const QPoint& p)
|
||||
{
|
||||
BasicDeviceSettingsDialog dialog(this);
|
||||
dialog.setUseReverseAPI(m_settings.m_useReverseAPI);
|
||||
dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress);
|
||||
dialog.setReverseAPIPort(m_settings.m_reverseAPIPort);
|
||||
dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex);
|
||||
|
||||
dialog.move(p);
|
||||
dialog.exec();
|
||||
|
||||
m_settings.m_useReverseAPI = dialog.useReverseAPI();
|
||||
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
|
||||
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
|
||||
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
|
||||
|
||||
sendSettings();
|
||||
}
|
||||
|
@ -133,6 +133,7 @@ private slots:
|
||||
void updateHardware();
|
||||
void updateStatus();
|
||||
void networkManagerFinished(QNetworkReply *reply);
|
||||
void openDeviceSettingsDialog(const QPoint& p);
|
||||
};
|
||||
|
||||
#endif // INCLUDE_SDRDAEMONSOURCEGUI_H
|
||||
|
@ -16,7 +16,10 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QNetworkReply>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
@ -26,8 +29,8 @@
|
||||
#include "util/simpleserializer.h"
|
||||
#include "dsp/dspcommands.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include <device/devicesourceapi.h>
|
||||
#include <dsp/filerecord.h>
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "dsp/filerecord.h"
|
||||
|
||||
#include "sdrdaemonsourceinput.h"
|
||||
#include "sdrdaemonsourceudphandler.h"
|
||||
@ -52,10 +55,15 @@ SDRdaemonSourceInput::SDRdaemonSourceInput(DeviceSourceAPI *deviceAPI) :
|
||||
|
||||
m_fileSink = new FileRecord(QString("test_%1.sdriq").arg(m_deviceAPI->getDeviceUID()));
|
||||
m_deviceAPI->addSink(m_fileSink);
|
||||
|
||||
m_networkManager = new QNetworkAccessManager();
|
||||
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
||||
}
|
||||
|
||||
SDRdaemonSourceInput::~SDRdaemonSourceInput()
|
||||
{
|
||||
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
||||
delete m_networkManager;
|
||||
stop();
|
||||
m_deviceAPI->removeSink(m_fileSink);
|
||||
delete m_fileSink;
|
||||
@ -194,6 +202,10 @@ bool SDRdaemonSourceInput::handleMessage(const Message& message)
|
||||
m_deviceAPI->stopAcquisition();
|
||||
}
|
||||
|
||||
if (m_settings.m_useReverseAPI) {
|
||||
webapiReverseSendStartStop(cmd.getStartStop());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureSDRdaemonSource::match(message))
|
||||
@ -215,6 +227,29 @@ void SDRdaemonSourceInput::applySettings(const SDRdaemonSourceSettings& settings
|
||||
std::ostringstream os;
|
||||
QString remoteAddress;
|
||||
m_SDRdaemonUDPHandler->getRemoteAddress(remoteAddress);
|
||||
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");
|
||||
}
|
||||
|
||||
if ((m_settings.m_dcBlock != settings.m_dcBlock) || (m_settings.m_iqCorrection != settings.m_iqCorrection) || force)
|
||||
{
|
||||
@ -228,6 +263,16 @@ void SDRdaemonSourceInput::applySettings(const SDRdaemonSourceSettings& settings
|
||||
m_SDRdaemonUDPHandler->getRemoteAddress(remoteAddress);
|
||||
|
||||
mutexLocker.unlock();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
m_settings = settings;
|
||||
m_remoteAddress = remoteAddress;
|
||||
|
||||
@ -361,3 +406,86 @@ void SDRdaemonSourceInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport
|
||||
response.getSdrDaemonSourceReport()->setMinNbBlocks(m_SDRdaemonUDPHandler->getMinNbBlocks());
|
||||
response.getSdrDaemonSourceReport()->setMaxNbRecovery(m_SDRdaemonUDPHandler->getMaxNbRecovery());
|
||||
}
|
||||
|
||||
void SDRdaemonSourceInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const SDRdaemonSourceSettings& settings, bool force)
|
||||
{
|
||||
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
||||
swgDeviceSettings->setTx(0);
|
||||
swgDeviceSettings->setDeviceHwType(new QString("SDRdaemonSource"));
|
||||
swgDeviceSettings->setSdrDaemonSourceSettings(new SWGSDRangel::SWGSDRdaemonSourceSettings());
|
||||
SWGSDRangel::SWGSDRdaemonSourceSettings *swgSDRDaemonSourceSettings = swgDeviceSettings->getSdrDaemonSourceSettings();
|
||||
|
||||
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
||||
|
||||
if (deviceSettingsKeys.contains("apiAddress") || force) {
|
||||
swgSDRDaemonSourceSettings->setApiAddress(new QString(settings.m_apiAddress));
|
||||
}
|
||||
if (deviceSettingsKeys.contains("apiPort") || force) {
|
||||
swgSDRDaemonSourceSettings->setApiPort(settings.m_apiPort);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("dataAddress") || force) {
|
||||
swgSDRDaemonSourceSettings->setDataAddress(new QString(settings.m_dataAddress));
|
||||
}
|
||||
if (deviceSettingsKeys.contains("dataPort") || force) {
|
||||
swgSDRDaemonSourceSettings->setDataPort(settings.m_dataPort);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("dcBlock") || force) {
|
||||
swgSDRDaemonSourceSettings->setDcBlock(settings.m_dcBlock ? 1 : 0);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("iqCorrection") || force) {
|
||||
swgSDRDaemonSourceSettings->setIqCorrection(settings.m_iqCorrection ? 1 : 0);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("fileRecordName") || force) {
|
||||
swgSDRDaemonSourceSettings->setFileRecordName(new QString(settings.m_fileRecordName));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void SDRdaemonSourceInput::webapiReverseSendStartStop(bool start)
|
||||
{
|
||||
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));
|
||||
|
||||
if (start) {
|
||||
m_networkManager->sendCustomRequest(m_networkRequest, "POST");
|
||||
} else {
|
||||
m_networkManager->sendCustomRequest(m_networkRequest, "DELETE");
|
||||
}
|
||||
}
|
||||
|
||||
void SDRdaemonSourceInput::networkManagerFinished(QNetworkReply *reply)
|
||||
{
|
||||
QNetworkReply::NetworkError replyError = reply->error();
|
||||
|
||||
if (replyError)
|
||||
{
|
||||
qWarning() << "SDRdaemonSourceInput::networkManagerFinished:"
|
||||
<< " error(" << (int) replyError
|
||||
<< "): " << replyError
|
||||
<< ": " << reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QString answer = reply->readAll();
|
||||
answer.chop(1); // remove last \n
|
||||
qDebug("SDRdaemonSourceInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
||||
}
|
||||
|
@ -17,21 +17,26 @@
|
||||
#ifndef INCLUDE_SDRDAEMONSOURCEINPUT_H
|
||||
#define INCLUDE_SDRDAEMONSOURCEINPUT_H
|
||||
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QTimer>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QTimer>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include <dsp/devicesamplesource.h>
|
||||
#include "sdrdaemonsourcesettings.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class DeviceSourceAPI;
|
||||
class SDRdaemonSourceUDPHandler;
|
||||
class FileRecord;
|
||||
|
||||
class SDRdaemonSourceInput : public DeviceSampleSource {
|
||||
Q_OBJECT
|
||||
public:
|
||||
class MsgConfigureSDRdaemonSource : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
@ -314,10 +319,17 @@ private:
|
||||
QString m_deviceDescription;
|
||||
std::time_t m_startingTimeStamp;
|
||||
FileRecord *m_fileSink; //!< File sink to record device I/Q output
|
||||
QNetworkAccessManager *m_networkManager;
|
||||
QNetworkRequest m_networkRequest;
|
||||
|
||||
void applySettings(const SDRdaemonSourceSettings& settings, bool force = false);
|
||||
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SDRdaemonSourceSettings& settings);
|
||||
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
||||
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const SDRdaemonSourceSettings& settings, bool force);
|
||||
void webapiReverseSendStartStop(bool start);
|
||||
|
||||
private slots:
|
||||
void networkManagerFinished(QNetworkReply *reply);
|
||||
};
|
||||
|
||||
#endif // INCLUDE_SDRDAEMONSOURCEINPUT_H
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
const PluginDescriptor SDRdaemonSourcePlugin::m_pluginDescriptor = {
|
||||
QString("SDRdaemon source input"),
|
||||
QString("4.1.0"),
|
||||
QString("4.3.2"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -31,6 +31,10 @@ void SDRdaemonSourceSettings::resetToDefaults()
|
||||
m_dcBlock = false;
|
||||
m_iqCorrection = false;
|
||||
m_fileRecordName = "";
|
||||
m_useReverseAPI = false;
|
||||
m_reverseAPIAddress = "127.0.0.1";
|
||||
m_reverseAPIPort = 8888;
|
||||
m_reverseAPIDeviceIndex = 0;
|
||||
}
|
||||
|
||||
QByteArray SDRdaemonSourceSettings::serialize() const
|
||||
@ -43,6 +47,10 @@ QByteArray SDRdaemonSourceSettings::serialize() const
|
||||
s.writeString(8, m_dataAddress);
|
||||
s.writeBool(9, m_dcBlock);
|
||||
s.writeBool(10, m_iqCorrection);
|
||||
s.writeBool(11, m_useReverseAPI);
|
||||
s.writeString(12, m_reverseAPIAddress);
|
||||
s.writeU32(13, m_reverseAPIPort);
|
||||
s.writeU32(14, m_reverseAPIDeviceIndex);
|
||||
|
||||
return s.final();
|
||||
}
|
||||
@ -60,6 +68,7 @@ bool SDRdaemonSourceSettings::deserialize(const QByteArray& data)
|
||||
if (d.getVersion() == 1)
|
||||
{
|
||||
quint32 uintval;
|
||||
|
||||
d.readString(5, &m_apiAddress, "127.0.0.1");
|
||||
d.readU32(6, &uintval, 9090);
|
||||
m_apiPort = uintval % (1<<16);
|
||||
@ -68,6 +77,18 @@ bool SDRdaemonSourceSettings::deserialize(const QByteArray& data)
|
||||
d.readString(8, &m_dataAddress, "127.0.0.1");
|
||||
d.readBool(9, &m_dcBlock, false);
|
||||
d.readBool(10, &m_iqCorrection, false);
|
||||
d.readBool(11, &m_useReverseAPI, false);
|
||||
d.readString(12, &m_reverseAPIAddress, "127.0.0.1");
|
||||
d.readU32(13, &uintval, 0);
|
||||
|
||||
if ((uintval > 1023) && (uintval < 65535)) {
|
||||
m_reverseAPIPort = uintval;
|
||||
} else {
|
||||
m_reverseAPIPort = 8888;
|
||||
}
|
||||
|
||||
d.readU32(14, &uintval, 0);
|
||||
m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -28,6 +28,10 @@ struct SDRdaemonSourceSettings {
|
||||
bool m_dcBlock;
|
||||
bool m_iqCorrection;
|
||||
QString m_fileRecordName;
|
||||
bool m_useReverseAPI;
|
||||
QString m_reverseAPIAddress;
|
||||
uint16_t m_reverseAPIPort;
|
||||
uint16_t m_reverseAPIDeviceIndex;
|
||||
|
||||
SDRdaemonSourceSettings();
|
||||
void resetToDefaults();
|
||||
|
Loading…
Reference in New Issue
Block a user