@@ -215,7 +215,8 @@ bool ATCmdParser::vrecv(const char *response, std::va_list args)
215
215
restart:
216
216
_aborted = false ;
217
217
// Iterate through each line in the expected response
218
- while (response[0 ]) {
218
+ // response being NULL means we just want to check for OOBs
219
+ while (!response || response[0 ]) {
219
220
// Since response is const, we need to copy it into our buffer to
220
221
// add the line's null terminator and clobber value-matches with asterisks.
221
222
//
@@ -224,7 +225,7 @@ bool ATCmdParser::vrecv(const char *response, std::va_list args)
224
225
int offset = 0 ;
225
226
bool whole_line_wanted = false ;
226
227
227
- while (response[i]) {
228
+ while (response && response [i]) {
228
229
if (response[i] == ' %' && response[i + 1 ] != ' %' && response[i + 1 ] != ' *' ) {
229
230
_buffer[offset++] = ' %' ;
230
231
_buffer[offset++] = ' *' ;
@@ -257,6 +258,11 @@ bool ATCmdParser::vrecv(const char *response, std::va_list args)
257
258
int j = 0 ;
258
259
259
260
while (true ) {
261
+ // If just peeking for OOBs, and at start of line, check
262
+ // readability
263
+ if (!response && j == 0 && !_fh->readable ()) {
264
+ return false ;
265
+ }
260
266
// Receive next character
261
267
int c = getc ();
262
268
if (c < 0 ) {
@@ -284,6 +290,7 @@ bool ATCmdParser::vrecv(const char *response, std::va_list args)
284
290
if ((unsigned )j == oob->len && memcmp (
285
291
oob->prefix , _buffer + offset, oob->len ) == 0 ) {
286
292
debug_if (_dbg_on, " AT! %s\n " , oob->prefix );
293
+ _oob_cb_count++;
287
294
oob->cb ();
288
295
289
296
if (_aborted) {
@@ -302,7 +309,7 @@ bool ATCmdParser::vrecv(const char *response, std::va_list args)
302
309
// Don't attempt scanning until we get delimiter if they included it in format
303
310
// This allows recv("Foo: %s\n") to work, and not match with just the first character of a string
304
311
// (scanf does not itself match whitespace in its format string, so \n is not significant to it)
305
- } else {
312
+ } else if (response) {
306
313
sscanf (_buffer + offset, _buffer, &count);
307
314
}
308
315
@@ -388,52 +395,9 @@ void ATCmdParser::abort()
388
395
389
396
bool ATCmdParser::process_oob ()
390
397
{
391
- if (!_fh->readable ()) {
392
- return false ;
393
- }
394
-
395
- int i = 0 ;
396
- while (true ) {
397
- // Receive next character
398
- int c = getc ();
399
- if (c < 0 ) {
400
- return false ;
401
- }
402
- // Simplify newlines (borrowed from retarget.cpp)
403
- if ((c == CR && _in_prev != LF) ||
404
- (c == LF && _in_prev != CR)) {
405
- _in_prev = c;
406
- c = ' \n ' ;
407
- } else if ((c == CR && _in_prev == LF) ||
408
- (c == LF && _in_prev == CR)) {
409
- _in_prev = c;
410
- // onto next character
411
- continue ;
412
- } else {
413
- _in_prev = c;
414
- }
415
- _buffer[i++] = c;
416
- _buffer[i] = 0 ;
417
-
418
- // Check for oob data
419
- struct oob *oob = _oobs;
420
- while (oob) {
421
- if (i == (int )oob->len && memcmp (
422
- oob->prefix , _buffer, oob->len ) == 0 ) {
423
- debug_if (_dbg_on, " AT! %s\r\n " , oob->prefix );
424
- oob->cb ();
425
- return true ;
426
- }
427
- oob = oob->next ;
428
- }
429
-
430
- // Clear the buffer when we hit a newline or ran out of space
431
- // running out of space usually means we ran into binary data
432
- if (((i + 1 ) >= _buffer_size) || (c == ' \n ' )) {
433
- debug_if (_dbg_on, " AT< %s" , _buffer);
434
- i = 0 ;
435
- }
436
- }
398
+ int pre_count = _oob_cb_count;
399
+ recv (NULL );
400
+ return _oob_cb_count != pre_count;
437
401
}
438
402
439
403
}
0 commit comments