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