Make sure that modemRead is properly maintaining sock_available

This commit is contained in:
Sara Damiano
2019-05-07 14:23:32 -04:00
parent e18c5dacbd
commit d5520757e4
9 changed files with 84 additions and 11 deletions

View File

@@ -58,6 +58,10 @@ public:
this->mux = -1; this->mux = -1;
sock_connected = false; sock_connected = false;
// at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -71,6 +75,8 @@ public:
if (sock_connected) { if (sock_connected) {
mux = newMux; mux = newMux;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
} }
return sock_connected; return sock_connected;
} }
@@ -112,7 +118,7 @@ public:
virtual int available() { virtual int available() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
if (!rx.size()) { if (!rx.size() && sock_connected) {
at->maintain(); at->maintain();
} }
return rx.size(); return rx.size();

View File

@@ -62,6 +62,8 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -72,6 +74,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
@@ -97,7 +103,7 @@ public:
rx.clear(); rx.clear();
at->maintain(); at->maintain();
while (sock_available > 0) { while (sock_available > 0) {
sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
rx.clear(); rx.clear();
at->maintain(); at->maintain();
} }
@@ -641,6 +647,7 @@ protected:
return 0; return 0;
} }
size_t len = stream.readStringUntil('\n').toInt(); size_t len = stream.readStringUntil('\n').toInt();
sockets[mux]->sock_available = len;
for (size_t i=0; i<len; i++) { for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); } while (!stream.available()) { TINY_GSM_YIELD(); }

View File

@@ -59,6 +59,8 @@ public:
sock_connected = false; sock_connected = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -69,6 +71,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
@@ -109,7 +115,7 @@ public:
virtual int available() { virtual int available() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
if (!rx.size()) { if (!rx.size() && sock_connected) {
at->maintain(); at->maintain();
} }
return rx.size(); return rx.size();
@@ -183,6 +189,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux, true); sock_connected = at->modemConnect(host, port, mux, true);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
}; };

View File

@@ -59,6 +59,8 @@ public:
sock_connected = false; sock_connected = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -69,6 +71,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
@@ -128,7 +134,7 @@ public:
continue; continue;
} }
// TODO: Read directly into user buffer? // TODO: Read directly into user buffer?
if (!rx.size()) { if (!rx.size() && sock_connected) {
at->maintain(); at->maintain();
} }
} }

View File

@@ -62,6 +62,8 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -72,6 +74,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
@@ -97,7 +103,7 @@ public:
rx.clear(); rx.clear();
at->maintain(); at->maintain();
while (sock_available > 0) { while (sock_available > 0) {
sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
rx.clear(); rx.clear();
at->maintain(); at->maintain();
} }
@@ -696,6 +702,7 @@ protected:
return 0; return 0;
} }
size_t len = stream.readStringUntil('\n').toInt(); size_t len = stream.readStringUntil('\n').toInt();
sockets[mux]->sock_available = len;
for (size_t i=0; i<len; i++) { for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); } while (!stream.available()) { TINY_GSM_YIELD(); }

View File

@@ -66,6 +66,8 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -76,6 +78,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
@@ -101,7 +107,7 @@ public:
rx.clear(); rx.clear();
at->maintain(); at->maintain();
while (sock_available > 0) { while (sock_available > 0) {
sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
rx.clear(); rx.clear();
at->maintain(); at->maintain();
} }
@@ -724,6 +730,7 @@ protected:
return 0; return 0;
} }
size_t len = stream.readStringUntil('\n').toInt(); size_t len = stream.readStringUntil('\n').toInt();
sockets[mux]->sock_available = len;
for (size_t i=0; i<len; i++) { for (size_t i=0; i<len; i++) {
while (!stream.available()) { TINY_GSM_YIELD(); } while (!stream.available()) { TINY_GSM_YIELD(); }

View File

@@ -71,6 +71,8 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -81,6 +83,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
@@ -106,7 +112,7 @@ public:
rx.clear(); rx.clear();
at->maintain(); at->maintain();
while (sock_available > 0) { while (sock_available > 0) {
sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
rx.clear(); rx.clear();
at->maintain(); at->maintain();
} }
@@ -228,6 +234,9 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux, true); sock_connected = at->modemConnect(host, port, mux, true);
// sock_connected = at->modemConnect(host, port, &mux, true);
// at->sockets[mux] = this;
// TODO: When is the socket attached?
return sock_connected; return sock_connected;
} }
}; };
@@ -421,6 +430,7 @@ public:
RegStatus getRegistrationStatus() { RegStatus getRegistrationStatus() {
sendAT(GF("+CGREG?")); sendAT(GF("+CGREG?"));
// TODO: Shouldn't this be CEREG for the EPS status of this 4G module?
if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) { if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) {
return REG_UNKNOWN; return REG_UNKNOWN;
} }

