mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-27 02:09:14 -05:00
LoRa demod: separate GUI and demod
This commit is contained in:
parent
26d7fe8d86
commit
e92b9a1114
@ -16,23 +16,29 @@
|
|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "../../channelrx/demodlora/lorademod.h"
|
|
||||||
|
|
||||||
#include <dsp/downchannelizer.h>
|
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "../../channelrx/demodlora/lorabits.h"
|
|
||||||
|
#include <dsp/downchannelizer.h>
|
||||||
|
#include "dsp/threadedbasebandsamplesink.h"
|
||||||
|
#include <device/devicesourceapi.h>
|
||||||
|
|
||||||
|
#include "lorademod.h"
|
||||||
|
#include "lorabits.h"
|
||||||
|
|
||||||
MESSAGE_CLASS_DEFINITION(LoRaDemod::MsgConfigureLoRaDemod, Message)
|
MESSAGE_CLASS_DEFINITION(LoRaDemod::MsgConfigureLoRaDemod, Message)
|
||||||
|
MESSAGE_CLASS_DEFINITION(LoRaDemod::MsgConfigureChannelizer, Message)
|
||||||
|
|
||||||
LoRaDemod::LoRaDemod(BasebandSampleSink* sampleSink) :
|
LoRaDemod::LoRaDemod(DeviceSourceAPI* deviceAPI) :
|
||||||
m_sampleSink(sampleSink),
|
m_deviceAPI(deviceAPI),
|
||||||
|
m_sampleSink(0),
|
||||||
m_settingsMutex(QMutex::Recursive)
|
m_settingsMutex(QMutex::Recursive)
|
||||||
{
|
{
|
||||||
setObjectName("LoRaDemod");
|
setObjectName("LoRaDemod");
|
||||||
|
|
||||||
m_Bandwidth = 7813;
|
m_Bandwidth = LoRaDemodSettings::bandwidths[0];
|
||||||
m_sampleRate = 96000;
|
m_sampleRate = 96000;
|
||||||
m_frequency = 0;
|
m_frequency = 0;
|
||||||
m_nco.setFreq(m_frequency, m_sampleRate);
|
m_nco.setFreq(m_frequency, m_sampleRate);
|
||||||
@ -48,6 +54,10 @@ LoRaDemod::LoRaDemod(BasebandSampleSink* sampleSink) :
|
|||||||
m_time = 0;
|
m_time = 0;
|
||||||
m_tune = 0;
|
m_tune = 0;
|
||||||
|
|
||||||
|
m_channelizer = new DownChannelizer(this);
|
||||||
|
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer);
|
||||||
|
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
||||||
|
|
||||||
loraFilter = new sfft(LORA_SFFT_LEN);
|
loraFilter = new sfft(LORA_SFFT_LEN);
|
||||||
negaFilter = new sfft(LORA_SFFT_LEN);
|
negaFilter = new sfft(LORA_SFFT_LEN);
|
||||||
|
|
||||||
@ -68,12 +78,10 @@ LoRaDemod::~LoRaDemod()
|
|||||||
delete [] history;
|
delete [] history;
|
||||||
if (finetune)
|
if (finetune)
|
||||||
delete [] finetune;
|
delete [] finetune;
|
||||||
}
|
|
||||||
|
|
||||||
void LoRaDemod::configure(MessageQueue* messageQueue, Real Bandwidth)
|
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
||||||
{
|
delete m_threadedChannelizer;
|
||||||
Message* cmd = MsgConfigureLoRaDemod::create(Bandwidth);
|
delete m_channelizer;
|
||||||
messageQueue->push(cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaDemod::dumpRaw()
|
void LoRaDemod::dumpRaw()
|
||||||
@ -302,18 +310,34 @@ bool LoRaDemod::handleMessage(const Message& cmd)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (MsgConfigureChannelizer::match(cmd))
|
||||||
|
{
|
||||||
|
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
|
||||||
|
|
||||||
|
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
||||||
|
cfg.getSampleRate(),
|
||||||
|
cfg.getCenterFrequency());
|
||||||
|
|
||||||
|
qDebug() << "LoRaDemod::handleMessage: MsgConfigureChannelizer: sampleRate: " << cfg.getSampleRate()
|
||||||
|
<< " centerFrequency: " << cfg.getCenterFrequency();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
else if (MsgConfigureLoRaDemod::match(cmd))
|
else if (MsgConfigureLoRaDemod::match(cmd))
|
||||||
{
|
{
|
||||||
MsgConfigureLoRaDemod& cfg = (MsgConfigureLoRaDemod&) cmd;
|
MsgConfigureLoRaDemod& cfg = (MsgConfigureLoRaDemod&) cmd;
|
||||||
|
|
||||||
m_settingsMutex.lock();
|
m_settingsMutex.lock();
|
||||||
|
|
||||||
m_Bandwidth = cfg.getBandwidth();
|
LoRaDemodSettings settings = cfg.getSettings();
|
||||||
|
|
||||||
|
m_Bandwidth = LoRaDemodSettings::bandwidths[settings.m_bandwidthIndex];
|
||||||
m_interpolator.create(16, m_sampleRate, m_Bandwidth/1.9);
|
m_interpolator.create(16, m_sampleRate, m_Bandwidth/1.9);
|
||||||
|
|
||||||
m_settingsMutex.unlock();
|
m_settingsMutex.unlock();
|
||||||
|
|
||||||
qDebug() << " MsgConfigureLoRaDemod: m_Bandwidth: " << m_Bandwidth;
|
m_settings = settings;
|
||||||
|
qDebug() << "LoRaDemod::handleMessage: MsgConfigureLoRaDemod: m_Bandwidth: " << m_Bandwidth;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -18,26 +18,78 @@
|
|||||||
#ifndef INCLUDE_LoRaDEMOD_H
|
#ifndef INCLUDE_LoRaDEMOD_H
|
||||||
#define INCLUDE_LoRaDEMOD_H
|
#define INCLUDE_LoRaDEMOD_H
|
||||||
|
|
||||||
#include <dsp/basebandsamplesink.h>
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <dsp/basebandsamplesink.h>
|
||||||
#include "dsp/nco.h"
|
#include "dsp/nco.h"
|
||||||
#include "dsp/interpolator.h"
|
#include "dsp/interpolator.h"
|
||||||
#include "util/message.h"
|
#include "util/message.h"
|
||||||
#include "dsp/fftfilt.h"
|
#include "dsp/fftfilt.h"
|
||||||
|
|
||||||
|
#include "lorademodsettings.h"
|
||||||
|
|
||||||
#define DATA_BITS (6)
|
#define DATA_BITS (6)
|
||||||
#define SAMPLEBITS (DATA_BITS + 2)
|
#define SAMPLEBITS (DATA_BITS + 2)
|
||||||
#define SPREADFACTOR (1 << SAMPLEBITS)
|
#define SPREADFACTOR (1 << SAMPLEBITS)
|
||||||
#define LORA_SFFT_LEN (SPREADFACTOR / 2)
|
#define LORA_SFFT_LEN (SPREADFACTOR / 2)
|
||||||
#define LORA_SQUELCH (3)
|
#define LORA_SQUELCH (3)
|
||||||
|
|
||||||
|
class DeviceSourceAPI;
|
||||||
|
class ThreadedBasebandSampleSink;
|
||||||
|
class DownChannelizer;
|
||||||
|
|
||||||
class LoRaDemod : public BasebandSampleSink {
|
class LoRaDemod : public BasebandSampleSink {
|
||||||
public:
|
public:
|
||||||
LoRaDemod(BasebandSampleSink* sampleSink);
|
class MsgConfigureLoRaDemod : public Message {
|
||||||
virtual ~LoRaDemod();
|
MESSAGE_CLASS_DECLARATION
|
||||||
|
|
||||||
void configure(MessageQueue* messageQueue, Real Bandwidth);
|
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);
|
||||||
|
virtual ~LoRaDemod();
|
||||||
|
void setSpectrumSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; }
|
||||||
|
|
||||||
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO);
|
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO);
|
||||||
virtual void start();
|
virtual void start();
|
||||||
@ -53,26 +105,10 @@ private:
|
|||||||
void hamming6(char* inout, int size);
|
void hamming6(char* inout, int size);
|
||||||
void prng6(char* inout, int size);
|
void prng6(char* inout, int size);
|
||||||
|
|
||||||
class MsgConfigureLoRaDemod : public Message {
|
DeviceSourceAPI *m_deviceAPI;
|
||||||
MESSAGE_CLASS_DECLARATION
|
ThreadedBasebandSampleSink* m_threadedChannelizer;
|
||||||
|
DownChannelizer* m_channelizer;
|
||||||
public:
|
LoRaDemodSettings m_settings;
|
||||||
Real getBandwidth() const { return m_Bandwidth; }
|
|
||||||
|
|
||||||
static MsgConfigureLoRaDemod* create(Real Bandwidth)
|
|
||||||
{
|
|
||||||
return new MsgConfigureLoRaDemod(Bandwidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Real m_Bandwidth;
|
|
||||||
|
|
||||||
MsgConfigureLoRaDemod(Real Bandwidth) :
|
|
||||||
Message(),
|
|
||||||
m_Bandwidth(Bandwidth)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Real m_Bandwidth;
|
Real m_Bandwidth;
|
||||||
int m_sampleRate;
|
int m_sampleRate;
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
#include "dsp/threadedbasebandsamplesink.h"
|
|
||||||
#include "ui_lorademodgui.h"
|
|
||||||
#include "ui_lorademodgui.h"
|
#include "ui_lorademodgui.h"
|
||||||
#include "dsp/spectrumvis.h"
|
#include "dsp/spectrumvis.h"
|
||||||
#include "gui/glspectrum.h"
|
#include "gui/glspectrum.h"
|
||||||
@ -137,21 +135,19 @@ LoRaDemodGUI::LoRaDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWi
|
|||||||
connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));
|
connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));
|
||||||
|
|
||||||
m_spectrumVis = new SpectrumVis(ui->glSpectrum);
|
m_spectrumVis = new SpectrumVis(ui->glSpectrum);
|
||||||
m_LoRaDemod = new LoRaDemod(m_spectrumVis);
|
m_LoRaDemod = new LoRaDemod(m_deviceAPI);
|
||||||
m_channelizer = new DownChannelizer(m_LoRaDemod);
|
m_LoRaDemod->setSpectrumSink(m_spectrumVis);
|
||||||
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer);
|
|
||||||
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
|
||||||
|
|
||||||
ui->glSpectrum->setCenterFrequency(16000);
|
ui->glSpectrum->setCenterFrequency(16000);
|
||||||
ui->glSpectrum->setSampleRate(32000);
|
ui->glSpectrum->setSampleRate(32000);
|
||||||
ui->glSpectrum->setDisplayWaterfall(true);
|
ui->glSpectrum->setDisplayWaterfall(true);
|
||||||
ui->glSpectrum->setDisplayMaxHold(true);
|
ui->glSpectrum->setDisplayMaxHold(true);
|
||||||
|
|
||||||
setTitleColor(Qt::magenta);
|
// setTitleColor(Qt::magenta);
|
||||||
|
//
|
||||||
m_channelMarker.setColor(Qt::magenta);
|
// m_channelMarker.setColor(Qt::magenta);
|
||||||
m_channelMarker.setBandwidth(LoRaDemodSettings::bandwidths[0]);
|
// m_channelMarker.setBandwidth(LoRaDemodSettings::bandwidths[0]);
|
||||||
m_channelMarker.setCenterFrequency(0);
|
// m_channelMarker.setCenterFrequency(0);
|
||||||
m_channelMarker.setVisible(true);
|
m_channelMarker.setVisible(true);
|
||||||
|
|
||||||
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged()));
|
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged()));
|
||||||
@ -160,17 +156,18 @@ LoRaDemodGUI::LoRaDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWi
|
|||||||
m_deviceAPI->addChannelMarker(&m_channelMarker);
|
m_deviceAPI->addChannelMarker(&m_channelMarker);
|
||||||
m_deviceAPI->addRollupWidget(this);
|
m_deviceAPI->addRollupWidget(this);
|
||||||
|
|
||||||
ui->spectrumGUI->setBuddies(m_channelizer->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
|
ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
|
||||||
|
|
||||||
applySettings();
|
m_settings.setChannelMarker(&m_channelMarker);
|
||||||
|
m_settings.setSpectrumGUI(ui->spectrumGUI);
|
||||||
|
|
||||||
|
displaySettings();
|
||||||
|
applySettings(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoRaDemodGUI::~LoRaDemodGUI()
|
LoRaDemodGUI::~LoRaDemodGUI()
|
||||||
{
|
{
|
||||||
m_deviceAPI->removeChannelInstance(this);
|
m_deviceAPI->removeChannelInstance(this);
|
||||||
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
|
||||||
delete m_threadedChannelizer;
|
|
||||||
delete m_channelizer;
|
|
||||||
delete m_LoRaDemod;
|
delete m_LoRaDemod;
|
||||||
delete m_spectrumVis;
|
delete m_spectrumVis;
|
||||||
delete ui;
|
delete ui;
|
||||||
@ -185,11 +182,15 @@ void LoRaDemodGUI::applySettings(bool force)
|
|||||||
{
|
{
|
||||||
if (m_doApplySettings)
|
if (m_doApplySettings)
|
||||||
{
|
{
|
||||||
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
setTitleColor(m_channelMarker.getColor());
|
||||||
|
|
||||||
|
LoRaDemod::MsgConfigureChannelizer* channelConfigMsg = LoRaDemod::MsgConfigureChannelizer::create(
|
||||||
LoRaDemodSettings::bandwidths[m_settings.m_bandwidthIndex],
|
LoRaDemodSettings::bandwidths[m_settings.m_bandwidthIndex],
|
||||||
m_channelMarker.getCenterFrequency());
|
m_channelMarker.getCenterFrequency());
|
||||||
|
m_LoRaDemod->getInputMessageQueue()->push(channelConfigMsg);
|
||||||
|
|
||||||
m_LoRaDemod->configure(m_LoRaDemod->getInputMessageQueue(), m_settings.m_bandwidthIndex);
|
LoRaDemod::MsgConfigureLoRaDemod* message = LoRaDemod::MsgConfigureLoRaDemod::create( m_settings, force);
|
||||||
|
m_LoRaDemod->getInputMessageQueue()->push(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,4 +202,11 @@ void LoRaDemodGUI::displaySettings()
|
|||||||
ui->BW->setValue(m_settings.m_bandwidthIndex);
|
ui->BW->setValue(m_settings.m_bandwidthIndex);
|
||||||
m_channelMarker.setBandwidth(thisBW);
|
m_channelMarker.setBandwidth(thisBW);
|
||||||
blockApplySettings(false);
|
blockApplySettings(false);
|
||||||
|
|
||||||
|
m_channelMarker.blockSignals(true);
|
||||||
|
m_channelMarker.setBandwidth(thisBW);
|
||||||
|
m_channelMarker.setCenterFrequency(0);
|
||||||
|
m_channelMarker.setColor(m_settings.m_rgbColor);
|
||||||
|
setTitleColor(m_settings.m_rgbColor);
|
||||||
|
m_channelMarker.blockSignals(false);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
class PluginAPI;
|
class PluginAPI;
|
||||||
class DeviceSourceAPI;
|
class DeviceSourceAPI;
|
||||||
class ThreadedBasebandSampleSink;
|
|
||||||
class DownChannelizer;
|
|
||||||
class LoRaDemod;
|
class LoRaDemod;
|
||||||
class SpectrumVis;
|
class SpectrumVis;
|
||||||
|
|
||||||
@ -55,8 +53,6 @@ private:
|
|||||||
bool m_basicSettingsShown;
|
bool m_basicSettingsShown;
|
||||||
bool m_doApplySettings;
|
bool m_doApplySettings;
|
||||||
|
|
||||||
ThreadedBasebandSampleSink* m_threadedChannelizer;
|
|
||||||
DownChannelizer* m_channelizer;
|
|
||||||
LoRaDemod* m_LoRaDemod;
|
LoRaDemod* m_LoRaDemod;
|
||||||
SpectrumVis* m_spectrumVis;
|
SpectrumVis* m_spectrumVis;
|
||||||
MessageQueue m_inputMessageQueue;
|
MessageQueue m_inputMessageQueue;
|
||||||
|
@ -21,6 +21,7 @@ void LoRaDemodSettings::resetToDefaults()
|
|||||||
{
|
{
|
||||||
m_bandwidthIndex = 0;
|
m_bandwidthIndex = 0;
|
||||||
m_spread = 0;
|
m_spread = 0;
|
||||||
|
m_rgbColor = QColor(255, 0, 255).rgb();
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray LoRaDemodSettings::serialize() const
|
QByteArray LoRaDemodSettings::serialize() const
|
||||||
|
Loading…
Reference in New Issue
Block a user