Browse Source

Some class cleaning

v_master
Sara Damiano 6 years ago
parent
commit
63ed6fafb7
12 changed files with 201 additions and 195 deletions
  1. +18
    -20
      src/TinyGsmClientA6.h
  2. +13
    -20
      src/TinyGsmClientBG96.h
  3. +13
    -28
      src/TinyGsmClientESP8266.h
  4. +13
    -20
      src/TinyGsmClientM590.h
  5. +13
    -10
      src/TinyGsmClientM95.h
  6. +30
    -28
      src/TinyGsmClientMC60.h
  7. +22
    -20
      src/TinyGsmClientSIM800.h
  8. +3
    -3
      src/TinyGsmClientSIM808.h
  9. +12
    -19
      src/TinyGsmClientUBLOX.h
  10. +18
    -8
      src/TinyGsmClientXBee.h
  11. +40
    -18
      src/TinyGsmCommon.h
  12. +6
    -1
      tools/test_build/test_build.ino

+ 18
- 20
src/TinyGsmClientA6.h View File

@ -190,11 +190,8 @@ public:
/*
* Basic functions
*/
bool begin() {
return init();
}
bool init() {
bool init(const char* pin = NULL) {
if (!testAT()) {
return false;
}
@ -212,6 +209,15 @@ public:
return true;
}
String getModemName() {
#if defined(TINY_GSM_MODEM_A6)
return "AI-Thinker A6";
#elif defined(TINY_GSM_MODEM_A7)
return "AI-Thinker A7";
#endif
return "AI-Thinker A6";
}
void setBaud(unsigned long baud) {
sendAT(GF("+IPR="), baud);
}
@ -255,6 +261,14 @@ public:
return false;
}
bool hasWifi() {
return false;
}
bool hasGPRS() {
return true;
}
/*
* Power functions
*/
@ -371,22 +385,6 @@ public:
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
}
bool waitForNetwork(unsigned long timeout = 60000L) {
for (unsigned long start = millis(); millis() - start < timeout; ) {
if (isNetworkConnected()) {
return true;
}
delay(250);
}
return false;
}
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE;
bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* GPRS functions
*/


+ 13
- 20
src/TinyGsmClientBG96.h View File

@ -214,11 +214,8 @@ public:
/*
* Basic functions
*/
bool begin() {
return init();
}
bool init() {
bool init(const char* pin = NULL) {
if (!testAT()) {
return false;
}
@ -230,6 +227,10 @@ public:
return true;
}
String getModemName() {
return "Quectel BG96";
}
void setBaud(unsigned long baud) {
sendAT(GF("+IPR="), baud);
}
@ -284,6 +285,14 @@ public:
return false; // TODO: For now
}
bool hasWifi() {
return false;
}
bool hasGPRS() {
return true;
}
/*
* Power functions
*/
@ -405,22 +414,6 @@ public:
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
}
bool waitForNetwork(unsigned long timeout = 60000L) {
for (unsigned long start = millis(); millis() - start < timeout; ) {
if (isNetworkConnected()) {
return true;
}
delay(250);
}
return false;
}
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE;
bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* GPRS functions
*/


+ 13
- 28
src/TinyGsmClientESP8266.h View File

