| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 06:43:20 +01:00
										 |  |  | // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					
						
							|  |  |  | // written by Christian Daniel                                                   //
 | 
					
						
							|  |  |  | // Copyright (C) 2014 John Greb <hexameron@spam.no>                              //
 | 
					
						
							|  |  |  | // Copyright (C) 2015-2019, 2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							|  |  |  | // Copyright (C) 2022 Jon Beniston, M7RCE <jon@beniston.com>                     //
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02: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 14:32:15 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef SDRBASE_DSP_DSPDEVICESINKENGINE_H_
 | 
					
						
							|  |  |  | #define SDRBASE_DSP_DSPDEVICESINKENGINE_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-18 13:37:27 +02:00
										 |  |  | #include <QObject>
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | #include <QTimer>
 | 
					
						
							|  |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include <QWaitCondition>
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 12:45:19 +01:00
										 |  |  | #include <stdint.h>
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | #include <list>
 | 
					
						
							| 
									
										
										
										
											2016-12-26 12:11:51 +01:00
										 |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | #include "dsp/dsptypes.h"
 | 
					
						
							|  |  |  | #include "util/messagequeue.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | #include "util/incrementalvector.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-20 13:49:21 +01:00
										 |  |  | #include "export.h"
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class DeviceSampleSink; | 
					
						
							|  |  |  | class BasebandSampleSource; | 
					
						
							|  |  |  | class BasebandSampleSink; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-18 13:37:27 +02:00
										 |  |  | class SDRBASE_API DSPDeviceSinkEngine : public QObject { | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	enum class State { | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 		StNotStarted,  //!< engine is before initialization
 | 
					
						
							|  |  |  | 		StIdle,        //!< engine is idle
 | 
					
						
							|  |  |  | 		StReady,       //!< engine is ready to run
 | 
					
						
							|  |  |  | 		StRunning,     //!< engine is running
 | 
					
						
							|  |  |  | 		StError        //!< engine is in error
 | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-18 13:37:27 +02:00
										 |  |  | 	DSPDeviceSinkEngine(uint32_t uid, QObject* parent = nullptr); | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	~DSPDeviceSinkEngine() final; | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 12:45:19 +01:00
										 |  |  | 	uint32_t getUID() const { return m_uid; } | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MessageQueue* getInputMessageQueue() { return &m_inputMessageQueue; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool initGeneration(); //!< Initialize generation sequence
 | 
					
						
							|  |  |  | 	bool startGeneration(); //!< Start generation sequence
 | 
					
						
							|  |  |  | 	void stopGeneration();   //!< Stop generation sequence
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void setSink(DeviceSampleSink* sink); //!< Set the sample sink type
 | 
					
						
							| 
									
										
										
										
											2017-09-16 11:34:25 +02:00
										 |  |  | 	DeviceSampleSink *getSink() { return m_deviceSampleSink; } | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 	void setSinkSequence(int sequence); //!< Set the sample sink sequence in type
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 	void addChannelSource(BasebandSampleSource* source);       //!< Add a baseband sample source
 | 
					
						
							| 
									
										
										
										
											2024-11-25 17:16:08 +00:00
										 |  |  | 	void removeChannelSource(BasebandSampleSource* source, bool deleting);    //!< Remove a baseband sample source
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 18:06:44 +02:00
										 |  |  | 	void addSpectrumSink(BasebandSampleSink* spectrumSink);    //!< Add a spectrum vis baseband sample sink
 | 
					
						
							|  |  |  | 	void removeSpectrumSink(BasebandSampleSink* spectrumSink); //!< Add a spectrum vis baseband sample sink
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	State state() const { return m_state; } //!< Return DSP engine current state
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	QString errorMessage() const; //!< Return the current error message
 | 
					
						
							|  |  |  | 	QString sinkDeviceDescription() const; //!< Return the sink device description
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-12-26 12:45:19 +01:00
										 |  |  | 	uint32_t m_uid; //!< unique ID
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MessageQueue m_inputMessageQueue;  //<! Input message queue. Post here.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	State m_state; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QString m_errorMessage; | 
					
						
							|  |  |  | 	QString m_deviceDescription; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DeviceSampleSink* m_deviceSampleSink; | 
					
						
							|  |  |  | 	int m_sampleSinkSequence; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	using BasebandSampleSources = std::list<BasebandSampleSource *>; | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 	BasebandSampleSources m_basebandSampleSources; //!< baseband sample sources within main thread (usually file input)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 18:06:44 +02:00
										 |  |  | 	BasebandSampleSink *m_spectrumSink; | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     IncrementalVector<Sample> m_sourceSampleBuffer; | 
					
						
							|  |  |  |     IncrementalVector<Sample> m_sourceZeroBuffer; | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-26 12:45:19 +01:00
										 |  |  | 	uint32_t m_sampleRate; | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 	quint64 m_centerFrequency; | 
					
						
							| 
									
										
										
										
											2023-06-18 00:44:20 +02:00
										 |  |  |     bool m_realElseComplex; | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  |     unsigned int m_sumIndex; //!< channel index when summing channels
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 	void workSampleFifo(); //!< transfer samples from baseband sources to sink if in running state
 | 
					
						
							|  |  |  |     void workSamples(SampleVector& data, unsigned int iBegin, unsigned int iEnd); | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	State gotoIdle();     //!< Go to the idle state
 | 
					
						
							|  |  |  | 	State gotoInit();     //!< Go to the acquisition init state from idle
 | 
					
						
							|  |  |  | 	State gotoRunning();  //!< Go to the running state from ready state
 | 
					
						
							|  |  |  | 	State gotoError(const QString& errorMsg); //!< Go to an error state
 | 
					
						
							| 
									
										
										
										
											2022-08-27 10:18:17 +01:00
										 |  |  | 	void setState(State state); | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 13:17:02 +02:00
										 |  |  | 	void handleSetSink(const DeviceSampleSink* sink); //!< Manage sink setting
 | 
					
						
							| 
									
										
										
										
											2024-08-17 22:34:30 +02:00
										 |  |  |     bool handleMessage(const Message& cmd); | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							| 
									
										
										
										
											2019-11-15 01:04:24 +01:00
										 |  |  | 	void handleData(); //!< Handle data when samples have to be written to the sample FIFO
 | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | 	void handleInputMessages(); //!< Handle input message queue
 | 
					
						
							| 
									
										
										
										
											2022-08-27 10:18:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | signals: | 
					
						
							|  |  |  | 	void stateChanged(); | 
					
						
							| 
									
										
										
										
											2024-10-10 13:57:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void generationStopped(); | 
					
						
							|  |  |  | 	void sampleSet(); | 
					
						
							|  |  |  | 	void spectrumSinkRemoved(); | 
					
						
							| 
									
										
										
										
											2016-10-17 18:15:08 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* SDRBASE_DSP_DSPDEVICESINKENGINE_H_ */
 |