FreeRTOS: FreeRTOS Cellular Library v1.2.0
FreeRTOS Cellular Library
cellular_at_core.h File Reference
#include <stdbool.h>
#include <string.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define CELLULAR_AT_MAX_STRING_SIZE   ( 256U )
 Maximum size of an AT string.
 
#define CELLULAR_AT_MAX_PREFIX_SIZE   ( 32 )
 Maximum size of an AT prefix.
 
#define ARRY_SIZE(x)   ( sizeof( x ) / sizeof( x[ 0 ] ) )
 The array size of an array.
 

Enumerations

enum  CellularATError_t {
  CELLULAR_AT_SUCCESS = 0 , CELLULAR_AT_BAD_PARAMETER , CELLULAR_AT_NO_MEMORY , CELLULAR_AT_UNSUPPORTED ,
  CELLULAR_AT_MODEM_ERROR , CELLULAR_AT_ERROR , CELLULAR_AT_UNKNOWN
}
 Represents error codes returned from AT Core APIs. More...
 

Functions

CellularATError_t Cellular_ATRemovePrefix (char **ppString)
 Remove prefix from a string. More...
 
CellularATError_t Cellular_ATRemoveLeadingWhiteSpaces (char **ppString)
 Remove all leading white spaces from an AT response. More...
 
CellularATError_t Cellular_ATRemoveTrailingWhiteSpaces (char *pString)
 Remove all trailing white spaces from an AT response. More...
 
CellularATError_t Cellular_ATRemoveAllWhiteSpaces (char *pString)
 Remove all white spaces from an AT response. More...
 
CellularATError_t Cellular_ATRemoveOutermostDoubleQuote (char **ppString)
 Remove outermost double quotes from an AT response. More...
 
CellularATError_t Cellular_ATRemoveAllDoubleQuote (char *pString)
 Remove all double quotes from an AT response. More...
 
CellularATError_t Cellular_ATGetNextTok (char **ppString, char **ppTokOutput)
 Extract the next token based on comma (',') as delimiter. More...
 
CellularATError_t Cellular_ATGetSpecificNextTok (char **ppString, const char *pDelimiter, char **ppTokOutput)
 Extract the next token based on the provided delimiter. More...
 
CellularATError_t Cellular_ATHexStrToHex (const char *pString, uint8_t *pHexData, uint16_t hexDataLen)
 Convert HEX string to HEX. More...
 
CellularATError_t Cellular_ATIsStrDigit (const char *pString, bool *pResult)
 Check if a string is numeric. More...
 
CellularATError_t Cellular_ATIsPrefixPresent (const char *pString, bool *pResult)
 check if a string as prefix present by determine present of ':' More...
 
CellularATError_t Cellular_ATStrDup (char **ppDst, const char *pSrc)
 duplicate string from pSrc to ppDst, malloc is use to allocate mem space for ppDst More...
 
CellularATError_t Cellular_ATStrStartWith (const char *pString, const char *pPrefix, bool *pResult)
 check if a string starts with certain prefix More...
 
CellularATError_t Cellular_ATcheckErrorCode (const char *pInputBuf, const char *const *const ppKeyList, size_t keyListLen, bool *pResult)
 check if certain success code/error code present in the input buffer More...
 
CellularATError_t Cellular_ATStrtoi (const char *pStr, int32_t base, int32_t *pResult)
 Convert string to int32_t. More...
 

Enumeration Type Documentation

◆ CellularATError_t

Represents error codes returned from AT Core APIs.

Enumerator
CELLULAR_AT_SUCCESS 

The operation was successful.

CELLULAR_AT_BAD_PARAMETER 

One or more of the input parameters is not valid.

CELLULAR_AT_NO_MEMORY 

Memory allocation failure.

CELLULAR_AT_UNSUPPORTED 

The operation is not supported.

CELLULAR_AT_MODEM_ERROR 

Error in modem response.

CELLULAR_AT_ERROR 

Generic Error or boolean false.

CELLULAR_AT_UNKNOWN 

Any other error other than the above mentioned ones.

Function Documentation

◆ Cellular_ATRemovePrefix()

CellularATError_t Cellular_ATRemovePrefix ( char **  ppString)

Remove prefix from a string.

Many AT responses contain prefix of the form +XXXX. This function removes the prefix by moving the pointer after the prefix. For example:

Input: +—+—+—+—+—+—+—+—+—+—+—+ | + | C | P | I | N | : | R | E | A | D | Y | +—+—+—+—+—+—+—+—+—+—+—+ ^ | *ppString

