Digi XBee(R) ANSI C Host Library
Macros | Typedefs | Functions

Because this framework dispatches received frames to frame handlers, this API layer for sockets makes use of callbacks to pass received data back to the calling code. More...

#include "xbee/platform.h"
#include "xbee/socket_frames.h"
#include "xbee/tx_status.h"

Go to the source code of this file.

Macros

#define XBEE_SOCK_SOCKET_COUNT   10
 Number of sockets to track on the host. More...
 
#define XBEE_SOCK_FRAME_HANDLERS   { 0, 0, xbee_sock_frame_handler, NULL }
 Macro for xbee_frame_handlers table of xbee_dispatch_table_entry_t structs.
 

Typedefs

typedef int xbee_sock_t
 Unique identifier for sockets created in this API layer. More...
 
typedef void(* xbee_sock_notify_fn) (xbee_sock_t socket, uint8_t frame_type, uint8_t message)
 Callback handler for notification of various socket events. More...
 
typedef void(* xbee_sock_receive_fn) (xbee_sock_t socket, uint8_t status, const void *payload, size_t payload_len)
 Callback for data received on sockets created with xbee_sock_connect(). More...
 
typedef void(* xbee_sock_receive_from_fn) (xbee_sock_t socket, uint8_t status, uint32_t remote_addr, uint16_t remote_port, const void *datagram, size_t datagram_len)
 Callback for datagrams received on UDP sockets created with xbee_sock_bind(). More...
 
typedef xbee_sock_receive_fn(* xbee_sock_ipv4_client_fn) (xbee_sock_t listening_socket, xbee_sock_t client_socket, uint32_t remote_addr, uint16_t remote_port)
 Callback for TCP/SSL sockets created with xbee_sock_listen(). More...
 
typedef void(* xbee_sock_option_resp_fn) (xbee_sock_t socket, uint8_t option_id, uint8_t status, const void *data, size_t data_len)
 Callback for responses to Get/Set Option requests sent with xbee_sock_option(). More...
 

Functions

xbee_sock_t xbee_sock_create (xbee_dev_t *xbee, uint8_t protocol, xbee_sock_notify_fn notify_handler)
 Allocate a socket from the local socket table, and send a Socket Create frame to the XBee module to allocate space in its socket table. More...
 
int xbee_sock_connect (xbee_sock_t socket, uint16_t remote_port, uint32_t remote_addr, const char *remote_host, xbee_sock_receive_fn receive_handler)
 Connect a socket created with xbee_sock_create() to a remote host. More...
 
int xbee_sock_bind (xbee_sock_t socket, uint16_t local_port, xbee_sock_receive_from_fn receive_from_handler)
 Bind a UDP socket to a local port to accept datagrams from multiple hosts. More...
 
int xbee_sock_listen (xbee_sock_t socket, uint16_t local_port, xbee_sock_ipv4_client_fn ipv4_client_handler)
 Listen on a local port for inbound TCP/SSL connections from multiple hosts. More...
 
int xbee_sock_send (xbee_sock_t socket, uint8_t tx_options, const void *payload, size_t payload_len)
 Send data on a Connected socket, or an IPv4 Client socket spawned from a Listening socket. More...
 
int xbee_sock_sendto (xbee_sock_t socket, uint8_t tx_options, uint32_t remote_addr, uint16_t remote_port, const void *payload, size_t payload_len)
 Send a datagram on a Bound UDP socket. More...
 
int xbee_sock_option (xbee_sock_t socket, uint8_t option_id, const void *data, size_t data_len, xbee_sock_option_resp_fn callback)
 Get or set a socket option. More...
 
int xbee_sock_reset (xbee_dev_t *xbee)
 Send command to close all open sockets on device xbee, even if they aren't tracked in the local sockets table. More...
 
int xbee_sock_close (xbee_sock_t socket)
 Close and release a socket. More...
 
int xbee_sock_close_all (xbee_dev_t *xbee)
 Close all created sockets for a given XBee device. More...
 
int xbee_sock_frame_handler (xbee_dev_t *xbee, const void FAR *rawframe, uint16_t length, void FAR *context)
 Frame handler for all response frames. More...
 

Detailed Description

Because this framework dispatches received frames to frame handlers, this API layer for sockets makes use of callbacks to pass received data back to the calling code.

Calling code uses xbee_sock_create() to create a new local socket entry and allocate a socket on the XBee module. It also registers a callback for notifications related to that socket. Those notifications include Create, Connect and Bind/Listen status events, delivery status of payloads sent with xbee_sock_send()/xbee_sock_sendto(), and socket state changes.

xbee_sock_create() returns an xbee_sock_t used to identify the socket in all other APIs.

Once created, the caller can attach the socket in three different ways:

API to initiate Callback Prototype Protos Description


xbee_sock_connect xbee_sock_receive_fn All Single destination xbee_sock_bind xbee_sock_receive_from_fn UDP Mult. destinations xbee_sock_listen xbee_sock_ipv4_client_fn TCP/SSL Inbound connections

For use with XBee Cellular firmware versions ending in x15 or later.