Merge branch 'development' into mueller/DeviceHandler-LocalPools

This commit is contained in:
Steffen Gaisser 2020-12-10 17:00:51 +01:00
commit 3fd18f9c58
12 changed files with 236 additions and 129 deletions

View File

@ -15,6 +15,10 @@ a C file without issues
- The same is possible for the event reporting service (PUS5) - The same is possible for the event reporting service (PUS5)
- PUS Health Service added, which allows to command and retrieve health via PUS packets - PUS Health Service added, which allows to command and retrieve health via PUS packets
### File System Interface
- A new interfaces specifies the functions for a software object which exposes the file system of a given hardware to use message based file handling (e.g. PUS commanding)
### Internal Error Reporter ### Internal Error Reporter
- The new internal error reporter uses the local data pools. The pool IDs for - The new internal error reporter uses the local data pools. The pool IDs for

80
memory/HasFileSystemIF.h Normal file
View File

@ -0,0 +1,80 @@
#ifndef FSFW_MEMORY_HASFILESYSTEMIF_H_
#define FSFW_MEMORY_HASFILESYSTEMIF_H_
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../returnvalues/FwClassIds.h"
#include "../ipc/messageQueueDefinitions.h"
#include <cstddef>
/**
* @brief Generic interface for objects which expose a file system to enable
* message based file handling.
* @author J. Meier, R. Mueller
*/
class HasFileSystemIF {
public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::FILE_SYSTEM;
static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x00);
static constexpr ReturnValue_t FILE_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01);
static constexpr ReturnValue_t FILE_LOCKED = MAKE_RETURN_CODE(0x02);
static constexpr ReturnValue_t DIRECTORY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03);
static constexpr ReturnValue_t DIRECTORY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x04);
static constexpr ReturnValue_t DIRECTORY_NOT_EMPTY = MAKE_RETURN_CODE(0x05);
static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_WRITE = MAKE_RETURN_CODE(0x06); //! P1: Sequence number missing
static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(0x07); //! P1: Sequence number missing
virtual ~HasFileSystemIF() {}
/**
* Function to get the MessageQueueId_t of the implementing object
* @return MessageQueueId_t of the object
*/
virtual MessageQueueId_t getCommandQueue() const = 0;
/**
* Generic function to append to file.
* @param dirname Directory of the file
* @param filename The filename of the file
* @param data The data to write to the file
* @param size The size of the data to write
* @param packetNumber Current packet number. Can be used to verify that
* there are no missing packets.
* @param args Any other arguments which an implementation might require.
* @param bytesWritten Actual bytes written to file
* For large files the write procedure must be split in multiple calls
* to writeToFile
*/
virtual ReturnValue_t appendToFile(const char* repositoryPath,
const char* filename, const uint8_t* data, size_t size,
uint16_t packetNumber, void* args = nullptr) = 0;
/**
* Generic function to create a new file.
* @param repositoryPath
* @param filename
* @param data
* @param size
* @param args Any other arguments which an implementation might require.
* @return
*/
virtual ReturnValue_t createFile(const char* repositoryPath,
const char* filename, const uint8_t* data = nullptr,
size_t size = 0, void* args = nullptr) = 0;
/**
* Generic function to delete a file.
* @param repositoryPath
* @param filename
* @param args
* @return
*/
virtual ReturnValue_t deleteFile(const char* repositoryPath,
const char* filename, void* args = nullptr) = 0;
};
#endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */

View File

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

View File

