From 3cc73fbf613e606a847f2f5252c4fdf7fff81628 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 1 Oct 2015 04:39:00 +0200 Subject: [PATCH] RTL-SDR: replaced serializer by setting class --- plugins/samplesource/rtlsdr/CMakeLists.txt | 4 +- plugins/samplesource/rtlsdr/rtlsdrgui.h | 2 +- plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 53 +------------- plugins/samplesource/rtlsdr/rtlsdrinput.h | 26 ++----- ...{rtlsdrserializer.h => rtlsdrsettings.cpp} | 71 +++++++++++++++---- ...{rtlsdrserializer.cpp => rtlsdrsettings.h} | 33 +++++---- 6 files changed, 90 insertions(+), 99 deletions(-) rename plugins/samplesource/rtlsdr/{rtlsdrserializer.h => rtlsdrsettings.cpp} (53%) rename plugins/samplesource/rtlsdr/{rtlsdrserializer.cpp => rtlsdrsettings.h} (70%) diff --git a/plugins/samplesource/rtlsdr/CMakeLists.txt b/plugins/samplesource/rtlsdr/CMakeLists.txt index 02537afa0..58b2f910f 100644 --- a/plugins/samplesource/rtlsdr/CMakeLists.txt +++ b/plugins/samplesource/rtlsdr/CMakeLists.txt @@ -4,7 +4,7 @@ set(rtlsdr_SOURCES rtlsdrgui.cpp rtlsdrinput.cpp rtlsdrplugin.cpp - rtlsdrserializer.cpp + rtlsdrsettings.cpp rtlsdrthread.cpp ) @@ -12,7 +12,7 @@ set(rtlsdr_HEADERS rtlsdrgui.h rtlsdrinput.h rtlsdrplugin.h - rtlsdrserializer.h + rtlsdrsettings.h rtlsdrthread.h ) diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.h b/plugins/samplesource/rtlsdr/rtlsdrgui.h index ef9fbeaf8..cf3a61b9c 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.h +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.h @@ -34,7 +34,7 @@ private: Ui::RTLSDRGui* ui; PluginAPI* m_pluginAPI; - RTLSDRInput::Settings m_settings; + RTLSDRSettings m_settings; QTimer m_updateTimer; std::vector m_gains; SampleSource* m_sampleSource; diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index 226c3ef07..854bb00cf 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -23,61 +23,10 @@ #include "rtlsdrgui.h" #include "dsp/dspcommands.h" #include "dsp/dspengine.h" -#include "rtlsdrserializer.h" MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgConfigureRTLSDR, Message) MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgReportRTLSDR, Message) -RTLSDRInput::Settings::Settings() : - m_devSampleRate(1024*1000), - m_centerFrequency(435000*1000), - m_gain(0), - m_loPpmCorrection(0), - m_log2Decim(4) -{ -} - -void RTLSDRInput::Settings::resetToDefaults() -{ - m_devSampleRate = 1024*1000; - m_centerFrequency = 435000*1000; - m_gain = 0; - m_loPpmCorrection = 0; - m_log2Decim = 4; -} - -QByteArray RTLSDRInput::Settings::serialize() const -{ - SampleSourceSerializer::Data data; - - data.m_lnaGain = m_gain; - data.m_log2Decim = m_log2Decim; - data.m_frequency = m_centerFrequency; - data.m_rate = m_devSampleRate; - data.m_correction = m_loPpmCorrection; - - QByteArray byteArray; - - RTLSDRSerializer::writeSerializedData(data, byteArray); - - return byteArray; -} - -bool RTLSDRInput::Settings::deserialize(const QByteArray& serializedData) -{ - SampleSourceSerializer::Data data; - - bool valid = RTLSDRSerializer::readSerializedData(serializedData, data); - - m_gain = data.m_lnaGain; - m_log2Decim = data.m_log2Decim; - m_centerFrequency = data.m_frequency; - m_devSampleRate = data.m_rate; - m_loPpmCorrection = data.m_correction; - - return valid; -} - RTLSDRInput::RTLSDRInput() : m_settings(), m_dev(0), @@ -260,7 +209,7 @@ bool RTLSDRInput::handleMessage(const Message& message) } } -bool RTLSDRInput::applySettings(const Settings& settings, bool force) +bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force) { QMutexLocker mutexLocker(&m_mutex); bool forwardChange = false; diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.h b/plugins/samplesource/rtlsdr/rtlsdrinput.h index db135da3d..732282e9e 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.h +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.h @@ -19,6 +19,7 @@ #define INCLUDE_RTLSDRINPUT_H #include "dsp/samplesource.h" +#include "rtlsdrsettings.h" #include #include @@ -26,34 +27,21 @@ class RTLSDRThread; class RTLSDRInput : public SampleSource { public: - struct Settings { - int m_devSampleRate; - quint64 m_centerFrequency; - qint32 m_gain; - qint32 m_loPpmCorrection; - quint32 m_log2Decim; - - Settings(); - void resetToDefaults(); - QByteArray serialize() const; - bool deserialize(const QByteArray& data); - }; - class MsgConfigureRTLSDR : public Message { MESSAGE_CLASS_DECLARATION public: - const Settings& getSettings() const { return m_settings; } + const RTLSDRSettings& getSettings() const { return m_settings; } - static MsgConfigureRTLSDR* create(const Settings& settings) + static MsgConfigureRTLSDR* create(const RTLSDRSettings& settings) { return new MsgConfigureRTLSDR(settings); } private: - Settings m_settings; + RTLSDRSettings m_settings; - MsgConfigureRTLSDR(const Settings& settings) : + MsgConfigureRTLSDR(const RTLSDRSettings& settings) : Message(), m_settings(settings) { } @@ -96,13 +84,13 @@ public: private: QMutex m_mutex; - Settings m_settings; + RTLSDRSettings m_settings; rtlsdr_dev_t* m_dev; RTLSDRThread* m_rtlSDRThread; QString m_deviceDescription; std::vector m_gains; - bool applySettings(const Settings& settings, bool force); + bool applySettings(const RTLSDRSettings& settings, bool force); }; #endif // INCLUDE_RTLSDRINPUT_H diff --git a/plugins/samplesource/rtlsdr/rtlsdrserializer.h b/plugins/samplesource/rtlsdr/rtlsdrsettings.cpp similarity index 53% rename from plugins/samplesource/rtlsdr/rtlsdrserializer.h rename to plugins/samplesource/rtlsdr/rtlsdrsettings.cpp index 4cc8b826d..9f6b9dc53 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrserializer.h +++ b/plugins/samplesource/rtlsdr/rtlsdrsettings.cpp @@ -14,19 +14,66 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#ifndef PLUGINS_SAMPLESOURCE_RTLSDR_RTLSDRSERIALIZER_H_ -#define PLUGINS_SAMPLESOURCE_RTLSDR_RTLSDRSERIALIZER_H_ +#include +#include "util/simpleserializer.h" +#include "rtlsdrsettings.h" -#include "util/samplesourceserializer.h" - -class RTLSDRSerializer +RTLSDRSettings::RTLSDRSettings() { -public: - SampleSourceSerializer::Data m_data; + resetToDefaults(); +} + +void RTLSDRSettings::resetToDefaults() +{ + m_devSampleRate = 1024*1000; + m_centerFrequency = 435000*1000; + m_gain = 0; + m_loPpmCorrection = 0; + m_log2Decim = 4; + m_dcBlock = false; + m_iqImbalance = false; +} + +QByteArray RTLSDRSettings::serialize() const +{ + SimpleSerializer s(1); + + s.writeS32(1, m_devSampleRate); + s.writeS32(2, m_gain); + s.writeS32(3, m_loPpmCorrection); + s.writeU32(4, m_log2Decim); + s.writeBool(5, m_dcBlock); + s.writeBool(6, m_iqImbalance); + + return s.final(); +} + +bool RTLSDRSettings::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if (!d.isValid()) + { + resetToDefaults(); + return false; + } + + if (d.getVersion() == 1) + { + d.readS32(1, &m_devSampleRate, 0); + d.readS32(2, &m_gain, 0); + d.readS32(3, &m_loPpmCorrection, 0); + d.readU32(4, &m_log2Decim, 4); + d.readBool(5, &m_dcBlock, false); + d.readBool(6, &m_iqImbalance, false); + + return true; + } + else + { + resetToDefaults(); + return false; + } +} - static void writeSerializedData(const SampleSourceSerializer::Data& data, QByteArray& serializedData); - static bool readSerializedData(const QByteArray& serializedData, SampleSourceSerializer::Data& data); - static void setDefaults(SampleSourceSerializer::Data& data); -}; -#endif /* PLUGINS_SAMPLESOURCE_RTLSDR_RTLSDRSERIALIZER_H_ */ diff --git a/plugins/samplesource/rtlsdr/rtlsdrserializer.cpp b/plugins/samplesource/rtlsdr/rtlsdrsettings.h similarity index 70% rename from plugins/samplesource/rtlsdr/rtlsdrserializer.cpp rename to plugins/samplesource/rtlsdr/rtlsdrsettings.h index ad1d379c7..e8ec4714c 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrserializer.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrsettings.h @@ -14,19 +14,26 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include "rtlsdrserializer.h" +#ifndef _RTLSDR_RTLSDRSETTINGS_H_ +#define _RTLSDR_RTLSDRSETTINGS_H_ -void RTLSDRSerializer::writeSerializedData(const SampleSourceSerializer::Data& data, QByteArray& serializedData) -{ - SampleSourceSerializer::writeSerializedData(data, serializedData); -} +struct RTLSDRSettings { + int m_devSampleRate; + quint64 m_centerFrequency; + qint32 m_gain; + qint32 m_loPpmCorrection; + quint32 m_log2Decim; + bool m_dcBlock; + bool m_iqImbalance; -bool RTLSDRSerializer::readSerializedData(const QByteArray& serializedData, SampleSourceSerializer::Data& data) -{ - return SampleSourceSerializer::readSerializedData(serializedData, data); -} + RTLSDRSettings(); + void resetToDefaults(); + QByteArray serialize() const; + bool deserialize(const QByteArray& data); +}; -void RTLSDRSerializer::setDefaults(SampleSourceSerializer::Data& data) -{ - SampleSourceSerializer::setDefaults(data); -} + + + + +#endif /* _RTLSDR_RTLSDRSETTINGS_H_ */