progress printer #158

Merged
muellerr merged 3 commits from meier/startracker into develop 2022-03-01 17:50:13 +01:00
6 changed files with 87 additions and 30 deletions

View File

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

View File

@ -171,7 +171,6 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
// Size of one image part which can be sent per action request // Size of one image part which can be sent per action request
static const size_t SIZE_IMAGE_PART = 1024; static const size_t SIZE_IMAGE_PART = 1024;
static constexpr uint32_t FIVE_PERCENT = 5;
static const uint32_t FLASH_REGION_SIZE = 0x20000; static const uint32_t FLASH_REGION_SIZE = 0x20000;
class ImageDownload { class ImageDownload {
@ -251,8 +250,6 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
bool terminate = false; bool terminate = false;
uint32_t nextProgressPrint = 0;
#ifdef EGSE #ifdef EGSE
bool timestamping = false; bool timestamping = false;
#else #else
@ -344,14 +341,6 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
ReturnValue_t checkPath(std::string name); ReturnValue_t checkPath(std::string name);
#endif #endif
/**
* @brief Prints progress of transfer which can be useful for large data transfers
*
* @param itemsTransferred Number of items transferred
* @param fullNumItems Full number of items to transfer
*/
void printProgress(uint32_t itemsTransferred, uint32_t fullNumItems);
/** /**
* @brief Unlocks a range of flash regions * @brief Unlocks a range of flash regions
* *

View File

@ -1,6 +1,7 @@
target_sources(${LIB_EIVE_MISSION} PRIVATE target_sources(${LIB_EIVE_MISSION} PRIVATE
TmFunnel.cpp TmFunnel.cpp
Timestamp.cpp Timestamp.cpp
ProgressPrinter.cpp
) )

View File

@ -0,0 +1,16 @@
#include "ProgressPrinter.h"
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
ProgressPrinter::ProgressPrinter(std::string name, uint32_t numSteps)
: name(name), numSteps(numSteps) {}
ProgressPrinter::~ProgressPrinter() {
}
void ProgressPrinter::print(uint32_t currentStep) {
float progressInPercent = static_cast<float>(currentStep) / static_cast<float>(numSteps) * 100;
if (static_cast<uint32_t>(progressInPercent) >= nextProgressPrint) {
sif::info << name << " progress: " << progressInPercent << " %" << std::endl;
nextProgressPrint += FIVE_PERCENT;
}
}

View File

@ -0,0 +1,37 @@
#ifndef MISSION_UTILITY_PROGRESSPRINTER_H_
#define MISSION_UTILITY_PROGRESSPRINTER_H_
#include <string>
/**
* @brief Class which can be used to print the progress of processes in percent.
*
* @author J. Meier
*/
class ProgressPrinter {
public:
/**
* @brief Constructor
*
* @param name Name of the process to monitor
* @param numSteps Number of steps to execute
*/
ProgressPrinter(std::string name, uint32_t numSteps);
virtual ~ProgressPrinter();
/**
* @brief Will print the progress
*
* @param currentStep Current step from which to derive progress
*/
void print(uint32_t step);
private:
static constexpr uint32_t FIVE_PERCENT = 5;
std::string name = "";
uint32_t numSteps = 0;
uint32_t nextProgressPrint = 0;
};
#endif /* MISSION_UTILITY_PROGRESSPRINTER_H_ */

2
tmtc

@ -1 +1 @@
Subproject commit 56d414d9fc0d6b05f967c47a0bd124fc06de2ad3 Subproject commit 9efb347aa241e5fb7a864540edbd87908110339c