Skip to content

Commit 04242c7

Browse files
Hasnain VirkAri Parkkila
authored andcommitted
Updating BG96 to accomodate socket id assignment
Socket ids will be assigned in the create_socket_impl(...) method. This is the point where an actual socket creation at the modem takes place.
1 parent bded22e commit 04242c7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
6969

7070
if ((_at.get_last_error() == NSAPI_ERROR_OK) && err) {
7171
if (err == BG96_SOCKET_BIND_FAIL) {
72-
socket->created = false;
72+
socket->id = -1;
7373
_at.unlock();
7474
return NSAPI_ERROR_PARAMETER;
7575
}
@@ -106,7 +106,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
106106
_at.unlock();
107107

108108
if ((ret_val == NSAPI_ERROR_OK) && (modem_connect_id == request_connect_id)) {
109-
socket->created = true;
109+
socket->id = request_connect_id;
110110
socket->remoteAddress = address;
111111
socket->connected = true;
112112
return NSAPI_ERROR_OK;
@@ -182,10 +182,14 @@ void QUECTEL_BG96_CellularStack::handle_open_socket_response(int &modem_connect_
182182
nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *socket)
183183
{
184184
int modem_connect_id = -1;
185-
int request_connect_id = socket->id;
186185
int remote_port = 0;
187186
int err = -1;
188187

188+
int request_connect_id = find_socket_index(socket);
189+
// assert here as its a programming error if the socket container doesn't contain
190+
// specified handle
191+
MBED_ASSERT(request_connect_id != -1);
192+
189193
if (socket->proto == NSAPI_UDP && !socket->connected) {
190194
_at.cmd_start("AT+QIOPEN=");
191195
_at.write_int(_cid);
@@ -201,7 +205,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
201205

202206
if ((_at.get_last_error() == NSAPI_ERROR_OK) && err) {
203207
if (err == BG96_SOCKET_BIND_FAIL) {
204-
socket->created = false;
208+
socket->id = -1;
205209
return NSAPI_ERROR_PARAMETER;
206210
}
207211
_at.cmd_start("AT+QICLOSE=");
@@ -233,7 +237,7 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
233237

234238
if ((_at.get_last_error() == NSAPI_ERROR_OK) && err) {
235239
if (err == BG96_SOCKET_BIND_FAIL) {
236-
socket->created = false;
240+
socket->id = -1;
237241
return NSAPI_ERROR_PARAMETER;
238242
}
239243
_at.cmd_start("AT+QICLOSE=");
@@ -261,7 +265,9 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
261265

262266
nsapi_error_t ret_val = _at.get_last_error();
263267

264-
socket->created = ((ret_val == NSAPI_ERROR_OK) && (modem_connect_id == request_connect_id));
268+
if (ret_val == NSAPI_ERROR_OK && (modem_connect_id == request_connect_id)) {
269+
socket->id = request_connect_id;
270+
}
265271

266272
return ret_val;
267273
}

0 commit comments

Comments
 (0)