From 2d9c0bcfd2934f35ef8038ba49ea5e1d9e94ba25 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 30 Sep 2015 03:46:46 +0200 Subject: [PATCH] Review presets #1. Apply to HackRF --- CMakeLists.txt | 4 +- include-gpl/settings/preset.h | 13 +-- plugins/samplesource/hackrf/CMakeLists.txt | 4 +- plugins/samplesource/hackrf/hackrfgui.cpp | 6 +- plugins/samplesource/hackrf/hackrfgui.h | 2 +- plugins/samplesource/hackrf/hackrfinput.cpp | 79 +--------------- plugins/samplesource/hackrf/hackrfinput.h | 36 ++----- plugins/samplesource/hackrf/hackrfplugin.cpp | 8 +- plugins/samplesource/hackrf/hackrfplugin.h | 6 +- .../samplesource/hackrf/hackrfserializer.cpp | 89 ------------------ .../samplesource/hackrf/hackrfsettings.cpp | 93 +++++++++++++++++++ .../{hackrfserializer.h => hackrfsettings.h} | 49 +++++----- sdrbase/plugin/pluginmanager.cpp | 34 ++++--- sdrbase/settings/preset.cpp | 33 +++---- 14 files changed, 183 insertions(+), 273 deletions(-) delete mode 100644 plugins/samplesource/hackrf/hackrfserializer.cpp create mode 100644 plugins/samplesource/hackrf/hackrfsettings.cpp rename plugins/samplesource/hackrf/{hackrfserializer.h => hackrfsettings.h} (63%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a94975796..67310eedb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,8 +33,8 @@ ENDIF() ############################################################################## #include(${QT_USE_FILE}) -set( QT_DEFINITIONS "${QT_DEFINITIONS} -DQT_NO_DEBUG_OUTPUT" ) -#set( QT_DEFINITIONS "${QT_DEFINITIONS}" ) +#set( QT_DEFINITIONS "${QT_DEFINITIONS} -DQT_NO_DEBUG_OUTPUT" ) +set( QT_DEFINITIONS "${QT_DEFINITIONS}" ) add_definitions(${QT_DEFINITIONS}) if(MSVC) diff --git a/include-gpl/settings/preset.h b/include-gpl/settings/preset.h index 330bdfde8..ad87e206d 100644 --- a/include-gpl/settings/preset.h +++ b/include-gpl/settings/preset.h @@ -34,9 +34,6 @@ public: void setSpectrumConfig(const QByteArray& data) { m_spectrumConfig = data; } const QByteArray& getSpectrumConfig() const { return m_spectrumConfig; } - void setShowScope(bool value) { m_showScope = value; } - bool getShowScope() const { return m_showScope; } - void setLayout(const QByteArray& data) { m_layout = data; } const QByteArray& getLayout() const { return m_layout; } @@ -54,14 +51,12 @@ public: int getChannelCount() const { return m_channelConfigs.count(); } const ChannelConfig& getChannelConfig(int index) const { return m_channelConfigs.at(index); } - void setSourceConfig(const QString& source, const QByteArray& generalConfig, const QByteArray& config) + void setSourceConfig(const QString& source, const QByteArray& config) { m_source = source; - m_sourceGeneralConfig = generalConfig; m_sourceConfig = config; } const QString& getSource() const { return m_source; } - const QByteArray& getSourceGeneralConfig() const { return m_sourceGeneralConfig; } const QByteArray& getSourceConfig() const { return m_sourceConfig; } protected: @@ -74,16 +69,12 @@ protected: QByteArray m_spectrumConfig; QByteArray m_scopeConfig; - // dc offset and i/q imbalance correction + // dc offset and i/q imbalance correction TODO: move it into the source data bool m_dcOffsetCorrection; bool m_iqImbalanceCorrection; - // display scope dock - bool m_showScope; - // sample source and sample source configuration QString m_source; - QByteArray m_sourceGeneralConfig; QByteArray m_sourceConfig; // channels and configurations diff --git a/plugins/samplesource/hackrf/CMakeLists.txt b/plugins/samplesource/hackrf/CMakeLists.txt index 971f029ff..c366e6d68 100644 --- a/plugins/samplesource/hackrf/CMakeLists.txt +++ b/plugins/samplesource/hackrf/CMakeLists.txt @@ -4,7 +4,7 @@ set(hackrf_SOURCES hackrfgui.cpp hackrfinput.cpp hackrfplugin.cpp - hackrfserializer.cpp + hackrfsettings.cpp hackrfthread.cpp ) @@ -12,7 +12,7 @@ set(hackrf_HEADERS hackrfgui.h hackrfinput.h hackrfplugin.h - hackrfserializer.h + hackrfsettings.h hackrfthread.h ) diff --git a/plugins/samplesource/hackrf/hackrfgui.cpp b/plugins/samplesource/hackrf/hackrfgui.cpp index 9fbb748b9..ed7d92c6b 100644 --- a/plugins/samplesource/hackrf/hackrfgui.cpp +++ b/plugins/samplesource/hackrf/hackrfgui.cpp @@ -233,13 +233,13 @@ void HackRFGui::on_decim_valueChanged(int value) void HackRFGui::on_fcPos_currentIndexChanged(int index) { if (index == 0) { - m_settings.m_fcPos = HackRFInput::FC_POS_INFRA; + m_settings.m_fcPos = HackRFSettings::FC_POS_INFRA; sendSettings(); } else if (index == 1) { - m_settings.m_fcPos = HackRFInput::FC_POS_SUPRA; + m_settings.m_fcPos = HackRFSettings::FC_POS_SUPRA; sendSettings(); } else if (index == 2) { - m_settings.m_fcPos = HackRFInput::FC_POS_CENTER; + m_settings.m_fcPos = HackRFSettings::FC_POS_CENTER; sendSettings(); } } diff --git a/plugins/samplesource/hackrf/hackrfgui.h b/plugins/samplesource/hackrf/hackrfgui.h index 5706f9fdd..bc2e77e2e 100644 --- a/plugins/samplesource/hackrf/hackrfgui.h +++ b/plugins/samplesource/hackrf/hackrfgui.h @@ -60,7 +60,7 @@ private: Ui::HackRFGui* ui; PluginAPI* m_pluginAPI; - HackRFInput::Settings m_settings; + HackRFSettings m_settings; QTimer m_updateTimer; SampleSource* m_sampleSource; diff --git a/plugins/samplesource/hackrf/hackrfinput.cpp b/plugins/samplesource/hackrf/hackrfinput.cpp index 7e0692ea4..d711b26ca 100644 --- a/plugins/samplesource/hackrf/hackrfinput.cpp +++ b/plugins/samplesource/hackrf/hackrfinput.cpp @@ -24,82 +24,11 @@ #include "hackrfinput.h" #include "hackrfgui.h" -#include "hackrfserializer.h" #include "hackrfthread.h" MESSAGE_CLASS_DEFINITION(HackRFInput::MsgConfigureHackRF, Message) MESSAGE_CLASS_DEFINITION(HackRFInput::MsgReportHackRF, Message) -HackRFInput::Settings::Settings() : - m_centerFrequency(435000*1000), - m_devSampleRateIndex(0), - m_LOppmTenths(0), - m_lnaGain(14), - m_bandwidthIndex(0), - m_vgaGain(4), - m_log2Decim(0), - m_fcPos(FC_POS_CENTER), - m_biasT(false), - m_lnaExt(false) -{ -} - -void HackRFInput::Settings::resetToDefaults() -{ - m_centerFrequency = 435000*1000; - m_devSampleRateIndex = 0; - m_LOppmTenths = 0; - m_lnaGain = 14; - m_bandwidthIndex = 0; - m_vgaGain = 4; - m_log2Decim = 0; - m_fcPos = FC_POS_CENTER; - m_biasT = false; - m_lnaExt = false; -} - -QByteArray HackRFInput::Settings::serialize() const -{ - HackRFSerializer::HackRFData data; - - data.m_data.m_frequency = m_centerFrequency; - data.m_LOppmTenths = m_LOppmTenths; - data.m_sampleRateIndex = m_devSampleRateIndex; - data.m_log2Decim = m_log2Decim; - data.m_fcPos = (qint32) m_fcPos; - data.m_lnaGain = m_lnaGain; - data.m_bandwidthIndex = m_bandwidthIndex; - data.m_vgaGain = m_vgaGain; - data.m_biasT = m_biasT; - data.m_lnaExt = m_lnaExt; - - QByteArray byteArray; - - HackRFSerializer::writeSerializedData(data, byteArray); - - return byteArray; -} - -bool HackRFInput::Settings::deserialize(const QByteArray& serializedData) -{ - HackRFSerializer::HackRFData data; - - bool valid = HackRFSerializer::readSerializedData(serializedData, data); - - m_centerFrequency = data.m_data.m_frequency; - m_LOppmTenths = data.m_LOppmTenths; - m_devSampleRateIndex = data.m_sampleRateIndex; - m_log2Decim = data.m_log2Decim; - m_fcPos = (fcPos_t) data.m_fcPos; - m_lnaGain = data.m_lnaGain; - m_bandwidthIndex = data.m_bandwidthIndex; - m_vgaGain = data.m_vgaGain; - m_biasT = data.m_biasT; - m_lnaExt = data.m_lnaExt; - - return valid; -} - HackRFInput::HackRFInput() : m_settings(), m_dev(0), @@ -242,7 +171,7 @@ void HackRFInput::setCenterFrequency(quint64 freq_hz) } } -bool HackRFInput::applySettings(const Settings& settings, bool force) +bool HackRFInput::applySettings(const HackRFSettings& settings, bool force) { QMutexLocker mutexLocker(&m_mutex); @@ -313,19 +242,19 @@ bool HackRFInput::applySettings(const Settings& settings, bool force) m_settings.m_centerFrequency = settings.m_centerFrequency; m_settings.m_LOppmTenths = settings.m_LOppmTenths; - if ((m_settings.m_log2Decim == 0) || (m_settings.m_fcPos == FC_POS_CENTER)) + if ((m_settings.m_log2Decim == 0) || (m_settings.m_fcPos == HackRFSettings::FC_POS_CENTER)) { deviceCenterFrequency = m_settings.m_centerFrequency; f_img = deviceCenterFrequency; } else { - if (m_settings.m_fcPos == FC_POS_INFRA) + if (m_settings.m_fcPos == HackRFSettings::FC_POS_INFRA) { deviceCenterFrequency = m_settings.m_centerFrequency + (devSampleRate / 4); f_img = deviceCenterFrequency + devSampleRate/2; } - else if (m_settings.m_fcPos == FC_POS_SUPRA) + else if (m_settings.m_fcPos == HackRFSettings::FC_POS_SUPRA) { deviceCenterFrequency = m_settings.m_centerFrequency - (devSampleRate / 4); f_img = deviceCenterFrequency - devSampleRate/2; diff --git a/plugins/samplesource/hackrf/hackrfinput.h b/plugins/samplesource/hackrf/hackrfinput.h index 7a01f331c..5349aec6a 100644 --- a/plugins/samplesource/hackrf/hackrfinput.h +++ b/plugins/samplesource/hackrf/hackrfinput.h @@ -19,51 +19,29 @@ #include "dsp/samplesource.h" #include "libhackrf/hackrf.h" +#include "hackrfsettings.h" #include class HackRFThread; class HackRFInput : public SampleSource { public: - typedef enum { - FC_POS_INFRA = 0, - FC_POS_SUPRA, - FC_POS_CENTER - } fcPos_t; - - struct Settings { - quint64 m_centerFrequency; - qint32 m_LOppmTenths; - quint32 m_devSampleRateIndex; - quint32 m_bandwidthIndex; - quint32 m_lnaGain; - quint32 m_vgaGain; - quint32 m_log2Decim; - fcPos_t m_fcPos; - bool m_biasT; - bool m_lnaExt; - - Settings(); - void resetToDefaults(); - QByteArray serialize() const; - bool deserialize(const QByteArray& data); - }; class MsgConfigureHackRF : public Message { MESSAGE_CLASS_DECLARATION public: - const Settings& getSettings() const { return m_settings; } + const HackRFSettings& getSettings() const { return m_settings; } - static MsgConfigureHackRF* create(const Settings& settings) + static MsgConfigureHackRF* create(const HackRFSettings& settings) { return new MsgConfigureHackRF(settings); } private: - Settings m_settings; + HackRFSettings m_settings; - MsgConfigureHackRF(const Settings& settings) : + MsgConfigureHackRF(const HackRFSettings& settings) : Message(), m_settings(settings) { } @@ -100,12 +78,12 @@ public: virtual bool handleMessage(const Message& message); private: - bool applySettings(const Settings& settings, bool force); + bool applySettings(const HackRFSettings& settings, bool force); hackrf_device *open_hackrf_from_sequence(int sequence); void setCenterFrequency(quint64 freq); QMutex m_mutex; - Settings m_settings; + HackRFSettings m_settings; struct hackrf_device* m_dev; HackRFThread* m_hackRFThread; QString m_deviceDescription; diff --git a/plugins/samplesource/hackrf/hackrfplugin.cpp b/plugins/samplesource/hackrf/hackrfplugin.cpp index c557ecfc1..42a0e6c50 100644 --- a/plugins/samplesource/hackrf/hackrfplugin.cpp +++ b/plugins/samplesource/hackrf/hackrfplugin.cpp @@ -33,6 +33,8 @@ const PluginDescriptor HackRFPlugin::m_pluginDescriptor = { QString("https://github.com/f4exb/sdrangel") }; +const QString HackRFPlugin::m_deviceTypeID = HACKRF_DEVICE_TYPE_ID; + HackRFPlugin::HackRFPlugin(QObject* parent) : QObject(parent), m_pluginAPI(0) @@ -47,7 +49,7 @@ const PluginDescriptor& HackRFPlugin::getPluginDescriptor() const void HackRFPlugin::initPlugin(PluginAPI* pluginAPI) { m_pluginAPI = pluginAPI; - m_pluginAPI->registerSampleSource("org.osmocom.sdr.samplesource.hackrf", this); + m_pluginAPI->registerSampleSource(m_deviceTypeID, this); } PluginInterface::SampleSourceDevices HackRFPlugin::enumSampleSources() @@ -96,7 +98,7 @@ PluginInterface::SampleSourceDevices HackRFPlugin::enumSampleSources() s.writeS32(1, i); s.writeString(2, serial_str); s.writeU64(3, serial_num); - result.append(SampleSourceDevice(displayedName, "org.osmocom.sdr.samplesource.hackrf", s.final())); + result.append(SampleSourceDevice(displayedName, m_deviceTypeID, s.final())); qDebug("HackRFPlugin::enumSampleSources: enumerated HackRF device #%d", i); hackrf_close(hackrf_ptr); @@ -120,7 +122,7 @@ PluginGUI* HackRFPlugin::createSampleSourcePluginGUI(const QString& sourceName, return 0; } - if(sourceName == "org.osmocom.sdr.samplesource.hackrf") + if(sourceName == m_deviceTypeID) { HackRFGui* gui = new HackRFGui(m_pluginAPI); m_pluginAPI->setInputGUI(gui); diff --git a/plugins/samplesource/hackrf/hackrfplugin.h b/plugins/samplesource/hackrf/hackrfplugin.h index 9bf1b026d..8de848017 100644 --- a/plugins/samplesource/hackrf/hackrfplugin.h +++ b/plugins/samplesource/hackrf/hackrfplugin.h @@ -20,10 +20,12 @@ #include #include "plugin/plugininterface.h" +#define HACKRF_DEVICE_TYPE_ID "sdrangel.samplesource.hackrf" + class HackRFPlugin : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) - Q_PLUGIN_METADATA(IID "org.osmocom.sdr.samplesource.hackrf") + Q_PLUGIN_METADATA(IID HACKRF_DEVICE_TYPE_ID) public: explicit HackRFPlugin(QObject* parent = NULL); @@ -34,6 +36,8 @@ public: SampleSourceDevices enumSampleSources(); PluginGUI* createSampleSourcePluginGUI(const QString& sourceName, const QByteArray& address); + static const QString m_deviceTypeID; + private: static const PluginDescriptor m_pluginDescriptor; diff --git a/plugins/samplesource/hackrf/hackrfserializer.cpp b/plugins/samplesource/hackrf/hackrfserializer.cpp deleted file mode 100644 index 9a9e2d5af..000000000 --- a/plugins/samplesource/hackrf/hackrfserializer.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////// -// Copyright (C) 2015 Edouard Griffiths, F4EXB // -// // -// 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 . // -/////////////////////////////////////////////////////////////////////////////////// - -#include "hackrfserializer.h" - -void HackRFSerializer::writeSerializedData(const HackRFData& data, QByteArray& serializedData) -{ - QByteArray sampleSourceSerialized; - SampleSourceSerializer::writeSerializedData(data.m_data, sampleSourceSerialized); - - SimpleSerializer s(1); - - s.writeBlob(1, sampleSourceSerialized); - s.writeS32(2, data.m_LOppmTenths); - s.writeU32(3, data.m_sampleRateIndex); - s.writeU32(4, data.m_log2Decim); - s.writeS32(5, data.m_fcPos); - s.writeU32(6, data.m_lnaGain); - s.writeU32(7, data.m_bandwidthIndex); - s.writeU32(8, data.m_vgaGain); - s.writeBool(9, data.m_biasT); - s.writeBool(10, data.m_lnaExt); - - serializedData = s.final(); -} - -bool HackRFSerializer::readSerializedData(const QByteArray& serializedData, HackRFData& data) -{ - bool valid = SampleSourceSerializer::readSerializedData(serializedData, data.m_data); - - QByteArray sampleSourceSerialized; - - SimpleDeserializer d(serializedData); - - if (!d.isValid()) - { - setDefaults(data); - return false; - } - - if (d.getVersion() == SampleSourceSerializer::getSerializerVersion()) - { - int intval; - - d.readBlob(1, &sampleSourceSerialized); - d.readS32(2, &data.m_LOppmTenths, 0); - d.readU32(3, &data.m_sampleRateIndex, 0); - d.readU32(4, &data.m_log2Decim, 0); - d.readS32(5, &data.m_fcPos, 0); - d.readU32(6, &data.m_lnaGain, 16); - d.readU32(7, &data.m_bandwidthIndex, 0); - d.readU32(8, &data.m_vgaGain, 16); - d.readBool(9, &data.m_biasT, false); - d.readBool(10, &data.m_lnaExt, false); - - return SampleSourceSerializer::readSerializedData(sampleSourceSerialized, data.m_data); - } - else - { - setDefaults(data); - return false; - } -} - -void HackRFSerializer::setDefaults(HackRFData& data) -{ - data.m_LOppmTenths = 0; - data.m_sampleRateIndex = 0; - data.m_log2Decim = 0; - data.m_fcPos = 0; - data.m_lnaGain = 16; - data.m_bandwidthIndex = 0; - data.m_vgaGain = 16; - data.m_biasT = false; - data.m_lnaExt = false; -} diff --git a/plugins/samplesource/hackrf/hackrfsettings.cpp b/plugins/samplesource/hackrf/hackrfsettings.cpp new file mode 100644 index 000000000..096f397f8 --- /dev/null +++ b/plugins/samplesource/hackrf/hackrfsettings.cpp @@ -0,0 +1,93 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2015 Edouard Griffiths, F4EXB // +// // +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include "util/simpleserializer.h" +#include "hackrfsettings.h" + +HackRFSettings::HackRFSettings() +{ + resetToDefaults(); +} + +void HackRFSettings::resetToDefaults() +{ + m_centerFrequency = 435000 * 1000; + m_LOppmTenths = 0; + m_devSampleRateIndex = 0; + m_biasT = false; + m_log2Decim = 0; + m_fcPos = FC_POS_CENTER; + m_lnaExt = false; + m_lnaGain = 16; + m_bandwidthIndex = 0; + m_vgaGain = 16; + m_dcBlock = false; + m_iqCorrection = false; +} + +QByteArray HackRFSettings::serialize() const +{ + SimpleSerializer s(1); + + s.writeS32(1, m_LOppmTenths); + s.writeU32(2, m_devSampleRateIndex); + s.writeBool(3, m_biasT); + s.writeU32(4, m_log2Decim); + s.writeS32(5, m_fcPos); + s.writeBool(6, m_lnaExt); + s.writeU32(7, m_lnaGain); + s.writeU32(8, m_bandwidthIndex); + s.writeU32(9, m_vgaGain); + s.writeBool(10, m_dcBlock); + s.writeBool(11, m_iqCorrection); + + return s.final(); +} + +bool HackRFSettings::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if (!d.isValid()) + { + resetToDefaults(); + return false; + } + + if (d.getVersion() == 1) + { + int intval; + + d.readS32(1, &m_LOppmTenths, 0); + d.readU32(2, &m_devSampleRateIndex, 0); + d.readBool(3, &m_biasT, false); + d.readU32(4, &m_log2Decim, 0); + d.readS32(5, &intval, 0); + m_fcPos = (fcPos_t) intval; + d.readBool(6, &m_lnaExt, false); + d.readU32(7, &m_lnaGain, 16); + d.readU32(8, &m_bandwidthIndex, 0); + d.readU32(9, &m_vgaGain, 16); + + return true; + } + else + { + resetToDefaults(); + return false; + } +} diff --git a/plugins/samplesource/hackrf/hackrfserializer.h b/plugins/samplesource/hackrf/hackrfsettings.h similarity index 63% rename from plugins/samplesource/hackrf/hackrfserializer.h rename to plugins/samplesource/hackrf/hackrfsettings.h index 17789eb6c..ec22574c8 100644 --- a/plugins/samplesource/hackrf/hackrfserializer.h +++ b/plugins/samplesource/hackrf/hackrfsettings.h @@ -14,32 +14,33 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#ifndef PLUGINS_SAMPLESOURCE_HACKRF_HACKRFSERIALIZER_H_ -#define PLUGINS_SAMPLESOURCE_HACKRF_HACKRFSERIALIZER_H_ +#ifndef _HACKRF_HACKRFSETTINGS_H_ +#define _HACKRF_HACKRFSETTINGS_H_ -#include "util/samplesourceserializer.h" +struct HackRFSettings { + typedef enum { + FC_POS_INFRA = 0, + FC_POS_SUPRA, + FC_POS_CENTER + } fcPos_t; -class HackRFSerializer -{ -public: - struct HackRFData - { - SampleSourceSerializer::Data m_data; - qint32 m_LOppmTenths; - quint32 m_sampleRateIndex; - quint32 m_log2Decim; - qint32 m_fcPos; - quint32 m_lnaGain; - quint32 m_bandwidthIndex; - quint32 m_vgaGain; - bool m_biasT; - bool m_lnaExt; - }; + quint64 m_centerFrequency; + qint32 m_LOppmTenths; + quint32 m_devSampleRateIndex; + quint32 m_bandwidthIndex; + quint32 m_lnaGain; + quint32 m_vgaGain; + quint32 m_log2Decim; + fcPos_t m_fcPos; + bool m_biasT; + bool m_lnaExt; + bool m_dcBlock; + bool m_iqCorrection; - static void writeSerializedData(const HackRFData& data, QByteArray& serializedData); - static bool readSerializedData(const QByteArray& serializedData, HackRFData& data); - static void setDefaults(HackRFData& data); + HackRFSettings(); + void resetToDefaults(); + QByteArray serialize() const; + bool deserialize(const QByteArray& data); }; - -#endif /* PLUGINS_SAMPLESOURCE_HACKRF_HACKRFSERIALIZER_H_ */ +#endif /* _HACKRF_HACKRFSETTINGS_H_ */ diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index 787e73c90..d33088d36 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -83,9 +83,7 @@ void PluginManager::registerSampleSource(const QString& sourceName, PluginInterf void PluginManager::loadSettings(const Preset* preset) { - qDebug() << "PluginManager::loadSettings"; - - fprintf(stderr, "Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); + fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription())); // copy currently open channels and clear list ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations; @@ -100,11 +98,11 @@ void PluginManager::loadSettings(const Preset* preset) for(int i = 0; i < openChannels.count(); i++) { - qDebug(" - compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel)); + qDebug("PluginManager::loadSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel)); if(openChannels[i].m_channelName == channelConfig.m_channel) { - qDebug("channel [%s] found", qPrintable(openChannels[i].m_channelName)); + qDebug("PluginManager::loadSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName)); reg = openChannels.takeAt(i); m_channelInstanceRegistrations.append(reg); break; @@ -119,7 +117,7 @@ void PluginManager::loadSettings(const Preset* preset) { if(m_channelRegistrations[i].m_channelName == channelConfig.m_channel) { - qDebug(" - creating new channel [%s]", qPrintable(channelConfig.m_channel)); + qDebug("PluginManager::loadSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel)); reg = ChannelInstanceRegistration(channelConfig.m_channel, m_channelRegistrations[i].m_plugin->createChannel(channelConfig.m_channel)); break; } @@ -128,7 +126,7 @@ void PluginManager::loadSettings(const Preset* preset) if(reg.m_gui != NULL) { - qDebug(" - deserializing channel [%s]", qPrintable(channelConfig.m_channel)); + qDebug("PluginManager::loadSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channel)); reg.m_gui->deserialize(channelConfig.m_config); } } @@ -136,7 +134,7 @@ void PluginManager::loadSettings(const Preset* preset) // everything, that is still "available" is not needed anymore for(int i = 0; i < openChannels.count(); i++) { - qDebug("destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName)); + qDebug("PluginManager::loadSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName)); openChannels[i].m_gui->destroy(); } @@ -144,10 +142,12 @@ void PluginManager::loadSettings(const Preset* preset) if(m_sampleSourcePluginGUI != 0) { + qDebug("PluginManager::loadSettings: source compare [%s] vs [%s]", qPrintable(m_sampleSourceName), qPrintable(preset->getSource())); + // TODO: have one set of source presets per identified source (preset -> find source with name) if(m_sampleSourceName == preset->getSource()) { - qDebug() << " - deserializing source " << qPrintable(m_sampleSourceName); + qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceName); m_sampleSourcePluginGUI->deserialize(preset->getSourceConfig()); } @@ -172,14 +172,20 @@ bool PluginManager::ChannelInstanceRegistration::operator<(const ChannelInstance void PluginManager::saveSettings(Preset* preset) { - if(m_sampleSourcePluginGUI != NULL) { - //preset->setSourceConfig(m_sampleSourceName, m_sampleSourcePluginGUI->serializeGeneral(), m_sampleSourcePluginGUI->serialize()); + if(m_sampleSourcePluginGUI != NULL) + { + preset->setSourceConfig(m_sampleSourceName, m_sampleSourcePluginGUI->serialize()); preset->setCenterFrequency(m_sampleSourcePluginGUI->getCenterFrequency()); - } else { - preset->setSourceConfig(QString::null, QByteArray(), QByteArray()); } + else + { + preset->setSourceConfig(QString::null, QByteArray()); + } + qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type - for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) { + + for(int i = 0; i < m_channelInstanceRegistrations.count(); i++) + { preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize()); } } diff --git a/sdrbase/settings/preset.cpp b/sdrbase/settings/preset.cpp index 9ba2de228..29ca43cdd 100644 --- a/sdrbase/settings/preset.cpp +++ b/sdrbase/settings/preset.cpp @@ -17,7 +17,6 @@ void Preset::resetToDefaults() m_scopeConfig.clear(); m_dcOffsetCorrection = false; m_iqImbalanceCorrection = false; - m_showScope = true; m_layout.clear(); m_spectrumConfig.clear(); m_channelConfigs.clear(); @@ -33,15 +32,13 @@ QByteArray Preset::serialize() const s.writeString(1, m_group); s.writeString(2, m_description); s.writeU64(3, m_centerFrequency); - s.writeBool(4, m_showScope); - s.writeBlob(5, m_layout); - s.writeBlob(6, m_spectrumConfig); - s.writeBool(7, m_dcOffsetCorrection); - s.writeBool(8, m_iqImbalanceCorrection); - s.writeBlob(9, m_scopeConfig); - s.writeString(10, m_source); - s.writeBlob(11, m_sourceGeneralConfig); - s.writeBlob(12, m_sourceConfig); + s.writeBlob(4, m_layout); + s.writeBlob(5, m_spectrumConfig); + s.writeBool(6, m_dcOffsetCorrection); + s.writeBool(7, m_iqImbalanceCorrection); + s.writeBlob(8, m_scopeConfig); + s.writeString(9, m_source); + s.writeBlob(10, m_sourceConfig); s.writeS32(200, m_channelConfigs.size()); @@ -69,15 +66,13 @@ bool Preset::deserialize(const QByteArray& data) d.readString(1, &m_group, "default"); d.readString(2, &m_description, "no name"); d.readU64(3, &m_centerFrequency, 0); - d.readBool(4, &m_showScope, true); - d.readBlob(5, &m_layout); - d.readBlob(6, &m_spectrumConfig); - d.readBool(7, &m_dcOffsetCorrection, false); - d.readBool(8, &m_iqImbalanceCorrection, false); - d.readBlob(9, &m_scopeConfig); - d.readString(10, &m_source); - d.readBlob(11, &m_sourceGeneralConfig); - d.readBlob(12, &m_sourceConfig); + d.readBlob(4, &m_layout); + d.readBlob(5, &m_spectrumConfig); + d.readBool(6, &m_dcOffsetCorrection, false); + d.readBool(7, &m_iqImbalanceCorrection, false); + d.readBlob(8, &m_scopeConfig); + d.readString(9, &m_source); + d.readBlob(10, &m_sourceConfig); qDebug() << " m_group: " << m_group.toStdString().c_str();