root / branches / wireless / code / projects / unit_tests / test_wireless2.c @ 1647
History | View | Annotate | Download (7.96 KB)
1 |
#include <stdlib.h> |
---|---|
2 |
#include <stdio.h> |
3 |
#include <string.h> |
4 |
#include <wireless.h> |
5 |
#include <lights.h> |
6 |
#include <dragonfly_lib.h> |
7 |
#include <xbee.h> |
8 |
|
9 |
uint8_t group_1_function(uint8_t* data,uint8_t length,uint8_t source); |
10 |
uint8_t group_2_function(uint8_t* data,uint8_t length,uint8_t source); |
11 |
uint8_t group_3_function(uint8_t* data,uint8_t length,uint8_t source); |
12 |
uint8_t group_4_function(uint8_t* data,uint8_t length,uint8_t source); |
13 |
uint8_t test_function_1(void);
|
14 |
|
15 |
uint16_t friendAddress = 0;
|
16 |
|
17 |
/* This function tests out the full functionality of the new wireless library.
|
18 |
* It must be run on two colony bots simultaneously to properly test all funtions.
|
19 |
*/
|
20 |
int main(int argsc, char* argv[]) |
21 |
{ |
22 |
orb_init(); |
23 |
usb_init(); |
24 |
int status = 0; |
25 |
|
26 |
usb_puts("New Wireless Library Test Suite\r\n");
|
27 |
|
28 |
/*Initialize the wirelss library*/
|
29 |
usb_puts("Initializing library...\r\n");
|
30 |
orb1_set_color(BLUE); |
31 |
status = wl_init(); |
32 |
switch(status){
|
33 |
case 0: |
34 |
usb_puts("Library initialization successful\r\n\r\n");
|
35 |
orb1_set_color(GREEN); |
36 |
break;
|
37 |
case -1: |
38 |
usb_puts("Initialization failed: already initialized\r\n\r\n");
|
39 |
orb1_set_color(GREEN); |
40 |
break;
|
41 |
case -2: |
42 |
usb_puts("Initialization failed: XBEE initialization failed\r\n\r\n");
|
43 |
orb1_set_color(RED); |
44 |
break;
|
45 |
default:
|
46 |
usb_puts("Error: Unreconnized status code: ");
|
47 |
usb_puti(status); |
48 |
usb_puts("\r\n\r\n");
|
49 |
orb1_set_color(RED); |
50 |
break;
|
51 |
} |
52 |
while((status!=0) && 1); |
53 |
|
54 |
/*Test all constants defined correctly*/
|
55 |
status = 0;
|
56 |
usb_puts("Testing constants...");
|
57 |
orb2_set_color(GREEN); |
58 |
if(GLOBAL!=0){ |
59 |
usb_puts("\r\nGLOBAL defined as ");
|
60 |
usb_puti(GLOBAL); |
61 |
status++; |
62 |
} |
63 |
usb_puts(".");
|
64 |
if(PAN!=1){ |
65 |
usb_puts("\r\nPAN defined as ");
|
66 |
usb_puti(PAN); |
67 |
status++; |
68 |
} |
69 |
usb_puts(".");
|
70 |
if(BROADCAST!=0xFFFF){ |
71 |
usb_puts("\r\nBROADCAST defined as ");
|
72 |
usb_puti(BROADCAST); |
73 |
status++; |
74 |
} |
75 |
usb_puts(".");
|
76 |
if(RELIABLE!=0){ |
77 |
usb_puts("\r\nRELIABLE defined as ");
|
78 |
usb_puti(RELIABLE); |
79 |
status++; |
80 |
} |
81 |
usb_puts(".");
|
82 |
if(FAST!=1){ |
83 |
usb_puts("\r\nFAST defined as ");
|
84 |
usb_puti(FAST); |
85 |
status++; |
86 |
} |
87 |
usb_puts(".");
|
88 |
if(NORMAL_PRIORITY!=0){ |
89 |
usb_puts("\r\nNORMAL_PRIORITY defined as ");
|
90 |
usb_puti(NORMAL_PRIORITY); |
91 |
status++; |
92 |
} |
93 |
usb_puts(".");
|
94 |
if(HIGH_PRIORITY!=1){ |
95 |
usb_puts("\r\nHIGH_PRIORITY defined as ");
|
96 |
usb_puti(HIGH_PRIORITY); |
97 |
status++; |
98 |
} |
99 |
usb_puts(".\r\nConstant test complete. There were ");
|
100 |
usb_puti(status); |
101 |
usb_puts(" errors\r\n");
|
102 |
if(status!=0){ |
103 |
orb2_set_color(ORANGE); |
104 |
delay_ms(500);
|
105 |
} |
106 |
/*Tests function registration*/
|
107 |
usb_puts("\r\nTesting function registration");
|
108 |
int registers[8], count; |
109 |
status = 0;
|
110 |
orb2_set_color(GREEN); |
111 |
registers[0] = wl_register_handler(1, group_1_function, 0); |
112 |
registers[1] = wl_register_handler(2, group_2_function, 1); |
113 |
registers[2] = wl_register_handler(3, group_3_function, 0); |
114 |
registers[3] = wl_register_handler(4, group_4_function, 1); |
115 |
registers[4] = wl_register_handler(0, group_1_function, 0); |
116 |
registers[5] = wl_register_handler(6, NULL, 0); |
117 |
registers[6] = wl_register_handler(30, group_3_function, 0); |
118 |
registers[7] = wl_register_handler(-1, group_4_function, 0); |
119 |
for(count=0; count<=3; count++){ |
120 |
if(registers[count] != 0){ |
121 |
usb_puts("\r\nFunction registration error: attempt ");
|
122 |
usb_puti(count); |
123 |
usb_puts(" returned ");
|
124 |
usb_puti(registers[count]); |
125 |
usb_puts(" instead of success\r\n");
|
126 |
orb2_set_color(ORANGE); |
127 |
status++; |
128 |
} |
129 |
} |
130 |
for(count=4; count<=6; count++){ |
131 |
if(registers[count] == 0){ |
132 |
usb_puts("\r\nFunction registration error: attempt ");
|
133 |
usb_puti(count); |
134 |
usb_puts(" succeeded instead of failing\r\n");
|
135 |
orb2_set_color(ORANGE); |
136 |
status++; |
137 |
} |
138 |
if(registers[count] != 0 && registers[count] != -5){ |
139 |
usb_puts("\r\nFunction registration error: attempt ");
|
140 |
usb_puti(count); |
141 |
usb_puts(" returned ");
|
142 |
usb_puti(registers[count]); |
143 |
usb_puts(" instead of -5\r\n");
|
144 |
orb2_set_color(ORANGE); |
145 |
status++; |
146 |
} |
147 |
} |
148 |
if(registers[7] == 0){ |
149 |
usb_puts("\r\nCongrats, you let an array write to index -1\r\n");
|
150 |
orb2_set_color(RED); |
151 |
status++; |
152 |
} |
153 |
usb_puts("Registration test completed. There were ");
|
154 |
usb_puti(status); |
155 |
usb_puts(" errors\r\n");
|
156 |
delay_ms(500);
|
157 |
|
158 |
/*Tests XBee functions*/
|
159 |
usb_puts("\r\nTesting XBee fuctions...\r\n");
|
160 |
status = 0;
|
161 |
orb2_set_color(GREEN); |
162 |
unsigned int pan = xbee_get_pan_id(); |
163 |
if(pan != 0){ |
164 |
usb_puts("Pan error: defaulted to non-default Pan id :");
|
165 |
usb_puti(pan); |
166 |
orb2_set_color(ORANGE); |
167 |
status++; |
168 |
} |
169 |
pan = xbee_set_pan_id(1);
|
170 |
if(pan != 0){ |
171 |
usb_puts("\r\nPan error: error setting Pan id: ");
|
172 |
usb_puti(pan); |
173 |
orb2_set_color(ORANGE); |
174 |
status++; |
175 |
} |
176 |
pan = xbee_get_pan_id(); |
177 |
if(pan != 0){ |
178 |
usb_puts("\r\nPan error: Pan id reads different than set value 1: ");
|
179 |
usb_puti(pan); |
180 |
orb2_set_color(ORANGE); |
181 |
status++; |
182 |
} |
183 |
|
184 |
usb_puts("\r\nXBee tests completed. There were ");
|
185 |
usb_puti(status); |
186 |
usb_puts(" errors.\r\n");
|
187 |
|
188 |
/*Tests sending in fast mode*/
|
189 |
usb_puts("\r\nTests sending basic packets in fast mode...\r\n");
|
190 |
status = 0;
|
191 |
uint16_t data = xbee_get_address(); |
192 |
status = wl_send(&data, 2, 0, GLOBAL, BROADCAST, FAST); |
193 |
usb_puts("Global fast broadcast basic send exit code ");
|
194 |
usb_puti(status); |
195 |
status = wl_send(&data, 2, 0, GLOBAL, PAN, FAST); |
196 |
usb_puts("\r\nGlobal fast pan send basic exit code ");
|
197 |
usb_puti(status); |
198 |
status = wl_send(&data, 2, 0, GLOBAL, BROADCAST, FAST); |
199 |
usb_puts("\r\nGlobal fast broadcast basic send exit code ");
|
200 |
usb_puti(status); |
201 |
status = wl_send(&data, 2, 0, GLOBAL, PAN, FAST); |
202 |
usb_puts("\r\nGlobal fast pan send basic exit code ");
|
203 |
usb_puti(status); |
204 |
status = wl_send(&data, 2, 1, GLOBAL, BROADCAST, FAST); |
205 |
usb_puts("\r\nGlobal fast broadcast group 1 send exit code ");
|
206 |
usb_puti(status); |
207 |
status = wl_send(&data, 2, 2, GLOBAL, PAN, FAST); |
208 |
usb_puts("\r\nGlobal fast pan send group 2 exit code ");
|
209 |
usb_puti(status); |
210 |
status = wl_send(&data, 2, 1, GLOBAL, BROADCAST, FAST); |
211 |
usb_puts("\r\nGlobal fast broadcast group 3 send exit code ");
|
212 |
usb_puti(status); |
213 |
status = wl_send(&data, 2, 2, GLOBAL, PAN, FAST); |
214 |
usb_puts("\r\nGlobal fast pan send group 4 exit code ");
|
215 |
usb_puti(status); |
216 |
usb_puts("\r\nFast send tests successful\r\n");
|
217 |
|
218 |
/*Sends packets in fast mode until other robot responds*/
|
219 |
usb_puts("Sending basic packets until other robot responds");
|
220 |
status = 0;
|
221 |
char address[2]; /*will contain a 16 bit address, so length always 2*/ |
222 |
while(status <= 0){ |
223 |
wl_send(data, 2, 0, GLOBAL, BROADCAST, FAST); |
224 |
status = wl_get_basic(&address, 2);
|
225 |
if(status < 0){ |
226 |
usb_puts("\r\nReceive error code ");
|
227 |
usb_puti(status); |
228 |
orb2_set_color(ORANGE); |
229 |
} |
230 |
} |
231 |
usb_puts("\r\nReceived packet from robot: ");
|
232 |
usb_puti(address); |
233 |
friendAddress = *address; |
234 |
|
235 |
|
236 |
/*Terminates wireless functions*/
|
237 |
usb_puts("\r\n\r\nTerminating wireless...\r\n");
|
238 |
status = wl_init(); |
239 |
switch(status){
|
240 |
case 0: |
241 |
usb_puts("Wireless termination successful\r\n\r\n");
|
242 |
orb1_set_color(BLUE); |
243 |
break;
|
244 |
case -3: |
245 |
usb_puts("Termination failed: library not initialized\r\n\r\n");
|
246 |
orb1_set_color(BLUE); |
247 |
break;
|
248 |
case -5: |
249 |
usb_puts("Termination failed\r\n\r\n");
|
250 |
orb1_set_color(RED); |
251 |
break;
|
252 |
case -6: |
253 |
usb_puts("Termination failed: function unregistration failed\r\n\r\n");
|
254 |
orb1_set_color(ORANGE); |
255 |
break;
|
256 |
default:
|
257 |
usb_puts("Error: Unreconnized status code: ");
|
258 |
usb_puti(status); |
259 |
orb1_set_color(RED); |
260 |
break;
|
261 |
} |
262 |
|
263 |
usb_puts("\r\n\r\nWireless Library tests completed");
|
264 |
while(1){} |
265 |
} |
266 |
|
267 |
uint8_t group_1_function(uint8_t* data,uint8_t length,uint8_t source){ |
268 |
usb_puts("\r\nFunction 1 called");
|
269 |
return 0; |
270 |
} |
271 |
uint8_t group_2_function(uint8_t* data,uint8_t length,uint8_t source){ |
272 |
usb_puts("\r\nFunction 2 called");
|
273 |
return 0; |
274 |
} |
275 |
uint8_t group_3_function(uint8_t* data,uint8_t length,uint8_t source){ |
276 |
usb_puts("\r\nFunction 3 called");
|
277 |
return 0; |
278 |
} |
279 |
uint8_t group_4_function(uint8_t* data,uint8_t length,uint8_t source){ |
280 |
usb_puts("\r\nFunction 4 called");
|
281 |
return 0; |
282 |
} |
283 |
//The first robot to receive the address of another robot will trigger this function.
|
284 |
uint8_t test_function_1(void){
|
285 |
uint16_t myAddress = xbee_get_address(); |
286 |
usb_puti(myAddress); |
287 |
|
288 |
return 0; |
289 |
} |
290 |
|
291 |
//Cheat Functions
|
292 |
//These will run instead of the real functions while David fixes the library
|
293 |
|