Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / projects / unit_tests / test_xbee.c @ 1624

History | View | Annotate | Download (2.58 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
 
15
int testxbee(void) {
16

    
17
  unsigned char buf[100];
18
  int i=0;
19
        
20
        usb_init();
21
        usb_puts("usb turned on, test starting:\r\n");
22
  
23
  int ret = xbee_init();
24
  
25
  if (ret != WL_SUCCESS) {
26
    usb_puts("xbee_init() failed\r\n");
27
    usb_puti(ret);
28
    usb_puts("|\r\n");
29
    return -1;
30
  } else {
31
    usb_puts("xbee_init successful\r\n");
32
  }
33
 
34
        usb_puts("\r\n\n");
35
        delay_ms(1000);
36
  
37
  // check registers
38
  WL_DEBUG_PRINT("receive interrupt flag(80)=");
39
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXCIE1));
40
  WL_DEBUG_PRINT("|\r\nreceive flag(10)=");
41
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXEN1));
42
  WL_DEBUG_PRINT("|\r\ntransmit flag(08)=");
43
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<TXEN1));
44
  WL_DEBUG_PRINT("|\r\ncharacter size(06)=");
45
  WL_DEBUG_PRINT_HEX(UCSR1C&((1<<UCSZ10)|(1<<UCSZ11)));
46
  WL_DEBUG_PRINT("|\r\ncharacter size2(00)=");
47
  WL_DEBUG_PRINT_HEX((UCSR1B&(1<<UCSZ12))|(0<<UCSZ12));
48
  WL_DEBUG_PRINT("|\r\n");
49
    
50
        
51
        // try getting xbee address
52
  /*xbee_send_read_at_command("MY");
53
  while(i++ < 10000) {
54
    if(xbee_get_packet(buf) == 3) {
55
      usb_puts("got response from xbee\r\n");
56
      //usb_puts("packet:");
57
      //usb_puts(buf);
58
      //usb_puts("|end\r\n");
59
      break; // got a response
60
    }
61
  }*/
62
  
63
  // try setting channel
64
  /*xbee_set_channel(0x0F);
65
  while(i++ < 10000) {
66
    if(xbee_get_packet(buf) == 3) {
67
      usb_puts("got response from xbee\r\n");
68
      break; // got a response
69
    }
70
  }
71
  
72
  xbee_send_read_at_command("CH");
73
  while(i++ < 10000) {
74
    if(xbee_get_packet(buf) == 3) {
75
      usb_puts("got response from xbee\r\n");
76
      break; // got a response
77
    }
78
  }
79
  
80
  usb_puts("\r\nxbee set channel works\r\n\r\n");
81
  
82
  wl_set_channel(0x16);
83
  while(i++ < 10000) {
84
    if(xbee_get_packet(buf) == 3) {
85
      usb_puts("got response from xbee\r\n");
86
      break; // got a response
87
    }
88
  }
89
  
90
  xbee_send_read_at_command("CH");
91
  while(i++ < 10000) {
92
    if(xbee_get_packet(buf) == 3) {
93
      usb_puts("got response from xbee\r\n");
94
      break; // got a response
95
    }
96
  }  
97
  
98
  usb_puts("\r\nwireless set channel works\r\n");*/
99
  
100
  // scan all xbees in network
101
  /*xbee_send_read_at_command("ND");
102
  i=0;
103
  while(i < 1000) {
104
    if(xbee_get_packet(buf) == 3) {
105
      usb_puts("got response from xbee\r\n");
106
      i++;
107
    }
108
  }*/
109
  
110
  // end of tests
111
  if (xbee_terminate() != 0) {
112
    usb_puts("xbee_terminate error\r\n");
113
  } else {
114
    usb_puts("xbee_terminate success\r\n");
115
  }
116
  usb_puts("testxbee done\r\n\r\n");
117
    
118
        return 0;
119
}