Skip to content

Cellular: Added BG96 handling for socket closing URC #10411

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
Apr 18, 2019
Merged
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
Original file line number Diff line number Diff line change
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,30 @@ 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();
const int urc_string_length = _at.read_string(urc_string, sizeof(urc_string));
const int sock_id = _at.read_int();
const nsapi_error_t err = _at.unlock_return_error();

if (err != NSAPI_ERROR_OK) {
return;
}

bool recv = strcmp(urc_string, "recv") == 0;
bool closed = strcmp(urc_string, "closed") == 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 (recv || closed) {
if (sock->_cb) {
sock->_cb(sock->_data);
}
break;
}
}
}
Expand Down