| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2016 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.                                           //
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02: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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | #ifndef INCLUDE_FILEOUTPUT_H
 | 
					
						
							|  |  |  | #define INCLUDE_FILEOUTPUT_H
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QString>
 | 
					
						
							|  |  |  | #include <QTimer>
 | 
					
						
							| 
									
										
										
										
											2020-07-12 10:22:24 +02:00
										 |  |  | #include <QThread>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | #include <ctime>
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  | #include "dsp/devicesamplesink.h"
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | #include "fileoutputsettings.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-21 01:21:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | class FileOutputWorker; | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | class DeviceAPI; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | class FileOutput : public DeviceSampleSink { | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	class MsgConfigureFileOutput : public Message { | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		const FileOutputSettings& getSettings() const { return m_settings; } | 
					
						
							| 
									
										
										
										
											2017-10-14 07:28:57 +02:00
										 |  |  | 		bool getForce() const { return m_force; } | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		static MsgConfigureFileOutput* create(const FileOutputSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 			return new MsgConfigureFileOutput(settings, force); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		FileOutputSettings m_settings; | 
					
						
							| 
									
										
										
										
											2017-10-14 07:28:57 +02:00
										 |  |  | 		bool m_force; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		MsgConfigureFileOutput(const FileOutputSettings& settings, bool force) : | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 			Message(), | 
					
						
							| 
									
										
										
										
											2017-10-14 07:28:57 +02:00
										 |  |  | 			m_settings(settings), | 
					
						
							|  |  |  | 			m_force(force) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-14 00:38:22 +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) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	class MsgConfigureFileOutputName : public Message { | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		const QString& getFileName() const { return m_fileName; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		static MsgConfigureFileOutputName* create(const QString& fileName) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 			return new MsgConfigureFileOutputName(fileName); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 		QString m_fileName; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		MsgConfigureFileOutputName(const QString& fileName) : | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_fileName(fileName) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	class MsgConfigureFileOutputWork : public Message { | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		bool isWorking() const { return m_working; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		static MsgConfigureFileOutputWork* create(bool working) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 			return new MsgConfigureFileOutputWork(working); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 		bool m_working; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		MsgConfigureFileOutputWork(bool working) : | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_working(working) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	class MsgConfigureFileOutputStreamTiming : public Message { | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		static MsgConfigureFileOutputStreamTiming* create() | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 			return new MsgConfigureFileOutputStreamTiming(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		MsgConfigureFileOutputStreamTiming() : | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 			Message() | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	class MsgReportFileOutputGeneration : public Message { | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		bool getAcquisition() const { return m_acquisition; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		static MsgReportFileOutputGeneration* create(bool acquisition) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 			return new MsgReportFileOutputGeneration(acquisition); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	protected: | 
					
						
							|  |  |  | 		bool m_acquisition; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		MsgReportFileOutputGeneration(bool acquisition) : | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_acquisition(acquisition) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	class MsgReportFileOutputStreamTiming : public Message { | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		std::size_t getSamplesCount() const { return m_samplesCount; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		static MsgReportFileOutputStreamTiming* create(std::size_t samplesCount) | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 			return new MsgReportFileOutputStreamTiming(samplesCount); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	protected: | 
					
						
							|  |  |  | 		std::size_t m_samplesCount; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 		MsgReportFileOutputStreamTiming(std::size_t samplesCount) : | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_samplesCount(samplesCount) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	FileOutput(DeviceAPI *deviceAPI); | 
					
						
							|  |  |  | 	virtual ~FileOutput(); | 
					
						
							| 
									
										
										
										
											2017-09-16 11:34:25 +02:00
										 |  |  | 	virtual void destroy(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-25 12:59:44 +01:00
										 |  |  |     virtual void init(); | 
					
						
							| 
									
										
										
										
											2017-04-14 03:44:49 +02:00
										 |  |  | 	virtual bool start(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	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; } | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	virtual const QString& getDeviceDescription() const; | 
					
						
							|  |  |  | 	virtual int getSampleRate() const; | 
					
						
							| 
									
										
										
										
											2019-05-10 00:34:35 +02:00
										 |  |  |     virtual void setSampleRate(int sampleRate) { (void) sampleRate; } | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	virtual quint64 getCenterFrequency() const; | 
					
						
							| 
									
										
										
										
											2017-12-28 04:04:50 +01:00
										 |  |  |     virtual void setCenterFrequency(qint64 centerFrequency); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	std::time_t getStartingTimeStamp() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	virtual bool handleMessage(const Message& message); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     DeviceAPI *m_deviceAPI; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	QMutex m_mutex; | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	FileOutputSettings m_settings; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	std::ofstream m_ofstream; | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	FileOutputWorker* m_fileOutputWorker; | 
					
						
							|  |  |  |     QThread m_fileOutputWorkerThread; | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	QString m_deviceDescription; | 
					
						
							|  |  |  | 	QString m_fileName; | 
					
						
							|  |  |  | 	std::time_t m_startingTimeStamp; | 
					
						
							|  |  |  | 	const QTimer& m_masterTimer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-12 10:22:24 +02:00
										 |  |  |     void startWorker(); | 
					
						
							|  |  |  |     void stopWorker(); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | 	void openFileStream(); | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | 	void applySettings(const FileOutputSettings& settings, bool force = false); | 
					
						
							| 
									
										
										
										
											2016-10-19 18:42:57 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-04 00:29:15 +02:00
										 |  |  | #endif // INCLUDE_FILEOUTPUT_H
 |