Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
ATParser Class Reference
Parser class for parsing AT commands. More...
#include <ATParser.h>
Public Member Functions | |
ATParser (BufferedSpi &serial_spi, const char *delimiter="\r\n", int buffer_size=1440, int timeout=DEFAULT_SPI_TIMEOUT) | |
Constructor. | |
~ATParser () | |
Destructor. | |
void | setTimeout (int timeout) |
Allows timeout to be changed between commands. | |
void | setDelimiter (const char *delimiter) |
Sets string of characters to use as line delimiters. | |
bool | send (const char *command,...) |
Sends an AT command. | |
bool | recv (const char *response,...) |
Receive an AT response. | |
int | putc (char c) |
Write a single byte to the underlying stream. | |
int | getc () |
Get a single byte from the underlying stream. | |
int | write (const char *data, int size_of_data, int size_in_buff) |
Write an array of bytes to the underlying stream assuming the header of the command is already in _txbuffer. | |
int | read (char *data) |
Read an array of bytes from the underlying stream. | |
int | printf (const char *format,...) |
Direct printf to underlying stream. | |
int | scanf (const char *format,...) |
Direct scanf on underlying stream. | |
void | oob (const char *prefix, mbed::Callback< void()> func) |
Attach a callback for out-of-band data. | |
void | flush () |
Flushes the underlying stream. | |
void | abort () |
Abort current recv. | |
bool | process_oob (void) |
Process out-of-band data. | |
int | get_size (void) |
Get buffer_size. |
Detailed Description
Parser class for parsing AT commands.
Here are some examples:
ATParser at = ATParser(serial, "\r\n"); int value; char buffer[100]; at.send("AT") && at.recv("OK"); at.send("AT+CWMODE=%d", 3) && at.recv("OK"); at.send("AT+CWMODE?") && at.recv("+CWMODE:%d\r\nOK", &value); at.recv("+IPD,%d:", &value); at.read(buffer, value); at.recv("OK");
Definition at line 48 of file ATParser.h.
Constructor & Destructor Documentation
ATParser | ( | BufferedSpi & | serial_spi, |
const char * | delimiter = "\r\n" , |
||
int | buffer_size = 1440 , |
||
int | timeout = DEFAULT_SPI_TIMEOUT |
||
) |
Constructor.
- Parameters:
-
serial spi interface to use for AT commands buffer_size size of internal buffer for transaction timeout timeout of the connection delimiter string of characters to use as line delimiters
Definition at line 45 of file ATParser.cpp.
~ATParser | ( | ) |
Destructor.
Definition at line 84 of file ATParser.h.
Member Function Documentation
void abort | ( | ) |
Abort current recv.
Can be called from oob handler to interrupt the current recv operation.
Definition at line 448 of file ATParser.cpp.
void flush | ( | ) |
Flushes the underlying stream.
Definition at line 66 of file ATParser.cpp.
int get_size | ( | void | ) |
Get buffer_size.
Definition at line 240 of file ATParser.h.
int getc | ( | ) |
Get a single byte from the underlying stream.
- Returns:
- The byte that was read or -1 during a timeout
Definition at line 61 of file ATParser.cpp.
void oob | ( | const char * | prefix, |
mbed::Callback< void()> | func | ||
) |
Attach a callback for out-of-band data.
- Parameters:
-
prefix string on when to initiate callback func callback to call when string is read
- Note:
- out-of-band data is only processed during a scanf call
int printf | ( | const char * | format, |
... | |||
) |
Direct printf to underlying stream.
- See also:
- printf
- Parameters:
-
format format string to pass to printf ... arguments to printf
- Returns:
- number of bytes written or -1 on failure
Definition at line 400 of file ATParser.cpp.
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.
- Returns:
- true if oob data processed, false otherwise
int putc | ( | char | c ) |
Write a single byte to the underlying stream.
- Parameters:
-
c The byte to write
- Returns:
- The byte that was written or -1 during a timeout
Definition at line 56 of file ATParser.cpp.
int read | ( | char * | data ) |
Read an array of bytes from the underlying stream.
- Parameters:
-
data the destination for the read bytes size number of bytes to read
- Returns:
- number of bytes read or -1 on failure
Definition at line 98 of file ATParser.cpp.
bool recv | ( | const char * | response, |
... | |||
) |
Receive an AT response.
Receives a formatted response using scanf style formatting
- See also:
- scanf
Responses are parsed line at a time. Any received data that does not match the response is ignored until a timeout occurs.
- Parameters:
-
response scanf-like format string of response to expect ... all scanf-like arguments to extract from response
- Returns:
- true only if response is successfully matched
Definition at line 427 of file ATParser.cpp.
int scanf | ( | const char * | format, |
... | |||
) |
Direct scanf on underlying stream.
- See also:
- scanf
- Parameters:
-
format format string to pass to scanf ... arguments to scanf
- Returns:
- number of bytes read or -1 on failure
Definition at line 409 of file ATParser.cpp.
bool send | ( | const char * | command, |
... | |||
) |
Sends an AT command.
Sends a formatted command using printf style formatting
- See also:
- printf
- Parameters:
-
command printf-like format string of command to send which is appended with a newline ... all printf-like arguments to insert into command
- Returns:
- true only if command is successfully sent
Definition at line 418 of file ATParser.cpp.
void setDelimiter | ( | const char * | delimiter ) |
Sets string of characters to use as line delimiters.
- Parameters:
-
delimiter string of characters to use as line delimiters
Definition at line 109 of file ATParser.h.
void setTimeout | ( | int | timeout ) |
Allows timeout to be changed between commands.
- Parameters:
-
timeout timeout of the connection
Definition at line 99 of file ATParser.h.
int write | ( | const char * | data, |
int | size_of_data, | ||
int | size_in_buff | ||
) |
Write an array of bytes to the underlying stream assuming the header of the command is already in _txbuffer.
- Parameters:
-
data the array of bytes to write size_of_data number of bytes in data array size_in_buff number of bytes already in the internal buff
- Returns:
- number of bytes written or -1 on failure
Definition at line 76 of file ATParser.cpp.
Generated on Tue Jul 12 2022 19:12:19 by 1.7.2