eive-obsw/linux/payload/PlocMpsocHandler.cpp

1536 lines
54 KiB
C++
Raw Normal View History

2023-05-12 15:52:47 +02:00
#include <fsfw/globalfunctions/arrayprinter.h>
2023-03-26 16:42:00 +02:00
#include <linux/payload/PlocMpsocHandler.h>
#include <linux/payload/plocSupvDefs.h>
2022-03-22 11:35:44 +01:00
2023-02-28 09:13:41 +01:00
#include <sstream>
2022-03-22 11:35:44 +01:00
#include "OBSWConfig.h"
2022-01-06 18:05:21 +01:00
#include "fsfw/datapool/PoolReadGuard.h"
2022-03-22 11:35:44 +01:00
#include "fsfw/globalfunctions/CRC.h"
2021-03-29 14:37:52 +02:00
2023-05-15 15:15:58 +02:00
PlocMpsocHandler::PlocMpsocHandler(object_id_t objectId, object_id_t uartComIFid,
CookieIF* comCookie, PlocMpsocSpecialComHelper* plocMPSoCHelper,
2022-03-30 09:19:30 +02:00
Gpio uartIsolatorSwitch, object_id_t supervisorHandler)
2022-03-27 14:42:20 +02:00
: DeviceHandlerBase(objectId, uartComIFid, comCookie),
2023-05-02 15:04:14 +02:00
hkReport(this),
2023-05-15 15:19:12 +02:00
specialComHelper(plocMPSoCHelper),
2022-03-30 09:19:30 +02:00
uartIsolatorSwitch(uartIsolatorSwitch),
supervisorHandler(supervisorHandler),
commandActionHelper(this) {
2022-03-27 14:42:20 +02:00
if (comCookie == nullptr) {
sif::error << "PlocMPSoCHandler: Invalid communication cookie" << std::endl;
}
2022-03-22 11:35:44 +01:00
eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5);
2022-03-30 09:19:30 +02:00
commandActionHelperQueue =
QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5);
2022-08-15 18:53:25 +02:00
spParams.maxSize = sizeof(commandBuffer);
spParams.buf = commandBuffer;
2021-03-29 14:37:52 +02:00
}
2023-05-15 15:15:58 +02:00
PlocMpsocHandler::~PlocMpsocHandler() {}
2021-03-29 14:37:52 +02:00
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::initialize() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-22 11:35:44 +01:00
result = DeviceHandlerBase::initialize();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return result;
}
2022-11-10 18:07:59 +01:00
uartComIf = dynamic_cast<SerialComIF*>(communicationInterface);
2022-03-22 11:35:44 +01:00
if (uartComIf == nullptr) {
sif::warning << "PlocMPSoCHandler::initialize: Invalid uart com if" << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
2022-01-06 18:05:21 +01:00
2022-03-22 11:35:44 +01:00
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
if (manager == nullptr) {
2022-01-06 18:05:21 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-03-22 11:35:44 +01:00
sif::error << "PlocMPSoCHandler::initialize: Invalid event manager" << std::endl;
2022-01-06 18:05:21 +01:00
#endif
2022-03-22 11:35:44 +01:00
return ObjectManagerIF::CHILD_INIT_FAILED;
;
}
result = manager->registerListener(eventQueue->getId());
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-17 17:33:14 +02:00
result = manager->subscribeToEvent(
eventQueue->getId(), event::getEventId(PlocMpsocSpecialComHelper::MPSOC_FLASH_WRITE_FAILED));
if (result != returnvalue::OK) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
result = manager->subscribeToEvent(
eventQueue->getId(),
2023-05-15 15:15:58 +02:00
event::getEventId(PlocMpsocSpecialComHelper::MPSOC_FLASH_WRITE_SUCCESSFUL));
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2023-05-17 17:33:14 +02:00
return ObjectManagerIF::CHILD_INIT_FAILED;
}
result = manager->subscribeToEvent(
eventQueue->getId(),
event::getEventId(PlocMpsocSpecialComHelper::MPSOC_FLASH_READ_SUCCESSFUL));
if (result != returnvalue::OK) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
result = manager->subscribeToEvent(
eventQueue->getId(), event::getEventId(PlocMpsocSpecialComHelper::MPSOC_FLASH_READ_FAILED));
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return ObjectManagerIF::CHILD_INIT_FAILED;
}
2022-01-06 18:05:21 +01:00
2023-05-15 15:19:12 +02:00
result = specialComHelper->setComIF(communicationInterface);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return ObjectManagerIF::CHILD_INIT_FAILED;
}
2023-05-15 15:19:12 +02:00
specialComHelper->setComCookie(comCookie);
specialComHelper->setSequenceCount(&sequenceCount);
2022-03-30 09:19:30 +02:00
result = commandActionHelper.initialize();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-30 09:19:30 +02:00
return ObjectManagerIF::CHILD_INIT_FAILED;
}
2022-03-22 11:35:44 +01:00
return result;
2022-01-03 08:01:55 +01:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::performOperationHook() {
2023-05-15 13:25:53 +02:00
if (commandIsPending and cmdCountdown.hasTimedOut()) {
2023-10-16 14:46:02 +02:00
sif::warning << "PlocMpsocHandler: Command " << getPendingCommand() << " has timed out"
<< std::endl;
2023-05-15 13:25:53 +02:00
commandIsPending = false;
// TODO: Better returnvalue?
cmdDoneHandler(false, returnvalue::FAILED);
}
2022-03-22 11:35:44 +01:00
EventMessage event;
2022-08-24 17:27:47 +02:00
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == returnvalue::OK;
2022-03-22 11:35:44 +01:00
result = eventQueue->receiveMessage(&event)) {
switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE:
handleEvent(&event);
break;
default:
sif::debug << "PlocMPSoCHandler::performOperationHook: Did not subscribe to this event"
<< " message" << std::endl;
break;
2022-01-07 09:50:04 +01:00
}
2022-03-22 11:35:44 +01:00
}
2022-03-30 09:19:30 +02:00
CommandMessage message;
2022-04-04 13:40:45 +02:00
for (ReturnValue_t result = commandActionHelperQueue->receiveMessage(&message);
2022-08-24 17:27:47 +02:00
result == returnvalue::OK; result = commandActionHelperQueue->receiveMessage(&message)) {
2022-03-30 09:19:30 +02:00
result = commandActionHelper.handleReply(&message);
2022-08-24 17:27:47 +02:00
if (result == returnvalue::OK) {
2022-03-30 09:19:30 +02:00
continue;
}
}
2022-01-07 09:50:04 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
2022-03-22 11:35:44 +01:00
const uint8_t* data, size_t size) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-04-30 16:21:59 +02:00
switch (actionId) {
case mpsoc::SET_UART_TX_TRISTATE: {
uartIsolatorSwitch.pullLow();
return EXECUTION_FINISHED;
break;
}
case mpsoc::RELEASE_UART_TX: {
uartIsolatorSwitch.pullHigh();
return EXECUTION_FINISHED;
break;
default:
break;
}
2022-04-29 22:55:01 +02:00
}
2022-01-06 18:05:21 +01:00
2023-05-17 17:33:14 +02:00
if (specialComHelperExecuting) {
2022-03-22 11:35:44 +01:00
return MPSoCReturnValuesIF::MPSOC_HELPER_EXECUTING;
}
2022-01-06 18:05:21 +01:00
2022-03-22 11:35:44 +01:00
switch (actionId) {
2023-05-03 19:54:30 +02:00
case mpsoc::TC_FLASH_WRITE_FULL_FILE: {
2023-05-11 20:21:44 +02:00
mpsoc::FlashBasePusCmd flashWritePusCmd;
result = flashWritePusCmd.extractFields(data, size);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-25 09:08:01 +01:00
return result;
}
2023-05-15 15:19:12 +02:00
result = specialComHelper->startFlashWrite(flashWritePusCmd.getObcFile(),
flashWritePusCmd.getMPSoCFile());
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-17 17:33:14 +02:00
specialComHelperExecuting = true;
return EXECUTION_FINISHED;
}
2023-05-03 19:54:30 +02:00
case mpsoc::TC_FLASH_READ_FULL_FILE: {
2023-05-11 20:21:44 +02:00
mpsoc::FlashReadPusCmd flashReadPusCmd;
result = flashReadPusCmd.extractFields(data, size);
if (result != returnvalue::OK) {
return result;
}
2023-05-15 15:19:12 +02:00
result = specialComHelper->startFlashRead(flashReadPusCmd.getObcFile(),
flashReadPusCmd.getMPSoCFile(),
flashReadPusCmd.getReadSize());
2023-05-11 20:21:44 +02:00
if (result != returnvalue::OK) {
return result;
}
2023-05-17 17:33:14 +02:00
specialComHelperExecuting = true;
2023-05-11 20:21:44 +02:00
return EXECUTION_FINISHED;
2023-05-03 19:54:30 +02:00
}
case (mpsoc::OBSW_RESET_SEQ_COUNT): {
sequenceCount = 0;
return EXECUTION_FINISHED;
2022-01-06 18:05:21 +01:00
}
default:
2022-03-22 11:35:44 +01:00
break;
}
2023-05-15 13:27:24 +02:00
// For longer commands, do not set these.
commandIsPending = true;
cmdCountdown.resetTimer();
2022-03-22 11:35:44 +01:00
return DeviceHandlerBase::executeAction(actionId, commandedBy, data, size);
2022-01-06 18:05:21 +01:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::doStartUp() {
2023-05-12 12:37:25 +02:00
if (startupState == StartupState::IDLE) {
startupState = StartupState::HW_INIT;
}
if (startupState == StartupState::HW_INIT) {
if (handleHwStartup()) {
2023-05-12 12:37:25 +02:00
startupState = StartupState::DONE;
}
}
if (startupState == StartupState::DONE) {
setMode(_MODE_TO_ON);
hkReport.setReportingEnabled(true);
powerState = PowerState::IDLE;
2023-05-12 12:37:25 +02:00
startupState = StartupState::IDLE;
}
2021-03-29 14:37:52 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::doShutDown() {
if (handleHwShutdown()) {
hkReport.setReportingEnabled(false);
setMode(_MODE_POWER_DOWN);
commandIsPending = false;
sequenceCount = 0;
powerState = PowerState::IDLE;
startupState = StartupState::IDLE;
2023-05-16 18:41:04 +02:00
}
2022-03-27 14:42:20 +02:00
}
2022-03-22 11:35:44 +01:00
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
2023-05-17 17:33:14 +02:00
if (not commandIsPending and not specialComHelperExecuting) {
2023-05-12 16:29:15 +02:00
*id = mpsoc::TC_GET_HK_REPORT;
2023-05-12 17:39:15 +02:00
commandIsPending = true;
2023-05-12 16:29:15 +02:00
return buildCommandFromCommand(*id, nullptr, 0);
}
2023-05-12 11:06:26 +02:00
return NOTHING_TO_SEND;
2022-03-22 11:35:44 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
return NOTHING_TO_SEND;
2022-03-22 11:35:44 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
2022-03-22 11:35:44 +01:00
const uint8_t* commandData,
size_t commandDataLen) {
spParams.buf = commandBuffer;
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-22 11:35:44 +01:00
switch (deviceCommand) {
case (mpsoc::TC_MEM_WRITE): {
result = prepareTcMemWrite(commandData, commandDataLen);
break;
}
case (mpsoc::TC_MEM_READ): {
result = prepareTcMemRead(commandData, commandDataLen);
break;
}
case (mpsoc::TC_FLASHDELETE): {
result = prepareTcFlashDelete(commandData, commandDataLen);
break;
}
case (mpsoc::TC_REPLAY_START): {
result = prepareTcReplayStart(commandData, commandDataLen);
break;
}
case (mpsoc::TC_REPLAY_STOP): {
result = prepareTcReplayStop();
break;
2022-01-03 08:01:55 +01:00
}
2022-03-22 11:35:44 +01:00
case (mpsoc::TC_DOWNLINK_PWR_ON): {
result = prepareTcDownlinkPwrOn(commandData, commandDataLen);
break;
}
case (mpsoc::TC_DOWNLINK_PWR_OFF): {
result = prepareTcDownlinkPwrOff();
break;
}
case (mpsoc::TC_REPLAY_WRITE_SEQUENCE): {
result = prepareTcReplayWriteSequence(commandData, commandDataLen);
break;
}
2023-05-02 13:42:20 +02:00
case (mpsoc::TC_GET_HK_REPORT): {
result = prepareTcGetHkReport();
break;
}
2023-05-03 15:24:47 +02:00
case (mpsoc::TC_FLASH_GET_DIRECTORY_CONTENT): {
result = prepareTcGetDirContent(commandData, commandDataLen);
break;
}
2022-03-24 17:39:50 +01:00
case (mpsoc::TC_MODE_REPLAY): {
2022-03-25 09:08:01 +01:00
result = prepareTcModeReplay();
break;
}
2022-04-20 21:33:39 +02:00
case (mpsoc::TC_MODE_IDLE): {
result = prepareTcModeIdle();
break;
}
case (mpsoc::TC_CAM_CMD_SEND): {
result = prepareTcCamCmdSend(commandData, commandDataLen);
break;
}
case (mpsoc::TC_CAM_TAKE_PIC): {
2023-03-13 11:05:21 +01:00
result = prepareTcCamTakePic(commandData, commandDataLen);
break;
}
case (mpsoc::TC_SIMPLEX_SEND_FILE): {
2023-03-13 11:05:21 +01:00
result = prepareTcSimplexSendFile(commandData, commandDataLen);
break;
}
case (mpsoc::TC_DOWNLINK_DATA_MODULATE): {
2023-03-13 11:05:21 +01:00
result = prepareTcDownlinkDataModulate(commandData, commandDataLen);
break;
}
2023-02-28 09:13:41 +01:00
case (mpsoc::TC_MODE_SNAPSHOT): {
2023-03-13 11:05:21 +01:00
result = prepareTcModeSnapshot();
break;
2023-02-28 09:13:41 +01:00
}
2022-03-22 11:35:44 +01:00
default:
sif::debug << "PlocMPSoCHandler::buildCommandFromCommand: Command not implemented"
<< std::endl;
result = DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
break;
}
2022-01-03 08:01:55 +01:00
2022-08-24 17:27:47 +02:00
if (result == returnvalue::OK) {
2022-03-22 11:35:44 +01:00
/**
* Flushing the receive buffer to make sure there are no data left from a faulty reply.
*/
uartComIf->flushUartRxBuffer(comCookie);
}
return result;
2021-03-29 14:37:52 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::fillCommandAndReplyMap() {
2022-03-22 11:35:44 +01:00
this->insertInCommandMap(mpsoc::TC_MEM_WRITE);
this->insertInCommandMap(mpsoc::TC_MEM_READ);
this->insertInCommandMap(mpsoc::TC_FLASHDELETE);
2023-05-03 19:54:30 +02:00
insertInCommandMap(mpsoc::TC_FLASH_WRITE_FULL_FILE);
insertInCommandMap(mpsoc::TC_FLASH_READ_FULL_FILE);
2022-03-22 11:35:44 +01:00
this->insertInCommandMap(mpsoc::TC_REPLAY_START);
this->insertInCommandMap(mpsoc::TC_REPLAY_STOP);
this->insertInCommandMap(mpsoc::TC_DOWNLINK_PWR_ON);
this->insertInCommandMap(mpsoc::TC_DOWNLINK_PWR_OFF);
this->insertInCommandMap(mpsoc::TC_REPLAY_WRITE_SEQUENCE);
2022-03-24 17:39:50 +01:00
this->insertInCommandMap(mpsoc::TC_MODE_REPLAY);
2022-04-20 21:33:39 +02:00
this->insertInCommandMap(mpsoc::TC_MODE_IDLE);
this->insertInCommandMap(mpsoc::TC_CAM_CMD_SEND);
2023-05-02 13:42:20 +02:00
this->insertInCommandMap(mpsoc::TC_GET_HK_REPORT);
2022-04-29 22:55:01 +02:00
this->insertInCommandMap(mpsoc::RELEASE_UART_TX);
this->insertInCommandMap(mpsoc::SET_UART_TX_TRISTATE);
2023-02-28 09:13:41 +01:00
this->insertInCommandMap(mpsoc::TC_CAM_TAKE_PIC);
2023-05-03 15:24:47 +02:00
this->insertInCommandMap(mpsoc::TC_FLASH_GET_DIRECTORY_CONTENT);
2023-02-28 09:13:41 +01:00
this->insertInCommandMap(mpsoc::TC_SIMPLEX_SEND_FILE);
this->insertInCommandMap(mpsoc::TC_DOWNLINK_DATA_MODULATE);
this->insertInCommandMap(mpsoc::TC_MODE_SNAPSHOT);
2022-04-20 21:33:39 +02:00
this->insertInReplyMap(mpsoc::ACK_REPORT, 3, nullptr, mpsoc::SIZE_ACK_REPORT);
2022-03-22 11:35:44 +01:00
this->insertInReplyMap(mpsoc::EXE_REPORT, 3, nullptr, mpsoc::SIZE_EXE_REPORT);
this->insertInReplyMap(mpsoc::TM_MEMORY_READ_REPORT, 2, nullptr, mpsoc::SIZE_TM_MEM_READ_REPORT);
2023-05-12 11:06:26 +02:00
this->insertInReplyMap(mpsoc::TM_GET_HK_REPORT, 5, nullptr, mpsoc::SIZE_TM_HK_REPORT);
this->insertInReplyMap(mpsoc::TM_CAM_CMD_RPT, 2, nullptr, mpsoc::SP_MAX_SIZE);
2023-05-12 15:52:47 +02:00
this->insertInReplyMap(mpsoc::TM_FLASH_DIRECTORY_CONTENT, 2, nullptr, mpsoc::SP_MAX_SIZE);
2022-03-22 11:35:44 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::scanForReply(const uint8_t* start, size_t remainingSize,
2022-03-22 11:35:44 +01:00
DeviceCommandId_t* foundId, size_t* foundLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
SpacePacketReader spacePacket;
spacePacket.setReadOnlyData(start, remainingSize);
2023-10-16 14:36:30 +02:00
if (DEBUG_MPSOC_COMMUNICATION) {
sif::debug << "RECV MPSOC packet. APID 0x" << std::hex << std::setw(3) << spacePacket.getApid()
<< std::dec << " Size " << spacePacket.getFullPacketLen() << " SSC "
<< spacePacket.getSequenceCount() << std::endl;
}
if (spacePacket.isNull()) {
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
}
auto res = spacePacket.checkSize();
2022-08-24 17:27:47 +02:00
if (res != returnvalue::OK) {
return res;
}
uint16_t apid = spacePacket.getApid();
2022-03-22 11:35:44 +01:00
2023-05-03 15:24:47 +02:00
auto handleDedicatedReply = [&](DeviceCommandId_t replyId) {
*foundLen = spacePacket.getFullPacketLen();
foundPacketLen = *foundLen;
*foundId = replyId;
};
2022-03-22 11:35:44 +01:00
switch (apid) {
case (mpsoc::apid::ACK_SUCCESS):
*foundLen = mpsoc::SIZE_ACK_REPORT;
*foundId = mpsoc::ACK_REPORT;
break;
case (mpsoc::apid::ACK_FAILURE):
*foundLen = mpsoc::SIZE_ACK_REPORT;
*foundId = mpsoc::ACK_REPORT;
break;
case (mpsoc::apid::TM_MEMORY_READ_REPORT):
*foundLen = tmMemReadReport.rememberRequestedSize;
*foundId = mpsoc::TM_MEMORY_READ_REPORT;
break;
2022-04-20 21:33:39 +02:00
case (mpsoc::apid::TM_CAM_CMD_RPT):
2023-05-03 15:24:47 +02:00
handleDedicatedReply(mpsoc::TM_CAM_CMD_RPT);
2022-04-20 21:33:39 +02:00
break;
2023-05-02 13:42:20 +02:00
case (mpsoc::apid::TM_HK_GET_REPORT): {
2023-05-03 15:24:47 +02:00
handleDedicatedReply(mpsoc::TM_GET_HK_REPORT);
break;
}
case (mpsoc::apid::TM_FLASH_DIRECTORY_CONTENT): {
handleDedicatedReply(mpsoc::TM_FLASH_DIRECTORY_CONTENT);
2023-05-02 13:42:20 +02:00
break;
}
2022-03-22 11:35:44 +01:00
case (mpsoc::apid::EXE_SUCCESS):
*foundLen = mpsoc::SIZE_EXE_REPORT;
*foundId = mpsoc::EXE_REPORT;
break;
case (mpsoc::apid::EXE_FAILURE):
*foundLen = mpsoc::SIZE_EXE_REPORT;
*foundId = mpsoc::EXE_REPORT;
break;
default: {
2023-05-12 15:52:47 +02:00
sif::debug << "PlocMPSoCHandler::scanForReply: Reply has invalid APID 0x" << std::hex
<< std::setfill('0') << std::setw(2) << apid << std::dec << std::endl;
2022-03-22 11:35:44 +01:00
*foundLen = remainingSize;
return MPSoCReturnValuesIF::INVALID_APID;
}
}
2022-04-20 21:33:39 +02:00
2023-05-12 17:39:15 +02:00
uint16_t recvSeqCnt = ((*(start + 2) << 8) | *(start + 3)) & PACKET_SEQUENCE_COUNT_MASK;
2022-03-22 11:35:44 +01:00
if (recvSeqCnt != sequenceCount) {
2022-05-03 14:59:23 +02:00
triggerEvent(MPSOC_HANDLER_SEQUENCE_COUNT_MISMATCH, sequenceCount, recvSeqCnt);
2022-03-22 11:35:44 +01:00
sequenceCount = recvSeqCnt;
}
2023-01-09 13:29:59 +01:00
// This sequence count ping pong does not make any sense but it is how the MPSoC expects it.
sequenceCount++;
2023-05-15 13:25:53 +02:00
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-22 11:35:44 +01:00
switch (id) {
2022-01-05 11:26:01 +01:00
case mpsoc::ACK_REPORT: {
2022-03-22 11:35:44 +01:00
result = handleAckReport(packet);
break;
}
2022-01-05 11:26:01 +01:00
case (mpsoc::TM_MEMORY_READ_REPORT): {
2022-03-22 11:35:44 +01:00
result = handleMemoryReadReport(packet);
break;
}
2023-05-02 13:42:20 +02:00
case (mpsoc::TM_GET_HK_REPORT): {
result = handleGetHkReport(packet);
break;
}
2022-04-20 21:33:39 +02:00
case (mpsoc::TM_CAM_CMD_RPT): {
result = handleCamCmdRpt(packet);
break;
}
2023-05-03 15:24:47 +02:00
case (mpsoc::TM_FLASH_DIRECTORY_CONTENT): {
result = verifyPacket(packet, foundPacketLen);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PLOC MPSoC: Flash directory content reply invalid CRC" << std::endl;
}
/** Send data to commanding queue */
handleDeviceTm(packet + mpsoc::DATA_FIELD_OFFSET,
foundPacketLen - mpsoc::DATA_FIELD_OFFSET - mpsoc::CRC_SIZE,
mpsoc::TM_FLASH_DIRECTORY_CONTENT);
nextReplyId = mpsoc::EXE_REPORT;
return result;
}
2022-01-05 11:26:01 +01:00
case (mpsoc::EXE_REPORT): {
2022-03-22 11:35:44 +01:00
result = handleExecutionReport(packet);
break;
}
default: {
2022-03-22 11:35:44 +01:00
sif::debug << "PlocMPSoCHandler::interpretDeviceReply: Unknown device reply id" << std::endl;
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
2022-03-22 11:35:44 +01:00
}
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::setNormalDatapoolEntriesInvalid() {
2023-05-03 15:24:47 +02:00
PoolReadGuard pg(&hkReport);
hkReport.setValidity(false, true);
}
2023-10-16 14:36:30 +02:00
uint32_t PlocMpsocHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 15000; }
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
2022-03-22 11:35:44 +01:00
LocalDataPoolManager& poolManager) {
2023-05-02 15:04:14 +02:00
localDataPoolMap.emplace(mpsoc::poolid::STATUS, &peStatus);
localDataPoolMap.emplace(mpsoc::poolid::MODE, &peMode);
localDataPoolMap.emplace(mpsoc::poolid::DOWNLINK_PWR_ON, &peDownlinkPwrOn);
2023-05-12 12:14:37 +02:00
localDataPoolMap.emplace(mpsoc::poolid::DOWNLINK_REPLY_ACTIIVE, &peDownlinkReplyActive);
2023-05-02 15:04:14 +02:00
localDataPoolMap.emplace(mpsoc::poolid::DOWNLINK_JESD_SYNC_STATUS, &peDownlinkJesdSyncStatus);
localDataPoolMap.emplace(mpsoc::poolid::DOWNLINK_DAC_STATUS, &peDownlinkDacStatus);
localDataPoolMap.emplace(mpsoc::poolid::CAM_STATUS, &peCameraStatus);
localDataPoolMap.emplace(mpsoc::poolid::CAM_SDI_STATUS, &peCameraSdiStatus);
localDataPoolMap.emplace(mpsoc::poolid::CAM_FPGA_TEMP, &peCameraFpgaTemp);
localDataPoolMap.emplace(mpsoc::poolid::CAM_SOC_TEMP, &peCameraSocTemp);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_TEMP, &peSysmonTemp);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCINT, &peSysmonVccInt);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCAUX, &peSysmonVccAux);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCBRAM, &peSysmonVccBram);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCPAUX, &peSysmonVccPaux);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCPINT, &peSysmonVccPint);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCCPDRO, &peSysmonVccPdro);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_MB12V, &peSysmonMb12V);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_MB3V3, &peSysmonMb3V3);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_MB1V8, &peSysmonMb1V8);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC12V, &peSysmonVcc12V);
2023-05-12 12:14:37 +02:00
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC5V, &peSysmonVcc5V);
2023-05-02 15:04:14 +02:00
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC3V3, &peSysmonVcc3V3);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC3V3VA, &peSysmonVcc3V3VA);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC2V5DDR, &peSysmonVcc2V5DDR);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC1V2DDR, &peSysmonVcc1V2DDR);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC0V9, &peSysmonVcc0V9);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_VCC0V6VTT, &peSysmonVcc0V6VTT);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_SAFE_COTS_CUR, &peSysmonSafeCotsCur);
localDataPoolMap.emplace(mpsoc::poolid::SYSMON_NVM4_XO_CUR, &peSysmonNvm4XoCur);
localDataPoolMap.emplace(mpsoc::poolid::SEM_UNCORRECTABLE_ERRS, &peSemUncorrectableErrs);
localDataPoolMap.emplace(mpsoc::poolid::SEM_CORRECTABLE_ERRS, &peSemCorrectableErrs);
localDataPoolMap.emplace(mpsoc::poolid::SEM_STATUS, &peSemStatus);
localDataPoolMap.emplace(mpsoc::poolid::REBOOT_MPSOC_REQUIRED, &peRebootMpsocRequired);
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(hkReport.getSid(), false, 10.0));
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::handleEvent(EventMessage* eventMessage) {
2022-03-22 11:35:44 +01:00
object_id_t objectId = eventMessage->getReporter();
switch (objectId) {
2022-01-07 09:50:04 +01:00
case objects::PLOC_MPSOC_HELPER: {
2023-05-17 17:33:14 +02:00
specialComHelperExecuting = false;
2022-03-22 11:35:44 +01:00
break;
2022-01-07 09:50:04 +01:00
}
default:
2022-03-22 11:35:44 +01:00
sif::debug << "PlocMPSoCHandler::handleEvent: Did not subscribe to this event" << std::endl;
break;
}
2022-01-07 09:50:04 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcMemWrite(const uint8_t* commandData,
2022-03-22 11:35:44 +01:00
size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
mpsoc::TcMemWrite tcMemWrite(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
result = tcMemWrite.setPayload(commandData, commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcMemWrite);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-04-15 13:17:15 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcMemRead(const uint8_t* commandData,
2022-03-22 11:35:44 +01:00
size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
mpsoc::TcMemRead tcMemRead(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
result = tcMemRead.setPayload(commandData, commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcMemRead);
2022-03-22 11:35:44 +01:00
tmMemReadReport.rememberRequestedSize = tcMemRead.getMemLen() * 4 + TmMemReadReport::FIX_SIZE;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-21 08:35:28 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcFlashDelete(const uint8_t* commandData,
2022-03-22 11:35:44 +01:00
size_t commandDataLen) {
if (commandDataLen > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) {
2022-03-30 09:19:30 +02:00
return MPSoCReturnValuesIF::NAME_TOO_LONG;
2022-03-22 11:35:44 +01:00
}
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
mpsoc::TcFlashDelete tcFlashDelete(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
std::string filename = std::string(reinterpret_cast<const char*>(commandData), commandDataLen);
result = tcFlashDelete.setPayload(filename);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcFlashDelete);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-22 11:35:44 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcReplayStart(const uint8_t* commandData,
2022-03-22 11:35:44 +01:00
size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
mpsoc::TcReplayStart tcReplayStart(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
result = tcReplayStart.setPayload(commandData, commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcReplayStart);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-21 11:05:41 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcReplayStop() {
mpsoc::TcReplayStop tcReplayStop(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
finishTcPrep(tcReplayStop);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-22 11:35:44 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcDownlinkPwrOn(const uint8_t* commandData,
2022-03-22 11:35:44 +01:00
size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
mpsoc::TcDownlinkPwrOn tcDownlinkPwrOn(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
result = tcDownlinkPwrOn.setPayload(commandData, commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcDownlinkPwrOn);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-21 16:21:51 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcDownlinkPwrOff() {
mpsoc::TcDownlinkPwrOff tcDownlinkPwrOff(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
finishTcPrep(tcDownlinkPwrOff);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-21 16:21:51 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcGetHkReport() {
2023-05-12 11:06:26 +02:00
mpsoc::TcGetHkReport tcGetHkReport(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
finishTcPrep(tcGetHkReport);
2023-05-02 13:42:20 +02:00
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcReplayWriteSequence(const uint8_t* commandData,
2022-03-21 16:21:51 +01:00
size_t commandDataLen) {
mpsoc::TcReplayWriteSeq tcReplayWriteSeq(spParams, sequenceCount);
2023-05-17 18:44:12 +02:00
ReturnValue_t result = tcReplayWriteSeq.setPayload(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcReplayWriteSeq);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-21 16:21:51 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcModeReplay() {
mpsoc::TcModeReplay tcModeReplay(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
finishTcPrep(tcModeReplay);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-24 17:39:50 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcModeIdle() {
mpsoc::TcModeIdle tcModeIdle(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
finishTcPrep(tcModeIdle);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-04-20 21:33:39 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcCamCmdSend(const uint8_t* commandData,
2022-04-20 21:33:39 +02:00
size_t commandDataLen) {
mpsoc::TcCamcmdSend tcCamCmdSend(spParams, sequenceCount);
2023-05-17 18:44:12 +02:00
ReturnValue_t result = tcCamCmdSend.setPayload(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcCamCmdSend);
2022-04-20 21:33:39 +02:00
nextReplyId = mpsoc::TM_CAM_CMD_RPT;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-04-20 21:33:39 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcCamTakePic(const uint8_t* commandData,
size_t commandDataLen) {
mpsoc::TcCamTakePic tcCamTakePic(spParams, sequenceCount);
2023-05-17 18:44:12 +02:00
ReturnValue_t result = tcCamTakePic.setPayload(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcCamTakePic);
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcSimplexSendFile(const uint8_t* commandData,
2023-03-13 11:05:21 +01:00
size_t commandDataLen) {
mpsoc::TcSimplexSendFile tcSimplexSendFile(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
ReturnValue_t result = tcSimplexSendFile.setPayload(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcSimplexSendFile);
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcGetDirContent(const uint8_t* commandData,
2023-05-03 15:24:47 +02:00
size_t commandDataLen) {
mpsoc::TcGetDirContent tcGetDirContent(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
ReturnValue_t result = tcGetDirContent.setPayload(commandData, commandDataLen);
2023-05-03 15:24:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcGetDirContent);
2023-05-03 15:24:47 +02:00
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcDownlinkDataModulate(const uint8_t* commandData,
size_t commandDataLen) {
mpsoc::TcDownlinkDataModulate tcDownlinkDataModulate(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
ReturnValue_t result = tcDownlinkDataModulate.setPayload(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
2023-05-16 13:34:06 +02:00
finishTcPrep(tcDownlinkDataModulate);
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::prepareTcModeSnapshot() {
2023-02-14 14:00:53 +01:00
mpsoc::TcModeSnapshot tcModeSnapshot(spParams, sequenceCount);
2023-05-16 13:34:06 +02:00
finishTcPrep(tcModeSnapshot);
2023-02-14 14:00:53 +01:00
return returnvalue::OK;
}
2023-05-16 13:34:06 +02:00
ReturnValue_t PlocMpsocHandler::finishTcPrep(mpsoc::TcBase& tcBase) {
2022-08-19 15:49:22 +02:00
nextReplyId = mpsoc::ACK_REPORT;
2023-05-16 13:34:06 +02:00
ReturnValue_t result = tcBase.finishPacket();
if (result != returnvalue::OK) {
return result;
}
2022-08-19 15:49:22 +02:00
rawPacket = commandBuffer;
2023-05-16 13:34:06 +02:00
rawPacketLen = tcBase.getFullPacketLen();
2022-12-22 17:17:23 +01:00
sequenceCount++;
2023-10-16 14:36:30 +02:00
if (DEBUG_MPSOC_COMMUNICATION) {
sif::debug << "SEND MPSOC packet. APID 0x" << std::hex << std::setw(3) << tcBase.getApid()
<< " Size " << std::dec << tcBase.getFullPacketLen() << " SSC "
<< tcBase.getSeqCount() << std::endl;
}
2023-10-16 14:46:02 +02:00
cmdCountdown.resetTimer();
2023-05-16 13:34:06 +02:00
return returnvalue::OK;
2022-08-19 15:49:22 +02:00
}
2022-01-05 11:26:01 +01:00
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::verifyPacket(const uint8_t* start, size_t foundLen) {
2022-08-19 15:49:22 +02:00
if (CRC::crc16ccitt(start, foundLen) != 0) {
2022-03-22 11:35:44 +01:00
return MPSoCReturnValuesIF::CRC_FAILURE;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-04-11 12:04:13 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::handleAckReport(const uint8_t* data) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2021-04-15 13:17:15 +02:00
2022-03-22 11:35:44 +01:00
result = verifyPacket(data, mpsoc::SIZE_ACK_REPORT);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleAckReport: CRC failure" << std::endl;
2022-03-22 11:35:44 +01:00
nextReplyId = mpsoc::NONE;
replyRawReplyIfnotWiretapped(data, mpsoc::SIZE_ACK_REPORT);
triggerEvent(MPSOC_HANDLER_CRC_FAILURE);
sendFailureReport(mpsoc::ACK_REPORT, MPSoCReturnValuesIF::CRC_FAILURE);
disableAllReplies();
return IGNORE_REPLY_DATA;
}
2021-04-15 13:17:15 +02:00
2022-03-22 11:35:44 +01:00
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
switch (apid) {
case mpsoc::apid::ACK_FAILURE: {
DeviceCommandId_t commandId = getPendingCommand();
2023-05-15 15:15:58 +02:00
uint16_t status = mpsoc::getStatusFromRawData(data);
2023-05-15 15:19:12 +02:00
sif::warning << "MPSoC ACK Failure: " << mpsoc::getStatusString(status) << std::endl;
2022-03-22 11:35:44 +01:00
if (commandId != DeviceHandlerIF::NO_COMMAND_ID) {
2022-03-25 09:08:01 +01:00
triggerEvent(ACK_FAILURE, commandId, status);
2022-03-22 11:35:44 +01:00
}
sendFailureReport(mpsoc::ACK_REPORT, status);
2022-03-22 11:35:44 +01:00
disableAllReplies();
nextReplyId = mpsoc::NONE;
result = IGNORE_REPLY_DATA;
break;
}
case mpsoc::apid::ACK_SUCCESS: {
setNextReplyId();
break;
}
default: {
sif::debug << "PlocMPSoCHandler::handleAckReport: Invalid APID in Ack report" << std::endl;
2022-08-24 17:27:47 +02:00
result = returnvalue::FAILED;
2022-03-22 11:35:44 +01:00
break;
}
}
2021-03-29 14:37:52 +02:00
2022-03-22 11:35:44 +01:00
return result;
2021-03-29 14:37:52 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::handleExecutionReport(const uint8_t* data) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2021-04-15 13:17:15 +02:00
2022-03-22 11:35:44 +01:00
result = verifyPacket(data, mpsoc::SIZE_EXE_REPORT);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleExecutionReport: CRC failure" << std::endl;
2022-03-22 11:35:44 +01:00
nextReplyId = mpsoc::NONE;
return result;
}
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK;
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
switch (apid) {
2022-01-05 11:26:01 +01:00
case (mpsoc::apid::EXE_SUCCESS): {
2023-05-15 13:25:53 +02:00
cmdDoneHandler(true, result);
2022-03-22 11:35:44 +01:00
break;
2021-04-11 12:04:13 +02:00
}
2022-01-05 11:26:01 +01:00
case (mpsoc::apid::EXE_FAILURE): {
2022-03-22 11:35:44 +01:00
DeviceCommandId_t commandId = getPendingCommand();
2023-05-15 14:40:14 +02:00
if (commandId == DeviceHandlerIF::NO_COMMAND_ID) {
2022-03-22 11:35:44 +01:00
sif::debug << "PlocMPSoCHandler::handleExecutionReport: Unknown command id" << std::endl;
}
2023-05-15 15:15:58 +02:00
uint16_t status = mpsoc::getStatusFromRawData(data);
2023-05-15 15:19:12 +02:00
sif::warning << "MPSoC EXE Failure: " << mpsoc::getStatusString(status) << std::endl;
2023-05-15 14:40:14 +02:00
triggerEvent(EXE_FAILURE, commandId, status);
2022-03-22 11:35:44 +01:00
sendFailureReport(mpsoc::EXE_REPORT, MPSoCReturnValuesIF::RECEIVED_EXE_FAILURE);
result = IGNORE_REPLY_DATA;
2023-05-15 13:25:53 +02:00
cmdDoneHandler(false, MPSoCReturnValuesIF::RECEIVED_EXE_FAILURE);
2022-03-22 11:35:44 +01:00
break;
2021-04-11 12:04:13 +02:00
}
default: {
sif::warning << "PlocMPSoCHandler::handleExecutionReport: Unknown APID" << std::endl;
2022-08-24 17:27:47 +02:00
result = returnvalue::FAILED;
2022-03-22 11:35:44 +01:00
break;
}
2022-03-22 11:35:44 +01:00
}
nextReplyId = mpsoc::NONE;
return result;
2021-04-11 12:04:13 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::handleMemoryReadReport(const uint8_t* data) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-22 11:35:44 +01:00
result = verifyPacket(data, tmMemReadReport.rememberRequestedSize);
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleMemoryReadReport: Memory read report has invalid crc"
2022-03-26 20:47:25 +01:00
<< std::endl;
2022-03-22 11:35:44 +01:00
}
uint16_t memLen =
*(data + mpsoc::MEM_READ_RPT_LEN_OFFSET) << 8 | *(data + mpsoc::MEM_READ_RPT_LEN_OFFSET + 1);
/** Send data to commanding queue */
2023-05-03 15:24:47 +02:00
handleDeviceTm(data + mpsoc::DATA_FIELD_OFFSET, mpsoc::SIZE_MEM_READ_RPT_FIX + memLen * 4,
2022-03-22 11:35:44 +01:00
mpsoc::TM_MEMORY_READ_REPORT);
nextReplyId = mpsoc::EXE_REPORT;
return result;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::handleGetHkReport(const uint8_t* data) {
2023-05-02 13:42:20 +02:00
ReturnValue_t result = verifyPacket(data, foundPacketLen);
if (result != returnvalue::OK) {
return result;
}
SpacePacketReader packetReader(data, foundPacketLen);
2023-05-11 20:14:12 +02:00
const uint8_t* dataStart = data + 6;
PoolReadGuard pg(&hkReport);
size_t deserLen = mpsoc::SIZE_TM_HK_REPORT;
SerializeIF::Endianness endianness = SerializeIF::Endianness::NETWORK;
result = SerializeAdapter::deSerialize(&hkReport.status.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.mode.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.downlinkPwrOn.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.downlinkReplyActive.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.downlinkJesdSyncStatus.value, &dataStart,
&deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.downlinkDacStatus.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.camStatus.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.camSdiStatus.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.camFpgaTemp.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonTemp.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccInt.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccAux.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccBram.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccPaux.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccPint.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVccPdro.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonMb12V.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonMb3V3.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonMb1V8.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc12V.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.sysmonVcc5V.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc3V3.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc3V3VA.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc2V5DDR.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc1V2DDR.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc0V9.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonVcc0V6VTT.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonSafeCotsCur.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.sysmonNvm4XoCur.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.semUncorrectableErrs.value, &dataStart,
&deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hkReport.semCorrectableErrs.value, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
result =
SerializeAdapter::deSerialize(&hkReport.semStatus.value, &dataStart, &deserLen, endianness);
if (result != returnvalue::OK) {
return result;
}
// Skip the weird filename
dataStart += 256;
result = SerializeAdapter::deSerialize(&hkReport.rebootMpsocRequired, &dataStart, &deserLen,
endianness);
if (result != returnvalue::OK) {
return result;
}
2023-05-02 13:42:20 +02:00
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::handleCamCmdRpt(const uint8_t* data) {
2023-05-02 13:42:20 +02:00
ReturnValue_t result = verifyPacket(data, foundPacketLen);
2022-04-20 21:33:39 +02:00
if (result == MPSoCReturnValuesIF::CRC_FAILURE) {
sif::warning << "PlocMPSoCHandler::handleCamCmdRpt: CRC failure" << std::endl;
}
2023-05-02 13:42:20 +02:00
SpacePacketReader packetReader(data, foundPacketLen);
const uint8_t* dataFieldPtr = data + mpsoc::SPACE_PACKET_HEADER_SIZE + sizeof(uint16_t);
2023-05-02 13:42:20 +02:00
std::string camCmdRptMsg(reinterpret_cast<const char*>(dataFieldPtr),
foundPacketLen - mpsoc::SPACE_PACKET_HEADER_SIZE - sizeof(uint16_t) - 3);
2022-05-04 19:08:37 +02:00
#if OBSW_DEBUG_PLOC_MPSOC == 1
2022-08-19 21:41:24 +02:00
uint8_t ackValue = *(packetReader.getFullData() + packetReader.getFullPacketLen() - 2);
2022-05-04 19:08:37 +02:00
sif::info << "PlocMPSoCHandler: CamCmdRpt message: " << camCmdRptMsg << std::endl;
sif::info << "PlocMPSoCHandler: CamCmdRpt Ack value: 0x" << std::hex
<< static_cast<unsigned int>(ackValue) << std::endl;
#endif /* OBSW_DEBUG_PLOC_MPSOC == 1 */
2023-05-03 15:24:47 +02:00
handleDeviceTm(packetReader.getPacketData() + sizeof(uint16_t),
2022-08-15 18:34:26 +02:00
packetReader.getPacketDataLen() - 1, mpsoc::TM_CAM_CMD_RPT);
2022-04-20 21:33:39 +02:00
return result;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command,
2022-03-22 11:35:44 +01:00
uint8_t expectedReplies, bool useAlternateId,
DeviceCommandId_t alternateReplyID) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-22 11:35:44 +01:00
uint8_t enabledReplies = 0;
2023-05-03 13:37:20 +02:00
auto enableThreeReplies = [&](DeviceCommandId_t replyId) {
enabledReplies = 3;
result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, replyId);
if (result != returnvalue::OK) {
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id "
<< mpsoc::TM_MEMORY_READ_REPORT << " not in replyMap" << std::endl;
return result;
}
2023-05-11 20:14:12 +02:00
return returnvalue::OK;
2023-05-03 13:37:20 +02:00
};
2022-03-22 11:35:44 +01:00
switch (command->first) {
2022-01-05 11:26:01 +01:00
case mpsoc::TC_MEM_WRITE:
2022-03-21 08:35:28 +01:00
case mpsoc::TC_FLASHDELETE:
2022-03-21 16:21:51 +01:00
case mpsoc::TC_REPLAY_START:
case mpsoc::TC_REPLAY_STOP:
case mpsoc::TC_DOWNLINK_PWR_ON:
case mpsoc::TC_DOWNLINK_PWR_OFF:
case mpsoc::TC_REPLAY_WRITE_SEQUENCE:
2022-03-24 17:39:50 +01:00
case mpsoc::TC_MODE_REPLAY:
2022-04-20 21:33:39 +02:00
case mpsoc::TC_MODE_IDLE:
2023-02-28 09:13:41 +01:00
case mpsoc::TC_CAM_TAKE_PIC:
case mpsoc::TC_SIMPLEX_SEND_FILE:
case mpsoc::TC_DOWNLINK_DATA_MODULATE:
case mpsoc::TC_MODE_SNAPSHOT:
2022-03-22 11:35:44 +01:00
enabledReplies = 2;
break;
2023-05-03 13:37:20 +02:00
case mpsoc::TC_GET_HK_REPORT: {
2023-05-11 20:14:12 +02:00
result = enableThreeReplies(mpsoc::TM_GET_HK_REPORT);
if (result != returnvalue::OK) {
return result;
}
2023-05-03 13:37:20 +02:00
break;
}
2022-01-05 11:26:01 +01:00
case mpsoc::TC_MEM_READ: {
2023-05-11 20:14:12 +02:00
result = enableThreeReplies(mpsoc::TM_MEMORY_READ_REPORT);
if (result != returnvalue::OK) {
return result;
}
2022-04-20 21:33:39 +02:00
break;
}
case mpsoc::TC_CAM_CMD_SEND: {
2023-05-11 20:14:12 +02:00
result = enableThreeReplies(mpsoc::TM_CAM_CMD_RPT);
if (result != returnvalue::OK) {
return result;
}
2022-03-22 11:35:44 +01:00
break;
}
2023-05-03 15:24:47 +02:00
case mpsoc::TC_FLASH_GET_DIRECTORY_CONTENT: {
result = enableThreeReplies(mpsoc::TM_FLASH_DIRECTORY_CONTENT);
if (result != returnvalue::OK) {
return result;
}
break;
}
2022-03-25 09:08:01 +01:00
case mpsoc::OBSW_RESET_SEQ_COUNT:
break;
default:
2022-03-22 11:35:44 +01:00
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Unknown command id" << std::endl;
break;
}
2022-03-22 11:35:44 +01:00
/**
* Every command causes at least one acknowledgment and one execution report. Therefore both
* replies will be enabled here.
*/
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, mpsoc::ACK_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::ACK_REPORT
<< " not in replyMap" << std::endl;
}
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
result =
DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, mpsoc::EXE_REPORT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
sif::debug << "PlocMPSoCHandler::enableReplyInReplyMap: Reply with id " << mpsoc::EXE_REPORT
<< " not in replyMap" << std::endl;
}
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
switch (command->first) {
2022-03-21 16:21:51 +01:00
case mpsoc::TC_REPLAY_WRITE_SEQUENCE: {
2022-03-22 11:35:44 +01:00
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
2022-03-26 20:47:25 +01:00
// Overwrite delay cycles because replay write sequence command can required up to
// 30 seconds for execution
iter->second.delayCycles = mpsoc::TC_WRITE_SEQ_EXECUTION_DELAY;
break;
}
case mpsoc::TC_DOWNLINK_PWR_ON: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
iter->second.delayCycles = mpsoc::TC_DOWNLINK_PWR_ON_EXECUTION_DELAY;
break;
}
case mpsoc::TC_CAM_TAKE_PIC: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
iter->second.delayCycles = mpsoc::TC_CAM_TAKE_PIC_EXECUTION_DELAY;
2022-03-22 11:35:44 +01:00
break;
2022-03-21 16:21:51 +01:00
}
2023-02-28 19:56:42 +01:00
case mpsoc::TC_SIMPLEX_SEND_FILE: {
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
iter->second.delayCycles = mpsoc::TC_SIMPLEX_SEND_FILE_DELAY;
break;
}
2022-03-21 16:21:51 +01:00
default:
2022-03-22 11:35:44 +01:00
break;
}
2022-03-21 16:21:51 +01:00
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::setNextReplyId() {
2022-03-22 11:35:44 +01:00
switch (getPendingCommand()) {
2022-01-05 11:26:01 +01:00
case mpsoc::TC_MEM_READ:
2022-03-22 11:35:44 +01:00
nextReplyId = mpsoc::TM_MEMORY_READ_REPORT;
break;
2023-05-12 15:52:47 +02:00
case mpsoc::TC_FLASH_GET_DIRECTORY_CONTENT: {
nextReplyId = mpsoc::TM_FLASH_DIRECTORY_CONTENT;
break;
}
2023-05-12 11:06:26 +02:00
case mpsoc::TC_GET_HK_REPORT: {
nextReplyId = mpsoc::TM_GET_HK_REPORT;
break;
}
default:
2022-03-22 11:35:44 +01:00
/* If no telemetry is expected the next reply is always the execution report */
nextReplyId = mpsoc::EXE_REPORT;
break;
}
}
2023-05-03 15:24:47 +02:00
2023-05-15 15:15:58 +02:00
size_t PlocMpsocHandler::getNextReplyLength(DeviceCommandId_t commandId) {
2022-03-22 11:35:44 +01:00
size_t replyLen = 0;
2022-03-22 11:35:44 +01:00
if (nextReplyId == mpsoc::NONE) {
return replyLen;
}
2022-03-22 11:35:44 +01:00
DeviceReplyIter iter = deviceReplyMap.find(nextReplyId);
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
if (iter != deviceReplyMap.end()) {
if (iter->second.delayCycles == 0) {
/* Reply inactive */
return replyLen;
}
2022-03-22 11:35:44 +01:00
switch (nextReplyId) {
case mpsoc::TM_MEMORY_READ_REPORT: {
replyLen = tmMemReadReport.rememberRequestedSize;
break;
}
2022-04-20 21:33:39 +02:00
case mpsoc::TM_CAM_CMD_RPT:
2022-04-21 09:31:52 +02:00
// Read acknowledgment, camera and execution report in one go because length of camera
// report is not fixed
replyLen = mpsoc::SP_MAX_SIZE;
2022-04-20 21:33:39 +02:00
break;
2023-05-03 15:30:30 +02:00
case mpsoc::TM_FLASH_DIRECTORY_CONTENT:
// I think the reply size is not fixed either.
replyLen = mpsoc::SP_MAX_SIZE;
break;
2022-03-22 11:35:44 +01:00
default: {
replyLen = iter->second.replyLen;
break;
}
}
2022-03-22 11:35:44 +01:00
} else {
sif::debug << "PlocMPSoCHandler::getNextReplyLength: No entry for reply with reply id "
<< std::hex << nextReplyId << " in deviceReplyMap" << std::endl;
}
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
return replyLen;
2021-04-11 12:04:13 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocHandler::doSendReadHook() {
// Prevent DHB from polling UART during commands executed by the mpsoc helper task
2023-05-17 17:33:14 +02:00
if (specialComHelperExecuting) {
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
MessageQueueIF* PlocMpsocHandler::getCommandQueuePtr() { return commandActionHelperQueue; }
2022-03-30 09:19:30 +02:00
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::stepSuccessfulReceived(ActionId_t actionId, uint8_t step) { return; }
2022-03-30 09:19:30 +02:00
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::stepFailedReceived(ActionId_t actionId, uint8_t step,
2022-04-04 13:40:45 +02:00
ReturnValue_t returnCode) {
switch (actionId) {
2022-05-03 14:59:23 +02:00
case supv::START_MPSOC: {
2022-04-04 13:40:45 +02:00
sif::warning << "PlocMPSoCHandler::stepFailedReceived: Failed to start MPSoC" << std::endl;
break;
2022-05-03 14:59:23 +02:00
}
case supv::SHUTDOWN_MPSOC: {
2022-04-04 13:40:45 +02:00
triggerEvent(MPSOC_SHUTDOWN_FAILED);
sif::warning << "PlocMPSoCHandler::stepFailedReceived: Failed to shutdown MPSoC" << std::endl;
break;
2022-05-03 14:59:23 +02:00
}
2022-04-04 13:40:45 +02:00
default:
sif::debug << "PlocMPSoCHandler::stepFailedReceived: Received unexpected action reply"
<< std::endl;
break;
}
powerState = PowerState::SUPV_FAILED;
2022-03-30 09:19:30 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) {
2022-04-04 13:40:45 +02:00
return;
2022-03-30 09:19:30 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::completionSuccessfulReceived(ActionId_t actionId) {
2023-09-25 17:21:28 +02:00
if (actionId == supv::ACK_REPORT) {
2023-10-16 14:36:30 +02:00
// I seriously don't know why this happens..
// sif::warning
// << "PlocMpsocHandler::completionSuccessfulReceived: Only received ACK report. Consider
// "
// "increasing the MPSoC boot timer."
// << std::endl;
2023-09-25 17:21:28 +02:00
} else if (actionId != supv::EXE_REPORT) {
sif::warning << "PlocMpsocHandler::completionSuccessfulReceived: Did not expect the action "
<< "ID " << actionId << std::endl;
2022-04-04 13:40:45 +02:00
return;
}
switch (powerState) {
2023-09-25 17:10:13 +02:00
case PowerState::PENDING_STARTUP: {
mpsocBootTransitionCd.resetTimer();
powerState = PowerState::DONE;
break;
}
case PowerState::PENDING_SHUTDOWN: {
powerState = PowerState::DONE;
2022-04-04 13:40:45 +02:00
break;
}
default: {
2022-03-30 09:19:30 +02:00
break;
}
2022-04-04 13:40:45 +02:00
}
2022-03-30 09:19:30 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) {
2022-04-04 13:40:45 +02:00
handleActionCommandFailure(actionId);
2022-03-30 09:19:30 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::handleDeviceTm(const uint8_t* data, size_t dataSize,
2022-03-22 11:35:44 +01:00
DeviceCommandId_t replyId) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
if (wiretappingMode == RAW) {
/* Data already sent in doGetRead() */
return;
}
2022-03-22 11:35:44 +01:00
DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId);
if (iter == deviceReplyMap.end()) {
sif::debug << "PlocMPSoCHandler::handleDeviceTM: Unknown reply id" << std::endl;
return;
}
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
if (queueId == NO_COMMANDER) {
return;
}
2021-04-11 12:04:13 +02:00
2022-03-22 11:35:44 +01:00
result = actionHelper.reportData(queueId, replyId, data, dataSize);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-22 11:35:44 +01:00
sif::debug << "PlocMPSoCHandler::handleDeviceTM: Failed to report data" << std::endl;
}
2021-03-29 14:37:52 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::disableAllReplies() {
2022-05-04 19:08:37 +02:00
using namespace mpsoc;
2022-03-22 11:35:44 +01:00
DeviceReplyMap::iterator iter;
2021-03-29 14:37:52 +02:00
2022-03-22 11:35:44 +01:00
/* Disable ack reply */
2022-05-04 19:08:37 +02:00
iter = deviceReplyMap.find(ACK_REPORT);
2022-03-22 11:35:44 +01:00
DeviceReplyInfo* info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
2021-03-29 14:37:52 +02:00
2022-03-22 11:35:44 +01:00
DeviceCommandId_t commandId = getPendingCommand();
2021-03-29 14:37:52 +02:00
2023-05-11 20:14:12 +02:00
auto disableCommandWithReply = [&](DeviceCommandId_t replyId) {
2023-05-03 13:37:20 +02:00
iter = deviceReplyMap.find(replyId);
info = &(iter->second);
info->delayCycles = 0;
info->active = false;
info->command = deviceCommandMap.end();
};
2022-03-22 11:35:44 +01:00
/* If the command expects a telemetry packet the appropriate tm reply will be disabled here */
switch (commandId) {
2022-05-04 19:08:37 +02:00
case TC_MEM_WRITE:
2023-02-28 09:13:41 +01:00
case TC_FLASHDELETE:
case TC_REPLAY_START:
case TC_REPLAY_STOP:
case TC_DOWNLINK_PWR_ON:
case TC_DOWNLINK_PWR_OFF:
case TC_REPLAY_WRITE_SEQUENCE:
case TC_MODE_REPLAY:
case TC_MODE_IDLE:
case TC_CAM_TAKE_PIC:
case TC_SIMPLEX_SEND_FILE:
case TC_DOWNLINK_DATA_MODULATE:
case TC_MODE_SNAPSHOT:
2022-03-22 11:35:44 +01:00
break;
2022-05-04 19:08:37 +02:00
case TC_MEM_READ: {
2023-05-03 13:37:20 +02:00
disableCommandWithReply(TM_MEMORY_READ_REPORT);
break;
}
case TC_GET_HK_REPORT: {
disableCommandWithReply(TM_GET_HK_REPORT);
2022-05-04 19:08:37 +02:00
break;
}
2023-05-03 15:24:47 +02:00
case TC_FLASH_GET_DIRECTORY_CONTENT: {
disableCommandWithReply(TM_FLASH_DIRECTORY_CONTENT);
break;
}
2022-05-04 19:08:37 +02:00
case TC_CAM_CMD_SEND: {
2023-05-03 13:37:20 +02:00
disableCommandWithReply(TM_CAM_CMD_RPT);
2022-03-22 11:35:44 +01:00
break;
}
default: {
2022-05-04 19:08:37 +02:00
sif::debug << "PlocMPSoCHandler::disableAllReplies: Unknown command id: " << commandId
2022-03-22 11:35:44 +01:00
<< std::endl;
break;
}
2022-03-22 11:35:44 +01:00
}
/* We always need to disable the execution report reply here */
2022-03-22 11:35:44 +01:00
disableExeReportReply();
2022-03-26 20:47:25 +01:00
nextReplyId = mpsoc::NONE;
2021-03-29 14:37:52 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) {
2022-03-22 11:35:44 +01:00
DeviceReplyIter iter = deviceReplyMap.find(replyId);
if (iter == deviceReplyMap.end()) {
sif::debug << "PlocMPSoCHandler::sendFailureReport: Reply not in reply map" << std::endl;
return;
}
DeviceCommandInfo* info = &(iter->second.command->second);
if (info == nullptr) {
sif::debug << "PlocMPSoCHandler::sendFailureReport: Reply has no active command" << std::endl;
return;
}
if (info->sendReplyTo != NO_COMMANDER) {
actionHelper.finish(false, info->sendReplyTo, iter->first, status);
}
info->isExecuting = false;
2021-03-29 14:37:52 +02:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::disableExeReportReply() {
2022-03-22 11:35:44 +01:00
DeviceReplyIter iter = deviceReplyMap.find(mpsoc::EXE_REPORT);
DeviceReplyInfo* info = &(iter->second);
info->delayCycles = 0;
info->command = deviceCommandMap.end();
2022-03-26 20:47:25 +01:00
/* Expected replies is set to one here. The value will be set to 0 in replyToReply() */
2022-03-22 11:35:44 +01:00
info->command->second.expectedReplies = 0;
}
2022-03-24 17:39:50 +01:00
void PlocMpsocHandler::stopSpecialComHelper() {
if (specialComHelper != nullptr) {
specialComHelper->stopProcess();
}
specialComHelperExecuting = false;
}
bool PlocMpsocHandler::handleHwStartup() {
#if OBSW_MPSOC_JTAG_BOOT == 1
uartIsolatorSwitch.pullHigh();
startupState = StartupState::WAIT_CYCLES;
return true;
#endif
if (powerState == PowerState::IDLE) {
if (supv::SUPV_ON) {
commandActionHelper.commandAction(supervisorHandler, supv::START_MPSOC);
supvTransitionCd.resetTimer();
powerState = PowerState::PENDING_STARTUP;
} else {
triggerEvent(SUPV_NOT_ON, 1);
// Set back to OFF for now, failing the transition.
setMode(MODE_OFF);
}
}
if (powerState == PowerState::SUPV_FAILED) {
setMode(MODE_OFF);
powerState = PowerState::IDLE;
return false;
}
if (powerState == PowerState::PENDING_STARTUP) {
if (supvTransitionCd.hasTimedOut()) {
// Process with transition nonetheless..
triggerEvent(SUPV_REPLY_TIMEOUT);
powerState = PowerState::DONE;
} else {
return false;
}
}
if (powerState == PowerState::DONE) {
2023-09-25 17:10:13 +02:00
if (mpsocBootTransitionCd.hasTimedOut()) {
// Wait a bit for the MPSoC to fully boot.
uartIsolatorSwitch.pullHigh();
powerState = PowerState::IDLE;
} else {
return false;
}
}
return true;
}
bool PlocMpsocHandler::handleHwShutdown() {
stopSpecialComHelper();
uartIsolatorSwitch.pullLow();
#if OBSW_MPSOC_JTAG_BOOT == 1
powerState = PowerState::DONE;
return true;
#endif
if (powerState == PowerState::IDLE) {
if (supv::SUPV_ON) {
commandActionHelper.commandAction(supervisorHandler, supv::SHUTDOWN_MPSOC);
supvTransitionCd.resetTimer();
powerState = PowerState::PENDING_SHUTDOWN;
} else {
triggerEvent(SUPV_NOT_ON, 0);
powerState = PowerState::DONE;
}
}
if (powerState == PowerState::PENDING_SHUTDOWN) {
if (supvTransitionCd.hasTimedOut()) {
powerState = PowerState::DONE;
// Process with transition nonetheless..
triggerEvent(SUPV_REPLY_TIMEOUT);
return true;
} else {
// Wait till power state is OFF.
return false;
}
}
return true;
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::handleActionCommandFailure(ActionId_t actionId) {
2022-03-30 09:19:30 +02:00
switch (actionId) {
case supv::ACK_REPORT:
case supv::EXE_REPORT:
2022-04-04 13:40:45 +02:00
break;
default:
2023-09-25 17:48:30 +02:00
sif::warning << "PlocMPSoCHandler::handleActionCommandFailure: Did not expect the action ID "
<< actionId << std::endl;
2022-04-04 13:40:45 +02:00
return;
}
switch (powerState) {
case PowerState::PENDING_STARTUP: {
2022-05-03 14:59:23 +02:00
sif::info << "PlocMPSoCHandler::handleActionCommandFailure: MPSoC boot command failed"
2022-05-06 19:53:33 +02:00
<< std::endl;
2022-05-03 14:59:23 +02:00
// This is commonly the case when the MPSoC is already operational. Thus the power state is
// set to on here
2022-04-04 13:40:45 +02:00
break;
}
case PowerState::PENDING_SHUTDOWN: {
2022-05-03 14:59:23 +02:00
// FDIR will intercept event and switch PLOC power off
triggerEvent(MPSOC_SHUTDOWN_FAILED);
2022-04-04 13:40:45 +02:00
sif::warning << "PlocMPSoCHandler::handleActionCommandFailure: Failed to shutdown MPSoC"
<< std::endl;
break;
}
2022-03-30 09:19:30 +02:00
default:
2022-04-04 13:40:45 +02:00
break;
2022-03-30 09:19:30 +02:00
}
powerState = PowerState::SUPV_FAILED;
return;
2022-03-30 09:19:30 +02:00
}
2023-05-15 15:15:58 +02:00
LocalPoolDataSetBase* PlocMpsocHandler::getDataSetHandle(sid_t sid) {
2023-05-02 15:04:14 +02:00
if (sid == hkReport.getSid()) {
return &hkReport;
}
return nullptr;
}
2023-05-15 15:15:58 +02:00
bool PlocMpsocHandler::dontCheckQueue() {
2023-05-15 13:25:53 +02:00
// The TC and TMs need to be handled strictly sequentially, so while a command is pending,
2023-10-16 15:06:02 +02:00
// more specifically while replies are still expected, do not check the queue.
2023-05-15 13:25:53 +02:00
return commandIsPending;
}
2023-05-15 15:15:58 +02:00
void PlocMpsocHandler::cmdDoneHandler(bool success, ReturnValue_t result) {
2023-05-15 13:25:53 +02:00
commandIsPending = false;
auto commandIter = deviceCommandMap.find(getPendingCommand());
if (commandIter != deviceCommandMap.end()) {
commandIter->second.isExecuting = false;
if (commandIter->second.sendReplyTo != MessageQueueIF::NO_QUEUE) {
actionHelper.finish(success, commandIter->second.sendReplyTo, getPendingCommand(), result);
}
}
disableAllReplies();
}
2023-09-29 15:33:09 +02:00
ReturnValue_t PlocMpsocHandler::checkModeCommand(Mode_t commandedMode, Submode_t commandedSubmode,
uint32_t* msToReachTheMode) {
if (commandedMode != MODE_OFF) {
PoolReadGuard pg(&enablePl);
if (pg.getReadResult() == returnvalue::OK) {
2023-10-10 11:54:32 +02:00
if (enablePl.plUseAllowed.isValid() and not enablePl.plUseAllowed.value) {
return NON_OP_STATE_OF_CHARGE;
2023-09-29 15:33:09 +02:00
}
}
}
return DeviceHandlerBase::checkModeCommand(commandedMode, commandedSubmode, msToReachTheMode);
}