From 868e2bedf9b73e1b666750f4469ba6a10c15f73e Mon Sep 17 00:00:00 2001 From: Adrian Cervera Andes Date: Thu, 30 Apr 2020 16:22:09 +0200 Subject: [PATCH 1/2] Added setPhoneFunctionalityImpl function --- src/TinyGsmClientBG96.h | 8 ++++++-- src/TinyGsmClientM590.h | 8 ++++++-- src/TinyGsmClientMC60.h | 11 +++++++---- src/TinyGsmClientSIM5360.h | 8 ++++++-- src/TinyGsmClientSIM7000.h | 11 +++++++---- src/TinyGsmClientSIM7600.h | 8 ++++++-- src/TinyGsmClientSIM800.h | 15 +++++++++++---- src/TinyGsmClientSaraR4.h | 8 ++++++-- src/TinyGsmClientUBLOX.h | 11 +++++++---- src/TinyGsmModem.tpp | 6 ++++-- 10 files changed, 66 insertions(+), 28 deletions(-) diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index b5c36a0..ad777a2 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -203,8 +203,7 @@ class TinyGsmBG96 : public TinyGsmModem, protected: bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=1,1")); - if (waitResponse(10000L, GF("OK")) != 1) { return false; } + if (!setPhoneFunctionality(1, true)) { return false; } waitResponse(10000L, GF("APP RDY")); return init(); } @@ -225,6 +224,11 @@ class TinyGsmBG96 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L, GF("OK")) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 8b915ee..6a8986f 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -172,8 +172,7 @@ class TinyGsmM590 : public TinyGsmModem, protected: bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=15")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(15)) { return false; } // MODEM:STARTUP waitResponse(60000L, GF(GSM_NL "+PBREADY" GSM_NL)); return init(); @@ -189,6 +188,11 @@ class TinyGsmM590 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index a71e96a..7e177a4 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -198,10 +198,8 @@ class TinyGsmMC60 : public TinyGsmModem, protected: bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=0")); - if (waitResponse(10000L) != 1) { return false; } - sendAT(GF("+CFUN=1,1")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(0)) { return false; } + if (!setPhoneFunctionality(1, true)) { return false; } delay(3000); return init(); } @@ -221,6 +219,11 @@ class TinyGsmMC60 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index 7ce9b50..ea63454 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -233,8 +233,7 @@ class TinyGsmSim5360 : public TinyGsmModem, } bool radioOffImpl() { - sendAT(GF("+CFUN=4")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(4)) { return false; } delay(3000); return true; } @@ -244,6 +243,11 @@ class TinyGsmSim5360 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index eab1d68..bc56fae 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -212,10 +212,8 @@ class TinyGsmSim7000 : public TinyGsmModem, */ protected: bool restartImpl() { - sendAT(GF("+CFUN=0")); - if (waitResponse(10000L) != 1) { return false; } - sendAT(GF("+CFUN=1,1")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(0)) { return false; } + if (!setPhoneFunctionality(1, true)) { return false; } waitResponse(10000L, GF("SMS Ready"), GF("RDY")); return init(); } @@ -234,6 +232,11 @@ class TinyGsmSim7000 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index d2f2c35..38aa092 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -232,8 +232,7 @@ class TinyGsmSim7600 : public TinyGsmModem, } bool radioOffImpl() { - sendAT(GF("+CFUN=4")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(4)) { return false; } delay(3000); return true; } @@ -243,6 +242,11 @@ class TinyGsmSim7600 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index cabfaca..a6bdcaf 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -253,10 +253,8 @@ class TinyGsmSim800 : public TinyGsmModem, if (!testAT()) { return false; } sendAT(GF("&W")); waitResponse(); - sendAT(GF("+CFUN=0")); - if (waitResponse(10000L) != 1) { return false; } - sendAT(GF("+CFUN=1,1")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(0)) { return false; } + if (!setPhoneFunctionality(1, true)) { return false; } delay(3000); return init(); } @@ -275,6 +273,15 @@ class TinyGsmSim800 : public TinyGsmModem, return waitResponse() == 1; } + // 0 Minimum functionality + // 1 Full functionality (Default) + // 4 Disable phone both transmit and receive RF circuits. + // Reset the MT before setting it to power level. + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 09dbd9f..816e5d4 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -298,8 +298,7 @@ class TinyGsmSaraR4 : public TinyGsmModem, // using +CFUN=15 instead of the more common CFUN=1,1 bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=15")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(15)) { return false; } delay(3000); // TODO(?): Verify delay timing here return init(); } @@ -311,6 +310,11 @@ class TinyGsmSaraR4 : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 98ea7a0..764a223 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -235,8 +235,7 @@ class TinyGsmUBLOX : public TinyGsmModem, bool factoryDefaultImpl() { sendAT(GF("+UFACTORY=0,1")); // No factory restore, erase NVM waitResponse(); - sendAT(GF("+CFUN=16")); // Reset - return waitResponse() == 1; + return setPhoneFunctionality(16); // Reset } /* @@ -245,8 +244,7 @@ class TinyGsmUBLOX : public TinyGsmModem, protected: bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=16")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(16)) { return false; } delay(3000); // TODO(?): Verify delay timing here return init(); } @@ -258,6 +256,11 @@ class TinyGsmUBLOX : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmModem.tpp b/src/TinyGsmModem.tpp index d088546..519b3c4 100644 --- a/src/TinyGsmModem.tpp +++ b/src/TinyGsmModem.tpp @@ -65,6 +65,9 @@ class TinyGsmModem { bool sleepEnable(bool enable = true) { return thisModem().sleepEnableImpl(enable); } + bool setPhoneFunctionality(uint8_t fun, bool reset = false) { + return thisModem().setPhoneFunctionality(fun, reset); + } /* * Generic network functions @@ -164,8 +167,7 @@ class TinyGsmModem { */ protected: bool radioOffImpl() { - thisModem().sendAT(GF("+CFUN=0")); - if (thisModem().waitResponse(10000L) != 1) { return false; } + if (!thisModem().setPhoneFunctionality(0)) { return false; } delay(3000); return true; } From 5fbd80b3b26f647070a442727511d286f026e431 Mon Sep 17 00:00:00 2001 From: Adrian Cervera Andes Date: Thu, 30 Apr 2020 16:49:45 +0200 Subject: [PATCH 2/2] Fixed bad reference and added not implemented --- src/TinyGsmClientA6.h | 2 ++ src/TinyGsmClientESP8266.h | 2 ++ src/TinyGsmClientM95.h | 2 ++ src/TinyGsmClientSequansMonarch.h | 2 ++ src/TinyGsmClientXBee.h | 2 ++ src/TinyGsmModem.tpp | 4 +++- 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 0983597..3a344fa 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -190,6 +190,8 @@ class TinyGsmA6 : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 9a8687a..38d8a50 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -200,6 +200,8 @@ class TinyGsmESP8266 : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index a0878ab..16a07e0 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -226,6 +226,8 @@ class TinyGsmM95 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index 8f85edd..393a918 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -315,6 +315,8 @@ class TinyGsmSequansMonarch return waitResponse() == 1; } + bool setPhoneFunctionality(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index e3b39a0..0669351 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -572,6 +572,8 @@ class TinyGsmXBee : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmModem.tpp b/src/TinyGsmModem.tpp index 519b3c4..b813bea 100644 --- a/src/TinyGsmModem.tpp +++ b/src/TinyGsmModem.tpp @@ -66,7 +66,7 @@ class TinyGsmModem { return thisModem().sleepEnableImpl(enable); } bool setPhoneFunctionality(uint8_t fun, bool reset = false) { - return thisModem().setPhoneFunctionality(fun, reset); + return thisModem().setPhoneFunctionalityImpl(fun, reset); } /* @@ -174,6 +174,8 @@ class TinyGsmModem { bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */