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