root / branches / wireless / code / projects / unit_tests / test_xbee.c @ 1617
History | View | Annotate | Download (2 KB)
1 | 1432 | dsschult | #include <dragonfly_lib.h> |
---|---|---|---|
2 | #include <xbee.h> |
||
3 | |||
4 | #define ROBOT
|
||
5 | #define WL_DEBUG
|
||
6 | |||
7 | /*
|
||
8 | * This function tests the xbee, returning the results to teraterm
|
||
9 | *
|
||
10 | *
|
||
11 | */
|
||
12 | |||
13 | int testxbee(void) { |
||
14 | |||
15 | unsigned char buf[100]; |
||
16 | int i=0; |
||
17 | |||
18 | usb_init(); |
||
19 | usb_puts("usb turned on, test starting:\r\n");
|
||
20 | |||
21 | 1617 | dsschult | if (xbee_init() != 0) { |
22 | usb_puts("xbee_init() failed\r\n");
|
||
23 | 1437 | dsschult | return -1; |
24 | } else {
|
||
25 | 1617 | dsschult | usb_puts("xbee_init successful\r\n");
|
26 | 1432 | dsschult | } |
27 | 1437 | dsschult | |
28 | 1432 | dsschult | usb_puts("\r\n\n");
|
29 | delay_ms(1000);
|
||
30 | 1492 | dsschult | |
31 | // check registers
|
||
32 | |||
33 | 1432 | dsschult | |
34 | // try getting xbee address
|
||
35 | 1617 | dsschult | /*xbee_send_read_at_command("MY");
|
36 | 1432 | dsschult | while(i++ < 10000) {
|
37 | if(xbee_get_packet(buf) == 3) {
|
||
38 | usb_puts("got response from xbee\r\n");
|
||
39 | //usb_puts("packet:");
|
||
40 | //usb_puts(buf);
|
||
41 | //usb_puts("|end\r\n");
|
||
42 | break; // got a response
|
||
43 | }
|
||
44 | 1617 | dsschult | }*/
|
45 | 1437 | dsschult | |
46 | 1492 | dsschult | // try setting channel
|
47 | /*xbee_set_channel(0x0F);
|
||
48 | while(i++ < 10000) {
|
||
49 | if(xbee_get_packet(buf) == 3) {
|
||
50 | usb_puts("got response from xbee\r\n");
|
||
51 | break; // got a response
|
||
52 | }
|
||
53 | }
|
||
54 | |||
55 | xbee_send_read_at_command("CH");
|
||
56 | while(i++ < 10000) {
|
||
57 | if(xbee_get_packet(buf) == 3) {
|
||
58 | usb_puts("got response from xbee\r\n");
|
||
59 | break; // got a response
|
||
60 | }
|
||
61 | }
|
||
62 | |||
63 | usb_puts("\r\nxbee set channel works\r\n\r\n");
|
||
64 | |||
65 | wl_set_channel(0x16);
|
||
66 | while(i++ < 10000) {
|
||
67 | if(xbee_get_packet(buf) == 3) {
|
||
68 | usb_puts("got response from xbee\r\n");
|
||
69 | break; // got a response
|
||
70 | }
|
||
71 | }
|
||
72 | |||
73 | xbee_send_read_at_command("CH");
|
||
74 | while(i++ < 10000) {
|
||
75 | if(xbee_get_packet(buf) == 3) {
|
||
76 | usb_puts("got response from xbee\r\n");
|
||
77 | break; // got a response
|
||
78 | }
|
||
79 | }
|
||
80 | |||
81 | usb_puts("\r\nwireless set channel works\r\n");*/
|
||
82 | |||
83 | // scan all xbees in network
|
||
84 | 1617 | dsschult | /*xbee_send_read_at_command("ND");
|
85 | 1492 | dsschult | i=0;
|
86 | while(i < 1000) {
|
||
87 | if(xbee_get_packet(buf) == 3) {
|
||
88 | usb_puts("got response from xbee\r\n");
|
||
89 | i++;
|
||
90 | }
|
||
91 | 1617 | dsschult | }*/
|
92 | 1492 | dsschult | |
93 | // end of tests
|
||
94 | 1617 | dsschult | if (xbee_terminate() != 0) { |
95 | usb_puts("xbee_terminate error\r\n");
|
||
96 | } else {
|
||
97 | usb_puts("xbee_terminate success\r\n");
|
||
98 | } |
||
99 | 1432 | dsschult | usb_puts("testxbee done\r\n\r\n");
|
100 | 1437 | dsschult | |
101 | 1432 | dsschult | return 0; |
102 | 1617 | dsschult | } |