Dependencies:
BufferedSerial
Diff: ATParser.h
- Revision:
- 5:26bc9255b751
- Parent:
- 4:38acbd6f9d9e
- Child:
- 6:51f1171b5ebc
--- a/ATParser.h Fri Jul 17 16:38:44 2015 +0000
+++ b/ATParser.h Fri Jul 17 17:23:57 2015 +0000
@@ -19,7 +19,7 @@
*/
#include "mbed.h"
-#include <stdarg.h>
+#include <cstdarg>
#include "BufferedSerial.h"
@@ -51,10 +51,9 @@
* @param serial serial interface to use for AT commands
* @param buffer_size size of internal buffer for transaction
* @param timeout timeout of the connection
- * @param echo flag to indicate if an echo of sent characters should be expected
* @param delimiter string of characters to use as line delimiters
*/
- ATParser(BufferedSerial *serial, int buffer_size = 256, int timeout = 3000,
+ ATParser(BufferedSerial *serial, int buffer_size = 256, int timeout = 8000,
const char *delimiter = "\r\n") :
_serial(serial),
_buffer_size(buffer_size) {
@@ -88,22 +87,44 @@
_delimiter = delimiter;
_delim_size = strlen(delimiter);
}
+
+ /**
+ * Sends an AT command
+ *
+ * Sends a formatted command using printf style formatting
+ * @see printf
+ *
+ * @param command printf-like format string of command to send which
+ * is appended with the specified delimiter
+ * @param ... all printf-like arguments to insert into command
+ * @return true only if command is successfully sent
+ */
+ bool send(const char *command, ...);
+ bool vsend(const char *command, va_list args);
+
+ /**
+ * Recieve an AT response
+ *
+ * Recieves a formatted response using scanf style formatting
+ * @see 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.
+ *
+ * @param response scanf-like format string of response to expect
+ * @param ... all scanf-like arguments to extract from response
+ * @return true only if response is successfully matched
+ */
+ bool recv(const char *response, ...);
+ bool vrecv(const char *response, va_list args);
/**
* Issue AT commands
*
- * Sends formatted command and waits for formatted response.
- * Any recieved data that does not match the specified response
- * is ignored until the timeout has passed.
- *
- * Both the command and response use format strings that are internally
- * passed to printf and scanf respectively.
- * @see printf
- * @see scanf
- *
- * Commands are expected to be formatted with specified delimiters.
- * Sent commands are appended with the delimiter, and responses are
- * seperated by delimiters before attempting to parse.
+ * Issues formatted commands and parses formatted responses.
+ * A command call is identical to a send call followed by a recv call.
+ * @see send, recv
*
* Here are some examples:
* @code
@@ -113,31 +134,32 @@
* @endcode
*
* @param command printf-like format string of command to send
- * @param response scanf-like format string of response to parse
+ * @param response scanf-like format string of response to expect
* @param ... all printf-like arguments to insert into command followed by
- * all scanf-like pointers to destinations for response values
+ * all scanf-like arguments to extract from response
* @return true only if response is successfully matched
*/
bool command(const char *command, const char *response, ...);
+ bool vcommand(const char *command, const char *response, va_list args);
/**
- * Write a single byte to the underlying stream
- *
- * @param c The byte to write
- * @return The byte that was written or -1 during a timeout
- */
+ * Write a single byte to the underlying stream
+ *
+ * @param c The byte to write
+ * @return The byte that was written or -1 during a timeout
+ */
int putc(char c);
/**
- * Get a single byte from the underlying stream
- *
- * @return The byte that was read or -1 during a timeout
- */
+ * Get a single byte from the underlying stream
+ *
+ * @return The byte that was read or -1 during a timeout
+ */
int getc();
/**
- * Flushes the underlying stream
- */
+ * Flushes the underlying stream
+ */
void flush();
};