Parser for AT commands and similar protocols

Dependencies:   BufferedSerial

Dependents:   ESP8266 xdot-passthru Lab_10 Lab9 ... more

Fork of ATParser by NetworkSocketAPI

Revision:
13:46a18ad08efc
Parent:
12:7d3c3f7ce928
diff -r 7d3c3f7ce928 -r 46a18ad08efc ATParser.cpp
--- a/ATParser.cpp	Thu Feb 18 15:59:15 2016 -0600
+++ b/ATParser.cpp	Thu Feb 18 16:01:03 2016 -0600
@@ -229,10 +229,6 @@
         int j = 0;
 
         while (true) {
-            // Ran out of space
-            if (j+1 >= _buffer_size - offset) {
-                return false;
-            }
             // Recieve next character
             int c = getc();
             if (c < 0) {
@@ -260,8 +256,11 @@
                 break;
             }
 
-            // Clear the buffer when we hit a newline
-            if (strcmp(&_buffer[offset + j-_delim_size], _delimiter) == 0) {
+            // Clear the buffer when we hit a newline or ran out of space
+            // running out of space usually means we ran into binary data
+            if (j+1 >= _buffer_size - offset ||
+                strcmp(&_buffer[offset + j-_delim_size], _delimiter) == 0) {
+
                 debug_if(dbg_on, "AT< %s", _buffer+offset);
                 j = 0;
             }