From 3e1fd15613a5311a5e98f40216be21ce0bb5f0d6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 10 Aug 2022 10:34:02 +0200 Subject: [PATCH] completed all indication parameters --- src/fsfw/cfdp/handler/UserBase.cpp | 9 --------- src/fsfw/cfdp/handler/UserBase.h | 23 +++++++++------------- src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp | 4 ++-- src/fsfw/cfdp/tlv/FilestoreRequestTlv.h | 8 ++++---- src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp | 12 +++++------ src/fsfw/cfdp/tlv/FilestoreResponseTlv.h | 15 +++++++------- src/fsfw/cfdp/tlv/FilestoreTlvBase.h | 17 ++++++++-------- src/fsfw/cfdp/tlv/StringLv.cpp | 2 ++ src/fsfw/cfdp/tlv/StringLv.h | 1 + unittests/cfdp/handler/testDestHandler.cpp | 2 -- unittests/cfdp/pdu/testFinishedPdu.cpp | 8 ++++---- unittests/cfdp/pdu/testMetadataPdu.cpp | 3 +-- unittests/cfdp/testOtherTlvs.cpp | 12 +++++------ unittests/mocks/cfdp/UserMock.cpp | 10 ++++++---- unittests/mocks/cfdp/UserMock.h | 11 ++++++----- 15 files changed, 64 insertions(+), 73 deletions(-) diff --git a/src/fsfw/cfdp/handler/UserBase.cpp b/src/fsfw/cfdp/handler/UserBase.cpp index 1cb726fe..9e757896 100644 --- a/src/fsfw/cfdp/handler/UserBase.cpp +++ b/src/fsfw/cfdp/handler/UserBase.cpp @@ -2,14 +2,5 @@ #include #include -void cfdp::testFunc() { - std::vector testVec; - testVec.reserve(10); - std::array customMsg = {1, 2, 3, 4}; - MessageToUserTlv tlv0(customMsg.data(), customMsg.size()); - std::cout << testVec.size() << std::endl; - testVec[0] = &tlv0; - FilestoreResponseTlv tlv1(); -} cfdp::UserBase::UserBase(HasFileSystemIF& vfs) : vfs(vfs) {} diff --git a/src/fsfw/cfdp/handler/UserBase.h b/src/fsfw/cfdp/handler/UserBase.h index 333c7b6b..34af89a5 100644 --- a/src/fsfw/cfdp/handler/UserBase.h +++ b/src/fsfw/cfdp/handler/UserBase.h @@ -13,8 +13,6 @@ namespace cfdp { -void testFunc(); - struct TransactionFinishedParams { TransactionFinishedParams(TransactionId id, ConditionCode code, FileDeliveryStatus status, FileDeliveryCode delivCode) @@ -24,18 +22,17 @@ struct TransactionFinishedParams { ConditionCode condCode; FileDeliveryStatus status; FileDeliveryCode deliveryCode; - std::pair fsResponses; + std::vector fsResponses; StatusReportIF* statusReport = nullptr; }; -struct MetadataRecvParams { +struct MetadataRecvdParams { TransactionId id; EntityId sourceId; size_t fileSize; const char* sourceFileName; const char* destFileName; std::vector msgsToUser; - // std::pair msgsToUser; }; struct FileSegmentRecvdParams { @@ -65,17 +62,15 @@ class UserBase { virtual void transactionIndication(TransactionId id) = 0; virtual void eofSentIndication(TransactionId id) = 0; - - virtual void abandonedIndication(TransactionId id, ConditionCode code, uint64_t progress) = 0; - virtual void eofRecvIndication(TransactionId id) = 0; - - // TODO: Parameters virtual void transactionFinishedIndication(TransactionFinishedParams params) = 0; - virtual void metadataRecvdIndication(MetadataRecvParams params) = 0; + virtual void metadataRecvdIndication(MetadataRecvdParams params) = 0; virtual void fileSegmentRecvdIndication(FileSegmentRecvdParams params) = 0; - virtual void reportIndication() = 0; - virtual void suspendedIndication() = 0; - virtual void resumedIndication() = 0; + virtual void reportIndication(TransactionId id, StatusReportIF& report) = 0; + virtual void suspendedIndication(TransactionId id, ConditionCode code) = 0; + virtual void resumedIndication(TransactionId id, size_t progress) = 0; + virtual void faultIndication(TransactionId id, ConditionCode code, size_t progress) = 0; + virtual void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) = 0; + virtual void eofRecvIndication(TransactionId id) = 0; private: HasFileSystemIF& vfs; diff --git a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp index 9ad7c645..eb7a2cd2 100644 --- a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp +++ b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.cpp @@ -3,10 +3,10 @@ #include "fsfw/FSFW.h" FilestoreRequestTlv::FilestoreRequestTlv(cfdp::FilestoreActionCode actionCode, - cfdp::Lv &firstFileName) + cfdp::StringLv &firstFileName) : FilestoreTlvBase(actionCode, firstFileName) {} -FilestoreRequestTlv::FilestoreRequestTlv(cfdp::Lv &firstFileName) +FilestoreRequestTlv::FilestoreRequestTlv(cfdp::StringLv &firstFileName) : FilestoreTlvBase(cfdp::FilestoreActionCode::INVALID, firstFileName) {} void FilestoreRequestTlv::setSecondFileName(cfdp::Lv *secondFileName) { diff --git a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h index 5acb0ef4..94faaa07 100644 --- a/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h +++ b/src/fsfw/cfdp/tlv/FilestoreRequestTlv.h @@ -9,9 +9,9 @@ class FilestoreRequestTlv : public cfdp::FilestoreTlvBase { public: - FilestoreRequestTlv(cfdp::FilestoreActionCode actionCode, cfdp::Lv &firstFileName); + FilestoreRequestTlv(cfdp::FilestoreActionCode actionCode, cfdp::StringLv &firstFileName); - FilestoreRequestTlv(cfdp::Lv &firstFileName); + explicit FilestoreRequestTlv(cfdp::StringLv &firstFileName); void setSecondFileName(cfdp::Lv *secondFileName); @@ -29,8 +29,8 @@ class FilestoreRequestTlv : public cfdp::FilestoreTlvBase { ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) override; - uint8_t getLengthField() const override; - cfdp::TlvTypes getType() const override; + [[nodiscard]] uint8_t getLengthField() const override; + [[nodiscard]] cfdp::TlvTypes getType() const override; private: cfdp::Lv *secondFileName = nullptr; diff --git a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp index 36945725..c4c72702 100644 --- a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp +++ b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.cpp @@ -1,10 +1,10 @@ #include "FilestoreResponseTlv.h" FilestoreResponseTlv::FilestoreResponseTlv(cfdp::FilestoreActionCode actionCode, uint8_t statusCode, - cfdp::Lv &firstFileName, cfdp::Lv *fsMsg) + cfdp::StringLv &firstFileName, cfdp::Lv *fsMsg) : FilestoreTlvBase(actionCode, firstFileName), statusCode(statusCode), filestoreMsg(fsMsg) {} -FilestoreResponseTlv::FilestoreResponseTlv(cfdp::Lv &firstFileName, cfdp::Lv *fsMsg) +FilestoreResponseTlv::FilestoreResponseTlv(cfdp::StringLv &firstFileName, cfdp::Lv *fsMsg) : FilestoreTlvBase(firstFileName), statusCode(0), filestoreMsg(fsMsg) {} uint8_t FilestoreResponseTlv::getLengthField() const { @@ -20,12 +20,12 @@ uint8_t FilestoreResponseTlv::getLengthField() const { return 1 + firstFileName.getSerializedSize() + optFieldsLen; } -void FilestoreResponseTlv::setSecondFileName(cfdp::Lv *secondFileName) { - this->secondFileName = secondFileName; +void FilestoreResponseTlv::setSecondFileName(cfdp::StringLv *secondFileName_) { + this->secondFileName = secondFileName_; } -void FilestoreResponseTlv::setFilestoreMessage(cfdp::Lv *filestoreMsg) { - this->filestoreMsg = filestoreMsg; +void FilestoreResponseTlv::setFilestoreMessage(cfdp::Lv *filestoreMsg_) { + this->filestoreMsg = filestoreMsg_; } ReturnValue_t FilestoreResponseTlv::serialize(uint8_t **buffer, size_t *size, size_t maxSize, diff --git a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h index 7b68ba57..47868693 100644 --- a/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h +++ b/src/fsfw/cfdp/tlv/FilestoreResponseTlv.h @@ -4,17 +4,18 @@ #include "Lv.h" #include "TlvIF.h" #include "fsfw/cfdp/tlv/FilestoreTlvBase.h" +#include "fsfw/cfdp/tlv/StringLv.h" #include "fsfw/cfdp/tlv/Tlv.h" class FilestoreResponseTlv : public cfdp::FilestoreTlvBase { public: - FilestoreResponseTlv(cfdp::Lv& firstFileName, cfdp::Lv* fsMsg); + FilestoreResponseTlv(cfdp::StringLv& firstFileName, cfdp::Lv* fsMsg); FilestoreResponseTlv(cfdp::FilestoreActionCode actionCode, uint8_t statusCode, - cfdp::Lv& firstFileName, cfdp::Lv* fsMsg); + cfdp::StringLv& firstFileName, cfdp::Lv* fsMsg); - uint8_t getStatusCode() const; - void setSecondFileName(cfdp::Lv* secondFileName); + [[nodiscard]] uint8_t getStatusCode() const; + void setSecondFileName(cfdp::StringLv* secondFileName); void setFilestoreMessage(cfdp::Lv* filestoreMsg); ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, @@ -31,12 +32,12 @@ class FilestoreResponseTlv : public cfdp::FilestoreTlvBase { ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override; - uint8_t getLengthField() const override; - cfdp::TlvTypes getType() const override; + [[nodiscard]] uint8_t getLengthField() const override; + [[nodiscard]] cfdp::TlvTypes getType() const override; private: uint8_t statusCode; - cfdp::Lv* secondFileName = nullptr; + cfdp::StringLv* secondFileName = nullptr; cfdp::Lv* filestoreMsg = nullptr; ReturnValue_t deSerializeFromValue(const uint8_t** buffer, size_t* size, diff --git a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h index 04012cda..2db08946 100644 --- a/src/fsfw/cfdp/tlv/FilestoreTlvBase.h +++ b/src/fsfw/cfdp/tlv/FilestoreTlvBase.h @@ -11,6 +11,7 @@ #include #include +#include "StringLv.h" #include "fsfw/FSFW.h" namespace cfdp { @@ -65,8 +66,8 @@ static constexpr uint8_t FSR_DENY_DIR_NOT_ALLOWED = 0b0010; class FilestoreTlvBase : public TlvIF { public: - FilestoreTlvBase(cfdp::Lv& firstFileName) : firstFileName(firstFileName){}; - FilestoreTlvBase(FilestoreActionCode actionCode, cfdp::Lv& firstFileName) + explicit FilestoreTlvBase(cfdp::StringLv& firstFileName) : firstFileName(firstFileName){}; + FilestoreTlvBase(FilestoreActionCode actionCode, cfdp::StringLv& firstFileName) : actionCode(actionCode), firstFileName(firstFileName){}; ReturnValue_t commonSerialize(uint8_t** buffer, size_t* size, size_t maxSize, @@ -101,7 +102,7 @@ class FilestoreTlvBase : public TlvIF { if (*size < 3) { return SerializeIF::STREAM_TOO_SHORT; } - cfdp::TlvTypes type = static_cast(**buffer); + auto type = static_cast(**buffer); if (type != getType()) { return cfdp::INVALID_TLV_TYPE; } @@ -117,7 +118,7 @@ class FilestoreTlvBase : public TlvIF { return HasReturnvaluesIF::RETURN_OK; } - bool requiresSecondFileName() const { + [[nodiscard]] bool requiresSecondFileName() const { using namespace cfdp; if (actionCode == FilestoreActionCode::RENAME_FILE or actionCode == FilestoreActionCode::APPEND_FILE or @@ -141,9 +142,9 @@ class FilestoreTlvBase : public TlvIF { #endif } - FilestoreActionCode getActionCode() const { return actionCode; } + [[nodiscard]] FilestoreActionCode getActionCode() const { return actionCode; } - void setActionCode(FilestoreActionCode actionCode) { this->actionCode = actionCode; } + void setActionCode(FilestoreActionCode actionCode_) { this->actionCode = actionCode_; } cfdp::Lv& getFirstFileName() { return firstFileName; } @@ -160,11 +161,11 @@ class FilestoreTlvBase : public TlvIF { return result; } - size_t getSerializedSize() const override { return getLengthField() + 2; } + [[nodiscard]] size_t getSerializedSize() const override { return getLengthField() + 2; } protected: FilestoreActionCode actionCode = FilestoreActionCode::INVALID; - cfdp::Lv& firstFileName; + cfdp::StringLv& firstFileName; }; } // namespace cfdp diff --git a/src/fsfw/cfdp/tlv/StringLv.cpp b/src/fsfw/cfdp/tlv/StringLv.cpp index abbdb34a..60c278a7 100644 --- a/src/fsfw/cfdp/tlv/StringLv.cpp +++ b/src/fsfw/cfdp/tlv/StringLv.cpp @@ -5,3 +5,5 @@ cfdp::StringLv::StringLv(const std::string& fileName) cfdp::StringLv::StringLv(const char* filename, size_t len) : Lv(reinterpret_cast(filename), len) {} + +cfdp::StringLv::StringLv() : Lv() {} diff --git a/src/fsfw/cfdp/tlv/StringLv.h b/src/fsfw/cfdp/tlv/StringLv.h index 86c2d738..a6cc8e20 100644 --- a/src/fsfw/cfdp/tlv/StringLv.h +++ b/src/fsfw/cfdp/tlv/StringLv.h @@ -9,6 +9,7 @@ namespace cfdp { class StringLv : public Lv { public: + StringLv(); explicit StringLv(const std::string& fileName); explicit StringLv(const char* filename, size_t len); }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 7d641a38..32ed606d 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -8,8 +8,6 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { EntityId localId = EntityId(UnsignedByteField(2)); auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); - // auto destHandler = DestHandler(); - cfdp::testFunc(); SECTION("State") {} } \ No newline at end of file diff --git a/unittests/cfdp/pdu/testFinishedPdu.cpp b/unittests/cfdp/pdu/testFinishedPdu.cpp index d117ed58..d5d17124 100644 --- a/unittests/cfdp/pdu/testFinishedPdu.cpp +++ b/unittests/cfdp/pdu/testFinishedPdu.cpp @@ -35,7 +35,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { // Add a filestore response std::string firstName = "hello.txt"; - cfdp::Lv firstNameLv(reinterpret_cast(firstName.data()), firstName.size()); + cfdp::StringLv firstNameLv(firstName); FilestoreResponseTlv response(cfdp::FilestoreActionCode::DELETE_FILE, cfdp::FSR_APPEND_FILE_1_NOT_EXISTS, firstNameLv, nullptr); FilestoreResponseTlv* responsePtr = &response; @@ -53,7 +53,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { // Add two filestore responses and a fault location parameter std::string secondName = "hello2.txt"; - cfdp::Lv secondNameLv(reinterpret_cast(secondName.data()), secondName.size()); + cfdp::StringLv secondNameLv(secondName); FilestoreResponseTlv response2(cfdp::FilestoreActionCode::DENY_FILE, cfdp::FSR_SUCCESS, secondNameLv, nullptr); REQUIRE(response2.getSerializedSize() == 15); @@ -101,7 +101,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { sz = 0; buffer = fnBuffer.data(); std::string firstName = "hello.txt"; - cfdp::Lv firstNameLv(reinterpret_cast(firstName.data()), firstName.size()); + cfdp::StringLv firstNameLv(firstName); FilestoreResponseTlv response(cfdp::FilestoreActionCode::DELETE_FILE, cfdp::FSR_NOT_PERFORMED, firstNameLv, nullptr); FilestoreResponseTlv* responsePtr = &response; @@ -130,7 +130,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") { // Add two filestore responses and a fault location parameter std::string secondName = "hello2.txt"; - cfdp::Lv secondNameLv(reinterpret_cast(secondName.data()), secondName.size()); + cfdp::StringLv secondNameLv(secondName); FilestoreResponseTlv response2(cfdp::FilestoreActionCode::DENY_FILE, cfdp::FSR_SUCCESS, secondNameLv, nullptr); REQUIRE(response2.getSerializedSize() == 15); diff --git a/unittests/cfdp/pdu/testMetadataPdu.cpp b/unittests/cfdp/pdu/testMetadataPdu.cpp index dec3b479..0dbc4a70 100644 --- a/unittests/cfdp/pdu/testMetadataPdu.cpp +++ b/unittests/cfdp/pdu/testMetadataPdu.cpp @@ -20,8 +20,7 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") { PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); std::string firstFileName = "hello.txt"; - cfdp::Lv sourceFileName(reinterpret_cast(firstFileName.data()), - firstFileName.size()); + cfdp::StringLv sourceFileName(firstFileName); cfdp::Lv destFileName; FileSize fileSize(35); MetadataInfo info(false, ChecksumType::MODULAR, fileSize, sourceFileName, destFileName); diff --git a/unittests/cfdp/testOtherTlvs.cpp b/unittests/cfdp/testOtherTlvs.cpp index 3551fcdf..d8167e87 100644 --- a/unittests/cfdp/testOtherTlvs.cpp +++ b/unittests/cfdp/testOtherTlvs.cpp @@ -25,9 +25,9 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { SECTION("Filestore Response TLV") { std::string name = "hello.txt"; - cfdp::Lv firstName(reinterpret_cast(name.data()), name.size()); + cfdp::StringLv firstName(name); std::string name2 = "hello2.txt"; - cfdp::Lv secondName(reinterpret_cast(name2.data()), name2.size()); + cfdp::StringLv secondName(name2); std::string msg = "12345"; cfdp::Lv fsMsg(reinterpret_cast(msg.data()), msg.size()); FilestoreResponseTlv response(cfdp::FilestoreActionCode::APPEND_FILE, cfdp::FSR_SUCCESS, @@ -42,8 +42,8 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { SerializeIF::Endianness::NETWORK); REQUIRE(result == HasReturnvaluesIF::RETURN_OK); REQUIRE(rawResponse.getType() == cfdp::TlvTypes::FILESTORE_RESPONSE); - cfdp::Lv emptyMsg; - cfdp::Lv emptySecondName; + cfdp::StringLv emptyMsg; + cfdp::StringLv emptySecondName; FilestoreResponseTlv emptyTlv(firstName, &emptyMsg); emptyTlv.setSecondFileName(&emptySecondName); result = emptyTlv.deSerialize(rawResponse, SerializeIF::Endianness::NETWORK); @@ -59,9 +59,9 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") { SECTION("Filestore Request TLV") { std::string name = "hello.txt"; - cfdp::Lv firstName(reinterpret_cast(name.data()), name.size()); + cfdp::StringLv firstName(name); std::string name2 = "hello2.txt"; - cfdp::Lv secondName(reinterpret_cast(name2.data()), name2.size()); + cfdp::StringLv secondName(name2); FilestoreRequestTlv request(cfdp::FilestoreActionCode::APPEND_FILE, firstName); // second name not set yet diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index a38ceefc..bcef4e68 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -8,8 +8,10 @@ void cfdp::UserMock::abandonedIndication(cfdp::TransactionId id, cfdp::Condition uint64_t progress) {} void cfdp::UserMock::eofRecvIndication(cfdp::TransactionId id) {} void cfdp::UserMock::transactionFinishedIndication(TransactionFinishedParams finishedParams) {} -void cfdp::UserMock::metadataRecvdIndication(MetadataRecvParams params) {} +void cfdp::UserMock::metadataRecvdIndication(MetadataRecvdParams params) {} void cfdp::UserMock::fileSegmentRecvdIndication(FileSegmentRecvdParams params) {} -void cfdp::UserMock::reportIndication() {} -void cfdp::UserMock::suspendedIndication() {} -void cfdp::UserMock::resumedIndication() {} +void cfdp::UserMock::reportIndication(TransactionId id, StatusReportIF& report) {} +void cfdp::UserMock::suspendedIndication(TransactionId id, ConditionCode code) {} +void cfdp::UserMock::resumedIndication(TransactionId id, size_t progress) {} +void cfdp::UserMock::faultIndication(cfdp::TransactionId id, cfdp::ConditionCode code, + size_t progress) {} diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index bcdff3c9..7106a844 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -10,14 +10,15 @@ class UserMock : public UserBase { public: void transactionIndication(TransactionId id) override; void eofSentIndication(TransactionId id) override; - void abandonedIndication(TransactionId id, ConditionCode code, uint64_t progress) override; + void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) override; void eofRecvIndication(TransactionId id) override; void transactionFinishedIndication(TransactionFinishedParams params) override; - void metadataRecvdIndication(MetadataRecvParams params) override; + void metadataRecvdIndication(MetadataRecvdParams params) override; void fileSegmentRecvdIndication(FileSegmentRecvdParams params) override; - void reportIndication() override; - void suspendedIndication() override; - void resumedIndication() override; + void reportIndication(TransactionId id, StatusReportIF& report) override; + void suspendedIndication(TransactionId id, ConditionCode code) override; + void resumedIndication(TransactionId id, size_t progress) override; + void faultIndication(TransactionId id, ConditionCode code, size_t progress) override; }; } // namespace cfdp