From 99a5b3938cca348c50d356cfa1ca57cea9f814f7 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 17 May 2019 10:50:44 -0400 Subject: [PATCH] Removed recursive calls to maitain (shouldn't I have leared) --- src/TinyGsmClientBG96.h | 4 ---- src/TinyGsmClientM95.h | 4 ---- src/TinyGsmClientMC60.h | 4 ---- src/TinyGsmClientSIM7000.h | 4 ---- src/TinyGsmClientSIM800.h | 4 ---- src/TinyGsmClientUBLOX.h | 40 ++++++++++++++++++++------------------ 6 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 6352c81..f0c987a 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -656,7 +656,6 @@ protected: return 0; } // TODO: Wait for ACK? AT+QISEND=id,0 - maintain(); // look for a very quick response from the remote return len; } @@ -675,7 +674,6 @@ protected: } waitResponse(); DBG("### READ:", len, "from", mux); - maintain(); // Listen for a close or other URC return len; } @@ -692,7 +690,6 @@ protected: if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); } - maintain(); // Listen for a close or other URC return result; } @@ -711,7 +708,6 @@ protected: int res = stream.readStringUntil(',').toInt(); // socket state waitResponse(); - maintain(); // Listen for a close or other URC // 0 Initial, 1 Opening, 2 Connected, 3 Listening, 4 Closing return 2 == res; diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 1f30240..4c51eaa 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -708,7 +708,6 @@ protected: } } waitResponse(5000L); - maintain(); // look for a very quick response from the remote // streamSkipUntil(','); // Skip mux // return stream.readStringUntil('\n').toInt(); @@ -730,7 +729,6 @@ protected: } waitResponse(); DBG("### READ:", len, "from", mux); - maintain(); // Listen for a close or other URC return len; } @@ -747,7 +745,6 @@ protected: if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); } - maintain(); // Listen for a close or other URC return result; } @@ -766,7 +763,6 @@ protected: int res = stream.readStringUntil(',').toInt(); // socket state waitResponse(); - maintain(); // Listen for a close or other URC // 0 Initial, 1 Opening, 2 Connected, 3 Listening, 4 Closing return 2 == res; diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index f2283fb..902ec72 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -740,7 +740,6 @@ protected: // streamSkipUntil(','); // Skip mux // return stream.readStringUntil('\n').toInt(); - maintain(); // look for a very quick response from the remote return len; // TODO } @@ -759,7 +758,6 @@ protected: } waitResponse(); DBG("### READ:", len, "from", mux); - maintain(); // Listen for a close or other URC return len; } @@ -776,7 +774,6 @@ protected: if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); } - maintain(); // Listen for a close or other URC return result; } @@ -795,7 +792,6 @@ protected: int res = stream.readStringUntil(',').toInt(); // socket state waitResponse(); - maintain(); // Listen for a close or other URC // 0 Initial, 1 Opening, 2 Connected, 3 Listening, 4 Closing return 2 == res; diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 8f8024a..53468cf 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -960,7 +960,6 @@ protected: return 0; } streamSkipUntil(','); // Skip mux - maintain(); // look for a very quick response from the remote return stream.readStringUntil('\n').toInt(); } @@ -1003,7 +1002,6 @@ protected: } waitResponse(); DBG("### READ:", len_confirmed, "from", mux); - maintain(); // Listen for a close or other URC return len_confirmed; } @@ -1019,7 +1017,6 @@ protected: if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); } - maintain(); // Listen for a close or other URC return result; } @@ -1027,7 +1024,6 @@ protected: sendAT(GF("+CIPSTATUS="), mux); int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), GF(",\"INITIAL\"")); waitResponse(); - maintain(); // Listen for a close or other URC return 1 == res; } diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index d3c699f..20a2b61 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -883,7 +883,6 @@ protected: return 0; } streamSkipUntil(','); // Skip mux - maintain(); // look for a very quick response from the remote return stream.readStringUntil('\n').toInt(); } @@ -926,7 +925,6 @@ protected: } waitResponse(); DBG("### READ:", len_confirmed, "from", mux); - maintain(); // Listen for a close or other URC return len_confirmed; } @@ -942,7 +940,6 @@ protected: if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); } - maintain(); // Listen for a close or other URC return result; } @@ -950,7 +947,6 @@ protected: sendAT(GF("+CIPSTATUS="), mux); int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), GF(",\"INITIAL\"")); waitResponse(); - maintain(); // Listen for a close or other URC return 1 == res; } diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index ff29ae7..e52b30e 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -62,8 +62,8 @@ public: sock_connected = false; got_data = false; - // Don't attach the socket here because we won't know the mux channel number - // until the u-blox assigns it upon opening the socket + at->sockets[mux] = this; + return true; } @@ -88,11 +88,14 @@ public: } TINY_GSM_YIELD(); rx.clear(); - // sock_connected = at->modemConnect(host, port, mux); + + uint8_t oldMux = mux; sock_connected = at->modemConnect(host, port, &mux); + if (mux != oldMux) { + DBG("WARNING: Mux number changed from", oldMux, "to", mux); + at->sockets[oldMux] = NULL; + } at->sockets[mux] = this; - // Attach the socket after attempting connection because u-blox will assign - // whatever mux number is next regardless of the number requested. at->maintain(); return sock_connected; } @@ -276,15 +279,8 @@ public: #endif waitResponse(); - String name = getModemName(); - DBG(GF("### Modem:"), name); - if (name.startsWith("u-blox SARA-R4") or name.startsWith("u-blox SARA-N4")) { - DBG(GF("### This is an LTE-M modem!"), name); - isCatM = true; - } - else if (name.startsWith("u-blox SARA-N2")) { - DBG(GF("### SARA N2 NB-IoT modems not supported!"), name); - } + getModemName(); + int ret = getSimStatus(); // if the sim isn't ready and a pin has been provided, try to unlock the sim if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) { @@ -317,8 +313,18 @@ public: } res2.replace(GSM_NL "OK" GSM_NL, ""); res2.trim(); + + String name = res1 + String(' ') + res2; + DBG("### Modem:", name); + if (name.startsWith("u-blox SARA-R4") or name.startsWith("u-blox SARA-N4")) { + DBG("### This is an LTE-M modem!"); + isCatM = true; + } + else if (name.startsWith("u-blox SARA-N2")) { + DBG("### SARA N2 NB-IoT modems not supported!"); + } - return res1 + String(' ') + res2; + return name; } void setBaud(unsigned long baud) { @@ -835,7 +841,6 @@ protected: streamSkipUntil(','); // Skip mux int sent = stream.readStringUntil('\n').toInt(); waitResponse(); // sends back OK after the confirmation of number sent - maintain(); // look for a very quick response from the remote return sent; } @@ -857,7 +862,6 @@ protected: streamSkipUntil('\"'); waitResponse(); DBG("### READ:", len, "from", mux); - maintain(); // Listen for a close or other URC return len; } @@ -876,7 +880,6 @@ protected: if (!result && res != 2 && res != 3) { // Don't check modemGetConnected after an error sockets[mux]->sock_connected = modemGetConnected(mux); } - maintain(); // Listen for a close or other URC return result; } @@ -902,7 +905,6 @@ protected: // 9: the socket is in LAST_ACK status // 10: the socket is in TIME_WAIT status waitResponse(); - maintain(); // Listen for a close or other URC return (result != 0); }