Refactor Power Switch #48
@ -1,7 +1,7 @@
|
||||
target_sources(${LIB_FSFW_NAME}
|
||||
PRIVATE
|
||||
Fuse.cpp
|
||||
PowerComponent.cpp
|
||||
PowerSensor.cpp
|
||||
PowerSwitcher.cpp
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE
|
||||
Fuse.cpp
|
||||
PowerComponent.cpp
|
||||
PowerSensor.cpp
|
||||
PowerSwitcher.cpp
|
||||
DummyPowerSwitcher.cpp
|
||||
)
|
43
src/fsfw/power/DummyPowerSwitcher.cpp
Normal file
43
src/fsfw/power/DummyPowerSwitcher.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "DummyPowerSwitcher.h"
|
||||
|
||||
DummyPowerSwitcher::DummyPowerSwitcher(size_t numberOfSwitches, size_t numberOfFuses,
|
||||
uint32_t switchDelayMs)
|
||||
: switcherList(numberOfSwitches), fuseList(numberOfFuses), switchDelayMs(switchDelayMs) {}
|
||||
|
||||
void DummyPowerSwitcher::setInitialSwitcherList(std::vector<ReturnValue_t> switcherList) {
|
||||
this->switcherList = switcherList;
|
||||
}
|
||||
|
||||
void DummyPowerSwitcher::setInitialFusesList(std::vector<ReturnValue_t> fuseList) {
|
||||
this->fuseList = fuseList;
|
||||
}
|
||||
|
||||
ReturnValue_t DummyPowerSwitcher::sendSwitchCommand(power::Switch_t switchNr, ReturnValue_t onOff) {
|
||||
if (switchNr < switcherList.capacity()) {
|
||||
switcherList[switchNr] = onOff;
|
||||
}
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t DummyPowerSwitcher::sendFuseOnCommand(uint8_t fuseNr) {
|
||||
if (fuseNr < fuseList.capacity()) {
|
||||
fuseList[fuseNr] = FUSE_ON;
|
||||
}
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t DummyPowerSwitcher::getSwitchState(power::Switch_t switchNr) const {
|
||||
if (switchNr < switcherList.capacity()) {
|
||||
return switcherList[switchNr];
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t DummyPowerSwitcher::getFuseState(uint8_t fuseNr) const {
|
||||
if (fuseNr < fuseList.capacity()) {
|
||||
return fuseList[fuseNr];
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
uint32_t DummyPowerSwitcher::getSwitchDelayMs(void) const { return switchDelayMs; }
|
29
src/fsfw/power/DummyPowerSwitcher.h
Normal file
29
src/fsfw/power/DummyPowerSwitcher.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef FSFW_SRC_FSFW_POWER_DUMMYPOWERSWITCHER_H_
|
||||
#define FSFW_SRC_FSFW_POWER_DUMMYPOWERSWITCHER_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
#include "PowerSwitchIF.h"
|
||||
#include "definitions.h"
|
||||
|
||||
class DummyPowerSwitcher : public PowerSwitchIF {
|
||||
public:
|
||||
DummyPowerSwitcher(size_t numberOfSwitches, size_t numberOfFuses, uint32_t switchDelayMs = 5000);
|
||||
|
||||
void setInitialSwitcherList(std::vector<ReturnValue_t> switcherList);
|
||||
void setInitialFusesList(std::vector<ReturnValue_t> switcherList);
|
||||
|
||||
virtual ReturnValue_t sendSwitchCommand(power::Switch_t switchNr, ReturnValue_t onOff) override;
|
||||
virtual ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override;
|
||||
virtual ReturnValue_t getSwitchState(power::Switch_t switchNr) const override;
|
||||
virtual ReturnValue_t getFuseState(uint8_t fuseNr) const override;
|
||||
virtual uint32_t getSwitchDelayMs(void) const override;
|
||||
|
||||
private:
|
||||
std::vector<ReturnValue_t> switcherList;
|
||||
std::vector<ReturnValue_t> fuseList;
|
||||
uint32_t switchDelayMs = 5000;
|
||||
};
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_POWER_DUMMYPOWERSWITCHER_H_ */
|
@ -34,14 +34,14 @@ class Fuse : public SystemObject,
|
||||
};
|
||||
|
||||
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.
|
||||
//! PSS detected that current on a fuse is totally out of bounds.
|
||||
static const Event FUSE_CURRENT_HIGH = MAKE_EVENT(1, severity::LOW);
|
||||
//! PSS detected a fuse that went off.
|
||||
static const Event FUSE_WENT_OFF = MAKE_EVENT(2, severity::LOW);
|
||||
//! PSS detected a fuse that violates its limits.
|
||||
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);
|
||||
|
||||
typedef std::list<PowerComponentIF *> DeviceList;
|
||||
Fuse(object_id_t fuseObjectId, uint8_t fuseId, sid_t variableSet, VariableIds ids,
|
||||
|
@ -15,7 +15,8 @@ PowerSensor::PowerSensor(object_id_t objectId, sid_t setId, VariableIds ids, Def
|
||||
limits.currentMin, limits.currentMax, events.currentLow, events.currentHigh),
|
||||
voltageLimit(objectId, MODULE_ID_VOLTAGE, ids.pidVoltage, confirmationCount,
|
||||
limits.voltageMin, limits.voltageMax, events.voltageLow, events.voltageHigh) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue();
|
||||
commandQueue =
|
||||
QueueFactory::instance()->createMessageQueue(3, MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
PowerSensor::~PowerSensor() { QueueFactory::instance()->deleteMessageQueue(commandQueue); }
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "../events/Event.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "definitions.h"
|
||||
/**
|
||||
*
|
||||
* @brief This interface defines a connection to a device that is capable of
|
||||
@ -37,11 +38,11 @@ class PowerSwitchIF : public HasReturnvaluesIF {
|
||||
* @param switchNr
|
||||
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
|
||||
*/
|
||||
virtual void sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) const = 0;
|
||||
virtual ReturnValue_t sendSwitchCommand(power::Switch_t switchNr, ReturnValue_t onOff) = 0;
|
||||
/**
|
||||
* Sends a command to the Power Unit to enable a certain fuse.
|
||||
*/
|
||||
virtual void sendFuseOnCommand(uint8_t fuseNr) const = 0;
|
||||
virtual ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) = 0;
|
||||
|
||||
/**
|
||||
* get the state of the Switches.
|
||||
@ -51,7 +52,7 @@ class PowerSwitchIF : public HasReturnvaluesIF {
|
||||
* - @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;
|
||||
virtual ReturnValue_t getSwitchState(power::Switch_t switchNr) const = 0;
|
||||
/**
|
||||
* get state of a fuse.
|
||||
* @param fuseNr
|
||||
|
@ -1,19 +1,12 @@
|
||||
#include "fsfw/power/PowerSwitcher.h"
|
||||
|
||||
#include "definitions.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
PowerSwitcher::PowerSwitcher(uint8_t setSwitch1, uint8_t setSwitch2,
|
||||
PowerSwitcher::State_t setStartState)
|
||||
: state(setStartState), firstSwitch(setSwitch1), secondSwitch(setSwitch2) {}
|
||||
|
||||
ReturnValue_t PowerSwitcher::initialize(object_id_t powerSwitchId) {
|
||||
power = ObjectManager::instance()->get<PowerSwitchIF>(powerSwitchId);
|
||||
if (power == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
PowerSwitcher::PowerSwitcher(PowerSwitchIF* switcher, power::Switch_t setSwitch1,
|
||||
power::Switch_t setSwitch2, PowerSwitcher::State_t setStartState)
|
||||
: power(switcher), state(setStartState), firstSwitch(setSwitch1), secondSwitch(setSwitch2) {}
|
||||
|
||||
ReturnValue_t PowerSwitcher::getStateOfSwitches() {
|
||||
SwitchReturn_t result = howManySwitches();
|
||||
@ -52,18 +45,37 @@ void PowerSwitcher::commandSwitches(ReturnValue_t onOff) {
|
||||
return;
|
||||
}
|
||||
|
||||
void PowerSwitcher::turnOn() {
|
||||
void PowerSwitcher::turnOn(bool checkCurrentState) {
|
||||
if (checkCurrentState) {
|
||||
if (getStateOfSwitches() == PowerSwitchIF::SWITCH_ON) {
|
||||
state = SWITCH_IS_ON;
|
||||
return;
|
||||
}
|
||||
}
|
||||
commandSwitches(PowerSwitchIF::SWITCH_ON);
|
||||
state = WAIT_ON;
|
||||
}
|
||||
|
||||
void PowerSwitcher::turnOff() {
|
||||
void PowerSwitcher::turnOff(bool checkCurrentState) {
|
||||
if (checkCurrentState) {
|
||||
if (getStateOfSwitches() == PowerSwitchIF::SWITCH_OFF) {
|
||||
state = SWITCH_IS_OFF;
|
||||
return;
|
||||
}
|
||||
}
|
||||
commandSwitches(PowerSwitchIF::SWITCH_OFF);
|
||||
state = WAIT_OFF;
|
||||
}
|
||||
|
||||
bool PowerSwitcher::active() {
|
||||
if (state == WAIT_OFF or state == WAIT_ON) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PowerSwitcher::SwitchReturn_t PowerSwitcher::howManySwitches() {
|
||||
if (secondSwitch == NO_SWITCH) {
|
||||
if (secondSwitch == power::NO_SWITCH) {
|
||||
return ONE_SWITCH;
|
||||
} else {
|
||||
return TWO_SWITCHES;
|
||||
|
@ -14,28 +14,28 @@ class PowerSwitcher : public HasReturnvaluesIF {
|
||||
SWITCH_IS_OFF,
|
||||
SWITCH_IS_ON,
|
||||
};
|
||||
State_t state;
|
||||
|
||||
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,
|
||||
PowerSwitcher(PowerSwitchIF* switcher, uint8_t setSwitch1, uint8_t setSwitch2 = power::NO_SWITCH,
|
||||
State_t setStartState = SWITCH_IS_OFF);
|
||||
ReturnValue_t initialize(object_id_t powerSwitchId);
|
||||
void turnOn();
|
||||
void turnOff();
|
||||
void turnOn(bool checkCurrentState = true);
|
||||
void turnOff(bool checkCurrentState = true);
|
||||
bool active();
|
||||
void doStateMachine();
|
||||
State_t getState();
|
||||
ReturnValue_t checkSwitchState();
|
||||
uint32_t getSwitchDelay();
|
||||
uint8_t getFirstSwitch() const;
|
||||
uint8_t getSecondSwitch() const;
|
||||
power::Switch_t getFirstSwitch() const;
|
||||
power::Switch_t getSecondSwitch() const;
|
||||
|
||||
private:
|
||||
uint8_t firstSwitch;
|
||||
uint8_t secondSwitch;
|
||||
PowerSwitchIF* power = nullptr;
|
||||
State_t state;
|
||||
power::Switch_t firstSwitch = power::NO_SWITCH;
|
||||
power::Switch_t secondSwitch = power::NO_SWITCH;
|
||||
|
||||
static const uint8_t NO_SWITCH = 0xFF;
|
||||
enum SwitchReturn_t { ONE_SWITCH = 1, TWO_SWITCHES = 2 };
|
||||
ReturnValue_t getStateOfSwitches();
|
||||
void commandSwitches(ReturnValue_t onOff);
|
||||
|
13
src/fsfw/power/definitions.h
Normal file
13
src/fsfw/power/definitions.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef FSFW_SRC_FSFW_POWER_DEFINITIONS_H_
|
||||
#define FSFW_SRC_FSFW_POWER_DEFINITIONS_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace power {
|
||||
|
||||
using Switch_t = uint8_t;
|
||||
static constexpr Switch_t NO_SWITCH = 0xFF;
|
||||
|
||||
} // namespace power
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_POWER_DEFINITIONS_H_ */
|
@ -1,8 +1,9 @@
|
||||
#include "version.h"
|
||||
#include "fsfw/FSFWVersion.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "fsfw/FSFWVersion.h"
|
||||
|
||||
#ifdef major
|
||||
#undef major
|
||||
#endif
|
||||
|
@ -29,7 +29,7 @@ class Version {
|
||||
}
|
||||
|
||||
friend bool operator>(const Version& v1, const Version& v2) {
|
||||
return not (v1 < v2) and not (v1 == v2);
|
||||
return not(v1 < v2) and not(v1 == v2);
|
||||
}
|
||||
|
||||
friend bool operator<=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 < v2)); }
|
||||
|
@ -17,15 +17,15 @@ TEST_CASE("Version API Tests", "[TestVersionAPI]") {
|
||||
fsfw::Version v1 = fsfw::Version(1, 1, 1);
|
||||
fsfw::Version v2 = fsfw::Version(1, 1, 1);
|
||||
REQUIRE(v1 == v2);
|
||||
REQUIRE(not (v1 < v2));
|
||||
REQUIRE(not (v1 > v2));
|
||||
REQUIRE(not(v1 < v2));
|
||||
REQUIRE(not(v1 > v2));
|
||||
REQUIRE(v1 <= v2);
|
||||
REQUIRE(v1 >= v2);
|
||||
v1.revision -= 1;
|
||||
REQUIRE(v1 != v2);
|
||||
REQUIRE(not (v1 == v2));
|
||||
REQUIRE(not (v1 > v2));
|
||||
REQUIRE(not (v1 >= v2));
|
||||
REQUIRE(not(v1 == v2));
|
||||
REQUIRE(not(v1 > v2));
|
||||
REQUIRE(not(v1 >= v2));
|
||||
REQUIRE(v1 < v2);
|
||||
REQUIRE(v1 <= v2);
|
||||
v1.revision += 1;
|
||||
@ -33,60 +33,60 @@ TEST_CASE("Version API Tests", "[TestVersionAPI]") {
|
||||
REQUIRE(v1 != v2);
|
||||
REQUIRE(v1 < v2);
|
||||
REQUIRE(v1 <= v2);
|
||||
REQUIRE(not (v1 == v2));
|
||||
REQUIRE(not (v1 > v2));
|
||||
REQUIRE(not (v1 >= v2));
|
||||
REQUIRE(not(v1 == v2));
|
||||
REQUIRE(not(v1 > v2));
|
||||
REQUIRE(not(v1 >= v2));
|
||||
v1.minor += 1;
|
||||
v1.major -= 1;
|
||||
REQUIRE(v1 != v2);
|
||||
REQUIRE(v1 < v2);
|
||||
REQUIRE(v1 <= v2);
|
||||
REQUIRE(not (v1 == v2));
|
||||
REQUIRE(not (v1 > v2));
|
||||
REQUIRE(not (v1 >= v2));
|
||||
REQUIRE(not(v1 == v2));
|
||||
REQUIRE(not(v1 > v2));
|
||||
REQUIRE(not(v1 >= v2));
|
||||
v1.major += 1;
|
||||
REQUIRE(v1 == v2);
|
||||
REQUIRE(v1 <= v2);
|
||||
REQUIRE(v1 >= v2);
|
||||
REQUIRE(not (v1 != v2));
|
||||
REQUIRE(not (v1 > v2));
|
||||
REQUIRE(not (v1 < v2));
|
||||
REQUIRE(not(v1 != v2));
|
||||
REQUIRE(not(v1 > v2));
|
||||
REQUIRE(not(v1 < v2));
|
||||
v1.major += 1;
|
||||
v1.minor -= 1;
|
||||
REQUIRE(v1 != v2);
|
||||
REQUIRE(v1 > v2);
|
||||
REQUIRE(v1 >= v2);
|
||||
REQUIRE(not (v1 == v2));
|
||||
REQUIRE(not (v1 < v2));
|
||||
REQUIRE(not (v1 <= v2));
|
||||
REQUIRE(not(v1 == v2));
|
||||
REQUIRE(not(v1 < v2));
|
||||
REQUIRE(not(v1 <= v2));
|
||||
v1.major -= 1;
|
||||
v1.minor += 2;
|
||||
v1.revision -= 1;
|
||||
REQUIRE(v1 != v2);
|
||||
REQUIRE(v1 > v2);
|
||||
REQUIRE(v1 >= v2);
|
||||
REQUIRE(not (v1 == v2));
|
||||
REQUIRE(not (v1 < v2));
|
||||
REQUIRE(not (v1 <= v2));
|
||||
REQUIRE(not(v1 == v2));
|
||||
REQUIRE(not(v1 < v2));
|
||||
REQUIRE(not(v1 <= v2));
|
||||
v1.minor -= 1;
|
||||
v1.revision += 2;
|
||||
REQUIRE(v1 != v2);
|
||||
REQUIRE(v1 > v2);
|
||||
REQUIRE(v1 >= v2);
|
||||
REQUIRE(not (v1 == v2));
|
||||
REQUIRE(not (v1 < v2));
|
||||
REQUIRE(not (v1 <= v2));
|
||||
REQUIRE(not(v1 == v2));
|
||||
REQUIRE(not(v1 < v2));
|
||||
REQUIRE(not(v1 <= v2));
|
||||
v1.revision -= 1;
|
||||
REQUIRE(v1 == v2);
|
||||
REQUIRE(v1 <= v2);
|
||||
REQUIRE(v1 >= v2);
|
||||
REQUIRE(not (v1 != v2));
|
||||
REQUIRE(not(v1 != v2));
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::info << "v" << fsfw::FSFW_VERSION << std::endl;
|
||||
#endif
|
||||
char verString[10] = {};
|
||||
fsfw::FSFW_VERSION.getVersion(verString, sizeof(verString));
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
printf("v%s\n",verString);
|
||||
printf("v%s\n", verString);
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user