root / branches / wireless / code / projects / unit_tests / test_wireless2.c @ 1744
History | View | Annotate | Download (12.1 KB)
1 |
#include <wl_defs.h> |
---|---|
2 |
#include <string.h> |
3 |
#include <wireless.h> |
4 |
#include <lights.h> |
5 |
#include <dragonfly_lib.h> |
6 |
#include <xbee.h> |
7 |
|
8 |
|
9 |
void group_1_function(uint8_t* data,uint8_t length,uint8_t source);
|
10 |
void group_2_function(uint8_t* data,uint8_t length,uint8_t source);
|
11 |
void group_3_function(uint8_t* data,uint8_t length,uint8_t source);
|
12 |
void group_4_function(uint8_t* data,uint8_t length,uint8_t source);
|
13 |
void test_function_1(void); |
14 |
void test_sending();
|
15 |
void test_receiving();
|
16 |
|
17 |
uint16_t friendAddress = 0;
|
18 |
|
19 |
/* This function tests out the full functionality of the new wireless library.
|
20 |
* It must be run on two colony bots simultaneously to properly test all funtions.
|
21 |
*/
|
22 |
void testwireless2(void) |
23 |
{ |
24 |
orb_init(); |
25 |
usb_init(); |
26 |
int status = 0; |
27 |
|
28 |
WL_DEBUG_PRINT_P("New Wireless Library Test Suite\r\n");
|
29 |
|
30 |
/*Initialize the wirelss library*/
|
31 |
WL_DEBUG_PRINT_P("Initializing library...\r\n");
|
32 |
orb1_set_color(BLUE); |
33 |
status = wl_init(); |
34 |
switch(status){
|
35 |
case 0: |
36 |
WL_DEBUG_PRINT_P("Library initialization successful\r\n\r\n");
|
37 |
orb1_set_color(GREEN); |
38 |
break;
|
39 |
case -1: |
40 |
WL_DEBUG_PRINT_P("Initialization failed: already initialized\r\n\r\n");
|
41 |
orb1_set_color(GREEN); |
42 |
break;
|
43 |
case -2: |
44 |
WL_DEBUG_PRINT_P("Initialization failed: XBEE initialization failed\r\n\r\n");
|
45 |
orb1_set_color(RED); |
46 |
break;
|
47 |
default:
|
48 |
WL_DEBUG_PRINT_P("Error: Unreconnized status code: ");
|
49 |
usb_puti(status); |
50 |
WL_DEBUG_PRINT_P("\r\n\r\n");
|
51 |
orb1_set_color(RED); |
52 |
break;
|
53 |
} |
54 |
while((status!=0) && 1); |
55 |
|
56 |
/*Test all constants defined correctly*/
|
57 |
status = 0;
|
58 |
WL_DEBUG_PRINT_P("Testing constants...");
|
59 |
orb2_set_color(GREEN); |
60 |
if(GLOBAL!=0){ |
61 |
WL_DEBUG_PRINT_P("\r\nGLOBAL defined as ");
|
62 |
usb_puti(GLOBAL); |
63 |
status++; |
64 |
} |
65 |
WL_DEBUG_PRINT_P(".");
|
66 |
if(PAN!=1){ |
67 |
WL_DEBUG_PRINT_P("\r\nPAN defined as ");
|
68 |
usb_puti(PAN); |
69 |
status++; |
70 |
} |
71 |
WL_DEBUG_PRINT_P(".");
|
72 |
if(BROADCAST!=0xFFFF){ |
73 |
WL_DEBUG_PRINT_P("\r\nBROADCAST defined as ");
|
74 |
usb_puti(BROADCAST); |
75 |
status++; |
76 |
} |
77 |
WL_DEBUG_PRINT_P(".");
|
78 |
if(RELIABLE!=0){ |
79 |
WL_DEBUG_PRINT_P("\r\nRELIABLE defined as ");
|
80 |
usb_puti(RELIABLE); |
81 |
status++; |
82 |
} |
83 |
WL_DEBUG_PRINT_P(".");
|
84 |
if(FAST!=1){ |
85 |
WL_DEBUG_PRINT_P("\r\nFAST defined as ");
|
86 |
usb_puti(FAST); |
87 |
status++; |
88 |
} |
89 |
WL_DEBUG_PRINT_P(".");
|
90 |
if(NORMAL_PRIORITY!=0){ |
91 |
WL_DEBUG_PRINT_P("\r\nNORMAL_PRIORITY defined as ");
|
92 |
usb_puti(NORMAL_PRIORITY); |
93 |
status++; |
94 |
} |
95 |
WL_DEBUG_PRINT_P(".");
|
96 |
if(HIGH_PRIORITY!=1){ |
97 |
WL_DEBUG_PRINT_P("\r\nHIGH_PRIORITY defined as ");
|
98 |
usb_puti(HIGH_PRIORITY); |
99 |
status++; |
100 |
} |
101 |
WL_DEBUG_PRINT_P(".\r\nConstant test complete. There were ");
|
102 |
usb_puti(status); |
103 |
WL_DEBUG_PRINT_P(" errors\r\n");
|
104 |
if(status!=0){ |
105 |
orb2_set_color(ORANGE); |
106 |
delay_ms(500);
|
107 |
} |
108 |
/*Tests function registration*/
|
109 |
WL_DEBUG_PRINT_P("\r\nTesting function registration");
|
110 |
int registers[8], count; |
111 |
status = 0;
|
112 |
orb2_set_color(GREEN); |
113 |
registers[0] = wl_register_handler(1, group_1_function, 0); |
114 |
registers[1] = wl_register_handler(2, group_2_function, 1); |
115 |
registers[2] = wl_register_handler(3, group_3_function, 0); |
116 |
registers[3] = wl_register_handler(4, group_4_function, 1); |
117 |
registers[4] = wl_register_handler(0, group_1_function, 0); |
118 |
registers[5] = wl_register_handler(6, NULL, 0); |
119 |
registers[6] = wl_register_handler(30, group_3_function, 0); |
120 |
registers[7] = wl_register_handler(-1, group_4_function, 0); |
121 |
for(count=0; count<=3; count++){ |
122 |
if(registers[count] != 0){ |
123 |
WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
|
124 |
usb_puti(count); |
125 |
WL_DEBUG_PRINT_P(" returned ");
|
126 |
usb_puti(registers[count]); |
127 |
WL_DEBUG_PRINT_P(" instead of success\r\n");
|
128 |
orb2_set_color(ORANGE); |
129 |
status++; |
130 |
} |
131 |
} |
132 |
for(count=4; count<=6; count++){ |
133 |
if(registers[count] == 0){ |
134 |
WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
|
135 |
usb_puti(count); |
136 |
WL_DEBUG_PRINT_P(" succeeded instead of failing\r\n");
|
137 |
orb2_set_color(ORANGE); |
138 |
status++; |
139 |
} |
140 |
if(registers[count] != 0 && registers[count] != -5){ |
141 |
WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
|
142 |
usb_puti(count); |
143 |
WL_DEBUG_PRINT_P(" returned ");
|
144 |
usb_puti(registers[count]); |
145 |
WL_DEBUG_PRINT_P(" instead of -5\r\n");
|
146 |
orb2_set_color(ORANGE); |
147 |
status++; |
148 |
} |
149 |
} |
150 |
if(registers[7] == 0){ |
151 |
WL_DEBUG_PRINT_P("\r\nCongrats, you let an array write to index -1\r\n");
|
152 |
orb2_set_color(RED); |
153 |
status++; |
154 |
} |
155 |
WL_DEBUG_PRINT_P("Registration test completed. There were ");
|
156 |
usb_puti(status); |
157 |
WL_DEBUG_PRINT_P(" errors\r\n");
|
158 |
delay_ms(500);
|
159 |
|
160 |
/*Tests XBee functions*/
|
161 |
WL_DEBUG_PRINT_P("\r\nTesting XBee fuctions...\r\n");
|
162 |
status = 0;
|
163 |
orb2_set_color(GREEN); |
164 |
/* while(1){
|
165 |
uint16_t pan = xbee_get_pan();
|
166 |
if(pan != 0){
|
167 |
WL_DEBUG_PRINT_P("Pan error: defaulted to non-default Pan id (0):");
|
168 |
usb_puti(pan);
|
169 |
orb2_set_color(ORANGE);
|
170 |
status++;
|
171 |
}
|
172 |
status = xbee_set_pan(0x2B7D);
|
173 |
if(status != 0){
|
174 |
WL_DEBUG_PRINT_P("\r\nPan error: error setting Pan id: ");
|
175 |
// usb_puth16(pan);
|
176 |
orb2_set_color(ORANGE);
|
177 |
status++;
|
178 |
}
|
179 |
pan = xbee_get_pan();
|
180 |
if(pan != 0x2B7D){
|
181 |
WL_DEBUG_PRINT_P("\r\nPan error: Pan id reads different than set value 0x2B7D: ");
|
182 |
usb_puth16(pan);
|
183 |
orb2_set_color(ORANGE);
|
184 |
status++;
|
185 |
}
|
186 |
status = xbee_set_pan(0);
|
187 |
if(status != 0){
|
188 |
WL_DEBUG_PRINT_P("\r\nPan error: error setting Pan id: ");
|
189 |
usb_puti(pan);
|
190 |
orb2_set_color(ORANGE);
|
191 |
status++;
|
192 |
}
|
193 |
pan = xbee_get_pan();
|
194 |
if(pan != 0){
|
195 |
WL_DEBUG_PRINT_P("\r\nPan error: Pan id reads different than set value 0: ");
|
196 |
usb_puti(pan);
|
197 |
orb2_set_color(ORANGE);
|
198 |
status++;
|
199 |
}
|
200 |
int chanCount;
|
201 |
for(chanCount = 0x0B; chanCount <= 0x1A; chanCount++){
|
202 |
xbee_set_channel(0x10);
|
203 |
WL_DEBUG_PRINT_P("\r\nChannel: ");
|
204 |
WL_DEBUG_PRINT_HEX(xbee_get_channel());
|
205 |
}
|
206 |
uint16_t data = xbee_get_address();
|
207 |
uint8_t sendBuffer[2];
|
208 |
uint16_t address = 0;
|
209 |
sendBuffer[0] = (data& 0xFF00) >> 8;
|
210 |
sendBuffer[1] = (data& 0x00FF);
|
211 |
wl_send((uint8_t*)&sendBuffer, 2, 0, GLOBAL, BROADCAST, FAST);
|
212 |
}
|
213 |
*/
|
214 |
WL_DEBUG_PRINT_P("\r\nXBee tests completed. There were ");
|
215 |
usb_puti(status); |
216 |
WL_DEBUG_PRINT_P(" errors.\r\n");
|
217 |
|
218 |
/*Tests sending in fast mode*/
|
219 |
WL_DEBUG_PRINT_P("\r\nTests sending basic packets in fast mode...\r\n");
|
220 |
status = 0;
|
221 |
uint16_t data = xbee_get_address(); |
222 |
/* status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, BROADCAST, FAST);
|
223 |
WL_DEBUG_PRINT_P("Global fast broadcast basic send exit code ");
|
224 |
usb_puti(status);
|
225 |
status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, PAN, FAST);
|
226 |
WL_DEBUG_PRINT_P("\r\nGlobal fast pan send basic exit code ");
|
227 |
usb_puti(status);
|
228 |
status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, BROADCAST, FAST);
|
229 |
WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast basic send exit code ");
|
230 |
usb_puti(status);
|
231 |
status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, PAN, FAST);
|
232 |
WL_DEBUG_PRINT_P("\r\nGlobal fast pan send basic exit code ");
|
233 |
usb_puti(status);
|
234 |
status = wl_send((uint8_t*)&data, 2, 1, GLOBAL, BROADCAST, FAST);
|
235 |
WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast group 1 send exit code ");
|
236 |
usb_puti(status);
|
237 |
status = wl_send((uint8_t*)&data, 2, 2, GLOBAL, PAN, FAST);
|
238 |
WL_DEBUG_PRINT_P("\r\nGlobal fast pan send group 2 exit code ");
|
239 |
usb_puti(status);
|
240 |
status = wl_send((uint8_t*)&data, 2, 1, GLOBAL, BROADCAST, FAST);
|
241 |
WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast group 3 send exit code ");
|
242 |
usb_puti(status);
|
243 |
status = wl_send((uint8_t*)&data, 2, 2, GLOBAL, PAN, FAST);
|
244 |
WL_DEBUG_PRINT_P("\r\nGlobal fast pan send group 4 exit code ");
|
245 |
usb_puti(status);
|
246 |
WL_DEBUG_PRINT_P("\r\nFast send tests successful\r\n");
|
247 |
*/
|
248 |
/*Sends packets in fast mode until other robot responds*/
|
249 |
status = 0;
|
250 |
int len = 0; |
251 |
uint8_t buffer[10];
|
252 |
uint8_t sendBuffer[2];
|
253 |
uint16_t address = 0;
|
254 |
orb2_set_color(BLUE); |
255 |
while(1){ |
256 |
/* WL_DEBUG_PRINT_P("\r\nMy address: ");
|
257 |
usb_puti(data);
|
258 |
usb_puti(xbee_get_address());
|
259 |
sendBuffer[0] = (data& 0xFF00) >> 8;
|
260 |
sendBuffer[1] = (data& 0x00FF);
|
261 |
wl_send((uint8_t*)&sendBuffer, 2, 0, GLOBAL, BROADCAST, FAST);
|
262 |
delay_ms(1000);
|
263 |
len = wl_get_basic(buffer, 10);
|
264 |
if(len != 0){
|
265 |
address = (buffer[0] << 8) + buffer[1];
|
266 |
orb2_set_color(GREEN);
|
267 |
WL_DEBUG_PRINT_P("\r\nLength: ");
|
268 |
WL_DEBUG_PRINT_INT(len);
|
269 |
WL_DEBUG_PRINT_P("\r\nFriend address: ");
|
270 |
usb_puth16(address);
|
271 |
friendAddress = address;
|
272 |
}
|
273 |
*/ if(button1_read()){ |
274 |
test_sending(); |
275 |
break;
|
276 |
} |
277 |
if(button2_read()){
|
278 |
test_receiving(); |
279 |
break;
|
280 |
} |
281 |
} |
282 |
|
283 |
|
284 |
/*Terminates wireless functions*/
|
285 |
WL_DEBUG_PRINT_P("\r\n\r\nTerminating wireless...\r\n");
|
286 |
status = wl_init(); |
287 |
switch(status){
|
288 |
case 0: |
289 |
WL_DEBUG_PRINT_P("Wireless termination successful\r\n\r\n");
|
290 |
orb1_set_color(BLUE); |
291 |
break;
|
292 |
case -3: |
293 |
WL_DEBUG_PRINT_P("Termination failed: library not initialized\r\n\r\n");
|
294 |
orb1_set_color(BLUE); |
295 |
break;
|
296 |
case -5: |
297 |
WL_DEBUG_PRINT_P("Termination failed\r\n\r\n");
|
298 |
orb1_set_color(RED); |
299 |
break;
|
300 |
case -6: |
301 |
WL_DEBUG_PRINT_P("Termination failed: function unregistration failed\r\n\r\n");
|
302 |
orb1_set_color(ORANGE); |
303 |
break;
|
304 |
default:
|
305 |
WL_DEBUG_PRINT_P("Error: Unreconnized status code: ");
|
306 |
usb_puti(status); |
307 |
orb1_set_color(RED); |
308 |
break;
|
309 |
} |
310 |
|
311 |
WL_DEBUG_PRINT_P("\r\n\r\nWireless Library tests completed");
|
312 |
while(1){} |
313 |
} |
314 |
|
315 |
void test_sending(){
|
316 |
uint8_t count; |
317 |
//Testing all wrappers for FAST mode
|
318 |
for(count = 0; count < 5; count++){ |
319 |
usb_puti(count); |
320 |
usb_puti(wl_send_basic(&count, 1));
|
321 |
delay_ms(1000);
|
322 |
} |
323 |
for(count = 5; count < 10; count++){ |
324 |
usb_puti(count); |
325 |
usb_puti(wl_send_global(&count, 1, 0)); |
326 |
delay_ms(1000);
|
327 |
} |
328 |
for(count = 10; count < 15; count++){ |
329 |
usb_puti(count); |
330 |
usb_puti(wl_send_pan(&count, 1, xbee_get_pan()));
|
331 |
delay_ms(1000);
|
332 |
} |
333 |
/* for(count = 15; count < 20; count++){
|
334 |
usb_puti(count);
|
335 |
usb_puti(wl_send_robot(&count, 1, 0, friendAddress, FAST));
|
336 |
delay_ms(1000);
|
337 |
}
|
338 |
*/ for(count = 20; count < 25; count++){ |
339 |
usb_puti(count); |
340 |
usb_puti(wl_send_global(&count, 1, 1)); |
341 |
delay_ms(1000);
|
342 |
} |
343 |
for(count = 25; count < 30; count++){ |
344 |
usb_puti(count); |
345 |
usb_puti(wl_send_global(&count, 1, 2)); |
346 |
delay_ms(1000);
|
347 |
} |
348 |
for(count = 30; count < 35; count++){ |
349 |
usb_puti(count); |
350 |
usb_puti(wl_send_global(&count, 1, 3)); |
351 |
delay_ms(1000);
|
352 |
} |
353 |
for(count = 35; count < 40; count++){ |
354 |
usb_puti(count); |
355 |
usb_puti(wl_send_global(&count, 1, 4)); |
356 |
delay_ms(1000);
|
357 |
} |
358 |
//FAST mode tests completed. Now testing ACK system
|
359 |
/* for(count = 40; count < 45; count++){
|
360 |
usb_puti(count);
|
361 |
usb_puti(wl_send_robot(&count, 1, 0, friendAddress, RELIABLE));
|
362 |
delay_ms(1000);
|
363 |
}
|
364 |
for(count = 45; count < 50; count++){
|
365 |
usb_puti(count);
|
366 |
usb_puti(wl_send_robot(&count, 1, 1, friendAddress, RELIABLE));
|
367 |
delay_ms(1000);
|
368 |
}
|
369 |
for(count = 50; count < 55; count++){
|
370 |
usb_puti(count);
|
371 |
usb_puti(wl_send_robot(&count, 1, 2, friendAddress, RELIABLE));
|
372 |
delay_ms(1000);
|
373 |
}
|
374 |
for(count = 55; count < 60; count++){
|
375 |
usb_puti(count);
|
376 |
usb_puti(wl_send_robot(&count, 1, 3, friendAddress, RELIABLE));
|
377 |
delay_ms(1000);
|
378 |
}
|
379 |
for(count = 60; count < 65; count++){
|
380 |
usb_puti(count);
|
381 |
usb_puti(wl_send_robot(&count, 1, 4, friendAddress, RELIABLE));
|
382 |
delay_ms(1000);
|
383 |
}
|
384 |
WL_DEBUG_PRINT_P("ACK Errors: ");
|
385 |
usb_puti(wl_ack_error());
|
386 |
wl_ack_reset();
|
387 |
usb_puti(wl_ack_error());
|
388 |
for(count = 65; count < 70; count++){//changed friendAddress, all should fail
|
389 |
usb_puti(count);
|
390 |
usb_puti(wl_send_robot(&count, 1, 0, friendAddress + 1, RELIABLE));
|
391 |
delay_ms(count * 10);
|
392 |
}
|
393 |
WL_DEBUG_PRINT_P("ACK Errors: ");
|
394 |
usb_puti(wl_ack_error());
|
395 |
*/}
|
396 |
|
397 |
void test_receiving(){
|
398 |
int8_t result, length; |
399 |
char* data[8]; |
400 |
while(1){ |
401 |
result = wl_get_basic(data, length); |
402 |
if(result){
|
403 |
WL_DEBUG_PRINT_P("\r\nData length: ");
|
404 |
WL_DEBUG_PRINT_INT(result); |
405 |
WL_DEBUG_PRINT_P("\r\nData: ");
|
406 |
WL_DEBUG_PRINT_HEX(*data); |
407 |
}else{
|
408 |
delay_ms(100);
|
409 |
} |
410 |
} |
411 |
} |
412 |
|
413 |
void group_1_function(uint8_t* data,uint8_t length,uint8_t source){
|
414 |
WL_DEBUG_PRINT_P("\r\nFunction 1 called");
|
415 |
return 0; |
416 |
} |
417 |
void group_2_function(uint8_t* data,uint8_t length,uint8_t source){
|
418 |
WL_DEBUG_PRINT_P("\r\nFunction 2 called");
|
419 |
return 0; |
420 |
} |
421 |
void group_3_function(uint8_t* data,uint8_t length,uint8_t source){
|
422 |
WL_DEBUG_PRINT_P("\r\nFunction 3 called");
|
423 |
return 0; |
424 |
} |
425 |
void group_4_function(uint8_t* data,uint8_t length,uint8_t source){
|
426 |
WL_DEBUG_PRINT_P("\r\nFunction 4 called");
|
427 |
return 0; |
428 |
} |
429 |
//The first robot to receive the address of another robot will trigger this function.
|
430 |
void test_function_1(void){ |
431 |
uint16_t myAddress = xbee_get_address(); |
432 |
usb_puti(myAddress); |
433 |
|
434 |
return 0; |
435 |
} |
436 |
|
437 |
//Cheat Functions
|
438 |
//These will run instead of the real functions while David fixes the library
|
439 |
|