|
20 | 20 |
|
21 | 21 | using namespace mbed;
|
22 | 22 |
|
| 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 | + |
23 | 29 | QUECTEL_BG96_CellularStack::QUECTEL_BG96_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : AT_CellularStack(atHandler, cid, stack_type)
|
24 | 30 | {
|
25 | 31 | _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,
|
110 | 116 |
|
111 | 117 | void QUECTEL_BG96_CellularStack::urc_qiurc()
|
112 | 118 | {
|
113 |
| - int sock_id = 0; |
114 |
| - |
| 119 | + char urc_string[MAX_QIURC_LENGTH + 1]; |
115 | 120 | _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 | + } |
119 | 138 |
|
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) { |
123 | 140 | if (sock->_cb) {
|
124 | 141 | sock->_cb(sock->_data);
|
125 | 142 | }
|
126 |
| - break; |
127 | 143 | }
|
128 | 144 | }
|
129 | 145 | }
|
|
0 commit comments