From 1768b653ec82b23b611b9160c72e446dfde3000c Mon Sep 17 00:00:00 2001 From: Kimmo Vaisanen Date: Fri, 20 Sep 2019 09:24:50 +0300 Subject: [PATCH] Cellular: Handle SEND FAIL and ERROR response QISEND command can respond either SEND OK, SEND FAIL or ERROR. If response is not SEND OK, sent bytes should not be checked but error should be reported. --- .../targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp | 9 +++++++-- .../targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp index bcaa9a2b45..ee9652e4f6 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp @@ -300,12 +300,17 @@ nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_sendto_impl(CellularSoc _at.write_bytes((uint8_t *)data, size); _at.resp_start(); _at.set_stop_tag("\r\n"); + // Possible responses are SEND OK, SEND FAIL or ERROR. + char response[16]; + response[0] = '\0'; + _at.read_string(response, sizeof(response)); _at.resp_stop(); + if (strcmp(response, "SEND OK") != 0) { + return NSAPI_ERROR_DEVICE_ERROR; + } // Get the sent count after sending - nsapi_size_or_error_t err = _at.at_cmd_int("+QISEND", "=", sent_len_after, "%d%d", socket->id, 0); - if (err == NSAPI_ERROR_OK) { sent_len = sent_len_after - sent_len_before; return sent_len; diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp index d02118b321..36241c81c1 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularStack.cpp @@ -440,7 +440,14 @@ nsapi_size_or_error_t QUECTEL_M26_CellularStack::socket_sendto_impl(CellularSock _at.write_bytes((uint8_t *)data, sent_len); _at.resp_start(); _at.set_stop_tag("\r\n"); + // Possible responses are SEND OK, SEND FAIL or ERROR. + char response[16]; + response[0] = '\0'; + _at.read_string(response, sizeof(response)); _at.resp_stop(); + if (strcmp(response, "SEND OK") != 0) { + return NSAPI_ERROR_DEVICE_ERROR; + } if (_at.get_last_error() != NSAPI_ERROR_OK) { tr_error("QUECTEL_M26_CellularStack:%s:%u:[NSAPI_ERROR_DEVICE_ERROR]", __FUNCTION__, __LINE__);