Cleanup after XBee merge

This commit is contained in:
Volodymyr Shymanskyy
2017-09-27 12:35:58 +03:00
parent 9e179b95e6
commit 685061b9ae
7 changed files with 48 additions and 81 deletions

View File

@@ -348,17 +348,6 @@ public:
return false; return false;
} }
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) {
return false;
}
bool networkDisconnect() {
return false;
}
/* /*
* GPRS functions * GPRS functions
*/ */

View File

@@ -212,9 +212,6 @@ public:
return autoBaud(); return autoBaud();
} }
/*
* SIM card functions
*/
/* /*
* Generic network functions * Generic network functions
@@ -311,17 +308,6 @@ public:
return res; return res;
} }
/*
* GPRS functions
*/
bool gprsConnect(const char* apn, const char* user, const char* pwd) {
return false;
}
bool gprsDisconnect() {
return false;
}
private: private:
int modemConnect(const char* host, uint16_t port, uint8_t mux) { int modemConnect(const char* host, uint16_t port, uint8_t mux) {
@@ -330,7 +316,7 @@ private:
GFP(GSM_OK), GFP(GSM_OK),
GFP(GSM_ERROR), GFP(GSM_ERROR),
GF(GSM_NL "ALREADY CONNECT" GSM_NL)); GF(GSM_NL "ALREADY CONNECT" GSM_NL));
waitResponse(100, GF("1,CONNECT")); waitResponse(100, GF("1,CONNECT")); // TODO
return (1 == rsp); return (1 == rsp);
} }

View File

@@ -357,17 +357,6 @@ public:
return false; return false;
} }
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) {
return false;
}
bool networkDisconnect() {
return false;
}
/* /*
* GPRS functions * GPRS functions
*/ */

View File

@@ -426,17 +426,6 @@ public:
return false; return false;
} }
/*
* WiFi functions
*/
bool networkConnect(const char* ssid, const char* pwd) {
return false;
}
bool networkDisconnect() {
return false;
}
/* /*
* GPRS functions * GPRS functions
*/ */
@@ -449,11 +438,11 @@ public:
sendAT(GF("+SAPBR=3,1,\"APN\",\""), apn, '"'); sendAT(GF("+SAPBR=3,1,\"APN\",\""), apn, '"');
waitResponse(); waitResponse();
if (user) { if (user && strlen(user) > 0) {
sendAT(GF("+SAPBR=3,1,\"USER\",\""), user, '"'); sendAT(GF("+SAPBR=3,1,\"USER\",\""), user, '"');
waitResponse(); waitResponse();
} }
if (pwd) { if (pwd && strlen(pwd) > 0) {
sendAT(GF("+SAPBR=3,1,\"PWD\",\""), pwd, '"'); sendAT(GF("+SAPBR=3,1,\"PWD\",\""), pwd, '"');
waitResponse(); waitResponse();
} }
@@ -868,7 +857,7 @@ public:
streamWrite("AT", cmd..., GSM_NL); streamWrite("AT", cmd..., GSM_NL);
stream.flush(); stream.flush();
TINY_GSM_YIELD(); TINY_GSM_YIELD();
DBG("### AT:", cmd...); //DBG("### AT:", cmd...);
} }
// TODO: Optimize this! // TODO: Optimize this!
@@ -910,7 +899,7 @@ public:
String mode = stream.readStringUntil(','); String mode = stream.readStringUntil(',');
if (mode.toInt() == 1) { if (mode.toInt() == 1) {
int mux = stream.readStringUntil('\n').toInt(); 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; sockets[mux]->got_data = true;
} }
data = ""; data = "";
@@ -921,7 +910,7 @@ public:
int nl = data.lastIndexOf(GSM_NL, data.length()-8); int nl = data.lastIndexOf(GSM_NL, data.length()-8);
int coma = data.indexOf(',', nl+2); int coma = data.indexOf(',', nl+2);
int mux = data.substring(nl+2, coma).toInt(); 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; sockets[mux]->sock_connected = false;
} }
data = ""; data = "";

View File

