XBee Firmware Library  1.6.0
Files | Functions

Files

file  atmode.h
 
file  xbee_atmode.c
 

Functions

XBEE_BEGIN_DECLS int xbee_atmode_enter (xbee_dev_t *xbee)
 Attempt to enter AT command mode (delay 1 second, send +++, delay 1 second). More...
 
int xbee_atmode_exit (xbee_dev_t *xbee)
 Leave AT command mode and return to idle mode. More...
 
int xbee_atmode_read_response (xbee_dev_t *xbee, char FAR *response, int resp_size, int FAR *bytesread)
 Non-blocking function reads response to request sent with xbee_atmode_send_request to an XBee device in AT Command Mode. More...
 
int xbee_atmode_send_request (xbee_dev_t *xbee, const char FAR *command)
 Send an AT request and wait for a response. More...
 
int xbee_atmode_tick (xbee_dev_t *xbee)
 Advance the XBee device state machine when entering or exiting AT Command Mode or waiting for a response to a command. More...
 

Detailed Description

This network stack was designed for use with XBee modules in API mode, but it is sometimes necessary to work with a module in AT mode (for example, performing DigiMesh firmware updates).

Function Documentation

_xbee_atmode_debug int xbee_atmode_enter ( xbee_dev_t xbee)

Attempt to enter AT command mode (delay 1 second, send +++, delay 1 second).

After calling xbee_atmode_enter(), you must continue to call xbee_atmode_tick() until it returns XBEE_MODE_COMMAND (successfully entered command mode) or XBEE_MODE_IDLE (failed to enter command mode).

Parameters
[in]xbeeXBee device
Return values
0Initiated sequence to enter command mode.
-EINVALInvalid XBee device passed to function.
See also
xbee_atmode_exit, xbee_atmode_tick
_xbee_atmode_debug int xbee_atmode_exit ( xbee_dev_t xbee)

Leave AT command mode and return to idle mode.

XBee driver doesn't consider the XBee module to be in idle mode until xbee_atmode_tick() returns XBEE_MODE_IDLE.

Parameters
[in]xbeeXBee device
Return values
0Already in idle mode, or sent command to return to it. Call xbee_atmode_tick() until it returns XBEE_MODE_IDLE.
-EINVALInvalid XBee device passed to function.
-EBUSYCan't exit until receipt of response from previous command. Call function again later.
See also
xbee_atmode_enter, xbee_atmode_tick
_xbee_atmode_debug int xbee_atmode_read_response ( xbee_dev_t xbee,
char FAR *  response,
int  resp_size,
int FAR *  bytesread 
)

Non-blocking function reads response to request sent with xbee_atmode_send_request to an XBee device in AT Command Mode.

Reads up to trailing return () before returning success (0). Does not include trailing return in response.

Sample code for using this function:

1 char response[40];
2 int bytesread, retval;
3 
4  *response = '\0'; // start with empty response
5 bytesread = 0;
6 
7 do {
8  retval = xbee_atmode_read_response( xbee, response,
9  sizeof( response), &bytesread);
10 } while (retval == -EAGAIN);
11 
12 if (retval < 0)
13  printf( "error %d reading response\n", retval);
14 else
15  printf( "response is %s\n", response);
    @param[in]              xbee                    XBee device

    @param[out]             response                Buffer to hold the response.  Since this function
                                    is non-blocking, and may require multiple calls to read the
                                    entire response, the buffer is used to hold the partial
                                    response until the XBee sends a return (\r).

    @param[in]              resp_size       Size of response buffer passed in parameter 2.

    @param[in,out]  bytesread       Pointer to an integer that is tracking the number
                                    of bytes already read.  Function will read new bytes starting at
                                    \a &response[*bytesread] and will increment \a *bytesread for
                                    every byte added to \a response.

                                    If NULL, function will append new bytes to the end of
                                    \a response.

    @retval 0                               received complete line
    @retval -EINVAL         Invalid parameter passed to function.
    @retval -EPERM          XBee isn't waiting for a response
    @retval -ENOSPC         buffer filled before "\r" received
    @retval -EAGAIN         haven't read entire response yet, call function again
    @retval -ETIMEDOUT      timed out waiting for response

    @sa     xbee_atmode_send_request
_xbee_atmode_debug int xbee_atmode_send_request ( xbee_dev_t xbee,
const char FAR *  command 
)

Send an AT request and wait for a response.

Automatically prepends the request with "AT" and adds the trailing carriage-return.

Parameters
[in]xbeeXBee device
[in]commandCommand to send (without leading AT or trailing )
Return values
0Command sent
-EINVALInvalid parameter passed to function.
-ENOSPCNot enough room in transmit buffer to send request.
See also
xbee_atmode_read_response
_xbee_atmode_debug int xbee_atmode_tick ( xbee_dev_t xbee)

Advance the XBee device state machine when entering or exiting AT Command Mode or waiting for a response to a command.

Parameters
[in]xbeeXBee device
Return values
>=0Current state of XBee device. See the function help for xbee_mode for a list of modes.
-EINVALInvalid XBee device passed to function.
<0 Undocumented error.
See also
xbee_atmode_enter, xbee_atmode_tick