fsfw/src/fsfw/tcdistribution/TcPacketCheckPUS.cpp

45 lines
1.7 KiB
C++
Raw Normal View History

#include "fsfw/tcdistribution/TcPacketCheckPUS.h"
2020-10-01 13:23:06 +02:00
2021-07-13 20:22:54 +02:00
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
2022-02-02 10:29:30 +01:00
#include "fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h"
2021-07-13 20:22:54 +02:00
#include "fsfw/tmtcservices/VerificationCodes.h"
2022-02-02 10:29:30 +01:00
TcPacketCheckPUS::TcPacketCheckPUS(uint16_t setApid) : apid(setApid) {}
ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketBase* currentPacket) {
2022-02-02 10:29:30 +01:00
TcPacketStoredBase* storedPacket = dynamic_cast<TcPacketStoredBase*>(currentPacket);
TcPacketPusBase* tcPacketBase = dynamic_cast<TcPacketPusBase*>(currentPacket);
if (tcPacketBase == nullptr or storedPacket == nullptr) {
2022-08-15 20:28:16 +02:00
return returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
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;
2022-02-02 10:29:30 +01:00
if (not storedPacket->isSizeCorrect()) {
return INCOMPLETE_PACKET;
}
2021-06-14 11:44:39 +02:00
2022-02-02 10:29:30 +01:00
condition = (tcPacketBase->getSecondaryHeaderFlag() != CCSDS_SECONDARY_HEADER_FLAG) ||
(tcPacketBase->getPusVersionNumber() != PUS_VERSION_NUMBER);
if (condition) {
return INCORRECT_SECONDARY_HEADER;
}
2022-08-15 20:28:16 +02:00
return returnvalue::OK;
}
2022-02-02 10:29:30 +01:00
uint16_t TcPacketCheckPUS::getApid() const { return apid; }