Parser for AT commands and similar protocols

Dependencies:   BufferedSerial

Revision:
9:9bcb87c27208
Parent:
8:91515b168c70
Child:
10:553f9ffaf657
diff -r 91515b168c70 -r 9bcb87c27208 ATParser.h
--- a/ATParser.h	Mon Jul 20 20:56:30 2015 +0000
+++ b/ATParser.h	Mon Jul 20 21:28:39 2015 +0000
@@ -25,22 +25,22 @@
 
  
 /**
- * Parser class for parsing AT commands
- *
- * Here are some examples:
- * @code
- * 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");
- * @endcode
- */
+* Parser class for parsing AT commands
+*
+* Here are some examples:
+* @code
+* 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");
+* @endcode
+*/
 class ATParser {
 private:
     // Serial information
@@ -101,7 +101,7 @@
     * Sends an AT command
     *
     * Sends a formatted command using printf style formatting
-    * @see printf
+    * @see ::printf
     *
     * @param command printf-like format string of command to send which 
     *                is appended with the specified delimiter
@@ -115,7 +115,7 @@
     * Recieve an AT response
     *
     * Recieves a formatted response using scanf style formatting
-    * @see scanf
+    * @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
@@ -148,7 +148,7 @@
     *
     * @param data the array of bytes to write
     * @param size number of bytes to write
-    * @return number of bytes written
+    * @return number of bytes written or -1 on failure
     */
     int write(const char *data, int size);
     
@@ -157,11 +157,33 @@
     *
     * @param data the destination for the read bytes
     * @param size number of bytes to read
-    * @return number of bytes read
+    * @return number of bytes read or -1 on failure
     */
     int read(char *data, int size);
     
     /**
+    * Direct printf to underlying stream
+    * @see ::printf
+    *
+    * @param format format string to pass to printf
+    * @param ... arguments to printf
+    * @return number of bytes written or -1 on failure
+    */
+    int printf(const char *format, ...);
+    int vprintf(const char *format, va_list args);
+    
+    /**
+    * Direct scanf on underlying stream
+    * @see ::scanf
+    *
+    * @param format format string to pass to scanf
+    * @param ... arguments to scanf
+    * @return number of bytes read or -1 on failure
+    */
+    int scanf(const char *format, ...);
+    int vscanf(const char *format, va_list args);
+    
+    /**
     * Flushes the underlying stream
     */
     void flush();