-
Notifications
You must be signed in to change notification settings - Fork 1
/
PulseTimer.h
102 lines (74 loc) · 2.42 KB
/
PulseTimer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <cstdlib>
#include <iostream.h>
#include <time.h>
#include <sys/siginfo.h>
#include <sys/neutrino.h>
// include -lmath linker option at compile time to avoid "undefined reference" error
#include <math.h>
#ifndef pulsetimer_h
#define pulsetimer_h
// pulse from timer (check the pulse's code value upon message receipt)
#define PULSE_FROM_TIMER 1
//-----------------------------------------------------------------------------------------
// PulseTimer interface.
//-----------------------------------------------------------------------------------------
class PulseTimer
{
//-----------------------------------------------------------------------------------------
// Public members
//-----------------------------------------------------------------------------------------
public:
// constructor
PulseTimer(double, int);
// destructor
~PulseTimer();
// starts timer
int start();
// stops timer
int stop();
// (re)initializes the guts of the timer structure
void reset();
// detaches timer from the channel.
int detach();
// returns a handle to the current timer instance (itself)
timer_t getTimerId();
// returns connection id
int getConnectionId();
// returns seconds portion of the time interval
long getSeconds();
// returns nanoseconds portion of the time interval
long getNanoseconds();
// returns timer's running state
bool isRunning();
// returns timer's detached state
bool isDetached();
//-----------------------------------------------------------------------------------------
// Private members
//-----------------------------------------------------------------------------------------
private:
timer_t timerId;
struct itimerspec timer;
struct sigevent event;
int connectionId;
long seconds;
long nanoseconds;
bool running;
bool detached;
//-----------------------------------------------------------------------------------------
// Protected members
//-----------------------------------------------------------------------------------------
protected:
// attaches connection
void connectionAttach(int);
// sets seconds portion of the time interval
void setInterval(double interval);
// creates timer
void createTimer();
// sets connection id
void setConnectionId(int id);
// sets timer's running flag (1=true, 0=false)
void setRunning(bool);
// sets timer's detached flag (1=true, 0=false)
void setDetached(bool);
};
#endif