#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include "cellular_config.h"
#include "cellular_config_defaults.h"
Go to the source code of this file.
Macros | |
#define | ARRAY_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. | |
CellularATError_t | Cellular_ATRemoveLeadingWhiteSpaces (char **ppString) |
Remove all leading white spaces from an AT response. | |
CellularATError_t | Cellular_ATRemoveTrailingWhiteSpaces (char *pString) |
Remove all trailing white spaces from an AT response. | |
CellularATError_t | Cellular_ATRemoveAllWhiteSpaces (char *pString) |
Remove all white spaces from an AT response. | |
CellularATError_t | Cellular_ATRemoveOutermostDoubleQuote (char **ppString) |
Remove outermost double quotes from an AT response. | |
CellularATError_t | Cellular_ATRemoveAllDoubleQuote (char *pString) |
Remove all double quotes from an AT response. | |
CellularATError_t | Cellular_ATGetNextTok (char **ppString, char **ppTokOutput) |
Extract the next token based on comma (',') as delimiter. | |
CellularATError_t | Cellular_ATGetSpecificNextTok (char **ppString, const char *pDelimiter, char **ppTokOutput) |
Extract the next token based on the provided delimiter. | |
CellularATError_t | Cellular_ATHexStrToHex (const char *pString, uint8_t *pHexData, uint16_t hexDataLen) |
Convert HEX string to HEX. | |
CellularATError_t | Cellular_ATIsStrDigit (const char *pString, bool *pResult) |
Check if a string is numeric. | |
CellularATError_t | Cellular_ATIsPrefixPresent (const char *pString, bool *pResult) |
check if a string as prefix present by determine present of ':' | |
CellularATError_t | Cellular_ATStrDup (char **ppDst, const char *pSrc) |
duplicate string from pSrc to ppDst, malloc is use to allocate mem space for ppDst | |
CellularATError_t | Cellular_ATStrStartWith (const char *pString, const char *pPrefix, bool *pResult) |
check if a string starts with certain prefix | |
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 | |
CellularATError_t | Cellular_ATStrtoi (const char *pStr, int32_t base, int32_t *pResult) |
Convert string to int32_t. | |
enum CellularATError_t |
Represents error codes returned from AT Core APIs.
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.
[in,out] | ppString | The AT response to remove the prefix from. In case of success, the pointer is updated to move past the prefix. |
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
[in,out] | ppString | The AT response to remove the leading white spaces from. In case of success, the pointer is updated to the first non white space character. |
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' | +—+—+—+—+—+—+—+—+---—+–+–+---—+
[in,out] | pString | The AT response to remove the trailing white spaces from. |
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' | +—+—+—+—+—+—+—+—+---—+---—+
[in,out] | pString | The AT response to remove the white spaces from. |
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
[in,out] | ppString | The AT response to remove the double quotes from. |
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' | +—+—+—+—+—+—+—+—+---—+—+—+—+---—+
[in,out] | pString | The AT response to remove the double quotes from. |
CellularATError_t Cellular_ATGetNextTok | ( | char ** | ppString, |
char ** | ppTokOutput | ||
) |
Extract the next token based on comma (',') as delimiter.
[in,out] | ppString | The AT response to extract the token from. |
[in,out] | ppTokOutput | The output parameter to return the location of the token. |
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.
[in,out] | ppString | The AT response to extract the token from. |
[in] | pDelimiter | The delimiter string. |
[in,out] | ppTokOutput | The output parameter to return the location of the token. |
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.
[in] | pString | The hex string to convert to HEX. |
[out] | pHexData | The buffer to return the converted HEX data into. |
[in] | hexDataLen | The length of the buffer. |
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.
[in] | pString | The input string to check. |
[out] | pResult | The bool output parameter to return whether or not the string is numeric. |
CellularATError_t Cellular_ATIsPrefixPresent | ( | const char * | pString, |
bool * | pResult | ||
) |
check if a string as prefix present by determine present of ':'
[in] | pString | input string |
[out] | pResult | The bool output parameter to return whether or not the string is numeric. |
CellularATError_t Cellular_ATStrDup | ( | char ** | ppDst, |
const char * | pSrc | ||
) |
duplicate string from pSrc to ppDst, malloc is use to allocate mem space for ppDst
[in] | pSrc | input string to be copied |
[out] | ppDst | destination pointer |
CellularATError_t Cellular_ATStrStartWith | ( | const char * | pString, |
const char * | pPrefix, | ||
bool * | pResult | ||
) |
check if a string starts with certain prefix
[in] | pString | input string |
[in] | pPrefix | input prefix |
[out] | pResult | return true if prefix is at start of pString, else false |
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
[in] | pInputBuf | the haystack buffer |
[in] | ppKeyList | list of keys |
[in] | keyListLen | size of the keyList array |
[out] | pResult | return true if any of Keys in ppKeyList is found in is at start of pString, else false |
CellularATError_t Cellular_ATStrtoi | ( | const char * | pStr, |
int32_t | base, | ||
int32_t * | pResult | ||
) |
Convert string to int32_t.
[in] | pStr | the input string buffer. |
[in] | base | Numerical base (radix) of pStr. Input string should not contain leading space or zero. |
[out] | pResult | converted int32_t result. |