@ -1,17 +1,16 @@
#ifndef FUSE_H_ #ifndef FSFW_POWER_FUSE_H_
#define 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 "../devicehandlers/HealthDevice.h"
#include "../monitoring/AbsLimitMonitor.h" #include "../monitoring/AbsLimitMonitor.h"
#include "../power/PowerComponentIF.h"
#include "../power/PowerSwitchIF.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include "../parameters/ParameterHelper.h" #include "../parameters/ParameterHelper.h"
#include <list> #include <list>
#include "../datapoollocal/StaticLocalDataSet.h"
namespace Factory { namespace Factory {
void setStaticFrameworkObjectIds(); 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 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;
@ -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. 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();
@ -70,7 +69,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:
@ -85,12 +84,14 @@ private:
}; };
PowerMonitor powerMonitor; PowerMonitor powerMonitor;
GlobDataSet set; StaticLocalDataSet<3> set;
PIDReader<float> voltage;
PIDReader<float> current; lp_var_t<float> voltage;
PIDReader<uint8_t> state; lp_var_t<float> current;
gp_float_t power; lp_var_t<uint8_t> state;
MessageQueueIF* commandQueue;
lp_var_t<float> power;
MessageQueueIF* commandQueue = nullptr;
ParameterHelper parameterHelper; ParameterHelper parameterHelper;
HealthHelper healthHelper; HealthHelper healthHelper;
static object_id_t powerSwitchId; static object_id_t powerSwitchId;
@ -103,4 +104,4 @@ private:
bool areSwitchesOfComponentOn(DeviceList::iterator iter); 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 "PowerComponent.h"
#include "../serialize/SerializeAdapter.h"
PowerComponent::PowerComponent() : PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF),
deviceObjectId(0), switchId1(0xFF), switchId2(0xFF), doIHaveTwoSwitches( doIHaveTwoSwitches(false) {
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) : PowerComponent::PowerComponent(object_id_t setId, uint8_t moduleId, float min,
deviceObjectId(setId), switchId1(switchId1), switchId2(switchId2), doIHaveTwoSwitches( float max, uint8_t switchId1, bool twoSwitches, uint8_t switchId2) :
twoSwitches), min(min), max(max), moduleId(moduleId) { deviceObjectId(setId), switchId1(switchId1), switchId2(switchId2),
doIHaveTwoSwitches(twoSwitches), min(min), max(max),
moduleId(moduleId) {
} }
ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size, ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size,
@ -80,7 +75,7 @@ ReturnValue_t PowerComponent::getParameter(uint8_t domainId,
parameterWrapper->set<>(max); parameterWrapper->set<>(max);
break; break;
default: default:
return INVALID_MATRIX_ID; return INVALID_IDENTIFIER_ID;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

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

View File

@ -1,14 +1,13 @@
#ifndef POWERCOMPONENTIF_H_ #ifndef FSFW_POWER_POWERCOMPONENTIF_H_
#define POWERCOMPONENTIF_H_ #define FSFW_POWER_POWERCOMPONENTIF_H_
#include "../serialize/SerializeIF.h" #include "../serialize/SerializeIF.h"
#include "../parameters/HasParametersIF.h" #include "../parameters/HasParametersIF.h"
#include "../objectmanager/SystemObjectIF.h"
class PowerComponentIF : public SerializeIF, public HasParametersIF { class PowerComponentIF : public SerializeIF, public HasParametersIF {
public: public:
virtual ~PowerComponentIF() { virtual ~PowerComponentIF() {}
}
virtual object_id_t getDeviceObjectId() = 0; virtual object_id_t getDeviceObjectId() = 0;
@ -21,4 +20,4 @@ public:
}; };
#endif /* POWERCOMPONENTIF_H_ */ #endif /* FSFW_POWER_POWERCOMPONENTIF_H_ */

View File

@ -1,14 +1,18 @@
#include "PowerSensor.h" #include "PowerSensor.h"
#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), commandQueue(NULL), parameterHelper(this), healthHelper(this, setId), set(), current( SystemObject(objectId), parameterHelper(this),
ids.pidCurrent, &set), voltage(ids.pidVoltage, &set), power( healthHelper(this, objectId),
ids.poolIdPower, &set, PoolVariableIF::VAR_WRITE), currentLimit( powerSensorSet(setId), current(ids.pidCurrent, &powerSensorSet),
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), voltageLimit(setId, MODULE_ID_VOLTAGE, events.currentHigh),
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();
@ -19,13 +23,13 @@ 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.value);
result2 = currentLimit.doCheck(current); result2 = currentLimit.doCheck(current.value);
} else { } else {
voltageLimit.setToInvalid(); voltageLimit.setToInvalid();
currentLimit.setToInvalid(); currentLimit.setToInvalid();
@ -37,9 +41,9 @@ ReturnValue_t PowerSensor::calculatePower() {
power.setValid(PoolVariableIF::INVALID); power.setValid(PoolVariableIF::INVALID);
} else { } else {
power.setValid(PoolVariableIF::VALID); power.setValid(PoolVariableIF::VALID);
power = current * voltage; power.value = current.value * voltage.value;
} }
set.commit(); powerSensorSet.commit();
return result1; return result1;
} }
@ -92,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

@ -1,9 +1,7 @@
#ifndef POWERSENSOR_H_ #ifndef FSFW_POWER_POWERSENSOR_H_
#define POWERSENSOR_H_ #define FSFW_POWER_POWERSENSOR_H_
#include "../datapoolglob/GlobalDataSet.h" #include "../datapoollocal/StaticLocalDataSet.h"
#include "../datapoolglob/GlobalPoolVariable.h"
#include "../datapoolglob/PIDReader.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 +10,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 +35,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);
@ -50,15 +52,19 @@ public:
ParameterWrapper *parameterWrapper, ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex); const ParameterWrapper *newValues, uint16_t startAtIndex);
private: private:
MessageQueueIF* commandQueue; 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;
@ -68,4 +74,4 @@ protected:
LimitMonitor<float> voltageLimit; LimitMonitor<float> voltageLimit;
}; };
#endif /* POWERSENSOR_H_ */ #endif /* FSFW_POWER_POWERSENSOR_H_ */

