| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2018 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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:39:30 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +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_SAMPLESINK_SOAPYSDROUTPUT_SOAPYSDROUTPUT_H_
 | 
					
						
							|  |  |  | #define PLUGINS_SAMPLESINK_SOAPYSDROUTPUT_SOAPYSDROUTPUT_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 23:00:31 +01:00
										 |  |  | #include <stdint.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | #include <QString>
 | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  | #include <QByteArray>
 | 
					
						
							| 
									
										
										
										
											2018-12-26 23:00:31 +01:00
										 |  |  | #include <QNetworkRequest>
 | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "dsp/devicesamplesink.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-30 10:02:32 +01:00
										 |  |  | #include "soapysdr/devicesoapysdrshared.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-30 20:31:16 +01:00
										 |  |  | #include "soapysdroutputsettings.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-26 23:00:31 +01:00
										 |  |  | class QNetworkAccessManager; | 
					
						
							|  |  |  | class QNetworkReply; | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | class DeviceSinkAPI; | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  | class SoapySDROutputThread; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace SoapySDR | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     class Device; | 
					
						
							| 
									
										
										
										
											2018-11-14 09:19:36 +01:00
										 |  |  |     class ArgInfo; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace SWGSDRangel | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     class SWGArgValue; | 
					
						
							|  |  |  |     class SWGArgInfo; | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SoapySDROutput : public DeviceSampleSink { | 
					
						
							| 
									
										
										
										
											2018-12-26 23:00:31 +01:00
										 |  |  |     Q_OBJECT | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  |     class MsgConfigureSoapySDROutput : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         const SoapySDROutputSettings& getSettings() const { return m_settings; } | 
					
						
							|  |  |  |         bool getForce() const { return m_force; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgConfigureSoapySDROutput* create(const SoapySDROutputSettings& settings, bool force) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgConfigureSoapySDROutput(settings, force); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         SoapySDROutputSettings m_settings; | 
					
						
							|  |  |  |         bool m_force; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgConfigureSoapySDROutput(const SoapySDROutputSettings& settings, bool force) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_settings(settings), | 
					
						
							|  |  |  |             m_force(force) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 23:54:32 +01:00
										 |  |  |     class MsgReportGainChange : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         const SoapySDROutputSettings& getSettings() const { return m_settings; } | 
					
						
							|  |  |  |         bool getGlobalGain() const { return m_globalGain; } | 
					
						
							|  |  |  |         bool getIndividualGains() const { return m_individualGains; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgReportGainChange* create(const SoapySDROutputSettings& settings, bool globalGain, bool individualGains) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgReportGainChange(settings, globalGain, individualGains); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         SoapySDROutputSettings m_settings; | 
					
						
							|  |  |  |         bool m_globalGain; | 
					
						
							|  |  |  |         bool m_individualGains; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgReportGainChange(const SoapySDROutputSettings& settings, bool globalGain, bool individualGains) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_settings(settings), | 
					
						
							|  |  |  |             m_globalGain(globalGain), | 
					
						
							|  |  |  |             m_individualGains(individualGains) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +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-10-29 18:27:58 +01:00
										 |  |  |     SoapySDROutput(DeviceSinkAPI *deviceAPI); | 
					
						
							|  |  |  |     virtual ~SoapySDROutput(); | 
					
						
							|  |  |  |     virtual void destroy(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void init(); | 
					
						
							|  |  |  |     virtual bool start(); | 
					
						
							|  |  |  |     virtual void stop(); | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  |     SoapySDROutputThread *getThread() { return m_thread; } | 
					
						
							|  |  |  |     void setThread(SoapySDROutputThread *thread) { m_thread = thread; } | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +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; | 
					
						
							|  |  |  |     virtual quint64 getCenterFrequency() const; | 
					
						
							|  |  |  |     virtual void setCenterFrequency(qint64 centerFrequency); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual bool handleMessage(const Message& message); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  |     void getFrequencyRange(uint64_t& min, uint64_t& max); | 
					
						
							| 
									
										
										
										
											2018-11-07 13:08:35 +01:00
										 |  |  |     void getGlobalGainRange(int& min, int& max); | 
					
						
							| 
									
										
										
										
											2018-11-08 01:52:48 +01:00
										 |  |  |     bool isAGCSupported(); | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  |     const SoapySDR::RangeList& getRateRanges(); | 
					
						
							| 
									
										
										
										
											2018-11-04 23:54:16 +01:00
										 |  |  |     const std::vector<std::string>& getAntennas(); | 
					
						
							| 
									
										
										
										
											2018-11-05 02:40:02 +01:00
										 |  |  |     const SoapySDR::RangeList& getBandwidthRanges(); | 
					
						
							| 
									
										
										
										
											2018-11-05 17:27:32 +01:00
										 |  |  |     const std::vector<DeviceSoapySDRParams::FrequencySetting>& getTunableElements(); | 
					
						
							| 
									
										
										
										
											2018-11-07 13:08:35 +01:00
										 |  |  |     const std::vector<DeviceSoapySDRParams::GainSetting>& getIndividualGainsRanges(); | 
					
						
							| 
									
										
										
										
											2018-11-11 09:31:27 +01:00
										 |  |  |     const SoapySDR::ArgInfoList& getStreamArgInfoList(); | 
					
						
							| 
									
										
										
										
											2018-11-12 01:10:51 +01:00
										 |  |  |     const SoapySDR::ArgInfoList& getDeviceArgInfoList(); | 
					
						
							| 
									
										
										
										
											2018-11-07 23:54:32 +01:00
										 |  |  |     void initGainSettings(SoapySDROutputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-15 22:25:33 +01:00
										 |  |  |     void initTunableElementsSettings(SoapySDROutputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-11 09:31:27 +01:00
										 |  |  |     void initStreamArgSettings(SoapySDROutputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-12 01:10:51 +01:00
										 |  |  |     void initDeviceArgSettings(SoapySDROutputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-08 21:42:49 +01:00
										 |  |  |     bool hasDCAutoCorrection(); | 
					
						
							|  |  |  |     bool hasDCCorrectionValue(); | 
					
						
							|  |  |  |     bool hasIQAutoCorrection() { return false; } // not in SoapySDR interface
 | 
					
						
							|  |  |  |     bool hasIQCorrectionValue(); | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2018-10-30 10:02:32 +01:00
										 |  |  |     DeviceSinkAPI *m_deviceAPI; | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  |     QMutex m_mutex; | 
					
						
							| 
									
										
										
										
											2018-10-30 20:31:16 +01:00
										 |  |  |     SoapySDROutputSettings m_settings; | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  |     QString m_deviceDescription; | 
					
						
							| 
									
										
										
										
											2018-10-30 10:02:32 +01:00
										 |  |  |     bool m_running; | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  |     SoapySDROutputThread *m_thread; | 
					
						
							|  |  |  |     DeviceSoapySDRShared m_deviceShared; | 
					
						
							| 
									
										
										
										
											2018-12-26 23:00:31 +01:00
										 |  |  |     QNetworkAccessManager *m_networkManager; | 
					
						
							|  |  |  |     QNetworkRequest m_networkRequest; | 
					
						
							| 
									
										
										
										
											2018-10-30 10:02:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool openDevice(); | 
					
						
							|  |  |  |     void closeDevice(); | 
					
						
							| 
									
										
										
										
											2018-11-04 11:45:59 +01:00
										 |  |  |     SoapySDROutputThread *findThread(); | 
					
						
							|  |  |  |     void moveThreadToBuddy(); | 
					
						
							|  |  |  |     bool applySettings(const SoapySDROutputSettings& settings, bool force = false); | 
					
						
							|  |  |  |     bool setDeviceCenterFrequency(SoapySDR::Device *dev, int requestedChannel, quint64 freq_hz, int loPpmTenths); | 
					
						
							| 
									
										
										
										
											2018-11-07 23:54:32 +01:00
										 |  |  |     void updateGains(SoapySDR::Device *dev, int requestedChannel, SoapySDROutputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-15 22:25:33 +01:00
										 |  |  |     void updateTunableElements(SoapySDR::Device *dev, int requestedChannel, SoapySDROutputSettings& settings); | 
					
						
							| 
									
										
										
										
											2018-11-14 09:19:36 +01:00
										 |  |  |     void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SoapySDROutputSettings& settings); | 
					
						
							|  |  |  |     void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response); | 
					
						
							| 
									
										
										
										
											2018-11-15 16:54:23 +01:00
										 |  |  |     QVariant webapiVariantFromArgValue(SWGSDRangel::SWGArgValue *argValue); | 
					
						
							| 
									
										
										
										
											2018-11-14 09:19:36 +01:00
										 |  |  |     void webapiFormatArgValue(const QVariant& v, SWGSDRangel::SWGArgValue *argValue); | 
					
						
							|  |  |  |     void webapiFormatArgInfo(const SoapySDR::ArgInfo& arg, SWGSDRangel::SWGArgInfo *argInfo); | 
					
						
							| 
									
										
										
										
											2018-12-26 23:00:31 +01:00
										 |  |  |     void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const SoapySDROutputSettings& settings, bool force); | 
					
						
							|  |  |  |     void webapiReverseSendStartStop(bool start); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							|  |  |  |     void networkManagerFinished(QNetworkReply *reply); | 
					
						
							| 
									
										
										
										
											2018-10-29 18:27:58 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* PLUGINS_SAMPLESINK_SOAPYSDROUTPUT_SOAPYSDROUTPUT_H_ */
 |