fsfw/pus/CService200ModeCommanding.cpp

130 lines
4.3 KiB
C++
Raw Normal View History

2020-08-13 20:53:35 +02:00
#include "CService200ModeCommanding.h"
#include "servicepackets/Service200Packets.h"
#include "../modes/HasModesIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../serialize/SerialLinkedListAdapter.h"
#include "../modes/ModeMessage.h"
CService200ModeCommanding::CService200ModeCommanding(object_id_t objectId,
2020-11-09 21:33:09 +01:00
uint16_t apid, uint8_t serviceId, uint8_t numParallelCommands,
uint16_t commandTimeoutSeconds):
2020-08-13 20:53:35 +02:00
CommandingServiceBase(objectId, apid, serviceId,
2020-11-09 21:33:09 +01:00
numParallelCommands, commandTimeoutSeconds) {}
2020-08-13 20:53:35 +02:00
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,
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);
}
ReturnValue_t CService200ModeCommanding::checkInterfaceAndAcquireMessageQueue(
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;
}
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;
}
2021-04-09 15:49:33 +02:00
ModeMessage::setModeMessage(message, ModeMessage::CMD_MODE_COMMAND, modeCommandPacket.getMode(),
2020-08-13 20:53:35 +02:00
modeCommandPacket.getSubmode());
return result;
}
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));
2020-09-29 15:39:24 +02:00
ReturnValue_t result = sendTmPacket(Subservice::REPLY_WRONG_MODE_REPLY, &wrongModeReply);
if(result == RETURN_OK){
// We want to produce an error here in any case because the mode was not correct
return RETURN_FAILED;
}
return result;
2020-08-13 20:53:35 +02:00
}
ReturnValue_t CService200ModeCommanding::prepareCantReachModeReply(
const CommandMessage *reply, object_id_t objectId) {
CantReachModePacket cantReachModePacket(objectId,
ModeMessage::getCantReachModeReason(reply));
2020-09-29 15:39:24 +02:00
ReturnValue_t result = sendTmPacket(Subservice::REPLY_CANT_REACH_MODE,
2020-08-13 20:53:35 +02:00
&cantReachModePacket);
2020-09-29 15:39:24 +02:00
if(result == RETURN_OK){
// We want to produce an error here in any case because the mode was not reached
return RETURN_FAILED;
}
return result;
2020-08-13 20:53:35 +02:00
}