Digi XBee(R) ANSI C Host Library
|
This layer wraps the AT request/response frames to provide an easy method for querying/setting registers on, and sending AT commands to the XBee.More...
Files | |
file | atcmd.h |
Sending AT command requests and processing the responses. | |
file | reg_descr.h |
Header for XBee register descriptors. | |
file | scan.h |
Structures for the ATAS (Active Scan) API responses. | |
file | xbee_atcmd.c |
Code related to sending AT command requests and processing the responses. | |
file | xbee_scan.c |
Code related to ATAS (Active Scan) responses. | |
Data Structures | |
union | xbee_at_cmd_t |
Datatype used for passing and storing XBee AT Commands. More... | |
struct | xbee_cmd_response_t |
Structure used to pass AT Command responses to registered callback handlers. More... | |
struct | xbee_cmd_request_t |
This structure is used to keep track of outstanding local and remote AT requests. More... | |
struct | xbee_header_local_at_req_t |
Header for AT Commands sent to the local (serially-attached) XBee. More... | |
struct | xbee_header_remote_at_req_t |
Header to AT Commands sent to a remote XBee on the network. More... | |
union | xbee_header_at_request_t |
Useful typedef to create either a local or remote request frame. More... | |
struct | xbee_header_local_at_resp_t |
XBEE_FRAME_LOCAL_AT_RESPONSE (0x88) More... | |
struct | xbee_header_remote_at_resp_t |
XBEE_FRAME_REMOTE_AT_RESPONSE (0x97) More... | |
struct | xbee_frame_local_at_resp_t |
Response to an AT Command sent to the local serially-connected XBee. More... | |
struct | xbee_frame_remote_at_resp_t |
Response to an AT Command sent to a remote XBee. More... | |
union | xbee_frame_at_response_t |
Useful typedef for casting either a local or remote response frame. More... | |
struct | xbee_command_list_context_t |
Context data passed to command list processor. More... | |
struct | xbee_atcmd_reg_t |
Entry for table of XBee registers to query at startup. More... | |
struct | _xbee_reg_descr_t |
struct | xbee_scan_zigbee_response_t |
union | xbee_scan_response_t |
Macros | |
#define | XBEE_CMD_REQUEST_TABLESIZE 2 |
Maximum number of outstanding requests. More... | |
#define | XBEE_CMD_MAX_PARAM_LENGTH 64 |
Maximum number of bytes in the parameter sent to a command. More... | |
#define | XBEE_CMD_REMOTE_TIMEOUT 180 |
Timeout (in seconds) to wait for a response to a remote command. More... | |
#define | XBEE_CMD_LOCAL_TIMEOUT 2 |
Timeout (in seconds) to wait for a response to a local command. | |
#define | XBEE_CMD_ATEO_INSECURE_JOIN (1<<0) |
#define | XBEE_CMD_ATEO_USE_TRUST_CENTER (1<<1) |
#define | XBEE_CMD_ATEO_USE_HASH_LINK_KEY (1<<2) |
#define | XBEE_CMD_ATEO_USE_AUTHENTICATION (1<<3) |
#define | XBEE_AT_RESP_STATUS(var) ((var) & XBEE_AT_RESP_STATUS_MASK) |
Macro for checking the status byte of an AT response. More... | |
#define | XBEE_ATCMD_REG(c1, c2, type, obj, field) |
Macro used in creating command list tables. More... | |
#define | XBEE_ATCMD_REG_CB(c1, c2, cb, flags) { { { c1, c2 } }, flags, XBEE_CLT_NONE, cb, 0, 0 } |
Macro used in creating command list tables. More... | |
#define | XBEE_ATCMD_REG_MOVE_THEN_CB(c1, c2, type, obj, field, cb, flags) |
Macro used in creating command list tables. More... | |
#define | XBEE_ATCMD_REG_SET_8(c1, c2, value) { { { c1, c2 } }, 0, XBEE_CLT_SET_8, NULL, value, 0 } |
Macro used in creating command list tables. More... | |
#define | XBEE_ATCMD_REG_END { { { '\0', '\0' } } } |
Macro used in creating command list tables. More... | |
#define | XBEE_ATCMD_REG_END_CMD(c1, c2) { { { c1, c2 } }, 0, XBEE_CLT_LAST, NULL, 0, 0 } |
Macro used in creating command list tables. More... | |
#define | XBEE_ATCMD_REG_END_CB(cb, flags) { { { '\0', '\0' } }, flags, XBEE_CLT_NONE, cb, 0, 0 } |
Macro used in creating command list tables. More... | |
#define | XBEE_ATCMD_REG_VALID(ptr) (ptr->command.w != 0) |
Macro used in create command list tables. More... | |
#define | xbee_cmd_list_status(clc) ((clc)->status) |
#define | XBEE_CMD_REQUEST_EMPTY(index) (xbee_cmd_request_table[index].device == NULL) |
Is entry index available (unused)? | |
#define | XBEE_CMD_REQUEST_HANDLE(index) ((index << 8) || xbee_cmd_request_table[index].sequence) |
Return the handle for entry index (combination of index and .sequence member of entry). More... | |
#define | XBEE_FRAME_HANDLE_LOCAL_AT |
#define | XBEE_FRAME_HANDLE_REMOTE_AT { XBEE_FRAME_REMOTE_AT_RESPONSE, 0, _xbee_cmd_handle_response, NULL } |
#define | XBEE_SCAN_TYPE_ZIGBEE 0x01 |
#define | _xbee_atcmd_debug |
#define | XBEE_ATCMD_REG_REFRESH_IDX 7 |
Offset into _xbee_atcmd_query_regs to use when refreshing the xbee_dev_t/ wpan_dev_t structure. More... | |
Typedefs | |
typedef int(* | xbee_cmd_callback_fn) (const xbee_cmd_response_t FAR *response) |
Callback registered to an AT Command with xbee_cmd_set_callback(). More... | |
typedef void(* | xbee_command_list_fn) (const xbee_cmd_response_t FAR *response, const struct xbee_atcmd_reg_t FAR *reg, void FAR *base) |
Callback registered for individual command list commands. More... | |
Enumerations | |
enum | xbee_at_resp_status { XBEE_AT_RESP_STATUS_MASK = 0x0F, XBEE_AT_RESP_SUCCESS = 0x00, XBEE_AT_RESP_ERROR = 0x01, XBEE_AT_RESP_BAD_COMMAND = 0x02, XBEE_AT_RESP_BAD_PARAMETER = 0x03, XBEE_AT_RESP_TX_FAIL = 0x04, XBEE_AT_RESP_NO_SESSION = 0x0B, XBEE_AT_RESP_ENCRYPTION_ERR = 0x0C, XBEE_AT_RESP_TO_BIT_NOT_SET = 0x0D, XBEE_AT_RESP_ATND_RSSI_INVALID = 0x40 } |
Possible values of status byte in xbee_header_local_at_resp_t and xbee_frame_local_at_resp_t. More... | |
enum | xbee_command_list_status { XBEE_COMMAND_LIST_RUNNING = -EBUSY, XBEE_COMMAND_LIST_DONE = 0, XBEE_COMMAND_LIST_TIMEOUT = -ETIMEDOUT, XBEE_COMMAND_LIST_ERROR = -EIO } |
Status codes for xbee_cmd_list_status() More... | |
enum | xbee_command_list_type { XBEE_CLT_NONE, XBEE_CLT_COPY, XBEE_CLT_COPY_PAD_LEFT, XBEE_CLT_COPY_BE, XBEE_CLT_SET, XBEE_CLT_SET_STR, XBEE_CLT_SET_BE, XBEE_CLT_SET_8, XBEE_CLT_LAST } |
enum | _xbee_rci_type_t { XBEE_RCI_TYPE_UINT32, XBEE_RCI_TYPE_HEX32, XBEE_RCI_TYPE_STRING, XBEE_RCI_TYPE_BIN, XBEE_RCI_TYPE_ADDR64 } |
iDigi RCI type names used by do_command type=zigbee. More... | |
Functions | |
int | xbee_cmd_list_execute (xbee_dev_t *xbee, xbee_command_list_context_t FAR *clc, const xbee_atcmd_reg_t FAR *list, void FAR *base, const wpan_address_t FAR *address) |
Execute a list of AT commands. More... | |
enum xbee_command_list_status() | xbee_cmd_list_status (xbee_command_list_context_t FAR *clc) |
Determine status of command list execution. More... | |
int | xbee_cmd_tick (void) |
This function should be called periodically (at least every few seconds) to expire old entries from the AT Command Request table. More... | |
xbee_cmd_request_t FAR * | _xbee_cmd_handle_to_address (int16_t handle) |
int | xbee_cmd_init_device (xbee_dev_t *xbee) |
Initialize the AT Command layer for an XBee device. More... | |
int | xbee_cmd_query_device (xbee_dev_t *xbee, uint_fast8_t refresh) |
Learn about the underlying device by sending a series of commands and storing the results in the xbee_dev_t. More... | |
int | xbee_cmd_query_status (xbee_dev_t *xbee) |
Check the status of querying an XBee device, as initiated by xbee_cmd_query_device(). More... | |
int16_t | xbee_cmd_create (xbee_dev_t *xbee, const char FAR command[3]) |
Allocate an AT Command request. More... | |
int | _xbee_cmd_release_request (xbee_cmd_request_t FAR *request) |
Release an entry from the request table by marking it as available. More... | |
int | xbee_cmd_release_handle (int16_t handle) |
Release an entry from the request table by marking it as available. More... | |
int | xbee_cmd_set_command (int16_t handle, const char FAR command[3]) |
Change the command associated with a request. More... | |
int | xbee_cmd_set_callback (int16_t handle, xbee_cmd_callback_fn callback, void FAR *context) |
Associate a callback with a given AT Command request. More... | |
int | xbee_cmd_set_target (int16_t handle, const addr64 FAR *ieee, uint16_t network_address) |
Associate a remote XBee device with a given AT Command request. More... | |
int | xbee_cmd_set_flags (int16_t handle, uint16_t flags) |
Set the flags for a given AT Command request. More... | |
int | xbee_cmd_clear_flags (int16_t handle, uint16_t flags) |
Clear the flags for a given AT Command request. More... | |
int | xbee_cmd_set_param (int16_t handle, uint32_t value) |
Set the parameter (up to 32-bits) for a given AT Command request. More... | |
int | xbee_cmd_set_param_bytes (int16_t handle, const void FAR *data, uint8_t length) |
Set the parameter for a given AT Command request to a sequence of bytes. More... | |
int | xbee_cmd_set_param_str (int16_t handle, const char FAR *str) |
Set a string parameter for a given AT Command request (e.g., the "NI" node identifier command). More... | |
int | xbee_cmd_send (int16_t handle) |
Send an AT Command to a local or remote XBee device. More... | |
int | xbee_cmd_simple (xbee_dev_t *xbee, const char FAR command[3], uint32_t value) |
Simple interface for sending a command with a parameter to the local XBee without checking for a response. More... | |
int | xbee_cmd_execute (xbee_dev_t *xbee, const char FAR command[3], const void FAR *data, uint8_t length) |
Simple interface for sending a command with an optional parameter to the local XBee without checking for a response. More... | |
int | _xbee_cmd_handle_response (xbee_dev_t *xbee, const void FAR *rawframe, uint16_t length, void FAR *context) |
Callback handler registered for frame types XBEE_FRAME_LOCAL_AT_RESPONSE (0x88) and XBEE_FRAME_REMOTE_AT_RESPONSE (0x97). More... | |
int | _xbee_cmd_modem_status (xbee_dev_t *xbee, const void FAR *payload, uint16_t length, void FAR *context) |
Receive modem status frames and update our network address (and payload size) on state changes. More... | |
int | xbee_scan_dump_response (xbee_dev_t *xbee, const void FAR *raw, uint16_t length, void FAR *context) |
int | _xbee_cmd_issue_list (xbee_dev_t *xbee, xbee_command_list_context_t FAR *clc, const xbee_cmd_response_t FAR *response) |
int | _xbee_cmd_list_callback (const xbee_cmd_response_t FAR *response) |
void | _xbee_cmd_query_handle_eo (const xbee_cmd_response_t FAR *response, const struct xbee_atcmd_reg_t FAR *reg, void FAR *base) |
void | _xbee_cmd_query_handle_ai (const xbee_cmd_response_t FAR *response, const struct xbee_atcmd_reg_t FAR *reg, void FAR *base) |
void | _xbee_cmd_query_handle_end (const xbee_cmd_response_t FAR *response, const struct xbee_atcmd_reg_t FAR *reg, void FAR *base) |
uint8_t | _xbee_cmd_encode_param (void FAR *buffer, uint32_t value) |
Store an unsigned integer in 1, 2 or 4 bytes as a parameter to an AT command. More... | |
void | xbee_identify (xbee_dev_t *xbee, bool_t identify) |
Programs with the ZCL Identify Server Cluster can call this function in their main loop to have the XBee module's association LED flash fast (100ms cycle) when in Identify Mode. More... | |
Variables | |
FAR xbee_cmd_request_t | xbee_cmd_request_table [XBEE_CMD_REQUEST_TABLESIZE] |
Table used to keep track of outstanding requests. | |
const char * | _xbee_rci_types [] |
Table to map _xbee_rci_type_t to RCI type string. | |
const FAR _xbee_reg_descr_t | _xbee_reg_table [] |
FAR xbee_cmd_request_t | xbee_cmd_request_table [XBEE_CMD_REQUEST_TABLESIZE] |
Table used to keep track of outstanding requests. | |
const xbee_atcmd_reg_t | _xbee_atcmd_query_regs [] |
xbee_command_list_context_t | _xbee_atcmd_query_regs_head |
Return values for xbee_cmd_callback_fn() functions. | |
#define | XBEE_ATCMD_DONE 0 |
Returned by an xbee_cmd_callback_fn() if the handle can be released. | |
#define | XBEE_ATCMD_REUSE 1 |
Returned by an xbee_cmd_callback_fn() if more reponses are expected, or it has re-used the command handle. More... | |
XBEE_REMOTE_AT_OPT_* | |
#define | XBEE_REMOTE_AT_OPT_QUEUE (0) |
Queue changes until ATAC command or another request with XBEE_REMOTE_AT_OPT_IMMEDIATE set. More... | |
#define | XBEE_REMOTE_AT_OPT_IMMEDIATE (1<<1) |
Apply changes immediately, don't wait for ATAC command. | |
#define | XBEE_REMOTE_AT_OPT_SECURE (1<<4) |
Send securely (requires Secure Session to target). | |
This layer wraps the AT request/response frames to provide an easy method for querying/setting registers on, and sending AT commands to the XBee.
#define XBEE_AT_RESP_STATUS | ( | var | ) | ((var) & XBEE_AT_RESP_STATUS_MASK) |
Macro for checking the status byte of an AT response.
If this library is compiled without DigiMesh support, we can use a simpler test.
Referenced by _sxa_disc_atnd_response(), _sxa_io_process_response(), and xbee_disc_atnd_response_handler().
#define XBEE_ATCMD_REG | ( | c1, | |
c2, | |||
type, | |||
obj, | |||
field | |||
) |
Macro used in creating command list tables.
This macro does not set a callback.
[in] | c1 | first character of AT command |
[in] | c2 | second character of AT command |
[in] | type | one of xbee_command_list_type enumerated values: XBEE_CLT_NONE - no action except to issue the command. 'obj' and 'field' parameters are ignored. XBEE_CLT_COPY - copy response data directly, followed by 0x00 to fill the target element XBEE_CLT_COPY_PAD_LEFT - copy response data directly, padding to the left with 0x00 to fill target element XBEE_CLT_COPY_BE - copy numeric data to host byte order XBEE_CLT_SET - set command parameter directly XBEE_CLT_SET_STR - set command parameter as null- terminated string. XBEE_CLT_SET_BE - set numeric command parameter |
[in] | obj | typedef name of object at base address |
[in] | field | field in obj in which to store result |
#define XBEE_ATCMD_REG_CB | ( | c1, | |
c2, | |||
cb, | |||
flags | |||
) | { { { c1, c2 } }, flags, XBEE_CLT_NONE, cb, 0, 0 } |
Macro used in creating command list tables.
[in] | c1 | first character of AT command |
[in] | c2 | second character of AT command |
[in] | cb | callback function (prototype xbee_command_list_fn) |
[in] | flags | 8-bit flags for callback (arbitrary). |
#define XBEE_ATCMD_REG_END { { { '\0', '\0' } } } |
Macro used in creating command list tables.
Used to terminate table, with no special final callback. This must be the last entry if used, or XBEE_ATCMD_REG_END_CB must be used.
#define XBEE_ATCMD_REG_END_CB | ( | cb, | |
flags | |||
) | { { { '\0', '\0' } }, flags, XBEE_CLT_NONE, cb, 0, 0 } |
Macro used in creating command list tables.
Used to terminate table, with a final callback. This must be the last entry if used, or XBEE_ATCMD_REG_END must be used.
[in] | cb | callback function (prototype xbee_command_list_fn). |
[in] | flags | 8-bit flags for callback (arbitrary). |
#define XBEE_ATCMD_REG_END_CMD | ( | c1, | |
c2 | |||
) | { { { c1, c2 } }, 0, XBEE_CLT_LAST, NULL, 0, 0 } |
Macro used in creating command list tables.
Used to terminate table, with a command (usually ND or WR). This must be the last entry if used.
Referenced by _sxa_io_process_response().
#define XBEE_ATCMD_REG_MOVE_THEN_CB | ( | c1, | |
c2, | |||
type, | |||
obj, | |||
field, | |||
cb, | |||
flags | |||
) |
Macro used in creating command list tables.
This is a combination of XBEE_ATCMD_REG (moving data automatically) and XBEE_ATCMD_REG_CB (calling a callback function). The callback function is invoked after the data move.
[in] | c1 | first character of AT command |
[in] | c2 | second character of AT command |
[in] | type | one of xbee_command_list_type enumerated values: XBEE_CLT_NONE - no action except to issue the command. 'obj' and 'field' parameters are ignored. XBEE_CLT_COPY - copy response data directly, followed by 0x00 to fill the target element XBEE_CLT_COPY_PAD_LEFT - copy response data directly, padding to the left with 0x00 to fill target element XBEE_CLT_COPY_BE - copy numeric data to host byte order XBEE_CLT_SET - set command parameter directly XBEE_CLT_SET_STR - set command parameter as null- terminated string. XBEE_CLT_SET_BE - set numeric command parameter |
[in] | obj | typedef name of object at base address |
[in] | field | field in obj in which to store result |
[in] | cb | callback function (prototype xbee_command_list_fn) |
[in] | flags | 8-bit flags for callback (arbitrary). |
#define XBEE_ATCMD_REG_REFRESH_IDX 7 |
Offset into _xbee_atcmd_query_regs to use when refreshing the xbee_dev_t/ wpan_dev_t structure.
Referenced by xbee_cmd_query_device().
#define XBEE_ATCMD_REG_SET_8 | ( | c1, | |
c2, | |||
value | |||
) | { { { c1, c2 } }, 0, XBEE_CLT_SET_8, NULL, value, 0 } |
Macro used in creating command list tables.
This macro does not set a callback.
[in] | c1 | first character of AT command |
[in] | c2 | second character of AT command |
[in] | value | unsigned 8-bit value (compile-time constant) to set. |
Referenced by _sxa_io_process_response().
#define XBEE_ATCMD_REG_VALID | ( | ptr | ) | (ptr->command.w != 0) |
Macro used in create command list tables.
Used to identify the last entry in the table (inserted with XBEE_ATCMD_REG_END_CB()).
Referenced by _xbee_cmd_list_callback().
#define XBEE_ATCMD_REUSE 1 |
Returned by an xbee_cmd_callback_fn() if more reponses are expected, or it has re-used the command handle.
Referenced by _xbee_cmd_handle_response(), _xbee_cmd_list_callback(), and xbee_cmd_tick().
#define XBEE_CMD_MAX_PARAM_LENGTH 64 |
Maximum number of bytes in the parameter sent to a command.
Platforms can override this when limiting to AT commands with shorter parameters (e.g., 16 bytes when not using the certificate parameters).
Referenced by xbee_cmd_set_param_bytes(), and xbee_cmd_set_param_str().
#define XBEE_CMD_REMOTE_TIMEOUT 180 |
Timeout (in seconds) to wait for a response to a remote command.
Set to a high value to allow for a sleeping end device.
Referenced by xbee_cmd_send().
#define XBEE_CMD_REQUEST_HANDLE | ( | index | ) | ((index << 8) || xbee_cmd_request_table[index].sequence) |
Return the handle for entry index (combination of index and .sequence member of entry).
#define XBEE_CMD_REQUEST_TABLESIZE 2 |
Maximum number of outstanding requests.
Two should be sufficient in most (all?) cases. One might even be enough if space is tight.
Referenced by _xbee_cmd_handle_response(), _xbee_cmd_handle_to_address(), xbee_cmd_create(), and xbee_cmd_tick().
#define XBEE_FRAME_HANDLE_LOCAL_AT |
#define XBEE_REMOTE_AT_OPT_QUEUE (0) |
Queue changes until ATAC command or another request with XBEE_REMOTE_AT_OPT_IMMEDIATE set.
Referenced by xbee_cmd_send().
typedef int(* xbee_cmd_callback_fn) (const xbee_cmd_response_t FAR *response) |
Callback registered to an AT Command with xbee_cmd_set_callback().
It should not modify the contents of the xbee_cmd_response_t structure passed to it. It should return either XBEE_ATCMD_DONE or XBEE_ATCMD_REUSE.
View the help on xbee_cmd_response_t for details on the members of that structure.
[in] | response | response received for AT Command |
XBEE_ATCMD_DONE | done with the request handle |
XBEE_ATCMD_REUSE | more responses are expected, or the request handle will be reused |
typedef void(* xbee_command_list_fn) (const xbee_cmd_response_t FAR *response, const struct xbee_atcmd_reg_t FAR *reg, void FAR *base) |
Callback registered for individual command list commands.
[in] | response | response received for AT Command. From this, the context field points to the start of the entire set of commands in the list being processed. |
[in] | reg | Table element for this command. Usually, the callback will dereference reg->context to find any required auxiliary data for processing this command. |
[in,out] | base | Base address of structure to populate with response value (typical use). |
enum _xbee_rci_type_t |
iDigi RCI type names used by do_command type=zigbee.
This table is used so as to avoid having XBEE_RCI_TYPE_STRING pointers in the register descriptor table.
enum xbee_at_resp_status |
Possible values of status
byte in xbee_header_local_at_resp_t and xbee_frame_local_at_resp_t.
Status codes for xbee_cmd_list_status()
We force these to be -Exxx codes (or 0).
Enumerator | |
---|---|
XBEE_CLT_NONE |
No default action. Often used for callbacks. |
XBEE_CLT_COPY |
Copy response data byte-for-byte to base struct, starting at offset 0 and setting remaining bytes to 0x00. |
XBEE_CLT_COPY_PAD_LEFT |
Copy response data byte-for-byte to base struct,. padding with 0x00 bytes before the copied data, to have last copied byte in last position of base struct. (see ATSH/ATSL). |
XBEE_CLT_COPY_BE |
Copy response, changing expected big-endian to host byte order, and store in base struct. Data must be 1, 2 or 4 bytes, assumed unsigned. |
XBEE_CLT_SET |
Use data in base struct as parameter for command, with binary data copied byte-for-byte. |
XBEE_CLT_SET_STR |
Use data in base struct as parameter for command, with null-terminated string data copied byte-for-byte. |
XBEE_CLT_SET_BE |
Use data in base struct as parameter for command, changing host byte order to big-endian. Data must be 1,2 or 4 bytes, assumed unsigned. |
XBEE_CLT_SET_8 |
Set value to immediate 8-bit constant in .bytes field of the xbee_atcmd_reg_t entry. No response. |
XBEE_CLT_LAST |
Last command, any response is discarded, no further command list entries are processed. This is useful if ND is the last command, since the command list will terminate, but discovered nodes will be handled subsequently (asynchronously). |
Store an unsigned integer in 1, 2 or 4 bytes as a parameter to an AT command.
[in] | buffer | buffer to store value |
[in] | value | value to store |
References FAR, htobe16, and htobe32.
Referenced by xbee_cmd_set_param(), xbee_cmd_set_target(), and xbee_cmd_simple().
int _xbee_cmd_handle_response | ( | xbee_dev_t * | xbee, |
const void FAR * | rawframe, | ||
uint16_t | length, | ||
void FAR * | context | ||
) |
Callback handler registered for frame types XBEE_FRAME_LOCAL_AT_RESPONSE (0x88) and XBEE_FRAME_REMOTE_AT_RESPONSE (0x97).
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 _xbee_cmd_release_request(), be16toh, be32toh, xbee_cmd_response_t::command, xbee_cmd_response_t::context, xbee_cmd_response_t::device, EINVAL, FAR, xbee_cmd_response_t::flags, xbee_dev_t::frame_id, xbee_cmd_response_t::handle, PRIpFAR, xbee_cmd_response_t::source, xbee_cmd_response_t::value, xbee_cmd_response_t::value_bytes, xbee_cmd_response_t::value_length, XBEE_ATCMD_REUSE, XBEE_CMD_FLAG_REMOTE, xbee_cmd_request_table, XBEE_CMD_REQUEST_TABLESIZE, XBEE_FRAME_LOCAL_AT_RESPONSE, XBEE_FRAME_REMOTE_AT_RESPONSE, XBEE_SET_TIMEOUT_SEC, and XBEE_UNUSED_PARAMETER.
xbee_cmd_request_t FAR * _xbee_cmd_handle_to_address | ( | int16_t | handle | ) |
Convert a handle (16-bit int) to a pointer into the command request table. Ensures that the handle is valid (correct index and sequence bytes).
[in] | handle | Handle returned from xbee_cmd_create(). |
References FAR, xbee_cmd_request_table, and XBEE_CMD_REQUEST_TABLESIZE.
Referenced by xbee_cmd_clear_flags(), xbee_cmd_release_handle(), xbee_cmd_send(), xbee_cmd_set_callback(), xbee_cmd_set_command(), xbee_cmd_set_flags(), xbee_cmd_set_param(), xbee_cmd_set_param_bytes(), xbee_cmd_set_target(), and xbee_cmd_tick().
int _xbee_cmd_issue_list | ( | xbee_dev_t * | xbee, |
xbee_command_list_context_t FAR * | clc, | ||
const xbee_cmd_response_t FAR * | response | ||
) |
Helper function to send off the next command in the list.
References FAR, XBEE_CLT_SET, XBEE_CLT_SET_8, XBEE_CLT_SET_BE, XBEE_CLT_SET_STR, xbee_cmd_create(), xbee_cmd_set_command(), xbee_cmd_set_param(), xbee_cmd_set_param_bytes(), and xbee_cmd_set_param_str().
Referenced by _xbee_cmd_list_callback(), and xbee_cmd_list_execute().
int _xbee_cmd_list_callback | ( | const xbee_cmd_response_t FAR * | response | ) |
Callback used by xbee_cmd_query_device (and possibly other functions) to learn about the attached XBee device (hardware/firmware version, address, etc.)
View function help for xbee_cmd_set_callback() for details on xbee_cmd_response_t structure.
This callback should only be called by xbee_cmd_handle_response(). ***
References _xbee_cmd_issue_list(), FAR, PRIsFAR, PRIX32, XBEE_AT_RESP_SUCCESS, XBEE_ATCMD_DONE, XBEE_ATCMD_REG_VALID, XBEE_ATCMD_REUSE, XBEE_CLT_COPY, XBEE_CLT_COPY_BE, XBEE_CLT_COPY_PAD_LEFT, XBEE_CLT_LAST, xbee_cmd_release_handle(), XBEE_CMD_RESP_FLAG_TIMEOUT, XBEE_CMD_RESP_MASK_STATUS, and xbee_cmd_send().
Referenced by xbee_cmd_list_execute().
int _xbee_cmd_modem_status | ( | xbee_dev_t * | xbee, |
const void FAR * | payload, | ||
uint16_t | length, | ||
void FAR * | context | ||
) |
Receive modem status frames and update our network address (and payload size) on state changes.
References EINVAL, FAR, xbee_dev_t::flags, xbee_cmd_query_device(), XBEE_MODEM_STATUS_COORD_START, XBEE_MODEM_STATUS_JOINED, XBEE_MODEM_STATUS_KEY_ESTABLISHED, and XBEE_UNUSED_PARAMETER.
int _xbee_cmd_release_request | ( | xbee_cmd_request_t FAR * | request | ) |
Release an entry from the request table by marking it as available.
For internal driver use only – userspace code should use xbee_cmd_release_handle() instead.
[in] | request | Address of the table entry. |
0 | request freed |
-EINVAL | address (request) is not valid |
References EINVAL.
Referenced by _xbee_cmd_handle_response(), xbee_cmd_release_handle(), xbee_cmd_send(), and xbee_cmd_tick().
Clear the flags for a given AT Command request.
[in] | handle | Handle to the request, as returned by xbee_cmd_create(). |
[in] | flags | One or more of the following:
|
0 | flags cleared |
-EINVAL | handle is not valid |
References _xbee_cmd_handle_to_address(), EINVAL, FAR, and XBEE_CMD_FLAG_USER_MASK.
int16_t xbee_cmd_create | ( | xbee_dev_t * | xbee, |
const char FAR | command[3] | ||
) |
Allocate an AT Command request.
[in] | xbee | XBee device to use as the target (local) or to send through (remote). This function will automatically call xbee_cmd_init() if it hasn't already been called for this device. |
[in] | command | Two-letter AT Command to send (e.g., "VR", "NI", etc.). |
>0 | a "handle" to a request that can be built up and sent to a local (serially-attached) or remote XBee module. |
-ENOSPC | the AT command table is full (increase the compile-time macro XBEE_CMD_REQUEST_TABLESIZE) |
-EINVAL | an invalid parameter was passed to the function |
References EINVAL, ENOSPC, FAR, xbee_dev_t::flags, xbee_cmd_init_device(), xbee_cmd_request_table, XBEE_CMD_REQUEST_TABLESIZE, xbee_cmd_tick(), XBEE_DEV_FLAG_CMD_INIT, and XBEE_SET_TIMEOUT_SEC.
Referenced by _xbee_cmd_issue_list(), xbee_io_configure(), xbee_io_set_digital_output(), and xbee_io_set_options().
int xbee_cmd_execute | ( | xbee_dev_t * | xbee, |
const char FAR | command[3], | ||
const void FAR * | data, | ||
uint8_t | length | ||
) |
Simple interface for sending a command with an optional parameter to the local XBee without checking for a response.
For an asynchronous method of sending AT commands and getting the response, see xbee_cmd_create, the xbee_cmd_set_* functions and xbee_cmd_send.
[in] | xbee | XBee device to use as the target. |
[in] | command | Two-letter AT Command to send (e.g., "ID", "CH", etc.). |
[in] | data | Optional big-endian (MSB-first) value to assign to command. Use NULL if command doesn't take a parameter. |
[in] | length | Number of bytes in data; ignored if data is NULL. |
0 | command sent |
-EINVAL | an invalid parameter was passed to the function |
-EBUSY | transmit serial buffer is full, or XBee is not accepting serial data (deasserting /CTS signal). |
References XBEE_FRAME_LOCAL_AT_CMD, xbee_frame_write(), and xbee_next_frame_id().
Referenced by xbee_disc_discover_nodes().
int xbee_cmd_init_device | ( | xbee_dev_t * | xbee | ) |
Initialize the AT Command layer for an XBee device.
You need to call this function before any of the other xbee_cmd_* functions.
[in] | xbee | XBee device on which to enable the AT Command layer. This function will automatically call xbee_cmd_query_device if it hasn't already been called for this device. |
0 | the XBee device was successfully configured to send and receive AT commands |
-EINVAL | an invalid parameter was passed to the function |
References addr64_format(), ADDR64_STRING_LENGTH, wpan_dev_t::address, CAST_FAR_TO_NEAR, EINVAL, FAR, xbee_dev_t::firmware_version, xbee_dev_t::flags, xbee_dev_t::hardware_version, PRIsFAR, PRIu32, PRIx16, PRIx32, xbee_dev_t::wpan_dev, WPAN_DEV_IS_JOINED, WPAN_FLAG_AUTHENTICATED, WPAN_FLAG_AUTHENTICATION_ENABLED, WPAN_FLAG_JOINED, WPAN_NET_ADDR_UNDEFINED, XBEE_AT_RESP_SUCCESS, xbee_cmd_query_device(), XBEE_CMD_RESP_FLAG_TIMEOUT, XBEE_CMD_RESP_MASK_STATUS, XBEE_DEV_FLAG_CMD_INIT, XBEE_DEV_FLAG_QUERY_BEGIN, XBEE_DEV_FLAG_QUERY_DONE, XBEE_DEV_FLAG_QUERY_ERROR, XBEE_DEV_FLAG_QUERY_INPROGRESS, XBEE_DEV_FLAG_QUERY_REFRESH, and XBEE_UNUSED_PARAMETER.
Referenced by _sxa_io_process_response(), and xbee_cmd_create().
int xbee_cmd_list_execute | ( | xbee_dev_t * | xbee, |
xbee_command_list_context_t FAR * | clc, | ||
const xbee_atcmd_reg_t FAR * | list, | ||
void FAR * | base, | ||
const wpan_address_t FAR * | address | ||
) |
Execute a list of AT commands.
[in,out] | xbee | Device to execute commands |
[out] | clc | List head to set up. This must be static since callback functions access it asynchronously. |
[in] | list | First entry of list of commands to execute. The list must be terminated by either XBEE_ATCMD_REG_END or XBEE_ATCMD_REG_END_CB. List entries are created using XBEE_ATCMD_REG macros etc. |
[in] | base | Base address of a structure to fill in with command results or as a source of values to set. |
[in] | address | Remote address, or NULL if local device. |
0 | started sending commands from the list |
-ENOSPC | the AT command table is full (increase the compile-time macro XBEE_CMD_REQUEST_TABLESIZE) |
-EINVAL | an invalid parameter was passed to the function |
References _xbee_cmd_issue_list(), _xbee_cmd_list_callback(), xbee_cmd_send(), xbee_cmd_set_callback(), and xbee_cmd_set_target().
Referenced by _sxa_io_process_response(), and xbee_cmd_query_device().
enum xbee_command_list_status() xbee_cmd_list_status | ( | xbee_command_list_context_t FAR * | clc | ) |
Determine status of command list execution.
[in] | clc | List head passed to xbee_cmd_list_execute(). |
XBEE_COMMAND_LIST_RUNNING | currently executing commands |
XBEE_COMMAND_LIST_DONE | successfully completed |
XBEE_COMMAND_LIST_TIMEOUT | timed out |
XBEE_COMMAND_LIST_ERROR | completed with error(s) |
Referenced by xbee_cmd_query_status(), and xbee_io_query_status().
int xbee_cmd_query_device | ( | xbee_dev_t * | xbee, |
uint_fast8_t | refresh | ||
) |
Learn about the underlying device by sending a series of commands and storing the results in the xbee_dev_t.
This function will likely get called by the XBee stack at some point in the startup/initialization phase.
Use xbee_cmd_query_status() to check on the progress of querying the device.
[in,out] | xbee | XBee device to query. |
[in] | refresh | if non-zero, just refresh the volatile values (e.g., network settings, as opposed to device serial number) |
0 | Started querying device. |
-EBUSY | Transmit serial buffer is full, or XBee is not accepting serial data (deasserting /CTS signal). |
References EINVAL, xbee_dev_t::flags, XBEE_ATCMD_REG_REFRESH_IDX, xbee_cmd_list_execute(), XBEE_DEV_FLAG_QUERY_BEGIN, XBEE_DEV_FLAG_QUERY_DONE, XBEE_DEV_FLAG_QUERY_ERROR, XBEE_DEV_FLAG_QUERY_INPROGRESS, and XBEE_DEV_FLAG_QUERY_REFRESH.
Referenced by _xbee_cmd_modem_status(), xbee_cmd_init_device(), and xbee_cmd_tick().
int xbee_cmd_query_status | ( | xbee_dev_t * | xbee | ) |
Check the status of querying an XBee device, as initiated by xbee_cmd_query_device().
[in] | xbee | device to check |
0 | query completed |
-EINVAL | xbee is NULL |
-EBUSY | query underway |
-ETIMEDOUT | query timed out |
-EIO | halted, but query may not have completed (unexpected response) |
References EINVAL, xbee_cmd_list_status(), and xbee_cmd_tick().
Referenced by _sxa_io_process_response().
int xbee_cmd_release_handle | ( | int16_t | handle | ) |
Release an entry from the request table by marking it as available.
[in] | handle | handle to the request (as returned by xbee_cmd_create) |
0 | request freed |
-EINVAL | handle is not valid |
References _xbee_cmd_handle_to_address(), and _xbee_cmd_release_request().
Referenced by _xbee_cmd_list_callback().
int xbee_cmd_send | ( | int16_t | handle | ) |
Send an AT Command to a local or remote XBee device.
[in] | handle | Handle to the request, as returned by xbee_cmd_create(). |
0 | frame sent |
-EINVAL | handle is not valid |
-EBUSY | transmit serial buffer is full, or XBee is not accepting serial data (deasserting /CTS signal). |
References _xbee_cmd_handle_to_address(), _xbee_cmd_release_request(), EINVAL, FAR, xbee_header_at_request_t::frame_type, hex_dump(), HEX_DUMP_FLAG_TAB, htobe16, xbee_header_at_request_t::local, xbee_header_at_request_t::remote, XBEE_CMD_FLAG_QUEUE_CHANGE, XBEE_CMD_FLAG_REMOTE, XBEE_CMD_FLAG_REUSE_HANDLE, XBEE_CMD_LOCAL_TIMEOUT, XBEE_CMD_REMOTE_TIMEOUT, XBEE_FRAME_LOCAL_AT_CMD, XBEE_FRAME_LOCAL_AT_CMD_Q, XBEE_FRAME_REMOTE_AT_CMD, xbee_frame_write(), xbee_next_frame_id(), XBEE_REMOTE_AT_OPT_IMMEDIATE, XBEE_REMOTE_AT_OPT_QUEUE, and XBEE_SET_TIMEOUT_SEC.
Referenced by _xbee_cmd_list_callback(), xbee_cmd_list_execute(), xbee_io_configure(), xbee_io_set_digital_output(), and xbee_io_set_options().
int xbee_cmd_set_callback | ( | int16_t | handle, |
xbee_cmd_callback_fn | callback, | ||
void FAR * | context | ||
) |
Associate a callback with a given AT Command request.
[in] | handle | Handle to the request, as returned by xbee_cmd_create(). |
[in] | callback | Callback function to receive the AT Command response. This function should take a single parameter (pointer to an xbee_cmd_response_t) and return either XBEE_ATCMD_DONE (if done with the request handle) or XBEE_ATCMD_REUSE (if more responses are expected, or the request handle is going to be reused). |
[in] | context | Context (or "userdata") value to pass to the callback along with the AT Command response when it arrives. Should be set to NULL if not used. |
0 | callback set |
-EINVAL | handle is not valid |
References _xbee_cmd_handle_to_address(), EINVAL, and FAR.
Referenced by xbee_cmd_list_execute().
Change the command associated with a request.
[in] | handle | handle to the request, as returned by xbee_cmd_create() |
[in] | command | two-letter AT Command to send (e.g., "VR", "NI", etc.) |
0 | command changed |
-EINVAL | handle is not valid |
References _xbee_cmd_handle_to_address(), EINVAL, and FAR.
Referenced by _xbee_cmd_issue_list().
Set the flags for a given AT Command request.
[in] | handle | Handle to the request, as returned by xbee_cmd_create(). |
[in] | flags | One or more of the following:
|
0 | flags set |
-EINVAL | handle is not valid |
References _xbee_cmd_handle_to_address(), EINVAL, FAR, and XBEE_CMD_FLAG_USER_MASK.
Set the parameter (up to 32-bits) for a given AT Command request.
[in] | handle | Handle to the request, as returned by xbee_cmd_create(). |
[in] | value | Value to use as the parameter to the AT Command. For negative values, or values > 0xFFFFFFFF, use xbee_cmd_set_param_bytes(). For string parameters (e.g., for the "NI" command), use xbee_cmd_set_param_str(). |
0 | parameter set |
-EINVAL | handle is not valid |
References _xbee_cmd_encode_param(), _xbee_cmd_handle_to_address(), EINVAL, and FAR.
Referenced by _xbee_cmd_issue_list(), xbee_io_configure(), xbee_io_set_digital_output(), and xbee_io_set_options().
Set the parameter for a given AT Command request to a sequence of bytes.
[in] | handle | Handle to the request, as returned by xbee_cmd_create(). |
[in] | data | Pointer to bytes (MSB-first) to copy into request. |
[in] | length | Number of bytes to copy. 0 < length <= XBEE_CMD_MAX_PARAM_LENGTH |
0 | parameter set |
-EINVAL | handle or length is not valid |
-EMSGSIZE | length is greater than XBEE_CMD_MAX_PARAM_LENGTH |
References _xbee_cmd_handle_to_address(), EINVAL, EMSGSIZE, FAR, and XBEE_CMD_MAX_PARAM_LENGTH.
Referenced by _xbee_cmd_issue_list(), and xbee_cmd_set_param_str().
Set a string parameter for a given AT Command request (e.g., the "NI" node identifier command).
[in] | handle | Handle to the request, as returned by xbee_cmd_create(). |
[in] | str | String to use as the parameter. Must be less than XBEE_CMD_MAX_PARAM_LENGTH characters long. |
0 | parameter set |
-EINVAL | handle is not valid |
-EMSGSIZE | str is more than XBEE_CMD_MAX_PARAM_LENGTH characters. |
References EMSGSIZE, XBEE_CMD_MAX_PARAM_LENGTH, and xbee_cmd_set_param_bytes().
Referenced by _xbee_cmd_issue_list().
Associate a remote XBee device with a given AT Command request.
By default, xbee_cmd_create() configures the request as a local AT Command for the serially-attached XBee module. Use this function to send the command to a remote device.
[in] | handle | Handle to the request, as returned by xbee_cmd_create(). |
[in] | ieee | Pointer to 64-bit IEEE hardware address of target, or NULL to switch back to the local XBee device.
|
[in] | network_address | 16-bit network address of target.
|
0 | target set |
-EINVAL | handle is not valid |
-ENOSYS | function not implemented (XBEE_CMD_DISABLE_REMOTE defined) |
References _xbee_cmd_encode_param(), _xbee_cmd_handle_to_address(), EINVAL, ENOSYS, FAR, and XBEE_CMD_FLAG_REMOTE.
Referenced by xbee_cmd_list_execute(), xbee_io_configure(), xbee_io_set_digital_output(), and xbee_io_set_options().
int xbee_cmd_simple | ( | xbee_dev_t * | xbee, |
const char FAR | command[3], | ||
uint32_t | value | ||
) |
Simple interface for sending a command with a parameter to the local XBee without checking for a response.
[in] | xbee | XBee device to use as the target. |
[in] | command | Two-letter AT Command to send (e.g., "ID", "CH", etc.). |
[in] | value | Value to use as the parameter to the AT Command. |
0 | command sent |
-EINVAL | an invalid parameter was passed to the function |
-EBUSY | transmit serial buffer is full, or XBee is not accepting serial data (deasserting /CTS signal). |
References _xbee_cmd_encode_param(), PRIu32, PRIx32, XBEE_FRAME_LOCAL_AT_CMD, and xbee_frame_write().
Referenced by xbee_identify().
int xbee_cmd_tick | ( | void | ) |
This function should be called periodically (at least every few seconds) to expire old entries from the AT Command Request table.
References _xbee_cmd_handle_to_address(), _xbee_cmd_release_request(), xbee_cmd_response_t::command, xbee_cmd_response_t::context, xbee_cmd_response_t::device, FAR, xbee_cmd_response_t::flags, xbee_dev_t::flags, xbee_cmd_response_t::handle, PRIpFAR, XBEE_ATCMD_DONE, XBEE_ATCMD_REUSE, XBEE_CHECK_TIMEOUT_SEC, xbee_cmd_query_device(), xbee_cmd_request_table, XBEE_CMD_REQUEST_TABLESIZE, XBEE_CMD_RESP_FLAG_TIMEOUT, XBEE_CMD_RESP_MASK_STATUS, and XBEE_DEV_FLAG_QUERY_REFRESH.
Referenced by _sxa_io_process_response(), xbee_cmd_create(), xbee_cmd_query_status(), and xbee_io_query_status().
void xbee_identify | ( | xbee_dev_t * | xbee, |
bool_t | identify | ||
) |
Programs with the ZCL Identify Server Cluster can call this function in their main loop to have the XBee module's association LED flash fast (100ms cycle) when in Identify Mode.
[in] | xbee | device to identify |
[in] | identify | TRUE if XBee should be in identify mode |
References xbee_cmd_simple().
const xbee_atcmd_reg_t _xbee_atcmd_query_regs[] |
List of XBee registers to query at startup; used to learn about the attached XBee module.