From 66c15d6412f27b351d58067a1ae5fafe96598e24 Mon Sep 17 00:00:00 2001 From: Mirela Chirica Date: Tue, 16 Apr 2019 13:04:48 +0300 Subject: [PATCH] Cellular: Added BG96 handling for socket closing URC --- .../BG96/QUECTEL_BG96_CellularStack.cpp | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp index 4cd9e00775e4..3bd275e40773 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp @@ -20,6 +20,12 @@ using namespace mbed; +const char *QIURC_RECV = "recv"; +const uint8_t QIURC_RECV_LENGTH = 4; +const char *QIURC_CLOSED = "closed"; +const uint8_t QIURC_CLOSED_LENGTH = 6; +const uint8_t MAX_QIURC_LENGTH = QIURC_CLOSED_LENGTH; + QUECTEL_BG96_CellularStack::QUECTEL_BG96_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : AT_CellularStack(atHandler, cid, stack_type) { _at.set_urc_handler("+QIURC:", mbed::Callback(this, &QUECTEL_BG96_CellularStack::urc_qiurc)); @@ -110,20 +116,29 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle, void QUECTEL_BG96_CellularStack::urc_qiurc() { - int sock_id = 0; - + char urc_string[MAX_QIURC_LENGTH + 1]; _at.lock(); - (void) _at.skip_param(); - sock_id = _at.read_int(); - _at.unlock(); + int urc_string_length = _at.read_string(urc_string, sizeof(urc_string)); + int sock_id = _at.read_int(); + nsapi_error_t err = _at.unlock_return_error(); + + if (err == NSAPI_ERROR_OK) { + + bool recv = memcmp(urc_string, "recv", urc_string_length) == 0; + bool closed = memcmp(urc_string, "closed", urc_string_length) == 0; + + CellularSocket *sock = find_socket(sock_id); + if (sock) { + if (closed) { + tr_error("Socket closed %d", sock_id); + sock->closed = true; + } - for (int i = 0; i < get_max_socket_count(); i++) { - CellularSocket *sock = _socket[i]; - if (sock && sock->id == sock_id) { - if (sock->_cb) { - sock->_cb(sock->_data); + if (recv || closed) { + if (sock && sock->_cb) { + sock->_cb(sock->_data); + } } - break; } } }