From 685061b9ae717daf9edec8878c87ff650825d9c8 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Wed, 27 Sep 2017 12:35:58 +0300 Subject: [PATCH] Cleanup after XBee merge --- TinyGsmClient.h | 2 +- TinyGsmClientA6.h | 15 ++----------- TinyGsmClientESP8266.h | 20 +++-------------- TinyGsmClientM590.h | 15 ++----------- TinyGsmClientSIM800.h | 27 +++++++---------------- TinyGsmClientXBee.h | 49 +++++++++++++++++++++++++++--------------- TinyGsmCommon.h | 1 - 7 files changed, 48 insertions(+), 81 deletions(-) diff --git a/TinyGsmClient.h b/TinyGsmClient.h index 07f1126..ef14a4e 100644 --- a/TinyGsmClient.h +++ b/TinyGsmClient.h @@ -9,7 +9,7 @@ #ifndef TinyGsmClient_h #define TinyGsmClient_h -#if defined(TINY_GSM_MODEM_SIM800) || defined(TINY_GSM_MODEM_SIM900) +#if defined(TINY_GSM_MODEM_SIM800) || defined(TINY_GSM_MODEM_SIM900) #include typedef TinyGsmSim800 TinyGsm; typedef TinyGsmSim800::GsmClient TinyGsmClient; diff --git a/TinyGsmClientA6.h b/TinyGsmClientA6.h index d511031..3377f92 100644 --- a/TinyGsmClientA6.h +++ b/TinyGsmClientA6.h @@ -348,17 +348,6 @@ public: return false; } - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) { - return false; - } - - bool networkDisconnect() { - return false; - } - /* * GPRS functions */ @@ -645,7 +634,7 @@ public: streamWrite("AT", cmd..., GSM_NL); stream.flush(); TINY_GSM_YIELD(); - // DBG("### AT:", cmd...); + //DBG("### AT:", cmd...); } // TODO: Optimize this! @@ -710,7 +699,7 @@ public: } } } while (millis() - startMillis < timeout); - finish: +finish: if (!index) { data.trim(); if (data.length()) { diff --git a/TinyGsmClientESP8266.h b/TinyGsmClientESP8266.h index 2931f57..6fffbb2 100644 --- a/TinyGsmClientESP8266.h +++ b/TinyGsmClientESP8266.h @@ -212,9 +212,6 @@ public: return autoBaud(); } - /* - * SIM card functions - */ /* * Generic network functions @@ -311,17 +308,6 @@ public: return res; } - /* - * GPRS functions - */ - bool gprsConnect(const char* apn, const char* user, const char* pwd) { - return false; - } - - bool gprsDisconnect() { - return false; - } - private: int modemConnect(const char* host, uint16_t port, uint8_t mux) { @@ -330,7 +316,7 @@ private: GFP(GSM_OK), GFP(GSM_ERROR), GF(GSM_NL "ALREADY CONNECT" GSM_NL)); - waitResponse(100, GF("1,CONNECT")); + waitResponse(100, GF("1,CONNECT")); // TODO return (1 == rsp); } @@ -383,7 +369,7 @@ public: streamWrite("AT", cmd..., GSM_NL); stream.flush(); TINY_GSM_YIELD(); - // DBG("### AT:", cmd...); + //DBG("### AT:", cmd...); } // TODO: Optimize this! @@ -444,7 +430,7 @@ public: } } } while (millis() - startMillis < timeout); - finish: +finish: if (!index) { data.trim(); if (data.length()) { diff --git a/TinyGsmClientM590.h b/TinyGsmClientM590.h index 8a9adda..b9d3a69 100644 --- a/TinyGsmClientM590.h +++ b/TinyGsmClientM590.h @@ -357,17 +357,6 @@ public: return false; } - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) { - return false; - } - - bool networkDisconnect() { - return false; - } - /* * GPRS functions */ @@ -632,7 +621,7 @@ public: streamWrite("AT", cmd..., GSM_NL); stream.flush(); TINY_GSM_YIELD(); - // DBG("### AT:", cmd...); + //DBG("### AT:", cmd...); } // TODO: Optimize this! @@ -698,7 +687,7 @@ public: } } } while (millis() - startMillis < timeout); - finish: +finish: if (!index) { data.trim(); if (data.length()) { diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index c0c3544..9085c27 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -9,8 +9,8 @@ #ifndef TinyGsmClientSIM800_h #define TinyGsmClientSIM800_h -// #define TINY_GSM_DEBUG Serial -// #define TINY_GSM_USE_HEX +//#define TINY_GSM_DEBUG Serial +//#define TINY_GSM_USE_HEX #if !defined(TINY_GSM_RX_BUFFER) #define TINY_GSM_RX_BUFFER 64 @@ -426,17 +426,6 @@ public: return false; } - /* - * WiFi functions - */ - bool networkConnect(const char* ssid, const char* pwd) { - return false; - } - - bool networkDisconnect() { - return false; - } - /* * GPRS functions */ @@ -449,11 +438,11 @@ public: sendAT(GF("+SAPBR=3,1,\"APN\",\""), apn, '"'); waitResponse(); - if (user) { + if (user && strlen(user) > 0) { sendAT(GF("+SAPBR=3,1,\"USER\",\""), user, '"'); waitResponse(); } - if (pwd) { + if (pwd && strlen(pwd) > 0) { sendAT(GF("+SAPBR=3,1,\"PWD\",\""), pwd, '"'); waitResponse(); } @@ -868,7 +857,7 @@ public: streamWrite("AT", cmd..., GSM_NL); stream.flush(); TINY_GSM_YIELD(); - DBG("### AT:", cmd...); + //DBG("### AT:", cmd...); } // TODO: Optimize this! @@ -910,7 +899,7 @@ public: String mode = stream.readStringUntil(','); if (mode.toInt() == 1) { int mux = stream.readStringUntil('\n').toInt(); - if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) { + if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->got_data = true; } data = ""; @@ -921,7 +910,7 @@ public: int nl = data.lastIndexOf(GSM_NL, data.length()-8); int coma = data.indexOf(',', nl+2); int mux = data.substring(nl+2, coma).toInt(); - if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) { + if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { sockets[mux]->sock_connected = false; } data = ""; @@ -929,7 +918,7 @@ public: } } } while (millis() - startMillis < timeout); - finish: +finish: if (!index) { data.trim(); if (data.length()) { diff --git a/TinyGsmClientXBee.h b/TinyGsmClientXBee.h index 475f34f..5f4b3aa 100644 --- a/TinyGsmClientXBee.h +++ b/TinyGsmClientXBee.h @@ -1,5 +1,5 @@ /** - * @file TinyWiFiClientESP8266.h + * @file TinyGsmClientXBee.h * @author Volodymyr Shymanskyy * @license LGPL-3.0 * @copyright Copyright (c) 2016 Volodymyr Shymanskyy @@ -47,11 +47,6 @@ enum RegStatus { class TinyGsm { -public: - TinyGsm(Stream& stream) - : stream(stream) - {} - public: class GsmClient : public Client @@ -114,6 +109,8 @@ public: } virtual size_t write(const uint8_t *buf, size_t size) { + TINY_GSM_YIELD(); + //at->maintain(); return at->modemSend(buf, size, mux); } @@ -122,6 +119,7 @@ public: } virtual int available() { + TINY_GSM_YIELD(); return at->stream.available(); } @@ -144,6 +142,13 @@ public: return sock_connected; } virtual operator bool() { return connected(); } + + /* + * Extended API + */ + + String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED; + private: TinyGsm* at; uint8_t mux; @@ -152,6 +157,12 @@ private: public: + TinyGsm(Stream& stream) + : stream(stream) + { + memset(sockets, 0, sizeof(sockets)); + } + /* * Basic functions */ @@ -360,9 +371,9 @@ public: return true; - fail: - exitCommand(); - return false; +fail: + exitCommand(); + return false; } bool networkDisconnect() { @@ -440,6 +451,7 @@ public: private: + int modemConnect(const char* host, uint16_t port, uint8_t mux = 0) { sendAT(GF("LA"), host); String strIP; strIP.reserve(16); @@ -495,7 +507,10 @@ private: return 1 == res; } - /* Private Utilities */ +public: + + /* Utilities */ + template void streamWrite(T last) { stream.print(last); @@ -520,8 +535,7 @@ private: } void streamClear(void) { - while (stream.available()) - {streamRead();} + while (stream.available()) { streamRead(); } } bool commandMode(void) { @@ -548,7 +562,7 @@ private: streamWrite("AT", cmd..., GSM_NL); stream.flush(); TINY_GSM_YIELD(); - DBG(">>> AT ", cmd..., "\r\n"); + //DBG("### AT:", cmd...); } // TODO: Optimize this! @@ -589,16 +603,17 @@ private: } } } while (millis() - startMillis < timeout); - finish: +finish: if (!index) { data.trim(); data.replace(GSM_NL GSM_NL, GSM_NL); data.replace(GSM_NL, "\r\n" " "); if (data.length()) { DBG("### Unhandled:", data, "\r\n"); - } else DBG("### NO RESPONSE!\r\n"); - } - else { + } else { + DBG("### NO RESPONSE!\r\n"); + } + } else { data.trim(); data.replace(GSM_NL GSM_NL, GSM_NL); data.replace(GSM_NL, "\r\n "); diff --git a/TinyGsmCommon.h b/TinyGsmCommon.h index 9b1596f..e0a37aa 100644 --- a/TinyGsmCommon.h +++ b/TinyGsmCommon.h @@ -46,7 +46,6 @@ namespace { template static void DBG(T last) { TINY_GSM_DEBUG.println(last); - // TINY_GSM_DEBUG.print(last); } template