Revision 111
Cool stuff...
wireless.c | ||
---|---|---|
6 | 6 |
#include "wl_defs.h" |
7 | 7 |
|
8 | 8 |
#ifndef ROBOT |
9 |
#include <time.h> |
|
9 |
#include <sys/time.h>
|
|
10 | 10 |
#include <signal.h> |
11 | 11 |
#else |
12 | 12 |
#include <time.h> |
... | ... | |
34 | 34 |
PacketGroupHandler* wl_packet_groups[WL_MAX_PACKET_GROUPS]; |
35 | 35 |
|
36 | 36 |
#ifndef ROBOT |
37 |
#ifdef _POSIX_TIMERS |
|
37 | 38 |
timer_t wl_timeout_timer; |
38 |
|
|
39 |
#endif |
|
39 | 40 |
//called when we time out, or receive interrupt |
40 | 41 |
void sig_handler(int signo) |
41 | 42 |
{ |
... | ... | |
51 | 52 |
} |
52 | 53 |
return; |
53 | 54 |
} |
55 |
#else |
|
56 |
//Alternate non posix code here. |
|
57 |
|
|
54 | 58 |
#endif |
55 | 59 |
|
56 | 60 |
/** |
... | ... | |
73 | 77 |
rtc_init(HALF_SECOND, &wl_do_timeout); |
74 | 78 |
#endif |
75 | 79 |
#else |
76 |
//create a timer to trigger every half second |
|
80 |
|
|
81 |
#ifdef _POSIX_TIMERS |
|
82 |
|
|
83 |
//create a timer to trigger every half second |
|
77 | 84 |
struct sigevent evp; |
78 | 85 |
evp.sigev_signo = SIGALRM; |
79 | 86 |
evp.sigev_notify = SIGEV_SIGNAL; |
... | ... | |
82 | 89 |
WL_DEBUG_PRINT("Error creating a timer.\r\n"); |
83 | 90 |
exit(1); |
84 | 91 |
} |
92 |
|
|
93 |
struct itimerspec wl_timeout_time; |
|
94 |
wl_timeout_time.it_interval.tv_sec = 0; |
|
95 |
wl_timeout_time.it_interval.tv_nsec = 500000000; |
|
96 |
wl_timeout_time.it_value.tv_sec = 0; |
|
97 |
wl_timeout_time.it_value.tv_nsec = 500000000; |
|
98 |
timer_settime(wl_timeout_timer, 0, |
|
99 |
&wl_timeout_time, NULL); |
|
100 |
#else |
|
101 |
|
|
102 |
printf("Creating a non posix timer.\n"); |
|
103 |
struct itimerval timer_val; |
|
104 |
struct timeval interval; |
|
105 |
interval.tv_sec = 0; |
|
106 |
interval.tv_usec = 500000; |
|
107 |
struct timeval first_time; |
|
108 |
first_time.tv_sec = 0; |
|
109 |
first_time.tv_usec = 500000; |
|
110 |
timer_val.it_interval = interval; |
|
111 |
timer_val.it_value = first_time; |
|
112 |
if(setitimer(ITIMER_REAL,&timer_val,NULL)==-1) |
|
113 |
{ |
|
114 |
WL_DEBUG_PRINT("Error creating a timer.\r\n"); |
|
115 |
perror("Failure's cause"); |
|
116 |
exit(1); |
|
117 |
} |
|
118 |
|
|
119 |
#endif |
|
120 |
|
|
85 | 121 |
struct sigaction wl_sig_act; |
86 | 122 |
wl_sig_act.sa_handler = (void *)sig_handler; |
87 | 123 |
wl_sig_act.sa_flags = 0; |
88 | 124 |
sigemptyset(&wl_sig_act.sa_mask); |
89 | 125 |
sigaction(SIGALRM, &wl_sig_act, 0); |
90 | 126 |
sigaction(SIGINT, &wl_sig_act, 0); |
91 |
struct itimerspec wl_timeout_time; |
|
92 |
wl_timeout_time.it_interval.tv_sec = 0; |
|
93 |
wl_timeout_time.it_interval.tv_nsec = 500000000; |
|
94 |
wl_timeout_time.it_value.tv_sec = 0; |
|
95 |
wl_timeout_time.it_value.tv_nsec = 500000000; |
|
96 |
timer_settime(wl_timeout_timer, 0, |
|
97 |
&wl_timeout_time, NULL); |
|
98 | 127 |
#endif |
99 | 128 |
} |
100 | 129 |
|
... | ... | |
104 | 133 |
void wl_terminate() |
105 | 134 |
{ |
106 | 135 |
#ifndef ROBOT |
107 |
timer_delete(wl_timeout_timer); |
|
136 |
#ifdef _POSIX_TIMERS |
|
137 |
timer_delete(wl_timeout_timer); |
|
138 |
#endif |
|
108 | 139 |
#endif |
109 | 140 |
|
110 | 141 |
int i; |
Also available in: Unified diff