From d251d7ed02417e9b9562721b5225d5b2ac9e7caf Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 13 Nov 2024 14:12:23 +0100 Subject: [PATCH] some improvements --- misc/archive/mgmRm3100Helpers.h | 4 +-- src/fsfw/housekeeping/PeriodicHkHelper.cpp | 37 ++++++++++++++++------ src/fsfw/housekeeping/PeriodicHkHelper.h | 6 +++- src/fsfw/housekeeping/PeriodicHkHelperIF.h | 1 + src/fsfw/serialize/SerializableList.h | 2 ++ 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/misc/archive/mgmRm3100Helpers.h b/misc/archive/mgmRm3100Helpers.h index 676c268f..be29915c 100644 --- a/misc/archive/mgmRm3100Helpers.h +++ b/misc/archive/mgmRm3100Helpers.h @@ -1,13 +1,13 @@ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ #define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_ +#include + #include "fsfw/datapoollocal/LocalPoolVariable.h" #include "fsfw/datapoollocal/StaticLocalDataSet.h" #include "fsfw/devicehandlers/DeviceHandlerIF.h" #include "fsfw/serialize/SerialLinkedListAdapter.h" -#include - namespace mgmRm3100 { /* Actually 10, we round up a little bit */ diff --git a/src/fsfw/housekeeping/PeriodicHkHelper.cpp b/src/fsfw/housekeeping/PeriodicHkHelper.cpp index b0b3052d..e690ebff 100644 --- a/src/fsfw/housekeeping/PeriodicHkHelper.cpp +++ b/src/fsfw/housekeeping/PeriodicHkHelper.cpp @@ -139,7 +139,7 @@ GeneratesPeriodicHkIF* PeriodicHelper::getOwner() const { return owner; } ReturnValue_t PeriodicHelper::generateHousekeepingPacket(const dp::sid_t sid, MessageQueueId_t destination) { store_address_t storeId; - const auto optSetSpec = getSetSpecification(sid); + const auto optSetSpec = getMutSetSpecification(sid); if (!optSetSpec.has_value()) { return DATASET_NOT_FOUND; } @@ -212,7 +212,7 @@ void PeriodicHelper::performPeriodicHkGeneration(SetSpecification& setSpec, time } ReturnValue_t PeriodicHelper::togglePeriodicGeneration(const dp::sid_t sid, const bool enable) { - const auto optSetSpec = getSetSpecification(sid); + const auto optSetSpec = getMutSetSpecification(sid); if (!optSetSpec.has_value()) { printWarningOrError(sif::OutputTypes::OUT_WARNING, "togglePeriodicGeneration", DATASET_NOT_FOUND); @@ -222,7 +222,7 @@ ReturnValue_t PeriodicHelper::togglePeriodicGeneration(const dp::sid_t sid, cons return returnvalue::OK; } -std::optional> PeriodicHelper::getSetSpecification( +std::optional> PeriodicHelper::getMutSetSpecification( dp::sid_t structureId) { for (auto& receiver : setList) { if (receiver.dataId.sid == structureId) { @@ -232,6 +232,16 @@ std::optional> PeriodicHelper::getSetSp return std::nullopt; } +std::optional> PeriodicHelper::getSetSpecification( + dp::sid_t structureId) const { + for (const auto& receiver : setList) { + if (receiver.dataId.sid == structureId) { + return receiver; + } + } + return std::nullopt; +} + ReturnValue_t PeriodicHelper::setCollectionInterval(dp::sid_t sid, dur_millis_t newCollectionIntervalMs) { bool wasUpdated = false; @@ -250,7 +260,7 @@ ReturnValue_t PeriodicHelper::setCollectionInterval(dp::sid_t sid, ReturnValue_t PeriodicHelper::generateSetStructurePacket(dp::structure_id_t sid) { // Get and check dataset first. - auto optSetSpec = getSetSpecification(sid); + auto optSetSpec = getMutSetSpecification(sid); if (!optSetSpec.has_value()) { printWarningOrError(sif::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration", DATASET_NOT_FOUND); @@ -301,10 +311,8 @@ ReturnValue_t PeriodicHelper::generateSetStructurePacket(dp::structure_id_t sid) ReturnValue_t PeriodicHelper::enablePeriodicPacket(const dp::structure_id_t structureId, const std::optional frequencyMs) { // Get and check dataset first. - const auto optSetSpec = getSetSpecification(structureId); + const auto optSetSpec = getMutSetSpecification(structureId); if (!optSetSpec.has_value()) { - printWarningOrError(sif::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration", - DATASET_NOT_FOUND); return DATASET_NOT_FOUND; } auto& setSpec = optSetSpec.value().get(); @@ -317,10 +325,8 @@ ReturnValue_t PeriodicHelper::enablePeriodicPacket(const dp::structure_id_t stru ReturnValue_t PeriodicHelper::disablePeriodicPacket(const dp::structure_id_t structureId) { // Get and check dataset first. - const auto optSetSpec = getSetSpecification(structureId); + const auto optSetSpec = getMutSetSpecification(structureId); if (!optSetSpec.has_value()) { - printWarningOrError(sif::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration", - DATASET_NOT_FOUND); return DATASET_NOT_FOUND; } auto& setSpec = optSetSpec.value().get(); @@ -328,6 +334,17 @@ ReturnValue_t PeriodicHelper::disablePeriodicPacket(const dp::structure_id_t str return returnvalue::OK; } +ReturnValue_t PeriodicHelper::collectionEnabled(dp::sid_t structureId, + bool& collectionEnabled) const { + // Get and check dataset first. + const auto optSetSpec = getSetSpecification(structureId); + if (!optSetSpec.has_value()) { + return DATASET_NOT_FOUND; + } + auto& setSpec = optSetSpec.value().get(); + collectionEnabled = setSpec.periodicCollectionEnabled; + return returnvalue::OK; +} object_id_t PeriodicHelper::getCreatorObjectId() const { return owner->getObjectId(); } void PeriodicHelper::printWarningOrError(sif::OutputTypes outputType, const char* functionName, diff --git a/src/fsfw/housekeeping/PeriodicHkHelper.h b/src/fsfw/housekeeping/PeriodicHkHelper.h index d5dbc2b3..837bb751 100644 --- a/src/fsfw/housekeeping/PeriodicHkHelper.h +++ b/src/fsfw/housekeeping/PeriodicHkHelper.h @@ -145,13 +145,17 @@ class PeriodicHelper : public PeriodicHelperIF { ReturnValue_t enablePeriodicPacket(dp::sid_t structureId, std::optional frequencyMs) override; ReturnValue_t disablePeriodicPacket(dp::sid_t structureId) override; + ReturnValue_t collectionEnabled(dp::sid_t structureId, bool& collectionEnabled) const override; ReturnValue_t setCollectionInterval(dp::sid_t structureId, dur_millis_t newCollectionIntervalMs) override; - std::optional> getSetSpecification( + std::optional> getMutSetSpecification( dp::sid_t structureId); + std::optional> getSetSpecification( + dp::sid_t structureId) const; + protected: std::optional getCollectionFrequency(dp::sid_t structureId); diff --git a/src/fsfw/housekeeping/PeriodicHkHelperIF.h b/src/fsfw/housekeeping/PeriodicHkHelperIF.h index 8dd3af11..29bd81c3 100644 --- a/src/fsfw/housekeeping/PeriodicHkHelperIF.h +++ b/src/fsfw/housekeeping/PeriodicHkHelperIF.h @@ -18,6 +18,7 @@ class PeriodicHelperIF { virtual ReturnValue_t enablePeriodicPacket(dp::sid_t structureId, std::optional frequencyMs) = 0; virtual ReturnValue_t disablePeriodicPacket(dp::sid_t structureId) = 0; + virtual ReturnValue_t collectionEnabled(dp::sid_t structureId, bool& collectionEnabled) const = 0; }; } // namespace hk \ No newline at end of file diff --git a/src/fsfw/serialize/SerializableList.h b/src/fsfw/serialize/SerializableList.h index 3e78dcfc..b1bcfa11 100644 --- a/src/fsfw/serialize/SerializableList.h +++ b/src/fsfw/serialize/SerializableList.h @@ -11,6 +11,8 @@ class List : public SerializeIF { serializables.push_back(serializable); } + size_t getNumberOfSerializables() const { return serializables.size(); } + [[nodiscard]] ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const override { ReturnValue_t result = returnvalue::OK;