Skip to content

Commit 46603f8

Browse files
authored
Merge pull request #10411 from mirelachirica/bg96_tcp_endpoint_close
Cellular: Added BG96 handling for socket closing URC
2 parents 8c69607 + 88ea0db commit 46603f8

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

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

Lines changed: 25 additions & 9 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,30 @@ 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+
const int urc_string_length = _at.read_string(urc_string, sizeof(urc_string));
122+
const int sock_id = _at.read_int();
123+
const nsapi_error_t err = _at.unlock_return_error();
124+
125+
if (err != NSAPI_ERROR_OK) {
126+
return;
127+
}
128+
129+
bool recv = strcmp(urc_string, "recv") == 0;
130+
bool closed = strcmp(urc_string, "closed") == 0;
131+
132+
CellularSocket *sock = find_socket(sock_id);
133+
if (sock) {
134+
if (closed) {
135+
tr_error("Socket closed %d", sock_id);
136+
sock->closed = true;
137+
}
119138

120-
for (int i = 0; i < get_max_socket_count(); i++) {
121-
CellularSocket *sock = _socket[i];
122-
if (sock && sock->id == sock_id) {
139+
if (recv || closed) {
123140
if (sock->_cb) {
124141
sock->_cb(sock->_data);
125142
}
126-
break;
127143
}
128144
}
129145
}

0 commit comments

Comments
 (0)