Skip to content

Commit f9aaee5

Browse files
Support added for async sockets
1 parent 122e771 commit f9aaee5

File tree

4 files changed

+18
-29
lines changed

4 files changed

+18
-29
lines changed

features/cellular/TESTS/api/cellular_network/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ static void test_detach()
371371
TEST_ASSERT(st == NSAPI_STATUS_DISCONNECTED);
372372

373373
TEST_ASSERT(nw->detach() == NSAPI_ERROR_OK);
374+
// wait to process URC's, received after detach
375+
rtos::Thread::wait(50);
374376
st = nw->get_connection_status();
375377
TEST_ASSERT(st == NSAPI_STATUS_DISCONNECTED);
376378
}

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -326,20 +326,3 @@ const char *UBLOX_AT_CellularNetwork::get_gateway()
326326
{
327327
return get_ip_address();
328328
}
329-
330-
nsapi_error_t UBLOX_AT_CellularNetwork::detach()
331-
{
332-
nsapi_error_t err;
333-
334-
_at.lock();
335-
_at.cmd_start("AT+CGATT=0");
336-
_at.cmd_stop();
337-
_at.resp_start();
338-
_at.resp_stop();
339-
err = _at.unlock_return_error();
340-
341-
// wait added to process CGREG and UUPSDD URC, which comes after detach.
342-
wait_ms(50);
343-
344-
return err;
345-
}

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularNetwork.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class UBLOX_AT_CellularNetwork : public AT_CellularNetwork
3434

3535
virtual const char *get_gateway();
3636

37-
virtual nsapi_error_t detach();
3837
protected:
3938
virtual NetworkStack *get_stack();
4039

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include "UBLOX_AT_CellularStack.h"
19+
#include "mbed_poll.h"
1920

2021
using namespace mbed;
2122
using namespace mbed_cellular_util;
@@ -192,6 +193,12 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
192193
int sent_len = 0;
193194
uint8_t ch = 0, cont = 50;
194195

196+
pollfh fhs;
197+
fhs.fh = _at.get_file_handle();
198+
fhs.events = POLLIN;
199+
int pollCount;
200+
201+
socket->rx_avail = false;
195202
if (socket->proto == NSAPI_UDP) {
196203
if (size > UBLOX_MAX_PACKET_SIZE) {
197204
return NSAPI_ERROR_PARAMETER;
@@ -202,11 +209,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
202209
_at.write_int(address.get_port());
203210
_at.write_int(size);
204211
_at.cmd_stop();
205-
wait_ms(50);
206-
while (ch != '@' && cont > 0) {
207-
_at.read_bytes(&ch, 1);
208-
cont--;
209-
}
212+
pollCount = poll(&fhs, 1, 50);
210213
_at.write_bytes((uint8_t *)data, size);
211214

212215
_at.resp_start("+USOST:");
@@ -231,11 +234,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
231234
_at.write_int(socket->id);
232235
_at.write_int(blk);
233236
_at.cmd_stop();
234-
wait_ms(50);
235-
while (ch != '@' && cont > 0) {
236-
_at.read_bytes(&ch, 1);
237-
cont--;
238-
}
237+
pollCount = poll(&fhs, 1, 50);
239238
_at.write_bytes((uint8_t *)buf, blk);
240239

241240
_at.resp_start("+USOWR:");
@@ -254,7 +253,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
254253
}
255254

256255
if (success && _at.get_last_error() == NSAPI_ERROR_OK) {
257-
socket->rx_avail = false;
258256
return size - count;
259257
}
260258
}
@@ -275,6 +273,13 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke
275273
int port = 0;
276274
Timer timer;
277275

276+
if (!socket->rx_avail) {
277+
_at.process_oob();
278+
if (!socket->rx_avail) {
279+
return NSAPI_ERROR_WOULD_BLOCK;
280+
}
281+
}
282+
278283
timer.start();
279284
if (socket->proto == NSAPI_UDP) {
280285
while (success && (size > 0)) {

0 commit comments

Comments
 (0)