Revision 901
added packet receive functionality to remote control server code
trunk/code/projects/libwireless/test/test.c | ||
---|---|---|
16 | 16 |
#define VEL_DOWN 8 |
17 | 17 |
|
18 | 18 |
void send_packet (char color, int dst_robot); |
19 |
void packet_receive(char type, int source, unsigned char* packet, int length); |
|
19 | 20 |
|
20 |
PacketGroupHandler packetHandler = {WL_CNTL_GROUP, NULL, NULL, NULL, NULL}; |
|
21 |
PacketGroupHandler cntlHandler = {WL_CNTL_GROUP, NULL, NULL, NULL, NULL}; |
|
22 |
PacketGroupHandler receiveHandler = {1, NULL, NULL, &packet_receive, NULL}; |
|
21 | 23 |
|
24 |
FILE *file; |
|
25 |
|
|
22 | 26 |
int main(int argc, char *argv[]) { |
23 | 27 |
if (argc != 2) { |
24 | 28 |
printf("Usage: ./test <robot #>\n"); |
... | ... | |
28 | 32 |
char c; |
29 | 33 |
int robot = atoi(argv[1]); |
30 | 34 |
|
35 |
file = fopen("data_test.txt", "w"); |
|
36 |
if (file == NULL) { |
|
37 |
printf("fopen error\n"); |
|
38 |
return 1; |
|
39 |
} |
|
31 | 40 |
initscr(); |
32 | 41 |
printf("Beginning: robot=%d\r\n", robot); |
33 | 42 |
wl_set_com_port("/dev/ttyUSB0"); |
34 | 43 |
wl_init(); |
35 | 44 |
wl_set_channel(0xF); |
36 | 45 |
printf("Wireless initialized.\r\n"); |
37 |
wl_register_packet_group(&packetHandler); |
|
46 |
wl_register_packet_group(&cntlHandler); |
|
47 |
wl_register_packet_group(&receiveHandler); |
|
38 | 48 |
printf("Packet groups initialized.\r\n"); |
39 | 49 |
fflush(stdout); |
40 | 50 |
//while (1); |
41 | 51 |
while (1) { |
52 |
wl_do(); |
|
42 | 53 |
c = getch(); |
43 | 54 |
printf("%c\r\n", c); |
44 | 55 |
fflush(stdout); |
56 |
if (c=='0') |
|
57 |
break; |
|
45 | 58 |
switch (c) { |
46 | 59 |
case 'w': |
47 | 60 |
send_packet(FORWARD, robot); |
... | ... | |
71 | 84 |
send_packet(VEL_DOWN, robot); |
72 | 85 |
break; |
73 | 86 |
default: |
74 |
//send_packet(FORWARD);
|
|
87 |
//send_packet(STOP, robot);
|
|
75 | 88 |
break; |
76 | 89 |
} |
77 | 90 |
} |
78 |
|
|
91 |
fclose(file); |
|
79 | 92 |
return 0; |
80 | 93 |
} |
81 | 94 |
|
... | ... | |
83 | 96 |
wl_send_robot_to_robot_global_packet(WL_CNTL_GROUP, type, NULL, 0, dst_robot, 0); |
84 | 97 |
//wl_send_global_packet(WL_CNTL_GROUP, type, NULL, 0, 0); |
85 | 98 |
} |
99 |
|
|
100 |
void packet_receive (char type, int source, unsigned char* packet, int length) { |
|
101 |
fprintf(file, "received packet: "); |
|
102 |
int i, temp; |
|
103 |
for (i = 0; i < length; i += 2) { |
|
104 |
temp = packet[i+1] << 8; |
|
105 |
temp &= 0xFF00; |
|
106 |
temp |= packet[i]; |
|
107 |
fprintf(file, "%d, ", temp); |
|
108 |
} |
|
109 |
fprintf(file, "\n"); |
|
110 |
} |
Also available in: Unified diff