renormalized line endings
This commit is contained in:
@ -1,70 +1,70 @@
|
||||
#include "AbstractTemperatureSensor.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
|
||||
AbstractTemperatureSensor::AbstractTemperatureSensor(object_id_t setObjectid,
|
||||
ThermalModuleIF *thermalModule) :
|
||||
SystemObject(setObjectid), commandQueue(NULL), healthHelper(this,
|
||||
setObjectid), parameterHelper(this) {
|
||||
if (thermalModule != NULL) {
|
||||
thermalModule->registerSensor(this);
|
||||
}
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue();
|
||||
}
|
||||
|
||||
AbstractTemperatureSensor::~AbstractTemperatureSensor() {
|
||||
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
||||
}
|
||||
|
||||
MessageQueueId_t AbstractTemperatureSensor::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t AbstractTemperatureSensor::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = healthHelper.initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = parameterHelper.initialize();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t AbstractTemperatureSensor::performOperation(uint8_t opCode) {
|
||||
handleCommandQueue();
|
||||
doChildOperation();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t AbstractTemperatureSensor::performHealthOp() {
|
||||
handleCommandQueue();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void AbstractTemperatureSensor::handleCommandQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
result = parameterHelper.handleParameterMessage(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
command.setToUnknownCommand();
|
||||
commandQueue->reply(&command);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t AbstractTemperatureSensor::setHealth(HealthState health) {
|
||||
healthHelper.setHealth(health);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
HasHealthIF::HealthState AbstractTemperatureSensor::getHealth() {
|
||||
return healthHelper.getHealth();
|
||||
}
|
||||
#include "AbstractTemperatureSensor.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
|
||||
AbstractTemperatureSensor::AbstractTemperatureSensor(object_id_t setObjectid,
|
||||
ThermalModuleIF *thermalModule) :
|
||||
SystemObject(setObjectid), commandQueue(NULL), healthHelper(this,
|
||||
setObjectid), parameterHelper(this) {
|
||||
if (thermalModule != NULL) {
|
||||
thermalModule->registerSensor(this);
|
||||
}
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue();
|
||||
}
|
||||
|
||||
AbstractTemperatureSensor::~AbstractTemperatureSensor() {
|
||||
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
||||
}
|
||||
|
||||
MessageQueueId_t AbstractTemperatureSensor::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t AbstractTemperatureSensor::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = healthHelper.initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = parameterHelper.initialize();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t AbstractTemperatureSensor::performOperation(uint8_t opCode) {
|
||||
handleCommandQueue();
|
||||
doChildOperation();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t AbstractTemperatureSensor::performHealthOp() {
|
||||
handleCommandQueue();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void AbstractTemperatureSensor::handleCommandQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
result = parameterHelper.handleParameterMessage(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
command.setToUnknownCommand();
|
||||
commandQueue->reply(&command);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t AbstractTemperatureSensor::setHealth(HealthState health) {
|
||||
healthHelper.setHealth(health);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
HasHealthIF::HealthState AbstractTemperatureSensor::getHealth() {
|
||||
return healthHelper.getHealth();
|
||||
}
|
||||
|
@ -1,64 +1,64 @@
|
||||
#ifndef ABSTRACTSENSOR_H_
|
||||
#define ABSTRACTSENSOR_H_
|
||||
|
||||
#include "../health/HasHealthIF.h"
|
||||
#include "../health/HealthHelper.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../tasks/ExecutableObjectIF.h"
|
||||
#include "../parameters/ParameterHelper.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "ThermalModuleIF.h"
|
||||
#include "tcsDefinitions.h"
|
||||
|
||||
/**
|
||||
* @defgroup thermal Thermal Components
|
||||
* @brief Contains all components related to thermal tasks (sensors, heaters)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Base class for Temperature Sensor, implements all important interfaces.
|
||||
* Please use the TemperatureSensor class to implement the actual sensors.
|
||||
* @ingroup thermal
|
||||
*/
|
||||
class AbstractTemperatureSensor: public HasHealthIF,
|
||||
public SystemObject,
|
||||
public ExecutableObjectIF,
|
||||
public ReceivesParameterMessagesIF {
|
||||
public:
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::T_SENSORS;
|
||||
static const Event TEMP_SENSOR_HIGH = MAKE_EVENT(0, SEVERITY::LOW);
|
||||
static const Event TEMP_SENSOR_LOW = MAKE_EVENT(1, SEVERITY::LOW);
|
||||
static const Event TEMP_SENSOR_GRADIENT = MAKE_EVENT(2, SEVERITY::LOW);
|
||||
|
||||
static constexpr float ZERO_KELVIN_C = -273.15;
|
||||
AbstractTemperatureSensor(object_id_t setObjectid,
|
||||
ThermalModuleIF *thermalModule);
|
||||
virtual ~AbstractTemperatureSensor();
|
||||
|
||||
virtual MessageQueueId_t getCommandQueue() const;
|
||||
|
||||
ReturnValue_t initialize();
|
||||
|
||||
ReturnValue_t performHealthOp();
|
||||
|
||||
ReturnValue_t performOperation(uint8_t opCode);
|
||||
|
||||
virtual float getTemperature() = 0;
|
||||
virtual bool isValid() = 0;
|
||||
|
||||
virtual void resetOldState() = 0;
|
||||
|
||||
ReturnValue_t setHealth(HealthState health);
|
||||
HasHealthIF::HealthState getHealth();
|
||||
protected:
|
||||
MessageQueueIF* commandQueue;
|
||||
HealthHelper healthHelper;
|
||||
ParameterHelper parameterHelper;
|
||||
|
||||
virtual void doChildOperation() = 0;
|
||||
|
||||
void handleCommandQueue();
|
||||
};
|
||||
|
||||
#endif /* ABSTRACTSENSOR_H_ */
|
||||
#ifndef ABSTRACTSENSOR_H_
|
||||
#define ABSTRACTSENSOR_H_
|
||||
|
||||
#include "../health/HasHealthIF.h"
|
||||
#include "../health/HealthHelper.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../tasks/ExecutableObjectIF.h"
|
||||
#include "../parameters/ParameterHelper.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "ThermalModuleIF.h"
|
||||
#include "tcsDefinitions.h"
|
||||
|
||||
/**
|
||||
* @defgroup thermal Thermal Components
|
||||
* @brief Contains all components related to thermal tasks (sensors, heaters)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Base class for Temperature Sensor, implements all important interfaces.
|
||||
* Please use the TemperatureSensor class to implement the actual sensors.
|
||||
* @ingroup thermal
|
||||
*/
|
||||
class AbstractTemperatureSensor: public HasHealthIF,
|
||||
public SystemObject,
|
||||
public ExecutableObjectIF,
|
||||
public ReceivesParameterMessagesIF {
|
||||
public:
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::T_SENSORS;
|
||||
static const Event TEMP_SENSOR_HIGH = MAKE_EVENT(0, SEVERITY::LOW);
|
||||
static const Event TEMP_SENSOR_LOW = MAKE_EVENT(1, SEVERITY::LOW);
|
||||
static const Event TEMP_SENSOR_GRADIENT = MAKE_EVENT(2, SEVERITY::LOW);
|
||||
|
||||
static constexpr float ZERO_KELVIN_C = -273.15;
|
||||
AbstractTemperatureSensor(object_id_t setObjectid,
|
||||
ThermalModuleIF *thermalModule);
|
||||
virtual ~AbstractTemperatureSensor();
|
||||
|
||||
virtual MessageQueueId_t getCommandQueue() const;
|
||||
|
||||
ReturnValue_t initialize();
|
||||
|
||||
ReturnValue_t performHealthOp();
|
||||
|
||||
ReturnValue_t performOperation(uint8_t opCode);
|
||||
|
||||
virtual float getTemperature() = 0;
|
||||
virtual bool isValid() = 0;
|
||||
|
||||
virtual void resetOldState() = 0;
|
||||
|
||||
ReturnValue_t setHealth(HealthState health);
|
||||
HasHealthIF::HealthState getHealth();
|
||||
protected:
|
||||
MessageQueueIF* commandQueue;
|
||||
HealthHelper healthHelper;
|
||||
ParameterHelper parameterHelper;
|
||||
|
||||
virtual void doChildOperation() = 0;
|
||||
|
||||
void handleCommandQueue();
|
||||
};
|
||||
|
||||
#endif /* ABSTRACTSENSOR_H_ */
|
||||
|
@ -1,22 +1,22 @@
|
||||
/**
|
||||
* \file AcceptsThermalMessagesIF.h
|
||||
*
|
||||
* \date 16.02.2020
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_
|
||||
#define FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
class AcceptsThermalMessagesIF {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief This is the empty virtual destructor as required for C++ interfaces.
|
||||
*/
|
||||
virtual ~AcceptsThermalMessagesIF() { }
|
||||
|
||||
virtual MessageQueueId_t getReceptionQueue() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_ */
|
||||
/**
|
||||
* \file AcceptsThermalMessagesIF.h
|
||||
*
|
||||
* \date 16.02.2020
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_
|
||||
#define FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
class AcceptsThermalMessagesIF {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief This is the empty virtual destructor as required for C++ interfaces.
|
||||
*/
|
||||
virtual ~AcceptsThermalMessagesIF() { }
|
||||
|
||||
virtual MessageQueueId_t getReceptionQueue() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_ */
|
||||
|
@ -1,96 +1,96 @@
|
||||
#ifndef MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_
|
||||
#define MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_
|
||||
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../thermal/ThermalComponentIF.h"
|
||||
#include "../thermal/AbstractTemperatureSensor.h"
|
||||
#include "../thermal/ThermalModule.h"
|
||||
#include "../thermal/ThermalMonitor.h"
|
||||
|
||||
// TODO: Documentaiton, how to use this? only use Thermal Component, which inherits core component?
|
||||
class CoreComponent: public ThermalComponentIF {
|
||||
public:
|
||||
struct Parameters {
|
||||
float lowerOpLimit;
|
||||
float upperOpLimit;
|
||||
float heaterOn;
|
||||
float hysteresis;
|
||||
float heaterSwitchoff;
|
||||
};
|
||||
|
||||
static const uint16_t COMPONENT_TEMP_CONFIRMATION = 5;
|
||||
|
||||
CoreComponent(object_id_t reportingObjectId, uint8_t domainId, uint32_t temperaturePoolId,
|
||||
uint32_t targetStatePoolId, uint32_t currentStatePoolId,
|
||||
uint32_t requestPoolId, GlobDataSet *dataSet,
|
||||
AbstractTemperatureSensor *sensor,
|
||||
AbstractTemperatureSensor *firstRedundantSensor,
|
||||
AbstractTemperatureSensor *secondRedundantSensor,
|
||||
ThermalModuleIF *thermalModule, Parameters parameters,
|
||||
Priority priority, StateRequest initialTargetState =
|
||||
ThermalComponentIF::STATE_REQUEST_OPERATIONAL);
|
||||
|
||||
virtual ~CoreComponent();
|
||||
|
||||
virtual HeaterRequest performOperation(uint8_t opCode);
|
||||
|
||||
void markStateIgnored();
|
||||
|
||||
object_id_t getObjectId();
|
||||
|
||||
uint8_t getDomainId() const;
|
||||
|
||||
virtual float getLowerOpLimit();
|
||||
|
||||
ReturnValue_t setTargetState(int8_t newState);
|
||||
|
||||
virtual void setOutputInvalid();
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
|
||||
protected:
|
||||
|
||||
AbstractTemperatureSensor *sensor;
|
||||
AbstractTemperatureSensor *firstRedundantSensor;
|
||||
AbstractTemperatureSensor *secondRedundantSensor;
|
||||
ThermalModuleIF *thermalModule;
|
||||
|
||||
gp_float_t temperature;
|
||||
gp_int8_t targetState;
|
||||
gp_int8_t currentState;
|
||||
gp_uint8_t heaterRequest;
|
||||
|
||||
bool isHeating;
|
||||
|
||||
bool isSafeComponent;
|
||||
|
||||
float minTemp;
|
||||
|
||||
float maxTemp;
|
||||
|
||||
Parameters parameters;
|
||||
|
||||
ThermalMonitor temperatureMonitor;
|
||||
|
||||
const uint8_t domainId;
|
||||
|
||||
virtual float getTemperature();
|
||||
virtual State getState(float temperature, Parameters parameters,
|
||||
int8_t targetState);
|
||||
|
||||
virtual void checkLimits(State state);
|
||||
|
||||
virtual HeaterRequest getHeaterRequest(int8_t targetState,
|
||||
float temperature, Parameters parameters);
|
||||
|
||||
virtual State getIgnoredState(int8_t state);
|
||||
|
||||
void updateMinMaxTemp();
|
||||
|
||||
virtual Parameters getParameters();
|
||||
};
|
||||
|
||||
#endif /* MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_ */
|
||||
#ifndef MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_
|
||||
#define MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_
|
||||
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../thermal/ThermalComponentIF.h"
|
||||
#include "../thermal/AbstractTemperatureSensor.h"
|
||||
#include "../thermal/ThermalModule.h"
|
||||
#include "../thermal/ThermalMonitor.h"
|
||||
|
||||
// TODO: Documentaiton, how to use this? only use Thermal Component, which inherits core component?
|
||||
class CoreComponent: public ThermalComponentIF {
|
||||
public:
|
||||
struct Parameters {
|
||||
float lowerOpLimit;
|
||||
float upperOpLimit;
|
||||
float heaterOn;
|
||||
float hysteresis;
|
||||
float heaterSwitchoff;
|
||||
};
|
||||
|
||||
static const uint16_t COMPONENT_TEMP_CONFIRMATION = 5;
|
||||
|
||||
CoreComponent(object_id_t reportingObjectId, uint8_t domainId, uint32_t temperaturePoolId,
|
||||
uint32_t targetStatePoolId, uint32_t currentStatePoolId,
|
||||
uint32_t requestPoolId, GlobDataSet *dataSet,
|
||||
AbstractTemperatureSensor *sensor,
|
||||
AbstractTemperatureSensor *firstRedundantSensor,
|
||||
AbstractTemperatureSensor *secondRedundantSensor,
|
||||
ThermalModuleIF *thermalModule, Parameters parameters,
|
||||
Priority priority, StateRequest initialTargetState =
|
||||
ThermalComponentIF::STATE_REQUEST_OPERATIONAL);
|
||||
|
||||
virtual ~CoreComponent();
|
||||
|
||||
virtual HeaterRequest performOperation(uint8_t opCode);
|
||||
|
||||
void markStateIgnored();
|
||||
|
||||
object_id_t getObjectId();
|
||||
|
||||
uint8_t getDomainId() const;
|
||||
|
||||
virtual float getLowerOpLimit();
|
||||
|
||||
ReturnValue_t setTargetState(int8_t newState);
|
||||
|
||||
virtual void setOutputInvalid();
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
|
||||
protected:
|
||||
|
||||
AbstractTemperatureSensor *sensor;
|
||||
AbstractTemperatureSensor *firstRedundantSensor;
|
||||
AbstractTemperatureSensor *secondRedundantSensor;
|
||||
ThermalModuleIF *thermalModule;
|
||||
|
||||
gp_float_t temperature;
|
||||
gp_int8_t targetState;
|
||||
gp_int8_t currentState;
|
||||
gp_uint8_t heaterRequest;
|
||||
|
||||
bool isHeating;
|
||||
|
||||
bool isSafeComponent;
|
||||
|
||||
float minTemp;
|
||||
|
||||
float maxTemp;
|
||||
|
||||
Parameters parameters;
|
||||
|
||||
ThermalMonitor temperatureMonitor;
|
||||
|
||||
const uint8_t domainId;
|
||||
|
||||
virtual float getTemperature();
|
||||
virtual State getState(float temperature, Parameters parameters,
|
||||
int8_t targetState);
|
||||
|
||||
virtual void checkLimits(State state);
|
||||
|
||||
virtual HeaterRequest getHeaterRequest(int8_t targetState,
|
||||
float temperature, Parameters parameters);
|
||||
|
||||
virtual State getIgnoredState(int8_t state);
|
||||
|
||||
void updateMinMaxTemp();
|
||||
|
||||
virtual Parameters getParameters();
|
||||
};
|
||||
|
||||
#endif /* MISSION_CONTROLLERS_TCS_CORECOMPONENT_H_ */
|
||||
|
@ -1,350 +1,350 @@
|
||||
#include "../devicehandlers/DeviceHandlerFailureIsolation.h"
|
||||
#include "Heater.h"
|
||||
|
||||
#include "../power/Fuse.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
|
||||
Heater::Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1) :
|
||||
HealthDevice(objectId, 0), internalState(STATE_OFF), powerSwitcher(
|
||||
NULL), pcduQueueId(0), switch0(switch0), switch1(switch1), wasOn(
|
||||
false), timedOut(false), reactedToBeingFaulty(false), passive(
|
||||
false), eventQueue(NULL), heaterOnCountdown(10800000)/*about two orbits*/, parameterHelper(
|
||||
this), lastAction(CLEAR) {
|
||||
eventQueue = QueueFactory::instance()->createMessageQueue();
|
||||
}
|
||||
|
||||
Heater::~Heater() {
|
||||
QueueFactory::instance()->deleteMessageQueue(eventQueue);
|
||||
}
|
||||
|
||||
ReturnValue_t Heater::set() {
|
||||
passive = false;
|
||||
//wait for clear before doing anything
|
||||
if (internalState == STATE_WAIT) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
if (healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
doAction(SET);
|
||||
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
} else {
|
||||
if (healthHelper.healthTable->isFaulty(getObjectId())) {
|
||||
if (!reactedToBeingFaulty) {
|
||||
reactedToBeingFaulty = true;
|
||||
doAction(CLEAR);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void Heater::clear(bool passive) {
|
||||
this->passive = passive;
|
||||
//Force switching off
|
||||
if (internalState == STATE_WAIT) {
|
||||
internalState = STATE_ON;
|
||||
}
|
||||
if (healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
doAction(CLEAR);
|
||||
} else if (healthHelper.healthTable->isFaulty(getObjectId())) {
|
||||
if (!reactedToBeingFaulty) {
|
||||
reactedToBeingFaulty = true;
|
||||
doAction(CLEAR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Heater::doAction(Action action) {
|
||||
//only act if we are not in the right state or in a transition
|
||||
if (action == SET) {
|
||||
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)
|
||||
|| (internalState == STATE_EXTERNAL_CONTROL)) {
|
||||
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
|
||||
internalState = STATE_WAIT_FOR_SWITCHES_ON;
|
||||
powerSwitcher->sendSwitchCommand(switch0, PowerSwitchIF::SWITCH_ON);
|
||||
powerSwitcher->sendSwitchCommand(switch1, PowerSwitchIF::SWITCH_ON);
|
||||
}
|
||||
} else { //clear
|
||||
if ((internalState == STATE_ON) || (internalState == STATE_FAULTY)
|
||||
|| (internalState == STATE_EXTERNAL_CONTROL)) {
|
||||
internalState = STATE_WAIT_FOR_SWITCHES_OFF;
|
||||
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
|
||||
powerSwitcher->sendSwitchCommand(switch0,
|
||||
PowerSwitchIF::SWITCH_OFF);
|
||||
powerSwitcher->sendSwitchCommand(switch1,
|
||||
PowerSwitchIF::SWITCH_OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Heater::setPowerSwitcher(PowerSwitchIF* powerSwitch) {
|
||||
this->powerSwitcher = powerSwitch;
|
||||
}
|
||||
|
||||
ReturnValue_t Heater::performOperation(uint8_t opCode) {
|
||||
handleQueue();
|
||||
handleEventQueue();
|
||||
|
||||
if (!healthHelper.healthTable->isFaulty(getObjectId())) {
|
||||
reactedToBeingFaulty = false;
|
||||
}
|
||||
|
||||
switch (internalState) {
|
||||
case STATE_ON:
|
||||
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_OFF)
|
||||
|| (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_OFF)) {
|
||||
//switch went off on its own
|
||||
//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
|
||||
if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
|
||||
triggerEvent(PowerSwitchIF::SWITCH_WENT_OFF);
|
||||
} else {
|
||||
internalState = STATE_EXTERNAL_CONTROL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_OFF:
|
||||
//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
|
||||
//But, only do anything if not already faulty (state off is the stable point for being faulty)
|
||||
if ((!healthHelper.healthTable->isFaulty(getObjectId()))
|
||||
&& (powerSwitcher->getSwitchState(switch0)
|
||||
== PowerSwitchIF::SWITCH_ON)
|
||||
&& (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_ON)) {
|
||||
//do not trigger FD events when under external control
|
||||
if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
|
||||
internalState = STATE_WAIT_FOR_SWITCHES_OFF;
|
||||
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
|
||||
powerSwitcher->sendSwitchCommand(switch0,
|
||||
PowerSwitchIF::SWITCH_OFF);
|
||||
powerSwitcher->sendSwitchCommand(switch1,
|
||||
PowerSwitchIF::SWITCH_OFF);
|
||||
} else {
|
||||
internalState = STATE_EXTERNAL_CONTROL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_PASSIVE:
|
||||
break;
|
||||
case STATE_WAIT_FOR_SWITCHES_ON:
|
||||
if (switchCountdown.hasTimedOut()) {
|
||||
if ((powerSwitcher->getSwitchState(switch0)
|
||||
== PowerSwitchIF::SWITCH_OFF)
|
||||
|| (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_OFF)) {
|
||||
triggerEvent(HEATER_STAYED_OFF);
|
||||
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
|
||||
} else {
|
||||
triggerEvent(HEATER_ON);
|
||||
internalState = STATE_ON;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_WAIT_FOR_SWITCHES_OFF:
|
||||
if (switchCountdown.hasTimedOut()) {
|
||||
//only check for both being on (ie heater still on)
|
||||
if ((powerSwitcher->getSwitchState(switch0)
|
||||
== PowerSwitchIF::SWITCH_ON)
|
||||
&& (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_ON)) {
|
||||
if (healthHelper.healthTable->isFaulty(getObjectId())) {
|
||||
if (passive) {
|
||||
internalState = STATE_PASSIVE;
|
||||
} else {
|
||||
internalState = STATE_OFF; //just accept it
|
||||
}
|
||||
triggerEvent(HEATER_ON); //but throw an event to make it more visible
|
||||
break;
|
||||
}
|
||||
triggerEvent(HEATER_STAYED_ON);
|
||||
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
|
||||
} else {
|
||||
triggerEvent(HEATER_OFF);
|
||||
if (passive) {
|
||||
internalState = STATE_PASSIVE;
|
||||
} else {
|
||||
internalState = STATE_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_ON)
|
||||
&& (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_ON)) {
|
||||
if (wasOn) {
|
||||
if (heaterOnCountdown.hasTimedOut()) {
|
||||
//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
|
||||
//it will be ok. whatcouldpossiblygowrong™
|
||||
if (!timedOut) {
|
||||
triggerEvent(HEATER_TIMEOUT);
|
||||
timedOut = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wasOn = true;
|
||||
heaterOnCountdown.resetTimer();
|
||||
timedOut = false;
|
||||
}
|
||||
} else {
|
||||
wasOn = false;
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void Heater::setSwitch(uint8_t number, ReturnValue_t state,
|
||||
uint32_t* uptimeOfSwitching) {
|
||||
if (powerSwitcher == NULL) {
|
||||
return;
|
||||
}
|
||||
if (powerSwitcher->getSwitchState(number) == state) {
|
||||
*uptimeOfSwitching = INVALID_UPTIME;
|
||||
} else {
|
||||
if ((*uptimeOfSwitching == INVALID_UPTIME)) {
|
||||
powerSwitcher->sendSwitchCommand(number, state);
|
||||
Clock::getUptime(uptimeOfSwitching);
|
||||
} else {
|
||||
uint32_t currentUptime;
|
||||
Clock::getUptime(¤tUptime);
|
||||
if (currentUptime - *uptimeOfSwitching
|
||||
> powerSwitcher->getSwitchDelayMs()) {
|
||||
*uptimeOfSwitching = INVALID_UPTIME;
|
||||
if (healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
if (state == PowerSwitchIF::SWITCH_ON) {
|
||||
triggerEvent(HEATER_STAYED_OFF);
|
||||
} else {
|
||||
triggerEvent(HEATER_STAYED_ON);
|
||||
}
|
||||
}
|
||||
//SHOULDDO MiniOps during switch timeout leads to a faulty switch
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessageQueueId_t Heater::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t Heater::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
EventManagerIF* manager = objectManager->get<EventManagerIF>(
|
||||
objects::EVENT_MANAGER);
|
||||
if (manager == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
result = manager->registerListener(eventQueue->getId());
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
ConfirmsFailuresIF* pcdu = objectManager->get<ConfirmsFailuresIF>(
|
||||
DeviceHandlerFailureIsolation::powerConfirmationId);
|
||||
if (pcdu == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
pcduQueueId = pcdu->getEventReceptionQueue();
|
||||
|
||||
result = manager->subscribeToAllEventsFrom(eventQueue->getId(),
|
||||
getObjectId());
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = parameterHelper.initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = healthHelper.initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void Heater::handleQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
parameterHelper.handleParameterMessage(&command);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Heater::getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
|
||||
uint16_t startAtIndex) {
|
||||
if (domainId != DOMAIN_ID_BASE) {
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case 0:
|
||||
parameterWrapper->set(heaterOnCountdown.timeout);
|
||||
break;
|
||||
default:
|
||||
return INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void Heater::handleEventQueue() {
|
||||
EventMessage event;
|
||||
for (ReturnValue_t result = eventQueue->receiveMessage(&event);
|
||||
result == HasReturnvaluesIF::RETURN_OK;
|
||||
result = eventQueue->receiveMessage(&event)) {
|
||||
switch (event.getMessageId()) {
|
||||
case EventMessage::EVENT_MESSAGE:
|
||||
switch (event.getEvent()) {
|
||||
case Fuse::FUSE_WENT_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.
|
||||
if (healthHelper.healthTable->isCommandable(getObjectId())) {
|
||||
healthHelper.setHealth(HasHealthIF::FAULTY);
|
||||
internalState = STATE_FAULTY;
|
||||
}
|
||||
break;
|
||||
case PowerSwitchIF::SWITCH_WENT_OFF:
|
||||
internalState = STATE_WAIT;
|
||||
event.setMessageId(EventMessage::CONFIRMATION_REQUEST);
|
||||
if (pcduQueueId != 0) {
|
||||
eventQueue->sendMessage(pcduQueueId, &event);
|
||||
} else {
|
||||
healthHelper.setHealth(HasHealthIF::FAULTY);
|
||||
internalState = STATE_FAULTY;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case EventMessage::YOUR_FAULT:
|
||||
healthHelper.setHealth(HasHealthIF::FAULTY);
|
||||
internalState = STATE_FAULTY;
|
||||
break;
|
||||
case EventMessage::MY_FAULT:
|
||||
//do nothing, we are already in STATE_WAIT and wait for a clear()
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "../devicehandlers/DeviceHandlerFailureIsolation.h"
|
||||
#include "Heater.h"
|
||||
|
||||
#include "../power/Fuse.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
|
||||
Heater::Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1) :
|
||||
HealthDevice(objectId, 0), internalState(STATE_OFF), powerSwitcher(
|
||||
NULL), pcduQueueId(0), switch0(switch0), switch1(switch1), wasOn(
|
||||
false), timedOut(false), reactedToBeingFaulty(false), passive(
|
||||
false), eventQueue(NULL), heaterOnCountdown(10800000)/*about two orbits*/, parameterHelper(
|
||||
this), lastAction(CLEAR) {
|
||||
eventQueue = QueueFactory::instance()->createMessageQueue();
|
||||
}
|
||||
|
||||
Heater::~Heater() {
|
||||
QueueFactory::instance()->deleteMessageQueue(eventQueue);
|
||||
}
|
||||
|
||||
ReturnValue_t Heater::set() {
|
||||
passive = false;
|
||||
//wait for clear before doing anything
|
||||
if (internalState == STATE_WAIT) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
if (healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
doAction(SET);
|
||||
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
} else {
|
||||
if (healthHelper.healthTable->isFaulty(getObjectId())) {
|
||||
if (!reactedToBeingFaulty) {
|
||||
reactedToBeingFaulty = true;
|
||||
doAction(CLEAR);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void Heater::clear(bool passive) {
|
||||
this->passive = passive;
|
||||
//Force switching off
|
||||
if (internalState == STATE_WAIT) {
|
||||
internalState = STATE_ON;
|
||||
}
|
||||
if (healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
doAction(CLEAR);
|
||||
} else if (healthHelper.healthTable->isFaulty(getObjectId())) {
|
||||
if (!reactedToBeingFaulty) {
|
||||
reactedToBeingFaulty = true;
|
||||
doAction(CLEAR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Heater::doAction(Action action) {
|
||||
//only act if we are not in the right state or in a transition
|
||||
if (action == SET) {
|
||||
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)
|
||||
|| (internalState == STATE_EXTERNAL_CONTROL)) {
|
||||
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
|
||||
internalState = STATE_WAIT_FOR_SWITCHES_ON;
|
||||
powerSwitcher->sendSwitchCommand(switch0, PowerSwitchIF::SWITCH_ON);
|
||||
powerSwitcher->sendSwitchCommand(switch1, PowerSwitchIF::SWITCH_ON);
|
||||
}
|
||||
} else { //clear
|
||||
if ((internalState == STATE_ON) || (internalState == STATE_FAULTY)
|
||||
|| (internalState == STATE_EXTERNAL_CONTROL)) {
|
||||
internalState = STATE_WAIT_FOR_SWITCHES_OFF;
|
||||
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
|
||||
powerSwitcher->sendSwitchCommand(switch0,
|
||||
PowerSwitchIF::SWITCH_OFF);
|
||||
powerSwitcher->sendSwitchCommand(switch1,
|
||||
PowerSwitchIF::SWITCH_OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Heater::setPowerSwitcher(PowerSwitchIF* powerSwitch) {
|
||||
this->powerSwitcher = powerSwitch;
|
||||
}
|
||||
|
||||
ReturnValue_t Heater::performOperation(uint8_t opCode) {
|
||||
handleQueue();
|
||||
handleEventQueue();
|
||||
|
||||
if (!healthHelper.healthTable->isFaulty(getObjectId())) {
|
||||
reactedToBeingFaulty = false;
|
||||
}
|
||||
|
||||
switch (internalState) {
|
||||
case STATE_ON:
|
||||
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_OFF)
|
||||
|| (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_OFF)) {
|
||||
//switch went off on its own
|
||||
//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
|
||||
if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
|
||||
triggerEvent(PowerSwitchIF::SWITCH_WENT_OFF);
|
||||
} else {
|
||||
internalState = STATE_EXTERNAL_CONTROL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_OFF:
|
||||
//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
|
||||
//But, only do anything if not already faulty (state off is the stable point for being faulty)
|
||||
if ((!healthHelper.healthTable->isFaulty(getObjectId()))
|
||||
&& (powerSwitcher->getSwitchState(switch0)
|
||||
== PowerSwitchIF::SWITCH_ON)
|
||||
&& (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_ON)) {
|
||||
//do not trigger FD events when under external control
|
||||
if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
|
||||
internalState = STATE_WAIT_FOR_SWITCHES_OFF;
|
||||
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
|
||||
powerSwitcher->sendSwitchCommand(switch0,
|
||||
PowerSwitchIF::SWITCH_OFF);
|
||||
powerSwitcher->sendSwitchCommand(switch1,
|
||||
PowerSwitchIF::SWITCH_OFF);
|
||||
} else {
|
||||
internalState = STATE_EXTERNAL_CONTROL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_PASSIVE:
|
||||
break;
|
||||
case STATE_WAIT_FOR_SWITCHES_ON:
|
||||
if (switchCountdown.hasTimedOut()) {
|
||||
if ((powerSwitcher->getSwitchState(switch0)
|
||||
== PowerSwitchIF::SWITCH_OFF)
|
||||
|| (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_OFF)) {
|
||||
triggerEvent(HEATER_STAYED_OFF);
|
||||
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
|
||||
} else {
|
||||
triggerEvent(HEATER_ON);
|
||||
internalState = STATE_ON;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_WAIT_FOR_SWITCHES_OFF:
|
||||
if (switchCountdown.hasTimedOut()) {
|
||||
//only check for both being on (ie heater still on)
|
||||
if ((powerSwitcher->getSwitchState(switch0)
|
||||
== PowerSwitchIF::SWITCH_ON)
|
||||
&& (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_ON)) {
|
||||
if (healthHelper.healthTable->isFaulty(getObjectId())) {
|
||||
if (passive) {
|
||||
internalState = STATE_PASSIVE;
|
||||
} else {
|
||||
internalState = STATE_OFF; //just accept it
|
||||
}
|
||||
triggerEvent(HEATER_ON); //but throw an event to make it more visible
|
||||
break;
|
||||
}
|
||||
triggerEvent(HEATER_STAYED_ON);
|
||||
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
|
||||
} else {
|
||||
triggerEvent(HEATER_OFF);
|
||||
if (passive) {
|
||||
internalState = STATE_PASSIVE;
|
||||
} else {
|
||||
internalState = STATE_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_ON)
|
||||
&& (powerSwitcher->getSwitchState(switch1)
|
||||
== PowerSwitchIF::SWITCH_ON)) {
|
||||
if (wasOn) {
|
||||
if (heaterOnCountdown.hasTimedOut()) {
|
||||
//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
|
||||
//it will be ok. whatcouldpossiblygowrong™
|
||||
if (!timedOut) {
|
||||
triggerEvent(HEATER_TIMEOUT);
|
||||
timedOut = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wasOn = true;
|
||||
heaterOnCountdown.resetTimer();
|
||||
timedOut = false;
|
||||
}
|
||||
} else {
|
||||
wasOn = false;
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void Heater::setSwitch(uint8_t number, ReturnValue_t state,
|
||||
uint32_t* uptimeOfSwitching) {
|
||||
if (powerSwitcher == NULL) {
|
||||
return;
|
||||
}
|
||||
if (powerSwitcher->getSwitchState(number) == state) {
|
||||
*uptimeOfSwitching = INVALID_UPTIME;
|
||||
} else {
|
||||
if ((*uptimeOfSwitching == INVALID_UPTIME)) {
|
||||
powerSwitcher->sendSwitchCommand(number, state);
|
||||
Clock::getUptime(uptimeOfSwitching);
|
||||
} else {
|
||||
uint32_t currentUptime;
|
||||
Clock::getUptime(¤tUptime);
|
||||
if (currentUptime - *uptimeOfSwitching
|
||||
> powerSwitcher->getSwitchDelayMs()) {
|
||||
*uptimeOfSwitching = INVALID_UPTIME;
|
||||
if (healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
if (state == PowerSwitchIF::SWITCH_ON) {
|
||||
triggerEvent(HEATER_STAYED_OFF);
|
||||
} else {
|
||||
triggerEvent(HEATER_STAYED_ON);
|
||||
}
|
||||
}
|
||||
//SHOULDDO MiniOps during switch timeout leads to a faulty switch
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessageQueueId_t Heater::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t Heater::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
EventManagerIF* manager = objectManager->get<EventManagerIF>(
|
||||
objects::EVENT_MANAGER);
|
||||
if (manager == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
result = manager->registerListener(eventQueue->getId());
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
ConfirmsFailuresIF* pcdu = objectManager->get<ConfirmsFailuresIF>(
|
||||
DeviceHandlerFailureIsolation::powerConfirmationId);
|
||||
if (pcdu == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
pcduQueueId = pcdu->getEventReceptionQueue();
|
||||
|
||||
result = manager->subscribeToAllEventsFrom(eventQueue->getId(),
|
||||
getObjectId());
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = parameterHelper.initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = healthHelper.initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void Heater::handleQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
result = healthHelper.handleHealthCommand(&command);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
parameterHelper.handleParameterMessage(&command);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Heater::getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
|
||||
uint16_t startAtIndex) {
|
||||
if (domainId != DOMAIN_ID_BASE) {
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case 0:
|
||||
parameterWrapper->set(heaterOnCountdown.timeout);
|
||||
break;
|
||||
default:
|
||||
return INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void Heater::handleEventQueue() {
|
||||
EventMessage event;
|
||||
for (ReturnValue_t result = eventQueue->receiveMessage(&event);
|
||||
result == HasReturnvaluesIF::RETURN_OK;
|
||||
result = eventQueue->receiveMessage(&event)) {
|
||||
switch (event.getMessageId()) {
|
||||
case EventMessage::EVENT_MESSAGE:
|
||||
switch (event.getEvent()) {
|
||||
case Fuse::FUSE_WENT_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.
|
||||
if (healthHelper.healthTable->isCommandable(getObjectId())) {
|
||||
healthHelper.setHealth(HasHealthIF::FAULTY);
|
||||
internalState = STATE_FAULTY;
|
||||
}
|
||||
break;
|
||||
case PowerSwitchIF::SWITCH_WENT_OFF:
|
||||
internalState = STATE_WAIT;
|
||||
event.setMessageId(EventMessage::CONFIRMATION_REQUEST);
|
||||
if (pcduQueueId != 0) {
|
||||
eventQueue->sendMessage(pcduQueueId, &event);
|
||||
} else {
|
||||
healthHelper.setHealth(HasHealthIF::FAULTY);
|
||||
internalState = STATE_FAULTY;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case EventMessage::YOUR_FAULT:
|
||||
healthHelper.setHealth(HasHealthIF::FAULTY);
|
||||
internalState = STATE_FAULTY;
|
||||
break;
|
||||
case EventMessage::MY_FAULT:
|
||||
//do nothing, we are already in STATE_WAIT and wait for a clear()
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
180
thermal/Heater.h
180
thermal/Heater.h
@ -1,90 +1,90 @@
|
||||
#ifndef FRAMEWORK_THERMAL_HEATER_H_
|
||||
#define FRAMEWORK_THERMAL_HEATER_H_
|
||||
|
||||
#include "../devicehandlers/HealthDevice.h"
|
||||
#include "../parameters/ParameterHelper.h"
|
||||
#include "../power/PowerSwitchIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../timemanager/Countdown.h"
|
||||
#include <stdint.h>
|
||||
//class RedundantHeater;
|
||||
|
||||
class Heater: public HealthDevice, public ReceivesParameterMessagesIF {
|
||||
friend class RedundantHeater;
|
||||
public:
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER;
|
||||
static const Event HEATER_ON = MAKE_EVENT(0, 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_STAYED_ON = MAKE_EVENT(3, SEVERITY::LOW);
|
||||
static const Event HEATER_STAYED_OFF = MAKE_EVENT(4, SEVERITY::LOW);
|
||||
|
||||
Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1);
|
||||
virtual ~Heater();
|
||||
|
||||
ReturnValue_t performOperation(uint8_t opCode);
|
||||
|
||||
ReturnValue_t initialize();
|
||||
|
||||
ReturnValue_t set();
|
||||
void clear(bool passive);
|
||||
|
||||
void setPowerSwitcher(PowerSwitchIF *powerSwitch);
|
||||
|
||||
MessageQueueId_t getCommandQueue() const;
|
||||
|
||||
ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
|
||||
protected:
|
||||
static const uint32_t INVALID_UPTIME = 0;
|
||||
|
||||
enum InternalState {
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
STATE_PASSIVE,
|
||||
STATE_WAIT_FOR_SWITCHES_ON,
|
||||
STATE_WAIT_FOR_SWITCHES_OFF,
|
||||
STATE_WAIT_FOR_FDIR, //used to avoid doing anything until fdir decided what to do
|
||||
STATE_FAULTY,
|
||||
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
|
||||
//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;
|
||||
MessageQueueId_t pcduQueueId;
|
||||
|
||||
uint8_t switch0;
|
||||
uint8_t switch1;
|
||||
|
||||
bool wasOn;
|
||||
|
||||
bool timedOut;
|
||||
|
||||
bool reactedToBeingFaulty;
|
||||
|
||||
bool passive;
|
||||
|
||||
MessageQueueIF* eventQueue;
|
||||
Countdown heaterOnCountdown;
|
||||
Countdown switchCountdown;
|
||||
ParameterHelper parameterHelper;
|
||||
|
||||
enum Action {
|
||||
SET, CLEAR
|
||||
} lastAction;
|
||||
|
||||
void doAction(Action action);
|
||||
|
||||
void setSwitch(uint8_t number, ReturnValue_t state,
|
||||
uint32_t *upTimeOfSwitching);
|
||||
|
||||
void handleQueue();
|
||||
|
||||
void handleEventQueue();
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_THERMAL_HEATER_H_ */
|
||||
#ifndef FRAMEWORK_THERMAL_HEATER_H_
|
||||
#define FRAMEWORK_THERMAL_HEATER_H_
|
||||
|
||||
#include "../devicehandlers/HealthDevice.h"
|
||||
#include "../parameters/ParameterHelper.h"
|
||||
#include "../power/PowerSwitchIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../timemanager/Countdown.h"
|
||||
#include <stdint.h>
|
||||
//class RedundantHeater;
|
||||
|
||||
class Heater: public HealthDevice, public ReceivesParameterMessagesIF {
|
||||
friend class RedundantHeater;
|
||||
public:
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER;
|
||||
static const Event HEATER_ON = MAKE_EVENT(0, 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_STAYED_ON = MAKE_EVENT(3, SEVERITY::LOW);
|
||||
static const Event HEATER_STAYED_OFF = MAKE_EVENT(4, SEVERITY::LOW);
|
||||
|
||||
Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1);
|
||||
virtual ~Heater();
|
||||
|
||||
ReturnValue_t performOperation(uint8_t opCode);
|
||||
|
||||
ReturnValue_t initialize();
|
||||
|
||||
ReturnValue_t set();
|
||||
void clear(bool passive);
|
||||
|
||||
void setPowerSwitcher(PowerSwitchIF *powerSwitch);
|
||||
|
||||
MessageQueueId_t getCommandQueue() const;
|
||||
|
||||
ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
|
||||
protected:
|
||||
static const uint32_t INVALID_UPTIME = 0;
|
||||
|
||||
enum InternalState {
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
STATE_PASSIVE,
|
||||
STATE_WAIT_FOR_SWITCHES_ON,
|
||||
STATE_WAIT_FOR_SWITCHES_OFF,
|
||||
STATE_WAIT_FOR_FDIR, //used to avoid doing anything until fdir decided what to do
|
||||
STATE_FAULTY,
|
||||
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
|
||||
//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;
|
||||
MessageQueueId_t pcduQueueId;
|
||||
|
||||
uint8_t switch0;
|
||||
uint8_t switch1;
|
||||
|
||||
bool wasOn;
|
||||
|
||||
bool timedOut;
|
||||
|
||||
bool reactedToBeingFaulty;
|
||||
|
||||
bool passive;
|
||||
|
||||
MessageQueueIF* eventQueue;
|
||||
Countdown heaterOnCountdown;
|
||||
Countdown switchCountdown;
|
||||
ParameterHelper parameterHelper;
|
||||
|
||||
enum Action {
|
||||
SET, CLEAR
|
||||
} lastAction;
|
||||
|
||||
void doAction(Action action);
|
||||
|
||||
void setSwitch(uint8_t number, ReturnValue_t state,
|
||||
uint32_t *upTimeOfSwitching);
|
||||
|
||||
void handleQueue();
|
||||
|
||||
void handleEventQueue();
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_THERMAL_HEATER_H_ */
|
||||
|
@ -1,50 +1,50 @@
|
||||
#ifndef REDUNDANTHEATER_H_
|
||||
#define REDUNDANTHEATER_H_
|
||||
|
||||
#include "../thermal/Heater.h"
|
||||
|
||||
class RedundantHeater {
|
||||
public:
|
||||
|
||||
struct Parameters {
|
||||
Parameters(uint32_t objectIdHeater0, uint32_t objectIdHeater1,
|
||||
uint8_t switch0Heater0, uint8_t switch1Heater0,
|
||||
uint8_t switch0Heater1, uint8_t switch1Heater1) :
|
||||
objectIdHeater0(objectIdHeater0), objectIdHeater1(objectIdHeater1),
|
||||
switch0Heater0(switch0Heater0),switch1Heater0(switch1Heater0),
|
||||
switch0Heater1(switch0Heater1), switch1Heater1(switch1Heater1) {
|
||||
}
|
||||
|
||||
Parameters() :
|
||||
objectIdHeater0(0), objectIdHeater1(0), switch0Heater0(0),
|
||||
switch1Heater0(0), switch0Heater1(0), switch1Heater1(0) {
|
||||
}
|
||||
|
||||
uint32_t objectIdHeater0;
|
||||
uint32_t objectIdHeater1;
|
||||
uint8_t switch0Heater0;
|
||||
uint8_t switch1Heater0;
|
||||
uint8_t switch0Heater1;
|
||||
uint8_t switch1Heater1;
|
||||
};
|
||||
|
||||
RedundantHeater(Parameters parameters);
|
||||
virtual ~RedundantHeater();
|
||||
|
||||
void performOperation(uint8_t opCode);
|
||||
|
||||
void triggerHeaterEvent(Event event);
|
||||
|
||||
void set(bool on, bool both, bool passive = false);
|
||||
|
||||
void setPowerSwitcher(PowerSwitchIF *powerSwitch);
|
||||
|
||||
protected:
|
||||
|
||||
Heater heater0;
|
||||
Heater heater1;
|
||||
|
||||
};
|
||||
|
||||
#endif /* REDUNDANTHEATER_H_ */
|
||||
|
||||
#ifndef REDUNDANTHEATER_H_
|
||||
#define REDUNDANTHEATER_H_
|
||||
|
||||
#include "../thermal/Heater.h"
|
||||
|
||||
class RedundantHeater {
|
||||
public:
|
||||
|
||||
struct Parameters {
|
||||
Parameters(uint32_t objectIdHeater0, uint32_t objectIdHeater1,
|
||||
uint8_t switch0Heater0, uint8_t switch1Heater0,
|
||||
uint8_t switch0Heater1, uint8_t switch1Heater1) :
|
||||
objectIdHeater0(objectIdHeater0), objectIdHeater1(objectIdHeater1),
|
||||
switch0Heater0(switch0Heater0),switch1Heater0(switch1Heater0),
|
||||
switch0Heater1(switch0Heater1), switch1Heater1(switch1Heater1) {
|
||||
}
|
||||
|
||||
Parameters() :
|
||||
objectIdHeater0(0), objectIdHeater1(0), switch0Heater0(0),
|
||||
switch1Heater0(0), switch0Heater1(0), switch1Heater1(0) {
|
||||
}
|
||||
|
||||
uint32_t objectIdHeater0;
|
||||
uint32_t objectIdHeater1;
|
||||
uint8_t switch0Heater0;
|
||||
uint8_t switch1Heater0;
|
||||
uint8_t switch0Heater1;
|
||||
uint8_t switch1Heater1;
|
||||
};
|
||||
|
||||
RedundantHeater(Parameters parameters);
|
||||
virtual ~RedundantHeater();
|
||||
|
||||
void performOperation(uint8_t opCode);
|
||||
|
||||
void triggerHeaterEvent(Event event);
|
||||
|
||||
void set(bool on, bool both, bool passive = false);
|
||||
|
||||
void setPowerSwitcher(PowerSwitchIF *powerSwitch);
|
||||
|
||||
protected:
|
||||
|
||||
Heater heater0;
|
||||
Heater heater1;
|
||||
|
||||
};
|
||||
|
||||
#endif /* REDUNDANTHEATER_H_ */
|
||||
|
||||
|
@ -1,222 +1,222 @@
|
||||
#ifndef TEMPERATURESENSOR_H_
|
||||
#define TEMPERATURESENSOR_H_
|
||||
|
||||
#include "../thermal/AbstractTemperatureSensor.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../monitoring/LimitMonitor.h"
|
||||
|
||||
/**
|
||||
* @brief This building block handles non-linear value conversion and
|
||||
* range checks for analog temperature sensors.
|
||||
* @details This class can be used to perform all necessary tasks for temperature sensors.
|
||||
* A sensor can be instantiated by calling the constructor.
|
||||
* The temperature is calculated from an input value with
|
||||
* the calculateOutputTemperature() function. Range checking and
|
||||
* limit monitoring is performed automatically.
|
||||
* The inputType specifies the type of the raw input while the
|
||||
* limitType specifies the type of the upper and lower limit to check against.
|
||||
* @ingroup thermal
|
||||
*/
|
||||
|
||||
template<typename inputType, typename limitType = inputType>
|
||||
class TemperatureSensor: public AbstractTemperatureSensor {
|
||||
public:
|
||||
/**
|
||||
* This structure contains parameters required for range checking
|
||||
* and the conversion from the input value to the output temperature.
|
||||
* a, b and c can be any parameters required to calculate the output
|
||||
* temperature from the input value, depending on the formula used.
|
||||
*
|
||||
* The parameters a,b and c are used in the calculateOutputTemperature() call.
|
||||
*
|
||||
* The lower and upper limits can be specified in any type, for example float for C values
|
||||
* or any other type for raw values.
|
||||
*/
|
||||
struct Parameters {
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
limitType lowerLimit;
|
||||
limitType upperLimit;
|
||||
float maxGradient;
|
||||
};
|
||||
|
||||
/**
|
||||
* Forward declaration for explicit instantiation of used parameters.
|
||||
*/
|
||||
struct UsedParameters {
|
||||
UsedParameters(Parameters parameters) :
|
||||
a(parameters.a), b(parameters.b), c(parameters.c),
|
||||
gradient(parameters.maxGradient) {}
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
float gradient;
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiate Temperature Sensor Object.
|
||||
* @param setObjectid objectId of the sensor object
|
||||
* @param inputValue Input value which is converted to a temperature
|
||||
* @param poolVariable Pool Variable to store the temperature value
|
||||
* @param vectorIndex Vector Index for the sensor monitor
|
||||
* @param parameters Calculation parameters, temperature limits, gradient limit
|
||||
* @param datapoolId Datapool ID of the output temperature
|
||||
* @param outputSet Output dataset for the output temperature to fetch it with read()
|
||||
* @param thermalModule respective thermal module, if it has one
|
||||
*/
|
||||
TemperatureSensor(object_id_t setObjectid,
|
||||
inputType *inputValue, PoolVariableIF *poolVariable,
|
||||
uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0, 0, 0},
|
||||
GlobDataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) :
|
||||
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
|
||||
inputValue(inputValue), poolVariable(poolVariable),
|
||||
outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE),
|
||||
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR,
|
||||
GlobalDataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex),
|
||||
DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, parameters.upperLimit,
|
||||
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH),
|
||||
oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) {
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This formula is used to calculate the temperature from an input value
|
||||
* with an arbitrary type.
|
||||
* A default implementation is provided but can be replaced depending
|
||||
* on the required calculation.
|
||||
* @param inputTemperature
|
||||
* @return
|
||||
*/
|
||||
virtual float calculateOutputTemperature(inputType inputValue) {
|
||||
return parameters.a * inputValue * inputValue
|
||||
+ parameters.b * inputValue + parameters.c;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void setInvalid() {
|
||||
outputTemperature = INVALID_TEMPERATURE;
|
||||
outputTemperature.setValid(false);
|
||||
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
||||
sensorMonitor.setToInvalid();
|
||||
}
|
||||
protected:
|
||||
static const int32_t INVALID_UPTIME = 0;
|
||||
|
||||
UsedParameters parameters;
|
||||
|
||||
inputType * inputValue;
|
||||
|
||||
PoolVariableIF *poolVariable;
|
||||
|
||||
gp_float_t outputTemperature;
|
||||
|
||||
LimitMonitor<limitType> sensorMonitor;
|
||||
|
||||
float oldTemperature;
|
||||
timeval uptimeOfOldTemperature;
|
||||
|
||||
void doChildOperation() {
|
||||
if (!poolVariable->isValid()
|
||||
|| !healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
setInvalid();
|
||||
return;
|
||||
}
|
||||
|
||||
outputTemperature = calculateOutputTemperature(*inputValue);
|
||||
outputTemperature.setValid(PoolVariableIF::VALID);
|
||||
|
||||
timeval uptime;
|
||||
Clock::getUptime(&uptime);
|
||||
|
||||
if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) {
|
||||
//In theory, we could use an AbsValueMonitor to monitor the gradient.
|
||||
//But this would require storing the maxGradient in DP and quite some overhead.
|
||||
//The concept of delta limits is a bit strange anyway.
|
||||
float deltaTime;
|
||||
float deltaTemp;
|
||||
|
||||
deltaTime = (uptime.tv_sec + uptime.tv_usec / 1000000.)
|
||||
- (uptimeOfOldTemperature.tv_sec
|
||||
+ uptimeOfOldTemperature.tv_usec / 1000000.);
|
||||
deltaTemp = oldTemperature - outputTemperature;
|
||||
if (deltaTemp < 0) {
|
||||
deltaTemp = -deltaTemp;
|
||||
}
|
||||
if (parameters.gradient < deltaTemp / deltaTime) {
|
||||
triggerEvent(TEMP_SENSOR_GRADIENT);
|
||||
//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 <20>C would be more easy to handle.
|
||||
sensorMonitor.doCheck(outputTemperature.value);
|
||||
|
||||
if (sensorMonitor.isOutOfLimits()) {
|
||||
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
||||
outputTemperature.setValid(PoolVariableIF::INVALID);
|
||||
outputTemperature = INVALID_TEMPERATURE;
|
||||
} else {
|
||||
oldTemperature = outputTemperature;
|
||||
uptimeOfOldTemperature = uptime;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
float getTemperature() {
|
||||
return outputTemperature;
|
||||
}
|
||||
|
||||
bool isValid() {
|
||||
return outputTemperature.isValid();
|
||||
}
|
||||
|
||||
static const uint16_t ADDRESS_A = 0;
|
||||
static const uint16_t ADDRESS_B = 1;
|
||||
static const uint16_t ADDRESS_C = 2;
|
||||
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.)
|
||||
|
||||
static const uint8_t DOMAIN_ID_SENSOR = 1;
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
||||
ReturnValue_t result = sensorMonitor.getParameter(domainId, parameterId,
|
||||
parameterWrapper, newValues, startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
if (domainId != this->DOMAIN_ID_BASE) {
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case ADDRESS_A:
|
||||
parameterWrapper->set(parameters.a);
|
||||
break;
|
||||
case ADDRESS_B:
|
||||
parameterWrapper->set(parameters.b);
|
||||
break;
|
||||
case ADDRESS_C:
|
||||
parameterWrapper->set(parameters.c);
|
||||
break;
|
||||
case ADDRESS_GRADIENT:
|
||||
parameterWrapper->set(parameters.gradient);
|
||||
break;
|
||||
default:
|
||||
return INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
virtual void resetOldState() {
|
||||
sensorMonitor.setToUnchecked();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* TEMPERATURESENSOR_H_ */
|
||||
#ifndef TEMPERATURESENSOR_H_
|
||||
#define TEMPERATURESENSOR_H_
|
||||
|
||||
#include "../thermal/AbstractTemperatureSensor.h"
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../monitoring/LimitMonitor.h"
|
||||
|
||||
/**
|
||||
* @brief This building block handles non-linear value conversion and
|
||||
* range checks for analog temperature sensors.
|
||||
* @details This class can be used to perform all necessary tasks for temperature sensors.
|
||||
* A sensor can be instantiated by calling the constructor.
|
||||
* The temperature is calculated from an input value with
|
||||
* the calculateOutputTemperature() function. Range checking and
|
||||
* limit monitoring is performed automatically.
|
||||
* The inputType specifies the type of the raw input while the
|
||||
* limitType specifies the type of the upper and lower limit to check against.
|
||||
* @ingroup thermal
|
||||
*/
|
||||
|
||||
template<typename inputType, typename limitType = inputType>
|
||||
class TemperatureSensor: public AbstractTemperatureSensor {
|
||||
public:
|
||||
/**
|
||||
* This structure contains parameters required for range checking
|
||||
* and the conversion from the input value to the output temperature.
|
||||
* a, b and c can be any parameters required to calculate the output
|
||||
* temperature from the input value, depending on the formula used.
|
||||
*
|
||||
* The parameters a,b and c are used in the calculateOutputTemperature() call.
|
||||
*
|
||||
* The lower and upper limits can be specified in any type, for example float for C values
|
||||
* or any other type for raw values.
|
||||
*/
|
||||
struct Parameters {
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
limitType lowerLimit;
|
||||
limitType upperLimit;
|
||||
float maxGradient;
|
||||
};
|
||||
|
||||
/**
|
||||
* Forward declaration for explicit instantiation of used parameters.
|
||||
*/
|
||||
struct UsedParameters {
|
||||
UsedParameters(Parameters parameters) :
|
||||
a(parameters.a), b(parameters.b), c(parameters.c),
|
||||
gradient(parameters.maxGradient) {}
|
||||
float a;
|
||||
float b;
|
||||
float c;
|
||||
float gradient;
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiate Temperature Sensor Object.
|
||||
* @param setObjectid objectId of the sensor object
|
||||
* @param inputValue Input value which is converted to a temperature
|
||||
* @param poolVariable Pool Variable to store the temperature value
|
||||
* @param vectorIndex Vector Index for the sensor monitor
|
||||
* @param parameters Calculation parameters, temperature limits, gradient limit
|
||||
* @param datapoolId Datapool ID of the output temperature
|
||||
* @param outputSet Output dataset for the output temperature to fetch it with read()
|
||||
* @param thermalModule respective thermal module, if it has one
|
||||
*/
|
||||
TemperatureSensor(object_id_t setObjectid,
|
||||
inputType *inputValue, PoolVariableIF *poolVariable,
|
||||
uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0, 0, 0},
|
||||
GlobDataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) :
|
||||
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
|
||||
inputValue(inputValue), poolVariable(poolVariable),
|
||||
outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE),
|
||||
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR,
|
||||
GlobalDataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex),
|
||||
DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, parameters.upperLimit,
|
||||
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH),
|
||||
oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) {
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This formula is used to calculate the temperature from an input value
|
||||
* with an arbitrary type.
|
||||
* A default implementation is provided but can be replaced depending
|
||||
* on the required calculation.
|
||||
* @param inputTemperature
|
||||
* @return
|
||||
*/
|
||||
virtual float calculateOutputTemperature(inputType inputValue) {
|
||||
return parameters.a * inputValue * inputValue
|
||||
+ parameters.b * inputValue + parameters.c;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void setInvalid() {
|
||||
outputTemperature = INVALID_TEMPERATURE;
|
||||
outputTemperature.setValid(false);
|
||||
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
||||
sensorMonitor.setToInvalid();
|
||||
}
|
||||
protected:
|
||||
static const int32_t INVALID_UPTIME = 0;
|
||||
|
||||
UsedParameters parameters;
|
||||
|
||||
inputType * inputValue;
|
||||
|
||||
PoolVariableIF *poolVariable;
|
||||
|
||||
gp_float_t outputTemperature;
|
||||
|
||||
LimitMonitor<limitType> sensorMonitor;
|
||||
|
||||
float oldTemperature;
|
||||
timeval uptimeOfOldTemperature;
|
||||
|
||||
void doChildOperation() {
|
||||
if (!poolVariable->isValid()
|
||||
|| !healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
setInvalid();
|
||||
return;
|
||||
}
|
||||
|
||||
outputTemperature = calculateOutputTemperature(*inputValue);
|
||||
outputTemperature.setValid(PoolVariableIF::VALID);
|
||||
|
||||
timeval uptime;
|
||||
Clock::getUptime(&uptime);
|
||||
|
||||
if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) {
|
||||
//In theory, we could use an AbsValueMonitor to monitor the gradient.
|
||||
//But this would require storing the maxGradient in DP and quite some overhead.
|
||||
//The concept of delta limits is a bit strange anyway.
|
||||
float deltaTime;
|
||||
float deltaTemp;
|
||||
|
||||
deltaTime = (uptime.tv_sec + uptime.tv_usec / 1000000.)
|
||||
- (uptimeOfOldTemperature.tv_sec
|
||||
+ uptimeOfOldTemperature.tv_usec / 1000000.);
|
||||
deltaTemp = oldTemperature - outputTemperature;
|
||||
if (deltaTemp < 0) {
|
||||
deltaTemp = -deltaTemp;
|
||||
}
|
||||
if (parameters.gradient < deltaTemp / deltaTime) {
|
||||
triggerEvent(TEMP_SENSOR_GRADIENT);
|
||||
//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 <20>C would be more easy to handle.
|
||||
sensorMonitor.doCheck(outputTemperature.value);
|
||||
|
||||
if (sensorMonitor.isOutOfLimits()) {
|
||||
uptimeOfOldTemperature.tv_sec = INVALID_UPTIME;
|
||||
outputTemperature.setValid(PoolVariableIF::INVALID);
|
||||
outputTemperature = INVALID_TEMPERATURE;
|
||||
} else {
|
||||
oldTemperature = outputTemperature;
|
||||
uptimeOfOldTemperature = uptime;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
float getTemperature() {
|
||||
return outputTemperature;
|
||||
}
|
||||
|
||||
bool isValid() {
|
||||
return outputTemperature.isValid();
|
||||
}
|
||||
|
||||
static const uint16_t ADDRESS_A = 0;
|
||||
static const uint16_t ADDRESS_B = 1;
|
||||
static const uint16_t ADDRESS_C = 2;
|
||||
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.)
|
||||
|
||||
static const uint8_t DOMAIN_ID_SENSOR = 1;
|
||||
|
||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
||||
ReturnValue_t result = sensorMonitor.getParameter(domainId, parameterId,
|
||||
parameterWrapper, newValues, startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
if (domainId != this->DOMAIN_ID_BASE) {
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case ADDRESS_A:
|
||||
parameterWrapper->set(parameters.a);
|
||||
break;
|
||||
case ADDRESS_B:
|
||||
parameterWrapper->set(parameters.b);
|
||||
break;
|
||||
case ADDRESS_C:
|
||||
parameterWrapper->set(parameters.c);
|
||||
break;
|
||||
case ADDRESS_GRADIENT:
|
||||
parameterWrapper->set(parameters.gradient);
|
||||
break;
|
||||
default:
|
||||
return INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
virtual void resetOldState() {
|
||||
sensorMonitor.setToUnchecked();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* TEMPERATURESENSOR_H_ */
|
||||
|
@ -1,114 +1,114 @@
|
||||
#ifndef THERMALCOMPONENTIF_H_
|
||||
#define THERMALCOMPONENTIF_H_
|
||||
|
||||
#include "../events/Event.h"
|
||||
#include "../parameters/HasParametersIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
|
||||
class ThermalComponentIF : public HasParametersIF {
|
||||
public:
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TCS_1;
|
||||
static const Event COMPONENT_TEMP_LOW = MAKE_EVENT(1, SEVERITY::LOW);
|
||||
static const Event COMPONENT_TEMP_HIGH = MAKE_EVENT(2, SEVERITY::LOW);
|
||||
static const Event COMPONENT_TEMP_OOL_LOW = MAKE_EVENT(3, SEVERITY::LOW);
|
||||
static const Event COMPONENT_TEMP_OOL_HIGH = MAKE_EVENT(4, SEVERITY::LOW);
|
||||
static const Event TEMP_NOT_IN_OP_RANGE = MAKE_EVENT(5, SEVERITY::LOW); //!< Is thrown when a device should start-up, but the temperature is out of OP range. P1: thermalState of the component, P2: 0
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::THERMAL_COMPONENT_IF;
|
||||
static const ReturnValue_t INVALID_TARGET_STATE = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t ABOVE_OPERATIONAL_LIMIT = MAKE_RETURN_CODE(0xF1);
|
||||
static const ReturnValue_t BELOW_OPERATIONAL_LIMIT = MAKE_RETURN_CODE(0xF2);
|
||||
|
||||
enum State {
|
||||
OUT_OF_RANGE_LOW = -2,
|
||||
NON_OPERATIONAL_LOW = -1,
|
||||
OPERATIONAL = 0,
|
||||
NON_OPERATIONAL_HIGH = 1,
|
||||
OUT_OF_RANGE_HIGH = 2,
|
||||
OUT_OF_RANGE_LOW_IGNORED = OUT_OF_RANGE_LOW - 10,
|
||||
NON_OPERATIONAL_LOW_IGNORED = NON_OPERATIONAL_LOW - 10,
|
||||
OPERATIONAL_IGNORED = OPERATIONAL + 10,
|
||||
NON_OPERATIONAL_HIGH_IGNORED = NON_OPERATIONAL_HIGH + 10,
|
||||
OUT_OF_RANGE_HIGH_IGNORED = OUT_OF_RANGE_HIGH + 10,
|
||||
UNKNOWN = 20
|
||||
};
|
||||
|
||||
enum StateRequest {
|
||||
STATE_REQUEST_HEATING = 4,
|
||||
STATE_REQUEST_IGNORE = 3,
|
||||
STATE_REQUEST_OPERATIONAL = 1,
|
||||
STATE_REQUEST_NON_OPERATIONAL = 0
|
||||
};
|
||||
|
||||
/**
|
||||
* The elements are ordered by priority, lowest have highest priority
|
||||
*/
|
||||
enum Priority {
|
||||
SAFE = 0, //!< SAFE
|
||||
IDLE, //!< IDLE
|
||||
PAYLOAD, //!< PAYLOAD
|
||||
NUMBER_OF_PRIORITIES //!< MAX_PRIORITY
|
||||
};
|
||||
|
||||
/**
|
||||
* The elements are ordered by priority, lowest have highest priority
|
||||
*/
|
||||
enum HeaterRequest {
|
||||
HEATER_REQUEST_EMERGENCY_OFF = 0, //!< REQUEST_EMERGENCY_OFF
|
||||
HEATER_REQUEST_EMERGENCY_ON, //!< REQUEST_EMERGENCY_ON
|
||||
HEATER_REQUEST_OFF, //!< REQUEST_OFF
|
||||
HEATER_REQUEST_ON, //!< REQUEST_ON
|
||||
HEATER_DONT_CARE //!< DONT_CARE
|
||||
};
|
||||
|
||||
virtual ~ThermalComponentIF() {
|
||||
|
||||
}
|
||||
|
||||
virtual HeaterRequest performOperation(uint8_t opCode) = 0;
|
||||
|
||||
virtual object_id_t getObjectId() = 0;
|
||||
|
||||
virtual uint8_t getDomainId() const = 0;
|
||||
|
||||
virtual void markStateIgnored() = 0;
|
||||
|
||||
virtual float getLowerOpLimit() = 0;
|
||||
|
||||
virtual ReturnValue_t setTargetState(int8_t state) = 0;
|
||||
|
||||
virtual void setOutputInvalid() = 0;
|
||||
|
||||
static bool isOperational(int8_t state) {
|
||||
return ((state == OPERATIONAL) || (state == OPERATIONAL_IGNORED));
|
||||
}
|
||||
|
||||
static bool isOutOfRange(State state) {
|
||||
return ((state == OUT_OF_RANGE_HIGH)
|
||||
|| (state == OUT_OF_RANGE_HIGH_IGNORED)
|
||||
|| (state == OUT_OF_RANGE_LOW)
|
||||
|| (state == OUT_OF_RANGE_LOW_IGNORED) || (state == UNKNOWN));
|
||||
}
|
||||
|
||||
static bool isNonOperational(State state) {
|
||||
return !isOutOfRange(state);
|
||||
}
|
||||
|
||||
static bool isIgnoredState(State state) {
|
||||
switch (state) {
|
||||
case OUT_OF_RANGE_LOW_IGNORED:
|
||||
case OUT_OF_RANGE_HIGH_IGNORED:
|
||||
case NON_OPERATIONAL_LOW_IGNORED:
|
||||
case NON_OPERATIONAL_HIGH_IGNORED:
|
||||
case OPERATIONAL_IGNORED:
|
||||
case UNKNOWN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* THERMALCOMPONENTIF_H_ */
|
||||
#ifndef THERMALCOMPONENTIF_H_
|
||||
#define THERMALCOMPONENTIF_H_
|
||||
|
||||
#include "../events/Event.h"
|
||||
#include "../parameters/HasParametersIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
|
||||
class ThermalComponentIF : public HasParametersIF {
|
||||
public:
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::TCS_1;
|
||||
static const Event COMPONENT_TEMP_LOW = MAKE_EVENT(1, SEVERITY::LOW);
|
||||
static const Event COMPONENT_TEMP_HIGH = MAKE_EVENT(2, SEVERITY::LOW);
|
||||
static const Event COMPONENT_TEMP_OOL_LOW = MAKE_EVENT(3, SEVERITY::LOW);
|
||||
static const Event COMPONENT_TEMP_OOL_HIGH = MAKE_EVENT(4, SEVERITY::LOW);
|
||||
static const Event TEMP_NOT_IN_OP_RANGE = MAKE_EVENT(5, SEVERITY::LOW); //!< Is thrown when a device should start-up, but the temperature is out of OP range. P1: thermalState of the component, P2: 0
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::THERMAL_COMPONENT_IF;
|
||||
static const ReturnValue_t INVALID_TARGET_STATE = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t ABOVE_OPERATIONAL_LIMIT = MAKE_RETURN_CODE(0xF1);
|
||||
static const ReturnValue_t BELOW_OPERATIONAL_LIMIT = MAKE_RETURN_CODE(0xF2);
|
||||
|
||||
enum State {
|
||||
OUT_OF_RANGE_LOW = -2,
|
||||
NON_OPERATIONAL_LOW = -1,
|
||||
OPERATIONAL = 0,
|
||||
NON_OPERATIONAL_HIGH = 1,
|
||||
OUT_OF_RANGE_HIGH = 2,
|
||||
OUT_OF_RANGE_LOW_IGNORED = OUT_OF_RANGE_LOW - 10,
|
||||
NON_OPERATIONAL_LOW_IGNORED = NON_OPERATIONAL_LOW - 10,
|
||||
OPERATIONAL_IGNORED = OPERATIONAL + 10,
|
||||
NON_OPERATIONAL_HIGH_IGNORED = NON_OPERATIONAL_HIGH + 10,
|
||||
OUT_OF_RANGE_HIGH_IGNORED = OUT_OF_RANGE_HIGH + 10,
|
||||
UNKNOWN = 20
|
||||
};
|
||||
|
||||
enum StateRequest {
|
||||
STATE_REQUEST_HEATING = 4,
|
||||
STATE_REQUEST_IGNORE = 3,
|
||||
STATE_REQUEST_OPERATIONAL = 1,
|
||||
STATE_REQUEST_NON_OPERATIONAL = 0
|
||||
};
|
||||
|
||||
/**
|
||||
* The elements are ordered by priority, lowest have highest priority
|
||||
*/
|
||||
enum Priority {
|
||||
SAFE = 0, //!< SAFE
|
||||
IDLE, //!< IDLE
|
||||
PAYLOAD, //!< PAYLOAD
|
||||
NUMBER_OF_PRIORITIES //!< MAX_PRIORITY
|
||||
};
|
||||
|
||||
/**
|
||||
* The elements are ordered by priority, lowest have highest priority
|
||||
*/
|
||||
enum HeaterRequest {
|
||||
HEATER_REQUEST_EMERGENCY_OFF = 0, //!< REQUEST_EMERGENCY_OFF
|
||||
HEATER_REQUEST_EMERGENCY_ON, //!< REQUEST_EMERGENCY_ON
|
||||
HEATER_REQUEST_OFF, //!< REQUEST_OFF
|
||||
HEATER_REQUEST_ON, //!< REQUEST_ON
|
||||
HEATER_DONT_CARE //!< DONT_CARE
|
||||
};
|
||||
|
||||
virtual ~ThermalComponentIF() {
|
||||
|
||||
}
|
||||
|
||||
virtual HeaterRequest performOperation(uint8_t opCode) = 0;
|
||||
|
||||
virtual object_id_t getObjectId() = 0;
|
||||
|
||||
virtual uint8_t getDomainId() const = 0;
|
||||
|
||||
virtual void markStateIgnored() = 0;
|
||||
|
||||
virtual float getLowerOpLimit() = 0;
|
||||
|
||||
virtual ReturnValue_t setTargetState(int8_t state) = 0;
|
||||
|
||||
virtual void setOutputInvalid() = 0;
|
||||
|
||||
static bool isOperational(int8_t state) {
|
||||
return ((state == OPERATIONAL) || (state == OPERATIONAL_IGNORED));
|
||||
}
|
||||
|
||||
static bool isOutOfRange(State state) {
|
||||
return ((state == OUT_OF_RANGE_HIGH)
|
||||
|| (state == OUT_OF_RANGE_HIGH_IGNORED)
|
||||
|| (state == OUT_OF_RANGE_LOW)
|
||||
|| (state == OUT_OF_RANGE_LOW_IGNORED) || (state == UNKNOWN));
|
||||
}
|
||||
|
||||
static bool isNonOperational(State state) {
|
||||
return !isOutOfRange(state);
|
||||
}
|
||||
|
||||
static bool isIgnoredState(State state) {
|
||||
switch (state) {
|
||||
case OUT_OF_RANGE_LOW_IGNORED:
|
||||
case OUT_OF_RANGE_HIGH_IGNORED:
|
||||
case NON_OPERATIONAL_LOW_IGNORED:
|
||||
case NON_OPERATIONAL_HIGH_IGNORED:
|
||||
case OPERATIONAL_IGNORED:
|
||||
case UNKNOWN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* THERMALCOMPONENTIF_H_ */
|
||||
|
@ -1,288 +1,288 @@
|
||||
#include "../monitoring/LimitViolationReporter.h"
|
||||
#include "../monitoring/MonitoringMessageContent.h"
|
||||
#include "ThermalModule.h"
|
||||
|
||||
#include "AbstractTemperatureSensor.h"
|
||||
|
||||
ThermalModule::ThermalModule(uint32_t moduleTemperaturePoolId,
|
||||
uint32_t currentStatePoolId, uint32_t targetStatePoolId,
|
||||
GlobDataSet *dataSet, Parameters parameters,
|
||||
RedundantHeater::Parameters heaterParameters) :
|
||||
oldStrategy(ACTIVE_SINGLE), survivalTargetTemp(0), targetTemp(0), heating(
|
||||
false), parameters(parameters), moduleTemperature(
|
||||
moduleTemperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE), currentState(
|
||||
currentStatePoolId, dataSet, PoolVariableIF::VAR_WRITE), targetState(
|
||||
targetStatePoolId, dataSet, PoolVariableIF::VAR_READ) {
|
||||
heater = new RedundantHeater(heaterParameters);
|
||||
}
|
||||
|
||||
ThermalModule::ThermalModule(uint32_t moduleTemperaturePoolId, GlobDataSet* dataSet) :
|
||||
oldStrategy(ACTIVE_SINGLE), survivalTargetTemp(0), targetTemp(0), heating(
|
||||
false), parameters( { 0, 0 }), moduleTemperature(
|
||||
moduleTemperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE), heater(
|
||||
NULL), currentState(PoolVariableIF::INVALID, dataSet,
|
||||
PoolVariableIF::VAR_WRITE), targetState(PoolVariableIF::INVALID,
|
||||
dataSet, PoolVariableIF::VAR_READ) {
|
||||
}
|
||||
|
||||
ThermalModule::~ThermalModule() {
|
||||
delete heater;
|
||||
}
|
||||
|
||||
void ThermalModule::performOperation(uint8_t opCode) {
|
||||
if (heater != NULL) {
|
||||
heater->performOperation(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ThermalModule::performMode(Strategy strategy) {
|
||||
calculateTemperature();
|
||||
|
||||
bool safeOnly = (strategy == ACTIVE_SURVIVAL);
|
||||
ThermalComponentIF::HeaterRequest componentHeaterRequest =
|
||||
letComponentsPerformAndDeciceIfWeNeedToHeat(safeOnly);
|
||||
|
||||
if (heater == NULL) {
|
||||
informComponentsAboutHeaterState(false, NONE);
|
||||
return;
|
||||
}
|
||||
|
||||
bool heating = calculateModuleHeaterRequestAndSetModuleStatus(strategy);
|
||||
|
||||
if (componentHeaterRequest != ThermalComponentIF::HEATER_DONT_CARE) {
|
||||
//Components overwrite the module request.
|
||||
heating = ((componentHeaterRequest
|
||||
== ThermalComponentIF::HEATER_REQUEST_ON)
|
||||
|| (componentHeaterRequest
|
||||
== ThermalComponentIF::HEATER_REQUEST_EMERGENCY_ON));
|
||||
}
|
||||
|
||||
bool dual = (strategy == ACTIVE_DUAL);
|
||||
|
||||
if (strategy == PASSIVE) {
|
||||
informComponentsAboutHeaterState(false, NONE);
|
||||
if (oldStrategy != PASSIVE) {
|
||||
heater->set(false, false, true);
|
||||
}
|
||||
} else {
|
||||
if (safeOnly) {
|
||||
informComponentsAboutHeaterState(heating, SAFE);
|
||||
} else {
|
||||
informComponentsAboutHeaterState(heating, ALL);
|
||||
}
|
||||
heater->set(heating, dual);
|
||||
}
|
||||
oldStrategy = strategy;
|
||||
}
|
||||
|
||||
float ThermalModule::getTemperature() {
|
||||
return moduleTemperature;
|
||||
}
|
||||
|
||||
void ThermalModule::registerSensor(AbstractTemperatureSensor * sensor) {
|
||||
sensors.push_back(sensor);
|
||||
}
|
||||
|
||||
void ThermalModule::registerComponent(ThermalComponentIF* component,
|
||||
ThermalComponentIF::Priority priority) {
|
||||
components.push_back(ComponentData( { component, priority, ThermalComponentIF::HEATER_DONT_CARE }));
|
||||
}
|
||||
|
||||
void ThermalModule::calculateTemperature() {
|
||||
uint32_t numberOfValidSensors = 0;
|
||||
moduleTemperature = 0;
|
||||
std::list<AbstractTemperatureSensor *>::iterator iter = sensors.begin();
|
||||
for (; iter != sensors.end(); iter++) {
|
||||
if ((*iter)->isValid()) {
|
||||
moduleTemperature = moduleTemperature + (*iter)->getTemperature();
|
||||
numberOfValidSensors++;
|
||||
}
|
||||
}
|
||||
if (numberOfValidSensors != 0) {
|
||||
moduleTemperature = moduleTemperature / numberOfValidSensors;
|
||||
moduleTemperature.setValid(PoolVariableIF::VALID);
|
||||
} else {
|
||||
moduleTemperature = INVALID_TEMPERATURE;
|
||||
moduleTemperature.setValid(PoolVariableIF::INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
ThermalComponentIF* ThermalModule::findComponent(object_id_t objectId) {
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
if (iter->component->getObjectId() == objectId) {
|
||||
return iter->component;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ThermalComponentIF::HeaterRequest ThermalModule::letComponentsPerformAndDeciceIfWeNeedToHeat(
|
||||
bool safeOnly) {
|
||||
ThermalComponentIF::HeaterRequest heaterRequests[ThermalComponentIF::NUMBER_OF_PRIORITIES];
|
||||
|
||||
survivalTargetTemp = -999;
|
||||
targetTemp = -999;
|
||||
|
||||
for (uint8_t i = 0; i < ThermalComponentIF::NUMBER_OF_PRIORITIES; i++) {
|
||||
heaterRequests[i] = ThermalComponentIF::HEATER_DONT_CARE;
|
||||
}
|
||||
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
updateTargetTemperatures(iter->component,
|
||||
iter->priority == ThermalComponentIF::SAFE);
|
||||
ThermalComponentIF::HeaterRequest request =
|
||||
iter->component->performOperation(0);
|
||||
iter->request = request;
|
||||
if (request != ThermalComponentIF::HEATER_DONT_CARE) {
|
||||
if (request < heaterRequests[iter->priority]) {
|
||||
heaterRequests[iter->priority] = request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!safeOnly) {
|
||||
for (uint8_t i = ThermalComponentIF::NUMBER_OF_PRIORITIES - 1; i > 0;
|
||||
i--) {
|
||||
if (heaterRequests[i - 1] == ThermalComponentIF::HEATER_DONT_CARE) {
|
||||
heaterRequests[i - 1] = heaterRequests[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return heaterRequests[0];
|
||||
}
|
||||
|
||||
void ThermalModule::informComponentsAboutHeaterState(bool heaterIsOn,
|
||||
Informee whomToInform) {
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
switch (whomToInform) {
|
||||
case ALL:
|
||||
break;
|
||||
case SAFE:
|
||||
if (!(iter->priority == ThermalComponentIF::SAFE)) {
|
||||
iter->component->markStateIgnored();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case NONE:
|
||||
iter->component->markStateIgnored();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (heaterIsOn) {
|
||||
if ((iter->request
|
||||
== ThermalComponentIF::HEATER_REQUEST_EMERGENCY_OFF)
|
||||
|| (iter->request == ThermalComponentIF::HEATER_REQUEST_OFF)) {
|
||||
iter->component->markStateIgnored();
|
||||
}
|
||||
} else {
|
||||
if ((iter->request
|
||||
== ThermalComponentIF::HEATER_REQUEST_EMERGENCY_ON)
|
||||
|| (iter->request == ThermalComponentIF::HEATER_REQUEST_ON)) {
|
||||
iter->component->markStateIgnored();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThermalModule::initialize(PowerSwitchIF* powerSwitch) {
|
||||
if (heater != NULL) {
|
||||
heater->setPowerSwitcher(powerSwitch);
|
||||
}
|
||||
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
float componentLowerOpLimit = iter->component->getLowerOpLimit();
|
||||
if (iter->priority == ThermalComponentIF::SAFE) {
|
||||
if (componentLowerOpLimit > survivalTargetTemp) {
|
||||
survivalTargetTemp = componentLowerOpLimit;
|
||||
}
|
||||
} else {
|
||||
if (componentLowerOpLimit > targetTemp) {
|
||||
targetTemp = componentLowerOpLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (survivalTargetTemp > targetTemp) {
|
||||
targetTemp = survivalTargetTemp;
|
||||
}
|
||||
}
|
||||
|
||||
bool ThermalModule::calculateModuleHeaterRequestAndSetModuleStatus(
|
||||
Strategy strategy) {
|
||||
currentState.setValid(PoolVariableIF::VALID);
|
||||
if (moduleTemperature == INVALID_TEMPERATURE) {
|
||||
currentState = UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
float limit = targetTemp;
|
||||
bool heaterRequest = false;
|
||||
if (strategy == ACTIVE_SURVIVAL) {
|
||||
limit = survivalTargetTemp;
|
||||
}
|
||||
|
||||
if (moduleTemperature >= limit) {
|
||||
currentState = OPERATIONAL;
|
||||
} else {
|
||||
currentState = NON_OPERATIONAL;
|
||||
}
|
||||
|
||||
limit += parameters.heaterOn;
|
||||
|
||||
if (heating) {
|
||||
limit += parameters.hysteresis;
|
||||
}
|
||||
|
||||
if (targetState == STATE_REQUEST_HEATING) {
|
||||
if (moduleTemperature < limit) {
|
||||
heaterRequest = true;
|
||||
} else {
|
||||
heaterRequest = false;
|
||||
}
|
||||
}
|
||||
|
||||
heating = heaterRequest;
|
||||
|
||||
return heaterRequest;
|
||||
}
|
||||
|
||||
void ThermalModule::setHeating(bool on) {
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t writableTargetState(targetState.getDataPoolId(),
|
||||
&mySet, PoolVariableIF::VAR_WRITE);
|
||||
if (on) {
|
||||
writableTargetState = STATE_REQUEST_HEATING;
|
||||
} else {
|
||||
writableTargetState = STATE_REQUEST_PASSIVE;
|
||||
}
|
||||
mySet.commit(PoolVariableIF::VALID);
|
||||
}
|
||||
|
||||
void ThermalModule::updateTargetTemperatures(ThermalComponentIF* component,
|
||||
bool isSafe) {
|
||||
if (isSafe) {
|
||||
if (component->getLowerOpLimit() > survivalTargetTemp) {
|
||||
survivalTargetTemp = component->getLowerOpLimit();
|
||||
}
|
||||
} else {
|
||||
if (component->getLowerOpLimit() > targetTemp) {
|
||||
targetTemp = component->getLowerOpLimit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThermalModule::setOutputInvalid() {
|
||||
moduleTemperature = INVALID_TEMPERATURE;
|
||||
moduleTemperature.setValid(PoolVariableIF::INVALID);
|
||||
currentState.setValid(PoolVariableIF::INVALID);
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
iter->component->setOutputInvalid();
|
||||
}
|
||||
if (heater != NULL) {
|
||||
heater->set(false,true);
|
||||
}
|
||||
}
|
||||
#include "../monitoring/LimitViolationReporter.h"
|
||||
#include "../monitoring/MonitoringMessageContent.h"
|
||||
#include "ThermalModule.h"
|
||||
|
||||
#include "AbstractTemperatureSensor.h"
|
||||
|
||||
ThermalModule::ThermalModule(uint32_t moduleTemperaturePoolId,
|
||||
uint32_t currentStatePoolId, uint32_t targetStatePoolId,
|
||||
GlobDataSet *dataSet, Parameters parameters,
|
||||
RedundantHeater::Parameters heaterParameters) :
|
||||
oldStrategy(ACTIVE_SINGLE), survivalTargetTemp(0), targetTemp(0), heating(
|
||||
false), parameters(parameters), moduleTemperature(
|
||||
moduleTemperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE), currentState(
|
||||
currentStatePoolId, dataSet, PoolVariableIF::VAR_WRITE), targetState(
|
||||
targetStatePoolId, dataSet, PoolVariableIF::VAR_READ) {
|
||||
heater = new RedundantHeater(heaterParameters);
|
||||
}
|
||||
|
||||
ThermalModule::ThermalModule(uint32_t moduleTemperaturePoolId, GlobDataSet* dataSet) :
|
||||
oldStrategy(ACTIVE_SINGLE), survivalTargetTemp(0), targetTemp(0), heating(
|
||||
false), parameters( { 0, 0 }), moduleTemperature(
|
||||
moduleTemperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE), heater(
|
||||
NULL), currentState(PoolVariableIF::INVALID, dataSet,
|
||||
PoolVariableIF::VAR_WRITE), targetState(PoolVariableIF::INVALID,
|
||||
dataSet, PoolVariableIF::VAR_READ) {
|
||||
}
|
||||
|
||||
ThermalModule::~ThermalModule() {
|
||||
delete heater;
|
||||
}
|
||||
|
||||
void ThermalModule::performOperation(uint8_t opCode) {
|
||||
if (heater != NULL) {
|
||||
heater->performOperation(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ThermalModule::performMode(Strategy strategy) {
|
||||
calculateTemperature();
|
||||
|
||||
bool safeOnly = (strategy == ACTIVE_SURVIVAL);
|
||||
ThermalComponentIF::HeaterRequest componentHeaterRequest =
|
||||
letComponentsPerformAndDeciceIfWeNeedToHeat(safeOnly);
|
||||
|
||||
if (heater == NULL) {
|
||||
informComponentsAboutHeaterState(false, NONE);
|
||||
return;
|
||||
}
|
||||
|
||||
bool heating = calculateModuleHeaterRequestAndSetModuleStatus(strategy);
|
||||
|
||||
if (componentHeaterRequest != ThermalComponentIF::HEATER_DONT_CARE) {
|
||||
//Components overwrite the module request.
|
||||
heating = ((componentHeaterRequest
|
||||
== ThermalComponentIF::HEATER_REQUEST_ON)
|
||||
|| (componentHeaterRequest
|
||||
== ThermalComponentIF::HEATER_REQUEST_EMERGENCY_ON));
|
||||
}
|
||||
|
||||
bool dual = (strategy == ACTIVE_DUAL);
|
||||
|
||||
if (strategy == PASSIVE) {
|
||||
informComponentsAboutHeaterState(false, NONE);
|
||||
if (oldStrategy != PASSIVE) {
|
||||
heater->set(false, false, true);
|
||||
}
|
||||
} else {
|
||||
if (safeOnly) {
|
||||
informComponentsAboutHeaterState(heating, SAFE);
|
||||
} else {
|
||||
informComponentsAboutHeaterState(heating, ALL);
|
||||
}
|
||||
heater->set(heating, dual);
|
||||
}
|
||||
oldStrategy = strategy;
|
||||
}
|
||||
|
||||
float ThermalModule::getTemperature() {
|
||||
return moduleTemperature;
|
||||
}
|
||||
|
||||
void ThermalModule::registerSensor(AbstractTemperatureSensor * sensor) {
|
||||
sensors.push_back(sensor);
|
||||
}
|
||||
|
||||
void ThermalModule::registerComponent(ThermalComponentIF* component,
|
||||
ThermalComponentIF::Priority priority) {
|
||||
components.push_back(ComponentData( { component, priority, ThermalComponentIF::HEATER_DONT_CARE }));
|
||||
}
|
||||
|
||||
void ThermalModule::calculateTemperature() {
|
||||
uint32_t numberOfValidSensors = 0;
|
||||
moduleTemperature = 0;
|
||||
std::list<AbstractTemperatureSensor *>::iterator iter = sensors.begin();
|
||||
for (; iter != sensors.end(); iter++) {
|
||||
if ((*iter)->isValid()) {
|
||||
moduleTemperature = moduleTemperature + (*iter)->getTemperature();
|
||||
numberOfValidSensors++;
|
||||
}
|
||||
}
|
||||
if (numberOfValidSensors != 0) {
|
||||
moduleTemperature = moduleTemperature / numberOfValidSensors;
|
||||
moduleTemperature.setValid(PoolVariableIF::VALID);
|
||||
} else {
|
||||
moduleTemperature = INVALID_TEMPERATURE;
|
||||
moduleTemperature.setValid(PoolVariableIF::INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
ThermalComponentIF* ThermalModule::findComponent(object_id_t objectId) {
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
if (iter->component->getObjectId() == objectId) {
|
||||
return iter->component;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ThermalComponentIF::HeaterRequest ThermalModule::letComponentsPerformAndDeciceIfWeNeedToHeat(
|
||||
bool safeOnly) {
|
||||
ThermalComponentIF::HeaterRequest heaterRequests[ThermalComponentIF::NUMBER_OF_PRIORITIES];
|
||||
|
||||
survivalTargetTemp = -999;
|
||||
targetTemp = -999;
|
||||
|
||||
for (uint8_t i = 0; i < ThermalComponentIF::NUMBER_OF_PRIORITIES; i++) {
|
||||
heaterRequests[i] = ThermalComponentIF::HEATER_DONT_CARE;
|
||||
}
|
||||
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
updateTargetTemperatures(iter->component,
|
||||
iter->priority == ThermalComponentIF::SAFE);
|
||||
ThermalComponentIF::HeaterRequest request =
|
||||
iter->component->performOperation(0);
|
||||
iter->request = request;
|
||||
if (request != ThermalComponentIF::HEATER_DONT_CARE) {
|
||||
if (request < heaterRequests[iter->priority]) {
|
||||
heaterRequests[iter->priority] = request;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!safeOnly) {
|
||||
for (uint8_t i = ThermalComponentIF::NUMBER_OF_PRIORITIES - 1; i > 0;
|
||||
i--) {
|
||||
if (heaterRequests[i - 1] == ThermalComponentIF::HEATER_DONT_CARE) {
|
||||
heaterRequests[i - 1] = heaterRequests[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return heaterRequests[0];
|
||||
}
|
||||
|
||||
void ThermalModule::informComponentsAboutHeaterState(bool heaterIsOn,
|
||||
Informee whomToInform) {
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
switch (whomToInform) {
|
||||
case ALL:
|
||||
break;
|
||||
case SAFE:
|
||||
if (!(iter->priority == ThermalComponentIF::SAFE)) {
|
||||
iter->component->markStateIgnored();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case NONE:
|
||||
iter->component->markStateIgnored();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (heaterIsOn) {
|
||||
if ((iter->request
|
||||
== ThermalComponentIF::HEATER_REQUEST_EMERGENCY_OFF)
|
||||
|| (iter->request == ThermalComponentIF::HEATER_REQUEST_OFF)) {
|
||||
iter->component->markStateIgnored();
|
||||
}
|
||||
} else {
|
||||
if ((iter->request
|
||||
== ThermalComponentIF::HEATER_REQUEST_EMERGENCY_ON)
|
||||
|| (iter->request == ThermalComponentIF::HEATER_REQUEST_ON)) {
|
||||
iter->component->markStateIgnored();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThermalModule::initialize(PowerSwitchIF* powerSwitch) {
|
||||
if (heater != NULL) {
|
||||
heater->setPowerSwitcher(powerSwitch);
|
||||
}
|
||||
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
float componentLowerOpLimit = iter->component->getLowerOpLimit();
|
||||
if (iter->priority == ThermalComponentIF::SAFE) {
|
||||
if (componentLowerOpLimit > survivalTargetTemp) {
|
||||
survivalTargetTemp = componentLowerOpLimit;
|
||||
}
|
||||
} else {
|
||||
if (componentLowerOpLimit > targetTemp) {
|
||||
targetTemp = componentLowerOpLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (survivalTargetTemp > targetTemp) {
|
||||
targetTemp = survivalTargetTemp;
|
||||
}
|
||||
}
|
||||
|
||||
bool ThermalModule::calculateModuleHeaterRequestAndSetModuleStatus(
|
||||
Strategy strategy) {
|
||||
currentState.setValid(PoolVariableIF::VALID);
|
||||
if (moduleTemperature == INVALID_TEMPERATURE) {
|
||||
currentState = UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
float limit = targetTemp;
|
||||
bool heaterRequest = false;
|
||||
if (strategy == ACTIVE_SURVIVAL) {
|
||||
limit = survivalTargetTemp;
|
||||
}
|
||||
|
||||
if (moduleTemperature >= limit) {
|
||||
currentState = OPERATIONAL;
|
||||
} else {
|
||||
currentState = NON_OPERATIONAL;
|
||||
}
|
||||
|
||||
limit += parameters.heaterOn;
|
||||
|
||||
if (heating) {
|
||||
limit += parameters.hysteresis;
|
||||
}
|
||||
|
||||
if (targetState == STATE_REQUEST_HEATING) {
|
||||
if (moduleTemperature < limit) {
|
||||
heaterRequest = true;
|
||||
} else {
|
||||
heaterRequest = false;
|
||||
}
|
||||
}
|
||||
|
||||
heating = heaterRequest;
|
||||
|
||||
return heaterRequest;
|
||||
}
|
||||
|
||||
void ThermalModule::setHeating(bool on) {
|
||||
GlobDataSet mySet;
|
||||
gp_int8_t writableTargetState(targetState.getDataPoolId(),
|
||||
&mySet, PoolVariableIF::VAR_WRITE);
|
||||
if (on) {
|
||||
writableTargetState = STATE_REQUEST_HEATING;
|
||||
} else {
|
||||
writableTargetState = STATE_REQUEST_PASSIVE;
|
||||
}
|
||||
mySet.commit(PoolVariableIF::VALID);
|
||||
}
|
||||
|
||||
void ThermalModule::updateTargetTemperatures(ThermalComponentIF* component,
|
||||
bool isSafe) {
|
||||
if (isSafe) {
|
||||
if (component->getLowerOpLimit() > survivalTargetTemp) {
|
||||
survivalTargetTemp = component->getLowerOpLimit();
|
||||
}
|
||||
} else {
|
||||
if (component->getLowerOpLimit() > targetTemp) {
|
||||
targetTemp = component->getLowerOpLimit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ThermalModule::setOutputInvalid() {
|
||||
moduleTemperature = INVALID_TEMPERATURE;
|
||||
moduleTemperature.setValid(PoolVariableIF::INVALID);
|
||||
currentState.setValid(PoolVariableIF::INVALID);
|
||||
std::list<ComponentData>::iterator iter = components.begin();
|
||||
for (; iter != components.end(); iter++) {
|
||||
iter->component->setOutputInvalid();
|
||||
}
|
||||
if (heater != NULL) {
|
||||
heater->set(false,true);
|
||||
}
|
||||
}
|
||||
|
@ -1,95 +1,95 @@
|
||||
#ifndef THERMALMODULE_H_
|
||||
#define THERMALMODULE_H_
|
||||
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../devicehandlers/HealthDevice.h"
|
||||
#include "../events/EventReportingProxyIF.h"
|
||||
#include "ThermalModuleIF.h"
|
||||
#include <list>
|
||||
#include "tcsDefinitions.h"
|
||||
#include "RedundantHeater.h"
|
||||
class PowerSwitchIF;
|
||||
|
||||
/**
|
||||
* @brief Allows creation of different thermal control domains within a system.
|
||||
*/
|
||||
class ThermalModule: public ThermalModuleIF {
|
||||
friend class ThermalController;
|
||||
public:
|
||||
struct Parameters {
|
||||
float heaterOn;
|
||||
float hysteresis;
|
||||
};
|
||||
|
||||
ThermalModule(uint32_t moduleTemperaturePoolId, uint32_t currentStatePoolId,
|
||||
uint32_t targetStatePoolId, GlobDataSet *dataSet, Parameters parameters,
|
||||
RedundantHeater::Parameters heaterParameters);
|
||||
|
||||
ThermalModule(uint32_t moduleTemperaturePoolId, GlobDataSet *dataSet);
|
||||
|
||||
virtual ~ThermalModule();
|
||||
|
||||
void performOperation(uint8_t opCode);
|
||||
|
||||
void performMode(Strategy strategy);
|
||||
|
||||
float getTemperature();
|
||||
|
||||
void registerSensor(AbstractTemperatureSensor *sensor);
|
||||
|
||||
void registerComponent(ThermalComponentIF *component,
|
||||
ThermalComponentIF::Priority priority);
|
||||
|
||||
ThermalComponentIF *findComponent(object_id_t objectId);
|
||||
|
||||
void initialize(PowerSwitchIF* powerSwitch);
|
||||
|
||||
void setHeating(bool on);
|
||||
|
||||
virtual void setOutputInvalid();
|
||||
|
||||
protected:
|
||||
enum Informee {
|
||||
ALL, SAFE, NONE
|
||||
};
|
||||
|
||||
struct ComponentData {
|
||||
ThermalComponentIF *component;
|
||||
ThermalComponentIF::Priority priority;
|
||||
ThermalComponentIF::HeaterRequest request;
|
||||
};
|
||||
|
||||
Strategy oldStrategy;
|
||||
|
||||
float survivalTargetTemp;
|
||||
|
||||
float targetTemp;
|
||||
|
||||
bool heating;
|
||||
|
||||
Parameters parameters;
|
||||
|
||||
gp_float_t moduleTemperature;
|
||||
|
||||
RedundantHeater *heater;
|
||||
|
||||
gp_int8_t currentState;
|
||||
gp_int8_t targetState;
|
||||
|
||||
std::list<AbstractTemperatureSensor *> sensors;
|
||||
std::list<ComponentData> components;
|
||||
|
||||
void calculateTemperature();
|
||||
|
||||
ThermalComponentIF::HeaterRequest letComponentsPerformAndDeciceIfWeNeedToHeat(bool safeOnly);
|
||||
|
||||
void informComponentsAboutHeaterState(bool heaterIsOn,
|
||||
Informee whomToInform);
|
||||
|
||||
bool calculateModuleHeaterRequestAndSetModuleStatus(Strategy strategy);
|
||||
|
||||
void updateTargetTemperatures(ThermalComponentIF *component, bool isSafe);
|
||||
};
|
||||
|
||||
#endif /* THERMALMODULE_H_ */
|
||||
#ifndef THERMALMODULE_H_
|
||||
#define THERMALMODULE_H_
|
||||
|
||||
#include "../datapoolglob/GlobalDataSet.h"
|
||||
#include "../datapoolglob/GlobalPoolVariable.h"
|
||||
#include "../devicehandlers/HealthDevice.h"
|
||||
#include "../events/EventReportingProxyIF.h"
|
||||
#include "ThermalModuleIF.h"
|
||||
#include <list>
|
||||
#include "tcsDefinitions.h"
|
||||
#include "RedundantHeater.h"
|
||||
class PowerSwitchIF;
|
||||
|
||||
/**
|
||||
* @brief Allows creation of different thermal control domains within a system.
|
||||
*/
|
||||
class ThermalModule: public ThermalModuleIF {
|
||||
friend class ThermalController;
|
||||
public:
|
||||
struct Parameters {
|
||||
float heaterOn;
|
||||
float hysteresis;
|
||||
};
|
||||
|
||||
ThermalModule(uint32_t moduleTemperaturePoolId, uint32_t currentStatePoolId,
|
||||
uint32_t targetStatePoolId, GlobDataSet *dataSet, Parameters parameters,
|
||||
RedundantHeater::Parameters heaterParameters);
|
||||
|
||||
ThermalModule(uint32_t moduleTemperaturePoolId, GlobDataSet *dataSet);
|
||||
|
||||
virtual ~ThermalModule();
|
||||
|
||||
void performOperation(uint8_t opCode);
|
||||
|
||||
void performMode(Strategy strategy);
|
||||
|
||||
float getTemperature();
|
||||
|
||||
void registerSensor(AbstractTemperatureSensor *sensor);
|
||||
|
||||
void registerComponent(ThermalComponentIF *component,
|
||||
ThermalComponentIF::Priority priority);
|
||||
|
||||
ThermalComponentIF *findComponent(object_id_t objectId);
|
||||
|
||||
void initialize(PowerSwitchIF* powerSwitch);
|
||||
|
||||
void setHeating(bool on);
|
||||
|
||||
virtual void setOutputInvalid();
|
||||
|
||||
protected:
|
||||
enum Informee {
|
||||
ALL, SAFE, NONE
|
||||
};
|
||||
|
||||
struct ComponentData {
|
||||
ThermalComponentIF *component;
|
||||
ThermalComponentIF::Priority priority;
|
||||
ThermalComponentIF::HeaterRequest request;
|
||||
};
|
||||
|
||||
Strategy oldStrategy;
|
||||
|
||||
float survivalTargetTemp;
|
||||
|
||||
float targetTemp;
|
||||
|
||||
bool heating;
|
||||
|
||||
Parameters parameters;
|
||||
|
||||
gp_float_t moduleTemperature;
|
||||
|
||||
RedundantHeater *heater;
|
||||
|
||||
gp_int8_t currentState;
|
||||
gp_int8_t targetState;
|
||||
|
||||
std::list<AbstractTemperatureSensor *> sensors;
|
||||
std::list<ComponentData> components;
|
||||
|
||||
void calculateTemperature();
|
||||
|
||||
ThermalComponentIF::HeaterRequest letComponentsPerformAndDeciceIfWeNeedToHeat(bool safeOnly);
|
||||
|
||||
void informComponentsAboutHeaterState(bool heaterIsOn,
|
||||
Informee whomToInform);
|
||||
|
||||
bool calculateModuleHeaterRequestAndSetModuleStatus(Strategy strategy);
|
||||
|
||||
void updateTargetTemperatures(ThermalComponentIF *component, bool isSafe);
|
||||
};
|
||||
|
||||
#endif /* THERMALMODULE_H_ */
|
||||
|
@ -1,68 +1,68 @@
|
||||
#include "../thermal/ThermalMonitor.h"
|
||||
#include "../thermal/ThermalComponentIF.h"
|
||||
#include "../monitoring/MonitoringIF.h"
|
||||
ThermalMonitor::~ThermalMonitor() {
|
||||
}
|
||||
|
||||
void ThermalMonitor::sendTransitionEvent(float currentValue,
|
||||
ReturnValue_t state) {
|
||||
switch (state) {
|
||||
case MonitoringIF::BELOW_LOW_LIMIT:
|
||||
EventManagerIF::triggerEvent(reportingId,
|
||||
ThermalComponentIF::COMPONENT_TEMP_OOL_LOW, state);
|
||||
break;
|
||||
case MonitoringIF::ABOVE_HIGH_LIMIT:
|
||||
EventManagerIF::triggerEvent(reportingId,
|
||||
ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH, state);
|
||||
break;
|
||||
case ThermalComponentIF::BELOW_OPERATIONAL_LIMIT:
|
||||
EventManagerIF::triggerEvent(reportingId,
|
||||
ThermalComponentIF::COMPONENT_TEMP_LOW, state);
|
||||
break;
|
||||
case ThermalComponentIF::ABOVE_OPERATIONAL_LIMIT:
|
||||
EventManagerIF::triggerEvent(reportingId,
|
||||
ThermalComponentIF::COMPONENT_TEMP_HIGH, state);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool ThermalMonitor::isAboveHighLimit() {
|
||||
if (oldState == ThermalComponentIF::ABOVE_OPERATIONAL_LIMIT) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t ThermalMonitor::translateState(ThermalComponentIF::State state, float sample, float lowerLimit,
|
||||
float upperLimit, bool componentIsOperational) {
|
||||
if (ThermalComponentIF::isIgnoredState(state)) {
|
||||
setToUnchecked();
|
||||
return MonitoringIF::UNCHECKED;
|
||||
}
|
||||
switch (state) {
|
||||
case ThermalComponentIF::OUT_OF_RANGE_LOW:
|
||||
return monitorStateIs(MonitoringIF::BELOW_LOW_LIMIT, sample, lowerLimit);
|
||||
case ThermalComponentIF::NON_OPERATIONAL_LOW:
|
||||
if (componentIsOperational) {
|
||||
return monitorStateIs(ThermalComponentIF::BELOW_OPERATIONAL_LIMIT, sample, lowerLimit);
|
||||
} else {
|
||||
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
|
||||
}
|
||||
case ThermalComponentIF::OPERATIONAL:
|
||||
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
|
||||
case ThermalComponentIF::NON_OPERATIONAL_HIGH:
|
||||
if (componentIsOperational) {
|
||||
return monitorStateIs(ThermalComponentIF::ABOVE_OPERATIONAL_LIMIT, sample, upperLimit);
|
||||
} else {
|
||||
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
|
||||
}
|
||||
case ThermalComponentIF::OUT_OF_RANGE_HIGH:
|
||||
return monitorStateIs(MonitoringIF::ABOVE_HIGH_LIMIT, sample, upperLimit);
|
||||
default:
|
||||
//Never reached, all states covered.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
#include "../thermal/ThermalMonitor.h"
|
||||
#include "../thermal/ThermalComponentIF.h"
|
||||
#include "../monitoring/MonitoringIF.h"
|
||||
ThermalMonitor::~ThermalMonitor() {
|
||||
}
|
||||
|
||||
void ThermalMonitor::sendTransitionEvent(float currentValue,
|
||||
ReturnValue_t state) {
|
||||
switch (state) {
|
||||
case MonitoringIF::BELOW_LOW_LIMIT:
|
||||
EventManagerIF::triggerEvent(reportingId,
|
||||
ThermalComponentIF::COMPONENT_TEMP_OOL_LOW, state);
|
||||
break;
|
||||
case MonitoringIF::ABOVE_HIGH_LIMIT:
|
||||
EventManagerIF::triggerEvent(reportingId,
|
||||
ThermalComponentIF::COMPONENT_TEMP_OOL_HIGH, state);
|
||||
break;
|
||||
case ThermalComponentIF::BELOW_OPERATIONAL_LIMIT:
|
||||
EventManagerIF::triggerEvent(reportingId,
|
||||
ThermalComponentIF::COMPONENT_TEMP_LOW, state);
|
||||
break;
|
||||
case ThermalComponentIF::ABOVE_OPERATIONAL_LIMIT:
|
||||
EventManagerIF::triggerEvent(reportingId,
|
||||
ThermalComponentIF::COMPONENT_TEMP_HIGH, state);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool ThermalMonitor::isAboveHighLimit() {
|
||||
if (oldState == ThermalComponentIF::ABOVE_OPERATIONAL_LIMIT) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t ThermalMonitor::translateState(ThermalComponentIF::State state, float sample, float lowerLimit,
|
||||
float upperLimit, bool componentIsOperational) {
|
||||
if (ThermalComponentIF::isIgnoredState(state)) {
|
||||
setToUnchecked();
|
||||
return MonitoringIF::UNCHECKED;
|
||||
}
|
||||
switch (state) {
|
||||
case ThermalComponentIF::OUT_OF_RANGE_LOW:
|
||||
return monitorStateIs(MonitoringIF::BELOW_LOW_LIMIT, sample, lowerLimit);
|
||||
case ThermalComponentIF::NON_OPERATIONAL_LOW:
|
||||
if (componentIsOperational) {
|
||||
return monitorStateIs(ThermalComponentIF::BELOW_OPERATIONAL_LIMIT, sample, lowerLimit);
|
||||
} else {
|
||||
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
|
||||
}
|
||||
case ThermalComponentIF::OPERATIONAL:
|
||||
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
|
||||
case ThermalComponentIF::NON_OPERATIONAL_HIGH:
|
||||
if (componentIsOperational) {
|
||||
return monitorStateIs(ThermalComponentIF::ABOVE_OPERATIONAL_LIMIT, sample, upperLimit);
|
||||
} else {
|
||||
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
|
||||
}
|
||||
case ThermalComponentIF::OUT_OF_RANGE_HIGH:
|
||||
return monitorStateIs(MonitoringIF::ABOVE_HIGH_LIMIT, sample, upperLimit);
|
||||
default:
|
||||
//Never reached, all states covered.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,26 @@
|
||||
#ifndef FRAMEWORK_THERMAL_THERMALMONITOR_H_
|
||||
#define FRAMEWORK_THERMAL_THERMALMONITOR_H_
|
||||
|
||||
#include "../monitoring/MonitorReporter.h"
|
||||
#include "../thermal/ThermalComponentIF.h"
|
||||
|
||||
/**
|
||||
* What does it do. How to use it.
|
||||
*/
|
||||
class ThermalMonitor: public MonitorReporter<float> {
|
||||
public:
|
||||
template<typename ... Args>
|
||||
ThermalMonitor(Args ... args) :
|
||||
MonitorReporter<float>(std::forward<Args>(args)...) {
|
||||
}
|
||||
~ThermalMonitor();
|
||||
ReturnValue_t translateState(ThermalComponentIF::State state, float sample,
|
||||
float lowerLimit, float upperLimit, bool componentIsOperational = true);
|
||||
|
||||
bool isAboveHighLimit();
|
||||
protected:
|
||||
virtual void sendTransitionEvent(float currentValue, ReturnValue_t state);
|
||||
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_THERMAL_THERMALMONITOR_H_ */
|
||||
#ifndef FRAMEWORK_THERMAL_THERMALMONITOR_H_
|
||||
#define FRAMEWORK_THERMAL_THERMALMONITOR_H_
|
||||
|
||||
#include "../monitoring/MonitorReporter.h"
|
||||
#include "../thermal/ThermalComponentIF.h"
|
||||
|
||||
/**
|
||||
* What does it do. How to use it.
|
||||
*/
|
||||
class ThermalMonitor: public MonitorReporter<float> {
|
||||
public:
|
||||
template<typename ... Args>
|
||||
ThermalMonitor(Args ... args) :
|
||||
MonitorReporter<float>(std::forward<Args>(args)...) {
|
||||
}
|
||||
~ThermalMonitor();
|
||||
ReturnValue_t translateState(ThermalComponentIF::State state, float sample,
|
||||
float lowerLimit, float upperLimit, bool componentIsOperational = true);
|
||||
|
||||
bool isAboveHighLimit();
|
||||
protected:
|
||||
virtual void sendTransitionEvent(float currentValue, ReturnValue_t state);
|
||||
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_THERMAL_THERMALMONITOR_H_ */
|
||||
|
Reference in New Issue
Block a user