Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / projects / libwireless / xbee.h @ 1598

History | View | Annotate | Download (4.33 KB)

1
/**
2
 * Copyright (c) 2009 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

    
26
/**
27
 * @file xbee.h
28
 * @brief Contains definitions for using the XBee
29
 *
30
 * Contains definitions for interfacing with the 
31
 * XBee module, from either a robot or a computer.
32
 * To use a robot, define ROBOT in wl_defs.h, and
33
 * to use a computer, don't define ROBOT.
34
 *
35
 * @author Colony Project, CMU Robotics Club
36
 **/
37

    
38
#ifndef XBEE_H
39
#define XBEE_H
40

    
41
// need this for C99 int types
42
#ifndef STDINT_H
43
#define STDINT_H
44
#include <stdint.h>
45
#endif
46

    
47

    
48
/**
49
 * @defgroup xbee XBee
50
 * @brief Interface with the XBee module
51
 *
52
 * Interface with the XBee module.
53
 *
54
 * @{
55
 **/
56
 
57
 /**@defgroup xbee_const xbee constants 
58
  * @brief These are constants used for the xbee module.
59
  * @{ **/
60
 
61
// TODO: move constants to xbee.h so they can be used publicly
62

    
63
/**@brief The port to use the XBee from on the computer. **/
64
#ifndef ROBOT
65
#define XBEE_PORT_DEFAULT "/dev/ttyUSB1"
66
#endif
67
 
68
/**@name xbee options
69
 * @{ **/
70
 
71
/**@brief Unset PAN, uses XBee default **/
72
#define XBEE_PAN_DEFAULT 0xFFFF
73
/**@brief Unset channel, uses XBee default **/
74
#define XBEE_CHANNEL_DEFAULT 0
75
/**@brief Broadcast to all robots in the PAN **/
76
#define XBEE_BROADCAST 0xFFFF
77
/**@brief No special options **/
78
#define XBEE_OPTIONS_NONE 0x00
79
/**@brief Do not receive a TX_STATUS message from this packet **/
80
#define XBEE_OPTIONS_DISABLE_RESPONSE 0x01
81
/**@brief Send the packet to all PANS **/
82
#define XBEE_OPTIONS_BROADCAST_ALL_PANS 0x04
83
/**@brief A transmit status packet **/
84
#define XBEE_TX_STATUS 0x89
85
/**@brief A packet received from another XBee **/
86
#define XBEE_RX 0x81
87

    
88
/**@}
89
 * @name xbee frame types
90
 * @{ **/
91

    
92
// TODO: add comments for all of these definitions
93
#define XBEE_FRAME_START 0x7E
94
#define XBEE_GET_PACKET_TIMEOUT 1000
95

    
96
/*Frame Types*/
97
#define XBEE_FRAME_STATUS 0x8A
98
#define XBEE_FRAME_AT_COMMAND 0x08
99
#define XBEE_FRAME_AT_COMMAND_RESPONSE 0x88
100
#define XBEE_FRAME_TX_REQUEST_64 0x00
101
#define XBEE_FRAME_TX_REQUEST_16 0x01
102
#define XBEE_FRAME_TX_STATUS XBEE_TX_STATUS
103
#define XBEE_FRAME_RX_64 0x80
104
#define XBEE_FRAME_RX_16 XBEE_RX
105

    
106
/** @} **/
107

    
108

    
109
// TODO: is this a good size?
110
/*Buffer sizes*/
111
#define XBEE_BUFFER_SIZE        128
112
#define PACKET_BUFFER_SIZE        108
113

    
114
/**@} **/ // end const group
115
 
116
/**
117
 * @defgroup xbee_funcs Xbee Functions
118
 * @brief These are the public xbee functions.
119
 * @{
120
 **/
121
  
122
// TODO: convert all int references to int16_t syntax (see stdint.h)
123

    
124
/**@brief Initialize the XBee library **/
125
int xbee_lib_init(void);
126
/**@brief Uninitialize the XBee library **/
127
void xbee_terminate(void);
128
/**@brief Get a packet from the XBee **/
129
int xbee_get_packet(unsigned char* packet);
130
/**@brief Send a packet to the XBee **/
131
int xbee_send_packet(char* packet, int len, int dest, char options, char frame);
132
/**@brief Set the PAN ID for the XBee **/
133
int xbee_set_pan_id(int id);
134
/**@brief Get the XBee's PAN ID **/
135
unsigned int xbee_get_pan_id(void);
136
/**@brief Set the channel the XBee is currently using **/
137
int xbee_set_channel(int channel);
138
/**@brief Get the channel the XBee is currently using **/
139
int xbee_get_channel(void);
140
/**@brief Get the XBee's 16-bit address **/
141
unsigned int xbee_get_address(void);
142
/**@brief Set the com port on a computer, undefined on the robot**/
143
void xbee_set_com_port(char* port);
144
/**@brief Reset XBee **/
145
int xbee_reset(void);
146

    
147
/**@} **/ //end xbee_funcs group
148

    
149
/**@} **/ //end defgroup
150

    
151
#endif