Output: +—+—+—+—+—+—+—+—+—+—+—+ | + | C | P | I | N | : | R | E | A | D | Y | +—+—+—+—+—+—+—+—+—+—+—+ ^ | *ppString

Note that a prefix is always followed by colon (':') and this function removes colon as well.

Parameters
[in,out]ppStringThe AT response to remove the prefix from. In case of success, the pointer is updated to move past the prefix.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATRemoveLeadingWhiteSpaces()

CellularATError_t Cellular_ATRemoveLeadingWhiteSpaces ( char **  ppString)

Remove all leading white spaces from an AT response.

Leading white spaces are removed by updating the pointer to the first non-white space character. For example:

Input: +–+–+–+—+—+—+—+—+—+—+—+---—+ | | | | r | e | s | p | o | n | s | e | '\0' | +–+–+–+—+—+—+—+—+—+—+—+---—+ ^ | *ppString

Output: +–+–+–+—+—+—+—+—+—+—+—+---—+ | | | | r | e | s | p | o | n | s | e | '\0' | +–+–+–+—+—+—+—+—+—+—+—+---—+ ^ | *ppString

Parameters
[in,out]ppStringThe AT response to remove the leading white spaces from. In case of success, the pointer is updated to the first non white space character.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATRemoveTrailingWhiteSpaces()

CellularATError_t Cellular_ATRemoveTrailingWhiteSpaces ( char *  pString)

Remove all trailing white spaces from an AT response.

Trailing spaces are removed by making the character next to the last non white space character NULL ('\0'). For example:

Input: +—+—+—+—+—+—+—+—+–+–+–+---—+ | r | e | s | p | o | n | s | e | | | | '\0' | +—+—+—+—+—+—+—+—+–+–+–+---—+

Output: +—+—+—+—+—+—+—+—+---—+–+–+---—+ | r | e | s | p | o | n | s | e | '\0' | | | '\0' | +—+—+—+—+—+—+—+—+---—+–+–+---—+

Parameters
[in,out]pStringThe AT response to remove the trailing white spaces from.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATRemoveAllWhiteSpaces()

CellularATError_t Cellular_ATRemoveAllWhiteSpaces ( char *  pString)

Remove all white spaces from an AT response.

White spaces are removed by copying the non-white space characters to the beginning. The character next to the last non-white space character is set to the null character ('\0'). For example:

Input: +–+–+–+—+—+—+—+—+—+—+– +—+---—+ | | | | r | e | s | p | | o | n | s | e | '\0' | +–+–+–+—+—+—+—+—+—+—+—+—+---—+

Output: +—+—+—+—+—+—+—+—+---—+---—+ | r | e | s | p | o | n | s | e | '\0' | '\0' | +—+—+—+—+—+—+—+—+---—+---—+

Parameters
[in,out]pStringThe AT response to remove the white spaces from.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATRemoveOutermostDoubleQuote()

CellularATError_t Cellular_ATRemoveOutermostDoubleQuote ( char **  ppString)

Remove outermost double quotes from an AT response.

If the first character is double quote, it is removed by updating the pointer to point to the next character. If the last character is double quote, it is removed by making it the null character. Nothing else is done in any other case. For example:

Input: +—+—+—+—+—+—+—+—+—+—+---—+ | " | r | e | s | p | o | n | s | e | " | '\0' | +—+—+—+—+—+—+—+—+—+—+---—+ ^ | *ppString

Output: +—+—+—+—+—+—+—+—+—+---—+---—+ | " | r | e | s | p | o | n | s | e | '\0' | '\0' | +—+—+—+—+—+—+—+—+—+---—+---—+ ^ | *ppString

Parameters
[in,out]ppStringThe AT response to remove the double quotes from.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATRemoveAllDoubleQuote()

CellularATError_t Cellular_ATRemoveAllDoubleQuote ( char *  pString)

Remove all double quotes from an AT response.

Double quotes are removed by copying all the other characters to the beginning. The character next to the last character is set to the null character ('\0'). For example:

Input: +—+—+—+—+—+—+—+—+—+—+—+—+---—+ | " | r | e | s | " | p | " | o | n | s | e | " | '\0' | +—+—+—+—+—+—+—+—+—+—+—+—+---—+

Output: +—+—+—+—+—+—+—+—+---—+—+—+—+---—+ | r | e | s | p | o | n | s | e | '\0' | s | e | " | '\0' | +—+—+—+—+—+—+—+—+---—+—+—+—+---—+

