1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 17:28:50 -05:00

Deep redesign: fixed FCD serialization. Pretty print utilities. Reverted optimization of source serializer

This commit is contained in:
f4exb 2015-08-28 11:12:31 +02:00
parent 38485ae0d0
commit 5101a08632
10 changed files with 218 additions and 9 deletions

View File

@ -111,6 +111,7 @@ set(sdrbase_SOURCES
sdrbase/util/message.cpp
sdrbase/util/messagequeue.cpp
sdrbase/util/prettyprint.cpp
sdrbase/util/syncmessenger.cpp
#sdrbase/util/miniz.cpp
sdrbase/util/samplesourceserializer.cpp
@ -188,6 +189,7 @@ set(sdrbase_HEADERS
include/util/export.h
include/util/message.h
include/util/messagequeue.h
include/util/prettyprint.h
include/util/syncmessenger.h
#include/util/miniz.h
include/util/samplesourceserializer.h

View File

@ -0,0 +1,40 @@
///////////////////////////////////////////////////////////////////////////////////
// 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_PRETTYPRINT_H_
#define INCLUDE_UTIL_PRETTYPRINT_H_
#include <QString>
class EscapeColors
{
public:
static const QString red;
static const QString blue;
static const QString green;
static const QString cyan;
static const QString purple;
static const QString yellow;
static const QString lightRed;
static const QString lightBlue;
static const QString lightGreen;
static const QString lightCyan;
static const QString lightPurple;
static const QString brown;
static const QString terminator;
};
#endif /* INCLUDE_UTIL_PRETTYPRINT_H_ */

View File

@ -36,7 +36,7 @@ public:
qint32 m_RxGain3; //!< Rx third stage amplifier gain
};
static const QByteArray& writeSerializedData(const Data& data);
static void writeSerializedData(const Data& data, QByteArray& serializedData);
static bool readSerializedData(const QByteArray& serializedData, Data& data);
static void setDefaults(Data& data);
static uint getSerializerVersion() { return m_version; }

View File

@ -19,7 +19,8 @@
void BladeRFSerializer::writeSerializedData(const BladeRFData& data, QByteArray& serializedData)
{
const QByteArray& sampleSourceSerialized = SampleSourceSerializer::writeSerializedData(data.m_data);
QByteArray sampleSourceSerialized;
SampleSourceSerializer::writeSerializedData(data.m_data, sampleSourceSerialized);
SimpleSerializer s(1);

View File

@ -25,7 +25,7 @@
#include "fcdgui.h"
#include "qthid.h"
#include "dsp/dspcommands.h"
#include "util/simpleserializer.h"
#include "fcdserializer.h"
MESSAGE_CLASS_DEFINITION(FCDInput::MsgConfigureFCD, Message)
//MESSAGE_CLASS_DEFINITION(FCDInput::MsgReportFCD, Message)
@ -48,16 +48,42 @@ void FCDInput::Settings::resetToDefaults()
QByteArray FCDInput::Settings::serialize() const
{
FCDSerializer::FCDData data;
data.m_data.m_lnaGain = gain;
data.m_data.m_frequency = centerFrequency;
data.m_range = range;
data.m_bias = bias;
QByteArray byteArray;
FCDSerializer::writeSerializedData(data, byteArray);
return byteArray;
/*
SimpleSerializer s(1);
s.writeU64(1, centerFrequency);
s.writeS32(2, range);
s.writeS32(3, gain);
s.writeS32(4, bias);
return s.final();
return s.final();*/
}
bool FCDInput::Settings::deserialize(const QByteArray& data)
bool FCDInput::Settings::deserialize(const QByteArray& serializedData)
{
FCDSerializer::FCDData data;
bool valid = FCDSerializer::readSerializedData(serializedData, data);
gain = data.m_data.m_lnaGain;
centerFrequency = data.m_data.m_frequency;
range = data.m_range;
bias = data.m_bias;
return valid;
/*
SimpleDeserializer d(data);
if (d.isValid() && d.getVersion() == 1)
@ -70,7 +96,7 @@ bool FCDInput::Settings::deserialize(const QByteArray& data)
}
resetToDefaults();
return true;
return true;*/
}
FCDInput::FCDInput() :

View File

@ -0,0 +1,68 @@
///////////////////////////////////////////////////////////////////////////////////
// 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 "fcdserializer.h"
void FCDSerializer::writeSerializedData(const FCDData& data, QByteArray& serializedData)
{
QByteArray sampleSourceSerialized;
SampleSourceSerializer::writeSerializedData(data.m_data, sampleSourceSerialized);
SimpleSerializer s(1);
s.writeBlob(1, sampleSourceSerialized);
s.writeS32(2, data.m_bias);
s.writeS32(3, data.m_range);
serializedData = s.final();
}
bool FCDSerializer::readSerializedData(const QByteArray& serializedData, FCDData& 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_bias);
d.readS32(3, &data.m_range);
return SampleSourceSerializer::readSerializedData(sampleSourceSerialized, data.m_data);
}
else
{
setDefaults(data);
return false;
}
}
void FCDSerializer::setDefaults(FCDData& data)
{
data.m_range = 0;
data.m_bias = 0;
}

