eive-obsw/mission/utility/ProgressPrinter.cpp

26 lines
917 B
C++
Raw Permalink Normal View History

2022-03-01 17:17:15 +01:00
#include "ProgressPrinter.h"
2022-04-30 16:21:59 +02:00
2022-05-23 12:05:42 +02:00
#include <cmath>
2022-05-23 18:37:04 +02:00
#include <iomanip>
2022-04-30 16:21:59 +02:00
2022-03-01 17:17:15 +01:00
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
ProgressPrinter::ProgressPrinter(std::string name, uint32_t numSteps, float percentageResolution)
2022-04-19 13:33:37 +02:00
: name(name), numSteps(numSteps), percentageResolution(percentageResolution) {}
2022-03-01 17:17:15 +01:00
ProgressPrinter::~ProgressPrinter() {}
2022-03-01 17:17:15 +01:00
void ProgressPrinter::print(uint32_t currentStep) {
float progressInPercent = static_cast<float>(currentStep) / static_cast<float>(numSteps) * 100;
if (progressInPercent >= nextProgressPrint) {
sif::info << name << " progress: " << std::setprecision(4) << progressInPercent << " %"
<< std::endl;
2022-04-19 13:33:37 +02:00
nextProgressPrint += percentageResolution;
2022-03-01 17:17:15 +01:00
}
2022-05-23 12:05:42 +02:00
if (nextProgressPrint - progressInPercent < 0) {
nextProgressPrint =
(std::floor(progressInPercent / percentageResolution) * percentageResolution) +
percentageResolution;
}
2022-03-01 17:17:15 +01:00
}