mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Revision:
188:bcfe06ba3d64
Parent:
187:0387e8f68319
Child:
189:f392fc9709a3
--- a/platform/ATCmdParser.cpp	Thu Sep 06 13:40:20 2018 +0100
+++ b/platform/ATCmdParser.cpp	Thu Nov 08 11:46:34 2018 +0000
@@ -210,7 +210,8 @@
 restart:
     _aborted = false;
     // Iterate through each line in the expected response
-    while (response[0]) {
+    // response being NULL means we just want to check for OOBs
+    while (!response || response[0]) {
         // Since response is const, we need to copy it into our buffer to
         // add the line's null terminator and clobber value-matches with asterisks.
         //
@@ -219,7 +220,7 @@
         int offset = 0;
         bool whole_line_wanted = false;
 
-        while (response[i]) {
+        while (response && response[i]) {
             if (response[i] == '%' && response[i + 1] != '%' && response[i + 1] != '*') {
                 _buffer[offset++] = '%';
                 _buffer[offset++] = '*';
@@ -252,6 +253,11 @@
         int j = 0;
 
         while (true) {
+            // If just peeking for OOBs, and at start of line, check
+            // readability
+            if (!response && j == 0 && !_fh->readable()) {
+                return false;
+            }
             // Receive next character
             int c = getc();
             if (c < 0) {
@@ -279,6 +285,7 @@
                 if ((unsigned)j == oob->len && memcmp(
                             oob->prefix, _buffer + offset, oob->len) == 0) {
                     debug_if(_dbg_on, "AT! %s\n", oob->prefix);
+                    _oob_cb_count++;
                     oob->cb();
 
                     if (_aborted) {
@@ -297,7 +304,7 @@
                 // Don't attempt scanning until we get delimiter if they included it in format
                 // This allows recv("Foo: %s\n") to work, and not match with just the first character of a string
                 // (scanf does not itself match whitespace in its format string, so \n is not significant to it)
-            } else {
+            } else if (response) {
                 sscanf(_buffer + offset, _buffer, &count);
             }
 
@@ -383,52 +390,9 @@
 
 bool ATCmdParser::process_oob()
 {
-    if (!_fh->readable()) {
-        return false;
-    }
-
-    int i = 0;
-    while (true) {
-        // Receive next character
-        int c = getc();
-        if (c < 0) {
-            return false;
-        }
-        // Simplify newlines (borrowed from retarget.cpp)
-        if ((c == CR && _in_prev != LF) ||
-                (c == LF && _in_prev != CR)) {
-            _in_prev = c;
-            c = '\n';
-        } else if ((c == CR && _in_prev == LF) ||
-                   (c == LF && _in_prev == CR)) {
-            _in_prev = c;
-            // onto next character
-            continue;
-        } else {
-            _in_prev = c;
-        }
-        _buffer[i++] = c;
-        _buffer[i] = 0;
-
-        // Check for oob data
-        struct oob *oob = _oobs;
-        while (oob) {
-            if (i == (int)oob->len && memcmp(
-                        oob->prefix, _buffer, oob->len) == 0) {
-                debug_if(_dbg_on, "AT! %s\r\n", oob->prefix);
-                oob->cb();
-                return true;
-            }
-            oob = oob->next;
-        }
-
-        // 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 (((i + 1) >= _buffer_size) || (c == '\n')) {
-            debug_if(_dbg_on, "AT< %s", _buffer);
-            i = 0;
-        }
-    }
+    int pre_count = _oob_cb_count;
+    recv(NULL);
+    return _oob_cb_count != pre_count;
 }