doc fix, various improvements

This commit is contained in:
Robin Müller 2020-06-24 16:01:17 +02:00
parent 72f3b16c24
commit 8a56964dab
2 changed files with 102 additions and 91 deletions

View File

@ -80,39 +80,49 @@ void CommandingServiceBase::handleCommandQueue() {
ReturnValue_t result = RETURN_FAILED; ReturnValue_t result = RETURN_FAILED;
for (result = commandQueue->receiveMessage(&reply); result == RETURN_OK; for (result = commandQueue->receiveMessage(&reply); result == RETURN_OK;
result = commandQueue->receiveMessage(&reply)) { result = commandQueue->receiveMessage(&reply)) {
handleCommandMessage(reply); handleCommandMessage(&reply);
} }
} }
void CommandingServiceBase::handleCommandMessage(CommandMessage& reply) { void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) {
bool isStep = false; bool isStep = false;
CommandMessage nextCommand; CommandMessage nextCommand;
CommandMapIter iter; CommandMapIter iter = commandMap.find(reply->getSender());
if (reply.getSender() == MessageQueueIF::NO_QUEUE) {
handleUnrequestedReply(&reply); // handle unrequested reply first
return; if (reply->getSender() == MessageQueueIF::NO_QUEUE or
} iter == commandMap.end()) {
if ((iter = commandMap.find(reply.getSender())) == 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->command, &iter->state, ReturnValue_t result = handleReply(reply, iter->command, &iter->state,
&nextCommand, iter->objectId, &isStep); &nextCommand, iter->objectId, &isStep);
/* If the child implementation does not implement special handling for
* rejected replies (RETURN_FAILED is returned), a failure verification
* will be generated with the reason as the return code and the initial
* command as failure parameter 1 */
if(reply->getCommand() == CommandMessage::REPLY_REJECTED and
result == RETURN_FAILED) {
result = reply->getReplyRejectedReason(
reinterpret_cast<Command_t*>(&failureParameter1));
}
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) {
@ -129,24 +139,24 @@ void CommandingServiceBase::handleCommandMessage(CommandMessage& reply) {
} }
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, CommandMessage& reply, CommandMapIter iter, CommandMessage* nextCommand,
bool& isStep) { CommandMessage* reply, bool& isStep) {
iter->command = nextCommand.getCommand(); iter->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) {
@ -161,19 +171,19 @@ void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
TC_VERIFY::COMPLETION_SUCCESS, TC_VERIFY::COMPLETION_SUCCESS,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId, iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, 0); iter->tcInfo.tcSequenceControl, 0);
checkAndExecuteFifo(&iter); checkAndExecuteFifo(iter);
} }
} }
else { else {
if (isStep) { if (isStep) {
nextCommand.clearCommandMessage(); nextCommand->clear();
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags, TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcPacketId,
iter->tcInfo.tcSequenceControl, sendResult, iter->tcInfo.tcSequenceControl, sendResult,
++iter->step, failureParameter1, failureParameter2); ++iter->step, failureParameter1, failureParameter2);
} else { } else {
nextCommand.clearCommandMessage(); nextCommand->clear();
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, TC_VERIFY::COMPLETION_FAILURE,
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId, iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
@ -182,7 +192,7 @@ void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
} }
failureParameter1 = 0; failureParameter1 = 0;
failureParameter2 = 0; failureParameter2 = 0;
checkAndExecuteFifo(&iter); checkAndExecuteFifo(iter);
} }
} }
@ -198,8 +208,8 @@ void CommandingServiceBase::handleRequestQueue() {
address = message.getStorageId(); address = message.getStorageId();
packet.setStoreAddress(address); packet.setStoreAddress(address);
if ((packet.getSubService() == 0) if (packet.getSubService() == 0
|| (isValidSubservice(packet.getSubService()) != RETURN_OK)) { or isValidSubservice(packet.getSubService()) != RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, INVALID_SUBSERVICE); rejectPacket(TC_VERIFY::START_FAILURE, &packet, INVALID_SUBSERVICE);
continue; continue;
} }
@ -212,8 +222,7 @@ void CommandingServiceBase::handleRequestQueue() {
} }
//Is a command already active for the target object? //Is a command already active for the target object?
typename FixedMap<MessageQueueId_t, CommandMapIter iter;
CommandingServiceBase::CommandInfo>::Iterator iter;
iter = commandMap.find(queue); iter = commandMap.find(queue);
if (iter != commandMap.end()) { if (iter != commandMap.end()) {
@ -228,7 +237,7 @@ void CommandingServiceBase::handleRequestQueue() {
if (result != RETURN_OK) { if (result != RETURN_OK) {
rejectPacket(TC_VERIFY::START_FAILURE, &packet, BUSY); rejectPacket(TC_VERIFY::START_FAILURE, &packet, BUSY);
} else { } else {
startExecution(&packet, &iter); startExecution(&packet, iter);
} }
} }
@ -281,46 +290,44 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
} }
void CommandingServiceBase::startExecution( void CommandingServiceBase::startExecution(TcPacketStored *storedPacket,
TcPacketStored *storedPacket, CommandMapIter iter) {
typename FixedMap<MessageQueueId_t, ReturnValue_t result = RETURN_OK;
CommandingServiceBase::CommandInfo>::Iterator *iter) { CommandMessage command;
ReturnValue_t result, sendResult = RETURN_OK; iter->subservice = storedPacket->getSubService();
CommandMessage message; result = prepareCommand(&command, iter->subservice,
(*iter)->subservice = storedPacket->getSubService();
result = prepareCommand(&message, (*iter)->subservice,
storedPacket->getApplicationData(), storedPacket->getApplicationData(),
storedPacket->getApplicationDataSize(), &(*iter)->state, storedPacket->getApplicationDataSize(), &iter->state,
(*iter)->objectId); iter->objectId);
ReturnValue_t sendResult = RETURN_OK;
switch (result) { switch (result) {
case RETURN_OK: case RETURN_OK:
if (message.getCommand() != CommandMessage::CMD_NONE) { if (command.getCommand() != CommandMessage::CMD_NONE) {
sendResult = commandQueue->sendMessage((*iter).value->first, sendResult = commandQueue->sendMessage(iter.value->first,
&message); &command);
} }
if (sendResult == RETURN_OK) { if (sendResult == RETURN_OK) {
Clock::getUptime(&(*iter)->uptimeOfStart); Clock::getUptime(&iter->uptimeOfStart);
(*iter)->step = 0; iter->step = 0;
// (*iter)->state = 0; iter->subservice = storedPacket->getSubService();
(*iter)->subservice = storedPacket->getSubService(); iter->command = command.getCommand();
(*iter)->command = message.getCommand(); iter->tcInfo.ackFlags = storedPacket->getAcknowledgeFlags();
(*iter)->tcInfo.ackFlags = storedPacket->getAcknowledgeFlags(); iter->tcInfo.tcPacketId = storedPacket->getPacketId();
(*iter)->tcInfo.tcPacketId = storedPacket->getPacketId(); iter->tcInfo.tcSequenceControl =
(*iter)->tcInfo.tcSequenceControl =
storedPacket->getPacketSequenceControl(); storedPacket->getPacketSequenceControl();
acceptPacket(TC_VERIFY::START_SUCCESS, storedPacket); acceptPacket(TC_VERIFY::START_SUCCESS, storedPacket);
} else { } else {
message.clearCommandMessage(); command.clear();
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult); rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
break; break;
case EXECUTION_COMPLETE: case EXECUTION_COMPLETE:
if (message.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,
&message); &command);
} }
if (sendResult == RETURN_OK) { if (sendResult == RETURN_OK) {
verificationReporter.sendSuccessReport(TC_VERIFY::START_SUCCESS, verificationReporter.sendSuccessReport(TC_VERIFY::START_SUCCESS,
@ -328,7 +335,7 @@ void CommandingServiceBase::startExecution(
acceptPacket(TC_VERIFY::COMPLETION_SUCCESS, storedPacket); acceptPacket(TC_VERIFY::COMPLETION_SUCCESS, storedPacket);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} else { } else {
message.clearCommandMessage(); command.clear();
rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult); rejectPacket(TC_VERIFY::START_FAILURE, storedPacket, sendResult);
checkAndExecuteFifo(iter); checkAndExecuteFifo(iter);
} }
@ -355,12 +362,10 @@ void CommandingServiceBase::acceptPacket(uint8_t reportId,
} }
void CommandingServiceBase::checkAndExecuteFifo( void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter iter) {
typename FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator *iter) {
store_address_t address; store_address_t address;
if ((*iter)->fifo.retrieve(&address) != RETURN_OK) { if (iter->fifo.retrieve(&address) != RETURN_OK) {
commandMap.erase(iter); commandMap.erase(&iter);
} else { } else {
TcPacketStored newPacket(address); TcPacketStored newPacket(address);
startExecution(&newPacket, iter); startExecution(&newPacket, iter);
@ -368,9 +373,8 @@ void CommandingServiceBase::checkAndExecuteFifo(
} }
void CommandingServiceBase::handleUnrequestedReply( void CommandingServiceBase::handleUnrequestedReply(CommandMessage* reply) {
CommandMessage* reply) { reply->clear();
reply->clearCommandMessage();
} }
@ -384,18 +388,18 @@ MessageQueueId_t CommandingServiceBase::getCommandQueue() {
void CommandingServiceBase::checkTimeout() { void CommandingServiceBase::checkTimeout() {
uint32_t uptime; uint32_t uptime;
Clock::getUptime(&uptime); Clock::getUptime(&uptime);
typename FixedMap<MessageQueueId_t, CommandMapIter iter;
CommandingServiceBase::CommandInfo>::Iterator iter;
for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) { for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) {
if ((iter->uptimeOfStart + (timeoutSeconds * 1000)) < uptime) { if ((iter->uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
verificationReporter.sendFailureReport( verificationReporter.sendFailureReport(
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags, TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl, iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
TIMEOUT); TIMEOUT);
checkAndExecuteFifo(&iter); checkAndExecuteFifo(iter);
} }
} }
} }
void CommandingServiceBase::setTaskIF(PeriodicTaskIF* task_) {
executingTask = task_;
}

View File

@ -97,9 +97,7 @@ public:
* 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_){ virtual void setTaskIF(PeriodicTaskIF* task_);
executingTask = task_;
};
protected: protected:
/** /**
@ -141,15 +139,15 @@ protected:
* @param objectId Target object ID * @param objectId Target object ID
* @return * @return
*/ */
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 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]
@ -163,19 +161,26 @@ protected:
* - @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 * - Anything else triggers a TC verification failure. If RETURN_FAILED
* is returned and the command ID is CommandMessage::REPLY_REJECTED,
* a failure verification message with the reason as the error parameter
* and the initial command as failure parameter 1.
*/ */
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
* its contents.
* @param reply * @param reply
* Reply which is non-const so the default implementation can clear the
* message.
*/ */
virtual void handleUnrequestedReply(CommandMessage *reply); virtual void handleUnrequestedReply(CommandMessage* reply);
virtual void doPeriodicOperation(); virtual void doPeriodicOperation();
@ -195,6 +200,9 @@ protected:
FIFO<store_address_t, 3> fifo; FIFO<store_address_t, 3> fifo;
}; };
using CommandMapIter = FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator;
const uint16_t apid; const uint16_t apid;
const uint8_t service; const uint8_t service;
@ -263,21 +271,21 @@ protected:
ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content, ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content,
SerializeIF* header = nullptr); SerializeIF* header = nullptr);
void checkAndExecuteFifo( void checkAndExecuteFifo(CommandMapIter iter);
typename FixedMap<MessageQueueId_t, CommandInfo>::Iterator *iter);
private: private:
using CommandMapIter = FixedMap<MessageQueueId_t,
CommandingServiceBase::CommandInfo>::Iterator;
/** /**
* 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 Queue handler. * once it has been started by @sa{startExecution()} in the request
* It handles replies generated by the devices and relayed by the specific service implementation. * queue handler.
* This means that it determines further course of action depending on the return values specified * It handles replies generated by the devices and relayed by the specific
* in the service implementation. * service implementation. This means that it determines further course of
* action depending on the return values specified in the service
* 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 needs to be set. * the static framework object ID @c VerificationReporter::messageReceiver
* 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
@ -298,12 +306,11 @@ private:
void acceptPacket(uint8_t reportId, TcPacketStored* packet); void acceptPacket(uint8_t reportId, TcPacketStored* packet);
void startExecution(TcPacketStored *storedPacket, void startExecution(TcPacketStored *storedPacket, CommandMapIter iter);
typename FixedMap<MessageQueueId_t, CommandInfo>::Iterator *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();
}; };