AT command parser

The AT command parser is a library for parsing the string that is returned after issuing an AT command. It parses the response parameters from the string and saves them in a list.

To store the parameters in a list, the parser uses the AT parameters storage module. The resulting list can be used by any external module to obtain the value of the parameters. Based on the type of the parameter, you can obtain its value by calling either at_params_int_get(), at_params_short_get(), at_params_array_get(), or at_params_string_get(). Probing which type of element is stored on which index can be done using the at_params_type_get().

Before using the AT command parser, you must initialize a list of AT command/response parameters by calling at_params_list_init(). Then, to parse a string, simply pass the returned AT command string to the library function at_parser_params_from_str().

API documentation

Header file: include/at_cmd_parser.h
Source file: lib/at_cmd_parser/src/at_cmd_parser.c
group at_cmd_parser

Basic parser for AT commands.

Functions

int at_parser_max_params_from_str(const char *at_params_str, char **next_param_str, struct at_param_list *const list, size_t max_params_count)

Parse a maximum number of AT command or response parameters from a string.

This function parses the parameters from at_params_str and saves them in list. If there are more parameters than max_params_count, they are ignored.

list must be initialized. It can be reused to parse multiple commands. When calling this function, the list is cleared. The maximum number of AT parameters that can be parsed and stored is limited by the size of list.

If an error is returned by the parser, the content of list should be ignored.

In the case a string contains multiple notifications, the parser will stop parsing when it is done parsing the first notification, and return the remainder of the string in this pointer. The return code will be EAGAIN. If multinotification is not used, this pointer can be set to NULL.

Parameters
  • at_params_str: AT parameters as a null-terminated string. Can be numeric or string parameters.

Parameters
  • list: Pointer to an initialized list where parameters are stored. Must not be NULL.
  • max_params_count: Maximum number of parameters expected in at_params_str. Can be set to a smaller value to parse only some parameters.
Return Value
  • 0: If the operation was successful.
  • -EAGAIN: New notification detected in string re-run the parser with the string pointed to by next_param_str.
  • -E2BIG: The at_param_list supplied cannot hold all detected parameters in string. The list will contain the maximum number of parameters possible.
  • -EINVAL: One or more of the supplied parameters are invalid.

int at_parser_params_from_str(const char *at_params_str, char **next_param_str, struct at_param_list *const list)

Parse AT command or response parameters from a string.

This function parses the parameters from at_params_str and saves them in list.

list must be initialized. It can be reused to parse multiple commands. When calling this function, the list is cleared. The maximum number of AT parameters that can be parsed and stored is limited by the size of list.

If an error is returned by the parser, the content of list should be ignored.

In the case a string contains multiple notifications, the parser will stop parsing when it is done parsing the first notification, and return the remainder of the string in this pointer. The return code will be EAGAIN. If multinotification is not used, this pointer can be set to NULL.

Parameters
  • at_params_str: AT parameters as a null-terminated string. Can be numeric or string parameters.

Parameters
  • list: Pointer to an initialized list where parameters are stored. Must not be NULL.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.
  • -EAGAIN: New notification detected in string re-run the parser with the string pointed to by next_param_str.
  • -E2BIG: The at_param_list supplied cannot hold all detected parameters in string. The list will contain the maximum number of parameters possible.
  • -EINVAL: One or more of the supplied parameters are invalid.