eive-obsw/archive/PlocSupervisorHandler.cpp

2028 lines
75 KiB
C++
Raw Normal View History

#include "PlocSupervisorHandler.h"
2022-03-27 13:07:18 +02:00
2022-09-16 11:43:11 +02:00
#include <fsfw/filesystem/HasFileSystemIF.h>
2022-11-16 13:26:49 +01:00
#include <fsfw/globalfunctions/arrayprinter.h>
2022-11-21 18:32:23 +01:00
#include <fsfw/tasks/TaskFactory.h>
2022-08-22 13:50:24 +02:00
2022-03-27 13:07:18 +02:00
#include <filesystem>
#include <fstream>
#include <sstream>
#include <string>
#include "OBSWConfig.h"
2022-04-10 18:46:39 +02:00
#include "eive/definitions.h"
#include "fsfw/datapool/PoolReadGuard.h"
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/ipc/QueueFactory.h"
#include "fsfw/timemanager/Clock.h"
2022-03-27 13:07:18 +02:00
using namespace supv;
2022-11-08 19:53:26 +01:00
using namespace returnvalue;
2022-11-16 15:03:10 +01:00
PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, CookieIF* comCookie,
Gpio uartIsolatorSwitch, power::Switch_t powerSwitch,
2022-11-15 17:40:19 +01:00
PlocSupvUartManager& supvHelper)
2022-11-16 15:03:10 +01:00
: DeviceHandlerBase(objectId, supvHelper.getObjectId(), 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),
2023-11-08 10:46:59 +01:00
countersReport(this),
2022-04-21 16:30:23 +02:00
adcReport(this),
2022-04-10 18:46:39 +02:00
powerSwitch(powerSwitch),
2022-11-15 17:41:15 +01:00
uartManager(supvHelper) {
2022-11-08 19:53:26 +01:00
if (comCookie == nullptr) {
2022-03-27 13:07:18 +02:00
sif::error << "PlocSupervisorHandler: Invalid com cookie" << std::endl;
}
spParams.buf = commandBuffer;
spParams.maxSize = sizeof(commandBuffer);
2022-04-10 18:46:39 +02:00
eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5);
}
2022-03-27 13:07:18 +02:00
PlocSupervisorHandler::~PlocSupervisorHandler() {}
ReturnValue_t PlocSupervisorHandler::initialize() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
result = DeviceHandlerBase::initialize();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-27 13:07:18 +02:00
return result;
}
#ifdef XIPHOS_Q7S
2022-03-27 13:07:18 +02:00
sdcMan = SdCardManager::instance();
2022-04-10 18:46:39 +02:00
#endif /* TE0720_1CFA */
result = eventSubscription();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-10 18:46:39 +02:00
return result;
}
2022-03-27 13:07:18 +02:00
return result;
}
2022-04-10 18:46:39 +02:00
void PlocSupervisorHandler::performOperationHook() {
2023-11-08 18:43:11 +01:00
if (normalCommandIsPending and normalCmdCd.hasTimedOut()) {
2023-11-08 18:19:24 +01:00
// Event, FDIR, printout? Leads to spam though and normally should not happen..
normalCommandIsPending = false;
}
2023-11-08 18:43:11 +01:00
if (commandIsPending and cmdCd.hasTimedOut()) {
2023-11-08 18:19:24 +01:00
// Event, FDIR, printout? Leads to spam though and normally should not happen..
commandIsPending = false;
2023-11-08 18:43:11 +01:00
// if(iter->second.sendReplyTo != NO_COMMANDER) {
// actionHelper.finish(true, iter->second.sendReplyTo, iter->first, returnvalue::OK);
// }
2023-11-08 18:19:24 +01:00
disableAllReplies();
}
2022-04-10 18:46:39 +02:00
EventMessage event;
2022-08-24 17:27:47 +02:00
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == returnvalue::OK;
2022-04-10 18:46:39 +02:00
result = eventQueue->receiveMessage(&event)) {
switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE:
handleEvent(&event);
break;
default:
sif::debug << "PlocSupervisorHandler::performOperationHook: Did not subscribe to this event"
2022-04-10 18:46:39 +02:00
<< " message" << std::endl;
break;
}
}
}
ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) {
2022-04-13 11:56:37 +02:00
using namespace supv;
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-04-10 18:46:39 +02:00
switch (actionId) {
default:
break;
}
2022-11-21 18:32:23 +01:00
if (uartManager.longerRequestActive()) {
return result::SUPV_HELPER_EXECUTING;
2022-04-10 18:46:39 +02:00
}
result = acceptExternalDeviceCommands();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2022-04-10 18:46:39 +02:00
switch (actionId) {
2022-04-13 11:56:37 +02:00
case PERFORM_UPDATE: {
2022-04-10 18:46:39 +02:00
if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
return result::FILENAME_TOO_LONG;
2022-04-10 18:46:39 +02:00
}
2022-11-21 18:32:23 +01:00
shutdownCmdSent = false;
2022-08-20 22:52:48 +02:00
UpdateParams params;
result = extractUpdateCommand(data, size, params);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-10 18:46:39 +02:00
return result;
}
2022-11-15 17:41:15 +01:00
result = uartManager.performUpdate(params);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-10 18:46:39 +02:00
return result;
}
return EXECUTION_FINISHED;
}
2022-05-23 12:05:42 +02:00
case CONTINUE_UPDATE: {
2022-11-21 18:32:23 +01:00
shutdownCmdSent = false;
2022-11-15 17:41:15 +01:00
uartManager.initiateUpdateContinuation();
2022-05-23 12:05:42 +02:00
return EXECUTION_FINISHED;
}
2022-08-22 13:50:24 +02:00
case MEMORY_CHECK_WITH_FILE: {
2022-11-21 18:32:23 +01:00
shutdownCmdSent = false;
2022-08-22 13:50:24 +02:00
UpdateParams params;
2023-02-17 12:19:53 +01:00
result = extractBaseParams(&data, size, params);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-22 12:08:39 +02:00
return result;
}
2022-08-22 13:50:24 +02:00
if (not std::filesystem::exists(params.file)) {
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
2022-08-22 12:08:39 +02:00
}
2022-11-15 17:41:15 +01:00
uartManager.performMemCheck(params.file, params.memId, params.startAddr);
2022-08-22 12:08:39 +02:00
return EXECUTION_FINISHED;
}
2022-04-10 18:46:39 +02:00
default:
break;
}
return DeviceHandlerBase::executeAction(actionId, commandedBy, data, size);
}
2022-03-27 13:07:18 +02:00
void PlocSupervisorHandler::doStartUp() {
2022-12-23 11:46:01 +01:00
if (startupState == StartupState::OFF) {
bootTimeout.resetTimer();
startupState = StartupState::BOOTING;
}
if (startupState == StartupState::BOOTING) {
if (bootTimeout.hasTimedOut()) {
uartIsolatorSwitch.pullHigh();
uartManager.start();
if (SET_TIME_DURING_BOOT) {
2022-11-18 16:13:55 +01:00
startupState = StartupState::SET_TIME;
2022-12-23 11:46:01 +01:00
} else {
startupState = StartupState::ON;
2022-06-17 08:31:36 +02:00
}
2022-11-18 16:13:55 +01:00
}
2022-12-23 11:46:01 +01:00
}
2023-05-12 09:32:24 +02:00
if (startupState == StartupState::TIME_WAS_SET) {
2022-12-23 11:46:01 +01:00
startupState = StartupState::ON;
}
if (startupState == StartupState::ON) {
2023-08-15 13:49:06 +02:00
hkset.setReportingEnabled(true);
supv::SUPV_ON = true;
2022-06-17 08:31:36 +02:00
setMode(_MODE_TO_ON);
2022-05-03 14:59:23 +02:00
}
}
2022-03-28 09:08:11 +02:00
void PlocSupervisorHandler::doShutDown() {
2022-03-28 13:54:46 +02:00
setMode(_MODE_POWER_DOWN);
2023-08-15 13:49:06 +02:00
hkset.setReportingEnabled(false);
hkset.setValidity(false, true);
2022-12-23 11:46:01 +01:00
shutdownCmdSent = false;
packetInBuffer = false;
nextReplyId = supv::NONE;
2022-11-15 17:41:15 +01:00
uartManager.stop();
2022-03-28 13:54:46 +02:00
uartIsolatorSwitch.pullLow();
2023-11-08 18:43:11 +01:00
disableAllReplies();
supv::SUPV_ON = false;
2022-05-03 14:59:23 +02:00
startupState = StartupState::OFF;
2022-03-28 09:08:11 +02:00
}
2022-03-27 13:07:18 +02:00
ReturnValue_t PlocSupervisorHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
2023-11-08 18:19:24 +01:00
if (not normalCommandIsPending) {
2023-08-15 13:49:06 +02:00
*id = GET_HK_REPORT;
2023-11-08 18:19:24 +01:00
normalCommandIsPending = true;
normalCmdCd.resetTimer();
2023-08-15 14:34:10 +02:00
return buildCommandFromCommand(*id, nullptr, 0);
2023-08-15 13:49:06 +02:00
}
2022-03-27 13:07:18 +02:00
return NOTHING_TO_SEND;
}
2022-03-27 13:07:18 +02:00
ReturnValue_t PlocSupervisorHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
2022-05-03 14:59:23 +02:00
if (startupState == StartupState::SET_TIME) {
*id = supv::SET_TIME_REF;
2023-05-12 09:32:24 +02:00
startupState = StartupState::WAIT_FOR_TIME_REPLY;
return buildCommandFromCommand(*id, nullptr, 0);
2022-05-03 14:59:23 +02:00
}
2022-03-27 13:07:18 +02:00
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) {
2022-04-13 11:56:37 +02:00
using namespace supv;
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::FAILED;
spParams.buf = commandBuffer;
2022-03-27 13:07:18 +02:00
switch (deviceCommand) {
2022-04-13 11:56:37 +02:00
case GET_HK_REPORT: {
2022-11-08 14:26:52 +01:00
prepareEmptyCmd(Apid::HK, static_cast<uint8_t>(tc::HkId::GET_REPORT));
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case START_MPSOC: {
sif::info << "PLOC SUPV: Starting MPSoC" << std::endl;
2022-11-08 14:26:52 +01:00
prepareEmptyCmd(Apid::BOOT_MAN, static_cast<uint8_t>(tc::BootManId::START_MPSOC));
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case SHUTDOWN_MPSOC: {
sif::info << "PLOC SUPV: Shutting down MPSoC" << std::endl;
2022-11-08 14:26:52 +01:00
prepareEmptyCmd(Apid::BOOT_MAN, static_cast<uint8_t>(tc::BootManId::SHUTDOWN_MPSOC));
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case SEL_MPSOC_BOOT_IMAGE: {
2022-03-27 13:07:18 +02:00
prepareSelBootImageCmd(commandData);
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case RESET_MPSOC: {
2023-10-26 11:19:21 +02:00
sif::info << "PLOC SUPV: Resetting MPSoC" << std::endl;
2022-11-08 14:26:52 +01:00
prepareEmptyCmd(Apid::BOOT_MAN, static_cast<uint8_t>(tc::BootManId::RESET_MPSOC));
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case SET_TIME_REF: {
2022-03-27 13:07:18 +02:00
result = prepareSetTimeRefCmd();
break;
}
2022-04-13 11:56:37 +02:00
case SET_BOOT_TIMEOUT: {
2022-03-27 13:07:18 +02:00
prepareSetBootTimeoutCmd(commandData);
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case SET_MAX_RESTART_TRIES: {
2022-03-27 13:07:18 +02:00
prepareRestartTriesCmd(commandData);
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case DISABLE_PERIOIC_HK_TRANSMISSION: {
2022-03-27 13:07:18 +02:00
prepareDisableHk();
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case GET_BOOT_STATUS_REPORT: {
2022-11-08 14:26:52 +01:00
prepareEmptyCmd(Apid::BOOT_MAN, static_cast<uint8_t>(tc::BootManId::GET_BOOT_STATUS_REPORT));
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case ENABLE_LATCHUP_ALERT: {
2022-03-27 13:07:18 +02:00
result = prepareLatchupConfigCmd(commandData, deviceCommand);
break;
}
2022-04-13 11:56:37 +02:00
case DISABLE_LATCHUP_ALERT: {
2022-03-27 13:07:18 +02:00
result = prepareLatchupConfigCmd(commandData, deviceCommand);
break;
}
2022-04-13 11:56:37 +02:00
case SET_ALERT_LIMIT: {
2022-03-27 13:07:18 +02:00
result = prepareSetAlertLimitCmd(commandData);
break;
}
2022-04-13 11:56:37 +02:00
case GET_LATCHUP_STATUS_REPORT: {
2022-11-08 14:26:52 +01:00
prepareEmptyCmd(Apid::LATCHUP_MON, static_cast<uint8_t>(tc::LatchupMonId::GET_STATUS_REPORT));
2022-08-24 17:27:47 +02:00
result = returnvalue::OK;
2022-04-21 16:30:23 +02:00
break;
}
2022-04-13 11:56:37 +02:00
case RUN_AUTO_EM_TESTS: {
2022-03-27 13:07:18 +02:00
result = prepareRunAutoEmTest(commandData);
break;
}
2022-04-13 11:56:37 +02:00
case SET_GPIO: {
2023-11-08 10:46:59 +01:00
result = prepareSetGpioCmd(commandData, commandDataLen);
2022-03-27 13:07:18 +02:00
break;
}
2022-11-08 20:37:57 +01:00
case FACTORY_RESET: {
result = prepareFactoryResetCmd(commandData, commandDataLen);
break;
}
2022-04-13 11:56:37 +02:00
case READ_GPIO: {
2023-11-08 10:46:59 +01:00
result = prepareReadGpioCmd(commandData, commandDataLen);
2022-03-27 13:07:18 +02:00
break;
}
2022-11-08 20:41:20 +01:00
case SET_SHUTDOWN_TIMEOUT: {
prepareSetShutdownTimeoutCmd(commandData);
result = returnvalue::OK;
break;
}
case FACTORY_FLASH: {
prepareEmptyCmd(Apid::BOOT_MAN, static_cast<uint8_t>(tc::BootManId::FACTORY_FLASH));
result = returnvalue::OK;
break;
}
case RESET_PL: {
prepareEmptyCmd(Apid::BOOT_MAN, static_cast<uint8_t>(tc::BootManId::RESET_PL));
result = returnvalue::OK;
break;
2022-11-09 19:24:48 +01:00
}
case SET_ADC_ENABLED_CHANNELS: {
prepareSetAdcEnabledChannelsCmd(commandData);
result = returnvalue::OK;
break;
}
case SET_ADC_WINDOW_AND_STRIDE: {
prepareSetAdcWindowAndStrideCmd(commandData);
result = returnvalue::OK;
break;
}
case SET_ADC_THRESHOLD: {
prepareSetAdcThresholdCmd(commandData);
result = returnvalue::OK;
break;
2022-11-11 11:06:08 +01:00
}
case WIPE_MRAM: {
result = prepareWipeMramCmd(commandData);
break;
2022-11-08 20:41:20 +01:00
}
2023-11-08 10:46:59 +01:00
case REQUEST_ADC_REPORT: {
prepareEmptyCmd(Apid::ADC_MON, static_cast<uint8_t>(tc::AdcMonId::REQUEST_ADC_SAMPLE));
result = returnvalue::OK;
break;
}
case REQUEST_LOGGING_COUNTERS: {
prepareEmptyCmd(Apid::DATA_LOGGER,
static_cast<uint8_t>(tc::DataLoggerServiceId::REQUEST_COUNTERS));
result = returnvalue::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;
}
2023-11-08 18:19:24 +01:00
commandIsPending = true;
2023-11-08 18:43:11 +01:00
cmdCd.resetTimer();
2022-03-27 13:07:18 +02:00
return result;
}
void PlocSupervisorHandler::fillCommandAndReplyMap() {
2022-11-08 20:04:57 +01:00
// Command only
2022-11-08 19:53:26 +01:00
insertInCommandMap(GET_HK_REPORT);
insertInCommandMap(START_MPSOC);
insertInCommandMap(SHUTDOWN_MPSOC);
2022-11-08 20:04:57 +01:00
insertInCommandMap(SEL_MPSOC_BOOT_IMAGE);
insertInCommandMap(SET_BOOT_TIMEOUT);
insertInCommandMap(SET_MAX_RESTART_TRIES);
insertInCommandMap(RESET_MPSOC);
2022-11-11 11:06:08 +01:00
insertInCommandMap(WIPE_MRAM);
2022-11-08 20:04:57 +01:00
insertInCommandMap(SET_TIME_REF);
insertInCommandMap(DISABLE_PERIOIC_HK_TRANSMISSION);
insertInCommandMap(GET_BOOT_STATUS_REPORT);
insertInCommandMap(ENABLE_LATCHUP_ALERT);
insertInCommandMap(DISABLE_LATCHUP_ALERT);
insertInCommandMap(SET_ALERT_LIMIT);
insertInCommandMap(GET_LATCHUP_STATUS_REPORT);
insertInCommandMap(RUN_AUTO_EM_TESTS);
insertInCommandMap(SET_GPIO);
insertInCommandMap(READ_GPIO);
2022-11-08 20:37:57 +01:00
insertInCommandMap(FACTORY_RESET);
2022-11-28 16:24:18 +01:00
insertInCommandMap(MEMORY_CHECK);
2022-11-08 20:04:57 +01:00
insertInCommandMap(SET_SHUTDOWN_TIMEOUT);
insertInCommandMap(FACTORY_FLASH);
2022-11-11 11:06:08 +01:00
insertInCommandMap(SET_ADC_ENABLED_CHANNELS);
insertInCommandMap(SET_ADC_THRESHOLD);
insertInCommandMap(SET_ADC_WINDOW_AND_STRIDE);
2022-11-08 20:04:57 +01:00
insertInCommandMap(RESET_PL);
2023-11-08 10:46:59 +01:00
insertInCommandMap(REQUEST_ADC_REPORT);
insertInCommandMap(REQUEST_LOGGING_COUNTERS);
2022-11-08 20:04:57 +01:00
// ACK replies, use countdown for them
2022-11-08 20:37:57 +01:00
insertInReplyMap(ACK_REPORT, 0, nullptr, SIZE_ACK_REPORT, false, &acknowledgementReportTimeout);
2022-11-08 20:04:57 +01:00
insertInReplyMap(EXE_REPORT, 0, nullptr, SIZE_EXE_REPORT, false, &executionReportTimeout);
2022-11-28 16:24:18 +01:00
insertInReplyMap(MEMORY_CHECK, 5, nullptr, 0, false);
2022-11-08 20:04:57 +01:00
// TM replies
2023-08-15 14:43:23 +02:00
insertInReplyMap(HK_REPORT, 3, &hkset);
2022-11-08 20:04:57 +01:00
insertInReplyMap(BOOT_STATUS_REPORT, 3, &bootStatusReport, SIZE_BOOT_STATUS_REPORT);
insertInReplyMap(LATCHUP_REPORT, 3, &latchupStatusReport, SIZE_LATCHUP_STATUS_REPORT);
2023-11-08 10:46:59 +01:00
insertInReplyMap(COUNTERS_REPORT, 3, &countersReport, SIZE_COUNTERS_REPORT);
2022-11-08 20:04:57 +01:00
insertInReplyMap(ADC_REPORT, 3, &adcReport, SIZE_ADC_REPORT);
2022-04-13 11:56:37 +02:00
}
ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
uint8_t expectedReplies,
bool useAlternateId,
DeviceCommandId_t alternateReplyID) {
2022-11-08 19:53:26 +01:00
ReturnValue_t result = OK;
2022-04-13 11:56:37 +02:00
uint8_t enabledReplies = 0;
switch (command->first) {
2022-04-21 16:30:23 +02:00
case GET_HK_REPORT: {
2022-04-13 11:56:37 +02:00
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, HK_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << HK_REPORT
<< " not in replyMap" << std::endl;
2022-04-13 11:56:37 +02:00
}
break;
}
2022-04-21 16:30:23 +02:00
case GET_BOOT_STATUS_REPORT: {
2022-04-13 11:56:37 +02:00
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
2022-04-21 16:30:23 +02:00
BOOT_STATUS_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-13 11:56:37 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-04-21 16:30:23 +02:00
<< BOOT_STATUS_REPORT << " not in replyMap" << std::endl;
2022-04-13 11:56:37 +02:00
}
break;
}
2022-04-21 16:30:23 +02:00
case GET_LATCHUP_STATUS_REPORT: {
2022-04-13 11:56:37 +02:00
enabledReplies = 3;
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, LATCHUP_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-13 11:56:37 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-04-21 16:30:23 +02:00
<< LATCHUP_REPORT << " not in replyMap" << std::endl;
2022-04-13 11:56:37 +02:00
}
break;
}
2023-11-08 10:46:59 +01:00
case REQUEST_LOGGING_COUNTERS: {
2022-04-13 11:56:37 +02:00
enabledReplies = 3;
result =
2023-11-08 10:46:59 +01:00
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, COUNTERS_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-13 11:56:37 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2023-11-08 10:46:59 +01:00
<< COUNTERS_REPORT << " not in replyMap" << std::endl;
2022-04-13 11:56:37 +02:00
}
break;
}
2022-04-21 16:30:23 +02:00
case REQUEST_ADC_REPORT: {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, ADC_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << ADC_REPORT
<< " not in replyMap" << std::endl;
2022-04-21 16:30:23 +02:00
}
break;
}
case FIRST_MRAM_DUMP: {
2022-04-13 11:56:37 +02:00
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, FIRST_MRAM_DUMP);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-13 11:56:37 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-04-21 16:30:23 +02:00
<< FIRST_MRAM_DUMP << " not in replyMap" << std::endl;
2022-04-13 11:56:37 +02:00
}
break;
}
2022-04-21 16:30:23 +02:00
case CONSECUTIVE_MRAM_DUMP: {
2022-04-13 11:56:37 +02:00
enabledReplies = 2; // expected replies will be increased in handleMramDumpPacket
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true,
2022-04-21 16:30:23 +02:00
CONSECUTIVE_MRAM_DUMP);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-13 11:56:37 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
2022-04-21 16:30:23 +02:00
<< CONSECUTIVE_MRAM_DUMP << " not in replyMap" << std::endl;
2022-04-13 11:56:37 +02:00
}
break;
}
2022-11-28 16:24:18 +01:00
case MEMORY_CHECK: {
enabledReplies = 3;
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, MEMORY_CHECK);
if (result != returnvalue::OK) {
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << MEMORY_CHECK
<< " not in replyMap" << std::endl;
}
break;
}
2022-04-21 16:30:23 +02:00
case START_MPSOC:
case SHUTDOWN_MPSOC:
case SEL_MPSOC_BOOT_IMAGE:
case SET_BOOT_TIMEOUT:
case SET_MAX_RESTART_TRIES:
case RESET_MPSOC:
case SET_TIME_REF:
case ENABLE_LATCHUP_ALERT:
case DISABLE_LATCHUP_ALERT:
case SET_ALERT_LIMIT:
case SET_ADC_ENABLED_CHANNELS:
case SET_ADC_WINDOW_AND_STRIDE:
case SET_ADC_THRESHOLD:
case RUN_AUTO_EM_TESTS:
2022-11-10 13:50:18 +01:00
case WIPE_MRAM:
2022-04-21 16:30:23 +02:00
case SET_GPIO:
2022-11-08 20:37:57 +01:00
case FACTORY_RESET:
2022-04-21 16:30:23 +02:00
case READ_GPIO:
case DISABLE_PERIOIC_HK_TRANSMISSION:
case SET_SHUTDOWN_TIMEOUT:
case FACTORY_FLASH:
case ENABLE_AUTO_TM:
case DISABLE_AUTO_TM:
2022-04-28 11:27:28 +02:00
case RESET_PL:
2022-04-13 11:56:37 +02:00
enabledReplies = 2;
break;
default:
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Unknown command id" << std::endl;
break;
}
/**
* Every command causes at least one acknowledgment and one execution report. Therefore both
* replies will be enabled here.
*/
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, ACK_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-21 16:30:23 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << ACK_REPORT
2022-04-13 11:56:37 +02:00
<< " not in replyMap" << std::endl;
}
2022-05-23 12:05:42 +02:00
setExecutionTimeout(command->first);
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, EXE_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-21 16:30:23 +02:00
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << EXE_REPORT
2022-04-13 11:56:37 +02:00
<< " not in replyMap" << std::endl;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
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-04-14 07:52:21 +02:00
using namespace supv;
2022-03-27 13:07:18 +02:00
2022-11-08 14:26:52 +01:00
tmReader.setData(start, remainingSize);
2022-11-17 13:24:39 +01:00
uint16_t apid = tmReader.getModuleApid();
if (DEBUG_PLOC_SUPV) {
handlePacketPrint();
2023-10-26 11:19:21 +02:00
}
2022-03-27 13:07:18 +02:00
switch (apid) {
2022-11-08 14:26:52 +01:00
case (Apid::TMTC_MAN): {
switch (tmReader.getServiceId()) {
case (static_cast<uint8_t>(supv::tm::TmtcId::ACK)):
case (static_cast<uint8_t>(supv::tm::TmtcId::NAK)): {
2022-11-08 19:53:26 +01:00
*foundLen = tmReader.getFullPacketLen();
*foundId = ReplyId::ACK_REPORT;
2022-11-08 14:26:52 +01:00
return OK;
}
case (static_cast<uint8_t>(supv::tm::TmtcId::EXEC_ACK)):
case (static_cast<uint8_t>(supv::tm::TmtcId::EXEC_NAK)): {
2022-11-08 19:53:26 +01:00
*foundLen = tmReader.getFullPacketLen();
2022-11-08 14:26:52 +01:00
*foundId = EXE_REPORT;
return OK;
}
}
2022-04-21 16:30:23 +02:00
break;
2022-11-08 14:26:52 +01:00
}
case (Apid::HK): {
if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::HkId::REPORT)) {
2023-11-08 18:19:24 +01:00
normalCommandIsPending = false;
// Yeah apparently this is needed??
disableCommand(GET_HK_REPORT);
2022-11-08 19:53:26 +01:00
*foundLen = tmReader.getFullPacketLen();
*foundId = ReplyId::HK_REPORT;
2022-11-08 14:26:52 +01:00
return OK;
} else if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::HkId::HARDFAULTS)) {
handleBadApidServiceCombination(SUPV_UNINIMPLEMENTED_TM, apid, tmReader.getServiceId());
return INVALID_DATA;
}
2022-03-27 13:07:18 +02:00
break;
2022-11-08 14:26:52 +01:00
}
case (Apid::BOOT_MAN): {
if (tmReader.getServiceId() ==
static_cast<uint8_t>(supv::tm::BootManId::BOOT_STATUS_REPORT)) {
2022-11-08 19:53:26 +01:00
*foundLen = tmReader.getFullPacketLen();
*foundId = ReplyId::BOOT_STATUS_REPORT;
2022-11-08 14:26:52 +01:00
return OK;
}
2022-03-27 13:07:18 +02:00
break;
2022-11-08 14:26:52 +01:00
}
2023-11-08 10:46:59 +01:00
case (Apid::ADC_MON): {
if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::AdcMonId::ADC_REPORT)) {
*foundLen = tmReader.getFullPacketLen();
*foundId = ReplyId::ADC_REPORT;
return OK;
}
break;
}
2022-11-08 14:26:52 +01:00
case (Apid::MEM_MAN): {
if (tmReader.getServiceId() ==
static_cast<uint8_t>(supv::tm::MemManId::UPDATE_STATUS_REPORT)) {
2022-11-08 19:53:26 +01:00
*foundLen = tmReader.getFullPacketLen();
*foundId = ReplyId::UPDATE_STATUS_REPORT;
2022-11-28 16:24:18 +01:00
return OK;
2022-11-08 14:26:52 +01:00
}
2023-11-08 10:46:59 +01:00
break;
}
case (Apid::DATA_LOGGER): {
if (tmReader.getServiceId() ==
static_cast<uint8_t>(supv::tm::DataLoggerId::COUNTERS_REPORT)) {
*foundLen = tmReader.getFullPacketLen();
*foundId = ReplyId::COUNTERS_REPORT;
return OK;
}
2022-03-27 13:07:18 +02:00
}
}
2022-11-08 14:26:52 +01:00
handleBadApidServiceCombination(SUPV_UNKNOWN_TM, apid, tmReader.getServiceId());
*foundLen = remainingSize;
return INVALID_DATA;
}
void PlocSupervisorHandler::handlePacketPrint() {
if (tmReader.getModuleApid() == Apid::TMTC_MAN) {
if ((tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::ACK)) or
(tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::NAK))) {
AcknowledgmentReport ack(tmReader);
2023-11-08 18:19:24 +01:00
ReturnValue_t result = ack.parse();
if (result != returnvalue::OK) {
sif::warning << "PlocSupervisorHandler: Parsing ACK failed" << std::endl;
}
2023-11-08 18:43:11 +01:00
if (REDUCE_NORMAL_MODE_PRINTOUT and ack.getRefModuleApid() == (uint8_t)supv::Apid::HK and
ack.getRefServiceId() == (uint8_t)supv::tc::HkId::GET_REPORT) {
2023-11-08 18:19:24 +01:00
return;
}
const char* printStr = "???";
if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::ACK)) {
printStr = "ACK";
} else if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::NAK)) {
printStr = "NAK";
}
sif::debug << "PlocSupervisorHandler: RECV " << printStr << " for APID Module ID "
<< (int)ack.getRefModuleApid() << " Service ID " << (int)ack.getRefServiceId()
<< " Seq Count " << ack.getRefSequenceCount() << std::endl;
return;
} else if ((tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_ACK)) or
(tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_NAK))) {
ExecutionReport exe(tmReader);
2023-11-08 18:19:24 +01:00
ReturnValue_t result = exe.parse();
if (result != returnvalue::OK) {
sif::warning << "PlocSupervisorHandler: Parsing EXE failed" << std::endl;
}
const char* printStr = "???";
2023-11-08 18:43:11 +01:00
if (REDUCE_NORMAL_MODE_PRINTOUT and exe.getRefModuleApid() == (uint8_t)supv::Apid::HK and
exe.getRefServiceId() == (uint8_t)supv::tc::HkId::GET_REPORT) {
2023-11-08 18:19:24 +01:00
return;
}
if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_ACK)) {
printStr = "ACK EXE";
} else if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_NAK)) {
printStr = "NAK EXE";
}
sif::debug << "PlocSupervisorHandler: RECV " << printStr << " for APID Module ID "
<< (int)exe.getRefModuleApid() << " Service ID " << (int)exe.getRefServiceId()
<< " Seq Count " << exe.getRefSequenceCount() << std::endl;
return;
}
}
sif::debug << "PlocSupervisorHandler: RECV PACKET Size " << tmReader.getFullPacketLen()
<< " Module APID " << (int)tmReader.getModuleApid() << " Service ID "
<< (int)tmReader.getServiceId() << std::endl;
}
ReturnValue_t PlocSupervisorHandler::interpretDeviceReply(DeviceCommandId_t id,
2022-03-27 13:07:18 +02:00
const uint8_t* packet) {
2022-04-21 16:30:23 +02:00
using namespace supv;
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
switch (id) {
2022-04-21 16:30:23 +02:00
case ACK_REPORT: {
2022-03-27 13:07:18 +02:00
result = handleAckReport(packet);
break;
}
2022-04-21 16:30:23 +02:00
case (HK_REPORT): {
2022-03-27 13:07:18 +02:00
result = handleHkReport(packet);
break;
}
2022-04-21 16:30:23 +02:00
case (BOOT_STATUS_REPORT): {
2022-03-27 13:07:18 +02:00
result = handleBootStatusReport(packet);
break;
2021-07-24 13:57:05 +02:00
}
2023-11-08 10:46:59 +01:00
case (COUNTERS_REPORT): {
result = genericHandleTm("COUNTERS", packet, countersReport);
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
countersReport.printSet();
#endif
break;
}
2022-04-21 16:30:23 +02:00
case (LATCHUP_REPORT): {
2022-03-27 13:07:18 +02:00
result = handleLatchupStatusReport(packet);
break;
2021-07-28 11:08:40 +02:00
}
2022-04-21 16:30:23 +02:00
case (ADC_REPORT): {
2023-11-08 10:46:59 +01:00
result = genericHandleTm("ADC", packet, adcReport);
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
adcReport.printSet();
#endif
2022-04-21 16:30:23 +02:00
break;
}
case (EXE_REPORT): {
2022-03-27 13:07:18 +02:00
result = handleExecutionReport(packet);
break;
}
2022-11-28 16:24:18 +01:00
case (UPDATE_STATUS_REPORT): {
// TODO: handle status report here
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;
}
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}));
2022-04-11 16:52:50 +02:00
localDataPoolMap.emplace(supv::HK_SOC_STATE, new PoolEntry<uint32_t>({0}));
2022-03-30 09:19:30 +02:00
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}));
2023-02-12 20:01:20 +01:00
localDataPoolMap.emplace(supv::FMC_STATE, &fmcStateEntry);
2022-03-30 09:19:30 +02:00
localDataPoolMap.emplace(supv::NUM_TCS, new PoolEntry<uint32_t>({0}));
2023-02-12 20:01:20 +01:00
localDataPoolMap.emplace(supv::TEMP_SUP, &tempSupEntry);
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}));
2022-04-11 16:52:50 +02:00
localDataPoolMap.emplace(supv::BR_SOC_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(supv::POWER_CYCLES, new PoolEntry<uint8_t>({0}));
2022-03-30 09:19:30 +02:00
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}));
2023-02-12 20:01:20 +01:00
localDataPoolMap.emplace(supv::BOOT_STATE, &bootStateEntry);
localDataPoolMap.emplace(supv::BOOT_CYCLES, &bootCyclesEntry);
2022-03-30 09:19:30 +02:00
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-04-11 16:52:50 +02:00
localDataPoolMap.emplace(supv::LATCHUP_RPT_IS_SET, new PoolEntry<uint8_t>({0}));
2022-03-27 13:07:18 +02:00
2023-11-08 10:46:59 +01:00
localDataPoolMap.emplace(supv::SIGNATURE, new PoolEntry<uint32_t>());
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNTS, &latchupCounters);
2022-04-22 08:55:57 +02:00
localDataPoolMap.emplace(supv::ADC_DEVIATION_TRIGGERS_CNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TC_RECEIVED_CNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TM_AVAILABLE_CNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::SUPERVISOR_BOOTS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_BOOTS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_BOOT_FAILED_ATTEMPTS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_POWER_UP, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MPSOC_UPDATES, new PoolEntry<uint32_t>({0}));
2023-11-08 10:46:59 +01:00
localDataPoolMap.emplace(supv::MPSOC_HEARTBEAT_RESETS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::CPU_WDT_RESETS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::PS_HEARTBEATS_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::PL_HEARTBEATS_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::EB_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::BM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::LM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::AM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::TCTMM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::MM_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::HK_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::DL_TASK_LOST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(supv::RWS_TASKS_LOST, new PoolEntry<uint32_t>(3));
localDataPoolMap.emplace(supv::ADC_RAW, &adcRawEntry);
localDataPoolMap.emplace(supv::ADC_ENG, &adcEngEntry);
2022-04-21 16:30:23 +02:00
2023-08-15 13:49:06 +02:00
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(hkset.getSid(), false, 10.0));
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2022-04-10 18:46:39 +02:00
void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-04-10 18:46:39 +02:00
object_id_t objectId = eventMessage->getReporter();
Event event = eventMessage->getEvent();
2022-04-10 18:46:39 +02:00
switch (objectId) {
case objects::PLOC_SUPERVISOR_HELPER: {
// After execution of update procedure, PLOC is in a state where it draws approx. 700 mA of
// current. To leave this state the shutdown MPSoC command must be sent here.
2022-11-15 17:24:38 +01:00
if (event == PlocSupvUartManager::SUPV_UPDATE_FAILED ||
event == PlocSupvUartManager::SUPV_UPDATE_SUCCESSFUL ||
event == PlocSupvUartManager::SUPV_CONTINUE_UPDATE_FAILED ||
event == PlocSupvUartManager::SUPV_CONTINUE_UPDATE_SUCCESSFUL ||
event == PlocSupvUartManager::SUPV_MEM_CHECK_FAIL ||
event == PlocSupvUartManager::SUPV_MEM_CHECK_OK) {
2022-11-21 18:32:23 +01:00
// Wait for a short period for the uart state machine to adjust
// TaskFactory::delayTask(5);
if (not shutdownCmdSent) {
shutdownCmdSent = true;
result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0);
if (result != returnvalue::OK) {
triggerEvent(SUPV_MPSOC_SHUTDOWN_BUILD_FAILED);
sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown "
"command"
<< std::endl;
return;
}
}
}
2022-04-10 18:46:39 +02:00
break;
}
default:
sif::debug << "PlocMPSoCHandler::handleEvent: Did not subscribe to this event" << std::endl;
break;
}
}
2022-04-27 16:08:17 +02:00
void PlocSupervisorHandler::setExecutionTimeout(DeviceCommandId_t command) {
using namespace supv;
switch (command) {
case FIRST_MRAM_DUMP:
case CONSECUTIVE_MRAM_DUMP:
2022-05-23 12:05:42 +02:00
executionReportTimeout.setTimeout(MRAM_DUMP_EXECUTION_TIMEOUT);
break;
case COPY_ADC_DATA_TO_MRAM:
2022-05-23 12:05:42 +02:00
executionReportTimeout.setTimeout(COPY_ADC_TO_MRAM_TIMEOUT);
break;
default:
2022-05-23 12:05:42 +02:00
executionReportTimeout.setTimeout(EXECUTION_DEFAULT_TIMEOUT);
break;
2022-04-27 16:08:17 +02:00
}
}
ReturnValue_t PlocSupervisorHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
2022-08-18 15:34:26 +02:00
if (CRC::crc16ccitt(start, foundLen) != 0) {
return result::CRC_FAILURE;
2022-03-27 13:07:18 +02:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) {
using namespace supv;
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-11-17 13:39:59 +01:00
if (not tmReader.verifyCrc()) {
2022-11-08 17:07:12 +01:00
sif::error << "PlocSupervisorHandler::handleAckReport: CRC failure" << std::endl;
nextReplyId = supv::NONE;
replyRawReplyIfnotWiretapped(data, supv::SIZE_ACK_REPORT);
triggerEvent(SUPV_CRC_FAILURE_EVENT);
sendFailureReport(supv::ACK_REPORT, result::CRC_FAILURE);
disableAllReplies();
return returnvalue::OK;
2022-11-08 16:56:42 +01:00
}
AcknowledgmentReport ack(tmReader);
result = ack.parse();
if (result != returnvalue::OK) {
2022-11-08 17:07:12 +01:00
nextReplyId = supv::NONE;
replyRawReplyIfnotWiretapped(data, supv::SIZE_ACK_REPORT);
triggerEvent(SUPV_CRC_FAILURE_EVENT);
sendFailureReport(supv::ACK_REPORT, result);
disableAllReplies();
return result;
}
if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::NAK)) {
DeviceCommandId_t commandId = getPendingCommand();
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
triggerEvent(SUPV_ACK_FAILURE, commandId, static_cast<uint32_t>(ack.getStatusCode()));
}
2022-11-17 13:48:40 +01:00
ack.printStatusInformation();
2022-11-08 17:07:12 +01:00
printAckFailureInfo(ack.getStatusCode(), commandId);
sendFailureReport(supv::ACK_REPORT, result::RECEIVED_ACK_FAILURE);
disableAllReplies();
nextReplyId = supv::NONE;
result = IGNORE_REPLY_DATA;
} else if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::ACK)) {
setNextReplyId();
2022-11-08 16:56:42 +01:00
}
2022-03-27 13:07:18 +02:00
return result;
}
ReturnValue_t PlocSupervisorHandler::handleExecutionReport(const uint8_t* data) {
using namespace supv;
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-11-17 13:39:59 +01:00
if (not tmReader.verifyCrc()) {
2022-11-08 19:53:26 +01:00
nextReplyId = supv::NONE;
return result::CRC_FAILURE;
}
ExecutionReport report(tmReader);
result = report.parse();
if (result != OK) {
nextReplyId = supv::NONE;
return result;
}
if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_ACK)) {
result = handleExecutionSuccessReport(report);
} else if (tmReader.getServiceId() == static_cast<uint8_t>(supv::tm::TmtcId::EXEC_NAK)) {
handleExecutionFailureReport(report);
}
2023-11-08 18:43:11 +01:00
commandIsPending = false;
2022-11-08 19:53:26 +01:00
nextReplyId = supv::NONE;
return result;
}
ReturnValue_t PlocSupervisorHandler::handleHkReport(const uint8_t* data) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
2023-08-15 14:34:10 +02:00
result = verifyPacket(data, tmReader.getFullPacketLen());
2022-03-27 13:07:18 +02:00
if (result == result::CRC_FAILURE) {
2022-03-27 13:07:18 +02:00
sif::error << "PlocSupervisorHandler::handleHkReport: Hk report has invalid crc" << std::endl;
2022-05-23 12:05:42 +02:00
return result;
2022-03-27 13:07:18 +02:00
}
2022-11-07 10:30:09 +01:00
uint16_t offset = supv::PAYLOAD_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;
2022-08-22 17:10:19 +02:00
hkset.setValidity(true, true);
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-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2021-07-24 13:57:05 +02:00
2022-11-18 14:18:45 +01:00
result = verifyPacket(data, tmReader.getFullPacketLen());
2021-07-24 13:57:05 +02:00
if (result == result::CRC_FAILURE) {
2022-03-27 13:07:18 +02:00
sif::error << "PlocSupervisorHandler::handleBootStatusReport: Boot status report has invalid"
" crc"
<< std::endl;
return result;
}
2022-11-18 14:18:45 +01:00
const uint8_t* payloadStart = tmReader.getPayloadStart();
uint16_t offset = 0;
bootStatusReport.socState = payloadStart[0];
2022-03-27 13:07:18 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
bootStatusReport.powerCycles = payloadStart[1];
2022-03-27 13:07:18 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
bootStatusReport.bootAfterMs = *(payloadStart + offset) << 24 |
*(payloadStart + offset + 1) << 16 |
*(payloadStart + offset + 2) << 8 | *(payloadStart + offset + 3);
2022-03-27 13:07:18 +02:00
offset += 4;
2022-11-18 14:18:45 +01:00
bootStatusReport.bootTimeoutMs = *(payloadStart + offset) << 24 |
*(payloadStart + offset + 1) << 16 |
*(payloadStart + offset + 2) << 8 | *(payloadStart + offset + 3);
2022-03-27 13:07:18 +02:00
offset += 4;
2022-11-18 14:18:45 +01:00
bootStatusReport.activeNvm = *(payloadStart + offset);
2022-03-27 13:07:18 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
bootStatusReport.bp0State = *(payloadStart + offset);
2022-03-27 13:07:18 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
bootStatusReport.bp1State = *(payloadStart + offset);
2022-03-27 13:07:18 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
bootStatusReport.bp2State = *(payloadStart + offset);
2022-04-06 07:10:20 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
bootStatusReport.bootState = *(payloadStart + offset);
2022-04-06 07:10:20 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
bootStatusReport.bootCycles = *(payloadStart + offset);
2022-03-27 13:07:18 +02:00
2022-03-30 09:19:30 +02:00
nextReplyId = supv::EXE_REPORT;
2022-08-22 17:09:39 +02:00
bootStatusReport.setValidity(true, true);
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-05-17 13:40:19 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: SoC State (0 - off, 1 - booting, 2 "
"- Update, 3 "
2022-05-12 10:50:12 +02:00
"- operating, 4 - Shutdown, 5 - Reset): "
2022-04-11 16:52:50 +02:00
<< static_cast<unsigned int>(bootStatusReport.socState.value) << std::endl;
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Power Cycles: "
<< static_cast<unsigned int>(bootStatusReport.powerCycles.value) << std::endl;
2022-03-27 13:07:18 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BootAfterMs: "
<< bootStatusReport.bootAfterMs << " ms" << std::endl;
2022-04-10 18:46:39 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BootTimeoutMs: " << 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: "
2022-04-10 18:46:39 +02:00
<< static_cast<unsigned int>(bootStatusReport.bootState.value) << std::endl;
2022-04-06 17:27:44 +02:00
sif::info << "PlocSupervisorHandler::handleBootStatusReport: Boot cycles: "
2022-04-10 18:46:39 +02:00
<< 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-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-11-18 14:18:45 +01:00
result = verifyPacket(data, tmReader.getFullPacketLen());
if (result == result::CRC_FAILURE) {
2022-03-27 13:07:18 +02:00
sif::error << "PlocSupervisorHandler::handleLatchupStatusReport: Latchup status report has "
<< "invalid crc" << std::endl;
return result;
}
2022-11-18 14:18:45 +01:00
const uint8_t* payloadData = tmReader.getPayloadStart();
uint16_t offset = 0;
latchupStatusReport.id = *(payloadData + offset);
2022-03-27 13:07:18 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
latchupStatusReport.cnt0 = *(payloadData + offset) << 8 | *(payloadData + offset + 1);
2022-03-27 13:07:18 +02:00
offset += 2;
2022-11-18 14:18:45 +01:00
latchupStatusReport.cnt1 = *(payloadData + offset) << 8 | *(payloadData + offset + 1);
2022-03-27 13:07:18 +02:00
offset += 2;
2022-11-18 14:18:45 +01:00
latchupStatusReport.cnt2 = *(payloadData + offset) << 8 | *(payloadData + offset + 1);
2022-03-27 13:07:18 +02:00
offset += 2;
2022-11-18 14:18:45 +01:00
latchupStatusReport.cnt3 = *(payloadData + offset) << 8 | *(payloadData + offset + 1);
2022-03-27 13:07:18 +02:00
offset += 2;
2022-11-18 14:18:45 +01:00
latchupStatusReport.cnt4 = *(payloadData + offset) << 8 | *(payloadData + offset + 1);
2022-03-27 13:07:18 +02:00
offset += 2;
2022-11-18 14:18:45 +01:00
latchupStatusReport.cnt5 = *(payloadData + offset) << 8 | *(payloadData + offset + 1);
2022-03-27 13:07:18 +02:00
offset += 2;
2022-11-18 14:18:45 +01:00
latchupStatusReport.cnt6 = *(payloadData + offset) << 8 | *(data + offset + 1);
2022-03-27 13:07:18 +02:00
offset += 2;
2022-11-18 14:18:45 +01:00
uint16_t msec = *(payloadData + offset) << 8 | *(payloadData + offset + 1);
2022-04-11 16:52:50 +02:00
latchupStatusReport.isSet = msec >> supv::LatchupStatusReport::IS_SET_BIT_POS;
latchupStatusReport.timeMsec = msec & (~(1 << latchupStatusReport.IS_SET_BIT_POS));
2022-04-06 07:10:20 +02:00
offset += 2;
2022-11-18 14:18:45 +01:00
latchupStatusReport.timeSec = *(payloadData + offset);
2022-04-06 07:10:20 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
latchupStatusReport.timeMin = *(payloadData + offset);
2022-04-06 07:10:20 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
latchupStatusReport.timeHour = *(payloadData + offset);
2022-04-06 07:10:20 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
latchupStatusReport.timeDay = *(payloadData + offset);
2022-04-06 07:10:20 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
latchupStatusReport.timeMon = *(payloadData + offset);
2022-04-06 07:10:20 +02:00
offset += 1;
2022-11-18 14:18:45 +01:00
latchupStatusReport.timeYear = *(payloadData + 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-04-11 16:52:50 +02:00
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: isSet: "
<< static_cast<unsigned int>(latchupStatusReport.isSet.value) << std::endl;
#endif
2022-03-27 13:07:18 +02:00
return result;
}
2023-11-08 10:46:59 +01:00
ReturnValue_t PlocSupervisorHandler::genericHandleTm(const char* contextString, const uint8_t* data,
LocalPoolDataSetBase& set) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-04-21 16:30:23 +02:00
2023-11-08 10:46:59 +01:00
result = verifyPacket(data, tmReader.getFullPacketLen());
2022-04-21 16:30:23 +02:00
if (result == result::CRC_FAILURE) {
2023-11-08 10:46:59 +01:00
sif::warning << "PlocSupervisorHandler: " << contextString << " report has "
<< "invalid CRC" << std::endl;
2022-04-21 16:30:23 +02:00
return result;
}
2022-11-07 10:30:09 +01:00
const uint8_t* dataField = data + supv::PAYLOAD_OFFSET;
2023-11-08 10:46:59 +01:00
PoolReadGuard pg(&set);
if (pg.getReadResult() != returnvalue::OK) {
2022-04-21 16:30:23 +02:00
return result;
}
2023-11-08 10:46:59 +01:00
set.setValidityBufferGeneration(false);
size_t size = set.getSerializedSize();
result = set.deSerialize(&dataField, &size, SerializeIF::Endianness::BIG);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2023-11-08 10:46:59 +01:00
sif::warning << "PlocSupervisorHandler: Deserialization failed" << std::endl;
2022-04-21 16:30:23 +02:00
}
2023-11-08 10:46:59 +01:00
set.setValidityBufferGeneration(true);
set.setValidity(true, true);
2022-04-21 16:30:23 +02:00
nextReplyId = supv::EXE_REPORT;
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;
2023-11-08 10:46:59 +01:00
case supv::REQUEST_LOGGING_COUNTERS:
nextReplyId = supv::COUNTERS_REPORT;
2022-04-14 07:52:21 +02:00
break;
2022-04-21 16:30:23 +02:00
case supv::REQUEST_ADC_REPORT:
nextReplyId = supv::ADC_REPORT;
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()) {
2022-04-27 16:08:17 +02:00
if ((iter->second.delayCycles == 0 && iter->second.countdown == nullptr) ||
(not iter->second.active && iter->second.countdown != nullptr)) {
2022-03-27 13:07:18 +02:00
/* 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-11-17 15:48:44 +01:00
void PlocSupervisorHandler::doOffActivity() {}
2022-11-17 15:48:44 +01:00
void PlocSupervisorHandler::handleDeviceTm(const uint8_t* data, size_t dataSize,
2022-03-27 13:07:18 +02:00
DeviceCommandId_t replyId) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::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);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-27 13:07:18 +02:00
sif::debug << "PlocSupervisorHandler::handleDeviceTM: Failed to report data" << std::endl;
}
}
2022-11-07 11:19:10 +01:00
ReturnValue_t PlocSupervisorHandler::prepareEmptyCmd(uint16_t apid, uint8_t serviceId) {
supv::NoPayloadPacket packet(spParams, apid, serviceId);
ReturnValue_t result = packet.buildPacket();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t PlocSupervisorHandler::prepareSelBootImageCmd(const uint8_t* commandData) {
supv::MPSoCBootSelect packet(spParams);
ReturnValue_t result =
2022-11-07 11:26:36 +01:00
packet.buildPacket(commandData[0], commandData[1], commandData[2], commandData[3]);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t PlocSupervisorHandler::prepareSetTimeRefCmd() {
2022-03-27 13:07:18 +02:00
Clock::TimeOfDay_t time;
ReturnValue_t result = Clock::getDateAndTime(&time);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-27 13:07:18 +02:00
sif::warning << "PlocSupervisorHandler::prepareSetTimeRefCmd: Failed to get current time"
<< std::endl;
return result::GET_TIME_FAILURE;
2022-03-27 13:07:18 +02:00
}
supv::SetTimeRef packet(spParams);
result = packet.buildPacket(&time);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t PlocSupervisorHandler::prepareDisableHk() {
supv::DisablePeriodicHkTransmission packet(spParams);
ReturnValue_t result = packet.buildPacket();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-07-22 08:06:04 +02:00
}
ReturnValue_t PlocSupervisorHandler::prepareSetBootTimeoutCmd(const uint8_t* commandData) {
supv::SetBootTimeout packet(spParams);
2022-03-27 13:07:18 +02:00
uint32_t timeout = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 |
*(commandData + 3);
ReturnValue_t result = packet.buildPacket(timeout);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-07-22 08:06:04 +02:00
}
ReturnValue_t PlocSupervisorHandler::prepareRestartTriesCmd(const uint8_t* commandData) {
2022-03-27 13:07:18 +02:00
uint8_t restartTries = *(commandData);
supv::SetRestartTries packet(spParams);
ReturnValue_t result = packet.buildPacket(restartTries);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t PlocSupervisorHandler::prepareLatchupConfigCmd(const uint8_t* commandData,
2022-03-27 13:07:18 +02:00
DeviceCommandId_t deviceCommand) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
uint8_t latchupId = *commandData;
if (latchupId > 6) {
return result::INVALID_LATCHUP_ID;
2022-03-27 13:07:18 +02:00
}
switch (deviceCommand) {
2022-03-30 09:19:30 +02:00
case (supv::ENABLE_LATCHUP_ALERT): {
supv::LatchupAlert packet(spParams);
result = packet.buildPacket(true, latchupId);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-03-27 13:07:18 +02:00
break;
}
2022-03-30 09:19:30 +02:00
case (supv::DISABLE_LATCHUP_ALERT): {
supv::LatchupAlert packet(spParams);
result = packet.buildPacket(false, latchupId);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-03-27 13:07:18 +02:00
break;
}
default: {
2022-03-27 13:07:18 +02:00
sif::debug << "PlocSupervisorHandler::prepareLatchupConfigCmd: Invalid command id"
<< std::endl;
2022-08-24 17:27:47 +02:00
result = returnvalue::FAILED;
2022-03-27 13:07:18 +02:00
break;
}
2022-03-27 13:07:18 +02:00
}
return result;
}
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 result::INVALID_LATCHUP_ID;
2022-03-27 13:07:18 +02:00
}
supv::SetAlertlimit packet(spParams);
ReturnValue_t result = packet.buildPacket(latchupId, dutycycle);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2022-11-09 19:24:48 +01:00
ReturnValue_t PlocSupervisorHandler::prepareSetAdcEnabledChannelsCmd(const uint8_t* commandData) {
uint16_t ch = *(commandData) << 8 | *(commandData + 1);
supv::SetAdcEnabledChannels packet(spParams);
ReturnValue_t result = packet.buildPacket(ch);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-11-09 19:24:48 +01:00
return returnvalue::OK;
}
ReturnValue_t 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);
supv::SetAdcWindowAndStride packet(spParams);
ReturnValue_t result = packet.buildPacket(windowSize, stridingStepSize);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
ReturnValue_t 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);
supv::SetAdcThreshold packet(spParams);
ReturnValue_t result = packet.buildPacket(threshold);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
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 result::INVALID_TEST_PARAM;
2022-03-27 13:07:18 +02:00
}
supv::RunAutoEmTests packet(spParams);
ReturnValue_t result = packet.buildPacket(test);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-07-28 19:34:10 +02:00
}
2023-11-08 10:46:59 +01:00
ReturnValue_t PlocSupervisorHandler::prepareSetGpioCmd(const uint8_t* commandData,
size_t commandDataLen) {
if (commandDataLen < 3) {
return HasActionsIF::INVALID_PARAMETERS;
}
2022-03-27 13:07:18 +02:00
uint8_t port = *commandData;
uint8_t pin = *(commandData + 1);
uint8_t val = *(commandData + 2);
supv::SetGpio packet(spParams);
ReturnValue_t result = packet.buildPacket(port, pin, val);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-08-02 15:28:57 +02:00
}
2023-11-08 10:46:59 +01:00
ReturnValue_t PlocSupervisorHandler::prepareReadGpioCmd(const uint8_t* commandData,
size_t commandDataLen) {
if (commandDataLen < 2) {
return HasActionsIF::INVALID_PARAMETERS;
}
2022-03-27 13:07:18 +02:00
uint8_t port = *commandData;
uint8_t pin = *(commandData + 1);
supv::ReadGpio packet(spParams);
ReturnValue_t result = packet.buildPacket(port, pin);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-11-08 20:37:57 +01:00
return returnvalue::OK;
}
ReturnValue_t PlocSupervisorHandler::prepareFactoryResetCmd(const uint8_t* commandData,
size_t len) {
FactoryReset resetCmd(spParams);
2022-12-23 10:13:26 +01:00
if (len < 1) {
2022-12-23 10:32:21 +01:00
return HasActionsIF::INVALID_PARAMETERS;
2022-11-08 20:37:57 +01:00
}
2022-12-23 10:13:26 +01:00
ReturnValue_t result = resetCmd.buildPacket(commandData[0]);
2022-11-08 20:37:57 +01:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(resetCmd);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-08-02 15:28:57 +02:00
}
void PlocSupervisorHandler::finishTcPrep(TcBase& tc) {
2022-08-18 15:11:32 +02:00
nextReplyId = supv::ACK_REPORT;
rawPacket = commandBuffer;
rawPacketLen = tc.getFullPacketLen();
if (DEBUG_PLOC_SUPV) {
sif::debug << "PLOC SUPV: SEND PACKET Size " << tc.getFullPacketLen() << " Module APID "
<< (int)tc.getModuleApid() << " Service ID " << (int)tc.getServiceId() << std::endl;
}
2022-08-18 15:11:32 +02:00
}
ReturnValue_t PlocSupervisorHandler::prepareSetShutdownTimeoutCmd(const uint8_t* commandData) {
2022-04-06 07:10:20 +02:00
uint32_t timeout = 0;
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-04-06 07:10:20 +02:00
size_t size = sizeof(timeout);
result =
SerializeAdapter::deSerialize(&timeout, &commandData, &size, SerializeIF::Endianness::BIG);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-06 07:10:20 +02:00
sif::warning
<< "PlocSupervisorHandler::prepareSetShutdownTimeoutCmd: Failed to deserialize timeout"
<< std::endl;
2023-11-09 17:19:28 +01:00
return result;
2022-04-06 07:10:20 +02:00
}
supv::SetShutdownTimeout packet(spParams);
result = packet.buildPacket(timeout);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-04-06 07:10:20 +02:00
}
void PlocSupervisorHandler::disableAllReplies() {
using namespace supv;
2022-03-27 13:07:18 +02:00
DeviceReplyMap::iterator iter;
2022-03-27 13:07:18 +02:00
/* Disable ack reply */
iter = deviceReplyMap.find(ACK_REPORT);
2023-09-25 18:07:28 +02:00
if (iter == deviceReplyMap.end()) {
return;
}
2022-03-27 13:07:18 +02:00
DeviceReplyInfo* info = &(iter->second);
2023-09-25 18:07:28 +02:00
if (info == nullptr) {
return;
}
2022-03-27 13:07:18 +02:00
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) {
case GET_HK_REPORT: {
disableReply(GET_HK_REPORT);
2022-05-05 08:55:45 +02:00
break;
}
case FIRST_MRAM_DUMP:
case CONSECUTIVE_MRAM_DUMP: {
disableReply(commandId);
break;
}
case REQUEST_ADC_REPORT: {
disableReply(ADC_REPORT);
break;
}
case GET_BOOT_STATUS_REPORT: {
disableReply(BOOT_STATUS_REPORT);
break;
}
case GET_LATCHUP_STATUS_REPORT: {
disableReply(LATCHUP_REPORT);
break;
}
2023-11-08 10:46:59 +01:00
case REQUEST_LOGGING_COUNTERS: {
disableReply(COUNTERS_REPORT);
2022-03-27 13:07:18 +02:00
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::disableReply(DeviceCommandId_t replyId) {
DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId);
2023-11-08 18:49:57 +01:00
if (iter == deviceReplyMap.end()) {
return;
}
DeviceReplyInfo* info = &(iter->second);
info->delayCycles = 0;
info->active = false;
info->command = deviceCommandMap.end();
}
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);
2023-11-08 18:49:57 +01:00
if (iter == deviceReplyMap.end()) {
return;
}
2022-03-27 13:07:18 +02:00
DeviceReplyInfo* info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
2022-05-03 14:59:23 +02:00
info->active = false;
2022-03-27 13:07:18 +02:00
/* 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
2021-08-31 11:20:21 +02:00
ReturnValue_t PlocSupervisorHandler::handleMramDumpPacket(DeviceCommandId_t id) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::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-11-04 14:19:58 +01:00
result = verifyPacket(spacePacketBuffer, ccsds::HEADER_LEN + packetLen + 1);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-27 13:07:18 +02:00
sif::warning << "PlocSupervisorHandler::handleMramDumpPacket: CRC failure" << std::endl;
return result;
2021-07-31 08:32:57 +02:00
}
result = handleMramDumpFile(id);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
DeviceCommandMap::iterator iter = deviceCommandMap.find(id);
2023-11-08 18:49:57 +01:00
if (iter != deviceCommandMap.end()) {
actionHelper.finish(false, iter->second.sendReplyTo, id, result);
}
disableAllReplies();
nextReplyId = supv::NONE;
return result;
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);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-27 13:07:18 +02:00
}
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;
if (sequenceFlags != static_cast<uint8_t>(ccsds::SequenceFlags::LAST_SEGMENT) &&
(sequenceFlags != static_cast<uint8_t>(ccsds::SequenceFlags::UNSEGMENTED))) {
2022-03-27 13:07:18 +02:00
// Command expects at least one MRAM packet more and the execution report
info->expectedReplies = 2;
mramReplyInfo->countdown->resetTimer();
2022-03-27 13:07:18 +02:00
} else {
// Command expects the execution report
info->expectedReplies = 1;
mramReplyInfo->active = false;
2022-03-27 13:07:18 +02:00
}
exeReplyInfo->countdown->resetTimer();
2022-03-27 13:07:18 +02:00
return;
2021-08-01 17:11:32 +02:00
}
2021-08-31 11:20:21 +02:00
ReturnValue_t PlocSupervisorHandler::handleMramDumpFile(DeviceCommandId_t id) {
2022-10-25 11:31:06 +02:00
#ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
#endif
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
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>(ccsds::SequenceFlags::FIRST_SEGMENT) ||
(sequenceFlags == static_cast<uint8_t>(ccsds::SequenceFlags::UNSEGMENTED))) {
2022-03-27 13:07:18 +02:00
result = createMramDumpFile();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-27 13:07:18 +02:00
return result;
}
}
}
if (not std::filesystem::exists(activeMramFile)) {
sif::warning << "PlocSupervisorHandler::handleMramDumpFile: MRAM file does not exist"
<< std::endl;
return result::MRAM_FILE_NOT_EXISTS;
2022-03-27 13:07:18 +02:00
}
std::ofstream file(activeMramFile, std::ios_base::app | std::ios_base::out);
2022-11-04 14:19:58 +01:00
file.write(reinterpret_cast<const char*>(spacePacketBuffer + ccsds::HEADER_LEN), packetLen - 1);
2022-03-27 13:07:18 +02:00
file.close();
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-08-08 15:02:59 +02:00
}
2022-11-10 13:50:18 +01:00
ReturnValue_t PlocSupervisorHandler::prepareWipeMramCmd(const uint8_t* commandData) {
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 result::INVALID_MRAM_ADDRESSES;
}
supv::MramCmd packet(spParams);
ReturnValue_t result = packet.buildPacket(start, stop, supv::MramCmd::MramAction::WIPE);
if (result != returnvalue::OK) {
return result;
}
finishTcPrep(packet);
2022-11-10 13:50:18 +01:00
return returnvalue::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-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-27 13:07:18 +02:00
std::string timeStamp;
result = getTimeStampString(timeStamp);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-27 13:07:18 +02:00
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";
#ifdef XIPHOS_Q7S
2023-02-22 18:06:34 +01:00
const char* currentMountPrefix = sdcMan->getCurrentMountPrefix();
#else
2023-02-22 18:06:34 +01:00
const char* currentMountPrefix = "/mnt/sd0";
#endif /* BOARD_TE0720 == 0 */
2023-02-22 18:06:34 +01:00
if (currentMountPrefix == nullptr) {
return returnvalue::FAILED;
}
2021-08-08 15:02:59 +02:00
2022-03-27 13:07:18 +02:00
// Check if path to PLOC directory exists
2023-02-22 18:06:34 +01:00
if (not std::filesystem::exists(std::string(currentMountPrefix) + "/" + supervisorFilePath)) {
2022-05-05 08:55:45 +02:00
sif::warning << "PlocSupervisorHandler::createMramDumpFile: Supervisor path does not exist"
2022-03-27 13:07:18 +02:00
<< std::endl;
return result::PATH_DOES_NOT_EXIST;
2022-03-27 13:07:18 +02:00
}
2023-02-22 18:06:34 +01:00
activeMramFile = std::string(currentMountPrefix) + "/" + supervisorFilePath + "/" + filename;
2022-03-27 13:07:18 +02:00
// Create new file
std::ofstream file(activeMramFile, std::ios_base::out);
file.close();
2022-08-24 17:27:47 +02:00
return returnvalue::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);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::warning << "PlocSupervisorHandler::getTimeStampString: Failed to get current time"
2022-03-27 13:07:18 +02:00
<< std::endl;
return result::GET_TIME_FAILURE;
2022-03-27 13:07:18 +02:00
}
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);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-08-08 15:02:59 +02:00
}
2022-04-10 18:46:39 +02:00
ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* commandData, size_t size,
2022-08-24 12:02:16 +02:00
supv::UpdateParams& params) {
2022-08-22 13:50:24 +02:00
size_t remSize = size;
2022-08-20 22:52:48 +02:00
if (size > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE + sizeof(params.memId)) +
2022-08-24 15:16:46 +02:00
sizeof(params.startAddr) + sizeof(params.bytesWritten) + sizeof(params.seqCount) +
sizeof(uint8_t)) {
2022-04-10 18:46:39 +02:00
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Data size too big" << std::endl;
return result::INVALID_LENGTH;
2022-04-10 18:46:39 +02:00
}
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-08-22 13:50:24 +02:00
result = extractBaseParams(&commandData, size, params);
result = SerializeAdapter::deSerialize(&params.bytesWritten, &commandData, &remSize,
2022-08-20 22:52:48 +02:00
SerializeIF::Endianness::BIG);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-20 22:52:48 +02:00
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize bytes "
"already written"
<< std::endl;
return result;
}
2022-08-22 13:50:24 +02:00
result = SerializeAdapter::deSerialize(&params.seqCount, &commandData, &remSize,
2022-08-20 22:52:48 +02:00
SerializeIF::Endianness::BIG);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-20 22:52:48 +02:00
sif::warning
<< "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize start sequence count"
<< std::endl;
return result;
}
2022-08-24 15:16:46 +02:00
uint8_t delMemRaw = 0;
result = SerializeAdapter::deSerialize(&delMemRaw, &commandData, &remSize,
SerializeIF::Endianness::BIG);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-24 12:02:16 +02:00
sif::warning
<< "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize whether to delete "
2022-08-24 15:16:46 +02:00
"memory"
<< std::endl;
2022-08-24 12:02:16 +02:00
return result;
}
2022-08-24 15:16:46 +02:00
params.deleteMemory = delMemRaw;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-04-10 18:46:39 +02:00
}
2022-08-22 13:50:24 +02:00
ReturnValue_t PlocSupervisorHandler::extractBaseParams(const uint8_t** commandData, size_t& remSize,
2022-08-24 12:02:16 +02:00
supv::UpdateParams& params) {
2022-08-22 13:50:24 +02:00
bool nullTermFound = false;
for (size_t idx = 0; idx < remSize; idx++) {
if ((*commandData)[idx] == '\0') {
nullTermFound = true;
break;
}
}
if (not nullTermFound) {
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-08-22 13:50:24 +02:00
}
params.file = std::string(reinterpret_cast<const char*>(*commandData));
if (params.file.size() > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE)) {
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Filename too long" << std::endl;
return result::FILENAME_TOO_LONG;
2022-08-22 13:50:24 +02:00
}
*commandData += params.file.size() + SIZE_NULL_TERMINATOR;
remSize -= (params.file.size() + SIZE_NULL_TERMINATOR);
params.memId = **commandData;
*commandData += 1;
remSize -= 1;
ReturnValue_t result = SerializeAdapter::deSerialize(&params.startAddr, commandData, &remSize,
SerializeIF::Endianness::BIG);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-22 13:50:24 +02:00
sif::warning << "PlocSupervisorHandler::extractBaseParams: Failed to deserialize start address"
<< std::endl;
return result;
}
return result;
}
2022-04-10 18:46:39 +02:00
ReturnValue_t PlocSupervisorHandler::eventSubscription() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-04-10 18:46:39 +02:00
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
if (manager == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PlocSupervisorHandler::eventSubscritpion: Invalid event manager" << std::endl;
#endif
return ObjectManagerIF::CHILD_INIT_FAILED;
;
}
result = manager->registerListener(eventQueue->getId());
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-10 18:46:39 +02:00
return result;
}
2022-11-15 17:24:38 +01:00
result = manager->subscribeToEventRange(
eventQueue->getId(), event::getEventId(PlocSupvUartManager::SUPV_UPDATE_FAILED),
event::getEventId(PlocSupvUartManager::SUPV_MEM_CHECK_FAIL));
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-04-10 18:46:39 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "PlocSupervisorHandler::eventSubscritpion: Failed to subscribe to events from "
" ploc supervisor helper"
<< std::endl;
#endif
return ObjectManagerIF::CHILD_INIT_FAILED;
}
return result;
}
2022-04-29 08:34:23 +02:00
2022-11-08 19:53:26 +01:00
ReturnValue_t PlocSupervisorHandler::handleExecutionSuccessReport(ExecutionReport& report) {
2022-04-29 08:34:23 +02:00
DeviceCommandId_t commandId = getPendingCommand();
2023-11-08 18:43:11 +01:00
DeviceCommandMap::iterator iter = deviceCommandMap.find(commandId);
2023-11-08 18:49:57 +01:00
if (iter != deviceCommandMap.end() and iter->second.sendReplyTo != NO_COMMANDER) {
2023-11-08 18:43:11 +01:00
actionHelper.finish(true, iter->second.sendReplyTo, iter->first, returnvalue::OK);
2023-11-08 18:49:57 +01:00
iter->second.isExecuting = false;
2023-11-08 18:43:11 +01:00
}
2023-11-08 18:19:24 +01:00
commandIsPending = false;
switch (commandId) {
case supv::READ_GPIO: {
2022-11-08 11:08:21 +01:00
// TODO: Fix
2022-11-08 20:04:57 +01:00
uint16_t gpioState = report.getStatusCode();
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
sif::info << "PlocSupervisorHandler: Read GPIO TM, State: " << gpioState << std::endl;
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
2023-11-08 18:49:57 +01:00
if (iter != deviceCommandMap.end() and iter->second.sendReplyTo == NO_COMMAND_ID) {
2022-11-08 20:04:57 +01:00
return returnvalue::OK;
}
uint8_t data[sizeof(gpioState)];
size_t size = 0;
2023-11-08 18:43:11 +01:00
ReturnValue_t result = SerializeAdapter::serialize(&gpioState, data, &size, sizeof(gpioState),
SerializeIF::Endianness::BIG);
2022-11-08 20:04:57 +01:00
if (result != returnvalue::OK) {
sif::debug << "PlocSupervisorHandler: Failed to deserialize GPIO state" << std::endl;
}
result = actionHelper.reportData(iter->second.sendReplyTo, commandId, data, sizeof(data));
if (result != returnvalue::OK) {
sif::warning << "PlocSupervisorHandler: Read GPIO, failed to report data" << std::endl;
}
break;
}
2022-05-03 14:59:23 +02:00
case supv::SET_TIME_REF: {
2022-12-23 11:46:01 +01:00
// We could only allow proper bootup when the time was set successfully, but
// this makes debugging difficult.
2023-05-12 09:32:24 +02:00
if (startupState == StartupState::WAIT_FOR_TIME_REPLY) {
startupState = StartupState::TIME_WAS_SET;
}
2022-05-03 14:59:23 +02:00
break;
}
default:
break;
2022-04-29 08:34:23 +02:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-04-29 08:34:23 +02:00
}
2022-05-03 14:59:23 +02:00
2022-11-08 19:53:26 +01:00
void PlocSupervisorHandler::handleExecutionFailureReport(ExecutionReport& report) {
2022-05-03 14:59:23 +02:00
using namespace supv;
DeviceCommandId_t commandId = getPendingCommand();
2022-11-08 19:53:26 +01:00
report.printStatusInformation();
2022-05-03 14:59:23 +02:00
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
2022-11-08 19:53:26 +01:00
triggerEvent(SUPV_EXE_FAILURE, commandId, static_cast<uint32_t>(report.getStatusCode()));
2022-05-03 14:59:23 +02:00
}
sendFailureReport(EXE_REPORT, result::RECEIVED_EXE_FAILURE);
2022-05-03 14:59:23 +02:00
disableExeReportReply();
}
2022-11-08 14:26:52 +01:00
void PlocSupervisorHandler::handleBadApidServiceCombination(Event event, unsigned int apid,
unsigned int serviceId) {
const char* printString = "";
if (event == SUPV_UNKNOWN_TM) {
2022-11-16 13:26:49 +01:00
printString = "PlocSupervisorHandler: Unknown";
2022-11-08 14:26:52 +01:00
} else if (event == SUPV_UNINIMPLEMENTED_TM) {
2022-11-16 13:26:49 +01:00
printString = "PlocSupervisorHandler: Unimplemented";
2022-11-08 14:26:52 +01:00
}
triggerEvent(event, apid, tmReader.getServiceId());
2022-11-16 13:26:49 +01:00
sif::warning << printString << " APID service combination 0x" << std::setw(2) << std::setfill('0')
<< std::hex << apid << ", 0x" << std::setw(2) << serviceId << std::endl;
2022-11-08 14:26:52 +01:00
}
void PlocSupervisorHandler::printAckFailureInfo(uint16_t statusCode, DeviceCommandId_t commandId) {
2022-06-17 08:31:36 +02:00
switch (commandId) {
case (supv::SET_TIME_REF): {
2022-11-17 13:48:40 +01:00
sif::warning
<< "PlocSupervisoHandler: Setting time failed. Make sure the OBC has a valid time"
<< std::endl;
2022-06-17 08:31:36 +02:00
break;
}
default:
break;
}
}
2022-11-08 20:04:57 +01:00
ReturnValue_t PlocSupervisorHandler::getSwitches(const uint8_t** switches,
uint8_t* numberOfSwitches) {
if (powerSwitch == power::NO_SWITCH) {
return DeviceHandlerBase::NO_SWITCH;
}
*numberOfSwitches = 1;
*switches = &powerSwitch;
return returnvalue::OK;
}
uint32_t PlocSupervisorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
return 7000;
}
2022-11-08 20:41:20 +01:00
2023-11-08 18:19:24 +01:00
void PlocSupervisorHandler::disableCommand(DeviceCommandId_t cmd) {
2023-11-08 18:43:11 +01:00
auto commandIter = deviceCommandMap.find(GET_HK_REPORT);
commandIter->second.isExecuting = false;
2023-11-08 18:19:24 +01:00
}
2023-09-29 15:37:47 +02:00
ReturnValue_t PlocSupervisorHandler::checkModeCommand(Mode_t commandedMode,
Submode_t commandedSubmode,
uint32_t* msToReachTheMode) {
if (commandedMode != MODE_OFF) {
PoolReadGuard pg(&enablePl);
if (pg.getReadResult() == returnvalue::OK) {
2023-10-10 11:54:32 +02:00
if (enablePl.plUseAllowed.isValid() and not enablePl.plUseAllowed.value) {
return NON_OP_STATE_OF_CHARGE;
2023-09-29 15:37:47 +02:00
}
}
}
return DeviceHandlerBase::checkModeCommand(commandedMode, commandedSubmode, msToReachTheMode);
}