@ -206,11 +206,8 @@ public:
/*
* Basic functions
*/
bool begin() {
return init();
}
bool init() {
bool init(const char* pin = NULL) {
if (!testAT()) {
return false;
}
@ -229,6 +226,10 @@ public:
return true;
}
String getModemName() {
return "ESP8266";
}
void setBaud(unsigned long baud) {
sendAT(GF("+IPR="), baud);
}
@ -270,6 +271,14 @@ public:
return true;
}
bool hasWifi() {
return true;
}
bool hasGPRS() {
return false;
}
/*
* Power functions
*/
@ -381,30 +390,6 @@ public:
return res2;
}
/*
* GPRS functions
*/
bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) TINY_GSM_ATTR_NOT_AVAILABLE;
bool gprsDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* Messaging functions
*/
/*
* Location functions
*/
String getGsmLocation() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* Battery functions
*/
uint16_t getBattVoltage() TINY_GSM_ATTR_NOT_AVAILABLE;
int getBattPercent() TINY_GSM_ATTR_NOT_AVAILABLE;
protected:
bool modemConnect(const char* host, uint16_t port, uint8_t mux, bool ssl = false) {


+ 13
- 20
src/TinyGsmClientM590.h View File

@ -187,11 +187,8 @@ public:
/*
* Basic functions
*/
bool begin() {
return init();
}
bool init() {
bool init(const char* pin = NULL) {
if (!testAT()) {
return false;
}
@ -208,6 +205,10 @@ public:
return true;
}
String getModemName() {
return "Neoway M590";
}
void setBaud(unsigned long baud) {
sendAT(GF("+IPR="), baud);
}
@ -259,6 +260,14 @@ public:
return false;
}
bool hasWifi() {
return false;
}
bool hasGPRS() {
return true;
}
/*
* Power functions
*/
@ -379,22 +388,6 @@ public:
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
}
bool waitForNetwork(unsigned long timeout = 60000L) {
for (unsigned long start = millis(); millis() - start < timeout; ) {
if (isNetworkConnected()) {
return true;
}
delay(250);
}
return false;
}
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE;
bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* GPRS functions
*/


+ 13
- 10
src/TinyGsmClientM95.h View File

@ -194,11 +194,8 @@ public:
/*
* Basic functions
*/
bool begin() {
return init();
}
bool init() {
bool init(const char* pin = NULL) {
if (!testAT()) {
return false;
}
@ -215,6 +212,10 @@ public:
return true;
}
String getModemName() {
return "Quectel M95";
}
void setBaud(unsigned long baud) {
sendAT(GF("+IPR="), baud);
}
@ -273,6 +274,14 @@ public:
return false; // TODO: For now
}
bool hasWifi() {
return false;
}
bool hasGPRS() {
return true;
}
/*
* Power functions
*/
@ -416,12 +425,6 @@ public:
waitResponse();
}
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE;
bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* GPRS functions
*/


+ 30
- 28
src/TinyGsmClientMC60.h View File

