root / branches / wireless / code / projects / unit_tests / test_xbee.c @ 1935
History | View | Annotate | Download (2.41 KB)
1 |
#include <dragonfly_lib.h> |
---|---|
2 |
#include <wl_defs.h> |
3 |
#include "xbee.h" |
4 |
|
5 |
#define ROBOT
|
6 |
#define WL_DEBUG
|
7 |
|
8 |
/*
|
9 |
* This function tests the xbee, returning the results to teraterm
|
10 |
*
|
11 |
*
|
12 |
*/
|
13 |
|
14 |
int testxbee(void) { |
15 |
|
16 |
unsigned char buf[100]; |
17 |
int i=0; |
18 |
|
19 |
usb_init(); |
20 |
usb_puts("usb turned on, test starting:\r\n");
|
21 |
|
22 |
int ret = xbee_init();
|
23 |
|
24 |
if (ret != WL_SUCCESS) {
|
25 |
usb_puts("xbee_init() failed\r\n");
|
26 |
usb_puti(ret); |
27 |
usb_puts("|\r\n");
|
28 |
return -1; |
29 |
} else {
|
30 |
usb_puts("xbee_init successful\r\n");
|
31 |
} |
32 |
|
33 |
usb_puts("\r\n\n");
|
34 |
|
35 |
// check registers
|
36 |
WL_DEBUG_PRINT("receive interrupt flag(80)=");
|
37 |
WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXCIE1));
|
38 |
WL_DEBUG_PRINT("|\r\nreceive flag(10)=");
|
39 |
WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXEN1));
|
40 |
WL_DEBUG_PRINT("|\r\ntransmit flag(08)=");
|
41 |
WL_DEBUG_PRINT_HEX(UCSR1B&(1<<TXEN1));
|
42 |
WL_DEBUG_PRINT("|\r\ncharacter size(06)=");
|
43 |
WL_DEBUG_PRINT_HEX(UCSR1C&((1<<UCSZ10)|(1<<UCSZ11))); |
44 |
WL_DEBUG_PRINT("|\r\ncharacter size2(00)=");
|
45 |
WL_DEBUG_PRINT_HEX((UCSR1B&(1<<UCSZ12))|(0<<UCSZ12)); |
46 |
WL_DEBUG_PRINT("|\r\n");
|
47 |
|
48 |
// try getting xbee address
|
49 |
uint16_t address = xbee_get_address(); |
50 |
if(address != WL_ERROR_XBEE_COMMAND_16BIT) {
|
51 |
usb_puts("MY address:");
|
52 |
usb_puth8((uint8_t)(address>>8));
|
53 |
usb_puth8((uint8_t)(address&0xFF));
|
54 |
usb_puts("\r\n");
|
55 |
} else {
|
56 |
usb_puts("error getting MY address\r\n");
|
57 |
} |
58 |
|
59 |
// try setting channel
|
60 |
if (xbee_set_channel(0x0F) != WL_SUCCESS) { |
61 |
usb_puts("error setting channel\r\n");
|
62 |
} else {
|
63 |
usb_puts("ok from setting channel\r\n");
|
64 |
} |
65 |
|
66 |
int8_t channel = xbee_get_channel(); |
67 |
if (channel != WL_ERROR_XBEE_COMMAND) {
|
68 |
usb_puts("Channel reported:");
|
69 |
usb_puth8((uint8_t)channel); |
70 |
usb_puts("|should be:");
|
71 |
usb_puth8(0x0F);
|
72 |
usb_puts("\r\n");
|
73 |
} else {
|
74 |
usb_puts("error getting channel\r\n");
|
75 |
} |
76 |
|
77 |
// try setting pan
|
78 |
if (xbee_set_pan(0x1234) != WL_SUCCESS) { |
79 |
usb_puts("error setting pan\r\n");
|
80 |
} else {
|
81 |
usb_puts("ok from setting pan\r\n");
|
82 |
} |
83 |
|
84 |
uint16_t pan = xbee_get_pan(); |
85 |
if (channel != WL_ERROR_XBEE_COMMAND_16BIT) {
|
86 |
usb_puts("pan reported:");
|
87 |
usb_puth16(pan); |
88 |
usb_puts("|should be:");
|
89 |
usb_puth16(0x1234);
|
90 |
usb_puts("\r\n");
|
91 |
} else {
|
92 |
usb_puts("error getting pan\r\n");
|
93 |
} |
94 |
|
95 |
// end of tests
|
96 |
if (xbee_terminate() != 0) { |
97 |
usb_puts("xbee_terminate error\r\n");
|
98 |
} else {
|
99 |
usb_puts("xbee_terminate success\r\n");
|
100 |
} |
101 |
usb_puts("testxbee done\r\n\r\n");
|
102 |
|
103 |
return 0; |
104 |
} |