Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / behaviors / Wireless_test / wireless_test.c @ 1621

History | View | Annotate | Download (7.13 KB)

1 1619 bwasserm
#include <stdlib.h>
2
#include <stdio.h>
3
#include <string.h>
4 1621 bwasserm
#include <wireless.h>
5
#include <lights.h>
6
#include <dragonfly_lib.h>
7
#include <xbee.h>
8 1619 bwasserm
9 1621 bwasserm
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 1619 bwasserm
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 1621 bwasserm
int main(int argsc, char* argv[])
18 1619 bwasserm
{
19
        orb_init();
20
        usb_init();
21
        int status = 0;
22
23 1621 bwasserm
        usb_puts("New Wireless Library Test Suite\r\n");
24 1619 bwasserm
25
        /*Initialize the wirelss library*/
26 1621 bwasserm
        usb_puts("Initializing library...\r\n");
27 1619 bwasserm
        orb1_set_color(BLUE);
28
        status = wl_init();
29
        switch(status){
30
                case 0:
31 1621 bwasserm
                        usb_puts("Library initialization successful\r\n\r\n");
32 1619 bwasserm
                        orb1_set_color(GREEN);
33
                        break;
34
                case -1:
35 1621 bwasserm
                        usb_puts("Initialization failed: already initialized\r\n\r\n");
36 1619 bwasserm
                        orb1_set_color(GREEN);
37
                        break;
38
                case -2:
39 1621 bwasserm
                        usb_puts("Initialization failed: XBEE initialization failed\r\n\r\n");
40 1619 bwasserm
                        orb1_set_color(RED);
41
                        break;
42
                default:
43 1621 bwasserm
                        usb_puts("Error: Unreconnized status code: ");
44
                        usb_puti(status);
45
                        usb_puts("\r\n\r\n");
46 1619 bwasserm
                        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 1621 bwasserm
                usb_puts("\r\nGLOBAL defined as ");
57
                usb_puti(GLOBAL);
58 1619 bwasserm
                status++;
59
        }
60
        usb_puts(".");
61
        if(PAN!=1){
62 1621 bwasserm
                usb_puts("\r\nPAN defined as ");
63
                usb_puti(PAN);
64 1619 bwasserm
                status++;
65
        }
66
        usb_puts(".");
67
        if(BROADCAST!=0xFFFF){
68 1621 bwasserm
                usb_puts("\r\nBROADCAST defined as ");
69
                usb_puti(BROADCAST);
70 1619 bwasserm
                status++;
71
        }
72
        usb_puts(".");
73
        if(RELIABLE!=0){
74 1621 bwasserm
                usb_puts("\r\nRELIABLE defined as ");
75
                usb_puti(RELIABLE);
76 1619 bwasserm
                status++;
77
        }
78
        usb_puts(".");
79
        if(FAST!=1){
80 1621 bwasserm
                usb_puts("\r\nFAST defined as ");
81
                usb_puti(FAST);
82 1619 bwasserm
                status++;
83
        }
84
        usb_puts(".");
85
        if(NORMAL_PRIORITY!=0){
86 1621 bwasserm
                usb_puts("\r\nNORMAL_PRIORITY defined as ");
87
                usb_puti(NORMAL_PRIORITY);
88 1619 bwasserm
                status++;
89
        }
90
        usb_puts(".");
91
        if(HIGH_PRIORITY!=1){
92 1621 bwasserm
                usb_puts("\r\nHIGH_PRIORITY defined as ");
93
                usb_puti(HIGH_PRIORITY);
94 1619 bwasserm
                status++;
95
        }
96 1621 bwasserm
        usb_puts(".\r\nConstant test complete. There were ");
97
        usb_puti(status);
98
        usb_puts(" errors\r\n");
99 1619 bwasserm
        if(status!=0){
100
                orb2_set_color(ORANGE);
101
                delay_ms(500);
102 1621 bwasserm
        }
103 1619 bwasserm
        /*Tests function registration*/
104 1621 bwasserm
        usb_puts("\r\nTesting function registration");
105 1619 bwasserm
        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 1621 bwasserm
                        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 1619 bwasserm
                        orb2_set_color(ORANGE);
124
                        status++;
125
                }
126
        }
127
        for(count=4; count<=6; count++){
128
                if(registers[count] == 0){
129 1621 bwasserm
                        usb_puts("\r\nFunction registration error: attempt ");
130
                        usb_puti(count);
131
                        usb_puts(" succeeded instead of failing\r\n");
132 1619 bwasserm
                        orb2_set_color(ORANGE);
133
                        status++;
134
                }
135
                if(registers[count] != 0 && registers[count] != -5){
136 1621 bwasserm
                        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 1619 bwasserm
                        orb2_set_color(ORANGE);
142
                        status++;
143
                }
144
        }
145
        if(registers[7] == 0){
146 1621 bwasserm
                usb_puts("\r\nCongrats, you let an array write to index -1\r\n");
147 1619 bwasserm
                orb2_set_color(RED);
148
                status++;
149
        }
150 1621 bwasserm
        usb_puts("Registration test completed. There were ");
151
        usb_puti(status);
152
        usb_puts(" errors\r\n");
153 1619 bwasserm
        delay_ms(500);
154
155
        /*Tests XBee functions*/
