From 7c64797f035ef4173830a93bb19dada78d7a380c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 17:38:47 +0100 Subject: [PATCH 1/8] Add more baud rates --- hal/src/fsfw_hal/linux/uart/UartComIF.cpp | 44 ++++++++++++++++++++++ hal/src/fsfw_hal/linux/uart/UartCookie.cpp | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp index 0abff60e..3cfa0417 100644 --- a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp +++ b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp @@ -269,6 +269,50 @@ void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCooki cfsetispeed(options, B460800); cfsetospeed(options, B460800); break; + case 500000: + cfsetispeed(options, B500000); + cfsetospeed(options, B500000); + break; + case 576000: + cfsetispeed(options, B576000); + cfsetospeed(options, B576000); + break; + case 921600: + cfsetispeed(options, B921600); + cfsetospeed(options, B921600); + break; + case 1000000: + cfsetispeed(options, B1000000); + cfsetospeed(options, B1000000); + break; + case 1152000: + cfsetispeed(options, B1152000); + cfsetospeed(options, B1152000); + break; + case 1500000: + cfsetispeed(options, B1500000); + cfsetospeed(options, B1500000); + break; + case 2000000: + cfsetispeed(options, B2000000); + cfsetospeed(options, B2000000); + break; + case 2500000: + cfsetispeed(options, B2500000); + cfsetospeed(options, B2500000); + break; + case 3000000: + cfsetispeed(options, B3000000); + cfsetospeed(options, B3000000); + break; + case 3500000: + cfsetispeed(options, B3500000); + cfsetospeed(options, B3500000); + break; + case 4000000: + cfsetispeed(options, B4000000); + cfsetospeed(options, B4000000); + break; default: #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "UartComIF::configureBaudrate: Baudrate not supported" << std::endl; diff --git a/hal/src/fsfw_hal/linux/uart/UartCookie.cpp b/hal/src/fsfw_hal/linux/uart/UartCookie.cpp index 99e80a8e..63d90766 100644 --- a/hal/src/fsfw_hal/linux/uart/UartCookie.cpp +++ b/hal/src/fsfw_hal/linux/uart/UartCookie.cpp @@ -1,4 +1,4 @@ -#include "fsfw_hal/linux/uart/UartCookie.h" +#include "UartCookie.h" #include From f441505476a07c74c7859623fd4930f6575e3869 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 17:41:49 +0100 Subject: [PATCH 2/8] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d3b90b..284ccb6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information inside `fsfw/version.h` PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/559 +- Additional baudrates for Linux UART HAL + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/581 # [v4.0.0] From 3e17011087cfae3f3cbb9028cff35bf1d7a61e55 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 17:42:56 +0100 Subject: [PATCH 3/8] small tweaks for local datapool code --- src/fsfw/datapoollocal/LocalPoolObjectBase.cpp | 11 ++++++----- src/fsfw/datapoollocal/StaticLocalDataSet.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalPoolObjectBase.cpp b/src/fsfw/datapoollocal/LocalPoolObjectBase.cpp index c974601c..82aefc18 100644 --- a/src/fsfw/datapoollocal/LocalPoolObjectBase.cpp +++ b/src/fsfw/datapoollocal/LocalPoolObjectBase.cpp @@ -47,13 +47,14 @@ LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, HasLocalDataPoolIF* hkOwner = ObjectManager::instance()->get(poolOwner); if (hkOwner == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "LocalPoolVariable: The supplied pool owner did not implement the correct " - "interface HasLocalDataPoolIF!" - << std::endl; + sif::error << "LocalPoolVariable: The supplied pool owner 0x" << std::hex << poolOwner + << std::dec << " did not implement the correct interface " + << "HasLocalDataPoolIF" << std::endl; #else sif::printError( - "LocalPoolVariable: The supplied pool owner did not implement the correct " - "interface HasLocalDataPoolIF!\n"); + "LocalPoolVariable: The supplied pool owner 0x%08x did not implement the correct " + "interface HasLocalDataPoolIF\n", + poolOwner); #endif return; } diff --git a/src/fsfw/datapoollocal/StaticLocalDataSet.h b/src/fsfw/datapoollocal/StaticLocalDataSet.h index dd264e58..59047d67 100644 --- a/src/fsfw/datapoollocal/StaticLocalDataSet.h +++ b/src/fsfw/datapoollocal/StaticLocalDataSet.h @@ -46,7 +46,7 @@ class StaticLocalDataSet : public LocalPoolDataSetBase { } private: - std::array poolVarList; + std::array poolVarList = {}; }; #endif /* FSFW_DATAPOOLLOCAL_STATICLOCALDATASET_H_ */ From c60aa68d001270fec67b47c1af9f957d7e5bf372 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Thu, 24 Mar 2022 15:44:32 +0100 Subject: [PATCH 4/8] changed hal linux uart baudrate and bits per word to enums --- CHANGELOG.md | 4 +- hal/src/fsfw_hal/linux/uart/UartComIF.cpp | 68 +++++++++++----------- hal/src/fsfw_hal/linux/uart/UartCookie.cpp | 20 ++----- hal/src/fsfw_hal/linux/uart/UartCookie.h | 53 +++++++++++++---- 4 files changed, 83 insertions(+), 62 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 284ccb6e..f3eb6942 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572 - HAL Devicehandlers: Periodic printout is run-time configurable now - `oneShotAction` flag in the `TestTask` class is not static anymore +- HAL Linux Uart: Baudrate and bits per word are enums now, avoiding misconfigurations + PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/585 ## Removed @@ -35,8 +37,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information inside `fsfw/version.h` PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/559 -- Additional baudrates for Linux UART HAL - PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/581 # [v4.0.0] diff --git a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp index 3cfa0417..5aa72138 100644 --- a/hal/src/fsfw_hal/linux/uart/UartComIF.cpp +++ b/hal/src/fsfw_hal/linux/uart/UartComIF.cpp @@ -148,16 +148,16 @@ void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCook /* Clear size bits */ options->c_cflag &= ~CSIZE; switch (uartCookie->getBitsPerWord()) { - case 5: + case BitsPerWord::BITS_5: options->c_cflag |= CS5; break; - case 6: + case BitsPerWord::BITS_6: options->c_cflag |= CS6; break; - case 7: + case BitsPerWord::BITS_7: options->c_cflag |= CS7; break; - case 8: + case BitsPerWord::BITS_8: options->c_cflag |= CS8; break; default: @@ -193,123 +193,123 @@ void UartComIF::setFixedOptions(struct termios* options) { void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCookie) { switch (uartCookie->getBaudrate()) { - case 50: + case UartBaudRate::RATE_50: cfsetispeed(options, B50); cfsetospeed(options, B50); break; - case 75: + case UartBaudRate::RATE_75: cfsetispeed(options, B75); cfsetospeed(options, B75); break; - case 110: + case UartBaudRate::RATE_110: cfsetispeed(options, B110); cfsetospeed(options, B110); break; - case 134: + case UartBaudRate::RATE_134: cfsetispeed(options, B134); cfsetospeed(options, B134); break; - case 150: + case UartBaudRate::RATE_150: cfsetispeed(options, B150); cfsetospeed(options, B150); break; - case 200: + case UartBaudRate::RATE_200: cfsetispeed(options, B200); cfsetospeed(options, B200); break; - case 300: + case UartBaudRate::RATE_300: cfsetispeed(options, B300); cfsetospeed(options, B300); break; - case 600: + case UartBaudRate::RATE_600: cfsetispeed(options, B600); cfsetospeed(options, B600); break; - case 1200: + case UartBaudRate::RATE_1200: cfsetispeed(options, B1200); cfsetospeed(options, B1200); break; - case 1800: + case UartBaudRate::RATE_1800: cfsetispeed(options, B1800); cfsetospeed(options, B1800); break; - case 2400: + case UartBaudRate::RATE_2400: cfsetispeed(options, B2400); cfsetospeed(options, B2400); break; - case 4800: + case UartBaudRate::RATE_4800: cfsetispeed(options, B4800); cfsetospeed(options, B4800); break; - case 9600: + case UartBaudRate::RATE_9600: cfsetispeed(options, B9600); cfsetospeed(options, B9600); break; - case 19200: + case UartBaudRate::RATE_19200: cfsetispeed(options, B19200); cfsetospeed(options, B19200); break; - case 38400: + case UartBaudRate::RATE_38400: cfsetispeed(options, B38400); cfsetospeed(options, B38400); break; - case 57600: + case UartBaudRate::RATE_57600: cfsetispeed(options, B57600); cfsetospeed(options, B57600); break; - case 115200: + case UartBaudRate::RATE_115200: cfsetispeed(options, B115200); cfsetospeed(options, B115200); break; - case 230400: + case UartBaudRate::RATE_230400: cfsetispeed(options, B230400); cfsetospeed(options, B230400); break; - case 460800: + case UartBaudRate::RATE_460800: cfsetispeed(options, B460800); cfsetospeed(options, B460800); break; - case 500000: + case UartBaudRate::RATE_500000: cfsetispeed(options, B500000); cfsetospeed(options, B500000); break; - case 576000: + case UartBaudRate::RATE_576000: cfsetispeed(options, B576000); cfsetospeed(options, B576000); break; - case 921600: + case UartBaudRate::RATE_921600: cfsetispeed(options, B921600); cfsetospeed(options, B921600); break; - case 1000000: + case UartBaudRate::RATE_1000000: cfsetispeed(options, B1000000); cfsetospeed(options, B1000000); break; - case 1152000: + case UartBaudRate::RATE_1152000: cfsetispeed(options, B1152000); cfsetospeed(options, B1152000); break; - case 1500000: + case UartBaudRate::RATE_1500000: cfsetispeed(options, B1500000); cfsetospeed(options, B1500000); break; - case 2000000: + case UartBaudRate::RATE_2000000: cfsetispeed(options, B2000000); cfsetospeed(options, B2000000); break; - case 2500000: + case UartBaudRate::RATE_2500000: cfsetispeed(options, B2500000); cfsetospeed(options, B2500000); break; - case 3000000: + case UartBaudRate::RATE_3000000: cfsetispeed(options, B3000000); cfsetospeed(options, B3000000); break; - case 3500000: + case UartBaudRate::RATE_3500000: cfsetispeed(options, B3500000); cfsetospeed(options, B3500000); break; - case 4000000: + case UartBaudRate::RATE_4000000: cfsetispeed(options, B4000000); cfsetospeed(options, B4000000); break; diff --git a/hal/src/fsfw_hal/linux/uart/UartCookie.cpp b/hal/src/fsfw_hal/linux/uart/UartCookie.cpp index 63d90766..aa2dd214 100644 --- a/hal/src/fsfw_hal/linux/uart/UartCookie.cpp +++ b/hal/src/fsfw_hal/linux/uart/UartCookie.cpp @@ -3,7 +3,7 @@ #include UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, - uint32_t baudrate, size_t maxReplyLen) + UartBaudRate baudrate, size_t maxReplyLen) : handlerId(handlerId), deviceFile(deviceFile), uartMode(uartMode), @@ -12,7 +12,7 @@ UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes UartCookie::~UartCookie() {} -uint32_t UartCookie::getBaudrate() const { return baudrate; } +UartBaudRate UartCookie::getBaudrate() const { return baudrate; } size_t UartCookie::getMaxReplyLen() const { return maxReplyLen; } @@ -24,23 +24,11 @@ void UartCookie::setParityEven() { parity = Parity::EVEN; } Parity UartCookie::getParity() const { return parity; } -void UartCookie::setBitsPerWord(uint8_t bitsPerWord_) { - switch (bitsPerWord_) { - case 5: - case 6: - case 7: - case 8: - break; - default: -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "UartCookie::setBitsPerWord: Invalid bits per word specified" << std::endl; -#endif - return; - } +void UartCookie::setBitsPerWord(BitsPerWord bitsPerWord_) { bitsPerWord = bitsPerWord_; } -uint8_t UartCookie::getBitsPerWord() const { return bitsPerWord; } +BitsPerWord UartCookie::getBitsPerWord() const { return bitsPerWord; } StopBits UartCookie::getStopBits() const { return stopBits; } diff --git a/hal/src/fsfw_hal/linux/uart/UartCookie.h b/hal/src/fsfw_hal/linux/uart/UartCookie.h index 884665e5..6840b352 100644 --- a/hal/src/fsfw_hal/linux/uart/UartCookie.h +++ b/hal/src/fsfw_hal/linux/uart/UartCookie.h @@ -12,6 +12,41 @@ enum class StopBits { ONE_STOP_BIT, TWO_STOP_BITS }; enum class UartModes { CANONICAL, NON_CANONICAL }; +enum class BitsPerWord { BITS_5, BITS_6, BITS_7, BITS_8 }; + +enum class UartBaudRate { + RATE_50, + RATE_75, + RATE_110, + RATE_134, + RATE_150, + RATE_200, + RATE_300, + RATE_600, + RATE_1200, + RATE_1800, + RATE_2400, + RATE_4800, + RATE_9600, + RATE_19200, + RATE_38400, + RATE_57600, + RATE_115200, + RATE_230400, + RATE_460800, + RATE_500000, + RATE_576000, + RATE_921600, + RATE_1000000, + RATE_1152000, + RATE_1500000, + RATE_2000000, + RATE_2500000, + RATE_3000000, + RATE_3500000, + RATE_4000000 +}; + /** * @brief Cookie for the UartComIF. There are many options available to configure the UART driver. * The constructor only requests for common options like the baudrate. Other options can @@ -27,25 +62,23 @@ class UartCookie : public CookieIF { * @param uartMode Specify the UART mode. The canonical mode should be used if the * messages are separated by a delimited character like '\n'. See the * termios documentation for more information - * @param baudrate The baudrate to use for input and output. Possible Baudrates are: 50, - * 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, B19200, - * 38400, 57600, 115200, 230400, 460800 + * @param baudrate The baudrate to use for input and output. * @param maxReplyLen The maximum size an object using this cookie expects * @details * Default configuration: No parity * 8 databits (number of bits transfered with one uart frame) * One stop bit */ - UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, uint32_t baudrate, - size_t maxReplyLen); + UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, + UartBaudRate baudrate, size_t maxReplyLen); virtual ~UartCookie(); - uint32_t getBaudrate() const; + UartBaudRate getBaudrate() const; size_t getMaxReplyLen() const; std::string getDeviceFile() const; Parity getParity() const; - uint8_t getBitsPerWord() const; + BitsPerWord getBitsPerWord() const; StopBits getStopBits() const; UartModes getUartMode() const; object_id_t getHandlerId() const; @@ -76,7 +109,7 @@ class UartCookie : public CookieIF { /** * Function two set number of bits per UART frame. */ - void setBitsPerWord(uint8_t bitsPerWord_); + void setBitsPerWord(BitsPerWord bitsPerWord_); /** * Function to specify the number of stopbits. @@ -97,10 +130,10 @@ class UartCookie : public CookieIF { std::string deviceFile; const UartModes uartMode; bool flushInput = false; - uint32_t baudrate; + UartBaudRate baudrate; size_t maxReplyLen = 0; Parity parity = Parity::NONE; - uint8_t bitsPerWord = 8; + BitsPerWord bitsPerWord = BitsPerWord::BITS_8; uint8_t readCycles = 1; StopBits stopBits = StopBits::ONE_STOP_BIT; bool replySizeFixed = true; From d95582b81b1258d14da0507825b643f141112507 Mon Sep 17 00:00:00 2001 From: Cleanroom Laptop L590 Date: Thu, 24 Mar 2022 16:54:41 +0100 Subject: [PATCH 5/8] cmake lists update to suppress large warning --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9786d572..7ef11493 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,9 +48,10 @@ add_library(${LIB_FSFW_NAME}) if(FSFW_BUILD_UNITTESTS) message(STATUS "Building the FSFW unittests in addition to the static library") # Check whether the user has already installed Catch2 first - find_package(Catch2 3) + find_package(Catch2 3 QUIET) # Not installed, so use FetchContent to download and provide Catch2 if(NOT Catch2_FOUND) + message(STATUS "Catch2 installation not found. Downloading Catch2 library with FetchContent") include(FetchContent) FetchContent_Declare( From d9d9a28ef84f01b3915865cd5399e9ebe0e104f2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 24 Mar 2022 21:04:46 +0100 Subject: [PATCH 6/8] delete code which is not required anymore --- hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp index 69f6311e..52b6dc07 100644 --- a/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp +++ b/hal/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -1,9 +1,6 @@ #include "MgmLIS3MDLHandler.h" #include "fsfw/datapool/PoolReadGuard.h" -#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1 -#include "fsfw/globalfunctions/PeriodicOperationDivider.h" -#endif #include From 916ed3f56ac676f5a411895d4fadbb8665bb550e Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Mon, 28 Mar 2022 13:50:42 +0200 Subject: [PATCH 7/8] added function to add component to a periodic task by pointer --- src/fsfw/osal/freertos/PeriodicTask.cpp | 10 +++++++--- src/fsfw/osal/freertos/PeriodicTask.h | 10 ++++++++++ src/fsfw/osal/host/PeriodicTask.cpp | 10 +++++++--- src/fsfw/osal/host/PeriodicTask.h | 10 ++++++++++ src/fsfw/osal/linux/PeriodicPosixTask.cpp | 10 +++++++--- src/fsfw/osal/linux/PeriodicPosixTask.h | 8 ++++++++ src/fsfw/osal/rtems/PeriodicTask.cpp | 10 +++++++--- src/fsfw/osal/rtems/PeriodicTask.h | 9 +++++++++ src/fsfw/tasks/PeriodicTaskIF.h | 20 ++++++++++++-------- 9 files changed, 77 insertions(+), 20 deletions(-) diff --git a/src/fsfw/osal/freertos/PeriodicTask.cpp b/src/fsfw/osal/freertos/PeriodicTask.cpp index 8dfa0290..d2c46ea8 100644 --- a/src/fsfw/osal/freertos/PeriodicTask.cpp +++ b/src/fsfw/osal/freertos/PeriodicTask.cpp @@ -97,7 +97,11 @@ void PeriodicTask::taskFunctionality() { ReturnValue_t PeriodicTask::addComponent(object_id_t object) { ExecutableObjectIF* newObject = ObjectManager::instance()->get(object); - if (newObject == nullptr) { + return addComponent(newObject); +} + +ReturnValue_t PeriodicTask::addComponent(ExecutableObjectIF* object) { + if (object == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PeriodicTask::addComponent: Invalid object. Make sure" "it implement ExecutableObjectIF" @@ -105,8 +109,8 @@ ReturnValue_t PeriodicTask::addComponent(object_id_t object) { #endif return HasReturnvaluesIF::RETURN_FAILED; } - objectList.push_back(newObject); - newObject->setTaskIF(this); + objectList.push_back(object); + object->setTaskIF(this); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/osal/freertos/PeriodicTask.h b/src/fsfw/osal/freertos/PeriodicTask.h index cc395176..fc8e9092 100644 --- a/src/fsfw/osal/freertos/PeriodicTask.h +++ b/src/fsfw/osal/freertos/PeriodicTask.h @@ -63,6 +63,16 @@ class PeriodicTask : public PeriodicTaskIF, public FreeRTOSTaskIF { */ ReturnValue_t addComponent(object_id_t object) override; + /** + * Adds an object to the list of objects to be executed. + * The objects are executed in the order added. + * @param object Id of the object to add. + * @return + * -@c RETURN_OK on success + * -@c RETURN_FAILED if the object could not be added. + */ + ReturnValue_t addComponent(ExecutableObjectIF* object) override; + uint32_t getPeriodMs() const override; ReturnValue_t sleepFor(uint32_t ms) override; diff --git a/src/fsfw/osal/host/PeriodicTask.cpp b/src/fsfw/osal/host/PeriodicTask.cpp index 1de4aedf..cdcfafa6 100644 --- a/src/fsfw/osal/host/PeriodicTask.cpp +++ b/src/fsfw/osal/host/PeriodicTask.cpp @@ -102,11 +102,15 @@ void PeriodicTask::taskFunctionality() { ReturnValue_t PeriodicTask::addComponent(object_id_t object) { ExecutableObjectIF* newObject = ObjectManager::instance()->get(object); - if (newObject == nullptr) { + return addComponent(newObject); +} + +ReturnValue_t PeriodicTask::addComponent(ExecutableObjectIF* object) { + if (object == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - newObject->setTaskIF(this); - objectList.push_back(newObject); + object->setTaskIF(this); + objectList.push_back(object); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/osal/host/PeriodicTask.h b/src/fsfw/osal/host/PeriodicTask.h index 0c41c0f7..6c4d5e8b 100644 --- a/src/fsfw/osal/host/PeriodicTask.h +++ b/src/fsfw/osal/host/PeriodicTask.h @@ -59,6 +59,16 @@ class PeriodicTask : public PeriodicTaskIF { */ ReturnValue_t addComponent(object_id_t object); + /** + * Adds an object to the list of objects to be executed. + * The objects are executed in the order added. + * @param object pointer to the object to add. + * @return + * -@c RETURN_OK on success + * -@c RETURN_FAILED if the object could not be added. + */ + ReturnValue_t addComponent(ExecutableObjectIF* object); + uint32_t getPeriodMs() const; ReturnValue_t sleepFor(uint32_t ms); diff --git a/src/fsfw/osal/linux/PeriodicPosixTask.cpp b/src/fsfw/osal/linux/PeriodicPosixTask.cpp index ca346670..e1937df4 100644 --- a/src/fsfw/osal/linux/PeriodicPosixTask.cpp +++ b/src/fsfw/osal/linux/PeriodicPosixTask.cpp @@ -28,7 +28,11 @@ void* PeriodicPosixTask::taskEntryPoint(void* arg) { ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) { ExecutableObjectIF* newObject = ObjectManager::instance()->get(object); - if (newObject == nullptr) { + return addComponent(newObject); +} + +ReturnValue_t PeriodicPosixTask::addComponent(ExecutableObjectIF* object) { + if (object == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PeriodicTask::addComponent: Invalid object. Make sure" << " it implements ExecutableObjectIF!" << std::endl; @@ -39,8 +43,8 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) { #endif return HasReturnvaluesIF::RETURN_FAILED; } - objectList.push_back(newObject); - newObject->setTaskIF(this); + objectList.push_back(object); + object->setTaskIF(this); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/osal/linux/PeriodicPosixTask.h b/src/fsfw/osal/linux/PeriodicPosixTask.h index 1c3a52c7..3cd9847a 100644 --- a/src/fsfw/osal/linux/PeriodicPosixTask.h +++ b/src/fsfw/osal/linux/PeriodicPosixTask.h @@ -42,6 +42,14 @@ class PeriodicPosixTask : public PosixThread, public PeriodicTaskIF { */ ReturnValue_t addComponent(object_id_t object) override; + /** + * Adds an object to the list of objects to be executed. + * The objects are executed in the order added. + * @param object pointer to the object to add. + * @return RETURN_OK on success, RETURN_FAILED if the object could not be added. + */ + ReturnValue_t addComponent(ExecutableObjectIF* object) override; + uint32_t getPeriodMs() const override; ReturnValue_t sleepFor(uint32_t ms) override; diff --git a/src/fsfw/osal/rtems/PeriodicTask.cpp b/src/fsfw/osal/rtems/PeriodicTask.cpp index 1785c8cf..ae2ec426 100644 --- a/src/fsfw/osal/rtems/PeriodicTask.cpp +++ b/src/fsfw/osal/rtems/PeriodicTask.cpp @@ -68,11 +68,15 @@ void PeriodicTask::taskFunctionality() { ReturnValue_t PeriodicTask::addComponent(object_id_t object) { ExecutableObjectIF* newObject = ObjectManager::instance()->get(object); - if (newObject == nullptr) { + return addComponent(newObject); +} + +ReturnValue_t PeriodicTask::addComponent(ExecutableObjectIF* object) { + if (object == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - objectList.push_back(newObject); - newObject->setTaskIF(this); + objectList.push_back(object); + object->setTaskIF(this); return HasReturnvaluesIF::RETURN_OK; } diff --git a/src/fsfw/osal/rtems/PeriodicTask.h b/src/fsfw/osal/rtems/PeriodicTask.h index 119329f2..24ce4af1 100644 --- a/src/fsfw/osal/rtems/PeriodicTask.h +++ b/src/fsfw/osal/rtems/PeriodicTask.h @@ -59,6 +59,15 @@ class PeriodicTask : public RTEMSTaskBase, public PeriodicTaskIF { */ ReturnValue_t addComponent(object_id_t object) override; +/** + * Adds an object to the list of objects to be executed. + * The objects are executed in the order added. + * @param object pointer to the object to add. + * @return RETURN_OK on success, RETURN_FAILED if the object could not be added. + */ + ReturnValue_t addComponent(ExecutableObjectIF* object) override; + + uint32_t getPeriodMs() const override; ReturnValue_t sleepFor(uint32_t ms) override; diff --git a/src/fsfw/tasks/PeriodicTaskIF.h b/src/fsfw/tasks/PeriodicTaskIF.h index a8a51229..c78a32de 100644 --- a/src/fsfw/tasks/PeriodicTaskIF.h +++ b/src/fsfw/tasks/PeriodicTaskIF.h @@ -26,21 +26,25 @@ class PeriodicTaskIF { virtual ReturnValue_t startTask() = 0; /** - * Add a component (object) to a periodic task. The pointer to the - * task can be set optionally + * Add a component (object) to a periodic task. * @param object - * Add an object to the task. The most important case is to add an - * executable object with a function which will be called regularly - * (see ExecutableObjectIF) - * @param setTaskIF - * Can be used to specify whether the task object pointer is passed - * to the component. + * Add an object to the task. The object needs to implement ExecutableObjectIF * @return */ virtual ReturnValue_t addComponent(object_id_t object) { return HasReturnvaluesIF::RETURN_FAILED; }; + /** + * Add an object to a periodic task. + * @param object + * Add an object to the task. + * @return + */ + virtual ReturnValue_t addComponent(ExecutableObjectIF* object) { + return HasReturnvaluesIF::RETURN_FAILED; + }; + virtual ReturnValue_t sleepFor(uint32_t ms) = 0; virtual uint32_t getPeriodMs() const = 0; From 6c1db8473bdd7639065e230341d52007c58ecf49 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 31 Mar 2022 14:36:45 +0200 Subject: [PATCH 8/8] get alternative reply from device command info --- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 31 ++++++++++++++----- src/fsfw/devicehandlers/DeviceHandlerBase.h | 6 +++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 08a15d5f..0e2802ac 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -410,7 +410,7 @@ ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap( DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, LocalPoolDataSetBase* replyDataSet, size_t replyLen, bool periodic, bool hasDifferentReplyId, DeviceCommandId_t replyId) { // No need to check, as we may try to insert multiple times. - insertInCommandMap(deviceCommand); + insertInCommandMap(deviceCommand, hasDifferentReplyId, replyId); if (hasDifferentReplyId) { return insertInReplyMap(replyId, maxDelayCycles, replyDataSet, replyLen, periodic); } else { @@ -437,11 +437,15 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, } } -ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceCommand) { +ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceCommand, + bool useAlternativeReply, + DeviceCommandId_t alternativeReplyId) { DeviceCommandInfo info; info.expectedReplies = 0; info.isExecuting = false; info.sendReplyTo = NO_COMMANDER; + info.useAlternativeReplyId = alternativeReplyId; + info.alternativeReplyId = alternativeReplyId; auto resultPair = deviceCommandMap.emplace(deviceCommand, info); if (resultPair.second) { return RETURN_OK; @@ -451,12 +455,21 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceComm } size_t DeviceHandlerBase::getNextReplyLength(DeviceCommandId_t commandId) { - DeviceReplyIter iter = deviceReplyMap.find(commandId); - if (iter != deviceReplyMap.end()) { - return iter->second.replyLen; - } else { - return 0; + DeviceCommandId_t replyId = NO_COMMAND_ID; + DeviceCommandMap::iterator command = cookieInfo.pendingCommand; + if (command->second.useAlternativeReplyId) { + replyId = command->second.alternativeReplyId; } + else { + replyId = commandId; + } + DeviceReplyIter iter = deviceReplyMap.find(replyId); + if (iter != deviceReplyMap.end()) { + if (iter->second.delayCycles != 0) { + return iter->second.replyLen; + } + } + return 0; } ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply, @@ -651,7 +664,9 @@ void DeviceHandlerBase::doGetWrite() { // We need to distinguish here, because a raw command never expects a reply. //(Could be done in eRIRM, but then child implementations need to be careful. - result = enableReplyInReplyMap(cookieInfo.pendingCommand); + DeviceCommandMap::iterator command = cookieInfo.pendingCommand; + result = enableReplyInReplyMap(command, 1, command->second.useAlternativeReplyId, + command->second.alternativeReplyId); } else { // always generate a failure event, so that FDIR knows what's up triggerEvent(DEVICE_SENDING_COMMAND_FAILED, result, cookieInfo.pendingCommand->first); diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index c8b8b86d..5e974831 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -478,7 +478,9 @@ class DeviceHandlerBase : public DeviceHandlerIF, * @return - @c RETURN_OK when the command was successfully inserted, * - @c RETURN_FAILED else. */ - ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand); + ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand, + bool useAlternativeReply = false, + DeviceCommandId_t alternativeReplyId = 0); /** * Enables a periodic reply for a given command. It sets to delay cycles to the specified @@ -751,6 +753,8 @@ class DeviceHandlerBase : public DeviceHandlerIF, //! if this is != NO_COMMANDER, DHB was commanded externally and shall //! report everything to commander. MessageQueueId_t sendReplyTo; + bool useAlternativeReplyId; + DeviceCommandId_t alternativeReplyId; }; using DeviceCommandMap = std::map; /**