Space Packet Parser CRC Check #41
@ -1,11 +1,16 @@
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <fsfw/tmtcservices/SpacePacketParser.h>
|
||||
#include <fsfw/globalfunctions/CRC.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
SpacePacketParser::SpacePacketParser(std::vector<uint16_t> validPacketIds)
|
||||
: validPacketIds(validPacketIds) {}
|
||||
|
||||
void SpacePacketParser::enableCrcCheck() {
|
||||
checkCrc = true;
|
||||
}
|
||||
|
||||
ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t** buffer, const size_t maxSize,
|
||||
FoundPacketInfo& packetInfo) {
|
||||
if (buffer == nullptr or nextStartIdx > maxSize) {
|
||||
@ -31,6 +36,11 @@ ReturnValue_t SpacePacketParser::parseSpacePackets(const uint8_t** buffer, const
|
||||
}
|
||||
*buffer += packetInfo.sizeFound;
|
||||
packetInfo.startIdx = localIdx + amountRead;
|
||||
if (checkCrc) {
|
||||
if (CRC::crc16ccitt(bufPtr + localIdx, packetSize) != 0) {
|
||||
return CRC_CHECK_FAILED;
|
||||
}
|
||||
}
|
||||
nextStartIdx = localIdx + amountRead + packetInfo.sizeFound;
|
||||
amountRead = nextStartIdx;
|
||||
return result;
|
||||
|
@ -25,6 +25,13 @@ class SpacePacketParser {
|
||||
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);
|
||||
static constexpr ReturnValue_t CRC_CHECK_FAILED = MAKE_RETURN_CODE(0x02);
|
||||
|
||||
/**
|
||||
* brief If the last to bytes of a space packet hold a CRC16, this function can be used to enable
|
||||
* the CRC16 check when parsing the data.
|
||||
*/
|
||||
void enableCrcCheck();
|
||||
|
||||
/**
|
||||
* @brief Parser constructor.
|
||||
@ -61,6 +68,7 @@ class SpacePacketParser {
|
||||
std::vector<uint16_t> validPacketIds;
|
||||
size_t nextStartIdx = 0;
|
||||
size_t amountRead = 0;
|
||||
bool checkCrc = false;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TMTCSERVICES_PUSPARSER_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user