eive-obsw/linux/payload/PlocMpsocSpecialComHelper.cpp

518 lines
18 KiB
C++
Raw Normal View History

2023-05-16 11:08:33 +02:00
#include <fsfw/globalfunctions/arrayprinter.h>
2023-05-16 18:41:04 +02:00
#include <fsfw/tasks/TaskFactory.h>
2023-05-15 15:15:58 +02:00
#include <linux/payload/PlocMpsocSpecialComHelper.h>
2023-05-16 18:41:04 +02:00
#include <unistd.h>
2022-03-16 09:01:36 +01:00
2022-01-06 18:05:21 +01:00
#include <filesystem>
2022-03-16 09:01:36 +01:00
#include <fstream>
2022-01-06 18:05:21 +01:00
2024-04-30 15:14:22 +02:00
#include "fsfw/serviceinterface/ServiceInterfacePrinter.h"
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
#include "linux/payload/MpsocCommunication.h"
#include "linux/payload/plocMpsocHelpers.h"
#ifdef XIPHOS_Q7S
2022-09-16 11:53:33 +02:00
#include "bsp_q7s/fs/FilesystemHelper.h"
#endif
2022-08-15 18:34:26 +02:00
using namespace ploc;
2024-04-30 15:14:22 +02:00
PlocMpsocSpecialComHelper::PlocMpsocSpecialComHelper(object_id_t objectId,
MpsocCommunication& comInterface)
: SystemObject(objectId), comInterface(comInterface) {
2022-08-15 18:34:26 +02:00
spParams.buf = commandBuffer;
spParams.maxSize = sizeof(commandBuffer);
}
2022-01-06 18:05:21 +01:00
2023-05-15 15:15:58 +02:00
PlocMpsocSpecialComHelper::~PlocMpsocSpecialComHelper() {}
2022-01-06 18:05:21 +01:00
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::initialize() {
#ifdef XIPHOS_Q7S
2022-03-16 09:01:36 +01:00
sdcMan = SdCardManager::instance();
if (sdcMan == nullptr) {
sif::warning << "PlocMPSoCHelper::initialize: Invalid SD Card Manager" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-03-16 09:01:36 +01:00
}
#endif
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-06 18:05:21 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::performOperation(uint8_t operationCode) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-16 09:01:36 +01:00
semaphore.acquire();
while (true) {
2023-02-14 11:10:18 +01:00
#if OBSW_THREAD_TRACING == 1
trace::threadTrace(opCounter, "PLOC MPSOC Helper");
#endif
2022-03-16 09:01:36 +01:00
switch (internalState) {
case InternalState::IDLE: {
semaphore.acquire();
break;
}
case InternalState::FLASH_WRITE: {
result = performFlashWrite();
2022-08-24 17:27:47 +02:00
if (result == returnvalue::OK) {
2024-04-30 15:14:22 +02:00
triggerEvent(MPSOC_FLASH_WRITE_SUCCESSFUL, txSequenceCount.get());
2022-03-16 09:01:36 +01:00
} else {
2024-04-30 15:14:22 +02:00
triggerEvent(MPSOC_FLASH_WRITE_FAILED, txSequenceCount.get());
2022-01-06 18:05:21 +01:00
}
2022-03-16 09:01:36 +01:00
internalState = InternalState::IDLE;
break;
}
2023-05-03 19:37:10 +02:00
case InternalState::FLASH_READ: {
result = performFlashRead();
if (result == returnvalue::OK) {
2024-04-30 15:14:22 +02:00
triggerEvent(MPSOC_FLASH_READ_SUCCESSFUL, txSequenceCount.get());
2023-05-03 19:37:10 +02:00
} else {
2024-04-30 15:14:22 +02:00
sif::printWarning("PLOC MPSoC Helper: Flash read failed with code %04x\n", result);
triggerEvent(MPSOC_FLASH_READ_FAILED, txSequenceCount.get(), result);
2023-05-03 19:37:10 +02:00
}
internalState = InternalState::IDLE;
break;
}
2022-03-16 09:01:36 +01:00
default:
sif::debug << "PlocMPSoCHelper::performOperation: Invalid state" << std::endl;
break;
2022-01-06 18:05:21 +01:00
}
2022-03-16 09:01:36 +01:00
}
2022-01-06 18:05:21 +01:00
}
2024-04-30 15:14:22 +02:00
void PlocMpsocSpecialComHelper::setCommandSequenceCount(uint16_t sequenceCount_) {
txSequenceCount.set(sequenceCount_);
2022-01-06 18:05:21 +01:00
}
2024-04-30 15:14:22 +02:00
uint16_t PlocMpsocSpecialComHelper::getCommandSequenceCount() const {
return txSequenceCount.get();
2022-01-06 18:05:21 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::startFlashWrite(std::string obcFile,
std::string mpsocFile) {
2023-05-15 14:40:14 +02:00
if (internalState != InternalState::IDLE) {
return returnvalue::FAILED;
}
2023-05-11 20:21:44 +02:00
ReturnValue_t result = startFlashReadOrWriteBase(std::move(obcFile), std::move(mpsocFile));
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-16 09:01:36 +01:00
return result;
}
internalState = InternalState::FLASH_WRITE;
2023-05-15 14:40:14 +02:00
return semaphore.release();
2023-05-03 19:49:45 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::startFlashRead(std::string obcFile, std::string mpsocFile,
size_t readFileSize) {
2023-05-15 14:40:14 +02:00
if (internalState != InternalState::IDLE) {
return returnvalue::FAILED;
}
2023-05-11 20:21:44 +02:00
ReturnValue_t result = startFlashReadOrWriteBase(std::move(obcFile), std::move(mpsocFile));
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-27 13:07:18 +02:00
return result;
2022-03-26 20:47:25 +01:00
}
2023-05-03 19:49:45 +02:00
flashReadAndWrite.totalReadSize = readFileSize;
internalState = InternalState::FLASH_READ;
2023-05-15 14:40:14 +02:00
return semaphore.release();
2022-03-26 20:47:25 +01:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocSpecialComHelper::resetHelper() {
2022-08-15 18:53:25 +02:00
spParams.buf = commandBuffer;
2022-03-16 09:01:36 +01:00
terminate = false;
2024-04-30 15:14:22 +02:00
auto& helper = comInterface.getComHelper();
helper.flushUartRxBuffer();
2022-03-16 09:01:36 +01:00
}
2023-05-15 15:15:58 +02:00
void PlocMpsocSpecialComHelper::stopProcess() { terminate = true; }
2022-03-16 09:01:36 +01:00
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::performFlashWrite() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2023-05-03 17:46:47 +02:00
std::ifstream file(flashReadAndWrite.obcFile, std::ifstream::binary);
if (file.bad()) {
return returnvalue::FAILED;
}
2023-05-17 18:33:48 +02:00
result = flashfopen(mpsoc::FileAccessModes::WRITE | mpsoc::FileAccessModes::OPEN_ALWAYS);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
2022-03-16 12:36:05 +01:00
}
2022-03-16 09:01:36 +01:00
// Set position of next character to end of file input stream
file.seekg(0, file.end);
// tellg returns position of character in input stream
size_t remainingSize = file.tellg();
size_t dataLength = 0;
2022-03-26 20:47:25 +01:00
size_t bytesRead = 0;
2022-03-16 09:01:36 +01:00
while (remainingSize > 0) {
if (terminate) {
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-16 09:01:36 +01:00
}
2023-05-17 18:33:48 +02:00
// The minus 4 is necessary for unknown reasons. Maybe some bug in the ILH software?
if (remainingSize > mpsoc::MAX_FLASH_WRITE_DATA_SIZE - 4) {
dataLength = mpsoc::MAX_FLASH_WRITE_DATA_SIZE - 4;
2022-03-16 09:01:36 +01:00
} else {
dataLength = remainingSize;
}
2023-05-03 19:37:10 +02:00
if (file.bad() or not file.is_open()) {
return FILE_WRITE_ERROR;
2022-03-26 20:47:25 +01:00
}
2023-05-03 19:37:10 +02:00
file.seekg(bytesRead, file.beg);
file.read(reinterpret_cast<char*>(fileBuf.data()), dataLength);
bytesRead += dataLength;
remainingSize -= dataLength;
2024-04-30 15:14:22 +02:00
mpsoc::TcFlashWrite tc(spParams, txSequenceCount);
2023-05-16 18:41:04 +02:00
result = tc.setPayload(fileBuf.data(), dataLength);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-15 18:34:26 +02:00
return result;
}
2023-05-16 18:41:04 +02:00
result = tc.finishPacket();
if (result != returnvalue::OK) {
return result;
}
2024-04-30 15:14:22 +02:00
txSequenceCount.increment();
2023-05-03 19:37:10 +02:00
result = handlePacketTransmissionNoReply(tc);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-16 09:01:36 +01:00
return result;
}
}
2022-03-16 12:36:05 +01:00
result = flashfclose();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
2022-03-16 12:36:05 +01:00
}
2022-03-16 09:01:36 +01:00
return result;
2022-01-06 18:05:21 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::performFlashRead() {
2023-05-03 19:37:10 +02:00
std::error_code e;
if (std::filesystem::exists(flashReadAndWrite.obcFile)) {
// Truncate the file first.
std::ofstream ofile(flashReadAndWrite.obcFile, std::ios::binary | std::ios::trunc);
}
std::ofstream ofile(flashReadAndWrite.obcFile, std::ios::binary | std::ios::app);
if (ofile.bad() or not ofile.is_open()) {
2023-05-03 17:46:47 +02:00
return returnvalue::FAILED;
}
2023-05-17 18:33:48 +02:00
ReturnValue_t result = flashfopen(mpsoc::FileAccessModes::READ);
2023-05-03 17:46:47 +02:00
if (result != returnvalue::OK) {
2023-05-03 19:37:10 +02:00
std::filesystem::remove(flashReadAndWrite.obcFile, e);
2023-05-03 17:46:47 +02:00
return result;
}
2023-05-03 19:37:10 +02:00
size_t readSoFar = 0;
size_t nextReadSize = mpsoc::MAX_FLASH_READ_DATA_SIZE;
while (readSoFar < flashReadAndWrite.totalReadSize) {
if (terminate) {
std::filesystem::remove(flashReadAndWrite.obcFile, e);
return returnvalue::OK;
}
nextReadSize = mpsoc::MAX_FLASH_READ_DATA_SIZE;
if (flashReadAndWrite.totalReadSize - readSoFar < mpsoc::MAX_FLASH_READ_DATA_SIZE) {
nextReadSize = flashReadAndWrite.totalReadSize - readSoFar;
}
if (ofile.bad() or not ofile.is_open()) {
std::filesystem::remove(flashReadAndWrite.obcFile, e);
return FILE_READ_ERROR;
}
2024-04-30 15:14:22 +02:00
mpsoc::TcFlashRead flashReadRequest(spParams, txSequenceCount);
2023-05-16 13:34:06 +02:00
result = flashReadRequest.setPayload(nextReadSize);
if (result != returnvalue::OK) {
std::filesystem::remove(flashReadAndWrite.obcFile, e);
return result;
}
result = flashReadRequest.finishPacket();
2023-05-03 19:37:10 +02:00
if (result != returnvalue::OK) {
std::filesystem::remove(flashReadAndWrite.obcFile, e);
return result;
}
2024-04-30 15:14:22 +02:00
txSequenceCount.increment();
2023-05-16 18:41:04 +02:00
result = handlePacketTransmissionFlashRead(flashReadRequest, ofile, nextReadSize);
2023-05-03 19:37:10 +02:00
if (result != returnvalue::OK) {
std::filesystem::remove(flashReadAndWrite.obcFile, e);
return result;
}
readSoFar += nextReadSize;
}
2023-05-17 17:33:14 +02:00
result = flashfclose();
if (result != returnvalue::OK) {
return result;
}
2023-05-03 17:46:47 +02:00
return result;
}
2023-05-17 18:33:48 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::flashfopen(uint8_t mode) {
2022-08-15 18:53:25 +02:00
spParams.buf = commandBuffer;
2024-04-30 15:14:22 +02:00
mpsoc::TcFlashFopen flashFopen(spParams, txSequenceCount);
2023-05-16 13:34:06 +02:00
ReturnValue_t result = flashFopen.setPayload(flashReadAndWrite.mpsocFile, mode);
if (result != returnvalue::OK) {
return result;
}
result = flashFopen.finishPacket();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-16 12:36:05 +01:00
return result;
}
2024-04-30 15:14:22 +02:00
txSequenceCount.increment();
2023-05-03 19:37:10 +02:00
result = handlePacketTransmissionNoReply(flashFopen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-06 18:05:21 +01:00
return result;
2022-03-16 09:01:36 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-06 18:05:21 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::flashfclose() {
2022-08-15 18:53:25 +02:00
spParams.buf = commandBuffer;
2024-04-30 15:14:22 +02:00
mpsoc::TcFlashFclose flashFclose(spParams, txSequenceCount);
2023-05-16 18:41:04 +02:00
ReturnValue_t result = flashFclose.finishPacket();
if (result != returnvalue::OK) {
return result;
}
2024-04-30 15:14:22 +02:00
txSequenceCount.increment();
2023-05-16 18:41:04 +02:00
result = handlePacketTransmissionNoReply(flashFclose);
if (result != returnvalue::OK) {
return result;
}
return result;
2022-03-26 20:47:25 +01:00
}
2023-05-16 18:41:04 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::handlePacketTransmissionFlashRead(mpsoc::TcFlashRead& tc,
std::ofstream& ofile,
size_t expectedReadLen) {
2023-05-03 19:37:10 +02:00
ReturnValue_t result = sendCommand(tc);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
result = handleAck();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
2023-05-16 18:41:04 +02:00
result = handleTmReception();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
2024-04-30 15:14:22 +02:00
auto& spReader = comInterface.getSpReader();
2023-05-16 18:41:04 +02:00
// We have the nominal case where the flash read report appears first, or the case where we
// get an EXE failure immediately.
if (spReader.getApid() == mpsoc::apid::TM_FLASH_READ_REPORT) {
result = handleFlashReadReply(ofile, expectedReadLen);
if (result != returnvalue::OK) {
return result;
}
return handleExe();
} else if (spReader.getApid() == mpsoc::apid::EXE_FAILURE) {
2024-04-30 15:14:22 +02:00
handleExeFailure(spReader);
2023-05-16 18:41:04 +02:00
} else {
triggerEvent(MPSOC_EXE_INVALID_APID, spReader.getApid(), static_cast<uint32_t>(internalState));
sif::warning << "PLOC MPSoC: Expected execution report "
<< "but received space packet with apid " << std::hex << spReader.getApid()
<< std::endl;
}
return returnvalue::FAILED;
2023-05-03 19:37:10 +02:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::handlePacketTransmissionNoReply(ploc::SpTcBase& tc) {
2023-05-03 19:37:10 +02:00
ReturnValue_t result = sendCommand(tc);
if (result != returnvalue::OK) {
return result;
}
result = handleAck();
if (result != returnvalue::OK) {
return result;
}
return handleExe();
2022-03-16 12:36:05 +01:00
}
2022-03-16 09:01:36 +01:00
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::sendCommand(ploc::SpTcBase& tc) {
2024-04-30 15:14:22 +02:00
ReturnValue_t result = comInterface.send(tc.getFullPacket(), tc.getFullPacketLen());
mpsoc::printTxPacket(tc);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-16 09:01:36 +01:00
sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl;
2022-04-10 18:46:39 +02:00
triggerEvent(MPSOC_SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(internalState));
2022-01-06 18:05:21 +01:00
return result;
2022-03-16 09:01:36 +01:00
}
return result;
2022-01-06 18:05:21 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::handleAck() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2023-05-16 18:41:04 +02:00
result = handleTmReception();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-16 09:01:36 +01:00
return result;
}
2023-05-16 18:41:04 +02:00
result = checkReceivedTm();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-15 18:34:26 +02:00
return result;
}
2024-04-30 15:14:22 +02:00
const auto& spReader = comInterface.getSpReader();
2023-05-17 17:33:14 +02:00
uint16_t apid = spReader.getApid();
2022-03-16 09:01:36 +01:00
if (apid != mpsoc::apid::ACK_SUCCESS) {
2023-05-17 17:33:14 +02:00
handleAckApidFailure(spReader);
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-03-16 09:01:36 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-06 18:05:21 +01:00
}
2024-04-30 15:14:22 +02:00
void PlocMpsocSpecialComHelper::handleAckApidFailure(const SpacePacketReader& reader) {
2023-05-15 15:15:58 +02:00
uint16_t apid = reader.getApid();
2022-03-16 09:01:36 +01:00
if (apid == mpsoc::apid::ACK_FAILURE) {
2023-05-15 15:15:58 +02:00
uint16_t status = mpsoc::getStatusFromRawData(reader.getFullData());
2023-05-16 18:41:04 +02:00
sif::warning << "PLOC MPSoC ACK Failure: " << mpsoc::getStatusString(status) << std::endl;
2023-05-15 15:15:58 +02:00
triggerEvent(MPSOC_ACK_FAILURE_REPORT, static_cast<uint32_t>(internalState), status);
2022-03-16 09:01:36 +01:00
} else {
2022-04-10 18:46:39 +02:00
triggerEvent(MPSOC_ACK_INVALID_APID, apid, static_cast<uint32_t>(internalState));
2022-03-16 09:01:36 +01:00
sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Expected acknowledgement report "
<< "but received space packet with apid " << std::hex << apid << std::endl;
}
2022-01-06 18:05:21 +01:00
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::handleExe() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-08-15 18:34:26 +02:00
2023-05-16 18:41:04 +02:00
result = handleTmReception();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-15 18:34:26 +02:00
return result;
}
2023-05-16 18:41:04 +02:00
result = checkReceivedTm();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-16 09:01:36 +01:00
return result;
}
2024-04-30 15:14:22 +02:00
const auto& spReader = comInterface.getSpReader();
2023-05-16 18:41:04 +02:00
uint16_t apid = spReader.getApid();
if (apid == mpsoc::apid::EXE_FAILURE) {
2024-04-30 15:14:22 +02:00
handleExeFailure(spReader);
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2023-05-16 18:41:04 +02:00
} else if (apid != mpsoc::apid::EXE_SUCCESS) {
triggerEvent(MPSOC_EXE_INVALID_APID, apid, static_cast<uint32_t>(internalState));
sif::warning << "PLOC MPSoC: Expected execution report "
<< "but received space packet with apid " << std::hex << apid << std::endl;
2022-03-16 09:01:36 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-06 18:05:21 +01:00
}
2024-04-30 15:14:22 +02:00
void PlocMpsocSpecialComHelper::handleExeFailure(const SpacePacketReader& spReader) {
2023-05-16 18:41:04 +02:00
uint16_t status = mpsoc::getStatusFromRawData(spReader.getFullData());
sif::warning << "PLOC MPSoC EXE Failure: " << mpsoc::getStatusString(status) << std::endl;
triggerEvent(MPSOC_EXE_FAILURE_REPORT, static_cast<uint32_t>(internalState));
2022-01-06 18:05:21 +01:00
}
2023-05-16 18:41:04 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::handleTmReception() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2023-05-16 18:41:04 +02:00
tmCountdown.resetTimer();
uint32_t usleepDelay = 5;
while (true) {
if (tmCountdown.hasTimedOut()) {
triggerEvent(MPSOC_READ_TIMEOUT, tmCountdown.getTimeoutMs());
return returnvalue::FAILED;
}
2024-04-30 15:14:22 +02:00
result = tryReceiveNextReply();
if (result == MpsocCommunication::PACKET_RECEIVED) {
// Need to convert this, we are faking a synchronous API here.
result = returnvalue::OK;
2022-03-16 09:01:36 +01:00
break;
}
2024-04-30 15:14:22 +02:00
if (result != returnvalue::OK) {
if (result == MpsocCommunication::FAULTY_PACKET_SIZE) {
sif::printWarning("PLOC MPSoC Helper: retrieving next reply failed: faulty packet size\n");
} else if (result == MpsocCommunication::CRC_CHECK_FAILED) {
sif::printWarning("PLOC MPSoC Helper: retrieving next reply failed: CRC check failed\n");
}
sif::printWarning("PLOC MPSoC Helper: retrieving next reply failed with code %d\n", result);
return result;
2023-05-16 18:41:04 +02:00
}
usleep(usleepDelay);
if (usleepDelay < 200000) {
usleepDelay *= 4;
}
2022-03-16 09:01:36 +01:00
}
2022-08-15 18:34:26 +02:00
return result;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::handleFlashReadReply(std::ofstream& ofile,
size_t expectedReadLen) {
2023-05-16 18:41:04 +02:00
ReturnValue_t result = checkReceivedTm();
2023-05-03 19:37:10 +02:00
if (result != returnvalue::OK) {
return result;
}
2024-04-30 15:14:22 +02:00
auto& spReader = comInterface.getSpReader();
2023-05-16 18:41:04 +02:00
uint16_t apid = spReader.getApid();
2023-05-03 19:37:10 +02:00
if (apid != mpsoc::apid::TM_FLASH_READ_REPORT) {
triggerEvent(MPSOC_FLASH_READ_PACKET_ERROR, FlashReadErrorType::FLASH_READ_APID_ERROR);
sif::warning << "PLOC MPSoC Flash Read: Unexpected APID" << std::endl;
return result;
}
2023-05-16 18:41:04 +02:00
const uint8_t* packetData = spReader.getPacketData();
size_t deserDummy = spReader.getPacketDataLen() - mpsoc::CRC_SIZE;
2023-05-03 19:37:10 +02:00
uint32_t receivedReadLen = 0;
2023-05-17 18:33:48 +02:00
// I think this is buggy, weird stuff in the short name field.
2023-05-17 17:33:14 +02:00
// std::string receivedShortName = std::string(reinterpret_cast<const char*>(packetData), 12);
// if (receivedShortName != flashReadAndWrite.mpsocFile.substr(0, 11)) {
// sif::warning << "PLOC MPSoC Flash Read: Missmatch between request file name and "
// "received file name"
// << std::endl;
// triggerEvent(MPSOC_FLASH_READ_PACKET_ERROR, FlashReadErrorType::FLASH_READ_FILENAME_ERROR);
// return returnvalue::FAILED;
// }
2023-05-03 19:37:10 +02:00
packetData += 12;
result = SerializeAdapter::deSerialize(&receivedReadLen, &packetData, &deserDummy,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
if (receivedReadLen != expectedReadLen) {
sif::warning << "PLOC MPSoC Flash Read: Missmatch between request read length and "
"received read length"
<< std::endl;
triggerEvent(MPSOC_FLASH_READ_PACKET_ERROR, FlashReadErrorType::FLASH_READ_READLEN_ERROR);
return returnvalue::FAILED;
}
ofile.write(reinterpret_cast<const char*>(packetData), receivedReadLen);
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::fileCheck(std::string obcFile) {
2023-05-03 19:49:45 +02:00
#ifdef XIPHOS_Q7S
ReturnValue_t result = FilesystemHelper::checkPath(obcFile);
if (result != returnvalue::OK) {
return result;
}
#elif defined(TE0720_1CFA)
if (not std::filesystem::exists(obcFile)) {
sif::warning << "PlocMPSoCHelper::startFlashWrite: File " << obcFile << "does not exist"
<< std::endl;
return returnvalue::FAILED;
}
#endif
return returnvalue::OK;
}
2023-05-15 15:15:58 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::startFlashReadOrWriteBase(std::string obcFile,
std::string mpsocFile) {
2023-05-03 19:49:45 +02:00
ReturnValue_t result = fileCheck(obcFile);
if (result != returnvalue::OK) {
return result;
}
2023-05-11 20:21:44 +02:00
flashReadAndWrite.obcFile = std::move(obcFile);
flashReadAndWrite.mpsocFile = std::move(mpsocFile);
2023-05-15 14:40:14 +02:00
resetHelper();
return returnvalue::OK;
2023-05-03 19:49:45 +02:00
}
2023-05-16 18:41:04 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::checkReceivedTm() {
2024-04-30 15:14:22 +02:00
const auto& spReader = comInterface.getSpReader();
2023-05-16 18:41:04 +02:00
ReturnValue_t result = spReader.checkSize();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2023-05-16 18:41:04 +02:00
sif::error << "PLOC MPSoC: Size check on received TM failed" << std::endl;
2022-08-15 18:34:26 +02:00
triggerEvent(MPSOC_TM_SIZE_ERROR);
return result;
}
2024-04-30 15:14:22 +02:00
rxSequenceCount = spReader.getSequenceCount();
mpsoc::printRxPacket(spReader);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-06 18:05:21 +01:00
}
2024-04-30 15:14:22 +02:00
ReturnValue_t PlocMpsocSpecialComHelper::tryReceiveNextReply() {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2024-04-30 15:14:22 +02:00
result = comInterface.readSerialInterface();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-16 09:01:36 +01:00
triggerEvent(MPSOC_HELPER_REQUESTING_REPLY_FAILED, result,
static_cast<uint32_t>(static_cast<uint32_t>(internalState)));
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-03-16 09:01:36 +01:00
}
2024-04-30 15:14:22 +02:00
return comInterface.parseAndRetrieveNextPacket();
2022-01-06 18:05:21 +01:00
}