From 2616a3d64248cfa321d454b6abb41a98d1b516c8 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Mon, 17 Feb 2020 13:07:01 -0500 Subject: [PATCH] Change from switch case to required define Signed-off-by: Sara Damiano --- src/TinyGsmClientA6.h | 25 +-- src/TinyGsmClientBG96.h | 18 +- src/TinyGsmClientESP8266.h | 19 +-- src/TinyGsmClientM590.h | 21 +-- src/TinyGsmClientM95.h | 20 +-- src/TinyGsmClientMC60.h | 18 +- src/TinyGsmClientSIM5360.h | 7 +- src/TinyGsmClientSIM7000.h | 7 +- src/TinyGsmClientSIM7600.h | 7 +- src/TinyGsmClientSIM800.h | 23 ++- src/TinyGsmClientSaraR4.h | 25 ++- src/TinyGsmClientSequansMonarch.h | 7 +- src/TinyGsmClientUBLOX.h | 25 ++- src/TinyGsmClientXBee.h | 27 ++- src/TinyGsmTCP.tpp | 266 ++++++++++++++++-------------- 15 files changed, 247 insertions(+), 268 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 68c08ae..6c032a9 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -13,6 +13,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 8 +#define TINY_GSM_NO_MODEM_BUFFER #include "TinyGsmBattery.tpp" #include "TinyGsmCalling.tpp" @@ -37,17 +38,16 @@ enum RegStatus { REG_UNKNOWN = 4, }; -class TinyGsmA6 - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmTCP, - public TinyGsmCalling, - public TinyGsmSMS, - public TinyGsmTime, - public TinyGsmBattery { +class TinyGsmA6 : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmTCP, + public TinyGsmCalling, + public TinyGsmSMS, + public TinyGsmTime, + public TinyGsmBattery { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmCalling; friend class TinyGsmSMS; friend class TinyGsmTime; @@ -439,13 +439,6 @@ class TinyGsmA6 return len; } - size_t modemRead(size_t, uint8_t) { - return 0; - } - size_t modemGetAvailable(uint8_t) { - return 0; - } - bool modemGetConnected(uint8_t) { sendAT(GF("+CIPSTATUS")); // TODO(?) mux? int8_t res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 7afc440..3ec90de 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -13,6 +13,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 12 +#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE #include "TinyGsmBattery.tpp" #include "TinyGsmCalling.tpp" @@ -37,17 +38,16 @@ enum RegStatus { REG_UNKNOWN = 4, }; -class TinyGsmBG96 - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmTCP, - public TinyGsmCalling, - public TinyGsmSMS, - public TinyGsmTime, - public TinyGsmBattery { +class TinyGsmBG96 : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmTCP, + public TinyGsmCalling, + public TinyGsmSMS, + public TinyGsmTime, + public TinyGsmBattery { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmCalling; friend class TinyGsmSMS; friend class TinyGsmTime; diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 9165d5c..4f9e4b3 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -13,6 +13,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 5 +#define TINY_GSM_NO_MODEM_BUFFER #include "TinyGsmModem.tpp" #include "TinyGsmSSL.tpp" @@ -37,14 +38,13 @@ enum RegStatus { REG_UNKNOWN = 6, }; -class TinyGsmESP8266 - : public TinyGsmModem, - public TinyGsmWifi, - public TinyGsmTCP, - public TinyGsmSSL { +class TinyGsmESP8266 : public TinyGsmModem, + public TinyGsmWifi, + public TinyGsmTCP, + public TinyGsmSSL { friend class TinyGsmModem; friend class TinyGsmWifi; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSSL; /* @@ -301,13 +301,6 @@ class TinyGsmESP8266 return len; } - size_t modemRead(size_t, uint8_t) { - return 0; - } - size_t modemGetAvailable(uint8_t) { - return 0; - } - bool modemGetConnected(uint8_t mux) { sendAT(GF("+CIPSTATUS")); if (waitResponse(3000, GF("STATUS:")) != 1) { return false; } diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 9be27c8..137629e 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -13,6 +13,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 2 +#define TINY_GSM_NO_MODEM_BUFFER #include "TinyGsmGPRS.tpp" #include "TinyGsmModem.tpp" @@ -35,15 +36,14 @@ enum RegStatus { REG_UNKNOWN = 4, }; -class TinyGsmM590 - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmTCP, - public TinyGsmSMS, - public TinyGsmTime { +class TinyGsmM590 : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmTCP, + public TinyGsmSMS, + public TinyGsmTime { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSMS; friend class TinyGsmTime; @@ -317,13 +317,6 @@ class TinyGsmM590 return len; } - size_t modemRead(size_t, uint8_t) { - return 0; - } - size_t modemGetAvailable(uint8_t) { - return 0; - } - bool modemGetConnected(uint8_t mux) { sendAT(GF("+CIPSTATUS="), mux); int8_t res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 09182cb..c7256a4 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -14,6 +14,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 6 +#define TINY_GSM_BUFFER_READ_NO_CHECK #include "TinyGsmBattery.tpp" #include "TinyGsmCalling.tpp" @@ -39,18 +40,17 @@ enum RegStatus { REG_UNKNOWN = 4, }; -class TinyGsmM95 - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmTCP, - public TinyGsmCalling, - public TinyGsmSMS, - public TinyGsmTime, - public TinyGsmBattery, - public TinyGsmTemperature { +class TinyGsmM95 : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmTCP, + public TinyGsmCalling, + public TinyGsmSMS, + public TinyGsmTime, + public TinyGsmBattery, + public TinyGsmTemperature { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmCalling; friend class TinyGsmSMS; friend class TinyGsmTime; diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 81bcf96..d6e5eb5 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -16,6 +16,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 6 +#define TINY_GSM_BUFFER_READ_NO_CHECK #include "TinyGsmBattery.tpp" #include "TinyGsmCalling.tpp" @@ -40,17 +41,16 @@ enum RegStatus { REG_UNKNOWN = 4, }; -class TinyGsmMC60 - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmTCP, - public TinyGsmCalling, - public TinyGsmSMS, - public TinyGsmTime, - public TinyGsmBattery { +class TinyGsmMC60 : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmTCP, + public TinyGsmCalling, + public TinyGsmSMS, + public TinyGsmTime, + public TinyGsmBattery { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmCalling; friend class TinyGsmSMS; friend class TinyGsmTime; diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index 6ee06b2..139e9ca 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -13,6 +13,7 @@ // #define TINY_GSM_USE_HEX #define TINY_GSM_MUX_COUNT 10 +#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE #include "TinyGsmBattery.tpp" #include "TinyGsmGPRS.tpp" @@ -40,8 +41,7 @@ enum RegStatus { class TinyGsmSim5360 : public TinyGsmModem, public TinyGsmGPRS, - public TinyGsmTCP, + public TinyGsmTCP, public TinyGsmSMS, public TinyGsmTime, public TinyGsmGSMLocation, @@ -49,8 +49,7 @@ class TinyGsmSim5360 : public TinyGsmModem, public TinyGsmTemperature { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSMS; friend class TinyGsmTime; friend class TinyGsmGSMLocation; diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 8a03967..3f2df28 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -13,6 +13,7 @@ // #define TINY_GSM_USE_HEX #define TINY_GSM_MUX_COUNT 8 +#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE #include "TinyGsmBattery.tpp" #include "TinyGsmGPRS.tpp" @@ -39,16 +40,14 @@ enum RegStatus { class TinyGsmSim7000 : public TinyGsmModem, public TinyGsmGPRS, - public TinyGsmTCP, + public TinyGsmTCP, public TinyGsmSMS, public TinyGsmGPS, public TinyGsmTime, public TinyGsmBattery { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSMS; friend class TinyGsmGPS; friend class TinyGsmTime; diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index 911bf8e..6b8e8b3 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -13,6 +13,7 @@ // #define TINY_GSM_USE_HEX #define TINY_GSM_MUX_COUNT 10 +#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE #include "TinyGsmBattery.tpp" #include "TinyGsmGPRS.tpp" @@ -41,8 +42,7 @@ enum RegStatus { class TinyGsmSim7600 : public TinyGsmModem, public TinyGsmGPRS, - public TinyGsmTCP, + public TinyGsmTCP, public TinyGsmSMS, public TinyGsmGSMLocation, public TinyGsmGPS, @@ -51,8 +51,7 @@ class TinyGsmSim7600 : public TinyGsmModem, public TinyGsmTemperature { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSMS; friend class TinyGsmGPS; friend class TinyGsmGSMLocation; diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 59dcaf0..be9ba5a 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -14,6 +14,7 @@ // #define TINY_GSM_USE_HEX #define TINY_GSM_MUX_COUNT 5 +#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE #include "TinyGsmBattery.tpp" #include "TinyGsmCalling.tpp" @@ -39,20 +40,18 @@ enum RegStatus { REG_OK_ROAMING = 5, REG_UNKNOWN = 4, }; -class TinyGsmSim800 - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmTCP, - public TinyGsmSSL, - public TinyGsmCalling, - public TinyGsmSMS, - public TinyGsmGSMLocation, - public TinyGsmTime, - public TinyGsmBattery { +class TinyGsmSim800 : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmTCP, + public TinyGsmSSL, + public TinyGsmCalling, + public TinyGsmSMS, + public TinyGsmGSMLocation, + public TinyGsmTime, + public TinyGsmBattery { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSSL; friend class TinyGsmCalling; friend class TinyGsmSMS; diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 9e2c5b3..dbb6084 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -13,6 +13,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 7 +#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE #include "TinyGsmBattery.tpp" #include "TinyGsmGPRS.tpp" @@ -40,21 +41,19 @@ enum RegStatus { REG_UNKNOWN = 4, }; -class TinyGsmSaraR4 - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmTCP, - public TinyGsmSSL, - public TinyGsmBattery, - public TinyGsmGSMLocation, - public TinyGsmGPS, - public TinyGsmSMS, - public TinyGsmTemperature, - public TinyGsmTime { +class TinyGsmSaraR4 : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmTCP, + public TinyGsmSSL, + public TinyGsmBattery, + public TinyGsmGSMLocation, + public TinyGsmGPS, + public TinyGsmSMS, + public TinyGsmTemperature, + public TinyGsmTime { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSSL; friend class TinyGsmBattery; friend class TinyGsmGSMLocation; diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index f4353e1..d47abaf 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -12,6 +12,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 6 +#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE #include "TinyGsmCalling.tpp" #include "TinyGsmGPRS.tpp" @@ -50,8 +51,7 @@ enum SocketStatus { class TinyGsmSequansMonarch : public TinyGsmModem, public TinyGsmGPRS, - public TinyGsmTCP, + public TinyGsmTCP, public TinyGsmSSL, public TinyGsmCalling, public TinyGsmSMS, @@ -59,8 +59,7 @@ class TinyGsmSequansMonarch public TinyGsmTemperature { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSSL; friend class TinyGsmCalling; friend class TinyGsmSMS; diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 430c2d8..cddb756 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -13,6 +13,7 @@ // #define TINY_GSM_DEBUG Serial #define TINY_GSM_MUX_COUNT 7 +#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE #include "TinyGsmBattery.tpp" #include "TinyGsmCalling.tpp" @@ -40,21 +41,19 @@ enum RegStatus { REG_UNKNOWN = 4, }; -class TinyGsmUBLOX - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmTCP, - public TinyGsmSSL, - public TinyGsmCalling, - public TinyGsmSMS, - public TinyGsmGSMLocation, - public TinyGsmGPS, - public TinyGsmTime, - public TinyGsmBattery { +class TinyGsmUBLOX : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmTCP, + public TinyGsmSSL, + public TinyGsmCalling, + public TinyGsmSMS, + public TinyGsmGSMLocation, + public TinyGsmGPS, + public TinyGsmTime, + public TinyGsmBattery { friend class TinyGsmModem; friend class TinyGsmGPRS; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSSL; friend class TinyGsmCalling; friend class TinyGsmSMS; diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index b72229e..d45a90c 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -16,6 +16,7 @@ // XBee's do not support multi-plexing in transparent/command mode // The much more complicated API mode is needed for multi-plexing #define TINY_GSM_MUX_COUNT 1 +#define TINY_GSM_NO_MODEM_BUFFER // XBee's have a default guard time of 1 second (1000ms, 10 extra for safety // here) #define TINY_GSM_XBEE_GUARD_TIME 1010 @@ -65,19 +66,18 @@ enum XBeeType { XBEE3_LTEM_ATT = 0xB08, // Digi XBee3 Cellular LTE-M }; -class TinyGsmXBee - : public TinyGsmModem, - public TinyGsmGPRS, - public TinyGsmWifi, - public TinyGsmTCP, - public TinyGsmSSL, - public TinyGsmSMS, - public TinyGsmBattery, - public TinyGsmTemperature { +class TinyGsmXBee : public TinyGsmModem, + public TinyGsmGPRS, + public TinyGsmWifi, + public TinyGsmTCP, + public TinyGsmSSL, + public TinyGsmSMS, + public TinyGsmBattery, + public TinyGsmTemperature { friend class TinyGsmModem; friend class TinyGsmGPRS; friend class TinyGsmWifi; - friend class TinyGsmTCP; + friend class TinyGsmTCP; friend class TinyGsmSSL; friend class TinyGsmSMS; friend class TinyGsmBattery; @@ -1117,13 +1117,6 @@ class TinyGsmXBee return len; } - size_t modemRead(size_t, uint8_t) { - return 0; - } - size_t modemGetAvailable(uint8_t) { - return 0; - } - // NOTE: The CI command returns the status of the TCP connection as open only // after data has been sent on the socket. If it returns 0xFF the socket may // really be open, but no data has yet been sent. We return this unknown diff --git a/src/TinyGsmTCP.tpp b/src/TinyGsmTCP.tpp index acc7288..a66fb7f 100644 --- a/src/TinyGsmTCP.tpp +++ b/src/TinyGsmTCP.tpp @@ -19,8 +19,8 @@ #define TINY_GSM_RX_BUFFER 64 #endif -// Because of the ordering of resolution of overrides in templates, hese need to -// be written out every time. This macro is to shorten that. +// Because of the ordering of resolution of overrides in templates, these need +// to be written out every time. This macro is to shorten that. #define TINY_GSM_CLIENT_CONNECT_OVERRIDES \ virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { \ return connect(TinyGsmStringFromIp(ip).c_str(), port, timeout_s); \ @@ -32,16 +32,16 @@ return connect(ip, port, 75); \ } -enum modemInternalBuffferType { - NO_MODEM_BUFFER = - 0, // For modules that do not store incoming data in any sort of buffer - READ_NO_CHECK = 1, // Data is stored in a buffer, but we can only read from - // the buffer, not check how much data is stored in it - READ_AND_CHECK_SIZE = 2, // Data is stored in a buffer and we can both read - // and check the size of the buffer -}; +// // For modules that do not store incoming data in any sort of buffer +// #define TINY_GSM_NO_MODEM_BUFFER +// // Data is stored in a buffer, but we can only read from the buffer, +// // not check how much data is stored in it +// #define TINY_GSM_BUFFER_READ_NO_CHECK +// // Data is stored in a buffer and we can both read and check the size +// // of the buffer +// #define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE -template +template class TinyGsmTCP { public: /* @@ -68,7 +68,7 @@ class TinyGsmTCP { public: class GsmClient : public Client { // Make all classes created from the modem template friends - friend class TinyGsmTCP; + friend class TinyGsmTCP; typedef TinyGsmFifo RxFifo; public: @@ -77,14 +77,14 @@ class TinyGsmTCP { // Connect to a IP address given as an IPAddress object by // converting said IP address to text - // virtual int connect(IPAddress ip, uint16_t port, int timeout_s) { + // virtual int connect(IPAddress ip,uint16_t port, int timeout_s) { // return connect(TinyGsmStringFromIp(ip).c_str(), port, // timeout_s); // } // int connect(const char* host, uint16_t port) override { // return connect(host, port, 75); // } - // int connect(IPAddress ip, uint16_t port) override { + // int connect(IPAddress ip,uint16_t port) override { // return connect(ip, port, 75); // } @@ -124,107 +124,111 @@ class TinyGsmTCP { int available() override { TINY_GSM_YIELD(); - switch (bufType) { - // Returns the number of characters available in the TinyGSM fifo - case NO_MODEM_BUFFER: - if (!rx.size() && sock_connected) { at->maintain(); } - return rx.size(); - - // Returns the combined number of characters available in the TinyGSM - // fifo and the modem chips internal fifo. - case READ_NO_CHECK: - if (!rx.size()) { at->maintain(); } - return rx.size() + sock_available; - - // Returns the combined number of characters available in the TinyGSM - // fifo and the modem chips internal fifo, doing an extra check-in - // with the modem to see if anything has arrived without a UURC. - case READ_AND_CHECK_SIZE: - if (!rx.size()) { - if (millis() - prev_check > 500) { - got_data = true; - prev_check = millis(); - } - at->maintain(); - } - return rx.size() + sock_available; +#if defined TINY_GSM_NO_MODEM_BUFFER + // Returns the number of characters available in the TinyGSM fifo + if (!rx.size() && sock_connected) { at->maintain(); } + return rx.size(); + +#elif defined TINY_GSM_NO_MODEM_BUFFER + // Returns the combined number of characters available in the TinyGSM + // fifo and the modem chips internal fifo. + if (!rx.size()) { at->maintain(); } + return rx.size() + sock_available; + +#elif defined TINY_GSM_BUFFER_READ_AND_CHECK_SIZE + // Returns the combined number of characters available in the TinyGSM + // fifo and the modem chips internal fifo, doing an extra check-in + // with the modem to see if anything has arrived without a UURC. + if (!rx.size()) { + if (millis() - prev_check > 500) { + got_data = true; + prev_check = millis(); + } + at->maintain(); } + return rx.size() + sock_available; + +#else +#error Modem client has been incorrectly created +#endif } int read(uint8_t* buf, size_t size) override { TINY_GSM_YIELD(); - size_t cnt = 0; + size_t cnt = 0; + +#if defined TINY_GSM_NO_MODEM_BUFFER + // Reads characters out of the TinyGSM fifo, waiting for any URC's + // from the modem for new data if there's nothing in the fifo. uint32_t _startMillis = millis(); + while (cnt < size && millis() - _startMillis < _timeout) { + size_t chunk = TinyGsmMin(size - cnt, rx.size()); + if (chunk > 0) { + rx.get(buf, chunk); + buf += chunk; + cnt += chunk; + continue; + } /* TODO: Read directly into user buffer? */ + if (!rx.size() && sock_connected) { at->maintain(); } + } + return cnt; - switch (bufType) { - // Reads characters out of the TinyGSM fifo, waiting for any URC's - // from the modem for new data if there's nothing in the fifo. - case NO_MODEM_BUFFER: - while (cnt < size && millis() - _startMillis < _timeout) { - size_t chunk = TinyGsmMin(size - cnt, rx.size()); - if (chunk > 0) { - rx.get(buf, chunk); - buf += chunk; - cnt += chunk; - continue; - } /* TODO: Read directly into user buffer? */ - if (!rx.size() && sock_connected) { at->maintain(); } - } - return cnt; - - // Reads characters out of the TinyGSM fifo, and from the modem chip's - // internal fifo if avaiable. - case READ_NO_CHECK: - at->maintain(); - while (cnt < size) { - size_t chunk = TinyGsmMin(size - cnt, rx.size()); - if (chunk > 0) { - rx.get(buf, chunk); - buf += chunk; - cnt += chunk; - continue; - } /* TODO: Read directly into user buffer? */ - at->maintain(); - if (sock_available > 0) { - int n = at->modemRead( - TinyGsmMin((uint16_t)rx.free(), sock_available), mux); - if (n == 0) break; - } else { - break; - } - } - return cnt; - - // Reads characters out of the TinyGSM fifo, and from the modem chips - // internal fifo if avaiable, also double checking with the modem if - // data has arrived without issuing a UURC. - case READ_AND_CHECK_SIZE: - at->maintain(); - while (cnt < size) { - size_t chunk = TinyGsmMin(size - cnt, rx.size()); - if (chunk > 0) { - rx.get(buf, chunk); - buf += chunk; - cnt += chunk; - continue; - } - // Workaround: Some modules "forget" to notify about data arrival - if (millis() - prev_check > 500) { - got_data = true; - prev_check = millis(); - } - // TODO(vshymanskyy): Read directly into user buffer? - at->maintain(); - if (sock_available > 0) { - int n = at->modemRead( - TinyGsmMin((uint16_t)rx.free(), sock_available), mux); - if (n == 0) break; - } else { - break; - } - } - return cnt; +#elif defined TINY_GSM_BUFFER_READ_NO_CHECK + // Reads characters out of the TinyGSM fifo, and from the modem chip's + // internal fifo if avaiable. + at->maintain(); + while (cnt < size) { + size_t chunk = TinyGsmMin(size - cnt, rx.size()); + if (chunk > 0) { + rx.get(buf, chunk); + buf += chunk; + cnt += chunk; + continue; + } /* TODO: Read directly into user buffer? */ + at->maintain(); + if (sock_available > 0) { + int n = at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), + mux); + if (n == 0) break; + } else { + break; + } + } + return cnt; + +#elif defined TINY_GSM_BUFFER_READ_AND_CHECK_SIZE + // Reads characters out of the TinyGSM fifo, and from the modem chips + // internal fifo if avaiable, also double checking with the modem if + // data has arrived without issuing a UURC. + at->maintain(); + while (cnt < size) { + size_t chunk = TinyGsmMin(size - cnt, rx.size()); + if (chunk > 0) { + rx.get(buf, chunk); + buf += chunk; + cnt += chunk; + continue; + } + // Workaround: Some modules "forget" to notify about data arrival + if (millis() - prev_check > 500) { + got_data = true; + prev_check = millis(); + } + // TODO(vshymanskyy): Read directly into user buffer? + at->maintain(); + if (sock_available > 0) { + int n = at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), + mux); + if (n == 0) break; + } else { + break; + } } + return cnt; + +#else +#error Modem client has been incorrectly created +#endif } int read() override { @@ -264,12 +268,21 @@ class TinyGsmTCP { // Doing it this way allows the external mcu to find and get all of the // data that it wants from the socket even if it was closed externally. inline void dumpModemBuffer(uint32_t maxWaitMs) { +#if defined TINY_GSM_BUFFER_READ_AND_CHECK_SIZE || \ + defined TINY_GSM_BUFFER_READ_NO_CHECK TINY_GSM_YIELD(); uint32_t startMillis = millis(); do { rx.clear(); at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); } while (sock_available > 0 && (millis() - startMillis < maxWaitMs)); + +#elif defined TINY_GSM_NO_MODEM_BUFFER + // Do nothing + +#else +#error Modem client has been incorrectly created +#endif } modemType* at; @@ -286,26 +299,27 @@ class TinyGsmTCP { */ protected: void maintainImpl() { - switch (bufType) { - case READ_AND_CHECK_SIZE: - // Keep listening for modem URC's and proactively iterate through - // sockets asking if any data is avaiable - for (int mux = 0; mux < muxCount; mux++) { - GsmClient* sock = thisModem().sockets[mux]; - if (sock && sock->got_data) { - sock->got_data = false; - sock->sock_available = thisModem().modemGetAvailable(mux); - } - } - while (thisModem().stream.available()) { - thisModem().waitResponse(15, NULL, NULL); - } - break; - default: - // Just listen for any URC's - thisModem().waitResponse(100, NULL, NULL); - break; +#if defined TINY_GSM_BUFFER_READ_AND_CHECK_SIZE + // Keep listening for modem URC's and proactively iterate through + // sockets asking if any data is avaiable + for (int mux = 0; mux < muxCount; mux++) { + GsmClient* sock = thisModem().sockets[mux]; + if (sock && sock->got_data) { + sock->got_data = false; + sock->sock_available = thisModem().modemGetAvailable(mux); + } + } + while (thisModem().stream.available()) { + thisModem().waitResponse(15, NULL, NULL); } + +#elif defined TINY_GSM_NO_MODEM_BUFFER || defined TINY_GSM_BUFFER_READ_NO_CHECK + // Just listen for any URC's + thisModem().waitResponse(100, NULL, NULL); + +#else +#error Modem client has been incorrectly created +#endif } // Yields up to a time-out period and then reads a character from the stream