156 1621 bwasserm
        usb_puts("\r\nTesting XBee fuctions...\r\n");
157 1619 bwasserm
        status = 0;
158
        orb2_set_color(GREEN);
159
        unsigned int pan = xbee_get_pan_id();
160
        if(pan != 0){
161 1621 bwasserm
                usb_puts("Pan error: defaulted to non-default Pan id :");
162
                usb_puti(pan);
163 1619 bwasserm
                orb2_set_color(ORANGE);
164
                status++;
165
        }
166
        pan = xbee_set_pan_id(1);
167
        if(pan != 0){
168 1621 bwasserm
                usb_puts("\r\nPan error: error setting Pan id: ");
169
                usb_puti(pan);
170 1619 bwasserm
                orb2_set_color(ORANGE);
171
                status++;
172
        }
173
        pan = xbee_get_pan_id();
174
        if(pan != 0){
175 1621 bwasserm
                usb_puts("\r\nPan error: Pan id reads different than set value 1: ");
176
                usb_puti(pan);
177 1619 bwasserm
                orb2_set_color(ORANGE);
178
                status++;
179
        }
180
181 1621 bwasserm
        usb_puts("\r\nXBee tests completed. There were ");
182
        usb_puti(status);
183
        usb_puts(" errors.\r\n");
184 1619 bwasserm
185
        /*Tests sending in fast mode*/
186 1621 bwasserm
        usb_puts("\r\nTests sending basic packets in fast mode...\r\n");
187 1619 bwasserm
        status = 0;
188 1621 bwasserm
        uint16_t data = xbee_get_address();
189 1619 bwasserm
        status = wl_send(data, 2, 0, GLOBAL, BROADCAST, FAST);
190 1621 bwasserm
        usb_puts("Global fast broadcast basic send exit code ");
191
        usb_puti(status);
192 1619 bwasserm
        status = wl_send(data, 2, 0, GLOBAL, PAN, FAST);
193 1621 bwasserm
        usb_puts("\r\nGlobal fast pan send basic exit code ");
194
        usb_puti(status);
195 1619 bwasserm
        status = wl_send(data, 2, 0, GLOBAL, BROADCAST, FAST);
196 1621 bwasserm
        usb_puts("\r\nGlobal fast broadcast basic send exit code ");
197
        usb_puti(status);
198 1619 bwasserm
        status = wl_send(data, 2, 0, GLOBAL, PAN, FAST);
199 1621 bwasserm
        usb_puts("\r\nGlobal fast pan send basic exit code ");
200
        usb_puti(status);
201 1619 bwasserm
        status = wl_send(data, 2, 1, GLOBAL, BROADCAST, FAST);
202 1621 bwasserm
        usb_puts("\r\nGlobal fast broadcast group 1 send exit code ");
203
        usb_puti(status);
204 1619 bwasserm
        status = wl_send(data, 2, 2, GLOBAL, PAN, FAST);
205 1621 bwasserm
        usb_puts("\r\nGlobal fast pan send group 2 exit code ");
206
        usb_puti(status);
207 1619 bwasserm
        status = wl_send(data, 2, 1, GLOBAL, BROADCAST, FAST);
208 1621 bwasserm
        usb_puts("\r\nGlobal fast broadcast group 3 send exit code ");
209
        usb_puti(status);
210 1619 bwasserm
        status = wl_send(data, 2, 2, GLOBAL, PAN, FAST);
211 1621 bwasserm
        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 1619 bwasserm
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 1621 bwasserm
//        while(status == 0){
220
//                wl_send(data, 2, 0, GLOBAL, BROADCAST, FAST);
221
        //        status = wl_get_basic(packet, 2);
222 1619 bwasserm
223 1621 bwasserm
//        }
224 1619 bwasserm
225
226
        /*Terminates wireless functions*/
227 1621 bwasserm
        usb_puts("\r\n\r\nTerminating wireless...\r\n");
228 1619 bwasserm
        status = wl_init();
229
        switch(status){
230
                case 0:
231 1621 bwasserm
                        usb_puts("Wireless termination successful\r\n\r\n");
232 1619 bwasserm
                        orb1_set_color(BLUE);
233 1621 bwasserm
                        break;
234 1619 bwasserm
                case -3:
235 1621 bwasserm
                        usb_puts("Termination failed: library not initialized\r\n\r\n");
236 1619 bwasserm
                        orb1_set_color(BLUE);
237
                        break;
238
                case -5:
239 1621 bwasserm
                        usb_puts("Termination failed\r\n\r\n");
240 1619 bwasserm
                        orb1_set_color(RED);
241
                        break;
242
                case -6:
243 1621 bwasserm
                        usb_puts("Termination failed: function unregistration failed\r\n\r\n");
244 1619 bwasserm
                        orb1_set_color(ORANGE);
245
                        break;
246
                default:
247 1621 bwasserm
                        usb_puts("Error: Unreconnized status code: ");
248
                        usb_puti(status);
249 1619 bwasserm
                        orb1_set_color(RED);
250
                        break;
251
        }
252
253 1621 bwasserm
        usb_puts("\r\n\r\nWireless Library tests completed");
254
        while(1){}
255 1619 bwasserm
}
256 1621 bwasserm
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
}