root / demos / smart_run_around_fsm / lib / src / libwireless / wireless.h @ 1784
History | View | Annotate | Download (6.07 KB)
1 | 17 | bcoltin | /**
|
---|---|---|---|
2 | 242 | bcoltin | * Copyright (c) 2007 Colony Project
|
3 | 717 | jknichel | *
|
4 | 242 | bcoltin | * 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 | 717 | jknichel | *
|
13 | 242 | bcoltin | * The above copyright notice and this permission notice shall be
|
14 | * included in all copies or substantial portions of the Software.
|
||
15 | 717 | jknichel | *
|
16 | 242 | bcoltin | * 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 | 17 | 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 | 159 | jknichel | |
35 | #ifndef WIRELESS_H
|
||
36 | #define WIRELESS_H
|
||
37 | 717 | jknichel | |
38 | 17 | bcoltin | //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 | 717 | jknichel | //TODO: a PacketGroupHandler is at least 10 bytes (I don't know if function pointers are 2 bytes
|
44 | // or 4 bytes). That means that in the c file, your array of packet groups is at least 160 bytes.
|
||
45 | // Normally that might be fine (the robot's avr chips have 4k SRAM), but austin's chip only has
|
||
46 | // 1k SRAM, so if this number can be reduced or if the size of the struct could be reduced, that would be a plus.
|
||
47 | 17 | bcoltin | #define WL_MAX_PACKET_GROUPS 16 |
48 | |||
49 | /**
|
||
50 | * @defgroup wireless Wireless
|
||
51 | * @brief Wireless definitions.
|
||
52 | *
|
||
53 | * Contains functions and definitions for dealing with wireless functionality.<br><br>
|
||
54 | *
|
||
55 | 717 | jknichel | * The wireless library provides a modular method for dealing with
|
56 | 17 | bcoltin | * wireless packets, by allowing packet groups to be registered.
|
57 | * A packet group is a collection of packets which share a packet
|
||
58 | 717 | jknichel | * group code. Each packet in the group also has a type. A packet
|
59 | 17 | bcoltin | * group code and type are sent with each packet. When a packet
|
60 | 717 | jknichel | * with a group code registered in the wireless library is
|
61 | 17 | bcoltin | * received, the corresponding event handler is called. The
|
62 | * event handler uses the packet type and other information
|
||
63 | * stored in the packet to respond.<br><br>
|
||
64 | *
|
||
65 | * This architecture allows different wireless functionality to be
|
||
66 | * defined and handled separately, making it simpler and more
|
||
67 | * efficient to take advantage of the XBee's wireless functionality.
|
||
68 | *
|
||
69 | * @{
|
||
70 | **/
|
||
71 | |||
72 | /**
|
||
73 | * @struct PacketGroupHandler
|
||
74 | 717 | jknichel | * A PacketGroupHandler represents a packet group, and is used to
|
75 | 17 | bcoltin | * register a packet group with the wireless library. It contains
|
76 | * handlers for various events which can occur related to a packet
|
||
77 | * group.
|
||
78 | **/
|
||
79 | 717 | jknichel | //TODO: the order of member variables in this struct should be changed in case the compile packs the struct
|
80 | // In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
|
||
81 | // Thus, pointers should be first, followed by int, followed by char.
|
||
82 | 346 | bcoltin | typedef struct |
83 | { |
||
84 | 17 | bcoltin | /**
|
85 | * The group code for this packet group. This number
|
||
86 | * must be unique. The maximum number of packet groups
|
||
87 | * is defined by WL_MAX_PACKET_GROUPS.
|
||
88 | **/
|
||
89 | 717 | jknichel | //TODO: if this number must be less than or equal to WL_MAX_PACKET_GROUPS, don't you only need
|
90 | // one byte for it and it can be made an unsigned char?
|
||
91 | 17 | bcoltin | unsigned int groupCode; |
92 | |||
93 | /**
|
||
94 | * Called every half second (not in interrupt,
|
||
95 | * but in wl_do).
|
||
96 | **/
|
||
97 | void (*timeout_handler) (void); |
||
98 | 717 | jknichel | |
99 | 17 | bcoltin | /**
|
100 | * Called when a transmit status packet is received
|
||
101 | * from the XBee where the first four bits of the frame
|
||
102 | * are the group code.
|
||
103 | *
|
||
104 | * @param frame the last four bits of the frame
|
||
105 | * @param received is true if we received an ack, 0 if
|
||
106 | * we did not.
|
||
107 | **/
|
||
108 | void (*handle_response) (int frame, int received); |
||
109 | 717 | jknichel | |
110 | 17 | bcoltin | /**
|
111 | * Called when we receive a packet from this group.
|
||
112 | *
|
||
113 | * @param type the packet type
|
||
114 | * @param source the 16-bit address of the XBee this
|
||
115 | * packet was sent from
|
||
116 | * @param packet the packet received
|
||
117 | * @param length the length of the packet
|
||
118 | **/
|
||
119 | 424 | emarinel | void (*handle_receive) (char type, int source, unsigned char* packet, int length); |
120 | 623 | emarinel | |
121 | 17 | bcoltin | /**
|
122 | * Called for any cleanup when the network is turned off.
|
||
123 | **/
|
||
124 | void (*unregister) (void); |
||
125 | 623 | emarinel | |
126 | 17 | bcoltin | } PacketGroupHandler; |
127 | |||
128 | /**@brief Initialize the wireless library **/
|
||
129 | 418 | emarinel | int wl_init(void); |
130 | 17 | bcoltin | /**@brief Uninitialize the wireless library **/
|
131 | void wl_terminate(void); |
||
132 | /**@brief Perform wireless library functionality **/
|
||
133 | void wl_do(void); |
||
134 | /**@brief Register a packet group with the wireless library **/
|
||
135 | void wl_register_packet_group(PacketGroupHandler* h);
|
||
136 | /**@brief Unregister a packet group with the wireless library **/
|
||
137 | void wl_unregister_packet_group(PacketGroupHandler* h);
|
||
138 | 60 | bcoltin | |
139 | 17 | bcoltin | /**@brief Send a packet to a specific robot in any PAN **/
|
140 | 418 | emarinel | int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame); |
141 | 17 | bcoltin | /**@brief Send a packet to a specific robot in our PAN **/
|
142 | 418 | emarinel | int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame); |
143 | 17 | bcoltin | /**@brief Send a packet to all robots **/
|
144 | 397 | emarinel | int wl_send_global_packet(char group, char type, char* data, int len, char frame); |
145 | 17 | bcoltin | /**@brief Send a packet to all robots in our PAN **/
|
146 | 418 | emarinel | void wl_send_pan_packet(char group, char type, char* data, int len, char frame); |
147 | 60 | bcoltin | |
148 | /**@brief Set the PAN we are using **/
|
||
149 | 418 | emarinel | int wl_set_pan(int pan); |
150 | 60 | bcoltin | /**@brief Get the PAN we are using **/
|
151 | int wl_get_pan(void); |
||
152 | /**@brief Set the channel we are using **/
|
||
153 | 418 | emarinel | int wl_set_channel(int channel); |
154 | 60 | bcoltin | /**@brief Get the channel we are using **/
|
155 | int wl_get_channel(void); |
||
156 | 17 | bcoltin | /**@brief Get the 16-bit address of the XBee module **/
|
157 | 309 | emarinel | int wl_get_xbee_id(void); |
158 | 203 | justin | /**@brief Set the com port on a computer, undefined on the robot.**/
|
159 | void wl_set_com_port(char* port); |
||
160 | 17 | bcoltin | |
161 | /** @} **/ // end defgroup |
||
162 | 159 | jknichel | |
163 | #endif
|