root / branches / wireless / code / projects / unit_tests / test_wireless2.c @ 1650
History | View | Annotate | Download (11.1 KB)
1 |
#include <string.h> |
---|---|
2 |
#include <wireless.h> |
3 |
#include <lights.h> |
4 |
#include <dragonfly_lib.h> |
5 |
#include <xbee.h> |
6 |
#include <avr/pgmspace.h> |
7 |
|
8 |
void group_1_function(uint8_t* data,uint8_t length,uint8_t source);
|
9 |
void group_2_function(uint8_t* data,uint8_t length,uint8_t source);
|
10 |
void group_3_function(uint8_t* data,uint8_t length,uint8_t source);
|
11 |
void group_4_function(uint8_t* data,uint8_t length,uint8_t source);
|
12 |
void test_function_1(void); |
13 |
|
14 |
uint16_t friendAddress = 0;
|
15 |
|
16 |
char debug_output1[] PROGMEM = "New Wireless Library Test Suite\r\n"; |
17 |
char debug_output2[] PROGMEM = "Initializing library...\r\n"; |
18 |
char debug_output3[] PROGMEM = "Library initialization successful\r\n\r\n"; |
19 |
char debug_output4[] PROGMEM = "Initialization failed: already initialized\r\n\r\n"; |
20 |
char debug_output5[] PROGMEM = "Initialization failed: XBEE initialization failed\r\n\r\n"; |
21 |
char debug_output6[] PROGMEM = "Error: Unreconnized status code: "; |
22 |
char debug_output7[] PROGMEM = "\r\n\r\n"; |
23 |
char debug_output8[] PROGMEM = "Testing constants..."; |
24 |
char debug_output9[] PROGMEM = "\r\nGLOBAL defined as "; |
25 |
char debug_output10[] PROGMEM = "\r\nPAN defined as "; |
26 |
char debug_output11[] PROGMEM = "\r\nBROADCAST defined as "; |
27 |
char debug_output12[] PROGMEM = "\r\nRELIABLE defined as "; |
28 |
char debug_output13[] PROGMEM = "\r\nFAST defined as "; |
29 |
char debug_output14[] PROGMEM = "\r\nNORMAL_PRIORITY defined as "; |
30 |
char debug_output15[] PROGMEM = "\r\nHIGH_PRIORITY defined as "; |
31 |
char debug_output16[] PROGMEM = ".\r\nConstant test complete. There were "; |
32 |
char debug_output17[] PROGMEM = " errors\r\n"; |
33 |
char debug_output18[] PROGMEM = "\r\nTesting function registration"; |
34 |
char debug_output19[] PROGMEM = "\r\nFunction registration error: attempt "; |
35 |
char debug_output20[] PROGMEM = " returned "; |
36 |
char debug_output21[] PROGMEM = " instead of success\r\n"; |
37 |
char debug_output22[] PROGMEM = "\r\nFunction registration error: attempt "; |
38 |
char debug_output23[] PROGMEM = " succeeded instead of failing\r\n"; |
39 |
char debug_output24[] PROGMEM = "\r\nFunction registration error: attempt "; |
40 |
char debug_output25[] PROGMEM = " instead of -5\r\n"; |
41 |
char debug_output26[] PROGMEM = "\r\nCongrats, you let an array write to index -1\r\n"; |
42 |
char debug_output27[] PROGMEM = "Registration test completed. There were "; |
43 |
char debug_output28[] PROGMEM = " errors\r\n"; |
44 |
char debug_output29[] PROGMEM = "\r\nTesting XBee fuctions...\r\n"; |
45 |
char debug_output30[] PROGMEM = "Pan error: defaulted to non-default Pan id :"; |
46 |
char debug_output31[] PROGMEM = "\r\nPan error: error setting Pan id: "; |
47 |
char debug_output32[] PROGMEM = "\r\nPan error: Pan id reads different than set value 1: "; |
48 |
char debug_output33[] PROGMEM = "\r\nXBee tests completed. There were "; |
49 |
char debug_output34[] PROGMEM = " errors.\r\n"; |
50 |
char debug_output35[] PROGMEM = "\r\nTests sending basic packets in fast mode...\r\n"; |
51 |
char debug_output36[] PROGMEM = "Global fast broadcast basic send exit code "; |
52 |
char debug_output37[] PROGMEM = "\r\nGlobal fast pan send basic exit code "; |
53 |
char debug_output38[] PROGMEM = "\r\nGlobal fast broadcast basic send exit code "; |
54 |
char debug_output39[] PROGMEM = "\r\nGlobal fast pan send basic exit code "; |
55 |
char debug_output40[] PROGMEM = "\r\nGlobal fast broadcast group 1 send exit code "; |
56 |
char debug_output41[] PROGMEM = "\r\nGlobal fast pan send group 2 exit code "; |
57 |
char debug_output42[] PROGMEM = "\r\nGlobal fast broadcast group 3 send exit code "; |
58 |
char debug_output43[] PROGMEM = "\r\nGlobal fast pan send group 4 exit code "; |
59 |
char debug_output44[] PROGMEM = "\r\nFast send tests successful\r\n"; |
60 |
char debug_output45[] PROGMEM = "Sending basic packets until other robot responds"; |
61 |
char debug_output46[] PROGMEM = "\r\nReceive error code "; |
62 |
char debug_output47[] PROGMEM = "\r\nReceived packet from robot: "; |
63 |
char debug_output48[] PROGMEM = "\r\n\r\nTerminating wireless...\r\n"; |
64 |
char debug_output49[] PROGMEM = "Wireless termination successful\r\n\r\n"; |
65 |
char debug_output50[] PROGMEM = "Termination failed: library not initialized\r\n\r\n"; |
66 |
char debug_output51[] PROGMEM = "Termination failed\r\n\r\n"; |
67 |
char debug_output52[] PROGMEM = "Termination failed: function unregistration failed\r\n\r\n"; |
68 |
char debug_output53[] PROGMEM = "Error: Unreconnized status code: "; |
69 |
char debug_output54[] PROGMEM = "\r\n\r\nWireless Library tests completed"; |
70 |
char debug_output55[] PROGMEM = "\r\nFunction 1 called"; |
71 |
char debug_output56[] PROGMEM = "\r\nFunction 2 called"; |
72 |
char debug_output57[] PROGMEM = "\r\nFunction 3 called"; |
73 |
char debug_output58[] PROGMEM = "\r\nFunction 4 called"; |
74 |
|
75 |
|
76 |
/* This function tests out the full functionality of the new wireless library.
|
77 |
* It must be run on two colony bots simultaneously to properly test all funtions.
|
78 |
*/
|
79 |
void testwireless2(void) |
80 |
{ |
81 |
orb_init(); |
82 |
usb_init(); |
83 |
uint8_t status = 0;
|
84 |
|
85 |
usb_puts((PGM_P)debug_output1); |
86 |
|
87 |
/*Initialize the wirelss library*/
|
88 |
usb_puts(debug_output2); |
89 |
orb1_set_color(BLUE); |
90 |
status = wl_init(); |
91 |
switch(status){
|
92 |
case 0: |
93 |
usb_puts((PGM_P)debug_output3); |
94 |
orb1_set_color(GREEN); |
95 |
break;
|
96 |
case -1: |
97 |
usb_puts((PGM_P)debug_output4); |
98 |
orb1_set_color(GREEN); |
99 |
break;
|
100 |
case -2: |
101 |
usb_puts((PGM_P)debug_output5); |
102 |
orb1_set_color(RED); |
103 |
break;
|
104 |
default:
|
105 |
usb_puts((PGM_P)debug_output6); |
106 |
usb_puti(status); |
107 |
usb_puts((PGM_P)debug_output7); |
108 |
orb1_set_color(RED); |
109 |
break;
|
110 |
} |
111 |
while((status!=0) && 1); |
112 |
|
113 |
/*Test all constants defined correctly*/
|
114 |
status = 0;
|
115 |
usb_puts((PGM_P)debug_output8); |
116 |
orb2_set_color(GREEN); |
117 |
if(GLOBAL!=0){ |
118 |
usb_puts((PGM_P)debug_output9); |
119 |
usb_puti(GLOBAL); |
120 |
status++; |
121 |
} |
122 |
usb_puts(".");
|
123 |
if(PAN!=1){ |
124 |
usb_puts((PGM_P)debug_output10); |
125 |
usb_puti(PAN); |
126 |
status++; |
127 |
} |
128 |
usb_puts(".");
|
129 |
if(BROADCAST!=0xFFFF){ |
130 |
usb_puts((PGM_P)debug_output11); |
131 |
usb_puti(BROADCAST); |
132 |
status++; |
133 |
} |
134 |
usb_puts(".");
|
135 |
if(RELIABLE!=0){ |
136 |
usb_puts((PGM_P)debug_output12); |
137 |
usb_puti(RELIABLE); |
138 |
status++; |
139 |
} |
140 |
usb_puts(".");
|
141 |
if(FAST!=1){ |
142 |
usb_puts((PGM_P)debug_output13); |
143 |
usb_puti(FAST); |
144 |
status++; |
145 |
} |
146 |
usb_puts(".");
|
147 |
if(NORMAL_PRIORITY!=0){ |
148 |
usb_puts((PGM_P)debug_output14); |
149 |
usb_puti(NORMAL_PRIORITY); |
150 |
status++; |
151 |
} |
152 |
usb_puts(".");
|
153 |
if(HIGH_PRIORITY!=1){ |
154 |
usb_puts((PGM_P)debug_output15); |
155 |
usb_puti(HIGH_PRIORITY); |
156 |
status++; |
157 |
} |
158 |
usb_puts((PGM_P)debug_output16); |
159 |
usb_puti(status); |
160 |
usb_puts((PGM_P)debug_output17); |
161 |
if(status!=0){ |
162 |
orb2_set_color(ORANGE); |
163 |
delay_ms(500);
|
164 |
} |
165 |
/*Tests function registration*/
|
166 |
usb_puts((PGM_P)debug_output18); |
167 |
int8_t registers[8], count;
|
168 |
status = 0;
|
169 |
orb2_set_color(GREEN); |
170 |
registers[0] = wl_register_handler(1, group_1_function, 0); |
171 |
registers[1] = wl_register_handler(2, group_2_function, 1); |
172 |
registers[2] = wl_register_handler(3, group_3_function, 0); |
173 |
registers[3] = wl_register_handler(4, group_4_function, 1); |
174 |
registers[4] = wl_register_handler(0, group_1_function, 0); |
175 |
registers[5] = wl_register_handler(6, NULL, 0); |
176 |
registers[6] = wl_register_handler(30, group_3_function, 0); |
177 |
registers[7] = wl_register_handler(-1, group_4_function, 0); |
178 |
for(count=0; count<=3; count++){ |
179 |
if(registers[count] != 0){ |
180 |
usb_puts((PGM_P)debug_output19); |
181 |
usb_puti(count); |
182 |
usb_puts((PGM_P)debug_output20); |
183 |
usb_puti(registers[count]); |
184 |
usb_puts((PGM_P)debug_output21); |
185 |
orb2_set_color(ORANGE); |
186 |
status++; |
187 |
} |
188 |
} |
189 |
for(count=4; count<=6; count++){ |
190 |
if(registers[count] == 0){ |
191 |
usb_puts((PGM_P)debug_output22); |
192 |
usb_puti(count); |
193 |
usb_puts((PGM_P)debug_output23); |
194 |
orb2_set_color(ORANGE); |
195 |
status++; |
196 |
} |
197 |
if(registers[count] != 0 && registers[count] != -5){ |
198 |
usb_puts((PGM_P)debug_output24); |
199 |
usb_puti(count); |
200 |
usb_puts((PGM_P)debug_output20); |
201 |
usb_puti(registers[count]); |
202 |
usb_puts((PGM_P)debug_output25); |
203 |
orb2_set_color(ORANGE); |
204 |
status++; |
205 |
} |
206 |
} |
207 |
if(registers[7] == 0){ |
208 |
usb_puts((PGM_P)debug_output26); |
209 |
orb2_set_color(RED); |
210 |
status++; |
211 |
} |
212 |
usb_puts((PGM_P)debug_output27); |
213 |
usb_puti(status); |
214 |
usb_puts((PGM_P)debug_output28); |
215 |
delay_ms(500);
|
216 |
|
217 |
/*Tests XBee functions*/
|
218 |
usb_puts((PGM_P)debug_output29); |
219 |
status = 0;
|
220 |
orb2_set_color(GREEN); |
221 |
unsigned int pan = xbee_get_pan(); |
222 |
if(pan != 0){ |
223 |
usb_puts((PGM_P)debug_output30); |
224 |
usb_puti(pan); |
225 |
orb2_set_color(ORANGE); |
226 |
status++; |
227 |
} |
228 |
pan = xbee_set_pan(1);
|
229 |
if(pan != 0){ |
230 |
usb_puts((PGM_P)debug_output31); |
231 |
usb_puti(pan); |
232 |
orb2_set_color(ORANGE); |
233 |
status++; |
234 |
} |
235 |
pan = xbee_get_pan(); |
236 |
if(pan != 0){ |
237 |
usb_puts((PGM_P)debug_output32); |
238 |
usb_puti(pan); |
239 |
orb2_set_color(ORANGE); |
240 |
status++; |
241 |
} |
242 |
|
243 |
usb_puts((PGM_P)debug_output33); |
244 |
usb_puti(status); |
245 |
usb_puts((PGM_P)debug_output34); |
246 |
|
247 |
/*Tests sending in fast mode*/
|
248 |
usb_puts((PGM_P)debug_output35); |
249 |
status = 0;
|
250 |
uint16_t data = xbee_get_address(); |
251 |
status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, BROADCAST, FAST); |
252 |
usb_puts((PGM_P)debug_output36); |
253 |
usb_puti(status); |
254 |
status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, PAN, FAST); |
255 |
usb_puts((PGM_P)debug_output37); |
256 |
usb_puti(status); |
257 |
status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, BROADCAST, FAST); |
258 |
usb_puts((PGM_P)debug_output38); |
259 |
usb_puti(status); |
260 |
status = wl_send((uint8_t*)&data, 2, 0, GLOBAL, PAN, FAST); |
261 |
usb_puts((PGM_P)debug_output39); |
262 |
usb_puti(status); |
263 |
status = wl_send((uint8_t*)&data, 2, 1, GLOBAL, BROADCAST, FAST); |
264 |
usb_puts((PGM_P)debug_output40); |
265 |
usb_puti(status); |
266 |
status = wl_send((uint8_t*)&data, 2, 2, GLOBAL, PAN, FAST); |
267 |
usb_puts((PGM_P)debug_output41); |
268 |
usb_puti(status); |
269 |
status = wl_send((uint8_t*)&data, 2, 1, GLOBAL, BROADCAST, FAST); |
270 |
usb_puts((PGM_P)debug_output42); |
271 |
usb_puti(status); |
272 |
status = wl_send((uint8_t*)&data, 2, 2, GLOBAL, PAN, FAST); |
273 |
usb_puts((PGM_P)debug_output43); |
274 |
usb_puti(status); |
275 |
usb_puts((PGM_P)debug_output44); |
276 |
|
277 |
/*Sends packets in fast mode until other robot responds*/
|
278 |
usb_puts((PGM_P)debug_output45); |
279 |
status = 0;
|
280 |
char address[2]; /*will contain a 16 bit address, so length always 2*/ |
281 |
while(status <= 0){ |
282 |
wl_send((uint8_t*)&data, 2, 0, GLOBAL, BROADCAST, FAST); |
283 |
status = wl_get_basic(address, 2);
|
284 |
if(status < 0){ |
285 |
usb_puts((PGM_P)debug_output46); |
286 |
usb_puti(status); |
287 |
orb2_set_color(ORANGE); |
288 |
} |
289 |
} |
290 |
usb_puts((PGM_P)debug_output47); |
291 |
usb_puti((uint16_t)address); |
292 |
friendAddress = *address; |
293 |
|
294 |
|
295 |
/*Terminates wireless functions*/
|
296 |
usb_puts((PGM_P)debug_output48); |
297 |
status = wl_init(); |
298 |
switch(status){
|
299 |
case 0: |
300 |
usb_puts((PGM_P)debug_output49); |
301 |
orb1_set_color(BLUE); |
302 |
break;
|
303 |
case -3: |
304 |
usb_puts((PGM_P)debug_output50); |
305 |
orb1_set_color(BLUE); |
306 |
break;
|
307 |
case -5: |
308 |
usb_puts((PGM_P)debug_output51); |
309 |
orb1_set_color(RED); |
310 |
break;
|
311 |
case -6: |
312 |
usb_puts((PGM_P)debug_output52); |
313 |
orb1_set_color(ORANGE); |
314 |
break;
|
315 |
default:
|
316 |
usb_puts((PGM_P)debug_output53); |
317 |
usb_puti(status); |
318 |
orb1_set_color(RED); |
319 |
break;
|
320 |
} |
321 |
|
322 |
usb_puts((PGM_P)debug_output54); |
323 |
while(1){} |
324 |
} |
325 |
|
326 |
void group_1_function(uint8_t* data,uint8_t length,uint8_t source){
|
327 |
usb_puts((PGM_P)debug_output55); |
328 |
return 0; |
329 |
} |
330 |
void group_2_function(uint8_t* data,uint8_t length,uint8_t source){
|
331 |
usb_puts((PGM_P)debug_output56); |
332 |
return 0; |
333 |
} |
334 |
void group_3_function(uint8_t* data,uint8_t length,uint8_t source){
|
335 |
usb_puts((PGM_P)debug_output57); |
336 |
return 0; |
337 |
} |
338 |
void group_4_function(uint8_t* data,uint8_t length,uint8_t source){
|
339 |
usb_puts((PGM_P)debug_output58); |
340 |
return 0; |
341 |
} |
342 |
//The first robot to receive the address of another robot will trigger this function.
|
343 |
uint8_t test_function_1(void){
|
344 |
uint16_t myAddress = xbee_get_address(); |
345 |
usb_puti(myAddress); |
346 |
|
347 |
return 0; |
348 |
} |
349 |
|
350 |
//Cheat Functions
|
351 |
//These will run instead of the real functions while David fixes the library
|
352 |
|