Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / libwireless / lib / wireless.h @ 203

History | View | Annotate | Download (4.18 KB)

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