fsfw/src/fsfw/cfdp/pdu/AckPduReader.cpp

46 lines
1.7 KiB
C++
Raw Normal View History

2022-09-08 12:07:16 +02:00
#include "AckPduReader.h"
2022-09-08 12:07:16 +02:00
AckPduReader::AckPduReader(const uint8_t* pduBuf, size_t maxSize, AckInfo& info)
2022-08-03 16:00:48 +02:00
: FileDirectiveReader(pduBuf, maxSize), info(info) {}
2022-09-08 12:07:16 +02:00
ReturnValue_t AckPduReader::parseData() {
2022-08-03 16:00:48 +02:00
ReturnValue_t result = FileDirectiveReader::parseData();
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-08-22 16:35:53 +02:00
return result;
2022-02-02 10:29:30 +01:00
}
2022-08-03 16:00:48 +02:00
size_t currentIdx = FileDirectiveReader::getHeaderSize();
2022-02-02 10:29:30 +01:00
if (currentIdx + 2 > this->maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
2022-08-08 18:29:32 +02:00
if (not checkAndSetCodes(pointers.rawPtr[currentIdx], pointers.rawPtr[currentIdx + 1])) {
2022-02-02 10:29:30 +01:00
return cfdp::INVALID_ACK_DIRECTIVE_FIELDS;
}
2022-08-16 01:08:26 +02:00
return returnvalue::OK;
}
2022-09-08 12:07:16 +02:00
bool AckPduReader::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) {
2022-09-15 18:41:15 +02:00
cfdp::FileDirective directive;
2022-09-08 12:07:16 +02:00
if (not checkAckedDirectiveField(firstByte, directive)) {
2022-02-02 10:29:30 +01:00
return false;
}
2022-09-08 12:07:16 +02:00
this->info.setAckedDirective(directive);
2022-02-02 10:29:30 +01:00
uint8_t directiveSubtypeCode = firstByte & 0x0f;
if (directiveSubtypeCode != 0b0000 and directiveSubtypeCode != 0b0001) {
return false;
}
this->info.setDirectiveSubtypeCode(directiveSubtypeCode);
2022-09-15 18:41:15 +02:00
this->info.setAckedConditionCode(static_cast<cfdp::ConditionCode>(secondByte >> 4));
2022-02-02 10:29:30 +01:00
this->info.setTransactionStatus(static_cast<cfdp::AckTransactionStatus>(secondByte & 0x0f));
return true;
}
2022-09-08 12:07:16 +02:00
bool AckPduReader::checkAckedDirectiveField(uint8_t firstPduDataByte,
2022-09-15 18:41:15 +02:00
cfdp::FileDirective& ackedDirective) {
uint8_t ackedDirectiveRaw = static_cast<cfdp::FileDirective>(firstPduDataByte >> 4);
if (ackedDirectiveRaw != cfdp::FileDirective::EOF_DIRECTIVE and
ackedDirectiveRaw != cfdp::FileDirective::FINISH) {
2022-09-08 12:07:16 +02:00
return false;
}
2022-09-15 18:41:15 +02:00
ackedDirective = (static_cast<cfdp::FileDirective>(ackedDirectiveRaw));
2022-09-08 12:07:16 +02:00
return true;
}