Merge pull request 'power update' (#295) from KSat/fsfw:mueller/power-update into development

Reviewed-on: fsfw/fsfw#295
This commit is contained in:
Steffen Gaisser 2020-12-10 16:59:52 +01:00
commit 18f90ef2fc
10 changed files with 152 additions and 129 deletions

View File

@ -1,22 +1,25 @@
#include "Fuse.h"
#include "../monitoring/LimitViolationReporter.h"
#include "../monitoring/MonitoringMessageContent.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../power/Fuse.h"
#include "../serialize/SerialFixedArrayListAdapter.h"
#include "../ipc/QueueFactory.h"
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) :
SystemObject(fuseObjectId), oldFuseState(0), fuseId(fuseId), powerIF(
NULL), currentLimit(fuseObjectId, 1, ids.pidCurrent, confirmationCount,
maxCurrent, FUSE_CURRENT_HIGH), powerMonitor(fuseObjectId, 2,
GlobalDataPool::poolIdAndPositionToPid(ids.poolIdPower, 0),
confirmationCount), set(), voltage(ids.pidVoltage, &set), current(
ids.pidCurrent, &set), state(ids.pidState, &set), power(
ids.poolIdPower, &set, PoolVariableIF::VAR_READ_WRITE), commandQueue(
NULL), parameterHelper(this), healthHelper(this, fuseObjectId) {
SystemObject(fuseObjectId), oldFuseState(0), fuseId(fuseId),
currentLimit(fuseObjectId, 1, ids.pidCurrent, confirmationCount,
maxCurrent, FUSE_CURRENT_HIGH),
powerMonitor(fuseObjectId, 2, ids.poolIdPower,
confirmationCount),
set(variableSet), voltage(ids.pidVoltage, &set),
current(ids.pidCurrent, &set), state(ids.pidState, &set),
power(ids.poolIdPower, &set, PoolVariableIF::VAR_READ_WRITE),
parameterHelper(this), healthHelper(this, fuseObjectId) {
commandQueue = QueueFactory::instance()->createMessageQueue();
}
@ -75,7 +78,7 @@ ReturnValue_t Fuse::check() {
float lowLimit = 0.0;
float highLimit = RESIDUAL_POWER;
calculatePowerLimits(&lowLimit, &highLimit);
result = powerMonitor.checkPower(power, lowLimit, highLimit);
result = powerMonitor.checkPower(power.value, lowLimit, highLimit);
if (result == MonitoringIF::BELOW_LOW_LIMIT) {
reportEvents(POWER_BELOW_LOW_LIMIT);
} else if (result == MonitoringIF::ABOVE_HIGH_LIMIT) {
@ -132,7 +135,7 @@ void Fuse::calculateFusePower() {
return;
}
//Calculate fuse power.
power = current * voltage;
power.value = current.value * voltage.value;
power.setValid(PoolVariableIF::VALID);
}
@ -190,12 +193,12 @@ void Fuse::checkFuseState() {
reportEvents(FUSE_WENT_OFF);
}
}
oldFuseState = state;
oldFuseState = state.value;
}
float Fuse::getPower() {
if (power.isValid()) {
return power;
return power.value;
} else {
return 0.0;
}

View File

@ -1,17 +1,16 @@
#ifndef FUSE_H_
#define FUSE_H_
#ifndef FSFW_POWER_FUSE_H_
#define FSFW_POWER_FUSE_H_
#include "PowerComponentIF.h"
#include "PowerSwitchIF.h"
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/GlobalPoolVariable.h"
#include "../datapoolglob/PIDReader.h"
#include "../devicehandlers/HealthDevice.h"
#include "../monitoring/AbsLimitMonitor.h"
#include "../power/PowerComponentIF.h"
#include "../power/PowerSwitchIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../parameters/ParameterHelper.h"
#include <list>
#include "../datapoollocal/StaticLocalDataSet.h"
namespace Factory {
void setStaticFrameworkObjectIds();
}
@ -26,10 +25,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
public:
struct VariableIds {
uint32_t pidVoltage;
uint32_t pidCurrent;
uint32_t pidState;
uint32_t poolIdPower;
gp_id_t pidVoltage;
gp_id_t pidCurrent;
gp_id_t pidState;
gp_id_t poolIdPower;
};
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_1;
@ -39,8 +38,8 @@ public:
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;
Fuse(object_id_t fuseObjectId, uint8_t fuseId, VariableIds ids,
float maxCurrent, uint16_t confirmationCount = 2);
Fuse(object_id_t fuseObjectId, uint8_t fuseId, sid_t variableSet,
VariableIds ids, float maxCurrent, uint16_t confirmationCount = 2);
virtual ~Fuse();
void addDevice(PowerComponentIF *set);
float getPower();
@ -70,12 +69,12 @@ public:
private:
uint8_t oldFuseState;
uint8_t fuseId;
PowerSwitchIF *powerIF; //could be static in our case.
PowerSwitchIF *powerIF = nullptr; //could be static in our case.
AbsLimitMonitor<float> currentLimit;
class PowerMonitor: public MonitorReporter<float> {
public:
template<typename ... Args>
PowerMonitor(Args ... args) :
PowerMonitor(Args ... args):
MonitorReporter<float>(std::forward<Args>(args)...) {
}
ReturnValue_t checkPower(float sample, float lowerLimit,
@ -85,12 +84,14 @@ private:
};
PowerMonitor powerMonitor;
GlobDataSet set;
PIDReader<float> voltage;
PIDReader<float> current;
PIDReader<uint8_t> state;
gp_float_t power;
MessageQueueIF* commandQueue;
StaticLocalDataSet<3> set;
lp_var_t<float> voltage;
lp_var_t<float> current;
lp_var_t<uint8_t> state;
lp_var_t<float> power;
MessageQueueIF* commandQueue = nullptr;
ParameterHelper parameterHelper;
HealthHelper healthHelper;
static object_id_t powerSwitchId;
@ -103,4 +104,4 @@ private:
bool areSwitchesOfComponentOn(DeviceList::iterator iter);
};
#endif /* FUSE_H_ */
#endif /* FSFW_POWER_FUSE_H_ */

View File

@ -1,20 +1,15 @@
/**
* @file PowerComponent.cpp
* @brief This file defines the PowerComponent class.
* @date 28.08.2014
* @author baetz
*/
#include "PowerComponent.h"
#include "../serialize/SerializeAdapter.h"
PowerComponent::PowerComponent() :
deviceObjectId(0), switchId1(0xFF), switchId2(0xFF), doIHaveTwoSwitches(
false), min(0.0), max(0.0), moduleId(0) {
PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF),
doIHaveTwoSwitches(false) {
}
PowerComponent::PowerComponent(object_id_t setId, uint8_t moduleId, float min, float max,
uint8_t switchId1, bool twoSwitches, uint8_t switchId2) :
deviceObjectId(setId), switchId1(switchId1), switchId2(switchId2), doIHaveTwoSwitches(
twoSwitches), min(min), max(max), moduleId(moduleId) {
PowerComponent::PowerComponent(object_id_t setId, uint8_t moduleId, float min,
float max, uint8_t switchId1, bool twoSwitches, uint8_t switchId2) :
deviceObjectId(setId), switchId1(switchId1), switchId2(switchId2),
doIHaveTwoSwitches(twoSwitches), min(min), max(max),
moduleId(moduleId) {
}
ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size,
@ -57,7 +52,7 @@ float PowerComponent::getMax() {
}
ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
Endianness streamEndianness) {
ReturnValue_t result = SerializeAdapter::deSerialize(&min, buffer,
size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
@ -80,7 +75,7 @@ ReturnValue_t PowerComponent::getParameter(uint8_t domainId,
parameterWrapper->set<>(max);
break;
default:
return INVALID_MATRIX_ID;
return INVALID_IDENTIFIER_ID;
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,13 +1,17 @@
#ifndef POWERCOMPONENT_H_
#define POWERCOMPONENT_H_
#ifndef FSFW_POWER_POWERCOMPONENT_H_
#define FSFW_POWER_POWERCOMPONENT_H_
#include "../objectmanager/SystemObjectIF.h"
#include "PowerComponentIF.h"
#include "../objectmanager/frameworkObjects.h"
#include "../objectmanager/SystemObjectIF.h"
class PowerComponent: public PowerComponentIF {
public:
PowerComponent(object_id_t setId, uint8_t moduleId, float min, float max, uint8_t switchId1,
bool twoSwitches = false, uint8_t switchId2 = 0xFF);
PowerComponent(object_id_t setId, uint8_t moduleId, float min, float max,
uint8_t switchId1, bool twoSwitches = false,
uint8_t switchId2 = 0xFF);
virtual object_id_t getDeviceObjectId();
@ -31,18 +35,18 @@ public:
ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex);
private:
const object_id_t deviceObjectId;
const object_id_t deviceObjectId = objects::NO_OBJECT;
const uint8_t switchId1;
const uint8_t switchId2;
const bool doIHaveTwoSwitches;
float min;
float max;
float min = 0.0;
float max = 0.0;
uint8_t moduleId;
uint8_t moduleId = 0;
PowerComponent();
};
#endif /* POWERCOMPONENT_H_ */
#endif /* FSFW_POWER_POWERCOMPONENT_H_ */

View File

@ -1,24 +1,23 @@
#ifndef POWERCOMPONENTIF_H_
#define POWERCOMPONENTIF_H_
#ifndef FSFW_POWER_POWERCOMPONENTIF_H_
#define FSFW_POWER_POWERCOMPONENTIF_H_
#include "../serialize/SerializeIF.h"
#include "../parameters/HasParametersIF.h"
#include "../objectmanager/SystemObjectIF.h"
class PowerComponentIF : public SerializeIF, public HasParametersIF {
public:
virtual ~PowerComponentIF() {
virtual ~PowerComponentIF() {}
}
virtual object_id_t getDeviceObjectId() = 0;
virtual object_id_t getDeviceObjectId()=0;
virtual uint8_t getSwitchId1()=0;
virtual uint8_t getSwitchId2()=0;
virtual bool hasTwoSwitches()=0;
virtual uint8_t getSwitchId1() = 0;
virtual uint8_t getSwitchId2() = 0;
virtual bool hasTwoSwitches() = 0;
virtual float getMin() = 0;
virtual float getMax() = 0;
};
#endif /* POWERCOMPONENTIF_H_ */
#endif /* FSFW_POWER_POWERCOMPONENTIF_H_ */

View File

@ -1,14 +1,18 @@
#include "PowerSensor.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) :
SystemObject(setId), commandQueue(NULL), parameterHelper(this), healthHelper(this, setId), set(), current(
ids.pidCurrent, &set), voltage(ids.pidVoltage, &set), power(
ids.poolIdPower, &set, PoolVariableIF::VAR_WRITE), currentLimit(
setId, MODULE_ID_CURRENT, ids.pidCurrent, confirmationCount,
SystemObject(objectId), parameterHelper(this),
healthHelper(this, objectId),
powerSensorSet(setId), current(ids.pidCurrent, &powerSensorSet),
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,
events.currentHigh), voltageLimit(setId, MODULE_ID_VOLTAGE,
events.currentHigh),
voltageLimit(objectId, MODULE_ID_VOLTAGE,
ids.pidVoltage, confirmationCount, limits.voltageMin,
limits.voltageMax, events.voltageLow, events.voltageHigh) {
commandQueue = QueueFactory::instance()->createMessageQueue();
@ -19,13 +23,13 @@ PowerSensor::~PowerSensor() {
}
ReturnValue_t PowerSensor::calculatePower() {
set.read();
powerSensorSet.read();
ReturnValue_t result1 = HasReturnvaluesIF::RETURN_FAILED;
ReturnValue_t result2 = HasReturnvaluesIF::RETURN_FAILED;
if (healthHelper.healthTable->isHealthy(getObjectId()) && voltage.isValid()
&& current.isValid()) {
result1 = voltageLimit.doCheck(voltage);
result2 = currentLimit.doCheck(current);
result1 = voltageLimit.doCheck(voltage.value);
result2 = currentLimit.doCheck(current.value);
} else {
voltageLimit.setToInvalid();
currentLimit.setToInvalid();
@ -37,9 +41,9 @@ ReturnValue_t PowerSensor::calculatePower() {
power.setValid(PoolVariableIF::INVALID);
} else {
power.setValid(PoolVariableIF::VALID);
power = current * voltage;
power.value = current.value * voltage.value;
}
set.commit();
powerSensorSet.commit();
return result1;
}
@ -92,8 +96,8 @@ void PowerSensor::checkCommandQueue() {
}
void PowerSensor::setDataPoolEntriesInvalid() {
set.read();
set.commit(PoolVariableIF::INVALID);
powerSensorSet.read();
powerSensorSet.commit(PoolVariableIF::INVALID);
}
float PowerSensor::getPower() {

View File

@ -1,9 +1,7 @@
#ifndef POWERSENSOR_H_
#define POWERSENSOR_H_
#ifndef FSFW_POWER_POWERSENSOR_H_
#define FSFW_POWER_POWERSENSOR_H_
#include "../datapoolglob/GlobalDataSet.h"
#include "../datapoolglob/GlobalPoolVariable.h"
#include "../datapoolglob/PIDReader.h"
#include "../datapoollocal/StaticLocalDataSet.h"
#include "../devicehandlers/HealthDevice.h"
#include "../monitoring/LimitMonitor.h"
#include "../parameters/ParameterHelper.h"
@ -12,15 +10,18 @@
class PowerController;
/**
* @brief Does magic.
*/
class PowerSensor: public SystemObject,
public ReceivesParameterMessagesIF,
public HasHealthIF {
friend class PowerController;
public:
struct VariableIds {
uint32_t pidCurrent;
uint32_t pidVoltage;
uint32_t poolIdPower;
gp_id_t pidCurrent;
gp_id_t pidVoltage;
gp_id_t poolIdPower;
};
struct DefaultLimits {
float currentMin;
@ -34,8 +35,9 @@ public:
Event voltageLow;
Event voltageHigh;
};
PowerSensor(object_id_t setId, VariableIds setIds, DefaultLimits limits,
SensorEvents events, uint16_t confirmationCount = 0);
PowerSensor(object_id_t objectId, sid_t sid, VariableIds setIds,
DefaultLimits limits, SensorEvents events,
uint16_t confirmationCount = 0);
virtual ~PowerSensor();
ReturnValue_t calculatePower();
ReturnValue_t performOperation(uint8_t opCode);
@ -50,15 +52,19 @@ public:
ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex);
private:
MessageQueueIF* commandQueue;
MessageQueueIF* commandQueue = nullptr;
ParameterHelper parameterHelper;
HealthHelper healthHelper;
GlobDataSet set;
//GlobDataSet set;
StaticLocalDataSet<3> powerSensorSet;
//Variables in
PIDReader<float> current;
PIDReader<float> voltage;
lp_var_t<float> current;
lp_var_t<float> voltage;
//PIDReader<float> current;
//PIDReader<float> voltage;
//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_VOLTAGE = 2;
@ -68,4 +74,4 @@ protected:
LimitMonitor<float> voltageLimit;
};
#endif /* POWERSENSOR_H_ */
#endif /* FSFW_POWER_POWERSENSOR_H_ */

View File

@ -1,18 +1,16 @@
/**
* @file PowerSwitchIF.h
* @brief This file defines the PowerSwitchIF class.
* @date 20.03.2013
* @author baetz
*/
#ifndef POWERSWITCHIF_H_
#define POWERSWITCHIF_H_
#ifndef FSFW_POWER_POWERSWITCHIF_H_
#define FSFW_POWER_POWERSWITCHIF_H_
#include "../events/Event.h"
#include "../returnvalues/HasReturnvaluesIF.h"
/**
* This interface defines a connection to a device that is capable of turning on and off
* switches of devices identified by a switch ID.
*
* @brief This interface defines a connection to a device that is capable of
* turning on and off switches of devices identified by a switch ID.
* @details
* The virtual functions of this interface do not allow to make any assignments
* because they can be called asynchronosuly (const ending).
* @ingroup interfaces
*/
class PowerSwitchIF : public HasReturnvaluesIF {
public:
@ -72,4 +70,4 @@ public:
};
#endif /* POWERSWITCHIF_H_ */
#endif /* FSFW_POWER_POWERSWITCHIF_H_ */

View File

@ -1,15 +1,17 @@
#include "../objectmanager/ObjectManagerIF.h"
#include "PowerSwitcher.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
PowerSwitcher::PowerSwitcher(uint8_t setSwitch1, uint8_t setSwitch2,
PowerSwitcher::State_t setStartState) :
state(setStartState), firstSwitch(setSwitch1), secondSwitch(setSwitch2), power(NULL) {
PowerSwitcher::State_t setStartState):
state(setStartState), firstSwitch(setSwitch1),
secondSwitch(setSwitch2) {
}
ReturnValue_t PowerSwitcher::initialize(object_id_t powerSwitchId) {
power = objectManager->get<PowerSwitchIF>(powerSwitchId);
if (power == NULL) {
if (power == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
@ -17,19 +19,25 @@ ReturnValue_t PowerSwitcher::initialize(object_id_t powerSwitchId) {
ReturnValue_t PowerSwitcher::getStateOfSwitches() {
SwitchReturn_t result = howManySwitches();
switch (result) {
case ONE_SWITCH:
return power->getSwitchState(firstSwitch);
case TWO_SWITCHES:
if ((power->getSwitchState(firstSwitch) == PowerSwitchIF::SWITCH_ON)
&& (power->getSwitchState(secondSwitch) == PowerSwitchIF::SWITCH_ON)) {
case TWO_SWITCHES: {
ReturnValue_t firstSwitchState = power->getSwitchState(firstSwitch);
ReturnValue_t secondSwitchState = power->getSwitchState(firstSwitch);
if ((firstSwitchState == PowerSwitchIF::SWITCH_ON)
&& (secondSwitchState == PowerSwitchIF::SWITCH_ON)) {
return PowerSwitchIF::SWITCH_ON;
} else if ((power->getSwitchState(firstSwitch) == PowerSwitchIF::SWITCH_OFF)
&& (power->getSwitchState(secondSwitch) == PowerSwitchIF::SWITCH_OFF)) {
}
else if ((firstSwitchState == PowerSwitchIF::SWITCH_OFF)
&& (secondSwitchState == PowerSwitchIF::SWITCH_OFF)) {
return PowerSwitchIF::SWITCH_OFF;
} else {
}
else {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
default:
return HasReturnvaluesIF::RETURN_FAILED;
}

View File

@ -1,10 +1,13 @@
#ifndef POWERSWITCHER_H_
#define POWERSWITCHER_H_
#ifndef FSFW_POWER_POWERSWITCHER_H_
#define FSFW_POWER_POWERSWITCHER_H_
#include "PowerSwitchIF.h"
#include "../objectmanager/SystemObjectIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../timemanager/Countdown.h"
class PowerSwitcher : public HasReturnvaluesIF {
class PowerSwitcher: public HasReturnvaluesIF {
public:
enum State_t {
WAIT_OFF,
@ -16,7 +19,8 @@ public:
static const uint8_t INTERFACE_ID = CLASS_ID::POWER_SWITCHER;
static const ReturnValue_t IN_POWER_TRANSITION = MAKE_RETURN_CODE(1);
static const ReturnValue_t SWITCH_STATE_MISMATCH = MAKE_RETURN_CODE(2);
PowerSwitcher( uint8_t setSwitch1, uint8_t setSwitch2 = NO_SWITCH, State_t setStartState = SWITCH_IS_OFF );
PowerSwitcher( uint8_t setSwitch1, uint8_t setSwitch2 = NO_SWITCH,
State_t setStartState = SWITCH_IS_OFF );
ReturnValue_t initialize(object_id_t powerSwitchId);
void turnOn();
void turnOff();
@ -29,7 +33,8 @@ public:
private:
uint8_t firstSwitch;
uint8_t secondSwitch;
PowerSwitchIF* power;
PowerSwitchIF* power = nullptr;
static const uint8_t NO_SWITCH = 0xFF;
enum SwitchReturn_t {
ONE_SWITCH = 1,
@ -42,4 +47,4 @@ private:
#endif /* POWERSWITCHER_H_ */
#endif /* FSFW_POWER_POWERSWITCHER_H_ */