fsfw/src/fsfw/tcdistribution/PusPacketChecker.cpp

31 lines
1.1 KiB
C++
Raw Normal View History

2022-07-19 18:13:25 +02:00
#include "fsfw/tcdistribution/PusPacketChecker.h"
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tcdistribution/definitions.h"
#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h"
2022-07-27 17:00:43 +02:00
PusPacketChecker::PusPacketChecker(uint16_t apid, ccsds::PacketType packetType_,
2022-07-19 18:13:25 +02:00
ecss::PusVersion pusVersion_)
2022-07-27 17:00:43 +02:00
: pusVersion(pusVersion_), apid(apid) {}
2022-07-19 18:13:25 +02:00
2022-07-27 17:00:43 +02:00
ReturnValue_t PusPacketChecker::checkPacket(const PusTcReader& pusPacket, size_t packetLen) {
2022-07-19 18:13:25 +02:00
// Other primary header fields are checked by base class
2022-07-27 17:00:43 +02:00
if (not pusPacket.hasSecHeader()) {
2022-07-19 18:13:25 +02:00
return tcdistrib::INVALID_SEC_HEADER_FIELD;
}
2022-07-27 17:00:43 +02:00
uint16_t calculated_crc = CRC::crc16ccitt(pusPacket.getFullData(), pusPacket.getFullPacketLen());
2022-07-19 18:13:25 +02:00
if (calculated_crc != 0) {
return tcdistrib::INCORRECT_CHECKSUM;
}
2022-07-27 17:00:43 +02:00
if (pusPacket.getApid() != apid) {
return tcdistrib::INVALID_APID;
2022-07-19 18:13:25 +02:00
}
2022-07-27 17:00:43 +02:00
if (pusPacket.getPusVersion() != pusVersion) {
2022-07-19 18:13:25 +02:00
return tcdistrib::INVALID_PUS_VERSION;
}
2022-08-16 01:08:26 +02:00
return returnvalue::OK;
2022-07-19 18:13:25 +02:00
}
uint16_t PusPacketChecker::getApid() const { return apid; }