improved acknowledgment and execution handling in supervisor handler

This commit is contained in:
Jakob Meier
2022-04-30 11:08:36 +02:00
parent 6524f924c9
commit e1ffa97232
3 changed files with 121 additions and 115 deletions

View File

@ -162,7 +162,7 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d
switch (deviceCommand) {
case GET_HK_REPORT: {
sif::warning << "PlocSupervisorHandler::buildCommandFromCommand: Housekeeping report is "
<< "faulty. Needs to be fixed in vorago software" << std::endl;
<< "faulty. Needs to be fixed in vorago software" << std::endl;
prepareEmptyCmd(APID_GET_HK_REPORT);
result = RETURN_OK;
break;
@ -428,11 +428,10 @@ ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::ite
switch (command->first) {
case GET_HK_REPORT: {
enabledReplies = 3;
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, HK_REPORT);
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, HK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< HK_REPORT << " not in replyMap" << std::endl;
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << HK_REPORT
<< " not in replyMap" << std::endl;
}
break;
}
@ -448,8 +447,8 @@ ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::ite
}
case GET_LATCHUP_STATUS_REPORT: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
LATCHUP_REPORT);
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, LATCHUP_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< LATCHUP_REPORT << " not in replyMap" << std::endl;
@ -458,8 +457,8 @@ ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::ite
}
case LOGGING_REQUEST_COUNTERS: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
LOGGING_REPORT);
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, LOGGING_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< LOGGING_REPORT << " not in replyMap" << std::endl;
@ -468,18 +467,17 @@ ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::ite
}
case REQUEST_ADC_REPORT: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
ADC_REPORT);
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, ADC_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< ADC_REPORT << " not in replyMap" << std::endl;
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << ADC_REPORT
<< " not in replyMap" << std::endl;
}
break;
}
case FIRST_MRAM_DUMP: {
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
FIRST_MRAM_DUMP);
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, FIRST_MRAM_DUMP);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< FIRST_MRAM_DUMP << " not in replyMap" << std::endl;
@ -539,15 +537,13 @@ ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::ite
* Every command causes at least one acknowledgment and one execution report. Therefore both
* replies will be enabled here.
*/
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, ACK_REPORT);
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, ACK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << ACK_REPORT
<< " not in replyMap" << std::endl;
}
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, EXE_REPORT);
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, EXE_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << EXE_REPORT
<< " not in replyMap" << std::endl;
@ -792,7 +788,8 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) {
if (result != RETURN_OK) {
triggerEvent(SUPV_MPSOC_SHUWDOWN_BUILD_FAILED);
sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown "
"command" << std::endl;
"command"
<< std::endl;
return;
}
}
@ -806,14 +803,14 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) {
void PlocSupervisorHandler::setExecutionTimeout(DeviceCommandId_t command) {
using namespace supv;
switch(command) {
case FIRST_MRAM_DUMP:
case CONSECUTIVE_MRAM_DUMP:
executionTimeout.setTimeout(MRAM_DUMP_EXECUTION_TIMEOUT);
break;
default:
executionTimeout.setTimeout(EXECUTION_DEFAULT_TIMEOUT);
break;
switch (command) {
case FIRST_MRAM_DUMP:
case CONSECUTIVE_MRAM_DUMP:
executionTimeout.setTimeout(MRAM_DUMP_EXECUTION_TIMEOUT);
break;
default:
executionTimeout.setTimeout(EXECUTION_DEFAULT_TIMEOUT);
break;
}
}
@ -828,10 +825,10 @@ ReturnValue_t PlocSupervisorHandler::verifyPacket(const uint8_t* start, size_t f
ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) {
using namespace supv;
ReturnValue_t result = RETURN_OK;
ReturnValue_t result = RETURN_OK;
AcknowledgmentReport ack;
ack.addWholeData(data, SIZE_ACK_REPORT);
AcknowledgmentReport ack;
ack.addWholeData(data, SIZE_ACK_REPORT);
result = ack.checkCrc();
if (result != RETURN_OK) {
@ -844,12 +841,10 @@ ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) {
return RETURN_OK;
}
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
result = ack.checkApid();
switch (result) {
case supv::APID_ACK_FAILURE: {
case SupvReturnValuesIF::CRC_FAILURE: {
// TODO: Interpretation of status field in acknowledgment report
sif::debug << "PlocSupervisorHandler::handleAckReport: Received Ack failure report"
<< std::endl;
@ -863,43 +858,49 @@ ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) {
result = IGNORE_REPLY_DATA;
break;
}
case supv::APID_ACK_SUCCESS: {
case RETURN_OK: {
setNextReplyId();
break;
}
case SupvReturnValuesIF::INVALID_APID:
sif::warning << "PlocSupervisorHandler::handleAckReport: Invalid APID in Ack report"
<< std::endl;
sendFailureReport(supv::ACK_REPORT, result);
disableAllReplies();
nextReplyId = supv::NONE;
result = IGNORE_REPLY_DATA;
break;
default: {
sif::debug << "PlocSupervisorHandler::handleAckReport: Invalid APID in Ack report"
<< std::endl;
sif::error << "PlocSupervisorHandler::handleAckReport: APID parsing failed" << std::endl;
result = RETURN_FAILED;
break;
}
}
return result;
}
ReturnValue_t PlocSupervisorHandler::handleExecutionReport(const uint8_t* data) {
using namespace supv;
ReturnValue_t result = RETURN_OK;
result = verifyPacket(data, supv::SIZE_EXE_REPORT);
if (result == SupvReturnValuesIF::CRC_FAILURE) {
ExecutionReport exe;
exe.addWholeData(data, SIZE_EXE_REPORT);
result = exe.checkCrc();
if (result != RETURN_OK) {
sif::error << "PlocSupervisorHandler::handleExecutionReport: CRC failure" << std::endl;
nextReplyId = supv::NONE;
return result;
}
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
result = exe.checkApid();
switch (apid) {
case (supv::APID_EXE_SUCCESS): {
handleSpecialExecutionReport(data);
switch (result) {
case (RETURN_OK): {
handleSpecialExecutionReport(data);
break;
}
case (supv::APID_EXE_FAILURE): {
// TODO: Interpretation of status field in execution report
sif::error
<< "PlocSupervisorHandler::handleExecutionReport: Received execution failure report"
<< std::endl;
case (SupvReturnValuesIF::RECEIVED_EXE_FAILURE): {
DeviceCommandId_t commandId = getPendingCommand();
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
triggerEvent(SUPV_EXE_FAILURE, commandId);
@ -907,9 +908,7 @@ ReturnValue_t PlocSupervisorHandler::handleExecutionReport(const uint8_t* data)
sif::debug << "PlocSupervisorHandler::handleExecutionReport: Unknown command id"
<< std::endl;
}
uint16_t status = *(data + EXE_STATUS_OFFSET) << 8 | *(data + EXE_STATUS_OFFSET + 1);
sif::info << "Execution status: 0x" << std::hex << status << std::endl;
sendFailureReport(supv::EXE_REPORT, SupvReturnValuesIF::RECEIVED_EXE_FAILURE);
sendFailureReport(EXE_REPORT, SupvReturnValuesIF::RECEIVED_EXE_FAILURE);
disableExeReportReply();
result = IGNORE_REPLY_DATA;
break;
@ -1038,7 +1037,8 @@ ReturnValue_t PlocSupervisorHandler::handleBootStatusReport(const uint8_t* data)
nextReplyId = supv::EXE_REPORT;
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
sif::info << "PlocSupervisorHandler::handleBootStatusReport: SoC State (0 - off, 1 - booting, 3 - operating): "
sif::info << "PlocSupervisorHandler::handleBootStatusReport: SoC State (0 - off, 1 - booting, 3 "
"- operating, 4 - Shutdown): "
<< static_cast<unsigned int>(bootStatusReport.socState.value) << std::endl;
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Power Cycles: "
<< static_cast<unsigned int>(bootStatusReport.powerCycles.value) << std::endl;
@ -1167,7 +1167,8 @@ ReturnValue_t PlocSupervisorHandler::handleLoggingReport(const uint8_t* data) {
size_t size = loggingReport.getSerializedSize();
result = loggingReport.deSerialize(&dataField, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::warning << "PlocSupervisorHandler::handleLoggingReport: Deserialization failed" << std::endl;
sif::warning << "PlocSupervisorHandler::handleLoggingReport: Deserialization failed"
<< std::endl;
}
loggingReport.setValidityBufferGeneration(true);
loggingReport.setValidity(true, true);
@ -1594,7 +1595,9 @@ ReturnValue_t PlocSupervisorHandler::parseMramPackets(const uint8_t* packet, siz
*foundLen = remainingSize;
disableAllReplies();
bufferTop = 0;
sif::info << "PlocSupervisorHandler::parseMramPackets: Can not find MRAM packet in space packet buffer" << std::endl;
sif::info << "PlocSupervisorHandler::parseMramPackets: Can not find MRAM packet in space "
"packet buffer"
<< std::endl;
return SupvReturnValuesIF::MRAM_PACKET_PARSING_FAILURE;
}
}
@ -1679,7 +1682,8 @@ void PlocSupervisorHandler::increaseExpectedMramReplies(DeviceCommandId_t id) {
ReturnValue_t PlocSupervisorHandler::checkMramPacketApid() {
uint16_t apid = (spacePacketBuffer[0] << 8 | spacePacketBuffer[1]) & supv::APID_MASK;
if (apid != supv::APID_MRAM_DUMP_TM) {
sif::warning << "PlocSupervisorHandler::checkMramPacketApid: 0x" << std::hex << apid << std::endl;
sif::warning << "PlocSupervisorHandler::checkMramPacketApid: 0x" << std::hex << apid
<< std::endl;
return SupvReturnValuesIF::NO_MRAM_PACKET;
}
return APERIODIC_REPLY;
@ -1821,18 +1825,18 @@ ReturnValue_t PlocSupervisorHandler::eventSubscription() {
void PlocSupervisorHandler::handleSpecialExecutionReport(const uint8_t* data) {
DeviceCommandId_t commandId = getPendingCommand();
switch(commandId) {
case supv::READ_GPIO: {
supv::ExecutionReport exe;
exe.addWholeData(data, supv::SIZE_EXE_REPORT);
uint16_t gpioState = exe.getStatusCode();
switch (commandId) {
case supv::READ_GPIO: {
supv::ExecutionReport exe;
exe.addWholeData(data, supv::SIZE_EXE_REPORT);
uint16_t gpioState = exe.getStatusCode();
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
sif::info << "PlocsupervisorHandler: Read GPIO TM, State: " << gpioState << std::endl;
sif::info << "PlocsupervisorHandler: Read GPIO TM, State: " << gpioState << std::endl;
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
handleDeviceTM(reinterpret_cast<uint8_t*>(&gpioState), sizeof(gpioState), supv::EXE_REPORT);
break;
}
default:
break;
handleDeviceTM(reinterpret_cast<uint8_t*>(&gpioState), sizeof(gpioState), supv::EXE_REPORT);
break;
}
default:
break;
}
}