Parser for AT commands and similar protocols

Dependencies:   BufferedSerial

Dependents:   Final Final

Fork of ATParser by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
geky
Date:
Fri Jul 17 16:38:44 2015 +0000
Parent:
3:32915b9467d2
Child:
5:26bc9255b751
Commit message:
Exposed the underlying putc/getc methods for collecting raw data

Changed in this revision

ATParser.cpp Show annotated file Show diff for this revision Revisions of this file
ATParser.h Show annotated file Show diff for this revision Revisions of this file
--- a/ATParser.cpp	Fri Jul 17 16:31:58 2015 +0000
+++ b/ATParser.cpp	Fri Jul 17 16:38:44 2015 +0000
@@ -26,7 +26,7 @@
 
 
 // getc/putc handling with timeouts
-int ATParser::_putc(char c) {
+int ATParser::putc(char c) {
     Timer timer;
     timer.start();
     
@@ -39,7 +39,7 @@
     }
 }
 
-int ATParser::_getc() {
+int ATParser::getc() {
     Timer timer;
     timer.start();
     
@@ -52,7 +52,7 @@
     }
 }
 
-void ATParser::_flush() {
+void ATParser::flush() {
     while (_serial->readable())
         _serial->getc();
 }
@@ -61,13 +61,13 @@
 // getline/putline handling with timeouts/bounds checking
 bool ATParser::_putline(const char *line) {    
     for (int i = 0; line[i]; i++) {
-        if (_putc(line[i]) < 0)
+        if (putc(line[i]) < 0)
             return false;
     }
     
     // Finish with newline
     for (int i = 0; _delimiter[i]; i++) {
-        if (_putc(_delimiter[i]) < 0)
+        if (putc(_delimiter[i]) < 0)
             return false;
     }
     
@@ -82,7 +82,7 @@
     int i = 0;
     
     while (i < size) {
-        int c = _getc();
+        int c = getc();
         if (c < 0)
             return false;
             
@@ -107,7 +107,7 @@
     va_list args;
     va_start(args, response);
     
-    _flush();
+    flush();
     
     // Create and send command
     if (command) {
--- a/ATParser.h	Fri Jul 17 16:31:58 2015 +0000
+++ b/ATParser.h	Fri Jul 17 16:38:44 2015 +0000
@@ -37,14 +37,7 @@
     
     // Parsing information
     const char *_delimiter;
-    int _delim_size;
-    
-    // Helper methods for putc/getc with timeout
-    int _putc(char c);
-    int _getc();
-    
-    // Flush used to clear serial connection
-    void _flush();
+    int _delim_size;    
     
     // Helper methods for reading/writing lines with 
     // timeout and buffer limitations
@@ -126,5 +119,25 @@
     * @return true only if response is successfully matched
     */
     bool command(const char *command, const char *response, ...);
+    
+    /** 
+     * 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
+     */
+    int getc();
+    
+    /**
+     * Flushes the underlying stream
+     */
+    void flush();
 };