View 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_FCD_FCDSERIALIZER_H_
#define PLUGINS_SAMPLESOURCE_FCD_FCDSERIALIZER_H_
#include "util/samplesourceserializer.h"
class FCDSerializer
{
public:
struct FCDData
{
SampleSourceSerializer::Data m_data;
qint32 m_bias;
qint32 m_range;
};
static void writeSerializedData(const FCDData& data, QByteArray& serializedData);
static bool readSerializedData(const QByteArray& serializedData, FCDData& data);
static void setDefaults(FCDData& data);
};
#endif /* PLUGINS_SAMPLESOURCE_FCD_FCDSERIALIZER_H_ */

View File

@ -18,7 +18,7 @@
void RTLSDRSerializer::writeSerializedData(const SampleSourceSerializer::Data& data, QByteArray& serializedData)
{
serializedData = SampleSourceSerializer::writeSerializedData(data);
SampleSourceSerializer::writeSerializedData(data, serializedData);
}
bool RTLSDRSerializer::readSerializedData(const QByteArray& serializedData, SampleSourceSerializer::Data& data)

View File

@ -0,0 +1,33 @@
///////////////////////////////////////////////////////////////////////////////////
// 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/prettyprint.h"
const QString EscapeColors::red = "\033[0;31m";
const QString EscapeColors::blue = "\033[0;34m";
const QString EscapeColors::green = "\033[0;32m";
const QString EscapeColors::cyan = "\033[0;36m";
const QString EscapeColors::purple = "\033[0;35m";
const QString EscapeColors::yellow = "\033[0;33m";
const QString EscapeColors::lightRed = "\033[1;31m";
const QString EscapeColors::lightBlue = "\033[1;34m";
const QString EscapeColors::lightGreen = "\033[1;32m";
const QString EscapeColors::lightCyan = "\033[1;36m";
const QString EscapeColors::lightPurple = "\033[1;35m";
const QString EscapeColors::brown = "\033[1;33m";
const QString EscapeColors::terminator = "\033[0m";

View File

@ -18,7 +18,7 @@
const uint SampleSourceSerializer::m_version = 1;
const QByteArray& SampleSourceSerializer::writeSerializedData(const Data& data)
void SampleSourceSerializer::writeSerializedData(const Data& data, QByteArray& serializedData)
{
SimpleSerializer s(1);
@ -33,7 +33,7 @@ const QByteArray& SampleSourceSerializer::writeSerializedData(const Data& data)
s.writeS32(9, data.m_RxGain2);
s.writeS32(10, data.m_RxGain3);
return s.final();
serializedData = s.final();
}
bool SampleSourceSerializer::readSerializedData(const QByteArray& serializedData, Data& data)