1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-11-10 08:10:25 -05:00
sdrangel/plugins/channelrx/demodlora/lorademodsettings.cpp

140 lines
4.4 KiB
C++
Raw Normal View History

2020-02-08 18:21:38 +01:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019-2020 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 //
// (at your option) any later version. //
// //
// 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/>. //
///////////////////////////////////////////////////////////////////////////////////
2017-10-07 22:18:33 +02:00
#include "lorademodsettings.h"
#include <QColor>
#include "dsp/dspengine.h"
#include "util/simpleserializer.h"
#include "settings/serializable.h"
#include "lorademodsettings.h"
const int LoRaDemodSettings::bandwidths[] = {2500, 7813, 10417, 15625, 20833, 31250, 41667, 62500, 125000, 250000, 500000};
const int LoRaDemodSettings::nbBandwidths = 11;
2020-02-12 13:17:15 +01:00
const int LoRaDemodSettings::oversampling = 2;
2017-10-08 00:28:42 +02:00
2017-10-07 22:18:33 +02:00
LoRaDemodSettings::LoRaDemodSettings() :
2020-02-08 18:21:38 +01:00
m_inputFrequencyOffset(0),
2017-10-07 22:18:33 +02:00
m_channelMarker(0),
m_spectrumGUI(0)
{
resetToDefaults();
}
void LoRaDemodSettings::resetToDefaults()
{
2020-02-08 18:21:38 +01:00
m_bandwidthIndex = 5;
m_spreadFactor = 7;
m_deBits = 0;
m_codingScheme = CodingLoRa;
m_decodeActive = true;
m_eomSquelchTenths = 60;
m_nbSymbolsMax = 255;
2020-02-19 09:26:42 +01:00
m_preambleChirps = 8;
m_packetLength = 32;
m_nbParityBits = 1;
m_hasCRC = true;
m_hasHeader = true;
m_errorCheck = false;
2017-10-08 01:42:18 +02:00
m_rgbColor = QColor(255, 0, 255).rgb();
m_title = "LoRa Demodulator";
2017-10-07 22:18:33 +02:00
}
QByteArray LoRaDemodSettings::serialize() const
{
SimpleSerializer s(1);
2020-02-08 18:21:38 +01:00
s.writeS32(1, m_inputFrequencyOffset);
2017-10-08 00:28:42 +02:00
s.writeS32(2, m_bandwidthIndex);
2020-01-30 18:26:43 +01:00
s.writeS32(3, m_spreadFactor);
2017-10-07 22:18:33 +02:00
if (m_spectrumGUI) {
s.writeBlob(4, m_spectrumGUI->serialize());
}
if (m_channelMarker) {
s.writeBlob(5, m_channelMarker->serialize());
}
s.writeString(6, m_title);
2020-02-08 18:21:38 +01:00
s.writeS32(7, m_deBits);
s.writeS32(8, m_codingScheme);
s.writeBool(9, m_decodeActive);
s.writeS32(10, m_eomSquelchTenths);
s.writeS32(11, m_nbSymbolsMax);
2020-02-19 09:26:42 +01:00
s.writeS32(12, m_packetLength);
s.writeS32(13, m_nbParityBits);
s.writeBool(14, m_hasCRC);
s.writeBool(15, m_hasHeader);
s.writeBool(16, m_errorCheck);
s.writeS32(17, m_preambleChirps);
2017-10-07 22:18:33 +02:00
return s.final();
}
bool LoRaDemodSettings::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if(!d.isValid())
{
resetToDefaults();
return false;
}
if(d.getVersion() == 1)
{
QByteArray bytetmp;
int tmp;
2017-10-07 22:18:33 +02:00
2020-02-08 18:21:38 +01:00
d.readS32(1, &m_inputFrequencyOffset, 0);
2017-10-08 00:28:42 +02:00
d.readS32(2, &m_bandwidthIndex, 0);
2020-01-30 18:26:43 +01:00
d.readS32(3, &m_spreadFactor, 0);
2017-10-07 22:18:33 +02:00
if (m_spectrumGUI) {
d.readBlob(4, &bytetmp);
m_spectrumGUI->deserialize(bytetmp);
}
if (m_channelMarker) {
d.readBlob(5, &bytetmp);
m_channelMarker->deserialize(bytetmp);
}
d.readString(6, &m_title, "LoRa Demodulator");
2020-02-08 18:21:38 +01:00
d.readS32(7, &m_deBits, 0);
d.readS32(8, &tmp);
m_codingScheme = (CodingScheme) tmp;
d.readBool(9, &m_decodeActive, true);
d.readS32(10, &m_eomSquelchTenths, 60);
d.readS32(11, &m_nbSymbolsMax, 255);
2020-02-19 09:26:42 +01:00
d.readS32(12, &m_packetLength, 32);
d.readS32(13, &m_nbParityBits, 1);
d.readBool(14, &m_hasCRC, true);
d.readBool(15, &m_hasHeader, true);
d.readBool(16, &m_errorCheck, false);
d.readS32(17, &m_preambleChirps, 8);
2017-10-07 22:18:33 +02:00
return true;
}
else
{
resetToDefaults();
return false;
}
}