mirror of
https://github.com/KevinMidboe/TinyGSM.git
synced 2025-10-29 18:00:18 +00:00
Removed most of the extra debugging I'd added
This commit is contained in:
@@ -265,7 +265,7 @@ public:
|
|||||||
if (waitResponse(GF(GSM_NL "+SCID: SIM Card ID:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+SCID: SIM Card ID:")) != 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String res = streamReadUntil('\n');
|
String res = stream.readStringUntil('\n');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ public:
|
|||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
if (waitResponse(GF(GSM_NL)) != 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String res = streamReadUntil('\n');
|
String res = stream.readStringUntil('\n');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -305,7 +305,7 @@ public:
|
|||||||
return REG_UNKNOWN;
|
return REG_UNKNOWN;
|
||||||
}
|
}
|
||||||
streamSkipUntil(','); // Skip format (0)
|
streamSkipUntil(','); // Skip format (0)
|
||||||
int status = streamReadUntil('\n').toInt();
|
int status = stream.readStringUntil('\n').toInt();
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return (RegStatus)status;
|
return (RegStatus)status;
|
||||||
}
|
}
|
||||||
@@ -316,7 +316,7 @@ public:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
streamSkipUntil('"'); // Skip mode and format
|
||||||
String res = streamReadUntil('"');
|
String res = stream.readStringUntil('"');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -525,7 +525,7 @@ private:
|
|||||||
if (waitResponse(75000L, GF(GSM_NL "+CIPNUM:")) != 1) {
|
if (waitResponse(75000L, GF(GSM_NL "+CIPNUM:")) != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int newMux = streamReadUntil('\n').toInt();
|
int newMux = stream.readStringUntil('\n').toInt();
|
||||||
|
|
||||||
int rsp = waitResponse(75000L,
|
int rsp = waitResponse(75000L,
|
||||||
GF("CONNECT OK" GSM_NL),
|
GF("CONNECT OK" GSM_NL),
|
||||||
@@ -618,15 +618,13 @@ public:
|
|||||||
streamWrite(tail...);
|
streamWrite(tail...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool streamSkipUntil(char c) {
|
bool streamSkipUntil(char c) { //TODO: timeout
|
||||||
String skipped = stream.readStringUntil(c);
|
while (true) {
|
||||||
skipped.trim();
|
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||||
if (skipped.length()) {
|
if (stream.read() == c)
|
||||||
if (String(c) == GSM_NL || String(c) == "\n"){
|
|
||||||
DBG(skipped, c, " ");
|
|
||||||
} else DBG(skipped, c);
|
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
@@ -634,7 +632,7 @@ public:
|
|||||||
streamWrite("AT", cmd..., GSM_NL);
|
streamWrite("AT", cmd..., GSM_NL);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
DBG(GSM_NL, ">>> AT:", cmd...);
|
// DBG("### AT:", cmd...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
@@ -678,6 +676,7 @@ public:
|
|||||||
} else if (data.endsWith(GF("+CIPRCV:"))) {
|
} else if (data.endsWith(GF("+CIPRCV:"))) {
|
||||||
int mux = stream.readStringUntil(',').toInt();
|
int mux = stream.readStringUntil(',').toInt();
|
||||||
int len = stream.readStringUntil(',').toInt();
|
int len = stream.readStringUntil(',').toInt();
|
||||||
|
int len_orig = len;
|
||||||
if (len > sockets[mux]->rx.free()) {
|
if (len > sockets[mux]->rx.free()) {
|
||||||
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
|
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
|
||||||
} else {
|
} else {
|
||||||
@@ -687,6 +686,9 @@ public:
|
|||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||||
sockets[mux]->rx.put(stream.read());
|
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 = "";
|
data = "";
|
||||||
} else if (data.endsWith(GF("+TCPCLOSED:"))) {
|
} else if (data.endsWith(GF("+TCPCLOSED:"))) {
|
||||||
int mux = stream.readStringUntil('\n').toInt();
|
int mux = stream.readStringUntil('\n').toInt();
|
||||||
@@ -702,33 +704,9 @@ public:
|
|||||||
if (!index) {
|
if (!index) {
|
||||||
data.trim();
|
data.trim();
|
||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG(GSM_NL, "### Unhandled:", data);
|
DBG("### 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);
|
|
||||||
}
|
}
|
||||||
|
data = "";
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ public:
|
|||||||
at->sendAT(GF("+CIPCLOSE="), mux);
|
at->sendAT(GF("+CIPCLOSE="), mux);
|
||||||
sock_connected = false;
|
sock_connected = false;
|
||||||
at->waitResponse();
|
at->waitResponse();
|
||||||
at->waitResponse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual size_t write(const uint8_t *buf, size_t size) {
|
virtual size_t write(const uint8_t *buf, size_t size) {
|
||||||
@@ -224,7 +223,7 @@ public:
|
|||||||
int getSignalQuality() {
|
int getSignalQuality() {
|
||||||
sendAT(GF("+CWJAP_CUR?"));
|
sendAT(GF("+CWJAP_CUR?"));
|
||||||
int res1 = waitResponse(GF("No AP"), GF("+CWJAP_CUR:"));
|
int res1 = waitResponse(GF("No AP"), GF("+CWJAP_CUR:"));
|
||||||
if (res1 != 2){
|
if (res1 != 2) {
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -241,7 +240,7 @@ public:
|
|||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
sendAT(GF("+CIPSTATUS"));
|
sendAT(GF("+CIPSTATUS"));
|
||||||
int res1 = waitResponse(3000, GF("busy p..."), GF("STATUS:"));
|
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"));
|
int res2 = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5"));
|
||||||
if (res2 == 2 || res2 == 3 || res2 == 4) return true;
|
if (res2 == 2 || res2 == 3 || res2 == 4) return true;
|
||||||
}
|
}
|
||||||
@@ -290,9 +289,13 @@ public:
|
|||||||
/*
|
/*
|
||||||
* GPRS functions
|
* 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:
|
private:
|
||||||
|
|
||||||
@@ -350,32 +353,12 @@ public:
|
|||||||
return false;
|
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>
|
template<typename... Args>
|
||||||
void sendAT(Args... cmd) {
|
void sendAT(Args... cmd) {
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
streamWrite("AT", cmd..., GSM_NL);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
DBG(GSM_NL, ">>> AT", cmd...);
|
// DBG("### AT", cmd...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
@@ -390,9 +373,6 @@ public:
|
|||||||
String r5s(r5); r5s.trim();
|
String r5s(r5); r5s.trim();
|
||||||
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
||||||
data.reserve(64);
|
data.reserve(64);
|
||||||
bool gotData = false;
|
|
||||||
int mux = -1;
|
|
||||||
int len = 0;
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
do {
|
do {
|
||||||
@@ -419,6 +399,7 @@ public:
|
|||||||
} else if (data.endsWith(GF(GSM_NL "+IPD,"))) {
|
} else if (data.endsWith(GF(GSM_NL "+IPD,"))) {
|
||||||
int mux = stream.readStringUntil(',').toInt();
|
int mux = stream.readStringUntil(',').toInt();
|
||||||
int len = stream.readStringUntil(':').toInt();
|
int len = stream.readStringUntil(':').toInt();
|
||||||
|
int len_orig = len;
|
||||||
if (len > sockets[mux]->rx.free()) {
|
if (len > sockets[mux]->rx.free()) {
|
||||||
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
|
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
|
||||||
} else {
|
} else {
|
||||||
@@ -428,12 +409,13 @@ public:
|
|||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||||
sockets[mux]->rx.put(stream.read());
|
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 = "";
|
data = "";
|
||||||
return index;
|
return index;
|
||||||
} else if (data.endsWith(GF(GSM_NL "1,CLOSED" GSM_NL))) { //TODO: use mux
|
} else if (data.endsWith(GF(GSM_NL "1,CLOSED" GSM_NL))) { //TODO: use mux
|
||||||
sockets[1]->sock_connected = false;
|
sockets[1]->sock_connected = false;
|
||||||
index = 7;
|
|
||||||
goto finish;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (millis() - startMillis < timeout);
|
} while (millis() - startMillis < timeout);
|
||||||
@@ -441,32 +423,7 @@ public:
|
|||||||
if (!index) {
|
if (!index) {
|
||||||
data.trim();
|
data.trim();
|
||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG(GSM_NL, "### Unhandled:", data);
|
DBG("### 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ public:
|
|||||||
if (waitResponse(GF(GSM_NL "+CCID:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+CCID:")) != 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String res = streamReadUntil('\n');
|
String res = stream.readStringUntil('\n');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -284,7 +284,7 @@ public:
|
|||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
if (waitResponse(GF(GSM_NL)) != 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String res = streamReadUntil('\n');
|
String res = stream.readStringUntil('\n');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ public:
|
|||||||
return REG_UNKNOWN;
|
return REG_UNKNOWN;
|
||||||
}
|
}
|
||||||
streamSkipUntil(','); // Skip format (0)
|
streamSkipUntil(','); // Skip format (0)
|
||||||
int status = streamReadUntil('\n').toInt();
|
int status = stream.readStringUntil('\n').toInt();
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return (RegStatus)status;
|
return (RegStatus)status;
|
||||||
}
|
}
|
||||||
@@ -325,7 +325,7 @@ public:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
streamSkipUntil('"'); // Skip mode and format
|
||||||
String res = streamReadUntil('"');
|
String res = stream.readStringUntil('"');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -537,7 +537,7 @@ private:
|
|||||||
if (waitResponse(30000L, GF(GSM_NL "+TCPSEND:")) != 1) {
|
if (waitResponse(30000L, GF(GSM_NL "+TCPSEND:")) != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
streamReadUntil('\n');
|
stream.readStringUntil('\n');
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,7 +619,7 @@ public:
|
|||||||
streamWrite("AT", cmd..., GSM_NL);
|
streamWrite("AT", cmd..., GSM_NL);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
DBG(GSM_NL, ">>> AT:", cmd...);
|
DBG("### AT:", cmd...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
@@ -634,9 +634,6 @@ public:
|
|||||||
String r5s(r5); r5s.trim();
|
String r5s(r5); r5s.trim();
|
||||||
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
||||||
data.reserve(64);
|
data.reserve(64);
|
||||||
bool gotData = false;
|
|
||||||
int mux = -1;
|
|
||||||
int len = 0;
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
do {
|
do {
|
||||||
@@ -663,6 +660,7 @@ public:
|
|||||||
} else if (data.endsWith(GF("+TCPRECV:"))) {
|
} else if (data.endsWith(GF("+TCPRECV:"))) {
|
||||||
int mux = stream.readStringUntil(',').toInt();
|
int mux = stream.readStringUntil(',').toInt();
|
||||||
int len = stream.readStringUntil(',').toInt();
|
int len = stream.readStringUntil(',').toInt();
|
||||||
|
int len_orig = len;
|
||||||
if (len > sockets[mux]->rx.free()) {
|
if (len > sockets[mux]->rx.free()) {
|
||||||
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
|
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
|
||||||
} else {
|
} else {
|
||||||
@@ -672,6 +670,9 @@ public:
|
|||||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||||
sockets[mux]->rx.put(stream.read());
|
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 = "";
|
data = "";
|
||||||
} else if (data.endsWith(GF("+TCPCLOSE:"))) {
|
} else if (data.endsWith(GF("+TCPCLOSE:"))) {
|
||||||
int mux = stream.readStringUntil(',').toInt();
|
int mux = stream.readStringUntil(',').toInt();
|
||||||
@@ -688,33 +689,9 @@ public:
|
|||||||
if (!index) {
|
if (!index) {
|
||||||
data.trim();
|
data.trim();
|
||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG(GSM_NL, "### Unhandled:", data);
|
DBG("### 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);
|
|
||||||
}
|
}
|
||||||
|
data = "";
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -339,8 +339,9 @@ public:
|
|||||||
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String res = streamReadUntil('\n');
|
String res = stream.readStringUntil('\n');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
res.trim();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,8 +350,9 @@ public:
|
|||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
if (waitResponse(GF(GSM_NL)) != 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String res = streamReadUntil('\n');
|
String res = stream.readStringUntil('\n');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
res.trim();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,7 +381,7 @@ public:
|
|||||||
return REG_UNKNOWN;
|
return REG_UNKNOWN;
|
||||||
}
|
}
|
||||||
streamSkipUntil(','); // Skip format (0)
|
streamSkipUntil(','); // Skip format (0)
|
||||||
int status = streamReadUntil('\n').toInt();
|
int status = stream.readStringUntil('\n').toInt();
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return (RegStatus)status;
|
return (RegStatus)status;
|
||||||
}
|
}
|
||||||
@@ -390,7 +392,7 @@ public:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
streamSkipUntil('"'); // Skip mode and format
|
||||||
String res = streamReadUntil('"');
|
String res = stream.readStringUntil('"');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -665,7 +667,7 @@ public:
|
|||||||
streamSkipUntil(','); // Skip
|
streamSkipUntil(','); // Skip
|
||||||
streamSkipUntil(','); // Skip
|
streamSkipUntil(','); // Skip
|
||||||
|
|
||||||
uint16_t res = streamReadUntil(',').toInt();
|
uint16_t res = stream.readStringUntil(',').toInt();
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -708,7 +710,7 @@ protected:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip mux
|
||||||
return streamReadUntil('\n').toInt();
|
return stream.readStringUntil('\n').toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
@@ -725,15 +727,15 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
streamSkipUntil(','); // Skip mode 2/3
|
streamSkipUntil(','); // Skip mode 2/3
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip mux
|
||||||
size_t len = streamReadUntil(',').toInt();
|
size_t len = stream.readStringUntil(',').toInt();
|
||||||
sockets[mux]->sock_available = streamReadUntil('\n').toInt();
|
sockets[mux]->sock_available = stream.readStringUntil('\n').toInt();
|
||||||
|
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i=0; i<len; i++) {
|
||||||
#ifdef TINY_GSM_USE_HEX
|
#ifdef TINY_GSM_USE_HEX
|
||||||
while (stream.available() < 2) { TINY_GSM_YIELD(); }
|
while (stream.available() < 2) { TINY_GSM_YIELD(); }
|
||||||
char buf[4] = { 0, };
|
char buf[4] = { 0, };
|
||||||
buf[0] = streamRead();
|
buf[0] = stream.read();
|
||||||
buf[1] = streamRead();
|
buf[1] = stream.read();
|
||||||
char c = strtol(buf, NULL, 16);
|
char c = strtol(buf, NULL, 16);
|
||||||
DBG(c);
|
DBG(c);
|
||||||
#else
|
#else
|
||||||
@@ -752,7 +754,7 @@ protected:
|
|||||||
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
||||||
streamSkipUntil(','); // Skip mode 4
|
streamSkipUntil(','); // Skip mode 4
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip mux
|
||||||
result = streamReadUntil('\n').toInt();
|
result = stream.readStringUntil('\n').toInt();
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
@@ -828,7 +830,7 @@ public:
|
|||||||
streamWrite("AT", cmd..., GSM_NL);
|
streamWrite("AT", cmd..., GSM_NL);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
DBG(GSM_NL, ">>> AT:", cmd...);
|
DBG("### AT:", cmd...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
@@ -867,8 +869,7 @@ public:
|
|||||||
index = 5;
|
index = 5;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
||||||
index = 6;
|
String mode = stream.readStringUntil(',');
|
||||||
String mode = streamReadUntil(',');
|
|
||||||
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) {
|
||||||
@@ -879,7 +880,6 @@ public:
|
|||||||
data += mode;
|
data += mode;
|
||||||
}
|
}
|
||||||
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
|
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
|
||||||
index = 7;
|
|
||||||
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();
|
||||||
@@ -895,8 +895,9 @@ public:
|
|||||||
if (!index) {
|
if (!index) {
|
||||||
data.trim();
|
data.trim();
|
||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG(GSM_NL, "### Unhandled:", data);
|
DBG("### Unhandled:", data);
|
||||||
}
|
}
|
||||||
|
data = "";
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -473,7 +473,7 @@ private:
|
|||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
String return_string = stream.readStringUntil(c);
|
String return_string = stream.readStringUntil(c);
|
||||||
return_string.trim();
|
return_string.trim();
|
||||||
if (String(c) == GSM_NL){
|
if (String(c) == GSM_NL) {
|
||||||
DBG(return_string, "\r\n");
|
DBG(return_string, "\r\n");
|
||||||
} else DBG(return_string, c);
|
} else DBG(return_string, c);
|
||||||
return return_string;
|
return return_string;
|
||||||
@@ -484,21 +484,21 @@ private:
|
|||||||
{streamRead();}
|
{streamRead();}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool commandMode(void){
|
bool commandMode(void) {
|
||||||
delay(guardTime); // cannot send anything for 1 second before entering command mode
|
delay(guardTime); // cannot send anything for 1 second before entering command mode
|
||||||
streamWrite(GF("+++")); // enter command mode
|
streamWrite(GF("+++")); // enter command mode
|
||||||
DBG("\r\n+++\r\n");
|
DBG("\r\n+++\r\n");
|
||||||
return 1 == waitResponse(guardTime*2);
|
return 1 == waitResponse(guardTime*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeChanges(void){
|
void writeChanges(void) {
|
||||||
sendAT(GF("WR")); // Write changes to flash
|
sendAT(GF("WR")); // Write changes to flash
|
||||||
waitResponse();
|
waitResponse();
|
||||||
sendAT(GF("AC")); // Apply changes
|
sendAT(GF("AC")); // Apply changes
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
void exitCommand(void){
|
void exitCommand(void) {
|
||||||
sendAT(GF("CN")); // Exit command mode
|
sendAT(GF("CN")); // Exit command mode
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,14 +45,14 @@
|
|||||||
namespace {
|
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);
|
// TINY_GSM_DEBUG.print(last);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
static void DBG(T head, Args... tail) {
|
static void DBG(T head, Args... tail) {
|
||||||
TINY_GSM_DEBUG.print(head);
|
TINY_GSM_DEBUG.print(head);
|
||||||
// TINY_GSM_DEBUG.print(' ');
|
TINY_GSM_DEBUG.print(' ');
|
||||||
DBG(tail...);
|
DBG(tail...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user