2020-02-12 17:56:41 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Copyright (C) 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/>. //
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "lorademoddecoder.h"
|
2020-02-19 09:26:42 +01:00
|
|
|
#include "lorademoddecodertty.h"
|
|
|
|
|
#include "lorademoddecoderascii.h"
|
|
|
|
|
#include "lorademoddecoderlora.h"
|
2020-02-12 17:56:41 +01:00
|
|
|
|
|
|
|
|
LoRaDemodDecoder::LoRaDemodDecoder() :
|
|
|
|
|
m_codingScheme(LoRaDemodSettings::CodingTTY),
|
2020-02-19 09:26:42 +01:00
|
|
|
m_nbSymbolBits(5),
|
|
|
|
|
m_nbParityBits(1),
|
|
|
|
|
m_hasCRC(true),
|
|
|
|
|
m_hasHeader(true)
|
2020-02-12 17:56:41 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
LoRaDemodDecoder::~LoRaDemodDecoder()
|
|
|
|
|
{}
|
|
|
|
|
|
2020-02-19 09:26:42 +01:00
|
|
|
void LoRaDemodDecoder::setNbSymbolBits(unsigned int spreadFactor, unsigned int deBits)
|
|
|
|
|
{
|
|
|
|
|
m_spreadFactor = spreadFactor;
|
|
|
|
|
|
|
|
|
|
if (deBits >= spreadFactor) {
|
|
|
|
|
m_deBits = m_spreadFactor - 1;
|
|
|
|
|
} else {
|
|
|
|
|
m_deBits = deBits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_nbSymbolBits = m_spreadFactor - m_deBits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoRaDemodDecoder::decodeSymbols(const std::vector<unsigned short>& symbols, QString& str)
|
2020-02-12 17:56:41 +01:00
|
|
|
{
|
|
|
|
|
switch(m_codingScheme)
|
|
|
|
|
{
|
|
|
|
|
case LoRaDemodSettings::CodingTTY:
|
2020-02-19 09:26:42 +01:00
|
|
|
if (m_nbSymbolBits == 5) {
|
|
|
|
|
LoRaDemodDecoderTTY::decodeSymbols(symbols, str);
|
|
|
|
|
}
|
2020-02-12 17:56:41 +01:00
|
|
|
break;
|
|
|
|
|
case LoRaDemodSettings::CodingASCII:
|
2020-02-19 09:26:42 +01:00
|
|
|
if (m_nbSymbolBits == 5) {
|
|
|
|
|
LoRaDemodDecoderASCII::decodeSymbols(symbols, str);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-02-12 17:56:41 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 09:26:42 +01:00
|
|
|
void LoRaDemodDecoder::decodeSymbols(const std::vector<unsigned short>& symbols, QByteArray& bytes)
|
2020-02-12 17:56:41 +01:00
|
|
|
{
|
2020-02-19 09:26:42 +01:00
|
|
|
switch(m_codingScheme)
|
2020-02-12 17:56:41 +01:00
|
|
|
{
|
2020-02-19 09:26:42 +01:00
|
|
|
case LoRaDemodSettings::CodingLoRa:
|
|
|
|
|
if (m_nbSymbolBits >= 5)
|
2020-02-12 17:56:41 +01:00
|
|
|
{
|
2020-02-19 09:26:42 +01:00
|
|
|
LoRaDemodDecoderLoRa::decodeBytes(
|
|
|
|
|
bytes,
|
|
|
|
|
symbols,
|
|
|
|
|
m_nbSymbolBits,
|
|
|
|
|
m_hasHeader,
|
|
|
|
|
m_hasCRC,
|
|
|
|
|
m_nbParityBits,
|
|
|
|
|
m_packetLength,
|
|
|
|
|
m_errorCheck,
|
|
|
|
|
m_headerParityStatus,
|
|
|
|
|
m_headerCRCStatus,
|
|
|
|
|
m_payloadParityStatus,
|
|
|
|
|
m_payloadCRCStatus
|
|
|
|
|
);
|
2020-02-12 17:56:41 +01:00
|
|
|
}
|
2020-02-19 09:26:42 +01:00
|
|
|
break;
|
2020-02-12 17:56:41 +01:00
|
|
|
}
|
|
|
|
|
}
|