Reverse API: airspy HF changes

This commit is contained in:
f4exb 2018-12-25 11:01:18 +01:00
parent ea02e04f2d
commit 4a08ab33fe
9 changed files with 205 additions and 17 deletions

View File

@ -25,11 +25,11 @@
#include <dsp/devicesamplesource.h>
#include "airspysettings.h"
class QNetworkAccessManager;
class QNetworkReply;
class DeviceSourceAPI;
class AirspyThread;
class FileRecord;
class QNetworkAccessManager;
class QNetworkReply;
class AirspyInput : public DeviceSampleSource {
Q_OBJECT

View File

@ -32,7 +32,7 @@ const int AirspyPlugin::m_maxDevices = 32;
const PluginDescriptor AirspyPlugin::m_pluginDescriptor = {
QString("Airspy Input"),
QString("4.0.0"),
QString("4.3.2"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,

View File

@ -26,6 +26,8 @@
#include "ui_airspyhfgui.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 "airspyhfgui.h"
@ -50,6 +52,9 @@ AirspyHFGui::AirspyHFGui(DeviceUISet *deviceUISet, QWidget* parent) :
connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
m_statusTimer.start(500);
CRightClickEnabler *startStopRightClickEnabler = new CRightClickEnabler(ui->startStop);
connect(startStopRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(openDeviceSettingsDialog(const QPoint &)));
displaySettings();
m_rates = ((AirspyHFInput*) m_sampleSource)->getSampleRates();
@ -397,3 +402,22 @@ int AirspyHFGui::getDevSampleRateIndex(uint32_t sampeRate)
return -1;
}
void AirspyHFGui::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();
}

View File

@ -89,6 +89,7 @@ private slots:
void updateHardware();
void updateStatus();
void handleInputMessages();
void openDeviceSettingsDialog(const QPoint& p);
};
#endif // INCLUDE_AIRSPYHFGUI_H

View File

