Skip to content

Commit b69b66e

Browse files
pennamfacchinm
authored andcommitted
Gemalto Cinterion Cellular: Disable urcs while reading
1 parent 10ac121 commit b69b66e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Diff for: connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -524,20 +524,25 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
524524
return (_at.get_last_error() == NSAPI_ERROR_OK) ? accept_len : NSAPI_ERROR_DEVICE_ERROR;
525525
}
526526

527+
#define DISABLE_URCs _at.at_cmd_discard("^SCFG", "=", "%s%s","Tcp/WithURCs","off")
528+
#define RESTORE_URCs_AND_RETURN(ret) do { _at.at_cmd_discard("^SCFG", "=", "%s%s","Tcp/WithURCs","on"); return ret; } while(0)
529+
527530
nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
528531
void *buffer, nsapi_size_t size)
529532
{
530533
// AT_CellularStack::recvfrom(...) will make sure that we do have a socket
531534
// open on the modem, assert here to catch a programming error
532535
MBED_ASSERT(socket->id != -1);
533536

537+
DISABLE_URCs;
538+
534539
// we must use this flag, otherwise ^SISR URC can come while we are reading response and there is
535540
// no way to detect if that is really an URC or response
536541
if (!socket->pending_bytes) {
537542
_at.process_oob(); // check for ^SISR URC
538543
if (!socket->pending_bytes) {
539544
tr_debug("Socket %d recv would block", socket->id);
540-
return NSAPI_ERROR_WOULD_BLOCK;
545+
RESTORE_URCs_AND_RETURN(NSAPI_ERROR_WOULD_BLOCK);
541546
}
542547
}
543548

@@ -552,7 +557,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
552557
_at.resp_start("^SISR:");
553558
if (!_at.info_resp()) {
554559
tr_error("Socket %d not responding", socket->id);
555-
return NSAPI_ERROR_DEVICE_ERROR;
560+
RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR);
556561
}
557562

558563
int socket_id = _at.read_int();
@@ -564,24 +569,24 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
564569
goto sisr_retry;
565570
}
566571
tr_error("Socket recvfrom id %d != %d", socket_id, socket->id);
567-
return NSAPI_ERROR_DEVICE_ERROR;
572+
RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR);
568573
}
569574

570575
nsapi_size_or_error_t len = _at.read_int();
571576
if (len == 0) {
572577
tr_warn("Socket %d no data", socket->id);
573578
_at.resp_stop();
574-
return NSAPI_ERROR_WOULD_BLOCK;
579+
RESTORE_URCs_AND_RETURN(NSAPI_ERROR_WOULD_BLOCK);
575580
}
576581
if (len == -1) {
577582
if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleTX62 && _at.get_last_read_error() == -2) {
578583
_at.process_oob();
579584
tr_error("Socket %d recvfrom finished!", socket->id);
580585
socket->pending_bytes = 0;
581-
return NSAPI_ERROR_OK;
586+
RESTORE_URCs_AND_RETURN(NSAPI_ERROR_OK);
582587
}
583588
tr_error("Socket %d recvfrom failed!", socket->id);
584-
return NSAPI_ERROR_DEVICE_ERROR;
589+
RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR);
585590
}
586591
if (len >= (nsapi_size_or_error_t)size) {
587592
len = (nsapi_size_or_error_t)size;
@@ -606,7 +611,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
606611
int len = _at.read_bytes(at_buf + ip_len, 1);
607612
if (len <= 0) {
608613
tr_error("Socket %d recvfrom addr (len %d)", socket->id, ip_len);
609-
return NSAPI_ERROR_DEVICE_ERROR;
614+
RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR);
610615
}
611616
ip_len += len;
612617
} while (ip_len < ip_address_len && at_buf[ip_len - 2] != '\r' && at_buf[ip_len - 1] != '\n');
@@ -629,7 +634,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
629634
int ip_len = _at.read_string(ip_address, sizeof(ip_address));
630635
if (ip_len <= 0) {
631636
tr_error("Socket %d recvfrom addr (len %d)", socket->id, ip_len);
632-
return NSAPI_ERROR_DEVICE_ERROR;
637+
RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR);
633638
}
634639
}
635640

@@ -671,7 +676,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
671676

672677
_at.resp_stop();
673678

674-
return (_at.get_last_error() == NSAPI_ERROR_OK) ? (recv_len ? recv_len : NSAPI_ERROR_WOULD_BLOCK) : NSAPI_ERROR_DEVICE_ERROR;
679+
RESTORE_URCs_AND_RETURN((_at.get_last_error() == NSAPI_ERROR_OK) ? (recv_len ? recv_len : NSAPI_ERROR_WOULD_BLOCK) : NSAPI_ERROR_DEVICE_ERROR);
675680
}
676681

677682
// setup internet connection profile for sockets

0 commit comments

Comments
 (0)