From b9c7d1bd3f77f8d2da1e7376ef55df99ea26ec92 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 10 Oct 2020 18:09:04 +0200 Subject: [PATCH] added health subservices --- pus/CService200ModeCommanding.cpp | 5 ++- pus/CService200ModeCommanding.h | 5 +-- pus/CService201HealthCommanding.cpp | 54 +++++++++++++++++--------- pus/CService201HealthCommanding.h | 17 +++++--- pus/servicepackets/Service201Packets.h | 4 +- 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/pus/CService200ModeCommanding.cpp b/pus/CService200ModeCommanding.cpp index c63b47a6..c4e99359 100644 --- a/pus/CService200ModeCommanding.cpp +++ b/pus/CService200ModeCommanding.cpp @@ -7,9 +7,10 @@ #include "../modes/ModeMessage.h" CService200ModeCommanding::CService200ModeCommanding(object_id_t objectId, - uint16_t apid, uint8_t serviceId): + uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands, + uint16_t commandTimeoutSeconds): CommandingServiceBase(objectId, apid, serviceId, - NUMBER_OF_PARALLEL_COMMANDS,COMMAND_TIMEOUT_SECONDS) {} + numParallelCommands, commandTimeoutSeconds) {} CService200ModeCommanding::~CService200ModeCommanding() {} diff --git a/pus/CService200ModeCommanding.h b/pus/CService200ModeCommanding.h index c86d7b84..84040212 100644 --- a/pus/CService200ModeCommanding.h +++ b/pus/CService200ModeCommanding.h @@ -15,11 +15,10 @@ */ class CService200ModeCommanding: public CommandingServiceBase { public: - static constexpr uint8_t NUMBER_OF_PARALLEL_COMMANDS = 4; - static constexpr uint16_t COMMAND_TIMEOUT_SECONDS = 60; CService200ModeCommanding(object_id_t objectId, - uint16_t apid, uint8_t serviceId); + uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands = 4, + uint16_t commandTimeoutSeconds = 60); virtual~ CService200ModeCommanding(); protected: diff --git a/pus/CService201HealthCommanding.cpp b/pus/CService201HealthCommanding.cpp index 7e68533d..db43db89 100644 --- a/pus/CService201HealthCommanding.cpp +++ b/pus/CService201HealthCommanding.cpp @@ -6,9 +6,10 @@ #include "servicepackets/Service201Packets.h" CService201HealthCommanding::CService201HealthCommanding(object_id_t objectId, - uint16_t apid, uint8_t serviceId): + uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands, + uint16_t commandTimeoutSeconds): CommandingServiceBase(objectId, apid, serviceId, - NUMBER_OF_PARALLEL_COMMANDS,COMMAND_TIMEOUT_SECONDS) { + numParallelCommands, commandTimeoutSeconds) { } CService201HealthCommanding::~CService201HealthCommanding() { @@ -17,6 +18,8 @@ CService201HealthCommanding::~CService201HealthCommanding() { ReturnValue_t CService201HealthCommanding::isValidSubservice(uint8_t subservice) { switch(subservice) { case(Subservice::COMMAND_SET_HEALTH): + case(Subservice::COMMAND_ANNOUNCE_HEALTH): + case(Subservice::COMMAND_ANNOUNCE_HEALTH_ALL): return RETURN_OK; default: sif::error << "Invalid Subservice" << std::endl; @@ -47,19 +50,34 @@ ReturnValue_t CService201HealthCommanding::checkInterfaceAndAcquireMessageQueue( return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t CService201HealthCommanding::prepareCommand - (CommandMessage* message, uint8_t subservice, const uint8_t *tcData, +ReturnValue_t CService201HealthCommanding::prepareCommand( + CommandMessage* message, uint8_t subservice, const uint8_t *tcData, size_t tcDataLen, uint32_t *state, object_id_t objectId) { - HealthCommand healthCommand; - ReturnValue_t result = healthCommand.deSerialize(&tcData, &tcDataLen, - SerializeIF::Endianness::BIG); - if (result != RETURN_OK) { - return result; - } else { - HealthMessage::setHealthMessage(message, HealthMessage::HEALTH_SET, - healthCommand.getHealth()); - return result; - } + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + switch(subservice) { + case(Subservice::COMMAND_SET_HEALTH): { + HealthSetCommand healthCommand; + result = healthCommand.deSerialize(&tcData, &tcDataLen, + SerializeIF::Endianness::BIG); + if (result != RETURN_OK) { + break; + } + HealthMessage::setHealthMessage(message, HealthMessage::HEALTH_SET, + healthCommand.getHealth()); + break; + } + case(Subservice::COMMAND_ANNOUNCE_HEALTH): { + HealthMessage::setHealthMessage(message, + HealthMessage::HEALTH_ANNOUNCE); + break; + } + case(Subservice::COMMAND_ANNOUNCE_HEALTH_ALL): { + HealthMessage::setHealthMessage(message, + HealthMessage::HEALTH_ANNOUNCE_ALL); + break; + } + } + return result; } ReturnValue_t CService201HealthCommanding::handleReply @@ -68,17 +86,17 @@ ReturnValue_t CService201HealthCommanding::handleReply object_id_t objectId, bool *isStep) { Command_t replyId = reply->getCommand(); if (replyId == HealthMessage::REPLY_HEALTH_SET) { - prepareHealthSetReply(reply); + return prepareHealthSetReply(reply); } - return RETURN_OK; + return CommandingServiceBase::INVALID_REPLY; } -void CService201HealthCommanding::prepareHealthSetReply( +ReturnValue_t CService201HealthCommanding::prepareHealthSetReply( const CommandMessage* reply) { prepareHealthSetReply(reply); uint8_t health = static_cast(HealthMessage::getHealth(reply)); uint8_t oldHealth = static_cast(HealthMessage::getOldHealth(reply)); HealthSetReply healthSetReply(health, oldHealth); - sendTmPacket(Subservice::REPLY_HEALTH_SET, &healthSetReply); + return sendTmPacket(Subservice::REPLY_HEALTH_SET, &healthSetReply); } diff --git a/pus/CService201HealthCommanding.h b/pus/CService201HealthCommanding.h index 100f675e..124e2ac7 100644 --- a/pus/CService201HealthCommanding.h +++ b/pus/CService201HealthCommanding.h @@ -19,11 +19,10 @@ */ class CService201HealthCommanding: public CommandingServiceBase { public: - static const uint8_t NUMBER_OF_PARALLEL_COMMANDS = 4; - static const uint16_t COMMAND_TIMEOUT_SECONDS = 60; CService201HealthCommanding(object_id_t objectId, uint16_t apid, - uint8_t serviceId); + uint8_t serviceId, uint8_t numParallelCommands = 4, + uint16_t commandTimeoutSeconds = 60); virtual~ CService201HealthCommanding(); protected: /* CSB abstract function implementations */ @@ -47,11 +46,17 @@ private: ReturnValue_t checkInterfaceAndAcquireMessageQueue( MessageQueueId_t* MessageQueueToSet, object_id_t* objectId); - void prepareHealthSetReply(const CommandMessage *reply); + ReturnValue_t prepareHealthSetReply(const CommandMessage *reply); enum Subservice { - COMMAND_SET_HEALTH = 1, //!< [EXPORT] : [TC] Set health of target object - REPLY_HEALTH_SET = 2 //!< [EXPORT] : [TM] Reply to health set command which also provides old health + //! [EXPORT] : [TC] Set health of target object + COMMAND_SET_HEALTH = 1, + //! [EXPORT] : [TM] Reply to health set command which also provides old health + REPLY_HEALTH_SET = 2, + //! [EXPORT] : [TC] Commands object to announce their health as an event + COMMAND_ANNOUNCE_HEALTH = 3, + //! [EXPORT] : [TC] Commands all objects in the health map to announce their health + COMMAND_ANNOUNCE_HEALTH_ALL = 4 }; }; diff --git a/pus/servicepackets/Service201Packets.h b/pus/servicepackets/Service201Packets.h index 8dce88e5..aed821f9 100644 --- a/pus/servicepackets/Service201Packets.h +++ b/pus/servicepackets/Service201Packets.h @@ -5,10 +5,10 @@ #include "../../serialize/SerializeIF.h" #include "../../health/HasHealthIF.h" -class HealthCommand: public SerialLinkedListAdapter { //!< [EXPORT] : [SUBSERVICE] 1 +class HealthSetCommand: public SerialLinkedListAdapter { //!< [EXPORT] : [SUBSERVICE] 1 public: - HealthCommand() { + HealthSetCommand() { setLinks(); }