From fcb3d5b010e996922cebe0671c0974b4752483d6 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Thu, 23 May 2019 15:32:24 -0400 Subject: [PATCH] De-increment sock available as we read out of sock --- .gitignore | 2 ++ src/TinyGsmClientBG96.h | 2 ++ src/TinyGsmClientM95.h | 2 ++ src/TinyGsmClientMC60.h | 2 ++ src/TinyGsmClientSIM7000.h | 6 ++++-- src/TinyGsmClientSIM800.h | 6 ++++-- src/TinyGsmClientSaraR4.h | 2 ++ src/TinyGsmClientSequansMonarch.h | 4 +++- src/TinyGsmClientUBLOX.h | 2 ++ src/TinyGsmCommon.h | 2 +- 10 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index f617ccb..11753c7 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ .cproject .project .settings +.pioenvs +.piolibdeps .pio/* .clang_complete .gcc-flags.json diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 66a5058..904403c 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -548,6 +548,8 @@ protected: for (size_t i=0; isock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO } waitResponse(); DBG("### READ:", len, "from", mux); diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 038ec17..7106638 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -615,6 +615,8 @@ protected: for (size_t i=0; isock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO } waitResponse(); DBG("### READ:", len, "from", mux); diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 33afb7c..0db5348 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -622,6 +622,8 @@ protected: for (size_t i=0; isock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO } waitResponse(); DBG("### READ:", len, "from", mux); diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index e1c0008..da2060c 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -835,12 +835,12 @@ protected: size_t len_requested = stream.readStringUntil(',').toInt(); // ^^ Requested number of data bytes (1-1460 bytes)to be read size_t len_confirmed = stream.readStringUntil('\n').toInt(); + // ^^ Confirmed number of data bytes to be read, which may be less than requested. + // 0 indicates that no data can be read. if (len_confirmed < len_requested) { DBG(len_requested - len_confirmed, "fewer bytes confirmed than requested!"); } sockets[mux]->sock_available = len_confirmed; - // ^^ Confirmed number of data bytes to be read, which may be less than requested. - // 0 indicates that no data can be read. for (size_t i=0; irx.put(c); + sockets[mux]->sock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO } waitResponse(); DBG("### READ:", TinyGsmMin(len_confirmed, len_requested), "from", mux); diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index c6f72c0..3f38587 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -765,12 +765,12 @@ protected: size_t len_requested = stream.readStringUntil(',').toInt(); // ^^ Requested number of data bytes (1-1460 bytes)to be read size_t len_confirmed = stream.readStringUntil('\n').toInt(); + // ^^ Confirmed number of data bytes to be read, which may be less than requested. + // 0 indicates that no data can be read. if (len_confirmed < len_requested) { DBG(len_requested - len_confirmed, "fewer bytes confirmed than requested!"); } sockets[mux]->sock_available = len_confirmed; - // ^^ Confirmed number of data bytes to be read, which may be less than requested. - // 0 indicates that no data can be read. for (size_t i=0; irx.put(c); + sockets[mux]->sock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO } waitResponse(); DBG("### READ:", TinyGsmMin(len_confirmed, len_requested), "from", mux); diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index d06ec78..8a11245 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -610,6 +610,8 @@ protected: for (size_t i=0; isock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO } streamSkipUntil('\"'); waitResponse(); diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index e48bcde..ad79062 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -621,10 +621,12 @@ protected: while (!stream.available() && ((millis() - startMillis) < sockets[mux % TINY_GSM_MUX_COUNT]->_timeout)) { TINY_GSM_YIELD(); } \ char c = stream.read(); \ sockets[mux % TINY_GSM_MUX_COUNT]->rx.put(c); + sockets[mux % TINY_GSM_MUX_COUNT]->sock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO } // 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 5c56f9f..a9f0cb1 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -598,6 +598,8 @@ protected: for (size_t i=0; isock_available--; + // ^^ One less character available after moving from modem's FIFO to our FIFO } streamSkipUntil('\"'); waitResponse(); diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index a92c08e..5ddefe6 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -100,7 +100,7 @@ uint32_t TinyGsmAutoBaud(T& SerialAT, uint32_t minimum = 9600, uint32_t maximum DBG("Trying baud rate", rate, "..."); SerialAT.begin(rate); delay(10); - for (int i=0; i<3; i++) { + for (int i=0; i<10; i++) { SerialAT.print("AT\r\n"); String input = SerialAT.readString(); if (input.indexOf("OK") >= 0) {