fsfw/src/fsfw/cfdp/pdu/MetadataPduReader.cpp

61 lines
1.9 KiB
C++
Raw Normal View History

2022-08-08 17:53:42 +02:00
#include "MetadataPduReader.h"
2023-07-21 16:09:52 +02:00
MetadataPduReader::MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info,
cfdp::Tlv* optionsArray, size_t optArrayMaxSize)
: FileDirectiveReader(pduBuf, maxSize),
info(info),
optionArray(optionsArray),
optionArrayMaxSize(optArrayMaxSize) {}
2022-08-08 17:53:42 +02:00
ReturnValue_t MetadataPduReader::parseData() {
2023-07-21 16:09:52 +02:00
parsedOptions = 0;
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-02-02 10:29:30 +01:00
return result;
}
2022-08-03 16:00:48 +02:00
size_t currentIdx = FileDirectiveReader::getHeaderSize();
2022-08-08 18:29:32 +02:00
const uint8_t* buf = pointers.rawPtr + currentIdx;
2022-08-03 16:00:48 +02:00
size_t remSize = FileDirectiveReader::getWholePduSize() - currentIdx;
2022-02-02 10:29:30 +01:00
if (remSize < 1) {
return SerializeIF::STREAM_TOO_SHORT;
}
info.setClosureRequested((*buf >> 6) & 0x01);
2022-09-15 18:41:15 +02:00
info.setChecksumType(static_cast<cfdp::ChecksumType>(*buf & 0x0f));
2022-02-02 10:29:30 +01:00
remSize -= 1;
buf += 1;
auto endianness = getEndianness();
result = info.getFileSize().deSerialize(&buf, &remSize, endianness);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
return result;
}
result = info.getSourceFileName().deSerialize(&buf, &remSize, endianness);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
return result;
}
result = info.getDestFileName().deSerialize(&buf, &remSize, endianness);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
2022-02-02 10:29:30 +01:00
return result;
}
if (remSize > 0) {
2023-07-21 16:09:52 +02:00
if (optionArrayMaxSize == 0 or optionArray == nullptr) {
2022-02-02 10:29:30 +01:00
return cfdp::METADATA_CANT_PARSE_OPTIONS;
}
2022-02-02 10:29:30 +01:00
size_t optsIdx = 0;
while (remSize > 0) {
2023-07-21 16:09:52 +02:00
if (optsIdx > optionArrayMaxSize) {
2022-02-02 10:29:30 +01:00
return cfdp::METADATA_CANT_PARSE_OPTIONS;
}
2023-07-21 16:09:52 +02:00
result = optionArray[optsIdx].deSerialize(&buf, &remSize, endianness);
2022-08-16 01:08:26 +02:00
if (result != returnvalue::OK) {
return result;
2022-02-02 10:29:30 +01:00
}
optsIdx++;
}
2023-07-21 16:09:52 +02:00
parsedOptions = optsIdx;
2022-02-02 10:29:30 +01:00
}
return result;
}
2023-07-21 16:09:52 +02:00
size_t MetadataPduReader::getNumberOfParsedOptions() const { return parsedOptions; }