2020-10-01 13:23:06 +02:00
|
|
|
#include "TcPacketCheck.h"
|
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../globalfunctions/CRC.h"
|
|
|
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
|
|
|
#include "../storagemanager/StorageManagerIF.h"
|
|
|
|
#include "../tmtcservices/VerificationCodes.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
TcPacketCheck::TcPacketCheck( uint16_t setApid ) : apid(setApid) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
ReturnValue_t TcPacketCheck::checkPacket( TcPacketStored* currentPacket ) {
|
|
|
|
uint16_t calculated_crc = CRC::crc16ccitt( currentPacket->getWholeData(),
|
|
|
|
currentPacket->getFullSize() );
|
2016-06-15 23:48:41 +02:00
|
|
|
if ( calculated_crc != 0 ) {
|
|
|
|
return INCORRECT_CHECKSUM;
|
|
|
|
}
|
2020-10-01 13:23:06 +02:00
|
|
|
bool condition = (not currentPacket->hasSecondaryHeader()) or
|
|
|
|
(currentPacket->getPacketVersionNumber() != CCSDS_VERSION_NUMBER) or
|
|
|
|
(not currentPacket->isTelecommand());
|
2016-06-15 23:48:41 +02:00
|
|
|
if ( condition ) {
|
|
|
|
return INCORRECT_PRIMARY_HEADER;
|
|
|
|
}
|
2020-10-01 13:23:06 +02:00
|
|
|
if ( currentPacket->getAPID() != this->apid )
|
2016-06-15 23:48:41 +02:00
|
|
|
return ILLEGAL_APID;
|
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
if ( not currentPacket->isSizeCorrect() ) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return INCOMPLETE_PACKET;
|
|
|
|
}
|
2020-10-01 13:23:06 +02:00
|
|
|
condition = (currentPacket->getSecondaryHeaderFlag() != CCSDS_SECONDARY_HEADER_FLAG) ||
|
|
|
|
(currentPacket->getPusVersionNumber() != PUS_VERSION_NUMBER);
|
2016-06-15 23:48:41 +02:00
|
|
|
if ( condition ) {
|
|
|
|
return INCORRECT_SECONDARY_HEADER;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t TcPacketCheck::getApid() const {
|
|
|
|
return apid;
|
|
|
|
}
|