Skip to content

Commit 7ffa3dd

Browse files
committed
Merging changes from ATParser towards parser unification
1 parent 24418b4 commit 7ffa3dd

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

platform/ATCmdParser.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,44 @@ void ATCmdParser::abort()
380380
{
381381
_aborted = true;
382382
}
383+
384+
bool ATCmdParser::process_oob()
385+
{
386+
if (!_fh->readable()) {
387+
return false;
388+
}
389+
390+
int i = 0;
391+
while (true) {
392+
// Receive next character
393+
int c = getc();
394+
if (c < 0) {
395+
return false;
396+
}
397+
_buffer[i++] = c;
398+
_buffer[i] = 0;
399+
400+
// Check for oob data
401+
struct oob *oob = _oobs;
402+
while ( oob ) {
403+
if (i == (int)oob->len && memcmp(
404+
oob->prefix, _buffer, oob->len) == 0) {
405+
debug_if(_dbg_on, "AT! %s\r\n", oob->prefix);
406+
oob->cb();
407+
return true;
408+
}
409+
oob = oob->next;
410+
}
411+
412+
// Clear the buffer when we hit a newline or ran out of space
413+
// running out of space usually means we ran into binary data
414+
if (i+1 >= _buffer_size ||
415+
strcmp(&_buffer[i-_output_delim_size], _output_delimiter) == 0) {
416+
417+
debug_if(_dbg_on, "AT< %s", _buffer);
418+
i = 0;
419+
}
420+
}
421+
}
422+
423+

platform/ATCmdParser.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ class ATCmdParser : private NonCopyable<ATCmdParser>
288288
* recv operation.
289289
*/
290290
void abort();
291+
292+
/**
293+
* Process out-of-band data
294+
*
295+
* Process out-of-band data in the receive buffer. This function
296+
* returns immediately if there is no data to process.
297+
*
298+
* @return true if oob data processed, false otherwise
299+
*/
300+
bool process_oob(void);
291301
};
292302
} //namespace mbed
293303

0 commit comments

Comments
 (0)