View File

@ -1,18 +1,16 @@
/** #ifndef FSFW_POWER_POWERSWITCHIF_H_
* @file PowerSwitchIF.h #define FSFW_POWER_POWERSWITCHIF_H_
* @brief This file defines the PowerSwitchIF class.
* @date 20.03.2013
* @author baetz
*/
#ifndef POWERSWITCHIF_H_
#define POWERSWITCHIF_H_
#include "../events/Event.h" #include "../events/Event.h"
#include "../returnvalues/HasReturnvaluesIF.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 { class PowerSwitchIF : public HasReturnvaluesIF {
public: 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 "PowerSwitcher.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h" #include "../serviceinterface/ServiceInterfaceStream.h"
PowerSwitcher::PowerSwitcher(uint8_t setSwitch1, uint8_t setSwitch2, PowerSwitcher::PowerSwitcher(uint8_t setSwitch1, uint8_t setSwitch2,
PowerSwitcher::State_t setStartState): PowerSwitcher::State_t setStartState):
state(setStartState), firstSwitch(setSwitch1), secondSwitch(setSwitch2), power(NULL) { state(setStartState), firstSwitch(setSwitch1),
secondSwitch(setSwitch2) {
} }
ReturnValue_t PowerSwitcher::initialize(object_id_t powerSwitchId) { ReturnValue_t PowerSwitcher::initialize(object_id_t powerSwitchId) {
power = objectManager->get<PowerSwitchIF>(powerSwitchId); power = objectManager->get<PowerSwitchIF>(powerSwitchId);
if (power == NULL) { if (power == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
@ -17,19 +19,25 @@ ReturnValue_t PowerSwitcher::initialize(object_id_t powerSwitchId) {
ReturnValue_t PowerSwitcher::getStateOfSwitches() { ReturnValue_t PowerSwitcher::getStateOfSwitches() {
SwitchReturn_t result = howManySwitches(); SwitchReturn_t result = howManySwitches();
switch (result) { switch (result) {
case ONE_SWITCH: case ONE_SWITCH:
return power->getSwitchState(firstSwitch); return power->getSwitchState(firstSwitch);
case TWO_SWITCHES: case TWO_SWITCHES: {
if ((power->getSwitchState(firstSwitch) == PowerSwitchIF::SWITCH_ON) ReturnValue_t firstSwitchState = power->getSwitchState(firstSwitch);
&& (power->getSwitchState(secondSwitch) == PowerSwitchIF::SWITCH_ON)) { ReturnValue_t secondSwitchState = power->getSwitchState(firstSwitch);
if ((firstSwitchState == PowerSwitchIF::SWITCH_ON)
&& (secondSwitchState == PowerSwitchIF::SWITCH_ON)) {
return 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; return PowerSwitchIF::SWITCH_OFF;
} else { }
else {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
}
default: default:
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }

View File

@ -1,6 +1,9 @@
#ifndef POWERSWITCHER_H_ #ifndef FSFW_POWER_POWERSWITCHER_H_
#define POWERSWITCHER_H_ #define FSFW_POWER_POWERSWITCHER_H_
#include "PowerSwitchIF.h" #include "PowerSwitchIF.h"
#include "../objectmanager/SystemObjectIF.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include "../timemanager/Countdown.h" #include "../timemanager/Countdown.h"
@ -16,7 +19,8 @@ public:
static const uint8_t INTERFACE_ID = CLASS_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 IN_POWER_TRANSITION = MAKE_RETURN_CODE(1);
static const ReturnValue_t SWITCH_STATE_MISMATCH = MAKE_RETURN_CODE(2); 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); ReturnValue_t initialize(object_id_t powerSwitchId);
void turnOn(); void turnOn();
void turnOff(); void turnOff();
@ -29,7 +33,8 @@ public:
private: private:
uint8_t firstSwitch; uint8_t firstSwitch;
uint8_t secondSwitch; uint8_t secondSwitch;
PowerSwitchIF* power; PowerSwitchIF* power = nullptr;
static const uint8_t NO_SWITCH = 0xFF; static const uint8_t NO_SWITCH = 0xFF;
enum SwitchReturn_t { enum SwitchReturn_t {
ONE_SWITCH = 1, ONE_SWITCH = 1,
@ -42,4 +47,4 @@ private:
#endif /* POWERSWITCHER_H_ */ #endif /* FSFW_POWER_POWERSWITCHER_H_ */