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;

View File

@ -90,38 +90,37 @@ public:
/**
* @brief Starts sequence to upload image to star tracker
*
* @param image Name including absolute path if to image to upload. Must be previously
* transferred to the OBC with the CFDP protocoll.
* @param uploadImage_ Name including absolute path of the image to upload. Must be previously
* transferred to the OBC with the CFDP protocol.
*/
ReturnValue_t startImageUpload(std::string uploadImage_);
/**
* @brief Calling this function initiates the download of an image from the star tracker.
*
* @param Name of the image which will be created
* @param path Path where downloaded image will be stored
*/
ReturnValue_t startImageDownload(std::string downloadImagePath_);
ReturnValue_t startImageDownload(std::string path);
/**
* @brief Starts the flash write procedure
*
* @param flashWriteFile_ Full name including absolute path of file to write to flash
* @param fullname Full name including absolute path of file to write to flash
* @param region Region ID of flash region to write to
* @param address Start address of flash write procedure
*/
ReturnValue_t startFlashWrite(std::string flashWriteFile_, uint8_t region,
uint32_t address);
ReturnValue_t startFlashWrite(std::string fullname, uint8_t region, uint32_t address);
/**
* @brief Starts the flash read procedure
*
* @param flashWriteFile_ Full name including absolute path of file to write to flash
* @param path Path where file with read flash data will be created
* @param region Region ID of flash region to read from
* @param flashWriteAddress Start address of flash section to read
* @param address Start address of flash section to read
* @param length Number of bytes to read from flash
*/
ReturnValue_t startFlashRead(std::string flashReadPath_, uint8_t region,
uint32_t address, uint32_t length);
ReturnValue_t startFlashRead(std::string path, uint8_t region, uint32_t address,
uint32_t length);
/**
* @brief Starts the download of the FPGA image
@ -148,7 +147,7 @@ public:
/**
* @brief Changes the dafault name of downloaded images
*/
void setDownloadImageName(std::string image);
void setDownloadImageName(std::string filename);
/**
* @brief Sets the name of the file which will be created to store the data read from flash
@ -204,7 +203,6 @@ private:
// Name of file containing downloaded FPGA image
std::string fileName = "fpgaimage.bin";
};
FpgaDownload fpgaDownload;
class FpgaUpload {
@ -213,7 +211,6 @@ private:
// Full name of file to upload
std::string uploadFile;
};
FpgaUpload fpgaUpload;
static const uint32_t MAX_POLLS = 10000;
@ -245,31 +242,49 @@ private:
BinarySemaphore semaphore;
// Name including absolute path of image to upload
std::string uploadImage;
// Path where the downloaded image will be stored
std::string downloadImagePath;
// 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 flashReadPath = "";
class UploadImage {
public:
// Name including absolute path of image to upload
std::string uploadFile;
};
UploadImage uploadImage;
// Default name of downloaded image, can be changed via command
std::string downloadImage = "image.bin";
// Default name of file containing the data read from flash, can be changed via command
std::string flashReadFile = "flashread.bin";
// 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;
class DownloadImage {
public:
// Path where the downloaded image will be stored
std::string path;
// Default name of downloaded image, can be changed via command
std::string filename = "image.bin";
};
DownloadImage downloadImage;
class FlashWrite {
public:
// File which contains data to write when executing the flash write command
std::string fullname;
// Will be set with the flash write command
uint8_t region = 0;
// Will be set with the flash write command and specifies the start address where to write the
// flash data to
uint32_t address = 0;
};
FlashWrite flashWrite;
class FlashRead {
public:
// Path where the file containing the read data will be stored
std::string path = "";
// Default name of file containing the data read from flash, can be changed via command
std::string filename = "flashread.bin";
// Will be set with the flash read command
uint8_t region = 0;
// Will be set with the flash read command and specifies the start address of the flash section
// to read
uint32_t address = 0;
// Number of bytes to read from flash
uint32_t size = 0;
};
FlashRead flashRead;
SdCardManager* sdcMan = nullptr;

2
tmtc

@ -1 +1 @@
Subproject commit e3950bbbcca825b07c40b16658127210a9fe5fe2
Subproject commit 418ecb815b00d5d2081b8d55a480f4c13a0f7139