Parser class for parsing AT commands. More...
#include <ATCmdParser.h>
Public Member Functions | |
ATCmdParser (FileHandle *fh, const char *output_delimiter="\r", int buffer_size=256, int timeout=8000, bool debug=false) | |
Constructor. More... | |
~ATCmdParser () | |
Destructor. More... | |
void | set_timeout (int timeout) |
Allows timeout to be changed between commands. More... | |
void | set_delimiter (const char *output_delimiter) |
Sets string of characters to use as line delimiters. More... | |
void | debug_on (uint8_t on) |
Allows traces from modem to be turned on or off. More... | |
bool | send (const char *command,...) MBED_PRINTF_METHOD(1 |
Sends an AT command. More... | |
bool | recv (const char *response,...) MBED_SCANF_METHOD(1 |
Receive an AT response. More... | |
int | putc (char c) |
Write a single byte to the underlying stream. More... | |
int | getc () |
Get a single byte from the underlying stream. More... | |
int | write (const char *data, int size) |
Write an array of bytes to the underlying stream. More... | |
int | read (char *data, int size) |
Read an array of bytes from the underlying stream. More... | |
int | printf (const char *format,...) MBED_PRINTF_METHOD(1 |
Direct printf to underlying stream. More... | |
int | scanf (const char *format,...) MBED_SCANF_METHOD(1 |
Direct scanf on underlying stream This function does not itself match whitespace in its format string, so is not significant to it. More... | |
void | oob (const char *prefix, mbed::Callback< void()> func) |
Attach a callback for out-of-band data. More... | |
void | remove_oob (const char *prefix) |
remove_oob Removes oob callback handler More... | |
void | flush () |
Flushes the underlying stream. More... | |
void | abort () |
Abort current recv. More... | |
bool | process_oob (void) |
Process out-of-band data. More... | |
Parser class for parsing AT commands.
Here are some examples:
Definition at line 56 of file ATCmdParser.h.
ATCmdParser | ( | FileHandle * | fh, |
const char * | output_delimiter = "\r" , |
||
int | buffer_size = 256 , |
||
int | timeout = 8000 , |
||
bool | debug = false |
||
) |
Constructor.
fh | A FileHandle to the digital interface, used for AT commands |
output_delimiter | End of command-line termination |
buffer_size | Size of internal buffer for transaction |
timeout | Timeout of the connection |
debug | Turns on/off debug output for AT commands |
Definition at line 111 of file ATCmdParser.h.
~ATCmdParser | ( | ) |
Destructor.
Definition at line 124 of file ATCmdParser.h.
void abort | ( | ) |
Abort current recv.
Can be called from out-of-band handler to interrupt the current recv operation.
void debug_on | ( | uint8_t | on | ) |
Allows traces from modem to be turned on or off.
on | Set as 1 to turn on traces and 0 to disable traces. |
Definition at line 161 of file ATCmdParser.h.
void flush | ( | ) |
Flushes the underlying stream.
int getc | ( | ) |
Get a single byte from the underlying stream.
void oob | ( | const char * | prefix, |
mbed::Callback< void()> | func | ||
) |
Attach a callback for out-of-band data.
prefix | String on when to initiate callback |
func | Callback to call when string is read |
int printf | ( | const char * | format, |
... | |||
) |
Direct printf to underlying stream.
format | Format string to pass to printf |
... | Variable arguments to printf |
bool process_oob | ( | void | ) |
Process out-of-band data.
Process out-of-band data in the receive buffer. This function returns immediately if there is no data to process.
int putc | ( | char | c | ) |
Write a single byte to the underlying stream.
c | The byte to write |
int read | ( | char * | data, |
int | size | ||
) |
Read an array of bytes from the underlying stream.
data | The buffer for filling the read bytes |
size | Number of bytes to read |
bool recv | ( | const char * | response, |
... | |||
) |
Receive an AT response.
Receives a formatted response using scanf style formatting
Responses are parsed line at a time. Any received data that does not match the response is ignored until a timeout occurs.
response | scanf-like format string of response to expect |
... | all scanf-like arguments to extract from response |
void remove_oob | ( | const char * | prefix | ) |
remove_oob Removes oob callback handler
prefix | Prefix to identify oob to be removed. |
int scanf | ( | const char * | format, |
... | |||
) |
Direct scanf on underlying stream This function does not itself match whitespace in its format string, so
is not significant to it.
It should be used only when certain string is needed or format ends with certain character, otherwise it will fill the output with one character.
format | Format string to pass to scanf |
... | Variable arguments to scanf |
bool send | ( | const char * | command, |
... | |||
) |
Sends an AT command.
Sends a formatted command using printf style formatting
command | printf-like format string of command to send which is appended with a newline |
... | all printf-like arguments to insert into command |
void set_delimiter | ( | const char * | output_delimiter | ) |
Sets string of characters to use as line delimiters.
output_delimiter | String of characters to use as line delimiters |
Definition at line 150 of file ATCmdParser.h.
void set_timeout | ( | int | timeout | ) |
Allows timeout to be changed between commands.
timeout | ATCmdParser APIs (read/write/send/recv ..etc) throw an error if no response is received in timeout duration |
Definition at line 140 of file ATCmdParser.h.
int write | ( | const char * | data, |
int | size | ||
) |
Write an array of bytes to the underlying stream.
data | The array of bytes to write |
size | Number of bytes to write |