From 38ad9f0da272f3bfbabe9981addb6bd87e5f6b4e Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 22 Dec 2021 11:14:27 +0100 Subject: [PATCH] flash read wip --- bsp_q7s/devices/startracker/StrHelper.cpp | 68 +++++++++++++++++++++++ bsp_q7s/devices/startracker/StrHelper.h | 11 +++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/bsp_q7s/devices/startracker/StrHelper.cpp b/bsp_q7s/devices/startracker/StrHelper.cpp index a3d28305..bc4e034f 100644 --- a/bsp_q7s/devices/startracker/StrHelper.cpp +++ b/bsp_q7s/devices/startracker/StrHelper.cpp @@ -295,6 +295,74 @@ ReturnValue_t StrHelper::performFlashWrite() { return RETURN_OK; } +ReturnValue_t StrHelper::performFlashRead() { + ReturnValue_t result; + struct ReadActionRequest req; + uint32_t bytesRead = 0; + uint32_t size = 0; + uint32_t retries = 0; + Timestamp timestamp; + std::string file = flashReadPath + "/" + timestamp.str() + flashReadFile ; + std::ofstream file(file, std::ios_base::app | std::ios_base::out); + if(not std::filesystem::exists(file)) { + return FILE_CREATION_FAILED; + } + req.region = flashReadRegion; + req.address = flashReadAddress; + while(bytesRead < flashReadSize) { + if (terminate) { + return RETURN_OK; + } + if ((flashReadSize - bytesRead) < MAX_FLASH_DATA) { + req.length = flashReadSize - bytesRead; + } + else { + req.length = MAX_FLASH_DATA; + } + arc_pack_read_action_req(&req, commandBuffer, static_cast(req.length)); + + + + + result = sendAndRead(size, downloadReq.position); + if (result != RETURN_OK) { + if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { + uartComIF->flushUartRxBuffer(comCookie); + retries++; + continue; + } + file.close(); + return result; + } + result = checkReply(); + if (result != RETURN_OK) { + if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { + uartComIF->flushUartRxBuffer(comCookie); + retries++; + continue; + } + file.close(); + return result; + } + result = checkReplyPosition(downloadReq.position); + if (result != RETURN_OK) { + if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { + uartComIF->flushUartRxBuffer(comCookie); + retries++; + continue; + } + file.close(); + return result; + } + file.write(reinterpret_cast(datalinkLayer.getReply() + DATA_OFFSET), + IMAGE_DATA_SIZE); + downloadReq.position++; + retries = 0; + } + file.close(); + return RETURN_OK; +} + ReturnValue_t StrHelper::sendAndRead(size_t size, uint32_t parameter) { ReturnValue_t result = RETURN_OK; ReturnValue_t decResult = RETURN_OK; diff --git a/bsp_q7s/devices/startracker/StrHelper.h b/bsp_q7s/devices/startracker/StrHelper.h index f7a994b4..9fd74c7e 100644 --- a/bsp_q7s/devices/startracker/StrHelper.h +++ b/bsp_q7s/devices/startracker/StrHelper.h @@ -174,17 +174,24 @@ private: // File which contains data to write when executing the flash write command std::string flashWriteFile; // Path where the file containing the read data will be stored - std::string flashReadFilePath = ""; + std::string flashReadPath = ""; // Default name of downloaded image, can be changed via command std::string downloadImage = "image"; // Default name of file containing the data read from flash, can be changed via command - std::string flashReadImage = "flashread"; + std::string flashReadFile = "flashread"; // Will be set with the flash write command uint8_t flashWriteRegion = 0; // Will be set with the flash write command and specifies the start address where to write the // flash data to uint32_t flashWriteAddress = 0; + // Will be set with the flash read command + uint8_t flashReadRegion = 0; + // Will be set with the flash read command and specifies the start address of the flash section + // to read + uint32_t flashReadAddress = 0; + // Number of bytes to read from flash + uint32_t flashReadSize = 0; SdCardManager* sdcMan = nullptr;