From 26d7fe8d86d7c7741c832f1873b3c137c235003c Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 8 Oct 2017 00:28:42 +0200 Subject: [PATCH] LoRa demod: use settings in GUI --- plugins/channelrx/demodlora/lorademodgui.cpp | 104 +++++++----------- plugins/channelrx/demodlora/lorademodgui.h | 6 +- plugins/channelrx/demodlora/lorademodgui.ui | 2 +- .../channelrx/demodlora/lorademodsettings.cpp | 9 +- .../channelrx/demodlora/lorademodsettings.h | 5 +- 5 files changed, 55 insertions(+), 71 deletions(-) diff --git a/plugins/channelrx/demodlora/lorademodgui.cpp b/plugins/channelrx/demodlora/lorademodgui.cpp index 94d528c81..926dc3ee5 100644 --- a/plugins/channelrx/demodlora/lorademodgui.cpp +++ b/plugins/channelrx/demodlora/lorademodgui.cpp @@ -1,12 +1,10 @@ -#include "../../channelrx/demodlora/lorademodgui.h" -#include "../../channelrx/demodlora/lorademodgui.h" #include #include #include #include -#include "../../../sdrbase/dsp/threadedbasebandsamplesink.h" +#include "dsp/threadedbasebandsamplesink.h" #include "ui_lorademodgui.h" #include "ui_lorademodgui.h" #include "dsp/spectrumvis.h" @@ -15,7 +13,9 @@ #include "util/simpleserializer.h" #include "gui/basicchannelsettingswidget.h" #include "dsp/dspengine.h" -#include "../../channelrx/demodlora/lorademod.h" + +#include "lorademod.h" +#include "lorademodgui.h" const QString LoRaDemodGUI::m_channelID = "de.maintech.sdrangelove.channel.lora"; @@ -52,63 +52,26 @@ void LoRaDemodGUI::setCenterFrequency(qint64 centerFrequency) void LoRaDemodGUI::resetToDefaults() { - blockApplySettings(true); - - ui->BW->setValue(0); - ui->Spread->setValue(0); - - blockApplySettings(false); - applySettings(); + m_settings.resetToDefaults(); + displaySettings(); + applySettings(true); } QByteArray LoRaDemodGUI::serialize() const { - SimpleSerializer s(1); - s.writeS32(1, m_channelMarker.getCenterFrequency()); - s.writeS32(2, ui->BW->value()); - s.writeS32(3, ui->Spread->value()); - s.writeBlob(4, ui->spectrumGUI->serialize()); - return s.final(); + return m_settings.serialize(); } bool LoRaDemodGUI::deserialize(const QByteArray& data) { - SimpleDeserializer d(data); - - if(!d.isValid()) - { - resetToDefaults(); - return false; - } - - if(d.getVersion() == 1) - { - QByteArray bytetmp; - qint32 tmp; - - blockApplySettings(true); - m_channelMarker.blockSignals(true); - - d.readS32(1, &tmp, 0); - m_channelMarker.setCenterFrequency(tmp); - d.readS32(2, &tmp, 0); - ui->BW->setValue(tmp); - d.readS32(3, &tmp, 0); - ui->Spread->setValue(tmp); - d.readBlob(4, &bytetmp); - ui->spectrumGUI->deserialize(bytetmp); - - blockApplySettings(false); - m_channelMarker.blockSignals(false); - - applySettings(); - return true; - } - else - { - resetToDefaults(); - return false; - } + if(m_settings.deserialize(data)) { + displaySettings(); + applySettings(true); + return true; + } else { + resetToDefaults(); + return false; + } } bool LoRaDemodGUI::handleMessage(const Message& message __attribute__((unused))) @@ -123,10 +86,18 @@ void LoRaDemodGUI::viewChanged() void LoRaDemodGUI::on_BW_valueChanged(int value) { - const int loraBW[] = BANDWIDTHSTRING; - int thisBW = loraBW[value]; + if (value < 0) { + m_settings.m_bandwidthIndex = 0; + } else if (value < LoRaDemodSettings::nb_bandwidths) { + m_settings.m_bandwidthIndex = value; + } else { + m_settings.m_bandwidthIndex = LoRaDemodSettings::nb_bandwidths - 1; + } + + int thisBW = LoRaDemodSettings::bandwidths[value]; ui->BWText->setText(QString("%1 Hz").arg(thisBW)); m_channelMarker.setBandwidth(thisBW); + applySettings(); } @@ -178,9 +149,8 @@ LoRaDemodGUI::LoRaDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWi setTitleColor(Qt::magenta); - //m_channelMarker = new ChannelMarker(this); m_channelMarker.setColor(Qt::magenta); - m_channelMarker.setBandwidth(7813); + m_channelMarker.setBandwidth(LoRaDemodSettings::bandwidths[0]); m_channelMarker.setCenterFrequency(0); m_channelMarker.setVisible(true); @@ -203,7 +173,6 @@ LoRaDemodGUI::~LoRaDemodGUI() delete m_channelizer; delete m_LoRaDemod; delete m_spectrumVis; - //delete m_channelMarker; delete ui; } @@ -212,17 +181,24 @@ void LoRaDemodGUI::blockApplySettings(bool block) m_doApplySettings = !block; } -void LoRaDemodGUI::applySettings() +void LoRaDemodGUI::applySettings(bool force) { if (m_doApplySettings) { - const int loraBW[] = BANDWIDTHSTRING; - int thisBW = loraBW[ui->BW->value()]; - m_channelizer->configure(m_channelizer->getInputMessageQueue(), - thisBW, + LoRaDemodSettings::bandwidths[m_settings.m_bandwidthIndex], m_channelMarker.getCenterFrequency()); - m_LoRaDemod->configure(m_LoRaDemod->getInputMessageQueue(), thisBW); + m_LoRaDemod->configure(m_LoRaDemod->getInputMessageQueue(), m_settings.m_bandwidthIndex); } } + +void LoRaDemodGUI::displaySettings() +{ + blockApplySettings(true); + int thisBW = LoRaDemodSettings::bandwidths[m_settings.m_bandwidthIndex]; + ui->BWText->setText(QString("%1 Hz").arg(thisBW)); + ui->BW->setValue(m_settings.m_bandwidthIndex); + m_channelMarker.setBandwidth(thisBW); + blockApplySettings(false); +} diff --git a/plugins/channelrx/demodlora/lorademodgui.h b/plugins/channelrx/demodlora/lorademodgui.h index a48c4e221..59b116c57 100644 --- a/plugins/channelrx/demodlora/lorademodgui.h +++ b/plugins/channelrx/demodlora/lorademodgui.h @@ -6,7 +6,7 @@ #include "dsp/channelmarker.h" #include "util/messagequeue.h" -#define BANDWIDTHSTRING {7813,15625,20833,31250,62500} +#include "lorademodsettings.h" class PluginAPI; class DeviceSourceAPI; @@ -51,6 +51,7 @@ private: PluginAPI* m_pluginAPI; DeviceSourceAPI* m_deviceAPI; ChannelMarker m_channelMarker; + LoRaDemodSettings m_settings; bool m_basicSettingsShown; bool m_doApplySettings; @@ -64,7 +65,8 @@ private: virtual ~LoRaDemodGUI(); void blockApplySettings(bool block); - void applySettings(); + void applySettings(bool force = false); + void displaySettings(); }; #endif // INCLUDE_LoRaDEMODGUI_H diff --git a/plugins/channelrx/demodlora/lorademodgui.ui b/plugins/channelrx/demodlora/lorademodgui.ui index e779a7a71..ef9f95270 100644 --- a/plugins/channelrx/demodlora/lorademodgui.ui +++ b/plugins/channelrx/demodlora/lorademodgui.ui @@ -67,7 +67,7 @@ 0 - 3 + 4 1 diff --git a/plugins/channelrx/demodlora/lorademodsettings.cpp b/plugins/channelrx/demodlora/lorademodsettings.cpp index 8096499eb..67ef5fb2a 100644 --- a/plugins/channelrx/demodlora/lorademodsettings.cpp +++ b/plugins/channelrx/demodlora/lorademodsettings.cpp @@ -7,6 +7,9 @@ #include "settings/serializable.h" #include "lorademodsettings.h" +const int LoRaDemodSettings::bandwidths[] = {7813,15625,20833,31250,62500}; +const int LoRaDemodSettings::nb_bandwidths = 5; + LoRaDemodSettings::LoRaDemodSettings() : m_channelMarker(0), m_spectrumGUI(0) @@ -16,7 +19,7 @@ LoRaDemodSettings::LoRaDemodSettings() : void LoRaDemodSettings::resetToDefaults() { - m_bandwidth = 0; + m_bandwidthIndex = 0; m_spread = 0; } @@ -24,7 +27,7 @@ QByteArray LoRaDemodSettings::serialize() const { SimpleSerializer s(1); s.writeS32(1, m_centerFrequency); - s.writeS32(2, m_bandwidth); + s.writeS32(2, m_bandwidthIndex); s.writeS32(3, m_spread); if (m_spectrumGUI) { @@ -53,7 +56,7 @@ bool LoRaDemodSettings::deserialize(const QByteArray& data) QByteArray bytetmp; d.readS32(1, &m_centerFrequency, 0); - d.readS32(2, &m_bandwidth, 0); + d.readS32(2, &m_bandwidthIndex, 0); d.readS32(3, &m_spread, 0); if (m_spectrumGUI) { diff --git a/plugins/channelrx/demodlora/lorademodsettings.h b/plugins/channelrx/demodlora/lorademodsettings.h index 18686bc6c..b0dd29dfd 100644 --- a/plugins/channelrx/demodlora/lorademodsettings.h +++ b/plugins/channelrx/demodlora/lorademodsettings.h @@ -10,13 +10,16 @@ class Serializable; struct LoRaDemodSettings { int m_centerFrequency; - int m_bandwidth; + int m_bandwidthIndex; int m_spread; uint32_t m_rgbColor; Serializable *m_channelMarker; Serializable *m_spectrumGUI; + static const int bandwidths[]; + static const int nb_bandwidths; + LoRaDemodSettings(); void resetToDefaults(); void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; }