root / branches / slam / code / projects / colonet / DataRequests / server / test_main.c @ 201
History | View | Annotate | Download (1.74 KB)
1 |
#include <stdlib.h> |
---|---|
2 |
#include <stdio.h> |
3 |
#include <unistd.h> |
4 |
#include "data_requests.h" |
5 |
#include "wireless.h" |
6 |
#include "wl_token_ring.h" |
7 |
|
8 |
void IR_handler(unsigned char* data); |
9 |
void bom_handler(BomNode* head);
|
10 |
void encoder_handler(unsigned char* data); |
11 |
|
12 |
unsigned char bom_responded_flag; |
13 |
unsigned char ir_responded_flag; |
14 |
unsigned char encoder_responded_flag; |
15 |
|
16 |
int main(void){ |
17 |
wl_set_com_port("/dev/cu.usbserial-A1000Qu6");
|
18 |
wl_init(); |
19 |
wl_token_ring_register(); |
20 |
data_requests_init(bom_handler,IR_handler,encoder_handler); |
21 |
|
22 |
int robot_id;
|
23 |
bom_responded_flag = 0;
|
24 |
ir_responded_flag = 0;
|
25 |
encoder_responded_flag = 0;
|
26 |
int test_count;
|
27 |
while(1){ |
28 |
wl_do(); |
29 |
printf(".");
|
30 |
wl_token_iterator_begin(); |
31 |
while(wl_token_iterator_has_next()){
|
32 |
robot_id = wl_token_iterator_next(); |
33 |
|
34 |
bom_responded_flag = 0;
|
35 |
ir_responded_flag = 0;
|
36 |
encoder_responded_flag = 0;
|
37 |
/*
|
38 |
request_bom_data(robot_id);
|
39 |
while(!bom_responded_flag){
|
40 |
delay_ms(50);
|
41 |
}
|
42 |
*/
|
43 |
printf("Sending a request to %i\n",robot_id);
|
44 |
request_IR_data(robot_id); |
45 |
test_count=0;
|
46 |
while(!(ir_responded_flag)&&(test_count++<20)){ |
47 |
wl_do(); |
48 |
printf("Waiting on %i..\n",robot_id);
|
49 |
usleep(500000);
|
50 |
} |
51 |
/*
|
52 |
request_encoder_data(robot_id);
|
53 |
while(!encoder_responded_flag){
|
54 |
delay_ms(50);
|
55 |
}
|
56 |
*/
|
57 |
} |
58 |
usleep(500000);
|
59 |
} |
60 |
} |
61 |
|
62 |
void IR_handler(unsigned char* data){ |
63 |
char i = 0; |
64 |
printf("IR Callback occurred.\n");
|
65 |
for(i=0;i<5;i++){ |
66 |
printf("IR %i is %i\n",i+1,(int)data[i]); |
67 |
} |
68 |
ir_responded_flag=1;
|
69 |
} |
70 |
|
71 |
void bom_handler(BomNode* head){
|
72 |
bom_responded_flag=1;
|
73 |
} |
74 |
|
75 |
void encoder_handler(unsigned char* data){ |
76 |
encoder_responded_flag=1;
|
77 |
} |
78 |
|