root / trunk / code / projects / unit_tests / test_xbee.c @ 1890
History | View | Annotate | Download (2.66 KB)
1 | 1432 | dsschult | #include <dragonfly_lib.h> |
---|---|---|---|
2 | 1623 | dsschult | #include <wl_defs.h> |
3 | #include "xbee.h" |
||
4 | 1432 | dsschult | |
5 | #define ROBOT
|
||
6 | #define WL_DEBUG
|
||
7 | 1623 | dsschult | #define WL_DEBUG_PRINT_HEX(s) usb_puth8(s)
|
8 | 1432 | dsschult | |
9 | /*
|
||
10 | * This function tests the xbee, returning the results to teraterm
|
||
11 | *
|
||
12 | *
|
||
13 | */
|
||
14 | |||
15 | 1623 | dsschult | |
16 | 1432 | dsschult | int testxbee(void) { |
17 | |||
18 | unsigned char buf[100]; |
||
19 | int i=0; |
||
20 | |||
21 | usb_init(); |
||
22 | usb_puts("usb turned on, test starting:\r\n");
|
||
23 | 1623 | dsschult | xbee_init(); |
24 | 1432 | dsschult | |
25 | 1623 | dsschult | int ret = xbee_lib_init();
|
26 | |||
27 | if (ret != 0) { |
||
28 | usb_puts("xbee_init() failed\r\n");
|
||
29 | usb_puti(ret); |
||
30 | usb_puts("|\r\n");
|
||
31 | 1437 | dsschult | return -1; |
32 | } else {
|
||
33 | 1623 | dsschult | usb_puts("xbee_init successful\r\n");
|
34 | 1432 | dsschult | } |
35 | 1437 | dsschult | |
36 | 1432 | dsschult | usb_puts("\r\n\n");
|
37 | delay_ms(1000);
|
||
38 | 1623 | dsschult | |
39 | // check registers
|
||
40 | WL_DEBUG_PRINT("receive interrupt flag(80)=");
|
||
41 | WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXCIE1));
|
||
42 | WL_DEBUG_PRINT("|\r\nreceive flag(10)=");
|
||
43 | WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXEN1));
|
||
44 | WL_DEBUG_PRINT("|\r\ntransmit flag(08)=");
|
||
45 | WL_DEBUG_PRINT_HEX(UCSR1B&(1<<TXEN1));
|
||
46 | WL_DEBUG_PRINT("|\r\ncharacter size(06)=");
|
||
47 | WL_DEBUG_PRINT_HEX(UCSR1C&((1<<UCSZ10)|(1<<UCSZ11))); |
||
48 | WL_DEBUG_PRINT("|\r\ncharacter size2(00)=");
|
||
49 | WL_DEBUG_PRINT_HEX((UCSR1B&(1<<UCSZ12))|(0<<UCSZ12)); |
||
50 | WL_DEBUG_PRINT("|\r\n");
|
||
51 | |||
52 | 1432 | dsschult | |
53 | // try getting xbee address
|
||
54 | 1623 | dsschult | /*xbee_send_read_at_command("MY");
|
55 | 1432 | dsschult | while(i++ < 10000) {
|
56 | if(xbee_get_packet(buf) == 3) {
|
||
57 | usb_puts("got response from xbee\r\n");
|
||
58 | //usb_puts("packet:");
|
||
59 | //usb_puts(buf);
|
||
60 | //usb_puts("|end\r\n");
|
||
61 | break; // got a response
|
||
62 | }
|
||
63 | 1623 | dsschult | }*/
|
64 | |||
65 | // try setting channel
|
||
66 | /*xbee_set_channel(0x0F);
|
||
67 | while(i++ < 10000) {
|
||
68 | if(xbee_get_packet(buf) == 3) {
|
||
69 | usb_puts("got response from xbee\r\n");
|
||
70 | break; // got a response
|
||
71 | }
|
||
72 | 1432 | dsschult | }
|
73 | 1437 | dsschult | |
74 | 1623 | dsschult | xbee_send_read_at_command("CH");
|
75 | while(i++ < 10000) {
|
||
76 | if(xbee_get_packet(buf) == 3) {
|
||
77 | usb_puts("got response from xbee\r\n");
|
||
78 | break; // got a response
|
||
79 | }
|
||
80 | }
|
||
81 | |||
82 | usb_puts("\r\nxbee set channel works\r\n\r\n");
|
||
83 | |||
84 | wl_set_channel(0x16);
|
||
85 | while(i++ < 10000) {
|
||
86 | if(xbee_get_packet(buf) == 3) {
|
||
87 | usb_puts("got response from xbee\r\n");
|
||
88 | break; // got a response
|
||
89 | }
|
||
90 | }
|
||
91 | |||
92 | xbee_send_read_at_command("CH");
|
||
93 | while(i++ < 10000) {
|
||
94 | if(xbee_get_packet(buf) == 3) {
|
||
95 | usb_puts("got response from xbee\r\n");
|
||
96 | break; // got a response
|
||
97 | }
|
||
98 | }
|
||
99 | |||
100 | usb_puts("\r\nwireless set channel works\r\n");*/
|
||
101 | |||
102 | // scan all xbees in network
|
||
103 | /*xbee_send_read_at_command("ND");
|
||
104 | i=0;
|
||
105 | while(i < 1000) {
|
||
106 | if(xbee_get_packet(buf) == 3) {
|
||
107 | usb_puts("got response from xbee\r\n");
|
||
108 | i++;
|
||
109 | }
|
||
110 | }*/
|
||
111 | |||
112 | // end of tests
|
||
113 | 1437 | dsschult | xbee_terminate(); |
114 | 1623 | dsschult | /*if (xbee_terminate() != 0) {
|
115 | usb_puts("xbee_terminate error\r\n");
|
||
116 | } else {
|
||
117 | usb_puts("xbee_terminate success\r\n");
|
||
118 | }*/
|
||
119 | 1432 | dsschult | usb_puts("testxbee done\r\n\r\n");
|
120 | 1437 | dsschult | |
121 | 1432 | dsschult | return 0; |
122 | 1623 | dsschult | } |