mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-09-28 15:56:33 -04:00
Deep redesign: revised source serialization mechanism and use dedicated classes for this purpose
This commit is contained in:
parent
f4f9a74269
commit
5f0056f442
@ -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
|
||||
)
|
||||
|
49
include/util/samplesourceserializer.h
Normal file
49
include/util/samplesourceserializer.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#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_ */
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
@ -59,55 +60,46 @@ void BladerfInput::Settings::resetToDefaults()
|
||||
|
||||
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() :
|
||||
|
74
plugins/samplesource/bladerf/bladerfserializer.cpp
Normal file
74
plugins/samplesource/bladerf/bladerfserializer.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#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;
|
||||
}
|
39
plugins/samplesource/bladerf/bladerfserializer.h
Normal file
39
plugins/samplesource/bladerf/bladerfserializer.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#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_ */
|
83
sdrbase/util/samplesourceserializer.cpp
Normal file
83
sdrbase/util/samplesourceserializer.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user