xbee.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 INRIA
3  * Copyright (C) 2015-2016 Freie Universität Berlin
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
23 #ifndef XBEE_H
24 #define XBEE_H
25 
26 #include <stdint.h>
27 
28 #include "mutex.h"
29 #include "xtimer.h"
30 #include "periph/uart.h"
31 #include "periph/gpio.h"
32 #include "net/netdev.h"
33 #include "net/ieee802154.h"
34 #include "net/gnrc/nettype.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 #ifdef MODULE_XBEE_ENCRYPTION
44 #define XBEE_MAX_PAYLOAD_LENGTH (95U)
45 #else
46 #define XBEE_MAX_PAYLOAD_LENGTH (100U)
47 #endif
48 
52 #define XBEE_MAX_PKT_LENGTH (115U)
53 
57 #define XBEE_MAX_RESP_LENGTH (16U)
58 
62 #define XBEE_MAX_TXHDR_LENGTH (14U)
63 
67 #ifdef MODULE_GNRC_SIXLOWPAN
68 #define XBEE_DEFAULT_PROTOCOL (GNRC_NETTYPE_SIXLOWPAN)
69 #else
70 #define XBEE_DEFAULT_PROTOCOL (GNRC_NETTYPE_UNDEF)
71 #endif
72 
76 #define XBEE_DEFAULT_PANID (CONFIG_IEEE802154_DEFAULT_PANID)
77 
81 #define XBEE_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_CHANNEL)
82 
91 #define XBEE_ADDR_FLAGS_LONG (0x80)
92 
101 typedef enum {
113 
117 typedef struct {
119  uint32_t br;
120  gpio_t pin_sleep;
122  gpio_t pin_reset;
124 } xbee_params_t;
125 
129 typedef struct {
130  /* netdev fields */
131  const struct netdev_driver *driver;
133  void* context;
134  /* device driver specific fields */
136  uint8_t options;
137  uint8_t addr_flags;
138  uint8_t addr_short[2];
140  /* general variables for the UART RX state machine */
142  uint16_t int_size;
144  /* values for the UART TX state machine */
147  uint8_t cmd_buf[XBEE_MAX_RESP_LENGTH];
148  uint8_t tx_fid;
149  /* buffer and synchronization for command responses */
152  uint8_t resp_buf[XBEE_MAX_RESP_LENGTH];
153  uint16_t resp_count;
154  uint16_t resp_limit;
155  /* buffer and synchronization for incoming network packets */
156  uint8_t rx_buf[XBEE_MAX_PKT_LENGTH];
157  uint16_t rx_count;
158  uint16_t rx_limit;
159 } xbee_t;
160 
164 typedef struct {
165  uint8_t addr_len;
166  uint8_t bcast;
167  uint8_t rssi;
168  uint8_t src_addr[8];
169  uint8_t dst_addr[8];
170 } xbee_l2hdr_t;
171 
175 extern const netdev_driver_t xbee_driver;
176 
187 void xbee_setup(xbee_t *dev, const xbee_params_t *params);
188 
203 int xbee_build_hdr(xbee_t *dev, uint8_t *xhdr, size_t payload_len,
204  void *dst_addr, size_t addr_len);
205 
216 int xbee_parse_hdr(xbee_t *dev, const uint8_t *xhdr, xbee_l2hdr_t *l2hdr);
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif /* XBEE_H */
223 
xbee_t::p
xbee_params_t p
configuration parameters
Definition: xbee.h:135
netdev_driver
Structure to hold driver interface -> function mapping.
Definition: netdev.h:344
xbee_l2hdr_t
Data structure for extraction L2 information of received packets.
Definition: xbee.h:164
xbee_params_t::pin_sleep
gpio_t pin_sleep
GPIO pin that is connected to the SLEEP pin set to GPIO_UNDEF if not used.
Definition: xbee.h:120
xbee_params_t::pin_reset
gpio_t pin_reset
GPIO pin that is connected to the STATUS pin set to GPIO_UNDEF if not used.
Definition: xbee.h:122
xbee_t::event_callback
netdev_event_cb_t event_callback
callback for device events
Definition: xbee.h:132
ieee802154.h
IEEE 802.15.4 header definitions.
xbee_t::context
void * context
ptr to network stack context
Definition: xbee.h:133
XBEE_INT_STATE_IDLE
@ XBEE_INT_STATE_IDLE
waiting for the beginning of a new frame
Definition: xbee.h:102
xbee_t::rx_limit
uint16_t rx_limit
size RX frame transferred
Definition: xbee.h:158
XBEE_MAX_PKT_LENGTH
#define XBEE_MAX_PKT_LENGTH
Maximum packet length, including XBee API frame overhead.
Definition: xbee.h:52
xbee_t::resp_limit
uint16_t resp_limit
size RESP frame in transferred
Definition: xbee.h:154
xbee_build_hdr
int xbee_build_hdr(xbee_t *dev, uint8_t *xhdr, size_t payload_len, void *dst_addr, size_t addr_len)
Put together the internal proprietary XBee header.
XBEE_INT_STATE_SIZE2
@ XBEE_INT_STATE_SIZE2
waiting for the second byte (LSB) of the frame size field
Definition: xbee.h:105
xbee_t::tx_fid
uint8_t tx_fid
TX frame ID.
Definition: xbee.h:148
xbee_driver
const netdev_driver_t xbee_driver
Reference to the XBee driver interface.
xbee_l2hdr_t::addr_len
uint8_t addr_len
L2 address length (SRC and DST)
Definition: xbee.h:165
xbee_t::addr_long
eui64_t addr_long
own 802.15.4 long address
Definition: xbee.h:139
xbee_t::rx_count
uint16_t rx_count
counter for ongoing transmission
Definition: xbee.h:157
XBEE_INT_STATE_TYPE
@ XBEE_INT_STATE_TYPE
waiting for the frame type field
Definition: xbee.h:107
uart_t
unsigned int uart_t
Define default UART type identifier.
Definition: uart.h:76
xbee_setup
void xbee_setup(xbee_t *dev, const xbee_params_t *params)
Prepare the given Xbee device.
xbee_t::options
uint8_t options
options field
Definition: xbee.h:136
uart.h
Low-level UART peripheral driver interface definition.
xbee_l2hdr_t::rssi
uint8_t rssi
RSSI value.
Definition: xbee.h:167
netdev_event_cb_t
void(* netdev_event_cb_t)(netdev_t *dev, netdev_event_t event)
Event callback for signaling event to upper layers.
Definition: netdev.h:273
xbee_t::tx_lock
mutex_t tx_lock
mutex to allow only one transmission at a time
Definition: xbee.h:145
xbee_t::driver
const struct netdev_driver * driver
ptr to that driver's interface.
Definition: xbee.h:131
XBEE_MAX_RESP_LENGTH
#define XBEE_MAX_RESP_LENGTH
Maximum length of a command response.
Definition: xbee.h:57
netdev.h
Definitions low-level network driver interface.
nettype.h
Protocol type definitions.
xbee_t::int_size
uint16_t int_size
temporary space for parsing the frame size
Definition: xbee.h:142
XBEE_INT_STATE_RX
@ XBEE_INT_STATE_RX
handling incoming data when receiving radio packets
Definition: xbee.h:110
xbee_t
XBee device descriptor.
Definition: xbee.h:129
xbee_t::resp_lock
mutex_t resp_lock
mutex for waiting for AT command response frames
Definition: xbee.h:150
xbee_t::int_state
xbee_rx_state_t int_state
current state if the UART RX FSM
Definition: xbee.h:141
mutex.h
Mutex for thread synchronization.
XBEE_INT_STATE_SIZE1
@ XBEE_INT_STATE_SIZE1
waiting for the first byte (MSB) of the frame size field
Definition: xbee.h:103
gpio.h
Low-level GPIO peripheral driver interface definitions.
xbee_t::resp_count
uint16_t resp_count
counter for ongoing transmission
Definition: xbee.h:153
eui64_t
Data type to represent an EUI-64.
Definition: eui64.h:55
xbee_params_t::br
uint32_t br
baudrate to use
Definition: xbee.h:119
xbee_params_t
Configuration parameters for XBee devices.
Definition: xbee.h:117
xbee_rx_state_t
xbee_rx_state_t
States of the internal FSM for handling incoming UART frames.
Definition: xbee.h:101
xbee_l2hdr_t::bcast
uint8_t bcast
0 := unicast, 1:=broadcast
Definition: xbee.h:166
xbee_params_t::uart
uart_t uart
UART interfaced the device is connected to.
Definition: xbee.h:118
xbee_parse_hdr
int xbee_parse_hdr(xbee_t *dev, const uint8_t *xhdr, xbee_l2hdr_t *l2hdr)
Extract IEEE802.15.4 L2 header information from the XBee header.
xtimer.h
xtimer interface definitions
mutex_t
Mutex structure.
Definition: mutex.h:120
xbee_t::addr_flags
uint8_t addr_flags
address flags as defined above
Definition: xbee.h:137
XBEE_INT_STATE_RESP
@ XBEE_INT_STATE_RESP
handling incoming data for AT command responses
Definition: xbee.h:108