Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / projects / unit_tests / test_wireless2.c @ 1935

History | View | Annotate | Download (14.1 KB)

1 1658 dsschult
#include <wl_defs.h>
2 1646 dsschult
#include <string.h>
3
#include <wireless.h>
4
#include <lights.h>
5
#include <dragonfly_lib.h>
6
#include <xbee.h>
7
8 1658 dsschult
9 1649 alevkoy
void group_1_function(uint8_t* data,uint8_t length,uint8_t source);
10
void group_2_function(uint8_t* data,uint8_t length,uint8_t source);
11
void group_3_function(uint8_t* data,uint8_t length,uint8_t source);
12
void group_4_function(uint8_t* data,uint8_t length,uint8_t source);
13
void test_function_1(void);
14 1653 bwasserm
void test_sending();
15
void test_receiving();
16 1646 dsschult
17
uint16_t friendAddress = 0;
18
19
/* This function tests out the full functionality of the new wireless library.
20
 * It must be run on two colony bots simultaneously to properly test all funtions.
21
*/
22 1648 dsschult
void testwireless2(void)
23 1646 dsschult
{
24
        orb_init();
25
        usb_init();
26 1655 bwasserm
        int status = 0;
27 1646 dsschult
28 1658 dsschult
        WL_DEBUG_PRINT_P("New Wireless Library Test Suite\r\n");
29 1646 dsschult
30
        /*Initialize the wirelss library*/
31 1658 dsschult
        WL_DEBUG_PRINT_P("Initializing library...\r\n");
32 1646 dsschult
        orb1_set_color(BLUE);
33
        status = wl_init();
34
        switch(status){
35
                case 0:
36 1658 dsschult
                        WL_DEBUG_PRINT_P("Library initialization successful\r\n\r\n");
37 1646 dsschult
                        orb1_set_color(GREEN);
38
                        break;
39
                case -1:
40 1658 dsschult
                        WL_DEBUG_PRINT_P("Initialization failed: already initialized\r\n\r\n");
41 1646 dsschult
                        orb1_set_color(GREEN);
42
                        break;
43
                case -2:
44 1658 dsschult
                        WL_DEBUG_PRINT_P("Initialization failed: XBEE initialization failed\r\n\r\n");
45 1646 dsschult
                        orb1_set_color(RED);
46
                        break;
47
                default:
48 1658 dsschult
                        WL_DEBUG_PRINT_P("Error: Unreconnized status code: ");
49 1646 dsschult
                        usb_puti(status);
50 1658 dsschult
                        WL_DEBUG_PRINT_P("\r\n\r\n");
51 1646 dsschult
                        orb1_set_color(RED);
52
                        break;
53
        }
54
        while((status!=0) && 1);
55
56
        /*Test all constants defined correctly*/
57
        status = 0;
58 1658 dsschult
        WL_DEBUG_PRINT_P("Testing constants...");
59 1646 dsschult
        orb2_set_color(GREEN);
60
        if(GLOBAL!=0){
61 1658 dsschult
                WL_DEBUG_PRINT_P("\r\nGLOBAL defined as ");
62 1646 dsschult
                usb_puti(GLOBAL);
63
                status++;
64
        }
65 1658 dsschult
        WL_DEBUG_PRINT_P(".");
66 1646 dsschult
        if(PAN!=1){
67 1658 dsschult
                WL_DEBUG_PRINT_P("\r\nPAN defined as ");
68 1646 dsschult
                usb_puti(PAN);
69
                status++;
70
        }
71 1658 dsschult
        WL_DEBUG_PRINT_P(".");
72 1646 dsschult
        if(BROADCAST!=0xFFFF){
73 1658 dsschult
                WL_DEBUG_PRINT_P("\r\nBROADCAST defined as ");
74 1646 dsschult
                usb_puti(BROADCAST);
75
                status++;
76
        }
77 1658 dsschult
        WL_DEBUG_PRINT_P(".");
78 1646 dsschult
        if(RELIABLE!=0){
79 1658 dsschult
                WL_DEBUG_PRINT_P("\r\nRELIABLE defined as ");
80 1646 dsschult
                usb_puti(RELIABLE);
81
                status++;
82
        }
83 1658 dsschult
        WL_DEBUG_PRINT_P(".");
84 1646 dsschult
        if(FAST!=1){
85 1658 dsschult
                WL_DEBUG_PRINT_P("\r\nFAST defined as ");
86 1646 dsschult
                usb_puti(FAST);
87
                status++;
88
        }
89 1658 dsschult
        WL_DEBUG_PRINT_P(".");
90 1646 dsschult
        if(NORMAL_PRIORITY!=0){
91 1658 dsschult
                WL_DEBUG_PRINT_P("\r\nNORMAL_PRIORITY defined as ");
92 1646 dsschult
                usb_puti(NORMAL_PRIORITY);
93
                status++;
94
        }
95 1658 dsschult
        WL_DEBUG_PRINT_P(".");
96 1646 dsschult
        if(HIGH_PRIORITY!=1){
97 1658 dsschult
                WL_DEBUG_PRINT_P("\r\nHIGH_PRIORITY defined as ");
98 1646 dsschult
                usb_puti(HIGH_PRIORITY);
99
                status++;
100
        }
101 1658 dsschult
        WL_DEBUG_PRINT_P(".\r\nConstant test complete. There were ");
102 1646 dsschult
        usb_puti(status);
103 1658 dsschult
        WL_DEBUG_PRINT_P(" errors\r\n");
104 1646 dsschult
        if(status!=0){
105
                orb2_set_color(ORANGE);
106
                delay_ms(500);
107
        }
108
        /*Tests function registration*/
109 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nTesting function registration");
110 1655 bwasserm
        int registers[8], count;
111 1646 dsschult
        status = 0;
112
        orb2_set_color(GREEN);
113 1647 alevkoy
        registers[0] = wl_register_handler(1, group_1_function, 0);
114
        registers[1] = wl_register_handler(2, group_2_function, 1);
115
        registers[2] = wl_register_handler(3, group_3_function, 0);
116
        registers[3] = wl_register_handler(4, group_4_function, 1);
117
        registers[4] = wl_register_handler(0, group_1_function, 0);
118 1646 dsschult
        registers[5] = wl_register_handler(6, NULL, 0);
119 1647 alevkoy
        registers[6] = wl_register_handler(30, group_3_function, 0);
120
        registers[7] = wl_register_handler(-1, group_4_function, 0);
121 1646 dsschult
        for(count=0; count<=3; count++){
122
                if(registers[count] != 0){
123 1658 dsschult
                        WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
124 1646 dsschult
                        usb_puti(count);
125 1658 dsschult
                        WL_DEBUG_PRINT_P(" returned ");
126 1646 dsschult
                        usb_puti(registers[count]);
127 1658 dsschult
                        WL_DEBUG_PRINT_P(" instead of success\r\n");
128 1646 dsschult
                        orb2_set_color(ORANGE);
129
                        status++;
130
                }
131
        }
132
        for(count=4; count<=6; count++){
133
                if(registers[count] == 0){
134 1658 dsschult
                        WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
135 1646 dsschult
                        usb_puti(count);
136 1658 dsschult
                        WL_DEBUG_PRINT_P(" succeeded instead of failing\r\n");
137 1646 dsschult
                        orb2_set_color(ORANGE);
138
                        status++;
139
                }
140
                if(registers[count] != 0 && registers[count] != -5){
141 1658 dsschult
                        WL_DEBUG_PRINT_P("\r\nFunction registration error: attempt ");
142 1646 dsschult
                        usb_puti(count);
143 1658 dsschult
                        WL_DEBUG_PRINT_P(" returned ");
144 1646 dsschult
                        usb_puti(registers[count]);
145 1658 dsschult
                        WL_DEBUG_PRINT_P(" instead of -5\r\n");
146 1646 dsschult
                        orb2_set_color(ORANGE);
147
                        status++;
148
                }
149
        }
150
        if(registers[7] == 0){
151 1658 dsschult
                WL_DEBUG_PRINT_P("\r\nCongrats, you let an array write to index -1\r\n");
152 1646 dsschult
                orb2_set_color(RED);
153
                status++;
154
        }
155 1658 dsschult
        WL_DEBUG_PRINT_P("Registration test completed. There were ");
156 1646 dsschult
        usb_puti(status);
157 1658 dsschult
        WL_DEBUG_PRINT_P(" errors\r\n");
158 1646 dsschult
        delay_ms(500);
159
160
        /*Tests XBee functions*/
161 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nTesting XBee fuctions...\r\n");
162 1646 dsschult
        status = 0;
163
        orb2_set_color(GREEN);
164 1752 dsschult
  uint16_t pan = xbee_get_pan();
165
  if(pan != 0){
166
    WL_DEBUG_PRINT_P("Pan error: defaulted to non-default Pan id (0):");
167
    usb_puti(pan);
168
    orb2_set_color(ORANGE);
169
    status++;
170
  }
171
  status = xbee_set_pan(0x2B7D);
172
  if(status != 0){
173
    WL_DEBUG_PRINT_P("\r\nPan error: error setting Pan id: ");
174
    usb_puth16(pan);
175
    orb2_set_color(ORANGE);
176
    status++;
177
  }
178
  pan = xbee_get_pan();
179
  if(pan != 0x2B7D){
180
    WL_DEBUG_PRINT_P("\r\nPan error: Pan id reads different than set value 0x2B7D: ");
181
    usb_puth16(pan);
182
    orb2_set_color(ORANGE);
183
    status++;
184
  }
185
  status = xbee_set_pan(0);
186
  if(status != 0){
187
    WL_DEBUG_PRINT_P("\r\nPan error: error setting Pan id: ");
188
    usb_puti(pan);
189
    orb2_set_color(ORANGE);
190
    status++;
191
  }
192
  pan = xbee_get_pan();
193
  if(pan != 0){
194
    WL_DEBUG_PRINT_P("\r\nPan error: Pan id reads different than set value 0: ");
195
    usb_puti(pan);
196
    orb2_set_color(ORANGE);
197
    status++;
198
  }
199
  int chanCount;
200
  for(chanCount = 0x0B; chanCount <= 0x1A; chanCount++){
201
    xbee_set_channel(0x10);
202
    WL_DEBUG_PRINT_P("\r\nChannel: ");
203
    WL_DEBUG_PRINT_HEX(xbee_get_channel());
204
  }
205
  uint16_t data = xbee_get_address();
206
  uint8_t sendBuffer[2];
207
  uint16_t address = 0;
208
  sendBuffer[0] = (data& 0xFF00) >> 8;
209
  sendBuffer[1] = (data& 0x00FF);
210 1754 bwasserm
211 1752 dsschult
212
        WL_DEBUG_PRINT_P("\r\n\r\nXBee tests completed. There were ");
213 1646 dsschult
        usb_puti(status);
214 1658 dsschult
        WL_DEBUG_PRINT_P(" errors.\r\n");
215 1646 dsschult
216
        /*Tests sending in fast mode*/
217 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nTests sending basic packets in fast mode...\r\n");
218 1646 dsschult
        status = 0;
219 1755 dsschult
        status = wl_send(sendBuffer, 2, 0, GLOBAL, BROADCAST, FAST);
220 1658 dsschult
        WL_DEBUG_PRINT_P("Global fast broadcast basic send exit code ");
221 1646 dsschult
        usb_puti(status);
222 1752 dsschult
  char bigbuf[10];
223
  int8_t ret = wl_get(bigbuf,10);
224
  if (ret < 0) {
225
    WL_DEBUG_PRINT_P("error in wl_get:");
226
    WL_DEBUG_PRINT_INT(ret);
227
    WL_DEBUG_PRINT_P("\r\n");
228
  } else {
229
    WL_DEBUG_PRINT_P("get returned:");
230 1755 dsschult
    usb_puth16(bigbuf);
231 1752 dsschult
  }
232 1755 dsschult
        status = wl_send(sendBuffer, 2, 0, GLOBAL, PAN, FAST);
233 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nGlobal fast pan send basic exit code ");
234 1646 dsschult
        usb_puti(status);
235 1752 dsschult
  ret = wl_get(bigbuf,10);
236
  if (ret < 0) {
237
    WL_DEBUG_PRINT_P("error in wl_get:");
238
    WL_DEBUG_PRINT_INT(ret);
239
    WL_DEBUG_PRINT_P("\r\n");
240
  } else {
241
    WL_DEBUG_PRINT_P("get returned:");
242 1755 dsschult
    usb_puth16(bigbuf);
243 1752 dsschult
  }
244 1755 dsschult
        status = wl_send(sendBuffer, 2, 0, GLOBAL, BROADCAST, FAST);
245 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast basic send exit code ");
246 1646 dsschult
        usb_puti(status);
247 1752 dsschult
  ret = wl_get(bigbuf,10);
248
  if (ret < 0) {
249
    WL_DEBUG_PRINT_P("error in wl_get:");
250
    WL_DEBUG_PRINT_INT(ret);
251
    WL_DEBUG_PRINT_P("\r\n");
252
  } else {
253
    WL_DEBUG_PRINT_P("get returned:");
254 1755 dsschult
    usb_puth16(bigbuf);
255 1752 dsschult
  }
256 1755 dsschult
        status = wl_send(sendBuffer, 2, 0, GLOBAL, PAN, FAST);
257 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nGlobal fast pan send basic exit code ");
258 1646 dsschult
        usb_puti(status);
259 1752 dsschult
  ret = wl_get(bigbuf,10);
260
  if (ret < 0) {
261
    WL_DEBUG_PRINT_P("error in wl_get:");
262
    WL_DEBUG_PRINT_INT(ret);
263
    WL_DEBUG_PRINT_P("\r\n");
264
  } else {
265
    WL_DEBUG_PRINT_P("get returned:");
266 1755 dsschult
    usb_puth16(bigbuf);
267 1752 dsschult
  }
268 1755 dsschult
        status = wl_send(sendBuffer, 2, 1, GLOBAL, BROADCAST, FAST);
269 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast group 1 send exit code ");
270 1646 dsschult
        usb_puti(status);
271 1752 dsschult
  ret = wl_get(bigbuf,10);
272
  if (ret < 0) {
273
    WL_DEBUG_PRINT_P("error in wl_get:");
274
    WL_DEBUG_PRINT_INT(ret);
275
    WL_DEBUG_PRINT_P("\r\n");
276
  } else {
277
    WL_DEBUG_PRINT_P("get returned:");
278 1755 dsschult
    usb_puth16(bigbuf);
279 1752 dsschult
  }
280 1755 dsschult
        status = wl_send(sendBuffer, 2, 2, GLOBAL, PAN, FAST);
281 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nGlobal fast pan send group 2 exit code ");
282 1646 dsschult
        usb_puti(status);
283 1752 dsschult
  ret = wl_get(bigbuf,10);
284
  if (ret < 0) {
285
    WL_DEBUG_PRINT_P("error in wl_get:");
286
    WL_DEBUG_PRINT_INT(ret);
287
    WL_DEBUG_PRINT_P("\r\n");
288
  } else {
289
    WL_DEBUG_PRINT_P("get returned:");
290 1755 dsschult
    usb_puth16(bigbuf);
291 1752 dsschult
  }
292 1755 dsschult
        status = wl_send(sendBuffer, 2, 1, GLOBAL, BROADCAST, FAST);
293 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nGlobal fast broadcast group 3 send exit code ");
294 1646 dsschult
        usb_puti(status);
295 1752 dsschult
  ret = wl_get(bigbuf,10);
296
  if (ret < 0) {
297
    WL_DEBUG_PRINT_P("error in wl_get:");
298
    WL_DEBUG_PRINT_INT(ret);
299
    WL_DEBUG_PRINT_P("\r\n");
300
  } else {
301
    WL_DEBUG_PRINT_P("get returned:");
302 1755 dsschult
    usb_puth16(bigbuf);
303 1752 dsschult
  }
304 1755 dsschult
        status = wl_send(sendBuffer, 2, 2, GLOBAL, PAN, FAST);
305 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nGlobal fast pan send group 4 exit code ");
306 1646 dsschult
        usb_puti(status);
307 1752 dsschult
  ret = wl_get(bigbuf,10);
308
  if (ret < 0) {
309
    WL_DEBUG_PRINT_P("error in wl_get:");
310
    WL_DEBUG_PRINT_INT(ret);
311
    WL_DEBUG_PRINT_P("\r\n");
312
  } else {
313
    WL_DEBUG_PRINT_P("get returned:");
314 1755 dsschult
    usb_puth16(bigbuf);
315 1752 dsschult
  }
316 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nFast send tests successful\r\n");
317 1752 dsschult
318 1646 dsschult
        /*Sends packets in fast mode until other robot responds*/
319
        status = 0;
320 1689 dsschult
  int len = 0;
321 1663 bwasserm
        uint8_t buffer[10];
322 1752 dsschult
//        uint8_t sendBuffer[2];
323
        //uint16_t address = 0;
324 1653 bwasserm
        orb2_set_color(BLUE);
325 1689 dsschult
        while(1){
326 1752 dsschult
                WL_DEBUG_PRINT_P("\r\nMy address: ");
327 1675 bwasserm
                usb_puti(data);
328
                usb_puti(xbee_get_address());
329 1683 bwasserm
                sendBuffer[0] = (data& 0xFF00) >> 8;
330
                sendBuffer[1] = (data& 0x00FF);
331 1754 bwasserm
                wl_send((uint8_t*)sendBuffer, 2, 0, GLOBAL, BROADCAST, FAST);
332 1675 bwasserm
                delay_ms(1000);
333 1773 bwasserm
                len = wl_get(buffer, 10);
334 1689 dsschult
                if(len != 0){
335
      address = (buffer[0] << 8) + buffer[1];
336 1653 bwasserm
                        orb2_set_color(GREEN);
337 1744 bwasserm
                        WL_DEBUG_PRINT_P("\r\nLength: ");
338 1707 bwasserm
                        WL_DEBUG_PRINT_INT(len);
339 1658 dsschult
                        WL_DEBUG_PRINT_P("\r\nFriend address: ");
340 1683 bwasserm
                        usb_puth16(address);
341 1663 bwasserm
                        friendAddress = address;
342 1653 bwasserm
                }
343 1773 bwasserm
                if(button1_read()){
344 1653 bwasserm
                        test_sending();
345
                        break;
346
                }
347 1663 bwasserm
                if(button2_read()){
348 1653 bwasserm
                        test_receiving();
349
                        break;
350 1773 bwasserm
                }
351 1646 dsschult
        }
352
353 1655 bwasserm
354 1646 dsschult
        /*Terminates wireless functions*/
355 1658 dsschult
        WL_DEBUG_PRINT_P("\r\n\r\nTerminating wireless...\r\n");
356 1788 dsschult
        status = wl_terminate();
357 1646 dsschult
        switch(status){
358
                case 0:
359 1658 dsschult
                        WL_DEBUG_PRINT_P("Wireless termination successful\r\n\r\n");
360 1646 dsschult
                        orb1_set_color(BLUE);
361
                        break;
362
                case -3:
363 1658 dsschult
                        WL_DEBUG_PRINT_P("Termination failed: library not initialized\r\n\r\n");
364 1646 dsschult
                        orb1_set_color(BLUE);
365
                        break;
366
                case -5:
367 1658 dsschult
                        WL_DEBUG_PRINT_P("Termination failed\r\n\r\n");
368 1646 dsschult
                        orb1_set_color(RED);
369
                        break;
370
                case -6:
371 1658 dsschult
                        WL_DEBUG_PRINT_P("Termination failed: function unregistration failed\r\n\r\n");
372 1646 dsschult
                        orb1_set_color(ORANGE);
373
                        break;
374
                default:
375 1658 dsschult
                        WL_DEBUG_PRINT_P("Error: Unreconnized status code: ");
376 1646 dsschult
                        usb_puti(status);
377
                        orb1_set_color(RED);
378
                        break;
379
        }
380
381 1658 dsschult
        WL_DEBUG_PRINT_P("\r\n\r\nWireless Library tests completed");
382 1646 dsschult
        while(1){}
383
}
384
385 1655 bwasserm
void test_sending(){
386 1653 bwasserm
        uint8_t count;
387
        //Testing all wrappers for FAST mode
388 1752 dsschult
        for(count = 0; count < 5; count++){
389 1792 bwasserm
                WL_DEBUG_PRINT_P("\r\nSend number:");
390
                WL_DEBUG_PRINT_INT(count);
391 1653 bwasserm
                usb_puti(wl_send_basic(&count, 1));
392 1773 bwasserm
                delay_ms(300);
393 1653 bwasserm
        }
394
        for(count = 5; count < 10; count++){
395 1792 bwasserm
                WL_DEBUG_PRINT_P("\r\nSend number:");
396
                WL_DEBUG_PRINT_INT(count);
397 1653 bwasserm
                usb_puti(wl_send_global(&count, 1, 0));
398 1773 bwasserm
                delay_ms(300);
399 1653 bwasserm
        }
400
        for(count = 10; count < 15; count++){
401 1792 bwasserm
                WL_DEBUG_PRINT_P("\r\nSend number:");
402
                WL_DEBUG_PRINT_INT(count);
403 1653 bwasserm
                usb_puti(wl_send_pan(&count, 1, xbee_get_pan()));
404 1773 bwasserm
                delay_ms(300);
405 1653 bwasserm
        }
406 1773 bwasserm
        for(count = 15; count < 20; count++){
407 1792 bwasserm
                WL_DEBUG_PRINT_P("\r\nSend number:");
408
                WL_DEBUG_PRINT_INT(count);
409 1653 bwasserm
                usb_puti(wl_send_robot(&count, 1, 0, friendAddress, FAST));
410 1773 bwasserm
                delay_ms(300);
411 1653 bwasserm
        }
412 1773 bwasserm
        for(count = 20; count < 25; count++){
413 1792 bwasserm
                WL_DEBUG_PRINT_P("\r\nSend number:");
414
                WL_DEBUG_PRINT_INT(count);
415 1653 bwasserm
                usb_puti(wl_send_global(&count, 1, 1));
416 1773 bwasserm
                delay_ms(300);
417 1653 bwasserm
        }
418
        for(count = 25; count < 30; count++){
419 1792 bwasserm
                WL_DEBUG_PRINT_P("\r\nSend number:");
420
                WL_DEBUG_PRINT_INT(count);
421 1653 bwasserm
                usb_puti(wl_send_global(&count, 1, 2));
422 1773 bwasserm
                delay_ms(300);
423 1653 bwasserm
        }
424
        for(count = 30; count < 35; count++){
425 1792 bwasserm
                WL_DEBUG_PRINT_P("\r\nSend number:");
426
                WL_DEBUG_PRINT_INT(count);
427 1653 bwasserm
                usb_puti(wl_send_global(&count, 1, 3));
428 1773 bwasserm
                delay_ms(300);
429 1653 bwasserm
        }
430
        for(count = 35; count < 40; count++){
431 1792 bwasserm
                WL_DEBUG_PRINT_P("\r\nSend number:");
432
                WL_DEBUG_PRINT_INT(count);
433 1653 bwasserm
                usb_puti(wl_send_global(&count, 1, 4));
434 1773 bwasserm
                delay_ms(300);
435 1653 bwasserm
        }
436
        //FAST mode tests completed. Now testing ACK system
437 1744 bwasserm
/*        for(count = 40; count < 45; count++){
438 1653 bwasserm
                usb_puti(count);
439
                usb_puti(wl_send_robot(&count, 1, 0, friendAddress, RELIABLE));
440 1744 bwasserm
                delay_ms(1000);
441 1653 bwasserm
        }
442
        for(count = 45; count < 50; count++){
443
                usb_puti(count);
444
                usb_puti(wl_send_robot(&count, 1, 1, friendAddress, RELIABLE));
445 1744 bwasserm
                delay_ms(1000);
446 1653 bwasserm
        }
447
        for(count = 50; count < 55; count++){
448
                usb_puti(count);
449
                usb_puti(wl_send_robot(&count, 1, 2, friendAddress, RELIABLE));
450 1744 bwasserm
                delay_ms(1000);
451 1653 bwasserm
        }
452
        for(count = 55; count < 60; count++){
453
                usb_puti(count);
454
                usb_puti(wl_send_robot(&count, 1, 3, friendAddress, RELIABLE));
455 1744 bwasserm
                delay_ms(1000);
456 1653 bwasserm
        }
457
        for(count = 60; count < 65; count++){
458
                usb_puti(count);
459
                usb_puti(wl_send_robot(&count, 1, 4, friendAddress, RELIABLE));
460 1744 bwasserm
                delay_ms(1000);
461 1653 bwasserm
        }
462 1658 dsschult
        WL_DEBUG_PRINT_P("ACK Errors: ");
463 1653 bwasserm
        usb_puti(wl_ack_error());
464
        wl_ack_reset();
465
        usb_puti(wl_ack_error());
466 1663 bwasserm
        for(count = 65; count < 70; count++){//changed friendAddress, all should fail
467 1653 bwasserm
                usb_puti(count);
468
                usb_puti(wl_send_robot(&count, 1, 0, friendAddress + 1, RELIABLE));
469
                delay_ms(count * 10);
470
        }
471 1658 dsschult
        WL_DEBUG_PRINT_P("ACK Errors: ");
472 1653 bwasserm
        usb_puti(wl_ack_error());
473 1744 bwasserm
*/}
474 1653 bwasserm
475
void test_receiving(){
476 1773 bwasserm
        int8_t result, length = 8;
477 1653 bwasserm
        char* data[8];
478
        while(1){
479 1792 bwasserm
                result = wl_get(data, length);
480 1653 bwasserm
                if(result){
481 1744 bwasserm
                        WL_DEBUG_PRINT_P("\r\nData length: ");
482
                        WL_DEBUG_PRINT_INT(result);
483
                        WL_DEBUG_PRINT_P("\r\nData: ");
484
                        WL_DEBUG_PRINT_HEX(*data);
485
                }else{
486
                        delay_ms(100);
487 1653 bwasserm
                }
488
        }
489
}
490
491 1649 alevkoy
void group_1_function(uint8_t* data,uint8_t length,uint8_t source){
492 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nFunction 1 called");
493 1646 dsschult
        return 0;
494
}
495 1649 alevkoy
void group_2_function(uint8_t* data,uint8_t length,uint8_t source){
496 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nFunction 2 called");
497 1646 dsschult
        return 0;
498
}
499 1649 alevkoy
void group_3_function(uint8_t* data,uint8_t length,uint8_t source){
500 1773 bwasserm
        WL_DEBUG_PRINT_P("\r\nFunction 3 called. Length: ");
501
        WL_DEBUG_PRINT_INT(length);
502
        WL_DEBUG_PRINT_P(" Soucre: ");
503
        WL_DEBUG_PRINT_HEX(source);
504 1646 dsschult
        return 0;
505
}
506 1649 alevkoy
void group_4_function(uint8_t* data,uint8_t length,uint8_t source){
507 1658 dsschult
        WL_DEBUG_PRINT_P("\r\nFunction 4 called");
508 1646 dsschult
        return 0;
509
}
510
//The first robot to receive the address of another robot will trigger this function.
511 1656 bwasserm
void test_function_1(void){
512 1646 dsschult
        uint16_t myAddress = xbee_get_address();
513
        usb_puti(myAddress);
514 1655 bwasserm
515
        return 0;
516 1646 dsschult
}