@ -16,7 +16,10 @@
#include <string.h>
#include <errno.h>
#include <QDebug>
#include <QNetworkReply>
#include <QBuffer>
#include "SWGDeviceSettings.h"
#include "SWGDeviceState.h"
@ -54,11 +57,19 @@ AirspyHFInput::AirspyHFInput(DeviceSourceAPI *deviceAPI) :
openDevice();
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*)));
}
AirspyHFInput::~AirspyHFInput()
{
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;
closeDevice();
@ -309,6 +320,10 @@ bool AirspyHFInput::handleMessage(const Message& message)
m_deviceAPI->stopAcquisition();
}
if (m_settings.m_useReverseAPI) {
webapiReverseSendStartStop(cmd.getStartStop());
}
return true;
}
else if (MsgFileRecord::match(message))
@ -363,16 +378,23 @@ void AirspyHFInput::setDeviceCenterFrequency(quint64 freq_hz, const AirspyHFSett
bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
{
QMutexLocker mutexLocker(&m_mutex);
qDebug() << "AirspyHFInput::applySettings";
QMutexLocker mutexLocker(&m_mutex);
bool forwardChange = false;
airspyhf_error rc;
int sampleRateIndex = settings.m_devSampleRateIndex;
QList<QString> reverseAPIKeys;
qDebug() << "AirspyHFInput::applySettings";
int sampleRateIndex = settings.m_devSampleRateIndex;
if ((m_settings.m_bandIndex != settings.m_bandIndex) || force) {
reverseAPIKeys.append("bandIndex");
}
if ((m_settings.m_devSampleRateIndex != settings.m_devSampleRateIndex) || force)
{
reverseAPIKeys.append("devSampleRateIndex");
forwardChange = true;
if (settings.m_devSampleRateIndex >= m_sampleRates.size()) {
@ -397,6 +419,7 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
{
reverseAPIKeys.append("log2Decim");
forwardChange = true;
if (m_airspyHFThread != 0)
@ -408,6 +431,8 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
if ((m_settings.m_LOppmTenths != settings.m_LOppmTenths) || force)
{
reverseAPIKeys.append("LOppmTenths");
if (m_dev != 0)
{
rc = (airspyhf_error) airspyhf_set_calibration(m_dev, settings.m_LOppmTenths * 100);
@ -423,6 +448,16 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
}
}
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency)) {
reverseAPIKeys.append("centerFrequency");
}
if (force || (m_settings.m_transverterMode != settings.m_transverterMode)) {
reverseAPIKeys.append("transverterMode");
}
if (force || (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency)) {
reverseAPIKeys.append("transverterDeltaFrequency");
}
if (force || (m_settings.m_centerFrequency != settings.m_centerFrequency)
|| (m_settings.m_transverterMode != settings.m_transverterMode)
|| (m_settings.m_transverterDeltaFrequency != settings.m_transverterDeltaFrequency))
@ -455,6 +490,15 @@ bool AirspyHFInput::applySettings(const AirspyHFSettings& settings, bool force)
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
}
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;
}
@ -523,7 +567,7 @@ int AirspyHFInput::webapiSettingsPutPatch(
settings.m_transverterMode = response.getAirspyHfSettings()->getTransverterMode() != 0;
}
if (deviceSettingsKeys.contains("bandIndex")) {
settings.m_bandIndex = response.getAirspyHfSettings()->getBandIndex() != 0;
settings.m_bandIndex = response.getAirspyHfSettings()->getBandIndex();
}
if (deviceSettingsKeys.contains("fileRecordName")) {
settings.m_fileRecordName = *response.getAirspyHfSettings()->getFileRecordName();
@ -609,3 +653,88 @@ int AirspyHFInput::webapiRun(
return 200;
}
void AirspyHFInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const AirspyHFSettings& settings, bool force)
{
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
swgDeviceSettings->setTx(0);
swgDeviceSettings->setDeviceHwType(new QString("AirspyHF"));
swgDeviceSettings->setAirspyHfSettings(new SWGSDRangel::SWGAirspyHFSettings());
SWGSDRangel::SWGAirspyHFSettings *swgAirspyHFSettings = swgDeviceSettings->getAirspyHfSettings();
// transfer data that has been modified. When force is on transfer all data except reverse API data
if (deviceSettingsKeys.contains("centerFrequency") || force) {
swgAirspyHFSettings->setCenterFrequency(settings.m_centerFrequency);
}
if (deviceSettingsKeys.contains("devSampleRateIndex") || force) {
swgAirspyHFSettings->setDevSampleRateIndex(settings.m_devSampleRateIndex);
}
if (deviceSettingsKeys.contains("LOppmTenths") || force) {
swgAirspyHFSettings->setLOppmTenths(settings.m_LOppmTenths);
}
if (deviceSettingsKeys.contains("log2Decim") || force) {
swgAirspyHFSettings->setLog2Decim(settings.m_log2Decim);
}
if (deviceSettingsKeys.contains("transverterDeltaFrequency") || force) {
swgAirspyHFSettings->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
}
if (deviceSettingsKeys.contains("transverterMode") || force) {
swgAirspyHFSettings->setTransverterMode(settings.m_transverterMode ? 1 : 0);
}
if (deviceSettingsKeys.contains("bandIndex") || force) {
swgAirspyHFSettings->setBandIndex(settings.m_bandIndex);
}
if (deviceSettingsKeys.contains("fileRecordName") || force) {
swgAirspyHFSettings->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 AirspyHFInput::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 AirspyHFInput::networkManagerFinished(QNetworkReply *reply)
{
QNetworkReply::NetworkError replyError = reply->error();
if (replyError)
{
qWarning() << "AirspyHFInput::networkManagerFinished:"
<< " error(" << (int) replyError
<< "): " << replyError
<< ": " << reply->errorString();
return;
}
QString answer = reply->readAll();
answer.chop(1); // remove last \n
qDebug("AirspyHFInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
}

View File

@ -19,17 +19,21 @@
#include <QString>
#include <QByteArray>
#include <QNetworkRequest>
#include <libairspyhf/airspyhf.h>
#include <dsp/devicesamplesource.h>
#include "airspyhfsettings.h"
class QNetworkAccessManager;
class QNetworkReply;
class DeviceSourceAPI;
class AirspyHFThread;
class FileRecord;
class AirspyHFInput : public DeviceSampleSource {
Q_OBJECT
public:
class MsgConfigureAirspyHF : public Message {
MESSAGE_CLASS_DECLARATION
@ -141,14 +145,6 @@ public:
static const qint64 loHighLimitFreqVHF;
private:
bool openDevice();
void closeDevice();
bool applySettings(const AirspyHFSettings& settings, bool force);
airspyhf_device_t *open_airspyhf_from_serial(const QString& serialStr);
void setDeviceCenterFrequency(quint64 freq, const AirspyHFSettings& settings);
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const AirspyHFSettings& settings);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
DeviceSourceAPI *m_deviceAPI;
QMutex m_mutex;
AirspyHFSettings m_settings;
@ -158,6 +154,21 @@ private:
std::vector<uint32_t> m_sampleRates;
bool m_running;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
bool openDevice();
void closeDevice();
bool applySettings(const AirspyHFSettings& settings, bool force);
airspyhf_device_t *open_airspyhf_from_serial(const QString& serialStr);
void setDeviceCenterFrequency(quint64 freq, const AirspyHFSettings& settings);
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const AirspyHFSettings& settings);
void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const AirspyHFSettings& settings, bool force);
void webapiReverseSendStartStop(bool start);
private slots:
void networkManagerFinished(QNetworkReply *reply);
};
#endif // INCLUDE_AIRSPYHFINPUT_H

View File

@ -30,7 +30,7 @@
const PluginDescriptor AirspyHFPlugin::m_pluginDescriptor = {
QString("AirspyHF Input"),
QString("4.0.0"),
QString("4.3.2"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,

View File

@ -34,6 +34,10 @@ void AirspyHFSettings::resetToDefaults()
m_transverterDeltaFrequency = 0;
m_bandIndex = 0;
m_fileRecordName = "";
m_useReverseAPI = false;
m_reverseAPIAddress = "127.0.0.1";
m_reverseAPIPort = 8888;
m_reverseAPIDeviceIndex = 0;
}
QByteArray AirspyHFSettings::serialize() const
@ -46,6 +50,10 @@ QByteArray AirspyHFSettings::serialize() const
s.writeBool(7, m_transverterMode);
s.writeS64(8, m_transverterDeltaFrequency);
s.writeU32(9, m_bandIndex);
s.writeBool(10, m_useReverseAPI);
s.writeString(11, m_reverseAPIAddress);
s.writeU32(12, m_reverseAPIPort);
s.writeU32(13, m_reverseAPIDeviceIndex);
return s.final();
}
@ -73,7 +81,18 @@ bool AirspyHFSettings::deserialize(const QByteArray& data)
d.readS64(8, &m_transverterDeltaFrequency, 0);
d.readU32(9, &uintval, 0);
m_bandIndex = uintval > 1 ? 1 : uintval;
d.readBool(10, &m_useReverseAPI, false);
d.readString(11, &m_reverseAPIAddress, "127.0.0.1");
d.readU32(12, &uintval, 0);
if ((uintval > 1023) && (uintval < 65535)) {
m_reverseAPIPort = uintval;
} else {
m_reverseAPIPort = 8888;
}
d.readU32(13, &uintval, 0);
m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
return true;
}
else

View File

@ -29,6 +29,10 @@ struct AirspyHFSettings
qint64 m_transverterDeltaFrequency;
quint32 m_bandIndex;
QString m_fileRecordName;
bool m_useReverseAPI;
QString m_reverseAPIAddress;
uint16_t m_reverseAPIPort;
uint16_t m_reverseAPIDeviceIndex;
AirspyHFSettings();
void resetToDefaults();