added health subservices

This commit is contained in:
Robin Müller 2020-10-10 18:09:04 +02:00
parent 01e7a98425
commit b9c7d1bd3f
5 changed files with 54 additions and 31 deletions

View File

@ -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() {}

View File

@ -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:

View File

@ -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<uint8_t>(HealthMessage::getHealth(reply));
uint8_t oldHealth = static_cast<uint8_t>(HealthMessage::getOldHealth(reply));
HealthSetReply healthSetReply(health, oldHealth);
sendTmPacket(Subservice::REPLY_HEALTH_SET, &healthSetReply);
return sendTmPacket(Subservice::REPLY_HEALTH_SET, &healthSetReply);
}

View File

@ -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
};
};

View File

@ -5,10 +5,10 @@
#include "../../serialize/SerializeIF.h"
#include "../../health/HasHealthIF.h"
class HealthCommand: public SerialLinkedListAdapter<SerializeIF> { //!< [EXPORT] : [SUBSERVICE] 1
class HealthSetCommand: public SerialLinkedListAdapter<SerializeIF> { //!< [EXPORT] : [SUBSERVICE] 1
public:
HealthCommand() {
HealthSetCommand() {
setLinks();
}