diff --git a/examples/more/Industruino/Industruino.ino b/examples/more/Industruino/Industruino.ino index 6b8b48e..e1522d0 100644 --- a/examples/more/Industruino/Industruino.ino +++ b/examples/more/Industruino/Industruino.ino @@ -18,7 +18,9 @@ #define TINY_GSM_MODEM_SIM800 // Increase RX buffer if needed -// #define TINY_GSM_RX_BUFFER 512 +#if !defined(TINY_GSM_RX_BUFFER) +#define TINY_GSM_RX_BUFFER 512 +#endif #include #include diff --git a/src/TinyGsmBattery.tpp b/src/TinyGsmBattery.tpp index fe84379..0ed3b0a 100644 --- a/src/TinyGsmBattery.tpp +++ b/src/TinyGsmBattery.tpp @@ -66,7 +66,7 @@ class TinyGsmBattery { if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } thisModem().streamSkipUntil(','); // Skip battery charge status // Read battery charge level - int res = thisModem().streamGetInt(','); + int8_t res = thisModem().streamGetInt(','); // Wait for final OK thisModem().waitResponse(); return res; @@ -76,7 +76,7 @@ class TinyGsmBattery { thisModem().sendAT(GF("+CBC")); if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } // Read battery charge status - int res = thisModem().streamGetInt(','); + int8_t res = thisModem().streamGetInt(','); // Wait for final OK thisModem().waitResponse(); return res; diff --git a/src/TinyGsmCalling.tpp b/src/TinyGsmCalling.tpp index 467fe1d..413515a 100644 --- a/src/TinyGsmCalling.tpp +++ b/src/TinyGsmCalling.tpp @@ -59,8 +59,8 @@ class TinyGsmCalling { } else { thisModem().sendAT(GF("D"), number, ";"); } - int status = thisModem().waitResponse(60000L, GF("OK"), GF("BUSY"), - GF("NO ANSWER"), GF("NO CARRIER")); + int8_t status = thisModem().waitResponse(60000L, GF("OK"), GF("BUSY"), + GF("NO ANSWER"), GF("NO CARRIER")); switch (status) { case 1: return true; case 2: diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 8fe4de9..1d4f8f9 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -149,7 +149,7 @@ class TinyGsmA6 DBG(GF("### Modem:"), getModemName()); - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -298,11 +298,11 @@ class TinyGsmA6 return false; } - int rsp = waitResponse(60000L, GF(GSM_NL "+CIEV: \"SOUNDER\",0"), - GF(GSM_NL "+CIEV: \"CALL\",0")); + int8_t rsp = waitResponse(60000L, GF(GSM_NL "+CIEV: \"SOUNDER\",0"), + GF(GSM_NL "+CIEV: \"CALL\",0")); - int rsp2 = waitResponse(300L, GF(GSM_NL "BUSY" GSM_NL), - GF(GSM_NL "NO ANSWER" GSM_NL)); + int8_t rsp2 = waitResponse(300L, GF(GSM_NL "BUSY" GSM_NL), + GF(GSM_NL "NO ANSWER" GSM_NL)); return rsp == 1 && rsp2 == 0; } @@ -359,7 +359,7 @@ class TinyGsmA6 streamSkipUntil('"'); String hex = stream.readStringUntil('"'); streamSkipUntil(','); - int dcs = streamGetInt('\n'); + int8_t dcs = streamGetInt('\n'); if (dcs == 15) { return TinyGsmDecodeHex7bit(hex); @@ -389,7 +389,7 @@ class TinyGsmA6 if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; } streamSkipUntil(','); // Skip battery charge status // Read battery charge level - int res = streamGetInt('\n'); + int8_t res = streamGetInt('\n'); // Wait for final OK waitResponse(); return res; @@ -419,11 +419,11 @@ class TinyGsmA6 sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port); if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) { return false; } - int newMux = streamGetInt('\n'); + int8_t newMux = streamGetInt('\n'); - int rsp = waitResponse((timeout_ms - (millis() - startMillis)), - GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), - GF("ALREADY CONNECT" GSM_NL)); + int8_t rsp = waitResponse( + (timeout_ms - (millis() - startMillis)), GF("CONNECT OK" GSM_NL), + GF("CONNECT FAIL" GSM_NL), GF("ALREADY CONNECT" GSM_NL)); if (waitResponse() != 1) { return false; } *mux = newMux; @@ -448,8 +448,8 @@ class TinyGsmA6 bool modemGetConnected(uint8_t) { sendAT(GF("+CIPSTATUS")); // TODO(?) mux? - int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), - GF(",\"CLOSING\""), GF(",\"INITIAL\"")); + int8_t res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), + GF(",\"CLOSING\""), GF(",\"INITIAL\"")); waitResponse(); return 1 == res; } @@ -459,11 +459,11 @@ class TinyGsmA6 */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -477,7 +477,7 @@ class TinyGsmA6 TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -499,9 +499,9 @@ class TinyGsmA6 index = 5; goto finish; } else if (data.endsWith(GF("+CIPRCV:"))) { - int mux = streamGetInt(','); - int len = streamGetInt(','); - int len_orig = len; + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt(','); + int16_t len_orig = len; if (len > sockets[mux]->rx.free()) { DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free()); } else { @@ -515,7 +515,7 @@ class TinyGsmA6 } data = ""; } else if (data.endsWith(GF("+TCPCLOSED:"))) { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) { sockets[mux]->sock_connected = false; } @@ -535,18 +535,18 @@ class TinyGsmA6 return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index b102631..ac18c1f 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -167,7 +167,7 @@ class TinyGsmBG96 sendAT(GF("+CTZU=1")); if (waitResponse(10000L) != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -294,7 +294,7 @@ class TinyGsmBG96 bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 20) { if (ssl) { DBG("SSL not yet supported on this module!"); } - int rsp; + uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; // (1-16), (0-11), @@ -308,9 +308,7 @@ class TinyGsmBG96 if (streamGetInt(',') != mux) { return false; } // Read status - rsp = streamGetInt('\n'); - - return (0 == rsp); + return (0 == streamGetInt('\n')); } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { @@ -326,7 +324,7 @@ class TinyGsmBG96 size_t modemRead(size_t size, uint8_t mux) { sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); if (waitResponse(GF("+QIRD:")) != 1) { return 0; } - int len = streamGetInt('\n'); + int16_t len = streamGetInt('\n'); for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } waitResponse(); @@ -355,12 +353,12 @@ class TinyGsmBG96 if (waitResponse(GF("+QISTATE:")) != 1) { return false; } - streamSkipUntil(','); // Skip mux - streamSkipUntil(','); // Skip socket type - streamSkipUntil(','); // Skip remote ip - streamSkipUntil(','); // Skip remote port - streamSkipUntil(','); // Skip local port - int res = streamGetInt(','); // socket state + streamSkipUntil(','); // Skip mux + streamSkipUntil(','); // Skip socket type + streamSkipUntil(','); // Skip remote ip + streamSkipUntil(','); // Skip remote port + streamSkipUntil(','); // Skip local port + int8_t res = streamGetInt(','); // socket state waitResponse(); @@ -373,11 +371,11 @@ class TinyGsmBG96 */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -391,7 +389,7 @@ class TinyGsmBG96 TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -417,13 +415,13 @@ class TinyGsmBG96 String urc = stream.readStringUntil('\"'); streamSkipUntil(','); if (urc == "recv") { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); DBG("### URC RECV:", mux); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; } } else if (urc == "closed") { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); DBG("### URC CLOSE:", mux); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; @@ -446,18 +444,18 @@ class TinyGsmBG96 return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 08bea11..6ed34ce 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -202,25 +202,25 @@ class TinyGsmESP8266 RegStatus getRegistrationStatus() { sendAT(GF("+CIPSTATUS")); if (waitResponse(3000, GF("STATUS:")) != 1) return REG_UNKNOWN; - int status = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), - GF("5")); + int8_t status = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), + GF("5")); waitResponse(); // Returns an OK after the status return (RegStatus)status; } protected: - int16_t getSignalQualityImpl() { + int8_t getSignalQualityImpl() { sendAT(GF("+CWJAP_CUR?")); - int res1 = waitResponse(GF("No AP"), GF("+CWJAP_CUR:")); + int8_t res1 = waitResponse(GF("No AP"), GF("+CWJAP_CUR:")); if (res1 != 2) { waitResponse(); return 0; } - streamSkipUntil(','); // Skip SSID - streamSkipUntil(','); // Skip BSSID/MAC address - streamSkipUntil(','); // Skip Chanel number - int res2 = stream.parseInt(); // Read RSSI - waitResponse(); // Returns an OK after the value + streamSkipUntil(','); // Skip SSID + streamSkipUntil(','); // Skip BSSID/MAC address + streamSkipUntil(','); // Skip Chanel number + int8_t res2 = stream.parseInt(); // Read RSSI + waitResponse(); // Returns an OK after the value return res2; } @@ -243,7 +243,7 @@ class TinyGsmESP8266 String getLocalIPImpl() { sendAT(GF("+CIPSTA_CUR?")); - int res1 = waitResponse(GF("ERROR"), GF("+CWJAP_CUR:")); + int8_t res1 = waitResponse(GF("ERROR"), GF("+CWJAP_CUR:")); if (res1 != 2) { return ""; } String res2 = stream.readStringUntil('"'); waitResponse(); @@ -285,8 +285,8 @@ class TinyGsmESP8266 GF("\",\""), host, GF("\","), port, GF(","), TINY_GSM_TCP_KEEP_ALIVE); // TODO(?): Check mux - int rsp = waitResponse(timeout_ms, GFP(GSM_OK), GFP(GSM_ERROR), - GF("ALREADY CONNECT")); + int8_t rsp = waitResponse(timeout_ms, GFP(GSM_OK), GFP(GSM_ERROR), + GF("ALREADY CONNECT")); // if (rsp == 3) waitResponse(); // May return "ERROR" after the "ALREADY CONNECT" return (1 == rsp); @@ -311,8 +311,8 @@ class TinyGsmESP8266 bool modemGetConnected(uint8_t mux) { sendAT(GF("+CIPSTATUS")); if (waitResponse(3000, GF("STATUS:")) != 1) { return false; } - int status = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), - GF("5")); + int8_t status = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), + GF("5")); if (status != 3) { // if the status is anything but 3, there are no connections open waitResponse(); // Returns an OK after the status @@ -326,7 +326,7 @@ class TinyGsmESP8266 uint8_t has_status = waitResponse(GF("+CIPSTATUS:"), GFP(GSM_OK), GFP(GSM_ERROR)); if (has_status == 1) { - int returned_mux = streamGetInt(','); + int8_t returned_mux = streamGetInt(','); streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip type streamSkipUntil(','); // Skip remote IP @@ -348,10 +348,10 @@ class TinyGsmESP8266 */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -365,7 +365,7 @@ class TinyGsmESP8266 TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -384,9 +384,9 @@ class TinyGsmESP8266 index = 5; goto finish; } else if (data.endsWith(GF("+IPD,"))) { - int mux = streamGetInt(','); - int len = streamGetInt(':'); - int len_orig = len; + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt(':'); + int16_t len_orig = len; if (len > sockets[mux]->rx.free()) { DBG("### Buffer overflow: ", len, "received vs", sockets[mux]->rx.free(), "available"); @@ -401,10 +401,10 @@ class TinyGsmESP8266 } data = ""; } else if (data.endsWith(GF("CLOSED"))) { - int muxStart = + int8_t muxStart = TinyGsmMax(0, data.lastIndexOf(GSM_NL, data.length() - 8)); - int coma = data.indexOf(',', muxStart); - int mux = data.substring(muxStart, coma).toInt(); + int8_t coma = data.indexOf(',', muxStart); + int8_t mux = data.substring(muxStart, coma).toInt(); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } @@ -424,16 +424,16 @@ class TinyGsmESP8266 return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 204a470..f54a65d 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -128,7 +128,7 @@ class TinyGsmM590 DBG(GF("### Modem:"), getModemName()); - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -257,7 +257,7 @@ class TinyGsmM590 bool isGprsConnectedImpl() { sendAT(GF("+XIIC?")); if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return false; } - int res = streamGetInt(','); + int8_t res = streamGetInt(','); waitResponse(); return res == 1; } @@ -292,8 +292,9 @@ class TinyGsmM590 String ip = dnsIpQuery(host); sendAT(GF("+TCPSETUP="), mux, GF(","), ip, GF(","), port); - int rsp = waitResponse(timeout_ms, GF(",OK" GSM_NL), GF(",FAIL" GSM_NL), - GF("+TCPSETUP:Error" GSM_NL)); + int8_t rsp = waitResponse(timeout_ms, GF(",OK" GSM_NL), + GF(",FAIL" GSM_NL), + GF("+TCPSETUP:Error" GSM_NL)); if (1 == rsp) { return true; } else if (3 == rsp) { @@ -325,8 +326,8 @@ class TinyGsmM590 bool modemGetConnected(uint8_t mux) { sendAT(GF("+CIPSTATUS="), mux); - int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), - GF(",\"CLOSING\""), GF(",\"INITIAL\"")); + int8_t res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), + GF(",\"CLOSING\""), GF(",\"INITIAL\"")); waitResponse(); return 1 == res; } @@ -345,11 +346,11 @@ class TinyGsmM590 */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -363,7 +364,7 @@ class TinyGsmM590 TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -385,9 +386,9 @@ class TinyGsmM590 index = 5; goto finish; } else if (data.endsWith(GF("+TCPRECV:"))) { - int mux = streamGetInt(','); - int len = streamGetInt(','); - int len_orig = len; + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt(','); + int16_t len_orig = len; if (len > sockets[mux]->rx.free()) { DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free()); } else { @@ -401,7 +402,7 @@ class TinyGsmM590 } data = ""; } else if (data.endsWith(GF("+TCPCLOSE:"))) { - int mux = streamGetInt(','); + int8_t mux = streamGetInt(','); streamSkipUntil('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) { sockets[mux]->sock_connected = false; @@ -422,18 +423,18 @@ class TinyGsmM590 return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index a42fcac..8ca90de 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -174,7 +174,7 @@ class TinyGsmM95 sendAT(GF("+QNITZ=1")); if (waitResponse(10000L) != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -404,9 +404,9 @@ class TinyGsmM95 uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host, GF("\","), port); - int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), - GF("CONNECT FAIL" GSM_NL), - GF("ALREADY CONNECT" GSM_NL)); + int8_t rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), + GF("CONNECT FAIL" GSM_NL), + GF("ALREADY CONNECT" GSM_NL)); return (1 == rsp); } @@ -447,7 +447,7 @@ class TinyGsmM95 sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size); // If it replies only OK for the write command, it means there is no // received data in the buffer of the connection. - int res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR)); + int8_t res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR)); if (res == 1) { streamSkipUntil(':'); // skip IP address streamSkipUntil(','); // skip port @@ -485,12 +485,12 @@ class TinyGsmM95 if (waitResponse(GF("+QISTATE:")) != 1) { return false; } - streamSkipUntil(','); // Skip mux - streamSkipUntil(','); // Skip socket type - streamSkipUntil(','); // Skip remote ip - streamSkipUntil(','); // Skip remote port - streamSkipUntil(','); // Skip local port - int res = streamGetInt(','); // socket state + streamSkipUntil(','); // Skip mux + streamSkipUntil(','); // Skip socket type + streamSkipUntil(','); // Skip remote ip + streamSkipUntil(','); // Skip remote port + streamSkipUntil(','); // Skip local port + int8_t res = streamGetInt(','); // socket state waitResponse(); @@ -503,11 +503,11 @@ class TinyGsmM95 */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -521,7 +521,7 @@ class TinyGsmM95 TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -545,7 +545,7 @@ class TinyGsmM95 } else if (data.endsWith(GF(GSM_NL "+QIRDI:"))) { streamSkipUntil(','); // Skip the context streamSkipUntil(','); // Skip the role - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); DBG("### Got Data:", mux); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { // We have no way of knowing how much data actually came in, so @@ -554,9 +554,9 @@ class TinyGsmM95 } data = ""; } else if (data.endsWith(GF("CLOSED" GSM_NL))) { - int nl = data.lastIndexOf(GSM_NL, data.length() - 8); - int coma = data.indexOf(',', nl + 2); - int mux = data.substring(nl + 2, coma).toInt(); + int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8); + int8_t coma = data.indexOf(',', nl + 2); + int8_t mux = data.substring(nl + 2, coma).toInt(); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } @@ -576,18 +576,18 @@ class TinyGsmM95 return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 9ed700c..5f51b24 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -173,7 +173,7 @@ class TinyGsmMC60 sendAT(GF("+QNITZ=1")); if (waitResponse(10000L) != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -305,9 +305,9 @@ class TinyGsmMC60 delay(1000); continue; } - int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), - GF("NOT INSERTED"), GF("PH_SIM PIN"), - GF("PH_SIM PUK")); + int8_t status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), + GF("NOT INSERTED"), GF("PH_SIM PIN"), + GF("PH_SIM PUK")); waitResponse(); switch (status) { case 2: @@ -364,9 +364,9 @@ class TinyGsmMC60 uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host, GF("\","), port); - int rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), - GF("CONNECT FAIL" GSM_NL), - GF("ALREADY CONNECT" GSM_NL)); + int8_t rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), + GF("CONNECT FAIL" GSM_NL), + GF("ALREADY CONNECT" GSM_NL)); return (1 == rsp); } @@ -407,7 +407,7 @@ class TinyGsmMC60 sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size); // If it replies only OK for the write command, it means there is no // received data in the buffer of the connection. - int res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR)); + int8_t res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR)); if (res == 1) { streamSkipUntil(':'); // skip IP address streamSkipUntil(','); // skip port @@ -444,12 +444,12 @@ class TinyGsmMC60 if (waitResponse(GF("+QISTATE:")) != 1) { return false; } - streamSkipUntil(','); // Skip mux - streamSkipUntil(','); // Skip socket type - streamSkipUntil(','); // Skip remote ip - streamSkipUntil(','); // Skip remote port - streamSkipUntil(','); // Skip local port - int res = streamGetInt(','); // socket state + streamSkipUntil(','); // Skip mux + streamSkipUntil(','); // Skip socket type + streamSkipUntil(','); // Skip remote ip + streamSkipUntil(','); // Skip remote port + streamSkipUntil(','); // Skip local port + int8_t res = streamGetInt(','); // socket state waitResponse(); @@ -462,12 +462,12 @@ class TinyGsmMC60 */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL, - GsmConstStr r6 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL, + GsmConstStr r6 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -482,7 +482,7 @@ class TinyGsmMC60 TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -512,20 +512,20 @@ class TinyGsmMC60 streamSkipUntil(','); // Skip the context streamSkipUntil(','); // Skip the role // read the connection id - int mux = streamGetInt(','); + int8_t mux = streamGetInt(','); // read the number of packets in the buffer - int num_packets = streamGetInt(','); + int8_t num_packets = streamGetInt(','); // read the length of the current packet - int len_packet = streamGetInt('\n'); + int16_t len_packet = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_available = len_packet * num_packets; } data = ""; DBG("### Got Data:", len_packet * num_packets, "on", mux); } else if (data.endsWith(GF("CLOSED" GSM_NL))) { - int nl = data.lastIndexOf(GSM_NL, data.length() - 8); - int coma = data.indexOf(',', nl + 2); - int mux = data.substring(nl + 2, coma).toInt(); + int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8); + int8_t coma = data.indexOf(',', nl + 2); + int8_t mux = data.substring(nl + 2, coma).toInt(); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } @@ -545,20 +545,20 @@ class TinyGsmMC60 return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL, - GsmConstStr r6 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL, + GsmConstStr r6 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5, r6); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL, - GsmConstStr r6 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL, + GsmConstStr r6 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5, r6); } diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index 3f5c1f0..60e8189 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -169,7 +169,7 @@ class TinyGsmSim5360 : public TinyGsmModem, sendAT(GF("+CTZU=1")); if (waitResponse(10000L) != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -511,9 +511,9 @@ class TinyGsmSim5360 : public TinyGsmModem, #endif streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip mux/cid (connecion id) - int len_requested = streamGetInt(','); + int16_t len_requested = streamGetInt(','); // ^^ Requested number of data bytes (1-1460 bytes)to be read - int len_confirmed = streamGetInt('\n'); + int16_t len_confirmed = streamGetInt('\n'); // ^^ The data length which not read in the buffer for (int i = 0; i < len_requested; i++) { uint32_t startMillis = millis(); @@ -575,11 +575,11 @@ class TinyGsmSim5360 : public TinyGsmModem, */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -593,7 +593,7 @@ class TinyGsmSim5360 : public TinyGsmModem, TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -615,9 +615,9 @@ class TinyGsmSim5360 : public TinyGsmModem, index = 5; goto finish; } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { - int mode = streamGetInt(','); + int8_t mode = streamGetInt(','); if (mode == 1) { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; } @@ -627,8 +627,8 @@ class TinyGsmSim5360 : public TinyGsmModem, data += mode; } } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { - int mux = streamGetInt(','); - int len = streamGetInt('\n'); + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; sockets[mux]->sock_available = len; @@ -636,7 +636,7 @@ class TinyGsmSim5360 : public TinyGsmModem, data = ""; DBG("### Got Data:", len, "on", mux); } else if (data.endsWith(GF("+IPCLOSE:"))) { - int mux = streamGetInt(','); + int8_t mux = streamGetInt(','); streamSkipUntil('\n'); // Skip the reason code if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; @@ -663,18 +663,18 @@ class TinyGsmSim5360 : public TinyGsmModem, return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index 4c70e96..7d6b45a 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -171,7 +171,7 @@ class TinyGsmSim7000 : public TinyGsmModem, sendAT(GF("+CBATCHK=1")); if (waitResponse() != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -513,15 +513,14 @@ class TinyGsmSim7000 : public TinyGsmModem, bool ssl = false, int timeout_s = 75) { if (ssl) { DBG("SSL not yet supported on this module!"); } - int rsp; uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port); - rsp = waitResponse( - timeout_ms, GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), - GF("ALREADY CONNECT" GSM_NL), GF("ERROR" GSM_NL), - GF("CLOSE OK" GSM_NL)); // Happens when HTTPS handshake fails - return (1 == rsp); + return (1 == + waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL), + GF("CONNECT FAIL" GSM_NL), + GF("ALREADY CONNECT" GSM_NL), GF("ERROR" GSM_NL), + GF("CLOSE OK" GSM_NL))); } int16_t modemSend(const void* buff, size_t len, uint8_t mux) { @@ -544,9 +543,9 @@ class TinyGsmSim7000 : public TinyGsmModem, #endif streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip mux - int len_requested = streamGetInt(','); + int16_t len_requested = streamGetInt(','); // ^^ Requested number of data bytes (1-1460 bytes)to be read - int len_confirmed = streamGetInt('\n'); + int16_t len_confirmed = streamGetInt('\n'); // ^^ Confirmed number of data bytes to be read, which may be less than // requested. 0 indicates that no data can be read. This is actually be the // number of bytes that will be remaining after the read @@ -595,8 +594,8 @@ class TinyGsmSim7000 : public TinyGsmModem, bool modemGetConnected(uint8_t mux) { sendAT(GF("+CIPSTATUS="), mux); - int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), - GF(",\"CLOSING\""), GF(",\"INITIAL\"")); + int8_t res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), + GF(",\"CLOSING\""), GF(",\"INITIAL\"")); waitResponse(); return 1 == res; } @@ -606,11 +605,11 @@ class TinyGsmSim7000 : public TinyGsmModem, */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -624,7 +623,7 @@ class TinyGsmSim7000 : public TinyGsmModem, TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -646,9 +645,9 @@ class TinyGsmSim7000 : public TinyGsmModem, index = 5; goto finish; } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { - int mode = streamGetInt(','); + int8_t mode = streamGetInt(','); if (mode == 1) { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; } @@ -658,8 +657,8 @@ class TinyGsmSim7000 : public TinyGsmModem, data += mode; } } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { - int mux = streamGetInt(','); - int len = streamGetInt('\n'); + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; sockets[mux]->sock_available = len; @@ -667,9 +666,9 @@ class TinyGsmSim7000 : public TinyGsmModem, data = ""; DBG("### Got Data:", len, "on", mux); } else if (data.endsWith(GF("CLOSED" GSM_NL))) { - int nl = data.lastIndexOf(GSM_NL, data.length() - 8); - int coma = data.indexOf(',', nl + 2); - int mux = data.substring(nl + 2, coma).toInt(); + int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8); + int8_t coma = data.indexOf(',', nl + 2); + int8_t mux = data.substring(nl + 2, coma).toInt(); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } @@ -689,18 +688,18 @@ class TinyGsmSim7000 : public TinyGsmModem, return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index f3b50f8..9a1de84 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -173,7 +173,7 @@ class TinyGsmSim7600 : public TinyGsmModem, sendAT(GF("+CTZU=1")); if (waitResponse(10000L) != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -598,9 +598,9 @@ class TinyGsmSim7600 : public TinyGsmModem, #endif streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip mux/cid (connecion id) - int len_requested = streamGetInt(','); + int16_t len_requested = streamGetInt(','); // ^^ Requested number of data bytes (1-1460 bytes)to be read - int len_confirmed = streamGetInt('\n'); + int16_t len_confirmed = streamGetInt('\n'); // ^^ The data length which not read in the buffer for (int i = 0; i < len_requested; i++) { uint32_t startMillis = millis(); @@ -664,11 +664,11 @@ class TinyGsmSim7600 : public TinyGsmModem, */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -682,7 +682,7 @@ class TinyGsmSim7600 : public TinyGsmModem, TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -704,9 +704,9 @@ class TinyGsmSim7600 : public TinyGsmModem, index = 5; goto finish; } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { - int mode = streamGetInt(','); + int8_t mode = streamGetInt(','); if (mode == 1) { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; } @@ -716,8 +716,8 @@ class TinyGsmSim7600 : public TinyGsmModem, data += mode; } } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { - int mux = streamGetInt(','); - int len = streamGetInt('\n'); + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; sockets[mux]->sock_available = len; @@ -725,7 +725,7 @@ class TinyGsmSim7600 : public TinyGsmModem, data = ""; DBG("### Got Data:", len, "on", mux); } else if (data.endsWith(GF("+IPCLOSE:"))) { - int mux = streamGetInt(','); + int8_t mux = streamGetInt(','); streamSkipUntil('\n'); // Skip the reason code if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; @@ -752,18 +752,18 @@ class TinyGsmSim7600 : public TinyGsmModem, return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 9b9c81f..56ff122 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -176,7 +176,7 @@ class TinyGsmSim800 sendAT(GF("+CBATCHK=1")); waitResponse(); - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -480,7 +480,7 @@ class TinyGsmSim800 protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 75) { - int rsp; + int8_t rsp; uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; #if !defined(TINY_GSM_MODEM_SIM900) sendAT(GF("+CIPSSL="), ssl); @@ -516,9 +516,9 @@ class TinyGsmSim800 #endif streamSkipUntil(','); // Skip Rx mode 2/normal or 3/HEX streamSkipUntil(','); // Skip mux - int len_requested = streamGetInt(','); + int16_t len_requested = streamGetInt(','); // ^^ Requested number of data bytes (1-1460 bytes)to be read - int len_confirmed = streamGetInt('\n'); + int16_t len_confirmed = streamGetInt('\n'); // ^^ Confirmed number of data bytes to be read, which may be less than // requested. 0 indicates that no data can be read. This is actually be the // number of bytes that will be remaining after the read @@ -568,9 +568,9 @@ class TinyGsmSim800 bool modemGetConnected(uint8_t mux) { sendAT(GF("+CIPSTATUS="), mux); waitResponse(GF("+CIPSTATUS")); - int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), - GF(",\"CLOSING\""), GF(",\"REMOTE CLOSING\""), - GF(",\"INITIAL\"")); + int8_t res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), + GF(",\"CLOSING\""), GF(",\"REMOTE CLOSING\""), + GF(",\"INITIAL\"")); waitResponse(); return 1 == res; } @@ -580,11 +580,11 @@ class TinyGsmSim800 */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -598,7 +598,7 @@ class TinyGsmSim800 TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -620,9 +620,9 @@ class TinyGsmSim800 index = 5; goto finish; } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { - int mode = streamGetInt(','); + int8_t mode = streamGetInt(','); if (mode == 1) { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; } @@ -632,8 +632,8 @@ class TinyGsmSim800 data += mode; } } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { - int mux = streamGetInt(','); - int len = streamGetInt('\n'); + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; sockets[mux]->sock_available = len; @@ -641,9 +641,9 @@ class TinyGsmSim800 data = ""; DBG("### Got Data:", len, "on", mux); } else if (data.endsWith(GF("CLOSED" GSM_NL))) { - int nl = data.lastIndexOf(GSM_NL, data.length() - 8); - int coma = data.indexOf(',', nl + 2); - int mux = data.substring(nl + 2, coma).toInt(); + int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8); + int8_t coma = data.indexOf(',', nl + 2); + int8_t mux = data.substring(nl + 2, coma).toInt(); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } @@ -663,18 +663,18 @@ class TinyGsmSim800 return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index a1b65b9..514e38d 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -244,7 +244,7 @@ class TinyGsmSaraR4 sendAT(GF("+CTZU=1")); if (waitResponse(10000L) != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -477,7 +477,7 @@ class TinyGsmSaraR4 return getUbloxLocationRaw(1); } - bool inline getUbloxLocation(int8_t sensor, float* lat, float* lon, + inline bool getUbloxLocation(int8_t sensor, float* lat, float* lon, float* speed = 0, int* alt = 0, int* vsat = 0, int* usat = 0, float* accuracy = 0, int* year = 0, int* month = 0, int* day = 0, @@ -594,7 +594,7 @@ class TinyGsmSaraR4 sendAT(GF("+CIND?")); if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; } - int res = streamGetInt(','); + int8_t res = streamGetInt(','); int8_t percent = res * 20; // return is 0-5 // Wait for final OK waitResponse(); @@ -677,7 +677,7 @@ class TinyGsmSaraR4 if (waitResponse(timeout_ms - (millis() - startMillis), GF(GSM_NL "+UUSOCO:")) == 1) { streamGetInt(','); // skip repeated mux - int connection_status = streamGetInt('\n'); + int8_t connection_status = streamGetInt('\n'); DBG("### Waited", millis() - startMillis, "ms for socket to open"); return (0 == connection_status); } else { @@ -688,7 +688,7 @@ class TinyGsmSaraR4 } else { // use synchronous open sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port); - int rsp = waitResponse(timeout_ms - (millis() - startMillis)); + int8_t rsp = waitResponse(timeout_ms - (millis() - startMillis)); return (1 == rsp); } } @@ -702,7 +702,7 @@ class TinyGsmSaraR4 stream.flush(); if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; } streamSkipUntil(','); // Skip mux - int sent = streamGetInt('\n'); + int16_t sent = streamGetInt('\n'); waitResponse(); // sends back OK after the confirmation of number sent return sent; } @@ -711,7 +711,7 @@ class TinyGsmSaraR4 sendAT(GF("+USORD="), mux, ',', (uint16_t)size); if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } streamSkipUntil(','); // Skip mux - int len = streamGetInt(','); + int16_t len = streamGetInt(','); streamSkipUntil('\"'); for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } @@ -748,7 +748,7 @@ class TinyGsmSaraR4 streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip type - int result = streamGetInt('\n'); + int8_t result = streamGetInt('\n'); // 0: the socket is in INACTIVE status (it corresponds to CLOSED status // defined in RFC793 "TCP Protocol Specification" [112]) // 1: the socket is in LISTEN status @@ -770,11 +770,11 @@ class TinyGsmSaraR4 */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -788,7 +788,7 @@ class TinyGsmSaraR4 TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -810,8 +810,8 @@ class TinyGsmSaraR4 index = 5; goto finish; } else if (data.endsWith(GF("+UUSORD:"))) { - int mux = streamGetInt(','); - int len = streamGetInt('\n'); + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; sockets[mux]->sock_available = len; @@ -819,15 +819,15 @@ class TinyGsmSaraR4 data = ""; DBG("### URC Data Received:", len, "on", mux); } else if (data.endsWith(GF("+UUSOCL:"))) { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } data = ""; DBG("### URC Sock Closed: ", mux); } else if (data.endsWith(GF("+UUSOCO:"))) { - int mux = streamGetInt('\n'); - int socket_error = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); + int8_t socket_error = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux] && socket_error == 0) { sockets[mux]->sock_connected = true; @@ -848,18 +848,18 @@ class TinyGsmSaraR4 return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index d1b17ac..ab6a143 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -214,7 +214,7 @@ class TinyGsmSequansMonarch sendAT(GF("+CTZU=1")); if (waitResponse(10000L) != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -247,8 +247,8 @@ class TinyGsmSequansMonarch if (!testAT()) { return false; } sendAT(GF("+CFUN=0")); - int res = waitResponse(20000L, GFP(GSM_OK), GFP(GSM_ERROR), - GF("+SYSSTART")); + int8_t res = waitResponse(20000L, GFP(GSM_OK), GFP(GSM_ERROR), + GF("+SYSSTART")); if (res != 1 && res != 3) { return false; } sendAT(GF("+CFUN=1,1")); @@ -384,7 +384,7 @@ class TinyGsmSequansMonarch protected: bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false, int timeout_s = 75) { - int rsp; + int8_t rsp; uint32_t startMillis = millis(); uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000; @@ -496,7 +496,7 @@ class TinyGsmSequansMonarch sendAT(GF("+SQNSRECV="), mux, ',', (uint16_t)size); if (waitResponse(GF("+SQNSRECV: ")) != 1) { return 0; } streamSkipUntil(','); // Skip mux - int len = streamGetInt('\n'); + int16_t len = streamGetInt('\n'); for (int i = 0; i < len; i++) { uint32_t startMillis = millis(); while (!stream.available() && @@ -562,11 +562,11 @@ class TinyGsmSequansMonarch */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -580,7 +580,7 @@ class TinyGsmSequansMonarch TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -602,8 +602,8 @@ class TinyGsmSequansMonarch index = 5; goto finish; } else if (data.endsWith(GF(GSM_NL "+SQNSRING:"))) { - int mux = streamGetInt(','); - int len = streamGetInt('\n'); + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux % TINY_GSM_MUX_COUNT]) { sockets[mux % TINY_GSM_MUX_COUNT]->got_data = true; @@ -612,7 +612,7 @@ class TinyGsmSequansMonarch data = ""; DBG("### URC Data Received:", len, "on", mux); } else if (data.endsWith(GF("SQNSH: "))) { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux % TINY_GSM_MUX_COUNT]) { sockets[mux % TINY_GSM_MUX_COUNT]->sock_connected = false; @@ -633,18 +633,18 @@ class TinyGsmSequansMonarch return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index ab46f5a..e7d5f26 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -188,7 +188,7 @@ class TinyGsmUBLOX sendAT(GF("+CTZU=1")); if (waitResponse(10000L) != 1) { return false; } - int ret = getSimStatus(); + SimStatus 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) { simUnlock(pin); @@ -338,7 +338,7 @@ class TinyGsmUBLOX // param_tag = 8: PSD profile status: if the profile is active the return // value is 1, 0 otherwise sendAT(GF("+UPSND=0,8")); // Check if PSD profile 0 is now active - int res = waitResponse(GF(",8,1"), GF(",8,0")); + int8_t res = waitResponse(GF(",8,1"), GF(",8,0")); waitResponse(); // Should return another OK if (res == 1) { return true; // It's now active @@ -444,7 +444,7 @@ class TinyGsmUBLOX return getUbloxLocationRaw(1); } - bool inline getUbloxLocation(int8_t sensor, float* lat, float* lon, + inline bool getUbloxLocation(int8_t sensor, float* lat, float* lon, float* speed = 0, int* alt = 0, int* vsat = 0, int* usat = 0, float* accuracy = 0, int* year = 0, int* month = 0, int* day = 0, @@ -561,7 +561,7 @@ class TinyGsmUBLOX sendAT(GF("+CIND?")); if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; } - int res = streamGetInt(','); + int8_t res = streamGetInt(','); int8_t percent = res * 20; // return is 0-5 // Wait for final OK waitResponse(); @@ -621,7 +621,7 @@ class TinyGsmUBLOX // connect on the allocated socket sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port); - int rsp = waitResponse(timeout_ms - (millis() - startMillis)); + int8_t rsp = waitResponse(timeout_ms - (millis() - startMillis)); return (1 == rsp); } @@ -634,7 +634,7 @@ class TinyGsmUBLOX stream.flush(); if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; } streamSkipUntil(','); // Skip mux - int sent = streamGetInt('\n'); + int16_t sent = streamGetInt('\n'); waitResponse(); // sends back OK after the confirmation of number sent return sent; } @@ -643,7 +643,7 @@ class TinyGsmUBLOX sendAT(GF("+USORD="), mux, ',', (uint16_t)size); if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } streamSkipUntil(','); // Skip mux - int len = streamGetInt(','); + int16_t len = streamGetInt(','); streamSkipUntil('\"'); for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } @@ -680,7 +680,7 @@ class TinyGsmUBLOX streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip type - int result = streamGetInt('\n'); + int8_t result = streamGetInt('\n'); // 0: the socket is in INACTIVE status (it corresponds to CLOSED status // defined in RFC793 "TCP Protocol Specification" [112]) // 1: the socket is in LISTEN status @@ -702,11 +702,11 @@ class TinyGsmUBLOX */ public: // TODO(vshymanskyy): Optimize this! - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -720,7 +720,7 @@ class TinyGsmUBLOX TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -742,8 +742,8 @@ class TinyGsmUBLOX index = 5; goto finish; } else if (data.endsWith(GF("+UUSORD:"))) { - int mux = streamGetInt(','); - int len = streamGetInt('\n'); + int8_t mux = streamGetInt(','); + int16_t len = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; sockets[mux]->sock_available = len; @@ -751,7 +751,7 @@ class TinyGsmUBLOX data = ""; DBG("### URC Data Received:", len, "on", mux); } else if (data.endsWith(GF("+UUSOCL:"))) { - int mux = streamGetInt('\n'); + int8_t mux = streamGetInt('\n'); if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } @@ -771,18 +771,18 @@ class TinyGsmUBLOX return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), - GsmConstStr r3 = GFP(GSM_CME_ERROR), - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), + GsmConstStr r3 = GFP(GSM_CME_ERROR), + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index 14658cc..b72229e 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -665,7 +665,7 @@ class TinyGsmXBee } protected: - int16_t getSignalQualityImpl() { + int8_t getSignalQualityImpl() { XBEE_COMMAND_START_DECORATOR(5, 0); if (beeType == XBEE_UNKNOWN) @@ -1270,10 +1270,10 @@ class TinyGsmXBee // NOTE: This function is used while INSIDE command mode, so we're only // waiting for requested responses. The XBee has no unsoliliced responses // (URC's) when in command mode. - uint8_t waitResponse(uint32_t timeout_ms, String& data, - GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, String& data, + GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { /*String r1s(r1); r1s.trim(); String r2s(r2); r2s.trim(); String r3s(r3); r3s.trim(); @@ -1287,7 +1287,7 @@ class TinyGsmXBee TINY_GSM_YIELD(); while (stream.available() > 0) { TINY_GSM_YIELD(); - int a = stream.read(); + int8_t a = stream.read(); if (a <= 0) continue; // Skip 0x00 bytes, just in case data += static_cast(a); if (r1 && data.endsWith(r1)) { @@ -1328,16 +1328,16 @@ class TinyGsmXBee return index; } - uint8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { String data; return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5); } - uint8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), - GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, - GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { + int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK), + GsmConstStr r2 = GFP(GSM_ERROR), GsmConstStr r3 = NULL, + GsmConstStr r4 = NULL, GsmConstStr r5 = NULL) { return waitResponse(1000, r1, r2, r3, r4, r5); } @@ -1356,8 +1356,8 @@ class TinyGsmXBee // Default guard time is 1s, but the init fxn decreases it to 100 ms delay(guardTime + 10); streamWrite(GF("+++")); // enter command mode - int res = waitResponse(guardTime * 2); - success = (1 == res); + int8_t res = waitResponse(guardTime * 2); + success = (1 == res); if (0 == res) { triesUntilReset--; if (triesUntilReset == 0) { diff --git a/src/TinyGsmGPRS.tpp b/src/TinyGsmGPRS.tpp index 6fadc0e..880fec6 100644 --- a/src/TinyGsmGPRS.tpp +++ b/src/TinyGsmGPRS.tpp @@ -128,9 +128,9 @@ class TinyGsmGPRS { delay(1000); continue; } - int status = thisModem().waitResponse(GF("READY"), GF("SIM PIN"), - GF("SIM PUK"), GF("NOT INSERTED"), - GF("NOT READY")); + int8_t status = + thisModem().waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), + GF("NOT INSERTED"), GF("NOT READY")); thisModem().waitResponse(); switch (status) { case 2: @@ -153,7 +153,7 @@ class TinyGsmGPRS { bool isGprsConnectedImpl() { thisModem().sendAT(GF("+CGATT?")); if (thisModem().waitResponse(GF("+CGATT:")) != 1) { return false; } - int res = thisModem().streamGetInt('\n'); + int8_t res = thisModem().streamGetInt('\n'); thisModem().waitResponse(); if (res != 1) { return false; } diff --git a/src/TinyGsmModem.tpp b/src/TinyGsmModem.tpp index 07710b8..64cdc3b 100644 --- a/src/TinyGsmModem.tpp +++ b/src/TinyGsmModem.tpp @@ -24,7 +24,7 @@ class TinyGsmModem { return thisModem().initImpl(pin); } template - void sendAT(Args... cmd) { + inline void sendAT(Args... cmd) { thisModem().streamWrite("AT", cmd..., thisModem().gsmNL); thisModem().stream.flush(); TINY_GSM_YIELD(); /* DBG("### AT:", cmd...); */ @@ -180,11 +180,11 @@ class TinyGsmModem { // CREG = Generic network registration // CGREG = GPRS service registration // CEREG = EPS registration for LTE modules - int getRegistrationStatusXREG(const char* regCommand) { + int8_t getRegistrationStatusXREG(const char* regCommand) { thisModem().sendAT('+', regCommand, '?'); // check for any of the three for simplicity - int resp = thisModem().waitResponse(GF("+CREG:"), GF("+CGREG:"), - GF("+CEREG:")); + int8_t resp = thisModem().waitResponse(GF("+CREG:"), GF("+CGREG:"), + GF("+CEREG:")); if (resp != 1 && resp != 2 && resp != 3) { return -1; } thisModem().streamSkipUntil(','); /* Skip format (0) */ int status = thisModem().streamGetInt('\n'); @@ -201,10 +201,10 @@ class TinyGsmModem { } // Gets signal quality report according to 3GPP TS command AT+CSQ - int16_t getSignalQualityImpl() { + int8_t getSignalQualityImpl() { thisModem().sendAT(GF("+CSQ")); if (thisModem().waitResponse(GF("+CSQ:")) != 1) { return 99; } - int res = thisModem().streamGetInt(','); + int8_t res = thisModem().streamGetInt(','); thisModem().waitResponse(); return res; } @@ -218,7 +218,7 @@ class TinyGsmModem { return res; } - static IPAddress TinyGsmIpFromString(const String& strIP) { + static inline IPAddress TinyGsmIpFromString(const String& strIP) { int Parts[4] = { 0, }; @@ -245,17 +245,17 @@ class TinyGsmModem { protected: // Utility templates for writing/skipping characters on a stream template - void inline streamWrite(T last) { + inline void streamWrite(T last) { thisModem().stream.print(last); } template - void inline streamWrite(T head, Args... tail) { + inline void streamWrite(T head, Args... tail) { thisModem().stream.print(head); thisModem().streamWrite(tail...); } - int16_t inline streamGetInt(int8_t numChars) { + inline int16_t streamGetInt(int8_t numChars) { char buf[6]; size_t bytesRead = thisModem().stream.readBytes(buf, numChars); if (bytesRead) { @@ -269,7 +269,7 @@ class TinyGsmModem { template // calling with template only to prevent promotion of char to int - int16_t inline streamGetInt(T lastChar) { + inline int16_t streamGetInt(T lastChar) { char buf[6]; size_t bytesRead = thisModem().stream.readBytesUntil( lastChar, buf, static_cast(6)); @@ -282,7 +282,7 @@ class TinyGsmModem { } } - float inline streamGetFloat(int8_t numChars) { + inline float streamGetFloat(int8_t numChars) { char buf[16]; size_t bytesRead = thisModem().stream.readBytes(buf, numChars); DBG("### bytesRead:", bytesRead); @@ -297,7 +297,7 @@ class TinyGsmModem { template // calling with template only to prevent promotion of char to int - float inline streamGetFloat(T lastChar) { + inline float streamGetFloat(T lastChar) { char buf[16]; size_t bytesRead = thisModem().stream.readBytesUntil( lastChar, buf, static_cast(16)); @@ -310,7 +310,7 @@ class TinyGsmModem { } } - bool inline streamSkipUntil(const char c, const uint32_t timeout_ms = 1000L) { + inline bool streamSkipUntil(const char c, const uint32_t timeout_ms = 1000L) { uint32_t startMillis = millis(); while (millis() - startMillis < timeout_ms) { while (millis() - startMillis < timeout_ms && @@ -322,7 +322,7 @@ class TinyGsmModem { return false; } - void inline streamClear() { + inline void streamClear() { while (thisModem().stream.available()) { thisModem().waitResponse(50, NULL, NULL); } diff --git a/src/TinyGsmSMS.tpp b/src/TinyGsmSMS.tpp index 15ecc7f..9246994 100644 --- a/src/TinyGsmSMS.tpp +++ b/src/TinyGsmSMS.tpp @@ -47,7 +47,7 @@ class TinyGsmSMS { static inline String TinyGsmDecodeHex7bit(String& instr) { String result; byte reminder = 0; - int bitstate = 7; + int8_t bitstate = 7; for (uint8_t i = 0; i < instr.length(); i += 2) { char buf[4] = { 0, @@ -125,7 +125,7 @@ class TinyGsmSMS { thisModem().stream.readStringUntil('"'); String hex = thisModem().stream.readStringUntil('"'); thisModem().stream.readStringUntil(','); - int dcs = thisModem().streamGetInt('\n'); + int8_t dcs = thisModem().streamGetInt('\n'); if (dcs == 15) { return TinyGsmDecodeHex8bit(hex); diff --git a/src/TinyGsmTCP.tpp b/src/TinyGsmTCP.tpp index 7c47ec7..d9f0a5b 100644 --- a/src/TinyGsmTCP.tpp +++ b/src/TinyGsmTCP.tpp @@ -263,7 +263,7 @@ class TinyGsmTCP { // closes until all data is read from the buffer. // 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. - void inline dumpModemBuffer(uint32_t maxWaitMs) { + inline void dumpModemBuffer(uint32_t maxWaitMs) { TINY_GSM_YIELD(); rx.clear(); at->maintain(); @@ -317,7 +317,7 @@ class TinyGsmTCP { // character return? Will wait once in the first "while // !stream.available()" and then will wait again in the stream.read() // function. - void inline moveCharFromStreamToFifo(uint8_t mux) { + inline void moveCharFromStreamToFifo(uint8_t mux) { uint32_t startMillis = millis(); while (!thisModem().stream.available() && (millis() - startMillis < thisModem().sockets[mux]->_timeout)) {