2020-08-13 20:53:35 +02:00
|
|
|
#include "Countdown.h"
|
2021-09-27 19:57:42 +02:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-15 23:00:30 +01:00
|
|
|
Countdown::Countdown(uint32_t initialTimeout): timeout(initialTimeout) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Countdown::~Countdown() {
|
|
|
|
}
|
|
|
|
|
2021-09-27 19:57:42 +02:00
|
|
|
ReturnValue_t Countdown::setTimeout(uint32_t milliseconds) {
|
|
|
|
ReturnValue_t returnValue = Clock::getUptime( &startTime );
|
|
|
|
timeout = milliseconds;
|
|
|
|
return returnValue;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Countdown::hasTimedOut() const {
|
2021-09-27 19:57:42 +02:00
|
|
|
if ( uint32_t( this->getCurrentTime() - startTime) >= timeout) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Countdown::isBusy() const {
|
|
|
|
return !hasTimedOut();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t Countdown::resetTimer() {
|
|
|
|
return setTimeout(timeout);
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
void Countdown::timeOut() {
|
2021-09-27 19:57:42 +02:00
|
|
|
startTime = this->getCurrentTime() - timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Countdown::getRemainingMillis() const {
|
|
|
|
// We fetch the time before the if-statement
|
|
|
|
// to be sure that the return is in
|
|
|
|
// range 0 <= number <= timeout
|
|
|
|
uint32_t currentTime = this->getCurrentTime();
|
|
|
|
if (this->hasTimedOut()){
|
|
|
|
return 0;
|
|
|
|
}else{
|
|
|
|
return (startTime + timeout) - currentTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Countdown::getCurrentTime() const {
|
2018-07-12 16:29:32 +02:00
|
|
|
uint32_t current_time;
|
2021-09-27 19:57:42 +02:00
|
|
|
Clock::getUptime( ¤t_time );
|
|
|
|
return current_time;
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|