fsfw/src/fsfw/cfdp/pdu/AckPduCreator.cpp

34 lines
1.3 KiB
C++
Raw Normal View History

2022-09-08 12:07:16 +02:00
#include "AckPduCreator.h"
2022-09-08 12:07:16 +02:00
AckPduCreator::AckPduCreator(AckInfo &ackInfo, PduConfig &pduConf)
2022-09-15 18:41:15 +02:00
: FileDirectiveCreator(pduConf, cfdp::FileDirective::ACK, 2), ackInfo(ackInfo) {}
2022-09-08 12:07:16 +02:00
size_t AckPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); }
2022-09-08 12:07:16 +02:00
ReturnValue_t AckPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const {
2022-08-03 16:00:48 +02:00
ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
return result;
}
2022-09-15 18:41:15 +02:00
cfdp::FileDirective ackedDirective = ackInfo.getAckedDirective();
2022-02-02 10:29:30 +01:00
uint8_t directiveSubtypeCode = ackInfo.getDirectiveSubtypeCode();
2022-09-15 18:41:15 +02:00
cfdp::ConditionCode ackedConditionCode = ackInfo.getAckedConditionCode();
2022-02-02 10:29:30 +01:00
cfdp::AckTransactionStatus transactionStatus = ackInfo.getTransactionStatus();
2022-09-15 18:41:15 +02:00
if (ackedDirective != cfdp::FileDirective::FINISH and
ackedDirective != cfdp::FileDirective::EOF_DIRECTIVE) {
2022-02-02 10:29:30 +01:00
// TODO: better returncode
2022-08-16 01:08:26 +02:00
return returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
if (*size + 2 > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
**buffer = ackedDirective << 4 | directiveSubtypeCode;
*buffer += 1;
*size += 1;
**buffer = ackedConditionCode << 4 | transactionStatus;
*buffer += 1;
*size += 1;
2022-08-16 01:08:26 +02:00
return returnvalue::OK;
}