| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					
						
							|  |  |  | // written by Christian Daniel                                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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.                                           //
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +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 INCLUDE_RTLSDRINPUT_H
 | 
					
						
							|  |  |  | #define INCLUDE_RTLSDRINPUT_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QByteArray>
 | 
					
						
							| 
									
										
										
										
											2018-12-17 08:51:59 +01:00
										 |  |  | #include <QNetworkRequest>
 | 
					
						
							| 
									
										
										
										
											2016-10-02 23:16:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-08 11:53:56 +02:00
										 |  |  | #include "dsp/devicesamplesource.h"
 | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | #include "rtlsdrsettings.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include <rtl-sdr.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | class DeviceAPI; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | class RTLSDRThread; | 
					
						
							| 
									
										
										
										
											2018-12-17 08:51:59 +01:00
										 |  |  | class QNetworkAccessManager; | 
					
						
							|  |  |  | class QNetworkReply; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 23:16:40 +02:00
										 |  |  | class RTLSDRInput : public DeviceSampleSource { | 
					
						
							| 
									
										
										
										
											2018-12-18 06:14:18 +01:00
										 |  |  |     Q_OBJECT | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | public: | 
					
						
							|  |  |  | 	class MsgConfigureRTLSDR : public Message { | 
					
						
							|  |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 		const RTLSDRSettings& getSettings() const { return m_settings; } | 
					
						
							| 
									
										
										
										
											2017-10-14 07:07:32 +02:00
										 |  |  | 		bool getForce() const { return m_force; } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 07:07:32 +02:00
										 |  |  | 		static MsgConfigureRTLSDR* create(const RTLSDRSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-10-14 07:07:32 +02:00
										 |  |  | 			return new MsgConfigureRTLSDR(settings, force); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 		RTLSDRSettings m_settings; | 
					
						
							| 
									
										
										
										
											2017-10-14 07:07:32 +02:00
										 |  |  | 		bool m_force; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 07:07:32 +02:00
										 |  |  | 		MsgConfigureRTLSDR(const RTLSDRSettings& settings, bool force) : | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 			Message(), | 
					
						
							| 
									
										
										
										
											2017-10-14 07:07:32 +02:00
										 |  |  | 			m_settings(settings), | 
					
						
							|  |  |  | 			m_force(force) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +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) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | 	RTLSDRInput(DeviceAPI *deviceAPI); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	virtual ~RTLSDRInput(); | 
					
						
							| 
									
										
										
										
											2017-09-15 02:32:30 +02:00
										 |  |  | 	virtual void destroy(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-25 09:10:19 +01:00
										 |  |  | 	virtual void init(); | 
					
						
							| 
									
										
										
										
											2017-04-14 03:40:45 +02:00
										 |  |  | 	virtual bool start(); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	virtual void stop(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  |     virtual QByteArray serialize() const; | 
					
						
							|  |  |  |     virtual bool deserialize(const QByteArray& data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-24 19:58:26 +01:00
										 |  |  |     virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	virtual const QString& getDeviceDescription() const; | 
					
						
							|  |  |  | 	virtual int getSampleRate() const; | 
					
						
							| 
									
										
										
										
											2019-05-02 04:02:40 +02:00
										 |  |  |     virtual void setSampleRate(int sampleRate) { (void) sampleRate; } | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	virtual quint64 getCenterFrequency() const; | 
					
						
							| 
									
										
										
										
											2017-12-28 03:21:48 +01:00
										 |  |  |     virtual void setCenterFrequency(qint64 centerFrequency); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	virtual bool handleMessage(const Message& message); | 
					
						
							| 
									
										
										
										
											2014-11-07 19:26:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 23:49:14 +01:00
										 |  |  |     virtual int webapiSettingsGet( | 
					
						
							|  |  |  |                 SWGSDRangel::SWGDeviceSettings& response, | 
					
						
							|  |  |  |                 QString& errorMessage); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 18:50:36 +01:00
										 |  |  |     virtual int webapiSettingsPutPatch( | 
					
						
							|  |  |  |                 bool force, | 
					
						
							| 
									
										
										
										
											2017-12-27 01:46:33 +01:00
										 |  |  |                 const QStringList& deviceSettingsKeys, | 
					
						
							| 
									
										
										
										
											2017-12-07 18:50:36 +01:00
										 |  |  |                 SWGSDRangel::SWGDeviceSettings& response, // query + response
 | 
					
						
							|  |  |  |                 QString& errorMessage); | 
					
						
							| 
									
										
										
										
											2017-12-09 10:49:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-26 14:28:06 +02:00
										 |  |  |     virtual int webapiReportGet( | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceReport& response, | 
					
						
							|  |  |  |             QString& errorMessage); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-09 10:49:20 +01:00
										 |  |  |     virtual int webapiRunGet( | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |             QString& errorMessage); | 
					
						
							| 
									
										
										
										
											2017-12-07 18:50:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 17:12:33 +01:00
										 |  |  |     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 RTLSDRSettings& settings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static void webapiUpdateDeviceSettings( | 
					
						
							|  |  |  |             RTLSDRSettings& settings, | 
					
						
							|  |  |  |             const QStringList& deviceSettingsKeys, | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceSettings& response); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  | 	const std::vector<int>& getGains() const { return m_gains; } | 
					
						
							| 
									
										
										
										
											2014-11-07 19:26:02 +00:00
										 |  |  | 	void set_ds_mode(int on); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-23 19:15:56 +02:00
										 |  |  | 	static const quint64 frequencyLowRangeMin; | 
					
						
							|  |  |  | 	static const quint64 frequencyLowRangeMax; | 
					
						
							|  |  |  |     static const quint64 frequencyHighRangeMin; | 
					
						
							|  |  |  |     static const quint64 frequencyHighRangeMax; | 
					
						
							|  |  |  | 	static const int sampleRateLowRangeMin; | 
					
						
							|  |  |  |     static const int sampleRateLowRangeMax; | 
					
						
							|  |  |  |     static const int sampleRateHighRangeMin; | 
					
						
							|  |  |  |     static const int sampleRateHighRangeMax; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | 	DeviceAPI *m_deviceAPI; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	QMutex m_mutex; | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 	RTLSDRSettings m_settings; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	rtlsdr_dev_t* m_dev; | 
					
						
							|  |  |  | 	RTLSDRThread* m_rtlSDRThread; | 
					
						
							|  |  |  | 	QString m_deviceDescription; | 
					
						
							|  |  |  | 	std::vector<int> m_gains; | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  | 	bool m_running; | 
					
						
							| 
									
										
										
										
											2018-12-17 08:51:59 +01:00
										 |  |  |     QNetworkAccessManager *m_networkManager; | 
					
						
							|  |  |  |     QNetworkRequest m_networkRequest; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 01:21:25 +02:00
										 |  |  | 	bool openDevice(); | 
					
						
							|  |  |  | 	void closeDevice(); | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 	bool applySettings(const RTLSDRSettings& settings, bool force); | 
					
						
							| 
									
										
										
										
											2018-05-26 14:28:06 +02:00
										 |  |  |     void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response); | 
					
						
							| 
									
										
										
										
											2018-12-17 08:51:59 +01:00
										 |  |  |     void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const RTLSDRSettings& settings, bool force); | 
					
						
							| 
									
										
										
										
											2018-12-17 15:00:13 +01:00
										 |  |  |     void webapiReverseSendStartStop(bool start); | 
					
						
							| 
									
										
										
										
											2018-12-17 08:51:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							|  |  |  |     void networkManagerFinished(QNetworkReply *reply); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_RTLSDRINPUT_H
 |