fsfw/pus/CService200ModeCommanding.cpp

120 lines
4.1 KiB
C++
Raw Normal View History

2020-07-10 00:19:25 +02:00
#include <framework/pus/CService200ModeCommanding.h>
#include <framework/pus/servicepackets/Service200Packets.h>
#include <framework/modes/HasModesIF.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/serialize/SerialLinkedListAdapter.h>
#include <framework/modes/ModeMessage.h>
CService200ModeCommanding::CService200ModeCommanding(object_id_t objectId,
uint16_t apid, uint8_t serviceId):
CommandingServiceBase(objectId, apid, serviceId,
NUMBER_OF_PARALLEL_COMMANDS,COMMAND_TIMEOUT_SECONDS) {}
CService200ModeCommanding::~CService200ModeCommanding() {}
ReturnValue_t CService200ModeCommanding::isValidSubservice(uint8_t subservice) {
switch(subservice) {
case(Subservice::COMMAND_MODE_COMMAND):
case(Subservice::COMMAND_MODE_READ):
case(Subservice::COMMAND_MODE_ANNCOUNCE):
return RETURN_OK;
default:
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
}
}
ReturnValue_t CService200ModeCommanding::getMessageQueueAndObject(
uint8_t subservice, const uint8_t *tcData, size_t tcDataLen,
2020-07-10 03:16:08 +02:00
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);
return checkInterfaceAndAcquireMessageQueue(id,objectId);
2020-07-10 00:19:25 +02:00
}
ReturnValue_t CService200ModeCommanding::checkInterfaceAndAcquireMessageQueue(
2020-07-10 03:16:08 +02:00
MessageQueueId_t* messageQueueToSet, object_id_t* objectId) {
HasModesIF * destination = objectManager->get<HasModesIF>(*objectId);
if(destination == nullptr) {
return CommandingServiceBase::INVALID_OBJECT;
}
*messageQueueToSet = destination->getCommandQueue();
return HasReturnvaluesIF::RETURN_OK;
2020-07-10 00:19:25 +02:00
}
ReturnValue_t CService200ModeCommanding::prepareCommand(
CommandMessage* message,uint8_t subservice, const uint8_t *tcData,
size_t tcDataLen, uint32_t *state, object_id_t objectId) {
ModePacket modeCommandPacket;
ReturnValue_t result = modeCommandPacket.deSerialize(&tcData,
&tcDataLen, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
return result;
}
2020-07-10 03:16:08 +02:00
ModeMessage::setModeMessage(dynamic_cast<CommandMessage*>(message),
ModeMessage::CMD_MODE_COMMAND, modeCommandPacket.getMode(),
modeCommandPacket.getSubmode());
return result;
2020-07-10 00:19:25 +02:00
}
ReturnValue_t CService200ModeCommanding::handleReply(
const CommandMessage* reply, Command_t previousCommand,
uint32_t *state, CommandMessage* optionalNextCommand,
object_id_t objectId, bool *isStep) {
Command_t replyId = reply->getCommand();
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
switch(replyId) {
case(ModeMessage::REPLY_MODE_REPLY): {
result = prepareModeReply(reply, objectId);
break;
}
case(ModeMessage::REPLY_WRONG_MODE_REPLY): {
result = prepareWrongModeReply(reply, objectId);
break;
}
case(ModeMessage::REPLY_CANT_REACH_MODE): {
result = prepareCantReachModeReply(reply, objectId);
break;
}
case(ModeMessage::REPLY_MODE_INFO):
result = INVALID_REPLY;
break;
default:
result = RETURN_FAILED;
}
return result;
}
ReturnValue_t CService200ModeCommanding::prepareModeReply(
const CommandMessage *reply, object_id_t objectId) {
ModePacket modeReplyPacket(objectId,
ModeMessage::getMode(reply),
ModeMessage::getSubmode(reply));
return sendTmPacket(Subservice::REPLY_MODE_REPLY, &modeReplyPacket);
}
ReturnValue_t CService200ModeCommanding::prepareWrongModeReply(
const CommandMessage *reply, object_id_t objectId) {
ModePacket wrongModeReply(objectId, ModeMessage::getMode(reply),
ModeMessage::getSubmode(reply));
return sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, &wrongModeReply);
}
ReturnValue_t CService200ModeCommanding::prepareCantReachModeReply(
const CommandMessage *reply, object_id_t objectId) {
CantReachModePacket cantReachModePacket(objectId,
ModeMessage::getCantReachModeReason(reply));
return sendTmPacket(Subservice::REPLY_CANT_REACH_MODE,
&cantReachModePacket);
}