| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
 | 
					
						
							|  |  |  | // (C) 2015 John Greb                                                            //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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-01-11 00:12:58 +00: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 INCLUDE_LoRaDEMOD_H
 | 
					
						
							|  |  |  | #define INCLUDE_LoRaDEMOD_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 23:23:45 +02:00
										 |  |  | #include <QMutex>
 | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2017-10-08 01:42:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-01-11 00:12:58 +00:00
										 |  |  | #include "dsp/nco.h"
 | 
					
						
							|  |  |  | #include "dsp/interpolator.h"
 | 
					
						
							|  |  |  | #include "util/message.h"
 | 
					
						
							| 
									
										
										
										
											2015-01-11 19:30:48 +00:00
										 |  |  | #include "dsp/fftfilt.h"
 | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-08 01:42:18 +02:00
										 |  |  | #include "lorademodsettings.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-17 15:59:44 +00:00
										 |  |  | #define DATA_BITS (6)
 | 
					
						
							|  |  |  | #define SAMPLEBITS (DATA_BITS + 2)
 | 
					
						
							|  |  |  | #define SPREADFACTOR (1 << SAMPLEBITS)
 | 
					
						
							|  |  |  | #define LORA_SFFT_LEN (SPREADFACTOR / 2)
 | 
					
						
							| 
									
										
										
										
											2015-02-12 09:37:08 +00:00
										 |  |  | #define LORA_SQUELCH (3)
 | 
					
						
							| 
									
										
										
										
											2015-01-11 19:30:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | class DeviceAPI; | 
					
						
							| 
									
										
										
										
											2017-10-08 01:42:18 +02:00
										 |  |  | class ThreadedBasebandSampleSink; | 
					
						
							|  |  |  | class DownChannelizer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 17:27:12 +02:00
										 |  |  | class LoRaDemod : public BasebandSampleSink, public ChannelAPI { | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-10-08 01:42:18 +02:00
										 |  |  |     class MsgConfigureLoRaDemod : public Message { | 
					
						
							|  |  |  |         MESSAGE_CLASS_DECLARATION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         const LoRaDemodSettings& getSettings() const { return m_settings; } | 
					
						
							|  |  |  |         bool getForce() const { return m_force; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static MsgConfigureLoRaDemod* create(const LoRaDemodSettings& settings, bool force) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return new MsgConfigureLoRaDemod(settings, force); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         LoRaDemodSettings m_settings; | 
					
						
							|  |  |  |         bool m_force; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         MsgConfigureLoRaDemod(const LoRaDemodSettings& settings, bool force) : | 
					
						
							|  |  |  |             Message(), | 
					
						
							|  |  |  |             m_settings(settings), | 
					
						
							|  |  |  |             m_force(force) | 
					
						
							|  |  |  |         { } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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
										 |  |  | 	LoRaDemod(DeviceAPI* deviceAPI); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	virtual ~LoRaDemod(); | 
					
						
							| 
									
										
										
										
											2017-12-17 23:15:42 +01:00
										 |  |  | 	virtual void destroy() { delete this; } | 
					
						
							| 
									
										
										
										
											2017-10-08 01:42:18 +02:00
										 |  |  | 	void setSpectrumSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; } | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-25 08:24:23 +02:00
										 |  |  | 	virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO); | 
					
						
							| 
									
										
										
										
											2015-08-17 08:29:34 +02:00
										 |  |  | 	virtual void start(); | 
					
						
							|  |  |  | 	virtual void stop(); | 
					
						
							|  |  |  | 	virtual bool handleMessage(const Message& cmd); | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 0; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  |     static const QString m_channelIdURI; | 
					
						
							|  |  |  |     static const QString m_channelId; | 
					
						
							| 
									
										
										
										
											2017-11-08 14:23:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2015-01-21 00:53:00 +00:00
										 |  |  | 	int  detect(Complex sample, Complex angle); | 
					
						
							| 
									
										
										
										
											2015-01-25 17:27:20 +00:00
										 |  |  | 	void dumpRaw(void); | 
					
						
							| 
									
										
										
										
											2015-01-22 22:30:55 +00:00
										 |  |  | 	short synch (short bin); | 
					
						
							|  |  |  | 	short toGray(short bin); | 
					
						
							| 
									
										
										
										
											2015-02-12 09:37:08 +00:00
										 |  |  | 	void interleave6(char* inout, int size); | 
					
						
							|  |  |  | 	void hamming6(char* inout, int size); | 
					
						
							|  |  |  | 	void prng6(char* inout, int size); | 
					
						
							| 
									
										
										
										
											2015-02-05 19:38:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-08 22:11:53 +02:00
										 |  |  | 	DeviceAPI *m_deviceAPI; | 
					
						
							| 
									
										
										
										
											2017-10-08 01:42:18 +02:00
										 |  |  |     ThreadedBasebandSampleSink* m_threadedChannelizer; | 
					
						
							|  |  |  |     DownChannelizer* m_channelizer; | 
					
						
							|  |  |  |     LoRaDemodSettings m_settings; | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Real m_Bandwidth; | 
					
						
							|  |  |  | 	int m_sampleRate; | 
					
						
							|  |  |  | 	int m_frequency; | 
					
						
							| 
									
										
										
										
											2015-01-11 12:27:11 +00:00
										 |  |  | 	int m_chirp; | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | 	int m_angle; | 
					
						
							| 
									
										
										
										
											2015-01-12 19:59:45 +00:00
										 |  |  | 	int m_bin; | 
					
						
							| 
									
										
										
										
											2015-01-13 19:14:36 +00:00
										 |  |  | 	int m_result; | 
					
						
							|  |  |  | 	int m_count; | 
					
						
							| 
									
										
										
										
											2015-01-17 15:59:44 +00:00
										 |  |  | 	int m_header; | 
					
						
							| 
									
										
										
										
											2015-01-22 22:30:55 +00:00
										 |  |  | 	int m_time; | 
					
						
							|  |  |  | 	short m_tune; | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-11 19:30:48 +00:00
										 |  |  | 	sfft* loraFilter; | 
					
						
							| 
									
										
										
										
											2015-01-14 00:48:48 +00:00
										 |  |  | 	sfft* negaFilter; | 
					
						
							| 
									
										
										
										
											2015-01-21 00:53:00 +00:00
										 |  |  | 	float* mov; | 
					
						
							| 
									
										
										
										
											2015-01-22 22:30:55 +00:00
										 |  |  | 	short* history; | 
					
						
							| 
									
										
										
										
											2015-01-28 00:02:49 +00:00
										 |  |  | 	short* finetune; | 
					
						
							| 
									
										
										
										
											2015-01-11 19:30:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | 	NCO m_nco; | 
					
						
							|  |  |  | 	Interpolator m_interpolator; | 
					
						
							|  |  |  | 	Real m_sampleDistanceRemain; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 22:29:04 +02:00
										 |  |  | 	BasebandSampleSink* m_sampleSink; | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | 	SampleVector m_sampleBuffer; | 
					
						
							| 
									
										
										
										
											2015-08-24 23:23:45 +02:00
										 |  |  | 	QMutex m_settingsMutex; | 
					
						
							| 
									
										
										
										
											2015-01-11 00:12:58 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_LoRaDEMOD_H
 |