From 3bffb4f968ea14fa77596bf881621c8a1b14803d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 29 Aug 2022 15:20:33 +0200 Subject: [PATCH 01/10] fix for static fw obj setter --- misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp index 4670c7e7..4d6e91f1 100644 --- a/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp +++ b/misc/defaultcfg/fsfwconfig/objects/FsfwFactory.cpp @@ -35,7 +35,7 @@ void Factory::produceFsfwObjects(void) { } void Factory::setStaticFrameworkObjectIds() { - PusServiceBase::packetSource = objects::NO_OBJECT; + PusServiceBase::PUS_DISTRIBUTOR = objects::NO_OBJECT; PusServiceBase::PACKET_DESTINATION = objects::NO_OBJECT; CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; From b499dedd76637e1330a90f3f8ef0d0743ef0246a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 29 Aug 2022 15:27:53 +0200 Subject: [PATCH 02/10] remove TODO --- src/fsfw/datapoollocal/LocalDataPoolManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index fa76d2a7..0a7dd5ab 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -14,7 +14,6 @@ #include "internal/HasLocalDpIFManagerAttorney.h" #include "internal/LocalPoolDataSetAttorney.h" -// TODO: Get rid of this. This should be a constructor argument, not something hardcoded in any way object_id_t LocalDataPoolManager::defaultHkDestination = objects::PUS_SERVICE_3_HOUSEKEEPING; LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse, From cb23911ccd5b678bc53ceda59f5258b77a042a56 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 29 Aug 2022 15:30:45 +0200 Subject: [PATCH 03/10] default initialization of CDS short struct --- src/fsfw/timemanager/CCSDSTime.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fsfw/timemanager/CCSDSTime.h b/src/fsfw/timemanager/CCSDSTime.h index 607026e3..77801cec 100644 --- a/src/fsfw/timemanager/CCSDSTime.h +++ b/src/fsfw/timemanager/CCSDSTime.h @@ -39,13 +39,13 @@ class CCSDSTime { * Struct for CDS day-segmented format. */ struct CDS_short { - uint8_t pField; - uint8_t dayMSB; - uint8_t dayLSB; - uint8_t msDay_hh; - uint8_t msDay_h; - uint8_t msDay_l; - uint8_t msDay_ll; + uint8_t pField = P_FIELD_CDS_SHORT; + uint8_t dayMSB = 0; + uint8_t dayLSB = 0; + uint8_t msDay_hh = 0; + uint8_t msDay_h = 0; + uint8_t msDay_l = 0; + uint8_t msDay_ll = 0; }; /** * Struct for the CCS fromat in day of month variation with max resolution From 2cab73d9722da97c32ad46e63cbec4d54645b897 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 29 Aug 2022 20:08:59 +0200 Subject: [PATCH 04/10] avoid duplicate code --- src/fsfw/ipc/MessageQueueMessage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/ipc/MessageQueueMessage.cpp b/src/fsfw/ipc/MessageQueueMessage.cpp index 6e841c7f..b0ce090f 100644 --- a/src/fsfw/ipc/MessageQueueMessage.cpp +++ b/src/fsfw/ipc/MessageQueueMessage.cpp @@ -12,7 +12,7 @@ MessageQueueMessage::MessageQueueMessage() : messageSize(getMinimumMessageSize() MessageQueueMessage::MessageQueueMessage(uint8_t* data, size_t size) : messageSize(MessageQueueMessage::HEADER_SIZE + size) { if (size <= MessageQueueMessage::MAX_DATA_SIZE) { - std::memcpy(internalBuffer + MessageQueueMessage::HEADER_SIZE, data, size); + std::memcpy(MessageQueueMessage::getData(), data, size); this->messageSize = MessageQueueMessage::HEADER_SIZE + size; } else { #if FSFW_CPP_OSTREAM_ENABLED == 1 From 342a56410cd14a6e089670797e1b3fa1481ed512 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 10:28:55 +0200 Subject: [PATCH 05/10] delete commented function --- src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index baf91796..ba3f7a43 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -98,11 +98,6 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; - // virtual ReturnValue_t - // subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { - // return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); - // } - [[deprecated( "Please use the new API which takes all arguments as one wrapper " "struct")]] virtual ReturnValue_t From 92d65aa3a5ad2d393cf024d5861d30ffd6aad645 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 10:57:02 +0200 Subject: [PATCH 06/10] use old lpm api --- .../datapoollocal/LocalDataPoolManager.cpp | 65 +++++------ src/fsfw/datapoollocal/LocalDataPoolManager.h | 12 +- .../ProvidesDataPoolSubscriptionIF.h | 107 +++--------------- .../internalerror/InternalErrorReporter.cpp | 5 +- .../devicehandlers/MgmLIS3MDLHandler.cpp | 2 +- .../devicehandlers/MgmRM3100Handler.cpp | 2 +- unittests/datapoollocal/CMakeLists.txt | 2 +- unittests/mocks/LocalPoolOwnerBase.h | 16 +-- 8 files changed, 57 insertions(+), 154 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index fa76d2a7..daad19be 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -326,32 +326,27 @@ void LocalDataPoolManager::resetHkUpdateResetHelper() { } } -ReturnValue_t LocalDataPoolManager::subscribeForRegularPeriodicPacket( - subdp::RegularHkPeriodicParams params) { - return subscribeForPeriodicPacket(params); -} - -ReturnValue_t LocalDataPoolManager::subscribeForDiagPeriodicPacket( - subdp::DiagnosticsHkPeriodicParams params) { - return subscribeForPeriodicPacket(params); -} - -ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(subdp::ParamsBase& params) { +ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, bool enableReporting, + float collectionInterval, bool isDiagnostics, + object_id_t packetDestination) { struct HkReceiver hkReceiver; - hkReceiver.dataId.sid = params.sid; + hkReceiver.dataId.sid = sid; hkReceiver.reportingType = ReportingType::PERIODIC; hkReceiver.dataType = DataType::DATA_SET; - if (params.receiver == MessageQueueIF::NO_QUEUE) { - hkReceiver.destinationQueue = hkDestinationId; - } else { - hkReceiver.destinationQueue = params.receiver; + if (packetDestination != objects::NO_OBJECT) { + auto* receivedHkIF = ObjectManager::instance()->get(packetDestination); + if (receivedHkIF->getHkQueue() == MessageQueueIF::NO_QUEUE) { + hkReceiver.destinationQueue = hkDestinationId; + } else { + hkReceiver.destinationQueue = receivedHkIF->getHkQueue(); + } } - LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, params.sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); if (dataSet != nullptr) { - LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, params.enableReporting); - LocalPoolDataSetAttorney::setDiagnostic(*dataSet, params.isDiagnostics()); - LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, params.collectionInterval, + LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, enableReporting); + LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics); + LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, collectionInterval, owner->getPeriodicOperationFrequency()); } @@ -359,30 +354,26 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(subdp::ParamsBase return returnvalue::OK; } -ReturnValue_t LocalDataPoolManager::subscribeForRegularUpdatePacket( - subdp::RegularHkUpdateParams params) { - return subscribeForUpdatePacket(params); -} -ReturnValue_t LocalDataPoolManager::subscribeForDiagUpdatePacket( - subdp::DiagnosticsHkUpdateParams params) { - return subscribeForUpdatePacket(params); -} - -ReturnValue_t LocalDataPoolManager::subscribeForUpdatePacket(subdp::ParamsBase& params) { +ReturnValue_t LocalDataPoolManager::subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, + bool isDiagnostics, + object_id_t packetDestination) { struct HkReceiver hkReceiver; - hkReceiver.dataId.sid = params.sid; + hkReceiver.dataId.sid = sid; hkReceiver.reportingType = ReportingType::UPDATE_HK; hkReceiver.dataType = DataType::DATA_SET; - if (params.receiver == MessageQueueIF::NO_QUEUE) { - hkReceiver.destinationQueue = hkDestinationId; - } else { - hkReceiver.destinationQueue = params.receiver; + if (packetDestination != objects::NO_OBJECT) { + auto* receivedHkIF = ObjectManager::instance()->get(packetDestination); + if (receivedHkIF->getHkQueue() == MessageQueueIF::NO_QUEUE) { + hkReceiver.destinationQueue = hkDestinationId; + } else { + hkReceiver.destinationQueue = receivedHkIF->getHkQueue(); + } } - LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, params.sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); if (dataSet != nullptr) { LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, true); - LocalPoolDataSetAttorney::setDiagnostic(*dataSet, params.isDiagnostics()); + LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics); } hkReceivers.push_back(hkReceiver); diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.h b/src/fsfw/datapoollocal/LocalDataPoolManager.h index 7db079f6..8b12e29f 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.h +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.h @@ -241,13 +241,13 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces MutexIF* getMutexHandle(); LocalDataPoolManager* getPoolManagerHandle() override; - ReturnValue_t subscribeForRegularPeriodicPacket(subdp::RegularHkPeriodicParams params) override; - ReturnValue_t subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams params) override; - ReturnValue_t subscribeForPeriodicPacket(subdp::ParamsBase& params); + ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, + float collectionInterval, bool isDiagnostics, + object_id_t packetDestination = objects::NO_OBJECT) override; - ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) override; - ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) override; - ReturnValue_t subscribeForUpdatePacket(subdp::ParamsBase& params); + ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, + bool isDiagnostics, + object_id_t packetDestination = objects::NO_OBJECT) override; protected: /** Core data structure for the actual pool data */ diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index ba3f7a43..eb4e55b7 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -1,90 +1,24 @@ #ifndef FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ #define FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ -#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" -#include "fsfw/ipc/MessageQueueIF.h" -#include "fsfw/ipc/messageQueueDefinitions.h" -#include "fsfw/returnvalues/returnvalue.h" +#include "../ipc/messageQueueDefinitions.h" +#include "../returnvalues/returnvalue.h" #include "localPoolDefinitions.h" -namespace subdp { - -struct ParamsBase { - ParamsBase(sid_t sid, bool enableReporting, float collectionInterval, bool diagnostics) - : sid(sid), - enableReporting(enableReporting), - collectionInterval(collectionInterval), - diagnostics(diagnostics) {} - - [[nodiscard]] bool isDiagnostics() const { return diagnostics; } - - sid_t sid; - bool enableReporting; - float collectionInterval; - MessageQueueId_t receiver = MessageQueueIF::NO_QUEUE; - - protected: - bool diagnostics; -}; - -struct RegularHkPeriodicParams : public ParamsBase { - RegularHkPeriodicParams(sid_t sid, bool enableReporting, float collectionInterval) - : ParamsBase(sid, enableReporting, collectionInterval, false) {} -}; - -struct DiagnosticsHkPeriodicParams : public ParamsBase { - DiagnosticsHkPeriodicParams(sid_t sid, bool enableReporting, float collectionInterval) - : ParamsBase(sid, enableReporting, collectionInterval, true) {} -}; - -struct RegularHkUpdateParams : public ParamsBase { - RegularHkUpdateParams(sid_t sid, bool enableReporting) - : ParamsBase(sid, enableReporting, 0.0, false) {} -}; - -struct DiagnosticsHkUpdateParams : public ParamsBase { - DiagnosticsHkUpdateParams(sid_t sid, bool enableReporting) - : ParamsBase(sid, enableReporting, 0.0, true) {} -}; -} // namespace subdp - class ProvidesDataPoolSubscriptionIF { public: - virtual ~ProvidesDataPoolSubscriptionIF() = default; + virtual ~ProvidesDataPoolSubscriptionIF(){}; + /** - * @brief Subscribe for the generation of periodic packets. Used for regular HK packets + * @brief Subscribe for the generation of periodic packets. * @details * This subscription mechanism will generally be used by the data creator * to generate housekeeping packets which are downlinked directly. * @return */ - virtual ReturnValue_t subscribeForRegularPeriodicPacket( - subdp::RegularHkPeriodicParams params) = 0; - /** - * @brief Subscribe for the generation of periodic packets. Used for diagnostic packets - * @details - * This subscription mechanism will generally be used by the data creator - * to generate housekeeping packets which are downlinked directly. - * @return - */ - virtual ReturnValue_t subscribeForDiagPeriodicPacket( - subdp::DiagnosticsHkPeriodicParams params) = 0; - - [[deprecated( - "Please use the new API which takes all arguments as one wrapper " - "struct")]] virtual ReturnValue_t - subscribeForPeriodicPacket(sid_t sid, bool enableReporting, float collectionInterval, - bool isDiagnostics, - object_id_t packetDestination = objects::NO_OBJECT) { - if (isDiagnostics) { - subdp::DiagnosticsHkPeriodicParams params(sid, enableReporting, collectionInterval); - return subscribeForDiagPeriodicPacket(params); - } else { - subdp::RegularHkPeriodicParams params(sid, enableReporting, collectionInterval); - return subscribeForRegularPeriodicPacket(params); - } - } - + virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, + float collectionInterval, bool isDiagnostics, + object_id_t packetDestination) = 0; /** * @brief Subscribe for the generation of packets if the dataset * is marked as changed. @@ -95,23 +29,9 @@ class ProvidesDataPoolSubscriptionIF { * @param packetDestination * @return */ - virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; - virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; - - [[deprecated( - "Please use the new API which takes all arguments as one wrapper " - "struct")]] virtual ReturnValue_t - subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics, - object_id_t packetDestination = objects::NO_OBJECT) { - if (isDiagnostics) { - subdp::DiagnosticsHkUpdateParams params(sid, reportingEnabled); - return subscribeForDiagUpdatePacket(params); - } else { - subdp::RegularHkUpdateParams params(sid, reportingEnabled); - return subscribeForRegularUpdatePacket(params); - } - } - + virtual ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, + bool isDiagnostics, + object_id_t packetDestination) = 0; /** * @brief Subscribe for a notification message which will be sent * if a dataset has changed. @@ -126,7 +46,8 @@ class ProvidesDataPoolSubscriptionIF { * Otherwise, only an notification message is sent. * @return */ - virtual ReturnValue_t subscribeForSetUpdateMessage(uint32_t setId, object_id_t destinationObject, + virtual ReturnValue_t subscribeForSetUpdateMessage(const uint32_t setId, + object_id_t destinationObject, MessageQueueId_t targetQueueId, bool generateSnapshot) = 0; /** @@ -143,7 +64,7 @@ class ProvidesDataPoolSubscriptionIF { * only an notification message is sent. * @return */ - virtual ReturnValue_t subscribeForVariableUpdateMessage(lp_id_t localPoolId, + virtual ReturnValue_t subscribeForVariableUpdateMessage(const lp_id_t localPoolId, object_id_t destinationObject, MessageQueueId_t targetQueueId, bool generateSnapshot) = 0; diff --git a/src/fsfw/internalerror/InternalErrorReporter.cpp b/src/fsfw/internalerror/InternalErrorReporter.cpp index b3b77366..ad6b711c 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.cpp +++ b/src/fsfw/internalerror/InternalErrorReporter.cpp @@ -129,9 +129,8 @@ ReturnValue_t InternalErrorReporter::initializeLocalDataPool(localpool::DataPool localDataPoolMap.emplace(errorPoolIds::TM_HITS, &tmHitsEntry); localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, &queueHitsEntry); localDataPoolMap.emplace(errorPoolIds::STORE_HITS, &storeHitsEntry); - poolManager.subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams( - internalErrorSid, false, - static_cast(getPeriodicOperationFrequency()) / static_cast(1000.0))); + poolManager.subscribeForPeriodicPacket(internalErrorSid, false, + static_cast(getPeriodicOperationFrequency()) / static_cast(1000.0), true); internalErrorDataset.setValidity(true, true); return returnvalue::OK; } diff --git a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp index 9cb16c35..b4d64dbc 100644 --- a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -466,7 +466,7 @@ ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &lo LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTHS, &mgmXYZ); localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, &temperature); - poolManager.subscribeForRegularPeriodicPacket({dataset.getSid(), false, 10.0}); + poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false); return returnvalue::OK; } diff --git a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp index a32153eb..f1629d89 100644 --- a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp @@ -310,7 +310,7 @@ void MgmRM3100Handler::modeChanged() { internalState = InternalState::NONE; } ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(RM3100::FIELD_STRENGTHS, &mgmXYZ); - poolManager.subscribeForRegularPeriodicPacket({primaryDataset.getSid(), false, 10.0}); + poolManager.subscribeForPeriodicPacket(primaryDataset.getSid(), false, 10.0, false); return returnvalue::OK; } diff --git a/unittests/datapoollocal/CMakeLists.txt b/unittests/datapoollocal/CMakeLists.txt index 016645fd..4a7ed61a 100644 --- a/unittests/datapoollocal/CMakeLists.txt +++ b/unittests/datapoollocal/CMakeLists.txt @@ -2,5 +2,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testLocalPoolVariable.cpp testLocalPoolVector.cpp testDataSet.cpp - testLocalPoolManager.cpp + testLocalPoolManager.cpp ) diff --git a/unittests/mocks/LocalPoolOwnerBase.h b/unittests/mocks/LocalPoolOwnerBase.h index f1d1225f..9938c517 100644 --- a/unittests/mocks/LocalPoolOwnerBase.h +++ b/unittests/mocks/LocalPoolOwnerBase.h @@ -11,6 +11,7 @@ #include #include "fsfw/datapool/PoolEntry.h" +#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" #include "mocks/MessageQueueMock.h" #include "tests/TestsConfig.h" @@ -104,8 +105,7 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { } ReturnValue_t subscribePeriodicHk(bool enableReporting) { - return poolManager.subscribeForRegularPeriodicPacket( - subdp::RegularHkPeriodicParams(lpool::testSid, enableReporting, 0.2)); + return poolManager.subscribeForPeriodicPacket(lpool::testSid, enableReporting, 0.2, false); } ReturnValue_t subscribeWrapperSetUpdate(MessageQueueId_t receiverId) { @@ -121,17 +121,9 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { ReturnValue_t subscribeWrapperSetUpdateHk(bool diagnostics = false, AcceptsHkPacketsIF* receiver = nullptr) { if (diagnostics) { - auto params = subdp::DiagnosticsHkUpdateParams(lpool::testSid, true); - if (receiver != nullptr) { - params.receiver = receiver->getHkQueue(); - } - return poolManager.subscribeForDiagUpdatePacket(params); + return poolManager.subscribeForUpdatePacket(lpool::testSid, true, true); } else { - auto params = subdp::RegularHkUpdateParams(lpool::testSid, true); - if (receiver != nullptr) { - params.receiver = receiver->getHkQueue(); - } - return poolManager.subscribeForRegularUpdatePacket(params); + return poolManager.subscribeForUpdatePacket(lpool::testSid, true, false); } } From 0cc8af5eb0af8e7be94c59b3b9eebd318a85d7ec Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 10:57:17 +0200 Subject: [PATCH 07/10] afmt --- src/fsfw/datapoollocal/LocalDataPoolManager.cpp | 7 ++++--- src/fsfw/datapoollocal/LocalDataPoolManager.h | 12 ++++++------ src/fsfw/internalerror/InternalErrorReporter.cpp | 3 ++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index daad19be..555a4d68 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -326,9 +326,10 @@ void LocalDataPoolManager::resetHkUpdateResetHelper() { } } -ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, bool enableReporting, - float collectionInterval, bool isDiagnostics, - object_id_t packetDestination) { +ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, bool enableReporting, + float collectionInterval, + bool isDiagnostics, + object_id_t packetDestination) { struct HkReceiver hkReceiver; hkReceiver.dataId.sid = sid; hkReceiver.reportingType = ReportingType::PERIODIC; diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.h b/src/fsfw/datapoollocal/LocalDataPoolManager.h index 8b12e29f..7073474b 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.h +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.h @@ -241,13 +241,13 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces MutexIF* getMutexHandle(); LocalDataPoolManager* getPoolManagerHandle() override; - ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, - float collectionInterval, bool isDiagnostics, - object_id_t packetDestination = objects::NO_OBJECT) override; + ReturnValue_t subscribeForPeriodicPacket( + sid_t sid, bool enableReporting, float collectionInterval, bool isDiagnostics, + object_id_t packetDestination = objects::NO_OBJECT) override; - ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, - bool isDiagnostics, - object_id_t packetDestination = objects::NO_OBJECT) override; + ReturnValue_t subscribeForUpdatePacket( + sid_t sid, bool reportingEnabled, bool isDiagnostics, + object_id_t packetDestination = objects::NO_OBJECT) override; protected: /** Core data structure for the actual pool data */ diff --git a/src/fsfw/internalerror/InternalErrorReporter.cpp b/src/fsfw/internalerror/InternalErrorReporter.cpp index ad6b711c..ea2e09ef 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.cpp +++ b/src/fsfw/internalerror/InternalErrorReporter.cpp @@ -129,7 +129,8 @@ ReturnValue_t InternalErrorReporter::initializeLocalDataPool(localpool::DataPool localDataPoolMap.emplace(errorPoolIds::TM_HITS, &tmHitsEntry); localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, &queueHitsEntry); localDataPoolMap.emplace(errorPoolIds::STORE_HITS, &storeHitsEntry); - poolManager.subscribeForPeriodicPacket(internalErrorSid, false, + poolManager.subscribeForPeriodicPacket( + internalErrorSid, false, static_cast(getPeriodicOperationFrequency()) / static_cast(1000.0), true); internalErrorDataset.setValidity(true, true); return returnvalue::OK; From 9fedd03ed8137ab79a57dbc472248b5207fee8d0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 11:02:21 +0200 Subject: [PATCH 08/10] use cfg struct for local pool API --- .../datapoollocal/LocalDataPoolManager.cpp | 67 ++++++----- src/fsfw/datapoollocal/LocalDataPoolManager.h | 12 +- .../ProvidesDataPoolSubscriptionIF.h | 112 +++++++++++++++--- .../internalerror/InternalErrorReporter.cpp | 4 +- .../devicehandlers/MgmLIS3MDLHandler.cpp | 2 +- .../devicehandlers/MgmRM3100Handler.cpp | 2 +- unittests/datapoollocal/CMakeLists.txt | 2 +- unittests/mocks/LocalPoolOwnerBase.h | 16 ++- 8 files changed, 159 insertions(+), 58 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index d3f866f7..fa76d2a7 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -14,6 +14,7 @@ #include "internal/HasLocalDpIFManagerAttorney.h" #include "internal/LocalPoolDataSetAttorney.h" +// TODO: Get rid of this. This should be a constructor argument, not something hardcoded in any way object_id_t LocalDataPoolManager::defaultHkDestination = objects::PUS_SERVICE_3_HOUSEKEEPING; LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse, @@ -325,28 +326,32 @@ void LocalDataPoolManager::resetHkUpdateResetHelper() { } } -ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, bool enableReporting, - float collectionInterval, - bool isDiagnostics, - object_id_t packetDestination) { +ReturnValue_t LocalDataPoolManager::subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams params) { + return subscribeForPeriodicPacket(params); +} + +ReturnValue_t LocalDataPoolManager::subscribeForDiagPeriodicPacket( + subdp::DiagnosticsHkPeriodicParams params) { + return subscribeForPeriodicPacket(params); +} + +ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(subdp::ParamsBase& params) { struct HkReceiver hkReceiver; - hkReceiver.dataId.sid = sid; + hkReceiver.dataId.sid = params.sid; hkReceiver.reportingType = ReportingType::PERIODIC; hkReceiver.dataType = DataType::DATA_SET; - if (packetDestination != objects::NO_OBJECT) { - auto* receivedHkIF = ObjectManager::instance()->get(packetDestination); - if (receivedHkIF->getHkQueue() == MessageQueueIF::NO_QUEUE) { - hkReceiver.destinationQueue = hkDestinationId; - } else { - hkReceiver.destinationQueue = receivedHkIF->getHkQueue(); - } + if (params.receiver == MessageQueueIF::NO_QUEUE) { + hkReceiver.destinationQueue = hkDestinationId; + } else { + hkReceiver.destinationQueue = params.receiver; } - LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, params.sid); if (dataSet != nullptr) { - LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, enableReporting); - LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics); - LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, collectionInterval, + LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, params.enableReporting); + LocalPoolDataSetAttorney::setDiagnostic(*dataSet, params.isDiagnostics()); + LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, params.collectionInterval, owner->getPeriodicOperationFrequency()); } @@ -354,26 +359,30 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, bool e return returnvalue::OK; } -ReturnValue_t LocalDataPoolManager::subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, - bool isDiagnostics, - object_id_t packetDestination) { +ReturnValue_t LocalDataPoolManager::subscribeForRegularUpdatePacket( + subdp::RegularHkUpdateParams params) { + return subscribeForUpdatePacket(params); +} +ReturnValue_t LocalDataPoolManager::subscribeForDiagUpdatePacket( + subdp::DiagnosticsHkUpdateParams params) { + return subscribeForUpdatePacket(params); +} + +ReturnValue_t LocalDataPoolManager::subscribeForUpdatePacket(subdp::ParamsBase& params) { struct HkReceiver hkReceiver; - hkReceiver.dataId.sid = sid; + hkReceiver.dataId.sid = params.sid; hkReceiver.reportingType = ReportingType::UPDATE_HK; hkReceiver.dataType = DataType::DATA_SET; - if (packetDestination != objects::NO_OBJECT) { - auto* receivedHkIF = ObjectManager::instance()->get(packetDestination); - if (receivedHkIF->getHkQueue() == MessageQueueIF::NO_QUEUE) { - hkReceiver.destinationQueue = hkDestinationId; - } else { - hkReceiver.destinationQueue = receivedHkIF->getHkQueue(); - } + if (params.receiver == MessageQueueIF::NO_QUEUE) { + hkReceiver.destinationQueue = hkDestinationId; + } else { + hkReceiver.destinationQueue = params.receiver; } - LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, params.sid); if (dataSet != nullptr) { LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, true); - LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics); + LocalPoolDataSetAttorney::setDiagnostic(*dataSet, params.isDiagnostics()); } hkReceivers.push_back(hkReceiver); diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.h b/src/fsfw/datapoollocal/LocalDataPoolManager.h index 7073474b..7db079f6 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.h +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.h @@ -241,13 +241,13 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces MutexIF* getMutexHandle(); LocalDataPoolManager* getPoolManagerHandle() override; - ReturnValue_t subscribeForPeriodicPacket( - sid_t sid, bool enableReporting, float collectionInterval, bool isDiagnostics, - object_id_t packetDestination = objects::NO_OBJECT) override; + ReturnValue_t subscribeForRegularPeriodicPacket(subdp::RegularHkPeriodicParams params) override; + ReturnValue_t subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams params) override; + ReturnValue_t subscribeForPeriodicPacket(subdp::ParamsBase& params); - ReturnValue_t subscribeForUpdatePacket( - sid_t sid, bool reportingEnabled, bool isDiagnostics, - object_id_t packetDestination = objects::NO_OBJECT) override; + ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) override; + ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) override; + ReturnValue_t subscribeForUpdatePacket(subdp::ParamsBase& params); protected: /** Core data structure for the actual pool data */ diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index eb4e55b7..baf91796 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -1,24 +1,90 @@ #ifndef FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ #define FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ -#include "../ipc/messageQueueDefinitions.h" -#include "../returnvalues/returnvalue.h" +#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/messageQueueDefinitions.h" +#include "fsfw/returnvalues/returnvalue.h" #include "localPoolDefinitions.h" +namespace subdp { + +struct ParamsBase { + ParamsBase(sid_t sid, bool enableReporting, float collectionInterval, bool diagnostics) + : sid(sid), + enableReporting(enableReporting), + collectionInterval(collectionInterval), + diagnostics(diagnostics) {} + + [[nodiscard]] bool isDiagnostics() const { return diagnostics; } + + sid_t sid; + bool enableReporting; + float collectionInterval; + MessageQueueId_t receiver = MessageQueueIF::NO_QUEUE; + + protected: + bool diagnostics; +}; + +struct RegularHkPeriodicParams : public ParamsBase { + RegularHkPeriodicParams(sid_t sid, bool enableReporting, float collectionInterval) + : ParamsBase(sid, enableReporting, collectionInterval, false) {} +}; + +struct DiagnosticsHkPeriodicParams : public ParamsBase { + DiagnosticsHkPeriodicParams(sid_t sid, bool enableReporting, float collectionInterval) + : ParamsBase(sid, enableReporting, collectionInterval, true) {} +}; + +struct RegularHkUpdateParams : public ParamsBase { + RegularHkUpdateParams(sid_t sid, bool enableReporting) + : ParamsBase(sid, enableReporting, 0.0, false) {} +}; + +struct DiagnosticsHkUpdateParams : public ParamsBase { + DiagnosticsHkUpdateParams(sid_t sid, bool enableReporting) + : ParamsBase(sid, enableReporting, 0.0, true) {} +}; +} // namespace subdp + class ProvidesDataPoolSubscriptionIF { public: - virtual ~ProvidesDataPoolSubscriptionIF(){}; - + virtual ~ProvidesDataPoolSubscriptionIF() = default; /** - * @brief Subscribe for the generation of periodic packets. + * @brief Subscribe for the generation of periodic packets. Used for regular HK packets * @details * This subscription mechanism will generally be used by the data creator * to generate housekeeping packets which are downlinked directly. * @return */ - virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, bool enableReporting, - float collectionInterval, bool isDiagnostics, - object_id_t packetDestination) = 0; + virtual ReturnValue_t subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams params) = 0; + /** + * @brief Subscribe for the generation of periodic packets. Used for diagnostic packets + * @details + * This subscription mechanism will generally be used by the data creator + * to generate housekeeping packets which are downlinked directly. + * @return + */ + virtual ReturnValue_t subscribeForDiagPeriodicPacket( + subdp::DiagnosticsHkPeriodicParams params) = 0; + + [[deprecated( + "Please use the new API which takes all arguments as one wrapper " + "struct")]] virtual ReturnValue_t + subscribeForPeriodicPacket(sid_t sid, bool enableReporting, float collectionInterval, + bool isDiagnostics, + object_id_t packetDestination = objects::NO_OBJECT) { + if (isDiagnostics) { + subdp::DiagnosticsHkPeriodicParams params(sid, enableReporting, collectionInterval); + return subscribeForDiagPeriodicPacket(params); + } else { + subdp::RegularHkPeriodicParams params(sid, enableReporting, collectionInterval); + return subscribeForRegularPeriodicPacket(params); + } + } + /** * @brief Subscribe for the generation of packets if the dataset * is marked as changed. @@ -29,9 +95,28 @@ class ProvidesDataPoolSubscriptionIF { * @param packetDestination * @return */ - virtual ReturnValue_t subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, - bool isDiagnostics, - object_id_t packetDestination) = 0; + virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; + virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; + + // virtual ReturnValue_t + // subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { + // return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); + // } + + [[deprecated( + "Please use the new API which takes all arguments as one wrapper " + "struct")]] virtual ReturnValue_t + subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics, + object_id_t packetDestination = objects::NO_OBJECT) { + if (isDiagnostics) { + subdp::DiagnosticsHkUpdateParams params(sid, reportingEnabled); + return subscribeForDiagUpdatePacket(params); + } else { + subdp::RegularHkUpdateParams params(sid, reportingEnabled); + return subscribeForRegularUpdatePacket(params); + } + } + /** * @brief Subscribe for a notification message which will be sent * if a dataset has changed. @@ -46,8 +131,7 @@ class ProvidesDataPoolSubscriptionIF { * Otherwise, only an notification message is sent. * @return */ - virtual ReturnValue_t subscribeForSetUpdateMessage(const uint32_t setId, - object_id_t destinationObject, + virtual ReturnValue_t subscribeForSetUpdateMessage(uint32_t setId, object_id_t destinationObject, MessageQueueId_t targetQueueId, bool generateSnapshot) = 0; /** @@ -64,7 +148,7 @@ class ProvidesDataPoolSubscriptionIF { * only an notification message is sent. * @return */ - virtual ReturnValue_t subscribeForVariableUpdateMessage(const lp_id_t localPoolId, + virtual ReturnValue_t subscribeForVariableUpdateMessage(lp_id_t localPoolId, object_id_t destinationObject, MessageQueueId_t targetQueueId, bool generateSnapshot) = 0; diff --git a/src/fsfw/internalerror/InternalErrorReporter.cpp b/src/fsfw/internalerror/InternalErrorReporter.cpp index ea2e09ef..b3b77366 100644 --- a/src/fsfw/internalerror/InternalErrorReporter.cpp +++ b/src/fsfw/internalerror/InternalErrorReporter.cpp @@ -129,9 +129,9 @@ ReturnValue_t InternalErrorReporter::initializeLocalDataPool(localpool::DataPool localDataPoolMap.emplace(errorPoolIds::TM_HITS, &tmHitsEntry); localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, &queueHitsEntry); localDataPoolMap.emplace(errorPoolIds::STORE_HITS, &storeHitsEntry); - poolManager.subscribeForPeriodicPacket( + poolManager.subscribeForDiagPeriodicPacket(subdp::DiagnosticsHkPeriodicParams( internalErrorSid, false, - static_cast(getPeriodicOperationFrequency()) / static_cast(1000.0), true); + static_cast(getPeriodicOperationFrequency()) / static_cast(1000.0))); internalErrorDataset.setValidity(true, true); return returnvalue::OK; } diff --git a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp index b4d64dbc..9cb16c35 100644 --- a/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.cpp @@ -466,7 +466,7 @@ ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &lo LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTHS, &mgmXYZ); localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, &temperature); - poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false); + poolManager.subscribeForRegularPeriodicPacket({dataset.getSid(), false, 10.0}); return returnvalue::OK; } diff --git a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp index f1629d89..a32153eb 100644 --- a/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp +++ b/src/fsfw_hal/devicehandlers/MgmRM3100Handler.cpp @@ -310,7 +310,7 @@ void MgmRM3100Handler::modeChanged() { internalState = InternalState::NONE; } ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { localDataPoolMap.emplace(RM3100::FIELD_STRENGTHS, &mgmXYZ); - poolManager.subscribeForPeriodicPacket(primaryDataset.getSid(), false, 10.0, false); + poolManager.subscribeForRegularPeriodicPacket({primaryDataset.getSid(), false, 10.0}); return returnvalue::OK; } diff --git a/unittests/datapoollocal/CMakeLists.txt b/unittests/datapoollocal/CMakeLists.txt index 4a7ed61a..016645fd 100644 --- a/unittests/datapoollocal/CMakeLists.txt +++ b/unittests/datapoollocal/CMakeLists.txt @@ -2,5 +2,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testLocalPoolVariable.cpp testLocalPoolVector.cpp testDataSet.cpp - testLocalPoolManager.cpp + testLocalPoolManager.cpp ) diff --git a/unittests/mocks/LocalPoolOwnerBase.h b/unittests/mocks/LocalPoolOwnerBase.h index 9938c517..f1d1225f 100644 --- a/unittests/mocks/LocalPoolOwnerBase.h +++ b/unittests/mocks/LocalPoolOwnerBase.h @@ -11,7 +11,6 @@ #include #include "fsfw/datapool/PoolEntry.h" -#include "fsfw/housekeeping/AcceptsHkPacketsIF.h" #include "mocks/MessageQueueMock.h" #include "tests/TestsConfig.h" @@ -105,7 +104,8 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { } ReturnValue_t subscribePeriodicHk(bool enableReporting) { - return poolManager.subscribeForPeriodicPacket(lpool::testSid, enableReporting, 0.2, false); + return poolManager.subscribeForRegularPeriodicPacket( + subdp::RegularHkPeriodicParams(lpool::testSid, enableReporting, 0.2)); } ReturnValue_t subscribeWrapperSetUpdate(MessageQueueId_t receiverId) { @@ -121,9 +121,17 @@ class LocalPoolOwnerBase : public SystemObject, public HasLocalDataPoolIF { ReturnValue_t subscribeWrapperSetUpdateHk(bool diagnostics = false, AcceptsHkPacketsIF* receiver = nullptr) { if (diagnostics) { - return poolManager.subscribeForUpdatePacket(lpool::testSid, true, true); + auto params = subdp::DiagnosticsHkUpdateParams(lpool::testSid, true); + if (receiver != nullptr) { + params.receiver = receiver->getHkQueue(); + } + return poolManager.subscribeForDiagUpdatePacket(params); } else { - return poolManager.subscribeForUpdatePacket(lpool::testSid, true, false); + auto params = subdp::RegularHkUpdateParams(lpool::testSid, true); + if (receiver != nullptr) { + params.receiver = receiver->getHkQueue(); + } + return poolManager.subscribeForRegularUpdatePacket(params); } } From aea9db75cb925c92e5e9b574b4d754bd48e51dc6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 11:12:06 +0200 Subject: [PATCH 09/10] better name --- src/fsfw/tmtcservices/VerificationCodes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsfw/tmtcservices/VerificationCodes.h b/src/fsfw/tmtcservices/VerificationCodes.h index 91b76bde..479074eb 100644 --- a/src/fsfw/tmtcservices/VerificationCodes.h +++ b/src/fsfw/tmtcservices/VerificationCodes.h @@ -5,7 +5,7 @@ namespace tcverif { -enum VerifFlags : uint8_t { +enum VerificationFlags : uint8_t { NONE = 0b0000, ACCEPTANCE = 0b0001, START = 0b0010, From a9277622ce13c7e8ece4f0db86ba6bcdcc779e5f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 12:04:15 +0200 Subject: [PATCH 10/10] move data wrapper --- src/fsfw/tmtcpacket/pus/defs.h | 38 -------------- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp | 4 +- src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h | 3 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp | 4 +- src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h | 7 +-- src/fsfw/tmtcservices/tmHelpers.h | 12 ++--- src/fsfw/util/dataWrapper.h | 52 +++++++++++++++++++ .../tmtcservices/testStoreAndSendHelper.cpp | 8 +-- 8 files changed, 72 insertions(+), 56 deletions(-) create mode 100644 src/fsfw/util/dataWrapper.h diff --git a/src/fsfw/tmtcpacket/pus/defs.h b/src/fsfw/tmtcpacket/pus/defs.h index 69b3415c..c5172d8b 100644 --- a/src/fsfw/tmtcpacket/pus/defs.h +++ b/src/fsfw/tmtcpacket/pus/defs.h @@ -13,44 +13,6 @@ using PusChecksumT = uint16_t; //! Version numbers according to ECSS-E-ST-70-41C p.439 enum PusVersion : uint8_t { PUS_A = 1, PUS_C = 2 }; -struct RawData { - const uint8_t* data; - size_t len; -}; - -enum DataTypes { RAW, SERIALIZABLE }; - -union DataUnion { - RawData raw; - SerializeIF* serializable; -}; - -struct DataWrapper { - DataTypes type; - DataUnion dataUnion; - using BufPairT = std::pair; - - [[nodiscard]] size_t getLength() const { - if (type == DataTypes::RAW) { - return dataUnion.raw.len; - } else if (type == DataTypes::SERIALIZABLE and dataUnion.serializable != nullptr) { - return dataUnion.serializable->getSerializedSize(); - } - return 0; - } - - void setRawData(BufPairT bufPair) { - type = DataTypes::RAW; - dataUnion.raw.data = bufPair.first; - dataUnion.raw.len = bufPair.second; - } - - void setSerializable(SerializeIF& serializable) { - type = DataTypes::SERIALIZABLE; - dataUnion.serializable = &serializable; - } -}; - /** * This struct defines the data structure of a Space Packet when accessed * via a pointer. diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp index d85d5b72..14a440a0 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp @@ -37,14 +37,14 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max if (result != returnvalue::OK) { return result; } - if (pusParams.dataWrapper.type == ecss::DataTypes::RAW) { + if (pusParams.dataWrapper.type == util::DataTypes::RAW) { const uint8_t *data = pusParams.dataWrapper.dataUnion.raw.data; if (data != nullptr and userDataLen > 0) { std::memcpy(*buffer, data, userDataLen); *buffer += userDataLen; *size += userDataLen; } - } else if (pusParams.dataWrapper.type == ecss::DataTypes::SERIALIZABLE and + } else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and pusParams.dataWrapper.dataUnion.serializable != nullptr) { result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness); diff --git a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h index 72691c40..4b0d81c8 100644 --- a/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h +++ b/src/fsfw/tmtcpacket/pus/tc/PusTcCreator.h @@ -7,6 +7,7 @@ #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" #include "fsfw/tmtcpacket/pus/defs.h" #include "fsfw/tmtcpacket/pus/tc/PusTcIF.h" +#include "fsfw/util/dataWrapper.h" struct PusTcParams { PusTcParams(uint8_t service_, uint8_t subservice_) : service(service_), subservice(subservice_) {} @@ -15,7 +16,7 @@ struct PusTcParams { uint8_t subservice; uint8_t ackFlags = ecss::ACK_ALL; uint16_t sourceId = 0; - ecss::DataWrapper dataWrapper{}; + util::DataWrapper dataWrapper{}; uint8_t pusVersion = ecss::PusVersion::PUS_C; }; diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index 80853221..b754e990 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -77,12 +77,12 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max } } - if (pusParams.dataWrapper.type == ecss::DataTypes::RAW and + if (pusParams.dataWrapper.type == util::DataTypes::RAW and pusParams.dataWrapper.dataUnion.raw.data != nullptr) { std::memcpy(*buffer, pusParams.dataWrapper.dataUnion.raw.data, userDataLen); *buffer += userDataLen; *size += userDataLen; - } else if (pusParams.dataWrapper.type == ecss::DataTypes::SERIALIZABLE and + } else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and pusParams.dataWrapper.dataUnion.serializable != nullptr) { result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize, streamEndianness); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 706a7b70..8fd4f690 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -4,6 +4,7 @@ #include "PusTmIF.h" #include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h" #include "fsfw/tmtcpacket/pus/CustomUserDataIF.h" +#include "fsfw/util/dataWrapper.h" struct PusTmSecHeader { PusTmSecHeader() = default; @@ -22,19 +23,19 @@ struct PusTmSecHeader { struct PusTmParams { PusTmParams() = default; explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){}; - PusTmParams(PusTmSecHeader secHeader, ecss::DataWrapper dataWrapper) + PusTmParams(PusTmSecHeader secHeader, util::DataWrapper dataWrapper) : secHeader(secHeader), dataWrapper(dataWrapper) {} PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper) : secHeader(service, subservice, timeStamper) {} PusTmParams(uint8_t service, uint8_t subservice, TimeStamperIF* timeStamper, - ecss::DataWrapper dataWrapper_) + util::DataWrapper dataWrapper_) : PusTmParams(service, subservice, timeStamper) { dataWrapper = dataWrapper_; } PusTmSecHeader secHeader; - ecss::DataWrapper dataWrapper{}; + util::DataWrapper dataWrapper{}; }; class TimeStamperIF; diff --git a/src/fsfw/tmtcservices/tmHelpers.h b/src/fsfw/tmtcservices/tmHelpers.h index ab69c9c8..845a73b8 100644 --- a/src/fsfw/tmtcservices/tmHelpers.h +++ b/src/fsfw/tmtcservices/tmHelpers.h @@ -11,13 +11,13 @@ class DataWithObjectIdPrefix : public SerializeIF { public: DataWithObjectIdPrefix(object_id_t objectId, const uint8_t* srcData, size_t srcDataLen) : objectId(objectId) { - dataWrapper.type = ecss::DataTypes::RAW; + dataWrapper.type = util::DataTypes::RAW; dataWrapper.dataUnion.raw.data = srcData; dataWrapper.dataUnion.raw.len = srcDataLen; } DataWithObjectIdPrefix(object_id_t objectId, SerializeIF& serializable) : objectId(objectId) { - dataWrapper.type = ecss::DataTypes::SERIALIZABLE; + dataWrapper.type = util::DataTypes::SERIALIZABLE; dataWrapper.dataUnion.serializable = &serializable; } @@ -26,11 +26,11 @@ class DataWithObjectIdPrefix : public SerializeIF { if (*size + getSerializedSize() > maxSize) { return SerializeIF::BUFFER_TOO_SHORT; } - if (dataWrapper.type != ecss::DataTypes::RAW) { + if (dataWrapper.type != util::DataTypes::RAW) { if ((dataWrapper.dataUnion.raw.data == nullptr) and (dataWrapper.dataUnion.raw.len > 0)) { return returnvalue::FAILED; } - } else if (dataWrapper.type == ecss::DataTypes::SERIALIZABLE) { + } else if (dataWrapper.type == util::DataTypes::SERIALIZABLE) { if (dataWrapper.dataUnion.serializable == nullptr) { return returnvalue::FAILED; } @@ -40,7 +40,7 @@ class DataWithObjectIdPrefix : public SerializeIF { if (result != returnvalue::OK) { return result; } - if (dataWrapper.type != ecss::DataTypes::RAW) { + if (dataWrapper.type != util::DataTypes::RAW) { std::memcpy(*buffer, dataWrapper.dataUnion.raw.data, dataWrapper.dataUnion.raw.len); *buffer += dataWrapper.dataUnion.raw.len; *size += dataWrapper.dataUnion.raw.len; @@ -63,7 +63,7 @@ class DataWithObjectIdPrefix : public SerializeIF { private: object_id_t objectId; - ecss::DataWrapper dataWrapper{}; + util::DataWrapper dataWrapper{}; }; } // namespace telemetry diff --git a/src/fsfw/util/dataWrapper.h b/src/fsfw/util/dataWrapper.h new file mode 100644 index 00000000..f5dab447 --- /dev/null +++ b/src/fsfw/util/dataWrapper.h @@ -0,0 +1,52 @@ +#ifndef FSFW_UTIL_DATAWRAPPER_H +#define FSFW_UTIL_DATAWRAPPER_H + +#include +#include +#include + +#include "fsfw/serialize.h" + +namespace util { + +struct RawData { + const uint8_t* data; + size_t len; +}; + +enum DataTypes { RAW, SERIALIZABLE }; + +union DataUnion { + RawData raw; + SerializeIF* serializable; +}; + +struct DataWrapper { + DataTypes type; + DataUnion dataUnion; + using BufPairT = std::pair; + + [[nodiscard]] size_t getLength() const { + if (type == DataTypes::RAW) { + return dataUnion.raw.len; + } else if (type == DataTypes::SERIALIZABLE and dataUnion.serializable != nullptr) { + return dataUnion.serializable->getSerializedSize(); + } + return 0; + } + + void setRawData(BufPairT bufPair) { + type = DataTypes::RAW; + dataUnion.raw.data = bufPair.first; + dataUnion.raw.len = bufPair.second; + } + + void setSerializable(SerializeIF& serializable) { + type = DataTypes::SERIALIZABLE; + dataUnion.serializable = &serializable; + } +}; + +} // namespace util + +#endif // FSFW_UTIL_DATAWRAPPER_H diff --git a/unittests/tmtcservices/testStoreAndSendHelper.cpp b/unittests/tmtcservices/testStoreAndSendHelper.cpp index 4e1bb4fb..2731b28f 100644 --- a/unittests/tmtcservices/testStoreAndSendHelper.cpp +++ b/unittests/tmtcservices/testStoreAndSendHelper.cpp @@ -44,7 +44,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(creator.getSubService() == 2); REQUIRE(creator.getService() == 17); auto& params = creator.getParams(); - REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW); + REQUIRE(params.dataWrapper.type == util::DataTypes::RAW); REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr); REQUIRE(params.dataWrapper.dataUnion.raw.len == 0); REQUIRE(tmHelper.sendCounter == 0); @@ -65,7 +65,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == returnvalue::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); - REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW); + REQUIRE(params.dataWrapper.type == util::DataTypes::RAW); REQUIRE(params.dataWrapper.dataUnion.raw.data == data.data()); REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size()); } @@ -75,7 +75,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == returnvalue::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); - REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE); + REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE); REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer); } @@ -86,7 +86,7 @@ TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") { REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == returnvalue::OK); auto& creator = storeHelper.getCreatorRef(); auto& params = creator.getParams(); - REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE); + REQUIRE(params.dataWrapper.type == util::DataTypes::SERIALIZABLE); REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId); }