| 
									
										
										
										
											2018-08-24 08:43:15 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2018 Edouard Griffiths, F4EXB.                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // SDRdaemon source channel (Tx) UDP receiver thread                             //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // SDRdaemon is a detached SDR front end that handles the interface with a       //
 | 
					
						
							|  |  |  | // physical device and sends or receives the I/Q samples stream to or from a     //
 | 
					
						
							|  |  |  | // SDRangel instance via UDP. It is controlled via a Web REST API.               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCETHREAD_H_
 | 
					
						
							|  |  |  | #define SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCETHREAD_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QThread>
 | 
					
						
							|  |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include <QWaitCondition>
 | 
					
						
							|  |  |  | #include <QHostAddress>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "util/message.h"
 | 
					
						
							|  |  |  | #include "util/messagequeue.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SDRDaemonDataQueue; | 
					
						
							|  |  |  | class SDRDaemonDataBlock; | 
					
						
							|  |  |  | class QUdpSocket; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SDRDaemonChannelSourceThread : public QThread { | 
					
						
							|  |  |  |     Q_OBJECT | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     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-08-26 17:22:22 +02:00
										 |  |  |     class MsgDataBind : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         QHostAddress getAddress() const { return m_address; } | 
					
						
							|  |  |  |         uint16_t getPort() const { return m_port; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgDataBind* create(const QString& address, uint16_t port) { | 
					
						
							|  |  |  |             return new MsgDataBind(address, port); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected: | 
					
						
							|  |  |  |         QHostAddress m_address; | 
					
						
							|  |  |  |         uint16_t m_port; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgDataBind(const QString& address, uint16_t port) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_port(port) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_address.setAddress(address); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 01:09:12 +02:00
										 |  |  |     SDRDaemonChannelSourceThread(SDRDaemonDataQueue *dataQueue, QObject* parent = 0); | 
					
						
							| 
									
										
										
										
											2018-08-24 08:43:15 +02:00
										 |  |  |     ~SDRDaemonChannelSourceThread(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void startStop(bool start); | 
					
						
							| 
									
										
										
										
											2018-08-26 17:22:22 +02:00
										 |  |  |     void dataBind(const QString& address, uint16_t port); | 
					
						
							| 
									
										
										
										
											2018-08-24 08:43:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     QMutex m_startWaitMutex; | 
					
						
							|  |  |  |     QWaitCondition m_startWaiter; | 
					
						
							|  |  |  |     bool m_running; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-26 17:22:22 +02:00
										 |  |  |     MessageQueue m_inputMessageQueue; | 
					
						
							| 
									
										
										
										
											2018-08-24 08:43:15 +02:00
										 |  |  |     SDRDaemonDataQueue *m_dataQueue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QHostAddress m_address; | 
					
						
							|  |  |  |     QUdpSocket *m_socket; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 01:09:12 +02:00
										 |  |  |     static const uint32_t m_nbDataBlocks = 4;          //!< number of data blocks in the ring buffer
 | 
					
						
							|  |  |  |     SDRDaemonDataBlock *m_dataBlocks[m_nbDataBlocks];  //!< ring buffer of data blocks indexed by frame affinity
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-24 08:43:15 +02:00
										 |  |  |     void startWork(); | 
					
						
							|  |  |  |     void stopWork(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void run(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							|  |  |  |     void handleInputMessages(); | 
					
						
							| 
									
										
										
										
											2018-08-26 17:22:22 +02:00
										 |  |  |     void readPendingDatagrams(); | 
					
						
							| 
									
										
										
										
											2018-08-24 08:43:15 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* SDRDAEMON_CHANNEL_SDRDAEMONCHANNELSOURCETHREAD_H_ */
 |