@@ -1,5 +1,5 @@
/** /**
* @file TinyWiFiClientESP8266.h * @file TinyGsmClientXBee.h
* @author Volodymyr Shymanskyy * @author Volodymyr Shymanskyy
* @license LGPL-3.0 * @license LGPL-3.0
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy * @copyright Copyright (c) 2016 Volodymyr Shymanskyy
@@ -47,11 +47,6 @@ enum RegStatus {
class TinyGsm class TinyGsm
{ {
public:
TinyGsm(Stream& stream)
: stream(stream)
{}
public: public:
class GsmClient : public Client class GsmClient : public Client
@@ -114,6 +109,8 @@ public:
} }
virtual size_t write(const uint8_t *buf, size_t size) { virtual size_t write(const uint8_t *buf, size_t size) {
TINY_GSM_YIELD();
//at->maintain();
return at->modemSend(buf, size, mux); return at->modemSend(buf, size, mux);
} }
@@ -122,6 +119,7 @@ public:
} }
virtual int available() { virtual int available() {
TINY_GSM_YIELD();
return at->stream.available(); return at->stream.available();
} }
@@ -144,6 +142,13 @@ public:
return sock_connected; return sock_connected;
} }
virtual operator bool() { return connected(); } virtual operator bool() { return connected(); }
/*
* Extended API
*/
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
private: private:
TinyGsm* at; TinyGsm* at;
uint8_t mux; uint8_t mux;
@@ -152,6 +157,12 @@ private:
public: public:
TinyGsm(Stream& stream)
: stream(stream)
{
memset(sockets, 0, sizeof(sockets));
}
/* /*
* Basic functions * Basic functions
*/ */
@@ -440,6 +451,7 @@ public:
private: private:
int modemConnect(const char* host, uint16_t port, uint8_t mux = 0) { int modemConnect(const char* host, uint16_t port, uint8_t mux = 0) {
sendAT(GF("LA"), host); sendAT(GF("LA"), host);
String strIP; strIP.reserve(16); String strIP; strIP.reserve(16);
@@ -495,7 +507,10 @@ private:
return 1 == res; return 1 == res;
} }
/* Private Utilities */ public:
/* Utilities */
template<typename T> template<typename T>
void streamWrite(T last) { void streamWrite(T last) {
stream.print(last); stream.print(last);
@@ -520,8 +535,7 @@ private:
} }
void streamClear(void) { void streamClear(void) {
while (stream.available()) while (stream.available()) { streamRead(); }
{streamRead();}
} }
bool commandMode(void) { bool commandMode(void) {
@@ -548,7 +562,7 @@ private:
streamWrite("AT", cmd..., GSM_NL); streamWrite("AT", cmd..., GSM_NL);
stream.flush(); stream.flush();
TINY_GSM_YIELD(); TINY_GSM_YIELD();
DBG(">>> AT ", cmd..., "\r\n"); //DBG("### AT:", cmd...);
} }
// TODO: Optimize this! // TODO: Optimize this!
@@ -596,9 +610,10 @@ private:
data.replace(GSM_NL, "\r\n" " "); data.replace(GSM_NL, "\r\n" " ");
if (data.length()) { if (data.length()) {
DBG("### Unhandled:", data, "\r\n"); DBG("### Unhandled:", data, "\r\n");
} else DBG("### NO RESPONSE!\r\n"); } else {
DBG("### NO RESPONSE!\r\n");
} }
else { } else {
data.trim(); data.trim();
data.replace(GSM_NL GSM_NL, GSM_NL); data.replace(GSM_NL GSM_NL, GSM_NL);
data.replace(GSM_NL, "\r\n "); data.replace(GSM_NL, "\r\n ");

View File

@@ -46,7 +46,6 @@ namespace {
template<typename T> template<typename T>
static void DBG(T last) { static void DBG(T last) {
TINY_GSM_DEBUG.println(last); TINY_GSM_DEBUG.println(last);
// TINY_GSM_DEBUG.print(last);
} }
template<typename T, typename... Args> template<typename T, typename... Args>