M17: FrameDecoder: style formatting pass
This commit is contained in:
parent
79d2e9a27e
commit
5fe5cb287b
|
|
@ -8,8 +8,11 @@
|
||||||
# - AlignTrailingComments:
|
# - AlignTrailingComments:
|
||||||
# Kind: Always
|
# Kind: Always
|
||||||
# OverEmptyLines: 1
|
# OverEmptyLines: 1
|
||||||
|
# - BraceWrapping:
|
||||||
|
# AfterClass: true
|
||||||
# - Standard: c++14
|
# - Standard: c++14
|
||||||
# - BreakBeforeBinaryOperators: NonAssignment
|
# - BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
# - PenaltyBreakAssignment: 30
|
||||||
# Original header below
|
# Original header below
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
|
@ -46,7 +49,7 @@ AlwaysBreakTemplateDeclarations: false
|
||||||
BinPackArguments: true
|
BinPackArguments: true
|
||||||
BinPackParameters: true
|
BinPackParameters: true
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
AfterClass: false
|
AfterClass: true
|
||||||
AfterControlStatement: false
|
AfterControlStatement: false
|
||||||
AfterEnum: false
|
AfterEnum: false
|
||||||
AfterFunction: true
|
AfterFunction: true
|
||||||
|
|
@ -105,7 +108,7 @@ ObjCSpaceAfterProperty: true
|
||||||
ObjCSpaceBeforeProtocolList: true
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
|
||||||
# Taken from git's rules
|
# Taken from git's rules
|
||||||
PenaltyBreakAssignment: 10
|
PenaltyBreakAssignment: 30
|
||||||
PenaltyBreakBeforeFirstCallParameter: 30
|
PenaltyBreakBeforeFirstCallParameter: 30
|
||||||
PenaltyBreakComment: 10
|
PenaltyBreakComment: 10
|
||||||
PenaltyBreakFirstLessLess: 0
|
PenaltyBreakFirstLessLess: 0
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,12 @@
|
||||||
namespace M17
|
namespace M17
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class M17FrameType : uint8_t
|
enum class M17FrameType : uint8_t {
|
||||||
{
|
PREAMBLE = 0, ///< Frame contains a preamble.
|
||||||
PREAMBLE = 0, ///< Frame contains a preamble.
|
LINK_SETUP = 1, ///< Frame is a Link Setup Frame.
|
||||||
LINK_SETUP = 1, ///< Frame is a Link Setup Frame.
|
STREAM = 2, ///< Frame is a stream data frame.
|
||||||
STREAM = 2, ///< Frame is a stream data frame.
|
PACKET = 3, ///< Frame is a packet data frame.
|
||||||
PACKET = 3, ///< Frame is a packet data frame.
|
UNKNOWN = 4 ///< Frame is unknown.
|
||||||
UNKNOWN = 4 ///< Frame is unknown.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,7 +49,6 @@ enum class M17FrameType : uint8_t
|
||||||
class M17FrameDecoder
|
class M17FrameDecoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
|
|
@ -73,7 +71,7 @@ public:
|
||||||
* @param frame: byte array containg frame data.
|
* @param frame: byte array containg frame data.
|
||||||
* @return the type of frame recognized.
|
* @return the type of frame recognized.
|
||||||
*/
|
*/
|
||||||
M17FrameType decodeFrame(const frame_t& frame);
|
M17FrameType decodeFrame(const frame_t &frame);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the latest Link Setup Frame decoded. Check of the validity of the
|
* Get the latest Link Setup Frame decoded. Check of the validity of the
|
||||||
|
|
@ -81,7 +79,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return a reference to the latest Link Setup Frame decoded.
|
* @return a reference to the latest Link Setup Frame decoded.
|
||||||
*/
|
*/
|
||||||
const M17LinkSetupFrame& getLsf()
|
const M17LinkSetupFrame &getLsf()
|
||||||
{
|
{
|
||||||
return lsf;
|
return lsf;
|
||||||
}
|
}
|
||||||
|
|
@ -91,13 +89,12 @@ public:
|
||||||
*
|
*
|
||||||
* @return a reference to the latest stream data frame decoded.
|
* @return a reference to the latest stream data frame decoded.
|
||||||
*/
|
*/
|
||||||
const M17StreamFrame& getStreamFrame()
|
const M17StreamFrame &getStreamFrame()
|
||||||
{
|
{
|
||||||
return streamFrame;
|
return streamFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine frame type by searching which syncword among the standard M17
|
* Determine frame type by searching which syncword among the standard M17
|
||||||
* ones has the minumum hamming distance from the given one. If the hamming
|
* ones has the minumum hamming distance from the given one. If the hamming
|
||||||
|
|
@ -107,7 +104,7 @@ private:
|
||||||
* @param syncWord: frame syncword.
|
* @param syncWord: frame syncword.
|
||||||
* @return frame type based on the given syncword.
|
* @return frame type based on the given syncword.
|
||||||
*/
|
*/
|
||||||
M17FrameType getFrameType(const std::array< uint8_t, 2 >& syncWord);
|
M17FrameType getFrameType(const std::array<uint8_t, 2> &syncWord);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode Link Setup Frame data and update the internal LSF field with
|
* Decode Link Setup Frame data and update the internal LSF field with
|
||||||
|
|
@ -115,7 +112,7 @@ private:
|
||||||
*
|
*
|
||||||
* @param data: byte array containg frame data, without sync word.
|
* @param data: byte array containg frame data, without sync word.
|
||||||
*/
|
*/
|
||||||
void decodeLSF(const std::array< uint8_t, 46 >& data);
|
void decodeLSF(const std::array<uint8_t, 46> &data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode stream data and update the internal LSF field with the new
|
* Decode stream data and update the internal LSF field with the new
|
||||||
|
|
@ -123,7 +120,7 @@ private:
|
||||||
*
|
*
|
||||||
* @param data: byte array containg frame data, without sync word.
|
* @param data: byte array containg frame data, without sync word.
|
||||||
*/
|
*/
|
||||||
void decodeStream(const std::array< uint8_t, 46 >& data);
|
void decodeStream(const std::array<uint8_t, 46> &data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode a LICH block.
|
* Decode a LICH block.
|
||||||
|
|
@ -133,19 +130,18 @@ private:
|
||||||
* @param lich: LICH block to be decoded.
|
* @param lich: LICH block to be decoded.
|
||||||
* @return true when the LICH block is successfully decoded.
|
* @return true when the LICH block is successfully decoded.
|
||||||
*/
|
*/
|
||||||
bool decodeLich(std::array< uint8_t, 6 >& segment, const lich_t& lich);
|
bool decodeLich(std::array<uint8_t, 6> &segment, const lich_t &lich);
|
||||||
|
|
||||||
|
uint8_t lsfSegmentMap; ///< Bitmap for LSF reassembly from LICH
|
||||||
uint8_t lsfSegmentMap; ///< Bitmap for LSF reassembly from LICH
|
M17LinkSetupFrame lsf; ///< Latest LSF received.
|
||||||
M17LinkSetupFrame lsf; ///< Latest LSF received.
|
M17LinkSetupFrame lsfFromLich; ///< LSF assembled from LICH segments.
|
||||||
M17LinkSetupFrame lsfFromLich; ///< LSF assembled from LICH segments.
|
M17StreamFrame streamFrame; ///< Latest stream dat frame received.
|
||||||
M17StreamFrame streamFrame; ///< Latest stream dat frame received.
|
M17HardViterbi viterbi; ///< Viterbi decoder.
|
||||||
M17HardViterbi viterbi; ///< Viterbi decoder.
|
|
||||||
|
|
||||||
///< Maximum allowed hamming distance when determining the frame type.
|
///< Maximum allowed hamming distance when determining the frame type.
|
||||||
static constexpr uint8_t MAX_SYNC_HAMM_DISTANCE = 4;
|
static constexpr uint8_t MAX_SYNC_HAMM_DISTANCE = 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace M17
|
} // namespace M17
|
||||||
|
|
||||||
#endif // M17FRAMEDECODER_H
|
#endif // M17FRAMEDECODER_H
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,13 @@
|
||||||
|
|
||||||
using namespace M17;
|
using namespace M17;
|
||||||
|
|
||||||
M17FrameDecoder::M17FrameDecoder() { }
|
M17FrameDecoder::M17FrameDecoder()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
M17FrameDecoder::~M17FrameDecoder() { }
|
M17FrameDecoder::~M17FrameDecoder()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void M17FrameDecoder::reset()
|
void M17FrameDecoder::reset()
|
||||||
{
|
{
|
||||||
|
|
@ -41,10 +45,10 @@ void M17FrameDecoder::reset()
|
||||||
streamFrame.clear();
|
streamFrame.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
M17FrameType M17FrameDecoder::decodeFrame(const frame_t& frame)
|
M17FrameType M17FrameDecoder::decodeFrame(const frame_t &frame)
|
||||||
{
|
{
|
||||||
std::array< uint8_t, 2 > syncWord;
|
std::array<uint8_t, 2> syncWord;
|
||||||
std::array< uint8_t, 46 > data;
|
std::array<uint8_t, 46> data;
|
||||||
|
|
||||||
std::copy_n(frame.begin(), 2, syncWord.begin());
|
std::copy_n(frame.begin(), 2, syncWord.begin());
|
||||||
std::copy(frame.begin() + 2, frame.end(), data.begin());
|
std::copy(frame.begin() + 2, frame.end(), data.begin());
|
||||||
|
|
@ -55,8 +59,7 @@ M17FrameType M17FrameDecoder::decodeFrame(const frame_t& frame)
|
||||||
|
|
||||||
auto type = getFrameType(syncWord);
|
auto type = getFrameType(syncWord);
|
||||||
|
|
||||||
switch(type)
|
switch (type) {
|
||||||
{
|
|
||||||
case M17FrameType::LINK_SETUP:
|
case M17FrameType::LINK_SETUP:
|
||||||
decodeLSF(data);
|
decodeLSF(data);
|
||||||
break;
|
break;
|
||||||
|
|
@ -72,18 +75,19 @@ M17FrameType M17FrameDecoder::decodeFrame(const frame_t& frame)
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
M17FrameType M17FrameDecoder::getFrameType(const std::array< uint8_t, 2 >& syncWord)
|
M17FrameType
|
||||||
|
M17FrameDecoder::getFrameType(const std::array<uint8_t, 2> &syncWord)
|
||||||
{
|
{
|
||||||
// Preamble
|
// Preamble
|
||||||
M17FrameType type = M17FrameType::PREAMBLE;
|
M17FrameType type = M17FrameType::PREAMBLE;
|
||||||
uint8_t minDistance = hammingDistance(syncWord[0], 0x77)
|
uint8_t minDistance = hammingDistance(syncWord[0], 0x77)
|
||||||
+ hammingDistance(syncWord[1], 0x77);
|
+ hammingDistance(syncWord[1], 0x77);
|
||||||
|
|
||||||
// Link setup frame
|
// Link setup frame
|
||||||
uint8_t hammDistance = hammingDistance(syncWord[0], LSF_SYNC_WORD[0])
|
uint8_t hammDistance = hammingDistance(syncWord[0], LSF_SYNC_WORD[0])
|
||||||
+ hammingDistance(syncWord[1], LSF_SYNC_WORD[1]);
|
+ hammingDistance(syncWord[1], LSF_SYNC_WORD[1]);
|
||||||
if(hammDistance < minDistance)
|
|
||||||
{
|
if (hammDistance < minDistance) {
|
||||||
type = M17FrameType::LINK_SETUP;
|
type = M17FrameType::LINK_SETUP;
|
||||||
minDistance = hammDistance;
|
minDistance = hammDistance;
|
||||||
}
|
}
|
||||||
|
|
@ -91,45 +95,43 @@ M17FrameType M17FrameDecoder::getFrameType(const std::array< uint8_t, 2 >& syncW
|
||||||
// Stream frame
|
// Stream frame
|
||||||
hammDistance = hammingDistance(syncWord[0], STREAM_SYNC_WORD[0])
|
hammDistance = hammingDistance(syncWord[0], STREAM_SYNC_WORD[0])
|
||||||
+ hammingDistance(syncWord[1], STREAM_SYNC_WORD[1]);
|
+ hammingDistance(syncWord[1], STREAM_SYNC_WORD[1]);
|
||||||
if(hammDistance < minDistance)
|
|
||||||
{
|
if (hammDistance < minDistance) {
|
||||||
type = M17FrameType::STREAM;
|
type = M17FrameType::STREAM;
|
||||||
minDistance = hammDistance;
|
minDistance = hammDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check value of minimum hamming distance found, if exceeds the allowed
|
// Check value of minimum hamming distance found, if exceeds the allowed
|
||||||
// limit consider the frame as of unknown type.
|
// limit consider the frame as of unknown type.
|
||||||
if(minDistance > MAX_SYNC_HAMM_DISTANCE)
|
if (minDistance > MAX_SYNC_HAMM_DISTANCE) {
|
||||||
{
|
|
||||||
type = M17FrameType::UNKNOWN;
|
type = M17FrameType::UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void M17FrameDecoder::decodeLSF(const std::array< uint8_t, 46 >& data)
|
void M17FrameDecoder::decodeLSF(const std::array<uint8_t, 46> &data)
|
||||||
{
|
{
|
||||||
std::array< uint8_t, sizeof(M17LinkSetupFrame) > tmp;
|
std::array<uint8_t, sizeof(M17LinkSetupFrame)> tmp;
|
||||||
|
|
||||||
viterbi.decodePunctured(data, tmp, LSF_PUNCTURE);
|
viterbi.decodePunctured(data, tmp, LSF_PUNCTURE);
|
||||||
memcpy(&lsf.data, tmp.data(), tmp.size());
|
memcpy(&lsf.data, tmp.data(), tmp.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void M17FrameDecoder::decodeStream(const std::array< uint8_t, 46 >& data)
|
void M17FrameDecoder::decodeStream(const std::array<uint8_t, 46> &data)
|
||||||
{
|
{
|
||||||
// Extract and unpack the LICH segment contained at beginning of frame
|
// Extract and unpack the LICH segment contained at beginning of frame
|
||||||
lich_t lich;
|
lich_t lich;
|
||||||
std::array < uint8_t, 6 > lsfSegment;
|
std::array<uint8_t, 6> lsfSegment;
|
||||||
|
|
||||||
std::copy_n(data.begin(), lich.size(), lich.begin());
|
std::copy_n(data.begin(), lich.size(), lich.begin());
|
||||||
bool decodeOk = decodeLich(lsfSegment, lich);
|
bool decodeOk = decodeLich(lsfSegment, lich);
|
||||||
|
|
||||||
if(decodeOk)
|
if (decodeOk) {
|
||||||
{
|
|
||||||
// Append LICH segment
|
// Append LICH segment
|
||||||
uint8_t segmentNum = lsfSegment[5];
|
uint8_t segmentNum = lsfSegment[5];
|
||||||
uint8_t segmentSize = lsfSegment.size() - 1;
|
uint8_t segmentSize = lsfSegment.size() - 1;
|
||||||
uint8_t *ptr = reinterpret_cast < uint8_t * >(&lsfFromLich.data);
|
uint8_t *ptr = reinterpret_cast<uint8_t *>(&lsfFromLich.data);
|
||||||
ptr += segmentNum * segmentSize;
|
ptr += segmentNum * segmentSize;
|
||||||
memcpy(ptr, lsfSegment.data(), segmentSize);
|
memcpy(ptr, lsfSegment.data(), segmentSize);
|
||||||
|
|
||||||
|
|
@ -137,28 +139,28 @@ void M17FrameDecoder::decodeStream(const std::array< uint8_t, 46 >& data)
|
||||||
lsfSegmentMap |= 1 << segmentNum;
|
lsfSegmentMap |= 1 << segmentNum;
|
||||||
|
|
||||||
// Check if we have received all the six LICH segments
|
// Check if we have received all the six LICH segments
|
||||||
if(lsfSegmentMap == 0x3F)
|
if (lsfSegmentMap == 0x3F) {
|
||||||
{
|
if (lsfFromLich.valid())
|
||||||
if(lsfFromLich.valid()) lsf = lsfFromLich;
|
lsf = lsfFromLich;
|
||||||
lsfSegmentMap = 0;
|
lsfSegmentMap = 0;
|
||||||
lsfFromLich.clear();
|
lsfFromLich.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract and decode stream data
|
// Extract and decode stream data
|
||||||
std::array< uint8_t, 34 > punctured;
|
std::array<uint8_t, 34> punctured;
|
||||||
std::array< uint8_t, sizeof(M17StreamFrame) > tmp;
|
std::array<uint8_t, sizeof(M17StreamFrame)> tmp;
|
||||||
|
|
||||||
auto begin = data.begin();
|
auto begin = data.begin();
|
||||||
begin += lich.size();
|
begin += lich.size();
|
||||||
std::copy(begin, data.end(), punctured.begin());
|
std::copy(begin, data.end(), punctured.begin());
|
||||||
|
|
||||||
viterbi.decodePunctured(punctured, tmp, DATA_PUNCTURE);
|
viterbi.decodePunctured(punctured, tmp, DATA_PUNCTURE);
|
||||||
memcpy(&streamFrame.data, tmp.data(), tmp.size());
|
memcpy(&streamFrame.data, tmp.data(), tmp.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool M17FrameDecoder::decodeLich(std::array < uint8_t, 6 >& segment,
|
bool M17FrameDecoder::decodeLich(std::array<uint8_t, 6> &segment,
|
||||||
const lich_t& lich)
|
const lich_t &lich)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Extract and unpack the LICH segment contained in the frame header.
|
* Extract and unpack the LICH segment contained in the frame header.
|
||||||
|
|
@ -173,31 +175,26 @@ bool M17FrameDecoder::decodeLich(std::array < uint8_t, 6 >& segment,
|
||||||
|
|
||||||
segment.fill(0x00);
|
segment.fill(0x00);
|
||||||
|
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
uint32_t block = 0;
|
uint32_t block = 0;
|
||||||
|
|
||||||
for(size_t i = 0; i < 4; i++)
|
for (size_t i = 0; i < 4; i++) {
|
||||||
{
|
memcpy(&block, lich.data() + 3 * i, 3);
|
||||||
memcpy(&block, lich.data() + 3*i, 3);
|
|
||||||
block = __builtin_bswap32(block) >> 8;
|
block = __builtin_bswap32(block) >> 8;
|
||||||
uint16_t decoded = golay24_decode(block);
|
uint16_t decoded = golay24_decode(block);
|
||||||
|
|
||||||
// Unrecoverable error, abort decoding
|
// Unrecoverable error, abort decoding
|
||||||
if(decoded == 0xFFFF)
|
if (decoded == 0xFFFF) {
|
||||||
{
|
|
||||||
segment.fill(0x00);
|
segment.fill(0x00);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i & 1)
|
if (i & 1) {
|
||||||
{
|
segment[index++] |= (decoded >> 8); // upper 4 bits
|
||||||
segment[index++] |= (decoded >> 8); // upper 4 bits
|
segment[index++] = (decoded & 0xFF); // lower 8 bits
|
||||||
segment[index++] = (decoded & 0xFF); // lower 8 bits
|
} else {
|
||||||
}
|
segment[index++] |= (decoded >> 4); // upper 8 bits
|
||||||
else
|
segment[index] = (decoded & 0x0F) << 4; // lower 4 bits
|
||||||
{
|
|
||||||
segment[index++] |= (decoded >> 4); // upper 8 bits
|
|
||||||
segment[index] = (decoded & 0x0F) << 4; // lower 4 bits
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,7 +203,7 @@ bool M17FrameDecoder::decodeLich(std::array < uint8_t, 6 >& segment,
|
||||||
// zero and five.
|
// zero and five.
|
||||||
segment[5] >>= 5;
|
segment[5] >>= 5;
|
||||||
|
|
||||||
if(segment[5] > 5)
|
if (segment[5] > 5)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,10 @@ openrtx/include/interfaces/radio.h
|
||||||
openrtx/include/peripherals/gps.h
|
openrtx/include/peripherals/gps.h
|
||||||
openrtx/include/peripherals/rng.h
|
openrtx/include/peripherals/rng.h
|
||||||
openrtx/include/peripherals/rtc.h
|
openrtx/include/peripherals/rtc.h
|
||||||
|
openrtx/include/protocols/M17/M17FrameDecoder.hpp
|
||||||
openrtx/src/core/dsp.cpp
|
openrtx/src/core/dsp.cpp
|
||||||
openrtx/src/core/memory_profiling.cpp
|
openrtx/src/core/memory_profiling.cpp
|
||||||
|
openrtx/src/protocols/M17/M17FrameDecoder.cpp
|
||||||
platform/drivers/ADC/ADC0_GDx.h
|
platform/drivers/ADC/ADC0_GDx.h
|
||||||
platform/drivers/audio/MAX9814.h
|
platform/drivers/audio/MAX9814.h
|
||||||
platform/drivers/baseband/MCP4551.h
|
platform/drivers/baseband/MCP4551.h
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue