Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / unit_tests / test_xbee.c @ 1623

History | View | Annotate | Download (2.66 KB)

1
#include <dragonfly_lib.h>
2
#include <wl_defs.h>
3
#include "xbee.h"
4

    
5
#define ROBOT
6
#define WL_DEBUG
7
#define WL_DEBUG_PRINT_HEX(s) usb_puth8(s)
8

    
9
/*
10
 * This function tests the xbee, returning the results to teraterm
11
 *
12
 * 
13
 */
14
 
15
 
16
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
  xbee_init();
24
  
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");
31
    return -1;
32
  } else {
33
    usb_puts("xbee_init successful\r\n");
34
  }
35
 
36
        usb_puts("\r\n\n");
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
    
52
        
53
        // try getting xbee address
54
  /*xbee_send_read_at_command("MY");
55
  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
  }*/
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
  }
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
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
  }*/
119
  usb_puts("testxbee done\r\n\r\n");
120
    
121
        return 0;
122
}