this seems to work

This commit is contained in:
2023-07-21 16:09:52 +02:00
parent 6c9c4ee047
commit e00e198ff1
17 changed files with 134 additions and 128 deletions

View File

@ -1,2 +1,4 @@
target_sources(${LIB_FSFW_NAME} PRIVATE SourceHandler.cpp DestHandler.cpp
FaultHandlerBase.cpp UserBase.cpp)
target_sources(
${LIB_FSFW_NAME}
PRIVATE SourceHandler.cpp DestHandler.cpp MetadataParser.cpp
PutRequestReader.cpp FaultHandlerBase.cpp UserBase.cpp)

View File

@ -136,10 +136,8 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) {
cfdp::StringLv sourceFileName;
cfdp::StringLv destFileName;
MetadataInfo metadataInfo(transactionParams.fileSize, sourceFileName, destFileName);
cfdp::Tlv* tlvArrayAsPtr = tlvVec.data();
metadataInfo.setOptionsArray(&tlvArrayAsPtr, std::nullopt, tlvVec.size());
MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(),
metadataInfo);
metadataInfo, nullptr, 0);
ReturnValue_t result = reader.parseData();
// TODO: The standard does not really specify what happens if this kind of error happens
// I think it might be a good idea to cache some sort of error code, which
@ -357,8 +355,9 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met
params.fileSize = transactionParams.fileSize.getSize();
params.destFileName = transactionParams.destName.data();
params.sourceFileName = transactionParams.sourceName.data();
params.msgsToUserArray = dynamic_cast<MessageToUserTlv*>(userTlvVec.data());
params.msgsToUserLen = info.getOptionsLen();
// TODO: Is this really correct? Implement this correctly..
// params.msgsToUserArray = dynamic_cast<MessageToUserTlv*>(userTlvVec.data());
// params.msgsToUserLen = reader.getNumberOfParsedOptions();
destParams.user.metadataRecvdIndication(params);
return result;
}

View File

@ -0,0 +1 @@
#include "MetadataParser.h"

View File

@ -0,0 +1,12 @@
#pragma once
namespace cfdp {
class MetadataParser {
public:
MetadataParser();
private:
};
} // namespace cfdp

View File

@ -0,0 +1 @@
#include "PutRequestReader.h"

View File

@ -0,0 +1,29 @@
#pragma once
#include <optional>
#include <vector>
#include "fsfw/cfdp/VarLenFields.h"
#include "fsfw/cfdp/tlv/FilestoreRequestTlv.h"
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
namespace cfdp {
class PutRequest {
public:
EntityId destId;
std::optional<TransmissionMode> transmissionMode;
char destName[524]{};
std::optional<size_t> destNameSize;
char sourceName[524]{};
std::optional<size_t> sourceNameSize;
std::optional<bool> closureRequested;
std::vector<MessageToUserTlv> messagesToUser;
std::vector<FilestoreRequestTlv> fsRequest;
[[nodiscard]] bool isMetadataOnly() const {
return !destNameSize.has_value() and !sourceNameSize.has_value();
}
};
} // namespace cfdp

View File

