root / branches / wireless / code / projects / libwireless / xbee.h @ 1617
History | View | Annotate | Download (4.42 KB)
1 | 1576 | dsschult | /**
|
---|---|---|---|
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 | 1587 | dsschult | /**@defgroup xbee_const xbee constants
|
58 | * @brief These are constants used for the xbee module.
|
||
59 | * @{ **/
|
||
60 | 1604 | dsschult | |
61 | #ifndef XBEE_BAUD
|
||
62 | /** @brief The XBee baud rate **/
|
||
63 | #define XBEE_BAUD 115200 |
||
64 | 1587 | dsschult | #endif
|
65 | |||
66 | /**@name xbee options
|
||
67 | * @{ **/
|
||
68 | |||
69 | /**@brief Unset PAN, uses XBee default **/
|
||
70 | #define XBEE_PAN_DEFAULT 0xFFFF |
||
71 | /**@brief Unset channel, uses XBee default **/
|
||
72 | #define XBEE_CHANNEL_DEFAULT 0 |
||
73 | /**@brief Broadcast to all robots in the PAN **/
|
||
74 | #define XBEE_BROADCAST 0xFFFF |
||
75 | /**@brief No special options **/
|
||
76 | #define XBEE_OPTIONS_NONE 0x00 |
||
77 | /**@brief Do not receive a TX_STATUS message from this packet **/
|
||
78 | #define XBEE_OPTIONS_DISABLE_RESPONSE 0x01 |
||
79 | /**@brief Send the packet to all PANS **/
|
||
80 | #define XBEE_OPTIONS_BROADCAST_ALL_PANS 0x04 |
||
81 | /**@brief A transmit status packet **/
|
||
82 | #define XBEE_TX_STATUS 0x89 |
||
83 | /**@brief A packet received from another XBee **/
|
||
84 | #define XBEE_RX 0x81 |
||
85 | |||
86 | /**@}
|
||
87 | * @name xbee frame types
|
||
88 | * @{ **/
|
||
89 | |||
90 | // TODO: add comments for all of these definitions
|
||
91 | |||
92 | /*Frame Types*/
|
||
93 | 1601 | dsschult | #define XBEE_FRAME_START 0x7E |
94 | 1587 | dsschult | #define XBEE_FRAME_STATUS 0x8A |
95 | #define XBEE_FRAME_AT_COMMAND 0x08 |
||
96 | #define XBEE_FRAME_AT_COMMAND_RESPONSE 0x88 |
||
97 | #define XBEE_FRAME_TX_REQUEST_64 0x00 |
||
98 | #define XBEE_FRAME_TX_REQUEST_16 0x01 |
||
99 | #define XBEE_FRAME_TX_STATUS XBEE_TX_STATUS
|
||
100 | #define XBEE_FRAME_RX_64 0x80 |
||
101 | #define XBEE_FRAME_RX_16 XBEE_RX
|
||
102 | |||
103 | /** @} **/
|
||
104 | |||
105 | /**@} **/ // end const group |
||
106 | |||
107 | /**
|
||
108 | * @defgroup xbee_funcs Xbee Functions
|
||
109 | * @brief These are the public xbee functions.
|
||
110 | * @{
|
||
111 | **/
|
||
112 | |||
113 | 1576 | dsschult | /**@brief Initialize the XBee library **/
|
114 | 1604 | dsschult | int8_t xbee_init(void);
|
115 | 1576 | dsschult | /**@brief Uninitialize the XBee library **/
|
116 | 1604 | dsschult | int8_t xbee_terminate(void);
|
117 | /**@brief Send a byte to the xbee **/
|
||
118 | int8_t xbee_putc(uint8_t c); |
||
119 | /**@brief Read a byte form the xbee **/
|
||
120 | int16_t xbee_getc(void);
|
||
121 | /**@brief Read a byte from the xbee (nonblocking) **/
|
||
122 | int8_t xbee_getc_nb(uint8_t *c); |
||
123 | /**@brief Send an array of bytes to the xbee **/
|
||
124 | 1616 | dsschult | int8_t xbee_send(uint8_t* buf, uint16_t size); |
125 | 1604 | dsschult | /**@brief Add a buffer to the checksum value **/
|
126 | 1616 | dsschult | int8_t xbee_checksum_add(uint8_t *buf, uint8_t len, uint8_t* sum); |
127 | 1604 | dsschult | /**@brief Send a frame header to the xbee **/
|
128 | 1616 | dsschult | int8_t xbee_send_header(uint8_t type, uint16_t len); |
129 | 1576 | dsschult | /**@brief Send a packet to the XBee **/
|
130 | 1604 | dsschult | int8_t xbee_send_packet(uint8_t* packet, uint8_t len, uint16_t dest, uint8_t options, uint8_t frame); |
131 | 1576 | dsschult | /**@brief Set the PAN ID for the XBee **/
|
132 | 1611 | dsschult | int8_t xbee_set_pan_id(uint16_t id); |
133 | 1576 | dsschult | /**@brief Get the XBee's PAN ID **/
|
134 | 1604 | dsschult | uint16_t xbee_get_pan_id(void);
|
135 | 1576 | dsschult | /**@brief Set the channel the XBee is currently using **/
|
136 | 1611 | dsschult | int8_t xbee_set_channel(uint8_t channel); |
137 | 1576 | dsschult | /**@brief Get the channel the XBee is currently using **/
|
138 | 1604 | dsschult | int8_t xbee_get_channel(void);
|
139 | 1576 | dsschult | /**@brief Get the XBee's 16-bit address **/
|
140 | 1604 | dsschult | uint16_t xbee_get_address(void);
|
141 | 1576 | dsschult | /**@brief Reset XBee **/
|
142 | 1604 | dsschult | int8_t xbee_reset(void); // TODO: implement this function |
143 | 1576 | dsschult | |
144 | 1587 | dsschult | /**@} **/ //end xbee_funcs group |
145 | 1576 | dsschult | |
146 | 1587 | dsschult | /**@} **/ //end defgroup |
147 | |||
148 | 1576 | dsschult | #endif |