From dba3c27b99c4f7473909a27af7c60b1d8a31c10c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 8 Mar 2022 09:56:24 +0100 Subject: [PATCH 01/16] define FSFW_DISABLE_PRINTOUT in any case --- src/fsfw/FSFW.h.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fsfw/FSFW.h.in b/src/fsfw/FSFW.h.in index 9cfeab61b..953677bde 100644 --- a/src/fsfw/FSFW.h.in +++ b/src/fsfw/FSFW.h.in @@ -30,6 +30,10 @@ #define FSFW_VERBOSE_LEVEL 1 #endif /* FSFW_VERBOSE_LEVEL */ +#ifndef FSFW_DISABLE_PRINTOUT +#define FSFW_DISABLE_PRINTOUT 0 +#endif + #ifndef FSFW_USE_REALTIME_FOR_LINUX #define FSFW_USE_REALTIME_FOR_LINUX 0 #endif /* FSFW_USE_REALTIME_FOR_LINUX */ From d63c01b96f2eb031eb4d568879dfee2e2151537a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 8 Mar 2022 11:50:47 +0100 Subject: [PATCH 02/16] set timeout in countdown ctor --- src/fsfw/timemanager/Countdown.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fsfw/timemanager/Countdown.cpp b/src/fsfw/timemanager/Countdown.cpp index 8ff46f8df..a8ba78cbb 100644 --- a/src/fsfw/timemanager/Countdown.cpp +++ b/src/fsfw/timemanager/Countdown.cpp @@ -1,6 +1,8 @@ #include "fsfw/timemanager/Countdown.h" -Countdown::Countdown(uint32_t initialTimeout) : timeout(initialTimeout) {} +Countdown::Countdown(uint32_t initialTimeout) : timeout(initialTimeout) { + setTimeout(initialTimeout); +} Countdown::~Countdown() {} From 45b51f9ac87cd15ad46555198c682fd279daeab0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Mar 2022 19:05:07 +0100 Subject: [PATCH 03/16] improved version.h --- src/fsfw/FSFWVersion.h.in | 6 +++--- src/fsfw/version.cpp | 13 ++++++++----- src/fsfw/version.h | 25 +++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/fsfw/FSFWVersion.h.in b/src/fsfw/FSFWVersion.h.in index 7935b2f61..19a562143 100644 --- a/src/fsfw/FSFWVersion.h.in +++ b/src/fsfw/FSFWVersion.h.in @@ -2,8 +2,8 @@ #define FSFW_VERSION_H_ // Versioning is kept in project CMakeLists.txt file -#define FSFW_VERSION @FSFW_VERSION@ -#define FSFW_SUBVERSION @FSFW_SUBVERSION@ -#define FSFW_REVISION @FSFW_REVISION@ +#define FSFW_VERSION_MAJOR @FSFW_VERSION@ +#define FSFW_VERSION_MINOR @FSFW_SUBVERSION@ +#define FSFW_VERSION_REVISION @FSFW_REVISION@ #endif /* FSFW_VERSION_H_ */ diff --git a/src/fsfw/version.cpp b/src/fsfw/version.cpp index 1bdd6cc73..e1fc32c90 100644 --- a/src/fsfw/version.cpp +++ b/src/fsfw/version.cpp @@ -1,8 +1,11 @@ #include "version.h" + #include "fsfw/FSFWVersion.h" -void fsfw::getVersion(Version& v) { - v.major = FSFW_VERSION; - v.minor = FSFW_SUBVERSION; - v.revision = FSFW_REVISION; -} +const fsfw::Version fsfw::FSFW_VERSION = {FSFW_VERSION_MAJOR, FSFW_VERSION_MINOR, + FSFW_VERSION_REVISION}; + +fsfw::Version::Version(uint32_t major, uint32_t minor, uint32_t revision) + : major(major), minor(minor), revision(revision) {} + +void fsfw::getVersion(Version& version) {} diff --git a/src/fsfw/version.h b/src/fsfw/version.h index 04b7e3ce4..8340fc9de 100644 --- a/src/fsfw/version.h +++ b/src/fsfw/version.h @@ -5,14 +5,35 @@ namespace fsfw { -struct Version { +class Version { + public: + Version(uint32_t major, uint32_t minor, uint32_t revision); uint32_t major = 0; uint32_t minor = 0; uint32_t revision = 0; + + friend bool operator==(const Version& v1, const Version& v2) { + return (v1.major == v2.major and v1.minor == v2.minor and v1.revision == v2.revision); + } + + friend bool operator!=(const Version& v1, const Version& v2) { return not(v1 == v2); } + + friend bool operator<(const Version& v1, const Version& v2) { + return ((v1.major < v2.major) or (v1.major == v2.major and v1.minor < v2.minor) or + (v1.major == v2.major and v1.minor == v2.minor and v1.revision < v2.revision)); + } + + friend bool operator>(const Version& v1, const Version& v2) { return not(v1 < v2); } + + friend bool operator<=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 < v2)); } + + friend bool operator>=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 > v2)); } }; +extern const fsfw::Version FSFW_VERSION; + void getVersion(Version& version); -} +} // namespace fsfw #endif /* FSFW_SRC_FSFW_VERSION_H_ */ From b27f3b84aa37d5c8723f9a0408d2eb40e9302478 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Mar 2022 19:10:05 +0100 Subject: [PATCH 04/16] getter not required anymore --- src/fsfw/version.cpp | 2 -- src/fsfw/version.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/fsfw/version.cpp b/src/fsfw/version.cpp index e1fc32c90..133b96748 100644 --- a/src/fsfw/version.cpp +++ b/src/fsfw/version.cpp @@ -7,5 +7,3 @@ const fsfw::Version fsfw::FSFW_VERSION = {FSFW_VERSION_MAJOR, FSFW_VERSION_MINOR fsfw::Version::Version(uint32_t major, uint32_t minor, uint32_t revision) : major(major), minor(minor), revision(revision) {} - -void fsfw::getVersion(Version& version) {} diff --git a/src/fsfw/version.h b/src/fsfw/version.h index 8340fc9de..478608656 100644 --- a/src/fsfw/version.h +++ b/src/fsfw/version.h @@ -32,8 +32,6 @@ class Version { extern const fsfw::Version FSFW_VERSION; -void getVersion(Version& version); - } // namespace fsfw #endif /* FSFW_SRC_FSFW_VERSION_H_ */ From 97bc71a3ff9048e45c5306b02afafd30e783fa48 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Mar 2022 09:34:29 +0100 Subject: [PATCH 05/16] added tests --- src/fsfw/version.h | 28 ++++++++++++ tests/src/fsfw_tests/unit/CMakeLists.txt | 11 +++-- tests/src/fsfw_tests/unit/version.cpp | 55 ++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 tests/src/fsfw_tests/unit/version.cpp diff --git a/src/fsfw/version.h b/src/fsfw/version.h index 478608656..4ed748d13 100644 --- a/src/fsfw/version.h +++ b/src/fsfw/version.h @@ -1,7 +1,13 @@ #ifndef FSFW_SRC_FSFW_VERSION_H_ #define FSFW_SRC_FSFW_VERSION_H_ +#include "fsfw/FSFW.h" + +#if FSFW_CPP_OSTREAM_ENABLED == 1 +#include +#endif #include +#include namespace fsfw { @@ -28,6 +34,28 @@ class Version { friend bool operator<=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 < v2)); } friend bool operator>=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 > v2)); } + +#if FSFW_CPP_OSTREAM_ENABLED == 1 + /** + * Print format to given ostream using format "major.minor.revision" + * @param os + * @param v + * @return + */ + friend std::ostream& operator<<(std::ostream& os, const Version& v) { + os << v.major << "." << v.minor << "." << v.revision; + return os; + } +#endif + + /** + * Get version as format "major.minor.revision" + * @param str + * @param maxLen + */ + void getVersion(char* str, size_t maxLen) const { + snprintf(str, maxLen, "%d.%d.%d", major, minor, revision); + } }; extern const fsfw::Version FSFW_VERSION; diff --git a/tests/src/fsfw_tests/unit/CMakeLists.txt b/tests/src/fsfw_tests/unit/CMakeLists.txt index a83e2f7f8..a8d31d88a 100644 --- a/tests/src/fsfw_tests/unit/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/CMakeLists.txt @@ -2,14 +2,13 @@ target_sources(${FSFW_TEST_TGT} PRIVATE CatchDefinitions.cpp CatchFactory.cpp printChar.cpp + version.cpp ) -# if(FSFW_CUSTOM_UNITTEST_RUNNER) - target_sources(${FSFW_TEST_TGT} PRIVATE - CatchRunner.cpp - CatchSetup.cpp - ) -# endif() +target_sources(${FSFW_TEST_TGT} PRIVATE + CatchRunner.cpp + CatchSetup.cpp +) add_subdirectory(testcfg) add_subdirectory(action) diff --git a/tests/src/fsfw_tests/unit/version.cpp b/tests/src/fsfw_tests/unit/version.cpp new file mode 100644 index 000000000..6fcff215f --- /dev/null +++ b/tests/src/fsfw_tests/unit/version.cpp @@ -0,0 +1,55 @@ + +#include "fsfw/version.h" + +#include + +#include "fsfw/serviceinterface.h" +#include "fsfw_tests/unit/CatchDefinitions.h" + +TEST_CASE("Version API Tests", "[TestVersionAPI]") { + // Check that major version is non-zero + REQUIRE(fsfw::FSFW_VERSION.major > 0); + uint32_t fsfwMajor = fsfw::FSFW_VERSION.major; + REQUIRE(fsfw::Version(255, 0, 0) > fsfw::FSFW_VERSION); + REQUIRE(fsfw::Version(255, 0, 0) >= fsfw::FSFW_VERSION); + REQUIRE(fsfw::Version(0, 0, 0) < fsfw::FSFW_VERSION); + REQUIRE(fsfw::Version(0, 0, 0) <= fsfw::FSFW_VERSION); + fsfw::Version v1 = fsfw::Version(1, 1, 1); + fsfw::Version v2 = fsfw::Version(1, 1, 1); + v1.revision -= 1; + REQUIRE(v1 != v2); + REQUIRE(v1 < v2); + REQUIRE(v1 <= v2); + v1.revision += 1; + v1.minor -= 1; + REQUIRE(v1 != v2); + REQUIRE(v1 < v2); + REQUIRE(v1 <= v2); + v1.minor += 1; + v1.major -= 1; + REQUIRE(v1 != v2); + REQUIRE(v1 < v2); + REQUIRE(v1 <= v2); + v1.major += 1; + REQUIRE(v1 == v2); + v1.major += 1; + REQUIRE(v1 != v2); + REQUIRE(v1 > v2); + REQUIRE(v1 >= v2); + v1.major -= 1; + v1.minor += 1; + REQUIRE(v1 != v2); + REQUIRE(v1 > v2); + REQUIRE(v1 >= v2); + v1.minor -= 1; + v1.revision += 1; + REQUIRE(v1 != v2); + REQUIRE(v1 > v2); + REQUIRE(v1 >= v2); + v1.revision -= 1; + REQUIRE(v1 == v2); + sif::info << "v" << fsfw::FSFW_VERSION << std::endl; + char verString[10] = {}; + fsfw::FSFW_VERSION.getVersion(verString, sizeof(verString)); + sif::info << "v" << verString << std::endl; +} From b5d6b9745f3e5fdd10463677ca2acb688cad4e84 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 10 Mar 2022 09:56:23 +0100 Subject: [PATCH 06/16] undef major and minor --- src/fsfw/version.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fsfw/version.cpp b/src/fsfw/version.cpp index 133b96748..aa777c9ee 100644 --- a/src/fsfw/version.cpp +++ b/src/fsfw/version.cpp @@ -2,6 +2,9 @@ #include "fsfw/FSFWVersion.h" +#undef major +#undef minor + const fsfw::Version fsfw::FSFW_VERSION = {FSFW_VERSION_MAJOR, FSFW_VERSION_MINOR, FSFW_VERSION_REVISION}; From fec5f83f4f2459facee25939e0292115f89a6d73 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 11 Mar 2022 14:25:01 +0100 Subject: [PATCH 07/16] minor event changes --- src/fsfw/events/Event.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/fsfw/events/Event.h b/src/fsfw/events/Event.h index 20b66679e..edc1d838d 100644 --- a/src/fsfw/events/Event.h +++ b/src/fsfw/events/Event.h @@ -7,8 +7,19 @@ // could be moved to more suitable location #include -typedef uint16_t EventId_t; -typedef uint8_t EventSeverity_t; +using EventId_t = uint16_t; +using EventSeverity_t = uint8_t ; +using UniqueEventId_t = uint8_t; + +namespace severity { +enum Severity: EventSeverity_t { + INFO = 1, + LOW = 2, + MEDIUM = 3, + HIGH = 4 +}; + +} // namespace severity #define MAKE_EVENT(id, severity) (((severity) << 16) + (SUBSYSTEM_ID * 100) + (id)) @@ -20,18 +31,11 @@ constexpr EventId_t getEventId(Event event) { return (event & 0xFFFF); } constexpr EventSeverity_t getSeverity(Event event) { return ((event >> 16) & 0xFF); } -constexpr Event makeEvent(uint8_t subsystemId, uint8_t uniqueEventId, +constexpr Event makeEvent(uint8_t subsystemId, UniqueEventId_t uniqueEventId, EventSeverity_t eventSeverity) { return (eventSeverity << 16) + (subsystemId * 100) + uniqueEventId; } } // namespace event -namespace severity { -static constexpr EventSeverity_t INFO = 1; -static constexpr EventSeverity_t LOW = 2; -static constexpr EventSeverity_t MEDIUM = 3; -static constexpr EventSeverity_t HIGH = 4; -} // namespace severity - #endif /* EVENTOBJECT_EVENT_H_ */ From 543daaa95aa15d85a701c257ecf7c65964ea4d6f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Mar 2022 19:19:02 +0100 Subject: [PATCH 08/16] various tweaks and improvements --- src/fsfw/devicehandlers/AssemblyBase.cpp | 20 +++++++++++++------ src/fsfw/devicehandlers/AssemblyBase.h | 15 ++++++++++---- src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 20 ++++++++++++++++--- src/fsfw/devicehandlers/DeviceHandlerBase.h | 4 ++++ src/fsfw/fdir/FailureIsolationBase.cpp | 9 +++++---- 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/fsfw/devicehandlers/AssemblyBase.cpp b/src/fsfw/devicehandlers/AssemblyBase.cpp index c29022e53..414098adf 100644 --- a/src/fsfw/devicehandlers/AssemblyBase.cpp +++ b/src/fsfw/devicehandlers/AssemblyBase.cpp @@ -26,11 +26,7 @@ void AssemblyBase::performChildOperation() { void AssemblyBase::startTransition(Mode_t mode, Submode_t submode) { doStartTransition(mode, submode); - if (modeHelper.isForced()) { - triggerEvent(FORCING_MODE, mode, submode); - } else { - triggerEvent(CHANGING_MODE, mode, submode); - } + triggerModeHelperEvents(mode, submode); } void AssemblyBase::doStartTransition(Mode_t mode, Submode_t submode) { @@ -77,9 +73,10 @@ bool AssemblyBase::handleChildrenChangedHealth() { } HealthState healthState = healthHelper.healthTable->getHealth(iter->first); if (healthState == HasHealthIF::NEEDS_RECOVERY) { - triggerEvent(TRYING_RECOVERY); + triggerEvent(TRYING_RECOVERY, iter->first, 0); recoveryState = RECOVERY_STARTED; recoveringDevice = iter; + // The user needs to take care of commanding the children off in commandChildren doStartTransition(targetMode, targetSubmode); } else { triggerEvent(CHILD_CHANGED_HEALTH); @@ -228,6 +225,9 @@ ReturnValue_t AssemblyBase::handleHealthReply(CommandMessage* message) { bool AssemblyBase::checkAndHandleRecovery() { switch (recoveryState) { case RECOVERY_STARTED: + // The recovery was already start in #handleChildrenChangedHealth and we just need + // to wait for an off time period. + // TODO: make time period configurable recoveryState = RECOVERY_WAIT; recoveryOffTimer.resetTimer(); return true; @@ -266,3 +266,11 @@ void AssemblyBase::overwriteDeviceHealth(object_id_t objectId, HasHealthIF::Heal modeHelper.setForced(true); sendHealthCommand(childrenMap[objectId].commandQueue, EXTERNAL_CONTROL); } + +void AssemblyBase::triggerModeHelperEvents(Mode_t mode, Submode_t submode) { + if (modeHelper.isForced()) { + triggerEvent(FORCING_MODE, mode, submode); + } else { + triggerEvent(CHANGING_MODE, mode, submode); + } +} diff --git a/src/fsfw/devicehandlers/AssemblyBase.h b/src/fsfw/devicehandlers/AssemblyBase.h index f61925331..fd5c6ad6c 100644 --- a/src/fsfw/devicehandlers/AssemblyBase.h +++ b/src/fsfw/devicehandlers/AssemblyBase.h @@ -47,9 +47,8 @@ class AssemblyBase : public SubsystemBase { protected: /** - * Command children to reach [mode,submode] combination - * Can be done by setting #commandsOutstanding correctly, - * or using executeTable() + * Command children to reach [mode,submode] combination. Can be done by setting + * #commandsOutstanding correctly, or using #executeTable. * @param mode * @param submode * @return @@ -162,6 +161,12 @@ class AssemblyBase : public SubsystemBase { ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode); + /** + * Calls #doStartTransition and triggers an informative event as well that the mode will + * change + * @param mode + * @param submode + */ virtual void startTransition(Mode_t mode, Submode_t submode); /** @@ -190,7 +195,7 @@ class AssemblyBase : public SubsystemBase { * Manages recovery of a device * @return true if recovery is still ongoing, false else. */ - bool checkAndHandleRecovery(); + virtual bool checkAndHandleRecovery(); /** * Helper method to overwrite health state of one of the children. @@ -198,6 +203,8 @@ class AssemblyBase : public SubsystemBase { * @param objectId Must be a registered child. */ void overwriteDeviceHealth(object_id_t objectId, HasHealthIF::HealthState oldHealth); + + void triggerModeHelperEvents(Mode_t mode, Submode_t submode); }; #endif /* FSFW_DEVICEHANDLERS_ASSEMBLYBASE_H_ */ diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index 03f8da547..18f8a2f7c 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -49,9 +49,6 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t device printWarningOrError(sif::OutputTypes::OUT_ERROR, "DeviceHandlerBase", HasReturnvaluesIF::RETURN_FAILED, "Invalid cookie"); } - if (this->fdirInstance == nullptr) { - this->fdirInstance = new DeviceHandlerFailureIsolation(setObjectId, defaultFdirParentId); - } } void DeviceHandlerBase::setHkDestination(object_id_t hkDestination) { @@ -127,6 +124,17 @@ ReturnValue_t DeviceHandlerBase::initialize() { if (result != RETURN_OK) { return result; } + if (this->fdirInstance == nullptr) { + this->fdirInstance = new DeviceHandlerFailureIsolation(this->getObjectId(), defaultFdirParentId); + } + + if(this->parent != objects::NO_OBJECT) { + HasModesIF* modeIF = ObjectManager::instance()->get(this->parent); + HasHealthIF* healthIF = ObjectManager::instance()->get(this->parent); + if(modeIF != nullptr and healthIF != nullptr) { + setParentQueue(modeIF->getCommandQueue()); + } + } communicationInterface = ObjectManager::instance()->get(deviceCommunicationId); @@ -1494,3 +1502,9 @@ MessageQueueId_t DeviceHandlerBase::getCommanderQueueId(DeviceCommandId_t replyI } return commandIter->second.sendReplyTo; } + +void DeviceHandlerBase::setCustomFdir(FailureIsolationBase* fdir) { this->fdirInstance = fdir; } + +void DeviceHandlerBase::setParent(object_id_t parent) { this->parent = parent; } + +void DeviceHandlerBase::setPowerSwitcher(PowerSwitchIF* switcher) { this->powerSwitcher = switcher; } diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index bf6900d93..a8de34eb8 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -103,6 +103,9 @@ class DeviceHandlerBase : public DeviceHandlerIF, DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, CookieIF *comCookie, FailureIsolationBase *fdirInstance = nullptr, size_t cmdQueueSize = 20); + void setCustomFdir(FailureIsolationBase* fdir); + void setParent(object_id_t parent); + void setPowerSwitcher(PowerSwitchIF* switcher); void setHkDestination(object_id_t hkDestination); /** @@ -824,6 +827,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, /** Pointer to the used FDIR instance. If not provided by child, * default class is instantiated. */ FailureIsolationBase *fdirInstance; + object_id_t parent = objects::NO_OBJECT; //! To correctly delete the default instance. bool defaultFDIRUsed; diff --git a/src/fsfw/fdir/FailureIsolationBase.cpp b/src/fsfw/fdir/FailureIsolationBase.cpp index 5d04588fb..f576ecbdb 100644 --- a/src/fsfw/fdir/FailureIsolationBase.cpp +++ b/src/fsfw/fdir/FailureIsolationBase.cpp @@ -53,10 +53,11 @@ ReturnValue_t FailureIsolationBase::initialize() { if (parentIF == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "FailureIsolationBase::intialize: Parent object" - << "invalid." << std::endl; -#endif -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "Make sure it implements ConfirmsFailuresIF." << std::endl; + << "invalid" << std::endl; + sif::error << "Make sure it implements ConfirmsFailuresIF" << std::endl; +#else + sif::printError("FailureIsolationBase::intialize: Parent object invalid\n"); + sif::printError("Make sure it implements ConfirmsFailuresIF\n"); #endif return ObjectManagerIF::CHILD_INIT_FAILED; return RETURN_FAILED; From ddc1cdb1f5d1ee6f532c04b0419e24f8f40566cf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Mar 2022 19:22:24 +0100 Subject: [PATCH 09/16] additional docs --- src/fsfw/devicehandlers/AssemblyBase.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fsfw/devicehandlers/AssemblyBase.h b/src/fsfw/devicehandlers/AssemblyBase.h index fd5c6ad6c..ab5f2201f 100644 --- a/src/fsfw/devicehandlers/AssemblyBase.h +++ b/src/fsfw/devicehandlers/AssemblyBase.h @@ -48,7 +48,9 @@ class AssemblyBase : public SubsystemBase { protected: /** * Command children to reach [mode,submode] combination. Can be done by setting - * #commandsOutstanding correctly, or using #executeTable. + * #commandsOutstanding correctly, or using #executeTable. In case of an FDIR recovery, + * the user needs to ensure that the target devices are healthy. If a device is not healthy, + * a recovery might be on-going and the device needs to be commanded to off first. * @param mode * @param submode * @return From b6ed45a85cae1f1af83f352b4e6f8bb787743cb1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 17 Mar 2022 19:59:16 +0100 Subject: [PATCH 10/16] small form fix --- src/fsfw/fdir/FailureIsolationBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/fdir/FailureIsolationBase.cpp b/src/fsfw/fdir/FailureIsolationBase.cpp index f576ecbdb..c17cf6240 100644 --- a/src/fsfw/fdir/FailureIsolationBase.cpp +++ b/src/fsfw/fdir/FailureIsolationBase.cpp @@ -52,7 +52,7 @@ ReturnValue_t FailureIsolationBase::initialize() { ObjectManager::instance()->get(faultTreeParent); if (parentIF == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FailureIsolationBase::intialize: Parent object" + sif::error << "FailureIsolationBase::intialize: Parent object " << "invalid" << std::endl; sif::error << "Make sure it implements ConfirmsFailuresIF" << std::endl; #else From 927041209bdc4e2ffc6528d4083dbcc9d0ced098 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 21 Mar 2022 09:12:56 +0100 Subject: [PATCH 11/16] added override specifiers --- src/fsfw/subsystem/SubsystemBase.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/fsfw/subsystem/SubsystemBase.h b/src/fsfw/subsystem/SubsystemBase.h index 8cfd5be07..20507ce08 100644 --- a/src/fsfw/subsystem/SubsystemBase.h +++ b/src/fsfw/subsystem/SubsystemBase.h @@ -15,7 +15,9 @@ /** * @defgroup subsystems Subsystem Objects - * Contains all Subsystem and Assemblies + * All Subsystem and Assemblies can derive from this class. It contains helper classes to + * perform mode and health handling, which allows OBSW developers to build a mode tree for + * the whole satellite */ class SubsystemBase : public SystemObject, public HasModesIF, @@ -123,11 +125,11 @@ class SubsystemBase : public SystemObject, virtual void performChildOperation() = 0; virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, - uint32_t *msToReachTheMode) = 0; + uint32_t *msToReachTheMode) override = 0; - virtual void startTransition(Mode_t mode, Submode_t submode) = 0; + virtual void startTransition(Mode_t mode, Submode_t submode) override = 0; - virtual void getMode(Mode_t *mode, Submode_t *submode); + virtual void getMode(Mode_t *mode, Submode_t *submode) override; virtual void setToExternalControl(); From d791fc87b7bba11c1baa68d544cd991028ff3330 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 15:49:04 +0100 Subject: [PATCH 12/16] some improvements for PowerSwitcher --- src/fsfw/power/PowerSwitchIF.h | 5 +++-- src/fsfw/power/PowerSwitcher.cpp | 17 +++++------------ src/fsfw/power/PowerSwitcher.h | 15 +++++++-------- src/fsfw/power/definitions.h | 13 +++++++++++++ 4 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 src/fsfw/power/definitions.h diff --git a/src/fsfw/power/PowerSwitchIF.h b/src/fsfw/power/PowerSwitchIF.h index a31d89711..b2c0cb9bd 100644 --- a/src/fsfw/power/PowerSwitchIF.h +++ b/src/fsfw/power/PowerSwitchIF.h @@ -1,6 +1,7 @@ #ifndef FSFW_POWER_POWERSWITCHIF_H_ #define FSFW_POWER_POWERSWITCHIF_H_ +#include "definitions.h" #include "../events/Event.h" #include "../returnvalues/HasReturnvaluesIF.h" /** @@ -37,7 +38,7 @@ 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 void sendSwitchCommand(power::Switch_t switchNr, ReturnValue_t onOff) const = 0; /** * Sends a command to the Power Unit to enable a certain fuse. */ @@ -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 diff --git a/src/fsfw/power/PowerSwitcher.cpp b/src/fsfw/power/PowerSwitcher.cpp index 0a3f8521d..4f8e6cbe5 100644 --- a/src/fsfw/power/PowerSwitcher.cpp +++ b/src/fsfw/power/PowerSwitcher.cpp @@ -1,19 +1,12 @@ +#include "definitions.h" #include "fsfw/power/PowerSwitcher.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(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(); @@ -63,7 +56,7 @@ void PowerSwitcher::turnOff() { } PowerSwitcher::SwitchReturn_t PowerSwitcher::howManySwitches() { - if (secondSwitch == NO_SWITCH) { + if (secondSwitch == power::NO_SWITCH) { return ONE_SWITCH; } else { return TWO_SWITCHES; diff --git a/src/fsfw/power/PowerSwitcher.h b/src/fsfw/power/PowerSwitcher.h index c72c241d1..46e8d0fd4 100644 --- a/src/fsfw/power/PowerSwitcher.h +++ b/src/fsfw/power/PowerSwitcher.h @@ -14,28 +14,27 @@ 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 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); diff --git a/src/fsfw/power/definitions.h b/src/fsfw/power/definitions.h new file mode 100644 index 000000000..1e4fe2963 --- /dev/null +++ b/src/fsfw/power/definitions.h @@ -0,0 +1,13 @@ +#ifndef FSFW_SRC_FSFW_POWER_DEFINITIONS_H_ +#define FSFW_SRC_FSFW_POWER_DEFINITIONS_H_ + +#include + +namespace power { + +using Switch_t = uint8_t; +static constexpr Switch_t NO_SWITCH = 0xFF; + +} + +#endif /* FSFW_SRC_FSFW_POWER_DEFINITIONS_H_ */ From 6dd6f28db0259ec37c351a81ee8d26696f47118a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 15:55:18 +0100 Subject: [PATCH 13/16] added active function --- src/fsfw/power/PowerSwitcher.cpp | 7 +++++++ src/fsfw/power/PowerSwitcher.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/fsfw/power/PowerSwitcher.cpp b/src/fsfw/power/PowerSwitcher.cpp index 4f8e6cbe5..75273af02 100644 --- a/src/fsfw/power/PowerSwitcher.cpp +++ b/src/fsfw/power/PowerSwitcher.cpp @@ -55,6 +55,13 @@ void PowerSwitcher::turnOff() { 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 == power::NO_SWITCH) { return ONE_SWITCH; diff --git a/src/fsfw/power/PowerSwitcher.h b/src/fsfw/power/PowerSwitcher.h index 46e8d0fd4..9c3302c7d 100644 --- a/src/fsfw/power/PowerSwitcher.h +++ b/src/fsfw/power/PowerSwitcher.h @@ -22,6 +22,7 @@ class PowerSwitcher : public HasReturnvaluesIF { State_t setStartState = SWITCH_IS_OFF); void turnOn(); void turnOff(); + bool active(); void doStateMachine(); State_t getState(); ReturnValue_t checkSwitchState(); From 2823420c46410fe0ce8bd0c412835405a715e485 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 16:10:20 +0100 Subject: [PATCH 14/16] more docs --- src/fsfw/subsystem/Subsystem.h | 6 +++++- src/fsfw/subsystem/SubsystemBase.h | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/fsfw/subsystem/Subsystem.h b/src/fsfw/subsystem/Subsystem.h index 2c78c8cd3..953bb6821 100644 --- a/src/fsfw/subsystem/Subsystem.h +++ b/src/fsfw/subsystem/Subsystem.h @@ -12,8 +12,12 @@ #include "modes/ModeDefinitions.h" /** - * @brief TODO: documentation missing + * @brief This class extends the SubsystemBase to perform the management of mode tables + * and mode sequences * @details + * This class is able to use mode tables and sequences to command all its children into the + * right mode. Fallback sequences can be used to handle failed transitions or have a fallback + * in case a component can't keep its current mode. */ class Subsystem : public SubsystemBase, public HasModeSequenceIF { public: diff --git a/src/fsfw/subsystem/SubsystemBase.h b/src/fsfw/subsystem/SubsystemBase.h index 20507ce08..0853ed6ea 100644 --- a/src/fsfw/subsystem/SubsystemBase.h +++ b/src/fsfw/subsystem/SubsystemBase.h @@ -17,7 +17,12 @@ * @defgroup subsystems Subsystem Objects * All Subsystem and Assemblies can derive from this class. It contains helper classes to * perform mode and health handling, which allows OBSW developers to build a mode tree for - * the whole satellite + * the whole satellite. + * + * Aside from setting up a mode tree and being able to executing mode tables, this class does not + * provide an implementation on what to do with the features. To build a mode tree, helper classes + * like the #AssemblyBase or the #Subsystem class extend and use the functionality of the base + * class. */ class SubsystemBase : public SystemObject, public HasModesIF, @@ -98,6 +103,7 @@ class SubsystemBase : public SystemObject, Submode_t targetSubmode); /** + * This function takes care of sending all according mode commands specified inside a mode table. * We need to know the target Submode, as children are able to inherit the submode * Still, we have a default for all child implementations which do not use submode inheritance */ From bbe21e7e8957a39e6697c6dd4fb2fe044b560044 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 16:14:23 +0100 Subject: [PATCH 15/16] doc additions --- src/fsfw/devicehandlers/AssemblyBase.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/fsfw/devicehandlers/AssemblyBase.h b/src/fsfw/devicehandlers/AssemblyBase.h index ab5f2201f..a6e6e3dbb 100644 --- a/src/fsfw/devicehandlers/AssemblyBase.h +++ b/src/fsfw/devicehandlers/AssemblyBase.h @@ -12,7 +12,8 @@ * Documentation: Dissertation Baetz p.156, 157. * * This class reduces the complexity of controller components which would - * otherwise be needed for the handling of redundant devices. + * otherwise be needed for the handling of redundant devices. However, it can also be used to + * manage the mode keeping and recovery of non-redundant devices * * The template class monitors mode and health state of its children * and checks availability of devices on every detected change. @@ -26,11 +27,9 @@ * * Important: * - * The implementation must call registerChild(object_id_t child) - * for all commanded children during initialization. + * The implementation must call #registerChild for all commanded children during initialization. * The implementation must call the initialization function of the base class. * (This will call the function in SubsystemBase) - * */ class AssemblyBase : public SubsystemBase { public: From 4b5e3e70f7eb65780b697a81ba95ecc2a74a8b84 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Mar 2022 20:35:04 +0100 Subject: [PATCH 16/16] add option to directly check switch state --- src/fsfw/power/PowerSwitcher.cpp | 16 ++++++++++++++-- src/fsfw/power/PowerSwitcher.h | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/fsfw/power/PowerSwitcher.cpp b/src/fsfw/power/PowerSwitcher.cpp index 75273af02..83679772d 100644 --- a/src/fsfw/power/PowerSwitcher.cpp +++ b/src/fsfw/power/PowerSwitcher.cpp @@ -45,12 +45,24 @@ 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; } diff --git a/src/fsfw/power/PowerSwitcher.h b/src/fsfw/power/PowerSwitcher.h index 9c3302c7d..853bbb401 100644 --- a/src/fsfw/power/PowerSwitcher.h +++ b/src/fsfw/power/PowerSwitcher.h @@ -20,8 +20,8 @@ class PowerSwitcher : public HasReturnvaluesIF { static const ReturnValue_t SWITCH_STATE_MISMATCH = MAKE_RETURN_CODE(2); PowerSwitcher(PowerSwitchIF* switcher, uint8_t setSwitch1, uint8_t setSwitch2 = power::NO_SWITCH, State_t setStartState = SWITCH_IS_OFF); - void turnOn(); - void turnOff(); + void turnOn(bool checkCurrentState = true); + void turnOff(bool checkCurrentState = true); bool active(); void doStateMachine(); State_t getState();