From 3d7829226147b7a54d237e00e01ca7f203bbc189 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 24 May 2019 23:24:32 -0400 Subject: [PATCH] modemRead MUST end with sock_available correct --- src/TinyGsmClientBG96.h | 1 + src/TinyGsmClientM95.h | 2 -- src/TinyGsmClientMC60.h | 2 -- src/TinyGsmClientSIM7000.h | 11 ++--------- src/TinyGsmClientSIM800.h | 11 ++--------- src/TinyGsmClientSaraR4.h | 7 +++++-- src/TinyGsmClientSequansMonarch.h | 2 +- src/TinyGsmClientUBLOX.h | 7 +++++-- 8 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 132b993..19d9976 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -552,6 +552,7 @@ protected: } waitResponse(); DBG("### READ:", len, "from", mux); + sockets[mux]->sock_available = modemGetAvailable(); return len; } diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 3921fa7..346d04d 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -621,8 +621,6 @@ protected: streamSkipUntil(','); // skip port streamSkipUntil(','); // skip connection type (TCP/UDP) size_t len = stream.readStringUntil('\n').toInt(); // read length - sockets[mux]->sock_available = len; - for (size_t i=0; isock_available--; diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 667d6eb..b327fd0 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -628,8 +628,6 @@ protected: streamSkipUntil(','); // skip port streamSkipUntil(','); // skip connection type (TCP/UDP) size_t len = stream.readStringUntil('\n').toInt(); // read length - sockets[mux]->sock_available = len; - for (size_t i=0; isock_available--; diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 7726a3b..c8e04ef 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -183,23 +183,16 @@ public: String getModemName() { String name = "SIMCom SIM7000"; - sendAT(GF("+CGMI")); - String res1; - if (waitResponse(1000L, res1) != 1) { - return name; - } - res1.replace(GSM_NL "OK" GSM_NL, ""); - res1.trim(); - sendAT(GF("+GMM")); String res2; if (waitResponse(1000L, res2) != 1) { return name; } res2.replace(GSM_NL "OK" GSM_NL, ""); + res2.replace("_", " "); res2.trim(); - name = res1 + String(' ') + res2; + name = res2; DBG("### Modem:", name); return name; } diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 0e1d569..365f4ee 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -195,23 +195,16 @@ public: name = "SIMCom SIM900"; #endif - sendAT(GF("+CGMI")); - String res1; - if (waitResponse(1000L, res1) != 1) { - return name; - } - res1.replace(GSM_NL "OK" GSM_NL, ""); - res1.trim(); - sendAT(GF("+GMM")); String res2; if (waitResponse(1000L, res2) != 1) { return name; } res2.replace(GSM_NL "OK" GSM_NL, ""); + res2.replace("_", " "); res2.trim(); - name = res1 + String(' ') + res2; + name = res2; DBG("### Modem:", name); return name; } diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index a4763cd..a8aa3db 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -100,7 +100,7 @@ TINY_GSM_CLIENT_CONNECT_OVERLOADS() // that it wants from the socket even if it was closed externally. rx.clear(); at->maintain(); - while (sock_available > 0) { + while (sock_connected && sock_available > 0) { at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); @@ -613,6 +613,7 @@ protected: streamSkipUntil('\"'); waitResponse(); DBG("### READ:", len, "from", mux); + sockets[mux]->sock_available = modemGetAvailable(); return len; } @@ -628,8 +629,10 @@ protected: result = stream.readStringUntil('\n').toInt(); // if (result) DBG("### DATA AVAILABLE:", result, "on", mux); waitResponse(); + } else if (res == 3) { + streamSkipUntil('\n'); // Skip the error text } - if (!result && res != 2 && res != 3) { // Don't check modemGetConnected after an error + if (!result) sockets[mux]->sock_connected = modemGetConnected(mux); } return result; diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index 1c145e1..8599c5a 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -624,7 +624,7 @@ protected: } DBG("### Read:", len, "from", mux); waitResponse(); - // sockets[mux % TINY_GSM_MUX_COUNT]->sock_available = modemGetAvailable(mux); + sockets[mux % TINY_GSM_MUX_COUNT]->sock_available = modemGetAvailable(mux); return len; } diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index b232db3..d3fb6e3 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -100,7 +100,7 @@ TINY_GSM_CLIENT_CONNECT_OVERLOADS() // that it wants from the socket even if it was closed externally. rx.clear(); at->maintain(); - while (sock_available > 0) { + while (sock_connected && sock_available > 0) { at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); rx.clear(); at->maintain(); @@ -601,6 +601,7 @@ protected: streamSkipUntil('\"'); waitResponse(); DBG("### READ:", len, "from", mux); + sockets[mux]->sock_available = modemGetAvailable(); return len; } @@ -616,8 +617,10 @@ protected: result = stream.readStringUntil('\n').toInt(); // if (result) DBG("### DATA AVAILABLE:", result, "on", mux); waitResponse(); + } else if (res == 3) { + streamSkipUntil('\n'); // Skip the error text } - if (!result && res != 2 && res != 3) { // Don't check modemGetConnected after an error + if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); } return result;