2021-09-28 15:01:01 +02:00
|
|
|
#ifndef FRAMEWORK_TMTCSERVICES_PUSPARSER_H_
|
|
|
|
#define FRAMEWORK_TMTCSERVICES_PUSPARSER_H_
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include <cstdint>
|
|
|
|
#include <utility>
|
|
|
|
|
2021-09-28 15:01:01 +02:00
|
|
|
#include "fsfw/container/DynamicFIFO.h"
|
|
|
|
#include "fsfw/returnvalues/FwClassIds.h"
|
|
|
|
|
|
|
|
/**
|
2021-09-28 15:30:01 +02:00
|
|
|
* @brief This small helper class scans a given buffer for space packets.
|
|
|
|
* Can be used if space packets are serialized in a tightly packed frame.
|
2021-09-28 15:01:01 +02:00
|
|
|
* @details
|
2021-09-28 15:30:01 +02:00
|
|
|
* The parser uses the length field field and the 16-bit TC packet ID of the space packets to find
|
|
|
|
* find space packets in a given data stream
|
2021-09-28 15:01:01 +02:00
|
|
|
* @author R. Mueller
|
|
|
|
*/
|
|
|
|
class SpacePacketParser {
|
2022-02-02 10:29:30 +01:00
|
|
|
public:
|
2022-09-01 10:51:09 +02:00
|
|
|
struct FoundPacketInfo {
|
|
|
|
size_t startIdx = 0;
|
|
|
|
size_t sizeFound = 0;
|
|
|
|
};
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
static constexpr uint8_t INTERFACE_ID = CLASS_ID::SPACE_PACKET_PARSER;
|
|
|
|
static constexpr ReturnValue_t NO_PACKET_FOUND = MAKE_RETURN_CODE(0x00);
|
|
|
|
static constexpr ReturnValue_t SPLIT_PACKET = MAKE_RETURN_CODE(0x01);
|
2021-09-28 15:01:01 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Parser constructor.
|
|
|
|
* @param validPacketIds This vector contains the allowed 16-bit TC packet ID start markers
|
|
|
|
* The parser will search for these stark markers to detect the start of a space packet.
|
|
|
|
* It is also possible to pass an empty vector here, but this is not recommended.
|
|
|
|
* If an empty vector is passed, the parser will assume that the start of the given stream
|
|
|
|
* contains the start of a new space packet.
|
|
|
|
*/
|
|
|
|
SpacePacketParser(std::vector<uint16_t> validPacketIds);
|
2021-09-28 15:01:01 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
2022-09-01 10:51:09 +02:00
|
|
|
* Parse a given frame for space packets but also increments the given buffer.
|
2022-02-02 10:29:30 +01:00
|
|
|
* @param buffer Parser will look for space packets in this buffer
|
|
|
|
* @param maxSize Maximum size of the buffer
|
2022-09-01 10:51:09 +02:00
|
|
|
* @param packetInfo Information about packets found.
|
|
|
|
* -@c NO_PACKET_FOUND if no packet was found in the given buffer
|
|
|
|
* -@c SPLIT_PACKET if a packet was found but the detected size exceeds maxSize. packetInfo
|
|
|
|
* will contain the detected packet size and start index.
|
|
|
|
* -@c returnvalue::OK if a packet was found. Packet size and start index will be set in
|
|
|
|
* packetInfo
|
2022-02-02 10:29:30 +01:00
|
|
|
*/
|
2022-09-01 08:51:12 +02:00
|
|
|
ReturnValue_t parseSpacePackets(const uint8_t** buffer, const size_t maxSize,
|
2022-09-01 10:51:09 +02:00
|
|
|
FoundPacketInfo& packetInfo);
|
2021-09-28 15:01:01 +02:00
|
|
|
|
2022-09-05 16:31:56 +02:00
|
|
|
size_t getAmountRead() { return amountRead; }
|
2022-09-01 10:51:09 +02:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
nextStartIdx = 0;
|
|
|
|
amountRead = 0;
|
|
|
|
}
|
2021-09-28 15:30:01 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
private:
|
|
|
|
std::vector<uint16_t> validPacketIds;
|
2022-09-01 10:51:09 +02:00
|
|
|
size_t nextStartIdx = 0;
|
|
|
|
size_t amountRead = 0;
|
2021-09-28 15:01:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ */
|