root / branches / autonomous_recharging / code / lib / include / libwireless / wireless.h @ 743
History | View | Annotate | Download (5.28 KB)
1 | 18 | bcoltin | /**
|
---|---|---|---|
2 | 743 | bcoltin | * Copyright (c) 2007 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 | 18 | bcoltin | * @file wireless.h
|
28 | * @brief Contains definitions for the wireless library.
|
||
29 | *
|
||
30 | * Contains functions for the wireless library.
|
||
31 | *
|
||
32 | * @author Brian Coltin, Colony Project, CMU Robotics Club
|
||
33 | **/
|
||
34 | 743 | bcoltin | |
35 | #ifndef WIRELESS_H
|
||
36 | #define WIRELESS_H
|
||
37 | 18 | bcoltin | |
38 | //Note: If this is raised above 16, we will need to do
|
||
39 | //something about frame numbers for TX Status packets.
|
||
40 | /**
|
||
41 | * The maximum number of packet groups.
|
||
42 | **/
|
||
43 | #define WL_MAX_PACKET_GROUPS 16 |
||
44 | |||
45 | /**
|
||
46 | * @defgroup wireless Wireless
|
||
47 | * @brief Wireless definitions.
|
||
48 | *
|
||
49 | * Contains functions and definitions for dealing with wireless functionality.<br><br>
|
||
50 | *
|
||
51 | * The wireless library provides a modular method for dealing with
|
||
52 | * wireless packets, by allowing packet groups to be registered.
|
||
53 | * A packet group is a collection of packets which share a packet
|
||
54 | * group code. Each packet in the group also has a type. A packet
|
||
55 | * group code and type are sent with each packet. When a packet
|
||
56 | * with a group code registered in the wireless library is
|
||
57 | * received, the corresponding event handler is called. The
|
||
58 | * event handler uses the packet type and other information
|
||
59 | * stored in the packet to respond.<br><br>
|
||
60 | *
|
||
61 | * This architecture allows different wireless functionality to be
|
||
62 | * defined and handled separately, making it simpler and more
|
||
63 | * efficient to take advantage of the XBee's wireless functionality.
|
||
64 | *
|
||
65 | * @{
|
||
66 | **/
|
||
67 | |||
68 | /**
|
||
69 | * @struct PacketGroupHandler
|
||
70 | * A PacketGroupHandler represents a packet group, and is used to
|
||
71 | * register a packet group with the wireless library. It contains
|
||
72 | * handlers for various events which can occur related to a packet
|
||
73 | * group.
|
||
74 | **/
|
||
75 | typedef struct |
||
76 | { |
||
77 | /**
|
||
78 | * The group code for this packet group. This number
|
||
79 | * must be unique. The maximum number of packet groups
|
||
80 | * is defined by WL_MAX_PACKET_GROUPS.
|
||
81 | **/
|
||
82 | unsigned int groupCode; |
||
83 | |||
84 | /**
|
||
85 | * Called every half second (not in interrupt,
|
||
86 | * but in wl_do).
|
||
87 | **/
|
||
88 | void (*timeout_handler) (void); |
||
89 | |||
90 | /**
|
||
91 | * Called when a transmit status packet is received
|
||
92 | * from the XBee where the first four bits of the frame
|
||
93 | * are the group code.
|
||
94 | *
|
||
95 | * @param frame the last four bits of the frame
|
||
96 | * @param received is true if we received an ack, 0 if
|
||
97 | * we did not.
|
||
98 | **/
|
||
99 | void (*handle_response) (int frame, int received); |
||
100 | |||
101 | /**
|
||
102 | * Called when we receive a packet from this group.
|
||
103 | *
|
||
104 | * @param type the packet type
|
||
105 | * @param source the 16-bit address of the XBee this
|
||
106 | * packet was sent from
|
||
107 | * @param packet the packet received
|
||
108 | * @param length the length of the packet
|
||
109 | **/
|
||
110 | void (*handle_receive) (char type, int source, unsigned char* packet, |
||
111 | int length);
|
||
112 | |||
113 | /**
|
||
114 | * Called for any cleanup when the network is turned off.
|
||
115 | **/
|
||
116 | void (*unregister) (void); |
||
117 | |||
118 | } PacketGroupHandler; |
||
119 | |||
120 | /**@brief Initialize the wireless library **/
|
||
121 | 743 | bcoltin | int wl_init(void); |
122 | 18 | bcoltin | /**@brief Uninitialize the wireless library **/
|
123 | void wl_terminate(void); |
||
124 | /**@brief Perform wireless library functionality **/
|
||
125 | void wl_do(void); |
||
126 | /**@brief Register a packet group with the wireless library **/
|
||
127 | void wl_register_packet_group(PacketGroupHandler* h);
|
||
128 | /**@brief Unregister a packet group with the wireless library **/
|
||
129 | void wl_unregister_packet_group(PacketGroupHandler* h);
|
||
130 | 60 | bcoltin | |
131 | 18 | bcoltin | /**@brief Send a packet to a specific robot in any PAN **/
|
132 | void wl_send_robot_to_robot_global_packet(char group, char type, |
||
133 | char* data, int len, int dest, char frame); |
||
134 | /**@brief Send a packet to a specific robot in our PAN **/
|
||
135 | void wl_send_robot_to_robot_packet(char group, char type, |
||
136 | char* data, int len, int dest, char frame); |
||
137 | /**@brief Send a packet to all robots **/
|
||
138 | void wl_send_global_packet(char group, char type, |
||
139 | char* data, int len, char frame); |
||
140 | /**@brief Send a packet to all robots in our PAN **/
|
||
141 | void wl_send_pan_packet(char group, char type, |
||
142 | char* data, int len, char frame); |
||
143 | 60 | bcoltin | |
144 | /**@brief Set the PAN we are using **/
|
||
145 | void wl_set_pan(int pan); |
||
146 | /**@brief Get the PAN we are using **/
|
||
147 | int wl_get_pan(void); |
||
148 | /**@brief Set the channel we are using **/
|
||
149 | void wl_set_channel(int channel); |
||
150 | /**@brief Get the channel we are using **/
|
||
151 | int wl_get_channel(void); |
||
152 | 18 | bcoltin | /**@brief Get the 16-bit address of the XBee module **/
|
153 | 743 | bcoltin | int wl_get_xbee_id(void); |
154 | /**@brief Set the com port on a computer, undefined on the robot.**/
|
||
155 | void wl_set_com_port(char* port); |
||
156 | 18 | bcoltin | |
157 | /** @} **/ // end defgroup |
||
158 | |||
159 | 743 | bcoltin | #endif
|