AT (Hayes) command set library¶
AT (Hayes) command set library.
This module provides functions to interact with devices using AT commands.
Most functions compare the bytes echoed by the device with what they intended to send, and bail out if there’s no match.
Furthermore, the library tries to cope with difficulties regarding different line endings. It usually sends “<command><CR>”, but expects “<command>\LF\CR” as echo.
As a debugging aid, when compiled with “-DAT_PRINT_INCOMING=1”, every input byte gets printed.
-
void(*
at_urc_cb_t
()¶ Unsolicited result code callback.
Parameters
arg: optional argument code: urc string received from the device
-
int
at_dev_init
(at_dev_t * dev,uart.h::uart_t
uart, uint32_t baudrate, char * buf,msp430_types.h::size_t
bufsize)¶ Initialize AT device struct.
Parameters
dev: struct to initialize uart: UART the device is connected to baudrate: baudrate of the device buf: input buffer bufsize: size of buf
Return values
- 0 on success
- <0 otherwise
-
int
at_send_cmd_wait_ok
(at_dev_t * dev, const char * command, uint32_t timeout)¶ Simple command helper.
This function sends an AT command to the device and waits for “OK”.
Parameters
dev: device to operate on command: command string to send timeout: timeout (in usec) Return values
- 0 when device answers “OK”
- <0 otherwise
-
int
at_send_cmd_wait_prompt
(at_dev_t * dev, const char * command, uint32_t timeout)¶ Send AT command, wait for a prompt.
This function sends the supplied
command
, then waits for the prompt (>) character and returnsParameters
dev: device to operate on command: command string to send timeout: timeout (in usec) Return values
- 0 when prompt is received
- <0 otherwise
-
msp430_types.h::ssize_t
at_send_cmd_get_resp
(at_dev_t * dev, const char * command, char * resp_buf,msp430_types.h::size_t
len, uint32_t timeout)¶ Send AT command, wait for response.
This function sends the supplied
command
, then waits and returns one line of response.A possible empty line will be skipped.
Parameters
dev: device to operate on command: command to send resp_buf: buffer for storing response len: len of buffer
timeout: timeout (in usec) Return values
- length of response on success
- <0 on error
-
msp430_types.h::ssize_t
at_send_cmd_get_lines
(at_dev_t * dev, const char * command, char * resp_buf,msp430_types.h::size_t
len, bool keep_eol, uint32_t timeout)¶ Send AT command, wait for multiline response.
This function sends the supplied
command
, then returns all response lines until the device sends “OK”.If a line starts with “ERROR” or “+CME ERROR:”, or the buffer is full, the function returns -1.
Parameters
dev: device to operate on command: command to send resp_buf: buffer for storing response len: len of resp_buf
keep_eol: true to keep the CR character in the response timeout: timeout (in usec) Return values
- length of response on success
- <0 on error
-
int
at_expect_bytes
(at_dev_t * dev, const char * bytes, uint32_t timeout)¶ Expect bytes from device.
Parameters
dev: device to operate on bytes: buffer containing bytes to expect (NULL-terminated) timeout: timeout (in usec) Return values
- 0 on success
- <0 otherwise
-
void
at_send_bytes
(at_dev_t * dev, const char * bytes,msp430_types.h::size_t
len)¶ Send raw bytes to a device.
Parameters
dev: device to operate on bytes: buffer containing bytes to send len: number of bytes to send
-
int
at_send_cmd
(at_dev_t * dev, const char * command, uint32_t timeout)¶ Send command to device.
Parameters
dev: device to operate on command: command to send timeout: timeout (in usec) Return values
- 0 on success
- <0 otherwise
-
msp430_types.h::ssize_t
at_readline
(at_dev_t * dev, char * resp_buf,msp430_types.h::size_t
len, bool keep_eol, uint32_t timeout)¶ Read a line from device.
Parameters
dev: device to operate on resp_buf: buffer to store line len: size of resp_buf
keep_eol: true to keep the CR character in the response timeout: timeout (in usec) Return values
- line length on success
- <0 on error
-
void
at_drain
(at_dev_t * dev)¶ Drain device input buffer.
This function drains any possible bytes waiting in the device’s input buffer.
Parameters
dev: device to operate on
-
void
at_add_urc
(at_dev_t * dev, at_urc_t * urc)¶ Add a callback for an unsolicited response code.
Parameters
dev: device to operate on urc: unsolicited result code to register
-
void
at_remove_urc
(at_dev_t * dev, at_urc_t * urc)¶ Remove an unsolicited response code from the list.
Parameters
dev: device to operate on urc: unsolicited result code to remove
-
void
at_process_urc
(at_dev_t * dev, uint32_t timeout)¶ Process out-of-band data received from the device.
Parameters
dev: device to operate on timeout: timeout (in usec)
-
AT_SEND_EOL
¶ End of line character to send after the AT command.
1
"\r"
-
AT_SEND_ECHO
¶ Enable/disable the expected echo after an AT command is sent.
1
1
-
AT_SEND_EOL_LEN
¶ Shortcut for getting send end of line length.
1
(sizeof(AT_SEND_EOL) - 1)
-
AT_RECV_EOL_1
¶ 1st end of line character received (S3 aka CR character for a modem)
1
"\r"
-
AT_RECV_EOL_2
¶ 1st end of line character received (S4 aka LF character for a modem)
1
"\n"
-
AT_RECV_OK
¶ default OK reply of an AT device
1
"OK"
-
AT_RECV_ERROR
¶ default ERROR reply of an AT device
1
"ERROR"
-
AT_BUF_SIZE
¶ Internal buffer size used to process unsolicited result code data.
1
(128)
-
struct
at_urc_t
¶ Unsolicited result code data structure.
-
clist.h::clist_node_t
list_node
¶ node list
-
at.h::at_urc_cb_t
cb
¶ callback
-
const char *
code
¶ URC string which must match.
-
void *
arg
¶ optional argument
-
-
struct
at_dev_t
¶ AT device structure.
-
uart.h::uart_t
uart
¶ UART device where the AT device is attached.
-