mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-23 00:18:37 -05:00
Reverse API: Test Source changes (1)
This commit is contained in:
parent
91ffa1cf3c
commit
35538ab9c1
@ -25,6 +25,8 @@
|
||||
#include "plugin/pluginapi.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 "util/db.h"
|
||||
@ -66,6 +68,9 @@ TestSourceGui::TestSourceGui(DeviceUISet *deviceUISet, QWidget* parent) :
|
||||
|
||||
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
|
||||
m_sampleSource->setMessageQueueToGUI(&m_inputMessageQueue);
|
||||
|
||||
CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
|
||||
connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
|
||||
}
|
||||
|
||||
TestSourceGui::~TestSourceGui()
|
||||
@ -512,4 +517,21 @@ void TestSourceGui::updateSampleRateAndFrequency()
|
||||
ui->deviceRateText->setText(tr("%1k").arg((float)m_deviceSampleRate / 1000));
|
||||
}
|
||||
|
||||
void TestSourceGui::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_qBias_valueChanged(int value);
|
||||
void on_phaseImbalance_valueChanged(int value);
|
||||
void on_record_toggled(bool checked);
|
||||
void openDeviceSettingsDialog(const QPoint& p);
|
||||
void updateStatus();
|
||||
void updateHardware();
|
||||
};
|
||||
|
@ -14,10 +14,14 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QDebug>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "SWGDeviceSettings.h"
|
||||
#include "SWGDeviceState.h"
|
||||
|
||||
@ -47,11 +51,20 @@ TestSourceInput::TestSourceInput(DeviceSourceAPI *deviceAPI) :
|
||||
if (!m_sampleFifo.setSize(96000 * 4)) {
|
||||
qCritical("TestSourceInput::TestSourceInput: Could not allocate SampleFifo");
|
||||
}
|
||||
|
||||
m_networkManager = new QNetworkAccessManager();
|
||||
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
||||
}
|
||||
|
||||
TestSourceInput::~TestSourceInput()
|
||||
{
|
||||
if (m_running) { stop(); }
|
||||
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
||||
delete m_networkManager;
|
||||
|
||||
if (m_running) {
|
||||
stop();
|
||||
}
|
||||
|
||||
m_deviceAPI->removeSink(m_fileSink);
|
||||
delete m_fileSink;
|
||||
}
|
||||
@ -210,6 +223,10 @@ bool TestSourceInput::handleMessage(const Message& message)
|
||||
m_deviceAPI->stopAcquisition();
|
||||
}
|
||||
|
||||
if (m_settings.m_useReverseAPI) {
|
||||
webapiReverseSendStartStop(cmd.getStartStop());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -220,6 +237,8 @@ bool TestSourceInput::handleMessage(const Message& message)
|
||||
|
||||
bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool force)
|
||||
{
|
||||
QList<QString> reverseAPIKeys;
|
||||
|
||||
if ((m_settings.m_autoCorrOptions != settings.m_autoCorrOptions) || force)
|
||||
{
|
||||
switch(settings.m_autoCorrOptions)
|
||||
@ -261,6 +280,8 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
|| (m_settings.m_sampleRate != settings.m_sampleRate)
|
||||
|| (m_settings.m_log2Decim != settings.m_log2Decim) || force)
|
||||
{
|
||||
reverseAPIKeys.append("centerFrequency");
|
||||
|
||||
qint64 deviceCenterFrequency = DeviceSampleSource::calculateDeviceCenterFrequency(
|
||||
settings.m_centerFrequency,
|
||||
0, // no transverter mode
|
||||
@ -382,6 +403,15 @@ bool TestSourceInput::applySettings(const TestSourceSettings& settings, bool for
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
@ -533,3 +563,110 @@ void TestSourceInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings&
|
||||
}
|
||||
}
|
||||
|
||||
void TestSourceInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const TestSourceSettings& settings, bool force)
|
||||
{
|
||||
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
||||
swgDeviceSettings->setTx(0);
|
||||
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);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("frequencyShift")) {
|
||||
swgTestSourceSettings->setFrequencyShift(settings.m_frequencyShift);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("sampleRate")) {
|
||||
swgTestSourceSettings->setSampleRate(settings.m_sampleRate);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("log2Decim")) {
|
||||
swgTestSourceSettings->setLog2Decim(settings.m_log2Decim);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("fcPos")) {
|
||||
swgTestSourceSettings->setFcPos((int) settings.m_fcPos);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("sampleSizeIndex")) {
|
||||
swgTestSourceSettings->setSampleSizeIndex(settings.m_sampleSizeIndex);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("amplitudeBits")) {
|
||||
swgTestSourceSettings->setAmplitudeBits(settings.m_amplitudeBits);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("autoCorrOptions")) {
|
||||
swgTestSourceSettings->setAutoCorrOptions((int) settings.m_sampleSizeIndex);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("modulation")) {
|
||||
swgTestSourceSettings->setModulation((int) settings.m_modulation);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("modulationTone")) {
|
||||
swgTestSourceSettings->setModulationTone(settings.m_modulationTone);
|
||||
}
|
||||
if (deviceSettingsKeys.contains("amModulation")) {
|
||||
swgTestSourceSettings->setAmModulation(settings.m_amModulation);
|
||||
};
|
||||
if (deviceSettingsKeys.contains("fmDeviation")) {
|
||||
swgTestSourceSettings->setFmDeviation(settings.m_fmDeviation);
|
||||
};
|
||||
if (deviceSettingsKeys.contains("dcFactor")) {
|
||||
swgTestSourceSettings->setDcFactor(settings.m_dcFactor);
|
||||
};
|
||||
if (deviceSettingsKeys.contains("iFactor")) {
|
||||
swgTestSourceSettings->setIFactor(settings.m_iFactor);
|
||||
};
|
||||
if (deviceSettingsKeys.contains("qFactor")) {
|
||||
swgTestSourceSettings->setQFactor(settings.m_qFactor);
|
||||
};
|
||||
if (deviceSettingsKeys.contains("phaseImbalance")) {
|
||||
swgTestSourceSettings->setPhaseImbalance(settings.m_phaseImbalance);
|
||||
};
|
||||
if (deviceSettingsKeys.contains("fileRecordName")) {
|
||||
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));
|
||||
|
||||
QBuffer *buffer=new QBuffer();
|
||||
buffer->open((QBuffer::ReadWrite));
|
||||
buffer->write(swgDeviceSettings->asJson().toUtf8());
|
||||
buffer->seek(0);
|
||||
|
||||
qDebug("TestSourceInput::webapiReverseSendSettings: %s", channelSettingsURL.toStdString().c_str());
|
||||
|
||||
// Always use PATCH to avoid passing reverse API settings
|
||||
m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
||||
|
||||
delete swgDeviceSettings;
|
||||
}
|
||||
|
||||
void TestSourceInput::webapiReverseSendStartStop(bool start)
|
||||
{
|
||||
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);
|
||||
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
||||
|
||||
if (start) {
|
||||
m_networkManager->sendCustomRequest(m_networkRequest, "POST");
|
||||
} else {
|
||||
m_networkManager->sendCustomRequest(m_networkRequest, "DELETE");
|
||||
}
|
||||
}
|
||||
|
||||
void TestSourceInput::networkManagerFinished(QNetworkReply *reply)
|
||||
{
|
||||
if (reply->error())
|
||||
{
|
||||
qDebug() << "TestSourceInput::networkManagerFinished: error: " << reply->errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QString answer = reply->readAll();
|
||||
qDebug("TestSourceInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QTimer>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include <dsp/devicesamplesource.h>
|
||||
#include "testsourcesettings.h"
|
||||
@ -27,6 +28,8 @@
|
||||
class DeviceSourceAPI;
|
||||
class TestSourceThread;
|
||||
class FileRecord;
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
|
||||
class TestSourceInput : public DeviceSampleSource {
|
||||
public:
|
||||
@ -138,9 +141,16 @@ private:
|
||||
QString m_deviceDescription;
|
||||
bool m_running;
|
||||
const QTimer& m_masterTimer;
|
||||
QNetworkAccessManager *m_networkManager;
|
||||
QNetworkRequest m_networkRequest;
|
||||
|
||||
bool applySettings(const TestSourceSettings& settings, bool force);
|
||||
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const TestSourceSettings& settings);
|
||||
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const TestSourceSettings& settings, bool force);
|
||||
void webapiReverseSendStartStop(bool start);
|
||||
|
||||
private slots:
|
||||
void networkManagerFinished(QNetworkReply *reply);
|
||||
};
|
||||
|
||||
#endif // _TESTSOURCE_TESTSOURCEINPUT_H_
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
const PluginDescriptor TestSourcePlugin::m_pluginDescriptor = {
|
||||
QString("Test Source input"),
|
||||
QString("4.2.4"),
|
||||
QString("4.3.2"),
|
||||
QString("(c) Edouard Griffiths, F4EXB"),
|
||||
QString("https://github.com/f4exb/sdrangel"),
|
||||
true,
|
||||
|
@ -42,6 +42,10 @@ void TestSourceSettings::resetToDefaults()
|
||||
m_qFactor = 0.0f;
|
||||
m_phaseImbalance = 0.0f;
|
||||
m_fileRecordName = "";
|
||||
m_useReverseAPI = false;
|
||||
m_reverseAPIAddress = "127.0.0.1";
|
||||
m_reverseAPIPort = 8888;
|
||||
m_reverseAPIDeviceIndex = 0;
|
||||
}
|
||||
|
||||
QByteArray TestSourceSettings::serialize() const
|
||||
@ -63,7 +67,10 @@ QByteArray TestSourceSettings::serialize() const
|
||||
s.writeS32(15, m_modulationTone);
|
||||
s.writeS32(16, m_amModulation);
|
||||
s.writeS32(17, m_fmDeviation);
|
||||
|
||||
s.writeBool(18, m_useReverseAPI);
|
||||
s.writeString(19, m_reverseAPIAddress);
|
||||
s.writeU32(20, m_reverseAPIPort);
|
||||
s.writeU32(21, m_reverseAPIDeviceIndex);
|
||||
return s.final();
|
||||
}
|
||||
|
||||
@ -80,6 +87,7 @@ bool TestSourceSettings::deserialize(const QByteArray& data)
|
||||
if (d.getVersion() == 1)
|
||||
{
|
||||
int intval;
|
||||
uint32_t utmp;
|
||||
|
||||
d.readS32(2, &m_frequencyShift, 0);
|
||||
d.readU32(3, &m_sampleRate, 768*1000);
|
||||
@ -112,6 +120,19 @@ bool TestSourceSettings::deserialize(const QByteArray& data)
|
||||
d.readS32(16, &m_amModulation, 50);
|
||||
d.readS32(17, &m_fmDeviation, 50);
|
||||
|
||||
d.readBool(18, &m_useReverseAPI, false);
|
||||
d.readString(19, &m_reverseAPIAddress, "127.0.0.1");
|
||||
d.readU32(20, &utmp, 0);
|
||||
|
||||
if ((utmp > 1023) && (utmp < 65535)) {
|
||||
m_reverseAPIPort = utmp;
|
||||
} else {
|
||||
m_reverseAPIPort = 8888;
|
||||
}
|
||||
|
||||
d.readU32(21, &utmp, 0);
|
||||
m_reverseAPIDeviceIndex = utmp > 99 ? 99 : utmp;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -60,6 +60,10 @@ struct TestSourceSettings {
|
||||
float m_qFactor; //!< -1.0 < x < 1.0
|
||||
float m_phaseImbalance; //!< -1.0 < x < 1.0
|
||||
QString m_fileRecordName;
|
||||
bool m_useReverseAPI;
|
||||
QString m_reverseAPIAddress;
|
||||
uint16_t m_reverseAPIPort;
|
||||
uint16_t m_reverseAPIDeviceIndex;
|
||||
|
||||
TestSourceSettings();
|
||||
void resetToDefaults();
|
||||
|
Loading…
Reference in New Issue
Block a user