From 3374892c61a0e823ae89daea8f3c100f6bda9b8b Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 1 Jan 2019 18:28:53 +0100 Subject: [PATCH] XTRX input: implemented REST API interfaces --- plugins/samplesource/xtrxinput/CMakeLists.txt | 2 + plugins/samplesource/xtrxinput/xtrxinput.cpp | 429 ++++++++++++- plugins/samplesource/xtrxinput/xtrxinput.h | 39 +- .../samplesource/xtrxinput/xtrxinputgui.cpp | 24 + plugins/samplesource/xtrxinput/xtrxinputgui.h | 1 + .../xtrxinput/xtrxinputsettings.cpp | 24 + .../xtrxinput/xtrxinputsettings.h | 11 +- .../samplesource/xtrxinput/CMakeLists.txt | 2 + sdrbase/resources/res.qrc | 1 + sdrbase/resources/webapi/doc/html2/index.html | 127 +++- .../webapi/doc/swagger/include/Xtrx.yaml | 85 +++ .../resources/webapi/doc/swagger/swagger.yaml | 6 +- sdrbase/webapi/webapirequestmapper.cpp | 61 +- .../sdrangel/api/swagger/include/Xtrx.yaml | 82 +++ swagger/sdrangel/api/swagger/swagger.yaml | 6 +- swagger/sdrangel/code/html2/index.html | 127 +++- .../code/qt5/client/SWGAMDemodReport.cpp | 2 +- .../code/qt5/client/SWGAMDemodReport.h | 2 +- .../code/qt5/client/SWGAMDemodSettings.cpp | 2 +- .../code/qt5/client/SWGAMDemodSettings.h | 2 +- .../code/qt5/client/SWGAMModReport.cpp | 2 +- .../sdrangel/code/qt5/client/SWGAMModReport.h | 2 +- .../code/qt5/client/SWGAMModSettings.cpp | 2 +- .../code/qt5/client/SWGAMModSettings.h | 2 +- .../code/qt5/client/SWGATVModReport.cpp | 2 +- .../code/qt5/client/SWGATVModReport.h | 2 +- .../code/qt5/client/SWGATVModSettings.cpp | 2 +- .../code/qt5/client/SWGATVModSettings.h | 2 +- .../code/qt5/client/SWGAirspyHFReport.cpp | 2 +- .../code/qt5/client/SWGAirspyHFReport.h | 2 +- .../code/qt5/client/SWGAirspyHFSettings.cpp | 2 +- .../code/qt5/client/SWGAirspyHFSettings.h | 2 +- .../code/qt5/client/SWGAirspyReport.cpp | 2 +- .../code/qt5/client/SWGAirspyReport.h | 2 +- .../code/qt5/client/SWGAirspySettings.cpp | 2 +- .../code/qt5/client/SWGAirspySettings.h | 2 +- .../sdrangel/code/qt5/client/SWGArgInfo.cpp | 2 +- swagger/sdrangel/code/qt5/client/SWGArgInfo.h | 2 +- .../sdrangel/code/qt5/client/SWGArgValue.cpp | 2 +- .../sdrangel/code/qt5/client/SWGArgValue.h | 2 +- .../code/qt5/client/SWGAudioDevices.cpp | 2 +- .../code/qt5/client/SWGAudioDevices.h | 2 +- .../code/qt5/client/SWGAudioInputDevice.cpp | 2 +- .../code/qt5/client/SWGAudioInputDevice.h | 2 +- .../code/qt5/client/SWGAudioOutputDevice.cpp | 2 +- .../code/qt5/client/SWGAudioOutputDevice.h | 2 +- .../code/qt5/client/SWGBFMDemodReport.cpp | 2 +- .../code/qt5/client/SWGBFMDemodReport.h | 2 +- .../code/qt5/client/SWGBFMDemodSettings.cpp | 2 +- .../code/qt5/client/SWGBFMDemodSettings.h | 2 +- .../sdrangel/code/qt5/client/SWGBandwidth.cpp | 2 +- .../sdrangel/code/qt5/client/SWGBandwidth.h | 2 +- .../qt5/client/SWGBladeRF1InputSettings.cpp | 2 +- .../qt5/client/SWGBladeRF1InputSettings.h | 2 +- .../qt5/client/SWGBladeRF1OutputSettings.cpp | 2 +- .../qt5/client/SWGBladeRF1OutputSettings.h | 2 +- .../qt5/client/SWGBladeRF2InputReport.cpp | 2 +- .../code/qt5/client/SWGBladeRF2InputReport.h | 2 +- .../qt5/client/SWGBladeRF2InputSettings.cpp | 2 +- .../qt5/client/SWGBladeRF2InputSettings.h | 2 +- .../qt5/client/SWGBladeRF2OutputReport.cpp | 2 +- .../code/qt5/client/SWGBladeRF2OutputReport.h | 2 +- .../qt5/client/SWGBladeRF2OutputSettings.cpp | 2 +- .../qt5/client/SWGBladeRF2OutputSettings.h | 2 +- .../code/qt5/client/SWGCWKeyerSettings.cpp | 2 +- .../code/qt5/client/SWGCWKeyerSettings.h | 2 +- .../sdrangel/code/qt5/client/SWGChannel.cpp | 2 +- swagger/sdrangel/code/qt5/client/SWGChannel.h | 2 +- .../code/qt5/client/SWGChannelListItem.cpp | 2 +- .../code/qt5/client/SWGChannelListItem.h | 2 +- .../code/qt5/client/SWGChannelReport.cpp | 2 +- .../code/qt5/client/SWGChannelReport.h | 2 +- .../code/qt5/client/SWGChannelSettings.cpp | 2 +- .../code/qt5/client/SWGChannelSettings.h | 2 +- .../code/qt5/client/SWGChannelsDetail.cpp | 2 +- .../code/qt5/client/SWGChannelsDetail.h | 2 +- .../sdrangel/code/qt5/client/SWGComplex.cpp | 2 +- swagger/sdrangel/code/qt5/client/SWGComplex.h | 2 +- .../code/qt5/client/SWGDSDDemodReport.cpp | 2 +- .../code/qt5/client/SWGDSDDemodReport.h | 2 +- .../code/qt5/client/SWGDSDDemodSettings.cpp | 2 +- .../code/qt5/client/SWGDSDDemodSettings.h | 2 +- .../code/qt5/client/SWGDVSeralDevices.cpp | 2 +- .../code/qt5/client/SWGDVSeralDevices.h | 2 +- .../code/qt5/client/SWGDVSerialDevice.cpp | 2 +- .../code/qt5/client/SWGDVSerialDevice.h | 2 +- .../code/qt5/client/SWGDaemonSinkSettings.cpp | 2 +- .../code/qt5/client/SWGDaemonSinkSettings.h | 2 +- .../code/qt5/client/SWGDaemonSourceReport.cpp | 2 +- .../code/qt5/client/SWGDaemonSourceReport.h | 2 +- .../qt5/client/SWGDaemonSourceSettings.cpp | 2 +- .../code/qt5/client/SWGDaemonSourceSettings.h | 2 +- .../code/qt5/client/SWGDeviceListItem.cpp | 2 +- .../code/qt5/client/SWGDeviceListItem.h | 2 +- .../code/qt5/client/SWGDeviceReport.cpp | 25 +- .../code/qt5/client/SWGDeviceReport.h | 9 +- .../sdrangel/code/qt5/client/SWGDeviceSet.cpp | 2 +- .../sdrangel/code/qt5/client/SWGDeviceSet.h | 2 +- .../code/qt5/client/SWGDeviceSetApi.cpp | 2 +- .../code/qt5/client/SWGDeviceSetApi.h | 2 +- .../code/qt5/client/SWGDeviceSetList.cpp | 2 +- .../code/qt5/client/SWGDeviceSetList.h | 2 +- .../code/qt5/client/SWGDeviceSettings.cpp | 25 +- .../code/qt5/client/SWGDeviceSettings.h | 9 +- .../code/qt5/client/SWGDeviceState.cpp | 2 +- .../sdrangel/code/qt5/client/SWGDeviceState.h | 2 +- .../code/qt5/client/SWGErrorResponse.cpp | 2 +- .../code/qt5/client/SWGErrorResponse.h | 2 +- .../code/qt5/client/SWGFCDProPlusSettings.cpp | 2 +- .../code/qt5/client/SWGFCDProPlusSettings.h | 2 +- .../code/qt5/client/SWGFCDProSettings.cpp | 2 +- .../code/qt5/client/SWGFCDProSettings.h | 2 +- .../code/qt5/client/SWGFileSourceReport.cpp | 2 +- .../code/qt5/client/SWGFileSourceReport.h | 2 +- .../code/qt5/client/SWGFileSourceSettings.cpp | 2 +- .../code/qt5/client/SWGFileSourceSettings.h | 2 +- .../sdrangel/code/qt5/client/SWGFrequency.cpp | 2 +- .../sdrangel/code/qt5/client/SWGFrequency.h | 2 +- .../code/qt5/client/SWGFrequencyBand.cpp | 2 +- .../code/qt5/client/SWGFrequencyBand.h | 2 +- .../code/qt5/client/SWGFrequencyRange.cpp | 2 +- .../code/qt5/client/SWGFrequencyRange.h | 2 +- swagger/sdrangel/code/qt5/client/SWGGain.cpp | 2 +- swagger/sdrangel/code/qt5/client/SWGGain.h | 2 +- .../qt5/client/SWGHackRFInputSettings.cpp | 2 +- .../code/qt5/client/SWGHackRFInputSettings.h | 2 +- .../qt5/client/SWGHackRFOutputSettings.cpp | 2 +- .../code/qt5/client/SWGHackRFOutputSettings.h | 2 +- .../sdrangel/code/qt5/client/SWGHelpers.cpp | 2 +- swagger/sdrangel/code/qt5/client/SWGHelpers.h | 2 +- .../code/qt5/client/SWGHttpRequest.cpp | 2 +- .../sdrangel/code/qt5/client/SWGHttpRequest.h | 2 +- .../code/qt5/client/SWGInstanceApi.cpp | 2 +- .../sdrangel/code/qt5/client/SWGInstanceApi.h | 2 +- .../client/SWGInstanceChannelsResponse.cpp | 2 +- .../qt5/client/SWGInstanceChannelsResponse.h | 2 +- .../qt5/client/SWGInstanceDevicesResponse.cpp | 2 +- .../qt5/client/SWGInstanceDevicesResponse.h | 2 +- .../qt5/client/SWGInstanceSummaryResponse.cpp | 2 +- .../qt5/client/SWGInstanceSummaryResponse.h | 2 +- .../code/qt5/client/SWGLimeSdrInputReport.cpp | 2 +- .../code/qt5/client/SWGLimeSdrInputReport.h | 2 +- .../qt5/client/SWGLimeSdrInputSettings.cpp | 2 +- .../code/qt5/client/SWGLimeSdrInputSettings.h | 2 +- .../qt5/client/SWGLimeSdrOutputReport.cpp | 2 +- .../code/qt5/client/SWGLimeSdrOutputReport.h | 2 +- .../qt5/client/SWGLimeSdrOutputSettings.cpp | 2 +- .../qt5/client/SWGLimeSdrOutputSettings.h | 2 +- .../qt5/client/SWGLocationInformation.cpp | 2 +- .../code/qt5/client/SWGLocationInformation.h | 2 +- .../code/qt5/client/SWGLoggingInfo.cpp | 2 +- .../sdrangel/code/qt5/client/SWGLoggingInfo.h | 2 +- .../code/qt5/client/SWGModelFactory.h | 10 +- .../code/qt5/client/SWGNFMDemodReport.cpp | 2 +- .../code/qt5/client/SWGNFMDemodReport.h | 2 +- .../code/qt5/client/SWGNFMDemodSettings.cpp | 2 +- .../code/qt5/client/SWGNFMDemodSettings.h | 2 +- .../code/qt5/client/SWGNFMModReport.cpp | 2 +- .../code/qt5/client/SWGNFMModReport.h | 2 +- .../code/qt5/client/SWGNFMModSettings.cpp | 2 +- .../code/qt5/client/SWGNFMModSettings.h | 2 +- .../sdrangel/code/qt5/client/SWGNamedEnum.cpp | 2 +- .../sdrangel/code/qt5/client/SWGNamedEnum.h | 2 +- swagger/sdrangel/code/qt5/client/SWGObject.h | 2 +- .../code/qt5/client/SWGPerseusReport.cpp | 2 +- .../code/qt5/client/SWGPerseusReport.h | 2 +- .../code/qt5/client/SWGPerseusSettings.cpp | 2 +- .../code/qt5/client/SWGPerseusSettings.h | 2 +- .../qt5/client/SWGPlutoSdrInputReport.cpp | 2 +- .../code/qt5/client/SWGPlutoSdrInputReport.h | 2 +- .../qt5/client/SWGPlutoSdrInputSettings.cpp | 2 +- .../qt5/client/SWGPlutoSdrInputSettings.h | 2 +- .../qt5/client/SWGPlutoSdrOutputReport.cpp | 2 +- .../code/qt5/client/SWGPlutoSdrOutputReport.h | 2 +- .../qt5/client/SWGPlutoSdrOutputSettings.cpp | 2 +- .../qt5/client/SWGPlutoSdrOutputSettings.h | 2 +- .../code/qt5/client/SWGPresetExport.cpp | 2 +- .../code/qt5/client/SWGPresetExport.h | 2 +- .../code/qt5/client/SWGPresetGroup.cpp | 2 +- .../sdrangel/code/qt5/client/SWGPresetGroup.h | 2 +- .../code/qt5/client/SWGPresetIdentifier.cpp | 2 +- .../code/qt5/client/SWGPresetIdentifier.h | 2 +- .../code/qt5/client/SWGPresetImport.cpp | 2 +- .../code/qt5/client/SWGPresetImport.h | 2 +- .../code/qt5/client/SWGPresetItem.cpp | 2 +- .../sdrangel/code/qt5/client/SWGPresetItem.h | 2 +- .../code/qt5/client/SWGPresetTransfer.cpp | 2 +- .../code/qt5/client/SWGPresetTransfer.h | 2 +- .../sdrangel/code/qt5/client/SWGPresets.cpp | 2 +- swagger/sdrangel/code/qt5/client/SWGPresets.h | 2 +- .../sdrangel/code/qt5/client/SWGRDSReport.cpp | 2 +- .../sdrangel/code/qt5/client/SWGRDSReport.h | 2 +- .../client/SWGRDSReport_altFrequencies.cpp | 2 +- .../qt5/client/SWGRDSReport_altFrequencies.h | 2 +- swagger/sdrangel/code/qt5/client/SWGRange.cpp | 2 +- swagger/sdrangel/code/qt5/client/SWGRange.h | 2 +- .../code/qt5/client/SWGRangeFloat.cpp | 2 +- .../sdrangel/code/qt5/client/SWGRangeFloat.h | 2 +- .../code/qt5/client/SWGRtlSdrReport.cpp | 2 +- .../code/qt5/client/SWGRtlSdrReport.h | 2 +- .../code/qt5/client/SWGRtlSdrSettings.cpp | 2 +- .../code/qt5/client/SWGRtlSdrSettings.h | 2 +- .../code/qt5/client/SWGSDRPlayReport.cpp | 2 +- .../code/qt5/client/SWGSDRPlayReport.h | 2 +- .../code/qt5/client/SWGSDRPlaySettings.cpp | 2 +- .../code/qt5/client/SWGSDRPlaySettings.h | 2 +- .../qt5/client/SWGSDRdaemonSinkReport.cpp | 2 +- .../code/qt5/client/SWGSDRdaemonSinkReport.h | 2 +- .../qt5/client/SWGSDRdaemonSinkSettings.cpp | 2 +- .../qt5/client/SWGSDRdaemonSinkSettings.h | 2 +- .../qt5/client/SWGSDRdaemonSourceReport.cpp | 2 +- .../qt5/client/SWGSDRdaemonSourceReport.h | 2 +- .../qt5/client/SWGSDRdaemonSourceSettings.cpp | 2 +- .../qt5/client/SWGSDRdaemonSourceSettings.h | 2 +- .../code/qt5/client/SWGSSBDemodReport.cpp | 2 +- .../code/qt5/client/SWGSSBDemodReport.h | 2 +- .../code/qt5/client/SWGSSBDemodSettings.cpp | 2 +- .../code/qt5/client/SWGSSBDemodSettings.h | 2 +- .../code/qt5/client/SWGSSBModReport.cpp | 2 +- .../code/qt5/client/SWGSSBModReport.h | 2 +- .../code/qt5/client/SWGSSBModSettings.cpp | 2 +- .../code/qt5/client/SWGSSBModSettings.h | 2 +- .../code/qt5/client/SWGSampleRate.cpp | 2 +- .../sdrangel/code/qt5/client/SWGSampleRate.h | 2 +- .../code/qt5/client/SWGSamplingDevice.cpp | 2 +- .../code/qt5/client/SWGSamplingDevice.h | 2 +- .../client/SWGSoapySDRFrequencySetting.cpp | 2 +- .../qt5/client/SWGSoapySDRFrequencySetting.h | 2 +- .../qt5/client/SWGSoapySDRGainSetting.cpp | 2 +- .../code/qt5/client/SWGSoapySDRGainSetting.h | 2 +- .../qt5/client/SWGSoapySDRInputSettings.cpp | 2 +- .../qt5/client/SWGSoapySDRInputSettings.h | 2 +- .../qt5/client/SWGSoapySDROutputSettings.cpp | 2 +- .../qt5/client/SWGSoapySDROutputSettings.h | 2 +- .../code/qt5/client/SWGSoapySDRReport.cpp | 2 +- .../code/qt5/client/SWGSoapySDRReport.h | 2 +- .../code/qt5/client/SWGSuccessResponse.cpp | 2 +- .../code/qt5/client/SWGSuccessResponse.h | 2 +- .../code/qt5/client/SWGTestSourceSettings.cpp | 2 +- .../code/qt5/client/SWGTestSourceSettings.h | 2 +- .../code/qt5/client/SWGUDPSinkReport.cpp | 2 +- .../code/qt5/client/SWGUDPSinkReport.h | 2 +- .../code/qt5/client/SWGUDPSinkSettings.cpp | 2 +- .../code/qt5/client/SWGUDPSinkSettings.h | 2 +- .../code/qt5/client/SWGUDPSourceReport.cpp | 2 +- .../code/qt5/client/SWGUDPSourceReport.h | 2 +- .../code/qt5/client/SWGUDPSourceSettings.cpp | 2 +- .../code/qt5/client/SWGUDPSourceSettings.h | 2 +- .../code/qt5/client/SWGWFMDemodReport.cpp | 2 +- .../code/qt5/client/SWGWFMDemodReport.h | 2 +- .../code/qt5/client/SWGWFMDemodSettings.cpp | 2 +- .../code/qt5/client/SWGWFMDemodSettings.h | 2 +- .../code/qt5/client/SWGWFMModReport.cpp | 2 +- .../code/qt5/client/SWGWFMModReport.h | 2 +- .../code/qt5/client/SWGWFMModSettings.cpp | 2 +- .../code/qt5/client/SWGWFMModSettings.h | 2 +- .../code/qt5/client/SWGXtrxInputReport.cpp | 211 +++++++ .../code/qt5/client/SWGXtrxInputReport.h | 88 +++ .../code/qt5/client/SWGXtrxInputSettings.cpp | 572 ++++++++++++++++++ .../code/qt5/client/SWGXtrxInputSettings.h | 191 ++++++ 260 files changed, 2366 insertions(+), 271 deletions(-) create mode 100644 sdrbase/resources/webapi/doc/swagger/include/Xtrx.yaml create mode 100644 swagger/sdrangel/api/swagger/include/Xtrx.yaml create mode 100644 swagger/sdrangel/code/qt5/client/SWGXtrxInputReport.cpp create mode 100644 swagger/sdrangel/code/qt5/client/SWGXtrxInputReport.h create mode 100644 swagger/sdrangel/code/qt5/client/SWGXtrxInputSettings.cpp create mode 100644 swagger/sdrangel/code/qt5/client/SWGXtrxInputSettings.h 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;