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

This commit is contained in:
Robin Müller 2021-04-22 19:55:02 +02:00
commit 763347f203
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
8 changed files with 440 additions and 399 deletions

View File

@ -42,6 +42,13 @@
//! Specify whether a special mode store is used for Subsystem components. //! Specify whether a special mode store is used for Subsystem components.
#define FSFW_USE_MODESTORE 0 #define FSFW_USE_MODESTORE 0
//! Defines if the real time scheduler for linux should be used.
//! If set to 0, this will also disable priority settings for linux
//! as most systems will not allow to set nice values without privileges
//! For embedded linux system set this to 1.
//! If set to 1 the binary needs "cap_sys_nice=eip" privileges to run
#define FSFW_USE_REALTIME_FOR_LINUX 1
namespace fsfwconfig { namespace fsfwconfig {
//! Default timestamp size. The default timestamp will be an eight byte CDC //! Default timestamp size. The default timestamp will be an eight byte CDC
//! short timestamp. //! short timestamp.
@ -60,12 +67,6 @@ static constexpr uint8_t FSFW_CSB_FIFO_DEPTH = 6;
static constexpr size_t FSFW_PRINT_BUFFER_SIZE = 124; static constexpr size_t FSFW_PRINT_BUFFER_SIZE = 124;
//! Defines if the real time scheduler for linux should be used.
//! If set to 0, this will also disable priority settings for linux
//! as most systems will not allow to set nice values without privileges
//! For embedded linux system set this to 1.
//! If set to 1 the binary needs "cap_sys_nice=eip" privileges to run
#define FSFW_USE_REALTIME_FOR_LINUX 1
} }
#endif /* CONFIG_FSFWCONFIG_H_ */ #endif /* CONFIG_FSFWCONFIG_H_ */

View File

