diff --git a/src/fsfw/pus/CServiceHealthCommanding.cpp b/src/fsfw/pus/CServiceHealthCommanding.cpp index 4a2339d9e..8efa3287f 100644 --- a/src/fsfw/pus/CServiceHealthCommanding.cpp +++ b/src/fsfw/pus/CServiceHealthCommanding.cpp @@ -10,9 +10,23 @@ CServiceHealthCommanding::CServiceHealthCommanding(HealthServiceCfg args) : CommandingServiceBase(args.objectId, args.apid, "PUS 201 Health MGMT", args.service, args.numParallelCommands, args.commandTimeoutSeconds), - healthTable(args.table), + healthTableId(args.table), maxNumHealthInfoPerCycle(args.maxNumHealthInfoPerCycle) {} +ReturnValue_t CServiceHealthCommanding::initialize() { + ReturnValue_t result = CommandingServiceBase::initialize(); + if (result != returnvalue::OK) { + return result; + } + + healthTable = ObjectManager::instance()->get(healthTableId); + if(healthTable == nullptr) { + return returnvalue::FAILED; + } + + return returnvalue::OK; +} + ReturnValue_t CServiceHealthCommanding::isValidSubservice(uint8_t subservice) { switch (subservice) { case (Subservice::COMMAND_SET_HEALTH): @@ -134,7 +148,7 @@ void CServiceHealthCommanding::doPeriodicOperation() { ReturnValue_t CServiceHealthCommanding::iterateHealthTable(bool reset) { std::pair pair; - ReturnValue_t result = healthTable.iterate(&pair, reset); + ReturnValue_t result = healthTable->iterate(&pair, reset); if (result != returnvalue::OK) { return result; } else { diff --git a/src/fsfw/pus/CServiceHealthCommanding.h b/src/fsfw/pus/CServiceHealthCommanding.h index 18f6c140f..2cc16589f 100644 --- a/src/fsfw/pus/CServiceHealthCommanding.h +++ b/src/fsfw/pus/CServiceHealthCommanding.h @@ -6,7 +6,7 @@ #include "fsfw/tmtcservices/CommandingServiceBase.h" struct HealthServiceCfg { - HealthServiceCfg(object_id_t objectId, uint16_t apid, HealthTable &healthTable, + HealthServiceCfg(object_id_t objectId, uint16_t apid, object_id_t healthTable, uint16_t maxNumHealthInfoPerCycle) : objectId(objectId), apid(apid), @@ -14,7 +14,7 @@ struct HealthServiceCfg { maxNumHealthInfoPerCycle(maxNumHealthInfoPerCycle) {} object_id_t objectId; uint16_t apid; - HealthTable &table; + object_id_t table; uint16_t maxNumHealthInfoPerCycle; uint8_t service = 201; uint8_t numParallelCommands = 4; @@ -40,6 +40,8 @@ class CServiceHealthCommanding : public CommandingServiceBase { CServiceHealthCommanding(HealthServiceCfg args); ~CServiceHealthCommanding() override = default; + ReturnValue_t initialize() override; + protected: /* CSB abstract function implementations */ ReturnValue_t isValidSubservice(uint8_t subservice) override; @@ -57,7 +59,8 @@ class CServiceHealthCommanding : public CommandingServiceBase { void doPeriodicOperation() override; private: - HealthTable &healthTable; + const object_id_t healthTableId; + HealthTable *healthTable; uint16_t maxNumHealthInfoPerCycle = 0; bool reportAllHealth = false; ReturnValue_t iterateHealthTable(bool reset);