Browse Source

Removed most of the extra debugging I'd added

v_master
SRGDamia1 7 years ago
parent
commit
3589a8e22b
6 changed files with 72 additions and 159 deletions
  1. +22
    -44
      TinyGsmClientA6.h
  2. +14
    -57
      TinyGsmClientESP8266.h
  3. +12
    -35
      TinyGsmClientM590.h
  4. +17
    -16
      TinyGsmClientSIM800.h
  5. +4
    -4
      TinyGsmClientXBee.h
  6. +3
    -3
      TinyGsmCommon.h

+ 22
- 44
TinyGsmClientA6.h View File

@ -265,7 +265,7 @@ public:
if (waitResponse(GF(GSM_NL "+SCID: SIM Card ID:")) != 1) {
return "";
}
String res = streamReadUntil('\n');
String res = stream.readStringUntil('\n');
waitResponse();
return res;
}
@ -275,7 +275,7 @@ public:
if (waitResponse(GF(GSM_NL)) != 1) {
return "";
}
String res = streamReadUntil('\n');
String res = stream.readStringUntil('\n');
waitResponse();
return res;
}
@ -305,7 +305,7 @@ public:
return REG_UNKNOWN;
}
streamSkipUntil(','); // Skip format (0)
int status = streamReadUntil('\n').toInt();
int status = stream.readStringUntil('\n').toInt();
waitResponse();
return (RegStatus)status;
}
@ -316,7 +316,7 @@ public:
return "";
}
streamSkipUntil('"'); // Skip mode and format
String res = streamReadUntil('"');
String res = stream.readStringUntil('"');
waitResponse();
return res;
}
@ -525,7 +525,7 @@ private:
if (waitResponse(75000L, GF(GSM_NL "+CIPNUM:")) != 1) {
return false;
}
int newMux = streamReadUntil('\n').toInt();
int newMux = stream.readStringUntil('\n').toInt();
int rsp = waitResponse(75000L,
GF("CONNECT OK" GSM_NL),
@ -618,15 +618,13 @@ public:
streamWrite(tail...);
}
bool streamSkipUntil(char c) {
String skipped = stream.readStringUntil(c);
skipped.trim();
if (skipped.length()) {
if (String(c) == GSM_NL || String(c) == "\n"){
DBG(skipped, c, " ");
} else DBG(skipped, c);
return true;
} else return false;
bool streamSkipUntil(char c) { //TODO: timeout
while (true) {
while (!stream.available()) { TINY_GSM_YIELD(); }
if (stream.read() == c)
return true;
}
return false;
}
template<typename... Args>
@ -634,7 +632,7 @@ public:
streamWrite("AT", cmd..., GSM_NL);
stream.flush();
TINY_GSM_YIELD();
DBG(GSM_NL, ">>> AT:", cmd...);
// DBG("### AT:", cmd...);
}
// TODO: Optimize this!
@ -678,6 +676,7 @@ public:
} else if (data.endsWith(GF("+CIPRCV:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil(',').toInt();
int len_orig = len;
if (len > sockets[mux]->rx.free()) {
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
} else {
@ -687,6 +686,9 @@ public:
while (!stream.available()) { TINY_GSM_YIELD(); }
sockets[mux]->rx.put(stream.read());
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
}
data = "";
} else if (data.endsWith(GF("+TCPCLOSED:"))) {
int mux = stream.readStringUntil('\n').toInt();
@ -702,33 +704,9 @@ public:
if (!index) {
data.trim();
if (data.length()) {
DBG(GSM_NL, "### Unhandled:", data);
}
}
else {
data.trim();
data.replace(GSM_NL GSM_NL, GSM_NL);
data.replace(GSM_NL, GSM_NL " ");
if (data.length()) {
DBG(GSM_NL, "<<< ", data);
}
}
if (gotData) {
int len_orig = len;
if (len > sockets[mux]->rx.free()) {
DBG(GSM_NL, "### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
} else {
DBG(GSM_NL, "### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
TINY_GSM_YIELD();
int r = stream.read();
if (r <= 0) continue; // Skip 0x00 bytes, just in case
sockets[mux]->rx.put((char)r);
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
DBG("### Unhandled:", data);
}
data = "";
}
return index;
}
@ -737,14 +715,14 @@ public:
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
{
String data;
return waitResponse(timeout, data, r1, r2, r3, r4, r5);
String data;
return waitResponse(timeout, data, r1, r2, r3, r4, r5);
}
uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
{
return waitResponse(1000, r1, r2, r3, r4, r5);
return waitResponse(1000, r1, r2, r3, r4, r5);
}
private:


+ 14
- 57
TinyGsmClientESP8266.h View File

@ -76,7 +76,6 @@ public:
at->sendAT(GF("+CIPCLOSE="), mux);
sock_connected = false;
at->waitResponse();
at->waitResponse();
}
virtual size_t write(const uint8_t *buf, size_t size) {
@ -224,7 +223,7 @@ public:
int getSignalQuality() {
sendAT(GF("+CWJAP_CUR?"));
int res1 = waitResponse(GF("No AP"), GF("+CWJAP_CUR:"));
if (res1 != 2){
if (res1 != 2) {
waitResponse();
return 0;
}
@ -241,7 +240,7 @@ public:
for (unsigned long start = millis(); millis() - start < timeout; ) {
sendAT(GF("+CIPSTATUS"));
int res1 = waitResponse(3000, GF("busy p..."), GF("STATUS:"));
if (res1 == 2){
if (res1 == 2) {
int res2 = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5"));
if (res2 == 2 || res2 == 3 || res2 == 4) return true;
}
@ -290,9 +289,13 @@ public:
/*
* GPRS functions
*/
bool gprsConnect(const char* apn, const char* user, const char* pwd) TINY_GSM_ATTR_NOT_IMPLEMENTED;
bool gprsConnect(const char* apn, const char* user, const char* pwd) {
return false;
}
bool gprsDisconnect() TINY_GSM_ATTR_NOT_IMPLEMENTED;
bool gprsDisconnect() {
return false;
}
private:
@ -350,32 +353,12 @@ public:
return false;
}
String streamReadUntil(char c) {
String return_string = stream.readStringUntil(c);
return_string.trim();
if (String(c) == GSM_NL || String(c) == "\n"){
DBG(return_string, c, " ");
} else DBG(return_string, c);
return return_string;
}
bool streamSkipUntil(char c) {
String skipped = stream.readStringUntil(c);
skipped.trim();
if (skipped.length()) {
if (String(c) == GSM_NL || String(c) == "\n"){
DBG(skipped, c, " ");
} else DBG(skipped, c);
return true;
} else return false;
}
template<typename... Args>
void sendAT(Args... cmd) {
streamWrite("AT", cmd..., GSM_NL);
stream.flush();
TINY_GSM_YIELD();
DBG(GSM_NL, ">>> AT", cmd...);
// DBG("### AT", cmd...);
}
// TODO: Optimize this!
@ -390,9 +373,6 @@ public:
String r5s(r5); r5s.trim();
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
data.reserve(64);
bool gotData = false;
int mux = -1;
int len = 0;
int index = 0;
unsigned long startMillis = millis();
do {
@ -419,6 +399,7 @@ public:
} else if (data.endsWith(GF(GSM_NL "+IPD,"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil(':').toInt();
int len_orig = len;
if (len > sockets[mux]->rx.free()) {
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
} else {
@ -428,12 +409,13 @@ public:
while (!stream.available()) { TINY_GSM_YIELD(); }
sockets[mux]->rx.put(stream.read());
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
}
data = "";
return index;
} else if (data.endsWith(GF(GSM_NL "1,CLOSED" GSM_NL))) { //TODO: use mux
sockets[1]->sock_connected = false;
index = 7;
goto finish;
}
}
} while (millis() - startMillis < timeout);
@ -441,34 +423,9 @@ public:
if (!index) {
data.trim();
if (data.length()) {
DBG(GSM_NL, "### Unhandled:", data);
}
}
else {
data.trim();
data.replace(GSM_NL GSM_NL, GSM_NL);
data.replace(GSM_NL, GSM_NL " ");
if (data.length()) {
DBG(GSM_NL, "<<< ", data);
DBG("### Unhandled:", data);
}
}
if (gotData) {
int len_orig = len;
if (len > sockets[mux]->rx.free()) {
DBG(GSM_NL, "### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
} else {
DBG(GSM_NL, "### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
TINY_GSM_YIELD();
int r = stream.read();
if (r <= 0) continue; // Skip 0x00 bytes, just in case
sockets[mux]->rx.put((char)r);
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
}
}
return index;
}


+ 12
- 35
TinyGsmClientM590.h View File

@ -274,7 +274,7 @@ public:
if (waitResponse(GF(GSM_NL "+CCID:")) != 1) {
return "";
}
String res = streamReadUntil('\n');
String res = stream.readStringUntil('\n');
waitResponse();
return res;
}
@ -284,7 +284,7 @@ public:
if (waitResponse(GF(GSM_NL)) != 1) {
return "";
}
String res = streamReadUntil('\n');
String res = stream.readStringUntil('\n');
waitResponse();
return res;
}
@ -314,7 +314,7 @@ public:
return REG_UNKNOWN;
}
streamSkipUntil(','); // Skip format (0)
int status = streamReadUntil('\n').toInt();
int status = stream.readStringUntil('\n').toInt();
waitResponse();
return (RegStatus)status;
}
@ -325,7 +325,7 @@ public:
return "";
}
streamSkipUntil('"'); // Skip mode and format
String res = streamReadUntil('"');
String res = stream.readStringUntil('"');
waitResponse();
return res;
}
@ -537,7 +537,7 @@ private:
if (waitResponse(30000L, GF(GSM_NL "+TCPSEND:")) != 1) {
return 0;
}
streamReadUntil('\n');
stream.readStringUntil('\n');
return len;
}
@ -619,7 +619,7 @@ public:
streamWrite("AT", cmd..., GSM_NL);
stream.flush();
TINY_GSM_YIELD();
DBG(GSM_NL, ">>> AT:", cmd...);
DBG("### AT:", cmd...);
}
// TODO: Optimize this!
@ -634,9 +634,6 @@ public:
String r5s(r5); r5s.trim();
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
data.reserve(64);
bool gotData = false;
int mux = -1;
int len = 0;
int index = 0;
unsigned long startMillis = millis();
do {
@ -663,6 +660,7 @@ public:
} else if (data.endsWith(GF("+TCPRECV:"))) {
int mux = stream.readStringUntil(',').toInt();
int len = stream.readStringUntil(',').toInt();
int len_orig = len;
if (len > sockets[mux]->rx.free()) {
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
} else {
@ -672,6 +670,9 @@ public:
while (!stream.available()) { TINY_GSM_YIELD(); }
sockets[mux]->rx.put(stream.read());
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
}
data = "";
} else if (data.endsWith(GF("+TCPCLOSE:"))) {
int mux = stream.readStringUntil(',').toInt();
@ -688,33 +689,9 @@ public:
if (!index) {
data.trim();
if (data.length()) {
DBG(GSM_NL, "### Unhandled:", data);
}
}
else {
data.trim();
data.replace(GSM_NL GSM_NL, GSM_NL);
data.replace(GSM_NL, GSM_NL " ");
if (data.length()) {
DBG(GSM_NL, "<<< ", data);
}
}
if (gotData) {
int len_orig = len;
if (len > sockets[mux]->rx.free()) {
DBG(GSM_NL, "### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
} else {
DBG(GSM_NL, "### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
TINY_GSM_YIELD();
int r = stream.read();
if (r <= 0) continue; // Skip 0x00 bytes, just in case
sockets[mux]->rx.put((char)r);
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
DBG("### Unhandled:", data);
}
data = "";
}
return index;
}


+ 17
- 16
TinyGsmClientSIM800.h View File

@ -339,8 +339,9 @@ public:
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
return "";
}
String res = streamReadUntil('\n');
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
return res;
}
@ -349,8 +350,9 @@ public:
if (waitResponse(GF(GSM_NL)) != 1) {
return "";
}
String res = streamReadUntil('\n');
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
return res;
}
@ -379,7 +381,7 @@ public:
return REG_UNKNOWN;
}
streamSkipUntil(','); // Skip format (0)
int status = streamReadUntil('\n').toInt();
int status = stream.readStringUntil('\n').toInt();
waitResponse();
return (RegStatus)status;
}
@ -390,7 +392,7 @@ public:
return "";
}
streamSkipUntil('"'); // Skip mode and format
String res = streamReadUntil('"');
String res = stream.readStringUntil('"');
waitResponse();
return res;
}
@ -665,7 +667,7 @@ public:
streamSkipUntil(','); // Skip
streamSkipUntil(','); // Skip
uint16_t res = streamReadUntil(',').toInt();
uint16_t res = stream.readStringUntil(',').toInt();
waitResponse();
return res;
}
@ -708,7 +710,7 @@ protected:
return -1;
}
streamSkipUntil(','); // Skip mux
return streamReadUntil('\n').toInt();
return stream.readStringUntil('\n').toInt();
}
size_t modemRead(size_t size, uint8_t mux) {
@ -725,15 +727,15 @@ protected:
#endif
streamSkipUntil(','); // Skip mode 2/3
streamSkipUntil(','); // Skip mux
size_t len = streamReadUntil(',').toInt();
sockets[mux]->sock_available = streamReadUntil('\n').toInt();
size_t len = stream.readStringUntil(',').toInt();
sockets[mux]->sock_available = stream.readStringUntil('\n').toInt();
for (size_t i=0; i<len; i++) {
#ifdef TINY_GSM_USE_HEX
while (stream.available() < 2) { TINY_GSM_YIELD(); }
char buf[4] = { 0, };
buf[0] = streamRead();
buf[1] = streamRead();
buf[0] = stream.read();
buf[1] = stream.read();
char c = strtol(buf, NULL, 16);
DBG(c);
#else
@ -752,7 +754,7 @@ protected:
if (waitResponse(GF("+CIPRXGET:")) == 1) {
streamSkipUntil(','); // Skip mode 4
streamSkipUntil(','); // Skip mux
result = streamReadUntil('\n').toInt();
result = stream.readStringUntil('\n').toInt();
waitResponse();
}
if (!result) {
@ -828,7 +830,7 @@ public:
streamWrite("AT", cmd..., GSM_NL);
stream.flush();
TINY_GSM_YIELD();
DBG(GSM_NL, ">>> AT:", cmd...);
DBG("### AT:", cmd...);
}
// TODO: Optimize this!
@ -867,8 +869,7 @@ public:
index = 5;
goto finish;
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
index = 6;
String mode = streamReadUntil(',');
String mode = stream.readStringUntil(',');
if (mode.toInt() == 1) {
int mux = stream.readStringUntil('\n').toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) {
@ -879,7 +880,6 @@ public:
data += mode;
}
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
index = 7;
int nl = data.lastIndexOf(GSM_NL, data.length()-8);
int coma = data.indexOf(',', nl+2);
int mux = data.substring(nl+2, coma).toInt();
@ -895,8 +895,9 @@ public:
if (!index) {
data.trim();
if (data.length()) {
DBG(GSM_NL, "### Unhandled:", data);
DBG("### Unhandled:", data);
}
data = "";
}
return index;
}


+ 4
- 4
TinyGsmClientXBee.h View File

@ -473,7 +473,7 @@ private:
TINY_GSM_YIELD();
String return_string = stream.readStringUntil(c);
return_string.trim();
if (String(c) == GSM_NL){
if (String(c) == GSM_NL) {
DBG(return_string, "\r\n");
} else DBG(return_string, c);
return return_string;
@ -484,21 +484,21 @@ private:
{streamRead();}
}
bool commandMode(void){
bool commandMode(void) {
delay(guardTime); // cannot send anything for 1 second before entering command mode
streamWrite(GF("+++")); // enter command mode
DBG("\r\n+++\r\n");
return 1 == waitResponse(guardTime*2);
}
void writeChanges(void){
void writeChanges(void) {
sendAT(GF("WR")); // Write changes to flash
waitResponse();
sendAT(GF("AC")); // Apply changes
waitResponse();
}
void exitCommand(void){
void exitCommand(void) {
sendAT(GF("CN")); // Exit command mode
waitResponse();
}


+ 3
- 3
TinyGsmCommon.h View File

@ -45,14 +45,14 @@
namespace {
template<typename T>
static void DBG(T last) {
// TINY_GSM_DEBUG.println(last);
TINY_GSM_DEBUG.print(last);
TINY_GSM_DEBUG.println(last);
// TINY_GSM_DEBUG.print(last);
}
template<typename T, typename... Args>
static void DBG(T head, Args... tail) {
TINY_GSM_DEBUG.print(head);
// TINY_GSM_DEBUG.print(' ');
TINY_GSM_DEBUG.print(' ');
DBG(tail...);
}
}


Loading…
Cancel
Save