ATParser for X-NUCLEO-IDW01M1 module

Dependencies:   BufferedSerial

Dependents:   SPWF01SA-lapi-1 SPWF01SA Nucleo-AWS-IoT-mbed

Fork of ATParser by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

ATParser Class Reference

ATParser Class Reference

Parser class for parsing AT commands. More...

#include <ATParser.h>

Public Member Functions

 ATParser (BufferedSerial &serial, const char *delimiter="\r\n", int buffer_size=256, int timeout=8000, bool debug=false)
 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.
void debugOn (uint8_t on)
 Allows echo to be on or off.
bool send (const char *command,...)
 Sends an AT command.
bool recv (const char *response,...)
 Recieve 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)
 Write an array of bytes to the underlying stream.
int read (char *data, int size)
 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 flush ()
 Flushes the underlying stream.

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 43 of file ATParser.h.


Constructor & Destructor Documentation

ATParser ( BufferedSerial &  serial,
const char *  delimiter = "\r\n",
int  buffer_size = 256,
int  timeout = 8000,
bool  debug = false 
)

Constructor.

Parameters:
serialserial interface to use for AT commands
buffer_sizesize of internal buffer for transaction
timeouttimeout of the connection
delimiterstring of characters to use as line delimiters

Definition at line 66 of file ATParser.h.

~ATParser (  )

Destructor.

Definition at line 78 of file ATParser.h.


Member Function Documentation

void debugOn ( uint8_t  on )

Allows echo to be on or off.

Parameters:
echo1 for echo and 0 turns it off

Definition at line 110 of file ATParser.h.

void flush (  )

Flushes the underlying stream.

Definition at line 56 of file ATParser.cpp.

int getc (  )

Get a single byte from the underlying stream.

Returns:
The byte that was read or -1 during a timeout

Definition at line 41 of file ATParser.cpp.

int printf ( const char *  format,
  ... 
)

Direct printf to underlying stream.

See also:
printf
Parameters:
formatformat string to pass to printf
...arguments to printf
Returns:
number of bytes written or -1 on failure

Definition at line 306 of file ATParser.cpp.

int putc ( char  c )

Write a single byte to the underlying stream.

Parameters:
cThe byte to write
Returns:
The byte that was written or -1 during a timeout

Definition at line 26 of file ATParser.cpp.

int read ( char *  data,
int  size 
)

Read an array of bytes from the underlying stream.

Parameters:
datathe destination for the read bytes
sizenumber of bytes to read
Returns:
number of bytes read or -1 on failure

Definition at line 76 of file ATParser.cpp.

bool recv ( const char *  response,
  ... 
)

Recieve an AT response.

Recieves a formatted response using scanf style formatting

See also:
scanf

Responses are parsed line at a time using the specified delimiter. Any recieved data that does not match the response is ignored until a timeout occurs.

Parameters:
responsescanf-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 333 of file ATParser.cpp.

int scanf ( const char *  format,
  ... 
)

Direct scanf on underlying stream.

See also:
scanf
Parameters:
formatformat string to pass to scanf
...arguments to scanf
Returns:
number of bytes read or -1 on failure

Definition at line 315 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:
commandprintf-like format string of command to send which is appended with the specified delimiter
...all printf-like arguments to insert into command
Returns:
true only if command is successfully sent

Definition at line 324 of file ATParser.cpp.

void setDelimiter ( const char *  delimiter )

Sets string of characters to use as line delimiters.

Parameters:
delimiterstring of characters to use as line delimiters

Definition at line 100 of file ATParser.h.

void setTimeout ( int  timeout )

Allows timeout to be changed between commands.

Parameters:
timeouttimeout of the connection

Definition at line 87 of file ATParser.h.

int write ( const char *  data,
int  size 
)

Write an array of bytes to the underlying stream.

Parameters:
datathe array of bytes to write
sizenumber of bytes to write
Returns:
number of bytes written or -1 on failure

Definition at line 65 of file ATParser.cpp.