View File

@@ -68,6 +68,8 @@ public:
got_data = false; got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -78,6 +80,10 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux); sock_connected = at->modemConnect(host, port, mux);
// sock_connected = at->modemConnect(host, port, &mux);
// at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
return sock_connected; return sock_connected;
} }
@@ -103,7 +109,7 @@ public:
rx.clear(); rx.clear();
at->maintain(); at->maintain();
while (sock_available > 0) { while (sock_available > 0) {
sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
rx.clear(); rx.clear();
at->maintain(); at->maintain();
} }
@@ -223,6 +229,9 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
sock_connected = at->modemConnect(host, port, mux, true); sock_connected = at->modemConnect(host, port, mux, true);
// sock_connected = at->modemConnect(host, port, &mux, true);
// at->sockets[mux] = this;
// TODO: When is the socket attached?
return sock_connected; return sock_connected;
} }
}; };

View File

@@ -61,6 +61,11 @@ public:
prev_check = 0; prev_check = 0;
sock_connected = false; sock_connected = false;
got_data = false; got_data = false;
// at->sockets[mux] = this;
// ^^ TODO: attach the socket here at init? Or later at connect?
// Currently done inconsistently between modems
return true; return true;
} }
@@ -81,8 +86,11 @@ public:
} }
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
// sock_connected = at->modemConnect(host, port, mux);
sock_connected = at->modemConnect(host, port, &mux); sock_connected = at->modemConnect(host, port, &mux);
at->sockets[mux] = this; at->sockets[mux] = this;
// ^^ TODO: attach the socet after attempting connection or above at init?
// Currently done inconsistently between modems
at->maintain(); at->maintain();
return sock_connected; return sock_connected;
} }
@@ -109,7 +117,7 @@ public:
rx.clear(); rx.clear();
at->maintain(); at->maintain();
while (sock_available > 0) { while (sock_available > 0) {
sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
rx.clear(); rx.clear();
at->maintain(); at->maintain();
} }
@@ -229,8 +237,10 @@ public:
stop(); stop();
TINY_GSM_YIELD(); TINY_GSM_YIELD();
rx.clear(); rx.clear();
// sock_connected = at->modemConnect(host, port, mux, true);
sock_connected = at->modemConnect(host, port, &mux, true); sock_connected = at->modemConnect(host, port, &mux, true);
at->sockets[mux] = this; at->sockets[mux] = this;
// TODO: When is the socket attached?
at->maintain(); at->maintain();
return sock_connected; return sock_connected;
} }
@@ -809,6 +819,7 @@ protected:
} }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
size_t len = stream.readStringUntil(',').toInt(); size_t len = stream.readStringUntil(',').toInt();
sockets[mux]->sock_available = len;
streamSkipUntil('\"'); streamSkipUntil('\"');
for (size_t i=0; i<len; i++) { for (size_t i=0; i<len; i++) {
@@ -895,7 +906,7 @@ public:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
while (stream.available() > 0) { while (stream.available() > 0) {
int a = stream.read(); int a = stream.read();
if (a < 0) continue; if (a <= 0) continue; // Skip 0x00 bytes, just in case
data += (char)a; data += (char)a;
if (r1 && data.endsWith(r1)) { if (r1 && data.endsWith(r1)) {
index = 1; index = 1;
@@ -926,7 +937,7 @@ public:
sockets[mux]->sock_connected = false; sockets[mux]->sock_connected = false;
} }
data = ""; data = "";
DBG("### Closed:", mux); DBG("### Closed: ", mux);
} }
} }
} while (millis() - startMillis < timeout); } while (millis() - startMillis < timeout);