From 41531c339bf0408f433ff674ae5e47fc0b109444 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Tue, 11 Feb 2020 11:08:03 -0500 Subject: [PATCH] Reorder some functions --- src/TinyGsmClientA6.h | 44 ++++++++++--------- src/TinyGsmClientBG96.h | 32 +++++++------- src/TinyGsmClientESP8266.h | 28 ++++++------ src/TinyGsmClientM590.h | 34 ++++++++------- src/TinyGsmClientM95.h | 36 ++++++++-------- src/TinyGsmClientMC60.h | 72 ++++++++++++++++--------------- src/TinyGsmClientSIM5360.h | 48 +++++++++++---------- src/TinyGsmClientSIM7000.h | 34 ++++++++------- src/TinyGsmClientSIM7600.h | 48 +++++++++++---------- src/TinyGsmClientSIM800.h | 34 ++++++++------- src/TinyGsmClientSaraR4.h | 34 ++++++++------- src/TinyGsmClientSequansMonarch.h | 40 +++++++++-------- src/TinyGsmClientUBLOX.h | 48 ++++++++++++--------- src/TinyGsmClientXBee.h | 68 +++++++++++++---------------- 14 files changed, 317 insertions(+), 283 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index f0d62af..4d14984 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -189,19 +189,6 @@ class TinyGsmA6 bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; - /* - * SIM card functions - */ - protected: - String getSimCCIDImpl() { - sendAT(GF("+CCID")); - if (waitResponse(GF(GSM_NL "+SCID: SIM Card ID:")) != 1) { return ""; } - String res = stream.readStringUntil('\n'); - waitResponse(); - res.trim(); - return res; - } - /* * Generic network functions */ @@ -216,6 +203,22 @@ class TinyGsmA6 return (s == REG_OK_HOME || s == REG_OK_ROAMING); } + /* + * IP Address functions + */ + protected: + String getLocalIPImpl() { + sendAT(GF("+CIFSR")); + String res; + if (waitResponse(10000L, res) != 1) { + return ""; + } + res.replace(GSM_NL "OK" GSM_NL, ""); + res.replace(GSM_NL, ""); + res.trim(); + return res; + } + /* * GPRS functions */ @@ -272,15 +275,16 @@ class TinyGsmA6 } /* - * IP Address functions + * SIM card functions */ protected: - String getLocalIPImpl() { - sendAT(GF("+CIFSR")); - String res; - if (waitResponse(10000L, res) != 1) { return ""; } - res.replace(GSM_NL "OK" GSM_NL, ""); - res.replace(GSM_NL, ""); + String getSimCCIDImpl() { + sendAT(GF("+CCID")); + if (waitResponse(GF(GSM_NL "+SCID: SIM Card ID:")) != 1) { + return ""; + } + String res = stream.readStringUntil('\n'); + waitResponse(); res.trim(); return res; } diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index e47c623..b7b7706 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -208,19 +208,6 @@ class TinyGsmBG96 return waitResponse() == 1; } - /* - * SIM card functions - */ - protected: - String getSimCCIDImpl() { - sendAT(GF("+QCCID")); - if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) { return ""; } - String res = stream.readStringUntil('\n'); - waitResponse(); - res.trim(); - return res; - } - /* * Generic network functions */ @@ -235,6 +222,12 @@ class TinyGsmBG96 return (s == REG_OK_HOME || s == REG_OK_ROAMING); } + /* + * IP Address functions + */ + protected: + // Can follow all of the IP functions from the template + /* * GPRS functions */ @@ -267,10 +260,19 @@ class TinyGsmBG96 } /* - * IP Address functions + * SIM card functions */ protected: - // Can follow all of the IP functions from the template + String getSimCCIDImpl() { + sendAT(GF("+QCCID")); + if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) { + return ""; + } + String res = stream.readStringUntil('\n'); + waitResponse(); + res.trim(); + return res; + } /* * Phone Call functions diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 7433b8f..156cb1f 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -257,6 +257,21 @@ class TinyGsmESP8266 } } + /* + * IP Address functions + */ + protected: + String getLocalIPImpl() { + sendAT(GF("+CIPSTA_CUR?")); + int res1 = waitResponse(GF("ERROR"), GF("+CWJAP_CUR:")); + if (res1 != 2) { + return ""; + } + String res2 = stream.readStringUntil('"'); + waitResponse(); + return res2; + } + /* * WiFi functions */ @@ -277,19 +292,6 @@ class TinyGsmESP8266 return retVal; } - /* - * IP Address functions - */ - protected: - String getLocalIPImpl() { - sendAT(GF("+CIPSTA_CUR?")); - int res1 = waitResponse(GF("ERROR"), GF("+CWJAP_CUR:")); - if (res1 != 2) { return ""; } - String res2 = stream.readStringUntil('"'); - waitResponse(); - return res2; - } - /* * Phone Call functions */ diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index a508273..a54357a 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -190,12 +190,6 @@ class TinyGsmM590 return waitResponse() == 1; } - /* - * SIM card functions - */ - protected: - // Able to follow all SIM card functions as inherited from the template - /* * Generic network functions */ @@ -210,6 +204,22 @@ class TinyGsmM590 return (s == REG_OK_HOME || s == REG_OK_ROAMING); } + /* + * IP Address functions + */ + protected: + String getLocalIPImpl() { + sendAT(GF("+XIIC?")); + if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { + return ""; + } + streamSkipUntil(','); + String res = stream.readStringUntil('\n'); + waitResponse(); + res.trim(); + return res; + } + /* * GPRS functions */ @@ -267,18 +277,10 @@ class TinyGsmM590 } /* - * IP Address functions + * SIM card functions */ protected: - String getLocalIPImpl() { - sendAT(GF("+XIIC?")); - if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return ""; } - streamSkipUntil(','); - String res = stream.readStringUntil('\n'); - waitResponse(); - res.trim(); - return res; - } + // Able to follow all SIM card functions as inherited from the template /* * Phone Call functions diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 223bcc5..af63f01 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -217,19 +217,6 @@ class TinyGsmM95 return waitResponse() == 1; } - /* - * SIM card functions - */ - protected: - String getSimCCIDImpl() { - sendAT(GF("+QCCID")); - if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) { return ""; } - String res = stream.readStringUntil('\n'); - waitResponse(); - res.trim(); - return res; - } - /* * Generic network functions */ @@ -254,6 +241,18 @@ class TinyGsmM95 waitResponse(); } + /* + * IP Address functions + */ + protected: + String getLocalIPImpl() { + sendAT(GF("+QILOCIP")); + streamSkipUntil('\n'); + String res = stream.readStringUntil('\n'); + res.trim(); + return res; + } + /* * GPRS functions */ @@ -334,13 +333,16 @@ class TinyGsmM95 } /* - * IP Address functions + * SIM card functions */ protected: - String getLocalIPImpl() { - sendAT(GF("+QILOCIP")); - streamSkipUntil('\n'); + String getSimCCIDImpl() { + sendAT(GF("+QCCID")); + if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) { + return ""; + } String res = stream.readStringUntil('\n'); + waitResponse(); res.trim(); return res; } diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 0ee5496..bb4b3e5 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -226,33 +226,6 @@ class TinyGsmMC60 return waitResponse() == 1; } - /* - * SIM card functions - */ - protected: - SimStatus getSimStatusImpl(uint32_t timeout_ms = 10000L) { - for (uint32_t start = millis(); millis() - start < timeout_ms;) { - sendAT(GF("+CPIN?")); - if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { - 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")); - waitResponse(); - switch (status) { - case 2: - case 3: return SIM_LOCKED; - case 5: - case 6: return SIM_ANTITHEFT_LOCKED; - case 1: return SIM_READY; - default: return SIM_ERROR; - } - } - return SIM_ERROR; - } - /* * Generic network functions */ @@ -267,6 +240,18 @@ class TinyGsmMC60 return (s == REG_OK_HOME || s == REG_OK_ROAMING); } + /* + * IP Address functions + */ + protected: + String getLocalIPImpl() { + sendAT(GF("+QILOCIP")); + streamSkipUntil('\n'); + String res = stream.readStringUntil('\n'); + res.trim(); + return res; + } + /* * GPRS functions */ @@ -326,15 +311,34 @@ class TinyGsmMC60 } /* - * IP Address functions + * SIM card functions */ protected: - String getLocalIPImpl() { - sendAT(GF("+QILOCIP")); - streamSkipUntil('\n'); - String res = stream.readStringUntil('\n'); - res.trim(); - return res; + SimStatus getSimStatusImpl(uint32_t timeout_ms = 10000L) { + for (uint32_t start = millis(); millis() - start < timeout_ms;) { + sendAT(GF("+CPIN?")); + if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) { + 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")); + waitResponse(); + switch (status) { + case 2: + case 3: + return SIM_LOCKED; + case 5: + case 6: + return SIM_ANTITHEFT_LOCKED; + case 1: + return SIM_READY; + default: + return SIM_ERROR; + } + } + return SIM_ERROR; } /* diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index 3588a3e..8740cd1 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -227,20 +227,6 @@ class TinyGsmSim5360 : public TinyGsmModem 0) { - DBG("XBee's do not support SIMs that require an unlock pin!"); - } - return false; - } - - String getSimCCIDImpl() { - return sendATGetString(GF("S#")); - } - - String getIMEIImpl() { - return sendATGetString(GF("IM")); - } - - SimStatus getSimStatusImpl(uint32_t) { - return SIM_READY; // unsupported - } - /* * Generic network functions */ @@ -715,6 +692,22 @@ class TinyGsmXBee return retVal; } + /* + * IP Address functions + */ + protected: + String getLocalIPImpl() { + XBEE_COMMAND_START_DECORATOR(5, "") + sendAT(GF("MY")); + String IPaddr; + IPaddr.reserve(16); + // wait for the response - this response can be very slow + IPaddr = readResponseString(30000); + XBEE_COMMAND_END_DECORATOR + IPaddr.trim(); + return IPaddr; + } + /* * WiFi functions */ @@ -795,24 +788,25 @@ class TinyGsmXBee return isNetworkConnected(); } - String getOperatorImpl() { - return sendATGetString(GF("MN")); - } + String getOperatorImpl() { return sendATGetString(GF("MN")); } /* - * IP Address functions + * SIM card functions */ protected: - String getLocalIPImpl() { - XBEE_COMMAND_START_DECORATOR(5, "") - sendAT(GF("MY")); - String IPaddr; - IPaddr.reserve(16); - // wait for the response - this response can be very slow - IPaddr = readResponseString(30000); - XBEE_COMMAND_END_DECORATOR - IPaddr.trim(); - return IPaddr; + bool simUnlockImpl(const char* pin) { // Not supported + if (pin && strlen(pin) > 0) { + DBG("XBee's do not support SIMs that require an unlock pin!"); + } + return false; + } + + String getSimCCIDImpl() { return sendATGetString(GF("S#")); } + + String getIMEIImpl() { return sendATGetString(GF("IM")); } + + SimStatus getSimStatusImpl(uint32_t) { + return SIM_READY; // unsupported } /*