From b73754dfd62ec61410160beca8562a558c6e89cc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 8 Sep 2022 12:07:16 +0200 Subject: [PATCH] implemented basic PDU forwarding --- ...AckPduSerializer.cpp => AckPduCreator.cpp} | 12 ++++----- .../{AckPduSerializer.h => AckPduCreator.h} | 12 ++++----- ...ckPduDeserializer.cpp => AckPduReader.cpp} | 26 ++++++++++++------- .../{AckPduDeserializer.h => AckPduReader.h} | 9 ++++--- src/fsfw/cfdp/pdu/CMakeLists.txt | 4 +-- unittests/cfdp/pdu/testAckPdu.cpp | 18 ++++++------- 6 files changed, 45 insertions(+), 36 deletions(-) rename src/fsfw/cfdp/pdu/{AckPduSerializer.cpp => AckPduCreator.cpp} (72%) rename src/fsfw/cfdp/pdu/{AckPduSerializer.h => AckPduCreator.h} (62%) rename src/fsfw/cfdp/pdu/{AckPduDeserializer.cpp => AckPduReader.cpp} (52%) rename src/fsfw/cfdp/pdu/{AckPduDeserializer.h => AckPduReader.h} (59%) diff --git a/src/fsfw/cfdp/pdu/AckPduSerializer.cpp b/src/fsfw/cfdp/pdu/AckPduCreator.cpp similarity index 72% rename from src/fsfw/cfdp/pdu/AckPduSerializer.cpp rename to src/fsfw/cfdp/pdu/AckPduCreator.cpp index 67744171..88fcedc9 100644 --- a/src/fsfw/cfdp/pdu/AckPduSerializer.cpp +++ b/src/fsfw/cfdp/pdu/AckPduCreator.cpp @@ -1,14 +1,12 @@ -#include "AckPduSerializer.h" +#include "AckPduCreator.h" -AckPduSerializer::AckPduSerializer(AckInfo &ackInfo, PduConfig &pduConf) +AckPduCreator::AckPduCreator(AckInfo &ackInfo, PduConfig &pduConf) : FileDirectiveCreator(pduConf, cfdp::FileDirectives::ACK, 2), ackInfo(ackInfo) {} -size_t AckPduSerializer::getSerializedSize() const { - return FileDirectiveCreator::getWholePduSize(); -} +size_t AckPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); } -ReturnValue_t AckPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const { +ReturnValue_t AckPduCreator::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/AckPduSerializer.h b/src/fsfw/cfdp/pdu/AckPduCreator.h similarity index 62% rename from src/fsfw/cfdp/pdu/AckPduSerializer.h rename to src/fsfw/cfdp/pdu/AckPduCreator.h index 92014e4e..c0a89cc3 100644 --- a/src/fsfw/cfdp/pdu/AckPduSerializer.h +++ b/src/fsfw/cfdp/pdu/AckPduCreator.h @@ -1,11 +1,11 @@ -#ifndef FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ -#define FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ +#ifndef FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ +#define FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ #include "AckInfo.h" #include "FileDirectiveCreator.h" #include "FileDirectiveReader.h" -class AckPduSerializer : public FileDirectiveCreator { +class AckPduCreator : public FileDirectiveCreator { public: /** * @brief Serializer to pack ACK PDUs @@ -16,9 +16,9 @@ class AckPduSerializer : public FileDirectiveCreator { * @param transactionStatus * @param pduConf */ - AckPduSerializer(AckInfo& ackInfo, PduConfig& pduConf); + AckPduCreator(AckInfo& ackInfo, PduConfig& pduConf); - size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; @@ -27,4 +27,4 @@ class AckPduSerializer : public FileDirectiveCreator { AckInfo& ackInfo; }; -#endif /* FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ */ +#endif /* FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ */ diff --git a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp b/src/fsfw/cfdp/pdu/AckPduReader.cpp similarity index 52% rename from src/fsfw/cfdp/pdu/AckPduDeserializer.cpp rename to src/fsfw/cfdp/pdu/AckPduReader.cpp index f09db97e..4f75a2b8 100644 --- a/src/fsfw/cfdp/pdu/AckPduDeserializer.cpp +++ b/src/fsfw/cfdp/pdu/AckPduReader.cpp @@ -1,9 +1,9 @@ -#include "AckPduDeserializer.h" +#include "AckPduReader.h" -AckPduDeserializer::AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info) +AckPduReader::AckPduReader(const uint8_t* pduBuf, size_t maxSize, AckInfo& info) : FileDirectiveReader(pduBuf, maxSize), info(info) {} -ReturnValue_t AckPduDeserializer::parseData() { +ReturnValue_t AckPduReader::parseData() { ReturnValue_t result = FileDirectiveReader::parseData(); if (result != returnvalue::OK) { return result; @@ -18,14 +18,12 @@ ReturnValue_t AckPduDeserializer::parseData() { return returnvalue::OK; } -bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) { - uint8_t ackedDirective = static_cast(firstByte >> 4); - - if (ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE and - ackedDirective != cfdp::FileDirectives::FINISH) { +bool AckPduReader::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) { + cfdp::FileDirectives directive; + if (not checkAckedDirectiveField(firstByte, directive)) { return false; } - this->info.setAckedDirective(static_cast(ackedDirective)); + this->info.setAckedDirective(directive); uint8_t directiveSubtypeCode = firstByte & 0x0f; if (directiveSubtypeCode != 0b0000 and directiveSubtypeCode != 0b0001) { return false; @@ -35,3 +33,13 @@ bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) this->info.setTransactionStatus(static_cast(secondByte & 0x0f)); return true; } +bool AckPduReader::checkAckedDirectiveField(uint8_t firstPduDataByte, + cfdp::FileDirectives& ackedDirective) { + uint8_t ackedDirectiveRaw = static_cast(firstPduDataByte >> 4); + if (ackedDirectiveRaw != cfdp::FileDirectives::EOF_DIRECTIVE and + ackedDirectiveRaw != cfdp::FileDirectives::FINISH) { + return false; + } + ackedDirective = (static_cast(ackedDirectiveRaw)); + return true; +} diff --git a/src/fsfw/cfdp/pdu/AckPduDeserializer.h b/src/fsfw/cfdp/pdu/AckPduReader.h similarity index 59% rename from src/fsfw/cfdp/pdu/AckPduDeserializer.h rename to src/fsfw/cfdp/pdu/AckPduReader.h index 4da50261..2b5dd411 100644 --- a/src/fsfw/cfdp/pdu/AckPduDeserializer.h +++ b/src/fsfw/cfdp/pdu/AckPduReader.h @@ -4,16 +4,19 @@ #include "AckInfo.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h" -class AckPduDeserializer : public FileDirectiveReader { +class AckPduReader : public FileDirectiveReader { public: - AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info); + AckPduReader(const uint8_t* pduBuf, size_t maxSize, AckInfo& info); /** * * @return * - cfdp::INVALID_DIRECTIVE_FIELDS: Invalid fields */ - ReturnValue_t parseData(); + ReturnValue_t parseData() override; + + static bool checkAckedDirectiveField(uint8_t firstPduDataByte, + cfdp::FileDirectives& ackedDirective); private: bool checkAndSetCodes(uint8_t rawAckedByte, uint8_t rawAckedConditionCode); diff --git a/src/fsfw/cfdp/pdu/CMakeLists.txt b/src/fsfw/cfdp/pdu/CMakeLists.txt index a8f0b5a9..22ac76c7 100644 --- a/src/fsfw/cfdp/pdu/CMakeLists.txt +++ b/src/fsfw/cfdp/pdu/CMakeLists.txt @@ -6,8 +6,8 @@ target_sources( FileDirectiveReader.cpp FileDirectiveCreator.cpp AckInfo.cpp - AckPduSerializer.cpp - AckPduDeserializer.cpp + AckPduCreator.cpp + AckPduReader.cpp EofInfo.cpp EofPduCreator.cpp EofPduReader.cpp diff --git a/unittests/cfdp/pdu/testAckPdu.cpp b/unittests/cfdp/pdu/testAckPdu.cpp index 02832d9f..44b66bd5 100644 --- a/unittests/cfdp/pdu/testAckPdu.cpp +++ b/unittests/cfdp/pdu/testAckPdu.cpp @@ -1,8 +1,8 @@ #include #include -#include "fsfw/cfdp/pdu/AckPduDeserializer.h" -#include "fsfw/cfdp/pdu/AckPduSerializer.h" +#include "fsfw/cfdp/pdu/AckPduCreator.h" +#include "fsfw/cfdp/pdu/AckPduReader.h" #include "fsfw/globalfunctions/arrayprinter.h" TEST_CASE("ACK PDU", "[cfdp][pdu]") { @@ -18,7 +18,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { auto pduConf = PduConfig(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); AckInfo ackInfo(FileDirectives::EOF_DIRECTIVE, ConditionCode::NO_ERROR, AckTransactionStatus::ACTIVE); - auto ackSerializer = AckPduSerializer(ackInfo, pduConf); + auto ackSerializer = AckPduCreator(ackInfo, pduConf); result = ackSerializer.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); @@ -30,7 +30,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { ackInfo.setAckedDirective(FileDirectives::FINISH); ackInfo.setAckedConditionCode(ConditionCode::FILESTORE_REJECTION); ackInfo.setTransactionStatus(AckTransactionStatus::TERMINATED); - auto ackSerializer2 = AckPduSerializer(ackInfo, pduConf); + auto ackSerializer2 = AckPduCreator(ackInfo, pduConf); bufptr = buf.data(); sz = 0; result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); @@ -44,7 +44,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { bufptr = buf.data(); sz = 0; ackInfo.setAckedDirective(FileDirectives::KEEP_ALIVE); - auto ackSerializer3 = AckPduSerializer(ackInfo, pduConf); + auto ackSerializer3 = AckPduCreator(ackInfo, pduConf); result = ackSerializer3.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); // Invalid file directive REQUIRE(result != returnvalue::OK); @@ -57,7 +57,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { SECTION("Deserialize") { AckInfo ackInfo2; - auto reader = AckPduDeserializer(buf.data(), sz, ackInfo2); + auto reader = AckPduReader(buf.data(), sz, ackInfo2); result = reader.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::EOF_DIRECTIVE); @@ -67,13 +67,13 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { AckInfo newInfo = AckInfo(FileDirectives::FINISH, ConditionCode::FILESTORE_REJECTION, AckTransactionStatus::TERMINATED); - auto ackSerializer2 = AckPduSerializer(newInfo, pduConf); + auto ackSerializer2 = AckPduCreator(newInfo, pduConf); bufptr = buf.data(); sz = 0; result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); REQUIRE(result == returnvalue::OK); - auto reader2 = AckPduDeserializer(buf.data(), sz, ackInfo2); + auto reader2 = AckPduReader(buf.data(), sz, ackInfo2); result = reader2.parseData(); REQUIRE(result == returnvalue::OK); REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::FINISH); @@ -93,7 +93,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") { result = reader2.parseData(); REQUIRE(result == cfdp::INVALID_DIRECTIVE_FIELD); buf[sz - 3] = cfdp::FileDirectives::ACK; - auto maxSizeTooSmall = AckPduDeserializer(buf.data(), sz - 2, ackInfo2); + auto maxSizeTooSmall = AckPduReader(buf.data(), sz - 2, ackInfo2); result = maxSizeTooSmall.parseData(); REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); }