it compiles again

This commit is contained in:
Robin Müller 2020-11-30 15:30:56 +01:00
parent e7a96d5ad8
commit f70ee7696a
16 changed files with 162 additions and 123 deletions

View File

@ -119,6 +119,7 @@ public:
LocalPoolVar<T> &operator=(T newValue); LocalPoolVar<T> &operator=(T newValue);
LocalPoolVar<T> &operator=(LocalPoolVar<T> newPoolVariable);
protected: protected:
/** /**
* @brief Like #read, but without a lock protection of the global pool. * @brief Like #read, but without a lock protection of the global pool.
@ -164,4 +165,5 @@ using lp_int64_t = LocalPoolVar<int64_t>;
using lp_float_t = LocalPoolVar<float>; using lp_float_t = LocalPoolVar<float>;
using lp_double_t = LocalPoolVar<double>; using lp_double_t = LocalPoolVar<double>;
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ */ #endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ */

View File

@ -86,6 +86,13 @@ inline LocalPoolVar<T> & LocalPoolVar<T>::operator =(T newValue) {
return *this; return *this;
} }
template<typename T>
inline LocalPoolVar<T>& LocalPoolVar<T>::operator =(
LocalPoolVar<T> newPoolVariable) {
value = newPoolVariable.value;
return *this;
}
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVar<T>::serialize(uint8_t** buffer, size_t* size, inline ReturnValue_t LocalPoolVar<T>::serialize(uint8_t** buffer, size_t* size,

View File

@ -47,7 +47,7 @@ public:
* @param dataSet The data set in which the variable shall register itself. * @param dataSet The data set in which the variable shall register itself.
* If nullptr, the variable is not registered. * If nullptr, the variable is not registered.
*/ */
LocalPoolVector(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, LocalPoolVector(HasLocalDataPoolIF* hkOwner, lp_id_t poolId,
DataSetIF* dataSet = nullptr, DataSetIF* dataSet = nullptr,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);

View File

@ -6,8 +6,8 @@
#endif #endif
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(lp_id_t poolId, inline LocalPoolVector<T, vectorSize>::LocalPoolVector(
HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, HasLocalDataPoolIF* hkOwner, lp_id_t poolId, DataSetIF* dataSet,
pool_rwm_t setReadWriteMode): pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {} LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {}

View File

@ -66,7 +66,7 @@ union gp_id_t {
gp_id_t(): raw(INVALID_GPID) {} gp_id_t(): raw(INVALID_GPID) {}
gp_id_t(object_id_t objectID, lp_id_t localPoolId): gp_id_t(object_id_t objectId, lp_id_t localPoolId):
objectId(objectId), objectId(objectId),
localPoolId(localPoolId) {} localPoolId(localPoolId) {}

View File

@ -8,11 +8,10 @@ template<typename T>
class AbsLimitMonitor: public MonitorBase<T> { class AbsLimitMonitor: public MonitorBase<T> {
public: public:
AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId, AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId,
object_id_t dataCreatorId, lp_id_t localPoolId, gp_id_t globalPoolId, uint16_t confirmationLimit, T limit,
uint16_t confirmationLimit, T limit,
Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE, Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE,
bool aboveIsViolation = true) : bool aboveIsViolation = true) :
MonitorBase<T>(reporterId, monitorId, dataCreatorId, localPoolId, MonitorBase<T>(reporterId, monitorId, globalPoolId,
confirmationLimit), confirmationLimit),
limit(limit), violationEvent(violationEvent), limit(limit), violationEvent(violationEvent),
aboveIsViolation(aboveIsViolation) { aboveIsViolation(aboveIsViolation) {
@ -67,7 +66,8 @@ protected:
switch (state) { switch (state) {
case MonitoringIF::OUT_OF_RANGE: case MonitoringIF::OUT_OF_RANGE:
EventManagerIF::triggerEvent(this->reportingId, EventManagerIF::triggerEvent(this->reportingId,
violationEvent, this->parameterId); violationEvent, this->parameterId.objectId,
this->parameterId.localPoolId);
break; break;
default: default:
break; break;

View File

@ -13,11 +13,11 @@ template<typename T>
class LimitMonitor: public MonitorBase<T> { class LimitMonitor: public MonitorBase<T> {
public: public:
LimitMonitor(object_id_t reporterId, uint8_t monitorId, LimitMonitor(object_id_t reporterId, uint8_t monitorId,
object_id_t creatorId, lp_id_t localPoolId, gp_id_t globalPoolId, uint16_t confirmationLimit, T lowerLimit,
uint16_t confirmationLimit, T lowerLimit, T upperLimit, T upperLimit, Event belowLowEvent =
Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT, MonitoringIF::VALUE_BELOW_LOW_LIMIT,
Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) : Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) :
MonitorBase<T>(reporterId, monitorId, creatorId, localPoolId, MonitorBase<T>(reporterId, monitorId, globalPoolId,
confirmationLimit), confirmationLimit),
lowerLimit(lowerLimit), upperLimit(upperLimit), lowerLimit(lowerLimit), upperLimit(upperLimit),
belowLowEvent(belowLowEvent), aboveHighEvent(aboveHighEvent) { belowLowEvent(belowLowEvent), aboveHighEvent(aboveHighEvent) {
@ -80,11 +80,11 @@ protected:
switch (state) { switch (state) {
case MonitoringIF::BELOW_LOW_LIMIT: case MonitoringIF::BELOW_LOW_LIMIT:
EventManagerIF::triggerEvent(this->reportingId, belowLowEvent, EventManagerIF::triggerEvent(this->reportingId, belowLowEvent,
this->parameterId); this->parameterId.objectId, this->parameterId.localPoolId);
break; break;
case MonitoringIF::ABOVE_HIGH_LIMIT: case MonitoringIF::ABOVE_HIGH_LIMIT:
EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent, EventManagerIF::triggerEvent(this->reportingId, aboveHighEvent,
this->parameterId); this->parameterId.objectId, this->parameterId.localPoolId);
break; break;
default: default:
break; break;

View File

@ -25,11 +25,10 @@ class MonitorBase: public MonitorReporter<T> {
public: public:
MonitorBase(object_id_t reporterId, uint8_t monitorId, MonitorBase(object_id_t reporterId, uint8_t monitorId,
object_id_t dataCreatorId, lp_id_t localPoolId, gp_id_t globalPoolId, uint16_t confirmationLimit):
uint16_t confirmationLimit): MonitorReporter<T>(reporterId, monitorId, globalPoolId,
MonitorReporter<T>(reporterId, monitorId, dataCreatorId,
confirmationLimit), confirmationLimit),
poolVariable(dataCreatorId, localPoolId) { poolVariable(globalPoolId) {
} }
virtual ~MonitorBase() { virtual ~MonitorBase() {

View File

@ -5,6 +5,7 @@
#include "MonitoringIF.h" #include "MonitoringIF.h"
#include "MonitoringMessageContent.h" #include "MonitoringMessageContent.h"
#include "../datapoollocal/locPoolDefinitions.h"
#include "../events/EventManagerIF.h" #include "../events/EventManagerIF.h"
#include "../parameters/HasParametersIF.h" #include "../parameters/HasParametersIF.h"
@ -18,7 +19,7 @@ public:
// TODO: Adapt to use SID instead of parameter ID. // TODO: Adapt to use SID instead of parameter ID.
MonitorReporter(object_id_t reportingId, uint8_t monitorId, MonitorReporter(object_id_t reportingId, uint8_t monitorId,
uint32_t parameterId, uint16_t confirmationLimit) : gp_id_t globalPoolId, uint16_t confirmationLimit) :
monitorId(monitorId), parameterId(parameterId), monitorId(monitorId), parameterId(parameterId),
reportingId(reportingId), oldState(MonitoringIF::UNCHECKED), reportingId(reportingId), oldState(MonitoringIF::UNCHECKED),
reportingEnabled(ENABLED), eventEnabled(ENABLED), currentCounter(0), reportingEnabled(ENABLED), eventEnabled(ENABLED), currentCounter(0),
@ -95,7 +96,7 @@ public:
protected: protected:
const uint8_t monitorId; const uint8_t monitorId;
const uint32_t parameterId; const gp_id_t parameterId;
object_id_t reportingId; object_id_t reportingId;
ReturnValue_t oldState; ReturnValue_t oldState;

View File

@ -3,6 +3,7 @@
#include "HasMonitorsIF.h" #include "HasMonitorsIF.h"
#include "MonitoringIF.h" #include "MonitoringIF.h"
#include "../datapoollocal/locPoolDefinitions.h"
#include "../objectmanager/ObjectManagerIF.h" #include "../objectmanager/ObjectManagerIF.h"
#include "../serialize/SerialBufferAdapter.h" #include "../serialize/SerialBufferAdapter.h"
#include "../serialize/SerialFixedArrayListAdapter.h" #include "../serialize/SerialFixedArrayListAdapter.h"
@ -16,12 +17,17 @@ void setStaticFrameworkObjectIds();
} }
//PID(uint32_t), TYPE, LIMIT_ID, value,limitValue, previous, later, timestamp //PID(uint32_t), TYPE, LIMIT_ID, value,limitValue, previous, later, timestamp
/**
* @brief Does magic.
* @tparam T
*/
template<typename T> template<typename T>
class MonitoringReportContent: public SerialLinkedListAdapter<SerializeIF> { class MonitoringReportContent: public SerialLinkedListAdapter<SerializeIF> {
friend void (Factory::setStaticFrameworkObjectIds)(); friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
SerializeElement<uint8_t> monitorId; SerializeElement<uint8_t> monitorId;
SerializeElement<uint32_t> parameterId; SerializeElement<uint32_t> parameterObjectId;
SerializeElement<lp_id_t> localPoolId;
SerializeElement<T> parameterValue; SerializeElement<T> parameterValue;
SerializeElement<T> limitValue; SerializeElement<T> limitValue;
SerializeElement<ReturnValue_t> oldState; SerializeElement<ReturnValue_t> oldState;
@ -30,20 +36,23 @@ public:
SerializeElement<SerialBufferAdapter<uint8_t>> timestampSerializer; SerializeElement<SerialBufferAdapter<uint8_t>> timestampSerializer;
TimeStamperIF* timeStamper; TimeStamperIF* timeStamper;
MonitoringReportContent() : MonitoringReportContent() :
SerialLinkedListAdapter<SerializeIF>( SerialLinkedListAdapter<SerializeIF>(&parameterObjectId),
LinkedElement<SerializeIF>::Iterator(&parameterId)), monitorId(0), parameterId( monitorId(0), parameterObjectId(0),
0), parameterValue(0), limitValue(0), oldState(0), newState( localPoolId(0), parameterValue(0),
0), rawTimestamp( { 0 }), timestampSerializer(rawTimestamp, limitValue(0), oldState(0), newState(0),
rawTimestamp( { 0 }), timestampSerializer(rawTimestamp,
sizeof(rawTimestamp)), timeStamper(NULL) { sizeof(rawTimestamp)), timeStamper(NULL) {
setAllNext(); setAllNext();
} }
MonitoringReportContent(uint32_t setPID, T value, T limitValue, MonitoringReportContent(gp_id_t globalPoolId, T value, T limitValue,
ReturnValue_t oldState, ReturnValue_t newState) : ReturnValue_t oldState, ReturnValue_t newState) :
SerialLinkedListAdapter<SerializeIF>( SerialLinkedListAdapter<SerializeIF>(&parameterObjectId),
LinkedElement<SerializeIF>::Iterator(&parameterId)), monitorId(0), parameterId( monitorId(0), parameterObjectId(globalPoolId.objectId),
setPID), parameterValue(value), limitValue(limitValue), oldState( localPoolId(globalPoolId.localPoolId),
oldState), newState(newState), timestampSerializer(rawTimestamp, parameterValue(value), limitValue(limitValue),
sizeof(rawTimestamp)), timeStamper(NULL) { oldState(oldState), newState(newState),
timestampSerializer(rawTimestamp, sizeof(rawTimestamp)),
timeStamper(NULL) {
setAllNext(); setAllNext();
if (checkAndSetStamper()) { if (checkAndSetStamper()) {
timeStamper->addTimeStamp(rawTimestamp, sizeof(rawTimestamp)); timeStamper->addTimeStamp(rawTimestamp, sizeof(rawTimestamp));
@ -53,16 +62,16 @@ private:
static object_id_t timeStamperId; static object_id_t timeStamperId;
void setAllNext() { void setAllNext() {
parameterId.setNext(&parameterValue); parameterObjectId.setNext(&parameterValue);
parameterValue.setNext(&limitValue); parameterValue.setNext(&limitValue);
limitValue.setNext(&oldState); limitValue.setNext(&oldState);
oldState.setNext(&newState); oldState.setNext(&newState);
newState.setNext(&timestampSerializer); newState.setNext(&timestampSerializer);
} }
bool checkAndSetStamper() { bool checkAndSetStamper() {
if (timeStamper == NULL) { if (timeStamper == nullptr) {
timeStamper = objectManager->get<TimeStamperIF>( timeStamperId ); timeStamper = objectManager->get<TimeStamperIF>( timeStamperId );
if ( timeStamper == NULL ) { if ( timeStamper == nullptr ) {
sif::error << "MonitoringReportContent::checkAndSetStamper: " sif::error << "MonitoringReportContent::checkAndSetStamper: "
"Stamper not found!" << std::endl; "Stamper not found!" << std::endl;
return false; return false;

View File

@ -8,17 +8,16 @@
object_id_t Fuse::powerSwitchId = 0; object_id_t Fuse::powerSwitchId = 0;
Fuse::Fuse(object_id_t fuseObjectId, uint8_t fuseId, VariableIds ids, Fuse::Fuse(object_id_t fuseObjectId, uint8_t fuseId,
sid_t variableSet, VariableIds ids,
float maxCurrent, uint16_t confirmationCount) : float maxCurrent, uint16_t confirmationCount) :
SystemObject(fuseObjectId), oldFuseState(0), fuseId(fuseId), powerIF( SystemObject(fuseObjectId), oldFuseState(0), fuseId(fuseId),
NULL),
currentLimit(fuseObjectId, 1, ids.pidCurrent, confirmationCount, currentLimit(fuseObjectId, 1, ids.pidCurrent, confirmationCount,
maxCurrent, FUSE_CURRENT_HIGH), maxCurrent, FUSE_CURRENT_HIGH),
powerMonitor(fuseObjectId, 2, powerMonitor(fuseObjectId, 2, ids.poolIdPower,
GlobalDataPool::poolIdAndPositionToPid(ids.poolIdPower, 0),
confirmationCount), confirmationCount),
set(), voltage(ids.pidVoltage, &set), current(ids.pidCurrent, &set), set(variableSet), voltage(ids.pidVoltage, &set),
state(ids.pidState, &set), current(ids.pidCurrent, &set), state(ids.pidState, &set),
power(ids.poolIdPower, &set, PoolVariableIF::VAR_READ_WRITE), power(ids.poolIdPower, &set, PoolVariableIF::VAR_READ_WRITE),
parameterHelper(this), healthHelper(this, fuseObjectId) { parameterHelper(this), healthHelper(this, fuseObjectId) {
commandQueue = QueueFactory::instance()->createMessageQueue(); commandQueue = QueueFactory::instance()->createMessageQueue();
@ -73,19 +72,19 @@ ReturnValue_t Fuse::check() {
checkFuseState(); checkFuseState();
calculateFusePower(); calculateFusePower();
//Check if power is valid and if fuse state is off or invalid. //Check if power is valid and if fuse state is off or invalid.
if (!power.isValid() || (state == 0) || !state.isValid()) { // if (!power.isValid() || (state == 0) || !state.isValid()) {
result = powerMonitor.setToInvalid(); // result = powerMonitor.setToInvalid();
} else { // } else {
float lowLimit = 0.0; // float lowLimit = 0.0;
float highLimit = RESIDUAL_POWER; // float highLimit = RESIDUAL_POWER;
calculatePowerLimits(&lowLimit, &highLimit); // calculatePowerLimits(&lowLimit, &highLimit);
result = powerMonitor.checkPower(power, lowLimit, highLimit); // result = powerMonitor.checkPower(power, lowLimit, highLimit);
if (result == MonitoringIF::BELOW_LOW_LIMIT) { // if (result == MonitoringIF::BELOW_LOW_LIMIT) {
reportEvents(POWER_BELOW_LOW_LIMIT); // reportEvents(POWER_BELOW_LOW_LIMIT);
} else if (result == MonitoringIF::ABOVE_HIGH_LIMIT) { // } else if (result == MonitoringIF::ABOVE_HIGH_LIMIT) {
reportEvents(POWER_ABOVE_HIGH_LIMIT); // reportEvents(POWER_ABOVE_HIGH_LIMIT);
} // }
} // }
set.commit(); set.commit();
return result; return result;
} }
@ -136,7 +135,7 @@ void Fuse::calculateFusePower() {
return; return;
} }
//Calculate fuse power. //Calculate fuse power.
power = current * voltage; //power = current * voltage;
power.setValid(PoolVariableIF::VALID); power.setValid(PoolVariableIF::VALID);
} }
@ -189,20 +188,20 @@ void Fuse::checkFuseState() {
oldFuseState = 0; oldFuseState = 0;
return; return;
} }
if (state == 0) { // if (state == 0) {
if (oldFuseState != 0) { // if (oldFuseState != 0) {
reportEvents(FUSE_WENT_OFF); // reportEvents(FUSE_WENT_OFF);
} // }
} // }
oldFuseState = state; // oldFuseState = state;
} }
float Fuse::getPower() { float Fuse::getPower() {
if (power.isValid()) { // if (power.isValid()) {
return power; // return power;
} else { // } else {
return 0.0; // return 0.0;
} // }
} }
void Fuse::setDataPoolEntriesInvalid() { void Fuse::setDataPoolEntriesInvalid() {

View File

@ -13,6 +13,7 @@
#include "../parameters/ParameterHelper.h" #include "../parameters/ParameterHelper.h"
#include <list> #include <list>
#include "../datapoollocal/StaticLocalDataSet.h"
namespace Factory { namespace Factory {
void setStaticFrameworkObjectIds(); void setStaticFrameworkObjectIds();
} }
@ -27,10 +28,10 @@ private:
static constexpr float RESIDUAL_POWER = 0.005 * 28.5; //!< This is the upper limit of residual power lost by fuses and switches. Worst case is Fuse and one of two switches on. See PCDU ICD 1.9 p29 bottom static constexpr float RESIDUAL_POWER = 0.005 * 28.5; //!< This is the upper limit of residual power lost by fuses and switches. Worst case is Fuse and one of two switches on. See PCDU ICD 1.9 p29 bottom
public: public:
struct VariableIds { struct VariableIds {
uint32_t pidVoltage; gp_id_t pidVoltage;
uint32_t pidCurrent; gp_id_t pidCurrent;
uint32_t pidState; gp_id_t pidState;
uint32_t poolIdPower; gp_id_t poolIdPower;
}; };
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_1; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_1;
@ -40,8 +41,8 @@ public:
static const Event POWER_BELOW_LOW_LIMIT = MAKE_EVENT(5, SEVERITY::LOW); //!< PSS detected a fuse that violates its limits. static const Event POWER_BELOW_LOW_LIMIT = MAKE_EVENT(5, SEVERITY::LOW); //!< PSS detected a fuse that violates its limits.
typedef std::list<PowerComponentIF*> DeviceList; typedef std::list<PowerComponentIF*> DeviceList;
Fuse(object_id_t fuseObjectId, uint8_t fuseId, VariableIds ids, Fuse(object_id_t fuseObjectId, uint8_t fuseId, sid_t variableSet,
float maxCurrent, uint16_t confirmationCount = 2); VariableIds ids, float maxCurrent, uint16_t confirmationCount = 2);
virtual ~Fuse(); virtual ~Fuse();
void addDevice(PowerComponentIF *set); void addDevice(PowerComponentIF *set);
float getPower(); float getPower();
@ -71,7 +72,7 @@ public:
private: private:
uint8_t oldFuseState; uint8_t oldFuseState;
uint8_t fuseId; uint8_t fuseId;
PowerSwitchIF *powerIF; //could be static in our case. PowerSwitchIF *powerIF = nullptr; //could be static in our case.
AbsLimitMonitor<float> currentLimit; AbsLimitMonitor<float> currentLimit;
class PowerMonitor: public MonitorReporter<float> { class PowerMonitor: public MonitorReporter<float> {
public: public:
@ -86,11 +87,16 @@ private:
}; };
PowerMonitor powerMonitor; PowerMonitor powerMonitor;
GlobDataSet set; StaticLocalDataSet<3> set;
PIDReader<float> voltage; //LocalPoolDataSetBase* set = nullptr;
PIDReader<float> current; //PIDReader<float> voltage;
PIDReader<uint8_t> state; //PIDReader<float> current;
gp_float_t power; //PIDReader<uint8_t> state;
lp_var_t<float> voltage;
lp_var_t<float> current;
lp_var_t<uint8_t> state;
lp_var_t<float> power;
MessageQueueIF* commandQueue = nullptr; MessageQueueIF* commandQueue = nullptr;
ParameterHelper parameterHelper; ParameterHelper parameterHelper;
HealthHelper healthHelper; HealthHelper healthHelper;

View File

@ -2,15 +2,17 @@
#include "../ipc/QueueFactory.h" #include "../ipc/QueueFactory.h"
PowerSensor::PowerSensor(object_id_t setId, VariableIds ids, PowerSensor::PowerSensor(object_id_t objectId, sid_t setId, VariableIds ids,
DefaultLimits limits, SensorEvents events, uint16_t confirmationCount) : DefaultLimits limits, SensorEvents events, uint16_t confirmationCount) :
SystemObject(setId), parameterHelper(this), healthHelper(this, setId), SystemObject(objectId), parameterHelper(this),
set(), current(ids.pidCurrent, &set), voltage(ids.pidVoltage, &set), healthHelper(this, objectId),
power(ids.poolIdPower, &set, PoolVariableIF::VAR_WRITE), powerSensorSet(setId), current(ids.pidCurrent, &powerSensorSet),
currentLimit(setId, MODULE_ID_CURRENT, ids.pidCurrent, confirmationCount, voltage(ids.pidVoltage, &powerSensorSet),
power(ids.poolIdPower, &powerSensorSet, PoolVariableIF::VAR_WRITE),
currentLimit(objectId, MODULE_ID_CURRENT, ids.pidCurrent, confirmationCount,
limits.currentMin, limits.currentMax, events.currentLow, limits.currentMin, limits.currentMax, events.currentLow,
events.currentHigh), events.currentHigh),
voltageLimit(setId, MODULE_ID_VOLTAGE, voltageLimit(objectId, MODULE_ID_VOLTAGE,
ids.pidVoltage, confirmationCount, limits.voltageMin, ids.pidVoltage, confirmationCount, limits.voltageMin,
limits.voltageMax, events.voltageLow, events.voltageHigh) { limits.voltageMax, events.voltageLow, events.voltageHigh) {
commandQueue = QueueFactory::instance()->createMessageQueue(); commandQueue = QueueFactory::instance()->createMessageQueue();
@ -21,27 +23,27 @@ PowerSensor::~PowerSensor() {
} }
ReturnValue_t PowerSensor::calculatePower() { ReturnValue_t PowerSensor::calculatePower() {
set.read(); powerSensorSet.read();
ReturnValue_t result1 = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result1 = HasReturnvaluesIF::RETURN_FAILED;
ReturnValue_t result2 = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result2 = HasReturnvaluesIF::RETURN_FAILED;
if (healthHelper.healthTable->isHealthy(getObjectId()) && voltage.isValid() // if (healthHelper.healthTable->isHealthy(getObjectId()) && voltage.isValid()
&& current.isValid()) { // && current.isValid()) {
result1 = voltageLimit.doCheck(voltage); // result1 = voltageLimit.doCheck(voltage);
result2 = currentLimit.doCheck(current); // result2 = currentLimit.doCheck(current);
} else { // } else {
voltageLimit.setToInvalid(); // voltageLimit.setToInvalid();
currentLimit.setToInvalid(); // currentLimit.setToInvalid();
result1 = OBJECT_NOT_HEALTHY; // result1 = OBJECT_NOT_HEALTHY;
} // }
if (result1 != HasReturnvaluesIF::RETURN_OK // if (result1 != HasReturnvaluesIF::RETURN_OK
|| result2 != HasReturnvaluesIF::RETURN_OK) { // || result2 != HasReturnvaluesIF::RETURN_OK) {
result1 = MonitoringIF::INVALID; // result1 = MonitoringIF::INVALID;
power.setValid(PoolVariableIF::INVALID); // power.setValid(PoolVariableIF::INVALID);
} else { // } else {
power.setValid(PoolVariableIF::VALID); // power.setValid(PoolVariableIF::VALID);
power = current * voltage; // power = current * voltage;
} // }
set.commit(); // powerSensorSet.commit();
return result1; return result1;
} }
@ -94,8 +96,8 @@ void PowerSensor::checkCommandQueue() {
} }
void PowerSensor::setDataPoolEntriesInvalid() { void PowerSensor::setDataPoolEntriesInvalid() {
set.read(); powerSensorSet.read();
set.commit(PoolVariableIF::INVALID); powerSensorSet.commit(PoolVariableIF::INVALID);
} }
float PowerSensor::getPower() { float PowerSensor::getPower() {

View File

@ -4,6 +4,7 @@
#include "../datapoolglob/GlobalDataSet.h" #include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/GlobalPoolVariable.h" #include "../datapoolglob/GlobalPoolVariable.h"
#include "../datapoolglob/PIDReader.h" #include "../datapoolglob/PIDReader.h"
#include "../datapoollocal/StaticLocalDataSet.h"
#include "../devicehandlers/HealthDevice.h" #include "../devicehandlers/HealthDevice.h"
#include "../monitoring/LimitMonitor.h" #include "../monitoring/LimitMonitor.h"
#include "../parameters/ParameterHelper.h" #include "../parameters/ParameterHelper.h"
@ -12,15 +13,18 @@
class PowerController; class PowerController;
/**
* @brief Does magic.
*/
class PowerSensor: public SystemObject, class PowerSensor: public SystemObject,
public ReceivesParameterMessagesIF, public ReceivesParameterMessagesIF,
public HasHealthIF { public HasHealthIF {
friend class PowerController; friend class PowerController;
public: public:
struct VariableIds { struct VariableIds {
uint32_t pidCurrent; gp_id_t pidCurrent;
uint32_t pidVoltage; gp_id_t pidVoltage;
uint32_t poolIdPower; gp_id_t poolIdPower;
}; };
struct DefaultLimits { struct DefaultLimits {
float currentMin; float currentMin;
@ -34,8 +38,9 @@ public:
Event voltageLow; Event voltageLow;
Event voltageHigh; Event voltageHigh;
}; };
PowerSensor(object_id_t setId, VariableIds setIds, DefaultLimits limits, PowerSensor(object_id_t objectId, sid_t sid, VariableIds setIds,
SensorEvents events, uint16_t confirmationCount = 0); DefaultLimits limits, SensorEvents events,
uint16_t confirmationCount = 0);
virtual ~PowerSensor(); virtual ~PowerSensor();
ReturnValue_t calculatePower(); ReturnValue_t calculatePower();
ReturnValue_t performOperation(uint8_t opCode); ReturnValue_t performOperation(uint8_t opCode);
@ -53,12 +58,16 @@ private:
MessageQueueIF* commandQueue = nullptr; MessageQueueIF* commandQueue = nullptr;
ParameterHelper parameterHelper; ParameterHelper parameterHelper;
HealthHelper healthHelper; HealthHelper healthHelper;
GlobDataSet set; //GlobDataSet set;
StaticLocalDataSet<3> powerSensorSet;
//Variables in //Variables in
PIDReader<float> current; lp_var_t<float> current;
PIDReader<float> voltage; lp_var_t<float> voltage;
//PIDReader<float> current;
//PIDReader<float> voltage;
//Variables out //Variables out
gp_float_t power; lp_var_t<float> power;
//gp_float_t power;
static const uint8_t MODULE_ID_CURRENT = 1; static const uint8_t MODULE_ID_CURRENT = 1;
static const uint8_t MODULE_ID_VOLTAGE = 2; static const uint8_t MODULE_ID_VOLTAGE = 2;

View File

@ -38,7 +38,8 @@ bool ThermalMonitorReporter::isAboveHighLimit() {
} }
} }
ReturnValue_t ThermalMonitorReporter::translateState(ThermalComponentIF::State state, float sample, float lowerLimit, ReturnValue_t ThermalMonitorReporter::translateState(
ThermalComponentIF::State state, float sample, float lowerLimit,
float upperLimit, bool componentIsOperational) { float upperLimit, bool componentIsOperational) {
if (ThermalComponentIF::isIgnoredState(state)) { if (ThermalComponentIF::isIgnoredState(state)) {
setToUnchecked(); setToUnchecked();
@ -46,10 +47,12 @@ ReturnValue_t ThermalMonitorReporter::translateState(ThermalComponentIF::State s
} }
switch (state) { switch (state) {
case ThermalComponentIF::OUT_OF_RANGE_LOW: case ThermalComponentIF::OUT_OF_RANGE_LOW:
return monitorStateIs(MonitoringIF::BELOW_LOW_LIMIT, sample, lowerLimit); return monitorStateIs(MonitoringIF::BELOW_LOW_LIMIT, sample,
lowerLimit);
case ThermalComponentIF::NON_OPERATIONAL_LOW: case ThermalComponentIF::NON_OPERATIONAL_LOW:
if (componentIsOperational) { if (componentIsOperational) {
return monitorStateIs(ThermalComponentIF::BELOW_OPERATIONAL_LIMIT, sample, lowerLimit); return monitorStateIs(ThermalComponentIF::BELOW_OPERATIONAL_LIMIT,
sample, lowerLimit);
} else { } else {
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0); return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
} }
@ -57,12 +60,14 @@ ReturnValue_t ThermalMonitorReporter::translateState(ThermalComponentIF::State s
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0); return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
case ThermalComponentIF::NON_OPERATIONAL_HIGH: case ThermalComponentIF::NON_OPERATIONAL_HIGH:
if (componentIsOperational) { if (componentIsOperational) {
return monitorStateIs(ThermalComponentIF::ABOVE_OPERATIONAL_LIMIT, sample, upperLimit); return monitorStateIs(ThermalComponentIF::ABOVE_OPERATIONAL_LIMIT,
sample, upperLimit);
} else { } else {
return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0); return monitorStateIs(HasReturnvaluesIF::RETURN_OK, sample, 0.0);
} }
case ThermalComponentIF::OUT_OF_RANGE_HIGH: case ThermalComponentIF::OUT_OF_RANGE_HIGH:
return monitorStateIs(MonitoringIF::ABOVE_HIGH_LIMIT, sample, upperLimit); return monitorStateIs(MonitoringIF::ABOVE_HIGH_LIMIT, sample,
upperLimit);
default: default:
//Never reached, all states covered. //Never reached, all states covered.
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;