fsfw/tcdistribution/TcPacketCheck.cpp

47 lines
1.5 KiB
C++
Raw Normal View History

2020-10-01 13:23:06 +02:00
#include "TcPacketCheck.h"
2020-08-13 20:53:35 +02:00
#include "../globalfunctions/CRC.h"
2021-06-14 10:19:01 +02:00
#include "../tmtcpacket/pus/tc/TcPacketBase.h"
#include "../tmtcpacket/pus/tc/TcPacketStoredBase.h"
2021-06-13 16:29:13 +02:00
#include "../serviceinterface/ServiceInterface.h"
2020-08-13 20:53:35 +02:00
#include "../storagemanager/StorageManagerIF.h"
#include "../tmtcservices/VerificationCodes.h"
2021-06-13 16:29:13 +02:00
TcPacketCheck::TcPacketCheck(uint16_t setApid): apid(setApid) {
}
2021-06-13 16:29:13 +02:00
ReturnValue_t TcPacketCheck::checkPacket(TcPacketStoredBase* currentPacket) {
TcPacketBase* tcPacketBase = currentPacket->getPacketBase();
if(tcPacketBase == nullptr) {
return RETURN_FAILED;
}
uint16_t calculated_crc = CRC::crc16ccitt(tcPacketBase->getWholeData(),
tcPacketBase->getFullSize());
if (calculated_crc != 0) {
return INCORRECT_CHECKSUM;
}
bool condition = (not tcPacketBase->hasSecondaryHeader()) or
(tcPacketBase->getPacketVersionNumber() != CCSDS_VERSION_NUMBER) or
(not tcPacketBase->isTelecommand());
if (condition) {
return INCORRECT_PRIMARY_HEADER;
}
if (tcPacketBase->getAPID() != this->apid)
return ILLEGAL_APID;
2021-06-13 16:29:13 +02:00
if (not currentPacket->isSizeCorrect()) {
return INCOMPLETE_PACKET;
}
2021-06-14 11:44:39 +02:00
2021-06-13 16:29:13 +02:00
condition = (tcPacketBase->getSecondaryHeaderFlag() != CCSDS_SECONDARY_HEADER_FLAG) ||
(tcPacketBase->getPusVersionNumber() != PUS_VERSION_NUMBER);
if (condition) {
return INCORRECT_SECONDARY_HEADER;
}
return RETURN_OK;
}
uint16_t TcPacketCheck::getApid() const {
2021-06-13 16:29:13 +02:00
return apid;
}