Project

General

Profile

Revision 1492

wireless library branch

View differences:

test_xbee.c
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
extern void xbee_terminate(void);
11

  
12
/*
13
 * This function tests the xbee, returning the results to teraterm
14
 *
15
 * 
16
 */
17
 
18
int testxbee(void) {
19

  
20
  unsigned char buf[100];
21
  int i=0;
22
	
23
	usb_init();
24
	usb_puts("usb turned on, test starting:\r\n");
25
  
26
  if (xbee_lib_init() != 0) {
27
    usb_puts("xbee_lib_init() failed\r\n");
28
    return -1;
29
  } else {
30
    usb_puts("xbee_lib__init successful\r\n");
31
  }
32
 
33
	usb_puts("\r\n\n");
34
	delay_ms(1000);
35
  
36
  // check registers
37
  
38
	
39
	// try getting xbee address
40
  xbee_send_read_at_command("MY");
41
  while(i++ < 10000) {
42
    if(xbee_get_packet(buf) == 3) {
43
      usb_puts("got response from xbee\r\n");
44
      //usb_puts("packet:");
45
      //usb_puts(buf);
46
      //usb_puts("|end\r\n");
47
      break; // got a response
48
    }
49
  }
50
  
51
  // try setting channel
52
  /*xbee_set_channel(0x0F);
53
  while(i++ < 10000) {
54
    if(xbee_get_packet(buf) == 3) {
55
      usb_puts("got response from xbee\r\n");
56
      break; // got a response
57
    }
58
  }
59
  
60
  xbee_send_read_at_command("CH");
61
  while(i++ < 10000) {
62
    if(xbee_get_packet(buf) == 3) {
63
      usb_puts("got response from xbee\r\n");
64
      break; // got a response
65
    }
66
  }
67
  
68
  usb_puts("\r\nxbee set channel works\r\n\r\n");
69
  
70
  wl_set_channel(0x16);
71
  while(i++ < 10000) {
72
    if(xbee_get_packet(buf) == 3) {
73
      usb_puts("got response from xbee\r\n");
74
      break; // got a response
75
    }
76
  }
77
  
78
  xbee_send_read_at_command("CH");
79
  while(i++ < 10000) {
80
    if(xbee_get_packet(buf) == 3) {
81
      usb_puts("got response from xbee\r\n");
82
      break; // got a response
83
    }
84
  }  
85
  
86
  usb_puts("\r\nwireless set channel works\r\n");*/
87
  
88
  // scan all xbees in network
89
  xbee_send_read_at_command("ND");
90
  i=0;
91
  while(i < 1000) {
92
    if(xbee_get_packet(buf) == 3) {
93
      usb_puts("got response from xbee\r\n");
94
      i++;
95
    }
96
  }
97
  
98
  // end of tests
99
  xbee_terminate();
100
  usb_puts("testxbee done\r\n\r\n");
101
    
102
	return 0;
103
}

Also available in: Unified diff