mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-08-14 15:33:34 -04:00
Deep redesign: revised source serialization mechanism and use dedicated classes for this purpose
This commit is contained in:
@@ -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)
|
||||
@@ -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() :
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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_ */
|
||||
Reference in New Issue
Block a user