From ea606ce21748810f5f4b52d23ce91a58ed081642 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 13 Apr 2023 12:08:31 +0200 Subject: [PATCH] adaptions and possible small fix for update process --- linux/acs/StrComHandler.cpp | 76 ++++++++++++++++++++++--------------- tmtc | 2 +- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/linux/acs/StrComHandler.cpp b/linux/acs/StrComHandler.cpp index 303c2228..4b3500c3 100644 --- a/linux/acs/StrComHandler.cpp +++ b/linux/acs/StrComHandler.cpp @@ -89,7 +89,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) { break; } case InternalState::FIRMWARE_UPDATE: { - replyTimeout.setTimeout(200); + replyTimeout.setTimeout(2000); resetReplyHandlingState(); result = performFirmwareUpdate(); if (result == returnvalue::OK) { @@ -390,7 +390,8 @@ ReturnValue_t StrComHandler::performFlashWrite() { #endif ReturnValue_t result = returnvalue::OK; uint32_t size = 0; - uint32_t bytesWritten = 0; + uint32_t bytesWrittenInRegion = 0; + size_t totalBytesWritten = 0; uint32_t fileSize = 0; struct WriteActionRequest req; @@ -412,20 +413,18 @@ ReturnValue_t StrComHandler::performFlashWrite() { ProgressPrinter progressPrinter("Flash write", fileSize); #endif /* OBSW_DEBUG_STARTRACKER == 1 */ uint32_t fileChunks = fileSize / CHUNK_SIZE; - bytesWritten = 0; + bytesWrittenInRegion = 0; req.region = flashWrite.firstRegion; req.length = CHUNK_SIZE; - for (uint32_t idx = 0; idx < fileChunks; idx++) { - if (terminate) { - return returnvalue::OK; - } - file.seekg(idx * CHUNK_SIZE, file.beg); + + auto writeNextSegment = [&](uint32_t chunkIdx) { + file.seekg(chunkIdx * CHUNK_SIZE, file.beg); file.read(reinterpret_cast(req.data), CHUNK_SIZE); - if (bytesWritten + CHUNK_SIZE > FLASH_REGION_SIZE) { + if (bytesWrittenInRegion + CHUNK_SIZE > FLASH_REGION_SIZE) { req.region++; - bytesWritten = 0; + bytesWrittenInRegion = 0; } - req.address = bytesWritten; + req.address = bytesWrittenInRegion; arc_pack_write_action_req(&req, cmdBuf.data(), &size); result = sendAndRead(size, req.address); if (result != returnvalue::OK) { @@ -435,34 +434,49 @@ ReturnValue_t StrComHandler::performFlashWrite() { if (result != returnvalue::OK) { return result; } - bytesWritten += CHUNK_SIZE; + totalBytesWritten += CHUNK_SIZE; + bytesWrittenInRegion += CHUNK_SIZE; #if OBSW_DEBUG_STARTRACKER == 1 - progressPrinter.print(idx * CHUNK_SIZE); + progressPrinter.print(chunkIdx * CHUNK_SIZE); #endif /* OBSW_DEBUG_STARTRACKER == 1 */ + return result; + }; + + for (uint32_t idx = 0; idx < fileChunks; idx++) { + if (terminate) { + return returnvalue::OK; + } + result = writeNextSegment(idx); + if(result != returnvalue::OK) { + return result; + } if (idx % 50 == 0) { // Some grace time for other tasks TaskFactory::delayTask(2); } } uint32_t remainingBytes = fileSize - fileChunks * CHUNK_SIZE; - file.seekg((fileChunks - 1) * CHUNK_SIZE, file.beg); - file.read(reinterpret_cast(req.data), remainingBytes); - file.close(); - if (bytesWritten + CHUNK_SIZE > FLASH_REGION_SIZE) { - req.region++; - bytesWritten = 0; - } - req.address = bytesWritten; - req.length = remainingBytes; - bytesWritten += remainingBytes; - arc_pack_write_action_req(&req, cmdBuf.data(), &size); - result = sendAndRead(size, req.address); - if (result != returnvalue::OK) { - return result; - } - result = checkActionReply(replyLen); - if (result != returnvalue::OK) { - return result; + if (remainingBytes > 0) { + file.seekg(fileChunks * CHUNK_SIZE, file.beg); + file.read(reinterpret_cast(req.data), remainingBytes); + file.close(); + if (bytesWrittenInRegion + CHUNK_SIZE > FLASH_REGION_SIZE) { + req.region++; + bytesWrittenInRegion = 0; + } + req.address = bytesWrittenInRegion; + req.length = remainingBytes; + totalBytesWritten += CHUNK_SIZE; + bytesWrittenInRegion += remainingBytes; + arc_pack_write_action_req(&req, cmdBuf.data(), &size); + result = sendAndRead(size, req.address); + if (result != returnvalue::OK) { + return result; + } + result = checkActionReply(replyLen); + if (result != returnvalue::OK) { + return result; + } } #if OBSW_DEBUG_STARTRACKER == 1 progressPrinter.print(fileSize); diff --git a/tmtc b/tmtc index 01b3a894..33fd280e 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 01b3a894e66e7f38dd2e7a35e329e99a6199b7f1 +Subproject commit 33fd280e517a55175072ea336c7f8e85bce6e55a