update tmtcservices module

This commit is contained in:
Robin Müller 2021-10-20 16:57:04 +02:00
parent eb00c50950
commit 96e56ddc64
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
7 changed files with 772 additions and 771 deletions

View File

@ -13,300 +13,300 @@ object_id_t CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT;
object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; object_id_t CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT;
CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId,
uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands, uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, size_t queueDepth) : uint16_t commandTimeoutSeconds, size_t queueDepth) :
SystemObject(setObjectId), apid(apid), service(service), SystemObject(setObjectId), apid(apid), service(service),
timeoutSeconds(commandTimeoutSeconds), timeoutSeconds(commandTimeoutSeconds),
commandMap(numberOfParallelCommands) { commandMap(numberOfParallelCommands) {
commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth);
} }
void CommandingServiceBase::setPacketSource(object_id_t packetSource) { void CommandingServiceBase::setPacketSource(object_id_t packetSource) {
this->packetSource = packetSource; this->packetSource = packetSource;
} }
void CommandingServiceBase::setPacketDestination( void CommandingServiceBase::setPacketDestination(
object_id_t packetDestination) { object_id_t packetDestination) {
this->packetDestination = packetDestination; this->packetDestination = packetDestination;
} }
CommandingServiceBase::~CommandingServiceBase() { CommandingServiceBase::~CommandingServiceBase() {
QueueFactory::instance()->deleteMessageQueue(commandQueue); QueueFactory::instance()->deleteMessageQueue(commandQueue);
QueueFactory::instance()->deleteMessageQueue(requestQueue); QueueFactory::instance()->deleteMessageQueue(requestQueue);
} }
ReturnValue_t CommandingServiceBase::performOperation(uint8_t opCode) { ReturnValue_t CommandingServiceBase::performOperation(uint8_t opCode) {
handleCommandQueue(); handleCommandQueue();
handleRequestQueue(); handleRequestQueue();
checkTimeout(); checkTimeout();
doPeriodicOperation(); doPeriodicOperation();
return RETURN_OK; return RETURN_OK;
} }
uint16_t CommandingServiceBase::getIdentifier() { uint16_t CommandingServiceBase::getIdentifier() {
return service; return service;
} }
MessageQueueId_t CommandingServiceBase::getRequestQueue() { MessageQueueId_t CommandingServiceBase::getRequestQueue() {
return requestQueue->getId(); return requestQueue->getId();
} }
ReturnValue_t CommandingServiceBase::initialize() { ReturnValue_t CommandingServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize(); ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
if(packetDestination == objects::NO_OBJECT) { if(packetDestination == objects::NO_OBJECT) {
packetDestination = defaultPacketDestination; packetDestination = defaultPacketDestination;
} }
AcceptsTelemetryIF* packetForwarding = AcceptsTelemetryIF* packetForwarding =
ObjectManager::instance()->get<AcceptsTelemetryIF>(packetDestination); ObjectManager::instance()->get<AcceptsTelemetryIF>(packetDestination);
if(packetSource == objects::NO_OBJECT) { if(packetSource == objects::NO_OBJECT) {
packetSource = defaultPacketSource; packetSource = defaultPacketSource;
} }
PUSDistributorIF* distributor = ObjectManager::instance()->get<PUSDistributorIF>( PUSDistributorIF* distributor = ObjectManager::instance()->get<PUSDistributorIF>(
packetSource); packetSource);
if (packetForwarding == nullptr or distributor == nullptr) { if (packetForwarding == nullptr or distributor == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CommandingServiceBase::intialize: Packet source or " sif::error << "CommandingServiceBase::intialize: Packet source or "
"packet destination invalid!" << std::endl; "packet destination invalid!" << std::endl;
#endif #endif
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
distributor->registerService(this); distributor->registerService(this);
requestQueue->setDefaultDestination( requestQueue->setDefaultDestination(
packetForwarding->getReportReceptionQueue()); packetForwarding->getReportReceptionQueue());
IPCStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE); IPCStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
TCStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE); TCStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (IPCStore == nullptr or TCStore == nullptr) { if (IPCStore == nullptr or TCStore == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CommandingServiceBase::intialize: IPC store or TC store " sif::error << "CommandingServiceBase::intialize: IPC store or TC store "
"not initialized yet!" << std::endl; "not initialized yet!" << std::endl;
#endif #endif
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
return RETURN_OK; return RETURN_OK;
} }
void CommandingServiceBase::handleCommandQueue() { void CommandingServiceBase::handleCommandQueue() {
CommandMessage reply; CommandMessage reply;
ReturnValue_t result = RETURN_FAILED; ReturnValue_t result = RETURN_FAILED;
while(true) { while(true) {
result = commandQueue->receiveMessage(&reply); result = commandQueue->receiveMessage(&reply);
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
handleCommandMessage(&reply); handleCommandMessage(&reply);
continue; continue;
} }
else if(result == MessageQueueIF::EMPTY) { else if(result == MessageQueueIF::EMPTY) {
break; break;
} }
else { else {
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CommandingServiceBase::handleCommandQueue: Receiving message failed" sif::warning << "CommandingServiceBase::handleCommandQueue: Receiving message failed"
"with code" << result << std::endl; "with code" << result << std::endl;
#else #else
sif::printWarning("CommandingServiceBase::handleCommandQueue: Receiving message " sif::printWarning("CommandingServiceBase::handleCommandQueue: Receiving message "
"failed with code %d\n", result); "failed with code %d\n", result);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */ #endif /* FSFW_VERBOSE_LEVEL >= 1 */
break; break;
} }
} }
} }
void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) { void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) {
bool isStep = false; bool isStep = false;
CommandMessage nextCommand; CommandMessage nextCommand;
CommandMapIter iter = commandMap.find(reply->getSender()); CommandMapIter iter = commandMap.find(reply->getSender());
// handle unrequested reply first // handle unrequested reply first
if (reply->getSender() == MessageQueueIF::NO_QUEUE or if (reply->getSender() == MessageQueueIF::NO_QUEUE or
iter == commandMap.end()) { iter == commandMap.end()) {
handleUnrequestedReply(reply); handleUnrequestedReply(reply);
return; return;
} }
nextCommand.setCommand(CommandMessage::CMD_NONE); nextCommand.setCommand(CommandMessage::CMD_NONE);
// Implemented by child class, specifies what to do with reply. // Implemented by child class, specifies what to do with reply.
ReturnValue_t result = handleReply(reply, iter->second.command, &iter->second.state, ReturnValue_t result = handleReply(reply, iter->second.command, &iter->second.state,
&nextCommand, iter->second.objectId, &isStep); &nextCommand, iter->second.objectId, &isStep);
/* If the child implementation does not implement special handling for /* If the child implementation does not implement special handling for
* rejected replies (RETURN_FAILED or INVALID_REPLY is returned), a * rejected replies (RETURN_FAILED or INVALID_REPLY is returned), a
* failure verification will be generated with the reason as the * failure verification will be generated with the reason as the
* return code and the initial command as failure parameter 1 */ * return code and the initial command as failure parameter 1 */
if((reply->getCommand() == CommandMessage::REPLY_REJECTED) and if((reply->getCommand() == CommandMessage::REPLY_REJECTED) and
(result == RETURN_FAILED or result == INVALID_REPLY)) { (result == RETURN_FAILED or result == INVALID_REPLY)) {
result = reply->getReplyRejectedReason(); result = reply->getReplyRejectedReason();
failureParameter1 = iter->second.command; failureParameter1 = iter->second.command;
} }
switch (result) { switch (result) {
case EXECUTION_COMPLETE: case EXECUTION_COMPLETE:
case RETURN_OK: case RETURN_OK:
case NO_STEP_MESSAGE: case NO_STEP_MESSAGE:
// handle result of reply handler implemented by developer. // handle result of reply handler implemented by developer.
handleReplyHandlerResult(result, iter, &nextCommand, reply, isStep); handleReplyHandlerResult(result, iter, &nextCommand, reply, isStep);
break; break;
case INVALID_REPLY: case INVALID_REPLY:
//might be just an unrequested reply at a bad moment //might be just an unrequested reply at a bad moment
handleUnrequestedReply(reply); handleUnrequestedReply(reply);
break; break;
default: default:
if (isStep) { if (isStep) {
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
tc_verification::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags, tc_verification::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags,
iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl,
result, ++iter->second.step, failureParameter1, result, ++iter->second.step, failureParameter1,
failureParameter2); failureParameter2);
} else { } else {
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
tc_verification::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, tc_verification::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags,
iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl,
result, 0, failureParameter1, failureParameter2); result, 0, failureParameter1, failureParameter2);
} }
failureParameter1 = 0; failureParameter1 = 0;
failureParameter2 = 0; failureParameter2 = 0;
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
break; break;
} }
} }
void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result, void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
CommandMapIter iter, CommandMessage* nextCommand, CommandMapIter iter, CommandMessage* nextCommand,
CommandMessage* reply, bool& isStep) { CommandMessage* reply, bool& isStep) {
iter->second.command = nextCommand->getCommand(); iter->second.command = nextCommand->getCommand();
// In case a new command is to be sent immediately, this is performed here. // In case a new command is to be sent immediately, this is performed here.
// If no new command is sent, only analyse reply result by initializing // If no new command is sent, only analyse reply result by initializing
// sendResult as RETURN_OK // sendResult as RETURN_OK
ReturnValue_t sendResult = RETURN_OK; ReturnValue_t sendResult = RETURN_OK;
if (nextCommand->getCommand() != CommandMessage::CMD_NONE) { if (nextCommand->getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage(reply->getSender(), sendResult = commandQueue->sendMessage(reply->getSender(),
nextCommand); nextCommand);
} }
if (sendResult == RETURN_OK) { if (sendResult == RETURN_OK) {
if (isStep and result != NO_STEP_MESSAGE) { if (isStep and result != NO_STEP_MESSAGE) {
verificationReporter.sendSuccessReport( verificationReporter.sendSuccessReport(
tc_verification::PROGRESS_SUCCESS, tc_verification::PROGRESS_SUCCESS,
iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId,
iter->second.tcInfo.tcSequenceControl, ++iter->second.step); iter->second.tcInfo.tcSequenceControl, ++iter->second.step);
} }
else { else {
verificationReporter.sendSuccessReport( verificationReporter.sendSuccessReport(
tc_verification::COMPLETION_SUCCESS, tc_verification::COMPLETION_SUCCESS,
iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId,
iter->second.tcInfo.tcSequenceControl, 0); iter->second.tcInfo.tcSequenceControl, 0);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
} }
else { else {
if (isStep) { if (isStep) {
nextCommand->clearCommandMessage(); nextCommand->clearCommandMessage();
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
tc_verification::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags, tc_verification::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags,
iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcPacketId,
iter->second.tcInfo.tcSequenceControl, sendResult, iter->second.tcInfo.tcSequenceControl, sendResult,
++iter->second.step, failureParameter1, failureParameter2); ++iter->second.step, failureParameter1, failureParameter2);
} else { } else {
nextCommand->clearCommandMessage(); nextCommand->clearCommandMessage();
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
tc_verification::COMPLETION_FAILURE, tc_verification::COMPLETION_FAILURE,
iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId, iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId,
iter->second.tcInfo.tcSequenceControl, sendResult, 0, iter->second.tcInfo.tcSequenceControl, sendResult, 0,
failureParameter1, failureParameter2); failureParameter1, failureParameter2);
} }
failureParameter1 = 0; failureParameter1 = 0;
failureParameter2 = 0; failureParameter2 = 0;
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
} }
void CommandingServiceBase::handleRequestQueue() { void CommandingServiceBase::handleRequestQueue() {
TmTcMessage message; TmTcMessage message;
ReturnValue_t result; ReturnValue_t result;
store_address_t address; store_address_t address;
TcPacketStoredPus packet; TcPacketStoredPus packet;
MessageQueueId_t queue; MessageQueueId_t queue;
object_id_t objectId; object_id_t objectId;
for (result = requestQueue->receiveMessage(&message); result == RETURN_OK; for (result = requestQueue->receiveMessage(&message); result == RETURN_OK;
result = requestQueue->receiveMessage(&message)) { result = requestQueue->receiveMessage(&message)) {
address = message.getStorageId(); address = message.getStorageId();
packet.setStoreAddress(address); packet.setStoreAddress(address, &packet);
if ((packet.getSubService() == 0) if ((packet.getSubService() == 0)
or (isValidSubservice(packet.getSubService()) != RETURN_OK)) { or (isValidSubservice(packet.getSubService()) != RETURN_OK)) {
rejectPacket(tc_verification::START_FAILURE, &packet, INVALID_SUBSERVICE); rejectPacket(tc_verification::START_FAILURE, &packet, INVALID_SUBSERVICE);
continue; continue;
} }
result = getMessageQueueAndObject(packet.getSubService(), result = getMessageQueueAndObject(packet.getSubService(),
packet.getApplicationData(), packet.getApplicationDataSize(), packet.getApplicationData(), packet.getApplicationDataSize(),
&queue, &objectId); &queue, &objectId);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
rejectPacket(tc_verification::START_FAILURE, &packet, result); rejectPacket(tc_verification::START_FAILURE, &packet, result);
continue; continue;
} }
//Is a command already active for the target object? //Is a command already active for the target object?
CommandMapIter iter; CommandMapIter iter;
iter = commandMap.find(queue); iter = commandMap.find(queue);
if (iter != commandMap.end()) { if (iter != commandMap.end()) {
result = iter->second.fifo.insert(address); result = iter->second.fifo.insert(address);
if (result != RETURN_OK) { if (result != RETURN_OK) {
rejectPacket(tc_verification::START_FAILURE, &packet, OBJECT_BUSY); rejectPacket(tc_verification::START_FAILURE, &packet, OBJECT_BUSY);
} }
} else { } else {
CommandInfo newInfo; //Info will be set by startExecution if neccessary CommandInfo newInfo; //Info will be set by startExecution if neccessary
newInfo.objectId = objectId; newInfo.objectId = objectId;
result = commandMap.insert(queue, newInfo, &iter); result = commandMap.insert(queue, newInfo, &iter);
if (result != RETURN_OK) { if (result != RETURN_OK) {
rejectPacket(tc_verification::START_FAILURE, &packet, BUSY); rejectPacket(tc_verification::START_FAILURE, &packet, BUSY);
} else { } else {
startExecution(&packet, iter); startExecution(&packet, iter);
} }
} }
} }
} }
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
const uint8_t* data, size_t dataLen, const uint8_t* headerData, const uint8_t* data, size_t dataLen, const uint8_t* headerData,
size_t headerSize) { size_t headerSize) {
#if FSFW_USE_PUS_C_TELEMETRY == 0 #if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice, TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, headerData, headerSize); this->tmPacketCounter, data, dataLen, headerData, headerSize);
#else #else
TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice, TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, headerData, headerSize); this->tmPacketCounter, data, dataLen, headerData, headerSize);
#endif #endif
ReturnValue_t result = tmPacketStored.sendPacket( ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId()); requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) { if (result == HasReturnvaluesIF::RETURN_OK) {
this->tmPacketCounter++; this->tmPacketCounter++;
} }
return result; return result;
} }
@ -316,7 +316,7 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
uint8_t* pBuffer = buffer; uint8_t* pBuffer = buffer;
size_t size = 0; size_t size = 0;
SerializeAdapter::serialize(&objectId, &pBuffer, &size, SerializeAdapter::serialize(&objectId, &pBuffer, &size,
sizeof(object_id_t), SerializeIF::Endianness::BIG); sizeof(object_id_t), SerializeIF::Endianness::BIG);
#if FSFW_USE_PUS_C_TELEMETRY == 0 #if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice, TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, buffer, size); this->tmPacketCounter, data, dataLen, buffer, size);
@ -351,95 +351,96 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
} }
void CommandingServiceBase::startExecution(TcPacketStoredBase *storedPacket, void CommandingServiceBase::startExecution(TcPacketStoredPus* storedPacket,
CommandMapIter iter) { CommandMapIter iter) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
CommandMessage command; CommandMessage command;
TcPacketBase* tcPacketBase = storedPacket->getPacketBase(); //TcPacketPusBase* tcPacketBase = storedPacket->getPacketBase();
if(tcPacketBase == nullptr) { if(storedPacket == nullptr) {
return; return;
} }
iter->second.subservice = tcPacketBase->getSubService(); iter->second.subservice = storedPacket->getSubService();
result = prepareCommand(&command, iter->second.subservice, result = prepareCommand(&command, iter->second.subservice,
tcPacketBase->getApplicationData(), storedPacket->getApplicationData(),
tcPacketBase->getApplicationDataSize(), &iter->second.state, storedPacket->getApplicationDataSize(), &iter->second.state,
iter->second.objectId); iter->second.objectId);
ReturnValue_t sendResult = RETURN_OK; ReturnValue_t sendResult = RETURN_OK;
switch (result) { switch (result) {
case RETURN_OK: case RETURN_OK:
if (command.getCommand() != CommandMessage::CMD_NONE) { if (command.getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage(iter.value->first, sendResult = commandQueue->sendMessage(iter.value->first,
&command); &command);
} }
if (sendResult == RETURN_OK) { if (sendResult == RETURN_OK) {
Clock::getUptime(&iter->second.uptimeOfStart); Clock::getUptime(&iter->second.uptimeOfStart);
iter->second.step = 0; iter->second.step = 0;
iter->second.subservice = tcPacketBase->getSubService(); iter->second.subservice = storedPacket->getSubService();
iter->second.command = command.getCommand(); iter->second.command = command.getCommand();
iter->second.tcInfo.ackFlags = tcPacketBase->getAcknowledgeFlags(); iter->second.tcInfo.ackFlags = storedPacket->getAcknowledgeFlags();
iter->second.tcInfo.tcPacketId = tcPacketBase->getPacketId(); iter->second.tcInfo.tcPacketId = storedPacket->getPacketId();
iter->second.tcInfo.tcSequenceControl = iter->second.tcInfo.tcSequenceControl =
tcPacketBase->getPacketSequenceControl(); storedPacket->getPacketSequenceControl();
acceptPacket(tc_verification::START_SUCCESS, storedPacket); acceptPacket(tc_verification::START_SUCCESS, storedPacket);
} else { } else {
command.clearCommandMessage(); command.clearCommandMessage();
rejectPacket(tc_verification::START_FAILURE, storedPacket, sendResult); rejectPacket(tc_verification::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
break; break;
case EXECUTION_COMPLETE: case EXECUTION_COMPLETE:
if (command.getCommand() != CommandMessage::CMD_NONE) { if (command.getCommand() != CommandMessage::CMD_NONE) {
//Fire-and-forget command. //Fire-and-forget command.
sendResult = commandQueue->sendMessage(iter.value->first, sendResult = commandQueue->sendMessage(iter.value->first,
&command); &command);
} }
if (sendResult == RETURN_OK) { if (sendResult == RETURN_OK) {
verificationReporter.sendSuccessReport(tc_verification::START_SUCCESS, verificationReporter.sendSuccessReport(tc_verification::START_SUCCESS,
storedPacket->getPacketBase()); storedPacket->getPacketBase());
acceptPacket(tc_verification::COMPLETION_SUCCESS, storedPacket); acceptPacket(tc_verification::COMPLETION_SUCCESS, storedPacket);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} else { } else {
command.clearCommandMessage(); command.clearCommandMessage();
rejectPacket(tc_verification::START_FAILURE, storedPacket, sendResult); rejectPacket(tc_verification::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
break; break;
default: default:
rejectPacket(tc_verification::START_FAILURE, storedPacket, result); rejectPacket(tc_verification::START_FAILURE, storedPacket, result);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
break; break;
} }
} }
void CommandingServiceBase::rejectPacket(uint8_t reportId, void CommandingServiceBase::rejectPacket(uint8_t reportId,
TcPacketStoredBase* packet, ReturnValue_t errorCode) { TcPacketStoredPus* packet, ReturnValue_t errorCode) {
verificationReporter.sendFailureReport(reportId, packet->getPacketBase(), errorCode); verificationReporter.sendFailureReport(reportId, dynamic_cast<TcPacketPusBase*>(packet),
packet->deletePacket(); errorCode);
packet->deletePacket();
} }
void CommandingServiceBase::acceptPacket(uint8_t reportId, void CommandingServiceBase::acceptPacket(uint8_t reportId,
TcPacketStoredBase* packet) { TcPacketStoredPus* packet) {
verificationReporter.sendSuccessReport(reportId, packet->getPacketBase()); verificationReporter.sendSuccessReport(reportId, dynamic_cast<TcPacketPusBase*>(packet));
packet->deletePacket(); packet->deletePacket();
} }
void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) { void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) {
store_address_t address; store_address_t address;
if (iter->second.fifo.retrieve(&address) != RETURN_OK) { if (iter->second.fifo.retrieve(&address) != RETURN_OK) {
commandMap.erase(&iter); commandMap.erase(&iter);
} else { } else {
TcPacketStoredPus newPacket(address); TcPacketStoredPus newPacket(address);
startExecution(&newPacket, iter); startExecution(&newPacket, iter);
} }
} }
void CommandingServiceBase::handleUnrequestedReply(CommandMessage* reply) { void CommandingServiceBase::handleUnrequestedReply(CommandMessage* reply) {
reply->clearCommandMessage(); reply->clearCommandMessage();
} }
@ -447,22 +448,22 @@ inline void CommandingServiceBase::doPeriodicOperation() {
} }
MessageQueueId_t CommandingServiceBase::getCommandQueue() { MessageQueueId_t CommandingServiceBase::getCommandQueue() {
return commandQueue->getId(); return commandQueue->getId();
} }
void CommandingServiceBase::checkTimeout() { void CommandingServiceBase::checkTimeout() {
uint32_t uptime; uint32_t uptime;
Clock::getUptime(&uptime); Clock::getUptime(&uptime);
CommandMapIter iter; CommandMapIter iter;
for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) { for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) {
if ((iter->second.uptimeOfStart + (timeoutSeconds * 1000)) < uptime) { if ((iter->second.uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
tc_verification::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags, tc_verification::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags,
iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl, iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl,
TIMEOUT); TIMEOUT);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
} }
} }
void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) { void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) {

View File

@ -14,8 +14,8 @@
#include "fsfw/container/FIFO.h" #include "fsfw/container/FIFO.h"
#include "fsfw/serialize/SerializeIF.h" #include "fsfw/serialize/SerializeIF.h"
class TcPacketStored;
class TcPacketStoredBase; class TcPacketStoredBase;
class TcPacketStoredPus;
namespace Factory{ namespace Factory{
void setStaticFrameworkObjectIds(); void setStaticFrameworkObjectIds();
@ -36,333 +36,333 @@ void setStaticFrameworkObjectIds();
* @ingroup pus_services * @ingroup pus_services
*/ */
class CommandingServiceBase: public SystemObject, class CommandingServiceBase: public SystemObject,
public AcceptsTelecommandsIF, public AcceptsTelecommandsIF,
public ExecutableObjectIF, public ExecutableObjectIF,
public HasReturnvaluesIF { public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)(); friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
// We could make this configurable via preprocessor and the FSFWConfig file. // We could make this configurable via preprocessor and the FSFWConfig file.
static constexpr uint8_t COMMAND_INFO_FIFO_DEPTH = static constexpr uint8_t COMMAND_INFO_FIFO_DEPTH =
fsfwconfig::FSFW_CSB_FIFO_DEPTH; fsfwconfig::FSFW_CSB_FIFO_DEPTH;
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE; static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE;
static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1); static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1);
static const ReturnValue_t NO_STEP_MESSAGE = MAKE_RETURN_CODE(2); static const ReturnValue_t NO_STEP_MESSAGE = MAKE_RETURN_CODE(2);
static const ReturnValue_t OBJECT_BUSY = MAKE_RETURN_CODE(3); static const ReturnValue_t OBJECT_BUSY = MAKE_RETURN_CODE(3);
static const ReturnValue_t BUSY = MAKE_RETURN_CODE(4); static const ReturnValue_t BUSY = MAKE_RETURN_CODE(4);
static const ReturnValue_t INVALID_TC = MAKE_RETURN_CODE(5); static const ReturnValue_t INVALID_TC = MAKE_RETURN_CODE(5);
static const ReturnValue_t INVALID_OBJECT = MAKE_RETURN_CODE(6); static const ReturnValue_t INVALID_OBJECT = MAKE_RETURN_CODE(6);
static const ReturnValue_t INVALID_REPLY = MAKE_RETURN_CODE(7); static const ReturnValue_t INVALID_REPLY = MAKE_RETURN_CODE(7);
/** /**
* Class constructor. Initializes two important MessageQueues: * Class constructor. Initializes two important MessageQueues:
* commandQueue for command reception and requestQueue for device reception * commandQueue for command reception and requestQueue for device reception
* @param setObjectId * @param setObjectId
* @param apid * @param apid
* @param service * @param service
* @param numberOfParallelCommands * @param numberOfParallelCommands
* @param commandTimeout_seconds * @param commandTimeout_seconds
* @param setPacketSource * @param setPacketSource
* @param setPacketDestination * @param setPacketDestination
* @param queueDepth * @param queueDepth
*/ */
CommandingServiceBase(object_id_t setObjectId, uint16_t apid, CommandingServiceBase(object_id_t setObjectId, uint16_t apid,
uint8_t service, uint8_t numberOfParallelCommands, uint8_t service, uint8_t numberOfParallelCommands,
uint16_t commandTimeoutSeconds, size_t queueDepth = 20); uint16_t commandTimeoutSeconds, size_t queueDepth = 20);
virtual ~CommandingServiceBase(); virtual ~CommandingServiceBase();
/** /**
* This setter can be used to set the packet source individually instead * This setter can be used to set the packet source individually instead
* of using the default static framework ID set in the factory. * of using the default static framework ID set in the factory.
* This should be called at object initialization and not during run-time! * This should be called at object initialization and not during run-time!
* @param packetSource * @param packetSource
*/ */
void setPacketSource(object_id_t packetSource); void setPacketSource(object_id_t packetSource);
/** /**
* This setter can be used to set the packet destination individually * This setter can be used to set the packet destination individually
* instead of using the default static framework ID set in the factory. * instead of using the default static framework ID set in the factory.
* This should be called at object initialization and not during run-time! * This should be called at object initialization and not during run-time!
* @param packetDestination * @param packetDestination
*/ */
void setPacketDestination(object_id_t packetDestination); void setPacketDestination(object_id_t packetDestination);
/*** /***
* This is the periodically called function. * This is the periodically called function.
* Handle request queue for external commands. * Handle request queue for external commands.
* Handle command Queue for internal commands. * Handle command Queue for internal commands.
* @param opCode is unused here at the moment * @param opCode is unused here at the moment
* @return RETURN_OK * @return RETURN_OK
*/ */
virtual ReturnValue_t performOperation(uint8_t opCode) override; virtual ReturnValue_t performOperation(uint8_t opCode) override;
virtual uint16_t getIdentifier(); virtual uint16_t getIdentifier();
/** /**
* Returns the requestQueue MessageQueueId_t * Returns the requestQueue MessageQueueId_t
* *
* The requestQueue is the queue for external commands (TC) * The requestQueue is the queue for external commands (TC)
* *
* @return requestQueue messageQueueId_t * @return requestQueue messageQueueId_t
*/ */
virtual MessageQueueId_t getRequestQueue(); virtual MessageQueueId_t getRequestQueue();
/** /**
* Returns the commandQueue MessageQueueId_t * Returns the commandQueue MessageQueueId_t
* *
* Remember the CommandQueue is the queue for internal communication * Remember the CommandQueue is the queue for internal communication
* @return commandQueue messageQueueId_t * @return commandQueue messageQueueId_t
*/ */
virtual MessageQueueId_t getCommandQueue(); virtual MessageQueueId_t getCommandQueue();
virtual ReturnValue_t initialize() override; virtual ReturnValue_t initialize() override;
/** /**
* Implementation of ExecutableObjectIF function * Implementation of ExecutableObjectIF function
* *
* Used to setup the reference of the task, that executes this component * Used to setup the reference of the task, that executes this component
* @param task Pointer to the taskIF of this task * @param task Pointer to the taskIF of this task
*/ */
virtual void setTaskIF(PeriodicTaskIF* task) override; virtual void setTaskIF(PeriodicTaskIF* task) override;
protected: protected:
/** /**
* Check the target subservice * Check the target subservice
* @param subservice[in] * @param subservice[in]
* @return * @return
* -@c RETURN_OK Subservice valid, continue message handling * -@c RETURN_OK Subservice valid, continue message handling
* -@c INVALID_SUBSERVICE if service is not known, rejects packet. * -@c INVALID_SUBSERVICE if service is not known, rejects packet.
*/ */
virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0; virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0;
/** /**
* Once a TC Request is valid, the existence of the destination and its * Once a TC Request is valid, the existence of the destination and its
* target interface is checked and retrieved. The target message queue ID * target interface is checked and retrieved. The target message queue ID
* can then be acquired by using the target interface. * can then be acquired by using the target interface.
* @param subservice * @param subservice
* @param tcData Application Data of TC Packet * @param tcData Application Data of TC Packet
* @param tcDataLen * @param tcDataLen
* @param id MessageQueue ID is stored here * @param id MessageQueue ID is stored here
* @param objectId Object ID is extracted and stored here * @param objectId Object ID is extracted and stored here
* @return * @return
* - @c RETURN_OK Cotinue message handling * - @c RETURN_OK Cotinue message handling
* - @c RETURN_FAILED Reject the packet and generates a start failure * - @c RETURN_FAILED Reject the packet and generates a start failure
* verification * verification
*/ */
virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice, virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice,
const uint8_t *tcData, size_t tcDataLen, MessageQueueId_t *id, const uint8_t *tcData, size_t tcDataLen, MessageQueueId_t *id,
object_id_t *objectId) = 0; object_id_t *objectId) = 0;
/** /**
* After the Message Queue and Object ID are determined, the command is * After the Message Queue and Object ID are determined, the command is
* prepared by using an implementation specific CommandMessage type * prepared by using an implementation specific CommandMessage type
* which is sent to the target object. It contains all necessary information * which is sent to the target object. It contains all necessary information
* for the device to execute telecommands. * for the device to execute telecommands.
* @param message [out] message which can be set and is sent to the object * @param message [out] message which can be set and is sent to the object
* @param subservice Subservice of the current communication * @param subservice Subservice of the current communication
* @param tcData Application data of command * @param tcData Application data of command
* @param tcDataLen Application data length * @param tcDataLen Application data length
* @param state [out/in] Setable state of the communication. * @param state [out/in] Setable state of the communication.
* communication * communication
* @param objectId Target object ID * @param objectId Target object ID
* @return * @return
* - @c RETURN_OK to generate a verification start message * - @c RETURN_OK to generate a verification start message
* - @c EXECUTION_COMPELTE Fire-and-forget command. Generate a completion * - @c EXECUTION_COMPELTE Fire-and-forget command. Generate a completion
* verification message. * verification message.
* - @c Anything else rejects the packets and generates a start failure * - @c Anything else rejects the packets and generates a start failure
* verification. * verification.
*/ */
virtual ReturnValue_t prepareCommand(CommandMessage* message, virtual ReturnValue_t prepareCommand(CommandMessage* message,
uint8_t subservice, const uint8_t *tcData, size_t tcDataLen, uint8_t subservice, const uint8_t *tcData, size_t tcDataLen,
uint32_t *state, object_id_t objectId) = 0; uint32_t *state, object_id_t objectId) = 0;
/** /**
* This function is implemented by child services to specify how replies * This function is implemented by child services to specify how replies
* to a command from another software component are handled. * to a command from another software component are handled.
* @param reply * @param reply
* This is the reply in form of a generic read-only command message. * This is the reply in form of a generic read-only command message.
* @param previousCommand * @param previousCommand
* Command_t of related command * Command_t of related command
* @param state [out/in] * @param state [out/in]
* Additional parameter which can be used to pass state information. * Additional parameter which can be used to pass state information.
* State of the communication * State of the communication
* @param optionalNextCommand [out] * @param optionalNextCommand [out]
* An optional next command which can be set in this function * An optional next command which can be set in this function
* @param objectId Source object ID * @param objectId Source object ID
* @param isStep Flag value to mark steps of command execution * @param isStep Flag value to mark steps of command execution
* @return * @return
* - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to * - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to
* generate TC verification success * generate TC verification success
* - @c INVALID_REPLY Calls handleUnrequestedReply * - @c INVALID_REPLY Calls handleUnrequestedReply
* - Anything else triggers a TC verification failure. If RETURN_FAILED or * - Anything else triggers a TC verification failure. If RETURN_FAILED or
* INVALID_REPLY is returned and the command ID is * INVALID_REPLY is returned and the command ID is
* CommandMessage::REPLY_REJECTED, a failure verification message with * CommandMessage::REPLY_REJECTED, a failure verification message with
* the reason as the error parameter and the initial command as * the reason as the error parameter and the initial command as
* failure parameter 1 is generated. * failure parameter 1 is generated.
*/ */
virtual ReturnValue_t handleReply(const CommandMessage* reply, virtual ReturnValue_t handleReply(const CommandMessage* reply,
Command_t previousCommand, uint32_t *state, Command_t previousCommand, uint32_t *state,
CommandMessage* optionalNextCommand, object_id_t objectId, CommandMessage* optionalNextCommand, object_id_t objectId,
bool *isStep) = 0; bool *isStep) = 0;
/** /**
* This function can be overidden to handle unrequested reply, * This function can be overidden to handle unrequested reply,
* when the reply sender ID is unknown or is not found is the command map. * when the reply sender ID is unknown or is not found is the command map.
* The default implementation will clear the command message and all * The default implementation will clear the command message and all
* its contents. * its contents.
* @param reply * @param reply
* Reply which is non-const so the default implementation can clear the * Reply which is non-const so the default implementation can clear the
* message. * message.
*/ */
virtual void handleUnrequestedReply(CommandMessage* reply); virtual void handleUnrequestedReply(CommandMessage* reply);
virtual void doPeriodicOperation(); virtual void doPeriodicOperation();
struct CommandInfo: public SerializeIF{ struct CommandInfo: public SerializeIF{
struct tcInfo { struct tcInfo {
uint8_t ackFlags; uint8_t ackFlags;
uint16_t tcPacketId; uint16_t tcPacketId;
uint16_t tcSequenceControl; uint16_t tcSequenceControl;
} tcInfo; } tcInfo;
uint32_t uptimeOfStart; uint32_t uptimeOfStart;
uint8_t step; uint8_t step;
uint8_t subservice; uint8_t subservice;
uint32_t state; uint32_t state;
Command_t command; Command_t command;
object_id_t objectId; object_id_t objectId;
FIFO<store_address_t, COMMAND_INFO_FIFO_DEPTH> fifo; FIFO<store_address_t, COMMAND_INFO_FIFO_DEPTH> fifo;
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
size_t maxSize, Endianness streamEndianness) const override{ size_t maxSize, Endianness streamEndianness) const override{
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
}; };
virtual size_t getSerializedSize() const override { virtual size_t getSerializedSize() const override {
return 0; return 0;
}; };
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override { Endianness streamEndianness) override {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
}; };
}; };
using CommandMapIter = FixedMap<MessageQueueId_t, using CommandMapIter = FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator; CommandingServiceBase::CommandInfo>::Iterator;
const uint16_t apid; const uint16_t apid;
const uint8_t service; const uint8_t service;
const uint16_t timeoutSeconds; const uint16_t timeoutSeconds;
uint8_t tmPacketCounter = 0; uint8_t tmPacketCounter = 0;
StorageManagerIF *IPCStore = nullptr; StorageManagerIF *IPCStore = nullptr;
StorageManagerIF *TCStore = nullptr; StorageManagerIF *TCStore = nullptr;
MessageQueueIF* commandQueue = nullptr; MessageQueueIF* commandQueue = nullptr;
MessageQueueIF* requestQueue = nullptr; MessageQueueIF* requestQueue = nullptr;
VerificationReporter verificationReporter; VerificationReporter verificationReporter;
FixedMap<MessageQueueId_t, CommandInfo> commandMap; FixedMap<MessageQueueId_t, CommandInfo> commandMap;
/* May be set be children to return a more precise failure condition. */ /* May be set be children to return a more precise failure condition. */
uint32_t failureParameter1 = 0; uint32_t failureParameter1 = 0;
uint32_t failureParameter2 = 0; uint32_t failureParameter2 = 0;
static object_id_t defaultPacketSource; static object_id_t defaultPacketSource;
object_id_t packetSource = objects::NO_OBJECT; object_id_t packetSource = objects::NO_OBJECT;
static object_id_t defaultPacketDestination; static object_id_t defaultPacketDestination;
object_id_t packetDestination = objects::NO_OBJECT; object_id_t packetDestination = objects::NO_OBJECT;
/** /**
* Pointer to the task which executes this component, * Pointer to the task which executes this component,
* is invalid before setTaskIF was called. * is invalid before setTaskIF was called.
*/ */
PeriodicTaskIF* executingTask = nullptr; PeriodicTaskIF* executingTask = nullptr;
/** /**
* @brief Send TM data from pointer to data. * @brief Send TM data from pointer to data.
* If a header is supplied it is added before data * If a header is supplied it is added before data
* @param subservice Number of subservice * @param subservice Number of subservice
* @param data Pointer to the data in the Packet * @param data Pointer to the data in the Packet
* @param dataLen Lenght of data in the Packet * @param dataLen Lenght of data in the Packet
* @param headerData HeaderData will be placed before data * @param headerData HeaderData will be placed before data
* @param headerSize Size of HeaderData * @param headerSize Size of HeaderData
*/ */
ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t *data, ReturnValue_t sendTmPacket(uint8_t subservice, const uint8_t *data,
size_t dataLen, const uint8_t* headerData = nullptr, size_t dataLen, const uint8_t* headerData = nullptr,
size_t headerSize = 0); size_t headerSize = 0);
/** /**
* @brief To send TM packets of objects that still need to be serialized * @brief To send TM packets of objects that still need to be serialized
* and consist of an object ID with appended data. * and consist of an object ID with appended data.
* @param subservice Number of subservice * @param subservice Number of subservice
* @param objectId ObjectId is placed before data * @param objectId ObjectId is placed before data
* @param data Data to append to the packet * @param data Data to append to the packet
* @param dataLen Length of Data * @param dataLen Length of Data
*/ */
ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId, ReturnValue_t sendTmPacket(uint8_t subservice, object_id_t objectId,
const uint8_t *data, size_t dataLen); const uint8_t *data, size_t dataLen);
/** /**
* @brief To send packets which are contained inside a class implementing * @brief To send packets which are contained inside a class implementing
* SerializeIF. * SerializeIF.
* @param subservice Number of subservice * @param subservice Number of subservice
* @param content This is a pointer to the serialized packet * @param content This is a pointer to the serialized packet
* @param header Serialize IF header which will be placed before content * @param header Serialize IF header which will be placed before content
*/ */
ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content, ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content,
SerializeIF* header = nullptr); SerializeIF* header = nullptr);
void checkAndExecuteFifo(CommandMapIter& iter); void checkAndExecuteFifo(CommandMapIter& iter);
private: private:
/** /**
* This method handles internal execution of a command, * This method handles internal execution of a command,
* once it has been started by @sa{startExecution()} in the request * once it has been started by @sa{startExecution()} in the request
* queue handler. * queue handler.
* It handles replies generated by the devices and relayed by the specific * It handles replies generated by the devices and relayed by the specific
* service implementation. This means that it determines further course of * service implementation. This means that it determines further course of
* action depending on the return values specified in the service * action depending on the return values specified in the service
* implementation. * implementation.
* This includes the generation of TC verification messages. Note that * This includes the generation of TC verification messages. Note that
* the static framework object ID @c VerificationReporter::messageReceiver * the static framework object ID @c VerificationReporter::messageReceiver
* needs to be set. * needs to be set.
* - TM[1,5] Step Successs * - TM[1,5] Step Successs
* - TM[1,6] Step Failure * - TM[1,6] Step Failure
* - TM[1,7] Completion Success * - TM[1,7] Completion Success
* - TM[1,8] Completion Failure * - TM[1,8] Completion Failure
*/ */
void handleCommandQueue(); void handleCommandQueue();
/** /**
* @brief Handler function for request queue * @brief Handler function for request queue
* @details * @details
* Sequence of request queue handling: * Sequence of request queue handling:
* isValidSubservice -> getMessageQueueAndObject -> startExecution * isValidSubservice -> getMessageQueueAndObject -> startExecution
* Generates a Start Success Reports TM[1,3] in subfunction * Generates a Start Success Reports TM[1,3] in subfunction
* @sa{startExecution()} or a Start Failure Report TM[1,4] by using the * @sa{startExecution()} or a Start Failure Report TM[1,4] by using the
* TC Verification Service. * TC Verification Service.
*/ */
void handleRequestQueue(); void handleRequestQueue();
void rejectPacket(uint8_t reportId, TcPacketStoredBase* packet, void rejectPacket(uint8_t reportId, TcPacketStoredPus* packet,
ReturnValue_t errorCode); ReturnValue_t errorCode);
void acceptPacket(uint8_t reportId, TcPacketStoredBase* packet); void acceptPacket(uint8_t reportId, TcPacketStoredPus* packet);
void startExecution(TcPacketStoredBase *storedPacket, CommandMapIter iter); void startExecution(TcPacketStoredPus* storedPacket, CommandMapIter iter);
void handleCommandMessage(CommandMessage* reply); void handleCommandMessage(CommandMessage* reply);
void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter, void handleReplyHandlerResult(ReturnValue_t result, CommandMapIter iter,
CommandMessage* nextCommand, CommandMessage* reply, bool& isStep); CommandMessage* nextCommand, CommandMessage* reply, bool& isStep);
void checkTimeout(); void checkTimeout();
}; };
#endif /* FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_ */ #endif /* FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_ */

