2021-08-29 07:31:34 +02:00
|
|
|
#include "PlocMemoryDumper.h"
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
#include <fsfw/src/fsfw/serialize/SerializeAdapter.h>
|
|
|
|
|
2021-08-29 07:31:34 +02:00
|
|
|
#include <filesystem>
|
2022-01-17 15:58:27 +01:00
|
|
|
#include <fstream>
|
2021-08-29 07:31:34 +02:00
|
|
|
#include <string>
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
#include "fsfw/ipc/QueueFactory.h"
|
2021-08-29 07:31:34 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
PlocMemoryDumper::PlocMemoryDumper(object_id_t objectId)
|
|
|
|
: SystemObject(objectId), commandActionHelper(this), actionHelper(this, nullptr) {
|
2022-02-22 20:27:13 +01:00
|
|
|
auto mqArgs = MqArgs(this->getObjectId());
|
|
|
|
commandQueue = QueueFactory::instance()->createMessageQueue(
|
|
|
|
QUEUE_SIZE, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
PlocMemoryDumper::~PlocMemoryDumper() {}
|
2021-08-29 07:31:34 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t PlocMemoryDumper::initialize() {
|
|
|
|
ReturnValue_t result = SystemObject::initialize();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = commandActionHelper.initialize();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = actionHelper.initialize(commandQueue);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t PlocMemoryDumper::performOperation(uint8_t operationCode) {
|
2022-01-17 15:58:27 +01:00
|
|
|
readCommandQueue();
|
|
|
|
doStateMachine();
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
|
|
|
|
2022-08-17 19:19:20 +02:00
|
|
|
ReturnValue_t PlocMemoryDumper::executeAction(Action* action) { return action->handle(); }
|
|
|
|
|
|
|
|
ReturnValue_t PlocMemoryDumper::handleAction(DumpMemoryAction* action) {
|
2022-01-17 15:58:27 +01:00
|
|
|
if (state != State::IDLE) {
|
|
|
|
return IS_BUSY;
|
|
|
|
}
|
2021-08-29 07:31:34 +02:00
|
|
|
|
2022-08-17 19:19:20 +02:00
|
|
|
if (action->endAddress <= action->startAddress) {
|
|
|
|
return MRAM_INVALID_ADDRESS_COMBINATION;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-08-17 19:19:20 +02:00
|
|
|
mram.startAddress = action->startAddress;
|
|
|
|
mram.endAddress = action->endAddress;
|
|
|
|
state = State::COMMAND_FIRST_MRAM_DUMP;
|
2021-08-29 07:31:34 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
return EXECUTION_FINISHED;
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
MessageQueueId_t PlocMemoryDumper::getCommandQueue() const { return commandQueue->getId(); }
|
2021-08-29 07:31:34 +02:00
|
|
|
|
2022-08-18 10:42:18 +02:00
|
|
|
ActionHelper* PlocMemoryDumper::getActionHelper() { return &actionHelper; }
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
MessageQueueIF* PlocMemoryDumper::getCommandQueuePtr() { return commandQueue; }
|
2021-08-29 07:31:34 +02:00
|
|
|
|
|
|
|
void PlocMemoryDumper::readCommandQueue() {
|
2022-01-17 15:58:27 +01:00
|
|
|
CommandMessage message;
|
2022-05-10 07:48:36 +02:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
for (result = commandQueue->receiveMessage(&message); result == HasReturnvaluesIF::RETURN_OK;
|
|
|
|
result = commandQueue->receiveMessage(&message)) {
|
|
|
|
if (result != RETURN_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
result = actionHelper.handleActionMessage(&message);
|
|
|
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = commandActionHelper.handleReply(&message);
|
|
|
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
continue;
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
sif::debug << "PlocMemoryDumper::readCommandQueue: Received message with invalid format"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocMemoryDumper::doStateMachine() {
|
2022-01-17 15:58:27 +01:00
|
|
|
switch (state) {
|
2021-08-29 07:31:34 +02:00
|
|
|
case State::IDLE:
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2021-08-29 07:31:34 +02:00
|
|
|
case State::COMMAND_FIRST_MRAM_DUMP:
|
2022-03-30 09:19:30 +02:00
|
|
|
commandNextMramDump(supv::FIRST_MRAM_DUMP);
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2021-08-29 07:31:34 +02:00
|
|
|
case State::COMMAND_CONSECUTIVE_MRAM_DUMP:
|
2022-03-30 09:19:30 +02:00
|
|
|
commandNextMramDump(supv::CONSECUTIVE_MRAM_DUMP);
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2021-08-29 07:31:34 +02:00
|
|
|
case State::EXECUTING_MRAM_DUMP:
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2021-08-29 07:31:34 +02:00
|
|
|
default:
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "PlocMemoryDumper::doStateMachine: Invalid state" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
void PlocMemoryDumper::stepSuccessfulReceived(ActionId_t actionId, uint8_t step) {}
|
2021-08-29 07:31:34 +02:00
|
|
|
|
|
|
|
void PlocMemoryDumper::stepFailedReceived(ActionId_t actionId, uint8_t step,
|
2022-05-06 19:30:20 +02:00
|
|
|
ReturnValue_t returnCode) {
|
|
|
|
triggerEvent(MRAM_DUMP_FAILED);
|
|
|
|
state = State::IDLE;
|
|
|
|
}
|
2021-08-29 07:31:34 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
void PlocMemoryDumper::dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) {}
|
2021-08-29 07:31:34 +02:00
|
|
|
|
|
|
|
void PlocMemoryDumper::completionSuccessfulReceived(ActionId_t actionId) {
|
2022-01-17 15:58:27 +01:00
|
|
|
switch (pendingCommand) {
|
2022-03-30 09:19:30 +02:00
|
|
|
case (supv::FIRST_MRAM_DUMP):
|
|
|
|
case (supv::CONSECUTIVE_MRAM_DUMP):
|
2022-01-17 15:58:27 +01:00
|
|
|
if (mram.endAddress == mram.startAddress) {
|
|
|
|
triggerEvent(MRAM_DUMP_FINISHED);
|
2021-08-29 07:31:34 +02:00
|
|
|
state = State::IDLE;
|
2022-01-17 15:58:27 +01:00
|
|
|
} else {
|
|
|
|
state = State::COMMAND_CONSECUTIVE_MRAM_DUMP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sif::debug << "PlocMemoryDumper::completionSuccessfulReceived: Invalid pending command"
|
|
|
|
<< std::endl;
|
|
|
|
state = State::IDLE;
|
|
|
|
break;
|
|
|
|
}
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
void PlocMemoryDumper::completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) {
|
|
|
|
switch (pendingCommand) {
|
2022-03-30 09:19:30 +02:00
|
|
|
case (supv::FIRST_MRAM_DUMP):
|
|
|
|
case (supv::CONSECUTIVE_MRAM_DUMP):
|
2022-01-17 15:58:27 +01:00
|
|
|
triggerEvent(MRAM_DUMP_FAILED, mram.lastStartAddress);
|
2022-05-05 08:55:45 +02:00
|
|
|
pendingCommand = NONE;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2021-08-29 07:31:34 +02:00
|
|
|
default:
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
state = State::IDLE;
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlocMemoryDumper::commandNextMramDump(ActionId_t dumpCommand) {
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
|
|
|
|
uint32_t tempStartAddress = 0;
|
|
|
|
uint32_t tempEndAddress = 0;
|
|
|
|
|
|
|
|
if (mram.endAddress - mram.startAddress > MAX_MRAM_DUMP_SIZE) {
|
|
|
|
tempStartAddress = mram.startAddress;
|
|
|
|
tempEndAddress = mram.startAddress + MAX_MRAM_DUMP_SIZE;
|
|
|
|
mram.startAddress += MAX_MRAM_DUMP_SIZE;
|
|
|
|
} else {
|
|
|
|
tempStartAddress = mram.startAddress;
|
|
|
|
tempEndAddress = mram.endAddress;
|
|
|
|
mram.startAddress = mram.endAddress;
|
|
|
|
}
|
2022-04-22 18:05:03 +02:00
|
|
|
mram.lastStartAddress = tempStartAddress;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
MemoryParams params(tempStartAddress, tempEndAddress);
|
|
|
|
|
|
|
|
result =
|
2022-08-24 22:29:42 +02:00
|
|
|
commandActionHelper.commandAction(commonObjects::PLOC_SUPERVISOR_HANDLER, dumpCommand, ¶ms);
|
2022-01-17 15:58:27 +01:00
|
|
|
if (result != RETURN_OK) {
|
|
|
|
sif::warning << "PlocMemoryDumper::commandNextMramDump: Failed to send mram dump command "
|
|
|
|
<< "with start address " << tempStartAddress << " and end address "
|
|
|
|
<< tempEndAddress << std::endl;
|
|
|
|
triggerEvent(SEND_MRAM_DUMP_FAILED, result, tempStartAddress);
|
|
|
|
state = State::IDLE;
|
|
|
|
pendingCommand = NONE;
|
2021-08-29 07:31:34 +02:00
|
|
|
return;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
|
|
|
state = State::EXECUTING_MRAM_DUMP;
|
|
|
|
pendingCommand = dumpCommand;
|
|
|
|
return;
|
2021-08-29 07:31:34 +02:00
|
|
|
}
|