countdown based HK generation #156
@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- `PusTmZcWriter` now exposes API to set message counter field.
|
- `PusTmZcWriter` now exposes API to set message counter field.
|
||||||
|
|
||||||
## Changed
|
## Changed
|
||||||
|
|
||||||
|
- HK generation is now countdown based.
|
||||||
- Bump ETL version to 20.35.14
|
- Bump ETL version to 20.35.14
|
||||||
https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/748
|
https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/748
|
||||||
- Renamed `PCDU_2` subsystem ID to `POWER_SWITCH_IF`.
|
- Renamed `PCDU_2` subsystem ID to `POWER_SWITCH_IF`.
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "fsfw/datapoollocal/LocalPoolDataSetBase.h"
|
#include "fsfw/datapoollocal/LocalPoolDataSetBase.h"
|
||||||
|
#include "fsfw/serviceinterface.h"
|
||||||
|
|
||||||
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(LocalPoolDataSetBase* owner)
|
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(LocalPoolDataSetBase* owner)
|
||||||
: owner(owner) {}
|
: owner(owner) {}
|
||||||
@ -10,51 +11,21 @@ PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(LocalPoolDataSetBase* own
|
|||||||
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
|
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
|
||||||
dur_millis_t minimumPeriodicInterval) {
|
dur_millis_t minimumPeriodicInterval) {
|
||||||
this->minimumPeriodicInterval = minimumPeriodicInterval;
|
this->minimumPeriodicInterval = minimumPeriodicInterval;
|
||||||
collectionIntervalTicks = intervalSecondsToIntervalTicks(collectionInterval);
|
changeCollectionInterval(collectionInterval);
|
||||||
/* This will cause a checkOpNecessary call to be true immediately. I think it's okay
|
|
||||||
if a HK packet is generated immediately instead of waiting one generation cycle. */
|
|
||||||
internalTickCounter = collectionIntervalTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() const {
|
|
||||||
return intervalTicksToSeconds(collectionIntervalTicks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeriodicHousekeepingHelper::checkOpNecessary() {
|
bool PeriodicHousekeepingHelper::checkOpNecessary() {
|
||||||
if (internalTickCounter >= collectionIntervalTicks) {
|
if (hkGenerationCd.hasTimedOut()) {
|
||||||
internalTickCounter = 1;
|
hkGenerationCd.resetTimer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
internalTickCounter++;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t PeriodicHousekeepingHelper::intervalSecondsToIntervalTicks(
|
|
||||||
float collectionIntervalSeconds) {
|
|
||||||
if (owner == nullptr) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Avoid division by zero */
|
|
||||||
if (minimumPeriodicInterval == 0) {
|
|
||||||
/* Perform operation each cycle */
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
dur_millis_t intervalInMs = collectionIntervalSeconds * 1000;
|
|
||||||
uint32_t divisor = minimumPeriodicInterval;
|
|
||||||
uint32_t ticks = std::ceil(static_cast<float>(intervalInMs) / divisor);
|
|
||||||
|
|
||||||
return ticks;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float PeriodicHousekeepingHelper::intervalTicksToSeconds(uint32_t collectionInterval) const {
|
|
||||||
/* Number of ticks times the minimum interval is in milliseconds, so we divide by 1000 to get
|
|
||||||
the value in seconds */
|
|
||||||
return static_cast<float>(collectionInterval * minimumPeriodicInterval / 1000.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeriodicHousekeepingHelper::changeCollectionInterval(float newIntervalSeconds) {
|
void PeriodicHousekeepingHelper::changeCollectionInterval(float newIntervalSeconds) {
|
||||||
collectionIntervalTicks = intervalSecondsToIntervalTicks(newIntervalSeconds);
|
uint32_t intervalMs = newIntervalSeconds * 1000;
|
||||||
|
if (newIntervalSeconds <= 0) {
|
||||||
|
intervalMs = minimumPeriodicInterval;
|
||||||
|
}
|
||||||
|
hkGenerationCd.setTimeout(intervalMs);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
|
#ifndef FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
|
||||||
#define FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
|
#define FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
|
||||||
|
|
||||||
|
#include <fsfw/timemanager/Countdown.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include "fsfw/timemanager/Clock.h"
|
#include "fsfw/timemanager/Clock.h"
|
||||||
@ -19,13 +21,9 @@ class PeriodicHousekeepingHelper {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
LocalPoolDataSetBase* owner = nullptr;
|
LocalPoolDataSetBase* owner = nullptr;
|
||||||
|
Countdown hkGenerationCd;
|
||||||
uint32_t intervalSecondsToIntervalTicks(float collectionIntervalSeconds);
|
|
||||||
float intervalTicksToSeconds(uint32_t collectionInterval) const;
|
|
||||||
|
|
||||||
dur_millis_t minimumPeriodicInterval = 0;
|
dur_millis_t minimumPeriodicInterval = 0;
|
||||||
uint32_t internalTickCounter = 1;
|
|
||||||
uint32_t collectionIntervalTicks = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_ */
|
#endif /* FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user