progress printer
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Jakob Meier
2022-03-01 17:17:15 +01:00
parent 6b88c525b2
commit 57b815c8ee
6 changed files with 87 additions and 30 deletions

View File

@ -7,6 +7,7 @@
#include "fsfw/timemanager/Countdown.h"
#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h"
#include "mission/utility/Timestamp.h"
#include "mission/utility/ProgressPrinter.h"
StrHelper::StrHelper(object_id_t objectId) : SystemObject(objectId) {}
@ -174,6 +175,9 @@ void StrHelper::enableTimestamping() { timestamping = true; }
ReturnValue_t StrHelper::performImageDownload() {
ReturnValue_t result;
#if OBSW_DEBUG_STARTRACKER == 1
ProgressPrinter progressPrinter("Image download", ImageDownload::LAST_POSITION);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
struct DownloadActionRequest downloadReq;
uint32_t size = 0;
uint32_t retries = 0;
@ -221,10 +225,10 @@ ReturnValue_t StrHelper::performImageDownload() {
}
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + IMAGE_DATA_OFFSET),
CHUNK_SIZE);
downloadReq.position++;
#if OBSW_DEBUG_STARTRACKER == 1
printProgress(downloadReq.position, ImageDownload::LAST_POSITION);
progressPrinter.print(downloadReq.position);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
downloadReq.position++;
retries = 0;
}
file.close();
@ -248,6 +252,9 @@ ReturnValue_t StrHelper::performImageUpload() {
file.seekg(0, file.end);
// tellg returns position of character in input stream
imageSize = file.tellg();
#if OBSW_DEBUG_STARTRACKER == 1
ProgressPrinter progressPrinter("Image upload", imageSize);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
while ((uploadReq.position + 1) * SIZE_IMAGE_PART < imageSize) {
if (terminate) {
file.close();
@ -267,7 +274,7 @@ ReturnValue_t StrHelper::performImageUpload() {
return result;
}
#if OBSW_DEBUG_STARTRACKER == 1
printProgress((uploadReq.position + 1) * SIZE_IMAGE_PART, imageSize);
progressPrinter.print((uploadReq.position + 1) * SIZE_IMAGE_PART);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
uploadReq.position++;
}
@ -287,7 +294,7 @@ ReturnValue_t StrHelper::performImageUpload() {
return result;
}
#if OBSW_DEBUG_STARTRACKER == 1
printProgress((uploadReq.position + 1) * SIZE_IMAGE_PART, imageSize);
progressPrinter.print((uploadReq.position + 1) * SIZE_IMAGE_PART);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
return RETURN_OK;
}
@ -322,6 +329,9 @@ ReturnValue_t StrHelper::performFlashWrite() {
sif::warning << "StrHelper::performFlashWrite: Invalid file" << std::endl;
return RETURN_FAILED;
}
#if OBSW_DEBUG_STARTRACKER == 1
ProgressPrinter progressPrinter("Flash write", fileSize);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
uint32_t fileChunks = fileSize / CHUNK_SIZE;
bytesWritten = 0;
req.region = flashWrite.firstRegion;
@ -350,6 +360,9 @@ ReturnValue_t StrHelper::performFlashWrite() {
return result;
}
bytesWritten += CHUNK_SIZE;
#if OBSW_DEBUG_STARTRACKER == 1
progressPrinter.print(idx * CHUNK_SIZE);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
}
uint32_t remainingBytes = fileSize - fileChunks * CHUNK_SIZE;
file.seekg((fileChunks - 1) * CHUNK_SIZE, file.beg);
@ -361,6 +374,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
}
req.address = bytesWritten;
req.length = remainingBytes;
bytesWritten += remainingBytes;
arc_pack_write_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address);
if (result != RETURN_OK) {
@ -370,11 +384,17 @@ ReturnValue_t StrHelper::performFlashWrite() {
if (result != RETURN_OK) {
return result;
}
#if OBSW_DEBUG_STARTRACKER == 1
progressPrinter.print(fileSize);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
return RETURN_OK;
}
ReturnValue_t StrHelper::performFlashRead() {
ReturnValue_t result;
#if OBSW_DEBUG_STARTRACKER == 1
ProgressPrinter progressPrinter("Flash read", flashRead.size);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
struct ReadActionRequest req;
uint32_t bytesRead = 0;
uint32_t size = 0;
@ -427,7 +447,7 @@ ReturnValue_t StrHelper::performFlashRead() {
}
retries = 0;
#if OBSW_DEBUG_STARTRACKER == 1
printProgress(bytesRead, flashRead.size);
progressPrinter.print(bytesRead);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
}
file.close();
@ -535,24 +555,15 @@ ReturnValue_t StrHelper::checkPath(std::string name) {
}
#endif
void StrHelper::printProgress(uint32_t itemsTransferred, uint32_t fullNumItems) {
float progressInPercent =
static_cast<float>(itemsTransferred) / static_cast<float>(fullNumItems) * 100;
if (static_cast<uint32_t>(progressInPercent) == nextProgressPrint) {
sif::info << "Str Helper Progress: " << progressInPercent << " %" << std::endl;
nextProgressPrint += FIVE_PERCENT;
}
if (nextProgressPrint > 100) {
nextProgressPrint = 0;
}
}
ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
ReturnValue_t result = RETURN_OK;
#if OBSW_DEBUG_STARTRACKER == 1
ProgressPrinter progressPrinter("Unlock and erase", to - from);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
struct UnlockActionRequest unlockReq;
struct EraseActionRequest eraseReq;
uint32_t size = 0;
for (uint8_t idx = from; idx <= to; idx++) {
for (uint32_t idx = from; idx <= to; idx++) {
unlockReq.region = idx;
unlockReq.code = startracker::region_secrets::secret[idx];
arc_pack_unlock_action_req(&unlockReq, commandBuffer, &size);
@ -571,6 +582,9 @@ ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
<< static_cast<unsigned int>(eraseReq.region) << std::endl;
return result;
}
#if OBSW_DEBUG_STARTRACKER == 1
progressPrinter.print(idx - from);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
}
return result;
}