From 42a1d6cccd5af37622eef41adba0d44520fd7814 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 10:03:42 +0200 Subject: [PATCH 01/14] default implementation of simple serialize/deserialize --- src/fsfw/serialize/SerializeIF.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index d806c161..de5abaeb 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -90,6 +90,32 @@ class SerializeIF { */ virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) = 0; + + /** + * Helper method which can be used if serialization should be performed without any additional + * pointer arithmetic on a passed buffer pointer + * @param buffer + * @param maxSize + * @param streamEndianness + * @return + */ + virtual ReturnValue_t serialize(uint8_t* buffer, size_t maxSize, Endianness streamEndianness) { + size_t tmpSize = 0; + return serialize(&buffer, &tmpSize, maxSize, streamEndianness); + } + + /** + * Helper methods which can be used if deserialization should be performed without any additional + * pointer arithmetic on a passed buffer pointer + * @param buffer + * @param maxSize + * @param streamEndianness + * @return + */ + virtual ReturnValue_t deSerialize(const uint8_t* buffer, size_t maxSize, + Endianness streamEndianness) { + return deSerialize(&buffer, &maxSize, streamEndianness); + } }; #endif /* FSFW_SERIALIZE_SERIALIZEIF_H_ */ From ddad97033d6224c65fa27195da7693f7907b963b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 10:06:42 +0200 Subject: [PATCH 02/14] expand serialize IF further --- CMakeLists.txt | 4 +-- src/fsfw/osal/linux/MessageQueue.cpp | 3 +- src/fsfw/serialize/SerializeIF.h | 9 +++--- src/fsfw_hal/CMakeLists.txt | 4 +-- src/fsfw_hal/common/gpio/CMakeLists.txt | 4 +-- src/fsfw_hal/devicehandlers/CMakeLists.txt | 8 ++--- src/fsfw_hal/linux/CMakeLists.txt | 30 ++++++++----------- src/fsfw_hal/linux/gpio/CMakeLists.txt | 18 +++++------ src/fsfw_hal/linux/i2c/CMakeLists.txt | 9 +----- src/fsfw_hal/linux/rpi/CMakeLists.txt | 4 +-- src/fsfw_hal/linux/spi/CMakeLists.txt | 9 +----- src/fsfw_hal/linux/uart/CMakeLists.txt | 5 +--- src/fsfw_hal/linux/uio/CMakeLists.txt | 4 +-- src/fsfw_hal/stm32h7/CMakeLists.txt | 4 +-- .../stm32h7/devicetest/CMakeLists.txt | 4 +-- src/fsfw_hal/stm32h7/gpio/CMakeLists.txt | 4 +-- src/fsfw_hal/stm32h7/i2c/CMakeLists.txt | 3 +- src/fsfw_hal/stm32h7/spi/CMakeLists.txt | 18 +++++------ src/fsfw_hal/stm32h7/uart/CMakeLists.txt | 3 +- src/fsfw_tests/CMakeLists.txt | 4 +-- .../integration/assemblies/CMakeLists.txt | 4 +-- .../integration/controller/CMakeLists.txt | 4 +-- .../integration/devices/CMakeLists.txt | 7 ++--- .../integration/task/CMakeLists.txt | 4 +-- src/fsfw_tests/internal/CMakeLists.txt | 8 ++--- .../internal/globalfunctions/CMakeLists.txt | 4 +-- src/fsfw_tests/internal/osal/CMakeLists.txt | 7 ++--- .../internal/serialize/CMakeLists.txt | 4 +-- 28 files changed, 68 insertions(+), 125 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae1a621e..e59eb4c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,8 +104,8 @@ if(FSFW_GENERATE_SECTIONS) option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON) endif() -option(FSFW_BUILD_TESTS - "Build unittest binary in addition to static library" OFF) +option(FSFW_BUILD_TESTS "Build unittest binary in addition to static library" + OFF) option(FSFW_CICD_BUILD "Build for CI/CD. This can disable problematic test" OFF) option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF) if(FSFW_BUILD_TESTS) diff --git a/src/fsfw/osal/linux/MessageQueue.cpp b/src/fsfw/osal/linux/MessageQueue.cpp index 4ef7f756..ec212165 100644 --- a/src/fsfw/osal/linux/MessageQueue.cpp +++ b/src/fsfw/osal/linux/MessageQueue.cpp @@ -292,7 +292,8 @@ ReturnValue_t MessageQueue::handleOpenError(mq_attr* attributes, uint32_t messag sif::error << "MessageQueue::MessageQueue: Default MQ size " << defaultMqMaxMsg << " is too small for requested message depth " << messageDepth << std::endl; sif::error << "This error can be fixed by setting the maximum " - "allowed message depth higher" << std::endl; + "allowed message depth higher" + << std::endl; #else sif::printError( "MessageQueue::MessageQueue: Default MQ size %d is too small for" diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index de5abaeb..3f4fdc38 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -34,7 +34,7 @@ class SerializeIF { static const ReturnValue_t TOO_MANY_ELEMENTS = MAKE_RETURN_CODE(3); // !< There are too many elements to be deserialized - virtual ~SerializeIF() {} + virtual ~SerializeIF() = default; /** * @brief * Function to serialize the object into a buffer with maxSize. Size represents the written @@ -66,7 +66,7 @@ class SerializeIF { * Gets the size of a object if it would be serialized in a buffer * @return Size of serialized object */ - virtual size_t getSerializedSize() const = 0; + [[nodiscard]] virtual size_t getSerializedSize() const = 0; /** * @brief @@ -99,7 +99,8 @@ class SerializeIF { * @param streamEndianness * @return */ - virtual ReturnValue_t serialize(uint8_t* buffer, size_t maxSize, Endianness streamEndianness) { + virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize, + Endianness streamEndianness) const { size_t tmpSize = 0; return serialize(&buffer, &tmpSize, maxSize, streamEndianness); } @@ -112,7 +113,7 @@ class SerializeIF { * @param streamEndianness * @return */ - virtual ReturnValue_t deSerialize(const uint8_t* buffer, size_t maxSize, + virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t maxSize, Endianness streamEndianness) { return deSerialize(&buffer, &maxSize, streamEndianness); } diff --git a/src/fsfw_hal/CMakeLists.txt b/src/fsfw_hal/CMakeLists.txt index b7559d4b..057ab3a6 100644 --- a/src/fsfw_hal/CMakeLists.txt +++ b/src/fsfw_hal/CMakeLists.txt @@ -2,9 +2,9 @@ add_subdirectory(devicehandlers) add_subdirectory(common) if(UNIX) - add_subdirectory(linux) + add_subdirectory(linux) endif() if(FSFW_HAL_ADD_STM32H7) - add_subdirectory(stm32h7) + add_subdirectory(stm32h7) endif() diff --git a/src/fsfw_hal/common/gpio/CMakeLists.txt b/src/fsfw_hal/common/gpio/CMakeLists.txt index 098c05fa..5c81d9cc 100644 --- a/src/fsfw_hal/common/gpio/CMakeLists.txt +++ b/src/fsfw_hal/common/gpio/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - GpioCookie.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE GpioCookie.cpp) diff --git a/src/fsfw_hal/devicehandlers/CMakeLists.txt b/src/fsfw_hal/devicehandlers/CMakeLists.txt index 94e67c72..17139416 100644 --- a/src/fsfw_hal/devicehandlers/CMakeLists.txt +++ b/src/fsfw_hal/devicehandlers/CMakeLists.txt @@ -1,5 +1,3 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - GyroL3GD20Handler.cpp - MgmRM3100Handler.cpp - MgmLIS3MDLHandler.cpp -) +target_sources( + ${LIB_FSFW_NAME} PRIVATE GyroL3GD20Handler.cpp MgmRM3100Handler.cpp + MgmLIS3MDLHandler.cpp) diff --git a/src/fsfw_hal/linux/CMakeLists.txt b/src/fsfw_hal/linux/CMakeLists.txt index f6d1a460..ffa5f5ee 100644 --- a/src/fsfw_hal/linux/CMakeLists.txt +++ b/src/fsfw_hal/linux/CMakeLists.txt @@ -1,25 +1,21 @@ if(FSFW_HAL_ADD_RASPBERRY_PI) - add_subdirectory(rpi) + add_subdirectory(rpi) endif() -target_sources(${LIB_FSFW_NAME} PRIVATE - UnixFileGuard.cpp - CommandExecutor.cpp - utility.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE UnixFileGuard.cpp CommandExecutor.cpp + utility.cpp) if(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS) -if(FSFW_HAL_LINUX_ADD_LIBGPIOD) - add_subdirectory(gpio) -endif() - add_subdirectory(uart) - # Adding those does not really make sense on Apple systems which - # are generally host systems. It won't even compile as the headers - # are missing - if(NOT APPLE) - add_subdirectory(i2c) - add_subdirectory(spi) - endif() + if(FSFW_HAL_LINUX_ADD_LIBGPIOD) + add_subdirectory(gpio) + endif() + add_subdirectory(uart) + # Adding those does not really make sense on Apple systems which are generally + # host systems. It won't even compile as the headers are missing + if(NOT APPLE) + add_subdirectory(i2c) + add_subdirectory(spi) + endif() endif() add_subdirectory(uio) diff --git a/src/fsfw_hal/linux/gpio/CMakeLists.txt b/src/fsfw_hal/linux/gpio/CMakeLists.txt index b1609850..f6e7f2b0 100644 --- a/src/fsfw_hal/linux/gpio/CMakeLists.txt +++ b/src/fsfw_hal/linux/gpio/CMakeLists.txt @@ -1,16 +1,12 @@ -# This abstraction layer requires the gpiod library. You can install this library -# with "sudo apt-get install -y libgpiod-dev". If you are cross-compiling, you need -# to install the package before syncing the sysroot to your host computer. +# This abstraction layer requires the gpiod library. You can install this +# library with "sudo apt-get install -y libgpiod-dev". If you are +# cross-compiling, you need to install the package before syncing the sysroot to +# your host computer. find_library(LIB_GPIO gpiod) if(${LIB_GPIO} MATCHES LIB_GPIO-NOTFOUND) - message(STATUS "gpiod library not found, not linking against it") + message(STATUS "gpiod library not found, not linking against it") else() - target_sources(${LIB_FSFW_NAME} PRIVATE - LinuxLibgpioIF.cpp - ) - target_link_libraries(${LIB_FSFW_NAME} PRIVATE - ${LIB_GPIO} - ) + target_sources(${LIB_FSFW_NAME} PRIVATE LinuxLibgpioIF.cpp) + target_link_libraries(${LIB_FSFW_NAME} PRIVATE ${LIB_GPIO}) endif() - diff --git a/src/fsfw_hal/linux/i2c/CMakeLists.txt b/src/fsfw_hal/linux/i2c/CMakeLists.txt index 3eb0882c..b94bdc99 100644 --- a/src/fsfw_hal/linux/i2c/CMakeLists.txt +++ b/src/fsfw_hal/linux/i2c/CMakeLists.txt @@ -1,8 +1 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC - I2cComIF.cpp - I2cCookie.cpp -) - - - - +target_sources(${LIB_FSFW_NAME} PUBLIC I2cComIF.cpp I2cCookie.cpp) diff --git a/src/fsfw_hal/linux/rpi/CMakeLists.txt b/src/fsfw_hal/linux/rpi/CMakeLists.txt index 47be218c..3a865037 100644 --- a/src/fsfw_hal/linux/rpi/CMakeLists.txt +++ b/src/fsfw_hal/linux/rpi/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - GpioRPi.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE GpioRPi.cpp) diff --git a/src/fsfw_hal/linux/spi/CMakeLists.txt b/src/fsfw_hal/linux/spi/CMakeLists.txt index 404e1f47..f242bb3b 100644 --- a/src/fsfw_hal/linux/spi/CMakeLists.txt +++ b/src/fsfw_hal/linux/spi/CMakeLists.txt @@ -1,8 +1 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC - SpiComIF.cpp - SpiCookie.cpp -) - - - - +target_sources(${LIB_FSFW_NAME} PUBLIC SpiComIF.cpp SpiCookie.cpp) diff --git a/src/fsfw_hal/linux/uart/CMakeLists.txt b/src/fsfw_hal/linux/uart/CMakeLists.txt index 21ed0278..9cad62a4 100644 --- a/src/fsfw_hal/linux/uart/CMakeLists.txt +++ b/src/fsfw_hal/linux/uart/CMakeLists.txt @@ -1,4 +1 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC - UartComIF.cpp - UartCookie.cpp -) +target_sources(${LIB_FSFW_NAME} PUBLIC UartComIF.cpp UartCookie.cpp) diff --git a/src/fsfw_hal/linux/uio/CMakeLists.txt b/src/fsfw_hal/linux/uio/CMakeLists.txt index e98a0865..e3498246 100644 --- a/src/fsfw_hal/linux/uio/CMakeLists.txt +++ b/src/fsfw_hal/linux/uio/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PUBLIC - UioMapper.cpp -) +target_sources(${LIB_FSFW_NAME} PUBLIC UioMapper.cpp) diff --git a/src/fsfw_hal/stm32h7/CMakeLists.txt b/src/fsfw_hal/stm32h7/CMakeLists.txt index bae3b1ac..e8843ed3 100644 --- a/src/fsfw_hal/stm32h7/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/CMakeLists.txt @@ -2,6 +2,4 @@ add_subdirectory(spi) add_subdirectory(gpio) add_subdirectory(devicetest) -target_sources(${LIB_FSFW_NAME} PRIVATE - dma.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE dma.cpp) diff --git a/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt b/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt index 7bd4c3a9..8e789ddb 100644 --- a/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/devicetest/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - GyroL3GD20H.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE GyroL3GD20H.cpp) diff --git a/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt b/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt index 35245b25..54d76b2d 100644 --- a/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/gpio/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - gpio.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE gpio.cpp) diff --git a/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt b/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt index 5ecb0990..a0d48465 100644 --- a/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/i2c/CMakeLists.txt @@ -1,2 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE -) +target_sources(${LIB_FSFW_NAME} PRIVATE) diff --git a/src/fsfw_hal/stm32h7/spi/CMakeLists.txt b/src/fsfw_hal/stm32h7/spi/CMakeLists.txt index aa5541bc..9a98f502 100644 --- a/src/fsfw_hal/stm32h7/spi/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/spi/CMakeLists.txt @@ -1,9 +1,9 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - spiCore.cpp - spiDefinitions.cpp - spiInterrupts.cpp - mspInit.cpp - SpiCookie.cpp - SpiComIF.cpp - stm32h743zi.cpp -) +target_sources( + ${LIB_FSFW_NAME} + PRIVATE spiCore.cpp + spiDefinitions.cpp + spiInterrupts.cpp + mspInit.cpp + SpiCookie.cpp + SpiComIF.cpp + stm32h743zi.cpp) diff --git a/src/fsfw_hal/stm32h7/uart/CMakeLists.txt b/src/fsfw_hal/stm32h7/uart/CMakeLists.txt index 5ecb0990..a0d48465 100644 --- a/src/fsfw_hal/stm32h7/uart/CMakeLists.txt +++ b/src/fsfw_hal/stm32h7/uart/CMakeLists.txt @@ -1,2 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE -) +target_sources(${LIB_FSFW_NAME} PRIVATE) diff --git a/src/fsfw_tests/CMakeLists.txt b/src/fsfw_tests/CMakeLists.txt index 5e16e0a7..d161699a 100644 --- a/src/fsfw_tests/CMakeLists.txt +++ b/src/fsfw_tests/CMakeLists.txt @@ -1,7 +1,7 @@ if(FSFW_ADD_INTERNAL_TESTS) - add_subdirectory(internal) + add_subdirectory(internal) endif() if(NOT FSFW_BUILD_TESTS) - add_subdirectory(integration) + add_subdirectory(integration) endif() diff --git a/src/fsfw_tests/integration/assemblies/CMakeLists.txt b/src/fsfw_tests/integration/assemblies/CMakeLists.txt index 22c06600..63a6447a 100644 --- a/src/fsfw_tests/integration/assemblies/CMakeLists.txt +++ b/src/fsfw_tests/integration/assemblies/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestAssembly.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE TestAssembly.cpp) diff --git a/src/fsfw_tests/integration/controller/CMakeLists.txt b/src/fsfw_tests/integration/controller/CMakeLists.txt index f5655b71..5eeb5c68 100644 --- a/src/fsfw_tests/integration/controller/CMakeLists.txt +++ b/src/fsfw_tests/integration/controller/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestController.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE TestController.cpp) diff --git a/src/fsfw_tests/integration/devices/CMakeLists.txt b/src/fsfw_tests/integration/devices/CMakeLists.txt index cfd238d2..d5799197 100644 --- a/src/fsfw_tests/integration/devices/CMakeLists.txt +++ b/src/fsfw_tests/integration/devices/CMakeLists.txt @@ -1,5 +1,2 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestCookie.cpp - TestDeviceHandler.cpp - TestEchoComIF.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE TestCookie.cpp TestDeviceHandler.cpp + TestEchoComIF.cpp) diff --git a/src/fsfw_tests/integration/task/CMakeLists.txt b/src/fsfw_tests/integration/task/CMakeLists.txt index 4cd481bf..62d5e8ef 100644 --- a/src/fsfw_tests/integration/task/CMakeLists.txt +++ b/src/fsfw_tests/integration/task/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestTask.cpp -) \ No newline at end of file +target_sources(${LIB_FSFW_NAME} PRIVATE TestTask.cpp) diff --git a/src/fsfw_tests/internal/CMakeLists.txt b/src/fsfw_tests/internal/CMakeLists.txt index 2a144a9b..c1af5467 100644 --- a/src/fsfw_tests/internal/CMakeLists.txt +++ b/src/fsfw_tests/internal/CMakeLists.txt @@ -1,8 +1,6 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - InternalUnitTester.cpp - UnittDefinitions.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE InternalUnitTester.cpp + UnittDefinitions.cpp) add_subdirectory(osal) add_subdirectory(serialize) -add_subdirectory(globalfunctions) \ No newline at end of file +add_subdirectory(globalfunctions) diff --git a/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt b/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt index cde97734..6e7e58ad 100644 --- a/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt +++ b/src/fsfw_tests/internal/globalfunctions/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - TestArrayPrinter.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE TestArrayPrinter.cpp) diff --git a/src/fsfw_tests/internal/osal/CMakeLists.txt b/src/fsfw_tests/internal/osal/CMakeLists.txt index 8d79d759..db1031a0 100644 --- a/src/fsfw_tests/internal/osal/CMakeLists.txt +++ b/src/fsfw_tests/internal/osal/CMakeLists.txt @@ -1,5 +1,2 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - testMq.cpp - testMutex.cpp - testSemaphore.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE testMq.cpp testMutex.cpp + testSemaphore.cpp) diff --git a/src/fsfw_tests/internal/serialize/CMakeLists.txt b/src/fsfw_tests/internal/serialize/CMakeLists.txt index 47e8b538..ee264d9d 100644 --- a/src/fsfw_tests/internal/serialize/CMakeLists.txt +++ b/src/fsfw_tests/internal/serialize/CMakeLists.txt @@ -1,3 +1 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE - IntTestSerialization.cpp -) +target_sources(${LIB_FSFW_NAME} PRIVATE IntTestSerialization.cpp) From 8e05fc0417d7fa247bf10c65ecc559b0de1fe3bb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 10:28:01 +0200 Subject: [PATCH 03/14] added a few more methods --- src/fsfw/serialize/SerializeIF.h | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 3f4fdc38..9fc5b731 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -61,6 +61,18 @@ class SerializeIF { */ virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const = 0; + /** + * Forwards to regular @serialize call with network endianness + */ + virtual ReturnValue_t serializeNe(uint8_t** buffer, size_t* size, size_t maxSize) { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); + } + /** + * If endianness is not explicitly specified, use machine endianness + */ + virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) { + return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); + } /** * Gets the size of a object if it would be serialized in a buffer @@ -90,6 +102,18 @@ class SerializeIF { */ virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) = 0; + /** + * Forwards to regular @deSerialize call with network endianness + */ + virtual ReturnValue_t deSerializeNe(const uint8_t** buffer, size_t* size, size_t maxSize) { + return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK); + } + /** + * If endianness is not explicitly specified, use machine endianness + */ + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size, size_t maxSize) { + return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE); + } /** * Helper method which can be used if serialization should be performed without any additional @@ -104,6 +128,18 @@ class SerializeIF { size_t tmpSize = 0; return serialize(&buffer, &tmpSize, maxSize, streamEndianness); } + /** + * Forwards to regular @serialize call with network endianness + */ + virtual ReturnValue_t serializeNe(uint8_t *buffer, size_t maxSize) const { + return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); + } + /** + * If endianness is not explicitly specified, use machine endianness + */ + virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const { + return serialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); + } /** * Helper methods which can be used if deserialization should be performed without any additional @@ -117,6 +153,18 @@ class SerializeIF { Endianness streamEndianness) { return deSerialize(&buffer, &maxSize, streamEndianness); } + /** + * Forwards to regular @serialize call with network endianness + */ + virtual ReturnValue_t deSerializeNe(uint8_t *buffer, size_t maxSize) const { + return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); + } + /** + * If endianness is not explicitly specified, use machine endianness + */ + virtual ReturnValue_t deSerialize(uint8_t *buffer, size_t maxSize) const { + return serialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); + } }; #endif /* FSFW_SERIALIZE_SERIALIZEIF_H_ */ From f2bf4b463e8bfe3219a368479ada88346528af18 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 10:34:19 +0200 Subject: [PATCH 04/14] expand serializeIF tests --- CMakeLists.txt | 2 +- unittests/serialize/CMakeLists.txt | 7 ++++--- ...rialLinkedPacket.h => SerialLinkedListAdapterPacket.h} | 8 ++++---- ...erialBufferAdapter.cpp => testSerialBufferAdapter.cpp} | 4 ++-- ...tSerialLinkedPacket.cpp => testSerialLinkedPacket.cpp} | 3 +-- .../{TestSerialization.cpp => testSerializeAdapter.cpp} | 0 unittests/serialize/testSerializeIF.cpp | 6 ++++++ 7 files changed, 18 insertions(+), 12 deletions(-) rename unittests/serialize/{TestSerialLinkedPacket.h => SerialLinkedListAdapterPacket.h} (80%) rename unittests/serialize/{TestSerialBufferAdapter.cpp => testSerialBufferAdapter.cpp} (98%) rename unittests/serialize/{TestSerialLinkedPacket.cpp => testSerialLinkedPacket.cpp} (98%) rename unittests/serialize/{TestSerialization.cpp => testSerializeAdapter.cpp} (100%) create mode 100644 unittests/serialize/testSerializeIF.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e59eb4c5..949c9403 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,7 @@ if(FSFW_BUILD_TESTS) configure_file(unittests/testcfg/TestsConfig.h.in tests/TestsConfig.h) project(${FSFW_TEST_TGT} CXX C) - add_executable(${FSFW_TEST_TGT}) + add_executable(${FSFW_TEST_TGT} unittests/serialize/testSerializeIF.cpp) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/unittests/serialize/CMakeLists.txt b/unittests/serialize/CMakeLists.txt index 96c80f4a..be4301db 100644 --- a/unittests/serialize/CMakeLists.txt +++ b/unittests/serialize/CMakeLists.txt @@ -1,5 +1,6 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - TestSerialBufferAdapter.cpp - TestSerialization.cpp - TestSerialLinkedPacket.cpp + testSerialBufferAdapter.cpp + testSerializeAdapter.cpp + testSerialLinkedPacket.cpp + testSerializeIF.cpp ) diff --git a/unittests/serialize/TestSerialLinkedPacket.h b/unittests/serialize/SerialLinkedListAdapterPacket.h similarity index 80% rename from unittests/serialize/TestSerialLinkedPacket.h rename to unittests/serialize/SerialLinkedListAdapterPacket.h index 0cfdd9ff..81268d28 100644 --- a/unittests/serialize/TestSerialLinkedPacket.h +++ b/unittests/serialize/SerialLinkedListAdapterPacket.h @@ -26,13 +26,13 @@ class TestPacket : public SerialLinkedListAdapter { setLinks(); } - uint32_t getHeader() const { return header.entry; } + [[nodiscard]] uint32_t getHeader() const { return header.entry; } - const uint8_t* getBuffer() { return buffer.entry.getConstBuffer(); } + [[nodiscard]] const uint8_t* getBuffer() const { return buffer.entry.getConstBuffer(); } size_t getBufferLength() { return buffer.getSerializedSize(); } - uint16_t getTail() const { return tail.entry; } + [[nodiscard]] uint16_t getTail() const { return tail.entry; } private: void setLinks() { @@ -47,4 +47,4 @@ class TestPacket : public SerialLinkedListAdapter { SerializeElement tail = 0; }; -#endif /* UNITTEST_TESTFW_NEWTESTS_TESTTEMPLATE_H_ */ +#endif /* UNITTEST_HOSTED_TESTSERIALLINKEDPACKET_H_ */ diff --git a/unittests/serialize/TestSerialBufferAdapter.cpp b/unittests/serialize/testSerialBufferAdapter.cpp similarity index 98% rename from unittests/serialize/TestSerialBufferAdapter.cpp rename to unittests/serialize/testSerialBufferAdapter.cpp index 2aa76ec8..f9fbece1 100644 --- a/unittests/serialize/TestSerialBufferAdapter.cpp +++ b/unittests/serialize/testSerialBufferAdapter.cpp @@ -92,7 +92,7 @@ TEST_CASE("Serial Buffer Adapter", "[single-file]") { testArray[3] = 1; testArray[4] = 1; testArray[5] = 0; - std::array test_recv_array; + std::array test_recv_array{}; arrayPtr = testArray.data(); // copy testArray[1] to testArray[4] into receive buffer, skip // size field (testArray[0]) for deSerialization. @@ -116,7 +116,7 @@ TEST_CASE("Serial Buffer Adapter", "[single-file]") { testArray[3] = 1; testArray[4] = 1; testArray[5] = 0; - std::array test_recv_array; + std::array test_recv_array{}; arrayPtr = testArray.data() + 2; // copy testArray[1] to testArray[4] into receive buffer, skip // size field (testArray[0]) diff --git a/unittests/serialize/TestSerialLinkedPacket.cpp b/unittests/serialize/testSerialLinkedPacket.cpp similarity index 98% rename from unittests/serialize/TestSerialLinkedPacket.cpp rename to unittests/serialize/testSerialLinkedPacket.cpp index 2d6e476f..40910efb 100644 --- a/unittests/serialize/TestSerialLinkedPacket.cpp +++ b/unittests/serialize/testSerialLinkedPacket.cpp @@ -1,11 +1,10 @@ -#include "TestSerialLinkedPacket.h" - #include #include #include #include "CatchDefinitions.h" +#include "SerialLinkedListAdapterPacket.h" TEST_CASE("Serial Linked Packet", "[SerLinkPacket]") { // perform set-up here diff --git a/unittests/serialize/TestSerialization.cpp b/unittests/serialize/testSerializeAdapter.cpp similarity index 100% rename from unittests/serialize/TestSerialization.cpp rename to unittests/serialize/testSerializeAdapter.cpp diff --git a/unittests/serialize/testSerializeIF.cpp b/unittests/serialize/testSerializeIF.cpp new file mode 100644 index 00000000..80bcba64 --- /dev/null +++ b/unittests/serialize/testSerializeIF.cpp @@ -0,0 +1,6 @@ + +#include + +TEST_CASE("Simple Test", "[SerSizeTest]") { + +} \ No newline at end of file From b809f90e727bb9669badc179446a91b00dbdf53d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 11:10:44 +0200 Subject: [PATCH 05/14] added unittests for new helpers --- src/fsfw/serialize.h | 10 +- src/fsfw/serialize/EndianConverter.h | 14 +- src/fsfw/serialize/SerializeIF.h | 14 +- unittests/mocks/SimpleSerializable.h | 40 ++++++ unittests/serialize/testSerializeIF.cpp | 170 +++++++++++++++++++++++- 5 files changed, 226 insertions(+), 22 deletions(-) create mode 100644 unittests/mocks/SimpleSerializable.h diff --git a/src/fsfw/serialize.h b/src/fsfw/serialize.h index edd7c9c7..514e1e0c 100644 --- a/src/fsfw/serialize.h +++ b/src/fsfw/serialize.h @@ -1,10 +1,10 @@ #ifndef FSFW_INC_FSFW_SERIALIZE_H_ #define FSFW_INC_FSFW_SERIALIZE_H_ -#include "src/core/serialize/EndianConverter.h" -#include "src/core/serialize/SerialArrayListAdapter.h" -#include "src/core/serialize/SerialBufferAdapter.h" -#include "src/core/serialize/SerialLinkedListAdapter.h" -#include "src/core/serialize/SerializeElement.h" +#include "fsfw/serialize/EndianConverter.h" +#include "fsfw/serialize/SerialArrayListAdapter.h" +#include "fsfw/serialize/SerialBufferAdapter.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" +#include "fsfw/serialize/SerializeElement.h" #endif /* FSFW_INC_FSFW_SERIALIZE_H_ */ diff --git a/src/fsfw/serialize/EndianConverter.h b/src/fsfw/serialize/EndianConverter.h index 3beae46a..9d6c73a3 100644 --- a/src/fsfw/serialize/EndianConverter.h +++ b/src/fsfw/serialize/EndianConverter.h @@ -4,7 +4,7 @@ #include #include -#include "../osal/Endiness.h" +#include "fsfw/osal/Endiness.h" /** * Helper class to convert variables or bitstreams between machine @@ -36,7 +36,7 @@ */ class EndianConverter { private: - EndianConverter(){}; + EndianConverter() = default; public: /** @@ -49,8 +49,8 @@ class EndianConverter { #error BYTE_ORDER_SYSTEM not defined #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN T tmp; - uint8_t *pointerOut = (uint8_t *)&tmp; - uint8_t *pointerIn = (uint8_t *)∈ + auto *pointerOut = reinterpret_cast(&tmp); + auto *pointerIn = reinterpret_cast(&in); for (size_t count = 0; count < sizeof(T); count++) { pointerOut[sizeof(T) - count - 1] = pointerIn[count]; } @@ -73,7 +73,6 @@ class EndianConverter { for (size_t count = 0; count < size; count++) { out[size - count - 1] = in[count]; } - return; #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN memcpy(out, in, size); return; @@ -90,8 +89,8 @@ class EndianConverter { #error BYTE_ORDER_SYSTEM not defined #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN T tmp; - uint8_t *pointerOut = (uint8_t *)&tmp; - uint8_t *pointerIn = (uint8_t *)∈ + auto *pointerOut = reinterpret_cast(&tmp); + auto *pointerIn = reinterpret_cast(&in); for (size_t count = 0; count < sizeof(T); count++) { pointerOut[sizeof(T) - count - 1] = pointerIn[count]; } @@ -116,7 +115,6 @@ class EndianConverter { return; #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN memcpy(out, in, size); - return; #endif } }; diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 9fc5b731..54a1f4e3 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -3,7 +3,7 @@ #include -#include "../returnvalues/HasReturnvaluesIF.h" +#include "fsfw/returnvalues/HasReturnvaluesIF.h" /** * @defgroup serialize Serialization @@ -105,13 +105,13 @@ class SerializeIF { /** * Forwards to regular @deSerialize call with network endianness */ - virtual ReturnValue_t deSerializeNe(const uint8_t** buffer, size_t* size, size_t maxSize) { + virtual ReturnValue_t deSerializeNe(const uint8_t** buffer, size_t* size) { return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size, size_t maxSize) { + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size) { return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE); } @@ -156,14 +156,14 @@ class SerializeIF { /** * Forwards to regular @serialize call with network endianness */ - virtual ReturnValue_t deSerializeNe(uint8_t *buffer, size_t maxSize) const { - return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); + virtual ReturnValue_t deSerializeNe(const uint8_t *buffer, size_t maxSize) { + return deSerialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t deSerialize(uint8_t *buffer, size_t maxSize) const { - return serialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); + virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t maxSize) { + return deSerialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); } }; diff --git a/unittests/mocks/SimpleSerializable.h b/unittests/mocks/SimpleSerializable.h new file mode 100644 index 00000000..5c28a09a --- /dev/null +++ b/unittests/mocks/SimpleSerializable.h @@ -0,0 +1,40 @@ +#ifndef FSFW_TESTS_SIMPLESERIALIZABLE_H +#define FSFW_TESTS_SIMPLESERIALIZABLE_H + +#include "fsfw/serialize.h" +#include "fsfw/osal/Endiness.h" + +class SimpleSerializable : public SerializeIF { + public: + ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + Endianness streamEndianness) const override { + if (*size + getSerializedSize() > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } + **buffer = someU8; + *buffer += 1; + *size += 1; + return SerializeAdapter::serialize(&someU16, buffer, size, maxSize, streamEndianness); + } + + [[nodiscard]] size_t getSerializedSize() const override { return 3; } + ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, + Endianness streamEndianness) override { + if (*size < getSerializedSize()) { + return SerializeIF::STREAM_TOO_SHORT; + } + someU8 = **buffer; + *size -= 1; + *buffer += 1; + return SerializeAdapter::deSerialize(&someU16, buffer, size, streamEndianness); + } + + [[nodiscard]] uint8_t getU8() const { return someU8; } + [[nodiscard]] uint16_t getU16() const { return someU16; } + + private: + uint8_t someU8 = 1; + uint16_t someU16 = 0x0203; +}; + +#endif // FSFW_TESTS_SIMPLESERIALIZABLE_H diff --git a/unittests/serialize/testSerializeIF.cpp b/unittests/serialize/testSerializeIF.cpp index 80bcba64..2cbe6132 100644 --- a/unittests/serialize/testSerializeIF.cpp +++ b/unittests/serialize/testSerializeIF.cpp @@ -1,6 +1,172 @@ +#include #include -TEST_CASE("Simple Test", "[SerSizeTest]") { - +#include "mocks/SimpleSerializable.h" + +using namespace std; + +TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { + auto simpleSer = SimpleSerializable(); + array buf{}; + uint8_t* ptr = buf.data(); + size_t len = 0; + + SECTION("Little Endian Normal") { + REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + CHECK(buf[0] == 1); + CHECK(buf[1] == 3); + CHECK(buf[2] == 2); + // Verify pointer arithmetic and size increment + CHECK(ptr == buf.data() + 3); + CHECK(len == 3); + } + + SECTION("Little Endian Simple") { + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + CHECK(buf[0] == 1); + CHECK(buf[1] == 3); + CHECK(buf[2] == 2); + } + + SECTION("Big Endian Normal") { + SECTION("Explicit") { + REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_OK); + } + SECTION("Network 0") { + REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + } + SECTION("Network 1") { + REQUIRE(simpleSer.serializeNe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK); + } + + CHECK(buf[0] == 1); + CHECK(buf[1] == 2); + CHECK(buf[2] == 3); + // Verify pointer arithmetic and size increment + CHECK(ptr == buf.data() + 3); + CHECK(len == 3); + } + + SECTION("Big Endian Simple") { + SECTION("Explicit") { + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_OK); + } + SECTION("Network 0") { + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + } + SECTION("Network 1") { + REQUIRE(simpleSer.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + } + CHECK(buf[0] == 1); + CHECK(buf[1] == 2); + CHECK(buf[2] == 3); + } + + SECTION("Machine Endian Implicit") { + REQUIRE(simpleSer.SerializeIF::serialize(&ptr, &len, buf.size()) == + HasReturnvaluesIF::RETURN_OK); + CHECK(buf[0] == 1); +#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN + CHECK(buf[1] == 3); + CHECK(buf[2] == 2); +#else + CHECK(buf[1] == 2); + CHECK(buf[2] == 3); +#endif + // Verify pointer arithmetic and size increment + CHECK(ptr == buf.data() + 3); + CHECK(len == 3); + } + + SECTION("Machine Endian Simple Implicit") { + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size()) == + HasReturnvaluesIF::RETURN_OK); + CHECK(buf[0] == 1); +#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN + CHECK(buf[1] == 3); + CHECK(buf[2] == 2); +#else + CHECK(buf[1] == 2); + CHECK(buf[2] == 3); +#endif + } +} + +TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { + auto simpleSer = SimpleSerializable(); + array buf = {5, 0, 1}; + const uint8_t* ptr = buf.data(); + size_t len = buf.size(); + + SECTION("Little Endian Normal") { + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + CHECK(simpleSer.getU8() == 5); + CHECK(simpleSer.getU16() == 0x0100); + CHECK(ptr == buf.data() + 3); + CHECK(len == 0); + } + + SECTION("Little Endian Simple") { + REQUIRE(simpleSer.SerializeIF::deSerialize(ptr, len, SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + CHECK(simpleSer.getU8() == 5); + CHECK(simpleSer.getU16() == 0x0100); + } + + SECTION("Big Endian Normal") { + SECTION("Explicit") { + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_OK); + } + SECTION("Network 0") { + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + } + SECTION("Network 1") { + REQUIRE(simpleSer.SerializeIF::deSerializeNe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK); + } + CHECK(simpleSer.getU8() == 5); + CHECK(simpleSer.getU16() == 1); + CHECK(ptr == buf.data() + 3); + CHECK(len == 0); + } + + SECTION("Big Endian Simple") { + SECTION("Explicit") { + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_OK); + } + SECTION("Network 0") { + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + } + SECTION("Network 1") { + REQUIRE(simpleSer.SerializeIF::deSerializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + } + CHECK(simpleSer.getU8() == 5); + CHECK(simpleSer.getU16() == 1); + } + + SECTION("Machine Endian Implicit") { + REQUIRE(simpleSer.SerializeIF::deSerialize(&ptr, &len) == HasReturnvaluesIF::RETURN_OK); + CHECK(simpleSer.getU8() == 5); +#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN + CHECK(simpleSer.getU16() == 0x0100); +#else + CHECK(simpleSer.getU16() == 1); +#endif + // Verify pointer arithmetic and size increment + CHECK(ptr == buf.data() + 3); + CHECK(len == 0); + } + + SECTION("Machine Endian Simple Implicit") { + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size()) == + HasReturnvaluesIF::RETURN_OK); + CHECK(simpleSer.getU8() == 5); +#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN + CHECK(simpleSer.getU16() == 0x0100); +#else + CHECK(simpleSer.getU16() == 1); +#endif + } } \ No newline at end of file From 3708df242320cc0edd5b103504a2ce926df6f078 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 23 Jul 2022 11:15:55 +0200 Subject: [PATCH 06/14] small fix --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 949c9403..e59eb4c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,7 @@ if(FSFW_BUILD_TESTS) configure_file(unittests/testcfg/TestsConfig.h.in tests/TestsConfig.h) project(${FSFW_TEST_TGT} CXX C) - add_executable(${FSFW_TEST_TGT} unittests/serialize/testSerializeIF.cpp) + add_executable(${FSFW_TEST_TGT}) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) From 2a34c831b199ab747e2bbab6db4237602157d873 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 11:33:12 +0200 Subject: [PATCH 07/14] use Be instead of Ne, which could be confused --- src/fsfw/serialize/SerializeIF.h | 16 ++++++++-------- unittests/serialize/testSerializeIF.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 54a1f4e3..921d8a5e 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -62,9 +62,9 @@ class SerializeIF { virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const = 0; /** - * Forwards to regular @serialize call with network endianness + * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t serializeNe(uint8_t** buffer, size_t* size, size_t maxSize) { + virtual ReturnValue_t serializeBe(uint8_t** buffer, size_t* size, size_t maxSize) { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } /** @@ -103,9 +103,9 @@ class SerializeIF { virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, Endianness streamEndianness) = 0; /** - * Forwards to regular @deSerialize call with network endianness + * Forwards to regular @deSerialize call with big (network) endianness */ - virtual ReturnValue_t deSerializeNe(const uint8_t** buffer, size_t* size) { + virtual ReturnValue_t deSerializeBe(const uint8_t** buffer, size_t* size) { return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK); } /** @@ -129,9 +129,9 @@ class SerializeIF { return serialize(&buffer, &tmpSize, maxSize, streamEndianness); } /** - * Forwards to regular @serialize call with network endianness + * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t serializeNe(uint8_t *buffer, size_t maxSize) const { + virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t maxSize) const { return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); } /** @@ -154,9 +154,9 @@ class SerializeIF { return deSerialize(&buffer, &maxSize, streamEndianness); } /** - * Forwards to regular @serialize call with network endianness + * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t deSerializeNe(const uint8_t *buffer, size_t maxSize) { + virtual ReturnValue_t deSerializeBe(const uint8_t *buffer, size_t maxSize) { return deSerialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); } /** diff --git a/unittests/serialize/testSerializeIF.cpp b/unittests/serialize/testSerializeIF.cpp index 2cbe6132..694f6d7f 100644 --- a/unittests/serialize/testSerializeIF.cpp +++ b/unittests/serialize/testSerializeIF.cpp @@ -38,7 +38,7 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.serializeNe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.serializeBe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK); } CHECK(buf[0] == 1); @@ -58,7 +58,7 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::serializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); } CHECK(buf[0] == 1); CHECK(buf[1] == 2); @@ -123,7 +123,7 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::deSerializeNe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::deSerializeBe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK); } CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 1); @@ -140,7 +140,7 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::deSerializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::deSerializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); } CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 1); From 380f1d02069debf2267f25cd432a49bea40ad1ae Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 14:40:10 +0200 Subject: [PATCH 08/14] remove obsolete returns --- src/fsfw/serialize/EndianConverter.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fsfw/serialize/EndianConverter.h b/src/fsfw/serialize/EndianConverter.h index 9d6c73a3..dc8944ca 100644 --- a/src/fsfw/serialize/EndianConverter.h +++ b/src/fsfw/serialize/EndianConverter.h @@ -75,7 +75,6 @@ class EndianConverter { } #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN memcpy(out, in, size); - return; #endif } @@ -112,7 +111,6 @@ class EndianConverter { for (size_t count = 0; count < size; count++) { out[size - count - 1] = in[count]; } - return; #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN memcpy(out, in, size); #endif From f3af88ae40e3dbaddac256cfcf13d0b4e9774c45 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 14:44:19 +0200 Subject: [PATCH 09/14] add [[nodiscard]] and const specifiers --- src/fsfw/serialize/SerializeIF.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 921d8a5e..7ef8c925 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -59,18 +59,18 @@ class SerializeIF { * - @c RETURN_FAILED Generic error * - @c RETURN_OK Successful serialization */ - virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const = 0; /** * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t serializeBe(uint8_t** buffer, size_t* size, size_t maxSize) { + [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t** buffer, size_t* size, size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) { + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); } @@ -123,7 +123,7 @@ class SerializeIF { * @param streamEndianness * @return */ - virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize, + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize, Endianness streamEndianness) const { size_t tmpSize = 0; return serialize(&buffer, &tmpSize, maxSize, streamEndianness); @@ -131,13 +131,13 @@ class SerializeIF { /** * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t maxSize) const { + [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t maxSize) const { return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const { + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const { return serialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); } From f80be9e9fac34bfb2c3fb25647e6b11289b0934c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 14:44:49 +0200 Subject: [PATCH 10/14] run afmt --- src/fsfw/container/SimpleRingBuffer.cpp | 14 +++++++------- src/fsfw/serialize/SerializeIF.h | 14 ++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/fsfw/container/SimpleRingBuffer.cpp b/src/fsfw/container/SimpleRingBuffer.cpp index 437e72ea..c104ea97 100644 --- a/src/fsfw/container/SimpleRingBuffer.cpp +++ b/src/fsfw/container/SimpleRingBuffer.cpp @@ -1,10 +1,10 @@ #include "fsfw/container/SimpleRingBuffer.h" -#include "fsfw/FSFW.h" - -#include "fsfw/serviceinterface.h" #include +#include "fsfw/FSFW.h" +#include "fsfw/serviceinterface.h" + SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld, size_t maxExcessBytes) : RingBufferBase<>(0, size, overwriteOld), maxExcessBytes(maxExcessBytes) { if (maxExcessBytes > size) { @@ -51,15 +51,15 @@ void SimpleRingBuffer::confirmBytesWritten(size_t amount) { } ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data, size_t amount) { - if(data == nullptr) { + if (data == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - if(amount > getMaxSize()) { + if (amount > getMaxSize()) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "SimpleRingBuffer::writeData: Amount of data too large" << std::endl; + sif::error << "SimpleRingBuffer::writeData: Amount of data too large" << std::endl; #else - sif::printError("SimpleRingBuffer::writeData: Amount of data too large\n"); + sif::printError("SimpleRingBuffer::writeData: Amount of data too large\n"); #endif #endif return HasReturnvaluesIF::RETURN_FAILED; diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 7ef8c925..47212ab1 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -60,17 +60,19 @@ class SerializeIF { * - @c RETURN_OK Successful serialization */ [[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const = 0; + Endianness streamEndianness) const = 0; /** * Forwards to regular @serialize call with big (network) endianness */ - [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t** buffer, size_t* size, size_t maxSize) const { + [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t **buffer, size_t *size, + size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - [[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const { + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, + size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); } @@ -105,13 +107,13 @@ class SerializeIF { /** * Forwards to regular @deSerialize call with big (network) endianness */ - virtual ReturnValue_t deSerializeBe(const uint8_t** buffer, size_t* size) { + virtual ReturnValue_t deSerializeBe(const uint8_t **buffer, size_t *size) { return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size) { + virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size) { return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE); } @@ -124,7 +126,7 @@ class SerializeIF { * @return */ [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize, - Endianness streamEndianness) const { + Endianness streamEndianness) const { size_t tmpSize = 0; return serialize(&buffer, &tmpSize, maxSize, streamEndianness); } From dc31358d525a9a8aed2eed855a68176c288c36dd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 21:31:09 +0200 Subject: [PATCH 11/14] adaption for SerializeIF - Returns serialized and deserialized size now --- src/fsfw/serialize/SerializeIF.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 47212ab1..5e7a2fb9 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -125,22 +125,26 @@ class SerializeIF { * @param streamEndianness * @return */ - [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize, + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t &serLen, size_t maxSize, Endianness streamEndianness) const { size_t tmpSize = 0; - return serialize(&buffer, &tmpSize, maxSize, streamEndianness); + ReturnValue_t result = serialize(&buffer, &tmpSize, maxSize, streamEndianness); + serLen = tmpSize; + return result; } /** * Forwards to regular @serialize call with big (network) endianness */ - [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t maxSize) const { - return serialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); + [[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t *buffer, size_t &serLen, + size_t maxSize) const { + return serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t maxSize) const { - return serialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); + [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t &serLen, + size_t maxSize) const { + return serialize(buffer, serLen, maxSize, SerializeIF::Endianness::MACHINE); } /** @@ -151,21 +155,24 @@ class SerializeIF { * @param streamEndianness * @return */ - virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t maxSize, + virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t &deserSize, size_t maxSize, Endianness streamEndianness) { - return deSerialize(&buffer, &maxSize, streamEndianness); + size_t deserLen = maxSize; + ReturnValue_t result = deSerialize(&buffer, &deserLen, streamEndianness); + deserSize = maxSize - deserLen; + return result; } /** * Forwards to regular @serialize call with big (network) endianness */ - virtual ReturnValue_t deSerializeBe(const uint8_t *buffer, size_t maxSize) { - return deSerialize(buffer, maxSize, SerializeIF::Endianness::NETWORK); + virtual ReturnValue_t deSerializeBe(const uint8_t *buffer, size_t &deserSize, size_t maxSize) { + return deSerialize(buffer, deserSize, maxSize, SerializeIF::Endianness::NETWORK); } /** * If endianness is not explicitly specified, use machine endianness */ - virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t maxSize) { - return deSerialize(buffer, maxSize, SerializeIF::Endianness::MACHINE); + virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t &deserSize, size_t maxSize) { + return deSerialize(buffer, deserSize, maxSize, SerializeIF::Endianness::MACHINE); } }; From b11cdf618405574ec1e603f79cae1166f7579a79 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 27 Jul 2022 21:32:22 +0200 Subject: [PATCH 12/14] update unittests --- unittests/serialize/testSerializeIF.cpp | 59 ++++++++++++++++++------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/unittests/serialize/testSerializeIF.cpp b/unittests/serialize/testSerializeIF.cpp index 694f6d7f..5200f8b7 100644 --- a/unittests/serialize/testSerializeIF.cpp +++ b/unittests/serialize/testSerializeIF.cpp @@ -13,7 +13,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { size_t len = 0; SECTION("Little Endian Normal") { - REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 1); CHECK(buf[1] == 3); CHECK(buf[2] == 2); @@ -23,10 +24,14 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { } SECTION("Little Endian Simple") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + size_t serLen = 0xff; + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size(), + SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 1); CHECK(buf[1] == 3); CHECK(buf[2] == 2); + CHECK(serLen == 3); } SECTION("Big Endian Normal") { @@ -35,7 +40,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { REQUIRE(simpleSer.serializeBe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK); @@ -50,19 +56,25 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { } SECTION("Big Endian Simple") { + size_t serLen = 0xff; SECTION("Explicit") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) == + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size(), + SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size(), + SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::serializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::serializeBe(buf.data(), serLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); } CHECK(buf[0] == 1); CHECK(buf[1] == 2); CHECK(buf[2] == 3); + CHECK(serLen == 3); } SECTION("Machine Endian Implicit") { @@ -82,7 +94,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { } SECTION("Machine Endian Simple Implicit") { - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size()) == + size_t serLen = 0xff; + REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); CHECK(buf[0] == 1); #if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN @@ -92,6 +105,7 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { CHECK(buf[1] == 2); CHECK(buf[2] == 3); #endif + CHECK(serLen == 3); } } @@ -102,7 +116,8 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { size_t len = buf.size(); SECTION("Little Endian Normal") { - REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 0x0100); CHECK(ptr == buf.data() + 3); @@ -110,17 +125,23 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { } SECTION("Little Endian Simple") { - REQUIRE(simpleSer.SerializeIF::deSerialize(ptr, len, SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK); + size_t deserLen = 0xff; + REQUIRE( + simpleSer.SerializeIF::deSerialize(ptr, deserLen, len, SerializeIF::Endianness::LITTLE) == + HasReturnvaluesIF::RETURN_OK); CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 0x0100); + CHECK(deserLen == 3); } SECTION("Big Endian Normal") { SECTION("Explicit") { - REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::BIG) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { REQUIRE(simpleSer.SerializeIF::deSerializeBe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK); @@ -132,18 +153,24 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { } SECTION("Big Endian Simple") { + size_t deserLen = 0xff; SECTION("Explicit") { - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) == + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), deserLen, buf.size(), + SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_OK); } SECTION("Network 0") { - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), deserLen, buf.size(), + SerializeIF::Endianness::NETWORK) == + HasReturnvaluesIF::RETURN_OK); } SECTION("Network 1") { - REQUIRE(simpleSer.SerializeIF::deSerializeBe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK); + REQUIRE(simpleSer.SerializeIF::deSerializeBe(buf.data(), deserLen, buf.size()) == + HasReturnvaluesIF::RETURN_OK); } CHECK(simpleSer.getU8() == 5); CHECK(simpleSer.getU16() == 1); + CHECK(deserLen == 3); } SECTION("Machine Endian Implicit") { @@ -160,7 +187,8 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { } SECTION("Machine Endian Simple Implicit") { - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size()) == + size_t deserLen = 0xff; + REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK); CHECK(simpleSer.getU8() == 5); #if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN @@ -168,5 +196,6 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { #else CHECK(simpleSer.getU16() == 1); #endif + CHECK(deserLen == 3); } } \ No newline at end of file From b28c26b288ca9e261a95d9564202336fb3c5cf5c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 15 Aug 2022 10:49:00 +0200 Subject: [PATCH 13/14] group MGM data in local pool vectors --- CMakeLists.txt | 6 +++++ .../devicehandlers/MgmLIS3MDLHandler.cpp | 27 ++++++++----------- .../devicehandlers/MgmLIS3MDLHandler.h | 2 ++ .../devicehandlers/MgmRM3100Handler.cpp | 11 ++++---- .../devicehandlers/MgmRM3100Handler.h | 1 + .../devicedefinitions/MgmLIS3HandlerDefs.h | 14 ++++------ .../devicedefinitions/MgmRM3100HandlerDefs.h | 14 ++++------ 7 files changed, 35 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfae2acb..95c00f28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,12 @@ option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON) option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF) option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON) +if(UNIX) + option(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS "Add Linux peripheral drivers" + OFF) + option(FSFW_HAL_LINUX_ADD_LIBGPIOD "Attempt to add Linux GPIOD drivers" OFF) +endif() + # Optional sources option(FSFW_ADD_PUS "Compile with PUS sources" ON) option(FSFW_ADD_MONITORING "Compile with monitoring components" ON) diff --git a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp index 644b488d..5ddc3245 100644 --- a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -286,26 +286,22 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons PoolReadGuard readHelper(&dataset); if (readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) { + if (std::abs(mgmX) > absLimitX or std::abs(mgmY) > absLimitY or + std::abs(mgmZ) > absLimitZ) { + dataset.fieldStrengths.setValid(false); + } if (std::abs(mgmX) < absLimitX) { - dataset.fieldStrengthX = mgmX; - dataset.fieldStrengthX.setValid(true); - } else { - dataset.fieldStrengthX.setValid(false); + dataset.fieldStrengths[0] = mgmX; } if (std::abs(mgmY) < absLimitY) { - dataset.fieldStrengthY = mgmY; - dataset.fieldStrengthY.setValid(true); - } else { - dataset.fieldStrengthY.setValid(false); + dataset.fieldStrengths[1] = mgmY; } if (std::abs(mgmZ) < absLimitZ) { - dataset.fieldStrengthZ = mgmZ; - dataset.fieldStrengthZ.setValid(true); - } else { - dataset.fieldStrengthZ.setValid(false); + dataset.fieldStrengths[2] = mgmZ; } + dataset.fieldStrengths.setValid(true); } break; } @@ -468,10 +464,9 @@ void MgmLIS3MDLHandler::modeChanged(void) { internalState = InternalState::STATE ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, new PoolEntry({0.0})); - localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, new PoolEntry({0.0})); - localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, new PoolEntry({0.0})); - localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, new PoolEntry({0.0})); + localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTHS, &mgmXYZ); + localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, &temperature); + poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h index 42bd5d4c..3250a739 100644 --- a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h +++ b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h @@ -103,6 +103,8 @@ class MgmLIS3MDLHandler : public DeviceHandlerBase { CommunicationStep communicationStep = CommunicationStep::DATA; bool commandExecuted = false; + PoolEntry mgmXYZ = PoolEntry(3); + PoolEntry temperature = PoolEntry(); /*------------------------------------------------------------------------*/ /* Device specific commands and variables */ /*------------------------------------------------------------------------*/ diff --git a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp index f9929d63..c329f5a6 100644 --- a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp @@ -309,9 +309,8 @@ void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE; ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry({0.0})); - localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry({0.0})); - localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry({0.0})); + localDataPoolMap.emplace(RM3100::FIELD_STRENGTHS, &mgmXYZ); + poolManager.subscribeForPeriodicPacket(primaryDataset.getSid(), false, 10.0, false); return HasReturnvaluesIF::RETURN_OK; } @@ -354,9 +353,9 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) { // TODO: Sanity check on values? PoolReadGuard readGuard(&primaryDataset); if (readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) { - primaryDataset.fieldStrengthX = fieldStrengthX; - primaryDataset.fieldStrengthY = fieldStrengthY; - primaryDataset.fieldStrengthZ = fieldStrengthZ; + primaryDataset.fieldStrengths[0] = fieldStrengthX; + primaryDataset.fieldStrengths[1] = fieldStrengthY; + primaryDataset.fieldStrengths[2] = fieldStrengthZ; primaryDataset.setValidity(true, true); } return RETURN_OK; diff --git a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h index d1048cb6..d45b2404 100644 --- a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h +++ b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.h @@ -85,6 +85,7 @@ class MgmRM3100Handler : public DeviceHandlerBase { bool goToNormalModeAtStartup = false; uint32_t transitionDelay; + PoolEntry mgmXYZ = PoolEntry(3); ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData, size_t commandDataLen); diff --git a/src/fsfw_hal/devicehandlers/devicedefinitions/MgmLIS3HandlerDefs.h b/src/fsfw_hal/devicehandlers/devicedefinitions/MgmLIS3HandlerDefs.h index 3d78c5c9..34237637 100644 --- a/src/fsfw_hal/devicehandlers/devicedefinitions/MgmLIS3HandlerDefs.h +++ b/src/fsfw_hal/devicehandlers/devicedefinitions/MgmLIS3HandlerDefs.h @@ -139,12 +139,7 @@ static const uint8_t CTRL_REG5_DEFAULT = 0; static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA; -enum MgmPoolIds : lp_id_t { - FIELD_STRENGTH_X, - FIELD_STRENGTH_Y, - FIELD_STRENGTH_Z, - TEMPERATURE_CELCIUS -}; +enum MgmPoolIds : lp_id_t { FIELD_STRENGTHS, TEMPERATURE_CELCIUS }; class MgmPrimaryDataset : public StaticLocalDataSet<4> { public: @@ -152,9 +147,10 @@ class MgmPrimaryDataset : public StaticLocalDataSet<4> { MgmPrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {} - lp_var_t fieldStrengthX = lp_var_t(sid.objectId, FIELD_STRENGTH_X, this); - lp_var_t fieldStrengthY = lp_var_t(sid.objectId, FIELD_STRENGTH_Y, this); - lp_var_t fieldStrengthZ = lp_var_t(sid.objectId, FIELD_STRENGTH_Z, this); + /** + * Field strenghts in uT + */ + lp_vec_t fieldStrengths = lp_vec_t(sid.objectId, FIELD_STRENGTHS, this); lp_var_t temperature = lp_var_t(sid.objectId, TEMPERATURE_CELCIUS, this); }; diff --git a/src/fsfw_hal/devicehandlers/devicedefinitions/MgmRM3100HandlerDefs.h b/src/fsfw_hal/devicehandlers/devicedefinitions/MgmRM3100HandlerDefs.h index e3eaff22..a2aa8ab0 100644 --- a/src/fsfw_hal/devicehandlers/devicedefinitions/MgmRM3100HandlerDefs.h +++ b/src/fsfw_hal/devicehandlers/devicedefinitions/MgmRM3100HandlerDefs.h @@ -101,11 +101,7 @@ class CycleCountCommand : public SerialLinkedListAdapter { static constexpr uint32_t MGM_DATASET_ID = READ_DATA; -enum MgmPoolIds : lp_id_t { - FIELD_STRENGTH_X, - FIELD_STRENGTH_Y, - FIELD_STRENGTH_Z, -}; +enum MgmPoolIds : lp_id_t { FIELD_STRENGTHS }; class Rm3100PrimaryDataset : public StaticLocalDataSet<3> { public: @@ -113,10 +109,10 @@ class Rm3100PrimaryDataset : public StaticLocalDataSet<3> { Rm3100PrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {} - // Field strengths in micro Tesla. - lp_var_t fieldStrengthX = lp_var_t(sid.objectId, FIELD_STRENGTH_X, this); - lp_var_t fieldStrengthY = lp_var_t(sid.objectId, FIELD_STRENGTH_Y, this); - lp_var_t fieldStrengthZ = lp_var_t(sid.objectId, FIELD_STRENGTH_Z, this); + /** + * Field strenghts in uT + */ + lp_vec_t fieldStrengths = lp_vec_t(sid.objectId, FIELD_STRENGTHS, this); }; } // namespace RM3100 From deeeef553b118192d45a921d6d3a1a3b5881ebd7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 15 Aug 2022 14:34:04 +0200 Subject: [PATCH 14/14] remove implicit machine endianness variants --- src/fsfw/serialize/SerializeIF.h | 26 ----------- unittests/serialize/testSerializeIF.cpp | 57 ------------------------- 2 files changed, 83 deletions(-) diff --git a/src/fsfw/serialize/SerializeIF.h b/src/fsfw/serialize/SerializeIF.h index 5e7a2fb9..f20bf21f 100644 --- a/src/fsfw/serialize/SerializeIF.h +++ b/src/fsfw/serialize/SerializeIF.h @@ -68,13 +68,6 @@ class SerializeIF { size_t maxSize) const { return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); } - /** - * If endianness is not explicitly specified, use machine endianness - */ - [[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, - size_t maxSize) const { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE); - } /** * Gets the size of a object if it would be serialized in a buffer @@ -110,12 +103,6 @@ class SerializeIF { virtual ReturnValue_t deSerializeBe(const uint8_t **buffer, size_t *size) { return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK); } - /** - * If endianness is not explicitly specified, use machine endianness - */ - virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size) { - return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE); - } /** * Helper method which can be used if serialization should be performed without any additional @@ -139,13 +126,6 @@ class SerializeIF { size_t maxSize) const { return serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK); } - /** - * If endianness is not explicitly specified, use machine endianness - */ - [[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t &serLen, - size_t maxSize) const { - return serialize(buffer, serLen, maxSize, SerializeIF::Endianness::MACHINE); - } /** * Helper methods which can be used if deserialization should be performed without any additional @@ -168,12 +148,6 @@ class SerializeIF { virtual ReturnValue_t deSerializeBe(const uint8_t *buffer, size_t &deserSize, size_t maxSize) { return deSerialize(buffer, deserSize, maxSize, SerializeIF::Endianness::NETWORK); } - /** - * If endianness is not explicitly specified, use machine endianness - */ - virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t &deserSize, size_t maxSize) { - return deSerialize(buffer, deserSize, maxSize, SerializeIF::Endianness::MACHINE); - } }; #endif /* FSFW_SERIALIZE_SERIALIZEIF_H_ */ diff --git a/unittests/serialize/testSerializeIF.cpp b/unittests/serialize/testSerializeIF.cpp index 5200f8b7..7aafe98f 100644 --- a/unittests/serialize/testSerializeIF.cpp +++ b/unittests/serialize/testSerializeIF.cpp @@ -76,37 +76,6 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") { CHECK(buf[2] == 3); CHECK(serLen == 3); } - - SECTION("Machine Endian Implicit") { - REQUIRE(simpleSer.SerializeIF::serialize(&ptr, &len, buf.size()) == - HasReturnvaluesIF::RETURN_OK); - CHECK(buf[0] == 1); -#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - CHECK(buf[1] == 3); - CHECK(buf[2] == 2); -#else - CHECK(buf[1] == 2); - CHECK(buf[2] == 3); -#endif - // Verify pointer arithmetic and size increment - CHECK(ptr == buf.data() + 3); - CHECK(len == 3); - } - - SECTION("Machine Endian Simple Implicit") { - size_t serLen = 0xff; - REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size()) == - HasReturnvaluesIF::RETURN_OK); - CHECK(buf[0] == 1); -#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - CHECK(buf[1] == 3); - CHECK(buf[2] == 2); -#else - CHECK(buf[1] == 2); - CHECK(buf[2] == 3); -#endif - CHECK(serLen == 3); - } } TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { @@ -172,30 +141,4 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") { CHECK(simpleSer.getU16() == 1); CHECK(deserLen == 3); } - - SECTION("Machine Endian Implicit") { - REQUIRE(simpleSer.SerializeIF::deSerialize(&ptr, &len) == HasReturnvaluesIF::RETURN_OK); - CHECK(simpleSer.getU8() == 5); -#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - CHECK(simpleSer.getU16() == 0x0100); -#else - CHECK(simpleSer.getU16() == 1); -#endif - // Verify pointer arithmetic and size increment - CHECK(ptr == buf.data() + 3); - CHECK(len == 0); - } - - SECTION("Machine Endian Simple Implicit") { - size_t deserLen = 0xff; - REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) == - HasReturnvaluesIF::RETURN_OK); - CHECK(simpleSer.getU8() == 5); -#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - CHECK(simpleSer.getU16() == 0x0100); -#else - CHECK(simpleSer.getU16() == 1); -#endif - CHECK(deserLen == 3); - } } \ No newline at end of file