From 56dca5185baf5418bd3d6a9b360fcf82f6c966c4 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Fri, 7 Sep 2018 18:15:42 -0400 Subject: [PATCH] Added virtual master class --- src/TinyGsmClientA6.h | 12 ++--- src/TinyGsmClientBG96.h | 12 ++--- src/TinyGsmClientESP8266.h | 12 ++--- src/TinyGsmClientM590.h | 12 ++--- src/TinyGsmClientM95.h | 12 ++--- src/TinyGsmClientMC60.h | 37 +++------------ src/TinyGsmClientSIM800.h | 12 ++--- src/TinyGsmClientUBLOX.h | 12 ++--- src/TinyGsmClientXBee.h | 12 ++--- src/TinyGsmCommon.h | 95 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 149 insertions(+), 79 deletions(-) diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index 6ad2752..9dbd80c 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -39,7 +39,7 @@ enum RegStatus { }; -class TinyGsmA6 +class TinyGsmA6 : public TinyGsmMasterModem { public: @@ -182,7 +182,7 @@ public: #else TinyGsmA6(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -445,6 +445,10 @@ public: return (res == 1); } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR")); String res; @@ -457,10 +461,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index 566ad3d..6a1de31 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmBG96 +class TinyGsmBG96 : public TinyGsmMasterModem { public: @@ -206,7 +206,7 @@ public: #else TinyGsmBG96(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -467,6 +467,10 @@ public: return localIP() != 0; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CGPADDR=1")); if (waitResponse(10000L, GF(GSM_NL "+CGPADDR:")) != 1) { @@ -480,10 +484,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 1a990ad..4381e85 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -39,7 +39,7 @@ enum RegStatus { -class TinyGsmESP8266 +class TinyGsmESP8266 : public TinyGsmMasterModem { public: @@ -198,7 +198,7 @@ public: #else TinyGsmESP8266(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -366,6 +366,10 @@ public: return retVal; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIPSTA_CUR??")); int res1 = waitResponse(GF("ERROR"), GF("+CWJAP_CUR:")); @@ -377,10 +381,6 @@ public: return res2; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * GPRS functions */ diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 5c085ae..d3ef97f 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -39,7 +39,7 @@ enum RegStatus { }; -class TinyGsmM590 +class TinyGsmM590 : public TinyGsmMasterModem { public: @@ -179,7 +179,7 @@ public: #else TinyGsmM590(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -451,6 +451,10 @@ public: return res == 1; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+XIIC?")); if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { @@ -463,10 +467,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index 808cea7..e45b94f 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmM95 +class TinyGsmM95 : public TinyGsmMasterModem { public: @@ -186,7 +186,7 @@ public: #else TinyGsmM95(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -470,6 +470,10 @@ public: return true; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+QILOCIP")); stream.readStringUntil('\n'); @@ -478,10 +482,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Phone Call functions */ diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index 8928c41..7c1c0f4 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -43,24 +43,10 @@ enum RegStatus { REG_UNKNOWN = 4, }; -//============================================================================// -//============================================================================// -// Declaration of the TinyGsmMC60 Class -//============================================================================// -//============================================================================// - - -class TinyGsmMC60 +class TinyGsmMC60 : public TinyGsmMasterModem { -//============================================================================// -//============================================================================// -// The MC60 Internal Client Class -//============================================================================// -//============================================================================// - - public: class GsmClient : public Client @@ -199,12 +185,6 @@ private: RxFifo rx; }; -//============================================================================// -//============================================================================// -// The MC60 Secure Client -//============================================================================// -//============================================================================// - class GsmClientSecure : public GsmClient { @@ -225,11 +205,6 @@ public: } }; -//============================================================================// -//============================================================================// -// The MC60 Modem Functions -//============================================================================// -//============================================================================// public: @@ -238,7 +213,7 @@ public: #else TinyGsmMC60(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -614,6 +589,10 @@ public: return waitResponse(60000L) == 1; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR;E0")); String res; @@ -624,10 +603,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index a6fd8a5..2a77e1b 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -46,7 +46,7 @@ enum RegStatus { //============================================================================// -class TinyGsmSim800 +class TinyGsmSim800 : public TinyGsmMasterModem { //============================================================================// @@ -228,7 +228,7 @@ public: #else TinyGsmSim800(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -602,6 +602,10 @@ public: return true; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+CIFSR;E0")); String res; @@ -614,10 +618,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index c411e63..f98ff2b 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -40,7 +40,7 @@ enum RegStatus { }; -class TinyGsmUBLOX +class TinyGsmUBLOX : public TinyGsmMasterModem { public: @@ -205,7 +205,7 @@ public: #else TinyGsmUBLOX(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) { memset(sockets, 0, sizeof(sockets)); } @@ -485,6 +485,10 @@ public: return localIP() != 0; } + /* + * IP Address functions + */ + String getLocalIP() { sendAT(GF("+UPSND=0,0")); if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) { @@ -499,10 +503,6 @@ public: return res; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * Messaging functions */ diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index f297a1b..89cc696 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -45,7 +45,7 @@ enum XBeeType { }; -class TinyGsmXBee +class TinyGsmXBee : public TinyGsmMasterModem { public: @@ -211,7 +211,7 @@ public: #else TinyGsmXBee(Stream& stream) #endif - : stream(stream) + : TinyGsmMasterModem(stream), stream(stream) {} /* @@ -559,6 +559,10 @@ fail: return res; } + /* + * IP Address functions + */ + String getLocalIP() { if (!commandMode()) return ""; // Return immediately sendAT(GF("MY")); @@ -570,10 +574,6 @@ fail: return IPaddr; } - IPAddress localIP() { - return TinyGsmIpFromString(getLocalIP()); - } - /* * GPRS functions */ diff --git a/src/TinyGsmCommon.h b/src/TinyGsmCommon.h index b803651..9df812f 100644 --- a/src/TinyGsmCommon.h +++ b/src/TinyGsmCommon.h @@ -194,4 +194,99 @@ String TinyGsmDecodeHex16bit(String &instr) { return result; } + + + +class TinyGsmMasterModem +{ + +public: + +class GsmClient : public Client +{ + friend class TinyGsmXBee; +}; + + +public: + +#ifdef GSM_DEFAULT_STREAM + TinyGsmMasterModem(Stream& stream = GSM_DEFAULT_STREAM) +#else + TinyGsmMasterModem(Stream& stream) +#endif + : stream(stream) + {} + + /* + * Basic functions + */ + + virtual bool begin() = 0; + virtual bool init() = 0; + virtual void setBaud(unsigned long baud) = 0; + virtual bool testAT(unsigned long timeout = 10000L) = 0; + virtual void maintain() = 0; + virtual bool factoryDefault() = 0; + virtual String getModemInfo() = 0; + virtual bool hasSSL() = 0; + + /* + * Power functions + */ + + virtual bool restart() = 0; + + /* + * SIM card functions + */ + + virtual bool simUnlock(const char *pin) = 0; + virtual String getSimCCID() = 0; + virtual String getIMEI() = 0; + virtual String getOperator() = 0; + + /* + * Generic network functions + */ + + virtual int getSignalQuality() = 0; + virtual bool isNetworkConnected() = 0; + + /* + * WiFi functions + */ + + virtual bool networkConnect(const char* ssid, const char* pwd) = 0; + virtual bool networkDisconnect() = 0; + + /* + * GPRS functions + */ + virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) = 0; + virtual bool gprsDisconnect() = 0; + virtual bool isGprsConnected() = 0; + + /* + * IP Address functions + */ + + virtual String getLocalIP() = 0; + virtual IPAddress localIP() { + return TinyGsmIpFromString(getLocalIP()); + } + + /* + * Messaging functions + */ + + virtual bool sendSMS(const String& number, const String& text) = 0; + +public: + Stream& stream; +}; + + + + #endif