Skip to content

Commit

Permalink
Merge pull request #5212 from SenRamakri/sen_ATCmdParserChanges2
Browse files Browse the repository at this point in the history
Merging changes from ATParser towards parser unification
  • Loading branch information
theotherjimmy committed Oct 5, 2017
2 parents da138f2 + 3e1459b commit 0dc264f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
41 changes: 41 additions & 0 deletions platform/ATCmdParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}


10 changes: 10 additions & 0 deletions platform/ATCmdParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ class ATCmdParser : private NonCopyable<ATCmdParser>
* 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

Expand Down

0 comments on commit 0dc264f

Please sign in to comment.