@ -221,11 +221,8 @@ public:
/*
* Basic functions
*/
bool begin() {
return init();
}
bool init() {
bool init(const char* pin = NULL) {
if (!testAT()) {
return false;
}
@ -239,6 +236,17 @@ public:
return true;
}
String getModemName() {
#if defined(TINY_GSM_MODEM_MC60)
return "Quectel MC60";
#elif defined(TINY_GSM_MODEM_MC60E)
return "Quectel MC60E";
#endif
return "Quectel MC60";
}
void setBaud(unsigned long baud) { return false; };
bool testAT(unsigned long timeout = 10000L) {
//streamWrite(GF("AAAAA" GSM_NL)); // TODO: extra A's to help detect the baud rate
for (unsigned long start = millis(); millis() - start < timeout; ) {
@ -294,15 +302,25 @@ public:
/*
* under development
*
bool hasSSL() {
sendAT(GF("+QIPSSL=?"));
if (waitResponse(GF(GSM_NL "+CIPSSL:")) != 1) {
return false;
}
return waitResponse() == 1;
*/
// bool hasSSL() {
// sendAT(GF("+QIPSSL=?"));
// if (waitResponse(GF(GSM_NL "+CIPSSL:")) != 1) {
// return false;
// }
// return waitResponse() == 1;
// }
bool hasSSL() { return false; }
bool hasWifi() {
return false;
}
*/
bool hasGPRS() {
return true;
}
/*
* Power functions
*/
@ -433,22 +451,6 @@ public:
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
}
bool waitForNetwork(unsigned long timeout = 60000L) {
for (unsigned long start = millis(); millis() - start < timeout; ) {
if (isNetworkConnected()) {
return true;
}
delay(250);
}
return false;
}
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE;
bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* GPRS functions
*/


+ 22
- 20
src/TinyGsmClientSIM800.h View File

@ -236,11 +236,8 @@ public:
/*
* Basic functions
*/
bool begin() {
return init();
}
bool init() {
bool init(const char* pin = NULL) {
if (!testAT()) {
return false;
}
@ -254,6 +251,19 @@ public:
return true;
}
String getModemName() {
#if defined(TINY_GSM_MODEM_SIM800)
return "SIMCom SIM800";
#elif defined(TINY_GSM_MODEM_SIM808)
return "SIMCom SIM808";
#elif defined(TINY_GSM_MODEM_SIM868)
return "SIMCom SIM868";
#elif defined(TINY_GSM_MODEM_SIM900)
return "SIMCom SIM900";
#endif
return "SIMCom SIM800";
}
void setBaud(unsigned long baud) {
sendAT(GF("+IPR="), baud);
}
@ -323,6 +333,14 @@ public:
#endif
}
bool hasWifi() {
return false;
}
bool hasGPRS() {
return true;
}
/*
* Power functions
*/
@ -466,22 +484,6 @@ public:
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
}
bool waitForNetwork(unsigned long timeout = 60000L) {
for (unsigned long start = millis(); millis() - start < timeout; ) {
if (isNetworkConnected()) {
return true;
}
delay(250);
}
return false;
}
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE;
bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* GPRS functions
*/


+ 3
- 3
src/TinyGsmClientSIM808.h View File

@ -27,7 +27,7 @@ public:
// enable GPS
bool enableGPS() {
uint16_t state;
// uint16_t state;
sendAT(GF("+CGNSPWR=1"));
if (waitResponse() != 1) {
@ -38,7 +38,7 @@ public:
}
bool disableGPS() {
uint16_t state;
// uint16_t state;
sendAT(GF("+CGNSPWR=0"));
if (waitResponse() != 1) {
@ -65,7 +65,7 @@ public:
// works only with ans SIM808 V2
bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0, int *vsat=0, int *usat=0) {
//String buffer = "";
char chr_buffer[12];
// char chr_buffer[12];
bool fix = false;
sendAT(GF("+CGNSINF"));


+ 12
- 19
src/TinyGsmClientUBLOX.h View File

@ -213,9 +213,6 @@ public:
/*
* Basic functions
*/
bool begin(const char* pin = NULL) {
return init(pin);
}
bool init(const char* pin = NULL) {
if (!testAT()) {
@ -232,6 +229,10 @@ public:
return (getSimStatus() == SIM_READY);
}
String getModemName() {
return "ESP8266";
}
void setBaud(unsigned long baud) {
sendAT(GF("+IPR="), baud);
}
@ -284,6 +285,14 @@ public:
return true;
}
bool hasWifi() {
return false;
}
bool hasGPRS() {
return true;
}
/*
* Power functions
*/
@ -404,22 +413,6 @@ public:
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
}
bool waitForNetwork(unsigned long timeout = 60000L) {
for (unsigned long start = millis(); millis() - start < timeout; ) {
if (isNetworkConnected()) {
return true;
}
delay(250);
}
return false;
}
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) TINY_GSM_ATTR_NOT_AVAILABLE;
bool networkDisconnect() TINY_GSM_ATTR_NOT_AVAILABLE;
/*
* GPRS functions
*/


+ 18
- 8
src/TinyGsmClientXBee.h View File

@ -217,11 +217,8 @@ public:
/*
* Basic functions
*/
bool begin() {
return init();
}
bool init() {
bool init(const char* pin = NULL) {
guardTime = 1100; // Start with a default guard time of 1 second
if (!commandMode(10)) return false; // Try up to 10 times for the init
@ -246,6 +243,10 @@ public:
return ret_val;
}
String getModemName() {
return getBeeName();
}
void setBaud(unsigned long baud) {
if (!commandMode()) return;
switch(baud)
@ -313,6 +314,16 @@ public:
else return true;
}
bool hasWifi() {
if (beeType == XBEE_S6B_WIFI) return true;
else return false;
}
bool hasGPRS() {
if (beeType == XBEE_S6B_WIFI) return false;
else return true;
}
XBeeType getBeeType() {
return beeType;
}
@ -360,8 +371,8 @@ public:
return false;
}
void setupPinSleep(bool maintainAssociation = false) {
if (!commandMode()) return; // Return immediately
bool sleepEnable(bool maintainAssociation = false) {
if (!commandMode()) return false; // Return immediately
sendAT(GF("SM"),1); // Pin sleep
waitResponse();
if (beeType == XBEE_S6B_WIFI && !maintainAssociation) {
@ -375,14 +386,13 @@ public:
}
writeChanges();
exitCommand();
return true;
}
bool poweroff() TINY_GSM_ATTR_NOT_IMPLEMENTED;
bool radioOff() TINY_GSM_ATTR_NOT_IMPLEMENTED;
bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
/*
* SIM card functions
*/


+ 40
- 18
src/TinyGsmCommon.h View File

@ -204,7 +204,7 @@ public:
class GsmClient : public Client
{
friend class TinyGsmXBee;
friend class TinyGsmMasterModem;
};
@ -222,50 +222,78 @@ public:
* Basic functions
*/
virtual bool begin() = 0;
virtual bool init() = 0;
// Prepare the modem for further functionality
virtual bool init(const char* pin = NULL) = 0;
// Begin is redundant with init
virtual bool begin(const char* pin = NULL) {
return init(pin);
}
// Returns a string with the chip name
virtual String getModemName() = 0;
// Sets the serial communication baud rate
virtual void setBaud(unsigned long baud) = 0;
// Checks that the modem is responding to standard AT commands
virtual bool testAT(unsigned long timeout = 10000L) = 0;
// Holds open communication with the modem waiting for data to come in
virtual void maintain() = 0;
// Resets all modem chip settings to factor defaults
virtual bool factoryDefault() = 0;
// Returns the response to a get info request. The format varies by modem.
virtual String getModemInfo() = 0;
// Answers whether secure communication is available on this modem
virtual bool hasSSL() = 0;
virtual bool hasWifi() = 0;
virtual bool hasGPRS() = 0;
/*
* Power functions
*/
virtual bool restart() = 0;
virtual bool poweroff() { return false; }
virtual bool radioOff() { return false; }
virtual bool sleepEnable(bool enable = true) { return false; }
/*
* SIM card functions
*/
virtual bool simUnlock(const char *pin) = 0;
virtual String getSimCCID() = 0;
virtual String getIMEI() = 0;
virtual String getOperator() = 0;
virtual bool simUnlock(const char *pin) { return false; }
virtual String getSimCCID() { return ""; }
virtual String getIMEI() { return ""; }
virtual String getOperator() { return ""; }
/*
* Generic network functions
*/
virtual int getSignalQuality() = 0;
// NOTE: this returns whether the modem is registered on the cellular or WiFi
// network NOT whether GPRS or other internet connections are available
virtual bool isNetworkConnected() = 0;
virtual bool waitForNetwork(unsigned long timeout = 60000L) {
for (unsigned long start = millis(); millis() - start < timeout; ) {
if (isNetworkConnected()) {
return true;
}
delay(250);
}
return false;
}
/*
* WiFi functions
*/
virtual bool networkConnect(const char* ssid, const char* pwd) = 0;
virtual bool networkDisconnect() = 0;
virtual bool networkConnect(const char* ssid, const char* pwd) { return false; }
virtual bool networkDisconnect() { return false; }
/*
* 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;
virtual bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) { return false; }
virtual bool gprsDisconnect() { return false; }
/*
* IP Address functions
@ -276,12 +304,6 @@ public:
return TinyGsmIpFromString(getLocalIP());
}
/*
* Messaging functions
*/
virtual bool sendSMS(const String& number, const String& text) = 0;
public:
Stream& stream;
};


+ 6
- 1
tools/test_build/test_build.ino View File

@ -3,6 +3,12 @@
* DO NOT USE THIS - this is just a compilation test!
*
**************************************************************/
// #define TINY_GSM_MODEM_SIM800 // Select for a SIM800, SIM900, or variant thereof
// #define TINY_GSM_MODEM_A6 // Select for a AI-Thinker A6 or A7 chip
// #define TINY_GSM_MODEM_M590 // Select for a Neoway M590
// #define TINY_GSM_MODEM_UBLOX // Select for most u-blox cellular modems
// #define TINY_GSM_MODEM_ESP8266 // Select for an ESP8266 using the DEFAULT AT COMMAND FIRMWARE
// #define TINY_GSM_MODEM_XBEE // Select for Digi brand WiFi or Cellular XBee's
#include <TinyGsmClient.h>
@ -77,4 +83,3 @@ void loop() {
modem.networkDisconnect();
#endif
}

Loading…
Cancel
Save