Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (2.59 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
        delay_ms(1000);
35
  
36
  // check registers
37
  WL_DEBUG_PRINT("receive interrupt flag(80)=");
38
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXCIE1));
39
  WL_DEBUG_PRINT("|\r\nreceive flag(10)=");
40
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<RXEN1));
41
  WL_DEBUG_PRINT("|\r\ntransmit flag(08)=");
42
  WL_DEBUG_PRINT_HEX(UCSR1B&(1<<TXEN1));
43
  WL_DEBUG_PRINT("|\r\ncharacter size(06)=");
44
  WL_DEBUG_PRINT_HEX(UCSR1C&((1<<UCSZ10)|(1<<UCSZ11)));
45
  WL_DEBUG_PRINT("|\r\ncharacter size2(00)=");
46
  WL_DEBUG_PRINT_HEX((UCSR1B&(1<<UCSZ12))|(0<<UCSZ12));
47
  WL_DEBUG_PRINT("|\r\n");
48
         
49
        // try getting xbee address
50
  uint16_t address = xbee_get_address();
51
  if(address != WL_ERROR_XBEE_COMMAND_16BIT) {
52
    usb_puts("MY address:");
53
    usb_puth8((uint8_t)(address>>8));
54
    usb_puth8((uint8_t)(address&0xFF)); 
55
    usb_puts("\r\n");
56
  } else {
57
    usb_puts("error getting MY address\r\n");
58
  }
59
  
60
  // try setting channel
61
  /*xbee_set_channel(0x0F);
62
  while(i++ < 10000) {
63
    if(xbee_get_packet(buf) == 3) {
64
      usb_puts("got response from xbee\r\n");
65
      break; // got a response
66
    }
67
  }
68
  
69
  xbee_send_read_at_command("CH");
70
  while(i++ < 10000) {
71
    if(xbee_get_packet(buf) == 3) {
72
      usb_puts("got response from xbee\r\n");
73
      break; // got a response
74
    }
75
  }
76
  
77
  usb_puts("\r\nxbee set channel works\r\n\r\n");
78
  
79
  wl_set_channel(0x16);
80
  while(i++ < 10000) {
81
    if(xbee_get_packet(buf) == 3) {
82
      usb_puts("got response from xbee\r\n");
83
      break; // got a response
84
    }
85
  }
86
  
87
  xbee_send_read_at_command("CH");
88
  while(i++ < 10000) {
89
    if(xbee_get_packet(buf) == 3) {
90
      usb_puts("got response from xbee\r\n");
91
      break; // got a response
92
    }
93
  }  
94
  
95
  usb_puts("\r\nwireless set channel works\r\n");*/
96
  
97
  // scan all xbees in network
98
  /*xbee_send_read_at_command("ND");
99
  i=0;
100
  while(i < 1000) {
101
    if(xbee_get_packet(buf) == 3) {
102
      usb_puts("got response from xbee\r\n");
103
      i++;
104
    }
105
  }*/
106
  
107
  // end of tests
108
  if (xbee_terminate() != 0) {
109
    usb_puts("xbee_terminate error\r\n");
110
  } else {
111
    usb_puts("xbee_terminate success\r\n");
112
  }
113
  usb_puts("testxbee done\r\n\r\n");
114
    
115
        return 0;
116
}