From 3dfc8822266e6e90e78ebaa1647bbfab53a58fb9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 11:03:25 +0200 Subject: [PATCH] impl finish PDU sending --- src/fsfw/cfdp/handler/DestHandler.cpp | 29 ++++++++++++++++++- src/fsfw/cfdp/pdu/CMakeLists.txt | 4 +-- src/fsfw/cfdp/pdu/FileDirectiveCreator.h | 4 +++ ...uSerializer.cpp => FinishedPduCreator.cpp} | 14 ++++----- src/fsfw/cfdp/pdu/FinishedPduCreator.h | 24 +++++++++++++++ ...Deserializer.cpp => FinishedPduReader.cpp} | 13 ++++----- ...dPduDeserializer.h => FinishedPduReader.h} | 10 +++---- src/fsfw/cfdp/pdu/FinishedPduSerializer.h | 23 --------------- unittests/cfdp/pdu/testFinishedPdu.cpp | 16 +++++----- 9 files changed, 83 insertions(+), 54 deletions(-) rename src/fsfw/cfdp/pdu/{FinishedPduSerializer.cpp => FinishedPduCreator.cpp} (72%) create mode 100644 src/fsfw/cfdp/pdu/FinishedPduCreator.h rename src/fsfw/cfdp/pdu/{FinishedPduDeserializer.cpp => FinishedPduReader.cpp} (85%) rename src/fsfw/cfdp/pdu/{FinishedPduDeserializer.h => FinishedPduReader.h} (52%) delete mode 100644 src/fsfw/cfdp/pdu/FinishedPduSerializer.h diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index 90e106a8..fcad9c79 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -7,8 +7,10 @@ #include "fsfw/FSFW.h" #include "fsfw/cfdp/pdu/EofPduReader.h" #include "fsfw/cfdp/pdu/FileDataReader.h" +#include "fsfw/cfdp/pdu/FinishedPduCreator.h" #include "fsfw/cfdp/pdu/HeaderReader.h" #include "fsfw/objectmanager.h" +#include "fsfw/tmtcservices/TmTcMessage.h" using namespace returnvalue; @@ -379,6 +381,7 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() { } return OK; } + ReturnValue_t cfdp::DestHandler::noticeOfCompletion() { if (dp.cfg.indicCfg.transactionFinishedIndicRequired) { TransactionFinishedParams params(tp.transactionId, tp.conditionCode, tp.deliveryCode, @@ -388,4 +391,28 @@ ReturnValue_t cfdp::DestHandler::noticeOfCompletion() { return OK; } -ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { return 0; } +ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { + FinishedInfo info(tp.conditionCode, tp.deliveryCode, tp.deliveryStatus); + FinishPduCreator finishedPdu(tp.pduConf, info); + store_address_t storeId; + uint8_t* dataPtr = nullptr; + ReturnValue_t result = + fp.tcStore->getFreeElement(&storeId, finishedPdu.getSerializedSize(), &dataPtr); + if (result != OK) { + // TODO: Error handling and event, this is a non CFDP specific error (most likely store is full) + return result; + } + size_t serLen = 0; + result = finishedPdu.serialize(dataPtr, serLen, finishedPdu.getSerializedSize()); + if (result != OK) { + // TODO: Error printout, this really should not happen + return result; + } + TmTcMessage msg(storeId); + result = fp.msgQueue.sendMessage(fp.packetDest.getReportReceptionQueue(), &msg); + if (result != OK) { + // TODO: Error handling and event, this is a non CFDP specific error (most likely store is full) + return result; + } + return OK; +} diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index 77386d20..a8f0b5a9 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -15,8 +15,8 @@ target_sources( NakPduSerializer.cpp NakPduDeserializer.cpp FinishedInfo.cpp - FinishedPduSerializer.cpp - FinishedPduDeserializer.cpp + FinishedPduCreator.cpp + FinishedPduReader.cpp MetadataInfo.cpp MetadataPduCreator.cpp MetadataPduReader.cpp diff --git a/src/fsfw/cfdp/pdu/FileDirectiveCreator.h b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h index 566ae3cc..6068fe64 100644 --- a/src/fsfw/cfdp/pdu/FileDirectiveCreator.h +++ b/src/fsfw/cfdp/pdu/FileDirectiveCreator.h @@ -16,6 +16,10 @@ class FileDirectiveCreator : public HeaderCreator { */ [[nodiscard]] size_t getSerializedSize() const override; + [[nodiscard]] ReturnValue_t serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const { + return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); + } + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; diff --git a/src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp b/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp similarity index 72% rename from src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp rename to src/fsfw/cfdp/pdu/FinishedPduCreator.cpp index b6f793f7..88f4491c 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduCreator.cpp @@ -1,20 +1,18 @@ -#include "FinishedPduSerializer.h" +#include "FinishedPduCreator.h" -FinishPduSerializer::FinishPduSerializer(PduConfig &conf, FinishedInfo &finishInfo) +FinishPduCreator::FinishPduCreator(PduConfig &conf, FinishedInfo &finishInfo) : FileDirectiveCreator(conf, cfdp::FileDirectives::FINISH, 0), finishInfo(finishInfo) { updateDirectiveFieldLen(); } -size_t FinishPduSerializer::getSerializedSize() const { - return FinishPduSerializer::getWholePduSize(); -} +size_t FinishPduCreator::getSerializedSize() const { return FinishPduCreator::getWholePduSize(); } -void FinishPduSerializer::updateDirectiveFieldLen() { +void FinishPduCreator::updateDirectiveFieldLen() { setDirectiveDataFieldLen(finishInfo.getSerializedSize()); } -ReturnValue_t FinishPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t FinishPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const { ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; diff --git a/src/fsfw/cfdp/pdu/FinishedPduCreator.h b/src/fsfw/cfdp/pdu/FinishedPduCreator.h new file mode 100644 index 00000000..bef59ada --- /dev/null +++ b/src/fsfw/cfdp/pdu/FinishedPduCreator.h @@ -0,0 +1,24 @@ +#ifndef FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ +#define FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ + +#include "FinishedInfo.h" +#include "fsfw/cfdp/pdu/FileDataCreator.h" +#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" + +class FinishPduCreator : public FileDirectiveCreator { + public: + FinishPduCreator(PduConfig& pduConf, FinishedInfo& finishInfo); + + void updateDirectiveFieldLen(); + + [[nodiscard]] size_t getSerializedSize() const override; + + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const override; + using FileDirectiveCreator::serialize; + + private: + FinishedInfo& finishInfo; +}; + +#endif /* FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp b/src/fsfw/cfdp/pdu/FinishedPduReader.cpp similarity index 85% rename from src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp rename to src/fsfw/cfdp/pdu/FinishedPduReader.cpp index 1f3eee18..475942e0 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/FinishedPduReader.cpp @@ -1,10 +1,9 @@ -#include "FinishedPduDeserializer.h" +#include "FinishedPduReader.h" -FinishPduDeserializer::FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize, - FinishedInfo& info) +FinishPduReader::FinishPduReader(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info) : FileDirectiveReader(pduBuf, maxSize), finishedInfo(info) {} -ReturnValue_t FinishPduDeserializer::parseData() { +ReturnValue_t FinishPduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { return result; @@ -29,10 +28,10 @@ ReturnValue_t FinishPduDeserializer::parseData() { return result; } -FinishedInfo& FinishPduDeserializer::getInfo() { return finishedInfo; } +FinishedInfo& FinishPduReader::getInfo() { return finishedInfo; } -ReturnValue_t FinishPduDeserializer::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf, - cfdp::ConditionCode conditionCode) { +ReturnValue_t FinishPduReader::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf, + cfdp::ConditionCode conditionCode) { ReturnValue_t result = returnvalue::OK; size_t fsResponsesIdx = 0; auto endianness = getEndianness(); diff --git a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.h b/src/fsfw/cfdp/pdu/FinishedPduReader.h similarity index 52% rename from src/fsfw/cfdp/pdu/FinishedPduDeserializer.h rename to src/fsfw/cfdp/pdu/FinishedPduReader.h index 1a13cad5..791a2ef4 100644 --- a/src/fsfw/cfdp/pdu/FinishedPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/FinishedPduReader.h @@ -1,12 +1,12 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ +#ifndef FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ +#define FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ #include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/FinishedInfo.h" -class FinishPduDeserializer : public FileDirectiveReader { +class FinishPduReader : public FileDirectiveReader { public: - FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info); + FinishPduReader(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info); ReturnValue_t parseData() override; @@ -19,4 +19,4 @@ class FinishPduDeserializer : public FileDirectiveReader { cfdp::ConditionCode conditionCode); }; -#endif /* FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ */ +#endif /* FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/FinishedPduSerializer.h b/src/fsfw/cfdp/pdu/FinishedPduSerializer.h deleted file mode 100644 index eb162c94..00000000 --- a/src/fsfw/cfdp/pdu/FinishedPduSerializer.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ - -#include "FinishedInfo.h" -#include "fsfw/cfdp/pdu/FileDataCreator.h" -#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" - -class FinishPduSerializer : public FileDirectiveCreator { - public: - FinishPduSerializer(PduConfig& pduConf, FinishedInfo& finishInfo); - - void updateDirectiveFieldLen(); - - size_t getSerializedSize() const override; - - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override; - - private: - FinishedInfo& finishInfo; -}; - -#endif /* FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ */ diff --git a/unittests/cfdp/pdu/testFinishedPdu.cpp b/unittests/cfdp/pdu/testFinishedPdu.cpp index 2f3c466e..194e4252 100644 --- a/unittests/cfdp/pdu/testFinishedPdu.cpp +++ b/unittests/cfdp/pdu/testFinishedPdu.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/FinishedPduDeserializer.h" -#include "fsfw/cfdp/pdu/FinishedPduSerializer.h" +#include "fsfw/cfdp/pdu/FinishedPduCreator.h" +#include "fsfw/cfdp/pdu/FinishedPduReader.h" #include "fsfw/globalfunctions/arrayprinter.h" TEST_CASE("Finished PDU", "[cfdp][pdu]") { @@ -22,7 +22,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); SECTION("Serialize") { - FinishPduSerializer serializer(pduConf, info); + FinishPduCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, fnBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); REQUIRE(serializer.getSerializedSize() == 12); @@ -87,10 +87,10 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { SECTION("Deserialize") { FinishedInfo emptyInfo; - FinishPduSerializer serializer(pduConf, info); + FinishPduCreator serializer(pduConf, info); result = serializer.serialize(&buffer, &sz, fnBuffer.size(), SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - FinishPduDeserializer deserializer(fnBuffer.data(), fnBuffer.size(), emptyInfo); + FinishPduReader deserializer(fnBuffer.data(), fnBuffer.size(), emptyInfo); result = deserializer.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(emptyInfo.getFileStatus() == cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY); @@ -114,7 +114,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { FilestoreResponseTlv emptyResponse(firstNameLv, nullptr); responsePtr = &emptyResponse; emptyInfo.setFilestoreResponsesArray(&responsePtr, nullptr, &len); - FinishPduDeserializer deserializer2(fnBuffer.data(), fnBuffer.size(), emptyInfo); + FinishPduReader deserializer2(fnBuffer.data(), fnBuffer.size(), emptyInfo); result = deserializer2.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(emptyInfo.getFsResponsesLen() == 1); @@ -152,7 +152,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { response.setFilestoreMessage(&emptyFsMsg); emptyInfo.setFilestoreResponsesArray(responses.data(), &len, &len); response2.setFilestoreMessage(&emptyFsMsg); - FinishPduDeserializer deserializer3(fnBuffer.data(), fnBuffer.size(), emptyInfo); + FinishPduReader deserializer3(fnBuffer.data(), fnBuffer.size(), emptyInfo); result = deserializer3.parseData(); REQUIRE(result == returnvalue::OK); auto& infoRef = deserializer3.getInfo(); @@ -181,7 +181,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { REQUIRE(result == cfdp::INVALID_TLV_TYPE); for (size_t maxSz = 0; maxSz < 45; maxSz++) { - FinishPduDeserializer faultyDeser(fnBuffer.data(), maxSz, emptyInfo); + FinishPduReader faultyDeser(fnBuffer.data(), maxSz, emptyInfo); result = faultyDeser.parseData(); REQUIRE(result != returnvalue::OK); }