AT parameters

The AT parameters module provides functionality to store lists of AT command or respond parameters. These lists can be used by other modules to write and read parameter values.

Tip

The primary intention of this module is to be used for AT command or respond parameters, but this is no requirement. You can use this module to store other kinds of parameters, as long as they consist of numeric or string values.

A parameter list contains an array of parameters defined by a type and a value. It can be cleared and reused, but once a list is created, its size cannot be changed. Each parameter in a list can be updated or cleared. When setting a parameter in the list, its value is copied. Parameters should be cleared to free the memory that they occupy. Getter and setter methods are available to read parameter values.

API documentation

group at_params

A parameter list contains an array of parameters defined by a type and a value. Those parameters could be arguments of an AT command, for example. They can be numeric or string values. The same list of parameters can be reused. Each parameter can be updated or cleared. Once the parameter list is created, its size cannot be changed. All parameters values are copied in the list. Parameters should be cleared to free that memory. Getter and setter methods are available to read parameter values.

Enums

enum at_param_type

Parameter type.

Values:

AT_PARAM_TYPE_EMPTY

Empty parameter.

AT_PARAM_TYPE_NUM_SHORT

Parameter of type short.

AT_PARAM_TYPE_NUM_INT

Parameter of type integer.

AT_PARAM_TYPE_STRING

Parameter of type string.

Functions

int at_params_list_init(struct at_param_list *list, size_t max_params_count)

Create a list of parameters.

An array of max_params_count is allocated. Each parameter is initialized to its default value. This function should not be called again before freeing the list.

Parameters
  • list: Parameter list to initialize.
  • max_params_count: Maximum number of element that the list can store.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

void at_params_list_clear(struct at_param_list *list)

Clear/reset all parameter types and values.

All parameter types and values are reset to default values.

Parameters
  • list: Parameter list to clear.

void at_params_list_free(struct at_param_list *list)

Free a list of parameters.

First the list is cleared. Then the list and its elements are deleted.

Parameters
  • list: Parameter list to free.

int at_params_clear(struct at_param_list *list, size_t index)

Clear/reset a parameter type and value.

Parameters
  • list: Parameter list.
  • index: Parameter index to clear.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int at_params_short_put(const struct at_param_list *list, size_t index, u16_t value)

Add a parameter in the list at the specified index and assign it a short value.

If a parameter exists at this index, it is replaced.

Parameters
  • list: Parameter list.
  • index: Index in the list where to put the parameter.
  • value: Parameter value.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int at_params_int_put(const struct at_param_list *list, size_t index, u32_t value)

Add a parameter in the list at the specified index and assign it an integer value.

If a parameter exists at this index, it is replaced.

Parameters
  • list: Parameter list.
  • index: Index in the list where to put the parameter.
  • value: Parameter value.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int at_params_string_put(const struct at_param_list *list, size_t index, const char *str, size_t str_len)

Add a parameter in the list at the specified index and assign it a string value.

The parameter string value is copied and added to the list as a null-terminated string. If a parameter exists at this index, it is replaced.

Parameters
  • list: Parameter list.
  • index: Index in the list where to put the parameter.
  • str: Pointer to the string value.
  • str_len: Number of characters of the string value str.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int at_params_size_get(const struct at_param_list *list, size_t index, size_t *len)

Get the size of a given parameter (in bytes).

A missing parameter has a size of ‘0’.

Parameters
  • list: Parameter list.
  • index: Parameter index in the list.
  • len: Length of the parameter in bytes.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int at_params_short_get(const struct at_param_list *list, size_t index, u16_t *value)

Get a parameter value as a short number.

Numeric values are stored as unsigned number. The parameter type must be a short, or an error is returned.

Parameters
  • list: Parameter list.
  • index: Parameter index in the list.
  • value: Parameter value.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int at_params_int_get(const struct at_param_list *list, size_t index, u32_t *value)

Get a parameter value as an integer number.

Numeric values are stored as unsigned number. The parameter type must be an integer, or an error is returned.

Parameters
  • list: Parameter list.
  • index: Parameter index in the list.
  • value: Parameter value.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

int at_params_string_get(const struct at_param_list *list, size_t index, char *value, size_t len)

Get a parameter value as a string.

The parameter type must be a string, or an error is returned. The string parameter value is copied to the buffer. len must be bigger than the string length, or an error is returned. The copied string is not null-terminated.

Parameters
  • list: Parameter list.
  • index: Parameter index in the list.
  • value: Pointer to the buffer where to copy the value.
  • len: Available space in value.
Return Value
  • 0: If the operation was successful. Otherwise, a (negative) error code is returned.

u32_t at_params_valid_count_get(const struct at_param_list *list)

Get the number of valid parameters in the list.

Return
The number of valid parameters until an empty parameter is found.
Parameters
  • list: Parameter list.

union at_param_value
#include <at_params.h>

Parameter value.

Public Members

u16_t short_val

Short value.

u32_t int_val

Integer value.

char *str_val

String value.

struct at_param
#include <at_params.h>

Parameter consisting of parameter type and value.

struct at_param_list
#include <at_params.h>

List of AT parameters that compose an AT command or response.

Contains an array of opaque data. Setter and getter methods should be used to get access to the parameters in the array.