Parameters
[in,out]pStringThe AT response to remove the double quotes from.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATGetNextTok()

CellularATError_t Cellular_ATGetNextTok ( char **  ppString,
char **  ppTokOutput 
)

Extract the next token based on comma (',') as delimiter.

Parameters
[in,out]ppStringThe AT response to extract the token from.
[in,out]ppTokOutputThe output parameter to return the location of the token.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATGetSpecificNextTok()

CellularATError_t Cellular_ATGetSpecificNextTok ( char **  ppString,
const char *  pDelimiter,
char **  ppTokOutput 
)

Extract the next token based on the provided delimiter.

This function uses *ppATResponse as the starting location to scan for tokens which are sequences of contiguous characters separated by delimiters. When it finds a token, *ppOutToken is updated to point to starting location of the token and *ppATResponse is updated to point to the next character after the token. This ensures that the next call to this function will extract the next occurrence of the token.

Parameters
[in,out]ppStringThe AT response to extract the token from.
[in]pDelimiterThe delimiter string.
[in,out]ppTokOutputThe output parameter to return the location of the token.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATHexStrToHex()

CellularATError_t Cellular_ATHexStrToHex ( const char *  pString,
uint8_t *  pHexData,
uint16_t  hexDataLen 
)

Convert HEX string to HEX.

This function requires the provided string to be of even length and returns CELLULAR_AT_BAD_PARAMETER if it is not. It also requires the output buffer to be of exactly half the length of the given hex string to ensure that it exactly fits the converted data.

It reads two characters and constructs a HEX byte by treating them upper and lower nibble of the byte. For example:

Input: +—+—+—+—+---—+ | 1 | 0 | A | B | '\0' | +—+—+—+—+---—+

Output: +-—+--—+---—+ | 16 | 171 | '\0' | +-—+--—+---—+

Decimal 16 is 0x10 and decimal 171 is 0xAB.

Parameters
[in]pStringThe hex string to convert to HEX.
[out]pHexDataThe buffer to return the converted HEX data into.
[in]hexDataLenThe length of the buffer.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATIsStrDigit()

CellularATError_t Cellular_ATIsStrDigit ( const char *  pString,
bool *  pResult 
)

Check if a string is numeric.

A string is numeric if all the characters in it are digits. For example, "1234" is numeric but "123YD" is not because 'Y' and 'D' are not digits.

Parameters
[in]pStringThe input string to check.
[out]pResultThe bool output parameter to return whether or not the string is numeric.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATIsPrefixPresent()

CellularATError_t Cellular_ATIsPrefixPresent ( const char *  pString,
bool *  pResult 
)

check if a string as prefix present by determine present of ':'

Parameters
[in]pStringinput string
[out]pResultThe bool output parameter to return whether or not the string is numeric.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATStrDup()

CellularATError_t Cellular_ATStrDup ( char **  ppDst,
const char *  pSrc 
)

duplicate string from pSrc to ppDst, malloc is use to allocate mem space for ppDst

Parameters
[in]pSrcinput string to be copied
[out]ppDstdestination pointer
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATStrStartWith()

CellularATError_t Cellular_ATStrStartWith ( const char *  pString,
const char *  pPrefix,
bool *  pResult 
)

check if a string starts with certain prefix

Parameters
[in]pStringinput string
[in]pPrefixinput prefix
[out]pResultreturn true if prefix is at start of pString, else false
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATcheckErrorCode()

CellularATError_t Cellular_ATcheckErrorCode ( const char *  pInputBuf,
const char *const *const  ppKeyList,
size_t  keyListLen,
bool *  pResult 
)

check if certain success code/error code present in the input buffer

Parameters
[in]pInputBufthe haystack buffer
[in]ppKeyListlist of keys
[in]keyListLensize of the keyList array
[out]pResultreturn true if any of Keys in ppKeyList is found in is at start of pString, else false
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.

◆ Cellular_ATStrtoi()

CellularATError_t Cellular_ATStrtoi ( const char *  pStr,
int32_t  base,
int32_t *  pResult 
)

Convert string to int32_t.

Parameters
[in]pStrthe input string buffer.
[in]baseNumerical base (radix) of pStr. Input string should not contain leading space or zero.
[out]pResultconverted int32_t result.
Returns
CELLULAR_AT_SUCCESS if the operation is successful, otherwise an error code indicating the cause of the error.