start file data pdu processing

This commit is contained in:
Robin Müller 2022-09-02 11:58:16 +02:00
parent dc79b7ba00
commit eae75b29e7
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
3 changed files with 42 additions and 13 deletions

View File

@ -2,6 +2,7 @@
#include <utility> #include <utility>
#include "fsfw/cfdp/pdu/FileDataReader.h"
#include "fsfw/cfdp/pdu/HeaderReader.h" #include "fsfw/cfdp/pdu/HeaderReader.h"
#include "fsfw/objectmanager.h" #include "fsfw/objectmanager.h"
#include "fsfw/serviceinterface.h" #include "fsfw/serviceinterface.h"
@ -18,9 +19,9 @@ cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams)
} }
ReturnValue_t cfdp::DestHandler::performStateMachine() { ReturnValue_t cfdp::DestHandler::performStateMachine() {
if (step == TransactionStep::IDLE) {
ReturnValue_t status = returnvalue::OK;
ReturnValue_t result; ReturnValue_t result;
ReturnValue_t status = returnvalue::OK;
if (step == TransactionStep::IDLE) {
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) {
if (infoIter->pduType == PduType::FILE_DIRECTIVE and if (infoIter->pduType == PduType::FILE_DIRECTIVE and
infoIter->directiveType == FileDirectives::METADATA) { infoIter->directiveType == FileDirectives::METADATA) {
@ -28,18 +29,31 @@ ReturnValue_t cfdp::DestHandler::performStateMachine() {
if (result != OK) { if (result != OK) {
status = result; status = result;
} }
fp.tcStore->deleteData(infoIter->storeId); // metadata packet was deleted in metadata handler because a store guard is used
dp.packetListRef.erase(infoIter++); dp.packetListRef.erase(infoIter++);
} }
} }
if (step == TransactionStep::IDLE) {
// To decrease the already high complexity of the software, all packets arriving before
// a metadata PDU are deleted.
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) {
fp.tcStore->deleteData(infoIter->storeId);
}
dp.packetListRef.clear();
}
if (step != TransactionStep::IDLE) { if (step != TransactionStep::IDLE) {
return CALL_FSM_AGAIN; return CALL_FSM_AGAIN;
} }
return status; return status;
} }
if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) { if (cfdpState == CfdpStates::BUSY_CLASS_1_NACKED) {
for (const auto& info : dp.packetListRef) { for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) {
if (info.pduType == PduType::FILE_DATA) { if (infoIter->pduType == PduType::FILE_DATA) {
result = handleFileDataPdu(*infoIter);
if (result != OK) {
status = result;
}
} }
} }
return returnvalue::OK; return returnvalue::OK;
@ -77,6 +91,7 @@ ReturnValue_t cfdp::DestHandler::initialize() {
} }
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) {
// Process metadata PDU // Process metadata PDU
auto constAccessorPair = fp.tcStore->getData(info.storeId); auto constAccessorPair = fp.tcStore->getData(info.storeId);
@ -102,6 +117,19 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) {
return startTransaction(reader, metadataInfo); return startTransaction(reader, metadataInfo);
} }
ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) {
// Process file data PDU
auto constAccessorPair = fp.tcStore->getData(info.storeId);
if (constAccessorPair.first != OK) {
// TODO: This is not a CFDP error. Event and/or warning?
cfdp::FileSize offset;
FileDataInfo fdInfo(offset);
FileDataReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), fdInfo);
return constAccessorPair.first;
}
return returnvalue::OK;
}
ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData, size_t maxSize) { ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData, size_t maxSize) {
// TODO: try to extract destination ID for error // TODO: try to extract destination ID for error
// TODO: Invalid metadata PDU. // TODO: Invalid metadata PDU.

View File

@ -77,6 +77,7 @@ class DestHandler {
ReturnValue_t initialize(); ReturnValue_t initialize();
ReturnValue_t handleMetadataPdu(const PacketInfo& info); ReturnValue_t handleMetadataPdu(const PacketInfo& info);
ReturnValue_t handleFileDataPdu(const PacketInfo& info);
ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize); ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize);
[[nodiscard]] CfdpStates getCfdpState() const; [[nodiscard]] CfdpStates getCfdpState() const;

View File

@ -6,25 +6,25 @@
class FileDataInfo { class FileDataInfo {
public: public:
FileDataInfo(cfdp::FileSize& offset); explicit FileDataInfo(cfdp::FileSize& offset);
FileDataInfo(cfdp::FileSize& offset, const uint8_t* fileData, size_t fileSize); FileDataInfo(cfdp::FileSize& offset, const uint8_t* fileData, size_t fileSize);
size_t getSerializedSize(bool largeFile = false) const; [[nodiscard]] size_t getSerializedSize(bool largeFile = false) const;
cfdp::FileSize& getOffset(); cfdp::FileSize& getOffset();
const uint8_t* getFileData(size_t* fileSize = nullptr) const; const uint8_t* getFileData(size_t* fileSize = nullptr) const;
void setFileData(const uint8_t* fileData, size_t fileSize); void setFileData(const uint8_t* fileData, size_t fileSize);
cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const; [[nodiscard]] cfdp::SegmentMetadataFlag getSegmentMetadataFlag() const;
cfdp::SegmentationControl getSegmentationControl() const; [[nodiscard]] cfdp::SegmentationControl getSegmentationControl() const;
cfdp::RecordContinuationState getRecordContinuationState() const; [[nodiscard]] cfdp::RecordContinuationState getRecordContinuationState() const;
void setRecordContinuationState(cfdp::RecordContinuationState recContState); void setRecordContinuationState(cfdp::RecordContinuationState recContState);
void setSegmentationControl(cfdp::SegmentationControl segCtrl); void setSegmentationControl(cfdp::SegmentationControl segCtrl);
size_t getSegmentMetadataLen() const; [[nodiscard]] size_t getSegmentMetadataLen() const;
void setSegmentMetadataLen(size_t len); void setSegmentMetadataLen(size_t len);
void setSegmentMetadata(const uint8_t* ptr); void setSegmentMetadata(const uint8_t* ptr);
bool hasSegmentMetadata() const; [[nodiscard]] bool hasSegmentMetadata() const;
void setSegmentMetadataFlag(bool enable); void setSegmentMetadataFlag(bool enable);
ReturnValue_t addSegmentMetadataInfo(cfdp::RecordContinuationState recContState, ReturnValue_t addSegmentMetadataInfo(cfdp::RecordContinuationState recContState,
const uint8_t* segmentMetadata, size_t segmentMetadataLen); const uint8_t* segmentMetadata, size_t segmentMetadataLen);