fix compilation with latest aversive
[protos/xbee-avr.git] / xbee.h
1 /*
2  * Copyright (c) 2011, Olivier MATZ <zer0@droids-corp.org>
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of the University of California, Berkeley nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 /* Callback when receiving data on a specific channel. The arguments
29  * of the function are the xbee device, the channel ID, the type of
30  * the frame (example: XBEE_TYPE_ATRESP), the pointer to the frame,
31  * the length of the frame, and an opaque pointer (reserved for user) */
32 typedef void (xbee_rx_cb_t)(struct xbee_dev *, int, int, void *,
33                             unsigned, void *);
34
35 /* an xbee queue */
36 struct xbee_channel {
37         int registered;
38         xbee_rx_cb_t *rx_cb;
39         void *arg;
40 };
41
42 #define XBEE_DEFAULT_CHANNEL 0
43 #define XBEE_MAX_CHANNEL 16
44 #define XBEE_CHANNEL_ANY XBEE_MAX_CHANNEL
45
46 /* structure identifying a xbee device */
47 struct xbee_dev {
48         FILE *file;
49         struct xbee_channel channel[XBEE_MAX_CHANNEL];
50         uint8_t frame_len;
51         char frame[XBEE_MAX_FRAME_LEN];
52         struct xbee_stats stats;
53         struct xbee_neigh_list neigh_list;
54 };
55
56 /* initialize xbee library */
57 int xbee_init(void);
58
59 /* open an xbee device */
60 int xbee_open(struct xbee_dev *dev, FILE *xbee_file);
61
62 /* closes an xbee device */
63 int xbee_close(struct xbee_dev *dev);
64
65 /* Register a channel, return the ID of the channel or a negative
66  * value on error. The rx_cb is a pointer to a function that will be
67  * called by xbee_read() when a frame is received for this channel. If
68  * rx_cb is NULL, no callback will occur. The "channel" argument can
69  * be XBEE_CHANNEL_ANY to let the library choose the channel, or a
70  * channel number to request a specific one. */
71 int xbee_register_channel(struct xbee_dev *dev, int channel,
72                           xbee_rx_cb_t *rx_cb, void *opaque);
73
74 /* This function (re)sets the opaque pointer on a registered
75  * channel. The function returns 0 on success and -1 on error (channel
76  * not registered). As the opaque pointer can already be set after a
77  * call to xbee_register_channel(), this function is only useful if
78  * the opaque pointer has to be modified. */
79 int xbee_set_opaque(struct xbee_dev *dev, int channel, void *opaque);
80
81 /* Unregister a channel, return 0 on success */
82 int xbee_unregister_channel(struct xbee_dev *dev, int channel_id);
83
84 /* read data from device fd and put it in queue */
85 int xbee_read(struct xbee_dev *dev);
86
87 /* process all data in queue */
88 int xbee_process_queue(struct xbee_dev *dev);