From 16688316a841ffe45909427089fe0af51dc0c81f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 5 Sep 2022 16:31:56 +0200 Subject: [PATCH] rename setBuffer to setConstBuffer --- CMakeLists.txt | 3 ++- src/fsfw/cfdp/tlv/Lv.cpp | 4 ++-- src/fsfw/cfdp/tlv/Tlv.cpp | 4 ++-- src/fsfw/pus/Service11TelecommandScheduling.tpp | 4 ++-- src/fsfw/serialize/SerialBufferAdapter.cpp | 10 +++++----- src/fsfw/serialize/SerialBufferAdapter.h | 17 +++++++++-------- src/fsfw/tmtcservices/SpacePacketParser.h | 5 +---- unittests/serialize/testSerialBufferAdapter.cpp | 3 ++- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b00a708..3011b244 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -360,7 +360,8 @@ if(NOT FSFW_CONFIG_PATH) if(NOT FSFW_BUILD_DOCS) message( WARNING - "${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set") + "${MSG_PREFIX} Flight Software Framework configuration path FSFW_CONFIG_PATH not set" + ) message( WARNING "${MSG_PREFIX} Setting default configuration from ${DEF_CONF_PATH} ..") diff --git a/src/fsfw/cfdp/tlv/Lv.cpp b/src/fsfw/cfdp/tlv/Lv.cpp index 9c72b260..33c0e381 100644 --- a/src/fsfw/cfdp/tlv/Lv.cpp +++ b/src/fsfw/cfdp/tlv/Lv.cpp @@ -21,7 +21,7 @@ cfdp::Lv& cfdp::Lv::operator=(const Lv& other) { if (value == nullptr or otherSize == 0) { this->zeroLen = true; } - this->value.setBuffer(value, otherSize); + this->value.setConstBuffer(value, otherSize); return *this; } @@ -70,7 +70,7 @@ ReturnValue_t cfdp::Lv::deSerialize(const uint8_t** buffer, size_t* size, } zeroLen = false; // Zero-copy implementation - value.setBuffer(const_cast(*buffer + 1), lengthField); + value.setConstBuffer(*buffer + 1, lengthField); *buffer += 1 + lengthField; *size -= 1 + lengthField; return returnvalue::OK; diff --git a/src/fsfw/cfdp/tlv/Tlv.cpp b/src/fsfw/cfdp/tlv/Tlv.cpp index 3a394741..9d5f7f15 100644 --- a/src/fsfw/cfdp/tlv/Tlv.cpp +++ b/src/fsfw/cfdp/tlv/Tlv.cpp @@ -75,7 +75,7 @@ ReturnValue_t cfdp::Tlv::deSerialize(const uint8_t **buffer, size_t *size, } zeroLen = false; // Zero-copy implementation - value.setBuffer(const_cast(*buffer + 1), lengthField); + value.setConstBuffer(*buffer + 1, lengthField); *buffer += 1 + lengthField; *size -= 1 + lengthField; return returnvalue::OK; @@ -96,7 +96,7 @@ void cfdp::Tlv::setValue(uint8_t *value, size_t len) { if (len > 0) { zeroLen = false; } - this->value.setBuffer(value, len); + this->value.setConstBuffer(value, len); } uint8_t cfdp::Tlv::getLengthField() const { return this->value.getSerializedSize() - 1; } diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index c82c1703..cb2f227f 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -571,7 +571,7 @@ inline ReturnValue_t Service11TelecommandScheduling::getMapFilterFr if (result != returnvalue::OK) { return result; } - if(fromTimestamp > toTimestamp) { + if (fromTimestamp > toTimestamp) { return INVALID_TIME_WINDOW; } itBegin = telecommandMap.begin(); @@ -580,7 +580,7 @@ inline ReturnValue_t Service11TelecommandScheduling::getMapFilterFr itBegin++; } - //start looking for end beginning at begin + // start looking for end beginning at begin itEnd = itBegin; while (itEnd->first <= toTimestamp && itEnd != telecommandMap.end()) { itEnd++; diff --git a/src/fsfw/serialize/SerialBufferAdapter.cpp b/src/fsfw/serialize/SerialBufferAdapter.cpp index 81919f37..cf28d2ba 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.cpp +++ b/src/fsfw/serialize/SerialBufferAdapter.cpp @@ -21,7 +21,7 @@ SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, count_t buffe bufferLength(bufferLength) {} template -SerialBufferAdapter::~SerialBufferAdapter() {} +SerialBufferAdapter::~SerialBufferAdapter() = default; template ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, @@ -119,10 +119,10 @@ const uint8_t* SerialBufferAdapter::getConstBuffer() const { } template -void SerialBufferAdapter::setBuffer(uint8_t* buffer, count_t bufferLength) { - this->buffer = buffer; - this->constBuffer = buffer; - this->bufferLength = bufferLength; +void SerialBufferAdapter::setConstBuffer(const uint8_t* buf, count_t bufLen) { + this->buffer = nullptr; + this->bufferLength = bufLen; + this->constBuffer = buf; } // forward Template declaration for linker diff --git a/src/fsfw/serialize/SerialBufferAdapter.h b/src/fsfw/serialize/SerialBufferAdapter.h index 3b95fa20..b156bb02 100644 --- a/src/fsfw/serialize/SerialBufferAdapter.h +++ b/src/fsfw/serialize/SerialBufferAdapter.h @@ -21,6 +21,7 @@ template class SerialBufferAdapter : public SerializeIF { public: + SerialBufferAdapter() = default; /** * Constructor for constant uint8_t buffer. Length field can be serialized optionally. * Type of length can be supplied as template type. @@ -40,12 +41,12 @@ class SerialBufferAdapter : public SerializeIF { */ SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, bool serializeLength = false); - virtual ~SerialBufferAdapter(); + ~SerialBufferAdapter() override; - virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - Endianness streamEndianness) const override; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + Endianness streamEndianness) const override; - virtual size_t getSerializedSize() const override; + [[nodiscard]] size_t getSerializedSize() const override; /** * @brief This function deserializes a buffer into the member buffer. @@ -59,12 +60,12 @@ class SerialBufferAdapter : public SerializeIF { * @param bigEndian * @return */ - virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness) override; + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) override; uint8_t* getBuffer(); - const uint8_t* getConstBuffer() const; - void setBuffer(uint8_t* buffer, count_t bufferLength); + [[nodiscard]] const uint8_t* getConstBuffer() const; + void setConstBuffer(const uint8_t* buf, count_t bufLen); private: bool serializeLength = false; diff --git a/src/fsfw/tmtcservices/SpacePacketParser.h b/src/fsfw/tmtcservices/SpacePacketParser.h index 3a1b4d16..ea0a2feb 100644 --- a/src/fsfw/tmtcservices/SpacePacketParser.h +++ b/src/fsfw/tmtcservices/SpacePacketParser.h @@ -17,7 +17,6 @@ */ class SpacePacketParser { public: - struct FoundPacketInfo { size_t startIdx = 0; size_t sizeFound = 0; @@ -51,9 +50,7 @@ class SpacePacketParser { ReturnValue_t parseSpacePackets(const uint8_t** buffer, const size_t maxSize, FoundPacketInfo& packetInfo); - size_t getAmountRead() { - return amountRead; - } + size_t getAmountRead() { return amountRead; } void reset() { nextStartIdx = 0; diff --git a/unittests/serialize/testSerialBufferAdapter.cpp b/unittests/serialize/testSerialBufferAdapter.cpp index e5ea379e..abd179e4 100644 --- a/unittests/serialize/testSerialBufferAdapter.cpp +++ b/unittests/serialize/testSerialBufferAdapter.cpp @@ -64,7 +64,8 @@ TEST_CASE("Serial Buffer Adapter", "[single-file]") { SECTION("Test set buffer function") { SerialBufferAdapter tv_serial_buffer_adapter_loc = SerialBufferAdapter((uint8_t*)nullptr, 0, true); - tv_serial_buffer_adapter_loc.setBuffer(test_serial_buffer.data(), test_serial_buffer.size()); + tv_serial_buffer_adapter_loc.setConstBuffer(test_serial_buffer.data(), + test_serial_buffer.size()); serialized_size = 0; arrayPtr = testArray.data(); SerializeAdapter::serialize(&test_value_bool, &arrayPtr, &serialized_size, testArray.size(),