Merging changes from ATParser towards parser unification

pull/5212/head
Senthil Ramakrishnan 2017-09-27 10:46:01 -05:00
parent 24418b43da
commit 7ffa3ddaaf
2 changed files with 51 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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