Support added for async sockets

pull/7619/head
mudassar-ublox 2018-08-15 14:52:57 +05:00
parent 122e771063
commit f9aaee55dd
4 changed files with 18 additions and 29 deletions

View File

@ -371,6 +371,8 @@ static void test_detach()
TEST_ASSERT(st == NSAPI_STATUS_DISCONNECTED);
TEST_ASSERT(nw->detach() == NSAPI_ERROR_OK);
// wait to process URC's, received after detach
rtos::Thread::wait(50);
st = nw->get_connection_status();
TEST_ASSERT(st == NSAPI_STATUS_DISCONNECTED);
}

View File

@ -326,20 +326,3 @@ const char *UBLOX_AT_CellularNetwork::get_gateway()
{
return get_ip_address();
}
nsapi_error_t UBLOX_AT_CellularNetwork::detach()
{
nsapi_error_t err;
_at.lock();
_at.cmd_start("AT+CGATT=0");
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();
err = _at.unlock_return_error();
// wait added to process CGREG and UUPSDD URC, which comes after detach.
wait_ms(50);
return err;
}

View File

@ -34,7 +34,6 @@ public:
virtual const char *get_gateway();
virtual nsapi_error_t detach();
protected:
virtual NetworkStack *get_stack();

View File

@ -16,6 +16,7 @@
*/
#include "UBLOX_AT_CellularStack.h"
#include "mbed_poll.h"
using namespace mbed;
using namespace mbed_cellular_util;
@ -192,6 +193,12 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
int sent_len = 0;
uint8_t ch = 0, cont = 50;
pollfh fhs;
fhs.fh = _at.get_file_handle();
fhs.events = POLLIN;
int pollCount;
socket->rx_avail = false;
if (socket->proto == NSAPI_UDP) {
if (size > UBLOX_MAX_PACKET_SIZE) {
return NSAPI_ERROR_PARAMETER;
@ -202,11 +209,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
_at.write_int(address.get_port());
_at.write_int(size);
_at.cmd_stop();
wait_ms(50);
while (ch != '@' && cont > 0) {
_at.read_bytes(&ch, 1);
cont--;
}
pollCount = poll(&fhs, 1, 50);
_at.write_bytes((uint8_t *)data, size);
_at.resp_start("+USOST:");
@ -231,11 +234,7 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
_at.write_int(socket->id);
_at.write_int(blk);
_at.cmd_stop();
wait_ms(50);
while (ch != '@' && cont > 0) {
_at.read_bytes(&ch, 1);
cont--;
}
pollCount = poll(&fhs, 1, 50);
_at.write_bytes((uint8_t *)buf, blk);
_at.resp_start("+USOWR:");
@ -254,7 +253,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
}
if (success && _at.get_last_error() == NSAPI_ERROR_OK) {
socket->rx_avail = false;
return size - count;
}
}
@ -275,6 +273,13 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke
int port = 0;
Timer timer;
if (!socket->rx_avail) {
_at.process_oob();
if (!socket->rx_avail) {
return NSAPI_ERROR_WOULD_BLOCK;
}
}
timer.start();
if (socket->proto == NSAPI_UDP) {
while (success && (size > 0)) {