Merge pull request 'Refactor Power Module' (#49) from mueller/refactor-power-switch-if-etc-eive into eive/develop

Reviewed-on: #49
This commit is contained in:
Jakob Meier 2022-03-31 09:01:24 +02:00
commit 61d0815de8
9 changed files with 121 additions and 41 deletions

View File

@ -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
)

View File

@ -0,0 +1,46 @@
#include "DummyPowerSwitcher.h"
DummyPowerSwitcher::DummyPowerSwitcher(object_id_t objectId, size_t numberOfSwitches,
size_t numberOfFuses, uint32_t switchDelayMs)
: SystemObject(objectId),
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; }

View File

@ -0,0 +1,31 @@
#ifndef FSFW_SRC_FSFW_POWER_DUMMYPOWERSWITCHER_H_
#define FSFW_SRC_FSFW_POWER_DUMMYPOWERSWITCHER_H_
#include <cstddef>
#include <vector>
#include "PowerSwitchIF.h"
#include "definitions.h"
#include "fsfw/objectmanager/SystemObject.h"
class DummyPowerSwitcher : public SystemObject, public PowerSwitchIF {
public:
DummyPowerSwitcher(object_id_t objectId, 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_ */

View File

@ -4,6 +4,7 @@
#include "definitions.h"
#include "../events/Event.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "definitions.h"
/**
*
* @brief This interface defines a connection to a device that is capable of
@ -38,11 +39,11 @@ class PowerSwitchIF : public HasReturnvaluesIF {
* @param switchNr
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
*/
virtual void sendSwitchCommand(power::Switch_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.

View File

@ -1,6 +1,7 @@
#include "definitions.h"
#include "fsfw/power/PowerSwitcher.h"
#include "definitions.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
@ -46,8 +47,8 @@ void PowerSwitcher::commandSwitches(ReturnValue_t onOff) {
}
void PowerSwitcher::turnOn(bool checkCurrentState) {
if(checkCurrentState) {
if(getStateOfSwitches() == PowerSwitchIF::SWITCH_ON) {
if (checkCurrentState) {
if (getStateOfSwitches() == PowerSwitchIF::SWITCH_ON) {
state = SWITCH_IS_ON;
return;
}
@ -57,8 +58,8 @@ void PowerSwitcher::turnOn(bool checkCurrentState) {
}
void PowerSwitcher::turnOff(bool checkCurrentState) {
if(checkCurrentState) {
if(getStateOfSwitches() == PowerSwitchIF::SWITCH_OFF) {
if (checkCurrentState) {
if (getStateOfSwitches() == PowerSwitchIF::SWITCH_OFF) {
state = SWITCH_IS_OFF;
return;
}
@ -68,7 +69,7 @@ void PowerSwitcher::turnOff(bool checkCurrentState) {
}
bool PowerSwitcher::active() {
if(state == WAIT_OFF or state == WAIT_ON) {
if (state == WAIT_OFF or state == WAIT_ON) {
return true;
}
return false;

View File

@ -8,6 +8,6 @@ namespace power {
using Switch_t = uint8_t;
static constexpr Switch_t NO_SWITCH = 0xFF;
}
} // namespace power
#endif /* FSFW_SRC_FSFW_POWER_DEFINITIONS_H_ */

View File

@ -1,8 +1,9 @@
#include "version.h"
#include "fsfw/FSFWVersion.h"
#include <cstdio>
#include "fsfw/FSFWVersion.h"
#ifdef major
#undef major
#endif

View File

@ -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)); }

View File

@ -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
}