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