updating code from Flying Laptop
This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
260
power/Fuse.cpp
Normal file
260
power/Fuse.cpp
Normal file
@ -0,0 +1,260 @@
|
||||
#include <framework/monitoring/LimitViolationReporter.h>
|
||||
#include <framework/monitoring/MonitoringMessageContent.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/power/Fuse.h>
|
||||
#include <framework/serialize/SerialFixedArrayListAdapter.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
|
||||
object_id_t Fuse::powerSwitchId = 0;
|
||||
|
||||
Fuse::Fuse(object_id_t fuseObjectId, uint8_t fuseId, 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,
|
||||
DataPool::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) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue();
|
||||
}
|
||||
|
||||
Fuse::~Fuse() {
|
||||
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
||||
}
|
||||
|
||||
void Fuse::addDevice(PowerComponentIF* switchSet) {
|
||||
devices.push_back(switchSet);
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = parameterHelper.initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = healthHelper.initialize();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
powerIF = objectManager->get<PowerSwitchIF>(powerSwitchId);
|
||||
if (powerIF == NULL) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
void Fuse::calculatePowerLimits(float* low, float* high) {
|
||||
for (DeviceList::iterator iter = devices.begin(); iter != devices.end();
|
||||
iter++) {
|
||||
if (areSwitchesOfComponentOn(iter)) {
|
||||
*low += (*iter)->getMin();
|
||||
*high += (*iter)->getMax();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::check() {
|
||||
set.read();
|
||||
if (!healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||
setAllMonitorsToUnchecked();
|
||||
set.commit(PoolVariableIF::INVALID);
|
||||
return RETURN_OK;
|
||||
}
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
checkFuseState();
|
||||
calculateFusePower();
|
||||
//Check if power is valid and if fuse state is off or invalid.
|
||||
if (!power.isValid() || (state == 0) || !state.isValid()) {
|
||||
result = powerMonitor.setToInvalid();
|
||||
} else {
|
||||
float lowLimit = 0.0;
|
||||
float highLimit = RESIDUAL_POWER;
|
||||
calculatePowerLimits(&lowLimit, &highLimit);
|
||||
result = powerMonitor.checkPower(power, lowLimit, highLimit);
|
||||
if (result == MonitoringIF::BELOW_LOW_LIMIT) {
|
||||
reportEvents(POWER_BELOW_LOW_LIMIT);
|
||||
} else if (result == MonitoringIF::ABOVE_HIGH_LIMIT) {
|
||||
reportEvents(POWER_ABOVE_HIGH_LIMIT);
|
||||
}
|
||||
}
|
||||
set.commit();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (DeviceList::const_iterator iter = devices.begin();
|
||||
iter != devices.end(); iter++) {
|
||||
result = (*iter)->serialize(buffer, size, max_size, bigEndian);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t Fuse::getSerializedSize() const {
|
||||
uint32_t size = 0;
|
||||
for (DeviceList::const_iterator iter = devices.begin();
|
||||
iter != devices.end(); iter++) {
|
||||
size += (*iter)->getSerializedSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
ReturnValue_t result = RETURN_FAILED;
|
||||
for (DeviceList::iterator iter = devices.begin(); iter != devices.end();
|
||||
iter++) {
|
||||
result = (*iter)->deSerialize(buffer, size, bigEndian);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
uint8_t Fuse::getFuseId() const {
|
||||
return fuseId;
|
||||
}
|
||||
|
||||
void Fuse::calculateFusePower() {
|
||||
ReturnValue_t result1 = currentLimit.check();
|
||||
if (result1 != HasReturnvaluesIF::RETURN_OK || !(voltage.isValid())) {
|
||||
power.setValid(PoolVariableIF::INVALID);
|
||||
return;
|
||||
}
|
||||
//Calculate fuse power.
|
||||
power = current * voltage;
|
||||
power.setValid(PoolVariableIF::VALID);
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::performOperation(uint8_t opCode) {
|
||||
checkCommandQueue();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void Fuse::reportEvents(Event event) {
|
||||
if (!powerMonitor.isEventEnabled()) {
|
||||
return;
|
||||
}
|
||||
for (DeviceList::iterator iter = devices.begin(); iter != devices.end();
|
||||
iter++) {
|
||||
if (areSwitchesOfComponentOn(iter)) {
|
||||
EventManagerIF::triggerEvent((*iter)->getDeviceObjectId(), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessageQueueId_t Fuse::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
void Fuse::setAllMonitorsToUnchecked() {
|
||||
currentLimit.setToUnchecked();
|
||||
powerMonitor.setToUnchecked();
|
||||
}
|
||||
|
||||
void Fuse::checkCommandQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
void Fuse::checkFuseState() {
|
||||
if (!state.isValid()) {
|
||||
oldFuseState = 0;
|
||||
return;
|
||||
}
|
||||
if (state == 0) {
|
||||
if (oldFuseState != 0) {
|
||||
reportEvents(FUSE_WENT_OFF);
|
||||
}
|
||||
}
|
||||
oldFuseState = state;
|
||||
}
|
||||
|
||||
float Fuse::getPower() {
|
||||
if (power.isValid()) {
|
||||
return power;
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void Fuse::setDataPoolEntriesInvalid() {
|
||||
set.read();
|
||||
set.commit(PoolVariableIF::INVALID);
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
|
||||
uint16_t startAtIndex) {
|
||||
ReturnValue_t result = currentLimit.getParameter(domainId, parameterId,
|
||||
parameterWrapper, newValues, startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
result = powerMonitor.getParameter(domainId, parameterId, parameterWrapper,
|
||||
newValues, startAtIndex);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Fuse::areSwitchesOfComponentOn(DeviceList::iterator iter) {
|
||||
if (powerIF->getSwitchState((*iter)->getSwitchId1())
|
||||
!= PowerSwitchIF::SWITCH_ON) {
|
||||
return false;
|
||||
}
|
||||
if ((*iter)->hasTwoSwitches()) {
|
||||
if ((powerIF->getSwitchState((*iter)->getSwitchId2())
|
||||
!= PowerSwitchIF::SWITCH_ON)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Fuse::isPowerValid() {
|
||||
return power.isValid();
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::setHealth(HealthState health) {
|
||||
healthHelper.setHealth(health);
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
HasHealthIF::HealthState Fuse::getHealth() {
|
||||
return healthHelper.getHealth();
|
||||
}
|
||||
|
||||
ReturnValue_t Fuse::PowerMonitor::checkPower(float sample, float lowerLimit,
|
||||
float upperLimit) {
|
||||
if (sample > upperLimit) {
|
||||
return this->monitorStateIs(MonitoringIF::ABOVE_HIGH_LIMIT, sample,
|
||||
upperLimit);
|
||||
} else if (sample < lowerLimit) {
|
||||
return this->monitorStateIs(MonitoringIF::BELOW_LOW_LIMIT, sample,
|
||||
lowerLimit);
|
||||
} else {
|
||||
return this->monitorStateIs(RETURN_OK, sample, 0.0); //Within limits.
|
||||
}
|
||||
}
|
105
power/Fuse.h
Normal file
105
power/Fuse.h
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef FUSE_H_
|
||||
#define FUSE_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/devicehandlers/HealthDevice.h>
|
||||
#include <framework/monitoring/AbsLimitMonitor.h>
|
||||
#include <framework/power/PowerComponentIF.h>
|
||||
#include <framework/power/PowerSwitchIF.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/parameters/ParameterHelper.h>
|
||||
#include <list>
|
||||
|
||||
namespace Factory{
|
||||
void setStaticFrameworkObjectIds();
|
||||
}
|
||||
|
||||
class Fuse: public SystemObject,
|
||||
public HasHealthIF,
|
||||
public HasReturnvaluesIF,
|
||||
public ReceivesParameterMessagesIF {
|
||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||
private:
|
||||
//TODO, modern gcc complains about const
|
||||
static const 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;
|
||||
};
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_1;
|
||||
static const Event FUSE_CURRENT_HIGH = MAKE_EVENT(1, SEVERITY::LOW); //!< PSS detected that current on a fuse is totally out of bounds.
|
||||
static const Event FUSE_WENT_OFF = MAKE_EVENT(2, SEVERITY::LOW); //!< PSS detected a fuse that went off.
|
||||
static const Event POWER_ABOVE_HIGH_LIMIT = MAKE_EVENT(4, 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;
|
||||
Fuse(object_id_t fuseObjectId, uint8_t fuseId, VariableIds ids,
|
||||
float maxCurrent, uint16_t confirmationCount = 2);
|
||||
virtual ~Fuse();
|
||||
void addDevice(PowerComponentIF* set);
|
||||
float getPower();
|
||||
|
||||
bool isPowerValid();
|
||||
|
||||
ReturnValue_t check();
|
||||
uint8_t getFuseId() const;
|
||||
ReturnValue_t initialize();
|
||||
DeviceList devices;
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const;
|
||||
uint32_t getSerializedSize() const;
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian);
|
||||
void setAllMonitorsToUnchecked();
|
||||
ReturnValue_t performOperation(uint8_t opCode);
|
||||
MessageQueueId_t getCommandQueue() const;
|
||||
void setDataPoolEntriesInvalid();
|
||||
ReturnValue_t setHealth(HealthState health);
|
||||
HasHealthIF::HealthState getHealth();
|
||||
|
||||
ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
|
||||
private:
|
||||
uint8_t oldFuseState;
|
||||
uint8_t fuseId;
|
||||
PowerSwitchIF* powerIF; //could be static in our case.
|
||||
AbsLimitMonitor<float> currentLimit;
|
||||
class PowerMonitor: public MonitorReporter<float> {
|
||||
public:
|
||||
template<typename ... Args>
|
||||
PowerMonitor(Args ... args) :
|
||||
MonitorReporter<float>(std::forward<Args>(args)...) {
|
||||
}
|
||||
ReturnValue_t checkPower(float sample, float lowerLimit,
|
||||
float upperLimit);
|
||||
void sendTransitionEvent(float currentValue, ReturnValue_t state) {
|
||||
}
|
||||
|
||||
};
|
||||
PowerMonitor powerMonitor;
|
||||
DataSet set;
|
||||
PIDReader<float> voltage;
|
||||
PIDReader<float> current;
|
||||
PIDReader<uint8_t> state;
|
||||
db_float_t power;
|
||||
MessageQueueIF* commandQueue;
|
||||
ParameterHelper parameterHelper;
|
||||
HealthHelper healthHelper;
|
||||
static object_id_t powerSwitchId;
|
||||
void calculatePowerLimits(float* low, float* high);
|
||||
void calculateFusePower();
|
||||
void checkFuseState();
|
||||
void reportEvents(Event event);
|
||||
void checkCommandQueue();
|
||||
|
||||
bool areSwitchesOfComponentOn(DeviceList::iterator iter);
|
||||
};
|
||||
|
||||
#endif /* FUSE_H_ */
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @file HasPowerSwitchIF.h
|
||||
* @brief This file defines the HasPowerSwitchIF class.
|
||||
* @date 25.02.2014
|
||||
* @author baetz
|
||||
*/
|
||||
#ifndef HASPOWERSWITCHIF_H_
|
||||
#define HASPOWERSWITCHIF_H_
|
||||
|
||||
|
||||
class HasPowerSwitchIF {
|
||||
public:
|
||||
virtual ~HasPowerSwitchIF() {}
|
||||
virtual ReturnValue_t getSwitches(uint8_t *firstSwitch,
|
||||
uint8_t *secondSwitch) = 0;
|
||||
virtual void getPowerLimit(float* low, float* high) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* HASPOWERSWITCHIF_H_ */
|
86
power/PowerComponent.cpp
Normal file
86
power/PowerComponent.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @file PowerComponent.cpp
|
||||
* @brief This file defines the PowerComponent class.
|
||||
* @date 28.08.2014
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include <framework/power/PowerComponent.h>
|
||||
|
||||
PowerComponent::PowerComponent() :
|
||||
deviceObjectId(0), switchId1(0xFF), switchId2(0xFF), doIHaveTwoSwitches(
|
||||
false), min(0.0), max(0.0), moduleId(0) {
|
||||
}
|
||||
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, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
ReturnValue_t result = SerializeAdapter<float>::serialize(&min, buffer,
|
||||
size, max_size, bigEndian);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return SerializeAdapter<float>::serialize(&max, buffer, size, max_size,
|
||||
bigEndian);
|
||||
}
|
||||
|
||||
uint32_t PowerComponent::getSerializedSize() const {
|
||||
return sizeof(min) + sizeof(max);
|
||||
}
|
||||
|
||||
object_id_t PowerComponent::getDeviceObjectId() {
|
||||
return deviceObjectId;
|
||||
}
|
||||
|
||||
uint8_t PowerComponent::getSwitchId1() {
|
||||
return switchId1;
|
||||
}
|
||||
|
||||
uint8_t PowerComponent::getSwitchId2() {
|
||||
return switchId2;
|
||||
}
|
||||
|
||||
bool PowerComponent::hasTwoSwitches() {
|
||||
return doIHaveTwoSwitches;
|
||||
}
|
||||
|
||||
float PowerComponent::getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
float PowerComponent::getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
ReturnValue_t result = SerializeAdapter<float>::deSerialize(&min, buffer,
|
||||
size, bigEndian);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return SerializeAdapter<float>::deSerialize(&max, buffer, size, bigEndian);
|
||||
}
|
||||
|
||||
ReturnValue_t PowerComponent::getParameter(uint8_t domainId,
|
||||
uint16_t parameterId, ParameterWrapper* parameterWrapper,
|
||||
const ParameterWrapper* newValues, uint16_t startAtIndex) {
|
||||
if (domainId != moduleId) {
|
||||
return INVALID_DOMAIN_ID;
|
||||
}
|
||||
switch (parameterId) {
|
||||
case 0:
|
||||
parameterWrapper->set<>(min);
|
||||
break;
|
||||
case 1:
|
||||
parameterWrapper->set<>(max);
|
||||
break;
|
||||
default:
|
||||
return INVALID_MATRIX_ID;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
48
power/PowerComponent.h
Normal file
48
power/PowerComponent.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef POWERCOMPONENT_H_
|
||||
#define POWERCOMPONENT_H_
|
||||
|
||||
#include <framework/objectmanager/SystemObjectIF.h>
|
||||
#include <framework/power/PowerComponentIF.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);
|
||||
|
||||
virtual object_id_t getDeviceObjectId();
|
||||
|
||||
virtual uint8_t getSwitchId1();
|
||||
virtual uint8_t getSwitchId2();
|
||||
|
||||
bool hasTwoSwitches();
|
||||
|
||||
float getMin();
|
||||
float getMax();
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const;
|
||||
|
||||
uint32_t getSerializedSize() const;
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian);
|
||||
|
||||
ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
private:
|
||||
const object_id_t deviceObjectId;
|
||||
const uint8_t switchId1;
|
||||
const uint8_t switchId2;
|
||||
|
||||
const bool doIHaveTwoSwitches;
|
||||
|
||||
float min;
|
||||
float max;
|
||||
|
||||
uint8_t moduleId;
|
||||
|
||||
PowerComponent();
|
||||
};
|
||||
|
||||
#endif /* POWERCOMPONENT_H_ */
|
24
power/PowerComponentIF.h
Normal file
24
power/PowerComponentIF.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef POWERCOMPONENTIF_H_
|
||||
#define POWERCOMPONENTIF_H_
|
||||
|
||||
#include <framework/serialize/SerializeIF.h>
|
||||
#include <framework/parameters/HasParametersIF.h>
|
||||
|
||||
class PowerComponentIF : public SerializeIF, public HasParametersIF {
|
||||
public:
|
||||
virtual ~PowerComponentIF() {
|
||||
|
||||
}
|
||||
|
||||
virtual object_id_t getDeviceObjectId()=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_ */
|
128
power/PowerSensor.cpp
Normal file
128
power/PowerSensor.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
#include <framework/power/PowerSensor.h>
|
||||
#include <framework/ipc/QueueFactory.h>
|
||||
|
||||
PowerSensor::PowerSensor(object_id_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,
|
||||
limits.currentMin, limits.currentMax, events.currentLow,
|
||||
events.currentHigh), voltageLimit(setId, MODULE_ID_VOLTAGE,
|
||||
ids.pidVoltage, confirmationCount, limits.voltageMin,
|
||||
limits.voltageMax, events.voltageLow, events.voltageHigh) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue();
|
||||
}
|
||||
|
||||
PowerSensor::~PowerSensor() {
|
||||
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSensor::calculatePower() {
|
||||
set.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);
|
||||
} else {
|
||||
voltageLimit.setToInvalid();
|
||||
currentLimit.setToInvalid();
|
||||
result1 = OBJECT_NOT_HEALTHY;
|
||||
}
|
||||
if (result1 != HasReturnvaluesIF::RETURN_OK
|
||||
|| result2 != HasReturnvaluesIF::RETURN_OK) {
|
||||
result1 = MonitoringIF::INVALID;
|
||||
power.setValid(PoolVariableIF::INVALID);
|
||||
} else {
|
||||
power.setValid(PoolVariableIF::VALID);
|
||||
power = current * voltage;
|
||||
}
|
||||
set.commit();
|
||||
return result1;
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSensor::performOperation(uint8_t opCode) {
|
||||
checkCommandQueue();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MessageQueueId_t PowerSensor::getCommandQueue() const {
|
||||
return commandQueue->getId();
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSensor::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();
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void PowerSensor::setAllMonitorsToUnchecked() {
|
||||
currentLimit.setToUnchecked();
|
||||
voltageLimit.setToUnchecked();
|
||||
}
|
||||
|
||||
void PowerSensor::checkCommandQueue() {
|
||||
CommandMessage command;
|
||||
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
void PowerSensor::setDataPoolEntriesInvalid() {
|
||||
set.read();
|
||||
set.commit(PoolVariableIF::INVALID);
|
||||
}
|
||||
|
||||
float PowerSensor::getPower() {
|
||||
if (power.isValid()) {
|
||||
return power.value;
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSensor::setHealth(HealthState health) {
|
||||
healthHelper.setHealth(health);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
HasHealthIF::HealthState PowerSensor::getHealth() {
|
||||
return healthHelper.getHealth();
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSensor::getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
|
||||
uint16_t startAtIndex) {
|
||||
ReturnValue_t result = currentLimit.getParameter(domainId, parameterId,
|
||||
parameterWrapper, newValues, startAtIndex);
|
||||
if (result != INVALID_DOMAIN_ID) {
|
||||
return result;
|
||||
}
|
||||
result = voltageLimit.getParameter(domainId, parameterId, parameterWrapper,
|
||||
newValues, startAtIndex);
|
||||
return result;
|
||||
}
|
71
power/PowerSensor.h
Normal file
71
power/PowerSensor.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef POWERSENSOR_H_
|
||||
#define POWERSENSOR_H_
|
||||
|
||||
#include <framework/datapool/DataSet.h>
|
||||
#include <framework/datapool/PIDReader.h>
|
||||
#include <framework/datapool/PoolVariable.h>
|
||||
#include <framework/devicehandlers/HealthDevice.h>
|
||||
#include <framework/monitoring/LimitMonitor.h>
|
||||
#include <framework/parameters/ParameterHelper.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
|
||||
class PowerController;
|
||||
|
||||
class PowerSensor: public SystemObject,
|
||||
public ReceivesParameterMessagesIF,
|
||||
public HasHealthIF {
|
||||
friend class PowerController;
|
||||
public:
|
||||
struct VariableIds {
|
||||
uint32_t pidCurrent;
|
||||
uint32_t pidVoltage;
|
||||
uint32_t poolIdPower;
|
||||
};
|
||||
struct DefaultLimits {
|
||||
float currentMin;
|
||||
float currentMax;
|
||||
float voltageMin;
|
||||
float voltageMax;
|
||||
};
|
||||
struct SensorEvents {
|
||||
Event currentLow;
|
||||
Event currentHigh;
|
||||
Event voltageLow;
|
||||
Event voltageHigh;
|
||||
};
|
||||
PowerSensor(object_id_t setId, VariableIds setIds, DefaultLimits limits,
|
||||
SensorEvents events, uint16_t confirmationCount = 0);
|
||||
virtual ~PowerSensor();
|
||||
ReturnValue_t calculatePower();
|
||||
ReturnValue_t performOperation(uint8_t opCode);
|
||||
void setAllMonitorsToUnchecked();
|
||||
MessageQueueId_t getCommandQueue() const;
|
||||
ReturnValue_t initialize();
|
||||
void setDataPoolEntriesInvalid();
|
||||
float getPower();
|
||||
ReturnValue_t setHealth(HealthState health);
|
||||
HasHealthIF::HealthState getHealth();
|
||||
ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||
ParameterWrapper *parameterWrapper,
|
||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||
private:
|
||||
MessageQueueIF* commandQueue;
|
||||
ParameterHelper parameterHelper;
|
||||
HealthHelper healthHelper;
|
||||
DataSet set;
|
||||
//Variables in
|
||||
PIDReader<float> current;
|
||||
PIDReader<float> voltage;
|
||||
//Variables out
|
||||
db_float_t power;
|
||||
|
||||
static const uint8_t MODULE_ID_CURRENT = 1;
|
||||
static const uint8_t MODULE_ID_VOLTAGE = 2;
|
||||
void checkCommandQueue();
|
||||
protected:
|
||||
LimitMonitor<float> currentLimit;
|
||||
LimitMonitor<float> voltageLimit;
|
||||
};
|
||||
|
||||
#endif /* POWERSENSOR_H_ */
|
@ -25,14 +25,14 @@ public:
|
||||
/**
|
||||
* The Returnvalues id of this class, required by HasReturnvaluesIF
|
||||
*/
|
||||
static const uint8_t INTERFACE_ID = POWER_SWITCH_IF;
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::POWER_SWITCH_IF;
|
||||
static const ReturnValue_t SWITCH_ON = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t SWITCH_OFF = MAKE_RETURN_CODE(0);
|
||||
static const ReturnValue_t SWITCH_TIMEOUT = MAKE_RETURN_CODE(2);
|
||||
static const ReturnValue_t FUSE_ON = MAKE_RETURN_CODE(3);
|
||||
static const ReturnValue_t FUSE_OFF = MAKE_RETURN_CODE(4);
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PCDU_2;
|
||||
static const Event SWITCH_WENT_OFF = MAKE_EVENT(0, SEVERITY::LOW); //!< Someone detected that a switch went off which shouldn't. Severity: Low, Parameter1: switchId1, Parameter2: switchId2 TODO: CHANGED EVENT_ID!
|
||||
static const Event SWITCH_WENT_OFF = MAKE_EVENT(0, SEVERITY::LOW); //!< Someone detected that a switch went off which shouldn't. Severity: Low, Parameter1: switchId1, Parameter2: switchId2
|
||||
/**
|
||||
* send a direct command to the Power Unit to enable/disable the specified switch.
|
||||
*
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* PowerSwitcher.cpp
|
||||
*
|
||||
* Created on: 21.01.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/power/PowerSwitcher.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
@ -14,8 +7,8 @@ PowerSwitcher::PowerSwitcher(uint8_t setSwitch1, uint8_t setSwitch2,
|
||||
state(setStartState), firstSwitch(setSwitch1), secondSwitch(setSwitch2), power(NULL) {
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSwitcher::initialize() {
|
||||
power = objectManager->get<PowerSwitchIF>(objects::PCDU_HANDLER);
|
||||
ReturnValue_t PowerSwitcher::initialize(object_id_t powerSwitchId) {
|
||||
power = objectManager->get<PowerSwitchIF>(powerSwitchId);
|
||||
if (power == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
@ -47,7 +40,7 @@ void PowerSwitcher::commandSwitches(ReturnValue_t onOff) {
|
||||
switch (result) {
|
||||
case TWO_SWITCHES:
|
||||
power->sendSwitchCommand(secondSwitch, onOff);
|
||||
/*NO BREAK*/
|
||||
/* NO BREAK falls through*/
|
||||
case ONE_SWITCH:
|
||||
power->sendSwitchCommand(firstSwitch, onOff);
|
||||
break;
|
||||
|
@ -1,10 +1,3 @@
|
||||
/*
|
||||
* PowerSwitcher.h
|
||||
*
|
||||
* Created on: 21.01.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef POWERSWITCHER_H_
|
||||
#define POWERSWITCHER_H_
|
||||
#include <framework/power/PowerSwitchIF.h>
|
||||
@ -20,11 +13,11 @@ public:
|
||||
SWITCH_IS_ON,
|
||||
};
|
||||
State_t state;
|
||||
static const uint8_t INTERFACE_ID = POWER_SWITCHER;
|
||||
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 );
|
||||
ReturnValue_t initialize();
|
||||
ReturnValue_t initialize(object_id_t powerSwitchId);
|
||||
void turnOn();
|
||||
void turnOff();
|
||||
void doStateMachine();
|
||||
|
Reference in New Issue
Block a user