eive-obsw/linux/devices/ploc/PlocSupervisorHandler.cpp

1561 lines
58 KiB
C++
Raw Normal View History

#include "PlocSupervisorHandler.h"
2022-03-27 13:07:18 +02:00
#include <fsfw/datapool/PoolReadGuard.h>
2022-03-27 13:07:18 +02:00
#include <fsfw/globalfunctions/CRC.h>
#include <fsfw/timemanager/Clock.h>
2022-03-27 13:07:18 +02:00
#include <filesystem>
#include <fstream>
#include <sstream>
#include <string>
#include "OBSWConfig.h"
PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid,
2022-03-30 09:19:30 +02:00
CookieIF* comCookie, Gpio uartIsolatorSwitch,
power::Switch_t powerSwitch)
2022-03-27 13:07:18 +02:00
: DeviceHandlerBase(objectId, uartComIFid, comCookie),
2022-03-27 14:42:20 +02:00
uartIsolatorSwitch(uartIsolatorSwitch),
2022-03-27 13:07:18 +02:00
hkset(this),
bootStatusReport(this),
2022-03-30 09:19:30 +02:00
latchupStatusReport(this),
powerSwitch(powerSwitch) {
2022-03-27 13:07:18 +02:00
if (comCookie == NULL) {
sif::error << "PlocSupervisorHandler: Invalid com cookie" << std::endl;
}
}
2022-03-27 13:07:18 +02:00
PlocSupervisorHandler::~PlocSupervisorHandler() {}
ReturnValue_t PlocSupervisorHandler::initialize() {
2022-03-27 13:07:18 +02: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 ObjectManagerIF::CHILD_INIT_FAILED;
}
2022-03-27 10:56:40 +02:00
#ifdef TE0720_1CFA
2022-03-27 13:07:18 +02:00
sdcMan = SdCardManager::instance();
#endif /* BOARD_TE0720 == 0 */
2022-03-27 13:07:18 +02:00
return result;
}
2022-03-27 13:07:18 +02:00
void PlocSupervisorHandler::doStartUp() {
setMode(_MODE_TO_ON);
2022-03-28 09:08:11 +02:00
uartIsolatorSwitch.pullHigh();
}
2022-03-28 09:08:11 +02:00
void PlocSupervisorHandler::doShutDown() {
2022-03-28 13:54:46 +02:00
setMode(_MODE_POWER_DOWN);
uartIsolatorSwitch.pullLow();
2022-03-28 09:08:11 +02:00
}
2022-03-27 13:07:18 +02:00
ReturnValue_t PlocSupervisorHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
return NOTHING_TO_SEND;
}
2022-03-27 13:07:18 +02:00
ReturnValue_t PlocSupervisorHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
return NOTHING_TO_SEND;
}
2022-03-27 13:07:18 +02:00
ReturnValue_t PlocSupervisorHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_FAILED;
switch (deviceCommand) {
2022-03-30 09:19:30 +02:00
case (supv::GET_HK_REPORT): {
prepareEmptyCmd(supv::APID_GET_HK_REPORT);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::RESTART_MPSOC): {
prepareEmptyCmd(supv::APID_RESTART_MPSOC);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::START_MPSOC): {
prepareEmptyCmd(supv::APID_START_MPSOC);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SHUTDOWN_MPSOC): {
prepareEmptyCmd(supv::APID_SHUTWOWN_MPSOC);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SEL_MPSOC_BOOT_IMAGE): {
2022-03-27 13:07:18 +02:00
prepareSelBootImageCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::RESET_MPSOC): {
prepareEmptyCmd(supv::APID_RESET_MPSOC);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_TIME_REF): {
2022-03-27 13:07:18 +02:00
result = prepareSetTimeRefCmd();
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_BOOT_TIMEOUT): {
2022-03-27 13:07:18 +02:00
prepareSetBootTimeoutCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_MAX_RESTART_TRIES): {
2022-03-27 13:07:18 +02:00
prepareRestartTriesCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::DISABLE_PERIOIC_HK_TRANSMISSION): {
2022-03-27 13:07:18 +02:00
prepareDisableHk();
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::GET_BOOT_STATUS_REPORT): {
prepareEmptyCmd(supv::APID_GET_BOOT_STATUS_RPT);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::WATCHDOGS_ENABLE): {
2022-03-27 13:07:18 +02:00
prepareWatchdogsEnableCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::WATCHDOGS_CONFIG_TIMEOUT): {
2022-03-27 13:07:18 +02:00
result = prepareWatchdogsConfigTimeoutCmd(commandData);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::ENABLE_LATCHUP_ALERT): {
2022-03-27 13:07:18 +02:00
result = prepareLatchupConfigCmd(commandData, deviceCommand);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::DISABLE_LATCHUP_ALERT): {
2022-03-27 13:07:18 +02:00
result = prepareLatchupConfigCmd(commandData, deviceCommand);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::AUTO_CALIBRATE_ALERT): {
2022-03-27 13:07:18 +02:00
result = prepareAutoCalibrateAlertCmd(commandData);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_ALERT_LIMIT): {
2022-03-27 13:07:18 +02:00
result = prepareSetAlertLimitCmd(commandData);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_ALERT_IRQ_FILTER): {
2022-03-27 13:07:18 +02:00
result = prepareSetAlertIrqFilterCmd(commandData);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_ADC_SWEEP_PERIOD): {
2022-03-27 13:07:18 +02:00
result = prepareSetAdcSweetPeriodCmd(commandData);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_ADC_ENABLED_CHANNELS): {
2022-03-27 13:07:18 +02:00
prepareSetAdcEnabledChannelsCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_ADC_WINDOW_AND_STRIDE): {
2022-03-27 13:07:18 +02:00
prepareSetAdcWindowAndStrideCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_ADC_THRESHOLD): {
2022-03-27 13:07:18 +02:00
prepareSetAdcThresholdCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::GET_LATCHUP_STATUS_REPORT): {
prepareEmptyCmd(supv::APID_GET_LATCHUP_STATUS_REPORT);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::COPY_ADC_DATA_TO_MRAM): {
prepareEmptyCmd(supv::APID_COPY_ADC_DATA_TO_MRAM);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::ENABLE_NVMS): {
2022-03-27 13:07:18 +02:00
prepareEnableNvmsCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SELECT_NVM): {
2022-03-27 13:07:18 +02:00
prepareSelectNvmCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::RUN_AUTO_EM_TESTS): {
2022-03-27 13:07:18 +02:00
result = prepareRunAutoEmTest(commandData);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::WIPE_MRAM): {
2022-03-27 13:07:18 +02:00
result = prepareWipeMramCmd(commandData);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::FIRST_MRAM_DUMP):
case (supv::CONSECUTIVE_MRAM_DUMP):
2022-03-27 13:07:18 +02:00
result = prepareDumpMramCmd(commandData);
break;
2022-03-30 09:19:30 +02:00
case (supv::PRINT_CPU_STATS): {
2022-03-27 13:07:18 +02:00
preparePrintCpuStatsCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_DBG_VERBOSITY): {
2022-03-27 13:07:18 +02:00
prepareSetDbgVerbosityCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::CAN_LOOPBACK_TEST): {
prepareEmptyCmd(supv::APID_CAN_LOOPBACK_TEST);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::SET_GPIO): {
2022-03-27 13:07:18 +02:00
prepareSetGpioCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::READ_GPIO): {
2022-03-27 13:07:18 +02:00
prepareReadGpioCmd(commandData);
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::RESTART_SUPERVISOR): {
prepareEmptyCmd(supv::APID_RESTART_SUPERVISOR);
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::FACTORY_RESET_CLEAR_ALL): {
supv::FactoryReset packet(supv::FactoryReset::Op::CLEAR_ALL);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::FACTORY_RESET_CLEAR_MIRROR): {
supv::FactoryReset packet(supv::FactoryReset::Op::MIRROR_ENTRIES);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::FACTORY_RESET_CLEAR_CIRCULAR): {
supv::FactoryReset packet(supv::FactoryReset::Op::CIRCULAR_ENTRIES);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
result = RETURN_OK;
break;
}
2022-03-30 09:19:30 +02:00
case (supv::UPDATE_AVAILABLE):
case (supv::UPDATE_IMAGE_DATA):
case (supv::UPDATE_VERIFY):
2022-03-27 13:07:18 +02:00
// Simply forward data from PLOC Updater to supervisor
std::memcpy(commandBuffer, commandData, commandDataLen);
rawPacket = commandBuffer;
rawPacketLen = commandDataLen;
2022-03-30 09:19:30 +02:00
nextReplyId = supv::ACK_REPORT;
2022-03-27 13:07:18 +02:00
result = RETURN_OK;
break;
2022-04-06 07:10:20 +02:00
case (supv::PREPARE_UPDATE): {
prepareEmptyCmd(supv::APID_PREPARE_UPDATE);
result = RETURN_OK;
break;
}
case (supv::START_MPSOC_QUIET): {
prepareEmptyCmd(supv::APID_START_MPSOC_QUIET);
result = RETURN_OK;
break;
}
case (supv::SET_SHUTDOWN_TIMEOUT): {
prepareSetShutdownTimeoutCmd(commandData);
result = RETURN_OK;
break;
}
case (supv::FACTORY_FLASH): {
prepareEmptyCmd(supv::APID_FACTORY_FLASH);
result = RETURN_OK;
break;
}
2022-03-27 13:07:18 +02:00
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;
}
void PlocSupervisorHandler::fillCommandAndReplyMap() {
2022-03-30 09:19:30 +02:00
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::UPDATE_AVAILABLE);
this->insertInCommandMap(supv::UPDATE_VERIFY);
this->insertInCommandMap(supv::UPDATE_IMAGE_DATA);
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);
2022-04-06 07:10:20 +02:00
this->insertInCommandMap(supv::PREPARE_UPDATE);
this->insertInCommandMap(supv::START_MPSOC_QUIET);
this->insertInCommandMap(supv::SET_SHUTDOWN_TIMEOUT);
this->insertInCommandMap(supv::FACTORY_FLASH);
2022-03-30 09:19:30 +02:00
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);
2022-04-06 17:27:44 +02:00
this->insertInReplyMap(supv::EXE_REPORT, 120, nullptr, supv::SIZE_EXE_REPORT);
2022-03-30 09:19:30 +02:00
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);
}
2022-03-27 13:07:18 +02:00
ReturnValue_t PlocSupervisorHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
2022-03-30 09:19:30 +02:00
if (nextReplyId == supv::FIRST_MRAM_DUMP) {
*foundId = supv::FIRST_MRAM_DUMP;
2022-03-27 13:07:18 +02:00
return parseMramPackets(start, remainingSize, foundLen);
2022-03-30 09:19:30 +02:00
} else if (nextReplyId == supv::CONSECUTIVE_MRAM_DUMP) {
*foundId = supv::CONSECUTIVE_MRAM_DUMP;
2022-03-27 13:07:18 +02:00
return parseMramPackets(start, remainingSize, foundLen);
}
ReturnValue_t result = RETURN_OK;
uint16_t apid = (*(start) << 8 | *(start + 1)) & APID_MASK;
switch (apid) {
2022-03-30 09:19:30 +02:00
case (supv::APID_ACK_SUCCESS):
*foundLen = supv::SIZE_ACK_REPORT;
*foundId = supv::ACK_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case (supv::APID_ACK_FAILURE):
*foundLen = supv::SIZE_ACK_REPORT;
*foundId = supv::ACK_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case (supv::APID_HK_REPORT):
*foundLen = supv::SIZE_HK_REPORT;
*foundId = supv::HK_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case (supv::APID_BOOT_STATUS_REPORT):
*foundLen = supv::SIZE_BOOT_STATUS_REPORT;
*foundId = supv::BOOT_STATUS_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case (supv::APID_LATCHUP_STATUS_REPORT):
*foundLen = supv::SIZE_LATCHUP_STATUS_REPORT;
*foundId = supv::LATCHUP_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case (supv::APID_EXE_SUCCESS):
*foundLen = supv::SIZE_EXE_REPORT;
*foundId = supv::EXE_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case (supv::APID_EXE_FAILURE):
*foundLen = supv::SIZE_EXE_REPORT;
*foundId = supv::EXE_REPORT;
2022-03-27 13:07:18 +02:00
break;
default: {
sif::debug << "PlocSupervisorHandler::scanForReply: Reply has invalid apid" << std::endl;
*foundLen = remainingSize;
return INVALID_APID;
}
}
2022-03-27 13:07:18 +02:00
return result;
}
2022-03-28 13:54:46 +02:00
ReturnValue_t PlocSupervisorHandler::getSwitches(const uint8_t** switches,
uint8_t* numberOfSwitches) {
2022-03-30 09:19:30 +02:00
if (powerSwitch == power::NO_SWITCH) {
2022-04-04 13:40:45 +02:00
return DeviceHandlerBase::NO_SWITCH;
2022-03-30 09:19:30 +02:00
}
2022-03-28 13:54:46 +02:00
*numberOfSwitches = 1;
*switches = &powerSwitch;
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::interpretDeviceReply(DeviceCommandId_t id,
2022-03-27 13:07:18 +02:00
const uint8_t* packet) {
ReturnValue_t result = RETURN_OK;
2022-03-27 13:07:18 +02:00
switch (id) {
2022-03-30 09:19:30 +02:00
case supv::ACK_REPORT: {
2022-03-27 13:07:18 +02:00
result = handleAckReport(packet);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::HK_REPORT): {
2022-03-27 13:07:18 +02:00
result = handleHkReport(packet);
break;
}
2022-03-30 09:19:30 +02:00
case (supv::BOOT_STATUS_REPORT): {
2022-03-27 13:07:18 +02:00
result = handleBootStatusReport(packet);
break;
2021-07-24 13:57:05 +02:00
}
2022-03-30 09:19:30 +02:00
case (supv::LATCHUP_REPORT): {
2022-03-27 13:07:18 +02:00
result = handleLatchupStatusReport(packet);
break;
2021-07-28 11:08:40 +02:00
}
2022-03-30 09:19:30 +02:00
case (supv::FIRST_MRAM_DUMP):
case (supv::CONSECUTIVE_MRAM_DUMP):
2022-03-27 13:07:18 +02:00
result = handleMramDumpPacket(id);
break;
2022-03-30 09:19:30 +02:00
case (supv::EXE_REPORT): {
2022-03-27 13:07:18 +02:00
result = handleExecutionReport(packet);
break;
}
default: {
2022-03-27 13:07:18 +02:00
sif::debug << "PlocSupervisorHandler::interpretDeviceReply: Unknown device reply id"
<< std::endl;
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
2022-03-27 13:07:18 +02:00
}
2022-03-27 13:07:18 +02:00
return result;
}
2022-03-27 13:07:18 +02:00
void PlocSupervisorHandler::setNormalDatapoolEntriesInvalid() {}
2022-03-27 13:07:18 +02:00
uint32_t PlocSupervisorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
ReturnValue_t PlocSupervisorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
2022-03-27 13:07:18 +02:00
LocalDataPoolManager& poolManager) {
2022-03-30 09:19:30 +02:00
localDataPoolMap.emplace(supv::NUM_TMS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TEMP_PS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TEMP_PL, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::SOC_STATE, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::NVM0_1_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::NVM3_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::MISSION_IO_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::FMC_STATE, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::NUM_TCS, new PoolEntry<uint32_t>({0}));
2022-04-06 07:10:20 +02:00
localDataPoolMap.emplace(supv::UPTIME, new PoolEntry<uint64_t>({0}));
2022-03-30 09:19:30 +02:00
localDataPoolMap.emplace(supv::CPULOAD, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::AVAILABLEHEAP, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::BOOT_SIGNAL, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::RESET_COUNTER, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BOOT_AFTER_MS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::BOOT_TIMEOUT_MS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::ACTIVE_NVM, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BP0_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BP1_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::BP2_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_ID, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::CNT0, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT1, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT2, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT3, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT4, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT5, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::CNT6, new PoolEntry<uint16_t>({0}));
2022-04-06 07:10:20 +02:00
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_MSEC, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_SEC, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_MIN, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_HOUR, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_DAY, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_MON, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::LATCHUP_RPT_TIME_YEAR, new PoolEntry<uint8_t>({0}));
2022-03-27 13:07:18 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
2022-03-27 13:07:18 +02:00
uint8_t expectedReplies,
bool useAlternateId,
DeviceCommandId_t alternateReplyID) {
ReturnValue_t result = RETURN_OK;
2022-03-27 13:07:18 +02:00
uint8_t enabledReplies = 0;
2022-03-27 13:07:18 +02:00
switch (command->first) {
2022-03-30 09:19:30 +02:00
case supv::GET_HK_REPORT: {
2022-03-27 13:07:18 +02:00
enabledReplies = 3;
2022-04-04 13:40:45 +02:00
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::HK_REPORT);
2022-03-27 13:07:18 +02:00
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-03-30 09:19:30 +02:00
<< supv::HK_REPORT << " not in replyMap" << std::endl;
2022-03-27 13:07:18 +02:00
}
break;
}
2022-03-30 09:19:30 +02:00
case supv::GET_BOOT_STATUS_REPORT: {
2022-03-27 13:07:18 +02:00
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
2022-03-30 09:19:30 +02:00
supv::BOOT_STATUS_REPORT);
2022-03-27 13:07:18 +02:00
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-03-30 09:19:30 +02:00
<< supv::BOOT_STATUS_REPORT << " not in replyMap" << std::endl;
2022-03-27 13:07:18 +02:00
}
break;
}
2022-03-30 09:19:30 +02:00
case supv::GET_LATCHUP_STATUS_REPORT: {
2022-03-27 13:07:18 +02:00
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
2022-03-30 09:19:30 +02:00
supv::LATCHUP_REPORT);
2022-03-27 13:07:18 +02:00
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-03-30 09:19:30 +02:00
<< supv::LATCHUP_REPORT << " not in replyMap" << std::endl;
2022-03-27 13:07:18 +02:00
}
break;
}
2022-03-30 09:19:30 +02:00
case supv::FIRST_MRAM_DUMP: {
2022-03-27 13:07:18 +02:00
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
2022-03-30 09:19:30 +02:00
supv::FIRST_MRAM_DUMP);
2022-03-27 13:07:18 +02:00
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-03-30 09:19:30 +02:00
<< supv::FIRST_MRAM_DUMP << " not in replyMap" << std::endl;
2022-03-27 13:07:18 +02:00
}
break;
2021-08-31 11:20:21 +02:00
}
2022-03-30 09:19:30 +02:00
case supv::CONSECUTIVE_MRAM_DUMP: {
2022-03-27 13:07:18 +02:00
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
2022-03-30 09:19:30 +02:00
supv::CONSECUTIVE_MRAM_DUMP);
2022-03-27 13:07:18 +02:00
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-03-30 09:19:30 +02:00
<< supv::CONSECUTIVE_MRAM_DUMP << " not in replyMap" << std::endl;
2022-03-27 13:07:18 +02:00
}
break;
2021-07-31 08:32:57 +02:00
}
2022-03-30 09:19:30 +02:00
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::UPDATE_AVAILABLE:
case supv::UPDATE_IMAGE_DATA:
case supv::UPDATE_VERIFY:
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:
2022-04-06 07:10:20 +02:00
case supv::PREPARE_UPDATE:
case supv::START_MPSOC_QUIET:
case supv::SET_SHUTDOWN_TIMEOUT:
case supv::FACTORY_FLASH:
2022-03-27 13:07:18 +02:00
enabledReplies = 2;
break;
default:
2022-03-27 13:07:18 +02: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 =
2022-03-30 09:19:30 +02:00
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::ACK_REPORT);
2022-03-27 13:07:18 +02:00
if (result != RETURN_OK) {
2022-04-04 13:40:45 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << supv::ACK_REPORT
<< " not in replyMap" << std::endl;
2022-03-27 13:07:18 +02:00
}
result =
2022-03-30 09:19:30 +02:00
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, supv::EXE_REPORT);
2022-03-27 13:07:18 +02:00
if (result != RETURN_OK) {
2022-04-04 13:40:45 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << supv::EXE_REPORT
<< " not in replyMap" << std::endl;
2022-03-27 13:07:18 +02:00
}
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
2022-03-27 13:07:18 +02:00
uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1);
uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2);
if (receivedCrc != recalculatedCrc) {
return CRC_FAILURE;
}
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) {
2022-03-27 13:07:18 +02:00
ReturnValue_t result = RETURN_OK;
2022-03-30 09:19:30 +02:00
result = verifyPacket(data, supv::SIZE_ACK_REPORT);
2022-03-27 13:07:18 +02:00
if (result == CRC_FAILURE) {
sif::error << "PlocSupervisorHandler::handleAckReport: CRC failure" << std::endl;
2022-03-30 09:19:30 +02:00
nextReplyId = supv::NONE;
replyRawReplyIfnotWiretapped(data, supv::SIZE_ACK_REPORT);
2022-03-27 13:07:18 +02:00
triggerEvent(SUPV_CRC_FAILURE_EVENT);
2022-03-30 09:19:30 +02:00
sendFailureReport(supv::ACK_REPORT, CRC_FAILURE);
2022-03-27 13:07:18 +02:00
disableAllReplies();
return RETURN_OK;
}
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
switch (apid) {
2022-03-30 09:19:30 +02:00
case supv::APID_ACK_FAILURE: {
2022-03-27 13:07:18 +02:00
// 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);
}
2022-03-30 09:19:30 +02:00
sendFailureReport(supv::ACK_REPORT, RECEIVED_ACK_FAILURE);
2022-03-27 13:07:18 +02:00
disableAllReplies();
2022-03-30 09:19:30 +02:00
nextReplyId = supv::NONE;
2022-03-27 13:07:18 +02:00
result = IGNORE_REPLY_DATA;
break;
}
2022-03-30 09:19:30 +02:00
case supv::APID_ACK_SUCCESS: {
2022-03-27 13:07:18 +02:00
setNextReplyId();
break;
}
default: {
sif::debug << "PlocSupervisorHandler::handleAckReport: Invalid APID in Ack report"
<< std::endl;
result = RETURN_FAILED;
break;
}
}
2022-03-27 13:07:18 +02:00
return result;
}
ReturnValue_t PlocSupervisorHandler::handleExecutionReport(const uint8_t* data) {
2022-03-27 13:07:18 +02:00
ReturnValue_t result = RETURN_OK;
2022-03-30 09:19:30 +02:00
result = verifyPacket(data, supv::SIZE_EXE_REPORT);
2022-03-27 13:07:18 +02:00
if (result == CRC_FAILURE) {
sif::error << "PlocSupervisorHandler::handleExecutionReport: CRC failure" << std::endl;
2022-03-30 09:19:30 +02:00
nextReplyId = supv::NONE;
2022-03-27 13:07:18 +02:00
return result;
}
2022-03-27 13:07:18 +02:00
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
2022-03-27 13:07:18 +02:00
switch (apid) {
2022-03-30 09:19:30 +02:00
case (supv::APID_EXE_SUCCESS): {
2022-03-27 13:07:18 +02:00
break;
}
2022-03-30 09:19:30 +02:00
case (supv::APID_EXE_FAILURE): {
2022-03-27 13:07:18 +02: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;
}
2022-04-06 17:27:44 +02:00
uint16_t status = *(data + EXE_STATUS_OFFSET) << 8 | *(data + EXE_STATUS_OFFSET + 1);
sif::info << "Execution status: 0x" << std::hex << status << std::endl;
2022-03-30 09:19:30 +02:00
sendFailureReport(supv::EXE_REPORT, RECEIVED_EXE_FAILURE);
2022-03-27 13:07:18 +02:00
disableExeReportReply();
result = IGNORE_REPLY_DATA;
break;
}
default: {
2022-03-27 13:07:18 +02:00
sif::error << "PlocSupervisorHandler::handleExecutionReport: Unknown APID" << std::endl;
result = RETURN_FAILED;
break;
}
2022-03-27 13:07:18 +02:00
}
2022-03-30 09:19:30 +02:00
nextReplyId = supv::NONE;
2022-03-27 13:07:18 +02:00
return result;
}
ReturnValue_t PlocSupervisorHandler::handleHkReport(const uint8_t* data) {
2022-03-27 13:07:18 +02:00
ReturnValue_t result = RETURN_OK;
2022-03-30 09:19:30 +02:00
result = verifyPacket(data, supv::SIZE_HK_REPORT);
2022-03-27 13:07:18 +02:00
if (result == CRC_FAILURE) {
sif::error << "PlocSupervisorHandler::handleHkReport: Hk report has invalid crc" << std::endl;
}
2022-03-30 09:19:30 +02:00
uint16_t offset = supv::DATA_FIELD_OFFSET;
2022-03-27 13:07:18 +02:00
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;
2022-04-06 07:10:20 +02:00
size_t size = sizeof(hkset.uptime.value);
result = SerializeAdapter::deSerialize(&hkset.uptime, data + offset, &size,
SerializeIF::Endianness::BIG);
offset += 8;
2022-03-27 13:07:18 +02:00
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;
2022-03-30 09:19:30 +02:00
nextReplyId = supv::EXE_REPORT;
2021-08-17 17:48:51 +02:00
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
2022-03-27 13:07:18 +02: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: "
<< static_cast<unsigned int>(hkset.nvm0_1_state.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleHkReport: nvm3_state: "
<< static_cast<unsigned int>(hkset.nvm3_state.value) << std::endl;
2022-04-06 17:27:44 +02:00
sif::info << "PlocSupervisorHandler::handleHkReport: mission_io_state: "
<< static_cast<unsigned int>(hkset.missionIoState.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleHkReport: fmc_state: "
<< static_cast<unsigned int>(hkset.fmcState.value) << std::endl;
2021-07-22 08:06:04 +02:00
#endif
2022-03-27 13:07:18 +02:00
return result;
}
2021-07-24 13:57:05 +02:00
ReturnValue_t PlocSupervisorHandler::handleBootStatusReport(const uint8_t* data) {
2022-03-27 13:07:18 +02:00
ReturnValue_t result = RETURN_OK;
2021-07-24 13:57:05 +02:00
2022-03-30 09:19:30 +02:00
result = verifyPacket(data, supv::SIZE_BOOT_STATUS_REPORT);
2021-07-24 13:57:05 +02:00
2022-03-27 13:07:18 +02:00
if (result == CRC_FAILURE) {
sif::error << "PlocSupervisorHandler::handleBootStatusReport: Boot status report has invalid"
" crc"
<< std::endl;
return result;
}
2022-03-30 09:19:30 +02:00
uint16_t offset = supv::DATA_FIELD_OFFSET;
2022-03-27 13:07:18 +02:00
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);
2022-04-06 07:10:20 +02:00
offset += 1;
bootStatusReport.bootState = *(data + offset);
offset += 1;
bootStatusReport.bootCycles = *(data + offset);
2022-03-27 13:07:18 +02:00
2022-03-30 09:19:30 +02:00
nextReplyId = supv::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-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Boot signal: "
<< static_cast<unsigned int>(bootStatusReport.bootSignal.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Reset counter: "
<< static_cast<unsigned int>(bootStatusReport.resetCounter.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BootAfterMs: "
<< bootStatusReport.bootAfterMs << " ms" << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BootTimeoutMs: "
2022-04-06 17:27:44 +02:00
<< std::dec << bootStatusReport.bootTimeoutMs << " ms" << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Active NVM: "
<< static_cast<unsigned int>(bootStatusReport.activeNvm.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP0: "
<< static_cast<unsigned int>(bootStatusReport.bp0State.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP1: "
<< static_cast<unsigned int>(bootStatusReport.bp1State.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP2: "
<< static_cast<unsigned int>(bootStatusReport.bp2State.value) << std::endl;
2022-04-06 17:27:44 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Boot state: "
<< static_cast<unsigned int>(bootStatusReport.bootState.value) << std::endl;
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Boot cycles: "
<< static_cast<unsigned int>(bootStatusReport.bootCycles.value) << std::endl;
2021-07-24 13:57:05 +02:00
#endif
2022-03-27 13:07:18 +02:00
return result;
2021-07-24 13:57:05 +02:00
}
ReturnValue_t PlocSupervisorHandler::handleLatchupStatusReport(const uint8_t* data) {
2022-03-27 13:07:18 +02:00
ReturnValue_t result = RETURN_OK;
2022-03-30 09:19:30 +02:00
result = verifyPacket(data, supv::SIZE_LATCHUP_STATUS_REPORT);
2022-03-27 13:07:18 +02:00
if (result == CRC_FAILURE) {
sif::error << "PlocSupervisorHandler::handleLatchupStatusReport: Latchup status report has "
<< "invalid crc" << std::endl;
return result;
}
2022-03-30 09:19:30 +02:00
uint16_t offset = supv::DATA_FIELD_OFFSET;
2022-03-27 13:07:18 +02:00
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;
2022-04-06 17:27:44 +02:00
latchupStatusReport.timeMsec = (*(data + offset) << 8 | *(data + offset + 1)) & 0x7FFF;
2022-04-06 07:10:20 +02:00
offset += 2;
latchupStatusReport.timeSec = *(data + offset);
offset += 1;
latchupStatusReport.timeMin = *(data + offset);
offset += 1;
latchupStatusReport.timeHour = *(data + offset);
offset += 1;
latchupStatusReport.timeDay = *(data + offset);
offset += 1;
latchupStatusReport.timeMon = *(data + offset);
offset += 1;
latchupStatusReport.timeYear = *(data + offset);
2022-03-27 13:07:18 +02:00
2022-03-30 09:19:30 +02:00
nextReplyId = supv::EXE_REPORT;
2021-08-17 17:48:51 +02:00
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Latchup ID: "
<< static_cast<unsigned int>(latchupStatusReport.id.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT0: "
<< latchupStatusReport.cnt0 << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT1: "
<< latchupStatusReport.cnt1 << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT2: "
<< latchupStatusReport.cnt2 << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT3: "
<< latchupStatusReport.cnt3 << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT4: "
<< latchupStatusReport.cnt4 << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT5: "
<< latchupStatusReport.cnt5 << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT6: "
<< latchupStatusReport.cnt6 << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Sec: "
2022-04-06 17:27:44 +02:00
<< static_cast<unsigned int>(latchupStatusReport.timeSec.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Min: "
2022-04-06 17:27:44 +02:00
<< static_cast<unsigned int>(latchupStatusReport.timeMin.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Hour: "
2022-04-06 17:27:44 +02:00
<< static_cast<unsigned int>(latchupStatusReport.timeHour.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Day: "
2022-04-06 17:27:44 +02:00
<< static_cast<unsigned int>(latchupStatusReport.timeDay.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Mon: "
2022-04-06 17:27:44 +02:00
<< static_cast<unsigned int>(latchupStatusReport.timeMon.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Year: "
2022-04-06 17:27:44 +02:00
<< static_cast<unsigned int>(latchupStatusReport.timeYear.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Msec: "
2022-04-06 17:27:44 +02:00
<< static_cast<unsigned int>(latchupStatusReport.timeMsec.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: isSet: 0x" << std::hex
<< latchupStatusReport.timeMsec << std::dec << std::endl;
#endif
2022-03-27 13:07:18 +02:00
return result;
}
void PlocSupervisorHandler::setNextReplyId() {
2022-03-27 13:07:18 +02:00
switch (getPendingCommand()) {
2022-03-30 09:19:30 +02:00
case supv::GET_HK_REPORT:
nextReplyId = supv::HK_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case supv::GET_BOOT_STATUS_REPORT:
nextReplyId = supv::BOOT_STATUS_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case supv::GET_LATCHUP_STATUS_REPORT:
nextReplyId = supv::LATCHUP_REPORT;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case supv::FIRST_MRAM_DUMP:
nextReplyId = supv::FIRST_MRAM_DUMP;
2022-03-27 13:07:18 +02:00
break;
2022-03-30 09:19:30 +02:00
case supv::CONSECUTIVE_MRAM_DUMP:
nextReplyId = supv::CONSECUTIVE_MRAM_DUMP;
2022-03-27 13:07:18 +02:00
break;
default:
2022-03-27 13:07:18 +02:00
/* If no telemetry is expected the next reply is always the execution report */
2022-03-30 09:19:30 +02:00
nextReplyId = supv::EXE_REPORT;
2022-03-27 13:07:18 +02:00
break;
}
}
2022-03-27 13:07:18 +02:00
size_t PlocSupervisorHandler::getNextReplyLength(DeviceCommandId_t commandId) {
size_t replyLen = 0;
2022-03-30 09:19:30 +02:00
if (nextReplyId == supv::NONE) {
2022-03-27 13:07:18 +02:00
return replyLen;
}
2022-03-30 09:19:30 +02:00
if (nextReplyId == supv::FIRST_MRAM_DUMP || nextReplyId == supv::CONSECUTIVE_MRAM_DUMP) {
2022-03-27 13:07:18 +02:00
/**
* 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.
*/
2022-03-30 09:19:30 +02:00
replyLen = supv::MAX_PACKET_SIZE * 20;
2022-03-27 13:07:18 +02:00
return replyLen;
}
2021-07-31 08:32:57 +02:00
2022-03-27 13:07:18 +02:00
DeviceReplyIter iter = deviceReplyMap.find(nextReplyId);
if (iter != deviceReplyMap.end()) {
if (iter->second.delayCycles == 0) {
/* Reply inactive */
return replyLen;
}
2022-03-27 13:07:18 +02:00
replyLen = iter->second.replyLen;
} else {
sif::debug << "PlocSupervisorHandler::getNextReplyLength: No entry for reply with reply id "
<< std::hex << nextReplyId << " in deviceReplyMap" << std::endl;
}
2022-03-27 13:07:18 +02:00
return replyLen;
}
2022-03-27 13:07:18 +02:00
void PlocSupervisorHandler::handleDeviceTM(const uint8_t* data, size_t dataSize,
DeviceCommandId_t replyId) {
ReturnValue_t result = RETURN_OK;
2022-03-27 13:07:18 +02:00
if (wiretappingMode == RAW) {
/* Data already sent in doGetRead() */
return;
}
2022-03-27 13:07:18 +02: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;
2022-03-27 13:07:18 +02:00
if (queueId == NO_COMMANDER) {
return;
}
2022-03-27 13:07:18 +02:00
result = actionHelper.reportData(queueId, replyId, data, dataSize);
if (result != RETURN_OK) {
sif::debug << "PlocSupervisorHandler::handleDeviceTM: Failed to report data" << std::endl;
}
}
void PlocSupervisorHandler::prepareEmptyCmd(uint16_t apid) {
2022-03-30 09:19:30 +02:00
supv::EmptyPacket packet(apid);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
2022-03-27 13:07:18 +02:00
void PlocSupervisorHandler::prepareSelBootImageCmd(const uint8_t* commandData) {
2022-03-30 09:19:30 +02:00
supv::MPSoCBootSelect packet(*commandData, *(commandData + 1), *(commandData + 2),
2022-04-04 13:40:45 +02:00
*(commandData + 3));
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
ReturnValue_t PlocSupervisorHandler::prepareSetTimeRefCmd() {
2022-03-27 13:07:18 +02: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;
}
2022-03-30 09:19:30 +02:00
supv::SetTimeRef packet(&time);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
2021-07-22 08:06:04 +02:00
void PlocSupervisorHandler::prepareDisableHk() {
2022-03-30 09:19:30 +02:00
supv::DisablePeriodicHkTransmission packet;
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
2021-07-22 08:06:04 +02:00
}
2022-03-27 13:07:18 +02:00
void PlocSupervisorHandler::prepareSetBootTimeoutCmd(const uint8_t* commandData) {
uint32_t timeout = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 |
*(commandData + 3);
2022-03-30 09:19:30 +02:00
supv::SetBootTimeout packet(timeout);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
2021-07-22 08:06:04 +02:00
}
2022-03-27 13:07:18 +02:00
void PlocSupervisorHandler::prepareRestartTriesCmd(const uint8_t* commandData) {
uint8_t restartTries = *(commandData);
2022-03-30 09:19:30 +02:00
supv::SetRestartTries packet(restartTries);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
2022-03-27 13:07:18 +02: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);
2022-03-30 09:19:30 +02:00
supv::WatchdogsEnable packet(watchdogPs, watchdogPl, watchdogInt);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
2022-03-27 13:07:18 +02: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;
}
2022-03-30 09:19:30 +02:00
supv::WatchdogsConfigTimeout packet(watchdog, timeout);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::prepareLatchupConfigCmd(const uint8_t* commandData,
2022-03-27 13:07:18 +02:00
DeviceCommandId_t deviceCommand) {
ReturnValue_t result = RETURN_OK;
uint8_t latchupId = *commandData;
if (latchupId > 6) {
return INVALID_LATCHUP_ID;
}
switch (deviceCommand) {
2022-03-30 09:19:30 +02:00
case (supv::ENABLE_LATCHUP_ALERT): {
supv::LatchupAlert packet(true, latchupId);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
break;
}
2022-03-30 09:19:30 +02:00
case (supv::DISABLE_LATCHUP_ALERT): {
supv::LatchupAlert packet(false, latchupId);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
break;
}
default: {
2022-03-27 13:07:18 +02:00
sif::debug << "PlocSupervisorHandler::prepareLatchupConfigCmd: Invalid command id"
<< std::endl;
result = RETURN_FAILED;
break;
}
2022-03-27 13:07:18 +02:00
}
return result;
}
ReturnValue_t PlocSupervisorHandler::prepareAutoCalibrateAlertCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02: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;
}
2022-03-30 09:19:30 +02:00
supv::AutoCalibrateAlert packet(latchupId, mg);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::prepareSetAlertIrqFilterCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint8_t latchupId = *commandData;
uint8_t tp = *(commandData + 1);
uint8_t div = *(commandData + 2);
if (latchupId > 6) {
return INVALID_LATCHUP_ID;
}
2022-03-30 09:19:30 +02:00
supv::SetAlertIrqFilter packet(latchupId, tp, div);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::prepareSetAlertLimitCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02: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;
}
2022-03-30 09:19:30 +02:00
supv::SetAlertlimit packet(latchupId, dutycycle);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
ReturnValue_t PlocSupervisorHandler::prepareSetAdcSweetPeriodCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint32_t sweepPeriod = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 |
*(commandData + 3);
if (sweepPeriod < 21) {
return SWEEP_PERIOD_TOO_SMALL;
}
2022-03-30 09:19:30 +02:00
supv::SetAdcSweepPeriod packet(sweepPeriod);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
return RETURN_OK;
}
void PlocSupervisorHandler::prepareSetAdcEnabledChannelsCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint16_t ch = *(commandData) << 8 | *(commandData + 1);
2022-03-30 09:19:30 +02:00
supv::SetAdcEnabledChannels packet(ch);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
void PlocSupervisorHandler::prepareSetAdcWindowAndStrideCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02: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);
2022-03-30 09:19:30 +02:00
supv::SetAdcWindowAndStride packet(windowSize, stridingStepSize);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
void PlocSupervisorHandler::prepareSetAdcThresholdCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint32_t threshold = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 |
*(commandData + 3);
2022-03-30 09:19:30 +02:00
supv::SetAdcThreshold packet(threshold);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
2021-07-28 11:55:16 +02:00
void PlocSupervisorHandler::prepareEnableNvmsCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint8_t n01 = *commandData;
uint8_t n3 = *(commandData + 1);
2022-03-30 09:19:30 +02:00
supv::EnableNvms packet(n01, n3);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
2021-07-28 11:55:16 +02:00
}
void PlocSupervisorHandler::prepareSelectNvmCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint8_t mem = *commandData;
2022-03-30 09:19:30 +02:00
supv::SelectNvm packet(mem);
2022-03-27 13:07:18 +02:00
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-03-27 13:07:18 +02:00
uint8_t test = *commandData;
if (test != 1 && test != 2) {
return INVALID_TEST_PARAM;
}
2022-03-30 09:19:30 +02:00
supv::RunAutoEmTests packet(test);
2022-03-27 13:07:18 +02:00
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-03-27 13:07:18 +02: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;
}
2022-03-30 09:19:30 +02:00
supv::MramCmd packet(start, stop, supv::MramCmd::MramAction::WIPE);
2022-03-27 13:07:18 +02:00
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-03-27 13:07:18 +02: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);
2022-03-30 09:19:30 +02:00
supv::MramCmd packet(start, stop, supv::MramCmd::MramAction::DUMP);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
if ((stop - start) <= 0) {
return INVALID_MRAM_ADDRESSES;
}
2022-03-30 09:19:30 +02:00
expectedMramDumpPackets = (stop - start) / supv::MAX_DATA_CAPACITY;
if ((stop - start) % supv::MAX_DATA_CAPACITY) {
2022-03-27 13:07:18 +02:00
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-03-27 13:07:18 +02:00
uint8_t en = *commandData;
2022-03-30 09:19:30 +02:00
supv::PrintCpuStats packet(en);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
2021-08-02 15:28:57 +02:00
}
void PlocSupervisorHandler::prepareSetDbgVerbosityCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint8_t vb = *commandData;
2022-03-30 09:19:30 +02:00
supv::SetDbgVerbosity packet(vb);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
2021-08-02 15:28:57 +02:00
}
void PlocSupervisorHandler::prepareSetGpioCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint8_t port = *commandData;
uint8_t pin = *(commandData + 1);
uint8_t val = *(commandData + 2);
2022-03-30 09:19:30 +02:00
supv::SetGpio packet(port, pin, val);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
2021-08-02 15:28:57 +02:00
}
void PlocSupervisorHandler::prepareReadGpioCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint8_t port = *commandData;
uint8_t pin = *(commandData + 1);
2022-03-30 09:19:30 +02:00
supv::ReadGpio packet(port, pin);
2022-03-27 13:07:18 +02:00
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
2021-08-02 15:28:57 +02:00
}
void PlocSupervisorHandler::packetToOutBuffer(uint8_t* packetData, size_t fullSize) {
2022-03-27 13:07:18 +02:00
memcpy(commandBuffer, packetData, fullSize);
rawPacket = commandBuffer;
rawPacketLen = fullSize;
2022-03-30 09:19:30 +02:00
nextReplyId = supv::ACK_REPORT;
}
2022-04-06 07:10:20 +02:00
void PlocSupervisorHandler::prepareSetShutdownTimeoutCmd(const uint8_t* commandData) {
uint32_t timeout = 0;
ReturnValue_t result = RETURN_OK;
size_t size = sizeof(timeout);
result =
SerializeAdapter::deSerialize(&timeout, &commandData, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::warning
<< "PlocSupervisorHandler::prepareSetShutdownTimeoutCmd: Failed to deserialize timeout"
<< std::endl;
}
supv::SetShutdownTimeout packet(timeout);
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
}
void PlocSupervisorHandler::disableAllReplies() {
2022-03-27 13:07:18 +02:00
DeviceReplyMap::iterator iter;
2022-03-27 13:07:18 +02:00
/* Disable ack reply */
2022-03-30 09:19:30 +02:00
iter = deviceReplyMap.find(supv::ACK_REPORT);
2022-03-27 13:07:18 +02:00
DeviceReplyInfo* info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
2022-03-27 13:07:18 +02:00
DeviceCommandId_t commandId = getPendingCommand();
2022-03-27 13:07:18 +02:00
/* If the command expects a telemetry packet the appropriate tm reply will be disabled here */
switch (commandId) {
2022-03-30 09:19:30 +02:00
case supv::GET_HK_REPORT: {
iter = deviceReplyMap.find(supv::GET_HK_REPORT);
2022-03-27 13:07:18 +02:00
info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
break;
}
default: {
2022-03-27 13:07:18 +02:00
break;
}
2022-03-27 13:07:18 +02:00
}
2022-03-27 13:07:18 +02:00
/* We must always disable the execution report reply here */
disableExeReportReply();
}
void PlocSupervisorHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) {
2022-03-27 13:07:18 +02:00
DeviceReplyIter iter = deviceReplyMap.find(replyId);
2022-03-27 13:07:18 +02:00
if (iter == deviceReplyMap.end()) {
sif::debug << "PlocSupervisorHandler::sendFailureReport: Reply not in reply map" << std::endl;
return;
}
2022-03-27 13:07:18 +02:00
DeviceCommandInfo* info = &(iter->second.command->second);
2022-03-27 13:07:18 +02:00
if (info == nullptr) {
sif::debug << "PlocSupervisorHandler::sendFailureReport: Reply has no active command"
<< std::endl;
return;
}
2022-03-27 13:07:18 +02:00
if (info->sendReplyTo != NO_COMMANDER) {
actionHelper.finish(false, info->sendReplyTo, iter->first, status);
}
info->isExecuting = false;
}
void PlocSupervisorHandler::disableExeReportReply() {
2022-03-30 09:19:30 +02:00
DeviceReplyIter iter = deviceReplyMap.find(supv::EXE_REPORT);
2022-03-27 13:07:18 +02:00
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-31 08:32:57 +02:00
2022-03-27 13:07:18 +02: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;
2022-03-30 09:19:30 +02:00
if (bufferTop >= supv::SPACE_PACKET_HEADER_LENGTH) {
2022-03-27 13:07:18 +02:00
packetLen = readSpacePacketLength(spacePacketBuffer);
2021-07-31 08:32:57 +02:00
}
2022-03-30 09:19:30 +02:00
if (bufferTop == supv::SPACE_PACKET_HEADER_LENGTH + packetLen + 1) {
2022-03-27 13:07:18 +02:00
packetInBuffer = true;
bufferTop = 0;
return checkMramPacketApid();
}
2022-03-30 09:19:30 +02:00
if (bufferTop == supv::MAX_PACKET_SIZE) {
2022-03-27 13:07:18 +02:00
*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-03-27 13:07:18 +02:00
ReturnValue_t result = RETURN_FAILED;
2021-07-31 08:32:57 +02:00
2022-03-27 13:07:18 +02:00
// Prepare packet for downlink
if (packetInBuffer) {
uint16_t packetLen = readSpacePacketLength(spacePacketBuffer);
2022-03-30 09:19:30 +02:00
result = verifyPacket(spacePacketBuffer, supv::SPACE_PACKET_HEADER_LENGTH + packetLen + 1);
2022-03-27 13:07:18 +02:00
if (result != RETURN_OK) {
sif::warning << "PlocSupervisorHandler::handleMramDumpPacket: CRC failure" << std::endl;
return result;
2021-07-31 08:32:57 +02:00
}
2022-03-27 13:07:18 +02:00
handleMramDumpFile(id);
if (downlinkMramDump == true) {
2022-03-30 09:19:30 +02:00
handleDeviceTM(spacePacketBuffer + supv::SPACE_PACKET_HEADER_LENGTH, packetLen - 1, id);
2022-03-27 13:07:18 +02:00
}
packetInBuffer = false;
receivedMramDumpPackets++;
if (expectedMramDumpPackets == receivedMramDumpPackets) {
2022-03-30 09:19:30 +02:00
nextReplyId = supv::EXE_REPORT;
2022-03-27 13:07:18 +02:00
}
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-03-27 13:07:18 +02:00
DeviceReplyMap::iterator mramDumpIter = deviceReplyMap.find(id);
2022-03-30 09:19:30 +02:00
DeviceReplyMap::iterator exeReportIter = deviceReplyMap.find(supv::EXE_REPORT);
2022-03-27 13:07:18 +02:00
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-03-27 13:07:18 +02: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;
2022-03-30 09:19:30 +02:00
if (sequenceFlags != static_cast<uint8_t>(supv::SequenceFlags::LAST_PKT) &&
(sequenceFlags != static_cast<uint8_t>(supv::SequenceFlags::STANDALONE_PKT))) {
2022-03-27 13:07:18 +02:00
// 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-03-30 09:19:30 +02:00
uint16_t apid = (spacePacketBuffer[0] << 8 | spacePacketBuffer[1]) & supv::APID_MASK;
if (apid != supv::APID_MRAM_DUMP_TM) {
2022-03-27 13:07:18 +02:00
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-03-27 13:07:18 +02:00
ReturnValue_t result = RETURN_OK;
uint16_t packetLen = readSpacePacketLength(spacePacketBuffer);
uint8_t sequenceFlags = readSequenceFlags(spacePacketBuffer);
2022-03-30 09:19:30 +02:00
if (id == supv::FIRST_MRAM_DUMP) {
if (sequenceFlags == static_cast<uint8_t>(supv::SequenceFlags::FIRST_PKT) ||
(sequenceFlags == static_cast<uint8_t>(supv::SequenceFlags::STANDALONE_PKT))) {
2022-03-27 13:07:18 +02:00
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);
2022-04-04 13:40:45 +02:00
file.write(reinterpret_cast<const char*>(spacePacketBuffer + supv::SPACE_PACKET_HEADER_LENGTH),
packetLen - 1);
2022-03-27 13:07:18 +02:00
file.close();
return RETURN_OK;
2021-08-08 15:02:59 +02:00
}
uint16_t PlocSupervisorHandler::readSpacePacketLength(uint8_t* spacePacket) {
2022-03-27 13:07:18 +02:00
return spacePacket[4] << 8 | spacePacket[5];
2021-08-08 15:02:59 +02:00
}
uint8_t PlocSupervisorHandler::readSequenceFlags(uint8_t* spacePacket) {
2022-03-27 13:07:18 +02:00
return spacePacketBuffer[2] >> 6;
2021-08-08 15:02:59 +02:00
}
ReturnValue_t PlocSupervisorHandler::createMramDumpFile() {
2022-03-27 13:07:18 +02: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-03-27 13:07:18 +02:00
std::string filename = "mram-dump--" + timeStamp + ".bin";
2022-03-27 10:56:40 +02:00
#ifdef TE0720_1CFA
2022-03-27 13:07:18 +02:00
std::string currentMountPrefix = sdcMan->getCurrentMountPrefix();
#else
2022-03-27 13:07:18 +02:00
std::string currentMountPrefix("/mnt/sd0");
#endif /* BOARD_TE0720 == 0 */
2021-08-08 15:02:59 +02:00
2022-03-27 13:07:18 +02: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-03-27 13:07:18 +02: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
}