From 2158208a2fbbd98c1fa5ced154866803f80d04f1 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 6 Jul 2020 00:33:55 +0200 Subject: [PATCH] new pus parser --- osal/linux/TcUnixUdpPollingTask.cpp | 1 - osal/linux/TcUnixUdpPollingTask.h | 2 +- tmtcservices/PusParser.cpp | 10 ++++++ tmtcservices/PusParser.h | 51 +++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tmtcservices/PusParser.cpp create mode 100644 tmtcservices/PusParser.h diff --git a/osal/linux/TcUnixUdpPollingTask.cpp b/osal/linux/TcUnixUdpPollingTask.cpp index 79dbdce2..f237a0f2 100644 --- a/osal/linux/TcUnixUdpPollingTask.cpp +++ b/osal/linux/TcUnixUdpPollingTask.cpp @@ -75,6 +75,5 @@ ReturnValue_t TcSocketPollingTask::initialize() { } ReturnValue_t TcSocketPollingTask::handleSuccessfullTcRead() { - return HasReturnvaluesIF::RETURN_OK; } diff --git a/osal/linux/TcUnixUdpPollingTask.h b/osal/linux/TcUnixUdpPollingTask.h index 09ee6c99..a6b0e9d4 100644 --- a/osal/linux/TcUnixUdpPollingTask.h +++ b/osal/linux/TcUnixUdpPollingTask.h @@ -49,6 +49,6 @@ private: ReturnValue_t handleSuccessfullTcRead(); - +}; #endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */ diff --git a/tmtcservices/PusParser.cpp b/tmtcservices/PusParser.cpp new file mode 100644 index 00000000..76934e33 --- /dev/null +++ b/tmtcservices/PusParser.cpp @@ -0,0 +1,10 @@ +#include + +PusParser::PusParser(uint16_t maxExpectedPusPackets, + bool storeSplitPackets): indexSizePairFIFO(maxExpectedPusPackets) { +} + +ReturnValue_t PusParser::parsePusPackets(const uint8_t *frame, + size_t frameSize) { + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/tmtcservices/PusParser.h b/tmtcservices/PusParser.h new file mode 100644 index 00000000..8fbf9652 --- /dev/null +++ b/tmtcservices/PusParser.h @@ -0,0 +1,51 @@ +#ifndef FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ +#define FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ + +#include + +#include +#include + +/** + * @brief This small helper class scans a given buffer for PUS packets. + * Can be used if PUS packets are serialized in a tightly packed frame. + * @details + * The parser uses the payload length field of PUS packets to find + * the respective PUS packet sizes. + * + * The parser parses a buffer by taking a pointer and the maximum size to scan. + * If PUS packets are found, they are stored in a FIFO which stores pairs + * consisting of the index in the buffer and the respective packet sizes. + * + * If the parser detects split packets (which means that the size of the + * next packet is larger than the remaining size to scan), it can either + * store that split packet or throw away the packet. + */ +class PusParser { +public: + /** + * Parser constructor. + * @param maxExpectedPusPackets + * Maximum expected number of PUS packets. A good estimate is to divide + * the frame size by the minimum size of a PUS packet (12 bytes) + * @param storeSplitPackets + * Specifies whether split packets are also stored inside the FIFO, + * with the size being the remaining frame size. + */ + PusParser(uint16_t maxExpectedPusPackets, bool storeSplitPackets); + + ReturnValue_t parsePusPackets(const uint8_t* frame, size_t frameSize); +private: + //! The first entry is the index inside the buffer while the second index + //! is the size of the PUS packet starting at that index. + using indexSizePair = std::pair; + //! A FIFO is used to store information about multiple PUS packets + //! inside the receive buffer. The maximum number of entries is defined + //! by the first constructor argument. + FIFO indexSizePairFIFO; + + bool storeSplitPackets = false; +}; + + +#endif /* FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ */