Skip to content

Commit 3fffa3b

Browse files
Hasnain VirkAri Parkkila
authored andcommitted
Updating BG95 to accomodate socket id assignment
Changes to accomodate socket id assignment upon actual creation of the socket at the modem.
1 parent 0308cb8 commit 3fffa3b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ nsapi_error_t QUECTEL_BC95_CellularStack::socket_connect(nsapi_socket_t handle,
5151
CellularSocket *socket = (CellularSocket *)handle;
5252

5353
_at.lock();
54-
if (!socket->created) {
54+
if (socket->id == -1) {
5555
const nsapi_error_t error_create = create_socket_impl(socket);
5656
if (error_create != NSAPI_ERROR_OK) {
5757
return error_create;
@@ -187,23 +187,26 @@ nsapi_error_t QUECTEL_BC95_CellularStack::create_socket_impl(CellularSocket *soc
187187
// Check for duplicate socket id delivered by modem
188188
for (int i = 0; i < BC95_SOCKET_MAX; i++) {
189189
CellularSocket *sock = _socket[i];
190-
if (sock && sock->created && sock->id == sock_id) {
191-
tr_error("Duplicate socket index: %d created:%d, sock_id: %d", i, sock->created, sock_id);
190+
if (sock && sock->id != -1 && sock->id == sock_id) {
191+
tr_error("Duplicate socket index: %d, sock_id: %d", i, sock_id);
192192
return NSAPI_ERROR_NO_SOCKET;
193193
}
194194
}
195195

196196
tr_info("Socket create id: %d", sock_id);
197197

198198
socket->id = sock_id;
199-
socket->created = true;
200199

201200
return NSAPI_ERROR_OK;
202201
}
203202

204203
nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
205204
const void *data, nsapi_size_t size)
206205
{
206+
//AT_CellularStack::socket_sendto(...) will create a socket on modem if it wasn't
207+
// open already.
208+
MBED_ASSERT(socket->id != -1);
209+
207210
int sent_len = 0;
208211

209212
if (size > PACKET_SIZE_MAX) {
@@ -250,6 +253,10 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
250253
nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
251254
void *buffer, nsapi_size_t size)
252255
{
256+
//AT_CellularStack::socket_recvfrom(...) will create a socket on modem if it wasn't
257+
// open already.
258+
MBED_ASSERT(socket->id != -1);
259+
253260
nsapi_size_or_error_t recv_len = 0;
254261
int port;
255262
char ip_address[NSAPI_IP_SIZE];

0 commit comments

Comments
 (0)