diff --git a/plugins/samplesource/xtrxinput/CMakeLists.txt b/plugins/samplesource/xtrxinput/CMakeLists.txt
index c7cbbdd45..29fd2c8f8 100644
--- a/plugins/samplesource/xtrxinput/CMakeLists.txt
+++ b/plugins/samplesource/xtrxinput/CMakeLists.txt
@@ -25,6 +25,7 @@ set(xtrxinput_FORMS
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${CMAKE_SOURCE_DIR}/devices
${LIBXTRX_INCLUDE_DIRS}
)
@@ -47,6 +48,7 @@ target_link_libraries(inputxtrx
${LIBXTRX_LIBRARIES}
sdrbase
sdrgui
+ swagger
xtrxdevice
)
diff --git a/plugins/samplesource/xtrxinput/xtrxinput.cpp b/plugins/samplesource/xtrxinput/xtrxinput.cpp
index 236d7aa5c..8f5ec79fd 100644
--- a/plugins/samplesource/xtrxinput/xtrxinput.cpp
+++ b/plugins/samplesource/xtrxinput/xtrxinput.cpp
@@ -14,13 +14,21 @@
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see . //
///////////////////////////////////////////////////////////////////////////////////
-
-#include
-#include
#include
#include
#include "xtrx_api.h"
+#include
+#include
+#include
+#include
+
+#include "SWGDeviceSettings.h"
+#include "SWGXtrxInputSettings.h"
+#include "SWGDeviceState.h"
+#include "SWGDeviceReport.h"
+#include "SWGXtrxInputReport.h"
+
#include "device/devicesourceapi.h"
#include "device/devicesinkapi.h"
#include "dsp/dspcommands.h"
@@ -49,10 +57,16 @@ XTRXInput::XTRXInput(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*)));
}
XTRXInput::~XTRXInput()
{
+ disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
+ delete m_networkManager;
+
if (m_running) {
stop();
}
@@ -627,8 +641,9 @@ bool XTRXInput::handleMessage(const Message& message)
{
uint64_t fifolevel = 0;
- xtrx_val_get(m_deviceShared.m_dev->getDevice(),
- XTRX_RX, XTRX_CH_AB, XTRX_PERF_LLFIFO, &fifolevel);
+ if (m_deviceShared.m_dev && m_deviceShared.m_dev->getDevice()) {
+ xtrx_val_get(m_deviceShared.m_dev->getDevice(), XTRX_RX, XTRX_CH_AB, XTRX_PERF_LLFIFO, &fifolevel);
+ }
MsgReportStreamInfo *report = MsgReportStreamInfo::create(
true,
@@ -797,6 +812,7 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
{
int requestedChannel = m_deviceAPI->getItemIndex();
XTRXInputThread *inputThread = findThread();
+ QList reverseAPIKeys;
bool forwardChangeOwnDSP = false;
bool forwardChangeRxDSP = false;
@@ -814,16 +830,22 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
// apply settings
- if ((m_settings.m_dcBlock != settings.m_dcBlock) || force) {
+ if ((m_settings.m_dcBlock != settings.m_dcBlock) || force)
+ {
+ reverseAPIKeys.append("dcBlock");
m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection);
}
- if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force) {
+ if ((m_settings.m_iqCorrection != settings.m_iqCorrection) || force)
+ {
+ reverseAPIKeys.append("iqCorrection");
m_deviceAPI->configureCorrections(settings.m_dcBlock, settings.m_iqCorrection);
}
if ((m_settings.m_pwrmode != settings.m_pwrmode))
{
+ reverseAPIKeys.append("pwrmode");
+
if (m_deviceShared.m_dev->getDevice() != 0)
{
if (xtrx_val_set(m_deviceShared.m_dev->getDevice(),
@@ -836,8 +858,15 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
}
}
- if ((m_settings.m_extClock != settings.m_extClock) ||
- (settings.m_extClock && (m_settings.m_extClockFreq != settings.m_extClockFreq)) || force)
+ if ((m_settings.m_extClock != settings.m_extClock) || force) {
+ reverseAPIKeys.append("extClock");
+ }
+ if ((m_settings.m_extClockFreq != settings.m_extClockFreq) || force) {
+ reverseAPIKeys.append("extClockFreq");
+ }
+
+ if ((m_settings.m_extClock != settings.m_extClock)
+ || (settings.m_extClock && (m_settings.m_extClockFreq != settings.m_extClockFreq)) || force)
{
if (m_deviceShared.m_dev->getDevice() != 0)
{
@@ -855,8 +884,15 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
}
}
+ if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || force) {
+ reverseAPIKeys.append("devSampleRate");
+ }
+ if ((m_settings.m_log2HardDecim != settings.m_log2HardDecim) || force) {
+ reverseAPIKeys.append("log2HardDecim");
+ }
+
if ((m_settings.m_devSampleRate != settings.m_devSampleRate)
- || (m_settings.m_log2HardDecim != settings.m_log2HardDecim) || force)
+ || (m_settings.m_log2HardDecim != settings.m_log2HardDecim) || force)
{
forwardChangeAllDSP = true; //m_settings.m_devSampleRate != settings.m_devSampleRate;
@@ -865,6 +901,22 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
}
}
+ if ((m_settings.m_gainMode != settings.m_gainMode) || force) {
+ reverseAPIKeys.append("gainMode");
+ }
+ if ((m_settings.m_gain != settings.m_gain) || force) {
+ reverseAPIKeys.append("gain");
+ }
+ if ((m_settings.m_lnaGain != settings.m_lnaGain) || force) {
+ reverseAPIKeys.append("lnaGain");
+ }
+ if ((m_settings.m_tiaGain != settings.m_tiaGain) || force) {
+ reverseAPIKeys.append("tiaGain");
+ }
+ if ((m_settings.m_pgaGain != settings.m_pgaGain) || force) {
+ reverseAPIKeys.append("pgaGain");
+ }
+
if (m_deviceShared.m_dev->getDevice() != 0)
{
if ((m_settings.m_gainMode != settings.m_gainMode) || force)
@@ -882,7 +934,9 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
}
else if (m_settings.m_gainMode == XTRXInputSettings::GAIN_AUTO)
{
- doGainAuto = true;
+ if (m_settings.m_gain != settings.m_gain) {
+ doGainAuto = true;
+ }
}
else if (m_settings.m_gainMode == XTRXInputSettings::GAIN_MANUAL)
{
@@ -900,6 +954,8 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
if ((m_settings.m_lpfBW != settings.m_lpfBW) || force)
{
+ reverseAPIKeys.append("lpfBW");
+
if (m_deviceShared.m_dev->getDevice() != 0) {
doLPCalibration = true;
}
@@ -934,6 +990,7 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
if ((m_settings.m_log2SoftDecim != settings.m_log2SoftDecim) || force)
{
+ reverseAPIKeys.append("log2SoftDecim");
forwardChangeOwnDSP = true;
if (inputThread != 0)
@@ -945,6 +1002,8 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
if ((m_settings.m_antennaPath != settings.m_antennaPath) || force)
{
+ reverseAPIKeys.append("antennaPath");
+
if (m_deviceShared.m_dev->getDevice() != 0)
{
if (xtrx_set_antenna(m_deviceShared.m_dev->getDevice(), settings.m_antennaPath) < 0) {
@@ -955,16 +1014,33 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
}
}
- if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) {
+ if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force)
+ {
+ reverseAPIKeys.append("centerFrequency");
doChangeFreq = true;
}
- if ((m_settings.m_ncoFrequency != settings.m_ncoFrequency) ||
- (m_settings.m_ncoEnable != settings.m_ncoEnable) || force)
+ if ((m_settings.m_ncoFrequency != settings.m_ncoFrequency) || force) {
+ reverseAPIKeys.append("ncoFrequency");
+ }
+ if ((m_settings.m_ncoEnable != settings.m_ncoEnable) || force) {
+ reverseAPIKeys.append("ncoEnable");
+ }
+
+ if ((m_settings.m_ncoFrequency != settings.m_ncoFrequency)
+ || (m_settings.m_ncoEnable != settings.m_ncoEnable) || force)
{
forceNCOFrequency = true;
}
+ 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;
@@ -1188,3 +1264,328 @@ bool XTRXInput::applySettings(const XTRXInputSettings& settings, bool force, boo
return true;
}
+
+int XTRXInput::webapiSettingsGet(
+ SWGSDRangel::SWGDeviceSettings& response,
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ response.setXtrxInputSettings(new SWGSDRangel::SWGXtrxInputSettings());
+ response.getXtrxInputSettings()->init();
+ webapiFormatDeviceSettings(response, m_settings);
+ return 200;
+}
+
+int XTRXInput::webapiSettingsPutPatch(
+ bool force,
+ const QStringList& deviceSettingsKeys,
+ SWGSDRangel::SWGDeviceSettings& response, // query + response
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ XTRXInputSettings settings = m_settings;
+
+ if (deviceSettingsKeys.contains("centerFrequency")) {
+ settings.m_centerFrequency = response.getXtrxInputSettings()->getCenterFrequency();
+ }
+ if (deviceSettingsKeys.contains("devSampleRate")) {
+ settings.m_devSampleRate = response.getXtrxInputSettings()->getDevSampleRate();
+ }
+ if (deviceSettingsKeys.contains("log2HardDecim")) {
+ settings.m_log2HardDecim = response.getXtrxInputSettings()->getLog2HardDecim();
+ }
+ if (deviceSettingsKeys.contains("dcBlock")) {
+ settings.m_dcBlock = response.getXtrxInputSettings()->getDcBlock() != 0;
+ }
+ if (deviceSettingsKeys.contains("iqCorrection")) {
+ settings.m_iqCorrection = response.getXtrxInputSettings()->getIqCorrection() != 0;
+ }
+ if (deviceSettingsKeys.contains("log2SoftDecim")) {
+ settings.m_log2SoftDecim = response.getXtrxInputSettings()->getLog2SoftDecim();
+ }
+ if (deviceSettingsKeys.contains("lpfBW")) {
+ settings.m_lpfBW = response.getXtrxInputSettings()->getLpfBw();
+ }
+ if (deviceSettingsKeys.contains("gain")) {
+ settings.m_gain = response.getXtrxInputSettings()->getGain();
+ }
+ if (deviceSettingsKeys.contains("ncoEnable")) {
+ settings.m_ncoEnable = response.getXtrxInputSettings()->getNcoEnable() != 0;
+ }
+ if (deviceSettingsKeys.contains("ncoFrequency")) {
+ settings.m_ncoFrequency = response.getXtrxInputSettings()->getNcoFrequency();
+ }
+ if (deviceSettingsKeys.contains("antennaPath")) {
+ settings.m_antennaPath = (xtrx_antenna_t) response.getXtrxInputSettings()->getAntennaPath();
+ }
+ if (deviceSettingsKeys.contains("gainMode")) {
+ settings.m_gainMode = (XTRXInputSettings::GainMode) response.getXtrxInputSettings()->getGainMode();
+ }
+ if (deviceSettingsKeys.contains("lnaGain")) {
+ settings.m_lnaGain = response.getXtrxInputSettings()->getLnaGain();
+ }
+ if (deviceSettingsKeys.contains("tiaGain")) {
+ settings.m_tiaGain = response.getXtrxInputSettings()->getTiaGain();
+ }
+ if (deviceSettingsKeys.contains("pgaGain")) {
+ settings.m_pgaGain = response.getXtrxInputSettings()->getPgaGain();
+ }
+ if (deviceSettingsKeys.contains("extClock")) {
+ settings.m_extClock = response.getXtrxInputSettings()->getExtClock() != 0;
+ }
+ if (deviceSettingsKeys.contains("extClockFreq")) {
+ settings.m_extClockFreq = response.getXtrxInputSettings()->getExtClockFreq();
+ }
+ if (deviceSettingsKeys.contains("pwrmode")) {
+ settings.m_pwrmode = response.getXtrxInputSettings()->getPwrmode();
+ }
+ if (deviceSettingsKeys.contains("fileRecordName")) {
+ settings.m_fileRecordName = *response.getXtrxInputSettings()->getFileRecordName();
+ }
+ if (deviceSettingsKeys.contains("useReverseAPI")) {
+ settings.m_useReverseAPI = response.getXtrxInputSettings()->getUseReverseApi() != 0;
+ }
+ if (deviceSettingsKeys.contains("reverseAPIAddress")) {
+ settings.m_reverseAPIAddress = *response.getXtrxInputSettings()->getReverseApiAddress() != 0;
+ }
+ if (deviceSettingsKeys.contains("reverseAPIPort")) {
+ settings.m_reverseAPIPort = response.getXtrxInputSettings()->getReverseApiPort();
+ }
+ if (deviceSettingsKeys.contains("reverseAPIDeviceIndex")) {
+ settings.m_reverseAPIDeviceIndex = response.getXtrxInputSettings()->getReverseApiDeviceIndex();
+ }
+
+ MsgConfigureXTRX *msg = MsgConfigureXTRX::create(settings, force);
+ m_inputMessageQueue.push(msg);
+
+ if (m_guiMessageQueue) // forward to GUI if any
+ {
+ MsgConfigureXTRX *msgToGUI = MsgConfigureXTRX::create(settings, force);
+ m_guiMessageQueue->push(msgToGUI);
+ }
+
+ webapiFormatDeviceSettings(response, settings);
+ return 200;
+}
+
+void XTRXInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const XTRXInputSettings& settings)
+{
+ response.getXtrxInputSettings()->setCenterFrequency(settings.m_centerFrequency);
+ response.getXtrxInputSettings()->setDevSampleRate(settings.m_devSampleRate);
+ response.getXtrxInputSettings()->setLog2HardDecim(settings.m_log2HardDecim);
+ response.getXtrxInputSettings()->setDcBlock(settings.m_dcBlock ? 1 : 0);
+ response.getXtrxInputSettings()->setIqCorrection(settings.m_iqCorrection ? 1 : 0);
+ response.getXtrxInputSettings()->setLog2SoftDecim(settings.m_log2SoftDecim);
+ response.getXtrxInputSettings()->setLpfBw(settings.m_lpfBW);
+ response.getXtrxInputSettings()->setGain(settings.m_gain);
+ response.getXtrxInputSettings()->setNcoEnable(settings.m_ncoEnable ? 1 : 0);
+ response.getXtrxInputSettings()->setNcoFrequency(settings.m_ncoFrequency);
+ response.getXtrxInputSettings()->setAntennaPath((int) settings.m_antennaPath);
+ response.getXtrxInputSettings()->setGainMode((int) settings.m_gainMode);
+ response.getXtrxInputSettings()->setLnaGain(settings.m_lnaGain);
+ response.getXtrxInputSettings()->setTiaGain(settings.m_tiaGain);
+ response.getXtrxInputSettings()->setPgaGain(settings.m_pgaGain);
+ response.getXtrxInputSettings()->setExtClock(settings.m_extClock ? 1 : 0);
+ response.getXtrxInputSettings()->setExtClockFreq(settings.m_extClockFreq);
+ response.getXtrxInputSettings()->setPwrmode(settings.m_pwrmode);
+
+ if (response.getXtrxInputSettings()->getFileRecordName()) {
+ *response.getXtrxInputSettings()->getFileRecordName() = settings.m_fileRecordName;
+ } else {
+ response.getXtrxInputSettings()->setFileRecordName(new QString(settings.m_fileRecordName));
+ }
+
+ response.getXtrxInputSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
+
+ if (response.getXtrxInputSettings()->getReverseApiAddress()) {
+ *response.getXtrxInputSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
+ } else {
+ response.getXtrxInputSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
+ }
+
+ response.getXtrxInputSettings()->setReverseApiPort(settings.m_reverseAPIPort);
+ response.getXtrxInputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
+}
+
+int XTRXInput::webapiReportGet(
+ SWGSDRangel::SWGDeviceReport& response,
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ response.setXtrxInputReport(new SWGSDRangel::SWGXtrxInputReport());
+ response.getXtrxInputReport()->init();
+ webapiFormatDeviceReport(response);
+ return 200;
+}
+
+int XTRXInput::webapiRunGet(
+ SWGSDRangel::SWGDeviceState& response,
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ m_deviceAPI->getDeviceEngineStateStr(*response.getState());
+ return 200;
+}
+
+int XTRXInput::webapiRun(
+ bool run,
+ SWGSDRangel::SWGDeviceState& response,
+ QString& errorMessage)
+{
+ (void) errorMessage;
+ m_deviceAPI->getDeviceEngineStateStr(*response.getState());
+ MsgStartStop *message = MsgStartStop::create(run);
+ m_inputMessageQueue.push(message);
+
+ if (m_guiMessageQueue) // forward to GUI if any
+ {
+ MsgStartStop *msgToGUI = MsgStartStop::create(run);
+ m_guiMessageQueue->push(msgToGUI);
+ }
+
+ return 200;
+}
+
+void XTRXInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
+{
+ int ret;
+ bool success = false;
+ double temp = 0.0;
+ bool gpsStatus = false;
+ uint64_t fifolevel = 0;
+ uint32_t fifosize = 1<<16;
+
+ if (m_deviceShared.m_dev && m_deviceShared.m_dev->getDevice())
+ {
+ ret = xtrx_val_get(m_deviceShared.m_dev->getDevice(),
+ XTRX_RX, XTRX_CH_AB, XTRX_PERF_LLFIFO, &fifolevel);
+ success = (ret >= 0);
+ temp = m_deviceShared.get_board_temperature() / 256.0;
+ gpsStatus = m_deviceShared.get_gps_status();
+ }
+
+ response.getXtrxInputReport()->setSuccess(success ? 1 : 0);
+ response.getXtrxInputReport()->setFifoSize(fifosize);
+ response.getXtrxInputReport()->setFifoFill(fifolevel);
+ response.getXtrxInputReport()->setTemperature(temp);
+ response.getXtrxInputReport()->setGpsLock(gpsStatus ? 1 : 0);
+}
+
+void XTRXInput::webapiReverseSendSettings(QList& deviceSettingsKeys, const XTRXInputSettings& settings, bool force)
+{
+ SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
+ swgDeviceSettings->setTx(0);
+ swgDeviceSettings->setDeviceHwType(new QString("XTRX"));
+ swgDeviceSettings->setXtrxInputSettings(new SWGSDRangel::SWGXtrxInputSettings());
+ SWGSDRangel::SWGXtrxInputSettings *swgXtrxInputSettings = swgDeviceSettings->getXtrxInputSettings();
+
+ // transfer data that has been modified. When force is on transfer all data except reverse API data
+
+ if (deviceSettingsKeys.contains("centerFrequency") || force) {
+ swgXtrxInputSettings->setCenterFrequency(settings.m_centerFrequency);
+ }
+ if (deviceSettingsKeys.contains("devSampleRate") || force) {
+ swgXtrxInputSettings->setDevSampleRate(settings.m_devSampleRate);
+ }
+ if (deviceSettingsKeys.contains("log2HardDecim") || force) {
+ swgXtrxInputSettings->setLog2HardDecim(settings.m_log2HardDecim);
+ }
+ if (deviceSettingsKeys.contains("dcBlock") || force) {
+ swgXtrxInputSettings->setDcBlock(settings.m_dcBlock ? 1 : 0);
+ }
+ if (deviceSettingsKeys.contains("iqCorrection") || force) {
+ swgXtrxInputSettings->setIqCorrection(settings.m_iqCorrection ? 1 : 0);
+ }
+ if (deviceSettingsKeys.contains("log2SoftDecim") || force) {
+ swgXtrxInputSettings->setLog2SoftDecim(settings.m_log2SoftDecim);
+ }
+ if (deviceSettingsKeys.contains("ncoEnable") || force) {
+ swgXtrxInputSettings->setNcoEnable(settings.m_ncoEnable ? 1 : 0);
+ }
+ if (deviceSettingsKeys.contains("ncoFrequency") || force) {
+ swgXtrxInputSettings->setNcoFrequency(settings.m_ncoFrequency);
+ }
+ if (deviceSettingsKeys.contains("lpfBW") || force) {
+ swgXtrxInputSettings->setLpfBw(settings.m_lpfBW);
+ }
+ if (deviceSettingsKeys.contains("antennaPath") || force) {
+ swgXtrxInputSettings->setAntennaPath((int) settings.m_antennaPath);
+ }
+ if (deviceSettingsKeys.contains("gainMode") || force) {
+ swgXtrxInputSettings->setGainMode((int) settings.m_gainMode);
+ }
+ if (deviceSettingsKeys.contains("gain") || force) {
+ swgXtrxInputSettings->setGain(settings.m_gain);
+ }
+ if (deviceSettingsKeys.contains("lnaGain") || force) {
+ swgXtrxInputSettings->setLnaGain(settings.m_lnaGain);
+ }
+ if (deviceSettingsKeys.contains("tiaGain") || force) {
+ swgXtrxInputSettings->setTiaGain(settings.m_tiaGain);
+ }
+ if (deviceSettingsKeys.contains("pgaGain") || force) {
+ swgXtrxInputSettings->setPgaGain(settings.m_pgaGain);
+ }
+ if (deviceSettingsKeys.contains("extClock") || force) {
+ swgXtrxInputSettings->setExtClock(settings.m_extClock ? 1 : 0);
+ }
+ if (deviceSettingsKeys.contains("extClockFreq") || force) {
+ swgXtrxInputSettings->setExtClockFreq(settings.m_extClockFreq);
+ }
+ if (deviceSettingsKeys.contains("pwrmode") || force) {
+ swgXtrxInputSettings->setPwrmode(settings.m_pwrmode);
+ }
+ if (deviceSettingsKeys.contains("fileRecordName") || force) {
+ swgXtrxInputSettings->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 XTRXInput::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 XTRXInput::networkManagerFinished(QNetworkReply *reply)
+{
+ QNetworkReply::NetworkError replyError = reply->error();
+
+ if (replyError)
+ {
+ qWarning() << "XTRXInput::networkManagerFinished:"
+ << " error(" << (int) replyError
+ << "): " << replyError
+ << ": " << reply->errorString();
+ return;
+ }
+
+ QString answer = reply->readAll();
+ answer.chop(1); // remove last \n
+ qDebug("XTRXInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
+}
diff --git a/plugins/samplesource/xtrxinput/xtrxinput.h b/plugins/samplesource/xtrxinput/xtrxinput.h
index 64d951695..3c98aa17f 100644
--- a/plugins/samplesource/xtrxinput/xtrxinput.h
+++ b/plugins/samplesource/xtrxinput/xtrxinput.h
@@ -17,14 +17,18 @@
#ifndef PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_
#define PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_
+#include
#include
-#include
+#include
+#include
#include "dsp/devicesamplesource.h"
#include "xtrx/devicextrxshared.h"
#include "xtrxinputsettings.h"
+class QNetworkAccessManager;
+class QNetworkReply;
class DeviceSourceAPI;
class XTRXInputThread;
struct DeviceXTRXParams;
@@ -32,6 +36,7 @@ class FileRecord;
class XTRXInput : public DeviceSampleSource
{
+ Q_OBJECT
public:
class MsgConfigureXTRX : public Message {
MESSAGE_CLASS_DECLARATION
@@ -190,6 +195,29 @@ public:
virtual bool handleMessage(const Message& message);
+ virtual int webapiSettingsGet(
+ SWGSDRangel::SWGDeviceSettings& response,
+ QString& errorMessage);
+
+ virtual int webapiSettingsPutPatch(
+ bool force,
+ const QStringList& deviceSettingsKeys,
+ SWGSDRangel::SWGDeviceSettings& response, // query + response
+ QString& errorMessage);
+
+ virtual int webapiReportGet(
+ SWGSDRangel::SWGDeviceReport& response,
+ QString& errorMessage);
+
+ virtual int webapiRunGet(
+ SWGSDRangel::SWGDeviceState& response,
+ QString& errorMessage);
+
+ virtual int webapiRun(
+ bool run,
+ SWGSDRangel::SWGDeviceState& response,
+ QString& errorMessage);
+
std::size_t getChannelIndex();
void getLORange(float& minF, float& maxF, float& stepF) const;
void getSRRange(float& minF, float& maxF, float& stepF) const;
@@ -208,6 +236,8 @@ private:
QString m_deviceDescription;
bool m_running;
DeviceXTRXShared m_deviceShared;
+ QNetworkAccessManager *m_networkManager;
+ QNetworkRequest m_networkRequest;
FileRecord *m_fileSink; //!< File sink to record device I/Q output
@@ -219,6 +249,13 @@ private:
void suspendTxThread();
void resumeTxThread();
bool applySettings(const XTRXInputSettings& settings, bool force = false, bool forceNCOFrequency = false);
+ void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const XTRXInputSettings& settings);
+ void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response);
+ void webapiReverseSendSettings(QList& deviceSettingsKeys, const XTRXInputSettings& settings, bool force);
+ void webapiReverseSendStartStop(bool start);
+
+private slots:
+ void networkManagerFinished(QNetworkReply *reply);
};
#endif /* PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUT_H_ */
diff --git a/plugins/samplesource/xtrxinput/xtrxinputgui.cpp b/plugins/samplesource/xtrxinput/xtrxinputgui.cpp
index 0a1f0babc..2f4f6c277 100644
--- a/plugins/samplesource/xtrxinput/xtrxinputgui.cpp
+++ b/plugins/samplesource/xtrxinput/xtrxinputgui.cpp
@@ -25,6 +25,8 @@
#include "ui_xtrxinputgui.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 "device/devicesourceapi.h"
@@ -71,6 +73,9 @@ XTRXInputGUI::XTRXInputGUI(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();
connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
@@ -578,3 +583,22 @@ void XTRXInputGUI::on_pwrmode_currentIndexChanged(int index)
m_settings.m_pwrmode = index;
sendSettings();
}
+
+void XTRXInputGUI::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();
+}
diff --git a/plugins/samplesource/xtrxinput/xtrxinputgui.h b/plugins/samplesource/xtrxinput/xtrxinputgui.h
index 2473169c3..d87f27a65 100644
--- a/plugins/samplesource/xtrxinput/xtrxinputgui.h
+++ b/plugins/samplesource/xtrxinput/xtrxinputgui.h
@@ -101,6 +101,7 @@ private slots:
void updateHardware();
void updateStatus();
+ void openDeviceSettingsDialog(const QPoint& p);
};
#endif /* PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTGUI_H_ */
diff --git a/plugins/samplesource/xtrxinput/xtrxinputsettings.cpp b/plugins/samplesource/xtrxinput/xtrxinputsettings.cpp
index 69bb0fc58..33cb46641 100644
--- a/plugins/samplesource/xtrxinput/xtrxinputsettings.cpp
+++ b/plugins/samplesource/xtrxinput/xtrxinputsettings.cpp
@@ -42,6 +42,11 @@ void XTRXInputSettings::resetToDefaults()
m_extClock = false;
m_extClockFreq = 0; // Auto
m_pwrmode = 1;
+ m_fileRecordName = "";
+ m_useReverseAPI = false;
+ m_reverseAPIAddress = "127.0.0.1";
+ m_reverseAPIPort = 8888;
+ m_reverseAPIDeviceIndex = 0;
}
QByteArray XTRXInputSettings::serialize() const
@@ -65,6 +70,11 @@ QByteArray XTRXInputSettings::serialize() const
s.writeBool(18, m_extClock);
s.writeU32(19, m_extClockFreq);
s.writeU32(20, m_pwrmode);
+ s.writeString(21, m_fileRecordName);
+ s.writeBool(22, m_useReverseAPI);
+ s.writeString(23, m_reverseAPIAddress);
+ s.writeU32(24, m_reverseAPIPort);
+ s.writeU32(25, m_reverseAPIDeviceIndex);
return s.final();
}
@@ -82,6 +92,7 @@ bool XTRXInputSettings::deserialize(const QByteArray& data)
if (d.getVersion() == 1)
{
int intval;
+ uint32_t uintval;
d.readDouble(1, &m_devSampleRate, 5e6);
d.readU32(2, &m_log2HardDecim, 2);
@@ -102,6 +113,19 @@ bool XTRXInputSettings::deserialize(const QByteArray& data)
d.readBool(18, &m_extClock, false);
d.readU32(19, &m_extClockFreq, 0);
d.readU32(20, &m_pwrmode, 2);
+ d.readString(21, &m_fileRecordName, "");
+ d.readBool(22, &m_useReverseAPI, false);
+ d.readString(23, &m_reverseAPIAddress, "127.0.0.1");
+ d.readU32(24, &uintval, 0);
+
+ if ((uintval > 1023) && (uintval < 65535)) {
+ m_reverseAPIPort = uintval;
+ } else {
+ m_reverseAPIPort = 8888;
+ }
+
+ d.readU32(25, &uintval, 0);
+ m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
return true;
}
diff --git a/plugins/samplesource/xtrxinput/xtrxinputsettings.h b/plugins/samplesource/xtrxinput/xtrxinputsettings.h
index 126f3a740..d31e653ba 100644
--- a/plugins/samplesource/xtrxinput/xtrxinputsettings.h
+++ b/plugins/samplesource/xtrxinput/xtrxinputsettings.h
@@ -18,7 +18,9 @@
#define PLUGINS_SAMPLESOURCE_XTRXINPUT_XTRXINPUTSETTINGS_H_
#include
+
#include
+#include
#include "xtrx_api.h"
@@ -41,18 +43,23 @@ struct XTRXInputSettings
bool m_dcBlock;
bool m_iqCorrection;
uint32_t m_log2SoftDecim;
- float m_lpfBW; //!< LMS amalog lowpass filter bandwidth (Hz)
+ float m_lpfBW; //!< LMS analog lowpass filter bandwidth (Hz)
uint32_t m_gain; //!< Optimally distributed gain (dB)
bool m_ncoEnable; //!< Enable TSP NCO and mixing
int m_ncoFrequency; //!< Actual NCO frequency (the resulting frequency with mixing is displayed)
xtrx_antenna_t m_antennaPath;
GainMode m_gainMode; //!< Gain mode: auto or manual
- uint32_t m_lnaGain; //!< Manual LAN gain
+ uint32_t m_lnaGain; //!< Manual LNA gain
uint32_t m_tiaGain; //!< Manual TIA gain
uint32_t m_pgaGain; //!< Manual PGA gain
bool m_extClock; //!< True if external clock source
uint32_t m_extClockFreq; //!< Frequency (Hz) of external clock source
uint32_t m_pwrmode;
+ QString m_fileRecordName;
+ bool m_useReverseAPI;
+ QString m_reverseAPIAddress;
+ uint16_t m_reverseAPIPort;
+ uint16_t m_reverseAPIDeviceIndex;
XTRXInputSettings();
void resetToDefaults();
diff --git a/pluginssrv/samplesource/xtrxinput/CMakeLists.txt b/pluginssrv/samplesource/xtrxinput/CMakeLists.txt
index 57ad4652b..4823f927a 100644
--- a/pluginssrv/samplesource/xtrxinput/CMakeLists.txt
+++ b/pluginssrv/samplesource/xtrxinput/CMakeLists.txt
@@ -20,6 +20,7 @@ set(xtrxinput_HEADERS
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
${CMAKE_SOURCE_DIR}/devices
${LIBXTRX_INCLUDE_DIRS}
)
@@ -38,6 +39,7 @@ target_link_libraries(inputxtrxsrv
${QT_LIBRARIES}
${LIBXTRX_LIBRARIES}
sdrbase
+ swagger
xtrxdevice
)
diff --git a/sdrbase/resources/res.qrc b/sdrbase/resources/res.qrc
index be9edc854..136e91aa5 100644
--- a/sdrbase/resources/res.qrc
+++ b/sdrbase/resources/res.qrc
@@ -36,6 +36,7 @@
webapi/doc/swagger/include/UDPSink.yaml
webapi/doc/swagger/include/WFMDemod.yaml
webapi/doc/swagger/include/WFMMod.yaml
+ webapi/doc/swagger/include/Xtrx.yaml
webapi/doc/swagger-ui/swagger-ui.js.map
webapi/doc/swagger-ui/swagger-ui.js
webapi/doc/swagger-ui/swagger-ui.css.map
diff --git a/sdrbase/resources/webapi/doc/html2/index.html b/sdrbase/resources/webapi/doc/html2/index.html
index 7e20021dd..158712913 100644
--- a/sdrbase/resources/webapi/doc/html2/index.html
+++ b/sdrbase/resources/webapi/doc/html2/index.html
@@ -2179,6 +2179,9 @@ margin-bottom: 20px;
},
"soapySDROutputReport" : {
"$ref" : "#/definitions/SoapySDRReport"
+ },
+ "xtrxInputReport" : {
+ "$ref" : "#/definitions/XtrxInputReport"
}
},
"description" : "Base device report. Only the device report corresponding to the device specified in the deviceHwType is or should be present."
@@ -2303,6 +2306,9 @@ margin-bottom: 20px;
},
"testSourceSettings" : {
"$ref" : "#/definitions/TestSourceSettings"
+ },
+ "xtrxInputSettings" : {
+ "$ref" : "#/definitions/XtrxInputSettings"
}
},
"description" : "Base device settings. Only the device settings corresponding to the device specified in the deviceHwType field is or should be present."
@@ -4845,6 +4851,123 @@ margin-bottom: 20px;
}
},
"description" : "WFMMod"
+};
+ defs.XtrxInputReport = {
+ "properties" : {
+ "success" : {
+ "type" : "integer",
+ "description" : "1 if info was successfully retrieved else 0"
+ },
+ "streamActive" : {
+ "type" : "integer",
+ "description" : "1 if active else 0"
+ },
+ "fifoSize" : {
+ "type" : "integer"
+ },
+ "fifoFill" : {
+ "type" : "integer"
+ },
+ "temperature" : {
+ "type" : "number",
+ "format" : "float"
+ },
+ "gpsLock" : {
+ "type" : "integer",
+ "description" : "1 if GPSDO is locked else 0"
+ }
+ },
+ "description" : "XTRX"
+};
+ defs.XtrxInputSettings = {
+ "properties" : {
+ "centerFrequency" : {
+ "type" : "integer",
+ "format" : "int64"
+ },
+ "devSampleRate" : {
+ "type" : "integer"
+ },
+ "log2HardDecim" : {
+ "type" : "integer"
+ },
+ "dcBlock" : {
+ "type" : "integer",
+ "description" : "Software DC blocking (1 for yes, 0 for no)"
+ },
+ "iqCorrection" : {
+ "type" : "integer",
+ "description" : "Software IQ imbalance correction (1 for yes, 0 for no)"
+ },
+ "log2SoftDecim" : {
+ "type" : "integer"
+ },
+ "lpfBW" : {
+ "type" : "integer",
+ "description" : "LMS analog lowpass filter bandwidth (Hz)"
+ },
+ "gain" : {
+ "type" : "integer",
+ "description" : "Optimally distributed gain (dB)"
+ },
+ "ncoEnable" : {
+ "type" : "integer",
+ "description" : "Enable TSP NCO and mixing (1 for yes, 0 for no)"
+ },
+ "ncoFrequency" : {
+ "type" : "integer",
+ "description" : "Frequency shift from LO"
+ },
+ "antennaPath" : {
+ "type" : "integer",
+ "description" : "Antenna selected (enum value from xtrx_antenna_t)"
+ },
+ "gainMode" : {
+ "type" : "integer",
+ "description" : "Gain mode auto or manual (enum value from GainMode)"
+ },
+ "lnaGain" : {
+ "type" : "integer",
+ "description" : "Manual LNA gain"
+ },
+ "tiaGain" : {
+ "type" : "integer",
+ "description" : "Manual TIA gain"
+ },
+ "pgaGain" : {
+ "type" : "integer",
+ "description" : "Manual PGA gain"
+ },
+ "extClock" : {
+ "type" : "integer",
+ "description" : "Use external clock source (1 for yes, 0 for no)"
+ },
+ "extClockFreq" : {
+ "type" : "integer",
+ "description" : "Frequency (Hz) of external clock source"
+ },
+ "pwrmode" : {
+ "type" : "integer",
+ "description" : "LMS power mode (0 save max to 7 perf max)"
+ },
+ "fileRecordName" : {
+ "type" : "string"
+ },
+ "useReverseAPI" : {
+ "type" : "integer",
+ "description" : "Synchronize with reverse API (1 for yes, 0 for no)"
+ },
+ "reverseAPIAddress" : {
+ "type" : "string"
+ },
+ "reverseAPIPort" : {
+ "type" : "integer"
+ },
+ "reverseAPIDeviceIndex" : {
+ "type" : "integer"
+ }
+ },
+ "description" : "XTRX"
};
@@ -5009,7 +5132,7 @@ margin-bottom: 20px;