View File

@ -12,28 +12,28 @@ object_id_t PusServiceBase::packetSource = 0;
object_id_t PusServiceBase::packetDestination = 0; object_id_t PusServiceBase::packetDestination = 0;
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid,
uint8_t setServiceId) : uint8_t setServiceId):
SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) { SystemObject(setObjectId), apid(setApid), serviceId(setServiceId) {
requestQueue = QueueFactory::instance()-> requestQueue = QueueFactory::instance()->
createMessageQueue(PUS_SERVICE_MAX_RECEPTION); createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
} }
PusServiceBase::~PusServiceBase() { PusServiceBase::~PusServiceBase() {
QueueFactory::instance()->deleteMessageQueue(requestQueue); QueueFactory::instance()->deleteMessageQueue(requestQueue);
} }
ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) {
handleRequestQueue(); handleRequestQueue();
ReturnValue_t result = this->performService(); ReturnValue_t result = this->performService();
if (result != RETURN_OK) { if (result != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PusService " << (uint16_t) this->serviceId sif::error << "PusService " << (uint16_t) this->serviceId
<< ": performService returned with " << (int16_t) result << ": performService returned with " << (int16_t) result
<< std::endl; << std::endl;
#endif #endif
return RETURN_FAILED; return RETURN_FAILED;
} }
return RETURN_OK; return RETURN_OK;
} }
void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle) { void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle) {
@ -41,88 +41,88 @@ void PusServiceBase::setTaskIF(PeriodicTaskIF* taskHandle) {
} }
void PusServiceBase::handleRequestQueue() { void PusServiceBase::handleRequestQueue() {
TmTcMessage message; TmTcMessage message;
ReturnValue_t result = RETURN_FAILED; ReturnValue_t result = RETURN_FAILED;
for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) { for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) {
ReturnValue_t status = this->requestQueue->receiveMessage(&message); ReturnValue_t status = this->requestQueue->receiveMessage(&message);
// if(status != MessageQueueIF::EMPTY) { // if(status != MessageQueueIF::EMPTY) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
// sif::debug << "PusServiceBase::performOperation: Receiving from " // sif::debug << "PusServiceBase::performOperation: Receiving from "
// << "MQ ID: " << std::hex << "0x" << std::setw(8) // << "MQ ID: " << std::hex << "0x" << std::setw(8)
// << std::setfill('0') << this->requestQueue->getId() // << std::setfill('0') << this->requestQueue->getId()
// << std::dec << " returned: " << status << std::setfill(' ') // << std::dec << " returned: " << status << std::setfill(' ')
// << std::endl; // << std::endl;
#endif #endif
// } // }
if (status == RETURN_OK) { if (status == RETURN_OK) {
this->currentPacket.setStoreAddress(message.getStorageId()); this->currentPacket.setStoreAddress(message.getStorageId(), &currentPacket);
//info << "Service " << (uint16_t) this->serviceId << //info << "Service " << (uint16_t) this->serviceId <<
// ": new packet!" << std::endl; // ": new packet!" << std::endl;
result = this->handleRequest(currentPacket.getSubService()); result = this->handleRequest(currentPacket.getSubService());
// debug << "Service " << (uint16_t)this->serviceId << // debug << "Service " << (uint16_t)this->serviceId <<
// ": handleRequest returned: " << (int)return_code << std::endl; // ": handleRequest returned: " << (int)return_code << std::endl;
if (result == RETURN_OK) { if (result == RETURN_OK) {
this->verifyReporter.sendSuccessReport( this->verifyReporter.sendSuccessReport(
tc_verification::COMPLETION_SUCCESS, &this->currentPacket); tc_verification::COMPLETION_SUCCESS, &this->currentPacket);
} }
else { else {
this->verifyReporter.sendFailureReport( this->verifyReporter.sendFailureReport(
tc_verification::COMPLETION_FAILURE, &this->currentPacket, tc_verification::COMPLETION_FAILURE, &this->currentPacket,
result, 0, errorParameter1, errorParameter2); result, 0, errorParameter1, errorParameter2);
} }
this->currentPacket.deletePacket(); this->currentPacket.deletePacket();
errorParameter1 = 0; errorParameter1 = 0;
errorParameter2 = 0; errorParameter2 = 0;
} }
else if (status == MessageQueueIF::EMPTY) { else if (status == MessageQueueIF::EMPTY) {
status = RETURN_OK; status = RETURN_OK;
// debug << "PusService " << (uint16_t)this->serviceId << // debug << "PusService " << (uint16_t)this->serviceId <<
// ": no new packet." << std::endl; // ": no new packet." << std::endl;
break; break;
} }
else { else {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PusServiceBase::performOperation: Service " sif::error << "PusServiceBase::performOperation: Service "
<< this->serviceId << ": Error receiving packet. Code: " << this->serviceId << ": Error receiving packet. Code: "
<< std::hex << status << std::dec << std::endl; << std::hex << status << std::dec << std::endl;
#endif #endif
} }
} }
} }
uint16_t PusServiceBase::getIdentifier() { uint16_t PusServiceBase::getIdentifier() {
return this->serviceId; return this->serviceId;
} }
MessageQueueId_t PusServiceBase::getRequestQueue() { MessageQueueId_t PusServiceBase::getRequestQueue() {
return this->requestQueue->getId(); return this->requestQueue->getId();
} }
ReturnValue_t PusServiceBase::initialize() { ReturnValue_t PusServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize(); ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
AcceptsTelemetryIF* destService = ObjectManager::instance()->get<AcceptsTelemetryIF>( AcceptsTelemetryIF* destService = ObjectManager::instance()->get<AcceptsTelemetryIF>(
packetDestination); packetDestination);
PUSDistributorIF* distributor = ObjectManager::instance()->get<PUSDistributorIF>( PUSDistributorIF* distributor = ObjectManager::instance()->get<PUSDistributorIF>(
packetSource); packetSource);
if (destService == nullptr or distributor == nullptr) { if (destService == nullptr or distributor == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PusServiceBase::PusServiceBase: Service " sif::error << "PusServiceBase::PusServiceBase: Service "
<< this->serviceId << ": Configuration error. Make sure " << this->serviceId << ": Configuration error. Make sure "
<< "packetSource and packetDestination are defined correctly" << "packetSource and packetDestination are defined correctly"
<< std::endl; << std::endl;
#endif #endif
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
this->requestQueue->setDefaultDestination( this->requestQueue->setDefaultDestination(
destService->getReportReceptionQueue()); destService->getReportReceptionQueue());
distributor->registerService(this); distributor->registerService(this);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { ReturnValue_t PusServiceBase::initializeAfterTaskCreation() {

View File

@ -35,126 +35,126 @@ void setStaticFrameworkObjectIds();
* @ingroup pus_services * @ingroup pus_services
*/ */
class PusServiceBase : public ExecutableObjectIF, class PusServiceBase : public ExecutableObjectIF,
public AcceptsTelecommandsIF, public AcceptsTelecommandsIF,
public SystemObject, public SystemObject,
public HasReturnvaluesIF { public HasReturnvaluesIF {
friend void (Factory::setStaticFrameworkObjectIds)(); friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
/** /**
* @brief The passed values are set, but inter-object initialization is * @brief The passed values are set, but inter-object initialization is
* done in the initialize method. * done in the initialize method.
* @param setObjectId * @param setObjectId
* The system object identifier of this Service instance. * The system object identifier of this Service instance.
* @param setApid * @param setApid
* The APID the Service is instantiated for. * The APID the Service is instantiated for.
* @param setServiceId * @param setServiceId
* The Service Identifier as specified in ECSS PUS. * The Service Identifier as specified in ECSS PUS.
*/ */
PusServiceBase( object_id_t setObjectId, uint16_t setApid, PusServiceBase( object_id_t setObjectId, uint16_t setApid,
uint8_t setServiceId); uint8_t setServiceId);
/** /**
* The destructor is empty. * The destructor is empty.
*/ */
virtual ~PusServiceBase(); virtual ~PusServiceBase();
/** /**
* @brief The handleRequest method shall handle any kind of Telecommand * @brief The handleRequest method shall handle any kind of Telecommand
* Request immediately. * Request immediately.
* @details * @details
* Implemetations can take the Telecommand in currentPacket and perform * Implemetations can take the Telecommand in currentPacket and perform
* any kind of operation. * any kind of operation.
* They may send additional "Start Success (1,3)" messages with the * They may send additional "Start Success (1,3)" messages with the
* verifyReporter, but Completion Success or Failure Reports are generated * verifyReporter, but Completion Success or Failure Reports are generated
* automatically after execution of this method. * automatically after execution of this method.
* *
* If a Telecommand can not be executed within one call cycle, * If a Telecommand can not be executed within one call cycle,
* this Base class is not the right parent. * this Base class is not the right parent.
* *
* The child class may add additional error information by setting * The child class may add additional error information by setting
* #errorParameters which aren attached to the generated verification * #errorParameters which aren attached to the generated verification
* message. * message.
* *
* Subservice checking should be implemented in this method. * Subservice checking should be implemented in this method.
* *
* @return The returned status_code is directly taken as main error code * @return The returned status_code is directly taken as main error code
* in the Verification Report. * in the Verification Report.
* On success, RETURN_OK shall be returned. * On success, RETURN_OK shall be returned.
*/ */
virtual ReturnValue_t handleRequest(uint8_t subservice) = 0; virtual ReturnValue_t handleRequest(uint8_t subservice) = 0;
/** /**
* In performService, implementations can handle periodic, * In performService, implementations can handle periodic,
* non-TC-triggered activities. * non-TC-triggered activities.
* The performService method is always called. * The performService method is always called.
* @return Currently, everything other that RETURN_OK only triggers * @return Currently, everything other that RETURN_OK only triggers
* diagnostic output. * diagnostic output.
*/ */
virtual ReturnValue_t performService() = 0; virtual ReturnValue_t performService() = 0;
/** /**
* This method implements the typical activity of a simple PUS Service. * This method implements the typical activity of a simple PUS Service.
* It checks for new requests, and, if found, calls handleRequest, sends * It checks for new requests, and, if found, calls handleRequest, sends
* completion verification messages and deletes * completion verification messages and deletes
* the TC requests afterwards. * the TC requests afterwards.
* performService is always executed afterwards. * performService is always executed afterwards.
* @return @c RETURN_OK if the periodic performService was successful. * @return @c RETURN_OK if the periodic performService was successful.
* @c RETURN_FAILED else. * @c RETURN_FAILED else.
*/ */
ReturnValue_t performOperation(uint8_t opCode) override; ReturnValue_t performOperation(uint8_t opCode) override;
virtual uint16_t getIdentifier() override; virtual uint16_t getIdentifier() override;
MessageQueueId_t getRequestQueue() override; MessageQueueId_t getRequestQueue() override;
virtual ReturnValue_t initialize() override; virtual ReturnValue_t initialize() override;
virtual void setTaskIF(PeriodicTaskIF* taskHandle) override; virtual void setTaskIF(PeriodicTaskIF* taskHandle) override;
virtual ReturnValue_t initializeAfterTaskCreation() override; virtual ReturnValue_t initializeAfterTaskCreation() override;
protected: protected:
/** /**
* @brief Handle to the underlying task * @brief Handle to the underlying task
* @details * @details
* Will be set by setTaskIF(), which is called on task creation. * Will be set by setTaskIF(), which is called on task creation.
*/ */
PeriodicTaskIF* taskHandle = nullptr; PeriodicTaskIF* taskHandle = nullptr;
/** /**
* The APID of this instance of the Service. * The APID of this instance of the Service.
*/ */
uint16_t apid; uint16_t apid;
/** /**
* The Service Identifier. * The Service Identifier.
*/ */
uint8_t serviceId; uint8_t serviceId;
/** /**
* One of two error parameters for additional error information. * One of two error parameters for additional error information.
*/ */
uint32_t errorParameter1 = 0; uint32_t errorParameter1 = 0;
/** /**
* One of two error parameters for additional error information. * One of two error parameters for additional error information.
*/ */
uint32_t errorParameter2 = 0; uint32_t errorParameter2 = 0;
/** /**
* This is a complete instance of the telecommand reception queue * This is a complete instance of the telecommand reception queue
* of the class. It is initialized on construction of the class. * of the class. It is initialized on construction of the class.
*/ */
MessageQueueIF* requestQueue = nullptr; MessageQueueIF* requestQueue = nullptr;
/** /**
* An instance of the VerificationReporter class, that simplifies * An instance of the VerificationReporter class, that simplifies
* sending any kind of verification message to the TC Verification Service. * sending any kind of verification message to the TC Verification Service.
*/ */
VerificationReporter verifyReporter; VerificationReporter verifyReporter;
/** /**
* The current Telecommand to be processed. * The current Telecommand to be processed.
* It is deleted after handleRequest was executed. * It is deleted after handleRequest was executed.
*/ */
TcPacketStoredPus currentPacket; TcPacketStoredPus currentPacket;
static object_id_t packetSource; static object_id_t packetSource;
static object_id_t packetDestination; static object_id_t packetDestination;
private: private:
/** /**
* This constant sets the maximum number of packets accepted per call. * This constant sets the maximum number of packets accepted per call.
* Remember that one packet must be completely handled in one * Remember that one packet must be completely handled in one
* #handleRequest call. * #handleRequest call.
*/ */
static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10; static const uint8_t PUS_SERVICE_MAX_RECEPTION = 10;
void handleRequestQueue(); void handleRequestQueue();
}; };
#endif /* FSFW_TMTCSERVICES_PUSSERVICEBASE_H_ */ #endif /* FSFW_TMTCSERVICES_PUSSERVICEBASE_H_ */

View File

@ -4,7 +4,7 @@
#include "VerificationCodes.h" #include "VerificationCodes.h"
#include "fsfw/ipc/MessageQueueMessage.h" #include "fsfw/ipc/MessageQueueMessage.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketBase.h" #include "fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
class PusVerificationMessage: public MessageQueueMessage { class PusVerificationMessage: public MessageQueueMessage {

View File

@ -17,7 +17,7 @@ VerificationReporter::VerificationReporter() :
VerificationReporter::~VerificationReporter() {} VerificationReporter::~VerificationReporter() {}
void VerificationReporter::sendSuccessReport(uint8_t set_report_id, void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
TcPacketBase* currentPacket, uint8_t set_step) { TcPacketPusBase* currentPacket, uint8_t set_step) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize(); this->initialize();
} }
@ -59,7 +59,7 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id,
} }
void VerificationReporter::sendFailureReport(uint8_t report_id, void VerificationReporter::sendFailureReport(uint8_t report_id,
TcPacketBase* currentPacket, ReturnValue_t error_code, uint8_t step, TcPacketPusBase* currentPacket, ReturnValue_t error_code, uint8_t step,
uint32_t parameter1, uint32_t parameter2) { uint32_t parameter1, uint32_t parameter2) {
if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) { if (acknowledgeQueue == MessageQueueIF::NO_QUEUE) {
this->initialize(); this->initialize();

View File

@ -25,13 +25,13 @@ public:
VerificationReporter(); VerificationReporter();
virtual ~VerificationReporter(); virtual ~VerificationReporter();
void sendSuccessReport( uint8_t set_report_id, TcPacketBase* current_packet, void sendSuccessReport( uint8_t set_report_id, TcPacketPusBase* current_packet,
uint8_t set_step = 0 ); uint8_t set_step = 0 );
void sendSuccessReport(uint8_t set_report_id, uint8_t ackFlags, void sendSuccessReport(uint8_t set_report_id, uint8_t ackFlags,
uint16_t tcPacketId, uint16_t tcSequenceControl, uint16_t tcPacketId, uint16_t tcSequenceControl,
uint8_t set_step = 0); uint8_t set_step = 0);
void sendFailureReport( uint8_t report_id, TcPacketBase* current_packet, void sendFailureReport( uint8_t report_id, TcPacketPusBase* current_packet,
ReturnValue_t error_code = 0, ReturnValue_t error_code = 0,
uint8_t step = 0, uint32_t parameter1 = 0, uint8_t step = 0, uint32_t parameter1 = 0,
uint32_t parameter2 = 0 ); uint32_t parameter2 = 0 );