Skip to content

Commit 287a1a8

Browse files
author
Ari Parkkila
committed
Cellular: AT handler review fixes
1 parent 3bdb6d1 commit 287a1a8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,13 @@ bool ATHandler::fill_buffer(bool wait_for_timeout)
358358
tr_debug("%s", __func__);
359359
// Reset buffer when full
360360
if (sizeof(_recv_buff) == _recv_len) {
361+
tr_error("AT overflow");
361362
reset_buffer();
362363
}
363364

364365
pollfh fhs;
365366
fhs.fh = _fileHandle;
366367
fhs.events = POLLIN;
367-
int timeout = 0;
368368
int count = poll(&fhs, 1, poll_timeout(wait_for_timeout));
369369
if (count > 0 && (fhs.revents & POLLIN)) {
370370
ssize_t len = _fileHandle->read(_recv_buff + _recv_len, sizeof(_recv_buff) - _recv_len);
@@ -374,10 +374,6 @@ bool ATHandler::fill_buffer(bool wait_for_timeout)
374374
}
375375
}
376376

377-
if (wait_for_timeout) {
378-
set_error(NSAPI_ERROR_DEVICE_ERROR);
379-
}
380-
381377
return false;
382378
}
383379

@@ -387,7 +383,8 @@ int ATHandler::get_char()
387383
tr_debug("%s", __func__);
388384
reset_buffer(); // try to read as much as possible
389385
if (!fill_buffer()) {
390-
tr_warn("AT TIMEOUT");
386+
tr_warn("AT timeout");
387+
set_error(NSAPI_ERROR_DEVICE_ERROR);
391388
return -1; // timeout to read
392389
}
393390
}
@@ -800,7 +797,10 @@ void ATHandler::resp(const char *prefix, bool check_urc)
800797
if (!prefix && ((_recv_len-_recv_pos) >= _max_resp_length)) {
801798
return;
802799
}
803-
(void)fill_buffer();
800+
if (!fill_buffer()) {
801+
// if we don't get any match and no data within timeout, set an error to indicate need for recovery
802+
set_error(NSAPI_ERROR_DEVICE_ERROR);
803+
}
804804
}
805805
}
806806

features/cellular/framework/AT/ATHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ class ATHandler
425425

426426
// Gets char from receiving buffer.
427427
// Resets and fills the buffer if all are already read (receiving position equals receiving length).
428+
// Returns a next char or -1 on failure (also sets error flag)
428429
int get_char();
429430
// Sets to 0 the reading position, reading length and the whole buffer content.
430431
void reset_buffer();

0 commit comments

Comments
 (0)