Merge remote-tracking branch 'upstream/development' into mueller/master

This commit is contained in:
Robin Müller 2022-04-09 14:37:16 +02:00
commit ff5153d011
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
18 changed files with 196 additions and 125 deletions

View File

@ -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 PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/572
- HAL Devicehandlers: Periodic printout is run-time configurable now - HAL Devicehandlers: Periodic printout is run-time configurable now
- `oneShotAction` flag in the `TestTask` class is not static anymore - `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 ## Removed

View File

@ -1,12 +1,9 @@
#include "MgmLIS3MDLHandler.h" #include "MgmLIS3MDLHandler.h"
#include "fsfw/datapool/PoolReadGuard.h"
#if FSFW_HAL_LIS3MDL_MGM_DEBUG == 1
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
#endif
#include <cmath> #include <cmath>
#include "fsfw/datapool/PoolReadGuard.h"
MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication, MgmLIS3MDLHandler::MgmLIS3MDLHandler(object_id_t objectId, object_id_t deviceCommunication,
CookieIF *comCookie, uint32_t transitionDelay) CookieIF *comCookie, uint32_t transitionDelay)
: DeviceHandlerBase(objectId, deviceCommunication, comCookie), : DeviceHandlerBase(objectId, deviceCommunication, comCookie),

View File

@ -148,16 +148,16 @@ void UartComIF::setDatasizeOptions(struct termios* options, UartCookie* uartCook
/* Clear size bits */ /* Clear size bits */
options->c_cflag &= ~CSIZE; options->c_cflag &= ~CSIZE;
switch (uartCookie->getBitsPerWord()) { switch (uartCookie->getBitsPerWord()) {
case 5: case BitsPerWord::BITS_5:
options->c_cflag |= CS5; options->c_cflag |= CS5;
break; break;
case 6: case BitsPerWord::BITS_6:
options->c_cflag |= CS6; options->c_cflag |= CS6;
break; break;
case 7: case BitsPerWord::BITS_7:
options->c_cflag |= CS7; options->c_cflag |= CS7;
break; break;
case 8: case BitsPerWord::BITS_8:
options->c_cflag |= CS8; options->c_cflag |= CS8;
break; break;
default: default:
@ -193,123 +193,123 @@ void UartComIF::setFixedOptions(struct termios* options) {
void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCookie) { void UartComIF::configureBaudrate(struct termios* options, UartCookie* uartCookie) {
switch (uartCookie->getBaudrate()) { switch (uartCookie->getBaudrate()) {
case 50: case UartBaudRate::RATE_50:
cfsetispeed(options, B50); cfsetispeed(options, B50);
cfsetospeed(options, B50); cfsetospeed(options, B50);
break; break;
case 75: case UartBaudRate::RATE_75:
cfsetispeed(options, B75); cfsetispeed(options, B75);
cfsetospeed(options, B75); cfsetospeed(options, B75);
break; break;
case 110: case UartBaudRate::RATE_110:
cfsetispeed(options, B110); cfsetispeed(options, B110);
cfsetospeed(options, B110); cfsetospeed(options, B110);
break; break;
case 134: case UartBaudRate::RATE_134:
cfsetispeed(options, B134); cfsetispeed(options, B134);
cfsetospeed(options, B134); cfsetospeed(options, B134);
break; break;
case 150: case UartBaudRate::RATE_150:
cfsetispeed(options, B150); cfsetispeed(options, B150);
cfsetospeed(options, B150); cfsetospeed(options, B150);
break; break;
case 200: case UartBaudRate::RATE_200:
cfsetispeed(options, B200); cfsetispeed(options, B200);
cfsetospeed(options, B200); cfsetospeed(options, B200);
break; break;
case 300: case UartBaudRate::RATE_300:
cfsetispeed(options, B300); cfsetispeed(options, B300);
cfsetospeed(options, B300); cfsetospeed(options, B300);
break; break;
case 600: case UartBaudRate::RATE_600:
cfsetispeed(options, B600); cfsetispeed(options, B600);
cfsetospeed(options, B600); cfsetospeed(options, B600);
break; break;
case 1200: case UartBaudRate::RATE_1200:
cfsetispeed(options, B1200); cfsetispeed(options, B1200);
cfsetospeed(options, B1200); cfsetospeed(options, B1200);
break; break;
case 1800: case UartBaudRate::RATE_1800:
cfsetispeed(options, B1800); cfsetispeed(options, B1800);
cfsetospeed(options, B1800); cfsetospeed(options, B1800);
break; break;
case 2400: case UartBaudRate::RATE_2400:
cfsetispeed(options, B2400); cfsetispeed(options, B2400);
cfsetospeed(options, B2400); cfsetospeed(options, B2400);
break; break;
case 4800: case UartBaudRate::RATE_4800:
cfsetispeed(options, B4800); cfsetispeed(options, B4800);
cfsetospeed(options, B4800); cfsetospeed(options, B4800);
break; break;
case 9600: case UartBaudRate::RATE_9600:
cfsetispeed(options, B9600); cfsetispeed(options, B9600);
cfsetospeed(options, B9600); cfsetospeed(options, B9600);
break; break;
case 19200: case UartBaudRate::RATE_19200:
cfsetispeed(options, B19200); cfsetispeed(options, B19200);
cfsetospeed(options, B19200); cfsetospeed(options, B19200);
break; break;
case 38400: case UartBaudRate::RATE_38400:
cfsetispeed(options, B38400); cfsetispeed(options, B38400);
cfsetospeed(options, B38400); cfsetospeed(options, B38400);
break; break;
case 57600: case UartBaudRate::RATE_57600:
cfsetispeed(options, B57600); cfsetispeed(options, B57600);
cfsetospeed(options, B57600); cfsetospeed(options, B57600);
break; break;
case 115200: case UartBaudRate::RATE_115200:
cfsetispeed(options, B115200); cfsetispeed(options, B115200);
cfsetospeed(options, B115200); cfsetospeed(options, B115200);
break; break;
case 230400: case UartBaudRate::RATE_230400:
cfsetispeed(options, B230400); cfsetispeed(options, B230400);
cfsetospeed(options, B230400); cfsetospeed(options, B230400);
break; break;
case 460800: case UartBaudRate::RATE_460800:
cfsetispeed(options, B460800); cfsetispeed(options, B460800);
cfsetospeed(options, B460800); cfsetospeed(options, B460800);
break; break;
case 500000: case UartBaudRate::RATE_500000:
cfsetispeed(options, B500000); cfsetispeed(options, B500000);
cfsetospeed(options, B500000); cfsetospeed(options, B500000);
break; break;
case 576000: case UartBaudRate::RATE_576000:
cfsetispeed(options, B576000); cfsetispeed(options, B576000);
cfsetospeed(options, B576000); cfsetospeed(options, B576000);
break; break;
case 921600: case UartBaudRate::RATE_921600:
cfsetispeed(options, B921600); cfsetispeed(options, B921600);
cfsetospeed(options, B921600); cfsetospeed(options, B921600);
break; break;
case 1000000: case UartBaudRate::RATE_1000000:
cfsetispeed(options, B1000000); cfsetispeed(options, B1000000);
cfsetospeed(options, B1000000); cfsetospeed(options, B1000000);
break; break;
case 1152000: case UartBaudRate::RATE_1152000:
cfsetispeed(options, B1152000); cfsetispeed(options, B1152000);
cfsetospeed(options, B1152000); cfsetospeed(options, B1152000);
break; break;
case 1500000: case UartBaudRate::RATE_1500000:
cfsetispeed(options, B1500000); cfsetispeed(options, B1500000);
cfsetospeed(options, B1500000); cfsetospeed(options, B1500000);
break; break;
case 2000000: case UartBaudRate::RATE_2000000:
cfsetispeed(options, B2000000); cfsetispeed(options, B2000000);
cfsetospeed(options, B2000000); cfsetospeed(options, B2000000);
break; break;
case 2500000: case UartBaudRate::RATE_2500000:
cfsetispeed(options, B2500000); cfsetispeed(options, B2500000);
cfsetospeed(options, B2500000); cfsetospeed(options, B2500000);
break; break;
case 3000000: case UartBaudRate::RATE_3000000:
cfsetispeed(options, B3000000); cfsetispeed(options, B3000000);
cfsetospeed(options, B3000000); cfsetospeed(options, B3000000);
break; break;
case 3500000: case UartBaudRate::RATE_3500000:
cfsetispeed(options, B3500000); cfsetispeed(options, B3500000);
cfsetospeed(options, B3500000); cfsetospeed(options, B3500000);
break; break;
case 4000000: case UartBaudRate::RATE_4000000:
cfsetispeed(options, B4000000); cfsetispeed(options, B4000000);
cfsetospeed(options, B4000000); cfsetospeed(options, B4000000);
break; break;

View File

@ -2,8 +2,8 @@
#include <fsfw/serviceinterface.h> #include <fsfw/serviceinterface.h>
UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate,
uint32_t baudrate, size_t maxReplyLen) size_t maxReplyLen, UartModes uartMode)
: handlerId(handlerId), : handlerId(handlerId),
deviceFile(deviceFile), deviceFile(deviceFile),
uartMode(uartMode), uartMode(uartMode),
@ -12,7 +12,7 @@ UartCookie::UartCookie(object_id_t handlerId, std::string deviceFile, UartModes
UartCookie::~UartCookie() {} UartCookie::~UartCookie() {}
uint32_t UartCookie::getBaudrate() const { return baudrate; } UartBaudRate UartCookie::getBaudrate() const { return baudrate; }
size_t UartCookie::getMaxReplyLen() const { return maxReplyLen; } size_t UartCookie::getMaxReplyLen() const { return maxReplyLen; }
@ -24,23 +24,9 @@ void UartCookie::setParityEven() { parity = Parity::EVEN; }
Parity UartCookie::getParity() const { return parity; } Parity UartCookie::getParity() const { return parity; }
void UartCookie::setBitsPerWord(uint8_t bitsPerWord_) { void UartCookie::setBitsPerWord(BitsPerWord bitsPerWord_) { bitsPerWord = 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;
}
bitsPerWord = bitsPerWord_;
}
uint8_t UartCookie::getBitsPerWord() const { return bitsPerWord; } BitsPerWord UartCookie::getBitsPerWord() const { return bitsPerWord; }
StopBits UartCookie::getStopBits() const { return stopBits; } StopBits UartCookie::getStopBits() const { return stopBits; }

View File

@ -12,6 +12,41 @@ enum class StopBits { ONE_STOP_BIT, TWO_STOP_BITS };
enum class UartModes { CANONICAL, NON_CANONICAL }; 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. * @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 * 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 * @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 * messages are separated by a delimited character like '\n'. See the
* termios documentation for more information * termios documentation for more information
* @param baudrate The baudrate to use for input and output. Possible Baudrates are: 50, * @param baudrate The baudrate to use for input and output.
* 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, B19200,
* 38400, 57600, 115200, 230400, 460800
* @param maxReplyLen The maximum size an object using this cookie expects * @param maxReplyLen The maximum size an object using this cookie expects
* @details * @details
* Default configuration: No parity * Default configuration: No parity
* 8 databits (number of bits transfered with one uart frame) * 8 databits (number of bits transfered with one uart frame)
* One stop bit * One stop bit
*/ */
UartCookie(object_id_t handlerId, std::string deviceFile, UartModes uartMode, uint32_t baudrate, UartCookie(object_id_t handlerId, std::string deviceFile, UartBaudRate baudrate,
size_t maxReplyLen); size_t maxReplyLen, UartModes uartMode = UartModes::NON_CANONICAL);
virtual ~UartCookie(); virtual ~UartCookie();
uint32_t getBaudrate() const; UartBaudRate getBaudrate() const;
size_t getMaxReplyLen() const; size_t getMaxReplyLen() const;
std::string getDeviceFile() const; std::string getDeviceFile() const;
Parity getParity() const; Parity getParity() const;
uint8_t getBitsPerWord() const; BitsPerWord getBitsPerWord() const;
StopBits getStopBits() const; StopBits getStopBits() const;
UartModes getUartMode() const; UartModes getUartMode() const;
object_id_t getHandlerId() const; object_id_t getHandlerId() const;
@ -76,7 +109,7 @@ class UartCookie : public CookieIF {
/** /**
* Function two set number of bits per UART frame. * 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. * Function to specify the number of stopbits.
@ -97,10 +130,10 @@ class UartCookie : public CookieIF {
std::string deviceFile; std::string deviceFile;
const UartModes uartMode; const UartModes uartMode;
bool flushInput = false; bool flushInput = false;
uint32_t baudrate; UartBaudRate baudrate;
size_t maxReplyLen = 0; size_t maxReplyLen = 0;
Parity parity = Parity::NONE; Parity parity = Parity::NONE;
uint8_t bitsPerWord = 8; BitsPerWord bitsPerWord = BitsPerWord::BITS_8;
uint8_t readCycles = 1; uint8_t readCycles = 1;
StopBits stopBits = StopBits::ONE_STOP_BIT; StopBits stopBits = StopBits::ONE_STOP_BIT;
bool replySizeFixed = true; bool replySizeFixed = true;

View File

@ -7,7 +7,7 @@
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/ServiceInterface.h"
template <typename T> template <typename T>
PoolEntry<T>::PoolEntry(uint8_t len, bool setValid): length(len), valid(setValid) { PoolEntry<T>::PoolEntry(uint8_t len, bool setValid) : length(len), valid(setValid) {
this->address = new T[this->length](); this->address = new T[this->length]();
std::memset(this->address, 0, this->getByteSize()); std::memset(this->address, 0, this->getByteSize());
} }

View File

@ -97,7 +97,11 @@ void PeriodicTask::taskFunctionality() {
ReturnValue_t PeriodicTask::addComponent(object_id_t object) { ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object); ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object);
if (newObject == nullptr) { return addComponent(newObject);
}
ReturnValue_t PeriodicTask::addComponent(ExecutableObjectIF* object) {
if (object == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure" sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
"it implement ExecutableObjectIF" "it implement ExecutableObjectIF"
@ -105,8 +109,8 @@ ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
objectList.push_back(newObject); objectList.push_back(object);
newObject->setTaskIF(this); object->setTaskIF(this);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -63,6 +63,16 @@ class PeriodicTask : public PeriodicTaskIF, public FreeRTOSTaskIF {
*/ */
ReturnValue_t addComponent(object_id_t object) override; 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; uint32_t getPeriodMs() const override;
ReturnValue_t sleepFor(uint32_t ms) override; ReturnValue_t sleepFor(uint32_t ms) override;

View File

@ -102,11 +102,15 @@ void PeriodicTask::taskFunctionality() {
ReturnValue_t PeriodicTask::addComponent(object_id_t object) { ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object); ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object);
if (newObject == nullptr) { return addComponent(newObject);
}
ReturnValue_t PeriodicTask::addComponent(ExecutableObjectIF* object) {
if (object == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
newObject->setTaskIF(this); object->setTaskIF(this);
objectList.push_back(newObject); objectList.push_back(object);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -59,6 +59,16 @@ class PeriodicTask : public PeriodicTaskIF {
*/ */
ReturnValue_t addComponent(object_id_t object); 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; uint32_t getPeriodMs() const;
ReturnValue_t sleepFor(uint32_t ms); ReturnValue_t sleepFor(uint32_t ms);

View File

@ -1,5 +1,4 @@
#include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/Clock.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <linux/sysinfo.h> #include <linux/sysinfo.h>
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
@ -7,8 +6,10 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <fstream>
#include <cstring> #include <cstring>
#include <fstream>
#include "fsfw/serviceinterface/ServiceInterface.h"
uint16_t Clock::leapSeconds = 0; uint16_t Clock::leapSeconds = 0;
MutexIF* Clock::timeMutex = NULL; MutexIF* Clock::timeMutex = NULL;
@ -155,12 +156,11 @@ ReturnValue_t Clock::convertTimevalToJD2000(timeval time, double* JD2000) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void handleClockError(const char* func) { void handleClockError(const char* func) {
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Clock::" << func << ": Failed with code " << errno << ": " << strerror(errno) sif::warning << "Clock::" << func << ": Failed with code " << errno << ": " << strerror(errno)
<< std::endl; << std::endl;
#else #else
sif::printWarning("Clock::%s: Failed with code %d: %s\n", func, errno, strerror(errno)); sif::printWarning("Clock::%s: Failed with code %d: %s\n", func, errno, strerror(errno));
#endif #endif

View File

@ -28,7 +28,11 @@ void* PeriodicPosixTask::taskEntryPoint(void* arg) {
ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) { ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) {
ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object); ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object);
if (newObject == nullptr) { return addComponent(newObject);
}
ReturnValue_t PeriodicPosixTask::addComponent(ExecutableObjectIF* object) {
if (object == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure" sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
<< " it implements ExecutableObjectIF!" << std::endl; << " it implements ExecutableObjectIF!" << std::endl;
@ -39,8 +43,8 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) {
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
objectList.push_back(newObject); objectList.push_back(object);
newObject->setTaskIF(this); object->setTaskIF(this);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -42,6 +42,14 @@ class PeriodicPosixTask : public PosixThread, public PeriodicTaskIF {
*/ */
ReturnValue_t addComponent(object_id_t object) override; 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; uint32_t getPeriodMs() const override;
ReturnValue_t sleepFor(uint32_t ms) override; ReturnValue_t sleepFor(uint32_t ms) override;

View File

@ -68,11 +68,15 @@ void PeriodicTask::taskFunctionality() {
ReturnValue_t PeriodicTask::addComponent(object_id_t object) { ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object); ExecutableObjectIF* newObject = ObjectManager::instance()->get<ExecutableObjectIF>(object);
if (newObject == nullptr) { return addComponent(newObject);
}
ReturnValue_t PeriodicTask::addComponent(ExecutableObjectIF* object) {
if (object == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
objectList.push_back(newObject); objectList.push_back(object);
newObject->setTaskIF(this); object->setTaskIF(this);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -59,6 +59,14 @@ class PeriodicTask : public RTEMSTaskBase, public PeriodicTaskIF {
*/ */
ReturnValue_t addComponent(object_id_t object) override; 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; uint32_t getPeriodMs() const override;
ReturnValue_t sleepFor(uint32_t ms) override; ReturnValue_t sleepFor(uint32_t ms) override;

View File

@ -3,9 +3,12 @@
#include <fsfw/ipc/QueueFactory.h> #include <fsfw/ipc/QueueFactory.h>
#include <fsfw/power/PowerSwitchIF.h> #include <fsfw/power/PowerSwitchIF.h>
PowerSwitcherComponent::PowerSwitcherComponent(object_id_t objectId, PowerSwitchIF* pwrSwitcher, power::Switch_t pwrSwitch) PowerSwitcherComponent::PowerSwitcherComponent(object_id_t objectId, PowerSwitchIF *pwrSwitcher,
: SystemObject(objectId), switcher(pwrSwitcher, pwrSwitch), modeHelper(this), power::Switch_t pwrSwitch)
healthHelper(this, objectId) { : SystemObject(objectId),
switcher(pwrSwitcher, pwrSwitch),
modeHelper(this),
healthHelper(this, objectId) {
queue = QueueFactory::instance()->createMessageQueue(); queue = QueueFactory::instance()->createMessageQueue();
} }
@ -25,12 +28,12 @@ ReturnValue_t PowerSwitcherComponent::performOperation(uint8_t opCode) {
continue; continue;
} }
} }
if(switcher.active()) { if (switcher.active()) {
switcher.doStateMachine(); switcher.doStateMachine();
auto currState = switcher.getState(); auto currState = switcher.getState();
if (currState == PowerSwitcher::SWITCH_IS_OFF) { if (currState == PowerSwitcher::SWITCH_IS_OFF) {
setMode(MODE_OFF, 0); setMode(MODE_OFF, 0);
} else if(currState == PowerSwitcher::SWITCH_IS_ON) { } else if (currState == PowerSwitcher::SWITCH_IS_ON) {
setMode(MODE_ON, 0); setMode(MODE_ON, 0);
} }
} }
@ -39,19 +42,17 @@ ReturnValue_t PowerSwitcherComponent::performOperation(uint8_t opCode) {
ReturnValue_t PowerSwitcherComponent::initialize() { ReturnValue_t PowerSwitcherComponent::initialize() {
ReturnValue_t result = modeHelper.initialize(); ReturnValue_t result = modeHelper.initialize();
if(result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
result = healthHelper.initialize(); result = healthHelper.initialize();
if(result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
return SystemObject::initialize(); return SystemObject::initialize();
} }
MessageQueueId_t PowerSwitcherComponent::getCommandQueue() const { MessageQueueId_t PowerSwitcherComponent::getCommandQueue() const { return queue->getId(); }
return queue->getId();
}
void PowerSwitcherComponent::getMode(Mode_t *mode, Submode_t *submode) { void PowerSwitcherComponent::getMode(Mode_t *mode, Submode_t *submode) {
*mode = this->mode; *mode = this->mode;
@ -64,25 +65,25 @@ ReturnValue_t PowerSwitcherComponent::setHealth(HealthState health) {
} }
ReturnValue_t PowerSwitcherComponent::checkModeCommand(Mode_t mode, Submode_t submode, ReturnValue_t PowerSwitcherComponent::checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode) { uint32_t *msToReachTheMode) {
*msToReachTheMode = 5000; *msToReachTheMode = 5000;
if(mode != MODE_ON and mode != MODE_OFF) { if (mode != MODE_ON and mode != MODE_OFF) {
return TRANS_NOT_ALLOWED; return TRANS_NOT_ALLOWED;
} }
return RETURN_OK; return RETURN_OK;
} }
void PowerSwitcherComponent::startTransition(Mode_t mode, Submode_t submode) { void PowerSwitcherComponent::startTransition(Mode_t mode, Submode_t submode) {
if(mode == MODE_OFF) { if (mode == MODE_OFF) {
switcher.turnOff(true); switcher.turnOff(true);
switcher.doStateMachine(); switcher.doStateMachine();
if(switcher.getState() == PowerSwitcher::SWITCH_IS_OFF) { if (switcher.getState() == PowerSwitcher::SWITCH_IS_OFF) {
setMode(MODE_OFF, 0); setMode(MODE_OFF, 0);
} }
} else if (mode == MODE_ON) { } else if (mode == MODE_ON) {
switcher.turnOn(true); switcher.turnOn(true);
switcher.doStateMachine(); switcher.doStateMachine();
if(switcher.getState() == PowerSwitcher::SWITCH_IS_ON) { if (switcher.getState() == PowerSwitcher::SWITCH_IS_ON) {
setMode(MODE_ON, 0); setMode(MODE_ON, 0);
} }
} }
@ -103,6 +104,4 @@ void PowerSwitcherComponent::setMode(Mode_t newMode, Submode_t newSubmode) {
announceMode(false); announceMode(false);
} }
HasHealthIF::HealthState PowerSwitcherComponent::getHealth() { HasHealthIF::HealthState PowerSwitcherComponent::getHealth() { return healthHelper.getHealth(); }
return healthHelper.getHealth();
}

View File

@ -6,8 +6,8 @@
#include <fsfw/modes/HasModesIF.h> #include <fsfw/modes/HasModesIF.h>
#include <fsfw/modes/ModeHelper.h> #include <fsfw/modes/ModeHelper.h>
#include <fsfw/objectmanager/SystemObject.h> #include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/power/definitions.h>
#include <fsfw/power/PowerSwitcher.h> #include <fsfw/power/PowerSwitcher.h>
#include <fsfw/power/definitions.h>
#include <fsfw/tasks/ExecutableObjectIF.h> #include <fsfw/tasks/ExecutableObjectIF.h>
class PowerSwitchIF; class PowerSwitchIF;
@ -22,19 +22,17 @@ class PowerSwitchIF;
* Commanding this component to MODE_OFF will cause the switcher to turn the switch off while * Commanding this component to MODE_OFF will cause the switcher to turn the switch off while
* commanding in to MODE_ON will cause the switcher to turn the switch on. * commanding in to MODE_ON will cause the switcher to turn the switch on.
*/ */
class PowerSwitcherComponent: class PowerSwitcherComponent : public SystemObject,
public SystemObject, public HasReturnvaluesIF,
public HasReturnvaluesIF, public ExecutableObjectIF,
public ExecutableObjectIF, public HasModesIF,
public HasModesIF, public HasHealthIF {
public HasHealthIF { public:
public: PowerSwitcherComponent(object_id_t objectId, PowerSwitchIF *pwrSwitcher,
PowerSwitcherComponent(object_id_t objectId, PowerSwitchIF* pwrSwitcher, power::Switch_t pwrSwitch);
power::Switch_t pwrSwitch);
private: private:
MessageQueueIF *queue = nullptr;
MessageQueueIF* queue = nullptr;
PowerSwitcher switcher; PowerSwitcher switcher;
Mode_t mode = MODE_OFF; Mode_t mode = MODE_OFF;
@ -52,7 +50,7 @@ private:
MessageQueueId_t getCommandQueue() const override; MessageQueueId_t getCommandQueue() const override;
void getMode(Mode_t *mode, Submode_t *submode) override; void getMode(Mode_t *mode, Submode_t *submode) override;
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode) override; uint32_t *msToReachTheMode) override;
void startTransition(Mode_t mode, Submode_t submode) override; void startTransition(Mode_t mode, Submode_t submode) override;
void setToExternalControl() override; void setToExternalControl() override;
void announceMode(bool recursive) override; void announceMode(bool recursive) override;

View File

@ -26,21 +26,25 @@ class PeriodicTaskIF {
virtual ReturnValue_t startTask() = 0; virtual ReturnValue_t startTask() = 0;
/** /**
* Add a component (object) to a periodic task. The pointer to the * Add a component (object) to a periodic task.
* task can be set optionally
* @param object * @param object
* Add an object to the task. The most important case is to add an * Add an object to the task. The object needs to implement ExecutableObjectIF
* 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.
* @return * @return
*/ */
virtual ReturnValue_t addComponent(object_id_t object) { virtual ReturnValue_t addComponent(object_id_t object) {
return HasReturnvaluesIF::RETURN_FAILED; 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 ReturnValue_t sleepFor(uint32_t ms) = 0;
virtual uint32_t getPeriodMs() const = 0; virtual uint32_t getPeriodMs() const = 0;