diff --git a/CMakeLists.txt b/CMakeLists.txt index f21ec5350..f5908243a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/include/util/prettyprint.h b/include/util/prettyprint.h new file mode 100644 index 000000000..f53839532 --- /dev/null +++ b/include/util/prettyprint.h @@ -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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_UTIL_PRETTYPRINT_H_ +#define INCLUDE_UTIL_PRETTYPRINT_H_ + +#include + +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_ */ diff --git a/include/util/samplesourceserializer.h b/include/util/samplesourceserializer.h index 84ce8c21a..c1dad5af2 100644 --- a/include/util/samplesourceserializer.h +++ b/include/util/samplesourceserializer.h @@ -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; } diff --git a/plugins/samplesource/bladerf/bladerfserializer.cpp b/plugins/samplesource/bladerf/bladerfserializer.cpp index 7991e5c47..a24494a37 100644 --- a/plugins/samplesource/bladerf/bladerfserializer.cpp +++ b/plugins/samplesource/bladerf/bladerfserializer.cpp @@ -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); diff --git a/plugins/samplesource/fcd/fcdinput.cpp b/plugins/samplesource/fcd/fcdinput.cpp index b9075b26a..4e23df0b5 100644 --- a/plugins/samplesource/fcd/fcdinput.cpp +++ b/plugins/samplesource/fcd/fcdinput.cpp @@ -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() : diff --git a/plugins/samplesource/fcd/fcdserializer.cpp b/plugins/samplesource/fcd/fcdserializer.cpp new file mode 100644 index 000000000..68dd6d424 --- /dev/null +++ b/plugins/samplesource/fcd/fcdserializer.cpp @@ -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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#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; +} diff --git a/plugins/samplesource/fcd/fcdserializer.h b/plugins/samplesource/fcd/fcdserializer.h new file mode 100644 index 000000000..735dd6a56 --- /dev/null +++ b/plugins/samplesource/fcd/fcdserializer.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_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_ */ diff --git a/plugins/samplesource/rtlsdr/rtlsdrserializer.cpp b/plugins/samplesource/rtlsdr/rtlsdrserializer.cpp index 1571d1db4..ad1d379c7 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrserializer.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrserializer.cpp @@ -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) diff --git a/sdrbase/util/prettyprint.cpp b/sdrbase/util/prettyprint.cpp new file mode 100644 index 000000000..f0fd9b643 --- /dev/null +++ b/sdrbase/util/prettyprint.cpp @@ -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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#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"; diff --git a/sdrbase/util/samplesourceserializer.cpp b/sdrbase/util/samplesourceserializer.cpp index 415b290fe..551a321e6 100644 --- a/sdrbase/util/samplesourceserializer.cpp +++ b/sdrbase/util/samplesourceserializer.cpp @@ -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)