fsfw/src/fsfw/pus/CService201HealthCommanding...

107 lines
4.6 KiB
C++
Raw Normal View History

2021-07-13 20:58:45 +02:00
#include "fsfw/pus/CService201HealthCommanding.h"
2020-12-01 14:59:35 +01:00
2021-07-13 20:58:45 +02:00
#include "fsfw/health/HasHealthIF.h"
#include "fsfw/health/HealthMessage.h"
2022-02-02 10:29:30 +01:00
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/pus/servicepackets/Service201Packets.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
2021-06-05 19:52:38 +02:00
2022-02-02 10:29:30 +01:00
CService201HealthCommanding::CService201HealthCommanding(object_id_t objectId, uint16_t apid,
uint8_t serviceId,
uint8_t numParallelCommands,
uint16_t commandTimeoutSeconds)
: CommandingServiceBase(objectId, apid, serviceId, numParallelCommands, commandTimeoutSeconds) {
2020-12-01 14:59:35 +01:00
}
ReturnValue_t CService201HealthCommanding::isValidSubservice(uint8_t subservice) {
2022-02-02 10:29:30 +01:00
switch (subservice) {
case (Subservice::COMMAND_SET_HEALTH):
case (Subservice::COMMAND_ANNOUNCE_HEALTH):
case (Subservice::COMMAND_ANNOUNCE_HEALTH_ALL):
return RETURN_OK;
default:
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::error << "Invalid Subservice" << std::endl;
#endif
2022-02-02 10:29:30 +01:00
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
}
2020-12-01 14:59:35 +01:00
}
2022-02-02 10:29:30 +01:00
ReturnValue_t CService201HealthCommanding::getMessageQueueAndObject(uint8_t subservice,
const uint8_t *tcData,
size_t tcDataLen,
MessageQueueId_t *id,
object_id_t *objectId) {
if (tcDataLen < sizeof(object_id_t)) {
return CommandingServiceBase::INVALID_TC;
}
SerializeAdapter::deSerialize(objectId, &tcData, &tcDataLen, SerializeIF::Endianness::BIG);
2020-12-01 14:59:35 +01:00
2022-02-02 10:29:30 +01:00
return checkInterfaceAndAcquireMessageQueue(id, objectId);
2020-12-01 14:59:35 +01:00
}
ReturnValue_t CService201HealthCommanding::checkInterfaceAndAcquireMessageQueue(
MessageQueueId_t *messageQueueToSet, const object_id_t *objectId) {
auto *destination = ObjectManager::instance()->get<HasHealthIF>(*objectId);
2022-02-02 10:29:30 +01:00
if (destination == nullptr) {
return CommandingServiceBase::INVALID_OBJECT;
}
2020-12-01 14:59:35 +01:00
2022-02-02 10:29:30 +01:00
*messageQueueToSet = destination->getCommandQueue();
return HasReturnvaluesIF::RETURN_OK;
2020-12-01 14:59:35 +01:00
}
2022-02-02 10:29:30 +01:00
ReturnValue_t CService201HealthCommanding::prepareCommand(CommandMessage *message,
uint8_t subservice, const uint8_t *tcData,
size_t tcDataLen, uint32_t *state,
object_id_t objectId) {
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) {
2020-12-01 14:59:35 +01:00
break;
2022-02-02 10:29:30 +01:00
}
HealthMessage::setHealthMessage(message, HealthMessage::HEALTH_SET,
healthCommand.getHealth());
break;
2020-12-01 14:59:35 +01:00
}
2022-02-02 10:29:30 +01:00
case (Subservice::COMMAND_ANNOUNCE_HEALTH): {
HealthMessage::setHealthMessage(message, HealthMessage::HEALTH_ANNOUNCE);
break;
2020-12-01 14:59:35 +01:00
}
2022-02-02 10:29:30 +01:00
case (Subservice::COMMAND_ANNOUNCE_HEALTH_ALL): {
HealthMessage::setHealthMessage(message, HealthMessage::HEALTH_ANNOUNCE_ALL);
break;
2020-12-01 14:59:35 +01:00
}
default: {
// Should never happen, subservice was already checked
result = RETURN_FAILED;
}
2022-02-02 10:29:30 +01:00
}
return result;
2020-12-01 14:59:35 +01:00
}
2022-02-02 10:29:30 +01:00
ReturnValue_t CService201HealthCommanding::handleReply(const CommandMessage *reply,
Command_t previousCommand, uint32_t *state,
CommandMessage *optionalNextCommand,
object_id_t objectId, bool *isStep) {
Command_t replyId = reply->getCommand();
if (replyId == HealthMessage::REPLY_HEALTH_SET) {
return EXECUTION_COMPLETE;
} else if (replyId == CommandMessageIF::REPLY_REJECTED) {
return reply->getReplyRejectedReason();
}
return CommandingServiceBase::INVALID_REPLY;
2020-12-01 14:59:35 +01:00
}
2020-12-01 15:05:54 +01:00
// Not used for now, health state already reported by event
2022-05-14 11:32:51 +02:00
[[maybe_unused]] ReturnValue_t CService201HealthCommanding::prepareHealthSetReply(
const CommandMessage *reply) {
auto health = static_cast<uint8_t>(HealthMessage::getHealth(reply));
auto oldHealth = static_cast<uint8_t>(HealthMessage::getOldHealth(reply));
2022-02-02 10:29:30 +01:00
HealthSetReply healthSetReply(health, oldHealth);
return sendTmPacket(Subservice::REPLY_HEALTH_SET, &healthSetReply);
2020-12-01 14:59:35 +01:00
}