start adding flash read

This commit is contained in:
Robin Müller 2023-05-03 17:46:47 +02:00
parent fa13703394
commit 0a109e552d
3 changed files with 30 additions and 12 deletions

View File

@ -207,7 +207,6 @@ void PlocMPSoCHandler::doShutDown() {
#endif
}
ReturnValue_t PlocMPSoCHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
*id = mpsoc::TC_GET_HK_REPORT;
return buildCommandFromCommand(*id, nullptr, 0);

View File

@ -93,8 +93,8 @@ ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string
}
#endif
flashWrite.obcFile = obcFile;
flashWrite.mpsocFile = mpsocFile;
flashReadAndWrite.obcFile = obcFile;
flashReadAndWrite.mpsocFile = mpsocFile;
internalState = InternalState::FLASH_WRITE;
result = resetHelper();
if (result != returnvalue::OK) {
@ -116,12 +116,14 @@ void PlocMPSoCHelper::stopProcess() { terminate = true; }
ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
ReturnValue_t result = returnvalue::OK;
std::ifstream file(flashReadAndWrite.obcFile, std::ifstream::binary);
if (file.bad()) {
return returnvalue::FAILED;
}
result = flashfopen();
if (result != returnvalue::OK) {
return result;
}
uint8_t tempData[mpsoc::MAX_DATA_SIZE];
std::ifstream file(flashWrite.obcFile, std::ifstream::binary);
// Set position of next character to end of file input stream
file.seekg(0, file.end);
// tellg returns position of character in input stream
@ -139,7 +141,7 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
}
if (file.is_open()) {
file.seekg(bytesRead, file.beg);
file.read(reinterpret_cast<char*>(tempData), dataLength);
file.read(reinterpret_cast<char*>(fileBuf.data()), dataLength);
bytesRead += dataLength;
remainingSize -= dataLength;
} else {
@ -147,7 +149,7 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
}
(*sequenceCount)++;
mpsoc::TcFlashWrite tc(spParams, *sequenceCount);
result = tc.buildPacket(tempData, dataLength);
result = tc.buildPacket(fileBuf.data(), dataLength);
if (result != returnvalue::OK) {
return result;
}
@ -163,12 +165,24 @@ ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
return result;
}
ReturnValue_t PlocMPSoCHelper::performFlashRead() {
std::ofstream ofile(flashReadAndWrite.obcFile);
if (ofile.bad()) {
return returnvalue::FAILED;
}
ReturnValue_t result = flashfopen();
if (result != returnvalue::OK) {
return result;
}
return result;
}
ReturnValue_t PlocMPSoCHelper::flashfopen() {
ReturnValue_t result = returnvalue::OK;
spParams.buf = commandBuffer;
(*sequenceCount)++;
mpsoc::FlashFopen flashFopen(spParams, *sequenceCount);
result = flashFopen.createPacket(flashWrite.mpsocFile, mpsoc::FlashFopen::APPEND);
result = flashFopen.createPacket(flashReadAndWrite.mpsocFile, mpsoc::FlashFopen::APPEND);
if (result != returnvalue::OK) {
return result;
}
@ -184,7 +198,7 @@ ReturnValue_t PlocMPSoCHelper::flashfclose() {
spParams.buf = commandBuffer;
(*sequenceCount)++;
mpsoc::FlashFclose flashFclose(spParams, *sequenceCount);
result = flashFclose.createPacket(flashWrite.mpsocFile);
result = flashFclose.createPacket(flashReadAndWrite.mpsocFile);
if (result != returnvalue::OK) {
return result;
}

View File

@ -111,13 +111,16 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
// buffer
static const int RETRIES = 10000;
struct FlashWrite {
struct FlashInfo {
std::string obcFile;
std::string mpsocFile;
};
struct FlashWrite flashWrite;
struct FlashRead : public FlashInfo {
size_t readSize = 0;
};
struct FlashRead flashReadAndWrite;
#if OBSW_THREAD_TRACING == 1
uint32_t opCounter = 0;
#endif
@ -134,7 +137,8 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
SpacePacketCreator creator;
ploc::SpTcParams spParams = ploc::SpTcParams(creator);
std::array<uint8_t, mpsoc::MAX_REPLY_SIZE> tmBuf;
std::array<uint8_t, mpsoc::MAX_DATA_SIZE> fileBuf{};
std::array<uint8_t, mpsoc::MAX_REPLY_SIZE> tmBuf{};
bool terminate = false;
@ -150,6 +154,7 @@ class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
ReturnValue_t resetHelper();
ReturnValue_t performFlashWrite();
ReturnValue_t performFlashRead();
ReturnValue_t flashfopen();
ReturnValue_t flashfclose();
ReturnValue_t handlePacketTransmission(ploc::SpTcBase& tc);