Skip to content

Commit

Permalink
Cellular: Added BG96 handling for socket closing URC
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirela Chirica committed Apr 16, 2019
1 parent 4401d41 commit 66c15d6
Showing 1 changed file with 26 additions and 11 deletions.
Expand Up @@ -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<void()>(this, &QUECTEL_BG96_CellularStack::urc_qiurc));
Expand Down Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit 66c15d6

Please sign in to comment.