flash read request
This commit is contained in:
@ -63,6 +63,17 @@ ReturnValue_t StrHelper::performOperation(uint8_t operationCode) {
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
case InternalState::FLASH_READ: {
|
||||
result = performFlashRead();
|
||||
if (result == RETURN_OK){
|
||||
triggerEvent(FLASH_READ_SUCCESSFUL);
|
||||
}
|
||||
else {
|
||||
triggerEvent(FLASH_READ_FAILED);
|
||||
}
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sif::debug << "StrHelper::performOperation: Invalid state" << std::endl;
|
||||
break;
|
||||
@ -121,8 +132,12 @@ void StrHelper::setDownloadImageName(std::string image) {
|
||||
downloadImage = image;
|
||||
}
|
||||
|
||||
void StrHelper::setFlashReadFilename(std::string filename) {
|
||||
flashReadFile = filename;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::startFlashWrite(std::string flashWriteFile_, uint8_t region,
|
||||
uint32_t flashWriteAddress) {
|
||||
uint32_t address) {
|
||||
ReturnValue_t result = checkPath(flashWriteFile_);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
@ -131,12 +146,33 @@ ReturnValue_t StrHelper::startFlashWrite(std::string flashWriteFile_, uint8_t re
|
||||
if(not std::filesystem::exists(flashWriteFile)) {
|
||||
return FILE_NOT_EXISTS;
|
||||
}
|
||||
flashWriteAddress = address;
|
||||
flashWriteRegion = region;
|
||||
internalState = InternalState::FLASH_WRITE;
|
||||
semaphore.release();
|
||||
terminate = false;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::startFlashRead(std::string flashReadFile_, uint8_t region,
|
||||
uint32_t address, uint16_t length) {
|
||||
ReturnValue_t result = checkPath(flashReadFile_);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
flashReadFile = flashReadFile_;
|
||||
if(not std::filesystem::exists(flashReadFile)) {
|
||||
return FILE_NOT_EXISTS;
|
||||
}
|
||||
flashReadAddress = address;
|
||||
flashReadRegion = region;
|
||||
flashReadSize = length;
|
||||
internalState = InternalState::FLASH_READ;
|
||||
semaphore.release();
|
||||
terminate = false;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::performImageDownload() {
|
||||
ReturnValue_t result;
|
||||
struct DownloadActionRequest downloadReq;
|
||||
@ -184,7 +220,7 @@ ReturnValue_t StrHelper::performImageDownload() {
|
||||
file.close();
|
||||
return result;
|
||||
}
|
||||
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + DATA_OFFSET),
|
||||
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + IMAGE_DATA_OFFSET),
|
||||
IMAGE_DATA_SIZE);
|
||||
downloadReq.position++;
|
||||
retries = 0;
|
||||
@ -274,7 +310,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
|
||||
if (result != RETURN_OK) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
result = checkFlashWriteReply(req);
|
||||
result = checkFlashActionReply(req.region, req.address, req.length);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -288,7 +324,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
|
||||
if (result != RETURN_OK) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
result = checkFlashWriteReply(req);
|
||||
result = checkFlashActionReply(req.region, req.address, req.length);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -302,13 +338,12 @@ ReturnValue_t StrHelper::performFlashRead() {
|
||||
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)) {
|
||||
std::string fullname = flashReadPath + "/" + timestamp.str() + flashReadFile ;
|
||||
std::ofstream file(fullname, std::ios_base::app | std::ios_base::out);
|
||||
if (not std::filesystem::exists(fullname)) {
|
||||
return FILE_CREATION_FAILED;
|
||||
}
|
||||
req.region = flashReadRegion;
|
||||
req.address = flashReadAddress;
|
||||
while(bytesRead < flashReadSize) {
|
||||
if (terminate) {
|
||||
return RETURN_OK;
|
||||
@ -319,12 +354,9 @@ ReturnValue_t StrHelper::performFlashRead() {
|
||||
else {
|
||||
req.length = MAX_FLASH_DATA;
|
||||
}
|
||||
arc_pack_read_action_req(&req, commandBuffer, static_cast<uint32_t>(req.length));
|
||||
|
||||
|
||||
|
||||
|
||||
result = sendAndRead(size, downloadReq.position);
|
||||
req.address = flashReadAddress + bytesRead;
|
||||
arc_pack_read_action_req(&req, commandBuffer, &size);
|
||||
result = sendAndRead(size, req.address);
|
||||
if (result != RETURN_OK) {
|
||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||
uartComIF->flushUartRxBuffer(comCookie);
|
||||
@ -344,7 +376,7 @@ ReturnValue_t StrHelper::performFlashRead() {
|
||||
file.close();
|
||||
return result;
|
||||
}
|
||||
result = checkReplyPosition(downloadReq.position);
|
||||
result = checkFlashActionReply(req.region, req.address, req.length);
|
||||
if (result != RETURN_OK) {
|
||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||
uartComIF->flushUartRxBuffer(comCookie);
|
||||
@ -354,9 +386,9 @@ ReturnValue_t StrHelper::performFlashRead() {
|
||||
file.close();
|
||||
return result;
|
||||
}
|
||||
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + DATA_OFFSET),
|
||||
IMAGE_DATA_SIZE);
|
||||
downloadReq.position++;
|
||||
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + FLASH_READ_DATA_OFFSET),
|
||||
req.length);
|
||||
bytesRead += req.length;
|
||||
retries = 0;
|
||||
}
|
||||
file.close();
|
||||
@ -446,8 +478,13 @@ ReturnValue_t StrHelper::checkReplyPosition(uint32_t expectedPosition) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::checkFlashWriteReply(struct WriteActionRequest& req) {
|
||||
ReturnValue_t StrHelper::checkFlashActionReply(uint8_t region_, uint32_t address_,
|
||||
uint16_t length_) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = checkReply();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
const uint8_t* data = datalinkLayer.getReply();
|
||||
uint8_t region = *(data + REGION_OFFSET);
|
||||
uint32_t address;
|
||||
@ -456,7 +493,7 @@ ReturnValue_t StrHelper::checkFlashWriteReply(struct WriteActionRequest& req) {
|
||||
result = SerializeAdapter::deSerialize(&address, &addressData, &size,
|
||||
SerializeIF::Endianness::LITTLE);
|
||||
if (result != RETURN_OK) {
|
||||
sif::warning << "StrHelper::checkFlashWriteReply: Deserialization of address failed"
|
||||
sif::warning << "StrHelper::checkFlashActionReply: Deserialization of address failed"
|
||||
<< std::endl;
|
||||
}
|
||||
uint16_t length;
|
||||
@ -465,16 +502,16 @@ ReturnValue_t StrHelper::checkFlashWriteReply(struct WriteActionRequest& req) {
|
||||
result = SerializeAdapter::deSerialize(&length, lengthData, &size,
|
||||
SerializeIF::Endianness::LITTLE);
|
||||
if (result != RETURN_OK) {
|
||||
sif::warning << "StrHelper::checkFlashWriteReply: Deserialization of length failed"
|
||||
sif::warning << "StrHelper::checkFlashActionReply: Deserialization of length failed"
|
||||
<< std::endl;
|
||||
}
|
||||
if (region != req.region) {
|
||||
if (region != region_) {
|
||||
return REGION_MISMATCH;
|
||||
}
|
||||
if (address != req.address) {
|
||||
if (address != address_) {
|
||||
return ADDRESS_MISMATCH;
|
||||
}
|
||||
if (region != req.length) {
|
||||
if (region != length_) {
|
||||
return LENGTH_MISMATCH;
|
||||
}
|
||||
return RETURN_OK;
|
||||
|
Reference in New Issue
Block a user