Many sub templates to inherit from!
This commit is contained in:
@@ -15,7 +15,15 @@
|
||||
|
||||
#define TINY_GSM_MUX_COUNT 5
|
||||
|
||||
#include "TinyGsmCommon.h"
|
||||
#include "TinyGsmBattery.tpp"
|
||||
#include "TinyGsmCalling.tpp"
|
||||
#include "TinyGsmGPRS.tpp"
|
||||
#include "TinyGsmGSMLocation.tpp"
|
||||
#include "TinyGsmModem.tpp"
|
||||
#include "TinyGsmSMS.tpp"
|
||||
#include "TinyGsmSSL.tpp"
|
||||
#include "TinyGsmTCP.tpp"
|
||||
#include "TinyGsmTime.tpp"
|
||||
|
||||
#define GSM_NL "\r\n"
|
||||
static const char GSM_OK[] TINY_GSM_PROGMEM = "OK" GSM_NL;
|
||||
@@ -31,10 +39,26 @@ enum RegStatus {
|
||||
REG_OK_ROAMING = 5,
|
||||
REG_UNKNOWN = 4,
|
||||
};
|
||||
class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
TINY_GSM_MUX_COUNT> {
|
||||
friend class TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
TINY_GSM_MUX_COUNT>;
|
||||
class TinyGsmSim800
|
||||
: public TinyGsmModem<TinyGsmSim800>,
|
||||
public TinyGsmGPRS<TinyGsmSim800>,
|
||||
public TinyGsmTCP<TinyGsmSim800, READ_AND_CHECK_SIZE, TINY_GSM_MUX_COUNT>,
|
||||
public TinyGsmSSL<TinyGsmSim800>,
|
||||
public TinyGsmCalling<TinyGsmSim800>,
|
||||
public TinyGsmSMS<TinyGsmSim800>,
|
||||
public TinyGsmGSMLocation<TinyGsmSim800>,
|
||||
public TinyGsmTime<TinyGsmSim800>,
|
||||
public TinyGsmBattery<TinyGsmSim800> {
|
||||
friend class TinyGsmModem<TinyGsmSim800>;
|
||||
friend class TinyGsmGPRS<TinyGsmSim800>;
|
||||
friend class TinyGsmTCP<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
TINY_GSM_MUX_COUNT>;
|
||||
friend class TinyGsmSSL<TinyGsmSim800>;
|
||||
friend class TinyGsmCalling<TinyGsmSim800>;
|
||||
friend class TinyGsmSMS<TinyGsmSim800>;
|
||||
friend class TinyGsmGSMLocation<TinyGsmSim800>;
|
||||
friend class TinyGsmTime<TinyGsmSim800>;
|
||||
friend class TinyGsmBattery<TinyGsmSim800>;
|
||||
|
||||
/*
|
||||
* Inner Client
|
||||
@@ -64,24 +88,16 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
}
|
||||
|
||||
public:
|
||||
int connect(const char* host, uint16_t port, int timeout_s) {
|
||||
virtual int connect(const char* host, uint16_t port, int timeout_s) {
|
||||
stop();
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
sock_connected = at->modemConnect(host, port, mux, false, timeout_s);
|
||||
return sock_connected;
|
||||
}
|
||||
int connect(IPAddress ip, uint16_t port, int timeout_s) {
|
||||
return connect(TinyGsmStringFromIp(ip).c_str(), port, timeout_s);
|
||||
}
|
||||
int connect(const char* host, uint16_t port) override {
|
||||
return connect(host, port, 75);
|
||||
}
|
||||
int connect(IPAddress ip, uint16_t port) override {
|
||||
return connect(ip, port, 75);
|
||||
}
|
||||
TINY_GSM_CLIENT_CONNECT_OVERRIDES
|
||||
|
||||
void stop(uint32_t maxWaitMs) {
|
||||
virtual void stop(uint32_t maxWaitMs) {
|
||||
dumpModemBuffer(maxWaitMs);
|
||||
at->sendAT(GF("+CIPCLOSE="), mux, GF(",1")); // Quick close
|
||||
sock_connected = false;
|
||||
@@ -110,13 +126,14 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
: GsmClientSim800(modem, mux) {}
|
||||
|
||||
public:
|
||||
int connect(const char* host, uint16_t port, int timeout_s) {
|
||||
int connect(const char* host, uint16_t port, int timeout_s) override {
|
||||
stop();
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
sock_connected = at->modemConnect(host, port, mux, true, timeout_s);
|
||||
return sock_connected;
|
||||
}
|
||||
TINY_GSM_CLIENT_CONNECT_OVERRIDES
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -206,23 +223,17 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
return waitResponse() == 1;
|
||||
}
|
||||
|
||||
bool thisHasSSL() {
|
||||
#if defined(TINY_GSM_MODEM_SIM900)
|
||||
return false;
|
||||
#else
|
||||
sendAT(GF("+CIPSSL=?"));
|
||||
if (waitResponse(GF(GSM_NL "+CIPSSL:")) != 1) { return false; }
|
||||
return waitResponse() == 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool thisHasWifi() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool thisHasGPRS() {
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
bool thisHasSSL() {
|
||||
#if defined(TINY_GSM_MODEM_SIM900)
|
||||
return false;
|
||||
#else
|
||||
sendAT(GF("+CIPSSL=?"));
|
||||
if (waitResponse(GF(GSM_NL "+CIPSSL:")) != 1) { return false; }
|
||||
return waitResponse() == 1;
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Power functions
|
||||
@@ -268,16 +279,10 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||
}
|
||||
|
||||
/*
|
||||
* IP Address functions
|
||||
*/
|
||||
protected:
|
||||
String getLocalIPImpl() {
|
||||
sendAT(GF("+CIFSR;E0"));
|
||||
String res;
|
||||
if (waitResponse(10000L, res) != 1) {
|
||||
return "";
|
||||
}
|
||||
if (waitResponse(10000L, res) != 1) { return ""; }
|
||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
||||
res.replace(GSM_NL, "");
|
||||
res.trim();
|
||||
@@ -400,10 +405,11 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
protected:
|
||||
// Can return a location from CIPGSMLOC as per the template
|
||||
|
||||
|
||||
/*
|
||||
* GPS location functions
|
||||
*/
|
||||
public:
|
||||
protected:
|
||||
// No functions of this type supported
|
||||
|
||||
/*
|
||||
@@ -413,10 +419,10 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE,
|
||||
// Can follow the standard CCLK function in the template
|
||||
|
||||
/*
|
||||
* Battery & temperature functions
|
||||
* Battery functions
|
||||
*/
|
||||
protected:
|
||||
float getTemperatureImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
// Follows all battery functions per template
|
||||
|
||||
/*
|
||||
* NTP server functions
|
||||
|
||||
Reference in New Issue
Block a user