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; }