2 * Copyright (c) 2011, Olivier MATZ <zer0@droids-corp.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
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.
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.
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 *,
42 #define XBEE_DEFAULT_CHANNEL 0
43 #define XBEE_MAX_CHANNEL 16
44 #define XBEE_CHANNEL_ANY XBEE_MAX_CHANNEL
46 /* structure identifying a xbee device */
49 struct xbee_channel channel[XBEE_MAX_CHANNEL];
51 char frame[XBEE_MAX_FRAME_LEN];
52 struct xbee_stats stats;
53 struct xbee_neigh_list neigh_list;
56 /* initialize xbee library */
59 /* open an xbee device */
60 int xbee_open(struct xbee_dev *dev, FILE *xbee_file);
62 /* closes an xbee device */
63 int xbee_close(struct xbee_dev *dev);
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);
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);
81 /* Unregister a channel, return 0 on success */
82 int xbee_unregister_channel(struct xbee_dev *dev, int channel_id);
84 /* read data from device fd and put it in queue */
85 int xbee_read(struct xbee_dev *dev);
87 /* process all data in queue */
88 int xbee_process_queue(struct xbee_dev *dev);