event buffer request wip

This commit is contained in:
Jakob Meier
2022-04-13 11:56:37 +02:00
parent 7f51ffc8fb
commit bd8cd49117
12 changed files with 627 additions and 789 deletions

View File

@ -21,6 +21,7 @@ PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t u
hkset(this),
bootStatusReport(this),
latchupStatusReport(this),
loggingReport(this),
powerSwitch(powerSwitch),
supvHelper(supvHelper) {
if (comCookie == NULL) {
@ -81,10 +82,11 @@ void PlocSupervisorHandler::performOperationHook() {
ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) {
using namespace supv;
ReturnValue_t result = RETURN_OK;
switch (actionId) {
case supv::TERMINATE_SUPV_HELPER: {
case TERMINATE_SUPV_HELPER: {
supvHelper->stopProcess();
break;
}
@ -97,7 +99,7 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
}
switch (actionId) {
case supv::PERFORM_UPDATE: {
case PERFORM_UPDATE: {
if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
return SupvReturnValuesIF::FILENAME_TOO_LONG;
}
@ -115,6 +117,11 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
plocSupvHelperExecuting = true;
return EXECUTION_FINISHED;
}
case LOGGING_REQUEST_EVENT_BUFFERS:
if (size > config::MAX_PATH_SIZE) {
return SupvReturnValuesIF::FILENAME_TOO_LONG;
}
supvHelper->startEventbBufferRequest(std::string(reinterpret_cast<const char*>(data), size));
default:
break;
}
@ -142,213 +149,193 @@ ReturnValue_t PlocSupervisorHandler::buildTransitionDeviceCommand(DeviceCommandI
ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData,
size_t commandDataLen) {
using namespace supv;
ReturnValue_t result = RETURN_FAILED;
switch (deviceCommand) {
case (supv::GET_HK_REPORT): {
prepareEmptyCmd(supv::APID_GET_HK_REPORT);
case GET_HK_REPORT: {
prepareEmptyCmd(APID_GET_HK_REPORT);
result = RETURN_OK;
break;
}
case (supv::RESTART_MPSOC): {
prepareEmptyCmd(supv::APID_RESTART_MPSOC);
case START_MPSOC: {
prepareEmptyCmd(APID_START_MPSOC);
result = RETURN_OK;
break;
}
case (supv::START_MPSOC): {
prepareEmptyCmd(supv::APID_START_MPSOC);
case SHUTDOWN_MPSOC: {
prepareEmptyCmd(APID_SHUTWOWN_MPSOC);
result = RETURN_OK;
break;
}
case (supv::SHUTDOWN_MPSOC): {
prepareEmptyCmd(supv::APID_SHUTWOWN_MPSOC);
result = RETURN_OK;
break;
}
case (supv::SEL_MPSOC_BOOT_IMAGE): {
case SEL_MPSOC_BOOT_IMAGE: {
prepareSelBootImageCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::RESET_MPSOC): {
prepareEmptyCmd(supv::APID_RESET_MPSOC);
case RESET_MPSOC: {
prepareEmptyCmd(APID_RESET_MPSOC);
result = RETURN_OK;
break;
}
case (supv::SET_TIME_REF): {
case SET_TIME_REF: {
result = prepareSetTimeRefCmd();
break;
}
case (supv::SET_BOOT_TIMEOUT): {
case SET_BOOT_TIMEOUT: {
prepareSetBootTimeoutCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::SET_MAX_RESTART_TRIES): {
case SET_MAX_RESTART_TRIES: {
prepareRestartTriesCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::DISABLE_PERIOIC_HK_TRANSMISSION): {
case DISABLE_PERIOIC_HK_TRANSMISSION: {
prepareDisableHk();
result = RETURN_OK;
break;
}
case (supv::GET_BOOT_STATUS_REPORT): {
prepareEmptyCmd(supv::APID_GET_BOOT_STATUS_RPT);
case GET_BOOT_STATUS_REPORT: {
prepareEmptyCmd(APID_GET_BOOT_STATUS_RPT);
result = RETURN_OK;
break;
}
case (supv::WATCHDOGS_ENABLE): {
prepareWatchdogsEnableCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::WATCHDOGS_CONFIG_TIMEOUT): {
result = prepareWatchdogsConfigTimeoutCmd(commandData);
break;
}
case (supv::ENABLE_LATCHUP_ALERT): {
case ENABLE_LATCHUP_ALERT: {
result = prepareLatchupConfigCmd(commandData, deviceCommand);
break;
}
case (supv::DISABLE_LATCHUP_ALERT): {
case DISABLE_LATCHUP_ALERT: {
result = prepareLatchupConfigCmd(commandData, deviceCommand);
break;
}
case (supv::AUTO_CALIBRATE_ALERT): {
result = prepareAutoCalibrateAlertCmd(commandData);
break;
}
case (supv::SET_ALERT_LIMIT): {
case SET_ALERT_LIMIT: {
result = prepareSetAlertLimitCmd(commandData);
break;
}
case (supv::SET_ALERT_IRQ_FILTER): {
result = prepareSetAlertIrqFilterCmd(commandData);
break;
}
case (supv::SET_ADC_SWEEP_PERIOD): {
result = prepareSetAdcSweetPeriodCmd(commandData);
break;
}
case (supv::SET_ADC_ENABLED_CHANNELS): {
case SET_ADC_ENABLED_CHANNELS: {
prepareSetAdcEnabledChannelsCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::SET_ADC_WINDOW_AND_STRIDE): {
case SET_ADC_WINDOW_AND_STRIDE: {
prepareSetAdcWindowAndStrideCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::SET_ADC_THRESHOLD): {
case SET_ADC_THRESHOLD: {
prepareSetAdcThresholdCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::GET_LATCHUP_STATUS_REPORT): {
prepareEmptyCmd(supv::APID_GET_LATCHUP_STATUS_REPORT);
case GET_LATCHUP_STATUS_REPORT: {
prepareEmptyCmd(APID_GET_LATCHUP_STATUS_REPORT);
result = RETURN_OK;
break;
}
case (supv::COPY_ADC_DATA_TO_MRAM): {
prepareEmptyCmd(supv::APID_COPY_ADC_DATA_TO_MRAM);
case COPY_ADC_DATA_TO_MRAM: {
prepareEmptyCmd(APID_COPY_ADC_DATA_TO_MRAM);
result = RETURN_OK;
break;
}
case (supv::ENABLE_NVMS): {
prepareEnableNvmsCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::SELECT_NVM): {
prepareSelectNvmCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::RUN_AUTO_EM_TESTS): {
case RUN_AUTO_EM_TESTS: {
result = prepareRunAutoEmTest(commandData);
break;
}
case (supv::WIPE_MRAM): {
case WIPE_MRAM: {
result = prepareWipeMramCmd(commandData);
break;
}
case (supv::FIRST_MRAM_DUMP):
case (supv::CONSECUTIVE_MRAM_DUMP):
case FIRST_MRAM_DUMP:
case CONSECUTIVE_MRAM_DUMP:
result = prepareDumpMramCmd(commandData);
break;
case (supv::PRINT_CPU_STATS): {
preparePrintCpuStatsCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::SET_DBG_VERBOSITY): {
prepareSetDbgVerbosityCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::CAN_LOOPBACK_TEST): {
prepareEmptyCmd(supv::APID_CAN_LOOPBACK_TEST);
result = RETURN_OK;
break;
}
case (supv::SET_GPIO): {
case SET_GPIO: {
prepareSetGpioCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::READ_GPIO): {
case READ_GPIO: {
prepareReadGpioCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::RESTART_SUPERVISOR): {
prepareEmptyCmd(supv::APID_RESTART_SUPERVISOR);
case RESTART_SUPERVISOR: {
prepareEmptyCmd(APID_RESTART_SUPERVISOR);
result = RETURN_OK;
break;
}
case (supv::FACTORY_RESET_CLEAR_ALL): {
supv::FactoryReset packet(supv::FactoryReset::Op::CLEAR_ALL);
case FACTORY_RESET_CLEAR_ALL: {
FactoryReset packet(FactoryReset::Op::CLEAR_ALL);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case (supv::FACTORY_RESET_CLEAR_MIRROR): {
supv::FactoryReset packet(supv::FactoryReset::Op::MIRROR_ENTRIES);
case FACTORY_RESET_CLEAR_MIRROR: {
FactoryReset packet(FactoryReset::Op::MIRROR_ENTRIES);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case (supv::FACTORY_RESET_CLEAR_CIRCULAR): {
supv::FactoryReset packet(supv::FactoryReset::Op::CIRCULAR_ENTRIES);
case FACTORY_RESET_CLEAR_CIRCULAR: {
FactoryReset packet(FactoryReset::Op::CIRCULAR_ENTRIES);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case (supv::START_MPSOC_QUIET): {
prepareEmptyCmd(supv::APID_START_MPSOC_QUIET);
case START_MPSOC_QUIET: {
prepareEmptyCmd(APID_START_MPSOC_QUIET);
result = RETURN_OK;
break;
}
case (supv::SET_SHUTDOWN_TIMEOUT): {
case SET_SHUTDOWN_TIMEOUT: {
prepareSetShutdownTimeoutCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::FACTORY_FLASH): {
prepareEmptyCmd(supv::APID_FACTORY_FLASH);
case FACTORY_FLASH: {
prepareEmptyCmd(APID_FACTORY_FLASH);
result = RETURN_OK;
break;
}
case (supv::ENABLE_AUTO_TM): {
supv::EnableAutoTm packet;
case ENABLE_AUTO_TM: {
EnableAutoTm packet;
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case (supv::DISABLE_AUTO_TM): {
supv::DisableAutoTm packet;
case DISABLE_AUTO_TM: {
DisableAutoTm packet;
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case ENABLE_ADC_MONITOR_TASK: {
EnableAdcMonitorTask packet;
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case DISABLE_ADC_MONITOR_TASK: {
DisableAdcMonitorTask packet;
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case LOGGING_REQUEST_COUNTERS: {
RequestLoggingData packet(RequestLoggingData::Sa::REQUEST_COUNTERS);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case LOGGING_CLEAR_COUNTERS: {
RequestLoggingData packet(RequestLoggingData::Sa::CLEAR_COUNTERS);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
case LOGGING_SET_TOPIC: {
RequestLoggingData packet(RequestLoggingData::Sa::SET_LOGGING_TOPIC);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
@ -371,57 +358,178 @@ ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t d
}
void PlocSupervisorHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(supv::GET_HK_REPORT);
this->insertInCommandMap(supv::RESTART_MPSOC);
this->insertInCommandMap(supv::START_MPSOC);
this->insertInCommandMap(supv::SHUTDOWN_MPSOC);
this->insertInCommandMap(supv::SEL_MPSOC_BOOT_IMAGE);
this->insertInCommandMap(supv::SET_BOOT_TIMEOUT);
this->insertInCommandMap(supv::SET_MAX_RESTART_TRIES);
this->insertInCommandMap(supv::RESET_MPSOC);
this->insertInCommandMap(supv::SET_TIME_REF);
this->insertInCommandMap(supv::DISABLE_PERIOIC_HK_TRANSMISSION);
this->insertInCommandMap(supv::GET_BOOT_STATUS_REPORT);
this->insertInCommandMap(supv::WATCHDOGS_ENABLE);
this->insertInCommandMap(supv::WATCHDOGS_CONFIG_TIMEOUT);
this->insertInCommandMap(supv::ENABLE_LATCHUP_ALERT);
this->insertInCommandMap(supv::DISABLE_LATCHUP_ALERT);
this->insertInCommandMap(supv::AUTO_CALIBRATE_ALERT);
this->insertInCommandMap(supv::SET_ALERT_LIMIT);
this->insertInCommandMap(supv::SET_ALERT_IRQ_FILTER);
this->insertInCommandMap(supv::SET_ADC_SWEEP_PERIOD);
this->insertInCommandMap(supv::SET_ADC_ENABLED_CHANNELS);
this->insertInCommandMap(supv::SET_ADC_WINDOW_AND_STRIDE);
this->insertInCommandMap(supv::SET_ADC_THRESHOLD);
this->insertInCommandMap(supv::GET_LATCHUP_STATUS_REPORT);
this->insertInCommandMap(supv::COPY_ADC_DATA_TO_MRAM);
this->insertInCommandMap(supv::ENABLE_NVMS);
this->insertInCommandMap(supv::SELECT_NVM);
this->insertInCommandMap(supv::RUN_AUTO_EM_TESTS);
this->insertInCommandMap(supv::WIPE_MRAM);
this->insertInCommandMap(supv::PRINT_CPU_STATS);
this->insertInCommandMap(supv::SET_DBG_VERBOSITY);
this->insertInCommandMap(supv::SET_GPIO);
this->insertInCommandMap(supv::READ_GPIO);
this->insertInCommandMap(supv::RESTART_SUPERVISOR);
this->insertInCommandMap(supv::FACTORY_RESET_CLEAR_ALL);
this->insertInCommandMap(supv::FACTORY_RESET_CLEAR_MIRROR);
this->insertInCommandMap(supv::FACTORY_RESET_CLEAR_CIRCULAR);
this->insertInCommandMap(supv::CAN_LOOPBACK_TEST);
this->insertInCommandMap(supv::START_MPSOC_QUIET);
this->insertInCommandMap(supv::SET_SHUTDOWN_TIMEOUT);
this->insertInCommandMap(supv::FACTORY_FLASH);
this->insertInCommandMap(supv::ENABLE_AUTO_TM);
this->insertInCommandMap(supv::DISABLE_AUTO_TM);
this->insertInCommandAndReplyMap(supv::FIRST_MRAM_DUMP, 3);
this->insertInCommandAndReplyMap(supv::CONSECUTIVE_MRAM_DUMP, 3);
this->insertInReplyMap(supv::ACK_REPORT, 3, nullptr, supv::SIZE_ACK_REPORT);
this->insertInReplyMap(supv::EXE_REPORT, 120, nullptr, supv::SIZE_EXE_REPORT);
this->insertInReplyMap(supv::HK_REPORT, 3, &hkset, supv::SIZE_HK_REPORT);
this->insertInReplyMap(supv::BOOT_STATUS_REPORT, 3, &bootStatusReport,
supv::SIZE_BOOT_STATUS_REPORT);
this->insertInReplyMap(supv::LATCHUP_REPORT, 3, &latchupStatusReport,
supv::SIZE_LATCHUP_STATUS_REPORT);
using namespace supv;
this->insertInCommandMap(GET_HK_REPORT);
this->insertInCommandMap(START_MPSOC);
this->insertInCommandMap(SHUTDOWN_MPSOC);
this->insertInCommandMap(SEL_MPSOC_BOOT_IMAGE);
this->insertInCommandMap(SET_BOOT_TIMEOUT);
this->insertInCommandMap(SET_MAX_RESTART_TRIES);
this->insertInCommandMap(RESET_MPSOC);
this->insertInCommandMap(SET_TIME_REF);
this->insertInCommandMap(DISABLE_PERIOIC_HK_TRANSMISSION);
this->insertInCommandMap(GET_BOOT_STATUS_REPORT);
this->insertInCommandMap(ENABLE_LATCHUP_ALERT);
this->insertInCommandMap(DISABLE_LATCHUP_ALERT);
this->insertInCommandMap(SET_ALERT_LIMIT);
this->insertInCommandMap(SET_ADC_ENABLED_CHANNELS);
this->insertInCommandMap(SET_ADC_WINDOW_AND_STRIDE);
this->insertInCommandMap(SET_ADC_THRESHOLD);
this->insertInCommandMap(GET_LATCHUP_STATUS_REPORT);
this->insertInCommandMap(COPY_ADC_DATA_TO_MRAM);
this->insertInCommandMap(RUN_AUTO_EM_TESTS);
this->insertInCommandMap(WIPE_MRAM);
this->insertInCommandMap(PRINT_CPU_STATS);
this->insertInCommandMap(SET_GPIO);
this->insertInCommandMap(READ_GPIO);
this->insertInCommandMap(RESTART_SUPERVISOR);
this->insertInCommandMap(FACTORY_RESET_CLEAR_ALL);
this->insertInCommandMap(FACTORY_RESET_CLEAR_MIRROR);
this->insertInCommandMap(FACTORY_RESET_CLEAR_CIRCULAR);
this->insertInCommandMap(START_MPSOC_QUIET);
this->insertInCommandMap(SET_SHUTDOWN_TIMEOUT);
this->insertInCommandMap(FACTORY_FLASH);
this->insertInCommandMap(ENABLE_AUTO_TM);
this->insertInCommandMap(DISABLE_AUTO_TM);
this->insertInCommandMap(ENABLE_ADC_MONITOR_TASK);
this->insertInCommandMap(DISABLE_ADC_MONITOR_TASK);
this->insertInCommandMap(LOGGING_REQUEST_COUNTERS);
this->insertInCommandAndReplyMap(FIRST_MRAM_DUMP, 3);
this->insertInCommandAndReplyMap(CONSECUTIVE_MRAM_DUMP, 3);
this->insertInReplyMap(ACK_REPORT, 3, nullptr, SIZE_ACK_REPORT);
this->insertInReplyMap(EXE_REPORT, 3, nullptr, SIZE_EXE_REPORT);
this->insertInReplyMap(HK_REPORT, 3, &hkset, SIZE_HK_REPORT);
this->insertInReplyMap(BOOT_STATUS_REPORT, 3, &bootStatusReport, SIZE_BOOT_STATUS_REPORT);
this->insertInReplyMap(LATCHUP_REPORT, 3, &latchupStatusReport, SIZE_LATCHUP_STATUS_REPORT);
this->insertInReplyMap(LOGGING_REPORT, 3, &loggingReport, SIZE_LOGGING_REPORT);
}
ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
uint8_t expectedReplies,
bool useAlternateId,
DeviceCommandId_t alternateReplyID) {
ReturnValue_t result = RETURN_OK;
uint8_t enabledReplies = 0;
switch (command->first) {
case supv::GET_HK_REPORT: {
enabledReplies = 3;
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::HK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::HK_REPORT << " not in replyMap" << std::endl;
}
break;
}
case supv::GET_BOOT_STATUS_REPORT: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::BOOT_STATUS_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::BOOT_STATUS_REPORT << " not in replyMap" << std::endl;
}
break;
}
case supv::GET_LATCHUP_STATUS_REPORT: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::LATCHUP_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::LATCHUP_REPORT << " not in replyMap" << std::endl;
}
break;
}
case supv::LOGGING_REQUEST_COUNTERS: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::LOGGING_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::LOGGING_REPORT << " not in replyMap" << std::endl;
}
break;
}
case supv::FIRST_MRAM_DUMP: {
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::FIRST_MRAM_DUMP);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::FIRST_MRAM_DUMP << " not in replyMap" << std::endl;
}
break;
}
case supv::CONSECUTIVE_MRAM_DUMP: {
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::CONSECUTIVE_MRAM_DUMP);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::CONSECUTIVE_MRAM_DUMP << " not in replyMap" << std::endl;
}
break;
}
case supv::START_MPSOC:
case supv::SHUTDOWN_MPSOC:
case supv::SEL_MPSOC_BOOT_IMAGE:
case supv::SET_BOOT_TIMEOUT:
case supv::SET_MAX_RESTART_TRIES:
case supv::RESET_MPSOC:
case supv::SET_TIME_REF:
case supv::ENABLE_LATCHUP_ALERT:
case supv::DISABLE_LATCHUP_ALERT:
case supv::SET_ALERT_LIMIT:
case supv::SET_ADC_ENABLED_CHANNELS:
case supv::SET_ADC_WINDOW_AND_STRIDE:
case supv::SET_ADC_THRESHOLD:
case supv::COPY_ADC_DATA_TO_MRAM:
case supv::RUN_AUTO_EM_TESTS:
case supv::WIPE_MRAM:
case supv::PRINT_CPU_STATS:
case supv::SET_GPIO:
case supv::READ_GPIO:
case supv::RESTART_SUPERVISOR:
case supv::FACTORY_RESET_CLEAR_ALL:
case supv::FACTORY_RESET_CLEAR_MIRROR:
case supv::FACTORY_RESET_CLEAR_CIRCULAR:
case supv::DISABLE_PERIOIC_HK_TRANSMISSION:
case supv::START_MPSOC_QUIET:
case supv::SET_SHUTDOWN_TIMEOUT:
case supv::FACTORY_FLASH:
case supv::ENABLE_AUTO_TM:
case supv::DISABLE_AUTO_TM:
case supv::ENABLE_ADC_MONITOR_TASK:
case supv::DISABLE_ADC_MONITOR_TASK:
enabledReplies = 2;
break;
default:
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Unknown command id" << std::endl;
break;
}
/**
* Every command causes at least one acknowledgment and one execution report. Therefore both
* replies will be enabled here.
*/
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::ACK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << supv::ACK_REPORT
<< " not in replyMap" << std::endl;
}
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::EXE_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << supv::EXE_REPORT
<< " not in replyMap" << std::endl;
}
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::scanForReply(const uint8_t* start, size_t remainingSize,
@ -459,6 +567,10 @@ ReturnValue_t PlocSupervisorHandler::scanForReply(const uint8_t* start, size_t r
*foundLen = supv::SIZE_LATCHUP_STATUS_REPORT;
*foundId = supv::LATCHUP_REPORT;
break;
case (supv::APID_DATA_LOGGER_DATA):
*foundLen = supv::SIZE_LOGGING_REPORT;
*foundId = supv::LOGGING_REPORT;
break;
case (supv::APID_EXE_SUCCESS):
*foundLen = supv::SIZE_EXE_REPORT;
*foundId = supv::EXE_REPORT;
@ -508,6 +620,10 @@ ReturnValue_t PlocSupervisorHandler::interpretDeviceReply(DeviceCommandId_t id,
result = handleLatchupStatusReport(packet);
break;
}
case (supv::LOGGING_REPORT): {
result = handleLoggingReport(packet);
break;
}
case (supv::FIRST_MRAM_DUMP):
case (supv::CONSECUTIVE_MRAM_DUMP):
result = handleMramDumpPacket(id);
@ -587,133 +703,6 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) {
}
}
ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
uint8_t expectedReplies,
bool useAlternateId,
DeviceCommandId_t alternateReplyID) {
ReturnValue_t result = RETURN_OK;
uint8_t enabledReplies = 0;
switch (command->first) {
case supv::GET_HK_REPORT: {
enabledReplies = 3;
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::HK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::HK_REPORT << " not in replyMap" << std::endl;
}
break;
}
case supv::GET_BOOT_STATUS_REPORT: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::BOOT_STATUS_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::BOOT_STATUS_REPORT << " not in replyMap" << std::endl;
}
break;
}
case supv::GET_LATCHUP_STATUS_REPORT: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::LATCHUP_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::LATCHUP_REPORT << " not in replyMap" << std::endl;
}
break;
}
case supv::FIRST_MRAM_DUMP: {
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::FIRST_MRAM_DUMP);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::FIRST_MRAM_DUMP << " not in replyMap" << std::endl;
}
break;
}
case supv::CONSECUTIVE_MRAM_DUMP: {
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
supv::CONSECUTIVE_MRAM_DUMP);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
<< supv::CONSECUTIVE_MRAM_DUMP << " not in replyMap" << std::endl;
}
break;
}
case supv::RESTART_MPSOC:
case supv::START_MPSOC:
case supv::SHUTDOWN_MPSOC:
case supv::SEL_MPSOC_BOOT_IMAGE:
case supv::SET_BOOT_TIMEOUT:
case supv::SET_MAX_RESTART_TRIES:
case supv::RESET_MPSOC:
case supv::SET_TIME_REF:
case supv::WATCHDOGS_ENABLE:
case supv::WATCHDOGS_CONFIG_TIMEOUT:
case supv::ENABLE_LATCHUP_ALERT:
case supv::DISABLE_LATCHUP_ALERT:
case supv::AUTO_CALIBRATE_ALERT:
case supv::SET_ALERT_LIMIT:
case supv::SET_ALERT_IRQ_FILTER:
case supv::SET_ADC_SWEEP_PERIOD:
case supv::SET_ADC_ENABLED_CHANNELS:
case supv::SET_ADC_WINDOW_AND_STRIDE:
case supv::SET_ADC_THRESHOLD:
case supv::COPY_ADC_DATA_TO_MRAM:
case supv::ENABLE_NVMS:
case supv::SELECT_NVM:
case supv::RUN_AUTO_EM_TESTS:
case supv::WIPE_MRAM:
case supv::SET_DBG_VERBOSITY:
case supv::CAN_LOOPBACK_TEST:
case supv::PRINT_CPU_STATS:
case supv::SET_GPIO:
case supv::READ_GPIO:
case supv::RESTART_SUPERVISOR:
case supv::FACTORY_RESET_CLEAR_ALL:
case supv::FACTORY_RESET_CLEAR_MIRROR:
case supv::FACTORY_RESET_CLEAR_CIRCULAR:
case supv::REQUEST_LOGGING_DATA:
case supv::DISABLE_PERIOIC_HK_TRANSMISSION:
case supv::START_MPSOC_QUIET:
case supv::SET_SHUTDOWN_TIMEOUT:
case supv::FACTORY_FLASH:
case supv::ENABLE_AUTO_TM:
case supv::DISABLE_AUTO_TM:
enabledReplies = 2;
break;
default:
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Unknown command id" << std::endl;
break;
}
/**
* Every command causes at least one acknowledgment and one execution report. Therefore both
* replies will be enabled here.
*/
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::ACK_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << supv::ACK_REPORT
<< " not in replyMap" << std::endl;
}
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::EXE_REPORT);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << supv::EXE_REPORT
<< " not in replyMap" << std::endl;
}
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1);
uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2);
@ -1037,6 +1026,41 @@ ReturnValue_t PlocSupervisorHandler::handleLatchupStatusReport(const uint8_t* da
return result;
}
ReturnValue_t PlocSupervisorHandler::handleLoggingReport(const uint8_t* data) {
ReturnValue_t result = RETURN_OK;
result = verifyPacket(data, supv::SIZE_LOGGING_REPORT);
if (result == SupvReturnValuesIF::CRC_FAILURE) {
sif::error << "PlocSupervisorHandler::handleLoggingReport: Logging report has "
<< "invalid crc" << std::endl;
return result;
}
const uint8_t* dataField = data + supv::DATA_FIELD_OFFSET + sizeof(sa);
result = loggingReport.read();
if (result != RETURN_OK) {
return result;
}
loggingReport.setValidityBufferGeneration(false);
size_t size = loggingReport.getSerializedSize();
result = loggingReport.deSerialize(&dataField, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::handleLoggingReport: Deserialization failed" << std::endl;
}
loggingReport.setValidityBufferGeneration(true);
loggingReport.setValidity(true, true);
result = loggingReport.commit();
if (result != RETURN_OK) {
return result;
}
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
loggingReport.printSet();
#endif
nextReplyId = supv::EXE_REPORT;
return result;
}
void PlocSupervisorHandler::setNextReplyId() {
switch (getPendingCommand()) {
case supv::GET_HK_REPORT:
@ -1161,34 +1185,6 @@ void PlocSupervisorHandler::prepareRestartTriesCmd(const uint8_t* commandData) {
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
void PlocSupervisorHandler::prepareWatchdogsEnableCmd(const uint8_t* commandData) {
uint8_t offset = 0;
uint8_t watchdogPs = *(commandData + offset);
offset += 1;
uint8_t watchdogPl = *(commandData + offset);
offset += 1;
uint8_t watchdogInt = *(commandData + offset);
supv::WatchdogsEnable packet(watchdogPs, watchdogPl, watchdogInt);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
ReturnValue_t PlocSupervisorHandler::prepareWatchdogsConfigTimeoutCmd(const uint8_t* commandData) {
uint8_t offset = 0;
uint8_t watchdog = *(commandData + offset);
offset += 1;
if (watchdog > 2) {
return SupvReturnValuesIF::INVALID_WATCHDOG;
}
uint32_t timeout = *(commandData + offset) << 24 | *(commandData + offset + 1) << 16 |
*(commandData + offset + 2) << 8 | *(commandData + offset + 3);
if (timeout < 1000 || timeout > 360000) {
return SupvReturnValuesIF::INVALID_WATCHDOG_TIMEOUT;
}
supv::WatchdogsConfigTimeout packet(watchdog, timeout);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::prepareLatchupConfigCmd(const uint8_t* commandData,
DeviceCommandId_t deviceCommand) {
ReturnValue_t result = RETURN_OK;
@ -1217,32 +1213,6 @@ ReturnValue_t PlocSupervisorHandler::prepareLatchupConfigCmd(const uint8_t* comm
return result;
}
ReturnValue_t PlocSupervisorHandler::prepareAutoCalibrateAlertCmd(const uint8_t* commandData) {
uint8_t offset = 0;
uint8_t latchupId = *commandData;
offset += 1;
uint32_t mg = *(commandData + offset) << 24 | *(commandData + offset + 1) << 16 |
*(commandData + offset + 2) << 8 | *(commandData + offset + 3);
if (latchupId > 6) {
return SupvReturnValuesIF::INVALID_LATCHUP_ID;
}
supv::AutoCalibrateAlert packet(latchupId, mg);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::prepareSetAlertIrqFilterCmd(const uint8_t* commandData) {
uint8_t latchupId = *commandData;
uint8_t tp = *(commandData + 1);
uint8_t div = *(commandData + 2);
if (latchupId > 6) {
return SupvReturnValuesIF::INVALID_LATCHUP_ID;
}
supv::SetAlertIrqFilter packet(latchupId, tp, div);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::prepareSetAlertLimitCmd(const uint8_t* commandData) {
uint8_t offset = 0;
uint8_t latchupId = *commandData;
@ -1257,17 +1227,6 @@ ReturnValue_t PlocSupervisorHandler::prepareSetAlertLimitCmd(const uint8_t* comm
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::prepareSetAdcSweetPeriodCmd(const uint8_t* commandData) {
uint32_t sweepPeriod = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 |
*(commandData + 3);
if (sweepPeriod < 21) {
return SupvReturnValuesIF::SWEEP_PERIOD_TOO_SMALL;
}
supv::SetAdcSweepPeriod packet(sweepPeriod);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
void PlocSupervisorHandler::prepareSetAdcEnabledChannelsCmd(const uint8_t* commandData) {
uint16_t ch = *(commandData) << 8 | *(commandData + 1);
supv::SetAdcEnabledChannels packet(ch);
@ -1290,19 +1249,6 @@ void PlocSupervisorHandler::prepareSetAdcThresholdCmd(const uint8_t* commandData
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
void PlocSupervisorHandler::prepareEnableNvmsCmd(const uint8_t* commandData) {
uint8_t n01 = *commandData;
uint8_t n3 = *(commandData + 1);
supv::EnableNvms packet(n01, n3);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
void PlocSupervisorHandler::prepareSelectNvmCmd(const uint8_t* commandData) {
uint8_t mem = *commandData;
supv::SelectNvm packet(mem);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
ReturnValue_t PlocSupervisorHandler::prepareRunAutoEmTest(const uint8_t* commandData) {
uint8_t test = *commandData;
if (test != 1 && test != 2) {
@ -1346,18 +1292,6 @@ ReturnValue_t PlocSupervisorHandler::prepareDumpMramCmd(const uint8_t* commandDa
return RETURN_OK;
}
void PlocSupervisorHandler::preparePrintCpuStatsCmd(const uint8_t* commandData) {
uint8_t en = *commandData;
supv::PrintCpuStats packet(en);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
void PlocSupervisorHandler::prepareSetDbgVerbosityCmd(const uint8_t* commandData) {
uint8_t vb = *commandData;
supv::SetDbgVerbosity packet(vb);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
void PlocSupervisorHandler::prepareSetGpioCmd(const uint8_t* commandData) {
uint8_t port = *commandData;
uint8_t pin = *(commandData + 1);
@ -1395,6 +1329,15 @@ void PlocSupervisorHandler::prepareSetShutdownTimeoutCmd(const uint8_t* commandD
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
ReturnValue_t PlocSupervisorHandler::prepareLoggingRequest(const uint8_t* commandData,
size_t commandDataLen) {
uint8_t sa = *commandData;
uint8_t tpc = *(commandData + 1);
supv::RequestLoggingData packet(sa, tpc);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
void PlocSupervisorHandler::disableAllReplies() {
DeviceReplyMap::iterator iter;
@ -1690,7 +1633,7 @@ ReturnValue_t PlocSupervisorHandler::eventSubscription() {
}
result = manager->subscribeToEventRange(
eventQueue->getId(), event::getEventId(PlocSupvHelper::SUPV_UPDATE_FAILED),
event::getEventId(PlocSupvHelper::TERMINATED_UPDATE_PROCEDURE));
event::getEventId(PlocSupvHelper::SUPV_EVENT_BUFFER_REQUEST_TERMINATED));
if (result != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "PlocSupervisorHandler::eventSubscritpion: Failed to subscribe to events from "