Skip to content

Cellular: Fix ATHandler URC processing #8790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions features/cellular/framework/AT/ATHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char
_previous_at_timeout(timeout),
_at_send_delay(send_delay),
_last_response_stop(0),
_processing(false),
_oob_queued(false),
_ref_count(1),
_is_fh_usable(true),
_stop_tag(NULL),
Expand Down Expand Up @@ -223,9 +223,8 @@ bool ATHandler::find_urc_handler(const char *prefix)

void ATHandler::event()
{
// _processing must be set before filehandle write/read to avoid repetitive sigio events
if (!_processing) {
_processing = true;
if (!_oob_queued) {
_oob_queued = true;
(void) _queue.call(Callback<void(void)>(this, &ATHandler::process_oob));
}
}
Expand All @@ -235,14 +234,12 @@ void ATHandler::lock()
#ifdef AT_HANDLER_MUTEX
_fileHandleMutex.lock();
#endif
_processing = true;
clear_error();
_start_time = rtos::Kernel::get_ms_count();
}

void ATHandler::unlock()
{
_processing = false;
#ifdef AT_HANDLER_MUTEX
_fileHandleMutex.unlock();
#endif
Expand Down Expand Up @@ -283,19 +280,22 @@ void ATHandler::process_oob()
return;
}
lock();
_oob_queued = false;
if (_fileHandle->readable() || (_recv_pos < _recv_len)) {
tr_debug("AT OoB readable %d, len %u", _fileHandle->readable(), _recv_len - _recv_pos);
_current_scope = NotSet;
uint32_t timeout = _at_timeout;
_at_timeout = PROCESS_URC_TIME;
while (true) {
_at_timeout = timeout;
if (match_urc()) {
if (!(_fileHandle->readable() || (_recv_pos < _recv_len))) {
break; // we have nothing to read anymore
}
} else if (mem_str(_recv_buff, _recv_len, CRLF, CRLF_LENGTH)) { // If no match found, look for CRLF and consume everything up to CRLF
_at_timeout = PROCESS_URC_TIME;
consume_to_tag(CRLF, true);
} else {
_at_timeout = PROCESS_URC_TIME;
if (!fill_buffer()) {
reset_buffer(); // consume anything that could not be handled
break;
Expand Down
2 changes: 1 addition & 1 deletion features/cellular/framework/AT/ATHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class ATHandler {
uint16_t _at_send_delay;
uint64_t _last_response_stop;

bool _processing;
bool _oob_queued;
int32_t _ref_count;
bool _is_fh_usable;

Expand Down