Improve MUX handling
This commit is contained in:
@@ -501,15 +501,16 @@ private:
|
|||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
#ifdef GSM_USE_HEX
|
#ifdef GSM_USE_HEX
|
||||||
sendAT(GF("+CIPRXGET=3,"), mux, ',', size);
|
sendAT(GF("+CIPRXGET=3,"), mux, ',', size);
|
||||||
if (waitResponse(GF("+CIPRXGET: 3,")) != 1) {
|
if (waitResponse(GF("+CIPRXGET:")) != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
sendAT(GF("+CIPRXGET=2,"), mux, ',', size);
|
sendAT(GF("+CIPRXGET=2,"), mux, ',', size);
|
||||||
if (waitResponse(GF("+CIPRXGET: 2,")) != 1) {
|
if (waitResponse(GF("+CIPRXGET:")) != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
stream.readStringUntil(','); // Skip mode 2/3
|
||||||
stream.readStringUntil(','); // Skip mux
|
stream.readStringUntil(','); // Skip mux
|
||||||
size_t len = stream.readStringUntil(',').toInt();
|
size_t len = stream.readStringUntil(',').toInt();
|
||||||
sockets[mux]->sock_available = stream.readStringUntil('\n').toInt();
|
sockets[mux]->sock_available = stream.readStringUntil('\n').toInt();
|
||||||
@@ -535,10 +536,10 @@ private:
|
|||||||
sendAT(GF("+CIPRXGET=4,"), mux);
|
sendAT(GF("+CIPRXGET=4,"), mux);
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
for (byte i = 0; i < 2; i++) {
|
for (byte i = 0; i < 2; i++) {
|
||||||
int res = waitResponse(GF("+CIPRXGET: 4"), GFP(GSM_OK), GFP(GSM_ERROR));
|
int res = waitResponse(GF("+CIPRXGET:"), GFP(GSM_OK), GFP(GSM_ERROR));
|
||||||
if (res == 1) {
|
if (res == 1) {
|
||||||
stream.readStringUntil(',');
|
stream.readStringUntil(','); // Skip mode 4
|
||||||
stream.readStringUntil(',');
|
stream.readStringUntil(','); // Skip mux
|
||||||
result = stream.readStringUntil('\n').toInt();
|
result = stream.readStringUntil('\n').toInt();
|
||||||
} else if (res == 2) {
|
} else if (res == 2) {
|
||||||
} else {
|
} else {
|
||||||
@@ -591,7 +592,8 @@ private:
|
|||||||
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 gotNewData = false;
|
bool gotData = false;
|
||||||
|
int mux = -1;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
do {
|
do {
|
||||||
@@ -614,14 +616,25 @@ private:
|
|||||||
} else if (r5 && data.endsWith(r5)) {
|
} else if (r5 && data.endsWith(r5)) {
|
||||||
index = 5;
|
index = 5;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET: 1,1" GSM_NL))) { //TODO: use mux
|
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
||||||
gotNewData = true;
|
String mode = stream.readStringUntil(',');
|
||||||
|
if (mode.toInt() == 1) {
|
||||||
|
mux = stream.readStringUntil('\n').toInt();
|
||||||
|
gotData = true;
|
||||||
data = "";
|
data = "";
|
||||||
} else if (data.endsWith(GF(GSM_NL "1, CLOSED" GSM_NL))) { //TODO: use mux
|
} else {
|
||||||
sockets[1]->sock_connected = false;
|
data += mode;
|
||||||
|
}
|
||||||
|
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
|
||||||
|
int nl = data.lastIndexOf(GSM_NL, data.length()-8);
|
||||||
|
int coma = data.indexOf(',', nl+2);
|
||||||
|
mux = data.substring(nl+2, coma).toInt();
|
||||||
|
if (mux) {
|
||||||
|
sockets[mux]->sock_connected = false;
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} while (millis() - startMillis < timeout);
|
} while (millis() - startMillis < timeout);
|
||||||
finish:
|
finish:
|
||||||
if (!index) {
|
if (!index) {
|
||||||
@@ -630,8 +643,8 @@ finish:
|
|||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
if (gotNewData) {
|
if (gotData) {
|
||||||
sockets[1]->sock_available = modemGetAvailable(1);
|
sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user