Cellular: ATHandler yield to wait review fixes

pull/6744/head
Ari Parkkila 2018-05-03 14:42:26 +03:00
parent 559abd3009
commit 9b896a16bb
2 changed files with 66 additions and 60 deletions

View File

@ -17,6 +17,7 @@
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include "ATHandler.h" #include "ATHandler.h"
#include "mbed_poll.h" #include "mbed_poll.h"
#include "FileHandle.h" #include "FileHandle.h"
@ -290,8 +291,7 @@ void ATHandler::process_oob()
break; // we have nothing to read anymore break; // we have nothing to read anymore
} }
_start_time = rtos::Kernel::get_ms_count(); // time to process next (potential) URC _start_time = rtos::Kernel::get_ms_count(); // time to process next (potential) URC
} else if (mem_str(_recv_buff, _recv_len, CRLF, CRLF_LENGTH)) { } else if (mem_str(_recv_buff, _recv_len, CRLF, CRLF_LENGTH)) { // If no match found, look for CRLF and consume everything up to CRLF
// If no match found, look for CRLF and consume everything up to CRLF
consume_to_tag(CRLF, true); consume_to_tag(CRLF, true);
} else { } else {
if (!fill_buffer()) { if (!fill_buffer()) {
@ -335,7 +335,7 @@ void ATHandler::rewind_buffer()
} }
} }
bool ATHandler::fill_buffer() bool ATHandler::fill_buffer(bool wait_for_timeout)
{ {
tr_debug("%s", __func__); tr_debug("%s", __func__);
// Reset buffer when full // Reset buffer when full
@ -343,8 +343,20 @@ bool ATHandler::fill_buffer()
reset_buffer(); reset_buffer();
} }
int timeout = (_start_time + _at_timeout) - rtos::Kernel::get_ms_count(); int timeout;
if (timeout >= 0) { if (wait_for_timeout) {
uint64_t now = rtos::Kernel::get_ms_count();
if (now >= _start_time + _at_timeout) {
timeout = 0;
} else if ( _start_time + _at_timeout - now > INT_MAX) {
timeout = INT_MAX;
} else {
timeout = _start_time + _at_timeout - now;
}
} else {
timeout = 0;
}
pollfh fhs; pollfh fhs;
fhs.fh = _fileHandle; fhs.fh = _fileHandle;
fhs.events = POLLIN; fhs.events = POLLIN;
@ -356,9 +368,10 @@ bool ATHandler::fill_buffer()
return true; return true;
} }
} }
}
if (wait_for_timeout) {
set_error(NSAPI_ERROR_DEVICE_ERROR); set_error(NSAPI_ERROR_DEVICE_ERROR);
}
return false; return false;
} }
@ -800,17 +813,11 @@ void ATHandler::resp_start(const char *prefix, bool stop)
// Try get as much data as possible // Try get as much data as possible
rewind_buffer(); rewind_buffer();
if (!fill_buffer()) { (void)fill_buffer(false);
tr_error("fill failed %s", prefix);
return;
}
if (prefix) { if (prefix) {
if ((strlen(prefix) < sizeof(_info_resp_prefix))) { MBED_ASSERT(strlen(prefix) < BUFF_SIZE);
strcpy(_info_resp_prefix, prefix); strcpy(_info_resp_prefix, prefix); // copy prefix so we can later use it without having to provide again for info_resp
} else {
MBED_ASSERT(0);
}
} }
set_scope(RespType); set_scope(RespType);
@ -1133,9 +1140,8 @@ bool ATHandler::check_cmd_send()
void ATHandler::flush() void ATHandler::flush()
{ {
while (_fileHandle->readable()) {
reset_buffer(); reset_buffer();
(void) fill_buffer(); while (fill_buffer(false)) {
reset_buffer();
} }
reset_buffer();
} }

View File

@ -432,7 +432,7 @@ private:
void rewind_buffer(); void rewind_buffer();
// Reads from serial to receiving buffer. // Reads from serial to receiving buffer.
// Returns true on successful read OR false on timeout. // Returns true on successful read OR false on timeout.
bool fill_buffer(); bool fill_buffer(bool wait_for_timeout = true);
void set_tag(tag_t* tag_dest, const char *tag_seq); void set_tag(tag_t* tag_dest, const char *tag_seq);