1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-25 12:12:02 -05:00
sdrangel/plugins/channelrx/demodlora/lorademod.h

153 lines
4.8 KiB
C
Raw Normal View History

2015-01-10 19:12:58 -05: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 //
// //
// 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
#include <QMutex>
2015-01-10 19:12:58 -05:00
#include <vector>
2017-10-07 19:42:18 -04:00
#include "dsp/basebandsamplesink.h"
#include "channel/channelsinkapi.h"
2015-01-10 19:12:58 -05:00
#include "dsp/nco.h"
#include "dsp/interpolator.h"
#include "util/message.h"
2015-01-11 14:30:48 -05:00
#include "dsp/fftfilt.h"
2015-01-10 19:12:58 -05:00
2017-10-07 19:42:18 -04:00
#include "lorademodsettings.h"
2015-01-17 10:59:44 -05:00
#define DATA_BITS (6)
#define SAMPLEBITS (DATA_BITS + 2)
#define SPREADFACTOR (1 << SAMPLEBITS)
#define LORA_SFFT_LEN (SPREADFACTOR / 2)
2015-02-12 04:37:08 -05:00
#define LORA_SQUELCH (3)
2015-01-11 14:30:48 -05:00
2017-10-07 19:42:18 -04:00
class DeviceSourceAPI;
class ThreadedBasebandSampleSink;
class DownChannelizer;
class LoRaDemod : public BasebandSampleSink, public ChannelSinkAPI {
2015-01-10 19:12:58 -05:00
public:
2017-10-07 19:42:18 -04: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)
{ }
};
LoRaDemod(DeviceSourceAPI* deviceAPI);
2015-08-17 02:29:34 -04:00
virtual ~LoRaDemod();
2017-12-17 17:15:42 -05:00
virtual void destroy() { delete this; }
2017-10-07 19:42:18 -04:00
void setSpectrumSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; }
2015-01-10 19:12:58 -05:00
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO);
2015-08-17 02:29:34 -04:00
virtual void start();
virtual void stop();
virtual bool handleMessage(const Message& cmd);
2015-01-10 19:12:58 -05:00
virtual void getIdentifier(QString& id) { id = objectName(); }
virtual void getTitle(QString& title) { title = m_settings.m_title; }
2017-12-17 17:15:42 -05:00
virtual qint64 getCenterFrequency() const { return 0; }
virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data);
static const QString m_channelIdURI;
static const QString m_channelId;
2015-01-10 19:12:58 -05:00
private:
2015-01-20 19:53:00 -05:00
int detect(Complex sample, Complex angle);
2015-01-25 12:27:20 -05:00
void dumpRaw(void);
2015-01-22 17:30:55 -05:00
short synch (short bin);
short toGray(short bin);
2015-02-12 04:37:08 -05:00
void interleave6(char* inout, int size);
void hamming6(char* inout, int size);
void prng6(char* inout, int size);
2015-02-05 14:38:46 -05:00
2017-10-07 19:42:18 -04:00
DeviceSourceAPI *m_deviceAPI;
ThreadedBasebandSampleSink* m_threadedChannelizer;
DownChannelizer* m_channelizer;
LoRaDemodSettings m_settings;
2015-01-10 19:12:58 -05:00
Real m_Bandwidth;
int m_sampleRate;
int m_frequency;
2015-01-11 07:27:11 -05:00
int m_chirp;
2015-01-10 19:12:58 -05:00
int m_angle;
2015-01-12 14:59:45 -05:00
int m_bin;
2015-01-13 14:14:36 -05:00
int m_result;
int m_count;
2015-01-17 10:59:44 -05:00
int m_header;
2015-01-22 17:30:55 -05:00
int m_time;
short m_tune;
2015-01-10 19:12:58 -05:00
2015-01-11 14:30:48 -05:00
sfft* loraFilter;
2015-01-13 19:48:48 -05:00
sfft* negaFilter;
2015-01-20 19:53:00 -05:00
float* mov;
2015-01-22 17:30:55 -05:00
short* history;
2015-01-27 19:02:49 -05:00
short* finetune;
2015-01-11 14:30:48 -05:00
2015-01-10 19:12:58 -05:00
NCO m_nco;
Interpolator m_interpolator;
Real m_sampleDistanceRemain;
BasebandSampleSink* m_sampleSink;
2015-01-10 19:12:58 -05:00
SampleVector m_sampleBuffer;
QMutex m_settingsMutex;
2015-01-10 19:12:58 -05:00
};
#endif // INCLUDE_LoRaDEMOD_H