| 
									
										
										
										
											2015-12-06 19:47:55 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015 F4EXB                                                      //
 | 
					
						
							|  |  |  | // written by Edouard Griffiths                                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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.                                           //
 | 
					
						
							| 
									
										
										
										
											2015-12-06 19:47:55 +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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 08:55:58 +01:00
										 |  |  | #ifndef INCLUDE_UDPSRC_H
 | 
					
						
							|  |  |  | #define INCLUDE_UDPSRC_H
 | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include <QHostAddress>
 | 
					
						
							| 
									
										
										
										
											2018-12-24 10:27:35 +01:00
										 |  |  | #include <QNetworkRequest>
 | 
					
						
							| 
									
										
										
										
											2017-11-19 18:18:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "dsp/basebandsamplesink.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  | #include "channel/channelapi.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | #include "dsp/nco.h"
 | 
					
						
							|  |  |  | #include "dsp/fftfilt.h"
 | 
					
						
							|  |  |  | #include "dsp/interpolator.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-04 03:44:06 +02:00
										 |  |  | #include "dsp/phasediscri.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-17 20:23:17 +02:00
										 |  |  | #include "dsp/movingaverage.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:32:40 +02:00
										 |  |  | #include "dsp/agc.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-20 22:18:33 +02:00
										 |  |  | #include "dsp/bandpass.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-11 23:45:56 +02:00
										 |  |  | #include "util/udpsinkutil.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | #include "util/message.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-03 04:02:21 +01:00
										 |  |  | #include "audio/audiofifo.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  | #include "udpsinksettings.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-24 10:27:35 +01:00
										 |  |  | class QNetworkAccessManager; | 
					
						
							|  |  |  | class QNetworkReply; | 
					
						
							| 
									
										
										
										
											2015-12-02 02:28:31 +01:00
										 |  |  | class QUdpSocket; | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | class DeviceAPI; | 
					
						
							| 
									
										
										
										
											2017-10-04 22:41:58 +02:00
										 |  |  | class ThreadedBasebandSampleSink; | 
					
						
							|  |  |  | class DownChannelizer; | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  | class UDPSink : public BasebandSampleSink, public ChannelAPI { | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-09-12 15:46:42 +02:00
										 |  |  |     class MsgConfigureUDPSource : public Message { | 
					
						
							| 
									
										
										
										
											2017-10-07 05:44:43 +02:00
										 |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  |         const UDPSinkSettings& getSettings() const { return m_settings; } | 
					
						
							| 
									
										
										
										
											2017-10-07 05:44:43 +02:00
										 |  |  |         bool getForce() const { return m_force; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 15:46:42 +02:00
										 |  |  |         static MsgConfigureUDPSource* create(const UDPSinkSettings& settings, bool force) | 
					
						
							| 
									
										
										
										
											2017-10-07 05:44:43 +02:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-09-12 15:46:42 +02:00
										 |  |  |             return new MsgConfigureUDPSource(settings, force); | 
					
						
							| 
									
										
										
										
											2017-10-07 05:44:43 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  |         UDPSinkSettings m_settings; | 
					
						
							| 
									
										
										
										
											2017-10-07 05:44:43 +02:00
										 |  |  |         bool m_force; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 15:46:42 +02:00
										 |  |  |         MsgConfigureUDPSource(const UDPSinkSettings& settings, bool force) : | 
					
						
							| 
									
										
										
										
											2017-10-07 05:44:43 +02:00
										 |  |  |             Message(), | 
					
						
							|  |  |  |             m_settings(settings), | 
					
						
							|  |  |  |             m_force(force) | 
					
						
							| 
									
										
										
										
											2017-10-07 06:04:05 +02:00
										 |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-10-07 05:44:43 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 22:41:58 +02:00
										 |  |  |     class MsgConfigureChannelizer : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         int getSampleRate() const { return m_sampleRate; } | 
					
						
							|  |  |  |         int getCenterFrequency() const { return m_centerFrequency; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgConfigureChannelizer(sampleRate, centerFrequency); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         int m_sampleRate; | 
					
						
							|  |  |  |         int  m_centerFrequency; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgConfigureChannelizer(int sampleRate, int centerFrequency) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_sampleRate(sampleRate), | 
					
						
							|  |  |  |             m_centerFrequency(centerFrequency) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | 	UDPSink(DeviceAPI *deviceAPI); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  | 	virtual ~UDPSink(); | 
					
						
							| 
									
										
										
										
											2017-12-17 23:15:42 +01:00
										 |  |  | 	virtual void destroy() { delete this; } | 
					
						
							| 
									
										
										
										
											2017-10-04 22:05:38 +02:00
										 |  |  | 	void setSpectrum(BasebandSampleSink* spectrum) { m_spectrum = spectrum; } | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void setSpectrum(MessageQueue* messageQueue, bool enabled); | 
					
						
							| 
									
										
										
										
											2017-05-16 23:39:49 +02:00
										 |  |  | 	double getMagSq() const { return m_magsq; } | 
					
						
							| 
									
										
										
										
											2017-08-17 20:23:17 +02:00
										 |  |  | 	double getInMagSq() const { return m_inMagsq; } | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  | 	bool getSquelchOpen() const { return m_squelchOpen; } | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); | 
					
						
							|  |  |  | 	virtual void start(); | 
					
						
							|  |  |  | 	virtual void stop(); | 
					
						
							|  |  |  | 	virtual bool handleMessage(const Message& cmd); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 18:18:17 +01:00
										 |  |  |     virtual void getIdentifier(QString& id) { id = objectName(); } | 
					
						
							|  |  |  |     virtual void getTitle(QString& title) { title = m_settings.m_title; } | 
					
						
							| 
									
										
										
										
											2017-12-17 23:15:42 +01:00
										 |  |  |     virtual qint64 getCenterFrequency() const { return m_settings.m_inputFrequencyOffset; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual QByteArray serialize() const; | 
					
						
							|  |  |  |     virtual bool deserialize(const QByteArray& data); | 
					
						
							| 
									
										
										
										
											2017-11-19 18:18:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  |     virtual int getNbSinkStreams() const { return 1; } | 
					
						
							|  |  |  |     virtual int getNbSourceStreams() const { return 0; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual qint64 getStreamCenterFrequency(int streamIndex, bool sinkElseSource) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         (void) streamIndex; | 
					
						
							|  |  |  |         (void) sinkElseSource; | 
					
						
							|  |  |  |         return m_settings.m_inputFrequencyOffset; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-25 18:44:24 +02:00
										 |  |  |     virtual int webapiSettingsGet( | 
					
						
							|  |  |  |             SWGSDRangel::SWGChannelSettings& response, | 
					
						
							|  |  |  |             QString& errorMessage); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual int webapiSettingsPutPatch( | 
					
						
							|  |  |  |             bool force, | 
					
						
							|  |  |  |             const QStringList& channelSettingsKeys, | 
					
						
							|  |  |  |             SWGSDRangel::SWGChannelSettings& response, | 
					
						
							|  |  |  |             QString& errorMessage); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual int webapiReportGet( | 
					
						
							|  |  |  |             SWGSDRangel::SWGChannelReport& response, | 
					
						
							|  |  |  |             QString& errorMessage); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-01 23:21:57 +02:00
										 |  |  |     static void webapiFormatChannelSettings( | 
					
						
							|  |  |  |         SWGSDRangel::SWGChannelSettings& response, | 
					
						
							|  |  |  |         const UDPSinkSettings& settings); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static void webapiUpdateChannelSettings( | 
					
						
							|  |  |  |             UDPSinkSettings& settings, | 
					
						
							|  |  |  |             const QStringList& channelSettingsKeys, | 
					
						
							|  |  |  |             SWGSDRangel::SWGChannelSettings& response); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 01:25:17 +02:00
										 |  |  |     uint32_t getNumberOfDeviceStreams() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  |     static const QString m_channelIdURI; | 
					
						
							|  |  |  |     static const QString m_channelId; | 
					
						
							| 
									
										
										
										
											2017-08-15 16:08:12 +02:00
										 |  |  | 	static const int udpBlockSize = 512; // UDP block size in number of bytes
 | 
					
						
							| 
									
										
										
										
											2016-04-03 11:29:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-03 04:02:21 +01:00
										 |  |  | public slots: | 
					
						
							|  |  |  |     void audioReadyRead(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-24 10:27:35 +01:00
										 |  |  | private slots: | 
					
						
							|  |  |  |     void networkManagerFinished(QNetworkReply *reply); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2018-09-12 15:46:42 +02:00
										 |  |  | 	class MsgUDPSinkSpectrum : public Message { | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 		MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		bool getEnabled() const { return m_enabled; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 15:46:42 +02:00
										 |  |  | 		static MsgUDPSinkSpectrum* create(bool enabled) | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2018-09-12 15:46:42 +02:00
										 |  |  | 			return new MsgUDPSinkSpectrum(enabled); | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 		bool m_enabled; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 15:46:42 +02:00
										 |  |  | 		MsgUDPSinkSpectrum(bool enabled) : | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 			Message(), | 
					
						
							|  |  |  | 			m_enabled(enabled) | 
					
						
							|  |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  | 	struct Sample16 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	    Sample16() : m_r(0), m_i(0) {} | 
					
						
							|  |  |  | 	    Sample16(int16_t r, int16_t i) : m_r(r), m_i(i) {} | 
					
						
							|  |  |  | 	    int16_t m_r; | 
					
						
							|  |  |  | 	    int16_t m_i; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct Sample24 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  | 	    Sample24() : m_r(0), m_i(0) {} | 
					
						
							|  |  |  | 	    Sample24(int32_t r, int32_t i) : m_r(r), m_i(i) {} | 
					
						
							|  |  |  |         int32_t m_r; | 
					
						
							|  |  |  |         int32_t m_i; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  |     DeviceAPI *m_deviceAPI; | 
					
						
							| 
									
										
										
										
											2017-10-04 22:41:58 +02:00
										 |  |  |     ThreadedBasebandSampleSink* m_threadedChannelizer; | 
					
						
							|  |  |  |     DownChannelizer* m_channelizer; | 
					
						
							| 
									
										
										
										
											2017-10-04 22:05:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-29 11:04:47 +01:00
										 |  |  |     int m_inputSampleRate; | 
					
						
							|  |  |  |     int m_inputFrequencyOffset; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  |     UDPSinkSettings m_settings; | 
					
						
							| 
									
										
										
										
											2017-11-19 18:18:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-03 04:02:21 +01:00
										 |  |  | 	QUdpSocket *m_audioSocket; | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-16 23:39:49 +02:00
										 |  |  | 	double m_magsq; | 
					
						
							| 
									
										
										
										
											2017-08-17 20:23:17 +02:00
										 |  |  |     double m_inMagsq; | 
					
						
							|  |  |  |     MovingAverage<double> m_outMovingAverage; | 
					
						
							|  |  |  |     MovingAverage<double> m_inMovingAverage; | 
					
						
							| 
									
										
										
										
											2017-08-20 00:32:40 +02:00
										 |  |  |     MovingAverage<double> m_amMovingAverage; | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Real m_scale; | 
					
						
							|  |  |  | 	Complex m_last, m_this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	NCO m_nco; | 
					
						
							|  |  |  | 	Interpolator m_interpolator; | 
					
						
							|  |  |  | 	Real m_sampleDistanceRemain; | 
					
						
							| 
									
										
										
										
											2015-11-19 08:55:58 +01:00
										 |  |  | 	fftfilt* UDPFilter; | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	SampleVector m_sampleBuffer; | 
					
						
							| 
									
										
										
										
											2018-09-11 23:45:56 +02:00
										 |  |  | 	UDPSinkUtil<Sample16> *m_udpBuffer16; | 
					
						
							|  |  |  | 	UDPSinkUtil<int16_t> *m_udpBufferMono16; | 
					
						
							|  |  |  |     UDPSinkUtil<Sample24> *m_udpBuffer24; | 
					
						
							| 
									
										
										
										
											2015-12-03 04:02:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	AudioVector m_audioBuffer; | 
					
						
							|  |  |  | 	uint m_audioBufferFill; | 
					
						
							|  |  |  | 	AudioFifo m_audioFifo; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 22:29:04 +02:00
										 |  |  | 	BasebandSampleSink* m_spectrum; | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 	bool m_spectrumEnabled; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	quint32 m_nextSSBId; | 
					
						
							|  |  |  | 	quint32 m_nextS16leId; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-06 09:33:29 +02:00
										 |  |  | 	char *m_udpAudioBuf; | 
					
						
							|  |  |  | 	static const int m_udpAudioPayloadSize = 8192; //!< UDP audio samples buffer. No UDP block on Earth is larger than this
 | 
					
						
							| 
									
										
										
										
											2017-08-21 13:10:54 +02:00
										 |  |  |     static const Real m_agcTarget; | 
					
						
							| 
									
										
										
										
											2016-04-06 09:33:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-04 03:44:06 +02:00
										 |  |  |     PhaseDiscriminators m_phaseDiscri; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-07 06:30:30 +02:00
										 |  |  |     double m_squelch; | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  |     bool m_squelchOpen; | 
					
						
							|  |  |  |     int  m_squelchOpenCount; | 
					
						
							|  |  |  |     int  m_squelchCloseCount; | 
					
						
							| 
									
										
										
										
											2017-08-20 23:44:40 +02:00
										 |  |  |     int  m_squelchGate; //!< number of samples computed from given gate
 | 
					
						
							|  |  |  |     int  m_squelchRelease; | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 00:32:40 +02:00
										 |  |  |     MagAGC m_agc; | 
					
						
							| 
									
										
										
										
											2017-08-20 22:18:33 +02:00
										 |  |  |     Bandpass<double> m_bandpass; | 
					
						
							| 
									
										
										
										
											2017-08-20 00:32:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-24 10:27:35 +01:00
										 |  |  |     QNetworkAccessManager *m_networkManager; | 
					
						
							|  |  |  |     QNetworkRequest m_networkRequest; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | 	QMutex m_settingsMutex; | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-09 00:59:10 +01:00
										 |  |  |     void applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force = true); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  |     void applySettings(const UDPSinkSettings& settings, bool force = false); | 
					
						
							| 
									
										
										
										
											2017-08-19 00:12:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-25 10:45:40 +02:00
										 |  |  |     void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response); | 
					
						
							| 
									
										
										
										
											2018-12-24 10:27:35 +01:00
										 |  |  |     void webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const UDPSinkSettings& settings, bool force); | 
					
						
							| 
									
										
										
										
											2018-05-25 10:45:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  |     inline void calculateSquelch(double value) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-10-07 06:30:30 +02:00
										 |  |  |         if ((!m_settings.m_squelchEnabled) || (value > m_squelch)) | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-08-20 23:44:40 +02:00
										 |  |  |             if (m_squelchGate == 0) | 
					
						
							| 
									
										
										
										
											2017-08-19 00:12:56 +02:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  |                 m_squelchOpen = true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-08-19 00:12:56 +02:00
										 |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2017-08-20 23:44:40 +02:00
										 |  |  |                 if (m_squelchOpenCount < m_squelchGate) | 
					
						
							| 
									
										
										
										
											2017-08-19 00:12:56 +02:00
										 |  |  |                 { | 
					
						
							|  |  |  |                     m_squelchOpenCount++; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2017-08-20 23:44:40 +02:00
										 |  |  |                     m_squelchCloseCount = m_squelchRelease; | 
					
						
							| 
									
										
										
										
											2017-08-19 00:12:56 +02:00
										 |  |  |                     m_squelchOpen = true; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2017-08-20 23:44:40 +02:00
										 |  |  |             if (m_squelchGate == 0) | 
					
						
							| 
									
										
										
										
											2017-08-19 00:12:56 +02:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  |                 m_squelchOpen = false; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-08-19 00:12:56 +02:00
										 |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (m_squelchCloseCount > 0) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     m_squelchCloseCount--; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     m_squelchOpenCount = 0; | 
					
						
							|  |  |  |                     m_squelchOpen = false; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inline void initSquelch(bool open) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (open) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_squelchOpen = true; | 
					
						
							| 
									
										
										
										
											2017-08-20 23:44:40 +02:00
										 |  |  |             m_squelchOpenCount = m_squelchGate; | 
					
						
							|  |  |  |             m_squelchCloseCount = m_squelchRelease; | 
					
						
							| 
									
										
										
										
											2017-08-18 00:10:15 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             m_squelchOpen = false; | 
					
						
							|  |  |  |             m_squelchOpenCount = 0; | 
					
						
							|  |  |  |             m_squelchCloseCount = 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |     void udpWrite(FixReal real, FixReal imag) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (SDR_RX_SAMP_SZ == 16) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  |             if (m_settings.m_sampleFormat == UDPSinkSettings::FormatIQ16) { | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |                 m_udpBuffer16->write(Sample16(real, imag)); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  |             } else if (m_settings.m_sampleFormat == UDPSinkSettings::FormatIQ24) { | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |                 m_udpBuffer24->write(Sample24(real<<8, imag<<8)); | 
					
						
							| 
									
										
										
										
											2018-04-19 13:34:22 +02:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 m_udpBuffer16->write(Sample16(real, imag)); | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else if (SDR_RX_SAMP_SZ == 24) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  |             if (m_settings.m_sampleFormat == UDPSinkSettings::FormatIQ16) { | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |                 m_udpBuffer16->write(Sample16(real>>8, imag>>8)); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:08:47 +02:00
										 |  |  |             } else if (m_settings.m_sampleFormat == UDPSinkSettings::FormatIQ24) { | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |                 m_udpBuffer24->write(Sample24(real, imag)); | 
					
						
							| 
									
										
										
										
											2018-04-19 13:34:22 +02:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2018-05-25 10:45:40 +02:00
										 |  |  |                 m_udpBuffer16->write(Sample16(real>>8, imag>>8)); | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void udpWriteMono(FixReal sample) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (SDR_RX_SAMP_SZ == 16) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-04-19 13:34:22 +02:00
										 |  |  |             m_udpBufferMono16->write(sample); | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         else if (SDR_RX_SAMP_SZ == 24) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-04-19 13:34:22 +02:00
										 |  |  |             m_udpBufferMono16->write(sample>>8); | 
					
						
							| 
									
										
										
										
											2018-01-28 02:30:15 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-28 03:06:30 +01:00
										 |  |  |     void udpWriteNorm(Real real, Real imag) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-19 13:34:22 +02:00
										 |  |  |         m_udpBuffer16->write(Sample16(real*32768.0, imag*32768.0)); | 
					
						
							| 
									
										
										
										
											2018-01-28 03:06:30 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void udpWriteNormMono(Real sample) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-19 13:34:22 +02:00
										 |  |  |         m_udpBufferMono16->write(sample*32768.0); | 
					
						
							| 
									
										
										
										
											2018-01-28 03:06:30 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 03:27:37 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 08:55:58 +01:00
										 |  |  | #endif // INCLUDE_UDPSRC_H
 |