Revision 1623
update to test cases in trunk
test_xbee.c | ||
---|---|---|
1 | 1 |
#include <dragonfly_lib.h> |
2 |
#include <xbee.h> |
|
2 |
#include <wl_defs.h> |
|
3 |
#include "xbee.h" |
|
3 | 4 |
|
4 | 5 |
#define ROBOT |
5 | 6 |
#define WL_DEBUG |
6 |
#define WL_DEBUG_PRINT( s ) usb_puts( S )
|
|
7 |
#define WL_DEBUG_PRINT_HEX(s) usb_puth8(s)
|
|
7 | 8 |
|
8 |
extern int xbee_send_read_at_command(char* command); |
|
9 |
extern int xbee_get_packet(unsigned char* dest); |
|
10 |
extern void xbee_terminate(void); |
|
11 |
|
|
12 | 9 |
/* |
13 | 10 |
* This function tests the xbee, returning the results to teraterm |
14 | 11 |
* |
15 | 12 |
* |
16 | 13 |
*/ |
17 | 14 |
|
15 |
|
|
18 | 16 |
int testxbee(void) { |
19 | 17 |
|
20 | 18 |
unsigned char buf[100]; |
... | ... | |
22 | 20 |
|
23 | 21 |
usb_init(); |
24 | 22 |
usb_puts("usb turned on, test starting:\r\n"); |
23 |
xbee_init(); |
|
25 | 24 |
|
26 |
if (xbee_lib_init() != 0) { |
|
27 |
usb_puts("xbee_lib_init() failed\r\n"); |
|
25 |
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"); |
|
28 | 31 |
return -1; |
29 | 32 |
} else { |
30 |
usb_puts("xbee_lib__init successful\r\n");
|
|
33 |
usb_puts("xbee_init successful\r\n"); |
|
31 | 34 |
} |
32 | 35 |
|
33 | 36 |
usb_puts("\r\n\n"); |
34 | 37 |
delay_ms(1000); |
38 |
|
|
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 |
|
|
35 | 52 |
|
36 | 53 |
// try getting xbee address |
37 |
xbee_send_read_at_command("MY"); |
|
54 |
/*xbee_send_read_at_command("MY");
|
|
38 | 55 |
while(i++ < 10000) { |
39 | 56 |
if(xbee_get_packet(buf) == 3) { |
40 | 57 |
usb_puts("got response from xbee\r\n"); |
... | ... | |
43 | 60 |
//usb_puts("|end\r\n"); |
44 | 61 |
break; // got a response |
45 | 62 |
} |
63 |
}*/ |
|
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 |
} |
|
46 | 72 |
} |
47 | 73 |
|
74 |
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 |
|
48 | 113 |
xbee_terminate(); |
114 |
/*if (xbee_terminate() != 0) { |
|
115 |
usb_puts("xbee_terminate error\r\n"); |
|
116 |
} else { |
|
117 |
usb_puts("xbee_terminate success\r\n"); |
|
118 |
}*/ |
|
49 | 119 |
usb_puts("testxbee done\r\n\r\n"); |
50 | 120 |
|
51 | 121 |
return 0; |
52 |
} |
|
122 |
} |
Also available in: Unified diff