fsfw/src/fsfw/housekeeping/PeriodicHousekeepingHelper.cpp

40 lines
1.3 KiB
C++
Raw Normal View History

2021-07-13 20:22:54 +02:00
#include "fsfw/housekeeping/PeriodicHousekeepingHelper.h"
2020-12-03 13:00:04 +01:00
2020-10-01 12:05:24 +02:00
#include <cmath>
2022-02-02 10:29:30 +01:00
#include "fsfw/datapoollocal/LocalPoolDataSetBase.h"
2023-07-10 14:14:31 +02:00
#include "fsfw/serviceinterface.h"
2022-02-02 10:29:30 +01:00
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(LocalPoolDataSetBase* owner)
: owner(owner) {}
2020-10-01 12:05:24 +02:00
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
2023-03-14 17:40:39 +01:00
dur_millis_t minimumPeriodicInterval) {
2022-02-02 10:29:30 +01:00
this->minimumPeriodicInterval = minimumPeriodicInterval;
2023-07-10 14:14:31 +02:00
changeCollectionInterval(collectionInterval);
2020-10-01 12:05:24 +02:00
}
2023-07-10 14:20:02 +02:00
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() const {
return collectionInterval;
}
2020-10-01 12:05:24 +02:00
bool PeriodicHousekeepingHelper::checkOpNecessary() {
2023-07-10 14:14:31 +02:00
if (hkGenerationCd.hasTimedOut()) {
hkGenerationCd.resetTimer();
2022-02-02 10:29:30 +01:00
return true;
}
return false;
2020-10-01 12:05:24 +02:00
}
2022-02-02 10:29:30 +01:00
void PeriodicHousekeepingHelper::changeCollectionInterval(float newIntervalSeconds) {
2023-07-10 14:14:31 +02:00
uint32_t intervalMs = newIntervalSeconds * 1000;
if (newIntervalSeconds <= 0) {
intervalMs = minimumPeriodicInterval;
2023-07-10 14:20:02 +02:00
newIntervalSeconds = static_cast<float>(minimumPeriodicInterval) / 1000.0;
2023-07-10 14:14:31 +02:00
}
2023-07-10 14:20:02 +02:00
collectionInterval = newIntervalSeconds;
2023-07-10 14:14:31 +02:00
hkGenerationCd.setTimeout(intervalMs);
// We want an immediate HK packet at the start, so time out the generation CD immediately.
hkGenerationCd.timeOut();
2020-10-01 12:05:24 +02:00
}