Skip to content

Commit 19fe543

Browse files
author
Mirela Chirica
committed
Cellular: Added BG96 handling for socket closing URC
1 parent 4401d41 commit 19fe543

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp

100644100755
Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
using namespace mbed;
2222

23+
const char *QIURC_RECV = "recv";
24+
const uint8_t QIURC_RECV_LENGTH = 4;
25+
const char *QIURC_CLOSED = "closed";
26+
const uint8_t QIURC_CLOSED_LENGTH = 6;
27+
const uint8_t MAX_QIURC_LENGTH = QIURC_CLOSED_LENGTH;
28+
2329
QUECTEL_BG96_CellularStack::QUECTEL_BG96_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : AT_CellularStack(atHandler, cid, stack_type)
2430
{
2531
_at.set_urc_handler("+QIURC:", mbed::Callback<void()>(this, &QUECTEL_BG96_CellularStack::urc_qiurc));
@@ -110,20 +116,29 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
110116

111117
void QUECTEL_BG96_CellularStack::urc_qiurc()
112118
{
113-
int sock_id = 0;
114-
119+
char urc_string[MAX_QIURC_LENGTH + 1];
115120
_at.lock();
116-
(void) _at.skip_param();
117-
sock_id = _at.read_int();
118-
_at.unlock();
121+
int urc_string_length = _at.read_string(urc_string, sizeof(urc_string));
122+
int sock_id = _at.read_int();
123+
nsapi_error_t err = _at.unlock_return_error();
124+
125+
if (err == NSAPI_ERROR_OK) {
126+
127+
bool recv = memcmp(urc_string, "recv", urc_string_length) == 0;
128+
bool closed = memcmp(urc_string, "closed", urc_string_length) == 0;
129+
130+
CellularSocket *sock = find_socket(sock_id);
131+
if (sock) {
132+
if (closed) {
133+
tr_error("Socket closed %d", sock_id);
134+
sock->closed = true;
135+
}
119136

120-
for (int i = 0; i < get_max_socket_count(); i++) {
121-
CellularSocket *sock = _socket[i];
122-
if (sock && sock->id == sock_id) {
123-
if (sock->_cb) {
124-
sock->_cb(sock->_data);
137+
if (recv || closed) {
138+
if (sock && sock->_cb) {
139+
sock->_cb(sock->_data);
140+
}
125141
}
126-
break;
127142
}
128143
}
129144
}

0 commit comments

Comments
 (0)