fpga download image command
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit
This commit is contained in:
@ -74,6 +74,17 @@ ReturnValue_t StrHelper::performOperation(uint8_t operationCode) {
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
case InternalState::DOWNLOAD_FPGA_IMAGE: {
|
||||
result = performFpgaDownload();
|
||||
if (result == RETURN_OK){
|
||||
triggerEvent(FPGA_DOWNLOAD_SUCCESSFUL);
|
||||
}
|
||||
else {
|
||||
triggerEvent(FPGA_DOWNLOAD_FAILED);
|
||||
}
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sif::debug << "StrHelper::performOperation: Invalid state" << std::endl;
|
||||
break;
|
||||
@ -109,15 +120,15 @@ ReturnValue_t StrHelper::startImageUpload(std::string uploadImage_) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::startImageDownload(std::string downloadPath_) {
|
||||
ReturnValue_t result = checkPath(downloadPath_);
|
||||
ReturnValue_t StrHelper::startImageDownload(std::string downloadImagePath_) {
|
||||
ReturnValue_t result = checkPath(downloadImagePath_);
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if(not std::filesystem::exists(downloadPath_)) {
|
||||
if(not std::filesystem::exists(downloadImagePath_)) {
|
||||
return PATH_NOT_EXISTS;
|
||||
}
|
||||
downloadPath = downloadPath_;
|
||||
downloadImagePath = downloadImagePath_;
|
||||
internalState = InternalState::DOWNLOAD_IMAGE;
|
||||
terminate = false;
|
||||
semaphore.release();
|
||||
@ -173,19 +184,30 @@ ReturnValue_t StrHelper::startFlashRead(std::string flashReadPath_, uint8_t regi
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::startFpgaDownload(std::string path, uint32_t startPosition,
|
||||
uint32_t length) {
|
||||
fpgaDownload.path = path;
|
||||
fpgaDownload.startPosition = startPosition;
|
||||
fpgaDownload.length = length;
|
||||
internalState = InternalState::DOWNLOAD_FPGA_IMAGE;
|
||||
semaphore.release();
|
||||
terminate = false;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::performImageDownload() {
|
||||
ReturnValue_t result;
|
||||
struct DownloadActionRequest downloadReq;
|
||||
uint32_t size = 0;
|
||||
uint32_t retries = 0;
|
||||
Timestamp timestamp;
|
||||
std::string image = downloadPath + "/" + timestamp.str() + downloadImage ;
|
||||
std::string image = downloadImagePath + "/" + timestamp.str() + downloadImage ;
|
||||
std::ofstream file(image, std::ios_base::app | std::ios_base::out);
|
||||
if(not std::filesystem::exists(image)) {
|
||||
return FILE_CREATION_FAILED;
|
||||
}
|
||||
downloadReq.position = 0;
|
||||
while(downloadReq.position < LAST_POSITION) {
|
||||
while(downloadReq.position < ImageDownload::LAST_POSITION) {
|
||||
if (terminate) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
@ -200,7 +222,7 @@ ReturnValue_t StrHelper::performImageDownload() {
|
||||
file.close();
|
||||
return result;
|
||||
}
|
||||
result = checkReply();
|
||||
result = checkActionReply();
|
||||
if (result != RETURN_OK) {
|
||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||
uartComIF->flushUartRxBuffer(comCookie);
|
||||
@ -257,7 +279,7 @@ ReturnValue_t StrHelper::performImageUpload() {
|
||||
if (result != RETURN_OK) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
result = checkReply();
|
||||
result = checkActionReply();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -274,7 +296,7 @@ ReturnValue_t StrHelper::performImageUpload() {
|
||||
if (result != RETURN_OK) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
result = checkReply();
|
||||
result = checkActionReply();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -366,7 +388,7 @@ ReturnValue_t StrHelper::performFlashRead() {
|
||||
file.close();
|
||||
return result;
|
||||
}
|
||||
result = checkReply();
|
||||
result = checkActionReply();
|
||||
if (result != RETURN_OK) {
|
||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||
uartComIF->flushUartRxBuffer(comCookie);
|
||||
@ -395,6 +417,58 @@ ReturnValue_t StrHelper::performFlashRead() {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::performFpgaDownload() {
|
||||
ReturnValue_t result;
|
||||
struct DownloadFPGAImageActionRequest req;
|
||||
uint32_t size = 0;
|
||||
uint32_t retries = 0;
|
||||
Timestamp timestamp;
|
||||
std::string image = fpgaDownload.path + "/" + timestamp.str() + fpgaDownload.fileName;
|
||||
std::ofstream file(image, std::ios_base::app | std::ios_base::out);
|
||||
if(not std::filesystem::exists(image)) {
|
||||
return FILE_CREATION_FAILED;
|
||||
}
|
||||
req.pos = fpgaDownload.startPosition;
|
||||
while(req.pos < fpgaDownload.length) {
|
||||
if (terminate) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
if (fpgaDownload.length - req.pos >= FpgaDownload::MAX_DATA) {
|
||||
req.length = FpgaDownload::MAX_DATA;
|
||||
}
|
||||
else {
|
||||
req.length = fpgaDownload.length - req.pos;
|
||||
}
|
||||
arc_pack_downloadfpgaimage_action_req(&req, commandBuffer, &size);
|
||||
result = sendAndRead(size, req.pos);
|
||||
if (result != RETURN_OK) {
|
||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||
uartComIF->flushUartRxBuffer(comCookie);
|
||||
retries++;
|
||||
continue;
|
||||
}
|
||||
file.close();
|
||||
return result;
|
||||
}
|
||||
result = checkFpgaDownloadReply(req.pos, req.length);
|
||||
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() + FpgaDownload::DATA_OFFSET),
|
||||
req.length);
|
||||
req.pos += req.length;
|
||||
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;
|
||||
@ -451,16 +525,16 @@ ReturnValue_t StrHelper::sendAndRead(size_t size, uint32_t parameter) {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::checkReply() {
|
||||
ReturnValue_t StrHelper::checkActionReply() {
|
||||
uint8_t type = datalinkLayer.getReplyFrameType();
|
||||
if (type != TMTC_ACTIONREPLY) {
|
||||
sif::warning << "StrHelper::checkReply: Received reply with invalid type ID"
|
||||
sif::warning << "StrHelper::checkActionReply: Received reply with invalid type ID"
|
||||
<< std::endl;
|
||||
return INVALID_TYPE_ID;
|
||||
}
|
||||
uint8_t status = datalinkLayer.getStatusField();
|
||||
if (status != ArcsecDatalinkLayer::STATUS_OK) {
|
||||
sif::warning << "StrHelper::checkReply: Status failure: "
|
||||
sif::warning << "StrHelper::checkActionReply: Status failure: "
|
||||
<< static_cast<unsigned int>(status) << std::endl;
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
@ -480,7 +554,7 @@ ReturnValue_t StrHelper::checkReplyPosition(uint32_t expectedPosition) {
|
||||
ReturnValue_t StrHelper::checkFlashActionReply(uint8_t region_, uint32_t address_,
|
||||
uint16_t length_) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = checkReply();
|
||||
result = checkActionReply();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
@ -494,6 +568,7 @@ ReturnValue_t StrHelper::checkFlashActionReply(uint8_t region_, uint32_t address
|
||||
if (result != RETURN_OK) {
|
||||
sif::warning << "StrHelper::checkFlashActionReply: Deserialization of address failed"
|
||||
<< std::endl;
|
||||
return result;
|
||||
}
|
||||
uint16_t length;
|
||||
size = sizeof(length);
|
||||
@ -516,6 +591,35 @@ ReturnValue_t StrHelper::checkFlashActionReply(uint8_t region_, uint32_t address
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::checkFpgaDownloadReply(uint32_t expectedPosition,
|
||||
uint32_t expectedLength) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = checkActionReply();
|
||||
if (result != RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
const uint8_t* data = datalinkLayer.getReply() + FpgaDownload::POSITION_OFFSET;
|
||||
uint32_t position;
|
||||
size_t size = sizeof(position);
|
||||
result = SerializeAdapter::deSerialize(&position, &data, &size,
|
||||
SerializeIF::Endianness::LITTLE);
|
||||
if (result != RETURN_OK) {
|
||||
sif::warning << "StrHelper::checkFpgaDownloadReply: Deserialization of position failed"
|
||||
<< std::endl;
|
||||
return result;
|
||||
}
|
||||
uint32_t length;
|
||||
size = sizeof(length);
|
||||
result = SerializeAdapter::deSerialize(&length, &data, &size,
|
||||
SerializeIF::Endianness::LITTLE);
|
||||
if (result != RETURN_OK) {
|
||||
sif::warning << "StrHelper::checkFpgaDownloadReply: Deserialization of length failed"
|
||||
<< std::endl;
|
||||
return result;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t StrHelper::checkPath(std::string name) {
|
||||
if (name.substr(0, sizeof(SdCardManager::SD_0_MOUNT_POINT))
|
||||
== std::string(SdCardManager::SD_0_MOUNT_POINT)) {
|
||||
|
Reference in New Issue
Block a user