2021-07-13 08:32:14 +02:00
|
|
|
#include "PlocSupervisorHandler.h"
|
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
|
|
|
|
2021-07-28 08:38:36 +02:00
|
|
|
PlocSupervisorHandler::PlocSupervisorHandler(object_id_t objectId, object_id_t uartComIFid,
|
2022-03-30 09:19:30 +02:00
|
|
|
CookieIF* comCookie, Gpio uartIsolatorSwitch,
|
2022-04-10 18:46:39 +02:00
|
|
|
power::Switch_t powerSwitch,
|
|
|
|
PlocSupvHelper* supvHelper)
|
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),
|
2022-04-13 11:56:37 +02:00
|
|
|
loggingReport(this),
|
2022-04-21 16:30:23 +02:00
|
|
|
adcReport(this),
|
2022-04-10 18:46:39 +02:00
|
|
|
powerSwitch(powerSwitch),
|
|
|
|
supvHelper(supvHelper) {
|
2022-03-27 13:07:18 +02:00
|
|
|
if (comCookie == NULL) {
|
|
|
|
sif::error << "PlocSupervisorHandler: Invalid com cookie" << std::endl;
|
|
|
|
}
|
2022-04-10 18:46:39 +02:00
|
|
|
eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5);
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
PlocSupervisorHandler::~PlocSupervisorHandler() {}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2021-07-23 13:27:58 +02:00
|
|
|
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-04-10 18:46:39 +02:00
|
|
|
#ifndef TE0720_1CFA
|
2022-03-27 13:07:18 +02:00
|
|
|
sdcMan = SdCardManager::instance();
|
2022-04-10 18:46:39 +02:00
|
|
|
#endif /* TE0720_1CFA */
|
|
|
|
if (supvHelper == nullptr) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::initialize: Invalid supervisor helper" << std::endl;
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
result = supvHelper->setComIF(uartComIf);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
supvHelper->setComCookie(comCookie);
|
|
|
|
|
|
|
|
result = eventSubscription();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2022-03-27 13:07:18 +02:00
|
|
|
return result;
|
2021-07-23 13:27:58 +02:00
|
|
|
}
|
|
|
|
|
2022-04-10 18:46:39 +02:00
|
|
|
void PlocSupervisorHandler::performOperationHook() {
|
|
|
|
EventMessage event;
|
|
|
|
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == RETURN_OK;
|
|
|
|
result = eventQueue->receiveMessage(&event)) {
|
|
|
|
switch (event.getMessageId()) {
|
|
|
|
case EventMessage::EVENT_MESSAGE:
|
|
|
|
handleEvent(&event);
|
|
|
|
break;
|
|
|
|
default:
|
2022-04-16 17:19:32 +02:00
|
|
|
sif::debug << "PlocSupervisorHandler::performOperationHook: Did not subscribe to this event"
|
2022-04-10 18:46:39 +02:00
|
|
|
<< " message" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-27 23:09:05 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::executeAction(Action* action) {
|
2022-04-13 11:56:37 +02:00
|
|
|
using namespace supv;
|
2022-04-10 18:46:39 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
2022-07-27 23:09:05 +02:00
|
|
|
//TODO
|
|
|
|
ActionId_t actionId = 0;
|
|
|
|
uint8_t *data = nullptr;
|
|
|
|
size_t size = 0;
|
|
|
|
|
2022-04-10 18:46:39 +02:00
|
|
|
switch (actionId) {
|
2022-04-13 11:56:37 +02:00
|
|
|
case TERMINATE_SUPV_HELPER: {
|
2022-04-10 18:46:39 +02:00
|
|
|
supvHelper->stopProcess();
|
2022-04-19 13:33:37 +02:00
|
|
|
return EXECUTION_FINISHED;
|
2022-04-10 18:46:39 +02:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plocSupvHelperExecuting) {
|
|
|
|
return SupvReturnValuesIF::SUPV_HELPER_EXECUTING;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 SupvReturnValuesIF::FILENAME_TOO_LONG;
|
|
|
|
}
|
|
|
|
std::string file = "";
|
|
|
|
uint8_t memoryId = 0;
|
|
|
|
uint32_t startAddress = 0;
|
|
|
|
result = extractUpdateCommand(data, size, &file, &memoryId, &startAddress);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = supvHelper->startUpdate(file, memoryId, startAddress);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
plocSupvHelperExecuting = true;
|
|
|
|
return EXECUTION_FINISHED;
|
|
|
|
}
|
2022-05-23 12:05:42 +02:00
|
|
|
case CONTINUE_UPDATE: {
|
|
|
|
supvHelper->initiateUpdateContinuation();
|
|
|
|
plocSupvHelperExecuting = true;
|
|
|
|
return EXECUTION_FINISHED;
|
|
|
|
}
|
2022-04-14 07:52:21 +02:00
|
|
|
case LOGGING_REQUEST_EVENT_BUFFERS: {
|
2022-04-13 11:56:37 +02:00
|
|
|
if (size > config::MAX_PATH_SIZE) {
|
|
|
|
return SupvReturnValuesIF::FILENAME_TOO_LONG;
|
|
|
|
}
|
2022-04-14 07:52:21 +02:00
|
|
|
result = supvHelper->startEventbBufferRequest(
|
|
|
|
std::string(reinterpret_cast<const char*>(data), size));
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
plocSupvHelperExecuting = true;
|
|
|
|
return EXECUTION_FINISHED;
|
|
|
|
}
|
2022-04-10 18:46:39 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-07-27 23:09:05 +02:00
|
|
|
return DeviceHandlerBase::executeAction(action);
|
2022-04-10 18:46:39 +02:00
|
|
|
}
|
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
void PlocSupervisorHandler::doStartUp() {
|
2022-06-17 08:31:36 +02:00
|
|
|
if (setTimeDuringStartup) {
|
|
|
|
switch (startupState) {
|
|
|
|
case StartupState::OFF: {
|
|
|
|
bootTimeout.resetTimer();
|
|
|
|
startupState = StartupState::BOOTING;
|
|
|
|
break;
|
2022-05-03 14:59:23 +02:00
|
|
|
}
|
2022-06-17 08:31:36 +02:00
|
|
|
case StartupState::BOOTING: {
|
|
|
|
if (bootTimeout.hasTimedOut()) {
|
|
|
|
uartIsolatorSwitch.pullHigh();
|
|
|
|
startupState = StartupState::SET_TIME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case StartupState::SET_TIME_EXECUTING:
|
|
|
|
break;
|
|
|
|
case StartupState::ON: {
|
|
|
|
setMode(_MODE_TO_ON);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2022-05-03 14:59:23 +02:00
|
|
|
}
|
2022-06-17 08:31:36 +02:00
|
|
|
} else {
|
|
|
|
uartIsolatorSwitch.pullHigh();
|
|
|
|
setMode(_MODE_TO_ON);
|
2022-05-03 14:59:23 +02:00
|
|
|
}
|
2021-07-13 08:32:14 +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);
|
|
|
|
uartIsolatorSwitch.pullLow();
|
2022-05-03 14:59:23 +02:00
|
|
|
startupState = StartupState::OFF;
|
2022-03-28 09:08:11 +02:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
|
|
|
return NOTHING_TO_SEND;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
startupState = StartupState::SET_TIME_EXECUTING;
|
2022-05-06 19:30:20 +02:00
|
|
|
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;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
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-03-27 13:07:18 +02:00
|
|
|
ReturnValue_t result = RETURN_FAILED;
|
|
|
|
switch (deviceCommand) {
|
2022-04-13 11:56:37 +02:00
|
|
|
case GET_HK_REPORT: {
|
|
|
|
prepareEmptyCmd(APID_GET_HK_REPORT);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case START_MPSOC: {
|
|
|
|
prepareEmptyCmd(APID_START_MPSOC);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case SHUTDOWN_MPSOC: {
|
|
|
|
prepareEmptyCmd(APID_SHUTWOWN_MPSOC);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case SEL_MPSOC_BOOT_IMAGE: {
|
2022-03-27 13:07:18 +02:00
|
|
|
prepareSelBootImageCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case RESET_MPSOC: {
|
|
|
|
prepareEmptyCmd(APID_RESET_MPSOC);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
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);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case SET_MAX_RESTART_TRIES: {
|
2022-03-27 13:07:18 +02:00
|
|
|
prepareRestartTriesCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case DISABLE_PERIOIC_HK_TRANSMISSION: {
|
2022-03-27 13:07:18 +02:00
|
|
|
prepareDisableHk();
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case GET_BOOT_STATUS_REPORT: {
|
|
|
|
prepareEmptyCmd(APID_GET_BOOT_STATUS_RPT);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
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 SET_ADC_ENABLED_CHANNELS: {
|
2022-03-27 13:07:18 +02:00
|
|
|
prepareSetAdcEnabledChannelsCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case SET_ADC_WINDOW_AND_STRIDE: {
|
2022-03-27 13:07:18 +02:00
|
|
|
prepareSetAdcWindowAndStrideCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case SET_ADC_THRESHOLD: {
|
2022-03-27 13:07:18 +02:00
|
|
|
prepareSetAdcThresholdCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case GET_LATCHUP_STATUS_REPORT: {
|
|
|
|
prepareEmptyCmd(APID_GET_LATCHUP_STATUS_REPORT);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case COPY_ADC_DATA_TO_MRAM: {
|
|
|
|
prepareEmptyCmd(APID_COPY_ADC_DATA_TO_MRAM);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-21 16:30:23 +02:00
|
|
|
case REQUEST_ADC_REPORT: {
|
|
|
|
prepareEmptyCmd(APID_REQUEST_ADC_REPORT);
|
|
|
|
result = RETURN_OK;
|
|
|
|
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 WIPE_MRAM: {
|
2022-03-27 13:07:18 +02:00
|
|
|
result = prepareWipeMramCmd(commandData);
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case FIRST_MRAM_DUMP:
|
|
|
|
case CONSECUTIVE_MRAM_DUMP:
|
2022-03-27 13:07:18 +02:00
|
|
|
result = prepareDumpMramCmd(commandData);
|
|
|
|
break;
|
2022-04-13 11:56:37 +02:00
|
|
|
case SET_GPIO: {
|
|
|
|
prepareSetGpioCmd(commandData);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case READ_GPIO: {
|
|
|
|
prepareReadGpioCmd(commandData);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case RESTART_SUPERVISOR: {
|
|
|
|
prepareEmptyCmd(APID_RESTART_SUPERVISOR);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case FACTORY_RESET_CLEAR_ALL: {
|
|
|
|
FactoryReset packet(FactoryReset::Op::CLEAR_ALL);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case FACTORY_RESET_CLEAR_MIRROR: {
|
|
|
|
FactoryReset packet(FactoryReset::Op::MIRROR_ENTRIES);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case FACTORY_RESET_CLEAR_CIRCULAR: {
|
|
|
|
FactoryReset packet(FactoryReset::Op::CIRCULAR_ENTRIES);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case START_MPSOC_QUIET: {
|
|
|
|
prepareEmptyCmd(APID_START_MPSOC_QUIET);
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case SET_SHUTDOWN_TIMEOUT: {
|
|
|
|
prepareSetShutdownTimeoutCmd(commandData);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FACTORY_FLASH: {
|
|
|
|
prepareEmptyCmd(APID_FACTORY_FLASH);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ENABLE_AUTO_TM: {
|
|
|
|
EnableAutoTm packet;
|
2022-03-27 13:07:18 +02:00
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case DISABLE_AUTO_TM: {
|
|
|
|
DisableAutoTm packet;
|
2022-03-27 13:07:18 +02:00
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case LOGGING_REQUEST_COUNTERS: {
|
|
|
|
RequestLoggingData packet(RequestLoggingData::Sa::REQUEST_COUNTERS);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2022-04-06 07:10:20 +02:00
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case LOGGING_CLEAR_COUNTERS: {
|
|
|
|
RequestLoggingData packet(RequestLoggingData::Sa::CLEAR_COUNTERS);
|
2022-04-11 16:52:50 +02:00
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-13 11:56:37 +02:00
|
|
|
case LOGGING_SET_TOPIC: {
|
2022-04-14 07:52:21 +02:00
|
|
|
uint8_t tpc = *(commandData);
|
|
|
|
RequestLoggingData packet(RequestLoggingData::Sa::SET_LOGGING_TOPIC, tpc);
|
2022-04-11 16:52:50 +02:00
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-28 11:27:28 +02:00
|
|
|
case RESET_PL: {
|
|
|
|
prepareEmptyCmd(APID_RESET_PL);
|
|
|
|
result = RETURN_OK;
|
|
|
|
break;
|
|
|
|
}
|
2022-05-05 19:18:39 +02:00
|
|
|
case ENABLE_NVMS: {
|
|
|
|
result = prepareEnableNvmsCommand(commandData);
|
|
|
|
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;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::fillCommandAndReplyMap() {
|
2022-04-13 11:56:37 +02:00
|
|
|
using namespace supv;
|
|
|
|
this->insertInCommandMap(GET_HK_REPORT);
|
|
|
|
this->insertInCommandMap(START_MPSOC);
|
|
|
|
this->insertInCommandMap(SHUTDOWN_MPSOC);
|
|
|
|
this->insertInCommandMap(SEL_MPSOC_BOOT_IMAGE);
|
|
|
|
this->insertInCommandMap(SET_BOOT_TIMEOUT);
|
|
|
|
this->insertInCommandMap(SET_MAX_RESTART_TRIES);
|
|
|
|
this->insertInCommandMap(RESET_MPSOC);
|
|
|
|
this->insertInCommandMap(SET_TIME_REF);
|
|
|
|
this->insertInCommandMap(DISABLE_PERIOIC_HK_TRANSMISSION);
|
|
|
|
this->insertInCommandMap(GET_BOOT_STATUS_REPORT);
|
|
|
|
this->insertInCommandMap(ENABLE_LATCHUP_ALERT);
|
|
|
|
this->insertInCommandMap(DISABLE_LATCHUP_ALERT);
|
|
|
|
this->insertInCommandMap(SET_ALERT_LIMIT);
|
|
|
|
this->insertInCommandMap(SET_ADC_ENABLED_CHANNELS);
|
|
|
|
this->insertInCommandMap(SET_ADC_WINDOW_AND_STRIDE);
|
|
|
|
this->insertInCommandMap(SET_ADC_THRESHOLD);
|
|
|
|
this->insertInCommandMap(GET_LATCHUP_STATUS_REPORT);
|
|
|
|
this->insertInCommandMap(COPY_ADC_DATA_TO_MRAM);
|
2022-04-21 16:30:23 +02:00
|
|
|
this->insertInCommandMap(REQUEST_ADC_REPORT);
|
2022-04-13 11:56:37 +02:00
|
|
|
this->insertInCommandMap(RUN_AUTO_EM_TESTS);
|
|
|
|
this->insertInCommandMap(WIPE_MRAM);
|
|
|
|
this->insertInCommandMap(SET_GPIO);
|
|
|
|
this->insertInCommandMap(READ_GPIO);
|
|
|
|
this->insertInCommandMap(RESTART_SUPERVISOR);
|
|
|
|
this->insertInCommandMap(FACTORY_RESET_CLEAR_ALL);
|
|
|
|
this->insertInCommandMap(FACTORY_RESET_CLEAR_MIRROR);
|
|
|
|
this->insertInCommandMap(FACTORY_RESET_CLEAR_CIRCULAR);
|
|
|
|
this->insertInCommandMap(START_MPSOC_QUIET);
|
|
|
|
this->insertInCommandMap(SET_SHUTDOWN_TIMEOUT);
|
|
|
|
this->insertInCommandMap(FACTORY_FLASH);
|
|
|
|
this->insertInCommandMap(ENABLE_AUTO_TM);
|
|
|
|
this->insertInCommandMap(DISABLE_AUTO_TM);
|
|
|
|
this->insertInCommandMap(LOGGING_REQUEST_COUNTERS);
|
2022-04-14 07:52:21 +02:00
|
|
|
this->insertInCommandMap(LOGGING_CLEAR_COUNTERS);
|
|
|
|
this->insertInCommandMap(LOGGING_SET_TOPIC);
|
2022-04-28 11:27:28 +02:00
|
|
|
this->insertInCommandMap(RESET_PL);
|
2022-05-05 19:18:39 +02:00
|
|
|
this->insertInCommandMap(ENABLE_NVMS);
|
2022-05-06 19:30:20 +02:00
|
|
|
this->insertInCommandAndReplyMap(FIRST_MRAM_DUMP, 0, nullptr, 0, false, false, FIRST_MRAM_DUMP,
|
|
|
|
&mramDumpTimeout);
|
|
|
|
this->insertInCommandAndReplyMap(CONSECUTIVE_MRAM_DUMP, 0, nullptr, 0, false, false,
|
|
|
|
CONSECUTIVE_MRAM_DUMP, &mramDumpTimeout);
|
2022-05-23 12:05:42 +02:00
|
|
|
this->insertInReplyMap(ACK_REPORT, 3, nullptr, SIZE_ACK_REPORT, false,
|
|
|
|
&acknowledgementReportTimeout);
|
|
|
|
this->insertInReplyMap(EXE_REPORT, 0, nullptr, SIZE_EXE_REPORT, false, &executionReportTimeout);
|
2022-04-13 11:56:37 +02:00
|
|
|
this->insertInReplyMap(HK_REPORT, 3, &hkset, SIZE_HK_REPORT);
|
|
|
|
this->insertInReplyMap(BOOT_STATUS_REPORT, 3, &bootStatusReport, SIZE_BOOT_STATUS_REPORT);
|
|
|
|
this->insertInReplyMap(LATCHUP_REPORT, 3, &latchupStatusReport, SIZE_LATCHUP_STATUS_REPORT);
|
|
|
|
this->insertInReplyMap(LOGGING_REPORT, 3, &loggingReport, SIZE_LOGGING_REPORT);
|
2022-04-21 16:30:23 +02:00
|
|
|
this->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-04-21 16:30:23 +02:00
|
|
|
using namespace supv;
|
2022-04-13 11:56:37 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
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;
|
2022-04-30 11:08:36 +02:00
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, HK_REPORT);
|
2022-04-13 11:56:37 +02:00
|
|
|
if (result != RETURN_OK) {
|
2022-04-30 11:08:36 +02:00
|
|
|
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-04-13 11:56:37 +02:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
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;
|
2022-04-30 11:08:36 +02:00
|
|
|
result =
|
|
|
|
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, LATCHUP_REPORT);
|
2022-04-13 11:56:37 +02:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
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;
|
|
|
|
}
|
2022-04-21 16:30:23 +02:00
|
|
|
case LOGGING_REQUEST_COUNTERS: {
|
2022-04-13 11:56:37 +02:00
|
|
|
enabledReplies = 3;
|
2022-04-30 11:08:36 +02:00
|
|
|
result =
|
|
|
|
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, LOGGING_REPORT);
|
2022-04-13 11:56:37 +02:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id "
|
2022-04-21 16:30:23 +02:00
|
|
|
<< LOGGING_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;
|
2022-04-30 11:08:36 +02:00
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, ADC_REPORT);
|
2022-04-21 16:30:23 +02:00
|
|
|
if (result != RETURN_OK) {
|
2022-04-30 11:08:36 +02:00
|
|
|
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
|
2022-04-30 11:08:36 +02:00
|
|
|
result =
|
|
|
|
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, FIRST_MRAM_DUMP);
|
2022-04-13 11:56:37 +02:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
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-04-13 11:56:37 +02:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
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-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 COPY_ADC_DATA_TO_MRAM:
|
|
|
|
case RUN_AUTO_EM_TESTS:
|
|
|
|
case WIPE_MRAM:
|
|
|
|
case SET_GPIO:
|
|
|
|
case READ_GPIO:
|
|
|
|
case RESTART_SUPERVISOR:
|
|
|
|
case FACTORY_RESET_CLEAR_ALL:
|
|
|
|
case FACTORY_RESET_CLEAR_MIRROR:
|
|
|
|
case FACTORY_RESET_CLEAR_CIRCULAR:
|
|
|
|
case DISABLE_PERIOIC_HK_TRANSMISSION:
|
|
|
|
case START_MPSOC_QUIET:
|
|
|
|
case SET_SHUTDOWN_TIMEOUT:
|
|
|
|
case FACTORY_FLASH:
|
|
|
|
case ENABLE_AUTO_TM:
|
|
|
|
case DISABLE_AUTO_TM:
|
|
|
|
case LOGGING_CLEAR_COUNTERS:
|
|
|
|
case LOGGING_SET_TOPIC:
|
2022-04-28 11:27:28 +02:00
|
|
|
case RESET_PL:
|
2022-05-05 19:18:39 +02:00
|
|
|
case ENABLE_NVMS:
|
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.
|
|
|
|
*/
|
2022-04-30 11:08:36 +02:00
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, ACK_REPORT);
|
2022-04-13 11:56:37 +02:00
|
|
|
if (result != RETURN_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);
|
|
|
|
|
2022-04-30 11:08:36 +02:00
|
|
|
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, EXE_REPORT);
|
2022-04-13 11:56:37 +02:00
|
|
|
if (result != RETURN_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (nextReplyId == FIRST_MRAM_DUMP) {
|
|
|
|
*foundId = FIRST_MRAM_DUMP;
|
2022-03-27 13:07:18 +02:00
|
|
|
return parseMramPackets(start, remainingSize, foundLen);
|
2022-04-14 07:52:21 +02:00
|
|
|
} else if (nextReplyId == CONSECUTIVE_MRAM_DUMP) {
|
|
|
|
*foundId = 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-04-14 07:52:21 +02:00
|
|
|
case (APID_ACK_SUCCESS):
|
|
|
|
*foundLen = SIZE_ACK_REPORT;
|
|
|
|
*foundId = ACK_REPORT;
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2022-04-14 07:52:21 +02:00
|
|
|
case (APID_ACK_FAILURE):
|
|
|
|
*foundLen = SIZE_ACK_REPORT;
|
|
|
|
*foundId = ACK_REPORT;
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2022-04-14 07:52:21 +02:00
|
|
|
case (APID_HK_REPORT):
|
|
|
|
*foundLen = SIZE_HK_REPORT;
|
|
|
|
*foundId = HK_REPORT;
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2022-04-14 07:52:21 +02:00
|
|
|
case (APID_BOOT_STATUS_REPORT):
|
|
|
|
*foundLen = SIZE_BOOT_STATUS_REPORT;
|
|
|
|
*foundId = BOOT_STATUS_REPORT;
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2022-04-14 07:52:21 +02:00
|
|
|
case (APID_LATCHUP_STATUS_REPORT):
|
|
|
|
*foundLen = SIZE_LATCHUP_STATUS_REPORT;
|
|
|
|
*foundId = LATCHUP_REPORT;
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2022-04-14 07:52:21 +02:00
|
|
|
case (APID_DATA_LOGGER_DATA):
|
|
|
|
*foundLen = SIZE_LOGGING_REPORT;
|
|
|
|
*foundId = LOGGING_REPORT;
|
2022-04-13 11:56:37 +02:00
|
|
|
break;
|
2022-04-21 16:30:23 +02:00
|
|
|
case (APID_ADC_REPORT):
|
|
|
|
*foundLen = SIZE_ADC_REPORT;
|
|
|
|
*foundId = ADC_REPORT;
|
|
|
|
break;
|
2022-04-14 07:52:21 +02:00
|
|
|
case (APID_EXE_SUCCESS):
|
|
|
|
*foundLen = SIZE_EXE_REPORT;
|
|
|
|
*foundId = EXE_REPORT;
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2022-04-14 07:52:21 +02:00
|
|
|
case (APID_EXE_FAILURE):
|
|
|
|
*foundLen = SIZE_EXE_REPORT;
|
|
|
|
*foundId = EXE_REPORT;
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
sif::debug << "PlocSupervisorHandler::scanForReply: Reply has invalid apid" << std::endl;
|
|
|
|
*foundLen = remainingSize;
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::INVALID_APID;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2022-03-28 11:34:06 +02:00
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
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-03-27 13:07:18 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
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;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2022-04-21 16:30:23 +02:00
|
|
|
case (HK_REPORT): {
|
2022-03-27 13:07:18 +02:00
|
|
|
result = handleHkReport(packet);
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
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
|
|
|
}
|
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 (LOGGING_REPORT): {
|
2022-04-13 11:56:37 +02:00
|
|
|
result = handleLoggingReport(packet);
|
|
|
|
break;
|
|
|
|
}
|
2022-04-21 16:30:23 +02:00
|
|
|
case (ADC_REPORT): {
|
|
|
|
result = handleAdcReport(packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (FIRST_MRAM_DUMP):
|
|
|
|
case (CONSECUTIVE_MRAM_DUMP):
|
2022-03-27 13:07:18 +02:00
|
|
|
result = handleMramDumpPacket(id);
|
|
|
|
break;
|
2022-04-21 16:30:23 +02:00
|
|
|
case (EXE_REPORT): {
|
2022-03-27 13:07:18 +02:00
|
|
|
result = handleExecutionReport(packet);
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
default: {
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::debug << "PlocSupervisorHandler::interpretDeviceReply: Unknown device reply id"
|
|
|
|
<< std::endl;
|
|
|
|
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
void PlocSupervisorHandler::setNormalDatapoolEntriesInvalid() {}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-05-03 14:59:23 +02:00
|
|
|
uint32_t PlocSupervisorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
|
|
|
|
return 7000;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
|
|
|
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}));
|
|
|
|
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}));
|
|
|
|
|
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}));
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-04-22 08:55:57 +02:00
|
|
|
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNT_0, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNT_1, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNT_2, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNT_3, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNT_4, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNT_5, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::LATCHUP_HAPPENED_CNT_6, new PoolEntry<uint32_t>({0}));
|
|
|
|
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}));
|
|
|
|
localDataPoolMap.emplace(supv::LAST_RECVD_TC, new PoolEntry<uint32_t>({0}));
|
2022-04-14 07:52:21 +02:00
|
|
|
|
2022-04-21 16:30:23 +02:00
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_0, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_1, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_2, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_3, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_4, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_5, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_6, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_7, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_8, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_9, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_10, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_11, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_12, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_13, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_14, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_RAW_15, new PoolEntry<uint16_t>({0}));
|
|
|
|
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_0, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_1, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_2, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_3, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_4, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_5, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_6, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_7, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_8, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_9, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_10, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_11, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_12, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_13, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_14, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(supv::ADC_ENG_15, new PoolEntry<uint16_t>({0}));
|
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-04-10 18:46:39 +02:00
|
|
|
void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) {
|
2022-04-25 11:03:02 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2022-04-10 18:46:39 +02:00
|
|
|
object_id_t objectId = eventMessage->getReporter();
|
2022-04-25 11:03:02 +02:00
|
|
|
Event event = eventMessage->getEvent();
|
2022-04-10 18:46:39 +02:00
|
|
|
switch (objectId) {
|
2022-08-25 14:43:27 +02:00
|
|
|
case objects::PLOC_SUPERVISOR_HELPER: {
|
2022-04-10 18:46:39 +02:00
|
|
|
plocSupvHelperExecuting = false;
|
2022-04-25 11:03:02 +02:00
|
|
|
// 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.
|
|
|
|
if (event == PlocSupvHelper::SUPV_UPDATE_FAILED ||
|
2022-05-23 12:05:42 +02:00
|
|
|
event == PlocSupvHelper::SUPV_UPDATE_SUCCESSFUL ||
|
|
|
|
event == PlocSupvHelper::SUPV_CONTINUE_UPDATE_FAILED ||
|
|
|
|
event == PlocSupvHelper::SUPV_CONTINUE_UPDATE_SUCCESSFUL) {
|
2022-07-27 23:09:05 +02:00
|
|
|
//TODO result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0);
|
2022-04-25 11:03:02 +02:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
triggerEvent(SUPV_MPSOC_SHUWDOWN_BUILD_FAILED);
|
|
|
|
sif::warning << "PlocSupervisorHandler::handleEvent: Failed to build MPSoC shutdown "
|
2022-04-30 11:08:36 +02:00
|
|
|
"command"
|
|
|
|
<< std::endl;
|
2022-04-25 11:03:02 +02:00
|
|
|
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;
|
2022-04-30 11:08:36 +02:00
|
|
|
switch (command) {
|
|
|
|
case FIRST_MRAM_DUMP:
|
|
|
|
case CONSECUTIVE_MRAM_DUMP:
|
2022-05-23 12:05:42 +02:00
|
|
|
executionReportTimeout.setTimeout(MRAM_DUMP_EXECUTION_TIMEOUT);
|
2022-04-30 11:08:36 +02:00
|
|
|
break;
|
2022-05-04 12:49:43 +02:00
|
|
|
case COPY_ADC_DATA_TO_MRAM:
|
2022-05-23 12:05:42 +02:00
|
|
|
executionReportTimeout.setTimeout(COPY_ADC_TO_MRAM_TIMEOUT);
|
2022-05-04 12:49:43 +02:00
|
|
|
break;
|
2022-04-30 11:08:36 +02:00
|
|
|
default:
|
2022-05-23 12:05:42 +02:00
|
|
|
executionReportTimeout.setTimeout(EXECUTION_DEFAULT_TIMEOUT);
|
2022-04-30 11:08:36 +02:00
|
|
|
break;
|
2022-04-27 16:08:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
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) {
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::CRC_FAILURE;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
|
|
|
return RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::handleAckReport(const uint8_t* data) {
|
2022-04-29 23:34:28 +02:00
|
|
|
using namespace supv;
|
2022-04-30 11:08:36 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2022-04-29 23:34:28 +02:00
|
|
|
|
2022-04-30 11:08:36 +02:00
|
|
|
AcknowledgmentReport ack;
|
|
|
|
ack.addWholeData(data, SIZE_ACK_REPORT);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-04-29 23:34:28 +02:00
|
|
|
result = ack.checkCrc();
|
|
|
|
if (result != RETURN_OK) {
|
2022-03-27 13:07:18 +02:00
|
|
|
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-04-10 18:46:39 +02:00
|
|
|
sendFailureReport(supv::ACK_REPORT, SupvReturnValuesIF::CRC_FAILURE);
|
2022-03-27 13:07:18 +02:00
|
|
|
disableAllReplies();
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2022-04-29 23:34:28 +02:00
|
|
|
result = ack.checkApid();
|
|
|
|
|
|
|
|
switch (result) {
|
2022-05-04 12:49:43 +02:00
|
|
|
case SupvReturnValuesIF::RECEIVED_ACK_FAILURE: {
|
2022-03-27 13:07:18 +02:00
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
|
|
|
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
|
2022-05-04 12:49:43 +02:00
|
|
|
triggerEvent(SUPV_ACK_FAILURE, commandId, static_cast<uint32_t>(ack.getStatusCode()));
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
2022-06-10 10:39:43 +02:00
|
|
|
printAckFailureInfo(ack.getStatusCode(), commandId);
|
2022-04-10 18:46:39 +02:00
|
|
|
sendFailureReport(supv::ACK_REPORT, SupvReturnValuesIF::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-04-30 11:08:36 +02:00
|
|
|
case RETURN_OK: {
|
2022-03-27 13:07:18 +02:00
|
|
|
setNextReplyId();
|
|
|
|
break;
|
|
|
|
}
|
2022-04-30 11:08:36 +02:00
|
|
|
case SupvReturnValuesIF::INVALID_APID:
|
|
|
|
sif::warning << "PlocSupervisorHandler::handleAckReport: Invalid APID in Ack report"
|
|
|
|
<< std::endl;
|
|
|
|
sendFailureReport(supv::ACK_REPORT, result);
|
|
|
|
disableAllReplies();
|
|
|
|
nextReplyId = supv::NONE;
|
|
|
|
result = IGNORE_REPLY_DATA;
|
|
|
|
break;
|
2022-03-27 13:07:18 +02:00
|
|
|
default: {
|
2022-04-30 11:08:36 +02:00
|
|
|
sif::error << "PlocSupervisorHandler::handleAckReport: APID parsing failed" << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
result = RETURN_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::handleExecutionReport(const uint8_t* data) {
|
2022-04-30 11:08:36 +02:00
|
|
|
using namespace supv;
|
2022-03-27 13:07:18 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-04-30 11:08:36 +02:00
|
|
|
ExecutionReport exe;
|
|
|
|
exe.addWholeData(data, SIZE_EXE_REPORT);
|
|
|
|
|
|
|
|
result = exe.checkCrc();
|
|
|
|
if (result != RETURN_OK) {
|
2022-03-27 13:07:18 +02:00
|
|
|
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;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-04-30 11:08:36 +02:00
|
|
|
result = exe.checkApid();
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-04-30 11:08:36 +02:00
|
|
|
switch (result) {
|
|
|
|
case (RETURN_OK): {
|
2022-05-03 14:59:23 +02:00
|
|
|
handleExecutionSuccessReport(data);
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2022-04-30 11:08:36 +02:00
|
|
|
case (SupvReturnValuesIF::RECEIVED_EXE_FAILURE): {
|
2022-05-04 12:49:43 +02:00
|
|
|
handleExecutionFailureReport(exe.getStatusCode());
|
2022-05-03 14:59:23 +02:00
|
|
|
result = RETURN_OK;
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
default: {
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::error << "PlocSupervisorHandler::handleExecutionReport: Unknown APID" << std::endl;
|
|
|
|
result = RETURN_FAILED;
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
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;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-04-10 18:46:39 +02:00
|
|
|
if (result == SupvReturnValuesIF::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-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-07-13 08:32:14 +02:00
|
|
|
|
2021-08-17 17:48:51 +02:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
2022-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: "
|
2021-07-13 08:32:14 +02:00
|
|
|
<< 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: "
|
2021-07-13 08:32:14 +02:00
|
|
|
<< 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: "
|
2021-07-13 08:32:14 +02:00
|
|
|
<< static_cast<unsigned int>(hkset.missionIoState.value) << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleHkReport: fmc_state: "
|
2021-07-13 08:32:14 +02:00
|
|
|
<< static_cast<unsigned int>(hkset.fmcState.value) << std::endl;
|
2021-07-22 08:06:04 +02:00
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
#endif
|
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2021-07-24 13:57:05 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::handleBootStatusReport(const uint8_t* data) {
|
2022-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-04-10 18:46:39 +02:00
|
|
|
if (result == SupvReturnValuesIF::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-03-30 09:19:30 +02:00
|
|
|
uint16_t offset = supv::DATA_FIELD_OFFSET;
|
2022-04-11 16:52:50 +02:00
|
|
|
bootStatusReport.socState = *(data + offset);
|
2022-03-27 13:07:18 +02:00
|
|
|
offset += 1;
|
2022-04-11 16:52:50 +02:00
|
|
|
bootStatusReport.powerCycles = *(data + offset);
|
2022-03-27 13:07:18 +02:00
|
|
|
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-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: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< 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: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.activeNvm.value) << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP0: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.bp0State.value) << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP1: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< static_cast<unsigned int>(bootStatusReport.bp1State.value) << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleBootStatusReport: BP2: "
|
2021-07-25 20:42:24 +02:00
|
|
|
<< 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
|
|
|
}
|
|
|
|
|
2021-07-28 08:38:36 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::handleLatchupStatusReport(const uint8_t* data) {
|
2022-03-27 13:07:18 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-30 09:19:30 +02:00
|
|
|
result = verifyPacket(data, supv::SIZE_LATCHUP_STATUS_REPORT);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-04-10 18:46:39 +02:00
|
|
|
if (result == SupvReturnValuesIF::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-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-11 16:52:50 +02:00
|
|
|
uint16_t msec = *(data + offset) << 8 | *(data + offset + 1);
|
|
|
|
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;
|
|
|
|
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-07-13 08:32:14 +02:00
|
|
|
|
2021-08-17 17:48:51 +02:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: Latchup ID: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< static_cast<unsigned int>(latchupStatusReport.id.value) << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT0: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt0 << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT1: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt1 << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT2: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt2 << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT3: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt3 << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT4: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt4 << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT5: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< latchupStatusReport.cnt5 << std::endl;
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::handleLatchupStatusReport: CNT6: "
|
2021-07-28 08:38:36 +02:00
|
|
|
<< 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;
|
2021-07-28 08:38:36 +02:00
|
|
|
#endif
|
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
return result;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-04-13 11:56:37 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::handleLoggingReport(const uint8_t* data) {
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
result = verifyPacket(data, supv::SIZE_LOGGING_REPORT);
|
|
|
|
|
|
|
|
if (result == SupvReturnValuesIF::CRC_FAILURE) {
|
2022-05-04 12:49:43 +02:00
|
|
|
sif::warning << "PlocSupervisorHandler::handleLoggingReport: Logging report has "
|
2022-05-05 19:18:39 +02:00
|
|
|
<< "invalid crc" << std::endl;
|
2022-04-13 11:56:37 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-04-14 07:52:21 +02:00
|
|
|
const uint8_t* dataField = data + supv::DATA_FIELD_OFFSET + sizeof(supv::RequestLoggingData::Sa);
|
2022-04-13 11:56:37 +02:00
|
|
|
result = loggingReport.read();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
loggingReport.setValidityBufferGeneration(false);
|
|
|
|
size_t size = loggingReport.getSerializedSize();
|
|
|
|
result = loggingReport.deSerialize(&dataField, &size, SerializeIF::Endianness::BIG);
|
|
|
|
if (result != RETURN_OK) {
|
2022-04-30 11:08:36 +02:00
|
|
|
sif::warning << "PlocSupervisorHandler::handleLoggingReport: Deserialization failed"
|
|
|
|
<< std::endl;
|
2022-04-13 11:56:37 +02:00
|
|
|
}
|
|
|
|
loggingReport.setValidityBufferGeneration(true);
|
|
|
|
loggingReport.setValidity(true, true);
|
|
|
|
result = loggingReport.commit();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
|
|
|
loggingReport.printSet();
|
|
|
|
#endif
|
|
|
|
nextReplyId = supv::EXE_REPORT;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-04-21 16:30:23 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::handleAdcReport(const uint8_t* data) {
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
result = verifyPacket(data, supv::SIZE_ADC_REPORT);
|
|
|
|
|
|
|
|
if (result == SupvReturnValuesIF::CRC_FAILURE) {
|
|
|
|
sif::error << "PlocSupervisorHandler::handleAdcReport: ADC report has "
|
|
|
|
<< "invalid crc" << std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t* dataField = data + supv::DATA_FIELD_OFFSET;
|
|
|
|
result = adcReport.read();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
adcReport.setValidityBufferGeneration(false);
|
|
|
|
size_t size = adcReport.getSerializedSize();
|
|
|
|
result = adcReport.deSerialize(&dataField, &size, SerializeIF::Endianness::BIG);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::handleAdcReport: Deserialization failed" << std::endl;
|
|
|
|
}
|
|
|
|
adcReport.setValidityBufferGeneration(true);
|
|
|
|
adcReport.setValidity(true, true);
|
|
|
|
result = adcReport.commit();
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
|
|
|
adcReport.printSet();
|
|
|
|
#endif
|
|
|
|
nextReplyId = supv::EXE_REPORT;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
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;
|
2022-04-14 07:52:21 +02:00
|
|
|
case supv::LOGGING_REQUEST_COUNTERS:
|
|
|
|
nextReplyId = supv::LOGGING_REPORT;
|
|
|
|
break;
|
2022-04-21 16:30:23 +02:00
|
|
|
case supv::REQUEST_ADC_REPORT:
|
|
|
|
nextReplyId = supv::ADC_REPORT;
|
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
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;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2021-07-28 08:38:36 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
size_t PlocSupervisorHandler::getNextReplyLength(DeviceCommandId_t commandId) {
|
|
|
|
size_t replyLen = 0;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-30 09:19:30 +02:00
|
|
|
if (nextReplyId == supv::NONE) {
|
2022-03-27 13:07:18 +02:00
|
|
|
return replyLen;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
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;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
return replyLen;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-04-19 13:33:37 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::doSendReadHook() {
|
|
|
|
// Prevent DHB from polling UART during commands executed by the supervisor helper task
|
|
|
|
if (plocSupvHelperExecuting) {
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2022-05-06 19:53:33 +02:00
|
|
|
void PlocSupervisorHandler::doOffActivity() { startupState = StartupState::OFF; }
|
2022-05-06 19:30:20 +02:00
|
|
|
|
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;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
if (wiretappingMode == RAW) {
|
|
|
|
/* Data already sent in doGetRead() */
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
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;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
if (queueId == NO_COMMANDER) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::prepareEmptyCmd(uint16_t apid) {
|
2022-04-10 18:46:39 +02:00
|
|
|
supv::ApidOnlyPacket packet(apid);
|
2022-03-27 13:07:18 +02:00
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
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());
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::GET_TIME_FAILURE;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
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-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
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());
|
2021-07-25 20:42:24 +02:00
|
|
|
}
|
|
|
|
|
2021-07-27 12:02:30 +02:00
|
|
|
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) {
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::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(true, latchupId);
|
2022-03-27 13:07:18 +02:00
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
break;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
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;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
|
|
|
default: {
|
2022-03-27 13:07:18 +02:00
|
|
|
sif::debug << "PlocSupervisorHandler::prepareLatchupConfigCmd: Invalid command id"
|
|
|
|
<< std::endl;
|
|
|
|
result = RETURN_FAILED;
|
|
|
|
break;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
|
|
|
return result;
|
2021-07-27 12:02:30 +02:00
|
|
|
}
|
|
|
|
|
2021-07-28 08:38:36 +02:00
|
|
|
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) {
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::INVALID_LATCHUP_ID;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
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;
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2021-07-28 08:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 08:38:36 +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) {
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::INVALID_TEST_PARAM;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
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) {
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::INVALID_MRAM_ADDRESSES;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
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) {
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::INVALID_MRAM_ADDRESSES;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
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::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
|
|
|
}
|
|
|
|
|
2021-07-27 12:02:30 +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;
|
2021-07-26 19:56:00 +02:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2022-04-13 11:56:37 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareLoggingRequest(const uint8_t* commandData,
|
|
|
|
size_t commandDataLen) {
|
2022-04-14 07:52:21 +02:00
|
|
|
using namespace supv;
|
|
|
|
RequestLoggingData::Sa sa = static_cast<RequestLoggingData::Sa>(*commandData);
|
2022-04-13 11:56:37 +02:00
|
|
|
uint8_t tpc = *(commandData + 1);
|
2022-04-14 07:52:21 +02:00
|
|
|
RequestLoggingData packet(sa, tpc);
|
2022-04-13 11:56:37 +02:00
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2022-05-05 19:18:39 +02:00
|
|
|
ReturnValue_t PlocSupervisorHandler::prepareEnableNvmsCommand(const uint8_t* commandData) {
|
|
|
|
using namespace supv;
|
|
|
|
uint8_t nvm01 = *(commandData);
|
|
|
|
uint8_t nvm3 = *(commandData + 1);
|
|
|
|
EnableNvms packet(nvm01, nvm3);
|
|
|
|
packetToOutBuffer(packet.getWholeData(), packet.getFullSize());
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocSupervisorHandler::disableAllReplies() {
|
2022-05-06 19:30:20 +02:00
|
|
|
using namespace supv;
|
2022-03-27 13:07:18 +02:00
|
|
|
DeviceReplyMap::iterator iter;
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
/* Disable ack reply */
|
2022-05-06 19:30:20 +02:00
|
|
|
iter = deviceReplyMap.find(ACK_REPORT);
|
2022-03-27 13:07:18 +02:00
|
|
|
DeviceReplyInfo* info = &(iter->second);
|
|
|
|
info->delayCycles = 0;
|
|
|
|
info->command = deviceCommandMap.end();
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
2021-07-13 08:32:14 +02:00
|
|
|
|
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-05-06 19:30:20 +02:00
|
|
|
case GET_HK_REPORT: {
|
|
|
|
disableReply(GET_HK_REPORT);
|
2022-05-05 08:55:45 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-05-06 19:30:20 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
case LOGGING_REQUEST_COUNTERS: {
|
|
|
|
disableReply(LOGGING_REPORT);
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
default: {
|
2022-03-27 13:07:18 +02:00
|
|
|
break;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
/* We must always disable the execution report reply here */
|
|
|
|
disableExeReportReply();
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 19:30:20 +02:00
|
|
|
void PlocSupervisorHandler::disableReply(DeviceCommandId_t replyId) {
|
|
|
|
DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId);
|
|
|
|
DeviceReplyInfo* info = &(iter->second);
|
|
|
|
info->delayCycles = 0;
|
|
|
|
info->active = false;
|
|
|
|
info->command = deviceCommandMap.end();
|
|
|
|
}
|
|
|
|
|
2021-07-13 08:32:14 +02:00
|
|
|
void PlocSupervisorHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) {
|
2022-03-27 13:07:18 +02:00
|
|
|
DeviceReplyIter iter = deviceReplyMap.find(replyId);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
if (iter == deviceReplyMap.end()) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::sendFailureReport: Reply not in reply map" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
DeviceCommandInfo* info = &(iter->second.command->second);
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
if (info == nullptr) {
|
|
|
|
sif::debug << "PlocSupervisorHandler::sendFailureReport: Reply has no active command"
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-07-13 08:32:14 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
if (info->sendReplyTo != NO_COMMANDER) {
|
|
|
|
actionHelper.finish(false, info->sendReplyTo, iter->first, status);
|
|
|
|
}
|
|
|
|
info->isExecuting = false;
|
2021-07-13 08:32:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocSupervisorHandler::disableExeReportReply() {
|
2022-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();
|
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-13 08:32:14 +02:00
|
|
|
}
|
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;
|
2022-04-30 11:08:36 +02:00
|
|
|
sif::info << "PlocSupervisorHandler::parseMramPackets: Can not find MRAM packet in space "
|
|
|
|
"packet buffer"
|
|
|
|
<< std::endl;
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::MRAM_PACKET_PARSING_FAILURE;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-06 19:30:20 +02:00
|
|
|
result = handleMramDumpFile(id);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
DeviceCommandMap::iterator iter = deviceCommandMap.find(id);
|
|
|
|
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);
|
|
|
|
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;
|
2022-05-06 19:30:20 +02:00
|
|
|
mramReplyInfo->countdown->resetTimer();
|
2022-03-27 13:07:18 +02:00
|
|
|
} else {
|
|
|
|
// Command expects the execution report
|
|
|
|
info->expectedReplies = 1;
|
2022-05-06 19:30:20 +02:00
|
|
|
mramReplyInfo->active = false;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
2022-05-06 19:30:20 +02:00
|
|
|
exeReplyInfo->countdown->resetTimer();
|
2022-03-27 13:07:18 +02:00
|
|
|
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-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::NO_MRAM_PACKET;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
|
|
|
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;
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::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-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";
|
2021-08-17 16:14:23 +02:00
|
|
|
|
2022-04-10 18:46:39 +02:00
|
|
|
#ifndef TE0720_1CFA
|
2022-03-27 13:07:18 +02:00
|
|
|
std::string currentMountPrefix = sdcMan->getCurrentMountPrefix();
|
2021-08-17 16:14:23 +02:00
|
|
|
#else
|
2022-03-27 13:07:18 +02:00
|
|
|
std::string currentMountPrefix("/mnt/sd0");
|
2021-08-17 16:14:23 +02:00
|
|
|
#endif /* BOARD_TE0720 == 0 */
|
2021-08-08 15:02:59 +02:00
|
|
|
|
2022-03-27 13:07:18 +02:00
|
|
|
// Check if path to PLOC directory exists
|
2022-05-05 08:55:45 +02:00
|
|
|
if (not std::filesystem::exists(std::string(currentMountPrefix + "/" + supervisorFilePath))) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::createMramDumpFile: Supervisor path does not exist"
|
2022-03-27 13:07:18 +02:00
|
|
|
<< std::endl;
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::PATH_DOES_NOT_EXIST;
|
2022-03-27 13:07:18 +02:00
|
|
|
}
|
2022-05-05 08:55:45 +02:00
|
|
|
activeMramFile = currentMountPrefix + "/" + supervisorFilePath + "/" + filename;
|
2022-03-27 13:07:18 +02:00
|
|
|
// 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) {
|
2022-05-06 19:30:20 +02:00
|
|
|
sif::warning << "PlocSupervisorHandler::getTimeStampString: Failed to get current time"
|
2022-03-27 13:07:18 +02:00
|
|
|
<< std::endl;
|
2022-04-10 18:46:39 +02:00
|
|
|
return SupvReturnValuesIF::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);
|
|
|
|
return RETURN_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,
|
|
|
|
std::string* file, uint8_t* memoryId,
|
|
|
|
uint32_t* startAddress) {
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
if (size > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE + sizeof(*memoryId)) +
|
|
|
|
sizeof(*startAddress)) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Data size too big" << std::endl;
|
|
|
|
return SupvReturnValuesIF::INVALID_LENGTH;
|
|
|
|
}
|
|
|
|
*file = std::string(reinterpret_cast<const char*>(commandData));
|
|
|
|
if (file->size() > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE)) {
|
|
|
|
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Filename too long" << std::endl;
|
|
|
|
return SupvReturnValuesIF::FILENAME_TOO_LONG;
|
|
|
|
}
|
|
|
|
*memoryId = *(commandData + file->size() + SIZE_NULL_TERMINATOR);
|
|
|
|
const uint8_t* startAddressPtr =
|
|
|
|
commandData + file->size() + SIZE_NULL_TERMINATOR + sizeof(*memoryId);
|
|
|
|
size_t remainingSize = 4;
|
|
|
|
result = SerializeAdapter::deSerialize(startAddress, startAddressPtr, &remainingSize,
|
|
|
|
SerializeIF::Endianness::BIG);
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::warning
|
|
|
|
<< "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize start address"
|
|
|
|
<< std::endl;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocSupervisorHandler::eventSubscription() {
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
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());
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = manager->subscribeToEventRange(
|
|
|
|
eventQueue->getId(), event::getEventId(PlocSupvHelper::SUPV_UPDATE_FAILED),
|
2022-04-13 11:56:37 +02:00
|
|
|
event::getEventId(PlocSupvHelper::SUPV_EVENT_BUFFER_REQUEST_TERMINATED));
|
2022-04-10 18:46:39 +02:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
#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-05-03 14:59:23 +02:00
|
|
|
void PlocSupervisorHandler::handleExecutionSuccessReport(const uint8_t* data) {
|
2022-04-29 08:34:23 +02:00
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
2022-04-30 11:08:36 +02:00
|
|
|
switch (commandId) {
|
|
|
|
case supv::READ_GPIO: {
|
|
|
|
supv::ExecutionReport exe;
|
|
|
|
exe.addWholeData(data, supv::SIZE_EXE_REPORT);
|
|
|
|
uint16_t gpioState = exe.getStatusCode();
|
2022-04-29 08:34:23 +02:00
|
|
|
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1
|
2022-05-03 14:59:23 +02:00
|
|
|
sif::info << "PlocSupervisorHandler: Read GPIO TM, State: " << gpioState << std::endl;
|
2022-04-29 08:34:23 +02:00
|
|
|
#endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */
|
2022-05-04 12:49:43 +02:00
|
|
|
DeviceCommandMap::iterator iter = deviceCommandMap.find(commandId);
|
|
|
|
if (iter->second.sendReplyTo == NO_COMMAND_ID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t data[sizeof(gpioState)];
|
|
|
|
size_t size = 0;
|
2022-05-05 19:18:39 +02:00
|
|
|
ReturnValue_t result = SerializeAdapter::serialize(&gpioState, data, &size, sizeof(gpioState),
|
|
|
|
SerializeIF::Endianness::BIG);
|
2022-05-04 12:49:43 +02:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::debug << "PlocSupervisorHandler: Failed to deserialize GPIO state" << std::endl;
|
|
|
|
}
|
|
|
|
result = actionHelper.reportData(iter->second.sendReplyTo, commandId, data, sizeof(data));
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::warning << "PlocSupervisorHandler: Read GPIO, failed to report data" << std::endl;
|
|
|
|
}
|
2022-04-30 11:08:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-05-03 14:59:23 +02:00
|
|
|
case supv::SET_TIME_REF: {
|
|
|
|
if (startupState == StartupState::SET_TIME_EXECUTING) {
|
|
|
|
startupState = StartupState::ON;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-04-30 11:08:36 +02:00
|
|
|
default:
|
|
|
|
break;
|
2022-04-29 08:34:23 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-03 14:59:23 +02:00
|
|
|
|
2022-05-04 12:49:43 +02:00
|
|
|
void PlocSupervisorHandler::handleExecutionFailureReport(uint16_t statusCode) {
|
2022-05-03 14:59:23 +02:00
|
|
|
using namespace supv;
|
|
|
|
DeviceCommandId_t commandId = getPendingCommand();
|
|
|
|
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
|
2022-05-04 12:49:43 +02:00
|
|
|
triggerEvent(SUPV_EXE_FAILURE, commandId, static_cast<uint32_t>(statusCode));
|
2022-05-03 14:59:23 +02:00
|
|
|
}
|
|
|
|
sendFailureReport(EXE_REPORT, SupvReturnValuesIF::RECEIVED_EXE_FAILURE);
|
|
|
|
disableExeReportReply();
|
|
|
|
}
|
2022-06-10 10:39:43 +02:00
|
|
|
|
|
|
|
void PlocSupervisorHandler::printAckFailureInfo(uint16_t statusCode, DeviceCommandId_t commandId) {
|
2022-06-17 08:31:36 +02:00
|
|
|
sif::warning << "PlocSupervisorHandler: Received Ack failure report with status code: 0x"
|
|
|
|
<< std::hex << statusCode << std::endl;
|
|
|
|
switch (commandId) {
|
|
|
|
case (supv::SET_TIME_REF): {
|
|
|
|
sif::info << "PlocSupervisoHandler: Setting time failed. Make sure the OBC has a valid time"
|
|
|
|
<< std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-06-10 10:39:43 +02:00
|
|
|
}
|