@ -24,6 +24,13 @@
* 1. check logic when active-> checkChildrenStateOn * 1. check logic when active-> checkChildrenStateOn
* 2. transition logic to change the mode -> commandChildren * 2. transition logic to change the mode -> commandChildren
* *
* Important:
*
* The implementation must call registerChild(object_id_t child)
* for all commanded children during initialization.
* The implementation must call the initialization function of the base class.
* (This will call the function in SubsystemBase)
*
*/ */
class AssemblyBase: public SubsystemBase { class AssemblyBase: public SubsystemBase {
public: public:
@ -41,9 +48,6 @@ public:
virtual ~AssemblyBase(); virtual ~AssemblyBase();
protected: protected:
// SHOULDDO: Change that OVERWRITE_HEALTH may be returned
// (or return internalState directly?)
/** /**
* Command children to reach [mode,submode] combination * Command children to reach [mode,submode] combination
* Can be done by setting #commandsOutstanding correctly, * Can be done by setting #commandsOutstanding correctly,
@ -68,6 +72,18 @@ protected:
virtual ReturnValue_t checkChildrenStateOn(Mode_t wantedMode, virtual ReturnValue_t checkChildrenStateOn(Mode_t wantedMode,
Submode_t wantedSubmode) = 0; Submode_t wantedSubmode) = 0;
/**
* Check whether a combination of mode and submode is valid.
*
* Ground Controller like precise return values from HasModesIF.
* So, please return any of them.
*
* @param mode The targeted mode
* @param submode The targeted submmode
* @return Any information why this combination is invalid from HasModesIF
* like HasModesIF::INVALID_SUBMODE.
* On success return HasReturnvaluesIF::RETURN_OK
*/
virtual ReturnValue_t isModeCombinationValid(Mode_t mode, virtual ReturnValue_t isModeCombinationValid(Mode_t mode,
Submode_t submode) = 0; Submode_t submode) = 0;

View File

@ -223,8 +223,16 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
status = pthread_create(&thread,&attributes,fnc_,arg_); status = pthread_create(&thread,&attributes,fnc_,arg_);
if(status != 0){ if(status != 0){
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Posix Thread create failed with: " << sif::error << "PosixThread::createTask: Failed with: " <<
strerror(status) << std::endl; strerror(status) << std::endl;
sif::error << "For FSFW_USE_REALTIME_FOR_LINUX == 1 make sure to call " <<
"\"all sudo setcap 'cap_sys_nice=eip'\" on the application or set "
"/etc/security/limit.conf" << std::endl;
#else
sif::printError("PosixThread::createTask: Create failed with: %s\n", strerror(status));
sif::printError("For FSFW_USE_REALTIME_FOR_LINUX == 1 make sure to call "
"\"all sudo setcap 'cap_sys_nice=eip'\" on the application or set "
"/etc/security/limit.conf\n");
#endif #endif
} }

View File

@ -5,8 +5,7 @@
SubsystemBase::SubsystemBase(object_id_t setObjectId, object_id_t parent, SubsystemBase::SubsystemBase(object_id_t setObjectId, object_id_t parent,
Mode_t initialMode, uint16_t commandQueueDepth) : Mode_t initialMode, uint16_t commandQueueDepth) :
SystemObject(setObjectId), mode(initialMode), submode(SUBMODE_NONE), SystemObject(setObjectId), mode(initialMode),
childrenChangedMode(false),
commandQueue(QueueFactory::instance()->createMessageQueue( commandQueue(QueueFactory::instance()->createMessageQueue(
commandQueueDepth, CommandMessage::MAX_MESSAGE_SIZE)), commandQueueDepth, CommandMessage::MAX_MESSAGE_SIZE)),
healthHelper(this, setObjectId), modeHelper(this), parentId(parent) { healthHelper(this, setObjectId), modeHelper(this), parentId(parent) {
@ -167,16 +166,16 @@ MessageQueueId_t SubsystemBase::getCommandQueue() const {
} }
ReturnValue_t SubsystemBase::initialize() { ReturnValue_t SubsystemBase::initialize() {
MessageQueueId_t parentQueue = 0; MessageQueueId_t parentQueue = MessageQueueIF::NO_QUEUE;
ReturnValue_t result = SystemObject::initialize(); ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
if (parentId != 0) { if (parentId != objects::NO_OBJECT) {
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId); SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
if (parent == NULL) { if (parent == nullptr) {
return RETURN_FAILED; return RETURN_FAILED;
} }
parentQueue = parent->getCommandQueue(); parentQueue = parent->getCommandQueue();

View File

@ -37,6 +37,17 @@ public:
virtual MessageQueueId_t getCommandQueue() const override; virtual MessageQueueId_t getCommandQueue() const override;
/**
* Function to register the child objects.
* Performs a checks if the child does implement HasHealthIF and/or HasModesIF
*
* Also adds them to the internal childrenMap.
*
* @param objectId
* @return RETURN_OK if successful
* CHILD_DOESNT_HAVE_MODES if Child is no HasHealthIF and no HasModesIF
* COULD_NOT_INSERT_CHILD If the Child could not be added to the ChildrenMap
*/
ReturnValue_t registerChild(object_id_t objectId); ReturnValue_t registerChild(object_id_t objectId);
virtual ReturnValue_t initialize() override; virtual ReturnValue_t initialize() override;
@ -56,9 +67,9 @@ protected:
Mode_t mode; Mode_t mode;
Submode_t submode; Submode_t submode = SUBMODE_NONE;
bool childrenChangedMode; bool childrenChangedMode = false;
/** /**
* Always check this against <=0, so you are robust against too many replies * Always check this against <=0, so you are robust against too many replies

View File

@ -1,353 +1,352 @@
#include "../devicehandlers/DeviceHandlerFailureIsolation.h"
#include "Heater.h" #include "Heater.h"
#include "../devicehandlers/DeviceHandlerFailureIsolation.h"
#include "../power/Fuse.h" #include "../power/Fuse.h"
#include "../ipc/QueueFactory.h" #include "../ipc/QueueFactory.h"
Heater::Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1) : Heater::Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1) :
HealthDevice(objectId, 0), internalState(STATE_OFF), powerSwitcher( HealthDevice(objectId, 0), internalState(STATE_OFF), switch0(switch0), switch1(switch1),
NULL), pcduQueueId(0), switch0(switch0), switch1(switch1), wasOn( heaterOnCountdown(10800000)/*about two orbits*/,
false), timedOut(false), reactedToBeingFaulty(false), passive( parameterHelper(this) {
false), eventQueue(NULL), heaterOnCountdown(10800000)/*about two orbits*/, parameterHelper( eventQueue = QueueFactory::instance()->createMessageQueue();
this), lastAction(CLEAR) {
eventQueue = QueueFactory::instance()->createMessageQueue();
} }
Heater::~Heater() { Heater::~Heater() {
QueueFactory::instance()->deleteMessageQueue(eventQueue); QueueFactory::instance()->deleteMessageQueue(eventQueue);
} }
ReturnValue_t Heater::set() { ReturnValue_t Heater::set() {
passive = false; passive = false;
//wait for clear before doing anything //wait for clear before doing anything
if (internalState == STATE_WAIT) { if (internalState == STATE_WAIT) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
if (healthHelper.healthTable->isHealthy(getObjectId())) { if (healthHelper.healthTable->isHealthy(getObjectId())) {
doAction(SET); doAction(SET);
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)){ if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)){
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} else { } else {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
} else { } else {
if (healthHelper.healthTable->isFaulty(getObjectId())) { if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (!reactedToBeingFaulty) { if (!reactedToBeingFaulty) {
reactedToBeingFaulty = true; reactedToBeingFaulty = true;
doAction(CLEAR); doAction(CLEAR);
} }
} }
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
void Heater::clear(bool passive) { void Heater::clear(bool passive) {
this->passive = passive; this->passive = passive;
//Force switching off //Force switching off
if (internalState == STATE_WAIT) { if (internalState == STATE_WAIT) {
internalState = STATE_ON; internalState = STATE_ON;
} }
if (healthHelper.healthTable->isHealthy(getObjectId())) { if (healthHelper.healthTable->isHealthy(getObjectId())) {
doAction(CLEAR); doAction(CLEAR);
} else if (healthHelper.healthTable->isFaulty(getObjectId())) { } else if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (!reactedToBeingFaulty) { if (!reactedToBeingFaulty) {
reactedToBeingFaulty = true; reactedToBeingFaulty = true;
doAction(CLEAR); doAction(CLEAR);
} }
} }
} }
void Heater::doAction(Action action) { void Heater::doAction(Action action) {
//only act if we are not in the right state or in a transition //only act if we are not in the right state or in a transition
if (action == SET) { if (action == SET) {
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE) if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)
|| (internalState == STATE_EXTERNAL_CONTROL)) { || (internalState == STATE_EXTERNAL_CONTROL)) {
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs()); switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
internalState = STATE_WAIT_FOR_SWITCHES_ON; internalState = STATE_WAIT_FOR_SWITCHES_ON;
powerSwitcher->sendSwitchCommand(switch0, PowerSwitchIF::SWITCH_ON); powerSwitcher->sendSwitchCommand(switch0, PowerSwitchIF::SWITCH_ON);
powerSwitcher->sendSwitchCommand(switch1, PowerSwitchIF::SWITCH_ON); powerSwitcher->sendSwitchCommand(switch1, PowerSwitchIF::SWITCH_ON);
} }
} else { //clear } else { //clear
if ((internalState == STATE_ON) || (internalState == STATE_FAULTY) if ((internalState == STATE_ON) || (internalState == STATE_FAULTY)
|| (internalState == STATE_EXTERNAL_CONTROL)) { || (internalState == STATE_EXTERNAL_CONTROL)) {
internalState = STATE_WAIT_FOR_SWITCHES_OFF; internalState = STATE_WAIT_FOR_SWITCHES_OFF;
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs()); switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
powerSwitcher->sendSwitchCommand(switch0, powerSwitcher->sendSwitchCommand(switch0,
PowerSwitchIF::SWITCH_OFF); PowerSwitchIF::SWITCH_OFF);
powerSwitcher->sendSwitchCommand(switch1, powerSwitcher->sendSwitchCommand(switch1,
PowerSwitchIF::SWITCH_OFF); PowerSwitchIF::SWITCH_OFF);
} }
} }
} }
void Heater::setPowerSwitcher(PowerSwitchIF* powerSwitch) { void Heater::setPowerSwitcher(PowerSwitchIF* powerSwitch) {
this->powerSwitcher = powerSwitch; this->powerSwitcher = powerSwitch;
} }
ReturnValue_t Heater::performOperation(uint8_t opCode) { ReturnValue_t Heater::performOperation(uint8_t opCode) {
handleQueue(); handleQueue();
handleEventQueue(); handleEventQueue();
if (!healthHelper.healthTable->isFaulty(getObjectId())) { if (!healthHelper.healthTable->isFaulty(getObjectId())) {
reactedToBeingFaulty = false; reactedToBeingFaulty = false;
} }
switch (internalState) { switch (internalState) {
case STATE_ON: case STATE_ON:
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_OFF) if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_OFF)
|| (powerSwitcher->getSwitchState(switch1) || (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_OFF)) { == PowerSwitchIF::SWITCH_OFF)) {
//switch went off on its own //switch went off on its own
//trigger event. FDIR can confirm if it is caused by MniOps and decide on the action //trigger event. FDIR can confirm if it is caused by MniOps and decide on the action
//do not trigger FD events when under external control //do not trigger FD events when under external control
if (healthHelper.getHealth() != EXTERNAL_CONTROL) { if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
triggerEvent(PowerSwitchIF::SWITCH_WENT_OFF); triggerEvent(PowerSwitchIF::SWITCH_WENT_OFF);
} else { } else {
internalState = STATE_EXTERNAL_CONTROL; internalState = STATE_EXTERNAL_CONTROL;
} }
} }
break; break;
case STATE_OFF: case STATE_OFF:
//check if heater is on, ie both switches are on //check if heater is on, ie both switches are on
//if so, just command it to off, to resolve the situation or force a switch stayed on event //if so, just command it to off, to resolve the situation or force a switch stayed on event
//But, only do anything if not already faulty (state off is the stable point for being faulty) //But, only do anything if not already faulty (state off is the stable point for being faulty)
if ((!healthHelper.healthTable->isFaulty(getObjectId())) if ((!healthHelper.healthTable->isFaulty(getObjectId()))
&& (powerSwitcher->getSwitchState(switch0) && (powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_ON) == PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1) && (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) { == PowerSwitchIF::SWITCH_ON)) {
//do not trigger FD events when under external control //do not trigger FD events when under external control
if (healthHelper.getHealth() != EXTERNAL_CONTROL) { if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
internalState = STATE_WAIT_FOR_SWITCHES_OFF; internalState = STATE_WAIT_FOR_SWITCHES_OFF;
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs()); switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
powerSwitcher->sendSwitchCommand(switch0, powerSwitcher->sendSwitchCommand(switch0,
PowerSwitchIF::SWITCH_OFF); PowerSwitchIF::SWITCH_OFF);
powerSwitcher->sendSwitchCommand(switch1, powerSwitcher->sendSwitchCommand(switch1,
PowerSwitchIF::SWITCH_OFF); PowerSwitchIF::SWITCH_OFF);
} else { } else {
internalState = STATE_EXTERNAL_CONTROL; internalState = STATE_EXTERNAL_CONTROL;
} }
} }
break; break;
case STATE_PASSIVE: case STATE_PASSIVE:
break; break;
case STATE_WAIT_FOR_SWITCHES_ON: case STATE_WAIT_FOR_SWITCHES_ON:
if (switchCountdown.hasTimedOut()) { if (switchCountdown.hasTimedOut()) {
if ((powerSwitcher->getSwitchState(switch0) if ((powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_OFF) == PowerSwitchIF::SWITCH_OFF)
|| (powerSwitcher->getSwitchState(switch1) || (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_OFF)) { == PowerSwitchIF::SWITCH_OFF)) {
triggerEvent(HEATER_STAYED_OFF); triggerEvent(HEATER_STAYED_OFF);
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
} else { } else {
triggerEvent(HEATER_ON); triggerEvent(HEATER_ON);
internalState = STATE_ON; internalState = STATE_ON;
} }
} }
break; break;
case STATE_WAIT_FOR_SWITCHES_OFF: case STATE_WAIT_FOR_SWITCHES_OFF:
if (switchCountdown.hasTimedOut()) { if (switchCountdown.hasTimedOut()) {
//only check for both being on (ie heater still on) //only check for both being on (ie heater still on)
if ((powerSwitcher->getSwitchState(switch0) if ((powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_ON) == PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1) && (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) { == PowerSwitchIF::SWITCH_ON)) {
if (healthHelper.healthTable->isFaulty(getObjectId())) { if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (passive) { if (passive) {
internalState = STATE_PASSIVE; internalState = STATE_PASSIVE;
} else { } else {
internalState = STATE_OFF; //just accept it internalState = STATE_OFF; //just accept it
} }
triggerEvent(HEATER_ON); //but throw an event to make it more visible triggerEvent(HEATER_ON); //but throw an event to make it more visible
break; break;
} }
triggerEvent(HEATER_STAYED_ON); triggerEvent(HEATER_STAYED_ON);
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
} else { } else {
triggerEvent(HEATER_OFF); triggerEvent(HEATER_OFF);
if (passive) { if (passive) {
internalState = STATE_PASSIVE; internalState = STATE_PASSIVE;
} else { } else {
internalState = STATE_OFF; internalState = STATE_OFF;
} }
} }
} }
break; break;
default: default:
break; break;
} }
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_ON) if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1) && (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) { == PowerSwitchIF::SWITCH_ON)) {
if (wasOn) { if (wasOn) {
if (heaterOnCountdown.hasTimedOut()) { if (heaterOnCountdown.hasTimedOut()) {
//SHOULDDO this means if a heater fails in single mode, the timeout will start again //SHOULDDO this means if a heater fails in single mode, the timeout will start again
//I am not sure if this is a bug, but atm I have no idea how to fix this and think //I am not sure if this is a bug, but atm I have no idea how to fix this and think
//it will be ok. whatcouldpossiblygowrong™ //it will be ok. whatcouldpossiblygowrong™
if (!timedOut) { if (!timedOut) {
triggerEvent(HEATER_TIMEOUT); triggerEvent(HEATER_TIMEOUT);
timedOut = true; timedOut = true;
} }
} }
} else { } else {
wasOn = true; wasOn = true;
heaterOnCountdown.resetTimer(); heaterOnCountdown.resetTimer();
timedOut = false; timedOut = false;
} }
} else { } else {
wasOn = false; wasOn = false;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void Heater::setSwitch(uint8_t number, ReturnValue_t state, void Heater::setSwitch(uint8_t number, ReturnValue_t state,
uint32_t* uptimeOfSwitching) { uint32_t* uptimeOfSwitching) {
if (powerSwitcher == NULL) { if (powerSwitcher == NULL) {
return; return;
} }
if (powerSwitcher->getSwitchState(number) == state) { if (powerSwitcher->getSwitchState(number) == state) {
*uptimeOfSwitching = INVALID_UPTIME; *uptimeOfSwitching = INVALID_UPTIME;
} else { } else {
if ((*uptimeOfSwitching == INVALID_UPTIME)) { if ((*uptimeOfSwitching == INVALID_UPTIME)) {
powerSwitcher->sendSwitchCommand(number, state); powerSwitcher->sendSwitchCommand(number, state);
Clock::getUptime(uptimeOfSwitching); Clock::getUptime(uptimeOfSwitching);
} else { } else {
uint32_t currentUptime; uint32_t currentUptime;
Clock::getUptime(&currentUptime); Clock::getUptime(&currentUptime);
if (currentUptime - *uptimeOfSwitching if (currentUptime - *uptimeOfSwitching
> powerSwitcher->getSwitchDelayMs()) { > powerSwitcher->getSwitchDelayMs()) {
*uptimeOfSwitching = INVALID_UPTIME; *uptimeOfSwitching = INVALID_UPTIME;
if (healthHelper.healthTable->isHealthy(getObjectId())) { if (healthHelper.healthTable->isHealthy(getObjectId())) {
if (state == PowerSwitchIF::SWITCH_ON) { if (state == PowerSwitchIF::SWITCH_ON) {
triggerEvent(HEATER_STAYED_OFF); triggerEvent(HEATER_STAYED_OFF);
} else { } else {
triggerEvent(HEATER_STAYED_ON); triggerEvent(HEATER_STAYED_ON);
} }
} }
//SHOULDDO MiniOps during switch timeout leads to a faulty switch }
} }
} }
}
} }
MessageQueueId_t Heater::getCommandQueue() const { MessageQueueId_t Heater::getCommandQueue() const {
return commandQueue->getId(); return commandQueue->getId();
} }
ReturnValue_t Heater::initialize() { ReturnValue_t Heater::initialize() {
ReturnValue_t result = SystemObject::initialize(); ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
EventManagerIF* manager = objectManager->get<EventManagerIF>( EventManagerIF* manager = objectManager->get<EventManagerIF>(
objects::EVENT_MANAGER); objects::EVENT_MANAGER);
if (manager == NULL) { if (manager == NULL) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
result = manager->registerListener(eventQueue->getId()); result = manager->registerListener(eventQueue->getId());
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
ConfirmsFailuresIF* pcdu = objectManager->get<ConfirmsFailuresIF>( ConfirmsFailuresIF* pcdu = objectManager->get<ConfirmsFailuresIF>(
DeviceHandlerFailureIsolation::powerConfirmationId); DeviceHandlerFailureIsolation::powerConfirmationId);
if (pcdu == NULL) { if (pcdu == NULL) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
pcduQueueId = pcdu->getEventReceptionQueue(); pcduQueueId = pcdu->getEventReceptionQueue();
result = manager->subscribeToAllEventsFrom(eventQueue->getId(), result = manager->subscribeToAllEventsFrom(eventQueue->getId(),
getObjectId()); getObjectId());
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
result = parameterHelper.initialize(); result = parameterHelper.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 HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void Heater::handleQueue() { void Heater::handleQueue() {
CommandMessage command; CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command); ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
result = healthHelper.handleHealthCommand(&command); result = healthHelper.handleHealthCommand(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
return;
}
result = parameterHelper.handleParameterMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
return; return;
} }
} result = parameterHelper.handleParameterMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
return;
}
}
} }
ReturnValue_t Heater::getParameter(uint8_t domainId, uint8_t uniqueId, ReturnValue_t Heater::getParameter(uint8_t domainId, uint8_t uniqueId,
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
uint16_t startAtIndex) { uint16_t startAtIndex) {
if (domainId != DOMAIN_ID_BASE) { if (domainId != DOMAIN_ID_BASE) {
return INVALID_DOMAIN_ID; return INVALID_DOMAIN_ID;
} }
switch (uniqueId) { switch (uniqueId) {
case 0: case 0:
parameterWrapper->set(heaterOnCountdown.timeout); parameterWrapper->set(heaterOnCountdown.timeout);
break; break;
default: default:
return INVALID_IDENTIFIER_ID; return INVALID_IDENTIFIER_ID;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void Heater::handleEventQueue() { void Heater::handleEventQueue() {
EventMessage event; EventMessage event;
for (ReturnValue_t result = eventQueue->receiveMessage(&event); for (ReturnValue_t result = eventQueue->receiveMessage(&event);
result == HasReturnvaluesIF::RETURN_OK; result == HasReturnvaluesIF::RETURN_OK;
result = eventQueue->receiveMessage(&event)) { result = eventQueue->receiveMessage(&event)) {
switch (event.getMessageId()) { switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE: case EventMessage::EVENT_MESSAGE:
switch (event.getEvent()) { switch (event.getEvent()) {
case Fuse::FUSE_WENT_OFF: case Fuse::FUSE_WENT_OFF:
case HEATER_STAYED_OFF: case HEATER_STAYED_OFF:
case HEATER_STAYED_ON://Setting it faulty does not help, but we need to reach a stable state and can check for being faulty before throwing this event again. // HEATER_STAYED_ON is a setting if faulty does not help, but we need to reach a stable state and can check
if (healthHelper.healthTable->isCommandable(getObjectId())) { // for being faulty before throwing this event again.
healthHelper.setHealth(HasHealthIF::FAULTY); case HEATER_STAYED_ON:
internalState = STATE_FAULTY; if (healthHelper.healthTable->isCommandable(getObjectId())) {
} healthHelper.setHealth(HasHealthIF::FAULTY);
break; internalState = STATE_FAULTY;
case PowerSwitchIF::SWITCH_WENT_OFF: }
internalState = STATE_WAIT; break;
event.setMessageId(EventMessage::CONFIRMATION_REQUEST); case PowerSwitchIF::SWITCH_WENT_OFF:
if (pcduQueueId != 0) { internalState = STATE_WAIT;
eventQueue->sendMessage(pcduQueueId, &event); event.setMessageId(EventMessage::CONFIRMATION_REQUEST);
} else { if (pcduQueueId != 0) {
healthHelper.setHealth(HasHealthIF::FAULTY); eventQueue->sendMessage(pcduQueueId, &event);
internalState = STATE_FAULTY; } else {
} healthHelper.setHealth(HasHealthIF::FAULTY);
break; internalState = STATE_FAULTY;
default: }
return; break;
} default:
break; return;
case EventMessage::YOUR_FAULT: }
healthHelper.setHealth(HasHealthIF::FAULTY); break;
internalState = STATE_FAULTY; case EventMessage::YOUR_FAULT:
break; healthHelper.setHealth(HasHealthIF::FAULTY);
case EventMessage::MY_FAULT: internalState = STATE_FAULTY;
//do nothing, we are already in STATE_WAIT and wait for a clear() break;
break; case EventMessage::MY_FAULT:
default: //do nothing, we are already in STATE_WAIT and wait for a clear()
return; break;
} default:
} return;
}
}
} }

View File

@ -1,90 +1,93 @@
#ifndef FRAMEWORK_THERMAL_HEATER_H_ #ifndef FSFW_THERMAL_HEATER_H_
#define FRAMEWORK_THERMAL_HEATER_H_ #define FSFW_THERMAL_HEATER_H_
#include "../devicehandlers/HealthDevice.h" #include "../devicehandlers/HealthDevice.h"
#include "../parameters/ParameterHelper.h" #include "../parameters/ParameterHelper.h"
#include "../power/PowerSwitchIF.h" #include "../power/PowerSwitchIF.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include "../timemanager/Countdown.h" #include "../timemanager/Countdown.h"
#include <stdint.h> #include <cstdint>
//class RedundantHeater;
class Heater: public HealthDevice, public ReceivesParameterMessagesIF { class Heater: public HealthDevice, public ReceivesParameterMessagesIF {
friend class RedundantHeater; friend class RedundantHeater;
public: public:
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER;
static const Event HEATER_ON = MAKE_EVENT(0, severity::INFO); static const Event HEATER_ON = MAKE_EVENT(0, severity::INFO);
static const Event HEATER_OFF = MAKE_EVENT(1, severity::INFO); static const Event HEATER_OFF = MAKE_EVENT(1, severity::INFO);
static const Event HEATER_TIMEOUT = MAKE_EVENT(2, severity::LOW); static const Event HEATER_TIMEOUT = MAKE_EVENT(2, severity::LOW);
static const Event HEATER_STAYED_ON = MAKE_EVENT(3, severity::LOW); static const Event HEATER_STAYED_ON = MAKE_EVENT(3, severity::LOW);
static const Event HEATER_STAYED_OFF = MAKE_EVENT(4, severity::LOW); static const Event HEATER_STAYED_OFF = MAKE_EVENT(4, severity::LOW);
Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1); Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1);
virtual ~Heater(); virtual ~Heater();
ReturnValue_t performOperation(uint8_t opCode); ReturnValue_t performOperation(uint8_t opCode);
ReturnValue_t initialize(); ReturnValue_t initialize();
ReturnValue_t set(); ReturnValue_t set();
void clear(bool passive); void clear(bool passive);
void setPowerSwitcher(PowerSwitchIF *powerSwitch); void setPowerSwitcher(PowerSwitchIF *powerSwitch);
MessageQueueId_t getCommandQueue() const; MessageQueueId_t getCommandQueue() const;
ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
ParameterWrapper *parameterWrapper, ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex); const ParameterWrapper *newValues, uint16_t startAtIndex);
protected: protected:
static const uint32_t INVALID_UPTIME = 0; static const uint32_t INVALID_UPTIME = 0;
enum InternalState { enum InternalState {
STATE_ON, STATE_ON,
STATE_OFF, STATE_OFF,
STATE_PASSIVE, STATE_PASSIVE,
STATE_WAIT_FOR_SWITCHES_ON, STATE_WAIT_FOR_SWITCHES_ON,
STATE_WAIT_FOR_SWITCHES_OFF, STATE_WAIT_FOR_SWITCHES_OFF,
STATE_WAIT_FOR_FDIR, //used to avoid doing anything until fdir decided what to do STATE_WAIT_FOR_FDIR, // Used to avoid doing anything until fdir decided what to do
STATE_FAULTY, STATE_FAULTY,
STATE_WAIT, //used when waiting for system to recover from miniops STATE_WAIT, // Used when waiting for system to recover from miniops
STATE_EXTERNAL_CONTROL //entered when under external control and a fdir reaction would be triggered. This is useful when leaving external control into an unknown state // Entered when under external control and a fdir reaction would be triggered.
//if no fdir reaction is triggered under external control the state is still ok and no need for any special treatment is needed // This is useful when leaving external control into an unknown state
} internalState; STATE_EXTERNAL_CONTROL
// If no fdir reaction is triggered under external control the state is still ok and
// no need for any special treatment is needed
} internalState;
PowerSwitchIF *powerSwitcher; PowerSwitchIF *powerSwitcher = nullptr;
MessageQueueId_t pcduQueueId; MessageQueueId_t pcduQueueId = MessageQueueIF::NO_QUEUE;
uint8_t switch0; uint8_t switch0;
uint8_t switch1; uint8_t switch1;
bool wasOn; bool wasOn = false;
bool timedOut; bool timedOut = false;
bool reactedToBeingFaulty; bool reactedToBeingFaulty = false;
bool passive; bool passive = false;
MessageQueueIF* eventQueue; MessageQueueIF* eventQueue = nullptr;
Countdown heaterOnCountdown; Countdown heaterOnCountdown;
Countdown switchCountdown; Countdown switchCountdown;
ParameterHelper parameterHelper; ParameterHelper parameterHelper;
enum Action { enum Action {
SET, CLEAR SET, CLEAR
} lastAction; } lastAction = CLEAR;
void doAction(Action action); void doAction(Action action);
void setSwitch(uint8_t number, ReturnValue_t state, void setSwitch(uint8_t number, ReturnValue_t state,
uint32_t *upTimeOfSwitching); uint32_t *upTimeOfSwitching);
void handleQueue(); void handleQueue();
void handleEventQueue(); void handleEventQueue();
}; };
#endif /* FRAMEWORK_THERMAL_HEATER_H_ */ #endif /* FSFW_THERMAL_HEATER_H_ */

