From 49bd8ee2f4f825699f7d03f37c071c82b5450c09 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Wed, 5 Jan 2022 12:23:33 +0100 Subject: [PATCH] Reorganised internal structure of M17LinkSetupFrame class, renamed M17Frame to M17StreamFrame and reorganised its structure --- .../include/protocols/M17/M17LinkSetupFrame.h | 10 +--- .../M17/{M17Frame.h => M17StreamFrame.h} | 58 +++++++++++++------ .../include/protocols/M17/M17Transmitter.h | 4 +- openrtx/include/protocols/M17/M17Utils.h | 2 +- .../src/protocols/M17/M17LinkSetupFrame.cpp | 2 +- openrtx/src/protocols/M17/M17Transmitter.cpp | 2 +- 6 files changed, 47 insertions(+), 31 deletions(-) rename openrtx/include/protocols/M17/{M17Frame.h => M17StreamFrame.h} (65%) diff --git a/openrtx/include/protocols/M17/M17LinkSetupFrame.h b/openrtx/include/protocols/M17/M17LinkSetupFrame.h index 17209531..d8ac8069 100644 --- a/openrtx/include/protocols/M17/M17LinkSetupFrame.h +++ b/openrtx/include/protocols/M17/M17LinkSetupFrame.h @@ -147,10 +147,8 @@ private: */ uint16_t crc16(const void *data, const size_t len); - /** - * Data structure corresponding to a full M17 Link Setup Frame. - */ - typedef struct + + struct __attribute__((packed)) { call_t dst; ///< Destination callsign call_t src; ///< Source callsign @@ -158,9 +156,7 @@ private: meta_t meta; ///< Metadata uint16_t crc; ///< CRC } - __attribute__((packed)) lsf_t; - - lsf_t data; ///< Underlying frame data. + data; ///< Frame data. }; #endif /* M17_LINKSETUPFRAME_H */ diff --git a/openrtx/include/protocols/M17/M17Frame.h b/openrtx/include/protocols/M17/M17StreamFrame.h similarity index 65% rename from openrtx/include/protocols/M17/M17Frame.h rename to openrtx/include/protocols/M17/M17StreamFrame.h index 638ae7aa..27364b97 100644 --- a/openrtx/include/protocols/M17/M17Frame.h +++ b/openrtx/include/protocols/M17/M17StreamFrame.h @@ -1,8 +1,8 @@ /*************************************************************************** - * Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, * - * Niccolò Izzo IU2KIN * - * Frederik Saraci IU2NRO * - * Silvano Seva IU2KWO * + * Copyright (C) 2021 - 2022 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN * + * Frederik Saraci IU2NRO * + * Silvano Seva IU2KWO * * * * 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 * @@ -32,14 +32,14 @@ /** * This class describes and handles a generic M17 data frame. */ -class M17Frame +class M17StreamFrame { public: /** * Constructor. */ - M17Frame() + M17StreamFrame() { clear(); } @@ -47,14 +47,14 @@ public: /** * Destructor. */ - ~M17Frame(){ } + ~M17StreamFrame(){ } /** * Clear the frame content, filling it with zeroes. */ void clear() { - memset(&data, 0x00, sizeof(dataFrame_t)); + memset(&data, 0x00, sizeof(data)); } /** @@ -65,7 +65,18 @@ public: void setFrameNumber(const uint16_t seqNum) { // NOTE: M17 fields are big-endian, we need to swap bytes - data.frameNum = __builtin_bswap16(seqNum & 0x7fff); + data.frameNum = __builtin_bswap16(seqNum & FN_MASK); + } + + /** + * Get frame sequence number. + * + * @return frame number, between 0 and 0x7FFF. + */ + uint16_t getFrameNumber() + { + // NOTE: M17 fields are big-endian, we need to swap bytes + return __builtin_bswap16(data.frameNum); } /** @@ -74,7 +85,18 @@ public: */ void lastFrame() { - data.frameNum |= 0x0080; + data.frameNum |= EOS_BIT; + } + + /** + * Check if this frame is the last one that is, get the value of the EOS + * bit. + * + * @return true if the frame has the EOS bit set. + */ + bool isLastFrame() + { + return ((data.frameNum & EOS_BIT) != 0) ? true : false; } /** @@ -100,17 +122,15 @@ public: private: - /** - * Data structure corresponding to a full M17 data frame. - */ - typedef struct + struct __attribute__((packed)) { - uint16_t frameNum; ///< Frame number - payload_t payload; ///< Payload data + uint16_t frameNum; // Frame number + payload_t payload; // Payload data } - __attribute__((packed)) dataFrame_t; - - dataFrame_t data; ///< Underlying frame data. + data; + ///< Frame data. + static constexpr uint16_t EOS_BIT = 0x0080; ///< End Of Stream bit. + static constexpr uint16_t FN_MASK = 0x7FFF; ///< Bitmask for frame number. }; #endif /* M17_FRAME_H */ diff --git a/openrtx/include/protocols/M17/M17Transmitter.h b/openrtx/include/protocols/M17/M17Transmitter.h index 3927451a..56d441fa 100644 --- a/openrtx/include/protocols/M17/M17Transmitter.h +++ b/openrtx/include/protocols/M17/M17Transmitter.h @@ -29,7 +29,7 @@ #include #include "M17ConvolutionalEncoder.h" #include "M17LinkSetupFrame.h" -#include "M17Frame.h" +#include "M17StreamFrame.h" #include "M17Modulator.h" namespace M17 @@ -83,7 +83,7 @@ private: M17ConvolutionalEncoder encoder; ///< Convolutional encoder. M17LinkSetupFrame lsf; ///< Link Setup Frame handler. - M17Frame dataFrame; ///< Data frame Handler. + M17StreamFrame dataFrame; ///< Data frame Handler. M17Modulator& modulator; ///< 4FSK modulator. std::array< lich_t, 6 > lichSegments; ///< Encoded LSF chunks for LICH generation. uint8_t currentLich; ///< Index of current LSF chunk. diff --git a/openrtx/include/protocols/M17/M17Utils.h b/openrtx/include/protocols/M17/M17Utils.h index 1266e7de..68c1e693 100644 --- a/openrtx/include/protocols/M17/M17Utils.h +++ b/openrtx/include/protocols/M17/M17Utils.h @@ -102,7 +102,7 @@ inline void setSymbol(std::array< uint8_t, N >& array, const size_t pos, setBit (array, 2 * pos + 1, 1); break; default: - assert("Error: storing unknown M17 symbol!"); + assert("Error: unknown M17 symbol!"); } } diff --git a/openrtx/src/protocols/M17/M17LinkSetupFrame.cpp b/openrtx/src/protocols/M17/M17LinkSetupFrame.cpp index 9b75d21a..37a071a0 100644 --- a/openrtx/src/protocols/M17/M17LinkSetupFrame.cpp +++ b/openrtx/src/protocols/M17/M17LinkSetupFrame.cpp @@ -36,7 +36,7 @@ M17LinkSetupFrame::~M17LinkSetupFrame() void M17LinkSetupFrame::clear() { - memset(&data, 0x00, sizeof(lsf_t)); + memset(&data, 0x00, sizeof(data)); data.dst.fill(0xFF); } diff --git a/openrtx/src/protocols/M17/M17Transmitter.cpp b/openrtx/src/protocols/M17/M17Transmitter.cpp index cd051217..680872df 100644 --- a/openrtx/src/protocols/M17/M17Transmitter.cpp +++ b/openrtx/src/protocols/M17/M17Transmitter.cpp @@ -102,7 +102,7 @@ void M17Transmitter::send(const payload_t& payload, const bool isLast) // Encode frame std::array encoded; encoder.reset(); - encoder.encode(dataFrame.getData(), encoded.data(), sizeof(M17Frame)); + encoder.encode(dataFrame.getData(), encoded.data(), sizeof(M17StreamFrame)); encoded[36] = encoder.flush(); std::array punctured;