Digi XBee(R) ANSI C Host Library
|
Files | |
file | sxa.h |
file | sxa_socket.h |
Header for Simplified XBee API TCP sockets over ZigBee. | |
file | xbee_reg_descr.c |
Code related to the register descriptor table. | |
file | xbee_sxa.c |
Simple XBee API. | |
file | xbee_sxa_socket.c |
Simple XBee API, TCP sockets over ZigBee. | |
Data Structures | |
struct | sxa_cached_group_t |
Cached register group value. More... | |
struct | sxa_node_t |
This structure and the attendant functions provide a useful layer for Rabbit applications who wish to use a simplified interface to the XBee API. More... | |
struct | _sxa_sock_hdr_t |
Macros | |
#define | sxa_list_head() sxa_table |
#define | sxa_list_count() sxa_table_count |
#define | _SXA_CACHED_PREFIX_SIZE (sizeof(sxa_cache_flags_t)) |
#define | _SXA_CACHED_STRING(name, len) XBEE_PACKED(, { sxa_cache_flags_t flags; uint8_t value[len+1]; }) name |
Cached string register value. More... | |
#define | _SXA_CACHED_BIN(name, len) XBEE_PACKED(, { sxa_cache_flags_t flags; uint8_t value[len]; }) name |
Cached binary register value. More... | |
#define | ZB_CAP_ADV_ADDR 0x00000001 |
#define | ZB_CAP_ZDO 0x00000002 |
#define | ZB_CAP_REMOTE_DDO 0x00000004 |
#define | ZB_CAP_GW_FW 0x00000008 |
#define | ZB_CAP_REMOTE_FW 0x00000010 |
#define | ZB_CAP_ZIGBEE 0x00000020 |
#define | ZB_CAP_ZBPRO 0x00000040 |
#define | ZB_CAP_DIGIMESH 0x00000080 |
#define | ZB_CAP_CHILDREN 0x00000100 |
#define | ZB_CAP_SE 0x00000200 |
#define | sxa_xbee(s) ((s)->xbee) |
#define | sxa_wpan_address(s) ((s)->addr_ptr) |
#define | XBEE_FRAME_HANDLE_ND_RESPONSE |
Macro for registering a handler to receive node announcements via both ATND responses and 0x95 frames received. More... | |
#define | XBEE_DISC_CLIENT_CLUST_ENTRY |
#define | XBEE_FRAME_HANDLE_IS_RESPONSE |
Macro for registering a handler to receive I/O samples via both ATIS responses and 0x92 frames received. More... | |
#define | XBEE_IO_CLIENT_CLUST_ENTRY |
#define | SXA_SOCKET_MTU 104 |
Network interface Maximum Transmission Unit, as seen by TCP stack. More... | |
#define | SXA_INDEX_TO_IP(index) IPADDR(127,1,0,index) |
Macro to generate the appropriate "loopback" IP address, i.e. More... | |
#define | SXA_STREAM_PORT UINT16_C(61616) |
Macro to use for first and last valid TCP port numbers, for both source port and destination port. More... | |
#define | SXA_MAX_STREAM_PORT UINT16_C(61616+255) |
#define | WPAN_ENDPOINT_DIGI_STREAM 0x66 |
Provisional endpoint for reliable stream. | |
#define | SXA_SOCKET_ENDPOINT |
Place this entry in endpoint table to enable SXA sockets. More... | |
#define | _XRT_ENTRY(state, tag, at, cxv, desc, units, min, max, rci_type, sxa_field, group) |
#define | F8 0x0002 |
#define | EZ 0x0004 |
#define | ZB 0x0408 |
#define | X9 0x0010 |
#define | X2 0x0020 |
#define | X8 0x0040 |
#define | DP 0x0080 |
#define | FZ 0x0001 |
#define | SE 0x0100 |
#define | ALL 0x07ff |
#define | GW 0x8000 |
#define | _xbee_sxa_debug |
#define | _sys_calloc(s) calloc( s, 1) |
#define | _sys_malloc(s) malloc( s) |
#define | _sys_free(p) free( p) |
#define | SXA_OFFSET(base, ofs) (void FAR *)((char FAR *)(base) + (ofs)) |
#define | _SXA_CG_INIT(id, field, get, fn) { id, offsetof(sxa_node_t, field), get, fn } |
#define | _SXA_CG_INIT_END { 0, 0, NULL, NULL } |
Typedefs | |
typedef uint8_t | sxa_cache_flags_t |
struct { | |
sxa_cache_flags_t flags | |
} | sxa_cached_t |
Cached generic register value (no data) More... | |
struct { | |
sxa_cache_flags_t flags | |
uint8_t value | |
} | sxa_cached_uint8_t |
Cached uint8_t register value. More... | |
struct { | |
sxa_cache_flags_t flags | |
uint16_t value | |
} | sxa_cached_uint16_t |
Cached uint16_t register value. More... | |
struct { | |
sxa_cache_flags_t flags | |
uint32_t value | |
} | sxa_cached_uint32_t |
Cached uint32_t register value. More... | |
struct { | |
sxa_cache_flags_t flags | |
addr64 value | |
} | sxa_cached_addr64 |
Cached extended address register value. More... | |
typedef void(* | sxa_cache_upd_fn) (struct sxa_node_t FAR *sxa, const struct sxa_cached_group_t FAR *cgroup) |
Function registered for cache group update post-processing. More... | |
Enumerations | |
enum | { _SXA_CACHED_UNKNOWN = 0x00, _SXA_CACHED_OK = 0x01, _SXA_CACHED_ERROR = 0x02, _SXA_CACHED_BUSY = 0x04, _SXA_CACHED_PENDING = 0x08, _SXA_CACHED_BAD_GROUP = 0x10 } |
enum | { SXA_CACHED_NONE, SXA_CACHED_NODE_ID, SXA_CACHED_IO_CONFIG, SXA_CACHED_DEVICE_INFO, SXA_CACHED_DHDL, SXA_CACHED_MISC = 255 } |
This enum gives numeric identification to all cache groups. More... | |
Functions | |
const sxa_cached_group_t FAR * | _sxa_cache_group_by_id (uint16_t id) |
void | _sxa_update_io_config_group (sxa_node_t FAR *sxa, const sxa_cached_group_t FAR *cgroup) |
void | _sxa_process_version_info (const xbee_cmd_response_t FAR *response, const struct xbee_atcmd_reg_t FAR *reg, void FAR *base) |
sxa_node_t FAR * | sxa_node_by_addr (const addr64 FAR *ieee_be) |
sxa_node_t FAR * | sxa_local_node (const xbee_dev_t *xbee) |
sxa_node_t FAR * | sxa_node_by_name (const char FAR *name) |
sxa_node_t FAR * | sxa_node_by_index (int index) |
sxa_node_t FAR * | sxa_node_add (xbee_dev_t *xbee, const xbee_node_id_t FAR *node_id) |
void | sxa_node_table_dump (void) |
xbee_dev_t *() | sxa_xbee (sxa_node_t FAR *sxa) |
wpan_address_t FAR *() | sxa_wpan_address (sxa_node_t FAR *sxa) |
int | sxa_get_digital_input (const sxa_node_t FAR *sxa, uint_fast8_t index) |
int | sxa_get_digital_output (const sxa_node_t FAR *sxa, uint_fast8_t index) |
int16_t | sxa_get_analog_input (const sxa_node_t FAR *sxa, uint_fast8_t index) |
int | sxa_set_digital_output (sxa_node_t FAR *sxa, uint_fast8_t index, enum xbee_io_digital_output_state state) |
int | sxa_io_configure (sxa_node_t FAR *sxa, uint_fast8_t index, enum xbee_io_type type) |
int | sxa_io_set_options (sxa_node_t FAR *sxa, uint16_t sample_rate, uint16_t change_mask) |
void | sxa_io_dump (sxa_node_t FAR *sxa) |
int | sxa_io_query (sxa_node_t FAR *sxa) |
int | sxa_io_query_status (sxa_node_t FAR *sxa) |
sxa_node_t FAR * | sxa_init_or_exit (xbee_dev_t *xbee, const wpan_endpoint_table_entry_t *ep_table, int verbose) |
void | _sxa_launch_update (sxa_node_t FAR *sxa, const struct _xbee_reg_descr_t FAR *xrd, uint16_t cache_group) |
void | sxa_tick (void) |
int | sxa_is_digi (const sxa_node_t FAR *sxa) |
int | _sxa_disc_process_node_data (xbee_dev_t *xbee, const void FAR *raw, int length) |
Function shared by multiple functions that process Node Identification Messages (0x95 frames and ATND responses). More... | |
int | _sxa_disc_atnd_response (xbee_dev_t *xbee, const void FAR *raw, uint16_t length, void FAR *context) |
Frame handler for processing AT Command Response frames. More... | |
int | _sxa_disc_handle_frame_0x95 (xbee_dev_t *xbee, const void FAR *raw, uint16_t length, void FAR *context) |
Frame handler for processing Node Identification Indicator (0x95) frames. More... | |
int | _sxa_disc_cluster_handler (const wpan_envelope_t FAR *envelope, void FAR *context) |
Cluster handler for "Digi Node Identification" cluster. More... | |
int | _sxa_io_process_response (const addr64 FAR *ieee_be, const void FAR *raw, int length) |
Function shared by multiple functions that process I/O sample messages (0x92 frames and ATIS responses). More... | |
int | _sxa_io_response_handler (xbee_dev_t *xbee, const void FAR *raw, uint16_t length, void FAR *context) |
int | _sxa_io_cluster_handler (const wpan_envelope_t FAR *envelope, void FAR *context) |
int | _sxa_remote_is_cmd_response_handler (xbee_dev_t *xbee, const void FAR *raw, uint16_t length, void FAR *context) |
int | _sxa_local_is_cmd_response_handler (xbee_dev_t *xbee, const void FAR *raw, uint16_t length, void FAR *context) |
sxa_cache_flags_t | sxa_cache_status (sxa_node_t FAR *sxa, const _xbee_reg_descr_t FAR *zb, uint16_t cache_group) |
void | _sxa_set_cache_status (sxa_node_t FAR *sxa, const _xbee_reg_descr_t FAR *zb, uint16_t cache_group, sxa_cache_flags_t flags) |
void FAR * | sxa_cached_value_ptr (sxa_node_t FAR *sxa, const _xbee_reg_descr_t FAR *zb) |
uint16_t | sxa_cached_value_len (sxa_node_t FAR *sxa, const _xbee_reg_descr_t FAR *zb) |
int | sxa_find_pending_cache (sxa_node_t FAR *sxa, const _xbee_reg_descr_t FAR *zb) |
int | sxa_schedule_update_cache (sxa_node_t FAR *sxa, const _xbee_reg_descr_t FAR *zb) |
int | _sxa_socket_tx_handler (struct LoopbackHandler __far *lh, ll_Gather *g) |
int | _sxa_socket_rx_handler (const wpan_envelope_t FAR *envelope, wpan_ep_state_t FAR *ep_state) |
int | sxa_socket_init (void) |
void | _sxa_cmd_list_cache_cb (const xbee_cmd_response_t FAR *response, const struct xbee_atcmd_reg_t FAR *reg, void FAR *base) |
Variables | |
const FAR sxa_cached_group_t | _sxa_default_cache_groups [] |
sxa_node_t FAR * | sxa_table |
int | sxa_table_count |
sxa_node_t FAR * | sxa_local_table |
const char * | _xbee_rci_types [] |
Table to map _xbee_rci_type_t to RCI type string. More... | |
const FAR _xbee_reg_descr_t | _xbee_reg_table [] |
sxa_node_t FAR * | sxa_table = NULL |
int | sxa_table_count = 0 |
sxa_node_t FAR * | sxa_local_table = NULL |
const FAR xbee_atcmd_reg_t | _sxa_ni_query_regs [] |
const FAR xbee_atcmd_reg_t | _sxa_devinfo_query_regs [] |
const FAR xbee_atcmd_reg_t | _sxa_dhdl_query_regs [] |
const FAR sxa_cached_group_t | _sxa_default_cache_groups [] |
const FAR xbee_atcmd_reg_t | _sxa_init_query_regs [] |
#define _SXA_CACHED_BIN | ( | name, | |
len | |||
) | XBEE_PACKED(, { sxa_cache_flags_t flags; uint8_t value[len]; }) name |
Cached binary register value.
This is in the form of a macro which generates an in-line struct definition, since binaries are arrays with generally different maximum lengths.
#define _SXA_CACHED_PREFIX_SIZE (sizeof(sxa_cache_flags_t)) |
Size of cache flags and any other prefix data in each sxa_cached_* struct. Each struct must have same prefix data. Only the final 'value' field may be different.
Referenced by _sxa_io_process_response().
#define _SXA_CACHED_STRING | ( | name, | |
len | |||
) | XBEE_PACKED(, { sxa_cache_flags_t flags; uint8_t value[len+1]; }) name |
Cached string register value.
This is in the form of a macro which generates an in-line struct definition, since strings are arrays with generally different maximum lengths.
One extra char is automatically added, for the null terminator.
#define _XRT_ENTRY | ( | state, | |
tag, | |||
at, | |||
cxv, | |||
desc, | |||
units, | |||
min, | |||
max, | |||
rci_type, | |||
sxa_field, | |||
group | |||
) |
#define SXA_INDEX_TO_IP | ( | index | ) | IPADDR(127,1,0,index) |
Macro to generate the appropriate "loopback" IP address, i.e.
the IP address to use to talk to a particular remote node defined by its SXA node table index.
#define SXA_SOCKET_ENDPOINT |
Place this entry in endpoint table to enable SXA sockets.
#define SXA_SOCKET_MTU 104 |
Network interface Maximum Transmission Unit, as seen by TCP stack.
Selection of this constant is a bit tricky. ZigBee has a small MTU, however the XBee modules accept larger payloads and fragments them if necessary when transmitting. TCP likes to avoid fragmentation and tries to select an MSS (TCP payload size) as large as possible, but not so large as to require any fragmentation along the transmission path.
There is no reliable method to set the MSS, because the ZigBee MTU depends on various header options such as encryption and source routing. Because of this, we select a conservative value for the TCP MSS of 64 bytes. To this, we add 40 bytes (for the IP and TCP headers) to get an MTU of 104, since TCP computes its MSS by assuming IP and TCP headers are required for each segment. This MTU of 104 exceeds that for ZigBee, however out implementation of SXA sockets effectively compresses the IP and TCP headers into a 6-byte header. This gives a real MTU of 64+6 = 70 bytes. This is an acceptable envelope payload size, which will avoid fragmentation.
Thus, whatever this constant is, the real MTU will be 34 bytes less than this, and the TCP MSS will be 40 bytes less.
#define SXA_STREAM_PORT UINT16_C(61616) |
Macro to use for first and last valid TCP port numbers, for both source port and destination port.
This range is selected since port numbers must compress into 8-bit fields.
#define XBEE_DISC_CLIENT_CLUST_ENTRY |
#define XBEE_FRAME_HANDLE_IS_RESPONSE |
Macro for registering a handler to receive I/O samples via both ATIS responses and 0x92 frames received.
Note that the XBEE_FRAME_IO_RESPONSE (0x92) handler is only necessary when ATAO=0. When ATAO is not zero, the 0x92 frames come in as 0x91 frames on the Digi Data Endpoint.
#define XBEE_FRAME_HANDLE_ND_RESPONSE |
Macro for registering a handler to receive node announcements via both ATND responses and 0x95 frames received.
Note that the XBEE_FRAME_NODE_ID (0x95) handler is only necessary when ATAO=0. When ATAO is not zero, the 0x95 frames come in as 0x91 frames on the Digi Data Endpoint.
#define XBEE_IO_CLIENT_CLUST_ENTRY |
typedef uint8_t sxa_cache_flags_t |
Flag data for register value cache status
For this library to work, structure packing must be enabled (accomplished using the XBEE_PACKED macro). This is because the size of the actual data must be derivable from the size of the containing structure, minus the size of the following flags field.
The flags field takes on one of the _SXA_CACHED_OK etc. values.
typedef void(* sxa_cache_upd_fn) (struct sxa_node_t FAR *sxa, const struct sxa_cached_group_t FAR *cgroup) |
Function registered for cache group update post-processing.
[in] | sxa | Relevant SXA. |
[in] | cgroup | Cache group being updated (within sxa) |
typedef { ... } sxa_cached_addr64 |
Cached extended address register value.
< Cache status flags (_SXA_CACHED_OK etc.) Cached value
typedef { ... } sxa_cached_t |
Cached generic register value (no data)
< Cache status flags (_SXA_CACHED_OK etc.)
typedef { ... } sxa_cached_uint16_t |
Cached uint16_t register value.
< Cache status flags (_SXA_CACHED_OK etc.) Cached value
typedef { ... } sxa_cached_uint32_t |
Cached uint32_t register value.
< Cache status flags (_SXA_CACHED_OK etc.) Cached value
typedef { ... } sxa_cached_uint8_t |
Cached uint8_t register value.
< Cache status flags (_SXA_CACHED_OK etc.) Cached value
anonymous enum |
This enum gives numeric identification to all cache groups.
anonymous enum |
int _sxa_disc_atnd_response | ( | xbee_dev_t * | xbee, |
const void FAR * | raw, | ||
uint16_t | length, | ||
void FAR * | context | ||
) |
Frame handler for processing AT Command Response frames.
Should only be called by the frame dispatcher and unit tests.
See the function help for xbee_frame_handler_fn() for full documentation on this function's API.
References _sxa_disc_process_node_data(), FAR, XBEE_AT_RESP_STATUS, and XBEE_AT_RESP_SUCCESS.
int _sxa_disc_cluster_handler | ( | const wpan_envelope_t FAR * | envelope, |
void FAR * | context | ||
) |
Cluster handler for "Digi Node Identification" cluster.
Used in the cluster table of WPAN_ENDPOINT_DIGI_DATA (0xE8) for cluster DIGI_CLUST_NODEID_MESSAGE (0x0095).
[in] | envelope | information about the frame (addresses, endpoint, profile, cluster, etc.) |
[in,out] | context |
0 | handled data |
!0 | some sort of error processing data |
References _sxa_disc_process_node_data().
int _sxa_disc_handle_frame_0x95 | ( | xbee_dev_t * | xbee, |
const void FAR * | raw, | ||
uint16_t | length, | ||
void FAR * | context | ||
) |
Frame handler for processing Node Identification Indicator (0x95) frames.
Should only be called by the frame dispatcher and unit tests.
See the function help for xbee_frame_handler_fn() for full documentation on this function's API.
References _SXA_CACHED_OK, _sxa_disc_process_node_data(), addr64_equal(), sxa_node_t::addr_ptr, wpan_dev_t::address, be32toh, FAR, sxa_node_t::next_local, PRIsFAR, PRIx32, xbee_dev_t::wpan_dev, WPAN_NET_ADDR_UNDEFINED, and xbee_disc_device_type_str().
int _sxa_disc_process_node_data | ( | xbee_dev_t * | xbee, |
const void FAR * | raw, | ||
int | length | ||
) |
Function shared by multiple functions that process Node Identification Messages (0x95 frames and ATND responses).
[in] | xbee | device that received the message |
[in] | raw | pointer to the message |
[in] | length | length of the message |
0 | successfully parsed |
!0 | error parsing data or calling handler() |
References EINVAL, FAR, hex_dump(), HEX_DUMP_FLAG_OFFSET, and xbee_disc_nd_parse().
Referenced by _sxa_disc_atnd_response(), _sxa_disc_cluster_handler(), and _sxa_disc_handle_frame_0x95().
Function shared by multiple functions that process I/O sample messages (0x92 frames and ATIS responses).
[in] | ieee_be | address of node that sent the ATIS response |
[in] | raw | pointer to the message (starting at sample count field) |
[in] | length | length of the message |
0 | successfully parsed |
!0 | error parsing data |
References _SXA_CACHED_BAD_GROUP, _SXA_CACHED_BUSY, _SXA_CACHED_ERROR, _SXA_CACHED_OK, _SXA_CACHED_PENDING, _SXA_CACHED_PREFIX_SIZE, _SXA_CACHED_UNKNOWN, _SXA_MAX_QUEUED, wpan_dev_t::address, _xbee_reg_descr_t::alias, EBUSY, EINVAL, FAR, hex_dump(), HEX_DUMP_FLAG_OFFSET, xbee_node_id_t::ieee_addr_be, sxa_node_t::next, sxa_node_t::next_local, PRIpFAR, _xbee_reg_descr_t::sxa_cache_group, SXA_CACHED_DEVICE_INFO, SXA_CACHED_IO_CONFIG, SXA_CACHED_MISC, SXA_CACHED_NODE_ID, SXA_CACHED_NONE, xbee_dev_t::wpan_dev, wpan_tick(), XBEE_AT_RESP_STATUS, XBEE_AT_RESP_SUCCESS, XBEE_ATCMD_REG_END_CMD, XBEE_ATCMD_REG_SET_8, XBEE_CHECK_TIMEOUT_MS, XBEE_CLT_COPY, XBEE_CLT_COPY_BE, xbee_cmd_init_device(), xbee_cmd_list_execute(), xbee_cmd_query_status(), XBEE_CMD_RESP_MASK_STATUS, xbee_cmd_tick(), xbee_dev_dump_settings(), xbee_dev_tick(), xbee_io_configure(), xbee_io_get_analog_input(), xbee_io_get_digital_input(), xbee_io_get_digital_output(), xbee_io_query_status(), xbee_io_response_dump(), xbee_io_response_parse(), xbee_io_set_digital_output(), xbee_io_set_options(), XBEE_SET_TIMEOUT_MS, and xbee_wpan_init().
const FAR sxa_cached_group_t _sxa_default_cache_groups[] |
const FAR xbee_atcmd_reg_t _sxa_devinfo_query_regs[] |
const FAR xbee_atcmd_reg_t _sxa_dhdl_query_regs[] |
const FAR xbee_atcmd_reg_t _sxa_init_query_regs[] |
const FAR xbee_atcmd_reg_t _sxa_ni_query_regs[] |
const char* _xbee_rci_types[] |
Table to map _xbee_rci_type_t to RCI type string.