Revision 1453
fixed some testbench bugs, added command line argument to specify wireless channel and more helpful output to the tester
main.c | ||
---|---|---|
26 | 26 |
#include "hunter_prey.h" |
27 | 27 |
#include <time.h> |
28 | 28 |
|
29 |
#define CHANNEL 12 //0xF // channel for wireless communication |
|
30 | 29 |
#define TYPE 42 // packet type for wireless communication |
31 | 30 |
#define ROBOTID 255 // make up a robot id because the PC doesn't have one |
32 | 31 |
|
... | ... | |
50 | 49 |
unsigned char *packet_data; // data received |
51 | 50 |
int ret; |
52 | 51 |
|
52 |
unsigned int channel = 0xF; |
|
53 |
|
|
53 | 54 |
struct timespec delay8, rem; |
54 | 55 |
|
56 |
if(argc > 1) { |
|
57 |
channel = atoi(argv[1]); |
|
58 |
} |
|
59 |
|
|
60 |
printf("using wireless channel %d\n", channel); |
|
61 |
|
|
55 | 62 |
delay8.tv_sec = 2; |
56 | 63 |
delay8.tv_nsec = 800000000; |
57 | 64 |
|
58 | 65 |
wl_set_com_port("/dev/ttyUSB0"); |
59 | 66 |
// set up wireless |
60 | 67 |
wl_basic_init_default(); |
61 |
wl_set_channel(CHANNEL);
|
|
68 |
wl_set_channel(channel);
|
|
62 | 69 |
|
63 | 70 |
printf("Testing communications\n\n"); |
64 | 71 |
|
... | ... | |
91 | 98 |
else |
92 | 99 |
printf("FAILED\n"); |
93 | 100 |
|
94 |
|
|
101 |
printf("robot should be prey\nPress enter to continue...\n"); |
|
95 | 102 |
waitKey(); |
96 | 103 |
|
97 | 104 |
// Send a TAG, receive an ACK |
... | ... | |
126 | 133 |
else |
127 | 134 |
printf("PASSED\n"); |
128 | 135 |
|
136 |
printf("Robot should be Hunter\nPress enter to continue...\n"); |
|
137 |
|
|
129 | 138 |
waitKey(); |
130 | 139 |
|
131 | 140 |
// Receive a TAG, send a delayed ACK |
... | ... | |
167 | 176 |
printf("FAILED\n"); |
168 | 177 |
|
169 | 178 |
|
179 |
printf("robot should be prey.\n Press Enter...\n"); |
|
170 | 180 |
waitKey(); |
171 | 181 |
|
172 | 182 |
printf("sending courtesy tag..."); |
... | ... | |
187 | 197 |
else |
188 | 198 |
printf("done\n"); |
189 | 199 |
|
190 |
waitKey(); |
|
191 | 200 |
|
192 | 201 |
// Receive a TAG, never send an ACK |
193 | 202 |
printf("Receive TAG, never send ACK... "); |
... | ... | |
200 | 209 |
|
201 | 210 |
printf("got TAG, monitoring for 5 seconds\n"); |
202 | 211 |
fflush(stdout); |
203 |
usleep(5000000); // wait 5 seconds to see if they TAG again |
|
212 |
delay8.tv_sec = 5; |
|
213 |
delay8.tv_nsec = 0; |
|
204 | 214 |
|
215 |
ret = nanosleep(&delay8, &rem); // wait for 5 secs |
|
216 |
while(ret) { |
|
217 |
// printf("nanosleep not done, needs to wait %ld more\n", rem.tv_nsec); |
|
218 |
ret = nanosleep(&rem, &rem); |
|
219 |
} |
|
220 |
|
|
205 | 221 |
if (wl_basic_do_default(&data_length)) |
206 | 222 |
printf("FAILED, robot is spamming\n"); |
207 | 223 |
else |
... | ... | |
211 | 227 |
else |
212 | 228 |
printf("FAILED\n"); |
213 | 229 |
|
230 |
printf("robot should be hunter.\nPress enter...\n"); |
|
231 |
|
|
214 | 232 |
waitKey(); |
215 | 233 |
|
216 | 234 |
// Receive TAG, send ACK to incorrect robot |
... | ... | |
232 | 250 |
else |
233 | 251 |
printf("FAILED\n"); |
234 | 252 |
|
253 |
|
|
254 |
printf("robot should wait and then still be hunter.\nPress Enter...\n"); |
|
235 | 255 |
waitKey(); |
236 | 256 |
|
237 | 257 |
// Simulate TAG from robot A to B, ACK from robot B to A |
... | ... | |
253 | 273 |
else |
254 | 274 |
printf("PASSED\n"); |
255 | 275 |
|
276 |
printf("robot should be waiting\n"); |
|
277 |
|
|
256 | 278 |
return 0; |
257 | 279 |
} |
258 | 280 |
|
Also available in: Unified diff