| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-18 10:07:41 +01:00
										 |  |  | // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					
						
							|  |  |  | // written by Christian Daniel                                                   //
 | 
					
						
							|  |  |  | // Copyright (C) 2015-2020, 2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 06:57:41 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_
 | 
					
						
							|  |  |  | #define PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 18:15:43 +01:00
										 |  |  | #include <stdint.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QByteArray>
 | 
					
						
							| 
									
										
										
										
											2018-12-26 18:15:43 +01:00
										 |  |  | #include <QNetworkRequest>
 | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-30 01:58:39 +01:00
										 |  |  | #include "soapysdr/devicesoapysdrshared.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | #include "dsp/devicesamplesource.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-01 02:32:26 +01:00
										 |  |  | #include "soapysdrinputsettings.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 18:15:43 +01:00
										 |  |  | class QNetworkAccessManager; | 
					
						
							|  |  |  | class QNetworkReply; | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | class DeviceAPI; | 
					
						
							| 
									
										
										
										
											2018-10-30 20:31:16 +01:00
										 |  |  | class SoapySDRInputThread; | 
					
						
							| 
									
										
										
										
											2018-11-02 02:33:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace SoapySDR | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     class Device; | 
					
						
							| 
									
										
										
										
											2018-11-14 02:06:36 +01:00
										 |  |  |     class ArgInfo; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace SWGSDRangel | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     class SWGArgValue; | 
					
						
							|  |  |  |     class SWGArgInfo; | 
					
						
							| 
									
										
										
										
											2018-11-02 02:33:04 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SoapySDRInput : public DeviceSampleSource | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-26 18:15:43 +01:00
										 |  |  |     Q_OBJECT | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-11-01 11:43:42 +01:00
										 |  |  |     class MsgConfigureSoapySDRInput : public Message { | 
					
						
							| 
									
										
										
										
											2018-11-01 02:32:26 +01:00
										 |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         const SoapySDRInputSettings& getSettings() const { return m_settings; } | 
					
						
							|  |  |  |         bool getForce() const { return m_force; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-01 11:43:42 +01:00
										 |  |  |         static MsgConfigureSoapySDRInput* create(const SoapySDRInputSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2018-11-01 02:32:26 +01:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-11-01 11:43:42 +01:00
										 |  |  |             return new MsgConfigureSoapySDRInput(settings, force); | 
					
						
							| 
									
										
										
										
											2018-11-01 02:32:26 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         SoapySDRInputSettings m_settings; | 
					
						
							|  |  |  |         bool m_force; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-01 11:43:42 +01:00
										 |  |  |         MsgConfigureSoapySDRInput(const SoapySDRInputSettings& settings, bool force) : | 
					
						
							| 
									
										
										
										
											2018-11-01 02:32:26 +01:00
										 |  |  |             Message(), | 
					
						
							|  |  |  |             m_settings(settings), | 
					
						
							|  |  |  |             m_force(force) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-01 11:43:42 +01:00
										 |  |  |     class MsgStartStop : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         bool getStartStop() const { return m_startStop; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgStartStop* create(bool startStop) { | 
					
						
							|  |  |  |             return new MsgStartStop(startStop); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected: | 
					
						
							|  |  |  |         bool m_startStop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgStartStop(bool startStop) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_startStop(startStop) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 23:21:37 +01:00
										 |  |  |     class MsgReportGainChange : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         const SoapySDRInputSettings& getSettings() const { return m_settings; } | 
					
						
							|  |  |  |         bool getGlobalGain() const { return m_globalGain; } | 
					
						
							|  |  |  |         bool getIndividualGains() const { return m_individualGains; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgReportGainChange* create(const SoapySDRInputSettings& settings, bool globalGain, bool individualGains) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgReportGainChange(settings, globalGain, individualGains); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         SoapySDRInputSettings m_settings; | 
					
						
							|  |  |  |         bool m_globalGain; | 
					
						
							|  |  |  |         bool m_individualGains; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgReportGainChange(const SoapySDRInputSettings& settings, bool globalGain, bool individualGains) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_settings(settings), | 
					
						
							|  |  |  |             m_globalGain(globalGain), | 
					
						
							|  |  |  |             m_individualGains(individualGains) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     SoapySDRInput(DeviceAPI *deviceAPI); | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  |     virtual ~SoapySDRInput(); | 
					
						
							|  |  |  |     virtual void destroy(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void init(); | 
					
						
							|  |  |  |     virtual bool start(); | 
					
						
							|  |  |  |     virtual void stop(); | 
					
						
							| 
									
										
										
										
											2018-10-30 20:31:16 +01:00
										 |  |  |     SoapySDRInputThread *getThread() { return m_thread; } | 
					
						
							|  |  |  |     void setThread(SoapySDRInputThread *thread) { m_thread = thread; } | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual QByteArray serialize() const; | 
					
						
							|  |  |  |     virtual bool deserialize(const QByteArray& data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } | 
					
						
							|  |  |  |     virtual const QString& getDeviceDescription() const; | 
					
						
							|  |  |  |     virtual int getSampleRate() const; | 
					
						
							| 
									
										
										
										
											2019-05-02 04:02:40 +02:00
										 |  |  |     virtual void setSampleRate(int sampleRate) { (void) sampleRate; } | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  |     virtual quint64 getCenterFrequency() const; | 
					
						
							|  |  |  |     virtual void setCenterFrequency(qint64 centerFrequency); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual bool handleMessage(const Message& message); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-01 02:32:26 +01:00
										 |  |  |     void getFrequencyRange(uint64_t& min, uint64_t& max); | 
					
						
							| 
									
										
										
										
											2018-11-07 01:33:17 +01:00
										 |  |  |     void getGlobalGainRange(int& min, int& max); | 
					
						
							| 
									
										
										
										
											2018-11-08 01:31:39 +01:00
										 |  |  |     bool isAGCSupported(); | 
					
						
							| 
									
										
										
										
											2018-11-04 23:54:16 +01:00
										 |  |  |     const std::vector<std::string>& getAntennas(); | 
					
						
							| 
									
										
										
										
											2018-11-05 02:19:40 +01:00
										 |  |  |     const SoapySDR::RangeList& getRateRanges(); | 
					
						
							|  |  |  |     const SoapySDR::RangeList& getBandwidthRanges(); | 
					
						
							| 
									
										
										
										
											2018-11-04 23:54:16 +01:00
										 |  |  |     int getAntennaIndex(const std::string& antenna); | 
					
						
							| 
									
										
										
										
											2018-11-05 17:27:32 +01:00
										 |  |  |     const std::vector<DeviceSoapySDRParams::FrequencySetting>& getTunableElements(); | 
					
						
							| 
									
										
										
										
											2018-11-07 01:33:17 +01:00
										 |  |  |     const std::vector<DeviceSoapySDRParams::GainSetting>& getIndividualGainsRanges(); | 
					
						
							| 
									
										
										
										
											2018-11-11 02:30:10 +01:00
										 |  |  |     const SoapySDR::ArgInfoList& getStreamArgInfoList(); | 
					
						
							| 
									
										
										
										
											2018-11-12 01:10:51 +01:00
										 |  |  |     const SoapySDR::ArgInfoList& getDeviceArgInfoList(); | 
					
						
							| 
									
										
										
										
											2018-11-07 23:21:37 +01:00
										 |  |  |     void initGainSettings(SoapySDRInputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-15 22:25:33 +01:00
										 |  |  |     void initTunableElementsSettings(SoapySDRInputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-11 02:30:10 +01:00
										 |  |  |     void initStreamArgSettings(SoapySDRInputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-12 01:10:51 +01:00
										 |  |  |     void initDeviceArgSettings(SoapySDRInputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-08 14:35:26 +01:00
										 |  |  |     bool hasDCAutoCorrection(); | 
					
						
							|  |  |  |     bool hasDCCorrectionValue(); | 
					
						
							|  |  |  |     bool hasIQAutoCorrection() { return false; } // not in SoapySDR interface
 | 
					
						
							|  |  |  |     bool hasIQCorrectionValue(); | 
					
						
							| 
									
										
										
										
											2018-11-01 02:32:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 23:34:03 +01:00
										 |  |  |     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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     static void webapiFormatDeviceSettings( | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							|  |  |  |             const SoapySDRInputSettings& settings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static void webapiUpdateDeviceSettings( | 
					
						
							|  |  |  |             SoapySDRInputSettings& settings, | 
					
						
							|  |  |  |             const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceSettings& response); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     DeviceAPI *m_deviceAPI; | 
					
						
							| 
									
										
										
										
											2018-11-02 02:33:04 +01:00
										 |  |  |     QMutex m_mutex; | 
					
						
							| 
									
										
										
										
											2022-09-26 00:56:55 +02:00
										 |  |  |     bool m_openSuccess; | 
					
						
							| 
									
										
										
										
											2018-11-02 02:33:04 +01:00
										 |  |  |     SoapySDRInputSettings m_settings; | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  |     QString m_deviceDescription; | 
					
						
							| 
									
										
										
										
											2018-10-30 01:58:39 +01:00
										 |  |  |     bool m_running; | 
					
						
							| 
									
										
										
										
											2018-11-02 02:33:04 +01:00
										 |  |  |     SoapySDRInputThread *m_thread; | 
					
						
							|  |  |  |     DeviceSoapySDRShared m_deviceShared; | 
					
						
							| 
									
										
										
										
											2018-12-26 18:15:43 +01:00
										 |  |  |     QNetworkAccessManager *m_networkManager; | 
					
						
							|  |  |  |     QNetworkRequest m_networkRequest; | 
					
						
							| 
									
										
										
										
											2018-10-30 01:58:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool openDevice(); | 
					
						
							|  |  |  |     void closeDevice(); | 
					
						
							| 
									
										
										
										
											2018-11-02 02:33:04 +01:00
										 |  |  |     SoapySDRInputThread *findThread(); | 
					
						
							| 
									
										
										
										
											2018-10-30 20:31:16 +01:00
										 |  |  |     void moveThreadToBuddy(); | 
					
						
							| 
									
										
										
										
											2018-11-02 02:33:04 +01:00
										 |  |  |     bool applySettings(const SoapySDRInputSettings& settings, bool force = false); | 
					
						
							|  |  |  |     bool setDeviceCenterFrequency(SoapySDR::Device *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths); | 
					
						
							| 
									
										
										
										
											2018-11-07 23:21:37 +01:00
										 |  |  |     void updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-15 22:25:33 +01:00
										 |  |  |     void updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDRInputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-14 02:06:36 +01:00
										 |  |  |     void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response); | 
					
						
							| 
									
										
										
										
											2019-08-04 20:24:44 +02:00
										 |  |  |     static QVariant webapiVariantFromArgValue(SWGSDRangel::SWGArgValue *argValue); | 
					
						
							|  |  |  |     static void webapiFormatArgValue(const QVariant& v, SWGSDRangel::SWGArgValue *argValue); | 
					
						
							| 
									
										
										
										
											2018-11-14 02:06:36 +01:00
										 |  |  |     void webapiFormatArgInfo(const SoapySDR::ArgInfo& arg, SWGSDRangel::SWGArgInfo *argInfo); | 
					
						
							| 
									
										
										
										
											2018-12-26 18:15:43 +01:00
										 |  |  |     void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const SoapySDRInputSettings& settings, bool force); | 
					
						
							|  |  |  |     void webapiReverseSendStartStop(bool start); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							|  |  |  |     void networkManagerFinished(QNetworkReply *reply); | 
					
						
							| 
									
										
										
										
											2018-10-29 16:39:25 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* PLUGINS_SAMPLESOURCE_SOAPYSDRINPUT_SOAPYSDRINPUT_H_ */
 |