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