fsfw/housekeeping/PeriodicHousekeepingHelper.cpp

50 lines
1.5 KiB
C++
Raw Normal View History

2020-09-19 02:46:29 +02:00
#include "PeriodicHousekeepingHelper.h"
2020-10-14 00:50:24 +02:00
#include "../datapoollocal/LocalPoolDataSetBase.h"
2020-09-19 02:46:29 +02:00
#include <cmath>
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(
LocalPoolDataSetBase* owner): owner(owner) {}
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
dur_millis_t minimumPeriodicInterval, bool isDiagnostics,
uint8_t nonDiagIntervalFactor) {
this->minimumPeriodicInterval = minimumPeriodicInterval;
2020-09-28 23:21:21 +02:00
if(not isDiagnostics) {
2020-09-19 02:46:29 +02:00
this->minimumPeriodicInterval = this->minimumPeriodicInterval *
nonDiagIntervalFactor;
}
2020-09-19 15:58:34 +02:00
collectionIntervalTicks = intervalSecondsToInterval(collectionInterval);
2020-09-19 02:46:29 +02:00
}
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() {
return intervalToIntervalSeconds(collectionIntervalTicks);
}
bool PeriodicHousekeepingHelper::checkOpNecessary() {
if(internalTickCounter >= collectionIntervalTicks) {
internalTickCounter = 1;
return true;
}
internalTickCounter++;
return false;
}
uint32_t PeriodicHousekeepingHelper::intervalSecondsToInterval(
float collectionIntervalSeconds) {
return std::ceil(collectionIntervalSeconds * 1000
/ minimumPeriodicInterval);
}
float PeriodicHousekeepingHelper::intervalToIntervalSeconds(
uint32_t collectionInterval) {
return static_cast<float>(collectionInterval *
minimumPeriodicInterval);
}
void PeriodicHousekeepingHelper::changeCollectionInterval(
float newIntervalSeconds) {
collectionIntervalTicks = intervalSecondsToInterval(newIntervalSeconds);
}