Robin Mueller
6d5eb5b387
- Added unittests for `PeriodicOperationDivider` and the `bitutil` helpers - Some API changes: Removed redundant bit part, because these functions are already in a namespace - Some bugfixes for `PeriodicOperationDivider`
42 lines
894 B
C++
42 lines
894 B
C++
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
|
|
|
|
|
|
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
|
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
|
divider(divider) {
|
|
}
|
|
|
|
bool PeriodicOperationDivider::checkAndIncrement() {
|
|
bool opNecessary = check();
|
|
if(opNecessary and resetAutomatically) {
|
|
resetCounter();
|
|
}
|
|
else {
|
|
counter++;
|
|
}
|
|
return opNecessary;
|
|
}
|
|
|
|
bool PeriodicOperationDivider::check() {
|
|
if(counter >= divider) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void PeriodicOperationDivider::resetCounter() {
|
|
counter = 1;
|
|
}
|
|
|
|
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
|
|
divider = newDivider;
|
|
}
|
|
|
|
uint32_t PeriodicOperationDivider::getCounter() const {
|
|
return counter;
|
|
}
|
|
|
|
uint32_t PeriodicOperationDivider::getDivider() const {
|
|
return divider;
|
|
}
|