Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / test / test_xbee.c @ 1432

History | View | Annotate | Download (1.04 KB)

1
#include <dragonfly_lib.h>
2
#include <xbee.h>
3

    
4
#define ROBOT
5
#define WL_DEBUG
6
#define WL_DEBUG_PRINT( s ) usb_puts( S )
7

    
8
extern int xbee_send_read_at_command(char* command);
9
extern int xbee_get_packet(unsigned char* dest);
10

    
11
/*
12
 * This function tests the xbee, returning the results to teraterm
13
 *
14
 * 
15
 */
16
 
17
static init = 0;
18

    
19
int testxbee(void) {
20

    
21
  unsigned char buf[100];
22
  int i=0;
23
        
24
        usb_init();
25
        usb_puts("usb turned on, test starting:\r\n");
26
  
27
  if(!init) {
28
    // initialize xbee only once
29
    if (xbee_lib_init() != 0) {
30
      usb_puts("xbee_lib_init() failed\r\n");
31
      return -1;
32
    } else {
33
      usb_puts("xbee_lib__init successful\r\n");
34
      init = 1;
35
    }
36
  }
37
  
38
        usb_puts("\r\n\n");
39
        delay_ms(1000);
40
        
41
        // try getting xbee address
42
  xbee_send_read_at_command("MY");
43
  while(i++ < 10000) {
44
    if(xbee_get_packet(buf) == 3) {
45
      usb_puts("got response from xbee\r\n");
46
      //usb_puts("packet:");
47
      //usb_puts(buf);
48
      //usb_puts("|end\r\n");
49
      break; // got a response
50
    }
51
  }
52
  usb_puts("testxbee done\r\n\r\n");
53
  
54
        return 0;
55
}