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