Skip to content

Commit 688a4e4

Browse files
author
Veijo Pesonen
committed
ESP8266: recv() is able to handle device busy indication
1 parent d96c9e8 commit 688a4e4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

components/wifi/esp8266-driver/ESP8266/ESP8266.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,12 +736,14 @@ int32_t ESP8266::_recv_tcp_passive(int id, void *data, uint32_t amount, uint32_t
736736
// NOTE: documentation v3.0 says '+CIPRECVDATA:<data_len>,' but it's not how the FW responds...
737737
bool done = _parser.send("AT+CIPRECVDATA=%d,%lu", id, amount)
738738
&& _parser.recv("OK\n");
739-
if (!done) {
740-
tr_debug("data request failed");
741-
}
739+
742740
_sock_i[id].tcp_data = NULL;
743741
_sock_active_id = -1;
744742

743+
if (!done) {
744+
goto BUSY;
745+
}
746+
745747
// update internal variable tcp_data_avbl to reflect the remaining data
746748
if (_sock_i[id].tcp_data_rcvd > 0) {
747749
if (_sock_i[id].tcp_data_rcvd > (int32_t)amount) {
@@ -764,6 +766,18 @@ int32_t ESP8266::_recv_tcp_passive(int id, void *data, uint32_t amount, uint32_t
764766

765767
_smutex.unlock();
766768
return ret;
769+
770+
BUSY:
771+
_process_oob(ESP8266_RECV_TIMEOUT, true);
772+
if (_busy) {
773+
tr_debug("_recv_tcp_passive(): modem busy");
774+
ret = NSAPI_ERROR_WOULD_BLOCK;
775+
} else {
776+
tr_error("_recv_tcp_passive(): unknown state");
777+
ret = NSAPI_ERROR_DEVICE_ERROR;
778+
}
779+
_smutex.unlock();
780+
return ret;
767781
}
768782

769783
int32_t ESP8266::recv_tcp(int id, void *data, uint32_t amount, uint32_t timeout)

0 commit comments

Comments
 (0)