| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2017 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                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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_SDRDAEMONSINKOUTPUT_H
 | 
					
						
							|  |  |  | #define INCLUDE_SDRDAEMONSINKOUTPUT_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <ctime>
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 18:13:57 +02:00
										 |  |  | #include <QObject>
 | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QTimer>
 | 
					
						
							|  |  |  | #include <QNetworkRequest>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | #include "dsp/devicesamplesink.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "sdrdaemonsinksettings.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SDRdaemonSinkThread; | 
					
						
							|  |  |  | class DeviceSinkAPI; | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  | class QNetworkAccessManager; | 
					
						
							|  |  |  | class QNetworkReply; | 
					
						
							|  |  |  | class QJsonObject; | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SDRdaemonSinkOutput : public DeviceSampleSink { | 
					
						
							| 
									
										
										
										
											2018-09-03 18:13:57 +02:00
										 |  |  |     Q_OBJECT | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | public: | 
					
						
							|  |  |  | 	class MsgConfigureSDRdaemonSink : public Message { | 
					
						
							|  |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		const SDRdaemonSinkSettings& getSettings() const { return m_settings; } | 
					
						
							|  |  |  | 		bool getForce() const { return m_force; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		static MsgConfigureSDRdaemonSink* create(const SDRdaemonSinkSettings& settings, bool force = false) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return new MsgConfigureSDRdaemonSink(settings, force); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 		SDRdaemonSinkSettings m_settings; | 
					
						
							|  |  |  | 		bool m_force; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MsgConfigureSDRdaemonSink(const SDRdaemonSinkSettings& settings, bool force) : | 
					
						
							|  |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_settings(settings), | 
					
						
							|  |  |  | 			m_force(force) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	class MsgConfigureSDRdaemonSinkWork : public Message { | 
					
						
							|  |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		bool isWorking() const { return m_working; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		static MsgConfigureSDRdaemonSinkWork* create(bool working) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			return new MsgConfigureSDRdaemonSinkWork(working); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 		bool m_working; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MsgConfigureSDRdaemonSinkWork(bool working) : | 
					
						
							|  |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_working(working) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class MsgConfigureSDRdaemonSinkChunkCorrection : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         int getChunkCorrection() const { return m_chunkCorrection; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgConfigureSDRdaemonSinkChunkCorrection* create(int chunkCorrection) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgConfigureSDRdaemonSinkChunkCorrection(chunkCorrection); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         int m_chunkCorrection; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgConfigureSDRdaemonSinkChunkCorrection(int chunkCorrection) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_chunkCorrection(chunkCorrection) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SDRdaemonSinkOutput(DeviceSinkAPI *deviceAPI); | 
					
						
							|  |  |  | 	virtual ~SDRdaemonSinkOutput(); | 
					
						
							|  |  |  | 	virtual void destroy(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-25 12:59:44 +01:00
										 |  |  |     virtual void init(); | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | 	virtual bool start(); | 
					
						
							|  |  |  | 	virtual void stop(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +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; } | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | 	virtual const QString& getDeviceDescription() const; | 
					
						
							|  |  |  | 	virtual int getSampleRate() const; | 
					
						
							|  |  |  | 	virtual quint64 getCenterFrequency() const; | 
					
						
							| 
									
										
										
										
											2018-09-07 00:58:09 +02:00
										 |  |  |     virtual void setCenterFrequency(qint64 centerFrequency __attribute__((unused))) {} | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | 	std::time_t getStartingTimeStamp() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	virtual bool handleMessage(const Message& message); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 00:40:33 +02: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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 18:22:45 +01:00
										 |  |  |     virtual int webapiRunGet( | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |             QString& errorMessage); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual int webapiRun( | 
					
						
							|  |  |  |             bool run, | 
					
						
							|  |  |  |             SWGSDRangel::SWGDeviceState& response, | 
					
						
							|  |  |  |             QString& errorMessage); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     DeviceSinkAPI *m_deviceAPI; | 
					
						
							|  |  |  | 	QMutex m_mutex; | 
					
						
							|  |  |  | 	SDRdaemonSinkSettings m_settings; | 
					
						
							| 
									
										
										
										
											2018-09-07 00:58:09 +02:00
										 |  |  | 	uint64_t m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | 	SDRdaemonSinkThread* m_sdrDaemonSinkThread; | 
					
						
							|  |  |  | 	QString m_deviceDescription; | 
					
						
							|  |  |  | 	std::time_t m_startingTimeStamp; | 
					
						
							|  |  |  | 	const QTimer& m_masterTimer; | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  | 	uint32_t m_tickCount; | 
					
						
							| 
									
										
										
										
											2018-09-03 18:13:57 +02:00
										 |  |  |     uint32_t m_tickMultiplier; | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QNetworkAccessManager *m_networkManager; | 
					
						
							|  |  |  |     QNetworkRequest m_networkRequest; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 08:43:07 +02:00
										 |  |  |     uint32_t m_lastRemoteSampleCount; | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  |     uint32_t m_lastSampleCount; | 
					
						
							| 
									
										
										
										
											2018-09-04 08:43:07 +02:00
										 |  |  |     uint64_t m_lastRemoteTimestampRateCorrection; | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  |     uint64_t m_lastTimestampRateCorrection; | 
					
						
							| 
									
										
										
										
											2018-09-07 09:22:17 +02:00
										 |  |  |     int m_lastQueueLength; | 
					
						
							| 
									
										
										
										
											2018-09-04 08:43:07 +02:00
										 |  |  |     uint32_t m_nbRemoteSamplesSinceRateCorrection; | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  |     uint32_t m_nbSamplesSinceRateCorrection; | 
					
						
							|  |  |  |     int m_chunkSizeCorrection; | 
					
						
							| 
									
										
										
										
											2018-09-03 18:13:57 +02:00
										 |  |  |     static const uint32_t NbSamplesForRateCorrection; | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void applySettings(const SDRdaemonSinkSettings& settings, bool force = false); | 
					
						
							| 
									
										
										
										
											2018-05-28 00:40:33 +02:00
										 |  |  |     void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SDRdaemonSinkSettings& settings); | 
					
						
							|  |  |  |     void webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response); | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void analyzeApiReply(const QJsonObject& jsonObject); | 
					
						
							| 
									
										
										
										
											2018-09-04 08:43:07 +02:00
										 |  |  |     void sampleRateCorrection(double remoteTimeDeltaUs, double timeDeltaUs, uint32_t remoteSampleCount, uint32_t sampleCount); | 
					
						
							| 
									
										
										
										
											2018-09-03 09:17:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							|  |  |  |     void tick(); | 
					
						
							|  |  |  |     void networkManagerFinished(QNetworkReply *reply); | 
					
						
							| 
									
										
										
										
											2017-12-14 18:02:49 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_SDRDAEMONSINKOUTPUT_H
 |