From d766469f1ea16cb42d462d4efa596aa0767f60f2 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 11 Jul 2023 14:57:17 +0200 Subject: [PATCH] working on HK and Dataset TM --- src/fsfw/datapool/Dataset.cpp | 6 ++-- src/fsfw/datapool/Dataset.h | 22 ++++++------ src/fsfw/datapool/TemplateSet.h | 4 +-- src/fsfw/housekeeping/CMakeLists.txt | 4 ++- .../housekeeping/GeneratesHousekeepingIF.h | 10 ++++++ src/fsfw/housekeeping/HousekeepingEntryIF.h | 5 +++ src/fsfw/housekeeping/HousekeepingHelper.cpp | 16 +++++++++ src/fsfw/housekeeping/HousekeepingHelper.h | 30 ++++++++++++++++ src/fsfw/housekeeping/HousekeepingSet.cpp | 18 ++++++++++ src/fsfw/housekeeping/HousekeepingSet.h | 35 +++++++++++++++++++ src/fsfw/tmtc/UdpTmTcBridge.cpp | 4 +-- 11 files changed, 137 insertions(+), 17 deletions(-) create mode 100644 src/fsfw/housekeeping/GeneratesHousekeepingIF.h create mode 100644 src/fsfw/housekeeping/HousekeepingEntryIF.h create mode 100644 src/fsfw/housekeeping/HousekeepingHelper.cpp create mode 100644 src/fsfw/housekeeping/HousekeepingHelper.h create mode 100644 src/fsfw/housekeeping/HousekeepingSet.cpp create mode 100644 src/fsfw/housekeeping/HousekeepingSet.h diff --git a/src/fsfw/datapool/Dataset.cpp b/src/fsfw/datapool/Dataset.cpp index db0414b85..1859ada87 100644 --- a/src/fsfw/datapool/Dataset.cpp +++ b/src/fsfw/datapool/Dataset.cpp @@ -4,6 +4,8 @@ #include #include +#include "HasDatapoolIF.h" + #ifdef FSFW_INTROSPECTION Dataset::Dataset(HasDatapoolIF* owner, bool allowUserCommit) : allocated(true), allowUserCommit(allowUserCommit) { @@ -21,13 +23,13 @@ void Dataset::setEnum(EnumIF *theEnum) { description = theEnum->getDescription(); } #else -Dataset::Dataset(HasDatapoolIF* owner, uint8_t id, bool allowUserCommit) +Dataset::Dataset(HasDatapoolIF* owner, DataSetId_t id, bool allowUserCommit) : allocated(true), allowUserCommit(allowUserCommit), id(id) { this->owner.pointer = owner; mutex = MutexFactory::instance()->createMutex(); } -Dataset::Dataset(uint32_t owner_id, uint8_t id): id(id) { this->owner.id = owner_id; } +Dataset::Dataset(uint32_t owner_id, DataSetId_t id): id(id) { this->owner.id = owner_id; } #endif Dataset::~Dataset() { MutexFactory::instance()->deleteMutex(mutex); } diff --git a/src/fsfw/datapool/Dataset.h b/src/fsfw/datapool/Dataset.h index 1ecd9cfb6..38c4a7d86 100644 --- a/src/fsfw/datapool/Dataset.h +++ b/src/fsfw/datapool/Dataset.h @@ -9,8 +9,10 @@ #include #include "DatasetEntryIF.h" -#include "HasDatapoolIF.h" +// TODO ring inclusion +// #include "HasDatapoolIF.h" +class HasDatapoolIF; using DataSetId_t = uint32_t; @@ -47,8 +49,8 @@ class Dataset { Dataset(uint32_t owner_id); void setEnum(EnumIF* theEnum); #else - Dataset(HasDatapoolIF* owner, uint32_t id, bool allowUserCommit); - Dataset(uint32_t owner_id, uint32_t id); + Dataset(HasDatapoolIF* owner, DataSetId_t id, bool allowUserCommit); + Dataset(uint32_t owner_id, DataSetId_t id); #endif public: ~Dataset(); @@ -87,7 +89,7 @@ class Dataset { * Force sending of TM packet, in reference to tc * */ - void commitAndReport(store_address_t tc); + void commitAndReport(store_address_t tc, size_t tc_offset); /** * Copy content of local copies into actual variable @@ -96,23 +98,23 @@ class Dataset { * calls setValid(valid) before committing * */ - void commitAndReport(bool valid, store_address_t tc); + void commitAndReport(bool valid, store_address_t tc, size_t tc_offset); /** * Copy content of local copies into actual variable - * Force sending of TM packet, in reference to tc + * Force sending of TM packet, in reference to tc, if tc is valid * */ - void commitAndReportIfRequested(store_address_t tc); + void commitAndReportIfRequested(store_address_t tc, size_t tc_offset); /** * Copy content of local copies into actual variable - * Force sending of TM packet, in reference to tc + * Force sending of TM packet, in reference to tc, if tc is valid * * calls setValid(valid) before committing * */ - void commitAndReportIfRequested(bool valid, store_address_t tc); + void commitAndReportIfRequested(bool valid, store_address_t tc, size_t tc_offset); /** * set all contained variables to #valid @@ -168,7 +170,7 @@ class Dataset { uint32_t id; HasDatapoolIF* pointer; } owner; - uint8_t id; + DataSetId_t id; MutexIF* mutex; #ifdef FSFW_INTROSPECTION const char* description; diff --git a/src/fsfw/datapool/TemplateSet.h b/src/fsfw/datapool/TemplateSet.h index cf31e63ea..1abab9ca9 100644 --- a/src/fsfw/datapool/TemplateSet.h +++ b/src/fsfw/datapool/TemplateSet.h @@ -1,6 +1,6 @@ #pragma once -#include "DataSet.h" +#include "Dataset.h" //TODO use object_id_t @@ -19,7 +19,7 @@ class TemplateSet : public Dataset { : Dataset(owner, static_cast(id), allowUserCommit) { owner->getDatapoolHelper()->registerSet(this); } - TemplateSet(uint32_t owner_id, HkIDs id) : Dataset(owner_id, static_cast(id) {} + TemplateSet(uint32_t owner_id, HkIDs id) : Dataset(owner_id, static_cast(id)) {} #endif virtual ~TemplateSet() = default; }; \ No newline at end of file diff --git a/src/fsfw/housekeeping/CMakeLists.txt b/src/fsfw/housekeeping/CMakeLists.txt index 236d3204d..3fc70e047 100644 --- a/src/fsfw/housekeeping/CMakeLists.txt +++ b/src/fsfw/housekeeping/CMakeLists.txt @@ -1,2 +1,4 @@ target_sources(${LIB_FSFW_NAME} PRIVATE HousekeepingMessage.cpp - PeriodicHousekeepingHelper.cpp) + PeriodicHousekeepingHelper.cpp + HousekeepingHelper.cpp + HousekeepingSet.cpp) diff --git a/src/fsfw/housekeeping/GeneratesHousekeepingIF.h b/src/fsfw/housekeeping/GeneratesHousekeepingIF.h new file mode 100644 index 000000000..9521b7efd --- /dev/null +++ b/src/fsfw/housekeeping/GeneratesHousekeepingIF.h @@ -0,0 +1,10 @@ +#pragma once + +#include "HousekeepingHelper.h" + +class GeneratesHousekeepingIF { + public: + virtual ~GeneratesHousekeepingIF() = default; + + virtual HousekeepingHelper* getHelper(); +}; \ No newline at end of file diff --git a/src/fsfw/housekeeping/HousekeepingEntryIF.h b/src/fsfw/housekeeping/HousekeepingEntryIF.h new file mode 100644 index 000000000..e27005921 --- /dev/null +++ b/src/fsfw/housekeeping/HousekeepingEntryIF.h @@ -0,0 +1,5 @@ +#pragma once + +class HousekeepingEntryIF { + +}; \ No newline at end of file diff --git a/src/fsfw/housekeeping/HousekeepingHelper.cpp b/src/fsfw/housekeeping/HousekeepingHelper.cpp new file mode 100644 index 000000000..199f06fe0 --- /dev/null +++ b/src/fsfw/housekeeping/HousekeepingHelper.cpp @@ -0,0 +1,16 @@ +#include "HousekeepingHelper.h" + +HousekeepingHelper::HousekeepingHelper() {} + +const HousekeepingSet* HousekeepingHelper::getHousekeepingSet(HousekeepingSetId_t id) { + auto iter = housekeepingSets.find(id); + if (iter == housekeepingSets.end()) { + return nullptr; + } + return iter->second; +} + +void HousekeepingHelper::registerSet(HousekeepingSet* set) { + auto id = set->getId(); + housekeepingSets.emplace(id, set); +} diff --git a/src/fsfw/housekeeping/HousekeepingHelper.h b/src/fsfw/housekeeping/HousekeepingHelper.h new file mode 100644 index 000000000..a92ef5d32 --- /dev/null +++ b/src/fsfw/housekeeping/HousekeepingHelper.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include + +#include "HousekeepingSet.h" + +class HousekeepingHelper { + friend class HousekeepingHelper; + + public: + HousekeepingHelper(); + ~HousekeepingHelper() = default; + + const HousekeepingSet* getHousekeepingSet(HousekeepingSetId_t id); + + const std::map* getHousekeepingSets() const { + return &housekeepingSets; + } + + void registerSet(HousekeepingSet* set); + + protected: + ReturnValue_t reportHousekeeping(SerializeIF* data, const Action* action = nullptr); + + private: + std::map housekeepingSets; +}; \ No newline at end of file diff --git a/src/fsfw/housekeeping/HousekeepingSet.cpp b/src/fsfw/housekeeping/HousekeepingSet.cpp new file mode 100644 index 000000000..9e895edd2 --- /dev/null +++ b/src/fsfw/housekeeping/HousekeepingSet.cpp @@ -0,0 +1,18 @@ +#include "HousekeepingSet.h" + +#include "GeneratesHousekeepingIF.h" + +#ifdef FSFW_INTROSPECTION +HousekeepingSet::HousekeepingSet(GeneratesHousekeepingIF* owner, HousekeepingSetId_t id) { + owner->getHelper()->registerSet(this); +} + +void HousekeepingSet::setEnum(EnumIF* theEnum) { + id = theEnum->getValue(); + description = theEnum->getDescription(); +} +#else +HousekeepingSet::HousekeepingSet(GeneratesHousekeepingIF* owner, HousekeepingSetId_t id) : id(id) { + owner->getHelper()->registerSet(this); +} +#endif diff --git a/src/fsfw/housekeeping/HousekeepingSet.h b/src/fsfw/housekeeping/HousekeepingSet.h new file mode 100644 index 000000000..5cc51930b --- /dev/null +++ b/src/fsfw/housekeeping/HousekeepingSet.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include + +#include "HousekeepingEntryIF.h" + +class HousekeepingHelper; +class GeneratesHousekeepingIF; + +using HousekeepingSetId_t = uint32_t; + +class HousekeepingSet { + public: +#ifdef FSFW_INTROSPECTION + HousekeepingSet(GeneratesHousekeepingIF* owner); + void setEnum(EnumIF* theEnum); +#else + HousekeepingSet(GeneratesHousekeepingIF* owner, HousekeepingSetId_t id); +#endif + + HousekeepingSetId_t getId() const { return id; } + + void report(const Action* action = nullptr); + + protected: + HousekeepingHelper* helper; + HousekeepingSetId_t id; +#ifdef FSFW_INTROSPECTION + const char* description; +#endif + std::vector variables; +}; \ No newline at end of file diff --git a/src/fsfw/tmtc/UdpTmTcBridge.cpp b/src/fsfw/tmtc/UdpTmTcBridge.cpp index 6ff5a0322..9a32d7464 100644 --- a/src/fsfw/tmtc/UdpTmTcBridge.cpp +++ b/src/fsfw/tmtc/UdpTmTcBridge.cpp @@ -218,7 +218,7 @@ void UdpTmTcBridgeNew::handleTM() { result = IPCStore->getData(tm, &tmData, &tmDataSize); if (result != returnvalue::OK) { // nothing to send - if (tc != store_address_t()) { + if (IPCStore->hasDataAtId(tc)) { IPCStore->deleteData(tc); } return; @@ -230,7 +230,7 @@ void UdpTmTcBridgeNew::handleTM() { sif::error << "UdpTmTcBridge::handleTM: sendto failed with " << errno << std::endl; } IPCStore->deleteData(tm); - if (tc != store_address_t()) { + if (IPCStore->hasDataAtId(tc)) { IPCStore->deleteData(tc); } }