deleted timer object
This commit is contained in:
parent
ad68802fe4
commit
2e37bd73e2
@ -1,57 +0,0 @@
|
|||||||
#include "fsfw/osal/linux/Timer.h"
|
|
||||||
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
|
|
||||||
Timer::Timer() {
|
|
||||||
sigevent sigEvent;
|
|
||||||
sigEvent.sigev_notify = SIGEV_NONE;
|
|
||||||
sigEvent.sigev_signo = 0;
|
|
||||||
sigEvent.sigev_value.sival_ptr = &timerId;
|
|
||||||
int status = timer_create(CLOCK_MONOTONIC, &sigEvent, &timerId);
|
|
||||||
if(status!=0){
|
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
||||||
sif::error << "Timer creation failed with: " << status <<
|
|
||||||
" errno: " << errno << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer::~Timer() {
|
|
||||||
timer_delete(timerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Timer::setTimer(uint32_t intervalMs) {
|
|
||||||
itimerspec timer;
|
|
||||||
timer.it_value.tv_sec = intervalMs / 1000;
|
|
||||||
timer.it_value.tv_nsec = (intervalMs * 1000000) % (1000000000);
|
|
||||||
timer.it_interval.tv_sec = 0;
|
|
||||||
timer.it_interval.tv_nsec = 0;
|
|
||||||
set = true;
|
|
||||||
return timer_settime(timerId, 0, &timer, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Timer::getTimer(uint32_t* remainingTimeMs){
|
|
||||||
itimerspec timer;
|
|
||||||
timer.it_value.tv_sec = 0;
|
|
||||||
timer.it_value.tv_nsec = 0;
|
|
||||||
timer.it_interval.tv_sec = 0;
|
|
||||||
timer.it_interval.tv_nsec = 0;
|
|
||||||
int status = timer_gettime(timerId, &timer);
|
|
||||||
|
|
||||||
*remainingTimeMs = timer.it_value.tv_sec * 1000 + timer.it_value.tv_nsec / 1000000;
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Timer::isSet() const {
|
|
||||||
return this->set;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Timer::resetTimer() {
|
|
||||||
if(not this->set) {
|
|
||||||
set = false;
|
|
||||||
}
|
|
||||||
setTimer(0);
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
#ifndef FRAMEWORK_OSAL_LINUX_TIMER_H_
|
|
||||||
#define FRAMEWORK_OSAL_LINUX_TIMER_H_
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is a helper for the creation of a Clock Monotonic timer which does not trigger a signal
|
|
||||||
*/
|
|
||||||
class Timer {
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Creates the Timer sets the timerId Member
|
|
||||||
*/
|
|
||||||
Timer();
|
|
||||||
/**
|
|
||||||
* Deletes the timer
|
|
||||||
*
|
|
||||||
* Careful! According to POSIX documentation:
|
|
||||||
* The treatment of any pending signal generated by the deleted timer is unspecified.
|
|
||||||
*/
|
|
||||||
virtual ~Timer();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the timer given in timerId to the given interval
|
|
||||||
*
|
|
||||||
* @param intervalMs Interval in ms to be set
|
|
||||||
* @return 0 on Success 1 else
|
|
||||||
*/
|
|
||||||
int setTimer(uint32_t intervalMs);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the remaining time of the timer
|
|
||||||
*
|
|
||||||
* @param remainingTimeMs Pointer to integer value which is used to return the remaining time
|
|
||||||
* @return 0 on Success 1 else (see timer_getime documentation of posix function)
|
|
||||||
*/
|
|
||||||
int getTimer(uint32_t* remainingTimeMs);
|
|
||||||
|
|
||||||
bool isSet() const;
|
|
||||||
void resetTimer();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool set = true;
|
|
||||||
timer_t timerId;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* FRAMEWORK_OSAL_LINUX_TIMER_H_ */
|
|
Loading…
Reference in New Issue
Block a user