From 3c1072d7c9d3c7c3eeb4d7287c024c7451505f4b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 6 Nov 2024 16:55:09 +0100 Subject: [PATCH] continue update --- CMakeLists.txt | 9 +- .../archive}/HasLocalDpIFManagerAttorney.cpp | 6 +- misc/archive/HasLocalDpIFManagerAttorney.h | 17 + misc/archive/HasLocalDpIFUserAttorney.cpp | 1 + .../archive}/HasLocalDpIFUserAttorney.h | 0 .../archive}/ProvidesDataPoolSubscriptionIF.h | 14 - .../archive}/SharedLocalDataset.cpp | 4 +- .../archive}/SharedLocalDataset.h | 20 +- src/fsfw/CMakeLists.txt | 1 - .../controller/ExtendedControllerBase.cpp | 14 +- src/fsfw/controller/ExtendedControllerBase.h | 11 +- src/fsfw/datapool.h | 11 + .../AccessLocalPoolF.h | 0 src/fsfw/datapool/CMakeLists.txt | 7 +- .../LocalPoolObjectBase.cpp | 30 +- .../LocalPoolObjectBase.h | 29 +- .../LocalPoolVector.h | 182 +++++++--- src/fsfw/datapool/LocalPoolVector.tpp | 0 .../MarkChangedIF.h | 0 src/fsfw/datapool/PoolDataSetBase.h | 13 +- src/fsfw/datapool/PoolVariable.h | 342 ++++++++++++++++++ src/fsfw/datapool/PoolVariable.tpp | 1 + .../SharedPool.cpp | 15 +- .../{datapoollocal => datapool}/SharedPool.h | 17 +- src/fsfw/datapool/SharedSet.cpp | 16 + .../LocalDataSet.h => datapool/SharedSet.h} | 21 +- .../SharedSetBase.cpp} | 86 ++--- .../SharedSetBase.h} | 45 ++- .../StaticSharedSet.h} | 20 +- .../definitions.h} | 35 +- src/fsfw/datapool/internal/CMakeLists.txt | 1 + .../internal/LocalPoolDataSetAttorney.h | 2 +- .../internal/SharedPoolAttorney.h} | 17 +- src/fsfw/datapoollocal.h | 11 - src/fsfw/datapoollocal/CMakeLists.txt | 6 - src/fsfw/datapoollocal/LocalDataSet.cpp | 15 - src/fsfw/datapoollocal/LocalPoolVariable.h | 185 ---------- src/fsfw/datapoollocal/LocalPoolVariable.tpp | 177 --------- src/fsfw/datapoollocal/LocalPoolVector.tpp | 165 --------- .../datapoollocal/PeriodicHkGenerationIF.h | 124 ------- .../datapoollocal/internal/CMakeLists.txt | 2 - .../internal/HasLocalDpIFManagerAttorney.h | 19 - .../internal/HasLocalDpIFUserAttorney.cpp | 4 - src/fsfw/devicehandlers/DeviceHandlerBase.cpp | 11 +- src/fsfw/devicehandlers/DeviceHandlerBase.h | 22 +- src/fsfw/devicehandlers/DeviceHandlerIF.h | 12 +- .../devicehandlers/DeviceHandlerThermalSet.h | 24 +- .../devicehandlers/FreshDeviceHandlerBase.h | 9 +- src/fsfw/housekeeping/CMakeLists.txt | 3 +- src/fsfw/housekeeping/GeneratesPeriodicHkIF.h | 64 ++++ src/fsfw/housekeeping/HousekeepingMessage.cpp | 53 +-- src/fsfw/housekeeping/HousekeepingMessage.h | 58 +-- .../housekeeping/HousekeepingPacketDownlink.h | 7 +- src/fsfw/housekeeping/HousekeepingSetPacket.h | 2 +- src/fsfw/housekeeping/HousekeepingSnapshot.h | 17 +- .../PeriodicHkHelper.cpp} | 64 ++-- .../PeriodicHkHelper.h} | 122 ++----- src/fsfw/housekeeping/PeriodicHkHelperIF.h | 23 ++ src/fsfw/housekeeping/definitions.h | 72 ++++ src/fsfw/internalerror/InternalErrorDataset.h | 20 +- .../internalerror/InternalErrorReporter.cpp | 8 +- .../internalerror/InternalErrorReporter.h | 19 +- src/fsfw/monitoring/AbsLimitMonitor.h | 2 +- src/fsfw/monitoring/LimitMonitor.h | 2 +- src/fsfw/monitoring/MonitorBase.h | 6 +- src/fsfw/monitoring/MonitorReporter.h | 13 +- .../monitoring/MonitoringMessageContent.h | 11 +- src/fsfw/power/Fuse.cpp | 5 +- src/fsfw/power/Fuse.h | 38 +- src/fsfw/power/PowerSensor.cpp | 4 +- src/fsfw/power/PowerSensor.h | 28 +- src/fsfw/pus/Service3Housekeeping.cpp | 31 +- src/fsfw/pus/Service3Housekeeping.h | 3 +- src/fsfw/pus/servicepackets/Service3Packets.h | 5 +- src/fsfw/thermal/ThermalComponent.cpp | 6 +- src/fsfw/thermal/ThermalComponent.h | 7 +- src/fsfw/thermal/ThermalComponentCore.cpp | 7 +- src/fsfw/thermal/ThermalComponentCore.h | 16 +- src/fsfw/thermal/ThermalModule.cpp | 10 +- src/fsfw/thermal/ThermalModule.h | 16 +- unittests/mocks/DeviceHandlerMock.cpp | 2 +- unittests/mocks/LocalPoolOwnerBase.cpp | 2 +- unittests/mocks/LocalPoolOwnerBase.h | 13 +- 83 files changed, 1185 insertions(+), 1347 deletions(-) rename {src/fsfw/datapoollocal/internal => misc/archive}/HasLocalDpIFManagerAttorney.cpp (63%) create mode 100644 misc/archive/HasLocalDpIFManagerAttorney.h create mode 100644 misc/archive/HasLocalDpIFUserAttorney.cpp rename {src/fsfw/datapoollocal/internal => misc/archive}/HasLocalDpIFUserAttorney.h (100%) rename {src/fsfw/datapoollocal => misc/archive}/ProvidesDataPoolSubscriptionIF.h (71%) rename {src/fsfw/datapoollocal => misc/archive}/SharedLocalDataset.cpp (88%) rename {src/fsfw/datapoollocal => misc/archive}/SharedLocalDataset.h (63%) create mode 100644 src/fsfw/datapool.h rename src/fsfw/{datapoollocal => datapool}/AccessLocalPoolF.h (100%) rename src/fsfw/{datapoollocal => datapool}/LocalPoolObjectBase.cpp (69%) rename src/fsfw/{datapoollocal => datapool}/LocalPoolObjectBase.h (52%) rename src/fsfw/{datapoollocal => datapool}/LocalPoolVector.h (54%) create mode 100644 src/fsfw/datapool/LocalPoolVector.tpp rename src/fsfw/{datapoollocal => datapool}/MarkChangedIF.h (100%) create mode 100644 src/fsfw/datapool/PoolVariable.h create mode 100644 src/fsfw/datapool/PoolVariable.tpp rename src/fsfw/{datapoollocal => datapool}/SharedPool.cpp (53%) rename src/fsfw/{datapoollocal => datapool}/SharedPool.h (78%) create mode 100644 src/fsfw/datapool/SharedSet.cpp rename src/fsfw/{datapoollocal/LocalDataSet.h => datapool/SharedSet.h} (59%) rename src/fsfw/{datapoollocal/SharedDatasetBase.cpp => datapool/SharedSetBase.cpp} (50%) rename src/fsfw/{datapoollocal/SharedDatasetBase.h => datapool/SharedSetBase.h} (83%) rename src/fsfw/{datapoollocal/StaticSharedDataset.h => datapool/StaticSharedSet.h} (71%) rename src/fsfw/{datapoollocal/localPoolDefinitions.h => datapool/definitions.h} (69%) create mode 100644 src/fsfw/datapool/internal/CMakeLists.txt rename src/fsfw/{datapoollocal => datapool}/internal/LocalPoolDataSetAttorney.h (83%) rename src/fsfw/{datapoollocal/internal/LocalDpManagerAttorney.h => datapool/internal/SharedPoolAttorney.h} (64%) delete mode 100644 src/fsfw/datapoollocal.h delete mode 100644 src/fsfw/datapoollocal/CMakeLists.txt delete mode 100644 src/fsfw/datapoollocal/LocalDataSet.cpp delete mode 100644 src/fsfw/datapoollocal/LocalPoolVariable.h delete mode 100644 src/fsfw/datapoollocal/LocalPoolVariable.tpp delete mode 100644 src/fsfw/datapoollocal/LocalPoolVector.tpp delete mode 100644 src/fsfw/datapoollocal/PeriodicHkGenerationIF.h delete mode 100644 src/fsfw/datapoollocal/internal/CMakeLists.txt delete mode 100644 src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.h delete mode 100644 src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp create mode 100644 src/fsfw/housekeeping/GeneratesPeriodicHkIF.h rename src/fsfw/{datapoollocal/PeriodicHkGenerationHelper.cpp => housekeeping/PeriodicHkHelper.cpp} (81%) rename src/fsfw/{datapoollocal/PeriodicHkGenerationHelper.h => housekeeping/PeriodicHkHelper.h} (62%) create mode 100644 src/fsfw/housekeeping/PeriodicHkHelperIF.h create mode 100644 src/fsfw/housekeeping/definitions.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e269a6c0..4c7332e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,11 +123,8 @@ option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF) set(FSFW_TEST_TGT fsfw-tests) set(FSFW_DUMMY_TGT fsfw-dummy) -add_library( - ${LIB_FSFW_NAME} - src/fsfw/datapoollocal/SharedPool.h src/fsfw/datapoollocal/SharedPool.cpp - src/fsfw/serialize/SerializableList.h - src/fsfw/serialize/SerializableListElement.h) +add_library(${LIB_FSFW_NAME} src/fsfw/housekeeping/PeriodicHkHelperIF.h + src/fsfw/housekeeping/definitions.h) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${LIB_FSFW_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION @@ -145,7 +142,7 @@ if(FSFW_BUILD_TESTS) configure_file(unittests/testcfg/TestsConfig.h.in tests/TestsConfig.h) project(${FSFW_TEST_TGT} CXX C) - add_executable(${FSFW_TEST_TGT} unittests/serialize/testList.cpp) + add_executable(${FSFW_TEST_TGT}) if(IPO_SUPPORTED AND FSFW_ENABLE_IPO) set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp b/misc/archive/HasLocalDpIFManagerAttorney.cpp similarity index 63% rename from src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp rename to misc/archive/HasLocalDpIFManagerAttorney.cpp index 996fdb4c..097a0ec0 100644 --- a/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.cpp +++ b/misc/archive/HasLocalDpIFManagerAttorney.cpp @@ -1,10 +1,10 @@ #include "HasLocalDpIFManagerAttorney.h" -#include "fsfw/datapoollocal/LocalPoolObjectBase.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationIF.h" +#include "fsfw/datapool/LocalPoolObjectBase.h" +#include "fsfw/housekeeping/GeneratesPeriodicHkIF.h" LocalPoolObjectBase* HasLocalDpIFManagerAttorney::getPoolObjectHandle( - PeriodicHkGenerationIF* clientIF, lp_id_t localPoolId) { + PeriodicHkGenerationIF* clientIF, dp::lp_id_t localPoolId) { return clientIF->getPoolObjectHandle(localPoolId); } diff --git a/misc/archive/HasLocalDpIFManagerAttorney.h b/misc/archive/HasLocalDpIFManagerAttorney.h new file mode 100644 index 00000000..4651d5e1 --- /dev/null +++ b/misc/archive/HasLocalDpIFManagerAttorney.h @@ -0,0 +1,17 @@ +#pragma once +#include + +#include "fsfw/datapool/definitions.h" + +class PeriodicHkGenerationIF; +class LocalPoolDataSetBase; +class LocalPoolObjectBase; + +class HasLocalDpIFManagerAttorney { + static LocalPoolObjectBase* getPoolObjectHandle(PeriodicHkGenerationIF* clientIF, + dp::lp_id_t localPoolId); + + static object_id_t getObjectId(PeriodicHkGenerationIF* clientIF); + + friend class hk::PeriodicHelper; +}; \ No newline at end of file diff --git a/misc/archive/HasLocalDpIFUserAttorney.cpp b/misc/archive/HasLocalDpIFUserAttorney.cpp new file mode 100644 index 00000000..619e415d --- /dev/null +++ b/misc/archive/HasLocalDpIFUserAttorney.cpp @@ -0,0 +1 @@ +#include "HasLocalDpIFUserAttorney.h" diff --git a/src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.h b/misc/archive/HasLocalDpIFUserAttorney.h similarity index 100% rename from src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.h rename to misc/archive/HasLocalDpIFUserAttorney.h diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/misc/archive/ProvidesDataPoolSubscriptionIF.h similarity index 71% rename from src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h rename to misc/archive/ProvidesDataPoolSubscriptionIF.h index ebe5498a..25ea3918 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/misc/archive/ProvidesDataPoolSubscriptionIF.h @@ -43,18 +43,4 @@ struct DiagnosticsHkUpdateParams : public ParamsBase { }; } // namespace subdp -class PeriodicHkGenerationProviderIF { - public: - virtual ~PeriodicHkGenerationProviderIF() = default; - - /** - * Set the periodic generation frequency without enabling the periodic generation of packets. - */ - virtual ReturnValue_t setCollectionInterval(sid_t structureId, - dur_millis_t newCollectionIntervalMs) = 0; - virtual ReturnValue_t enablePeriodicPacket(sid_t structureId, - std::optional frequencyMs) = 0; - virtual ReturnValue_t disablePeriodicPacket(sid_t structureId) = 0; -}; - #endif /* FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ */ diff --git a/src/fsfw/datapoollocal/SharedLocalDataset.cpp b/misc/archive/SharedLocalDataset.cpp similarity index 88% rename from src/fsfw/datapoollocal/SharedLocalDataset.cpp rename to misc/archive/SharedLocalDataset.cpp index a40eee8d..f3b9bf9f 100644 --- a/src/fsfw/datapoollocal/SharedLocalDataset.cpp +++ b/misc/archive/SharedLocalDataset.cpp @@ -1,6 +1,6 @@ -#include "fsfw/datapoollocal/SharedLocalDataset.h" +#include "fsfw/datapool/SharedLocalDataset.h" -SharedLocalDataset::SharedLocalDataset(object_id_t objectId, sid_t sid, const size_t maxSize) +SharedLocalDataset::SharedLocalDataset(object_id_t objectId, structure_id_t sid, const size_t maxSize) : SystemObject(objectId), SharedDatasetBase(sid, nullptr, maxSize), poolVarVector(maxSize) { this->setContainer(poolVarVector.data()); datasetLock = MutexFactory::instance()->createMutex(); diff --git a/src/fsfw/datapoollocal/SharedLocalDataset.h b/misc/archive/SharedLocalDataset.h similarity index 63% rename from src/fsfw/datapoollocal/SharedLocalDataset.h rename to misc/archive/SharedLocalDataset.h index 5290c1a1..eefde6a3 100644 --- a/src/fsfw/datapoollocal/SharedLocalDataset.h +++ b/misc/archive/SharedLocalDataset.h @@ -1,13 +1,15 @@ -#ifndef FSFW_DATAPOOLLOCAL_SHAREDLOCALDATASET_H_ -#define FSFW_DATAPOOLLOCAL_SHAREDLOCALDATASET_H_ +#pragma once #include -#include "../datapool/SharedDataSetIF.h" -#include "../objectmanager/SystemObject.h" -#include "SharedDatasetBase.h" +#include "fsfw/datapool/SharedDataSetIF.h" +#include "fsfw/objectmanager/SystemObject.h" +#include "SharedSetBase.h" +#include "SharedPool.h" -/** +namespace datapool { + + /** * This local dataset variation can be used if the dataset is used concurrently across * multiple threads. It provides a lock in addition to all other functionalities provided * by the LocalPoolDataSetBase class. @@ -15,9 +17,9 @@ * The user is completely responsible for locking and unlocking the dataset when using the * shared dataset. */ -class SharedLocalDataset : public SystemObject, public SharedDatasetBase, public SharedDataSetIF { +class SharedLocalDataset : public SystemObject, public SharedSetBase, public SharedDataSetIF { public: - SharedLocalDataset(object_id_t objectId, localpool::SharedPool& sharedPool, uint32_t setId, + SharedLocalDataset(object_id_t objectId, SharedPool& sharedPool, uint32_t setId, size_t maxSize); SharedLocalDataset(object_id_t objectId, sid_t sid, size_t maxSize); @@ -32,4 +34,4 @@ class SharedLocalDataset : public SystemObject, public SharedDatasetBase, public std::vector poolVarVector; }; -#endif /* FSFW_DATAPOOLLOCAL_SHAREDLOCALDATASET_H_ */ +} diff --git a/src/fsfw/CMakeLists.txt b/src/fsfw/CMakeLists.txt index c8d4dc37..3710078d 100644 --- a/src/fsfw/CMakeLists.txt +++ b/src/fsfw/CMakeLists.txt @@ -7,7 +7,6 @@ add_subdirectory(cfdp) add_subdirectory(container) add_subdirectory(controller) add_subdirectory(datapool) -add_subdirectory(datapoollocal) add_subdirectory(devicehandlers) add_subdirectory(events) add_subdirectory(fdir) diff --git a/src/fsfw/controller/ExtendedControllerBase.cpp b/src/fsfw/controller/ExtendedControllerBase.cpp index 4b39643f..961a4f63 100644 --- a/src/fsfw/controller/ExtendedControllerBase.cpp +++ b/src/fsfw/controller/ExtendedControllerBase.cpp @@ -10,16 +10,12 @@ ExtendedControllerBase::~ExtendedControllerBase() = default; ReturnValue_t ExtendedControllerBase::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t *data, size_t size) { - /* Needs to be overriden and implemented by child class. */ + // Needs to be overriden and implemented by child class. return returnvalue::OK; } object_id_t ExtendedControllerBase::getObjectId() const { return SystemObject::getObjectId(); } -// uint32_t ExtendedControllerBase::getPeriodicOperationFrequency() const { -// return this->executingTask->getPeriodMs(); -//} - ReturnValue_t ExtendedControllerBase::handleCommandMessage(CommandMessage *message) { ReturnValue_t result = actionHelper.handleActionMessage(message); if (result == returnvalue::OK) { @@ -78,12 +74,10 @@ ReturnValue_t ExtendedControllerBase::initialize() { ReturnValue_t ExtendedControllerBase::performOperation(uint8_t opCode) { handleQueue(); performControlOperation(opCode); - /* We do this after performing control operation because variables will be set changed - in this function. */ + // We do this after performing control operation because variables will be set changed + // in this function. hkHelper.performHkOperation(); return returnvalue::OK; } -MessageQueueId_t ExtendedControllerBase::getCommandQueue() const { return commandQueue->getId(); } - -// PeriodicHkGenerationHelper *ExtendedControllerBase::getHkManagerHandle() { return &hkHelper; } +MessageQueueId_t ExtendedControllerBase::getCommandQueue() const { return commandQueue->getId(); } \ No newline at end of file diff --git a/src/fsfw/controller/ExtendedControllerBase.h b/src/fsfw/controller/ExtendedControllerBase.h index c0e4639e..23afe7b7 100644 --- a/src/fsfw/controller/ExtendedControllerBase.h +++ b/src/fsfw/controller/ExtendedControllerBase.h @@ -1,10 +1,11 @@ #ifndef FSFW_CONTROLLER_EXTENDEDCONTROLLERBASE_H_ #define FSFW_CONTROLLER_EXTENDEDCONTROLLERBASE_H_ +#include + #include "ControllerBase.h" #include "fsfw/action.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationIF.h" +#include "fsfw/housekeeping/PeriodicHkHelper.h" /** * @brief Extends the basic ControllerBase with commonly used components @@ -15,9 +16,9 @@ */ class ExtendedControllerBase : public ControllerBase, public HasActionsIF, - public PeriodicHkGenerationIF { + public hk::GeneratesPeriodicHkIF { public: - ExtendedControllerBase(object_id_t objectId, size_t commandQueueDepth = 3); + explicit ExtendedControllerBase(object_id_t objectId, size_t commandQueueDepth = 3); ~ExtendedControllerBase() override; /* SystemObjectIF overrides */ @@ -29,7 +30,7 @@ class ExtendedControllerBase : public ControllerBase, ReturnValue_t performOperation(uint8_t opCode) override; protected: - PeriodicHkGenerationHelper hkHelper; + hk::PeriodicHelper hkHelper; ActionHelper actionHelper; /** diff --git a/src/fsfw/datapool.h b/src/fsfw/datapool.h new file mode 100644 index 00000000..632f95e5 --- /dev/null +++ b/src/fsfw/datapool.h @@ -0,0 +1,11 @@ +#ifndef FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ +#define FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ + +// Collected related headers +#include "fsfw/datapool/LocalPoolVector.h" +#include "fsfw/datapool/PoolVariable.h" +#include "fsfw/datapool/SharedPool.h" +#include "fsfw/datapool/SharedSet.h" +#include "fsfw/datapool/StaticSharedSet.h" + +#endif /* FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ */ diff --git a/src/fsfw/datapoollocal/AccessLocalPoolF.h b/src/fsfw/datapool/AccessLocalPoolF.h similarity index 100% rename from src/fsfw/datapoollocal/AccessLocalPoolF.h rename to src/fsfw/datapool/AccessLocalPoolF.h diff --git a/src/fsfw/datapool/CMakeLists.txt b/src/fsfw/datapool/CMakeLists.txt index b2ac592c..d82997c7 100644 --- a/src/fsfw/datapool/CMakeLists.txt +++ b/src/fsfw/datapool/CMakeLists.txt @@ -1 +1,6 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE PoolDataSetBase.cpp PoolEntry.cpp) +target_sources( + ${LIB_FSFW_NAME} + PRIVATE PoolDataSetBase.cpp PoolEntry.cpp SharedPool.cpp SharedSet.cpp + SharedSetBase.cpp LocalPoolObjectBase.cpp) + +add_subdirectory(internal) diff --git a/src/fsfw/datapoollocal/LocalPoolObjectBase.cpp b/src/fsfw/datapool/LocalPoolObjectBase.cpp similarity index 69% rename from src/fsfw/datapoollocal/LocalPoolObjectBase.cpp rename to src/fsfw/datapool/LocalPoolObjectBase.cpp index 7b3f437f..7cc09e13 100644 --- a/src/fsfw/datapoollocal/LocalPoolObjectBase.cpp +++ b/src/fsfw/datapool/LocalPoolObjectBase.cpp @@ -1,13 +1,11 @@ -#include "fsfw/datapoollocal/LocalPoolObjectBase.h" +#include "fsfw/datapool/LocalPoolObjectBase.h" -#include "fsfw/datapoollocal/AccessLocalPoolF.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationIF.h" +#include "fsfw/housekeeping/PeriodicHkHelper.h" #include "fsfw/objectmanager/ObjectManager.h" -#include "internal/HasLocalDpIFUserAttorney.h" -LocalPoolObjectBase::LocalPoolObjectBase(localpool::SharedPool& sharedPool, lp_id_t poolId, - DataSetIF* dataSet, pool_rwm_t setReadWriteMode) +using namespace dp; +PoolObjectBase::PoolObjectBase(SharedPool& sharedPool, dp::lp_id_t poolId, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode) : localPoolId(poolId), readWriteMode(setReadWriteMode), sharedPool(&sharedPool) { if (poolId == PoolVariableIF::NO_PARAMETER) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -21,8 +19,8 @@ LocalPoolObjectBase::LocalPoolObjectBase(localpool::SharedPool& sharedPool, lp_i } } -LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet, - pool_rwm_t setReadWriteMode) +PoolObjectBase::PoolObjectBase(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode) : localPoolId(poolId), readWriteMode(setReadWriteMode) { if (poolId == PoolVariableIF::NO_PARAMETER) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -35,7 +33,7 @@ LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, "which is the NO_PARAMETER value!\n"); #endif } - auto* hkOwner = ObjectManager::instance()->get(poolOwner); + auto* hkOwner = ObjectManager::instance()->get(poolOwner); if (hkOwner == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "LocalPoolVariable: The supplied pool owner 0x" << std::hex << poolOwner @@ -56,18 +54,18 @@ LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, } } -pool_rwm_t LocalPoolObjectBase::getReadWriteMode() const { return readWriteMode; } +pool_rwm_t PoolObjectBase ::getReadWriteMode() const { return readWriteMode; } -lp_id_t LocalPoolObjectBase::getDataPoolId() const { return localPoolId; } +lp_id_t PoolObjectBase ::getDataPoolId() const { return localPoolId; } -void LocalPoolObjectBase::setDataPoolId(lp_id_t poolId) { this->localPoolId = poolId; } +void PoolObjectBase::setDataPoolId(lp_id_t poolId) { this->localPoolId = poolId; } -void LocalPoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) { +void PoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) { this->readWriteMode = newReadWriteMode; } -void LocalPoolObjectBase::reportReadCommitError(const char* variableType, ReturnValue_t error, - bool read, object_id_t objectId, lp_id_t lpId) { +void PoolObjectBase::reportReadCommitError(const char* variableType, ReturnValue_t error, bool read, + object_id_t objectId, lp_id_t lpId) { #if FSFW_DISABLE_PRINTOUT == 0 const char* variablePrintout = variableType; if (variablePrintout == nullptr) { diff --git a/src/fsfw/datapoollocal/LocalPoolObjectBase.h b/src/fsfw/datapool/LocalPoolObjectBase.h similarity index 52% rename from src/fsfw/datapoollocal/LocalPoolObjectBase.h rename to src/fsfw/datapool/LocalPoolObjectBase.h index 9ea1cdb9..2ce76579 100644 --- a/src/fsfw/datapoollocal/LocalPoolObjectBase.h +++ b/src/fsfw/datapool/LocalPoolObjectBase.h @@ -1,32 +1,31 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ -#define FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ +#pragma once -#include "MarkChangedIF.h" #include "SharedPool.h" #include "fsfw/datapool/PoolVariableIF.h" +#include "fsfw/datapool/definitions.h" #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/returnvalues/returnvalue.h" -#include "localPoolDefinitions.h" class DataSetIF; +namespace datapool { /** * @brief This class serves as a non-template base for pool objects like pool variables * or pool vectors. */ -class LocalPoolObjectBase : public PoolVariableIF { +class PoolObjectBase : public PoolVariableIF { public: - LocalPoolObjectBase(localpool::SharedPool& sharedPool, lp_id_t poolId, DataSetIF* dataSet, - pool_rwm_t setReadWriteMode); + PoolObjectBase(dp::SharedPool& sharedPool, dp::lp_id_t poolId, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode); - LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); + PoolObjectBase(object_id_t poolOwner, dp::lp_id_t poolId, DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); void setReadWriteMode(pool_rwm_t newReadWriteMode) override; - pool_rwm_t getReadWriteMode() const override; + [[nodiscard]] pool_rwm_t getReadWriteMode() const override; - lp_id_t getDataPoolId() const override; - void setDataPoolId(lp_id_t poolId); + [[nodiscard]] lp_id_t getDataPoolId() const override; + void setDataPoolId(dp::lp_id_t poolId); protected: /** @@ -42,10 +41,10 @@ class LocalPoolObjectBase : public PoolVariableIF { ReadWriteMode_t readWriteMode = pool_rwm_t::VAR_READ_WRITE; //! @brief Pointer to the class which manages the HK pool. - localpool::SharedPool* sharedPool = nullptr; + dp::SharedPool* sharedPool = nullptr; void reportReadCommitError(const char* variableType, ReturnValue_t error, bool read, - object_id_t objectId, lp_id_t lpId); + object_id_t objectId, dp::lp_id_t lpId); }; -#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ */ +} // namespace datapool \ No newline at end of file diff --git a/src/fsfw/datapoollocal/LocalPoolVector.h b/src/fsfw/datapool/LocalPoolVector.h similarity index 54% rename from src/fsfw/datapoollocal/LocalPoolVector.h rename to src/fsfw/datapool/LocalPoolVector.h index cd35c170..4fbf114f 100644 --- a/src/fsfw/datapoollocal/LocalPoolVector.h +++ b/src/fsfw/datapool/LocalPoolVector.h @@ -1,14 +1,15 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ -#define FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ +#pragma once + +#include +#include -#include "../datapool/DataSetIF.h" -#include "../datapool/PoolEntry.h" -#include "../datapool/PoolVariableIF.h" -#include "../datapoollocal/PeriodicHkGenerationHelper.h" -#include "../serialize/SerializeAdapter.h" -#include "../serviceinterface/ServiceInterface.h" #include "LocalPoolObjectBase.h" -#include "internal/LocalDpManagerAttorney.h" +#include "fsfw/datapool/DataSetIF.h" +#include "fsfw/datapool/PoolEntry.h" +#include "fsfw/datapool/PoolVariableIF.h" +#include "fsfw/serviceinterface/ServiceInterface.h" + +namespace datapool { /** * @brief This is the access class for array-type data pool entries. @@ -24,16 +25,16 @@ * @tparam T * This template parameter specifies the data type of an array entry. Currently, * all plain data types are supported, but in principle any type is possible. - * @tparam vector_size + * @tparam N * This template parameter specifies the vector size of this entry. Using a * template parameter for this is not perfect, but avoids * dynamic memory allocation. * @ingroup data_pool */ -template -class LocalPoolVector : public LocalPoolObjectBase { +template +class PoolVector : public PoolObjectBase { public: - LocalPoolVector() = delete; + PoolVector() = delete; /** * This constructor is used by the data creators to have pool variable * instances which can also be stored in datasets. @@ -47,8 +48,9 @@ class LocalPoolVector : public LocalPoolObjectBase { * @param dataSet The data set in which the variable shall register itself. * If nullptr, the variable is not registered. */ - LocalPoolVector(localpool::SharedPool& sharedPool, lp_id_t poolId, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); + PoolVector(SharedPool& sharedPool, lp_id_t poolId, DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE) + : PoolObjectBase(sharedPool, poolId, dataSet, setReadWriteMode) {} /** * This constructor is used by data users like controllers to have @@ -64,8 +66,8 @@ class LocalPoolVector : public LocalPoolObjectBase { * @param dataSet The data set in which the variable shall register itself. * If nullptr, the variable is not registered. */ - LocalPoolVector(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); + PoolVector(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); /** * Variation which takes the unique global identifier of a local pool * vector. @@ -73,8 +75,10 @@ class LocalPoolVector : public LocalPoolObjectBase { * @param dataSet * @param setReadWriteMode */ - LocalPoolVector(gp_id_t globalPoolId, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); + PoolVector(g_id_t globalPoolId, DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE) + : PoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId, dataSet, setReadWriteMode) { + } /** * @brief This is the local copy of the data pool entry. @@ -82,27 +86,80 @@ class LocalPoolVector : public LocalPoolObjectBase { * The user can work on this attribute just like he would on a local * array of this type. */ - T value[vectorSize] = {}; + T value[N] = {}; /** * @brief The classes destructor is empty. * @details If commit() was not called, the local value is * discarded and not written back to the data pool. */ - ~LocalPoolVector() {}; + ~PoolVector() override {}; /** * @brief The operation returns the number of array entries * in this variable. */ - uint8_t getSize() { return vectorSize; } + size_t getSize() { return N; } - T& operator[](size_t i); - const T& operator[](size_t i) const; + T& operator[](size_t i) { + if (i < N) { + return value[i]; + } + // If this happens, I have to set some value. I consider this + // a configuration error, but I wont exit here. +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "PoolVector: Invalid index. Setting or returning" + " last value!" + << std::endl; +#else + sif::printWarning( + "PoolVector: Invalid index. Setting or returning" + " last value!\n"); +#endif + return value[N - 1]; + } + const T& operator[](size_t i) const { + if (i < N) { + return value[i]; + } + // If this happens, I have to set some value. I consider this + // a configuration error, but I wont exit here. +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "PoolVector: Invalid index. Setting or returning" + " last value!" + << std::endl; +#else + sif::printWarning( + "PoolVector: Invalid index. Setting or returning" + " last value!\n"); +#endif + return value[N - 1]; + } ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t maxSize, - SerializeIF::Endianness streamEndiannes) const override; - size_t getSerializedSize() const override; + SerializeIF::Endianness streamEndianness) const override { + ReturnValue_t result = returnvalue::FAILED; + for (uint16_t i = 0; i < N; i++) { + result = SerializeAdapter::serialize(&(value[i]), buffer, size, maxSize, streamEndianness); + if (result != returnvalue::OK) { + break; + } + } + return result; + } + + [[nodiscard]] size_t getSerializedSize() const override { + return N * SerializeAdapter::getSerializedSize(value); + } ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - SerializeIF::Endianness streamEndianness) override; + SerializeIF::Endianness streamEndianness) override { + ReturnValue_t result = returnvalue::FAILED; + for (uint16_t i = 0; i < N; i++) { + result = SerializeAdapter::deSerialize(&(value[i]), buffer, size, streamEndianness); + if (result != returnvalue::OK) { + break; + } + } + return result; + } /** * @brief This is a call to read the array's values @@ -118,7 +175,10 @@ class LocalPoolVector : public LocalPoolObjectBase { * at once to avoid the overhead of unnecessary lock und unlock operations. */ ReturnValue_t read(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, - uint32_t timeoutMs = 20) override; + uint32_t timeoutMs = 20) override { + MutexGuard mg(sharedPool->getPoolMutex(), timeoutType, timeoutMs); + return readWithoutLock(); + } /** * @brief The commit call copies the array values back to the data pool. @@ -129,15 +189,11 @@ class LocalPoolVector : public LocalPoolObjectBase { * It is recommended to use DataSets to read and commit multiple variables * at once to avoid the overhead of unnecessary lock und unlock operations. */ - ReturnValue_t commit(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, - uint32_t timeoutMs = 20) override; - - /** - * @brief This commit call also sets the validity of the pool entry. - * @details - */ - ReturnValue_t commit(bool valid, MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, - uint32_t timeoutMs = 20); + ReturnValue_t commit(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) override { + MutexGuard mg(sharedPool->getPoolMutex(), timeoutType, timeoutMs); + return commitWithoutLock(); + } + ReturnValue_t commit() { return commit(MutexIF::TimeoutType::WAITING, 20); } protected: /** @@ -148,7 +204,22 @@ class LocalPoolVector : public LocalPoolObjectBase { * of consecutive lock und unlock operations. * Declared protected to discourage free public usage. */ - ReturnValue_t readWithoutLock() override; + ReturnValue_t readWithoutLock() override { + if (readWriteMode == pool_rwm_t::VAR_WRITE) { + return PoolVariableIF::INVALID_READ_WRITE_MODE; + } + + PoolEntry* poolEntry = nullptr; + ReturnValue_t result = sharedPool->fetchPoolEntry(localPoolId, &poolEntry); + memset(this->value, 0, N * sizeof(T)); + + if (result != returnvalue::OK) { + return result; + } + std::memcpy(this->value, poolEntry->getDataPtr(), poolEntry->getByteSize()); + return returnvalue::OK; + } + /** * @brief Like #commit, but without a lock protection of the global pool. * @details @@ -157,19 +228,36 @@ class LocalPoolVector : public LocalPoolObjectBase { * of consecutive lock und unlock operations. * Declared protected to discourage free public usage. */ - ReturnValue_t commitWithoutLock() override; + ReturnValue_t commitWithoutLock() override { + if (readWriteMode == pool_rwm_t::VAR_READ) { + return PoolVariableIF::INVALID_READ_WRITE_MODE; + } + PoolEntry* poolEntry = nullptr; + ReturnValue_t result = sharedPool->fetchPoolEntry(localPoolId, &poolEntry); + if (result != returnvalue::OK) { + return result; + } + std::memcpy(poolEntry->getDataPtr(), this->value, poolEntry->getByteSize()); + return returnvalue::OK; + } private: #if FSFW_CPP_OSTREAM_ENABLED == 1 - // std::ostream is the type for object std::cout - template - friend std::ostream& operator<<(std::ostream& out, const LocalPoolVector& var); + std::ostream& operator<<(std::ostream& out, const PoolVector& var) { + out << "Vector: ["; + for (int i = 0; i < N; i++) { + out << var.value[i]; + if (i < N - 1) { + out << ", "; + } + } + out << "]"; + return out; + } #endif }; -#include "LocalPoolVector.tpp" +template +using vec_t = PoolVector; -template -using lp_vec_t = LocalPoolVector; - -#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ */ +} // namespace datapool diff --git a/src/fsfw/datapool/LocalPoolVector.tpp b/src/fsfw/datapool/LocalPoolVector.tpp new file mode 100644 index 00000000..e69de29b diff --git a/src/fsfw/datapoollocal/MarkChangedIF.h b/src/fsfw/datapool/MarkChangedIF.h similarity index 100% rename from src/fsfw/datapoollocal/MarkChangedIF.h rename to src/fsfw/datapool/MarkChangedIF.h diff --git a/src/fsfw/datapool/PoolDataSetBase.h b/src/fsfw/datapool/PoolDataSetBase.h index 14c75295..b7da7d7d 100644 --- a/src/fsfw/datapool/PoolDataSetBase.h +++ b/src/fsfw/datapool/PoolDataSetBase.h @@ -1,11 +1,14 @@ -#ifndef FSFW_DATAPOOL_POOLDATASETBASE_H_ -#define FSFW_DATAPOOL_POOLDATASETBASE_H_ +#pragma once #include "PoolDataSetIF.h" #include "PoolVariableIF.h" #include "fsfw/ipc/MutexIF.h" #include "fsfw/serialize/SerializeIF.h" +namespace datapool { +class SharedSetBase; +} + /** * @brief The DataSetBase class manages a set of locally checked out variables. * @details @@ -30,7 +33,7 @@ * @ingroup data_pool */ class PoolDataSetBase : public PoolDataSetIF, public SerializeIF { - friend class SharedDatasetBase; + friend class datapool::SharedSetBase; public: /** @@ -169,6 +172,4 @@ class PoolDataSetBase : public PoolDataSetIF, public SerializeIF { MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, uint32_t timeoutMs = 20); ReturnValue_t handleUnreadDatasetCommit( MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, uint32_t timeoutMs = 20); -}; - -#endif /* FSFW_DATAPOOL_POOLDATASETBASE_H_ */ +}; \ No newline at end of file diff --git a/src/fsfw/datapool/PoolVariable.h b/src/fsfw/datapool/PoolVariable.h new file mode 100644 index 00000000..d2685aab --- /dev/null +++ b/src/fsfw/datapool/PoolVariable.h @@ -0,0 +1,342 @@ +#pragma once + +#include + +#include "FSFWConfig.h" +#include "LocalPoolObjectBase.h" +#include "fsfw/datapool/DataSetIF.h" +#include "fsfw/datapool/PoolVariableIF.h" +#include "fsfw/serialize/SerializeAdapter.h" + +namespace datapool { + +/** + * @brief Local Pool Variable class which is used to access the local pools. + * @details + * This class is not stored in the map. Instead, it is used to access + * the pool entries by using a pointer to the map storing the pool + * entries. It can also be used to organize these pool entries into data sets. + * + * @tparam T The template parameter sets the type of the variable. Currently, + * all plain data types are supported, but in principle any type is possible. + * @ingroup data_pool + */ +template +class PoolVariable : public PoolObjectBase { + public: + //! Default ctor is forbidden. + PoolVariable() = delete; + + /** + * This constructor is used by the data creators to have pool variable + * instances which can also be stored in datasets. + * + * It does not fetch the current value from the data pool, which + * has to be done by calling the read() operation. + * Datasets can be used to access multiple local pool entries in an + * efficient way. A pointer to a dataset can be passed to register + * the pool variable in that dataset directly. + * @param poolId ID of the local pool entry. + * @param hkOwner Pointer of the owner. This will generally be the calling + * class itself which passes "this". + * @param dataSet The data set in which the variable shall register itself. + * If nullptr, the variable is not registered. + * @param setReadWriteMode Specify the read-write mode of the pool variable. + */ + PoolVariable(SharedPool& sharedPool, lp_id_t poolId, DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); + + /** + * This constructor is used by data users like controllers to have + * access to the local pool variables of data creators by supplying + * the respective creator object ID. + * + * It does not fetch the current value from the data pool, which + * has to be done by calling the read() operation. + * Datasets can be used to access multiple local pool entries in an + * efficient way. A pointer to a dataset can be passed to register + * the pool variable in that dataset directly. + * @param poolId ID of the local pool entry. + * @param hkOwner object ID of the pool owner. + * @param dataSet The data set in which the variable shall register itself. + * If nullptr, the variable is not registered. + * @param setReadWriteMode Specify the read-write mode of the pool variable. + * + */ + PoolVariable(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); + /** + * Variation which takes the global unique identifier of a pool variable. + * @param globalPoolId + * @param dataSet + * @param setReadWriteMode + */ + PoolVariable(g_id_t globalPoolId, DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); + + virtual ~PoolVariable() {}; + + /** + * @brief This is the local copy of the data pool entry. + * @details The user can work on this attribute + * just like he would on a simple local variable. + */ + T value = 0; + + ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, + SerializeIF::Endianness streamEndianness) const override; + size_t getSerializedSize() const override; + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + SerializeIF::Endianness streamEndianness) override; + + /** + * @brief This is a call to read the array's values + * from the global data pool. + * @details + * When executed, this operation tries to fetch the pool entry with matching + * data pool id from the data pool and copies all array values and the valid + * information to its local attributes. + * In case of a failure (wrong type, size or pool id not found), the + * variable is set to zero and invalid. + * The read call is protected with a lock. + * It is recommended to use DataSets to read and commit multiple variables + * at once to avoid the overhead of unnecessary lock und unlock operations. + * + */ + ReturnValue_t read(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, + uint32_t timeoutMs = 20) override; + /** + * @brief The commit call copies the array values back to the data pool. + * @details + * It checks type and size, as well as if the variable is writable. If so, + * the value is copied and the local valid flag is written back as well. + * The read call is protected with a lock. + * It is recommended to use DataSets to read and commit multiple variables + * at once to avoid the overhead of unnecessary lock und unlock operations. + */ + ReturnValue_t commit(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, + uint32_t timeoutMs = 20) override; + + PoolVariable& operator=(const T& newValue); + PoolVariable& operator=(const PoolVariable& newPoolVariable); + + //! Explicit type conversion operator. Allows casting the class to + //! its template type to perform operations on value. + explicit operator T() const; + + bool operator==(const PoolVariable& other) const; + bool operator==(const T& other) const; + + bool operator!=(const PoolVariable& other) const; + bool operator!=(const T& other) const; + + bool operator<(const PoolVariable& other) const; + bool operator<(const T& other) const; + + bool operator>(const PoolVariable& other) const; + bool operator>(const T& other) const; + + protected: + /** + * @brief Like #read, but without a lock protection of the global pool. + * @details + * The operation does NOT provide any mutual exclusive protection by itself. + * This can be used if the lock is handled externally to avoid the overhead + * of consecutive lock und unlock operations. + * Declared protected to discourage free public usage. + */ + ReturnValue_t readWithoutLock() override; + /** + * @brief Like #commit, but without a lock protection of the global pool. + * @details + * The operation does NOT provide any mutual exclusive protection by itself. + * This can be used if the lock is handled externally to avoid the overhead + * of consecutive lock und unlock operations. + * Declared protected to discourage free public usage. + */ + ReturnValue_t commitWithoutLock() override; + +#if FSFW_CPP_OSTREAM_ENABLED == 1 + // std::ostream is the type for object std::cout + template + friend std::ostream& operator<<(std::ostream& out, const LocalPoolVariable& var); +#endif +}; + +template +PoolVariable::PoolVariable(SharedPool& sharedPool, lp_id_t poolId, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode) + : PoolObjectBase(sharedPool, poolId, dataSet, setReadWriteMode) {} + +template +PoolVariable::PoolVariable(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode) + : PoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {} + +template +PoolVariable::PoolVariable(g_id_t globalPoolId, DataSetIF* dataSet, pool_rwm_t setReadWriteMode) + : PoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId, dataSet, setReadWriteMode) {} + +template +ReturnValue_t PoolVariable::read(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { + if (sharedPool == nullptr) { + return readWithoutLock(); + } + MutexIF* mutex = sharedPool->getPoolMutex(); + ReturnValue_t result = mutex->lockMutex(timeoutType, timeoutMs); + if (result != returnvalue::OK) { + return result; + } + result = readWithoutLock(); + mutex->unlockMutex(); + return result; +} + +template +inline ReturnValue_t PoolVariable::readWithoutLock() { + if (sharedPool == nullptr) { + return PoolVariableIF::INVALID_SHARED_POOL; + } + if (readWriteMode == pool_rwm_t::VAR_WRITE) { + return PoolVariableIF::INVALID_READ_WRITE_MODE; + } + + PoolEntry* poolEntry = nullptr; + if (ReturnValue_t result = sharedPool->fetchPoolEntry(localPoolId, &poolEntry); + result != returnvalue::OK) { + return result; + } + + this->value = *(poolEntry->getDataPtr()); + return returnvalue::OK; +} + +template +inline ReturnValue_t PoolVariable::commit(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { + if (sharedPool == nullptr) { + return commitWithoutLock(); + } + MutexIF* mutex = sharedPool->getPoolMutex(); + ReturnValue_t result = mutex->lockMutex(timeoutType, timeoutMs); + if (result != returnvalue::OK) { + return result; + } + result = commitWithoutLock(); + mutex->unlockMutex(); + return result; +} + +template +ReturnValue_t PoolVariable::commitWithoutLock() { + if (readWriteMode == pool_rwm_t::VAR_READ) { + return PoolVariableIF::INVALID_READ_WRITE_MODE; + } + + PoolEntry* poolEntry = nullptr; + ReturnValue_t result = sharedPool->fetchPoolEntry(localPoolId, &poolEntry); + if (result != returnvalue::OK) { + return result; + } + + *(poolEntry->getDataPtr()) = this->value; + return returnvalue::OK; +} + +template +ReturnValue_t PoolVariable::serialize(uint8_t** buffer, size_t* size, const size_t max_size, + SerializeIF::Endianness streamEndianness) const { + return SerializeAdapter::serialize(&value, buffer, size, max_size, streamEndianness); +} + +template +size_t PoolVariable::getSerializedSize() const { + return SerializeAdapter::getSerializedSize(&value); +} + +template +ReturnValue_t PoolVariable::deSerialize(const uint8_t** buffer, size_t* size, + SerializeIF::Endianness streamEndianness) { + return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness); +} + +#if FSFW_CPP_OSTREAM_ENABLED == 1 +template +inline std::ostream& operator<<(std::ostream& out, const PoolVariable& var) { + out << var.value; + return out; +} +#endif + +template +PoolVariable::operator T() const { + return value; +} + +template +PoolVariable& PoolVariable::operator=(const T& newValue) { + value = newValue; + return *this; +} + +template +PoolVariable& PoolVariable::operator=(const PoolVariable& newPoolVariable) { + value = newPoolVariable.value; + return *this; +} + +template +bool PoolVariable::operator==(const PoolVariable& other) const { + return this->value == other.value; +} + +template +bool PoolVariable::operator==(const T& other) const { + return this->value == other; +} + +template +bool PoolVariable::operator!=(const PoolVariable& other) const { + return not(*this == other); +} + +template +bool PoolVariable::operator!=(const T& other) const { + return not(*this == other); +} + +template +bool PoolVariable::operator<(const PoolVariable& other) const { + return this->value < other.value; +} + +template +bool PoolVariable::operator<(const T& other) const { + return this->value < other; +} + +template +bool PoolVariable::operator>(const PoolVariable& other) const { + return not(*this < other); +} + +template +bool PoolVariable::operator>(const T& other) const { + return not(*this < other); +} + +template +using var_t = PoolVariable; + +using bool_t = PoolVariable; +using u8_t = PoolVariable; +using u16_t = PoolVariable; +using u32_t = PoolVariable; +using u64_t = PoolVariable; +using i8_t = PoolVariable; +using i16_t = PoolVariable; +using i32_t = PoolVariable; +using i64_t = PoolVariable; +using f32_t = PoolVariable; +using f64_t = PoolVariable; + +} // namespace datapool diff --git a/src/fsfw/datapool/PoolVariable.tpp b/src/fsfw/datapool/PoolVariable.tpp new file mode 100644 index 00000000..6f70f09b --- /dev/null +++ b/src/fsfw/datapool/PoolVariable.tpp @@ -0,0 +1 @@ +#pragma once diff --git a/src/fsfw/datapoollocal/SharedPool.cpp b/src/fsfw/datapool/SharedPool.cpp similarity index 53% rename from src/fsfw/datapoollocal/SharedPool.cpp rename to src/fsfw/datapool/SharedPool.cpp index bfaf5e38..e0ad6338 100644 --- a/src/fsfw/datapoollocal/SharedPool.cpp +++ b/src/fsfw/datapool/SharedPool.cpp @@ -4,7 +4,8 @@ #include "fsfw/ipc/MutexFactory.h" #include "fsfw/serviceinterface.h" -localpool::SharedPool::SharedPool(object_id_t ownerId) : ownerId(ownerId) { +using namespace dp; +SharedPool::SharedPool(object_id_t ownerId) : ownerId(ownerId) { mutex = MutexFactory::instance()->createMutex(); if (mutex == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -15,20 +16,20 @@ localpool::SharedPool::SharedPool(object_id_t ownerId) : ownerId(ownerId) { } } -localpool::SharedPool::~SharedPool() { MutexFactory::instance()->deleteMutex(mutex); } +SharedPool::~SharedPool() { MutexFactory::instance()->deleteMutex(mutex); } -object_id_t localpool::SharedPool::getOwnerId() const { return ownerId; } +object_id_t SharedPool::getOwnerId() const { return ownerId; } -void localpool::SharedPool::addPoolEntry(lp_id_t poolId, PoolEntryIF* entry) { +void SharedPool::addPoolEntry(lp_id_t poolId, PoolEntryIF* entry) { localPoolMap.emplace(poolId, entry); } -MutexIF* localpool::SharedPool::getLocalPoolMutex() { return mutex; } +MutexIF* SharedPool::getPoolMutex() { return mutex; } -ReturnValue_t localpool::SharedPool::printPoolEntry(lp_id_t localPoolId) { +ReturnValue_t SharedPool::printPoolEntry(lp_id_t localPoolId) { auto poolIter = localPoolMap.find(localPoolId); if (poolIter == localPoolMap.end()) { - return localpool::POOL_ENTRY_NOT_FOUND; + return POOL_ENTRY_NOT_FOUND; } poolIter->second->print(); return returnvalue::OK; diff --git a/src/fsfw/datapoollocal/SharedPool.h b/src/fsfw/datapool/SharedPool.h similarity index 78% rename from src/fsfw/datapoollocal/SharedPool.h rename to src/fsfw/datapool/SharedPool.h index 695e87d9..eda785ca 100644 --- a/src/fsfw/datapoollocal/SharedPool.h +++ b/src/fsfw/datapool/SharedPool.h @@ -1,11 +1,10 @@ #pragma once -#include "AccessLocalPoolF.h" #include "fsfw/datapool/PoolEntry.h" +#include "fsfw/datapool/definitions.h" #include "fsfw/ipc/MutexIF.h" -#include "localPoolDefinitions.h" -namespace localpool { +namespace datapool { class SharedPool { public: @@ -29,7 +28,7 @@ class SharedPool { ReturnValue_t fetchPoolEntry(lp_id_t localPoolId, PoolEntry** poolEntry); ReturnValue_t printPoolEntry(lp_id_t localPoolId); void addPoolEntry(lp_id_t poolId, PoolEntryIF* entry); - MutexIF* getLocalPoolMutex(); + MutexIF* getPoolMutex(); private: object_id_t ownerId; @@ -42,22 +41,22 @@ class SharedPool { }; template -inline ReturnValue_t localpool::SharedPool::fetchPoolEntry(lp_id_t localPoolId, - PoolEntry** poolEntry) { +inline ReturnValue_t datapool::SharedPool::fetchPoolEntry(lp_id_t localPoolId, + PoolEntry** poolEntry) { if (poolEntry == nullptr) { return returnvalue::FAILED; } auto poolIter = localPoolMap.find(localPoolId); if (poolIter == localPoolMap.end()) { - return localpool::POOL_ENTRY_NOT_FOUND; + return POOL_ENTRY_NOT_FOUND; } *poolEntry = dynamic_cast*>(poolIter->second); if (*poolEntry == nullptr) { - return localpool::POOL_ENTRY_TYPE_CONFLICT; + return POOL_ENTRY_TYPE_CONFLICT; } return returnvalue::OK; } -} // namespace localpool +} // namespace datapool diff --git a/src/fsfw/datapool/SharedSet.cpp b/src/fsfw/datapool/SharedSet.cpp new file mode 100644 index 00000000..3150e2f3 --- /dev/null +++ b/src/fsfw/datapool/SharedSet.cpp @@ -0,0 +1,16 @@ +#include "SharedSet.h" + +using namespace dp; + +SharedSet::SharedSet(dp::SharedPool& sharedPool, uint32_t setId, const size_t maxNumberOfVariables) + : SharedSetBase(sharedPool, setId, nullptr, maxNumberOfVariables), + poolVarList(maxNumberOfVariables) { + this->setContainer(poolVarList.data()); +} + +SharedSet::SharedSet(dp::structure_id_t sid, const size_t maxNumberOfVariables) + : SharedSetBase(sid, nullptr, maxNumberOfVariables), poolVarList(maxNumberOfVariables) { + this->setContainer(poolVarList.data()); +} + +SharedSet::~SharedSet() = default; diff --git a/src/fsfw/datapoollocal/LocalDataSet.h b/src/fsfw/datapool/SharedSet.h similarity index 59% rename from src/fsfw/datapoollocal/LocalDataSet.h rename to src/fsfw/datapool/SharedSet.h index 0140c607..f7d516c9 100644 --- a/src/fsfw/datapoollocal/LocalDataSet.h +++ b/src/fsfw/datapool/SharedSet.h @@ -1,10 +1,11 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALDATASET_H_ -#define FSFW_DATAPOOLLOCAL_LOCALDATASET_H_ +#pragma once #include -#include "SharedDatasetBase.h" +#include "SharedPool.h" +#include "SharedSetBase.h" +namespace datapool { /** * @brief This dataset type can be used to group related pool variables if the number of * variables should not be fixed. @@ -18,20 +19,20 @@ * @tparam capacity Capacity of the static dataset, which is usually known * beforehand. */ -class SharedDataSet : public SharedDatasetBase { +class SharedSet : public SharedSetBase { public: - SharedDataSet(localpool::SharedPool& sharedPool, uint32_t setId, size_t maxSize); + SharedSet(SharedPool& sharedPool, uint32_t setId, size_t maxSize); - SharedDataSet(sid_t sid, size_t maxSize); + SharedSet(sid_t sid, size_t maxSize); - ~SharedDataSet() override; + ~SharedSet() override; //! Copying forbidden for now. - SharedDataSet(const SharedDataSet&) = delete; - SharedDataSet& operator=(const SharedDataSet&) = delete; + SharedSet(const SharedSet&) = delete; + SharedSet& operator=(const SharedSet&) = delete; private: std::vector poolVarList; }; -#endif /* FSFW_DATAPOOLLOCAL_LOCALDATASET_H_ */ +} // namespace datapool diff --git a/src/fsfw/datapoollocal/SharedDatasetBase.cpp b/src/fsfw/datapool/SharedSetBase.cpp similarity index 50% rename from src/fsfw/datapoollocal/SharedDatasetBase.cpp rename to src/fsfw/datapool/SharedSetBase.cpp index f8c950fc..59a40197 100644 --- a/src/fsfw/datapoollocal/SharedDatasetBase.cpp +++ b/src/fsfw/datapool/SharedSetBase.cpp @@ -1,44 +1,48 @@ +#include "SharedSetBase.h" + +#include + #include -#include "fsfw/datapoollocal.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h" +#include "fsfw/datapool.h" #include "fsfw/globalfunctions/bitutility.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/serialize/SerializeAdapter.h" #include "fsfw/serviceinterface/ServiceInterface.h" -SharedDatasetBase::SharedDatasetBase(localpool::SharedPool &sharedPool, uint32_t setId, - PoolVariableIF **registeredVariablesArray, - const size_t maxNumberOfVariables) +using namespace datapool; + +SharedSetBase::SharedSetBase(SharedPool &sharedPool, uint32_t setId, + PoolVariableIF **registeredVariablesArray, + const size_t maxNumberOfVariables) : base(registeredVariablesArray, maxNumberOfVariables), sharedPool(&sharedPool) { - mutexIfSingleDataCreator = sharedPool.getLocalPoolMutex(); + mutexIfSingleDataCreator = sharedPool.getPoolMutex(); this->sid.objectId = sharedPool.getOwnerId(); this->sid.ownerSetId = setId; } -SharedDatasetBase::SharedDatasetBase(sid_t sid, PoolVariableIF **registeredVariablesArray, - const size_t maxNumberOfVariables) +SharedSetBase::SharedSetBase(structure_id_t sid, PoolVariableIF **registeredVariablesArray, + const size_t maxNumberOfVariables) : base(registeredVariablesArray, maxNumberOfVariables) { - auto *hkOwner = ObjectManager::instance()->get(sid.objectId); + auto *hkOwner = ObjectManager::instance()->get(sid.objectId); if (hkOwner != nullptr) { sharedPool = hkOwner->getOptionalSharedPool(); if (sharedPool != nullptr) { - mutexIfSingleDataCreator = sharedPool->getLocalPoolMutex(); + mutexIfSingleDataCreator = sharedPool->getPoolMutex(); } } this->sid = sid; } -SharedDatasetBase::SharedDatasetBase(PoolVariableIF **registeredVariablesArray, - const size_t maxNumberOfVariables, - bool protectEveryReadCommitCall) +SharedSetBase::SharedSetBase(PoolVariableIF **registeredVariablesArray, + const size_t maxNumberOfVariables, bool protectEveryReadCommitCall) : base(registeredVariablesArray, maxNumberOfVariables) { base.setReadCommitProtectionBehaviour(protectEveryReadCommitCall); } -SharedDatasetBase::~SharedDatasetBase() { +SharedSetBase::~SharedSetBase() { // In case set was read but not comitted, we commit all variables with an invalid state if (base.state == PoolDataSetBase::States::STATE_SET_WAS_READ) { for (uint16_t count = 0; count < base.getFillCount(); count++) { @@ -49,27 +53,25 @@ SharedDatasetBase::~SharedDatasetBase() { } } -ReturnValue_t SharedDatasetBase::lockDataPool(MutexIF::TimeoutType timeoutType, - uint32_t timeoutMs) { +ReturnValue_t SharedSetBase::lockDataPool(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { if (mutexIfSingleDataCreator != nullptr) { return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs); } return returnvalue::OK; } -ReturnValue_t SharedDatasetBase::unlockDataPool() { +ReturnValue_t SharedSetBase::unlockDataPool() { if (mutexIfSingleDataCreator != nullptr) { return mutexIfSingleDataCreator->unlockMutex(); } return returnvalue::OK; } -ReturnValue_t SharedDatasetBase::serializeLocalPoolIds(uint8_t **buffer, size_t *size, - size_t maxSize, - SerializeIF::Endianness streamEndianness, - bool serializeFillCount) const { +ReturnValue_t SharedSetBase::serializeLocalPoolIds(uint8_t **buffer, size_t *size, size_t maxSize, + SerializeIF::Endianness streamEndianness, + bool serializeFillCount) const { /* Serialize fill count as uint8_t */ - uint8_t fillCount = this->getFillCount(); + auto fillCount = this->getFillCount(); if (serializeFillCount) { SerializeAdapter::serialize(&fillCount, buffer, size, maxSize, streamEndianness); } @@ -92,68 +94,68 @@ ReturnValue_t SharedDatasetBase::serializeLocalPoolIds(uint8_t **buffer, size_t return returnvalue::OK; } -uint8_t SharedDatasetBase::getLocalPoolIdsSerializedSize(bool serializeFillCount) const { +size_t SharedSetBase::getLocalPoolIdsSerializedSize(bool serializeFillCount) const { if (serializeFillCount) { - return base.getFillCount() * sizeof(lp_id_t) + sizeof(uint8_t); + return base.getFillCount() * sizeof(lp_id_t) + sizeof(u8_t); } else { return base.getFillCount() * sizeof(lp_id_t); } } -size_t SharedDatasetBase::getSerializedSize() const { return base.getSerializedSize(); } +size_t SharedSetBase::getSerializedSize() const { return base.getSerializedSize(); } -ReturnValue_t SharedDatasetBase::deSerialize(const uint8_t **buffer, size_t *size, - SerializeIF::Endianness streamEndianness) { +ReturnValue_t SharedSetBase::deSerialize(const uint8_t **buffer, size_t *size, + SerializeIF::Endianness streamEndianness) { return base.deSerialize(buffer, size, streamEndianness); } -ReturnValue_t SharedDatasetBase::serialize(uint8_t **buffer, size_t *size, size_t maxSize, - SerializeIF::Endianness streamEndianness) const { +ReturnValue_t SharedSetBase::serialize(uint8_t **buffer, size_t *size, size_t maxSize, + SerializeIF::Endianness streamEndianness) const { return base.serialize(buffer, size, maxSize, streamEndianness); } -[[nodiscard]] ReturnValue_t SharedDatasetBase::serialize( +[[nodiscard]] ReturnValue_t SharedSetBase::serialize( uint8_t *buffer, size_t &serLen, size_t maxSize, SerializeIF::Endianness streamEndianness) const { return SerializeIF::serialize(buffer, serLen, maxSize, streamEndianness); } -void SharedDatasetBase::setReportingEnabled(bool reportingEnabled) { +void SharedSetBase::setReportingEnabled(bool reportingEnabled) { this->reportingEnabled = reportingEnabled; } -bool SharedDatasetBase::getReportingEnabled() const { return reportingEnabled; } +bool SharedSetBase::getReportingEnabled() const { return reportingEnabled; } -sid_t SharedDatasetBase::getSid() const { return sid; } +structure_id_t SharedSetBase::getSid() const { return sid; } -object_id_t SharedDatasetBase::getCreatorObjectId() { +object_id_t SharedSetBase::getCreatorObjectId() { if (sharedPool != nullptr) { return sharedPool->getOwnerId(); } return objects::NO_OBJECT; } -void SharedDatasetBase::setAllVariablesReadOnly() { +void SharedSetBase::setAllVariablesReadOnly() { for (size_t idx = 0; idx < this->getFillCount(); idx++) { base.registeredVariables[idx]->setReadWriteMode(pool_rwm_t::VAR_READ); } } -void SharedDatasetBase::printSet() { return; } +void SharedSetBase::printSet() { return; } -ReturnValue_t SharedDatasetBase::read(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { +ReturnValue_t SharedSetBase::read(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { return base.read(timeoutType, timeoutMs); } -ReturnValue_t SharedDatasetBase::commit(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { +ReturnValue_t SharedSetBase::commit(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { return base.commit(timeoutType, timeoutMs); } -uint16_t SharedDatasetBase::getFillCount() const { return base.getFillCount(); } +uint16_t SharedSetBase::getFillCount() const { return base.getFillCount(); } -ReturnValue_t SharedDatasetBase::registerVariable(PoolVariableIF *variable) { +ReturnValue_t SharedSetBase::registerVariable(PoolVariableIF *variable) { return base.registerVariable(variable); } -void SharedDatasetBase::setContainer(PoolVariableIF **variablesContainer) { +void SharedSetBase::setContainer(PoolVariableIF **variablesContainer) { return base.setContainer(variablesContainer); } -PoolVariableIF **SharedDatasetBase::getContainer() const { return base.getContainer(); } +PoolVariableIF **SharedSetBase::getContainer() const { return base.getContainer(); } diff --git a/src/fsfw/datapoollocal/SharedDatasetBase.h b/src/fsfw/datapool/SharedSetBase.h similarity index 83% rename from src/fsfw/datapoollocal/SharedDatasetBase.h rename to src/fsfw/datapool/SharedSetBase.h index bee7fae9..c9ef5af9 100644 --- a/src/fsfw/datapoollocal/SharedDatasetBase.h +++ b/src/fsfw/datapool/SharedSetBase.h @@ -1,18 +1,16 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_ -#define FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_ +#pragma once -#include - -#include "MarkChangedIF.h" +#include "SharedPool.h" +#include "definitions.h" #include "fsfw/datapool/DataSetIF.h" #include "fsfw/datapool/PoolDataSetBase.h" -#include "fsfw/datapoollocal/SharedPool.h" -#include "localPoolDefinitions.h" class PeriodicHkGenerationHelper; class PeriodicHkGenerationIF; class PeriodicHousekeepingHelper; +namespace datapool { + /** * @brief The LocalDataSet class manages a set of locally checked out * variables for local data pools @@ -41,8 +39,8 @@ class PeriodicHousekeepingHelper; * * @ingroup data_pool */ -class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { - friend class PeriodicHousekeepingHelper; +class SharedSetBase : public SerializeIF, public PoolDataSetIF { + // friend class PeriodicHousekeepingHelper; public: /** @@ -51,8 +49,8 @@ class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { * This constructor also initializes the components required for * periodic handling. */ - SharedDatasetBase(localpool::SharedPool& sharedPool, uint32_t setId, - PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables); + SharedSetBase(SharedPool& sharedPool, uint32_t setId, PoolVariableIF** registeredVariablesArray, + size_t maxNumberOfVariables); /** * @brief Constructor for users of the local pool data, which need @@ -65,8 +63,7 @@ class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { * @param registeredVariablesArray * @param maxNumberOfVariables */ - SharedDatasetBase(sid_t sid, PoolVariableIF** registeredVariablesArray, - size_t maxNumberOfVariables); + SharedSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables); /** * @brief Simple constructor, if the dataset is not the owner by @@ -86,8 +83,8 @@ class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { * multiple creators, this flag can be set to protect all read and * commit calls separately. */ - SharedDatasetBase(PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables, - bool protectEveryReadCommitCall = true); + SharedSetBase(PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables, + bool protectEveryReadCommitCall = true); /** * @brief The destructor automatically manages writing the valid @@ -97,13 +94,13 @@ class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { * the destructor parses all variables that are still registered to the set. * For each, the valid flag in the data pool is set to "invalid". */ - ~SharedDatasetBase() override; + ~SharedSetBase() override; /* The copy constructor and assingment constructor are forbidden for now. The use-cases are limited and the first step would be to implement them properly for the base class */ - SharedDatasetBase(const SharedDatasetBase& otherSet) = delete; - const SharedDatasetBase& operator=(const SharedDatasetBase& otherSet) = delete; + SharedSetBase(const SharedSetBase& otherSet) = delete; + const SharedSetBase& operator=(const SharedSetBase& otherSet) = delete; /** * Helper functions used to set all currently contained variables to read-only. @@ -121,14 +118,14 @@ class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override; - [[nodiscard]] sid_t getSid() const; + [[nodiscard]] dp::sid_t getSid() const; [[nodiscard]] size_t getSerializedSize() const override; ReturnValue_t serializeLocalPoolIds(uint8_t** buffer, size_t* size, size_t maxSize, SerializeIF::Endianness streamEndianness, bool serializeFillCount = true) const; - [[nodiscard]] uint8_t getLocalPoolIdsSerializedSize(bool serializeFillCount = true) const; + [[nodiscard]] size_t getLocalPoolIdsSerializedSize(bool serializeFillCount = true) const; object_id_t getCreatorObjectId(); @@ -141,7 +138,7 @@ class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { * returns 0.0 * @return */ - float getCollectionInterval() const; + [[nodiscard]] float getCollectionInterval() const; /** * @brief Can be overwritten by a specific implementation of a dataset to print the set. @@ -160,8 +157,8 @@ class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { PoolVariableIF** getContainer() const; protected: - // I am tired of inheritance trees. This is the better solution, even if it means a bit more code. PoolDataSetBase base; + sid_t sid; //! This mutex is used if the data is created by one object only. MutexIF* mutexIfSingleDataCreator = nullptr; @@ -195,7 +192,7 @@ class SharedDatasetBase : public SerializeIF, public PoolDataSetIF { */ ReturnValue_t unlockDataPool() override; - localpool::SharedPool* sharedPool = nullptr; + dp::SharedPool* sharedPool = nullptr; }; -#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_ */ +} // namespace datapool \ No newline at end of file diff --git a/src/fsfw/datapoollocal/StaticSharedDataset.h b/src/fsfw/datapool/StaticSharedSet.h similarity index 71% rename from src/fsfw/datapoollocal/StaticSharedDataset.h rename to src/fsfw/datapool/StaticSharedSet.h index 50db1ded..7c96010f 100644 --- a/src/fsfw/datapoollocal/StaticSharedDataset.h +++ b/src/fsfw/datapool/StaticSharedSet.h @@ -2,11 +2,9 @@ #include -#include "../objectmanager/SystemObjectIF.h" -#include "LocalPoolVariable.h" -#include "LocalPoolVector.h" -#include "SharedDatasetBase.h" +#include "SharedSetBase.h" +namespace datapool { /** * @brief This dataset type can be used to group related pool variables if the number of * variables is fixed. @@ -20,8 +18,8 @@ * @tparam NUM_VARIABLES Capacity of the static dataset, which is usually known * beforehand. */ -template -class StaticSharedDataset : public SharedDatasetBase { +template +class StaticSharedSet : public datapool::SharedSetBase { public: /** * Constructor used by data owner and creator like device handlers. @@ -30,8 +28,8 @@ class StaticSharedDataset : public SharedDatasetBase { * @param sharedPool Shared pool this dataset will read from or write to. * @param setId */ - StaticSharedDataset(localpool::SharedPool& sharedPool, uint32_t setId) - : SharedDatasetBase(sharedPool, setId, nullptr, NUM_VARIABLES) { + StaticSharedSet(SharedPool& sharedPool, const uint32_t setId) + : SharedSetBase(sharedPool, setId, nullptr, NUM_VARIABLES) { this->setContainer(poolVarList.data()); } @@ -39,10 +37,12 @@ class StaticSharedDataset : public SharedDatasetBase { * Constructor used by data users like controllers. * @param sid */ - explicit StaticSharedDataset(sid_t sid) : SharedDatasetBase(sid, nullptr, NUM_VARIABLES) { + explicit StaticSharedSet(const structure_id_t sid) : SharedSetBase(sid, nullptr, NUM_VARIABLES) { this->setContainer(poolVarList.data()); } private: std::array poolVarList = {}; -}; \ No newline at end of file +}; + +} // namespace datapool \ No newline at end of file diff --git a/src/fsfw/datapoollocal/localPoolDefinitions.h b/src/fsfw/datapool/definitions.h similarity index 69% rename from src/fsfw/datapoollocal/localPoolDefinitions.h rename to src/fsfw/datapool/definitions.h index 1578fc27..5ade7dd0 100644 --- a/src/fsfw/datapoollocal/localPoolDefinitions.h +++ b/src/fsfw/datapool/definitions.h @@ -1,5 +1,4 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDEFINITIONS_H_ -#define FSFW_DATAPOOLLOCAL_LOCALPOOLDEFINITIONS_H_ +#pragma once #include #include @@ -8,12 +7,13 @@ #include "../objectmanager/SystemObjectIF.h" #include "../objectmanager/frameworkObjects.h" +namespace datapool { + /** * @brief Type definition for local pool entries. */ using lp_id_t = uint32_t; -namespace localpool { static constexpr uint32_t INVALID_LPID = -1; static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF; @@ -25,19 +25,17 @@ static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x01) pool variables, using the std::map interface. */ using DataPool = std::map; -} // namespace localpool - /** * Used as a unique identifier for data sets. Consists of 4 byte object ID and 4 byte set ID. */ -union sid_t { +union structure_id_t { static constexpr uint64_t INVALID_SID = -1; static constexpr uint32_t INVALID_OBJECT_ID = objects::NO_OBJECT; static constexpr uint32_t INVALID_SET_ID = -1; - sid_t() : raw(INVALID_SID) {} + structure_id_t() : raw(INVALID_SID) {} - sid_t(object_id_t objectId, uint32_t setId) : objectId(objectId), ownerSetId(setId) {} + structure_id_t(object_id_t objectId, uint32_t setId) : objectId(objectId), ownerSetId(setId) {} struct { object_id_t objectId; @@ -55,23 +53,24 @@ union sid_t { bool notSet() const { return raw == INVALID_SID; } - bool operator==(const sid_t& other) const { return raw == other.raw; } + bool operator==(const structure_id_t& other) const { return raw == other.raw; } - bool operator!=(const sid_t& other) const { return not(raw == other.raw); } + bool operator!=(const structure_id_t& other) const { return not(raw == other.raw); } }; +using sid_t = structure_id_t; + /** * Used as a global unique identifier for local pool variables. Consists of 4 byte object ID * and 4 byte local pool ID. */ -union gp_id_t { +union g_id_t { static constexpr uint64_t INVALID_GPID = -1; static constexpr uint32_t INVALID_OBJECT_ID = objects::NO_OBJECT; - static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID; - gp_id_t() : raw(INVALID_GPID) {} + g_id_t() : raw(INVALID_GPID) {} - gp_id_t(object_id_t objectId, lp_id_t localPoolId) + g_id_t(object_id_t objectId, lp_id_t localPoolId) : objectId(objectId), localPoolId(localPoolId) {} struct { @@ -83,9 +82,11 @@ union gp_id_t { bool notSet() const { return raw == INVALID_GPID; } - bool operator==(const gp_id_t& other) const { return raw == other.raw; } + bool operator==(const g_id_t& other) const { return raw == other.raw; } - bool operator!=(const gp_id_t& other) const { return not(raw == other.raw); } + bool operator!=(const g_id_t& other) const { return not(raw == other.raw); } }; -#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLDEFINITIONS_H_ */ +} // namespace datapool + +namespace dp = datapool; \ No newline at end of file diff --git a/src/fsfw/datapool/internal/CMakeLists.txt b/src/fsfw/datapool/internal/CMakeLists.txt new file mode 100644 index 00000000..a0d48465 --- /dev/null +++ b/src/fsfw/datapool/internal/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(${LIB_FSFW_NAME} PRIVATE) diff --git a/src/fsfw/datapoollocal/internal/LocalPoolDataSetAttorney.h b/src/fsfw/datapool/internal/LocalPoolDataSetAttorney.h similarity index 83% rename from src/fsfw/datapoollocal/internal/LocalPoolDataSetAttorney.h rename to src/fsfw/datapool/internal/LocalPoolDataSetAttorney.h index 84b1c32d..d2932f4c 100644 --- a/src/fsfw/datapoollocal/internal/LocalPoolDataSetAttorney.h +++ b/src/fsfw/datapool/internal/LocalPoolDataSetAttorney.h @@ -1,6 +1,6 @@ #pragma once -#include "fsfw/datapoollocal/SharedDatasetBase.h" +#include "fsfw/datapool/SharedSetBase.h" class LocalPoolDataSetAttorney { static void setReportingEnabled(SharedDatasetBase& set, bool enabled) { diff --git a/src/fsfw/datapoollocal/internal/LocalDpManagerAttorney.h b/src/fsfw/datapool/internal/SharedPoolAttorney.h similarity index 64% rename from src/fsfw/datapoollocal/internal/LocalDpManagerAttorney.h rename to src/fsfw/datapool/internal/SharedPoolAttorney.h index f0fe7057..f696219a 100644 --- a/src/fsfw/datapoollocal/internal/LocalDpManagerAttorney.h +++ b/src/fsfw/datapool/internal/SharedPoolAttorney.h @@ -1,9 +1,8 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALDPMANAGERATTORNEY_H_ -#define FSFW_DATAPOOLLOCAL_LOCALDPMANAGERATTORNEY_H_ +#pragma once -#include "../PeriodicHkGenerationHelper.h" -#include "fsfw/datapoollocal/SharedPool.h" +#include "fsfw/datapool/SharedPool.h" +namespace datapool { /** * @brief This is a helper class implements the Attorney-Client idiom for access to * LocalDataPoolManager internals @@ -14,17 +13,15 @@ * an explicit subset of the pool manager private/protected functions. * See: https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Friendship_and_the_Attorney-Client */ -class LocalDpManagerAttorney { +class SharedPoolAttorney { private: template - static ReturnValue_t fetchPoolEntry(localpool::SharedPool& manager, lp_id_t localPoolId, + static ReturnValue_t fetchPoolEntry(SharedPool& manager, lp_id_t localPoolId, PoolEntry** poolEntry) { return manager.fetchPoolEntry(localPoolId, poolEntry); } - static MutexIF* getMutexHandle(localpool::SharedPool& manager) { - return manager.getLocalPoolMutex(); - } + static MutexIF* getMutexHandle(SharedPool& manager) { return manager.getPoolMutex(); } template friend class LocalPoolVariable; @@ -32,4 +29,4 @@ class LocalDpManagerAttorney { friend class LocalPoolVector; }; -#endif /* FSFW_DATAPOOLLOCAL_LOCALDPMANAGERATTORNEY_H_ */ +} // namespace datapool \ No newline at end of file diff --git a/src/fsfw/datapoollocal.h b/src/fsfw/datapoollocal.h deleted file mode 100644 index 5607f8a6..00000000 --- a/src/fsfw/datapoollocal.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ -#define FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ - -/* Collected related headers */ -#include "fsfw/datapoollocal/LocalDataSet.h" -#include "fsfw/datapoollocal/LocalPoolVariable.h" -#include "fsfw/datapoollocal/LocalPoolVector.h" -#include "fsfw/datapoollocal/SharedLocalDataset.h" -#include "fsfw/datapoollocal/SharedPool.h" - -#endif /* FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ */ diff --git a/src/fsfw/datapoollocal/CMakeLists.txt b/src/fsfw/datapoollocal/CMakeLists.txt deleted file mode 100644 index c19aa0f5..00000000 --- a/src/fsfw/datapoollocal/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -target_sources( - ${LIB_FSFW_NAME} - PRIVATE PeriodicHkGenerationHelper.cpp LocalDataSet.cpp SharedDatasetBase.cpp - LocalPoolObjectBase.cpp SharedLocalDataset.cpp) - -add_subdirectory(internal) diff --git a/src/fsfw/datapoollocal/LocalDataSet.cpp b/src/fsfw/datapoollocal/LocalDataSet.cpp deleted file mode 100644 index 03c4d244..00000000 --- a/src/fsfw/datapoollocal/LocalDataSet.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "fsfw/datapoollocal/LocalDataSet.h" - -SharedDataSet::SharedDataSet(localpool::SharedPool& sharedPool, uint32_t setId, - const size_t maxNumberOfVariables) - : SharedDatasetBase(sharedPool, setId, nullptr, maxNumberOfVariables), - poolVarList(maxNumberOfVariables) { - this->setContainer(poolVarList.data()); -} - -SharedDataSet::SharedDataSet(sid_t sid, const size_t maxNumberOfVariables) - : SharedDatasetBase(sid, nullptr, maxNumberOfVariables), poolVarList(maxNumberOfVariables) { - this->setContainer(poolVarList.data()); -} - -SharedDataSet::~SharedDataSet() {} diff --git a/src/fsfw/datapoollocal/LocalPoolVariable.h b/src/fsfw/datapoollocal/LocalPoolVariable.h deleted file mode 100644 index 8f585d9e..00000000 --- a/src/fsfw/datapoollocal/LocalPoolVariable.h +++ /dev/null @@ -1,185 +0,0 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ -#define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ - -#include "../datapool/DataSetIF.h" -#include "../datapool/PoolVariableIF.h" -#include "../objectmanager/ObjectManagerIF.h" -#include "../serialize/SerializeAdapter.h" -#include "../serviceinterface/ServiceInterface.h" -#include "AccessLocalPoolF.h" -#include "LocalPoolObjectBase.h" -#include "PeriodicHkGenerationHelper.h" -#include "PeriodicHkGenerationIF.h" -#include "internal/LocalDpManagerAttorney.h" - -/** - * @brief Local Pool Variable class which is used to access the local pools. - * @details - * This class is not stored in the map. Instead, it is used to access - * the pool entries by using a pointer to the map storing the pool - * entries. It can also be used to organize these pool entries into data sets. - * - * @tparam T The template parameter sets the type of the variable. Currently, - * all plain data types are supported, but in principle any type is possible. - * @ingroup data_pool - */ -template -class LocalPoolVariable : public LocalPoolObjectBase { - public: - //! Default ctor is forbidden. - LocalPoolVariable() = delete; - - /** - * This constructor is used by the data creators to have pool variable - * instances which can also be stored in datasets. - * - * It does not fetch the current value from the data pool, which - * has to be done by calling the read() operation. - * Datasets can be used to access multiple local pool entries in an - * efficient way. A pointer to a dataset can be passed to register - * the pool variable in that dataset directly. - * @param poolId ID of the local pool entry. - * @param hkOwner Pointer of the owner. This will generally be the calling - * class itself which passes "this". - * @param dataSet The data set in which the variable shall register itself. - * If nullptr, the variable is not registered. - * @param setReadWriteMode Specify the read-write mode of the pool variable. - */ - LocalPoolVariable(localpool::SharedPool& sharedPool, lp_id_t poolId, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); - - /** - * This constructor is used by data users like controllers to have - * access to the local pool variables of data creators by supplying - * the respective creator object ID. - * - * It does not fetch the current value from the data pool, which - * has to be done by calling the read() operation. - * Datasets can be used to access multiple local pool entries in an - * efficient way. A pointer to a dataset can be passed to register - * the pool variable in that dataset directly. - * @param poolId ID of the local pool entry. - * @param hkOwner object ID of the pool owner. - * @param dataSet The data set in which the variable shall register itself. - * If nullptr, the variable is not registered. - * @param setReadWriteMode Specify the read-write mode of the pool variable. - * - */ - LocalPoolVariable(object_id_t poolOwner, lp_id_t poolId, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); - /** - * Variation which takes the global unique identifier of a pool variable. - * @param globalPoolId - * @param dataSet - * @param setReadWriteMode - */ - LocalPoolVariable(gp_id_t globalPoolId, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); - - virtual ~LocalPoolVariable() {}; - - /** - * @brief This is the local copy of the data pool entry. - * @details The user can work on this attribute - * just like he would on a simple local variable. - */ - T value = 0; - - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, - SerializeIF::Endianness streamEndianness) const override; - size_t getSerializedSize() const override; - ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - SerializeIF::Endianness streamEndianness) override; - - /** - * @brief This is a call to read the array's values - * from the global data pool. - * @details - * When executed, this operation tries to fetch the pool entry with matching - * data pool id from the data pool and copies all array values and the valid - * information to its local attributes. - * In case of a failure (wrong type, size or pool id not found), the - * variable is set to zero and invalid. - * The read call is protected with a lock. - * It is recommended to use DataSets to read and commit multiple variables - * at once to avoid the overhead of unnecessary lock und unlock operations. - * - */ - ReturnValue_t read(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, - uint32_t timeoutMs = 20) override; - /** - * @brief The commit call copies the array values back to the data pool. - * @details - * It checks type and size, as well as if the variable is writable. If so, - * the value is copied and the local valid flag is written back as well. - * The read call is protected with a lock. - * It is recommended to use DataSets to read and commit multiple variables - * at once to avoid the overhead of unnecessary lock und unlock operations. - */ - ReturnValue_t commit(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, - uint32_t timeoutMs = 20) override; - - LocalPoolVariable& operator=(const T& newValue); - LocalPoolVariable& operator=(const LocalPoolVariable& newPoolVariable); - - //! Explicit type conversion operator. Allows casting the class to - //! its template type to perform operations on value. - explicit operator T() const; - - bool operator==(const LocalPoolVariable& other) const; - bool operator==(const T& other) const; - - bool operator!=(const LocalPoolVariable& other) const; - bool operator!=(const T& other) const; - - bool operator<(const LocalPoolVariable& other) const; - bool operator<(const T& other) const; - - bool operator>(const LocalPoolVariable& other) const; - bool operator>(const T& other) const; - - protected: - /** - * @brief Like #read, but without a lock protection of the global pool. - * @details - * The operation does NOT provide any mutual exclusive protection by itself. - * This can be used if the lock is handled externally to avoid the overhead - * of consecutive lock und unlock operations. - * Declared protected to discourage free public usage. - */ - ReturnValue_t readWithoutLock() override; - /** - * @brief Like #commit, but without a lock protection of the global pool. - * @details - * The operation does NOT provide any mutual exclusive protection by itself. - * This can be used if the lock is handled externally to avoid the overhead - * of consecutive lock und unlock operations. - * Declared protected to discourage free public usage. - */ - ReturnValue_t commitWithoutLock() override; - -#if FSFW_CPP_OSTREAM_ENABLED == 1 - // std::ostream is the type for object std::cout - template - friend std::ostream& operator<<(std::ostream& out, const LocalPoolVariable& var); -#endif -}; - -#include "LocalPoolVariable.tpp" - -template -using lp_var_t = LocalPoolVariable; - -using lp_bool_t = LocalPoolVariable; -using lp_uint8_t = LocalPoolVariable; -using lp_uint16_t = LocalPoolVariable; -using lp_uint32_t = LocalPoolVariable; -using lp_uint64_t = LocalPoolVariable; -using lp_int8_t = LocalPoolVariable; -using lp_int16_t = LocalPoolVariable; -using lp_int32_t = LocalPoolVariable; -using lp_int64_t = LocalPoolVariable; -using lp_float_t = LocalPoolVariable; -using lp_double_t = LocalPoolVariable; - -#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ */ diff --git a/src/fsfw/datapoollocal/LocalPoolVariable.tpp b/src/fsfw/datapoollocal/LocalPoolVariable.tpp deleted file mode 100644 index 1776205b..00000000 --- a/src/fsfw/datapoollocal/LocalPoolVariable.tpp +++ /dev/null @@ -1,177 +0,0 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ -#define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ - -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ -#error Include LocalPoolVariable.h before LocalPoolVariable.tpp! -#endif - -template -inline LocalPoolVariable::LocalPoolVariable(localpool::SharedPool& sharedPool, lp_id_t poolId, - DataSetIF* dataSet, pool_rwm_t setReadWriteMode) - : LocalPoolObjectBase(sharedPool, poolId, dataSet, setReadWriteMode) {} - -template -inline LocalPoolVariable::LocalPoolVariable(object_id_t poolOwner, lp_id_t poolId, - DataSetIF* dataSet, pool_rwm_t setReadWriteMode) - : LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {} - -template -inline LocalPoolVariable::LocalPoolVariable(gp_id_t globalPoolId, DataSetIF* dataSet, - pool_rwm_t setReadWriteMode) - : LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId, dataSet, - setReadWriteMode) {} - -template -inline ReturnValue_t LocalPoolVariable::read(MutexIF::TimeoutType timeoutType, - uint32_t timeoutMs) { - if (sharedPool == nullptr) { - return readWithoutLock(); - } - MutexIF* mutex = LocalDpManagerAttorney::getMutexHandle(*sharedPool); - ReturnValue_t result = mutex->lockMutex(timeoutType, timeoutMs); - if (result != returnvalue::OK) { - return result; - } - result = readWithoutLock(); - mutex->unlockMutex(); - return result; -} - -template -inline ReturnValue_t LocalPoolVariable::readWithoutLock() { - if (sharedPool == nullptr) { - return PoolVariableIF::INVALID_SHARED_POOL; - } - if (readWriteMode == pool_rwm_t::VAR_WRITE) { - return PoolVariableIF::INVALID_READ_WRITE_MODE; - } - - PoolEntry* poolEntry = nullptr; - ReturnValue_t result = - LocalDpManagerAttorney::fetchPoolEntry(*sharedPool, localPoolId, &poolEntry); - if (result != returnvalue::OK) { - return result; - } - - this->value = *(poolEntry->getDataPtr()); - return returnvalue::OK; -} - -template -inline ReturnValue_t LocalPoolVariable::commit(MutexIF::TimeoutType timeoutType, - uint32_t timeoutMs) { - if (sharedPool == nullptr) { - return commitWithoutLock(); - } - MutexIF* mutex = LocalDpManagerAttorney::getMutexHandle(*sharedPool); - ReturnValue_t result = mutex->lockMutex(timeoutType, timeoutMs); - if (result != returnvalue::OK) { - return result; - } - result = commitWithoutLock(); - mutex->unlockMutex(); - return result; -} - -template -inline ReturnValue_t LocalPoolVariable::commitWithoutLock() { - if (readWriteMode == pool_rwm_t::VAR_READ) { - return PoolVariableIF::INVALID_READ_WRITE_MODE; - } - - PoolEntry* poolEntry = nullptr; - ReturnValue_t result = - LocalDpManagerAttorney::fetchPoolEntry(*sharedPool, localPoolId, &poolEntry); - if (result != returnvalue::OK) { - return result; - } - - *(poolEntry->getDataPtr()) = this->value; - return returnvalue::OK; -} - -template -inline ReturnValue_t LocalPoolVariable::serialize( - uint8_t** buffer, size_t* size, const size_t max_size, - SerializeIF::Endianness streamEndianness) const { - return SerializeAdapter::serialize(&value, buffer, size, max_size, streamEndianness); -} - -template -inline size_t LocalPoolVariable::getSerializedSize() const { - return SerializeAdapter::getSerializedSize(&value); -} - -template -inline ReturnValue_t LocalPoolVariable::deSerialize(const uint8_t** buffer, size_t* size, - SerializeIF::Endianness streamEndianness) { - return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness); -} - -#if FSFW_CPP_OSTREAM_ENABLED == 1 -template -inline std::ostream& operator<<(std::ostream& out, const LocalPoolVariable& var) { - out << var.value; - return out; -} -#endif - -template -inline LocalPoolVariable::operator T() const { - return value; -} - -template -inline LocalPoolVariable& LocalPoolVariable::operator=(const T& newValue) { - value = newValue; - return *this; -} - -template -inline LocalPoolVariable& LocalPoolVariable::operator=( - const LocalPoolVariable& newPoolVariable) { - value = newPoolVariable.value; - return *this; -} - -template -inline bool LocalPoolVariable::operator==(const LocalPoolVariable& other) const { - return this->value == other.value; -} - -template -inline bool LocalPoolVariable::operator==(const T& other) const { - return this->value == other; -} - -template -inline bool LocalPoolVariable::operator!=(const LocalPoolVariable& other) const { - return not(*this == other); -} - -template -inline bool LocalPoolVariable::operator!=(const T& other) const { - return not(*this == other); -} - -template -inline bool LocalPoolVariable::operator<(const LocalPoolVariable& other) const { - return this->value < other.value; -} - -template -inline bool LocalPoolVariable::operator<(const T& other) const { - return this->value < other; -} - -template -inline bool LocalPoolVariable::operator>(const LocalPoolVariable& other) const { - return not(*this < other); -} - -template -inline bool LocalPoolVariable::operator>(const T& other) const { - return not(*this < other); -} - -#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */ diff --git a/src/fsfw/datapoollocal/LocalPoolVector.tpp b/src/fsfw/datapoollocal/LocalPoolVector.tpp deleted file mode 100644 index a453ceae..00000000 --- a/src/fsfw/datapoollocal/LocalPoolVector.tpp +++ /dev/null @@ -1,165 +0,0 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_ -#define FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_ - -#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ -#error Include LocalPoolVector.h before LocalPoolVector.tpp! -#endif - -template -inline LocalPoolVector::LocalPoolVector(localpool::SharedPool& sharedPool, - lp_id_t poolId, DataSetIF* dataSet, - pool_rwm_t setReadWriteMode) - : LocalPoolObjectBase(sharedPool, poolId, dataSet, setReadWriteMode) {} - -template -inline LocalPoolVector::LocalPoolVector(object_id_t poolOwner, lp_id_t poolId, - DataSetIF* dataSet, - pool_rwm_t setReadWriteMode) - : LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {} - -template -inline LocalPoolVector::LocalPoolVector(gp_id_t globalPoolId, DataSetIF* dataSet, - pool_rwm_t setReadWriteMode) - : LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId, dataSet, - setReadWriteMode) {} - -template -inline ReturnValue_t LocalPoolVector::read(MutexIF::TimeoutType timeoutType, - uint32_t timeoutMs) { - MutexGuard(LocalDpManagerAttorney::getMutexHandle(*sharedPool), timeoutType, timeoutMs); - return readWithoutLock(); -} -template -inline ReturnValue_t LocalPoolVector::readWithoutLock() { - if (readWriteMode == pool_rwm_t::VAR_WRITE) { - return PoolVariableIF::INVALID_READ_WRITE_MODE; - } - - PoolEntry* poolEntry = nullptr; - ReturnValue_t result = - LocalDpManagerAttorney::fetchPoolEntry(*sharedPool, localPoolId, &poolEntry); - memset(this->value, 0, vectorSize * sizeof(T)); - - if (result != returnvalue::OK) { - return result; - } - std::memcpy(this->value, poolEntry->getDataPtr(), poolEntry->getByteSize()); - return returnvalue::OK; -} - -template -inline ReturnValue_t LocalPoolVector::commit(bool valid, - MutexIF::TimeoutType timeoutType, - uint32_t timeoutMs) { - // this->setValid(valid); - return commit(timeoutType, timeoutMs); -} - -template -inline ReturnValue_t LocalPoolVector::commit(MutexIF::TimeoutType timeoutType, - uint32_t timeoutMs) { - MutexGuard mg(LocalDpManagerAttorney::getMutexHandle(*sharedPool), timeoutType, timeoutMs); - return commitWithoutLock(); -} - -template -inline ReturnValue_t LocalPoolVector::commitWithoutLock() { - if (readWriteMode == pool_rwm_t::VAR_READ) { - return PoolVariableIF::INVALID_READ_WRITE_MODE; - } - PoolEntry* poolEntry = nullptr; - ReturnValue_t result = - LocalDpManagerAttorney::fetchPoolEntry(*sharedPool, localPoolId, &poolEntry); - if (result != returnvalue::OK) { - return result; - } - std::memcpy(poolEntry->getDataPtr(), this->value, poolEntry->getByteSize()); - return returnvalue::OK; -} - -template -inline T& LocalPoolVector::operator[](size_t i) { - if (i < vectorSize) { - return value[i]; - } - // If this happens, I have to set some value. I consider this - // a configuration error, but I wont exit here. -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "LocalPoolVector: Invalid index. Setting or returning" - " last value!" - << std::endl; -#else - sif::printWarning( - "LocalPoolVector: Invalid index. Setting or returning" - " last value!\n"); -#endif - return value[vectorSize - 1]; -} - -template -inline const T& LocalPoolVector::operator[](size_t i) const { - if (i < vectorSize) { - return value[i]; - } - // If this happens, I have to set some value. I consider this - // a configuration error, but I wont exit here. -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "LocalPoolVector: Invalid index. Setting or returning" - " last value!" - << std::endl; -#else - sif::printWarning( - "LocalPoolVector: Invalid index. Setting or returning" - " last value!\n"); -#endif - return value[vectorSize - 1]; -} - -template -inline ReturnValue_t LocalPoolVector::serialize( - uint8_t** buffer, size_t* size, size_t maxSize, - SerializeIF::Endianness streamEndianness) const { - ReturnValue_t result = returnvalue::FAILED; - for (uint16_t i = 0; i < vectorSize; i++) { - result = SerializeAdapter::serialize(&(value[i]), buffer, size, maxSize, streamEndianness); - if (result != returnvalue::OK) { - break; - } - } - return result; -} - -template -inline size_t LocalPoolVector::getSerializedSize() const { - return vectorSize * SerializeAdapter::getSerializedSize(value); -} - -template -inline ReturnValue_t LocalPoolVector::deSerialize( - const uint8_t** buffer, size_t* size, SerializeIF::Endianness streamEndianness) { - ReturnValue_t result = returnvalue::FAILED; - for (uint16_t i = 0; i < vectorSize; i++) { - result = SerializeAdapter::deSerialize(&(value[i]), buffer, size, streamEndianness); - if (result != returnvalue::OK) { - break; - } - } - return result; -} - -#if FSFW_CPP_OSTREAM_ENABLED == 1 -template -inline std::ostream& operator<<(std::ostream& out, const LocalPoolVector& var) { - out << "Vector: ["; - for (int i = 0; i < vectorSize; i++) { - out << var.value[i]; - if (i < vectorSize - 1) { - out << ", "; - } - } - out << "]"; - return out; -} -#endif - -#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_TPP_ */ diff --git a/src/fsfw/datapoollocal/PeriodicHkGenerationIF.h b/src/fsfw/datapoollocal/PeriodicHkGenerationIF.h deleted file mode 100644 index 469812ef..00000000 --- a/src/fsfw/datapoollocal/PeriodicHkGenerationIF.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ -#define FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ - -#include - -#include "PeriodicHkGenerationHelper.h" -#include "fsfw/datapool/PoolEntryIF.h" -#include "fsfw/housekeeping/HousekeepingMessage.h" -#include "fsfw/ipc/MessageQueueSenderIF.h" -#include "fsfw/serviceinterface.h" -#include "localPoolDefinitions.h" - -class AccessPoolManagerIF; -class PeriodicHkGenerationProviderIF; -class LocalPoolDataSetBase; -class LocalPoolObjectBase; - -/** - * @brief This interface is implemented by classes which posses a local data pool (not - * the managing class). It defines the relationship between the local data pool owner and the - * LocalDataPoolManager. - * @details - * Any class implementing this interface shall also have a LocalDataPoolManager member class which - * contains the actual pool data structure and exposes the public interface for it. - * - * The local data pool can be accessed using helper classes by using the - * LocalPoolVariable, LocalPoolVector or LocalDataSet classes. Every local pool variable can - * be uniquely identified by a global pool ID (gp_id_t) and every dataset tied - * to a pool manager can be uniqely identified by a global structure ID (sid_t). - * - * All software objects which want to use the local pool of another object shall also use this - * interface, for example to get a handle to the subscription interface. The interface - * can be retrieved using the object manager, provided the target object is a SystemObject. - * For example, the following line of code can be used to retrieve the interface - * - * HasLocalDataPoolIF* poolIF = ObjectManager::instance()-> - * get(objects::SOME_OBJECT); - * if(poolIF != nullptr) { - * doSomething() - * } - */ -class PeriodicHkGenerationIF { - friend class HasLocalDpIFManagerAttorney; - friend class HasLocalDpIFUserAttorney; - - public: - virtual ~PeriodicHkGenerationIF() = default; - - static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID; - - [[nodiscard]] virtual object_id_t getObjectId() const = 0; - - /** Command queue for housekeeping messages. */ - [[nodiscard]] virtual MessageQueueId_t getCommandQueue() const = 0; - - virtual ReturnValue_t serializeHkDataset(sid_t structureId, uint8_t* buf, size_t maxSize) = 0; - - virtual ReturnValue_t specifyHkDatasets(std::vector& setList) = 0; - - virtual localpool::SharedPool* getOptionalSharedPool() = 0; - - /** - * These function can be implemented by pool owner, if they are required - * and used by the housekeeping message interface. - * */ - virtual ReturnValue_t addDataSet(sid_t sid) { return returnvalue::FAILED; }; - virtual ReturnValue_t removeDataSet(sid_t sid) { return returnvalue::FAILED; }; - virtual ReturnValue_t changeCollectionInterval(sid_t sid, float newIntervalSeconds) { - return returnvalue::FAILED; - }; - - /** - * This function can be used by data pool consumers to retrieve a handle - * which allows subscriptions to dataset and variable updates in form of messages. - * The consumers can then read the most recent variable value by calling read with - * an own pool variable or set instance or using the deserialized snapshot data. - * Returns the HK manager casted to the required interface by default. - * @return - */ - // virtual PeriodicHkGenerationProviderIF* getSubscriptionInterface() { - // return getHkManagerHandle(); - //} - - protected: - /** - * Every class implementing this interface should have a local data pool manager. This - * function will return a reference to the manager. - * @return - */ - // virtual PeriodicHkGenerationHelper* getHkManagerHandle() = 0; - - /** - * Accessor handle required for internal handling. Not intended for users and therefore - * declared protected. Users should instead use pool variables, sets or the subscription - * interface to access pool entries. Returns the HK manager casted to a different interface - * by default. - * @return - */ - // virtual AccessPoolManagerIF* getAccessorHandle() { return getHkManagerHandle(); } - - /** - * Similar to the function above, but used to get a local pool variable - * handle. This is only needed for update notifications, so it is not - * defined as abstract. This function is protected to prevent users from - * using raw pool variable pointers which could not be thread-safe. - * Users should use the #ProvidesDataPoolSubscriptionIF. - * @param localPoolId - * @return - */ - virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden. " - "Returning nullptr!" - << std::endl; -#else - sif::printWarning( - "HasLocalDataPoolIF::getPoolObjectHandle: " - "Not overriden. Returning nullptr!\n"); -#endif - return nullptr; - } -}; - -#endif /* FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ */ diff --git a/src/fsfw/datapoollocal/internal/CMakeLists.txt b/src/fsfw/datapoollocal/internal/CMakeLists.txt deleted file mode 100644 index 6585d06e..00000000 --- a/src/fsfw/datapoollocal/internal/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE HasLocalDpIFUserAttorney.cpp - HasLocalDpIFManagerAttorney.cpp) diff --git a/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.h b/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.h deleted file mode 100644 index e0cf0e81..00000000 --- a/src/fsfw/datapoollocal/internal/HasLocalDpIFManagerAttorney.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef FSFW_DATAPOOLLOCAL_HASLOCALDPIFMANAGERATTORNEY_H_ -#define FSFW_DATAPOOLLOCAL_HASLOCALDPIFMANAGERATTORNEY_H_ - -#include "fsfw/datapoollocal/localPoolDefinitions.h" - -class PeriodicHkGenerationIF; -class LocalPoolDataSetBase; -class LocalPoolObjectBase; - -class HasLocalDpIFManagerAttorney { - static LocalPoolObjectBase* getPoolObjectHandle(PeriodicHkGenerationIF* clientIF, - lp_id_t localPoolId); - - static object_id_t getObjectId(PeriodicHkGenerationIF* clientIF); - - friend class PeriodicHkGenerationHelper; -}; - -#endif /* FSFW_DATAPOOLLOCAL_HASLOCALDPIFMANAGERATTORNEY_H_ */ diff --git a/src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp b/src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp deleted file mode 100644 index 87afb23c..00000000 --- a/src/fsfw/datapoollocal/internal/HasLocalDpIFUserAttorney.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "HasLocalDpIFUserAttorney.h" - -#include "fsfw/datapoollocal/AccessLocalPoolF.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationIF.h" diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp index c29300f5..44ae9fee 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.cpp +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.cpp @@ -1,11 +1,10 @@ #include "DeviceHandlerBase.h" #include "fsfw/datapool/PoolReadGuard.h" -#include "fsfw/datapoollocal/LocalPoolVariable.h" +#include "fsfw/datapool/PoolVariable.h" #include "fsfw/devicehandlers/AcceptsDeviceResponsesIF.h" #include "fsfw/devicehandlers/DeviceTmReportingWrapper.h" #include "fsfw/globalfunctions/CRC.h" -#include "fsfw/housekeeping/HousekeepingMessage.h" #include "fsfw/ipc/MessageQueueMessage.h" #include "fsfw/ipc/QueueFactory.h" #include "fsfw/objectmanager/ObjectManager.h" @@ -413,7 +412,7 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode, Submode_t s } ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap( - DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, SharedDatasetBase* replyDataSet, + DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, dp::SharedSetBase* replyDataSet, size_t replyLen, bool periodic, bool hasDifferentReplyId, DeviceCommandId_t replyId, Countdown* countdown) { // No need to check, as we may try to insert multiple times. @@ -428,7 +427,7 @@ ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap( ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, uint16_t maxDelayCycles, - SharedDatasetBase* dataSet, size_t replyLen, + dp::SharedSetBase* dataSet, size_t replyLen, bool periodic, Countdown* countdown) { DeviceReplyInfo info; info.maxDelayCycles = maxDelayCycles; @@ -529,7 +528,7 @@ ReturnValue_t DeviceHandlerBase::updatePeriodicReply(bool enable, DeviceCommandI } ReturnValue_t DeviceHandlerBase::setReplyDataset(DeviceCommandId_t replyId, - SharedDatasetBase* dataSet) { + dp::SharedSetBase* dataSet) { auto replyIter = deviceReplyMap.find(replyId); if (replyIter == deviceReplyMap.end()) { return returnvalue::FAILED; @@ -1611,4 +1610,4 @@ ReturnValue_t DeviceHandlerBase::finishAction(bool success, DeviceCommandId_t ac void DeviceHandlerBase::setNormalDatapoolEntriesInvalid() { return; } -PeriodicHkGenerationHelper& DeviceHandlerBase::getHkHelper() { return hkHelper; } +hk::PeriodicHelper& DeviceHandlerBase::getHkHelper() { return hkHelper; } diff --git a/src/fsfw/devicehandlers/DeviceHandlerBase.h b/src/fsfw/devicehandlers/DeviceHandlerBase.h index 1e26b47b..eb41a153 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/DeviceHandlerBase.h @@ -1,6 +1,8 @@ #ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ #define FSFW_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ +#include + #include #include @@ -10,9 +12,6 @@ #include "DeviceHandlerThermalSet.h" #include "fsfw/action/ActionHelper.h" #include "fsfw/action/HasActionsIF.h" -#include "fsfw/datapool/PoolVariableIF.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationIF.h" #include "fsfw/health/HealthHelper.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/modes/HasModesIF.h" @@ -20,7 +19,6 @@ #include "fsfw/parameters/ParameterHelper.h" #include "fsfw/power/PowerSwitchIF.h" #include "fsfw/returnvalues/returnvalue.h" -#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/serviceInterfaceDefintions.h" #include "fsfw/subsystem/ModeTreeConnectionIF.h" #include "fsfw/tasks/ExecutableObjectIF.h" @@ -88,7 +86,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, public ModeTreeChildIF, public ModeTreeConnectionIF, public ReceivesParameterMessagesIF, - public PeriodicHkGenerationIF { + public hk::GeneratesPeriodicHkIF { friend void(Factory::setStaticFrameworkObjectIds)(); public: @@ -109,7 +107,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, void setCustomFdir(FailureIsolationBase *fdir); void setPowerSwitcher(PowerSwitchIF *switcher); - PeriodicHkGenerationHelper &getHkHelper(); + hk::PeriodicHelper &getHkHelper(); /** * extending the modes of DeviceHandler IF for internal state machine @@ -508,7 +506,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, * - @c returnvalue::FAILED else. */ ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, - SharedDatasetBase *replyDataSet = nullptr, + dp::SharedSetBase *replyDataSet = nullptr, size_t replyLen = 0, bool periodic = false, bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0, @@ -529,7 +527,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, * - @c returnvalue::FAILED else. */ ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, - SharedDatasetBase *dataSet = nullptr, size_t replyLen = 0, + dp::SharedSetBase *dataSet = nullptr, size_t replyLen = 0, bool periodic = false, Countdown *countdown = nullptr); /** @@ -582,7 +580,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, * @details * Used by the local data pool manager. */ - ReturnValue_t setReplyDataset(DeviceCommandId_t replyId, SharedDatasetBase *dataset); + ReturnValue_t setReplyDataset(DeviceCommandId_t replyId, dp::SharedSetBase *dataset); /** * Get the time needed to transit from modeFrom to modeTo. @@ -790,7 +788,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, /** Cookie used for communication */ CookieIF *comCookie; - localpool::SharedPool sharedPool; + dp::SharedPool sharedPool; /* Health helper for HasHealthIF */ HealthHelper healthHelper; @@ -801,7 +799,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, /* Action helper for HasActionsIF */ ActionHelper actionHelper; /* Housekeeping Manager */ - PeriodicHkGenerationHelper hkHelper; + hk::PeriodicHelper hkHelper; /** * @brief Information about commands @@ -849,7 +847,7 @@ class DeviceHandlerBase : public DeviceHandlerIF, //! The dataset used to access housekeeping data related to the //! respective device reply. Will point to a dataset held by //! the child handler (if one is specified) - SharedDatasetBase *dataSet = nullptr; + dp::SharedSetBase *dataSet = nullptr; //! The command that expects this reply. DeviceCommandMap::iterator command; //! Instead of using delayCycles to specify the maximum time to wait for the device reply, it diff --git a/src/fsfw/devicehandlers/DeviceHandlerIF.h b/src/fsfw/devicehandlers/DeviceHandlerIF.h index acdb561c..8b939ed6 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerIF.h +++ b/src/fsfw/devicehandlers/DeviceHandlerIF.h @@ -2,11 +2,11 @@ #define FSFW_DEVICEHANDLERS_DEVICEHANDLERIF_H_ #include "../action/HasActionsIF.h" -#include "../datapoollocal/localPoolDefinitions.h" #include "../events/Event.h" #include "../ipc/MessageQueueSenderIF.h" #include "../modes/HasModesIF.h" #include "DeviceHandlerMessage.h" +#include "fsfw/datapool/definitions.h" /** * This is used to uniquely identify commands that are sent to a device @@ -120,10 +120,10 @@ class DeviceHandlerIF { NOTHING //!< Do nothing. }; - static constexpr uint32_t DEFAULT_THERMAL_SET_ID = sid_t::INVALID_SET_ID - 1; + static constexpr uint32_t DEFAULT_THERMAL_SET_ID = dp::sid_t::INVALID_SET_ID - 1; - static constexpr lp_id_t DEFAULT_THERMAL_STATE_POOL_ID = localpool::INVALID_LPID - 2; - static constexpr lp_id_t DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID = localpool::INVALID_LPID - 1; + static constexpr dp::lp_id_t DEFAULT_THERMAL_STATE_POOL_ID = dp::INVALID_LPID - 2; + static constexpr dp::lp_id_t DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID = dp::INVALID_LPID - 1; /** * Default Destructor @@ -138,8 +138,8 @@ class DeviceHandlerIF { }; struct ThermalStateCfg { - lp_id_t thermalStatePoolId = DeviceHandlerIF::DEFAULT_THERMAL_STATE_POOL_ID; - lp_id_t thermalRequestPoolId = DeviceHandlerIF::DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID; + dp::lp_id_t thermalStatePoolId = DeviceHandlerIF::DEFAULT_THERMAL_STATE_POOL_ID; + dp::lp_id_t thermalRequestPoolId = DeviceHandlerIF::DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID; uint32_t thermalSetId = DeviceHandlerIF::DEFAULT_THERMAL_SET_ID; }; diff --git a/src/fsfw/devicehandlers/DeviceHandlerThermalSet.h b/src/fsfw/devicehandlers/DeviceHandlerThermalSet.h index 7e52d271..3a12e89a 100644 --- a/src/fsfw/devicehandlers/DeviceHandlerThermalSet.h +++ b/src/fsfw/devicehandlers/DeviceHandlerThermalSet.h @@ -1,29 +1,29 @@ #ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERTHERMALSET_H_ #define FSFW_DEVICEHANDLERS_DEVICEHANDLERTHERMALSET_H_ -#include +#include +#include -#include "../datapoollocal/LocalPoolVariable.h" -#include "../datapoollocal/SharedLocalDataset.h" #include "DeviceHandlerIF.h" +#include "fsfw/datapool/PoolVariable.h" -class DeviceHandlerThermalSet : public StaticSharedDataset<2> { +class DeviceHandlerThermalSet : public dp::StaticSharedSet<2> { public: - DeviceHandlerThermalSet(PeriodicHkGenerationIF* hkOwner, ThermalStateCfg cfg) + DeviceHandlerThermalSet(hk::GeneratesPeriodicHkIF* hkOwner, ThermalStateCfg cfg) : DeviceHandlerThermalSet(hkOwner->getObjectId(), cfg) {} DeviceHandlerThermalSet(object_id_t deviceHandler, ThermalStateCfg cfg) - : StaticSharedDataset(sid_t(deviceHandler, cfg.thermalSetId)), + : StaticSharedSet(dp::structure_id_t(deviceHandler, cfg.thermalSetId)), thermalStatePoolId(cfg.thermalStatePoolId), heaterRequestPoolId(cfg.thermalRequestPoolId) {} - const lp_id_t thermalStatePoolId; - const lp_id_t heaterRequestPoolId; + const dp::lp_id_t thermalStatePoolId; + const dp::lp_id_t heaterRequestPoolId; - lp_var_t thermalState = - lp_var_t(sid.objectId, thermalStatePoolId, this); - lp_var_t heaterRequest = - lp_var_t(sid.objectId, heaterRequestPoolId, this); + dp::var_t thermalState = + dp::var_t(sid.objectId, thermalStatePoolId, this); + dp::var_t heaterRequest = + dp::var_t(sid.objectId, heaterRequestPoolId, this); }; #endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERTHERMALSET_H_ */ diff --git a/src/fsfw/devicehandlers/FreshDeviceHandlerBase.h b/src/fsfw/devicehandlers/FreshDeviceHandlerBase.h index 549c7193..48e1efe6 100644 --- a/src/fsfw/devicehandlers/FreshDeviceHandlerBase.h +++ b/src/fsfw/devicehandlers/FreshDeviceHandlerBase.h @@ -1,12 +1,13 @@ #pragma once +#include + #include "fsfw/action.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationIF.h" #include "fsfw/devicehandlers/DeviceHandlerIF.h" #include "fsfw/fdir/FailureIsolationBase.h" #include "fsfw/health/HasHealthIF.h" #include "fsfw/health/HealthHelper.h" +#include "fsfw/housekeeping/GeneratesPeriodicHkIF.h" #include "fsfw/modes/HasModesIF.h" #include "fsfw/objectmanager.h" #include "fsfw/parameters/ParameterHelper.h" @@ -34,7 +35,7 @@ class FreshDeviceHandlerBase : public SystemObject, public ModeTreeConnectionIF, public HasActionsIF, public ReceivesParameterMessagesIF, - public PeriodicHkGenerationIF { + public hk::GeneratesPeriodicHkIF { public: explicit FreshDeviceHandlerBase(DhbConfig config); ~FreshDeviceHandlerBase() override; @@ -61,7 +62,7 @@ class FreshDeviceHandlerBase : public SystemObject, ModeHelper modeHelper; HealthHelper healthHelper; ParameterHelper paramHelper; - PeriodicHkGenerationHelper hkHelper; + hk::PeriodicHelper hkHelper; bool hasCustomFdir = false; FailureIsolationBase* fdirInstance; diff --git a/src/fsfw/housekeeping/CMakeLists.txt b/src/fsfw/housekeeping/CMakeLists.txt index 339a1138..ac39ba35 100644 --- a/src/fsfw/housekeeping/CMakeLists.txt +++ b/src/fsfw/housekeeping/CMakeLists.txt @@ -1 +1,2 @@ -target_sources(${LIB_FSFW_NAME} PRIVATE HousekeepingMessage.cpp) +target_sources(${LIB_FSFW_NAME} PRIVATE HousekeepingMessage.cpp + PeriodicHkHelper.cpp) diff --git a/src/fsfw/housekeeping/GeneratesPeriodicHkIF.h b/src/fsfw/housekeeping/GeneratesPeriodicHkIF.h new file mode 100644 index 00000000..57ccc992 --- /dev/null +++ b/src/fsfw/housekeeping/GeneratesPeriodicHkIF.h @@ -0,0 +1,64 @@ +#pragma once + +#include + +#include + +#include "definitions.h" +#include "fsfw/datapool/definitions.h" + +namespace hk { + +/** + * @brief This interface is implemented by classes which posses a local data pool (not + * the managing class). It defines the relationship between the local data pool owner and the + * LocalDataPoolManager. + * @details + * Any class implementing this interface shall also have a LocalDataPoolManager member class which + * contains the actual pool data structure and exposes the public interface for it. + * + * The local data pool can be accessed using helper classes by using the + * LocalPoolVariable, LocalPoolVector or LocalDataSet classes. Every local pool variable can + * be uniquely identified by a global pool ID (gp_id_t) and every dataset tied + * to a pool manager can be uniqely identified by a global structure ID (sid_t). + * + * All software objects which want to use the local pool of another object shall also use this + * interface, for example to get a handle to the subscription interface. The interface + * can be retrieved using the object manager, provided the target object is a SystemObject. + * For example, the following line of code can be used to retrieve the interface + * + * HasLocalDataPoolIF* poolIF = ObjectManager::instance()-> + * get(objects::SOME_OBJECT); + * if(poolIF != nullptr) { + * doSomething() + * } + */ +class GeneratesPeriodicHkIF { + public: + [[nodiscard]] virtual object_id_t getObjectId() const = 0; + + /** Command queue for housekeeping messages. */ + [[nodiscard]] virtual MessageQueueId_t getCommandQueue() const = 0; + + virtual datapool::SharedPool* getOptionalSharedPool() = 0; + + protected: + virtual ~GeneratesPeriodicHkIF() = default; + + static constexpr uint32_t INVALID_LPID = dp::INVALID_LPID; + + virtual ReturnValue_t serializeHkDataset(dp::sid_t structureId, uint8_t* buf, size_t maxSize) = 0; + + virtual ReturnValue_t specifyHkDatasets(std::vector& setList) = 0; + + /** + * These function can be implemented by pool owner, if they are required + * and used by the housekeeping message interface. + * */ + virtual ReturnValue_t addDataSet(dp::sid_t sid) { return returnvalue::FAILED; }; + virtual ReturnValue_t removeDataSet(dp::sid_t sid) { return returnvalue::FAILED; }; + virtual ReturnValue_t changeCollectionInterval(dp::sid_t sid, float newIntervalSeconds) { + return returnvalue::FAILED; + }; +}; +} // namespace hk \ No newline at end of file diff --git a/src/fsfw/housekeeping/HousekeepingMessage.cpp b/src/fsfw/housekeeping/HousekeepingMessage.cpp index 3ef979fc..156251fc 100644 --- a/src/fsfw/housekeeping/HousekeepingMessage.cpp +++ b/src/fsfw/housekeeping/HousekeepingMessage.cpp @@ -8,7 +8,7 @@ HousekeepingMessage::~HousekeepingMessage() {} -void HousekeepingMessage::setHkReportReply(CommandMessage *message, sid_t sid, +void HousekeepingMessage::setHkReportReply(CommandMessage *message, dp::structure_id_t sid, store_address_t storeId) { message->setCommand(HK_REPORT); message->setMessageSize(HK_MESSAGE_SIZE); @@ -16,15 +16,15 @@ void HousekeepingMessage::setHkReportReply(CommandMessage *message, sid_t sid, message->setParameter3(storeId.raw); } -sid_t HousekeepingMessage::getHkDataReply(const CommandMessage *message, - store_address_t *storeIdToSet) { +dp::structure_id_t HousekeepingMessage::getHkDataReply(const CommandMessage *message, + store_address_t *storeIdToSet) { if (storeIdToSet != nullptr) { *storeIdToSet = message->getParameter3(); } return getSid(message); } -void HousekeepingMessage::setToggleReportingCommand(CommandMessage *message, sid_t sid, +void HousekeepingMessage::setToggleReportingCommand(CommandMessage *message, dp::structure_id_t sid, bool enableReporting) { if (enableReporting) { message->setCommand(ENABLE_PERIODIC_HK_REPORT_GENERATION); @@ -35,20 +35,21 @@ void HousekeepingMessage::setToggleReportingCommand(CommandMessage *message, sid setSid(message, sid); } -void HousekeepingMessage::setStructureReportingCommand(CommandMessage *command, sid_t sid) { +void HousekeepingMessage::setStructureReportingCommand(CommandMessage *command, + dp::structure_id_t sid) { command->setCommand(REPORT_HK_REPORT_STRUCTURES); setSid(command, sid); } -void HousekeepingMessage::setOneShotReportCommand(CommandMessage *command, sid_t sid) { +void HousekeepingMessage::setOneShotReportCommand(CommandMessage *command, dp::structure_id_t sid) { command->setCommand(GENERATE_ONE_PARAMETER_REPORT); setSid(command, sid); } void HousekeepingMessage::setCollectionIntervalModificationCommand(CommandMessage *command, - sid_t sid, + dp::structure_id_t sid, float collectionInterval) { command->setCommand(MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL); @@ -60,7 +61,7 @@ void HousekeepingMessage::setCollectionIntervalModificationCommand(CommandMessag setSid(command, sid); } -sid_t HousekeepingMessage::getCollectionIntervalModificationCommand( +dp::structure_id_t HousekeepingMessage::getCollectionIntervalModificationCommand( const CommandMessage *command, dur_millis_t &newCollectionIntervalMs) { std::memcpy(&newCollectionIntervalMs, command->getData() + 2 * sizeof(uint32_t), sizeof(newCollectionIntervalMs)); @@ -68,39 +69,39 @@ sid_t HousekeepingMessage::getCollectionIntervalModificationCommand( return getSid(command); } -void HousekeepingMessage::setHkRequestSuccessReply(CommandMessage *reply, sid_t sid) { +void HousekeepingMessage::setHkRequestSuccessReply(CommandMessage *reply, dp::structure_id_t sid) { setSid(reply, sid); reply->setCommand(HK_REQUEST_SUCCESS); } -void HousekeepingMessage::setHkRequestFailureReply(CommandMessage *reply, sid_t sid, +void HousekeepingMessage::setHkRequestFailureReply(CommandMessage *reply, dp::structure_id_t sid, ReturnValue_t error) { setSid(reply, sid); reply->setCommand(HK_REQUEST_FAILURE); reply->setParameter3(error); } -sid_t HousekeepingMessage::getHkRequestFailureReply(const CommandMessage *reply, - ReturnValue_t *error) { +dp::structure_id_t HousekeepingMessage::getHkRequestFailureReply(const CommandMessage *reply, + ReturnValue_t *error) { if (error != nullptr) { *error = reply->getParameter3(); } return getSid(reply); } -sid_t HousekeepingMessage::getSid(const CommandMessage *message) { - sid_t sid; +dp::structure_id_t HousekeepingMessage::getSid(const CommandMessage *message) { + dp::structure_id_t sid; std::memcpy(&sid.raw, message->getData(), sizeof(sid.raw)); return sid; } -gp_id_t HousekeepingMessage::getGpid(const CommandMessage *message) { - gp_id_t globalPoolId; +dp::g_id_t HousekeepingMessage::getGpid(const CommandMessage *message) { + dp::g_id_t globalPoolId; std::memcpy(&globalPoolId.raw, message->getData(), sizeof(globalPoolId.raw)); return globalPoolId; } -void HousekeepingMessage::setHkStuctureReportReply(CommandMessage *reply, sid_t sid, +void HousekeepingMessage::setHkStuctureReportReply(CommandMessage *reply, dp::structure_id_t sid, store_address_t storeId) { reply->setCommand(HK_DEFINITIONS_REPORT); setSid(reply, sid); @@ -123,34 +124,36 @@ void HousekeepingMessage::clear(CommandMessage *message) { message->setCommand(CommandMessage::CMD_NONE); } -sid_t HousekeepingMessage::getUpdateNotificationSetCommand(const CommandMessage *command) { +dp::structure_id_t HousekeepingMessage::getUpdateNotificationSetCommand( + const CommandMessage *command) { return getSid(command); } -gp_id_t HousekeepingMessage::getUpdateNotificationVariableCommand(const CommandMessage *command) { +dp::g_id_t HousekeepingMessage::getUpdateNotificationVariableCommand( + const CommandMessage *command) { return getGpid(command); } -sid_t HousekeepingMessage::getUpdateSnapshotSetCommand(const CommandMessage *command, - store_address_t *storeId) { +dp::structure_id_t HousekeepingMessage::getUpdateSnapshotSetCommand(const CommandMessage *command, + store_address_t *storeId) { if (storeId != nullptr) { *storeId = command->getParameter3(); } return getSid(command); } -gp_id_t HousekeepingMessage::getUpdateSnapshotVariableCommand(const CommandMessage *command, - store_address_t *storeId) { +dp::g_id_t HousekeepingMessage::getUpdateSnapshotVariableCommand(const CommandMessage *command, + store_address_t *storeId) { if (storeId != nullptr) { *storeId = command->getParameter3(); } return getGpid(command); } -void HousekeepingMessage::setSid(CommandMessage *message, sid_t sid) { +void HousekeepingMessage::setSid(CommandMessage *message, dp::structure_id_t sid) { std::memcpy(message->getData(), &sid.raw, sizeof(sid.raw)); } -void HousekeepingMessage::setGpid(CommandMessage *message, gp_id_t globalPoolId) { +void HousekeepingMessage::setGpid(CommandMessage *message, dp::g_id_t globalPoolId) { std::memcpy(message->getData(), &globalPoolId.raw, sizeof(globalPoolId.raw)); } diff --git a/src/fsfw/housekeeping/HousekeepingMessage.h b/src/fsfw/housekeeping/HousekeepingMessage.h index dd4005f3..7595b8a9 100644 --- a/src/fsfw/housekeeping/HousekeepingMessage.h +++ b/src/fsfw/housekeeping/HousekeepingMessage.h @@ -3,7 +3,7 @@ #include -#include "fsfw/datapoollocal/localPoolDefinitions.h" +#include "fsfw/datapool/definitions.h" #include "fsfw/ipc/CommandMessage.h" #include "fsfw/ipc/FwMessageTypes.h" #include "fsfw/objectmanager/frameworkObjects.h" @@ -18,7 +18,7 @@ class HousekeepingMessage { public: static constexpr size_t HK_MESSAGE_SIZE = - CommandMessageIF::HEADER_SIZE + sizeof(sid_t) + sizeof(uint32_t); + CommandMessageIF::HEADER_SIZE + sizeof(dp::structure_id_t) + sizeof(uint32_t); /** * Concrete instance is not used, instead this class operates on @@ -54,25 +54,27 @@ class HousekeepingMessage { // static constexpr Command_t UPDATE_HK_REPORT = MAKE_COMMAND_ID(134); - static sid_t getSid(const CommandMessage* message); - static gp_id_t getGpid(const CommandMessage* message); + static dp::sid_t getSid(const CommandMessage* message); + static dp::g_id_t getGpid(const CommandMessage* message); /* Housekeeping Interface Messages */ - static void setToggleReportingCommand(CommandMessage* command, sid_t sid, bool enableReporting); - static void setStructureReportingCommand(CommandMessage* command, sid_t sid); - static void setOneShotReportCommand(CommandMessage* command, sid_t sid); - static void setCollectionIntervalModificationCommand(CommandMessage* command, sid_t sid, + static void setToggleReportingCommand(CommandMessage* command, dp::sid_t sid, + bool enableReporting); + static void setStructureReportingCommand(CommandMessage* command, dp::sid_t sid); + static void setOneShotReportCommand(CommandMessage* command, dp::sid_t sid); + static void setCollectionIntervalModificationCommand(CommandMessage* command, dp::sid_t sid, float collectionInterval); - static void setHkReportReply(CommandMessage* reply, sid_t sid, store_address_t storeId); + static void setHkReportReply(CommandMessage* reply, dp::sid_t sid, store_address_t storeId); - static void setHkRequestSuccessReply(CommandMessage* reply, sid_t sid); - static void setHkRequestFailureReply(CommandMessage* reply, sid_t sid, ReturnValue_t error); + static void setHkRequestSuccessReply(CommandMessage* reply, dp::sid_t sid); + static void setHkRequestFailureReply(CommandMessage* reply, dp::sid_t sid, ReturnValue_t error); - static void setHkStuctureReportReply(CommandMessage* reply, sid_t sid, store_address_t storeId); + static void setHkStuctureReportReply(CommandMessage* reply, dp::sid_t sid, + store_address_t storeId); - static sid_t getHkRequestFailureReply(const CommandMessage* reply, ReturnValue_t* error); + static dp::sid_t getHkRequestFailureReply(const CommandMessage* reply, ReturnValue_t* error); /** * @brief Generic getter function for housekeeping data replies @@ -81,33 +83,35 @@ class HousekeepingMessage { * regular HK packets. This getter function should be used for the * command IDs 10, 12, 25 and 26. */ - static sid_t getHkDataReply(const CommandMessage* message, store_address_t* storeIdToSet); - static sid_t getCollectionIntervalModificationCommand(const CommandMessage* command, - dur_millis_t& newCollectionInterval); + static dp::sid_t getHkDataReply(const CommandMessage* message, store_address_t* storeIdToSet); + static dp::sid_t getCollectionIntervalModificationCommand(const CommandMessage* command, + dur_millis_t& newCollectionInterval); /* Update Notification Messages */ - static void setUpdateNotificationSetCommand(CommandMessage* command, sid_t sid); - static void setUpdateNotificationVariableCommand(CommandMessage* command, gp_id_t globalPoolId); + static void setUpdateNotificationSetCommand(CommandMessage* command, dp::sid_t sid); + static void setUpdateNotificationVariableCommand(CommandMessage* command, + dp::g_id_t globalPoolId); - static void setUpdateSnapshotSetCommand(CommandMessage* command, sid_t sid, + static void setUpdateSnapshotSetCommand(CommandMessage* command, dp::sid_t sid, store_address_t storeId); - static void setUpdateSnapshotVariableCommand(CommandMessage* command, gp_id_t globalPoolId, + static void setUpdateSnapshotVariableCommand(CommandMessage* command, dp::g_id_t globalPoolId, store_address_t storeId); - static sid_t getUpdateNotificationSetCommand(const CommandMessage* command); - static gp_id_t getUpdateNotificationVariableCommand(const CommandMessage* command); + static dp::sid_t getUpdateNotificationSetCommand(const CommandMessage* command); + static dp::g_id_t getUpdateNotificationVariableCommand(const CommandMessage* command); - static sid_t getUpdateSnapshotSetCommand(const CommandMessage* command, store_address_t* storeId); - static gp_id_t getUpdateSnapshotVariableCommand(const CommandMessage* command, - store_address_t* storeId); + static dp::sid_t getUpdateSnapshotSetCommand(const CommandMessage* command, + store_address_t* storeId); + static dp::g_id_t getUpdateSnapshotVariableCommand(const CommandMessage* command, + store_address_t* storeId); /** Utility */ static void clear(CommandMessage* message); private: - static void setSid(CommandMessage* message, sid_t sid); - static void setGpid(CommandMessage* message, gp_id_t globalPoolId); + static void setSid(CommandMessage* message, dp::sid_t sid); + static void setGpid(CommandMessage* message, dp::g_id_t globalPoolId); }; #endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGMESSAGE_H_ */ diff --git a/src/fsfw/housekeeping/HousekeepingPacketDownlink.h b/src/fsfw/housekeeping/HousekeepingPacketDownlink.h index 011c34b1..4ca9fd09 100644 --- a/src/fsfw/housekeeping/HousekeepingPacketDownlink.h +++ b/src/fsfw/housekeeping/HousekeepingPacketDownlink.h @@ -2,9 +2,8 @@ #include -#include "../datapoollocal/SharedDatasetBase.h" -#include "../serialize/SerialLinkedListAdapter.h" -#include "../storagemanager/StorageManagerIF.h" +#include "fsfw/datapool/SharedSetBase.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" /** * @brief This class will be used to serialize general housekeeping packets @@ -19,7 +18,7 @@ */ class HousekeepingPacketDownlink : public SerialLinkedListAdapter { public: - HousekeepingPacketDownlink(sid_t sid, const uint8_t* hkData, size_t hkDataLen) + HousekeepingPacketDownlink(dp::sid_t sid, const uint8_t* hkData, size_t hkDataLen) : sourceId(sid.objectId), setId(sid.ownerSetId), hkData(hkData, hkDataLen) { setLinks(); } diff --git a/src/fsfw/housekeeping/HousekeepingSetPacket.h b/src/fsfw/housekeeping/HousekeepingSetPacket.h index 54c599df..97f02b56 100644 --- a/src/fsfw/housekeeping/HousekeepingSetPacket.h +++ b/src/fsfw/housekeeping/HousekeepingSetPacket.h @@ -4,7 +4,7 @@ class HousekeepingSetPacket : public SerialLinkedListAdapter { public: - HousekeepingSetPacket(sid_t sid, bool reportingEnabled, dur_millis_t collectionIntervalMs) + HousekeepingSetPacket(dp::sid_t sid, bool reportingEnabled, dur_millis_t collectionIntervalMs) : objectId(sid.objectId), setId(sid.ownerSetId), reportingEnabled(reportingEnabled), diff --git a/src/fsfw/housekeeping/HousekeepingSnapshot.h b/src/fsfw/housekeeping/HousekeepingSnapshot.h index 2c1c635d..dd2fbf71 100644 --- a/src/fsfw/housekeeping/HousekeepingSnapshot.h +++ b/src/fsfw/housekeeping/HousekeepingSnapshot.h @@ -1,11 +1,10 @@ -#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGSNAPSHOT_H_ -#define FSFW_HOUSEKEEPING_HOUSEKEEPINGSNAPSHOT_H_ +#pragma once -#include "../datapoollocal/LocalPoolObjectBase.h" -#include "../serialize/SerialBufferAdapter.h" -#include "../serialize/SerialLinkedListAdapter.h" -#include "../timemanager/CCSDSTime.h" -#include "fsfw/datapoollocal/SharedDatasetBase.h" +#include "fsfw/datapool/LocalPoolObjectBase.h" +#include "fsfw/datapool/SharedSetBase.h" +#include "fsfw/serialize/SerialBufferAdapter.h" +#include "fsfw/serialize/SerialLinkedListAdapter.h" +#include "fsfw/timemanager/CCSDSTime.h" /** * @brief This helper class will be used to serialize and deserialize update housekeeping packets @@ -86,6 +85,4 @@ class HousekeepingSnapshot : public SerializeIF { size_t timeStampSize = 0; SerializeIF* updateData = nullptr; -}; - -#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGSNAPSHOT_H_ */ +}; \ No newline at end of file diff --git a/src/fsfw/datapoollocal/PeriodicHkGenerationHelper.cpp b/src/fsfw/housekeeping/PeriodicHkHelper.cpp similarity index 81% rename from src/fsfw/datapoollocal/PeriodicHkGenerationHelper.cpp rename to src/fsfw/housekeeping/PeriodicHkHelper.cpp index 3eb7b96f..abb1a502 100644 --- a/src/fsfw/datapoollocal/PeriodicHkGenerationHelper.cpp +++ b/src/fsfw/housekeeping/PeriodicHkHelper.cpp @@ -1,23 +1,19 @@ -#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h" +#include "PeriodicHkHelper.h" #include #include -#include "fsfw/datapoollocal.h" #include "fsfw/housekeeping/AcceptsHkPacketsIF.h" #include "fsfw/housekeeping/HousekeepingSetPacket.h" #include "fsfw/housekeeping/HousekeepingSnapshot.h" -#include "fsfw/ipc/MutexFactory.h" -#include "fsfw/ipc/MutexGuard.h" #include "fsfw/ipc/QueueFactory.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/timemanager/CCSDSTime.h" -#include "internal/HasLocalDpIFManagerAttorney.h" -#include "internal/LocalPoolDataSetAttorney.h" -PeriodicHkGenerationHelper::PeriodicHkGenerationHelper(PeriodicHkGenerationIF* owner, - MessageQueueIF* queueToUse, - MessageQueueId_t hkDestQueue) +using namespace hk; + +PeriodicHelper::PeriodicHelper(GeneratesPeriodicHkIF* owner, MessageQueueIF* queueToUse, + MessageQueueId_t hkDestQueue) : hkDestinationId(hkDestQueue) { if (owner == nullptr) { printWarningOrError(sif::OutputTypes::OUT_WARNING, "LocalDataPoolManager", returnvalue::FAILED, @@ -28,7 +24,7 @@ PeriodicHkGenerationHelper::PeriodicHkGenerationHelper(PeriodicHkGenerationIF* o hkQueue = queueToUse; } -ReturnValue_t PeriodicHkGenerationHelper::initialize(MessageQueueIF* queueToUse) { +ReturnValue_t PeriodicHelper::initialize(MessageQueueIF* queueToUse) { if (queueToUse != nullptr) { hkQueue = queueToUse; } @@ -61,13 +57,13 @@ ReturnValue_t PeriodicHkGenerationHelper::initialize(MessageQueueIF* queueToUse) return returnvalue::OK; } -ReturnValue_t PeriodicHkGenerationHelper::performHkOperation() { +ReturnValue_t PeriodicHelper::performHkOperation() { timeval now{}; Clock::getClockMonotonic(&now); for (auto& setSpec : setList) { switch (setSpec.reportingType) { - case (periodicHk::ReportingType::PERIODIC): { - if (setSpec.dataType == periodicHk::DataType::LOCAL_POOL_VARIABLE) { + case (ReportingType::PERIODIC): { + if (setSpec.dataType == DataType::LOCAL_POOL_VARIABLE) { // Periodic packets shall only be generated from datasets continue; } @@ -82,9 +78,9 @@ ReturnValue_t PeriodicHkGenerationHelper::performHkOperation() { return returnvalue::OK; } -ReturnValue_t PeriodicHkGenerationHelper::handleHousekeepingMessage(CommandMessage* message) { +ReturnValue_t PeriodicHelper::handleHousekeepingMessage(CommandMessage* message) { Command_t command = message->getCommand(); - sid_t sid = HousekeepingMessage::getSid(message); + dp::sid_t sid = HousekeepingMessage::getSid(message); ReturnValue_t result = returnvalue::OK; switch (command) { // Houskeeping interface handling. @@ -134,10 +130,10 @@ ReturnValue_t PeriodicHkGenerationHelper::handleHousekeepingMessage(CommandMessa return result; } -PeriodicHkGenerationIF* PeriodicHkGenerationHelper::getOwner() const { return owner; } +PeriodicHkGenerationIF* PeriodicHelper::getOwner() const { return owner; } -ReturnValue_t PeriodicHkGenerationHelper::generateHousekeepingPacket(const sid_t sid, - MessageQueueId_t destination) { +ReturnValue_t PeriodicHelper::generateHousekeepingPacket(const dp::sid_t sid, + MessageQueueId_t destination) { store_address_t storeId; auto optSetSpec = getSetSpecification(sid); if (!optSetSpec.has_value()) { @@ -185,8 +181,7 @@ ReturnValue_t PeriodicHkGenerationHelper::generateHousekeepingPacket(const sid_t return hkQueue->sendMessage(destination, &hkMessage); } -void PeriodicHkGenerationHelper::performPeriodicHkGeneration(periodicHk::SetSpecification& setSpec, - timeval& now) { +void PeriodicHelper::performPeriodicHkGeneration(SetSpecification& setSpec, timeval& now) { if (not setSpec.periodicCollectionEnabled) { return; } @@ -215,7 +210,7 @@ void PeriodicHkGenerationHelper::performPeriodicHkGeneration(periodicHk::SetSpec } } -ReturnValue_t PeriodicHkGenerationHelper::togglePeriodicGeneration(sid_t sid, bool enable) { +ReturnValue_t PeriodicHelper::togglePeriodicGeneration(dp::sid_t sid, bool enable) { auto optSetSpec = getSetSpecification(sid); if (!optSetSpec.has_value()) { printWarningOrError(sif::OutputTypes::OUT_WARNING, "togglePeriodicGeneration", @@ -226,8 +221,8 @@ ReturnValue_t PeriodicHkGenerationHelper::togglePeriodicGeneration(sid_t sid, bo return returnvalue::OK; } -std::optional> -PeriodicHkGenerationHelper::getSetSpecification(sid_t structureId) { +std::optional> PeriodicHelper::getSetSpecification( + sid_t structureId) { for (auto& receiver : setList) { if (receiver.dataId.sid == structureId) { return receiver; @@ -236,8 +231,8 @@ PeriodicHkGenerationHelper::getSetSpecification(sid_t structureId) { return std::nullopt; } -ReturnValue_t PeriodicHkGenerationHelper::setCollectionInterval( - sid_t sid, dur_millis_t newCollectionIntervalMs) { +ReturnValue_t PeriodicHelper::setCollectionInterval(sid_t sid, + dur_millis_t newCollectionIntervalMs) { bool wasUpdated = false; for (auto& receiver : setList) { if (receiver.dataId.sid == sid) { @@ -252,7 +247,7 @@ ReturnValue_t PeriodicHkGenerationHelper::setCollectionInterval( return returnvalue::OK; } -ReturnValue_t PeriodicHkGenerationHelper::generateSetStructurePacket(sid_t sid) { +ReturnValue_t PeriodicHelper::generateSetStructurePacket(sid_t sid) { // Get and check dataset first. auto optSetSpec = getSetSpecification(sid); if (!optSetSpec.has_value()) { @@ -302,8 +297,8 @@ ReturnValue_t PeriodicHkGenerationHelper::generateSetStructurePacket(sid_t sid) return result; } -ReturnValue_t PeriodicHkGenerationHelper::enablePeriodicPacket( - const sid_t structureId, const std::optional frequencyMs) { +ReturnValue_t PeriodicHelper::enablePeriodicPacket(const sid_t structureId, + const std::optional frequencyMs) { // Get and check dataset first. const auto optSetSpec = getSetSpecification(structureId); if (!optSetSpec.has_value()) { @@ -319,7 +314,7 @@ ReturnValue_t PeriodicHkGenerationHelper::enablePeriodicPacket( return returnvalue::OK; } -ReturnValue_t PeriodicHkGenerationHelper::disablePeriodicPacket(const sid_t structureId) { +ReturnValue_t PeriodicHelper::disablePeriodicPacket(const sid_t structureId) { // Get and check dataset first. const auto optSetSpec = getSetSpecification(structureId); if (!optSetSpec.has_value()) { @@ -332,11 +327,10 @@ ReturnValue_t PeriodicHkGenerationHelper::disablePeriodicPacket(const sid_t stru return returnvalue::OK; } -object_id_t PeriodicHkGenerationHelper::getCreatorObjectId() const { return owner->getObjectId(); } +object_id_t PeriodicHelper::getCreatorObjectId() const { return owner->getObjectId(); } -void PeriodicHkGenerationHelper::printWarningOrError(sif::OutputTypes outputType, - const char* functionName, ReturnValue_t error, - const char* errorPrint) { +void PeriodicHelper::printWarningOrError(sif::OutputTypes outputType, const char* functionName, + ReturnValue_t error, const char* errorPrint) { #if FSFW_VERBOSE_LEVEL >= 1 if (errorPrint == nullptr) { if (error == DATASET_NOT_FOUND) { @@ -388,10 +382,10 @@ void PeriodicHkGenerationHelper::printWarningOrError(sif::OutputTypes outputType #endif /* #if FSFW_VERBOSE_LEVEL >= 1 */ } -void PeriodicHkGenerationHelper::setHkDestinationId(const MessageQueueId_t hkDestId) { +void PeriodicHelper::setHkDestinationId(const MessageQueueId_t hkDestId) { hkDestinationId = hkDestId; } -void PeriodicHkGenerationHelper::addSetSpecification(const periodicHk::SetSpecification& setSpec) { +void PeriodicHelper::addSetSpecification(const SetSpecification& setSpec) { setList.push_back(setSpec); } diff --git a/src/fsfw/datapoollocal/PeriodicHkGenerationHelper.h b/src/fsfw/housekeeping/PeriodicHkHelper.h similarity index 62% rename from src/fsfw/datapoollocal/PeriodicHkGenerationHelper.h rename to src/fsfw/housekeeping/PeriodicHkHelper.h index a041b7c6..26a6b7a9 100644 --- a/src/fsfw/datapoollocal/PeriodicHkGenerationHelper.h +++ b/src/fsfw/housekeeping/PeriodicHkHelper.h @@ -1,86 +1,23 @@ -#ifndef FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ -#define FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ +#pragma once #include #include #include -#include "AccessLocalPoolF.h" -#include "ProvidesDataPoolSubscriptionIF.h" +#include "GeneratesPeriodicHkIF.h" +#include "PeriodicHkHelperIF.h" +#include "definitions.h" #include "fsfw/datapool/DataSetIF.h" -#include "fsfw/datapool/PoolEntry.h" -#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" +#include "fsfw/datapool/definitions.h" #include "fsfw/housekeeping/HousekeepingMessage.h" #include "fsfw/housekeeping/HousekeepingPacketDownlink.h" #include "fsfw/ipc/CommandMessage.h" #include "fsfw/ipc/MessageQueueIF.h" -#include "fsfw/ipc/MutexGuard.h" #include "fsfw/ipc/MutexIF.h" #include "fsfw/objectmanager/SystemObjectIF.h" #include "fsfw/serviceinterface/ServiceInterface.h" -namespace periodicHk { -/** - * Different types of housekeeping reporting are possible. - * 1. PERIODIC: - * HK packets are generated in fixed intervals and sent to - * destination. Fromat will be raw. - * 2. UPDATE_NOTIFICATION: - * Notification will be sent out if HK data has changed. - * 3. UPDATE_SNAPSHOT: - * HK packets are only generated if explicitely requested. - * Propably not necessary, just use multiple local data sets or - * shared datasets. - */ -enum class ReportingType : uint8_t { - //! Periodic generation of HK packets. - PERIODIC, -}; - -union DataId { - DataId() : sid() {} - static DataId forSetId(sid_t sid) { - DataId d; - d.sid = sid; - return d; - } - sid_t sid; - lp_id_t localPoolId; -}; - -/** Different data types are possible in the HK receiver map. For example, updates can be -requested for full datasets or for single pool variables. Periodic reporting is only possible -for data sets. */ -enum class DataType : uint8_t { LOCAL_POOL_VARIABLE, DATA_SET }; - -/** The data pool manager will keep an internal map of HK receivers. */ -struct SetSpecification { - friend class ::PeriodicHkGenerationHelper; - - public: - SetSpecification(sid_t structureId, size_t size, dur_millis_t collectionFrequency, - MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE) - : dataId(DataId::forSetId(structureId)), - collectionFrequency(collectionFrequency), - size(size), - destinationQueue(destinationQueue) {}; - // Object ID of receiver - object_id_t objectId = objects::NO_OBJECT; - - DataType dataType = DataType::DATA_SET; - DataId dataId; - - dur_millis_t collectionFrequency = 0; - size_t size = 0; - ReportingType reportingType = ReportingType::PERIODIC; - - private: - MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE; - bool periodicCollectionEnabled = false; - timeval lastGenerated{}; -}; - -} // namespace periodicHk +namespace hk { /** * @brief This class is the managing instance for the local data pool. @@ -106,10 +43,10 @@ struct SetSpecification { * Each pool entry has a valid state too. * @author R. Mueller */ -class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF { +class PeriodicHelper : public PeriodicHelperIF { //! Some classes using the pool manager directly need to access class internals of the //! manager. The attorney provides granular control of access to these internals. - friend class LocalDpManagerAttorney; + friend class SharedPoolAttorney; public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER; @@ -131,8 +68,8 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF { * @param queueToUse * validity state is generated when serializing or deserializing packets. */ - PeriodicHkGenerationHelper(PeriodicHkGenerationIF* owner, MessageQueueIF* queueToUse, - MessageQueueId_t hkDestQueue = MessageQueueIF::NO_QUEUE); + PeriodicHelper(GeneratesPeriodicHkIF* owner, MessageQueueIF* queueToUse, + MessageQueueId_t hkDestQueue = MessageQueueIF::NO_QUEUE); void setHkDestinationId(MessageQueueId_t hkDestId); @@ -173,17 +110,17 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF { * @param sid * @return */ - ReturnValue_t generateHousekeepingPacket(sid_t sid, + ReturnValue_t generateHousekeepingPacket(dp::sid_t sid, MessageQueueId_t destination = MessageQueueIF::NO_QUEUE); [[nodiscard]] PeriodicHkGenerationIF* getOwner() const; - void addSetSpecification(const periodicHk::SetSpecification& setSpec); - ReturnValue_t printPoolEntry(lp_id_t localPoolId); + void addSetSpecification(const SetSpecification& setSpec); + ReturnValue_t printPoolEntry(dp::lp_id_t localPoolId); /* Copying forbidden */ - PeriodicHkGenerationHelper(const PeriodicHkGenerationHelper&) = delete; - PeriodicHkGenerationHelper operator=(const PeriodicHkGenerationHelper&) = delete; + PeriodicHelper(const PeriodicHkGenerationHelper&) = delete; + PeriodicHelper operator=(const PeriodicHkGenerationHelper&) = delete; /** * This function can be used to clear the receivers list. This is @@ -206,32 +143,29 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF { /** * Set the periodic generation frequency without enabling the periodic generation of packets. */ - ReturnValue_t enablePeriodicPacket(sid_t structureId, + ReturnValue_t enablePeriodicPacket(dp::sid_t structureId, std::optional frequencyMs) override; - ReturnValue_t disablePeriodicPacket(sid_t structureId) override; + ReturnValue_t disablePeriodicPacket(dp::sid_t structureId) override; - ReturnValue_t setCollectionInterval(sid_t structureId, + ReturnValue_t setCollectionInterval(dp::sid_t structureId, dur_millis_t newCollectionIntervalMs) override; protected: - std::optional> getSetSpecification( - sid_t structureId); + std::optional> getSetSpecification( + dp::sid_t structureId); - ReturnValue_t subscribeForPeriodicPacket(subdp::ParamsBase& params); - ReturnValue_t subscribeForUpdatePacket(subdp::ParamsBase& params); - - std::optional getCollectionFrequency(sid_t structureId); + std::optional getCollectionFrequency(dp::sid_t structureId); /** The class which actually owns the manager (and its datapool). */ - PeriodicHkGenerationIF* owner = nullptr; + hk::GeneratesPeriodicHkIF* owner = nullptr; /** Default receiver for periodic HK packets */ MessageQueueId_t hkDestinationId = MessageQueueIF::NO_QUEUE; /** This vector will contain the list of HK receivers. */ - using SetList = std::vector; + using SetList = std::vector; - SetList setList; + SetList setList{}; /** * @brief Queue used for communication, for example commands. @@ -246,9 +180,9 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF { ReturnValue_t serializeHkPacketIntoStore(HousekeepingPacketDownlink& hkPacket, store_address_t& storeId, size_t* serializedSize); - void performPeriodicHkGeneration(periodicHk::SetSpecification& hkReceiver, timeval& now); - ReturnValue_t togglePeriodicGeneration(sid_t sid, bool enable); - ReturnValue_t generateSetStructurePacket(sid_t sid); + void performPeriodicHkGeneration(SetSpecification& hkReceiver, timeval& now); + ReturnValue_t togglePeriodicGeneration(dp::sid_t sid, bool enable); + ReturnValue_t generateSetStructurePacket(dp::sid_t sid); // void handleChangeResetLogic(periodicHk::DataType type, periodicHk::DataId dataId, // MarkChangedIF* toReset); @@ -261,4 +195,4 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF { const char* errorPrint = nullptr); }; -#endif /* FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ */ +} // namespace hk \ No newline at end of file diff --git a/src/fsfw/housekeeping/PeriodicHkHelperIF.h b/src/fsfw/housekeeping/PeriodicHkHelperIF.h new file mode 100644 index 00000000..8dd3af11 --- /dev/null +++ b/src/fsfw/housekeeping/PeriodicHkHelperIF.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "fsfw/datapool/definitions.h" +#include "fsfw/retval.h" + +namespace hk { +class PeriodicHelperIF { + public: + virtual ~PeriodicHelperIF() = default; + + /** + * Set the periodic generation frequency without enabling the periodic generation of packets. + */ + virtual ReturnValue_t setCollectionInterval(dp::sid_t structureId, + dur_millis_t newCollectionIntervalMs) = 0; + virtual ReturnValue_t enablePeriodicPacket(dp::sid_t structureId, + std::optional frequencyMs) = 0; + virtual ReturnValue_t disablePeriodicPacket(dp::sid_t structureId) = 0; +}; + +} // namespace hk \ No newline at end of file diff --git a/src/fsfw/housekeeping/definitions.h b/src/fsfw/housekeeping/definitions.h new file mode 100644 index 00000000..a4de3ba7 --- /dev/null +++ b/src/fsfw/housekeeping/definitions.h @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include +#include + +#include + +#include "fsfw/datapool/definitions.h" + +namespace hk { + +/** + * Different types of housekeeping reporting are possible. + * 1. PERIODIC: + * HK packets are generated in fixed intervals and sent to + * destination. Fromat will be raw. + * 2. UPDATE_NOTIFICATION: + * Notification will be sent out if HK data has changed. + * 3. UPDATE_SNAPSHOT: + * HK packets are only generated if explicitely requested. + * Propably not necessary, just use multiple local data sets or + * shared datasets. + */ +enum class ReportingType : uint8_t { + //! Periodic generation of HK packets. + PERIODIC, +}; + +union DataId { + DataId() : sid() {} + static DataId forSetId(dp::structure_id_t sid) { + DataId d; + d.sid = sid; + return d; + } + dp::sid_t sid; + dp::lp_id_t localPoolId; +}; + +/** Different data types are possible in the HK receiver map. For example, updates can be +requested for full datasets or for single pool variables. Periodic reporting is only possible +for data sets. */ +enum class DataType : uint8_t { LOCAL_POOL_VARIABLE, DATA_SET }; + +/** The data pool manager will keep an internal map of HK receivers. */ +struct SetSpecification { + public: + SetSpecification(dp::sid_t structureId, size_t size, dur_millis_t collectionFrequency, + MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE) + : dataId(DataId::forSetId(structureId)), + collectionFrequency(collectionFrequency), + size(size), + destinationQueue(destinationQueue) {}; + // Object ID of receiver + object_id_t objectId = objects::NO_OBJECT; + + DataType dataType = DataType::DATA_SET; + DataId dataId; + + dur_millis_t collectionFrequency = 0; + size_t size = 0; + ReportingType reportingType = ReportingType::PERIODIC; + + private: + MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE; + bool periodicCollectionEnabled = false; + timeval lastGenerated{}; +}; + +} // namespace hk diff --git a/src/fsfw/internalerror/InternalErrorDataset.h b/src/fsfw/internalerror/InternalErrorDataset.h index 73f03a07..41347917 100644 --- a/src/fsfw/internalerror/InternalErrorDataset.h +++ b/src/fsfw/internalerror/InternalErrorDataset.h @@ -1,24 +1,24 @@ #ifndef FSFW_INTERNALERROR_INTERNALERRORDATASET_H_ #define FSFW_INTERNALERROR_INTERNALERRORDATASET_H_ -#include -#include +#include +#include enum errorPoolIds { TM_HITS = 0, QUEUE_HITS = 1, STORE_HITS = 2, VALID = 3 }; -class InternalErrorDataset : public StaticSharedDataset<4> { +class InternalErrorDataset : public dp::StaticSharedSet<4> { public: static constexpr uint8_t ERROR_SET_ID = 0; - InternalErrorDataset(localpool::SharedPool& sharedPool) - : StaticSharedDataset(sharedPool, ERROR_SET_ID) {} + InternalErrorDataset(dp::SharedPool& sharedPool) : StaticSharedSet(sharedPool, ERROR_SET_ID) {} - InternalErrorDataset(object_id_t objectId) : StaticSharedDataset(sid_t(objectId, ERROR_SET_ID)) {} + InternalErrorDataset(object_id_t objectId) + : StaticSharedSet(dp::structure_id_t(objectId, ERROR_SET_ID)) {} - lp_var_t tmHits = lp_var_t(sid.objectId, TM_HITS, this); - lp_var_t queueHits = lp_var_t(sid.objectId, QUEUE_HITS, this); - lp_var_t storeHits = lp_var_t(sid.objectId, STORE_HITS, this); - lp_var_t valid = lp_var_t(sid.objectId, VALID, this); + dp::var_t tmHits = dp::var_t(sid.objectId, TM_HITS, this); + dp::var_t queueHits = dp::var_t(sid.objectId, QUEUE_HITS, this); + dp::var_t storeHits = dp::var_t(sid.objectId, STORE_HITS, this); + dp::var_t valid = dp::var_t(sid.objectId, VALID, this); }; #endif /* FSFW_INTERNALERROR_INTERNALERRORDATASET_H_ */ diff --git a/src/fsfw/internalerror/InternalErrorReporter.cpp b/src/fsfw/internalerror/InternalErrorReporter.cpp index 01d76d18..98916148 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.cpp +++ b/src/fsfw/internalerror/InternalErrorReporter.cpp @@ -152,8 +152,8 @@ void InternalErrorReporter::setMutexTimeout(MutexIF::TimeoutType timeoutType, ui this->timeoutMs = timeoutMs; } -ReturnValue_t InternalErrorReporter::serializeHkDataset(sid_t structureId, uint8_t *buf, - size_t maxSize) { +ReturnValue_t InternalErrorReporter::serializeHkDataset(dp::structure_id_t structureId, + uint8_t *buf, size_t maxSize) { if (structureId == internalErrorDataset.getSid()) { size_t serSize = 0; return internalErrorDataset.serialize(buf, serSize, maxSize, SerializeIF::Endianness::NETWORK); @@ -162,10 +162,10 @@ ReturnValue_t InternalErrorReporter::serializeHkDataset(sid_t structureId, uint8 } ReturnValue_t InternalErrorReporter::specifyHkDatasets( - std::vector &setSpecification) { + std::vector &setSpecification) { setSpecification.emplace_back(internalErrorDataset.getSid(), internalErrorDataset.getSerializedSize(), generationFrequency); return returnvalue::OK; } -localpool::SharedPool *InternalErrorReporter::getOptionalSharedPool() { return &sharedPool; } +dp::SharedPool *InternalErrorReporter::getOptionalSharedPool() { return &sharedPool; } diff --git a/src/fsfw/internalerror/InternalErrorReporter.h b/src/fsfw/internalerror/InternalErrorReporter.h index 976bfda7..c7704a15 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.h +++ b/src/fsfw/internalerror/InternalErrorReporter.h @@ -1,8 +1,10 @@ #ifndef FSFW_INTERNALERROR_INTERNALERRORREPORTER_H_ #define FSFW_INTERNALERROR_INTERNALERRORREPORTER_H_ +#include + #include "InternalErrorReporterIF.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h" +#include "fsfw/housekeeping/GeneratesPeriodicHkIF.h" #include "fsfw/internalerror/InternalErrorDataset.h" #include "fsfw/ipc/MutexIF.h" #include "fsfw/objectmanager/SystemObject.h" @@ -19,7 +21,7 @@ class InternalErrorReporter : public SystemObject, public ExecutableObjectIF, public InternalErrorReporterIF, - public PeriodicHkGenerationIF { + public hk::GeneratesPeriodicHkIF { public: InternalErrorReporter(object_id_t setObjectId, uint32_t messageQueueDepth, bool enableSetByDefault, dur_millis_t generationFrequency); @@ -38,12 +40,11 @@ class InternalErrorReporter : public SystemObject, [[nodiscard]] object_id_t getObjectId() const override; [[nodiscard]] MessageQueueId_t getCommandQueue() const override; - localpool::SharedPool* getOptionalSharedPool() override; + dp::SharedPool* getOptionalSharedPool() override; - ReturnValue_t serializeHkDataset(sid_t structureId, uint8_t* buf, size_t maxSize) override; + ReturnValue_t serializeHkDataset(dp::sid_t structureId, uint8_t* buf, size_t maxSize) override; - ReturnValue_t specifyHkDatasets( - std::vector& setSpecification) override; + ReturnValue_t specifyHkDatasets(std::vector& setSpecification) override; ReturnValue_t initialize() override; ReturnValue_t performOperation(uint8_t opCode) override; @@ -58,8 +59,8 @@ class InternalErrorReporter : public SystemObject, protected: MessageQueueIF* commandQueue; - localpool::SharedPool sharedPool; - PeriodicHkGenerationHelper hkHelper; + dp::SharedPool sharedPool; + hk::PeriodicHelper hkHelper; PeriodicTaskIF* executingTask = nullptr; @@ -69,7 +70,7 @@ class InternalErrorReporter : public SystemObject, bool enableSetByDefault; dur_millis_t generationFrequency; - sid_t internalErrorSid; + dp::structure_id_t internalErrorSid; InternalErrorDataset internalErrorDataset; bool diagnosticPrintout = true; diff --git a/src/fsfw/monitoring/AbsLimitMonitor.h b/src/fsfw/monitoring/AbsLimitMonitor.h index 159a3d2a..b302f5a1 100644 --- a/src/fsfw/monitoring/AbsLimitMonitor.h +++ b/src/fsfw/monitoring/AbsLimitMonitor.h @@ -9,7 +9,7 @@ template class AbsLimitMonitor : public MonitorBase { public: - AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId, gp_id_t globalPoolId, + AbsLimitMonitor(object_id_t reporterId, uint8_t monitorId, dp::g_id_t globalPoolId, uint16_t confirmationLimit, T limit, Event violationEvent = MonitoringIF::VALUE_OUT_OF_RANGE, bool aboveIsViolation = true) diff --git a/src/fsfw/monitoring/LimitMonitor.h b/src/fsfw/monitoring/LimitMonitor.h index 4fe9ee39..325c2a78 100644 --- a/src/fsfw/monitoring/LimitMonitor.h +++ b/src/fsfw/monitoring/LimitMonitor.h @@ -13,7 +13,7 @@ template class LimitMonitor : public MonitorBase { public: - LimitMonitor(object_id_t reporterId, uint8_t monitorId, gp_id_t globalPoolId, + LimitMonitor(object_id_t reporterId, uint8_t monitorId, dp::g_id_t globalPoolId, uint16_t confirmationLimit, T lowerLimit, T upperLimit, Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT, Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) diff --git a/src/fsfw/monitoring/MonitorBase.h b/src/fsfw/monitoring/MonitorBase.h index ce657cdd..b6404656 100644 --- a/src/fsfw/monitoring/MonitorBase.h +++ b/src/fsfw/monitoring/MonitorBase.h @@ -1,11 +1,11 @@ #ifndef FSFW_MONITORING_MONITORBASE_H_ #define FSFW_MONITORING_MONITORBASE_H_ -#include "../datapoollocal/LocalPoolVariable.h" #include "LimitViolationReporter.h" #include "MonitorReporter.h" #include "MonitoringIF.h" #include "MonitoringMessageContent.h" +#include "fsfw/datapool/PoolVariable.h" #include "monitoringConf.h" /** @@ -22,7 +22,7 @@ template class MonitorBase : public MonitorReporter { public: - MonitorBase(object_id_t reporterId, uint8_t monitorId, gp_id_t globalPoolId, + MonitorBase(object_id_t reporterId, uint8_t monitorId, dp::g_id_t globalPoolId, uint16_t confirmationLimit) : MonitorReporter(reporterId, monitorId, globalPoolId, confirmationLimit), poolVariable(globalPoolId) {} @@ -63,7 +63,7 @@ class MonitorBase : public MonitorReporter { return returnvalue::OK; } - LocalPoolVariable poolVariable; + dp::PoolVariable poolVariable; }; #endif /* FSFW_MONITORING_MONITORBASE_H_ */ diff --git a/src/fsfw/monitoring/MonitorReporter.h b/src/fsfw/monitoring/MonitorReporter.h index 09c39222..127e8f64 100644 --- a/src/fsfw/monitoring/MonitorReporter.h +++ b/src/fsfw/monitoring/MonitorReporter.h @@ -1,12 +1,11 @@ -#ifndef FSFW_MONITORING_MONITORREPORTER_H_ -#define FSFW_MONITORING_MONITORREPORTER_H_ +#pragma once -#include "../datapoollocal/localPoolDefinitions.h" #include "../events/EventManagerIF.h" #include "../parameters/HasParametersIF.h" #include "LimitViolationReporter.h" #include "MonitoringIF.h" #include "MonitoringMessageContent.h" +#include "fsfw/datapool/definitions.h" #include "monitoringConf.h" template @@ -17,7 +16,7 @@ class MonitorReporter : public HasParametersIF { // TODO: Adapt to use SID instead of parameter ID. - MonitorReporter(object_id_t reportingId, uint8_t monitorId, gp_id_t globalPoolId, + MonitorReporter(object_id_t reportingId, uint8_t monitorId, dp::g_id_t globalPoolId, uint16_t confirmationLimit) : monitorId(monitorId), globalPoolId(globalPoolId), @@ -84,7 +83,7 @@ class MonitorReporter : public HasParametersIF { protected: const uint8_t monitorId; - const gp_id_t globalPoolId; + const dp::g_id_t globalPoolId; object_id_t reportingId; ReturnValue_t oldState; @@ -161,6 +160,4 @@ class MonitorReporter : public HasParametersIF { } return returnvalue::OK; } -}; - -#endif /* FSFW_MONITORING_MONITORREPORTER_H_ */ +}; \ No newline at end of file diff --git a/src/fsfw/monitoring/MonitoringMessageContent.h b/src/fsfw/monitoring/MonitoringMessageContent.h index 7a7b5440..ab02a630 100644 --- a/src/fsfw/monitoring/MonitoringMessageContent.h +++ b/src/fsfw/monitoring/MonitoringMessageContent.h @@ -1,7 +1,5 @@ -#ifndef FSFW_MONITORING_MONITORINGMESSAGECONTENT_H_ -#define FSFW_MONITORING_MONITORINGMESSAGECONTENT_H_ +#pragma once -#include "../datapoollocal/localPoolDefinitions.h" #include "../objectmanager/ObjectManager.h" #include "../serialize/SerialBufferAdapter.h" #include "../serialize/SerialFixedArrayListAdapter.h" @@ -11,6 +9,7 @@ #include "../timemanager/TimeWriterIF.h" #include "HasMonitorsIF.h" #include "MonitoringIF.h" +#include "fsfw/datapool/definitions.h" #include "monitoringConf.h" namespace Factory { @@ -29,7 +28,7 @@ class MonitoringReportContent : public SerialLinkedListAdapter { public: SerializeElement monitorId; SerializeElement parameterObjectId; - SerializeElement localPoolId; + SerializeElement localPoolId; SerializeElement parameterValue; SerializeElement limitValue; SerializeElement oldState; @@ -50,7 +49,7 @@ class MonitoringReportContent : public SerialLinkedListAdapter { timeStamper(nullptr) { setAllNext(); } - MonitoringReportContent(gp_id_t globalPoolId, T value, T limitValue, ReturnValue_t oldState, + MonitoringReportContent(dp::g_id_t globalPoolId, T value, T limitValue, ReturnValue_t oldState, ReturnValue_t newState) : SerialLinkedListAdapter(¶meterObjectId), monitorId(0), @@ -94,5 +93,3 @@ class MonitoringReportContent : public SerialLinkedListAdapter { }; template object_id_t MonitoringReportContent::timeStamperId = 0; - -#endif /* FSFW_MONITORING_MONITORINGMESSAGECONTENT_H_ */ diff --git a/src/fsfw/power/Fuse.cpp b/src/fsfw/power/Fuse.cpp index 68010a21..898bb233 100644 --- a/src/fsfw/power/Fuse.cpp +++ b/src/fsfw/power/Fuse.cpp @@ -8,8 +8,9 @@ object_id_t Fuse::powerSwitchId = 0; -Fuse::Fuse(object_id_t ownerId, object_id_t fuseObjectId, uint8_t fuseId, sid_t variableSet, - VariableIds ids, float maxCurrent, uint16_t confirmationCount) +Fuse::Fuse(object_id_t ownerId, object_id_t fuseObjectId, uint8_t fuseId, + dp::structure_id_t variableSet, VariableIds ids, float maxCurrent, + uint16_t confirmationCount) : SystemObject(fuseObjectId), oldFuseState(0), fuseId(fuseId), diff --git a/src/fsfw/power/Fuse.h b/src/fsfw/power/Fuse.h index fa6623bb..908fbfc0 100644 --- a/src/fsfw/power/Fuse.h +++ b/src/fsfw/power/Fuse.h @@ -3,13 +3,13 @@ #include -#include "../datapoollocal/StaticSharedDataset.h" -#include "../devicehandlers/HealthDevice.h" -#include "../monitoring/AbsLimitMonitor.h" -#include "../parameters/ParameterHelper.h" -#include "../returnvalues/returnvalue.h" #include "PowerComponentIF.h" #include "PowerSwitchIF.h" +#include "fsfw/datapool/StaticSharedSet.h" +#include "fsfw/devicehandlers/HealthDevice.h" +#include "fsfw/monitoring/AbsLimitMonitor.h" +#include "fsfw/parameters/ParameterHelper.h" +#include "fsfw/returnvalues/returnvalue.h" namespace Factory { void setStaticFrameworkObjectIds(); @@ -25,20 +25,20 @@ enum FusePoolId { }; -class FuseSet : public StaticSharedDataset<6> { +class FuseSet : public datapool::StaticSharedSet<6> { public: static constexpr uint8_t FUSE_SET_ID = 0; - FuseSet(localpool::SharedPool &sharedPool) : StaticSharedDataset(sharedPool, FUSE_SET_ID) {} + FuseSet(dp::SharedPool &sharedPool) : StaticSharedSet(sharedPool, FUSE_SET_ID) {} - FuseSet(object_id_t objectId) : StaticSharedDataset(sid_t(objectId, FUSE_SET_ID)) {} + FuseSet(object_id_t objectId) : StaticSharedSet(dp::sid_t(objectId, FUSE_SET_ID)) {} - lp_var_t voltage = lp_var_t(sid.objectId, FusePoolId::VOLTAGE, this); - lp_var_t current = lp_var_t(sid.objectId, FusePoolId::CURRENT, this); - lp_var_t state = lp_var_t(sid.objectId, FusePoolId::STATE, this); - lp_var_t power = lp_var_t(sid.objectId, FusePoolId::POWER, this); - lp_var_t powerValid = lp_var_t(sid.objectId, FusePoolId::POWER_VALID, this); - lp_var_t setValid = lp_var_t(sid.objectId, FusePoolId::SET_VALID, this); + dp::f32_t voltage = dp::f32_t(sid.objectId, FusePoolId::VOLTAGE, this); + dp::f32_t current = dp::f32_t(sid.objectId, FusePoolId::CURRENT, this); + dp::u8_t state = dp::u8_t(sid.objectId, FusePoolId::STATE, this); + dp::f32_t power = dp::f32_t(sid.objectId, FusePoolId::POWER, this); + dp::u8_t powerValid = dp::u8_t(sid.objectId, FusePoolId::POWER_VALID, this); + dp::u8_t setValid = dp::u8_t(sid.objectId, FusePoolId::SET_VALID, this); }; class Fuse : public SystemObject, @@ -53,10 +53,10 @@ class Fuse : public SystemObject, //!< Worst case is Fuse and one of two switches on. See PCDU ICD 1.9 p29 bottom public: struct VariableIds { - gp_id_t pidVoltage; - gp_id_t pidCurrent; - gp_id_t pidState; - gp_id_t poolIdPower; + dp::g_id_t pidVoltage; + dp::g_id_t pidCurrent; + dp::g_id_t pidState; + dp::g_id_t poolIdPower; }; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::POWER_SWITCH_IF; @@ -70,7 +70,7 @@ class Fuse : public SystemObject, static const Event POWER_BELOW_LOW_LIMIT = MAKE_EVENT(5, severity::LOW); typedef std::list DeviceList; - Fuse(object_id_t ownerId, object_id_t fuseObjectId, uint8_t fuseId, sid_t variableSet, + Fuse(object_id_t ownerId, object_id_t fuseObjectId, uint8_t fuseId, dp::sid_t variableSet, VariableIds ids, float maxCurrent, uint16_t confirmationCount = 2); virtual ~Fuse(); void addDevice(PowerComponentIF *set); diff --git a/src/fsfw/power/PowerSensor.cpp b/src/fsfw/power/PowerSensor.cpp index 74f13f36..e0083482 100644 --- a/src/fsfw/power/PowerSensor.cpp +++ b/src/fsfw/power/PowerSensor.cpp @@ -3,8 +3,8 @@ #include "definitions.h" #include "fsfw/ipc/QueueFactory.h" -PowerSensor::PowerSensor(object_id_t objectId, sid_t setId, VariableIds ids, DefaultLimits limits, - SensorEvents events, uint16_t confirmationCount) +PowerSensor::PowerSensor(object_id_t objectId, dp::structure_id_t setId, VariableIds ids, + DefaultLimits limits, SensorEvents events, uint16_t confirmationCount) : SystemObject(objectId), parameterHelper(this), healthHelper(this, objectId), diff --git a/src/fsfw/power/PowerSensor.h b/src/fsfw/power/PowerSensor.h index 34d3679a..7c0dfa78 100644 --- a/src/fsfw/power/PowerSensor.h +++ b/src/fsfw/power/PowerSensor.h @@ -1,7 +1,7 @@ #ifndef FSFW_POWER_POWERSENSOR_H_ #define FSFW_POWER_POWERSENSOR_H_ -#include "fsfw/datapoollocal/StaticSharedDataset.h" +#include "fsfw/datapool/StaticSharedSet.h" #include "fsfw/devicehandlers/HealthDevice.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/monitoring/LimitMonitor.h" @@ -17,21 +17,19 @@ enum PowerSensorPoolId { SET_VALID = 3 }; -class PowerSensorSet : public StaticSharedDataset<6> { +class PowerSensorSet : public dp::StaticSharedSet<6> { public: static constexpr uint8_t POWER_SENSOR_SET_ID = 0; - PowerSensorSet(localpool::SharedPool &sharedPool) - : StaticSharedDataset(sharedPool, POWER_SENSOR_SET_ID) {} + PowerSensorSet(dp::SharedPool &sharedPool) : StaticSharedSet(sharedPool, POWER_SENSOR_SET_ID) {} PowerSensorSet(object_id_t objectId) - : StaticSharedDataset(sid_t(objectId, POWER_SENSOR_SET_ID)) {} + : StaticSharedSet(dp::sid_t(objectId, POWER_SENSOR_SET_ID)) {} - lp_var_t current = lp_var_t(sid.objectId, PowerSensorPoolId::CURRENT, this); - lp_var_t voltage = lp_var_t(sid.objectId, PowerSensorPoolId::VOLTAGE, this); - lp_var_t power = lp_var_t(sid.objectId, PowerSensorPoolId::POWER, this); - lp_var_t setIsValid = - lp_var_t(sid.objectId, PowerSensorPoolId::SET_VALID, this); + dp::f32_t current{sid.objectId, PowerSensorPoolId::CURRENT, this}; + dp::f32_t voltage{sid.objectId, PowerSensorPoolId::VOLTAGE, this}; + dp::f32_t power = {sid.objectId, PowerSensorPoolId::POWER, this}; + dp::u8_t setIsValid{sid.objectId, PowerSensorPoolId::SET_VALID, this}; }; /** * @brief Does magic. @@ -41,10 +39,10 @@ class PowerSensor : public SystemObject, public ReceivesParameterMessagesIF, pub public: struct VariableIds { - gp_id_t pidCurrent; - gp_id_t pidVoltage; - gp_id_t poolIdPower; - gp_id_t valid; + dp::g_id_t pidCurrent; + dp::g_id_t pidVoltage; + dp::g_id_t poolIdPower; + dp::g_id_t valid; }; struct DefaultLimits { float currentMin; @@ -58,7 +56,7 @@ class PowerSensor : public SystemObject, public ReceivesParameterMessagesIF, pub Event voltageLow; Event voltageHigh; }; - PowerSensor(object_id_t objectId, sid_t sid, VariableIds setIds, DefaultLimits limits, + PowerSensor(object_id_t objectId, dp::sid_t sid, VariableIds setIds, DefaultLimits limits, SensorEvents events, uint16_t confirmationCount = 0); virtual ~PowerSensor(); ReturnValue_t calculatePower(); diff --git a/src/fsfw/pus/Service3Housekeeping.cpp b/src/fsfw/pus/Service3Housekeeping.cpp index c6631fe3..87d7d6c2 100644 --- a/src/fsfw/pus/Service3Housekeeping.cpp +++ b/src/fsfw/pus/Service3Housekeeping.cpp @@ -1,9 +1,11 @@ #include "fsfw/pus/Service3Housekeeping.h" -#include "fsfw/datapoollocal/PeriodicHkGenerationIF.h" +#include "fsfw/housekeeping/GeneratesPeriodicHkIF.h" #include "fsfw/objectmanager/ObjectManager.h" #include "fsfw/pus/servicepackets/Service3Packets.h" +using namespace dp; + Service3Housekeeping::Service3Housekeeping(object_id_t objectId, uint16_t apid, uint8_t serviceId, uint32_t queueDepth, uint8_t numParallelCommands) : CommandingServiceBase(objectId, apid, "PUS 3 HK", serviceId, numParallelCommands, @@ -58,8 +60,7 @@ ReturnValue_t Service3Housekeeping::checkAndAcquireTargetID(object_id_t* objectI ReturnValue_t Service3Housekeeping::checkInterfaceAndAcquireMessageQueue( MessageQueueId_t* messageQueueToSet, object_id_t* objectId) { // check HasLocalDataPoolIF property of target - PeriodicHkGenerationIF* possibleTarget = - ObjectManager::instance()->get(*objectId); + auto* possibleTarget = ObjectManager::instance()->get(*objectId); if (possibleTarget == nullptr) { return CommandingServiceBase::INVALID_OBJECT; } @@ -99,12 +100,12 @@ ReturnValue_t Service3Housekeeping::prepareReportingTogglingCommand(CommandMessa bool enableReporting, const uint8_t* tcData, size_t tcDataLen) { - if (tcDataLen < sizeof(sid_t)) { + if (tcDataLen < sizeof(structure_id_t)) { // TC data should consist of object ID and set ID. return CommandingServiceBase::INVALID_TC; } - sid_t targetSid = buildSid(objectId, &tcData, &tcDataLen); + structure_id_t targetSid = buildStructureId(objectId, &tcData, &tcDataLen); HousekeepingMessage::setToggleReportingCommand(command, targetSid, enableReporting); return returnvalue::OK; } @@ -113,12 +114,12 @@ ReturnValue_t Service3Housekeeping::prepareStructureReportingCommand(CommandMess object_id_t objectId, const uint8_t* tcData, size_t tcDataLen) { - if (tcDataLen < sizeof(sid_t)) { + if (tcDataLen < sizeof(structure_id_t)) { // TC data should consist of object ID and set ID. return CommandingServiceBase::INVALID_TC; } - sid_t targetSid = buildSid(objectId, &tcData, &tcDataLen); + structure_id_t targetSid = buildStructureId(objectId, &tcData, &tcDataLen); HousekeepingMessage::setStructureReportingCommand(command, targetSid); return returnvalue::OK; } @@ -128,24 +129,24 @@ ReturnValue_t Service3Housekeeping::prepareOneShotReportCommand(CommandMessage* const uint8_t* tcData, size_t tcDataLen) { - if (tcDataLen < sizeof(sid_t)) { + if (tcDataLen < sizeof(structure_id_t)) { // TC data should consist of object ID and set ID. return CommandingServiceBase::INVALID_TC; } - sid_t targetSid = buildSid(objectId, &tcData, &tcDataLen); + structure_id_t targetSid = buildStructureId(objectId, &tcData, &tcDataLen); HousekeepingMessage::setOneShotReportCommand(command, targetSid); return returnvalue::OK; } ReturnValue_t Service3Housekeeping::prepareCollectionIntervalModificationCommand( CommandMessage* command, object_id_t objectId, const uint8_t* tcData, size_t tcDataLen) { - if (tcDataLen < sizeof(sid_t) + sizeof(float)) { + if (tcDataLen < sizeof(structure_id_t) + sizeof(float)) { /* SID plus the size of the new collection interval. */ return CommandingServiceBase::INVALID_TC; } - sid_t targetSid = buildSid(objectId, &tcData, &tcDataLen); + structure_id_t targetSid = buildStructureId(objectId, &tcData, &tcDataLen); float newCollectionInterval = 0; SerializeAdapter::deSerialize(&newCollectionInterval, &tcData, &tcDataLen, SerializeIF::Endianness::BIG); @@ -276,7 +277,7 @@ ReturnValue_t Service3Housekeeping::generateHkReply(const CommandMessage* hkMess uint8_t subserviceId) { store_address_t storeId; - sid_t sid = HousekeepingMessage::getHkDataReply(hkMessage, &storeId); + structure_id_t sid = HousekeepingMessage::getHkDataReply(hkMessage, &storeId); auto resultPair = ipcStore->getData(storeId); if (resultPair.first != returnvalue::OK) { return resultPair.first; @@ -286,9 +287,9 @@ ReturnValue_t Service3Housekeeping::generateHkReply(const CommandMessage* hkMess return sendTmPacket(static_cast(subserviceId), hkPacket.hkData, hkPacket.hkSize); } -sid_t Service3Housekeeping::buildSid(object_id_t objectId, const uint8_t** tcData, - size_t* tcDataLen) { - sid_t targetSid; +structure_id_t Service3Housekeeping::buildStructureId(object_id_t objectId, const uint8_t** tcData, + size_t* tcDataLen) { + structure_id_t targetSid; targetSid.objectId = objectId; // skip deserialization of object ID, was already done. *tcData += sizeof(object_id_t); diff --git a/src/fsfw/pus/Service3Housekeeping.h b/src/fsfw/pus/Service3Housekeeping.h index f336a50a..93597d52 100644 --- a/src/fsfw/pus/Service3Housekeeping.h +++ b/src/fsfw/pus/Service3Housekeeping.h @@ -97,7 +97,8 @@ class Service3Housekeeping : public CommandingServiceBase, public AcceptsHkPacke size_t tcDataLen); void handleUnrequestedReply(CommandMessage* reply) override; - sid_t buildSid(object_id_t objectId, const uint8_t** tcData, size_t* tcDataLen); + dp::structure_id_t buildStructureId(object_id_t objectId, const uint8_t** tcData, + size_t* tcDataLen); }; #endif /* FSFW_PUS_SERVICE3HOUSEKEEPINGSERVICE_H_ */ diff --git a/src/fsfw/pus/servicepackets/Service3Packets.h b/src/fsfw/pus/servicepackets/Service3Packets.h index d6c98b61..153bdfb7 100644 --- a/src/fsfw/pus/servicepackets/Service3Packets.h +++ b/src/fsfw/pus/servicepackets/Service3Packets.h @@ -11,11 +11,12 @@ */ class HkPacket { //!< [EXPORT] : [SUBSERVICE] 25, 26 public: - sid_t sid; //!< [EXPORT] : [COMMENT] Structure ID (SID) of housekeeping data. + dp::sid_t sid; //!< [EXPORT] : [COMMENT] Structure ID (SID) of housekeeping data. const uint8_t* hkData; //!< [EXPORT] : [MAXSIZE] Deduced size size_t hkSize; //!< [EXPORT] : [IGNORE] - HkPacket(sid_t sid, const uint8_t* data, size_t size) : sid(sid), hkData(data), hkSize(size) {} + HkPacket(dp::sid_t sid, const uint8_t* data, size_t size) + : sid(sid), hkData(data), hkSize(size) {} }; #endif /* FSFW_PUS_SERVICEPACKETS_SERVICE3PACKETS_H_ */ diff --git a/src/fsfw/thermal/ThermalComponent.cpp b/src/fsfw/thermal/ThermalComponent.cpp index 7bbf805b..b867283a 100644 --- a/src/fsfw/thermal/ThermalComponent.cpp +++ b/src/fsfw/thermal/ThermalComponent.cpp @@ -1,9 +1,9 @@ #include "fsfw/thermal/ThermalComponent.h" ThermalComponent::ThermalComponent(object_id_t reportingObjectId, uint8_t domainId, - gp_id_t temperaturePoolId, gp_id_t targetStatePoolId, - gp_id_t currentStatePoolId, gp_id_t requestPoolId, - SharedDatasetBase* dataSet, AbstractTemperatureSensor* sensor, + dp::g_id_t temperaturePoolId, dp::g_id_t targetStatePoolId, + dp::g_id_t currentStatePoolId, dp::g_id_t requestPoolId, + dp::SharedSetBase* dataSet, AbstractTemperatureSensor* sensor, AbstractTemperatureSensor* firstRedundantSensor, AbstractTemperatureSensor* secondRedundantSensor, ThermalModuleIF* thermalModule, Parameters parameters, diff --git a/src/fsfw/thermal/ThermalComponent.h b/src/fsfw/thermal/ThermalComponent.h index 47d0dae3..c088e6d8 100644 --- a/src/fsfw/thermal/ThermalComponent.h +++ b/src/fsfw/thermal/ThermalComponent.h @@ -44,9 +44,10 @@ class ThermalComponent : public ThermalComponentCore { * @param parameters * @param priority */ - ThermalComponent(object_id_t reportingObjectId, uint8_t domainId, gp_id_t temperaturePoolId, - gp_id_t targetStatePoolId, gp_id_t currentStatePoolId, gp_id_t requestPoolId, - SharedDatasetBase *dataSet, AbstractTemperatureSensor *sensor, + ThermalComponent(object_id_t reportingObjectId, uint8_t domainId, dp::g_id_t temperaturePoolId, + dp::g_id_t targetStatePoolId, dp::g_id_t currentStatePoolId, + dp::g_id_t requestPoolId, dp::SharedSetBase *dataSet, + AbstractTemperatureSensor *sensor, AbstractTemperatureSensor *firstRedundantSensor, AbstractTemperatureSensor *secondRedundantSensor, ThermalModuleIF *thermalModule, Parameters parameters, Priority priority); diff --git a/src/fsfw/thermal/ThermalComponentCore.cpp b/src/fsfw/thermal/ThermalComponentCore.cpp index 20dac159..9b678254 100644 --- a/src/fsfw/thermal/ThermalComponentCore.cpp +++ b/src/fsfw/thermal/ThermalComponentCore.cpp @@ -3,9 +3,10 @@ #include "fsfw/thermal/tcsDefinitions.h" ThermalComponentCore::ThermalComponentCore(object_id_t reportingObjectId, uint8_t domainId, - gp_id_t temperaturePoolId, gp_id_t targetStatePoolId, - gp_id_t currentStatePoolId, gp_id_t requestPoolId, - SharedDatasetBase* dataSet, Parameters parameters, + dp::g_id_t temperaturePoolId, + dp::g_id_t targetStatePoolId, + dp::g_id_t currentStatePoolId, dp::g_id_t requestPoolId, + dp::SharedSetBase* dataSet, Parameters parameters, StateRequest initialTargetState) : temperature(temperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE), targetState(targetStatePoolId, dataSet, PoolVariableIF::VAR_READ), diff --git a/src/fsfw/thermal/ThermalComponentCore.h b/src/fsfw/thermal/ThermalComponentCore.h index 7dce87a2..1f15439a 100644 --- a/src/fsfw/thermal/ThermalComponentCore.h +++ b/src/fsfw/thermal/ThermalComponentCore.h @@ -5,7 +5,7 @@ #include "ThermalComponentIF.h" #include "ThermalModule.h" #include "ThermalMonitorReporter.h" -#include "fsfw/datapoollocal/LocalPoolVariable.h" +#include "fsfw/datapool/PoolVariable.h" /** * @brief @@ -36,9 +36,9 @@ class ThermalComponentCore : public ThermalComponentIF { * @param initialTargetState */ ThermalComponentCore( - object_id_t reportingObjectId, uint8_t domainId, gp_id_t temperaturePoolId, - gp_id_t targetStatePoolId, gp_id_t currentStatePoolId, gp_id_t requestPoolId, - SharedDatasetBase *dataSet, Parameters parameters, + object_id_t reportingObjectId, uint8_t domainId, dp::g_id_t temperaturePoolId, + dp::g_id_t targetStatePoolId, dp::g_id_t currentStatePoolId, dp::g_id_t requestPoolId, + dp::SharedSetBase *dataSet, Parameters parameters, StateRequest initialTargetState = ThermalComponentIF::STATE_REQUEST_OPERATIONAL); void addSensor(AbstractTemperatureSensor *firstRedundantSensor); @@ -74,10 +74,10 @@ class ThermalComponentCore : public ThermalComponentIF { AbstractTemperatureSensor *secondRedundantSensor = nullptr; ThermalModuleIF *thermalModule = nullptr; - lp_var_t temperature; - lp_var_t targetState; - lp_var_t currentState; - lp_var_t heaterRequest; + dp::f32_t temperature; + dp::i8_t targetState; + dp::i8_t currentState; + dp::i8_t heaterRequest; bool isHeating = false; diff --git a/src/fsfw/thermal/ThermalModule.cpp b/src/fsfw/thermal/ThermalModule.cpp index 29eb26f1..2dcb7f43 100644 --- a/src/fsfw/thermal/ThermalModule.cpp +++ b/src/fsfw/thermal/ThermalModule.cpp @@ -4,8 +4,8 @@ #include "fsfw/monitoring/MonitoringMessageContent.h" #include "fsfw/thermal/AbstractTemperatureSensor.h" -ThermalModule::ThermalModule(gp_id_t moduleTemperaturePoolId, gp_id_t currentStatePoolId, - gp_id_t targetStatePoolId, SharedDatasetBase* dataSet, +ThermalModule::ThermalModule(dp::g_id_t moduleTemperaturePoolId, dp::g_id_t currentStatePoolId, + dp::g_id_t targetStatePoolId, dp::SharedSetBase* dataSet, Parameters parameters, RedundantHeater::Parameters heaterParameters) : oldStrategy(ACTIVE_SINGLE), parameters(parameters), @@ -15,12 +15,12 @@ ThermalModule::ThermalModule(gp_id_t moduleTemperaturePoolId, gp_id_t currentSta heater = new RedundantHeater(heaterParameters); } -ThermalModule::ThermalModule(gp_id_t moduleTemperaturePoolId, SharedDatasetBase* dataSet) +ThermalModule::ThermalModule(dp::g_id_t moduleTemperaturePoolId, dp::SharedSetBase* dataSet) : oldStrategy(ACTIVE_SINGLE), parameters({0, 0}), moduleTemperature(moduleTemperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE), - currentState(gp_id_t(), dataSet, PoolVariableIF::VAR_WRITE), - targetState(gp_id_t(), dataSet, PoolVariableIF::VAR_READ) {} + currentState(dp::g_id_t(), dataSet, PoolVariableIF::VAR_WRITE), + targetState(dp::g_id_t(), dataSet, PoolVariableIF::VAR_READ) {} ThermalModule::~ThermalModule() { delete heater; } diff --git a/src/fsfw/thermal/ThermalModule.h b/src/fsfw/thermal/ThermalModule.h index 787b56d6..bd3381ec 100644 --- a/src/fsfw/thermal/ThermalModule.h +++ b/src/fsfw/thermal/ThermalModule.h @@ -3,12 +3,12 @@ #include -#include "../datapoollocal/LocalPoolVariable.h" #include "../devicehandlers/HealthDevice.h" #include "../events/EventReportingProxyIF.h" #include "RedundantHeater.h" #include "ThermalModuleIF.h" -#include "fsfw/datapoollocal/SharedDatasetBase.h" +#include "fsfw/datapool/PoolVariable.h" +#include "fsfw/datapool/SharedSetBase.h" #include "tcsDefinitions.h" class PowerSwitchIF; @@ -25,11 +25,11 @@ class ThermalModule : public ThermalModuleIF { float hysteresis; }; - ThermalModule(gp_id_t moduleTemperaturePoolId, gp_id_t currentStatePoolId, - gp_id_t targetStatePoolId, SharedDatasetBase *dataSet, Parameters parameters, + ThermalModule(dp::g_id_t moduleTemperaturePoolId, dp::g_id_t currentStatePoolId, + dp::g_id_t targetStatePoolId, dp::SharedSetBase *dataSet, Parameters parameters, RedundantHeater::Parameters heaterParameters); - ThermalModule(gp_id_t moduleTemperaturePoolId, SharedDatasetBase *dataSet); + ThermalModule(dp::g_id_t moduleTemperaturePoolId, dp::SharedSetBase *dataSet); virtual ~ThermalModule(); @@ -70,12 +70,12 @@ class ThermalModule : public ThermalModuleIF { Parameters parameters; - lp_var_t moduleTemperature; + dp::f32_t moduleTemperature; RedundantHeater *heater = nullptr; - lp_var_t currentState; - lp_var_t targetState; + dp::i8_t currentState; + dp::i8_t targetState; std::list sensors; std::list components; diff --git a/unittests/mocks/DeviceHandlerMock.cpp b/unittests/mocks/DeviceHandlerMock.cpp index 93457d0e..90c1169a 100644 --- a/unittests/mocks/DeviceHandlerMock.cpp +++ b/unittests/mocks/DeviceHandlerMock.cpp @@ -109,7 +109,7 @@ ReturnValue_t DeviceHandlerMock::initialize() { return result; } -ReturnValue_t DeviceHandlerMock::serializeHkDataset(sid_t structureId, uint8_t *buf, +ReturnValue_t DeviceHandlerMock::serializeHkDataset(structure_id_t structureId, uint8_t *buf, size_t maxSize) { return returnvalue::OK; } diff --git a/unittests/mocks/LocalPoolOwnerBase.cpp b/unittests/mocks/LocalPoolOwnerBase.cpp index fcfd70f0..6f29f472 100644 --- a/unittests/mocks/LocalPoolOwnerBase.cpp +++ b/unittests/mocks/LocalPoolOwnerBase.cpp @@ -28,7 +28,7 @@ ReturnValue_t LocalPoolOwnerBase::initialize() { localpool::SharedPool *LocalPoolOwnerBase::getOptionalSharedPool() { return &sharedPool; } -ReturnValue_t LocalPoolOwnerBase::serializeHkDataset(sid_t structureId, uint8_t *buf, +ReturnValue_t LocalPoolOwnerBase::serializeHkDataset(structure_id_t structureId, uint8_t *buf, size_t maxSize) { return returnvalue::OK; } diff --git a/unittests/mocks/LocalPoolOwnerBase.h b/unittests/mocks/LocalPoolOwnerBase.h index e60405e3..fbfb76ff 100644 --- a/unittests/mocks/LocalPoolOwnerBase.h +++ b/unittests/mocks/LocalPoolOwnerBase.h @@ -1,10 +1,10 @@ #ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ #define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_ -#include -#include #include #include +#include +#include #include #include #include @@ -25,9 +25,9 @@ static constexpr uint32_t testSetId1 = 1; static constexpr uint32_t testSetId2 = 2; static constexpr uint8_t dataSetMaxVariables = 10; -static const auto testSid0 = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId0); -static const auto testSid1 = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId1); -static const auto testSid2 = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId2); +static const auto testSid0 = structure_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId0); +static const auto testSid1 = structure_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId1); +static const auto testSid2 = structure_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId2); static const gp_id_t uint8VarGpid = gp_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, uint8VarId); static const gp_id_t floatVarGpid = gp_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, floatVarId); @@ -73,7 +73,8 @@ class LocalPoolOwnerBase : public SystemObject, public PeriodicHkGenerationIF { [[nodiscard]] object_id_t getObjectId() const override { return SystemObject::getObjectId(); } - ReturnValue_t serializeHkDataset(sid_t structureId, uint8_t* buf, size_t maxSize) override; + ReturnValue_t serializeHkDataset(structure_id_t structureId, uint8_t* buf, + size_t maxSize) override; ReturnValue_t specifyHkDatasets(std::vector& setList) override;