2021-07-13 08:32:14 +02:00
|
|
|
#include "PlocSupervisorHandler.h"
|
|
|
|
|
|
|
|
#include <fsfw/datapool/PoolReadGuard.h>
|
2022-01-18 11:41:19 +01:00
|
|
|
#include <fsfw/globalfunctions/CRC.h>
|
2021-07-13 08:32:14 +02:00
|
|
|
#include <fsfw/timemanager/Clock.h>
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "OBSWConfig.h"
|
|
|
|
|
2021-07-28 08:38:36 +02:00
|
|
|
PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid,
|
2022-01-18 11:41:19 +01:00
|
|
|
CookieIF* comCookie)
|
|
|
|
: DeviceHandlerBase(objectId, uartComIFid, comCookie),
|
|
|
|
hkset(this),
|
|
|
|
bootStatusReport(this),
|
|
|
|
latchupStatusReport(this) {
|
|
|
|
if (comCookie == NULL) {
|
|
|
|
sif::error << "PlocSupervisorHandler: Invalid com cookie" << std::endl;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
PlocSupervisorHandler::~PlocSupervisorHandler() {}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2021-07-23 13:27:58 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::initialize() {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
result = DeviceHandlerBase::initialize();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
uartComIf = dynamic_cast<UartComIF*>(communicationInterface);
|
|
|
|
if (uartComIf == nullptr) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::initialize: Invalid uart com if" << std::endl;
|
|
|
|
return INVALID_UART_COM_IF;
|
|
|
|
}
|
2021-08-08 15:02:59 +02:00
|
|
|
|
2021-08-17 16:14:23 +02:00
|
|
|
#if BOARD_TE0720 == 0
|
2022-01-18 11:41:19 +01:00
|
|
|
sdcMan = SdCardManager::instance();
|
2021-08-17 16:14:23 +02:00
|
|
|
#endif /* BOARD_TE0720 == 0 */
|
2021-08-08 15:02:59 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return result;
|
2021-07-23 13:27:58 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
void PlocSupervisorHandler::doStartUp() {
|
2021-07-13 08:32:14 +02:00
|
|
|
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
|
2022-01-18 11:41:19 +01:00
|
|
|
setMode(MODE_NORMAL);
|
2021-07-13 08:32:14 +02:00
|
|
|
#else
|
2022-01-18 11:41:19 +01:00
|
|
|
setMode(_MODE_TO_ON);
|
2021-07-13 08:32:14 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
void PlocSupervisorHandler::doShutDown() { setMode(_MODE_POWER_DOWN); }
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t PlocSupervisorHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
|
|
|
return NOTHING_TO_SEND;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t PlocSupervisorHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
|
|
|
return NOTHING_TO_SEND;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
|
|
|
const uint8_t* commandData,
|
|
|
|
size_t commandDataLen) {
|
|
|
|
ReturnValue_t result = RETURN_FAILED;
|
|
|
|
switch (deviceCommand) {
|
|
|
|
case (PLOC_SPV::GET_HK_REPORT): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_GET_HK_REPORT);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::RESTART_MPSOC): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_RESTART_MPSOC);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::START_MPSOC): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_START_MPSOC);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SHUTDOWN_MPSOC): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_SHUTWOWN_MPSOC);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SEL_MPSOC_BOOT_IMAGE): {
|
|
|
|
prepareSelBootImageCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::RESET_MPSOC): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_RESET_MPSOC);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_TIME_REF): {
|
|
|
|
result = prepareSetTimeRefCmd();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_BOOT_TIMEOUT): {
|
|
|
|
prepareSetBootTimeoutCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_MAX_RESTART_TRIES): {
|
|
|
|
prepareRestartTriesCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::DISABLE_PERIOIC_HK_TRANSMISSION): {
|
|
|
|
prepareDisableHk();
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::GET_BOOT_STATUS_REPORT): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_GET_BOOT_STATUS_RPT);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::WATCHDOGS_ENABLE): {
|
|
|
|
prepareWatchdogsEnableCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::WATCHDOGS_CONFIG_TIMEOUT): {
|
|
|
|
result = prepareWatchdogsConfigTimeoutCmd(commandData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::ENABLE_LATCHUP_ALERT): {
|
|
|
|
result = prepareLatchupConfigCmd(commandData, deviceCommand);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::DISABLE_LATCHUP_ALERT): {
|
|
|
|
result = prepareLatchupConfigCmd(commandData, deviceCommand);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::AUTO_CALIBRATE_ALERT): {
|
|
|
|
result = prepareAutoCalibrateAlertCmd(commandData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_ALERT_LIMIT): {
|
|
|
|
result = prepareSetAlertLimitCmd(commandData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_ALERT_IRQ_FILTER): {
|
|
|
|
result = prepareSetAlertIrqFilterCmd(commandData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_ADC_SWEEP_PERIOD): {
|
|
|
|
result = prepareSetAdcSweetPeriodCmd(commandData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_ADC_ENABLED_CHANNELS): {
|
|
|
|
prepareSetAdcEnabledChannelsCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_ADC_WINDOW_AND_STRIDE): {
|
|
|
|
prepareSetAdcWindowAndStrideCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_ADC_THRESHOLD): {
|
|
|
|
prepareSetAdcThresholdCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::GET_LATCHUP_STATUS_REPORT): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_GET_LATCHUP_STATUS_REPORT);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::COPY_ADC_DATA_TO_MRAM): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_COPY_ADC_DATA_TO_MRAM);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::ENABLE_NVMS): {
|
|
|
|
prepareEnableNvmsCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SELECT_NVM): {
|
|
|
|
prepareSelectNvmCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::RUN_AUTO_EM_TESTS): {
|
|
|
|
result = prepareRunAutoEmTest(commandData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::WIPE_MRAM): {
|
|
|
|
result = prepareWipeMramCmd(commandData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::FIRST_MRAM_DUMP):
|
|
|
|
case (PLOC_SPV::CONSECUTIVE_MRAM_DUMP):
|
|
|
|
result = prepareDumpMramCmd(commandData);
|
|
|
|
break;
|
|
|
|
case (PLOC_SPV::PRINT_CPU_STATS): {
|
|
|
|
preparePrintCpuStatsCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_DBG_VERBOSITY): {
|
|
|
|
prepareSetDbgVerbosityCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::CAN_LOOPBACK_TEST): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_CAN_LOOPBACK_TEST);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::SET_GPIO): {
|
|
|
|
prepareSetGpioCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::READ_GPIO): {
|
|
|
|
prepareReadGpioCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::RESTART_SUPERVISOR): {
|
|
|
|
prepareEmptyCmd(PLOC_SPV::APID_RESTART_SUPERVISOR);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::FACTORY_RESET_CLEAR_ALL): {
|
|
|
|
PLOC_SPV::FactoryReset packet(PLOC_SPV::FactoryReset::Op::CLEAR_ALL);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::FACTORY_RESET_CLEAR_MIRROR): {
|
|
|
|
PLOC_SPV::FactoryReset packet(PLOC_SPV::FactoryReset::Op::MIRROR_ENTRIES);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::FACTORY_RESET_CLEAR_CIRCULAR): {
|
|
|
|
PLOC_SPV::FactoryReset packet(PLOC_SPV::FactoryReset::Op::CIRCULAR_ENTRIES);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (PLOC_SPV::UPDATE_AVAILABLE):
|
|
|
|
case (PLOC_SPV::UPDATE_IMAGE_DATA):
|
|
|
|
case (PLOC_SPV::UPDATE_VERIFY):
|
|
|
|
// Simply forward data from PLOC Updater to supervisor
|
|
|
|
std::memcpy(commandBuffer, commandData, commandDataLen);
|
|
|
|
rawPacket = commandBuffer;
|
|
|
|
rawPacketLen = commandDataLen;
|
|
|
|
nextReplyId = PLOC_SPV::ACK_REPORT;
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sif::debug << "PlocSupervisorHandler::buildCommandFromCommand: Command not implemented"
|
|
|
|
<< std::endl;
|
|
|
|
result = DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == RETURN_OK) {
|
|
|
|
/**
|
|
|
|
* Flushing the receive buffer to make sure there are no data left from a faulty reply.
|
|
|
|
*/
|
|
|
|
uartComIf->flushUartRxBuffer(comCookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::fillCommandAndReplyMap() {
|
2022-01-18 11:41:19 +01:00
|
|
|
this->insertInCommandMap(PLOC_SPV::GET_HK_REPORT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::RESTART_MPSOC);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::START_MPSOC);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SHUTDOWN_MPSOC);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SEL_MPSOC_BOOT_IMAGE);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_BOOT_TIMEOUT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_MAX_RESTART_TRIES);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::RESET_MPSOC);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_TIME_REF);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::DISABLE_PERIOIC_HK_TRANSMISSION);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::GET_BOOT_STATUS_REPORT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::UPDATE_AVAILABLE);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::UPDATE_VERIFY);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::UPDATE_IMAGE_DATA);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::WATCHDOGS_ENABLE);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::WATCHDOGS_CONFIG_TIMEOUT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::ENABLE_LATCHUP_ALERT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::DISABLE_LATCHUP_ALERT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::AUTO_CALIBRATE_ALERT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_ALERT_LIMIT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_ALERT_IRQ_FILTER);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_ADC_SWEEP_PERIOD);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_ADC_ENABLED_CHANNELS);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_ADC_WINDOW_AND_STRIDE);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_ADC_THRESHOLD);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::GET_LATCHUP_STATUS_REPORT);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::COPY_ADC_DATA_TO_MRAM);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::ENABLE_NVMS);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SELECT_NVM);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::RUN_AUTO_EM_TESTS);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::WIPE_MRAM);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::PRINT_CPU_STATS);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_DBG_VERBOSITY);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::SET_GPIO);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::READ_GPIO);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::RESTART_SUPERVISOR);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::FACTORY_RESET_CLEAR_ALL);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::FACTORY_RESET_CLEAR_MIRROR);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::FACTORY_RESET_CLEAR_CIRCULAR);
|
|
|
|
this->insertInCommandMap(PLOC_SPV::CAN_LOOPBACK_TEST);
|
|
|
|
this->insertInCommandAndReplyMap(PLOC_SPV::FIRST_MRAM_DUMP, 3);
|
|
|
|
this->insertInCommandAndReplyMap(PLOC_SPV::CONSECUTIVE_MRAM_DUMP, 3);
|
|
|
|
this->insertInReplyMap(PLOC_SPV::ACK_REPORT, 3, nullptr, PLOC_SPV::SIZE_ACK_REPORT);
|
|
|
|
this->insertInReplyMap(PLOC_SPV::EXE_REPORT, 3, nullptr, PLOC_SPV::SIZE_EXE_REPORT);
|
|
|
|
this->insertInReplyMap(PLOC_SPV::HK_REPORT, 3, &hkset, PLOC_SPV::SIZE_HK_REPORT);
|
|
|
|
this->insertInReplyMap(PLOC_SPV::BOOT_STATUS_REPORT, 3, &bootStatusReport,
|
|
|
|
PLOC_SPV::SIZE_BOOT_STATUS_REPORT);
|
|
|
|
this->insertInReplyMap(PLOC_SPV::LATCHUP_REPORT, 3, &latchupStatusReport,
|
|
|
|
PLOC_SPV::SIZE_LATCHUP_STATUS_REPORT);
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t PlocSupervisorHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
|
|
|
DeviceCommandId_t* foundId, size_t* foundLen) {
|
|
|
|
if (nextReplyId == PLOC_SPV::FIRST_MRAM_DUMP) {
|
|
|
|
*foundId = PLOC_SPV::FIRST_MRAM_DUMP;
|
|
|
|
return parseMramPackets(start, remainingSize, foundLen);
|
|
|
|
} else if (nextReplyId == PLOC_SPV::CONSECUTIVE_MRAM_DUMP) {
|
|
|
|
*foundId = PLOC_SPV::CONSECUTIVE_MRAM_DUMP;
|
|
|
|
return parseMramPackets(start, remainingSize, foundLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
uint16_t apid = (*(start) << 8 | *(start + 1)) & APID_MASK;
|
|
|
|
|
|
|
|
switch (apid) {
|
|
|
|
case (PLOC_SPV::APID_ACK_SUCCESS):
|
|
|
|
*foundLen = PLOC_SPV::SIZE_ACK_REPORT;
|
|
|
|
*foundId = PLOC_SPV::ACK_REPORT;
|
|
|
|
break;
|
|
|
|
case (PLOC_SPV::APID_ACK_FAILURE):
|
|
|
|
*foundLen = PLOC_SPV::SIZE_ACK_REPORT;
|
|
|
|
*foundId = PLOC_SPV::ACK_REPORT;
|
|
|
|
break;
|
|
|
|
case (PLOC_SPV::APID_HK_REPORT):
|
|
|
|
*foundLen = PLOC_SPV::SIZE_HK_REPORT;
|
|
|
|
*foundId = PLOC_SPV::HK_REPORT;
|
|
|
|
break;
|
|
|
|
case (PLOC_SPV::APID_BOOT_STATUS_REPORT):
|
|
|
|
*foundLen = PLOC_SPV::SIZE_BOOT_STATUS_REPORT;
|
|
|
|
*foundId = PLOC_SPV::BOOT_STATUS_REPORT;
|
|
|
|
break;
|
|
|
|
case (PLOC_SPV::APID_LATCHUP_STATUS_REPORT):
|
|
|
|
*foundLen = PLOC_SPV::SIZE_LATCHUP_STATUS_REPORT;
|
|
|
|
*foundId = PLOC_SPV::LATCHUP_REPORT;
|
|
|
|
break;
|
|
|
|
case (PLOC_SPV::APID_EXE_SUCCESS):
|
|
|
|
*foundLen = PLOC_SPV::SIZE_EXE_REPORT;
|
|
|
|
*foundId = PLOC_SPV::EXE_REPORT;
|
|
|
|
break;
|
|
|
|
case (PLOC_SPV::APID_EXE_FAILURE):
|
|
|
|
*foundLen = PLOC_SPV::SIZE_EXE_REPORT;
|
|
|
|
*foundId = PLOC_SPV::EXE_REPORT;
|
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
sif::debug << "PlocSupervisorHandler::scanForReply: Reply has invalid apid" << std::endl;
|
|
|
|
*foundLen = remainingSize;
|
|
|
|
return INVALID_APID;
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::interpretDeviceReply(DeviceCommandId_t id,
|
2022-01-18 11:41:19 +01:00
|
|
|
const uint8_t* packet) {
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
switch (id) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_SPV::ACK_REPORT: {
|
2022-01-18 11:41:19 +01:00
|
|
|
result = handleAckReport(packet);
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
case (PLOC_SPV::HK_REPORT): {
|
2022-01-18 11:41:19 +01:00
|
|
|
result = handleHkReport(packet);
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2021-07-24 13:57:05 +02:00
|
|
|
case (PLOC_SPV::BOOT_STATUS_REPORT): {
|
2022-01-18 11:41:19 +01:00
|
|
|
result = handleBootStatusReport(packet);
|
|
|
|
break;
|
2021-07-24 13:57:05 +02:00
|
|
|
}
|
2021-07-28 11:08:40 +02:00
|
|
|
case (PLOC_SPV::LATCHUP_REPORT): {
|
2022-01-18 11:41:19 +01:00
|
|
|
result = handleLatchupStatusReport(packet);
|
|
|
|
break;
|
2021-07-28 11:08:40 +02:00
|
|
|
}
|
2021-08-31 11:20:21 +02:00
|
|
|
case (PLOC_SPV::FIRST_MRAM_DUMP):
|
|
|
|
case (PLOC_SPV::CONSECUTIVE_MRAM_DUMP):
|
2022-01-18 11:41:19 +01:00
|
|
|
result = handleMramDumpPacket(id);
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
case (PLOC_SPV::EXE_REPORT): {
|
2022-01-18 11:41:19 +01:00
|
|
|
result = handleExecutionReport(packet);
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
default: {
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::debug << "PlocSupervisorHandler::interpretDeviceReply: Unknown device reply id"
|
|
|
|
<< std::endl;
|
|
|
|
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2022-01-18 11:41:19 +01:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
void PlocSupervisorHandler::setNormalDatapoolEntriesInvalid() {}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
uint32_t PlocSupervisorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
|
2021-07-13 08:32:14 +02:00
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
2022-01-18 11:41:19 +01:00
|
|
|
LocalDataPoolManager& poolManager) {
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::NUM_TMS, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::TEMP_PS, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::TEMP_PL, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::SOC_STATE, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::NVM0_1_STATE, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::NVM3_STATE, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::MISSION_IO_STATE, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::FMC_STATE, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::NUM_TCS, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::UPTIME, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::CPULOAD, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::AVAILABLEHEAP, new PoolEntry<uint32_t>({0}));
|
|
|
|
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::BOOT_SIGNAL, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::RESET_COUNTER, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::BOOT_AFTER_MS, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::BOOT_TIMEOUT_MS, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::ACTIVE_NVM, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::BP0_STATE, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::BP1_STATE, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::BP2_STATE, new PoolEntry<uint8_t>({0}));
|
|
|
|
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_ID, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::CNT0, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::CNT1, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::CNT2, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::CNT3, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::CNT4, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::CNT5, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::CNT6, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_RPT_TIME_SEC, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_RPT_TIME_MIN, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_RPT_TIME_HOUR, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_RPT_TIME_DAY, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_RPT_TIME_MON, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_RPT_TIME_YEAR, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_RPT_TIME_MSEC, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(PLOC_SPV::LATCHUP_RPT_TIME_IS_SET, new PoolEntry<uint32_t>({0}));
|
|
|
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 08:38:36 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t expectedReplies,
|
|
|
|
bool useAlternateId,
|
|
|
|
DeviceCommandId_t alternateReplyID) {
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-28 08:38:36 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t enabledReplies = 0;
|
2021-07-28 08:38:36 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
switch (command->first) {
|
2021-07-28 08:38:36 +02:00
|
|
|
case PLOC_SPV::GET_HK_REPORT: {
|
2022-01-18 11:41:19 +01:00
|
|
|
enabledReplies = 3;
|
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
|
|
|
|
PLOC_SPV::HK_REPORT);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
|
|
|
|
<< PLOC_SPV::HK_REPORT << " not in replyMap" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
case PLOC_SPV::GET_BOOT_STATUS_REPORT: {
|
2022-01-18 11:41:19 +01:00
|
|
|
enabledReplies = 3;
|
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
|
|
|
|
PLOC_SPV::BOOT_STATUS_REPORT);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
|
|
|
|
<< PLOC_SPV::BOOT_STATUS_REPORT << " not in replyMap" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
case PLOC_SPV::GET_LATCHUP_STATUS_REPORT: {
|
2022-01-18 11:41:19 +01:00
|
|
|
enabledReplies = 3;
|
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
|
|
|
|
PLOC_SPV::LATCHUP_REPORT);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
|
|
|
|
<< PLOC_SPV::LATCHUP_REPORT << " not in replyMap" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
2021-08-31 11:20:21 +02:00
|
|
|
case PLOC_SPV::FIRST_MRAM_DUMP: {
|
2022-01-18 11:41:19 +01:00
|
|
|
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
|
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
|
|
|
|
PLOC_SPV::FIRST_MRAM_DUMP);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
|
|
|
|
<< PLOC_SPV::FIRST_MRAM_DUMP << " not in replyMap" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2021-08-31 11:20:21 +02:00
|
|
|
}
|
|
|
|
case PLOC_SPV::CONSECUTIVE_MRAM_DUMP: {
|
2022-01-18 11:41:19 +01:00
|
|
|
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
|
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
|
|
|
|
PLOC_SPV::CONSECUTIVE_MRAM_DUMP);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
|
|
|
|
<< PLOC_SPV::CONSECUTIVE_MRAM_DUMP << " not in replyMap" << std::endl;
|
|
|
|
}
|
|
|
|
break;
|
2021-07-31 08:32:57 +02:00
|
|
|
}
|
2021-07-28 08:38:36 +02:00
|
|
|
case PLOC_SPV::RESTART_MPSOC:
|
|
|
|
case PLOC_SPV::START_MPSOC:
|
|
|
|
case PLOC_SPV::SHUTDOWN_MPSOC:
|
|
|
|
case PLOC_SPV::SEL_MPSOC_BOOT_IMAGE:
|
|
|
|
case PLOC_SPV::SET_BOOT_TIMEOUT:
|
|
|
|
case PLOC_SPV::SET_MAX_RESTART_TRIES:
|
|
|
|
case PLOC_SPV::RESET_MPSOC:
|
|
|
|
case PLOC_SPV::SET_TIME_REF:
|
|
|
|
case PLOC_SPV::UPDATE_AVAILABLE:
|
2021-08-08 15:02:59 +02:00
|
|
|
case PLOC_SPV::UPDATE_IMAGE_DATA:
|
|
|
|
case PLOC_SPV::UPDATE_VERIFY:
|
2021-07-28 08:38:36 +02:00
|
|
|
case PLOC_SPV::WATCHDOGS_ENABLE:
|
|
|
|
case PLOC_SPV::WATCHDOGS_CONFIG_TIMEOUT:
|
|
|
|
case PLOC_SPV::ENABLE_LATCHUP_ALERT:
|
|
|
|
case PLOC_SPV::DISABLE_LATCHUP_ALERT:
|
|
|
|
case PLOC_SPV::AUTO_CALIBRATE_ALERT:
|
|
|
|
case PLOC_SPV::SET_ALERT_LIMIT:
|
|
|
|
case PLOC_SPV::SET_ALERT_IRQ_FILTER:
|
|
|
|
case PLOC_SPV::SET_ADC_SWEEP_PERIOD:
|
|
|
|
case PLOC_SPV::SET_ADC_ENABLED_CHANNELS:
|
|
|
|
case PLOC_SPV::SET_ADC_WINDOW_AND_STRIDE:
|
|
|
|
case PLOC_SPV::SET_ADC_THRESHOLD:
|
|
|
|
case PLOC_SPV::COPY_ADC_DATA_TO_MRAM:
|
|
|
|
case PLOC_SPV::ENABLE_NVMS:
|
|
|
|
case PLOC_SPV::SELECT_NVM:
|
|
|
|
case PLOC_SPV::RUN_AUTO_EM_TESTS:
|
|
|
|
case PLOC_SPV::WIPE_MRAM:
|
|
|
|
case PLOC_SPV::SET_DBG_VERBOSITY:
|
|
|
|
case PLOC_SPV::CAN_LOOPBACK_TEST:
|
|
|
|
case PLOC_SPV::PRINT_CPU_STATS:
|
|
|
|
case PLOC_SPV::SET_GPIO:
|
|
|
|
case PLOC_SPV::READ_GPIO:
|
|
|
|
case PLOC_SPV::RESTART_SUPERVISOR:
|
2021-08-02 15:28:57 +02:00
|
|
|
case PLOC_SPV::FACTORY_RESET_CLEAR_ALL:
|
|
|
|
case PLOC_SPV::FACTORY_RESET_CLEAR_MIRROR:
|
|
|
|
case PLOC_SPV::FACTORY_RESET_CLEAR_CIRCULAR:
|
2021-07-28 08:38:36 +02:00
|
|
|
case PLOC_SPV::REQUEST_LOGGING_DATA:
|
2021-08-20 06:56:29 +02:00
|
|
|
case PLOC_SPV::DISABLE_PERIOIC_HK_TRANSMISSION:
|
2022-01-18 11:41:19 +01:00
|
|
|
enabledReplies = 2;
|
|
|
|
break;
|
2021-07-28 08:38:36 +02:00
|
|
|
default:
|
2022-01-18 11:41:19 +01:00
|
|
|
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, PLOC_SPV::ACK_REPORT);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
|
|
|
|
<< PLOC_SPV::ACK_REPORT << " not in replyMap" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
result =
|
|
|
|
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, PLOC_SPV::EXE_REPORT);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
|
|
|
|
<< PLOC_SPV::EXE_REPORT << " not in replyMap" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RETURN_OK;
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (receivedCrc != recalculatedCrc) {
|
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
result = verifyPacket(data, PLOC_SPV::SIZE_ACK_REPORT);
|
|
|
|
if (result == CRC_FAILURE) {
|
|
|
|
sif::error << "PlocSupervisorHandler::handleAckReport: CRC failure" << std::endl;
|
|
|
|
nextReplyId = PLOC_SPV::NONE;
|
|
|
|
replyRawReplyIfnotWiretapped(data, PLOC_SPV::SIZE_ACK_REPORT);
|
|
|
|
triggerEvent(SUPV_CRC_FAILURE_EVENT);
|
|
|
|
sendFailureReport(PLOC_SPV::ACK_REPORT, CRC_FAILURE);
|
|
|
|
disableAllReplies();
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
|
|
|
|
|
|
|
|
switch (apid) {
|
|
|
|
case PLOC_SPV::APID_ACK_FAILURE: {
|
|
|
|
// TODO: Interpretation of status field in acknowledgment report
|
|
|
|
sif::debug << "PlocSupervisorHandler::handleAckReport: Received Ack failure report"
|
|
|
|
<< std::endl;
|
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
|
|
|
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
|
|
|
|
triggerEvent(SUPV_ACK_FAILURE, commandId);
|
|
|
|
}
|
|
|
|
sendFailureReport(PLOC_SPV::ACK_REPORT, RECEIVED_ACK_FAILURE);
|
|
|
|
disableAllReplies();
|
|
|
|
nextReplyId = PLOC_SPV::NONE;
|
|
|
|
result = IGNORE_REPLY_DATA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PLOC_SPV::APID_ACK_SUCCESS: {
|
|
|
|
setNextReplyId();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
sif::debug << "PlocSupervisorHandler::handleAckReport: Invalid APID in Ack report"
|
|
|
|
<< std::endl;
|
|
|
|
result = RETURN_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::handleExecutionReport(const uint8_t* data) {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
result = verifyPacket(data, PLOC_SPV::SIZE_EXE_REPORT);
|
|
|
|
if (result == CRC_FAILURE) {
|
|
|
|
sif::error << "PlocSupervisorHandler::handleExecutionReport: CRC failure" << std::endl;
|
|
|
|
nextReplyId = PLOC_SPV::NONE;
|
|
|
|
return result;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
switch (apid) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case (PLOC_SPV::APID_EXE_SUCCESS): {
|
2022-01-18 11:41:19 +01:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
case (PLOC_SPV::APID_EXE_FAILURE): {
|
2022-01-18 11:41:19 +01:00
|
|
|
// TODO: Interpretation of status field in execution report
|
|
|
|
sif::error
|
|
|
|
<< "PlocSupervisorHandler::handleExecutionReport: Received execution failure report"
|
|
|
|
<< std::endl;
|
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
|
|
|
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
|
|
|
|
triggerEvent(SUPV_EXE_FAILURE, commandId);
|
|
|
|
} else {
|
|
|
|
sif::debug << "PlocSupervisorHandler::handleExecutionReport: Unknown command id"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
sendFailureReport(PLOC_SPV::EXE_REPORT, RECEIVED_EXE_FAILURE);
|
|
|
|
disableExeReportReply();
|
|
|
|
result = IGNORE_REPLY_DATA;
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
default: {
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::error << "PlocSupervisorHandler::handleExecutionReport: Unknown APID" << std::endl;
|
|
|
|
result = RETURN_FAILED;
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2022-01-18 11:41:19 +01:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
nextReplyId = PLOC_SPV::NONE;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::handleHkReport(const uint8_t* data) {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
result = verifyPacket(data, PLOC_SPV::SIZE_HK_REPORT);
|
|
|
|
|
|
|
|
if (result == CRC_FAILURE) {
|
|
|
|
sif::error << "PlocSupervisorHandler::handleHkReport: Hk report has invalid crc" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t offset = PLOC_SPV::DATA_FIELD_OFFSET;
|
|
|
|
hkset.tempPs = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
|
|
|
|
*(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.tempPl = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
|
|
|
|
*(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.tempSup = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
|
|
|
|
*(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.uptime = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
|
|
|
|
*(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.cpuLoad = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
|
|
|
|
*(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.availableHeap = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.numTcs = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
|
|
|
|
*(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.numTms = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
|
|
|
|
*(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.socState = *(data + offset) << 24 | *(data + offset + 1) << 16 | *(data + offset + 2) << 8 |
|
|
|
|
*(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
hkset.nvm0_1_state = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
hkset.nvm3_state = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
hkset.missionIoState = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
hkset.fmcState = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
nextReplyId = PLOC_SPV::EXE_REPORT;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2021-08-17 17:48:51 +02:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: temp_ps: " << hkset.tempPs << std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: temp_pl: " << hkset.tempPl << std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: temp_sup: " << hkset.tempSup << std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: uptime: " << hkset.uptime << std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: cpu_load: " << hkset.cpuLoad << std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: available_heap: " << hkset.availableHeap
|
|
|
|
<< std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: num_tcs: " << hkset.numTcs << std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: num_tms: " << hkset.numTms << std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: soc_state: " << hkset.socState << std::endl;
|
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: nvm0_1_state: "
|
2021-07-13 08:32:14 +02:00
|
|
|
<< static_cast<unsigned int>(hkset.nvm0_1_state.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: nvm3_state: "
|
2021-07-13 08:32:14 +02:00
|
|
|
<< static_cast<unsigned int>(hkset.nvm3_state.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: missoin_io_state: "
|
2021-07-13 08:32:14 +02:00
|
|
|
<< static_cast<unsigned int>(hkset.missionIoState.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: fmc_state: "
|
2021-07-13 08:32:14 +02:00
|
|
|
<< static_cast<unsigned int>(hkset.fmcState.value) << std::endl;
|
2021-07-22 08:06:04 +02:00
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
#endif
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2021-07-24 13:57:05 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::handleBootStatusReport(const uint8_t* data) {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-24 13:57:05 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
result = verifyPacket(data, PLOC_SPV::SIZE_BOOT_STATUS_REPORT);
|
2021-07-24 13:57:05 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (result == CRC_FAILURE) {
|
|
|
|
sif::error << "PlocSupervisorHandler::handleBootStatusReport: Boot status report has invalid"
|
|
|
|
" crc"
|
|
|
|
<< std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t offset = PLOC_SPV::DATA_FIELD_OFFSET;
|
|
|
|
bootStatusReport.bootSignal = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
bootStatusReport.resetCounter = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
bootStatusReport.bootAfterMs = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
bootStatusReport.bootTimeoutMs = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
bootStatusReport.activeNvm = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
bootStatusReport.bp0State = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
bootStatusReport.bp1State = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
bootStatusReport.bp2State = *(data + offset);
|
|
|
|
|
|
|
|
nextReplyId = PLOC_SPV::EXE_REPORT;
|
2021-07-24 13:57:05 +02:00
|
|
|
|
2021-08-17 17:48:51 +02:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Boot signal: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.bootSignal.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Reset counter: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.resetCounter.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BootAfterMs: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< bootStatusReport.bootAfterMs << " ms" << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BootTimeoutMs: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< bootStatusReport.bootTimeoutMs << " ms" << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Active NVM: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.activeNvm.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP0: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.bp0State.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP1: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.bp1State.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP2: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.bp2State.value) << std::endl;
|
2021-07-24 13:57:05 +02:00
|
|
|
#endif
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return result;
|
2021-07-24 13:57:05 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 08:38:36 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::handleLatchupStatusReport(const uint8_t* data) {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
result = verifyPacket(data, PLOC_SPV::SIZE_LATCHUP_STATUS_REPORT);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (result == CRC_FAILURE) {
|
|
|
|
sif::error << "PlocSupervisorHandler::handleLatchupStatusReport: Latchup status report has "
|
|
|
|
<< "invalid crc" << std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t offset = PLOC_SPV::DATA_FIELD_OFFSET;
|
|
|
|
latchupStatusReport.id = *(data + offset);
|
|
|
|
offset += 1;
|
|
|
|
latchupStatusReport.cnt0 = *(data + offset) << 8 | *(data + offset + 1);
|
|
|
|
offset += 2;
|
|
|
|
latchupStatusReport.cnt1 = *(data + offset) << 8 | *(data + offset + 1);
|
|
|
|
offset += 2;
|
|
|
|
latchupStatusReport.cnt2 = *(data + offset) << 8 | *(data + offset + 1);
|
|
|
|
offset += 2;
|
|
|
|
latchupStatusReport.cnt3 = *(data + offset) << 8 | *(data + offset + 1);
|
|
|
|
offset += 2;
|
|
|
|
latchupStatusReport.cnt4 = *(data + offset) << 8 | *(data + offset + 1);
|
|
|
|
offset += 2;
|
|
|
|
latchupStatusReport.cnt5 = *(data + offset) << 8 | *(data + offset + 1);
|
|
|
|
offset += 2;
|
|
|
|
latchupStatusReport.cnt6 = *(data + offset) << 8 | *(data + offset + 1);
|
|
|
|
offset += 2;
|
|
|
|
latchupStatusReport.timeSec = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
latchupStatusReport.timeMin = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
latchupStatusReport.timeHour = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
latchupStatusReport.timeDay = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
latchupStatusReport.timeMon = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
latchupStatusReport.timeYear = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
latchupStatusReport.timeMsec = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
latchupStatusReport.isSet = *(data + offset) << 24 | *(data + offset + 1) << 16 |
|
|
|
|
*(data + offset + 2) << 8 | *(data + offset + 3);
|
|
|
|
offset += 4;
|
|
|
|
|
|
|
|
nextReplyId = PLOC_SPV::EXE_REPORT;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2021-08-17 17:48:51 +02:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Latchup ID: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< static_cast<unsigned int>(latchupStatusReport.id.value) << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT0: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt0 << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT1: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt1 << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT2: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt2 << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT3: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt3 << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT4: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt4 << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT5: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt5 << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT6: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt6 << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Sec: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.timeSec << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Min: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.timeMin << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Hour: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.timeHour << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Day: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.timeDay << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Mon: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.timeMon << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Year: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.timeYear << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Msec: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.timeMsec << std::endl;
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: isSet: 0x" << std::hex
|
|
|
|
<< latchupStatusReport.timeMsec << std::dec << std::endl;
|
2021-07-28 08:38:36 +02:00
|
|
|
#endif
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::setNextReplyId() {
|
2022-01-18 11:41:19 +01:00
|
|
|
switch (getPendingCommand()) {
|
2021-07-13 08:32:14 +02:00
|
|
|
case PLOC_SPV::GET_HK_REPORT:
|
2022-01-18 11:41:19 +01:00
|
|
|
nextReplyId = PLOC_SPV::HK_REPORT;
|
|
|
|
break;
|
2021-07-26 12:08:38 +02:00
|
|
|
case PLOC_SPV::GET_BOOT_STATUS_REPORT:
|
2022-01-18 11:41:19 +01:00
|
|
|
nextReplyId = PLOC_SPV::BOOT_STATUS_REPORT;
|
|
|
|
break;
|
2021-07-28 08:38:36 +02:00
|
|
|
case PLOC_SPV::GET_LATCHUP_STATUS_REPORT:
|
2022-01-18 11:41:19 +01:00
|
|
|
nextReplyId = PLOC_SPV::LATCHUP_REPORT;
|
|
|
|
break;
|
2021-08-31 11:20:21 +02:00
|
|
|
case PLOC_SPV::FIRST_MRAM_DUMP:
|
2022-01-18 11:41:19 +01:00
|
|
|
nextReplyId = PLOC_SPV::FIRST_MRAM_DUMP;
|
|
|
|
break;
|
2021-08-31 11:20:21 +02:00
|
|
|
case PLOC_SPV::CONSECUTIVE_MRAM_DUMP:
|
2022-01-18 11:41:19 +01:00
|
|
|
nextReplyId = PLOC_SPV::CONSECUTIVE_MRAM_DUMP;
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
default:
|
2022-01-18 11:41:19 +01:00
|
|
|
/* If no telemetry is expected the next reply is always the execution report */
|
|
|
|
nextReplyId = PLOC_SPV::EXE_REPORT;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2021-07-28 08:38:36 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
size_t PlocSupervisorHandler::getNextReplyLength(DeviceCommandId_t commandId) {
|
|
|
|
size_t replyLen = 0;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (nextReplyId == PLOC_SPV::NONE) {
|
|
|
|
return replyLen;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (nextReplyId == PLOC_SPV::FIRST_MRAM_DUMP || nextReplyId == PLOC_SPV::CONSECUTIVE_MRAM_DUMP) {
|
|
|
|
/**
|
|
|
|
* Try to read 20 MRAM packets. If reply is larger, the packets will be read with the
|
|
|
|
* next doSendRead call. The command will be as long active as the packet with the sequence
|
|
|
|
* count indicating the last packet has not been received.
|
|
|
|
*/
|
|
|
|
replyLen = PLOC_SPV::MAX_PACKET_SIZE * 20;
|
|
|
|
return replyLen;
|
|
|
|
}
|
2021-07-31 08:32:57 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceReplyIter iter = deviceReplyMap.find(nextReplyId);
|
|
|
|
if (iter != deviceReplyMap.end()) {
|
|
|
|
if (iter->second.delayCycles == 0) {
|
|
|
|
/* Reply inactive */
|
|
|
|
return replyLen;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2022-01-18 11:41:19 +01:00
|
|
|
replyLen = iter->second.replyLen;
|
|
|
|
} else {
|
|
|
|
sif::debug << "PlocSupervisorHandler::getNextReplyLength: No entry for reply with reply id "
|
|
|
|
<< std::hex << nextReplyId << " in deviceReplyMap" << std::endl;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
return replyLen;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
void PlocSupervisorHandler::handleDeviceTM(const uint8_t* data, size_t dataSize,
|
|
|
|
DeviceCommandId_t replyId) {
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (wiretappingMode == RAW) {
|
|
|
|
/* Data already sent in doGetRead() */
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId);
|
|
|
|
if (iter == deviceReplyMap.end()) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::handleDeviceTM: Unknown reply id" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (queueId == NO_COMMANDER) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
result = actionHelper.reportData(queueId, replyId, data, dataSize);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::handleDeviceTM: Failed to report data" << std::endl;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareEmptyCmd(uint16_t apid) {
|
2022-01-18 11:41:19 +01:00
|
|
|
PLOC_SPV::EmptyPacket packet(apid);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
void PlocSupervisorHandler::prepareSelBootImageCmd(const uint8_t* commandData) {
|
|
|
|
PLOC_SPV::MPSoCBootSelect packet(*commandData, *(commandData + 1), *(commandData + 2),
|
|
|
|
*(commandData + 3));
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareSetTimeRefCmd() {
|
2022-01-18 11:41:19 +01:00
|
|
|
Clock::TimeOfDay_t time;
|
|
|
|
ReturnValue_t result = Clock::getDateAndTime(&time);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::prepareSetTimeRefCmd: Failed to get current time"
|
|
|
|
<< std::endl;
|
|
|
|
return GET_TIME_FAILURE;
|
|
|
|
}
|
|
|
|
PLOC_SPV::SetTimeRef packet(&time);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2021-07-22 08:06:04 +02:00
|
|
|
void PlocSupervisorHandler::prepareDisableHk() {
|
2022-01-18 11:41:19 +01:00
|
|
|
PLOC_SPV::DisablePeriodicHkTransmission packet;
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-22 08:06:04 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
void PlocSupervisorHandler::prepareSetBootTimeoutCmd(const uint8_t* commandData) {
|
|
|
|
uint32_t timeout = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 |
|
|
|
|
*(commandData + 3);
|
|
|
|
PLOC_SPV::SetBootTimeout packet(timeout);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-22 08:06:04 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
void PlocSupervisorHandler::prepareRestartTriesCmd(const uint8_t* commandData) {
|
|
|
|
uint8_t restartTries = *(commandData);
|
|
|
|
PLOC_SPV::SetRestartTries packet(restartTries);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-25 20:42:24 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
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);
|
|
|
|
PLOC_SPV::WatchdogsEnable packet(watchdogPs, watchdogPl, watchdogInt);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareWatchdogsConfigTimeoutCmd(const uint8_t* commandData) {
|
|
|
|
uint8_t offset = 0;
|
|
|
|
uint8_t watchdog = *(commandData + offset);
|
|
|
|
offset += 1;
|
|
|
|
if (watchdog > 2) {
|
|
|
|
return 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 INVALID_WATCHDOG_TIMEOUT;
|
|
|
|
}
|
|
|
|
PLOC_SPV::WatchdogsConfigTimeout packet(watchdog, timeout);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareLatchupConfigCmd(const uint8_t* commandData,
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceCommandId_t deviceCommand) {
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
uint8_t latchupId = *commandData;
|
|
|
|
if (latchupId > 6) {
|
|
|
|
return INVALID_LATCHUP_ID;
|
|
|
|
}
|
|
|
|
switch (deviceCommand) {
|
2021-07-27 12:02:30 +02:00
|
|
|
case (PLOC_SPV::ENABLE_LATCHUP_ALERT): {
|
2022-01-18 11:41:19 +01:00
|
|
|
PLOC_SPV::LatchupAlert packet(true, latchupId);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
break;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
|
|
|
case (PLOC_SPV::DISABLE_LATCHUP_ALERT): {
|
2022-01-18 11:41:19 +01:00
|
|
|
PLOC_SPV::LatchupAlert packet(false, latchupId);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
break;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
|
|
|
default: {
|
2022-01-18 11:41:19 +01:00
|
|
|
sif::debug << "PlocSupervisorHandler::prepareLatchupConfigCmd: Invalid command id"
|
|
|
|
<< std::endl;
|
|
|
|
result = RETURN_FAILED;
|
|
|
|
break;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
2022-01-18 11:41:19 +01:00
|
|
|
}
|
|
|
|
return result;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareAutoCalibrateAlertCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
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 INVALID_LATCHUP_ID;
|
|
|
|
}
|
|
|
|
PLOC_SPV::AutoCalibrateAlert packet(latchupId, mg);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 08:38:36 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareSetAlertIrqFilterCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t latchupId = *commandData;
|
|
|
|
uint8_t tp = *(commandData + 1);
|
|
|
|
uint8_t div = *(commandData + 2);
|
|
|
|
if (latchupId > 6) {
|
|
|
|
return INVALID_LATCHUP_ID;
|
|
|
|
}
|
|
|
|
PLOC_SPV::SetAlertIrqFilter packet(latchupId, tp, div);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareSetAlertLimitCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t offset = 0;
|
|
|
|
uint8_t latchupId = *commandData;
|
|
|
|
offset += 1;
|
|
|
|
uint32_t dutycycle = *(commandData + offset) << 24 | *(commandData + offset + 1) << 16 |
|
|
|
|
*(commandData + offset + 2) << 8 | *(commandData + offset + 3);
|
|
|
|
if (latchupId > 6) {
|
|
|
|
return INVALID_LATCHUP_ID;
|
|
|
|
}
|
|
|
|
PLOC_SPV::SetAlertlimit packet(latchupId, dutycycle);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareSetAdcSweetPeriodCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint32_t sweepPeriod = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 |
|
|
|
|
*(commandData + 3);
|
|
|
|
if (sweepPeriod < 21) {
|
|
|
|
return SWEEP_PERIOD_TOO_SMALL;
|
|
|
|
}
|
|
|
|
PLOC_SPV::SetAdcSweepPeriod packet(sweepPeriod);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareSetAdcEnabledChannelsCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint16_t ch = *(commandData) << 8 | *(commandData + 1);
|
|
|
|
PLOC_SPV::SetAdcEnabledChannels packet(ch);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareSetAdcWindowAndStrideCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t offset = 0;
|
|
|
|
uint16_t windowSize = *(commandData + offset) << 8 | *(commandData + offset + 1);
|
|
|
|
offset += 2;
|
|
|
|
uint16_t stridingStepSize = *(commandData + offset) << 8 | *(commandData + offset + 1);
|
|
|
|
PLOC_SPV::SetAdcWindowAndStride packet(windowSize, stridingStepSize);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareSetAdcThresholdCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint32_t threshold = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 |
|
|
|
|
*(commandData + 3);
|
|
|
|
PLOC_SPV::SetAdcThreshold packet(threshold);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 11:55:16 +02:00
|
|
|
void PlocSupervisorHandler::prepareEnableNvmsCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t n01 = *commandData;
|
|
|
|
uint8_t n3 = *(commandData + 1);
|
|
|
|
PLOC_SPV::EnableNvms packet(n01, n3);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-28 11:55:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareSelectNvmCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t mem = *commandData;
|
|
|
|
PLOC_SPV::SelectNvm packet(mem);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-28 11:55:16 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 19:34:10 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareRunAutoEmTest(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t test = *commandData;
|
|
|
|
if (test != 1 && test != 2) {
|
|
|
|
return INVALID_TEST_PARAM;
|
|
|
|
}
|
|
|
|
PLOC_SPV::RunAutoEmTests packet(test);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
2021-07-28 19:34:10 +02:00
|
|
|
}
|
|
|
|
|
2021-08-01 17:11:32 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareWipeMramCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint32_t start = 0;
|
|
|
|
uint32_t stop = 0;
|
|
|
|
size_t size = sizeof(start) + sizeof(stop);
|
|
|
|
SerializeAdapter::deSerialize(&start, &commandData, &size, SerializeIF::Endianness::BIG);
|
|
|
|
SerializeAdapter::deSerialize(&stop, &commandData, &size, SerializeIF::Endianness::BIG);
|
|
|
|
if ((stop - start) <= 0) {
|
|
|
|
return INVALID_MRAM_ADDRESSES;
|
|
|
|
}
|
|
|
|
PLOC_SPV::MramCmd packet(start, stop, PLOC_SPV::MramCmd::MramAction::WIPE);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
2021-07-28 19:34:10 +02:00
|
|
|
}
|
|
|
|
|
2021-08-01 17:11:32 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareDumpMramCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint32_t start = 0;
|
|
|
|
uint32_t stop = 0;
|
|
|
|
size_t size = sizeof(start) + sizeof(stop);
|
|
|
|
SerializeAdapter::deSerialize(&start, &commandData, &size, SerializeIF::Endianness::BIG);
|
|
|
|
SerializeAdapter::deSerialize(&stop, &commandData, &size, SerializeIF::Endianness::BIG);
|
|
|
|
PLOC_SPV::MramCmd packet(start, stop, PLOC_SPV::MramCmd::MramAction::DUMP);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
if ((stop - start) <= 0) {
|
|
|
|
return INVALID_MRAM_ADDRESSES;
|
|
|
|
}
|
|
|
|
expectedMramDumpPackets = (stop - start) / PLOC_SPV::MAX_DATA_CAPACITY;
|
|
|
|
if ((stop - start) % PLOC_SPV::MAX_DATA_CAPACITY) {
|
|
|
|
expectedMramDumpPackets++;
|
|
|
|
}
|
|
|
|
receivedMramDumpPackets = 0;
|
|
|
|
return RETURN_OK;
|
2021-07-29 09:21:33 +02:00
|
|
|
}
|
|
|
|
|
2021-08-02 15:28:57 +02:00
|
|
|
void PlocSupervisorHandler::preparePrintCpuStatsCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t en = *commandData;
|
|
|
|
PLOC_SPV::PrintCpuStats packet(en);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-08-02 15:28:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareSetDbgVerbosityCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t vb = *commandData;
|
|
|
|
PLOC_SPV::SetDbgVerbosity packet(vb);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-08-02 15:28:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareSetGpioCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t port = *commandData;
|
|
|
|
uint8_t pin = *(commandData + 1);
|
|
|
|
uint8_t val = *(commandData + 2);
|
|
|
|
PLOC_SPV::SetGpio packet(port, pin, val);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-08-02 15:28:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareReadGpioCmd(const uint8_t* commandData) {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint8_t port = *commandData;
|
|
|
|
uint8_t pin = *(commandData + 1);
|
|
|
|
PLOC_SPV::ReadGpio packet(port, pin);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-08-02 15:28:57 +02:00
|
|
|
}
|
|
|
|
|
2021-07-27 12:02:30 +02:00
|
|
|
void PlocSupervisorHandler::packetToOutBuffer(uint8_t* packetData, size_t fullSize) {
|
2022-01-18 11:41:19 +01:00
|
|
|
memcpy(commandBuffer, packetData, fullSize);
|
|
|
|
rawPacket = commandBuffer;
|
|
|
|
rawPacketLen = fullSize;
|
|
|
|
nextReplyId = PLOC_SPV::ACK_REPORT;
|
2021-07-26 19:56:00 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocSupervisorHandler::disableAllReplies() {
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceReplyMap::iterator iter;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
/* Disable ack reply */
|
|
|
|
iter = deviceReplyMap.find(PLOC_SPV::ACK_REPORT);
|
|
|
|
DeviceReplyInfo* info = &(iter->second);
|
|
|
|
info->delayCycles = 0;
|
|
|
|
info->command = deviceCommandMap.end();
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
/* If the command expects a telemetry packet the appropriate tm reply will be disabled here */
|
|
|
|
switch (commandId) {
|
2021-07-23 13:27:58 +02:00
|
|
|
case PLOC_SPV::GET_HK_REPORT: {
|
2022-01-18 11:41:19 +01:00
|
|
|
iter = deviceReplyMap.find(PLOC_SPV::GET_HK_REPORT);
|
|
|
|
info = &(iter->second);
|
|
|
|
info->delayCycles = 0;
|
|
|
|
info->command = deviceCommandMap.end();
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
default: {
|
2022-01-18 11:41:19 +01:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2022-01-18 11:41:19 +01:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
/* We must always disable the execution report reply here */
|
|
|
|
disableExeReportReply();
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) {
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceReplyIter iter = deviceReplyMap.find(replyId);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (iter == deviceReplyMap.end()) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::sendFailureReport: Reply not in reply map" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceCommandInfo* info = &(iter->second.command->second);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (info == nullptr) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::sendFailureReport: Reply has no active command"
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (info->sendReplyTo != NO_COMMANDER) {
|
|
|
|
actionHelper.finish(false, info->sendReplyTo, iter->first, status);
|
|
|
|
}
|
|
|
|
info->isExecuting = false;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::disableExeReportReply() {
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceReplyIter iter = deviceReplyMap.find(PLOC_SPV::EXE_REPORT);
|
|
|
|
DeviceReplyInfo* info = &(iter->second);
|
|
|
|
info->delayCycles = 0;
|
|
|
|
info->command = deviceCommandMap.end();
|
|
|
|
/* Expected replies is set to one here. The value will set to 0 in replyToReply() */
|
|
|
|
info->command->second.expectedReplies = 1;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2021-07-31 08:32:57 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t PlocSupervisorHandler::parseMramPackets(const uint8_t* packet, size_t remainingSize,
|
|
|
|
size_t* foundLen) {
|
|
|
|
ReturnValue_t result = IGNORE_FULL_PACKET;
|
|
|
|
uint16_t packetLen = 0;
|
|
|
|
*foundLen = 0;
|
|
|
|
|
|
|
|
for (size_t idx = 0; idx < remainingSize; idx++) {
|
|
|
|
std::memcpy(spacePacketBuffer + bufferTop, packet + idx, 1);
|
|
|
|
bufferTop += 1;
|
|
|
|
*foundLen += 1;
|
|
|
|
if (bufferTop >= PLOC_SPV::SPACE_PACKET_HEADER_LENGTH) {
|
|
|
|
packetLen = readSpacePacketLength(spacePacketBuffer);
|
2021-07-31 08:32:57 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
if (bufferTop == PLOC_SPV::SPACE_PACKET_HEADER_LENGTH + packetLen + 1) {
|
|
|
|
packetInBuffer = true;
|
|
|
|
bufferTop = 0;
|
|
|
|
return checkMramPacketApid();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bufferTop == PLOC_SPV::MAX_PACKET_SIZE) {
|
|
|
|
*foundLen = remainingSize;
|
|
|
|
disableAllReplies();
|
|
|
|
bufferTop = 0;
|
|
|
|
return MRAM_PACKET_PARSING_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2021-07-31 08:32:57 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 11:20:21 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::handleMramDumpPacket(DeviceCommandId_t id) {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_FAILED;
|
2021-07-31 08:32:57 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
// Prepare packet for downlink
|
|
|
|
if (packetInBuffer) {
|
|
|
|
uint16_t packetLen = readSpacePacketLength(spacePacketBuffer);
|
|
|
|
result = verifyPacket(spacePacketBuffer, PLOC_SPV::SPACE_PACKET_HEADER_LENGTH + packetLen + 1);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::handleMramDumpPacket: CRC failure" << std::endl;
|
|
|
|
return result;
|
2021-07-31 08:32:57 +02:00
|
|
|
}
|
2022-01-18 11:41:19 +01:00
|
|
|
handleMramDumpFile(id);
|
|
|
|
if (downlinkMramDump == true) {
|
|
|
|
handleDeviceTM(spacePacketBuffer + PLOC_SPV::SPACE_PACKET_HEADER_LENGTH, packetLen - 1, id);
|
|
|
|
}
|
|
|
|
packetInBuffer = false;
|
|
|
|
receivedMramDumpPackets++;
|
|
|
|
if (expectedMramDumpPackets == receivedMramDumpPackets) {
|
|
|
|
nextReplyId = PLOC_SPV::EXE_REPORT;
|
|
|
|
}
|
|
|
|
increaseExpectedMramReplies(id);
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
return result;
|
2021-08-01 17:11:32 +02:00
|
|
|
}
|
|
|
|
|
2021-08-31 11:20:21 +02:00
|
|
|
void PlocSupervisorHandler::increaseExpectedMramReplies(DeviceCommandId_t id) {
|
2022-01-18 11:41:19 +01:00
|
|
|
DeviceReplyMap::iterator mramDumpIter = deviceReplyMap.find(id);
|
|
|
|
DeviceReplyMap::iterator exeReportIter = deviceReplyMap.find(PLOC_SPV::EXE_REPORT);
|
|
|
|
if (mramDumpIter == deviceReplyMap.end()) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::increaseExpectedMramReplies: Dump MRAM reply not "
|
|
|
|
<< "in reply map" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (exeReportIter == deviceReplyMap.end()) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::increaseExpectedMramReplies: Execution report not "
|
|
|
|
<< "in reply map" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DeviceReplyInfo* mramReplyInfo = &(mramDumpIter->second);
|
|
|
|
if (mramReplyInfo == nullptr) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::increaseExpectedReplies: MRAM reply info nullptr"
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DeviceReplyInfo* exeReplyInfo = &(exeReportIter->second);
|
|
|
|
if (exeReplyInfo == nullptr) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::increaseExpectedReplies: Execution reply info"
|
|
|
|
<< " nullptr" << std::endl;
|
2021-08-01 17:11:32 +02:00
|
|
|
return;
|
2022-01-18 11:41:19 +01:00
|
|
|
}
|
|
|
|
DeviceCommandInfo* info = &(mramReplyInfo->command->second);
|
|
|
|
if (info == nullptr) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::increaseExpectedReplies: Command info nullptr"
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t sequenceFlags = spacePacketBuffer[2] >> 6;
|
|
|
|
if (sequenceFlags != static_cast<uint8_t>(PLOC_SPV::SequenceFlags::LAST_PKT) &&
|
|
|
|
(sequenceFlags != static_cast<uint8_t>(PLOC_SPV::SequenceFlags::STANDALONE_PKT))) {
|
|
|
|
// Command expects at least one MRAM packet more and the execution report
|
|
|
|
info->expectedReplies = 2;
|
|
|
|
// Wait maximum of 2 cycles for next MRAM packet
|
|
|
|
mramReplyInfo->delayCycles = 2;
|
|
|
|
// Also adapting delay cycles for execution report
|
|
|
|
exeReplyInfo->delayCycles = 3;
|
|
|
|
} else {
|
|
|
|
// Command expects the execution report
|
|
|
|
info->expectedReplies = 1;
|
|
|
|
mramReplyInfo->delayCycles = 0;
|
|
|
|
}
|
|
|
|
return;
|
2021-08-01 17:11:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::checkMramPacketApid() {
|
2022-01-18 11:41:19 +01:00
|
|
|
uint16_t apid = (spacePacketBuffer[0] << 8 | spacePacketBuffer[1]) & PLOC_SPV::APID_MASK;
|
|
|
|
if (apid != PLOC_SPV::APID_MRAM_DUMP_TM) {
|
|
|
|
return NO_MRAM_PACKET;
|
|
|
|
}
|
|
|
|
return APERIODIC_REPLY;
|
2021-07-31 08:32:57 +02:00
|
|
|
}
|
2021-08-08 15:02:59 +02:00
|
|
|
|
2021-08-31 11:20:21 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::handleMramDumpFile(DeviceCommandId_t id) {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
uint16_t packetLen = readSpacePacketLength(spacePacketBuffer);
|
|
|
|
uint8_t sequenceFlags = readSequenceFlags(spacePacketBuffer);
|
|
|
|
if (id == PLOC_SPV::FIRST_MRAM_DUMP) {
|
|
|
|
if (sequenceFlags == static_cast<uint8_t>(PLOC_SPV::SequenceFlags::FIRST_PKT) ||
|
|
|
|
(sequenceFlags == static_cast<uint8_t>(PLOC_SPV::SequenceFlags::STANDALONE_PKT))) {
|
|
|
|
result = createMramDumpFile();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (not std::filesystem::exists(activeMramFile)) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::handleMramDumpFile: MRAM file does not exist"
|
|
|
|
<< std::endl;
|
|
|
|
return MRAM_FILE_NOT_EXISTS;
|
|
|
|
}
|
|
|
|
std::ofstream file(activeMramFile, std::ios_base::app | std::ios_base::out);
|
|
|
|
file.write(
|
|
|
|
reinterpret_cast<const char*>(spacePacketBuffer + PLOC_SPV::SPACE_PACKET_HEADER_LENGTH),
|
|
|
|
packetLen - 1);
|
|
|
|
file.close();
|
|
|
|
return RETURN_OK;
|
2021-08-08 15:02:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t PlocSupervisorHandler::readSpacePacketLength(uint8_t* spacePacket) {
|
2022-01-18 11:41:19 +01:00
|
|
|
return spacePacket[4] << 8 | spacePacket[5];
|
2021-08-08 15:02:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t PlocSupervisorHandler::readSequenceFlags(uint8_t* spacePacket) {
|
2022-01-18 11:41:19 +01:00
|
|
|
return spacePacketBuffer[2] >> 6;
|
2021-08-08 15:02:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::createMramDumpFile() {
|
2022-01-18 11:41:19 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
std::string timeStamp;
|
|
|
|
result = getTimeStampString(timeStamp);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2021-08-08 15:02:59 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
std::string filename = "mram-dump--" + timeStamp + ".bin";
|
2021-08-17 16:14:23 +02:00
|
|
|
|
|
|
|
#if BOARD_TE0720 == 0
|
2022-01-18 11:41:19 +01:00
|
|
|
std::string currentMountPrefix = sdcMan->getCurrentMountPrefix();
|
2021-08-17 16:14:23 +02:00
|
|
|
#else
|
2022-01-18 11:41:19 +01:00
|
|
|
std::string currentMountPrefix("/mnt/sd0");
|
2021-08-17 16:14:23 +02:00
|
|
|
#endif /* BOARD_TE0720 == 0 */
|
2021-08-08 15:02:59 +02:00
|
|
|
|
2022-01-18 11:41:19 +01:00
|
|
|
// Check if path to PLOC directory exists
|
|
|
|
if (not std::filesystem::exists(std::string(currentMountPrefix + "/" + plocFilePath))) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::createMramDumpFile: Ploc path does not exist"
|
|
|
|
<< std::endl;
|
|
|
|
return PATH_DOES_NOT_EXIST;
|
|
|
|
}
|
|
|
|
activeMramFile = currentMountPrefix + "/" + plocFilePath + "/" + filename;
|
|
|
|
// Create new file
|
|
|
|
std::ofstream file(activeMramFile, std::ios_base::out);
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
return RETURN_OK;
|
2021-08-08 15:02:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::getTimeStampString(std::string& timeStamp) {
|
2022-01-18 11:41:19 +01:00
|
|
|
Clock::TimeOfDay_t time;
|
|
|
|
ReturnValue_t result = Clock::getDateAndTime(&time);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::createMramDumpFile: Failed to get current time"
|
|
|
|
<< std::endl;
|
|
|
|
return GET_TIME_FAILURE;
|
|
|
|
}
|
|
|
|
timeStamp = std::to_string(time.year) + "-" + std::to_string(time.month) + "-" +
|
|
|
|
std::to_string(time.day) + "--" + std::to_string(time.hour) + "-" +
|
|
|
|
std::to_string(time.minute) + "-" + std::to_string(time.second);
|
|
|
|
return RETURN_OK;
|
2021-08-08 15:02:59 +02:00
|
|
|
}
|