some improvements
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
Jakob Meier
2021-12-30 13:31:34 +01:00
parent 29e7ac210a
commit ac51ad7a4f
3 changed files with 92 additions and 77 deletions

View File

@ -116,13 +116,13 @@ void StrHelper::setComCookie(CookieIF* comCookie_) {
comCookie = comCookie_;
}
ReturnValue_t StrHelper::startImageUpload(std::string uploadImage_) {
ReturnValue_t result = checkPath(uploadImage_);
ReturnValue_t StrHelper::startImageUpload(std::string fullname) {
ReturnValue_t result = checkPath(fullname);
if (result != RETURN_OK) {
return result;
}
uploadImage = uploadImage_;
if(not std::filesystem::exists(uploadImage)) {
uploadImage.uploadFile = fullname;
if(not std::filesystem::exists(fullname)) {
return FILE_NOT_EXISTS;
}
internalState = InternalState::UPLOAD_FPGA_IMAGE;
@ -131,15 +131,15 @@ ReturnValue_t StrHelper::startImageUpload(std::string uploadImage_) {
return RETURN_OK;
}
ReturnValue_t StrHelper::startImageDownload(std::string downloadImagePath_) {
ReturnValue_t result = checkPath(downloadImagePath_);
ReturnValue_t StrHelper::startImageDownload(std::string path) {
ReturnValue_t result = checkPath(path);
if (result != RETURN_OK) {
return result;
}
if(not std::filesystem::exists(downloadImagePath_)) {
if(not std::filesystem::exists(path)) {
return PATH_NOT_EXISTS;
}
downloadImagePath = downloadImagePath_;
downloadImage.path = path;
internalState = InternalState::DOWNLOAD_IMAGE;
terminate = false;
semaphore.release();
@ -150,49 +150,49 @@ void StrHelper::stopProcess() {
terminate = true;
}
void StrHelper::setDownloadImageName(std::string image) {
downloadImage = image;
void StrHelper::setDownloadImageName(std::string filename) {
downloadImage.filename = filename;
}
void StrHelper::setFlashReadFilename(std::string filename) {
flashReadFile = filename;
flashRead.filename = filename;
}
void StrHelper::setDownloadFpgaImage(std::string filename) {
fpgaDownload.fileName = filename;
}
ReturnValue_t StrHelper::startFlashWrite(std::string flashWriteFile_, uint8_t region,
ReturnValue_t StrHelper::startFlashWrite(std::string fullname, uint8_t region,
uint32_t address) {
ReturnValue_t result = checkPath(flashWriteFile_);
ReturnValue_t result = checkPath(fullname);
if (result != RETURN_OK) {
return result;
}
flashWriteFile = flashWriteFile_;
if(not std::filesystem::exists(flashWriteFile)) {
flashWrite.fullname = fullname;
if(not std::filesystem::exists(flashWrite.fullname)) {
return FILE_NOT_EXISTS;
}
flashWriteAddress = address;
flashWriteRegion = region;
flashWrite.address = address;
flashWrite.region = region;
internalState = InternalState::FLASH_WRITE;
semaphore.release();
terminate = false;
return RETURN_OK;
}
ReturnValue_t StrHelper::startFlashRead(std::string flashReadPath_, uint8_t region,
ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t region,
uint32_t address, uint32_t length) {
ReturnValue_t result = checkPath(flashReadPath_);
ReturnValue_t result = checkPath(path);
if (result != RETURN_OK) {
return result;
}
flashReadPath = flashReadPath_;
if(not std::filesystem::exists(flashReadPath)) {
flashRead.path = path;
if(not std::filesystem::exists(flashRead.path)) {
return FILE_NOT_EXISTS;
}
flashReadAddress = address;
flashReadRegion = region;
flashReadSize = length;
flashRead.address = address;
flashRead.region = region;
flashRead.size = length;
internalState = InternalState::FLASH_READ;
semaphore.release();
terminate = false;
@ -224,7 +224,7 @@ ReturnValue_t StrHelper::performImageDownload() {
uint32_t size = 0;
uint32_t retries = 0;
Timestamp timestamp;
std::string image = downloadImagePath + "/" + timestamp.str() + downloadImage ;
std::string image = downloadImage.path + "/" + timestamp.str() + downloadImage.filename ;
std::ofstream file(image, std::ios_base::app | std::ios_base::out);
if(not std::filesystem::exists(image)) {
return FILE_CREATION_FAILED;
@ -281,12 +281,12 @@ ReturnValue_t StrHelper::performImageUpload() {
struct UploadActionRequest uploadReq;
uploadReq.position = 0;
std::memset(&uploadReq.data, 0, sizeof(uploadReq.data));
if (not std::filesystem::exists(uploadImage)) {
if (not std::filesystem::exists(uploadImage.uploadFile)) {
triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState));
internalState = InternalState::IDLE;
return RETURN_FAILED;
}
std::ifstream file(uploadImage, std::ifstream::binary);
std::ifstream file(uploadImage.uploadFile, 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
@ -332,17 +332,17 @@ ReturnValue_t StrHelper::performFlashWrite() {
uint32_t remainingBytes = 0;
uint32_t fileSize = 0;
struct WriteActionRequest req;
if (not std::filesystem::exists(flashWriteFile)) {
if (not std::filesystem::exists(flashWrite.fullname)) {
triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState));
internalState = InternalState::IDLE;
return RETURN_FAILED;
}
std::ifstream file(flashWriteFile, std::ifstream::binary);
std::ifstream file(flashWrite.fullname, std::ifstream::binary);
file.seekg(0, file.end);
fileSize = file.tellg();
remainingBytes = fileSize;
req.region = flashWriteRegion;
req.address = flashWriteAddress;
req.region = flashWrite.region;
req.address = flashWrite.address;
req.length = MAX_FLASH_DATA;
while(remainingBytes >= MAX_FLASH_DATA) {
if (terminate) {
@ -383,23 +383,23 @@ ReturnValue_t StrHelper::performFlashRead() {
uint32_t size = 0;
uint32_t retries = 0;
Timestamp timestamp;
std::string fullname = flashReadPath + "/" + timestamp.str() + flashReadFile ;
std::string fullname = flashRead.path + "/" + timestamp.str() + flashRead.filename ;
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;
while(bytesRead < flashReadSize) {
req.region = flashRead.region;
while(bytesRead < flashRead.size) {
if (terminate) {
return RETURN_OK;
}
if ((flashReadSize - bytesRead) < MAX_FLASH_DATA) {
req.length = flashReadSize - bytesRead;
if ((flashRead.size - bytesRead) < MAX_FLASH_DATA) {
req.length = flashRead.size - bytesRead;
}
else {
req.length = MAX_FLASH_DATA;
}
req.address = flashReadAddress + bytesRead;
req.address = flashRead.address + bytesRead;
arc_pack_read_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address);
if (result != RETURN_OK) {
@ -503,7 +503,7 @@ ReturnValue_t StrHelper::performFpgaUpload() {
internalState = InternalState::IDLE;
return RETURN_FAILED;
}
std::ifstream file(flashWriteFile, std::ifstream::binary);
std::ifstream file(flashWrite.fullname, std::ifstream::binary);
file.seekg(0, file.end);
fileSize = file.tellg();
req.pos = 0;