Revision 166
Recharging now works, wireless has been updated.
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 |
timer_t wl_timeout_timer; |
|
38 | 37 |
|
39 | 38 |
//called when we time out, or receive interrupt |
40 | 39 |
void sig_handler(int signo) |
... | ... | |
51 | 50 |
} |
52 | 51 |
return; |
53 | 52 |
} |
53 |
#else |
|
54 |
|
|
55 |
//called when the timer ticks |
|
56 |
void timer_handler(void) |
|
57 |
{ |
|
58 |
wl_timeout = 1; |
|
59 |
} |
|
60 |
|
|
54 | 61 |
#endif |
55 | 62 |
|
56 | 63 |
/** |
... | ... | |
68 | 75 |
//begin timeout timer |
69 | 76 |
#ifdef ROBOT |
70 | 77 |
#ifdef FIREFLY |
71 |
rtc_init(PRESCALE_DIV_256, 32, &wl_do_timeout);
|
|
78 |
rtc_init(PRESCALE_DIV_256, 32, &timer_handler);
|
|
72 | 79 |
#else |
73 |
rtc_init(HALF_SECOND, &wl_do_timeout);
|
|
80 |
rtc_init(HALF_SECOND, &timer_handler);
|
|
74 | 81 |
#endif |
75 | 82 |
#else |
76 |
//create a timer to trigger every half second |
|
77 |
struct sigevent evp; |
|
78 |
evp.sigev_signo = SIGALRM; |
|
79 |
evp.sigev_notify = SIGEV_SIGNAL; |
|
80 |
if (timer_create(CLOCK_REALTIME, &evp, &wl_timeout_timer) == -1) |
|
81 |
{ |
|
83 |
|
|
84 |
//create our timer |
|
85 |
struct itimerval timer_val; |
|
86 |
struct timeval interval; |
|
87 |
interval.tv_sec = 0; |
|
88 |
interval.tv_usec = 500000; |
|
89 |
struct timeval first_time; |
|
90 |
first_time.tv_sec = 0; |
|
91 |
first_time.tv_usec = 500000; |
|
92 |
timer_val.it_interval = interval; |
|
93 |
timer_val.it_value = first_time; |
|
94 |
if(setitimer(ITIMER_REAL,&timer_val,NULL)==-1) |
|
95 |
{ |
|
82 | 96 |
WL_DEBUG_PRINT("Error creating a timer.\r\n"); |
97 |
perror("Failure's cause"); |
|
83 | 98 |
exit(1); |
84 | 99 |
} |
100 |
|
|
101 |
//create signal handler |
|
85 | 102 |
struct sigaction wl_sig_act; |
86 | 103 |
wl_sig_act.sa_handler = (void *)sig_handler; |
87 | 104 |
wl_sig_act.sa_flags = 0; |
88 | 105 |
sigemptyset(&wl_sig_act.sa_mask); |
89 | 106 |
sigaction(SIGALRM, &wl_sig_act, 0); |
90 | 107 |
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 | 108 |
#endif |
99 | 109 |
} |
100 | 110 |
|
... | ... | |
103 | 113 |
**/ |
104 | 114 |
void wl_terminate() |
105 | 115 |
{ |
106 |
#ifndef ROBOT |
|
107 |
timer_delete(wl_timeout_timer); |
|
108 |
#endif |
|
109 |
|
|
110 | 116 |
int i; |
111 | 117 |
for (i = 0; i < WL_MAX_PACKET_GROUPS; i++) |
112 | 118 |
if (wl_packet_groups[i] != NULL && |
... | ... | |
350 | 356 |
{ |
351 | 357 |
WL_DEBUG_PRINT("No response received.\r\n"); |
352 | 358 |
if (wl_buf[2] == 2) |
359 |
{ |
|
353 | 360 |
WL_DEBUG_PRINT("CCA Failure\r\n"); |
361 |
} |
|
354 | 362 |
if (wl_buf[2] == 3) |
363 |
{ |
|
355 | 364 |
WL_DEBUG_PRINT("Purged\r\n"); |
365 |
} |
|
356 | 366 |
} |
357 | 367 |
|
358 | 368 |
if (wl_packet_groups[group] != NULL && |
... | ... | |
390 | 400 |
return; |
391 | 401 |
} |
392 | 402 |
|
393 |
usb_puts("Unexpected packet received.\n"); |
|
394 |
//WL_DEBUG_PRINT("Unexpected packet received from XBee.\r\n"); |
|
403 |
WL_DEBUG_PRINT("Unexpected packet received from XBee.\r\n"); |
|
395 | 404 |
return; |
396 | 405 |
} |
397 | 406 |
|
Also available in: Unified diff