View File

@ -1,5 +1,5 @@
#ifndef TEMPERATURESENSOR_H_ #ifndef FSFW_THERMAL_TEMPERATURESENSOR_H_
#define TEMPERATURESENSOR_H_ #define FSFW_THERMAL_TEMPERATURESENSOR_H_
#include "tcsDefinitions.h" #include "tcsDefinitions.h"
#include "AbstractTemperatureSensor.h" #include "AbstractTemperatureSensor.h"
@ -60,23 +60,22 @@ public:
/** /**
* Instantiate Temperature Sensor Object. * Instantiate Temperature Sensor Object.
* @param setObjectid objectId of the sensor object * @param setObjectid objectId of the sensor object
* @param inputValue Pointer to input value which is converted to a temperature * @param inputTemperature Pointer to a raw input value which is converted to an floating
* @param variableGpid Global Pool ID of the output value * point C output temperature
* @param inputVariable Input variable handle * @param outputGpid Global Pool ID of the output value
* @param vectorIndex Vector Index for the sensor monitor * @param vectorIndex Vector Index for the sensor monitor
* @param parameters Calculation parameters, temperature limits, gradient limit * @param parameters Calculation parameters, temperature limits, gradient limit
* @param outputSet Output dataset for the output temperature to fetch it with read() * @param outputSet Output dataset for the output temperature to fetch it with read()
* @param thermalModule respective thermal module, if it has one * @param thermalModule Respective thermal module, if it has one
*/ */
TemperatureSensor(object_id_t setObjectid, TemperatureSensor(object_id_t setObjectid,lp_var_t<limitType>* inputTemperature,
inputType *inputValue, gp_id_t variableGpid, PoolVariableIF* inputVariable, gp_id_t outputGpid, uint8_t vectorIndex, Parameters parameters = {0, 0, 0, 0, 0, 0},
uint8_t vectorIndex, Parameters parameters = {0, 0, 0, 0, 0, 0}, LocalPoolDataSetBase *outputSet = nullptr, ThermalModuleIF *thermalModule = nullptr) :
LocalPoolDataSetBase *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) :
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters), AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
inputValue(inputValue), poolVariable(inputVariable), inputTemperature(inputTemperature),
outputTemperature(variableGpid, outputSet, PoolVariableIF::VAR_WRITE), outputTemperature(outputGpid, outputSet, PoolVariableIF::VAR_WRITE),
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR, poolVariable, sensorMonitor(setObjectid, DOMAIN_ID_SENSOR, outputGpid,
DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, parameters.upperLimit, DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, parameters.upperLimit,
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH), TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH),
oldTemperature(20), uptimeOfOldTemperature({ thermal::INVALID_TEMPERATURE, 0 }) { oldTemperature(20), uptimeOfOldTemperature({ thermal::INVALID_TEMPERATURE, 0 }) {
@ -110,10 +109,7 @@ protected:
UsedParameters parameters; UsedParameters parameters;
inputType* inputValue; lp_var_t<limitType>* inputTemperature;
PoolVariableIF* poolVariable;
lp_var_t<float> outputTemperature; lp_var_t<float> outputTemperature;
LimitMonitor<limitType> sensorMonitor; LimitMonitor<limitType> sensorMonitor;
@ -122,22 +118,27 @@ protected:
timeval uptimeOfOldTemperature; timeval uptimeOfOldTemperature;
void doChildOperation() { void doChildOperation() {
if ((not poolVariable->isValid()) or ReturnValue_t result = inputTemperature->read(MutexIF::TimeoutType::WAITING, 20);
if(result != HasReturnvaluesIF::RETURN_OK) {
return;
}
if ((not inputTemperature->isValid()) or
(not healthHelper.healthTable->isHealthy(getObjectId()))) { (not healthHelper.healthTable->isHealthy(getObjectId()))) {
setInvalid(); setInvalid();
return; return;
} }
outputTemperature = calculateOutputTemperature(*inputValue); outputTemperature = calculateOutputTemperature(inputTemperature->value);
outputTemperature.setValid(PoolVariableIF::VALID); outputTemperature.setValid(PoolVariableIF::VALID);
timeval uptime; timeval uptime;
Clock::getUptime(&uptime); Clock::getUptime(&uptime);
if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) { if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) {
//In theory, we could use an AbsValueMonitor to monitor the gradient. // In theory, we could use an AbsValueMonitor to monitor the gradient.
//But this would require storing the maxGradient in DP and quite some overhead. // But this would require storing the maxGradient in DP and quite some overhead.
//The concept of delta limits is a bit strange anyway. // The concept of delta limits is a bit strange anyway.
float deltaTime; float deltaTime;
float deltaTemp; float deltaTemp;
@ -150,11 +151,11 @@ protected:
} }
if (parameters.gradient < deltaTemp / deltaTime) { if (parameters.gradient < deltaTemp / deltaTime) {
triggerEvent(TEMP_SENSOR_GRADIENT); triggerEvent(TEMP_SENSOR_GRADIENT);
//Don't set invalid, as we did not recognize it as invalid with full authority, let FDIR handle it // Don't set invalid, as we did not recognize it as invalid with full authority,
// let FDIR handle it
} }
} }
//Check is done against raw limits. SHOULDDO: Why? Using C would be more easy to handle.
sensorMonitor.doCheck(outputTemperature.value); sensorMonitor.doCheck(outputTemperature.value);
if (sensorMonitor.isOutOfLimits()) { if (sensorMonitor.isOutOfLimits()) {
@ -181,7 +182,10 @@ public:
static const uint16_t ADDRESS_C = 2; static const uint16_t ADDRESS_C = 2;
static const uint16_t ADDRESS_GRADIENT = 3; static const uint16_t ADDRESS_GRADIENT = 3;
static const uint16_t DEFAULT_CONFIRMATION_COUNT = 1; //!< Changed due to issue with later temperature checking even tough the sensor monitor was confirming already (Was 10 before with comment = Correlates to a 10s confirmation time. Chosen rather large, should not be so bad for components and helps survive glitches.) //! Changed due to issue with later temperature checking even tough the sensor monitor was
//! confirming already (Was 10 before with comment = Correlates to a 10s confirmation time.
//! Chosen rather large, should not be so bad for components and helps survive glitches.)
static const uint16_t DEFAULT_CONFIRMATION_COUNT = 1;
static const uint8_t DOMAIN_ID_SENSOR = 1; static const uint8_t DOMAIN_ID_SENSOR = 1;
@ -221,4 +225,4 @@ public:
}; };
#endif /* TEMPERATURESENSOR_H_ */ #endif /* FSFW_THERMAL_TEMPERATURESENSOR_H_ */