diff --git a/linux/devices/startracker/StrHelper.cpp b/linux/devices/startracker/StrHelper.cpp index f3a559a0..cab99a1a 100644 --- a/linux/devices/startracker/StrHelper.cpp +++ b/linux/devices/startracker/StrHelper.cpp @@ -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(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(itemsTransferred) / static_cast(fullNumItems) * 100; - if (static_cast(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(eraseReq.region) << std::endl; return result; } +#if OBSW_DEBUG_STARTRACKER == 1 + progressPrinter.print(idx - from); +#endif /* OBSW_DEBUG_STARTRACKER == 1 */ } return result; } diff --git a/linux/devices/startracker/StrHelper.h b/linux/devices/startracker/StrHelper.h index a3cb65ec..f34e96ce 100644 --- a/linux/devices/startracker/StrHelper.h +++ b/linux/devices/startracker/StrHelper.h @@ -171,7 +171,6 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu // Size of one image part which can be sent per action request static const size_t SIZE_IMAGE_PART = 1024; - static constexpr uint32_t FIVE_PERCENT = 5; static const uint32_t FLASH_REGION_SIZE = 0x20000; class ImageDownload { @@ -251,8 +250,6 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu bool terminate = false; - uint32_t nextProgressPrint = 0; - #ifdef EGSE bool timestamping = false; #else @@ -344,14 +341,6 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu ReturnValue_t checkPath(std::string name); #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 * diff --git a/mission/utility/CMakeLists.txt b/mission/utility/CMakeLists.txt index a6d4e57d..979ada94 100644 --- a/mission/utility/CMakeLists.txt +++ b/mission/utility/CMakeLists.txt @@ -1,6 +1,7 @@ target_sources(${LIB_EIVE_MISSION} PRIVATE TmFunnel.cpp Timestamp.cpp + ProgressPrinter.cpp ) diff --git a/mission/utility/ProgressPrinter.cpp b/mission/utility/ProgressPrinter.cpp new file mode 100644 index 00000000..c3a8e3f6 --- /dev/null +++ b/mission/utility/ProgressPrinter.cpp @@ -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(currentStep) / static_cast(numSteps) * 100; + if (static_cast(progressInPercent) >= nextProgressPrint) { + sif::info << name << " progress: " << progressInPercent << " %" << std::endl; + nextProgressPrint += FIVE_PERCENT; + } +} diff --git a/mission/utility/ProgressPrinter.h b/mission/utility/ProgressPrinter.h new file mode 100644 index 00000000..593526ba --- /dev/null +++ b/mission/utility/ProgressPrinter.h @@ -0,0 +1,37 @@ +#ifndef MISSION_UTILITY_PROGRESSPRINTER_H_ +#define MISSION_UTILITY_PROGRESSPRINTER_H_ + +#include + +/** + * @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_ */ diff --git a/tmtc b/tmtc index 56d414d9..9efb347a 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 56d414d9fc0d6b05f967c47a0bd124fc06de2ad3 +Subproject commit 9efb347aa241e5fb7a864540edbd87908110339c