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

View File

@ -432,7 +432,7 @@ private:
void rewind_buffer();
// Reads from serial to receiving buffer.
// 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);