diff --git a/CMakeLists.txt b/CMakeLists.txt
index 59b38b301..f21ec5350 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -113,6 +113,7 @@ set(sdrbase_SOURCES
sdrbase/util/messagequeue.cpp
sdrbase/util/syncmessenger.cpp
#sdrbase/util/miniz.cpp
+ sdrbase/util/samplesourceserializer.cpp
sdrbase/util/simpleserializer.cpp
sdrbase/util/spinlock.cpp
)
@@ -189,6 +190,7 @@ set(sdrbase_HEADERS
include/util/messagequeue.h
include/util/syncmessenger.h
#include/util/miniz.h
+ include/util/samplesourceserializer.h
include/util/simpleserializer.h
include/util/spinlock.h
)
diff --git a/include/util/samplesourceserializer.h b/include/util/samplesourceserializer.h
new file mode 100644
index 000000000..95b3ea0ca
--- /dev/null
+++ b/include/util/samplesourceserializer.h
@@ -0,0 +1,49 @@
+///////////////////////////////////////////////////////////////////////////////////
+// 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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#ifndef INCLUDE_UTIL_SAMPLESOURCESERIALIZER_H_
+#define INCLUDE_UTIL_SAMPLESOURCESERIALIZER_H_
+
+#include "util/simpleserializer.h"
+
+class SampleSourceSerializer
+{
+public:
+ struct Data
+ {
+ quint64 m_frequency; //!< RF center frequency
+ qint32 m_correction; //!< LO correction factor
+ qint32 m_rate; //!< RF sampler sample rate
+ quint32 m_log2Decim; //!< Decimation ratio log2
+ qint32 m_bandwidth; //!< RF bandwidth
+ qint32 m_fcPosition; //!< Decimated band placement (infradyne, supradyne, centered)
+ qint32 m_lnaGain; //!< RF LNA gain
+ qint32 m_RxGain1; //!< Rx first stage amplifier gain
+ qint32 m_RxGain2; //!< Rx second stage amplifier gain
+ qint32 m_RxGain3; //!< Rx third stage amplifier gain
+ };
+
+ static void writeSerializedData(const Data& data, QByteArray& serializedData);
+ static bool readSerializedData(const QByteArray& serializedData, Data& data);
+ static void setDefaults(Data& data);
+
+protected:
+ static const uint m_version;
+};
+
+
+
+#endif /* INCLUDE_UTIL_SAMPLESOURCESERIALIZER_H_ */
diff --git a/plugins/samplesource/bladerf/CMakeLists.txt b/plugins/samplesource/bladerf/CMakeLists.txt
index 3c7a3bc0f..235490f22 100644
--- a/plugins/samplesource/bladerf/CMakeLists.txt
+++ b/plugins/samplesource/bladerf/CMakeLists.txt
@@ -4,6 +4,7 @@ set(bladerf_SOURCES
bladerfgui.cpp
bladerfinput.cpp
bladerfplugin.cpp
+ bladerfserializer.cpp
bladerfthread.cpp
)
@@ -11,6 +12,7 @@ set(bladerf_HEADERS
bladerfgui.h
bladerfinput.h
bladerfplugin.h
+ bladerfserializer.h
bladerfthread.h
)
diff --git a/plugins/samplesource/bladerf/bladerfinput.cpp b/plugins/samplesource/bladerf/bladerfinput.cpp
index e726aae54..10c502f15 100644
--- a/plugins/samplesource/bladerf/bladerfinput.cpp
+++ b/plugins/samplesource/bladerf/bladerfinput.cpp
@@ -23,6 +23,7 @@
#include "bladerfgui.h"
#include "bladerfinput.h"
#include "bladerfthread.h"
+#include "bladerfserializer.h"
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgConfigureBladerf, Message)
MESSAGE_CLASS_DEFINITION(BladerfInput::MsgReportBladerf, Message)
@@ -52,62 +53,53 @@ void BladerfInput::Settings::resetToDefaults()
m_bandwidth = 1500000;
m_log2Decim = 0;
m_fcPos = FC_POS_INFRA;
- m_xb200 = false;
- m_xb200Path = BLADERF_XB200_MIX;
- m_xb200Filter = BLADERF_XB200_AUTO_1DB;
+ m_xb200 = false;
+ m_xb200Path = BLADERF_XB200_MIX;
+ m_xb200Filter = BLADERF_XB200_AUTO_1DB;
}
QByteArray BladerfInput::Settings::serialize() const
{
- SimpleSerializer s(1);
- s.writeS32(1, m_lnaGain);
- s.writeS32(2, m_vga1);
- s.writeS32(3, m_vga2);
- s.writeU32(4, m_log2Decim);
- s.writeBool(5, m_xb200);
- s.writeS32(6, (int) m_xb200Path);
- s.writeS32(7, (int) m_xb200Filter);
- s.writeS32(8, m_bandwidth);
- s.writeS32(9, (int) m_fcPos);
- s.writeU64(10, m_centerFrequency);
- s.writeS32(11, m_devSampleRate);
- return s.final();
+ BladeRFSerializer::BladeRFData data;
+
+ data.m_data.m_lnaGain = m_lnaGain;
+ data.m_data.m_RxGain1 = m_vga1;
+ data.m_data.m_RxGain2 = m_vga2;
+ data.m_data.m_log2Decim = m_log2Decim;
+ data.m_xb200 = m_xb200;
+ data.m_xb200Path = (int) m_xb200Path;
+ data.m_xb200Filter = (int) m_xb200Filter;
+ data.m_data.m_bandwidth = m_bandwidth;
+ data.m_data.m_fcPosition = (int) m_fcPos;
+ data.m_data.m_frequency = m_centerFrequency;
+ data.m_data.m_rate = m_devSampleRate;
+
+ QByteArray byteArray;
+
+ BladeRFSerializer::writeSerializedData(data, byteArray);
+
+ return byteArray;
}
-bool BladerfInput::Settings::deserialize(const QByteArray& data)
+bool BladerfInput::Settings::deserialize(const QByteArray& serializedData)
{
- SimpleDeserializer d(data);
+ BladeRFSerializer::BladeRFData data;
- if (!d.isValid())
- {
- resetToDefaults();
- return false;
- }
+ bool valid = BladeRFSerializer::readSerializedData(serializedData, data);
- if (d.getVersion() == 1)
- {
- int intval;
- d.readS32(1, &m_lnaGain, 0);
- d.readS32(2, &m_vga1, 20);
- d.readS32(3, &m_vga2, 9);
- d.readU32(4, &m_log2Decim, 0);
- d.readBool(5, &m_xb200);
- d.readS32(6, &intval);
- m_xb200Path = (bladerf_xb200_path) intval;
- d.readS32(7, &intval);
- m_xb200Filter = (bladerf_xb200_filter) intval;
- d.readS32(8, &m_bandwidth, 0);
- d.readS32(9, &intval, 0);
- m_fcPos = (fcPos_t) intval;
- d.readU64(10, &m_centerFrequency, 435000*1000);
- d.readS32(11, &m_devSampleRate, 3072000);
- return true;
- }
- else
- {
- resetToDefaults();
- return false;
- }
+ m_lnaGain = data.m_data.m_lnaGain;
+ m_vga1 = data.m_data.m_RxGain1;
+ m_vga2 = data.m_data.m_RxGain2;
+ m_log2Decim = data.m_data.m_log2Decim;
+ m_xb200 = data.m_xb200;
+ m_xb200Path = (bladerf_xb200_path) data.m_xb200Path;
+ m_xb200Filter = (bladerf_xb200_filter) data.m_xb200Filter;
+ m_bandwidth = data.m_data.m_bandwidth;
+ m_fcPos = (fcPos_t) data.m_data.m_fcPosition;
+ m_centerFrequency = data.m_data.m_frequency;
+ m_devSampleRate = data.m_data.m_rate;
+
+ return valid;
}
BladerfInput::BladerfInput() :
diff --git a/plugins/samplesource/bladerf/bladerfserializer.cpp b/plugins/samplesource/bladerf/bladerfserializer.cpp
new file mode 100644
index 000000000..56e465c89
--- /dev/null
+++ b/plugins/samplesource/bladerf/bladerfserializer.cpp
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////////////
+// 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 "bladerfinput.h"
+#include "bladerfserializer.h"
+
+void BladeRFSerializer::writeSerializedData(const BladeRFData& data, QByteArray& serializedData)
+{
+ QByteArray sampleSourceSerialized;
+ SampleSourceSerializer::writeSerializedData(data.m_data, sampleSourceSerialized);
+
+ SimpleSerializer s(1);
+
+ s.writeBlob(1, sampleSourceSerialized);
+ s.writeBool(2, data.m_xb200);
+ s.writeS32(3, (int) data.m_xb200Path);
+ s.writeS32(4, (int) data.m_xb200Filter);
+
+ serializedData = s.final();
+}
+
+bool BladeRFSerializer::readSerializedData(const QByteArray& serializedData, BladeRFData& data)
+{
+ bool valid = SampleSourceSerializer::readSerializedData(serializedData, data.m_data);
+
+ QByteArray sampleSourceSerialized;
+
+ SimpleDeserializer d(serializedData);
+
+ if (!d.isValid())
+ {
+ setDefaults(data);
+ return false;
+ }
+
+ if (d.getVersion() == m_version)
+ {
+ int intval;
+
+ d.readBlob(1, &sampleSourceSerialized);
+ d.readBool(2, &data.m_xb200);
+ d.readS32(3, &intval);
+ data.m_xb200Path = (bladerf_xb200_path) intval;
+ d.readS32(4, &intval);
+ data.m_xb200Filter = (bladerf_xb200_filter) intval;
+
+ return SampleSourceSerializer::readSerializedData(sampleSourceSerialized, data.m_data);
+ }
+ else
+ {
+ setDefaults(data);
+ return false;
+ }
+}
+
+void BladeRFSerializer::setDefaults(BladeRFData& data)
+{
+ data.m_xb200 = false;
+ data.m_xb200Path = BLADERF_XB200_MIX;
+ data.m_xb200Filter = BLADERF_XB200_AUTO_1DB;
+}
diff --git a/plugins/samplesource/bladerf/bladerfserializer.h b/plugins/samplesource/bladerf/bladerfserializer.h
new file mode 100644
index 000000000..7c661911e
--- /dev/null
+++ b/plugins/samplesource/bladerf/bladerfserializer.h
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////////////
+// 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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#ifndef PLUGINS_SAMPLESOURCE_BLADERF_BLADERFSERIALIZER_H_
+#define PLUGINS_SAMPLESOURCE_BLADERF_BLADERFSERIALIZER_H_
+
+#include "util/samplesourceserializer.h"
+
+class BladeRFSerializer : public SampleSourceSerializer
+{
+public:
+ struct BladeRFData
+ {
+ Data m_data;
+ bool m_xb200;
+ quint32 m_xb200Path;
+ quint32 m_xb200Filter;
+ };
+
+ static void writeSerializedData(const BladeRFData& data, QByteArray& serializedData);
+ static bool readSerializedData(const QByteArray& serializedData, BladeRFData& data);
+ static void setDefaults(BladeRFData& data);
+};
+
+
+#endif /* PLUGINS_SAMPLESOURCE_BLADERF_BLADERFSERIALIZER_H_ */
diff --git a/sdrbase/util/samplesourceserializer.cpp b/sdrbase/util/samplesourceserializer.cpp
new file mode 100644
index 000000000..551a321e6
--- /dev/null
+++ b/sdrbase/util/samplesourceserializer.cpp
@@ -0,0 +1,83 @@
+///////////////////////////////////////////////////////////////////////////////////
+// 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 "util/samplesourceserializer.h"
+
+const uint SampleSourceSerializer::m_version = 1;
+
+void SampleSourceSerializer::writeSerializedData(const Data& data, QByteArray& serializedData)
+{
+ SimpleSerializer s(1);
+
+ s.writeU64(1, data.m_frequency);
+ s.writeS32(2, data.m_correction);
+ s.writeS32(3, data.m_rate);
+ s.writeU32(4, data.m_log2Decim);
+ s.writeS32(5, data.m_bandwidth);
+ s.writeS32(6, data.m_fcPosition);
+ s.writeS32(7, data.m_lnaGain);
+ s.writeS32(8, data.m_RxGain1);
+ s.writeS32(9, data.m_RxGain2);
+ s.writeS32(10, data.m_RxGain3);
+
+ serializedData = s.final();
+}
+
+bool SampleSourceSerializer::readSerializedData(const QByteArray& serializedData, Data& data)
+{
+ SimpleDeserializer d(serializedData);
+
+ if (!d.isValid())
+ {
+ setDefaults(data);
+ return false;
+ }
+
+ if (d.getVersion() == m_version)
+ {
+ d.readU64(1, &data.m_frequency, 0);
+ d.readS32(2, &data.m_correction, 0);
+ d.readS32(3, &data.m_rate, 0);
+ d.readU32(4, &data.m_log2Decim, 0);
+ d.readS32(5, &data.m_bandwidth, 0);
+ d.readS32(6, &data.m_fcPosition, 0);
+ d.readS32(7, &data.m_lnaGain, 0);
+ d.readS32(8, &data.m_RxGain1, 0);
+ d.readS32(9, &data.m_RxGain2, 0);
+ d.readS32(10, &data.m_RxGain3, 0);
+
+ return true;
+ }
+ else
+ {
+ setDefaults(data);
+ return false;
+ }
+}
+
+void SampleSourceSerializer::setDefaults(Data& data)
+{
+ data.m_frequency = 0;
+ data.m_correction = 0;
+ data.m_rate = 0;
+ data.m_log2Decim = 0;
+ data.m_bandwidth = 0;
+ data.m_fcPosition = 0;
+ data.m_lnaGain = 0;
+ data.m_RxGain1 = 0;
+ data.m_RxGain2 = 0;
+ data.m_RxGain3 = 0;
+}