flash read wip

This commit is contained in:
Jakob Meier 2021-12-22 11:14:27 +01:00
parent d12027126c
commit 38ad9f0da2
2 changed files with 77 additions and 2 deletions

View File

@ -295,6 +295,74 @@ ReturnValue_t StrHelper::performFlashWrite() {
return RETURN_OK; 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<uint32_t>(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<const char*>(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 StrHelper::sendAndRead(size_t size, uint32_t parameter) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
ReturnValue_t decResult = RETURN_OK; ReturnValue_t decResult = RETURN_OK;

View File

@ -174,17 +174,24 @@ private:
// File which contains data to write when executing the flash write command // File which contains data to write when executing the flash write command
std::string flashWriteFile; std::string flashWriteFile;
// Path where the file containing the read data will be stored // 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 // Default name of downloaded image, can be changed via command
std::string downloadImage = "image"; std::string downloadImage = "image";
// Default name of file containing the data read from flash, can be changed via command // 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 // Will be set with the flash write command
uint8_t flashWriteRegion = 0; uint8_t flashWriteRegion = 0;
// Will be set with the flash write command and specifies the start address where to write the // Will be set with the flash write command and specifies the start address where to write the
// flash data to // flash data to
uint32_t flashWriteAddress = 0; 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; SdCardManager* sdcMan = nullptr;