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-13 16:29:13 +02:00
|
|
|
#include "../tmtcpacket/pus/TcPacketBase.h"
|
|
|
|
#include "../tmtcpacket/pus/TcPacketStoredBase.h"
|
|
|
|
#include "../serviceinterface/ServiceInterface.h"
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../storagemanager/StorageManagerIF.h"
|
|
|
|
#include "../tmtcservices/VerificationCodes.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-06-13 16:29:13 +02:00
|
|
|
TcPacketCheck::TcPacketCheck(uint16_t setApid): apid(setApid) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2021-06-13 16:29:13 +02:00
|
|
|
if (not currentPacket->isSizeCorrect()) {
|
|
|
|
return INCOMPLETE_PACKET;
|
|
|
|
}
|
|
|
|
condition = (tcPacketBase->getSecondaryHeaderFlag() != CCSDS_SECONDARY_HEADER_FLAG) ||
|
|
|
|
(tcPacketBase->getPusVersionNumber() != PUS_VERSION_NUMBER);
|
|
|
|
if (condition) {
|
|
|
|
return INCORRECT_SECONDARY_HEADER;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t TcPacketCheck::getApid() const {
|
2021-06-13 16:29:13 +02:00
|
|
|
return apid;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|