@ -157,7 +157,7 @@ ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
cfdp::StringLv sourceName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
cfdp::StringLv destName(transactionParams.destName.data(), transactionParams.destNameSize);
auto metadataInfo = MetadataInfo(transactionParams.fileSize, sourceName, destName);
auto metadataPdu = MetadataPduCreator(transactionParams.pduConf, metadataInfo);
auto metadataPdu = MetadataPduCreator(transactionParams.pduConf, metadataInfo, nullptr, 0);
ReturnValue_t result = sendGenericPdu(metadataPdu);
if (result != OK) {
return result;

View File

@ -57,6 +57,7 @@ struct PutRequestFull {
char sourceName[524]{};
size_t sourceNameSize = 0;
bool closureRequested = true;
// MessageToUserTlv
};
enum class CallStatus { DONE, CALL_AFTER_DELAY, CALL_AGAIN };

View File

@ -12,17 +12,6 @@ MetadataInfo::MetadataInfo(cfdp::Fss& fileSize, cfdp::StringLv& sourceFileName,
cfdp::StringLv& destFileName)
: fileSize(fileSize), sourceFileName(sourceFileName), destFileName(destFileName) {}
void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray_, std::optional<size_t> optionsLen_,
std::optional<size_t> maxOptionsLen_) {
this->optionsArray = optionsArray_;
if (maxOptionsLen_) {
this->maxOptionsLen = maxOptionsLen_.value();
}
if (optionsLen_) {
this->optionsLen = optionsLen_.value();
}
}
cfdp::ChecksumType MetadataInfo::getChecksumType() const { return checksumType; }
void MetadataInfo::setChecksumType(cfdp::ChecksumType checksumType_) {
@ -39,35 +28,6 @@ cfdp::StringLv& MetadataInfo::getDestFileName() { return destFileName; }
cfdp::Fss& MetadataInfo::getFileSize() { return fileSize; }
ReturnValue_t MetadataInfo::getOptions(cfdp::Tlv*** optionsArray_, size_t* optionsLen_,
size_t* maxOptsLen) {
if (optionsArray_ == nullptr or optionsArray == nullptr) {
return returnvalue::FAILED;
}
*optionsArray_ = optionsArray;
if (optionsLen_ != nullptr) {
*optionsLen_ = this->optionsLen;
}
if (maxOptsLen != nullptr) {
*maxOptsLen = this->maxOptionsLen;
}
return returnvalue::OK;
}
bool MetadataInfo::hasOptions() const {
if (optionsArray != nullptr and optionsLen > 0) {
return true;
}
return false;
}
bool MetadataInfo::canHoldOptions() const {
if (optionsArray != nullptr and maxOptionsLen > 0) {
return true;
}
return false;
}
size_t MetadataInfo::getSerializedSize(bool fssLarge) {
// 1 byte + minimal FSS 4 bytes
size_t size = 5;
@ -76,11 +36,6 @@ size_t MetadataInfo::getSerializedSize(bool fssLarge) {
}
size += sourceFileName.getSerializedSize();
size += destFileName.getSerializedSize();
if (hasOptions()) {
for (size_t idx = 0; idx < optionsLen; idx++) {
size += optionsArray[idx]->getSerializedSize();
}
}
return size;
}
@ -92,12 +47,4 @@ void MetadataInfo::setSourceFileName(cfdp::StringLv& sourceFileName_) {
this->sourceFileName = sourceFileName_;
}
size_t MetadataInfo::getMaxOptionsLen() const { return maxOptionsLen; }
void MetadataInfo::setMaxOptionsLen(size_t maxOptionsLen_) { this->maxOptionsLen = maxOptionsLen_; }
size_t MetadataInfo::getOptionsLen() const { return optionsLen; }
void MetadataInfo::setOptionsLen(size_t optionsLen_) { this->optionsLen = optionsLen_; }
cfdp::StringLv& MetadataInfo::getSourceFileName() { return sourceFileName; }

View File

@ -17,8 +17,6 @@ class MetadataInfo {
size_t getSerializedSize(bool fssLarge = false);
void setOptionsArray(cfdp::Tlv** optionsArray, std::optional<size_t> optionsLen,
std::optional<size_t> maxOptionsLen);
[[nodiscard]] cfdp::ChecksumType getChecksumType() const;
void setChecksumType(cfdp::ChecksumType checksumType);
[[nodiscard]] bool isClosureRequested() const;
@ -31,24 +29,12 @@ class MetadataInfo {
cfdp::StringLv& getSourceFileName();
cfdp::Fss& getFileSize();
[[nodiscard]] bool hasOptions() const;
[[nodiscard]] bool canHoldOptions() const;
ReturnValue_t getOptions(cfdp::Tlv*** optionsArray, size_t* optionsLen, size_t* maxOptsLen);
void setOptionsLen(size_t optionsLen);
[[nodiscard]] size_t getOptionsLen() const;
void setMaxOptionsLen(size_t maxOptionsLen);
[[nodiscard]] size_t getMaxOptionsLen() const;
private:
bool closureRequested = false;
cfdp::ChecksumType checksumType = cfdp::ChecksumType::NULL_CHECKSUM;
cfdp::Fss& fileSize;
cfdp::StringLv& sourceFileName;
cfdp::StringLv& destFileName;
cfdp::Tlv** optionsArray = nullptr;
size_t optionsLen = 0;
size_t maxOptionsLen = 0;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_ */

View File

@ -1,12 +1,22 @@
#include "MetadataPduCreator.h"
MetadataPduCreator::MetadataPduCreator(PduConfig &conf, MetadataInfo &info)
: FileDirectiveCreator(conf, cfdp::FileDirective::METADATA, 5), info(info) {
MetadataPduCreator::MetadataPduCreator(PduConfig &conf, MetadataInfo &info,
cfdp::Tlv **optionsArray, size_t optionsLen)
: FileDirectiveCreator(conf, cfdp::FileDirective::METADATA, 5),
info(info),
optionsArray(optionsArray),
optionsLen(optionsLen) {
updateDirectiveFieldLen();
}
void MetadataPduCreator::updateDirectiveFieldLen() {
setDirectiveDataFieldLen(info.getSerializedSize(getLargeFileFlag()));
size_t dirFieldLen = info.getSerializedSize(HeaderCreator::getLargeFileFlag());
if (optionsLen > 0 and optionsArray != nullptr) {
for (size_t idx = 0; idx < optionsLen; idx++) {
dirFieldLen += optionsArray[idx]->getSerializedSize();
}
}
setDirectiveDataFieldLen(dirFieldLen);
}
size_t MetadataPduCreator::getSerializedSize() const {
@ -38,12 +48,9 @@ ReturnValue_t MetadataPduCreator::serialize(uint8_t **buffer, size_t *size, size
return result;
}
if (info.hasOptions()) {
cfdp::Tlv **optsArray = nullptr;
size_t optsLen = 0;
info.getOptions(&optsArray, &optsLen, nullptr);
for (size_t idx = 0; idx < optsLen; idx++) {
result = optsArray[idx]->serialize(buffer, size, maxSize, streamEndianness);
if (optionsLen > 0 and optionsArray != nullptr) {
for (size_t idx = 0; idx < optionsLen; idx++) {
result = optionsArray[idx]->serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}

View File

@ -6,7 +6,8 @@
class MetadataPduCreator : public FileDirectiveCreator {
public:
MetadataPduCreator(PduConfig& conf, MetadataInfo& info);
MetadataPduCreator(PduConfig& conf, MetadataInfo& info, cfdp::Tlv** optionsArray,
size_t optionsLen);
void updateDirectiveFieldLen();
@ -18,6 +19,8 @@ class MetadataPduCreator : public FileDirectiveCreator {
private:
MetadataInfo& info;
cfdp::Tlv** optionsArray;
size_t optionsLen;
};
#endif /* FSFW_CFDP_PDU_METADATAPDUCREATOR_H_ */

View File

@ -1,9 +1,14 @@
#include "MetadataPduReader.h"
MetadataPduReader::MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info)
: FileDirectiveReader(pduBuf, maxSize), info(info) {}
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) {}
ReturnValue_t MetadataPduReader::parseData() {
parsedOptions = 0;
ReturnValue_t result = FileDirectiveReader::parseData();
if (result != returnvalue::OK) {
return result;
@ -32,26 +37,24 @@ ReturnValue_t MetadataPduReader::parseData() {
return result;
}
info.setOptionsLen(0);
if (remSize > 0) {
if (not info.canHoldOptions()) {
if (optionArrayMaxSize == 0 or optionArray == nullptr) {
return cfdp::METADATA_CANT_PARSE_OPTIONS;
}
cfdp::Tlv** optionsArray = nullptr;
size_t optsMaxLen = 0;
size_t optsIdx = 0;
info.getOptions(&optionsArray, nullptr, &optsMaxLen);
while (remSize > 0) {
if (optsIdx > optsMaxLen) {
if (optsIdx > optionArrayMaxSize) {
return cfdp::METADATA_CANT_PARSE_OPTIONS;
}
result = optionsArray[optsIdx]->deSerialize(&buf, &remSize, endianness);
result = optionArray[optsIdx].deSerialize(&buf, &remSize, endianness);
if (result != returnvalue::OK) {
return result;
}
optsIdx++;
}
info.setOptionsLen(optsIdx);
parsedOptions = optsIdx;
}
return result;
}
size_t MetadataPduReader::getNumberOfParsedOptions() const { return parsedOptions; }

View File

@ -6,12 +6,17 @@
class MetadataPduReader : public FileDirectiveReader {
public:
MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info);
MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info,
cfdp::Tlv* optionsArray, size_t optArrayMaxSize);
ReturnValue_t parseData() override;
[[nodiscard]] size_t getNumberOfParsedOptions() const;
private:
MetadataInfo& info;
cfdp::Tlv* optionArray;
size_t optionArrayMaxSize;
size_t parsedOptions = 0;
};
#endif /* FSFW_CFDP_PDU_METADATAPDUREADER_H_ */