Today's the day. Renamed platform to framework.
This commit is contained in:
20
power/HasPowerSwitchIF.h
Normal file
20
power/HasPowerSwitchIF.h
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @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_ */
|
75
power/PowerSwitchIF.h
Normal file
75
power/PowerSwitchIF.h
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @file PowerSwitchIF.h
|
||||
* @brief This file defines the PowerSwitchIF class.
|
||||
* @date 20.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef POWERSWITCHIF_H_
|
||||
#define POWERSWITCHIF_H_
|
||||
|
||||
#include <framework/events/Event.h>
|
||||
#include <framework/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.
|
||||
*/
|
||||
class PowerSwitchIF : public HasReturnvaluesIF {
|
||||
public:
|
||||
/**
|
||||
* Empty dtor.
|
||||
*/
|
||||
virtual ~PowerSwitchIF() {
|
||||
|
||||
}
|
||||
/**
|
||||
* The Returnvalues id of this class, required by HasReturnvaluesIF
|
||||
*/
|
||||
static const uint8_t INTERFACE_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!
|
||||
/**
|
||||
* send a direct command to the Power Unit to enable/disable the specified switch.
|
||||
*
|
||||
* @param switchNr
|
||||
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
|
||||
*/
|
||||
virtual void sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const = 0;
|
||||
/**
|
||||
* Sends a command to the Power Unit to enable a certain fuse.
|
||||
*/
|
||||
virtual void sendFuseOnCommand(uint8_t fuseNr) const = 0;
|
||||
|
||||
/**
|
||||
* get the state of the Switches.
|
||||
* @param switchNr
|
||||
* @return
|
||||
* - @c SWITCH_ON if the specified switch is on.
|
||||
* - @c SWITCH_OFF if the specified switch is off.
|
||||
* - @c RETURN_FAILED if an error occured
|
||||
*/
|
||||
virtual ReturnValue_t getSwitchState( uint8_t switchNr ) const = 0;
|
||||
/**
|
||||
* get state of a fuse.
|
||||
* @param fuseNr
|
||||
* @return
|
||||
* - @c FUSE_ON if the specified fuse is on.
|
||||
* - @c FUSE_OFF if the specified fuse is off.
|
||||
* - @c RETURN_FAILED if an error occured
|
||||
*/
|
||||
virtual ReturnValue_t getFuseState( uint8_t fuseNr ) const = 0;
|
||||
/**
|
||||
* The maximum delay that it will take to change a switch
|
||||
*
|
||||
* This may take into account the time to send a command, wait for it to be executed and see the switch changed.
|
||||
*/
|
||||
virtual uint32_t getSwitchDelayMs(void) const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* POWERSWITCHIF_H_ */
|
134
power/PowerSwitcher.cpp
Normal file
134
power/PowerSwitcher.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* PowerSwitcher.cpp
|
||||
*
|
||||
* Created on: 21.01.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/power/PowerSwitcher.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
PowerSwitcher::PowerSwitcher(uint8_t setSwitch1, uint8_t setSwitch2,
|
||||
PowerSwitcher::State_t setStartState) :
|
||||
state(setStartState), firstSwitch(setSwitch1), secondSwitch(setSwitch2), power(NULL) {
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSwitcher::initialize() {
|
||||
power = objectManager->get<PowerSwitchIF>(objects::PCDU_HANDLER);
|
||||
if (power == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
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)) {
|
||||
return PowerSwitchIF::SWITCH_ON;
|
||||
} else if ((power->getSwitchState(firstSwitch) == PowerSwitchIF::SWITCH_OFF)
|
||||
&& (power->getSwitchState(secondSwitch) == PowerSwitchIF::SWITCH_OFF)) {
|
||||
return PowerSwitchIF::SWITCH_OFF;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
default:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerSwitcher::commandSwitches(ReturnValue_t onOff) {
|
||||
SwitchReturn_t result = howManySwitches();
|
||||
switch (result) {
|
||||
case TWO_SWITCHES:
|
||||
power->sendSwitchCommand(secondSwitch, onOff);
|
||||
/*NO BREAK*/
|
||||
case ONE_SWITCH:
|
||||
power->sendSwitchCommand(firstSwitch, onOff);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void PowerSwitcher::turnOn() {
|
||||
commandSwitches(PowerSwitchIF::SWITCH_ON);
|
||||
state = WAIT_ON;
|
||||
}
|
||||
|
||||
void PowerSwitcher::turnOff() {
|
||||
commandSwitches(PowerSwitchIF::SWITCH_OFF);
|
||||
state = WAIT_OFF;
|
||||
}
|
||||
|
||||
PowerSwitcher::SwitchReturn_t PowerSwitcher::howManySwitches() {
|
||||
if (secondSwitch == NO_SWITCH) {
|
||||
return ONE_SWITCH;
|
||||
} else {
|
||||
return TWO_SWITCHES;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerSwitcher::doStateMachine() {
|
||||
switch (state) {
|
||||
case SWITCH_IS_OFF:
|
||||
case SWITCH_IS_ON:
|
||||
//Do nothing.
|
||||
break;
|
||||
case WAIT_OFF:
|
||||
if (getStateOfSwitches() == PowerSwitchIF::SWITCH_OFF) {
|
||||
state = SWITCH_IS_OFF;
|
||||
}
|
||||
break;
|
||||
case WAIT_ON:
|
||||
if (getStateOfSwitches() == PowerSwitchIF::SWITCH_ON) {
|
||||
state = SWITCH_IS_ON;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//Should never happen.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PowerSwitcher::checkSwitchState() {
|
||||
switch (state) {
|
||||
case WAIT_OFF:
|
||||
case WAIT_ON:
|
||||
return IN_POWER_TRANSITION;
|
||||
case SWITCH_IS_OFF:
|
||||
if (getStateOfSwitches() == PowerSwitchIF::SWITCH_OFF) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return SWITCH_STATE_MISMATCH;
|
||||
}
|
||||
case SWITCH_IS_ON:
|
||||
if (getStateOfSwitches() == PowerSwitchIF::SWITCH_ON) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return SWITCH_STATE_MISMATCH;
|
||||
}
|
||||
}
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
PowerSwitcher::State_t PowerSwitcher::getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
uint32_t PowerSwitcher::getSwitchDelay() {
|
||||
return power->getSwitchDelayMs();
|
||||
}
|
||||
|
||||
uint8_t PowerSwitcher::getFirstSwitch() const {
|
||||
return firstSwitch;
|
||||
}
|
||||
|
||||
uint8_t PowerSwitcher::getSecondSwitch() const {
|
||||
return secondSwitch;
|
||||
}
|
52
power/PowerSwitcher.h
Normal file
52
power/PowerSwitcher.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* PowerSwitcher.h
|
||||
*
|
||||
* Created on: 21.01.2014
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef POWERSWITCHER_H_
|
||||
#define POWERSWITCHER_H_
|
||||
#include <framework/power/PowerSwitchIF.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <framework/timemanager/Countdown.h>
|
||||
|
||||
class PowerSwitcher : public HasReturnvaluesIF {
|
||||
public:
|
||||
enum State_t {
|
||||
WAIT_OFF,
|
||||
WAIT_ON,
|
||||
SWITCH_IS_OFF,
|
||||
SWITCH_IS_ON,
|
||||
};
|
||||
State_t state;
|
||||
static const uint8_t INTERFACE_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();
|
||||
void turnOn();
|
||||
void turnOff();
|
||||
void doStateMachine();
|
||||
State_t getState();
|
||||
ReturnValue_t checkSwitchState();
|
||||
uint32_t getSwitchDelay();
|
||||
uint8_t getFirstSwitch() const;
|
||||
uint8_t getSecondSwitch() const;
|
||||
private:
|
||||
uint8_t firstSwitch;
|
||||
uint8_t secondSwitch;
|
||||
PowerSwitchIF* power;
|
||||
static const uint8_t NO_SWITCH = 0xFF;
|
||||
enum SwitchReturn_t {
|
||||
ONE_SWITCH = 1,
|
||||
TWO_SWITCHES = 2
|
||||
};
|
||||
ReturnValue_t getStateOfSwitches();
|
||||
void commandSwitches( ReturnValue_t onOff );
|
||||
SwitchReturn_t howManySwitches();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* POWERSWITCHER_H_ */
|
Reference in New Issue
Block a user