From 7ffa3ddaafc38fa54d0fc328c45f8ac4394b4024 Mon Sep 17 00:00:00 2001 From: Senthil Ramakrishnan Date: Wed, 27 Sep 2017 10:46:01 -0500 Subject: [PATCH] Merging changes from ATParser towards parser unification --- platform/ATCmdParser.cpp | 41 ++++++++++++++++++++++++++++++++++++++++ platform/ATCmdParser.h | 10 ++++++++++ 2 files changed, 51 insertions(+) diff --git a/platform/ATCmdParser.cpp b/platform/ATCmdParser.cpp index 6200f1fa4b..3e5ee2cde2 100644 --- a/platform/ATCmdParser.cpp +++ b/platform/ATCmdParser.cpp @@ -380,3 +380,44 @@ void ATCmdParser::abort() { _aborted = true; } + +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; + } + _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 || + strcmp(&_buffer[i-_output_delim_size], _output_delimiter) == 0) { + + debug_if(_dbg_on, "AT< %s", _buffer); + i = 0; + } + } +} + + diff --git a/platform/ATCmdParser.h b/platform/ATCmdParser.h index 03b1ef6b2a..1201a6055f 100644 --- a/platform/ATCmdParser.h +++ b/platform/ATCmdParser.h @@ -288,6 +288,16 @@ public: * recv operation. */ void abort(); + + /** + * Process out-of-band data + * + * Process out-of-band data in the receive buffer. This function + * returns immediately if there is no data to process. + * + * @return true if oob data processed, false otherwise + */ + bool process_oob(void); }; } //namespace mbed