From bb2c114dd2e6d669a81f39422716f8c102476661 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 7 Oct 2017 22:18:33 +0200 Subject: [PATCH] LoRa demod: created settings class --- plugins/channelrx/demodlora/CMakeLists.txt | 2 + plugins/channelrx/demodlora/demodlora.pro | 2 + .../channelrx/demodlora/lorademodsettings.cpp | 76 +++++++++++++++++++ .../channelrx/demodlora/lorademodsettings.h | 30 ++++++++ 4 files changed, 110 insertions(+) create mode 100644 plugins/channelrx/demodlora/lorademodsettings.cpp create mode 100644 plugins/channelrx/demodlora/lorademodsettings.h diff --git a/plugins/channelrx/demodlora/CMakeLists.txt b/plugins/channelrx/demodlora/CMakeLists.txt index a61d639cd..ba22f3c7b 100644 --- a/plugins/channelrx/demodlora/CMakeLists.txt +++ b/plugins/channelrx/demodlora/CMakeLists.txt @@ -3,12 +3,14 @@ project(lora) set(lora_SOURCES lorademod.cpp lorademodgui.cpp + lorademodsettings.cpp loraplugin.cpp ) set(lora_HEADERS lorademod.h lorademodgui.h + lorademodsettings.h loraplugin.h ) diff --git a/plugins/channelrx/demodlora/demodlora.pro b/plugins/channelrx/demodlora/demodlora.pro index c8be15b02..52ce48462 100644 --- a/plugins/channelrx/demodlora/demodlora.pro +++ b/plugins/channelrx/demodlora/demodlora.pro @@ -25,10 +25,12 @@ CONFIG(Debug):build_subdir = debug SOURCES += lorademod.cpp\ lorademodgui.cpp\ + lorademodsettings.cpp\ loraplugin.cpp HEADERS += lorademod.h\ lorademodgui.h\ + lorademodsettings.h\ loraplugin.h FORMS += lorademodgui.ui diff --git a/plugins/channelrx/demodlora/lorademodsettings.cpp b/plugins/channelrx/demodlora/lorademodsettings.cpp new file mode 100644 index 000000000..8096499eb --- /dev/null +++ b/plugins/channelrx/demodlora/lorademodsettings.cpp @@ -0,0 +1,76 @@ +#include "lorademodsettings.h" + +#include + +#include "dsp/dspengine.h" +#include "util/simpleserializer.h" +#include "settings/serializable.h" +#include "lorademodsettings.h" + +LoRaDemodSettings::LoRaDemodSettings() : + m_channelMarker(0), + m_spectrumGUI(0) +{ + resetToDefaults(); +} + +void LoRaDemodSettings::resetToDefaults() +{ + m_bandwidth = 0; + m_spread = 0; +} + +QByteArray LoRaDemodSettings::serialize() const +{ + SimpleSerializer s(1); + s.writeS32(1, m_centerFrequency); + s.writeS32(2, m_bandwidth); + s.writeS32(3, m_spread); + + if (m_spectrumGUI) { + s.writeBlob(4, m_spectrumGUI->serialize()); + } + + if (m_channelMarker) { + s.writeBlob(5, m_channelMarker->serialize()); + } + + return s.final(); +} + +bool LoRaDemodSettings::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if(!d.isValid()) + { + resetToDefaults(); + return false; + } + + if(d.getVersion() == 1) + { + QByteArray bytetmp; + + d.readS32(1, &m_centerFrequency, 0); + d.readS32(2, &m_bandwidth, 0); + d.readS32(3, &m_spread, 0); + + if (m_spectrumGUI) { + d.readBlob(4, &bytetmp); + m_spectrumGUI->deserialize(bytetmp); + } + + if (m_channelMarker) { + d.readBlob(5, &bytetmp); + m_channelMarker->deserialize(bytetmp); + } + + return true; + } + else + { + resetToDefaults(); + return false; + } +} diff --git a/plugins/channelrx/demodlora/lorademodsettings.h b/plugins/channelrx/demodlora/lorademodsettings.h new file mode 100644 index 000000000..18686bc6c --- /dev/null +++ b/plugins/channelrx/demodlora/lorademodsettings.h @@ -0,0 +1,30 @@ + +#ifndef PLUGINS_CHANNELRX_DEMODLORA_LORADEMODSETTINGS_H_ +#define PLUGINS_CHANNELRX_DEMODLORA_LORADEMODSETTINGS_H_ + +#include +#include + +class Serializable; + +struct LoRaDemodSettings +{ + int m_centerFrequency; + int m_bandwidth; + int m_spread; + uint32_t m_rgbColor; + + Serializable *m_channelMarker; + Serializable *m_spectrumGUI; + + LoRaDemodSettings(); + void resetToDefaults(); + void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; } + void setSpectrumGUI(Serializable *spectrumGUI) { m_spectrumGUI = spectrumGUI; } + QByteArray serialize() const; + bool deserialize(const QByteArray& data); +}; + + + +#endif /* PLUGINS_CHANNELRX_DEMODLORA_LORADEMODSETTINGS_H_ */