mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-06 07:07:48 -04:00
Reverse API: File Source
This commit is contained in:
parent
a6a0079049
commit
b435449dc3
@ -26,6 +26,8 @@
|
|||||||
#include "plugin/pluginapi.h"
|
#include "plugin/pluginapi.h"
|
||||||
#include "gui/colormapper.h"
|
#include "gui/colormapper.h"
|
||||||
#include "gui/glspectrum.h"
|
#include "gui/glspectrum.h"
|
||||||
|
#include "gui/crightclickenabler.h"
|
||||||
|
#include "gui/basicdevicesettingsdialog.h"
|
||||||
#include "dsp/dspengine.h"
|
#include "dsp/dspengine.h"
|
||||||
#include "dsp/dspcommands.h"
|
#include "dsp/dspcommands.h"
|
||||||
|
|
||||||
@ -63,6 +65,9 @@ FileSourceGui::FileSourceGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
|||||||
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
||||||
m_statusTimer.start(500);
|
m_statusTimer.start(500);
|
||||||
|
|
||||||
|
CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
|
||||||
|
connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
|
||||||
|
|
||||||
setAccelerationCombo();
|
setAccelerationCombo();
|
||||||
displaySettings();
|
displaySettings();
|
||||||
|
|
||||||
@ -438,3 +443,22 @@ void FileSourceGui::setNumberStr(int n, QString& s)
|
|||||||
s = tr("%1G").arg(n/1000000000);
|
s = tr("%1G").arg(n/1000000000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileSourceGui::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();
|
||||||
|
}
|
||||||
|
@ -97,6 +97,7 @@ private slots:
|
|||||||
void on_acceleration_currentIndexChanged(int index);
|
void on_acceleration_currentIndexChanged(int index);
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
void tick();
|
void tick();
|
||||||
|
void openDeviceSettingsDialog(const QPoint& p);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDE_FILESOURCEGUI_H
|
#endif // INCLUDE_FILESOURCEGUI_H
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QBuffer>
|
||||||
|
|
||||||
#include "SWGDeviceSettings.h"
|
#include "SWGDeviceSettings.h"
|
||||||
#include "SWGFileSourceSettings.h"
|
#include "SWGFileSourceSettings.h"
|
||||||
@ -62,10 +64,15 @@ FileSourceInput::FileSourceInput(DeviceSourceAPI *deviceAPI) :
|
|||||||
qDebug("FileSourceInput::FileSourceInput: device source engine: %p", m_deviceAPI->getDeviceSourceEngine());
|
qDebug("FileSourceInput::FileSourceInput: device source engine: %p", m_deviceAPI->getDeviceSourceEngine());
|
||||||
qDebug("FileSourceInput::FileSourceInput: device source engine message queue: %p", m_deviceAPI->getDeviceEngineInputMessageQueue());
|
qDebug("FileSourceInput::FileSourceInput: device source engine message queue: %p", m_deviceAPI->getDeviceEngineInputMessageQueue());
|
||||||
qDebug("FileSourceInput::FileSourceInput: device source: %p", m_deviceAPI->getDeviceSourceEngine()->getSource());
|
qDebug("FileSourceInput::FileSourceInput: device source: %p", m_deviceAPI->getDeviceSourceEngine()->getSource());
|
||||||
|
m_networkManager = new QNetworkAccessManager();
|
||||||
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSourceInput::~FileSourceInput()
|
FileSourceInput::~FileSourceInput()
|
||||||
{
|
{
|
||||||
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
||||||
|
delete m_networkManager;
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,6 +356,10 @@ bool FileSourceInput::handleMessage(const Message& message)
|
|||||||
m_deviceAPI->stopAcquisition();
|
m_deviceAPI->stopAcquisition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_settings.m_useReverseAPI) {
|
||||||
|
webapiReverseSendStartStop(cmd.getStartStop());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (FileSourceThread::MsgReportEOF::match(message))
|
else if (FileSourceThread::MsgReportEOF::match(message))
|
||||||
@ -386,12 +397,16 @@ bool FileSourceInput::handleMessage(const Message& message)
|
|||||||
|
|
||||||
bool FileSourceInput::applySettings(const FileSourceSettings& settings, bool force)
|
bool FileSourceInput::applySettings(const FileSourceSettings& settings, bool force)
|
||||||
{
|
{
|
||||||
|
QList<QString> reverseAPIKeys;
|
||||||
|
|
||||||
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) {
|
if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) {
|
||||||
m_centerFrequency = settings.m_centerFrequency;
|
m_centerFrequency = settings.m_centerFrequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((m_settings.m_accelerationFactor != settings.m_accelerationFactor) || force)
|
if ((m_settings.m_accelerationFactor != settings.m_accelerationFactor) || force)
|
||||||
{
|
{
|
||||||
|
reverseAPIKeys.append("accelerationFactor");
|
||||||
|
|
||||||
if (m_fileSourceThread)
|
if (m_fileSourceThread)
|
||||||
{
|
{
|
||||||
QMutexLocker mutexLocker(&m_mutex);
|
QMutexLocker mutexLocker(&m_mutex);
|
||||||
@ -403,6 +418,22 @@ bool FileSourceInput::applySettings(const FileSourceSettings& settings, bool for
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((m_settings.m_loop != settings.m_loop)) {
|
||||||
|
reverseAPIKeys.append("loop");
|
||||||
|
}
|
||||||
|
if ((m_settings.m_fileName != settings.m_fileName)) {
|
||||||
|
reverseAPIKeys.append("fileName");
|
||||||
|
}
|
||||||
|
|
||||||
|
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_settings = settings;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -533,4 +564,73 @@ void FileSourceInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& res
|
|||||||
response.getFileSourceReport()->setSampleSize(m_sampleSize);
|
response.getFileSourceReport()->setSampleSize(m_sampleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileSourceInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const FileSourceSettings& settings, bool force)
|
||||||
|
{
|
||||||
|
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
||||||
|
swgDeviceSettings->setTx(0);
|
||||||
|
swgDeviceSettings->setDeviceHwType(new QString("FileSource"));
|
||||||
|
swgDeviceSettings->setFileSourceSettings(new SWGSDRangel::SWGFileSourceSettings());
|
||||||
|
SWGSDRangel::SWGFileSourceSettings *swgFileSourceSettings = swgDeviceSettings->getFileSourceSettings();
|
||||||
|
|
||||||
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
||||||
|
|
||||||
|
if (deviceSettingsKeys.contains("accelerationFactor") || force) {
|
||||||
|
swgFileSourceSettings->setAccelerationFactor(settings.m_accelerationFactor);
|
||||||
|
}
|
||||||
|
if (deviceSettingsKeys.contains("loop") || force) {
|
||||||
|
swgFileSourceSettings->setLoop(settings.m_loop);
|
||||||
|
}
|
||||||
|
if (deviceSettingsKeys.contains("fileName") || force) {
|
||||||
|
swgFileSourceSettings->setFileName(new QString(settings.m_fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 FileSourceInput::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 FileSourceInput::networkManagerFinished(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
QNetworkReply::NetworkError replyError = reply->error();
|
||||||
|
|
||||||
|
if (replyError)
|
||||||
|
{
|
||||||
|
qWarning() << "FileSourceInput::networkManagerFinished:"
|
||||||
|
<< " error(" << (int) replyError
|
||||||
|
<< "): " << replyError
|
||||||
|
<< ": " << reply->errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString answer = reply->readAll();
|
||||||
|
answer.chop(1); // remove last \n
|
||||||
|
qDebug("FileSourceInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
||||||
|
}
|
||||||
|
@ -17,20 +17,25 @@
|
|||||||
#ifndef INCLUDE_FILESOURCEINPUT_H
|
#ifndef INCLUDE_FILESOURCEINPUT_H
|
||||||
#define INCLUDE_FILESOURCEINPUT_H
|
#define INCLUDE_FILESOURCEINPUT_H
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <dsp/devicesamplesource.h>
|
#include <QString>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
|
||||||
|
#include "dsp/devicesamplesource.h"
|
||||||
#include "filesourcesettings.h"
|
#include "filesourcesettings.h"
|
||||||
|
|
||||||
|
class QNetworkAccessManager;
|
||||||
|
class QNetworkReply;
|
||||||
class FileSourceThread;
|
class FileSourceThread;
|
||||||
class DeviceSourceAPI;
|
class DeviceSourceAPI;
|
||||||
|
|
||||||
class FileSourceInput : public DeviceSampleSource {
|
class FileSourceInput : public DeviceSampleSource {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
class MsgConfigureFileSource : public Message {
|
class MsgConfigureFileSource : public Message {
|
||||||
MESSAGE_CLASS_DECLARATION
|
MESSAGE_CLASS_DECLARATION
|
||||||
@ -326,12 +331,19 @@ public:
|
|||||||
quint64 m_recordLength; //!< record length in seconds computed from file size
|
quint64 m_recordLength; //!< record length in seconds computed from file size
|
||||||
quint64 m_startingTimeStamp;
|
quint64 m_startingTimeStamp;
|
||||||
const QTimer& m_masterTimer;
|
const QTimer& m_masterTimer;
|
||||||
|
QNetworkAccessManager *m_networkManager;
|
||||||
|
QNetworkRequest m_networkRequest;
|
||||||
|
|
||||||
void openFileStream();
|
void openFileStream();
|
||||||
void seekFileStream(int seekMillis);
|
void seekFileStream(int seekMillis);
|
||||||
bool applySettings(const FileSourceSettings& settings, bool force = false);
|
bool applySettings(const FileSourceSettings& settings, bool force = false);
|
||||||
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const FileSourceSettings& settings);
|
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const FileSourceSettings& settings);
|
||||||
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
|
||||||
|
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const FileSourceSettings& settings, bool force);
|
||||||
|
void webapiReverseSendStartStop(bool start);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void networkManagerFinished(QNetworkReply *reply);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INCLUDE_FILESOURCEINPUT_H
|
#endif // INCLUDE_FILESOURCEINPUT_H
|
||||||
|
@ -32,6 +32,10 @@ void FileSourceSettings::resetToDefaults()
|
|||||||
m_fileName = "./test.sdriq";
|
m_fileName = "./test.sdriq";
|
||||||
m_accelerationFactor = 1;
|
m_accelerationFactor = 1;
|
||||||
m_loop = true;
|
m_loop = true;
|
||||||
|
m_useReverseAPI = false;
|
||||||
|
m_reverseAPIAddress = "127.0.0.1";
|
||||||
|
m_reverseAPIPort = 8888;
|
||||||
|
m_reverseAPIDeviceIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray FileSourceSettings::serialize() const
|
QByteArray FileSourceSettings::serialize() const
|
||||||
@ -40,6 +44,11 @@ QByteArray FileSourceSettings::serialize() const
|
|||||||
s.writeString(1, m_fileName);
|
s.writeString(1, m_fileName);
|
||||||
s.writeU32(2, m_accelerationFactor);
|
s.writeU32(2, m_accelerationFactor);
|
||||||
s.writeBool(3, m_loop);
|
s.writeBool(3, m_loop);
|
||||||
|
s.writeBool(4, m_useReverseAPI);
|
||||||
|
s.writeString(5, m_reverseAPIAddress);
|
||||||
|
s.writeU32(6, m_reverseAPIPort);
|
||||||
|
s.writeU32(7, m_reverseAPIDeviceIndex);
|
||||||
|
|
||||||
return s.final();
|
return s.final();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,12 +61,30 @@ bool FileSourceSettings::deserialize(const QByteArray& data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(d.getVersion() == 1) {
|
if (d.getVersion() == 1)
|
||||||
|
{
|
||||||
|
uint32_t uintval;
|
||||||
|
|
||||||
d.readString(1, &m_fileName, "./test.sdriq");
|
d.readString(1, &m_fileName, "./test.sdriq");
|
||||||
d.readU32(2, &m_accelerationFactor, 1);
|
d.readU32(2, &m_accelerationFactor, 1);
|
||||||
d.readBool(3, &m_loop, true);
|
d.readBool(3, &m_loop, true);
|
||||||
|
d.readBool(4, &m_useReverseAPI, false);
|
||||||
|
d.readString(5, &m_reverseAPIAddress, "127.0.0.1");
|
||||||
|
d.readU32(6, &uintval, 0);
|
||||||
|
|
||||||
|
if ((uintval > 1023) && (uintval < 65535)) {
|
||||||
|
m_reverseAPIPort = uintval;
|
||||||
|
} else {
|
||||||
|
m_reverseAPIPort = 8888;
|
||||||
|
}
|
||||||
|
|
||||||
|
d.readU32(7, &uintval, 0);
|
||||||
|
m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
resetToDefaults();
|
resetToDefaults();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,11 @@ struct FileSourceSettings {
|
|||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
quint32 m_accelerationFactor;
|
quint32 m_accelerationFactor;
|
||||||
bool m_loop;
|
bool m_loop;
|
||||||
|
bool m_useReverseAPI;
|
||||||
|
QString m_reverseAPIAddress;
|
||||||
|
uint16_t m_reverseAPIPort;
|
||||||
|
uint16_t m_reverseAPIDeviceIndex;
|
||||||
|
|
||||||
static const unsigned int m_accelerationMaxScale; //!< Max power of 10 multiplier to 2,5,10 base ex: 2 -> 2,5,10,20,50,100,200,500,1000
|
static const unsigned int m_accelerationMaxScale; //!< Max power of 10 multiplier to 2,5,10 base ex: 2 -> 2,5,10,20,50,100,200,500,1000
|
||||||
|
|
||||||
FileSourceSettings();
|
FileSourceSettings();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user