Make sure that modemRead is properly maintaining sock_available
This commit is contained in:
@@ -58,6 +58,10 @@ public:
|
||||
this->mux = -1;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -71,6 +75,8 @@ public:
|
||||
if (sock_connected) {
|
||||
mux = newMux;
|
||||
at->sockets[mux] = this;
|
||||
// ^^ TODO: attach the socet after attempting connection or above at init?
|
||||
// Currently done inconsistently between modems
|
||||
}
|
||||
return sock_connected;
|
||||
}
|
||||
@@ -112,7 +118,7 @@ public:
|
||||
|
||||
virtual int available() {
|
||||
TINY_GSM_YIELD();
|
||||
if (!rx.size()) {
|
||||
if (!rx.size() && sock_connected) {
|
||||
at->maintain();
|
||||
}
|
||||
return rx.size();
|
||||
|
@@ -62,6 +62,8 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -72,6 +74,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -97,7 +103,7 @@ public:
|
||||
rx.clear();
|
||||
at->maintain();
|
||||
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();
|
||||
at->maintain();
|
||||
}
|
||||
@@ -641,6 +647,7 @@ protected:
|
||||
return 0;
|
||||
}
|
||||
size_t len = stream.readStringUntil('\n').toInt();
|
||||
sockets[mux]->sock_available = len;
|
||||
|
||||
for (size_t i=0; i<len; i++) {
|
||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||
|
@@ -59,6 +59,8 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -69,6 +71,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -109,7 +115,7 @@ public:
|
||||
|
||||
virtual int available() {
|
||||
TINY_GSM_YIELD();
|
||||
if (!rx.size()) {
|
||||
if (!rx.size() && sock_connected) {
|
||||
at->maintain();
|
||||
}
|
||||
return rx.size();
|
||||
@@ -183,6 +189,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
@@ -59,6 +59,8 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -69,6 +71,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -128,7 +134,7 @@ public:
|
||||
continue;
|
||||
}
|
||||
// TODO: Read directly into user buffer?
|
||||
if (!rx.size()) {
|
||||
if (!rx.size() && sock_connected) {
|
||||
at->maintain();
|
||||
}
|
||||
}
|
||||
|
@@ -62,6 +62,8 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -72,6 +74,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -97,7 +103,7 @@ public:
|
||||
rx.clear();
|
||||
at->maintain();
|
||||
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();
|
||||
at->maintain();
|
||||
}
|
||||
@@ -696,6 +702,7 @@ protected:
|
||||
return 0;
|
||||
}
|
||||
size_t len = stream.readStringUntil('\n').toInt();
|
||||
sockets[mux]->sock_available = len;
|
||||
|
||||
for (size_t i=0; i<len; i++) {
|
||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||
|
@@ -66,6 +66,8 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -76,6 +78,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -101,7 +107,7 @@ public:
|
||||
rx.clear();
|
||||
at->maintain();
|
||||
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();
|
||||
at->maintain();
|
||||
}
|
||||
@@ -724,6 +730,7 @@ protected:
|
||||
return 0;
|
||||
}
|
||||
size_t len = stream.readStringUntil('\n').toInt();
|
||||
sockets[mux]->sock_available = len;
|
||||
|
||||
for (size_t i=0; i<len; i++) {
|
||||
while (!stream.available()) { TINY_GSM_YIELD(); }
|
||||
|
@@ -71,6 +71,8 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -81,6 +83,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -106,7 +112,7 @@ public:
|
||||
rx.clear();
|
||||
at->maintain();
|
||||
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();
|
||||
at->maintain();
|
||||
}
|
||||
@@ -228,6 +234,9 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
};
|
||||
@@ -421,6 +430,7 @@ public:
|
||||
|
||||
RegStatus getRegistrationStatus() {
|
||||
sendAT(GF("+CGREG?"));
|
||||
// TODO: Shouldn't this be CEREG for the EPS status of this 4G module?
|
||||
if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) {
|
||||
return REG_UNKNOWN;
|
||||
}
|
||||
|
@@ -68,6 +68,8 @@ public:
|
||||
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;
|
||||
}
|
||||
@@ -78,6 +80,10 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -103,7 +109,7 @@ public:
|
||||
rx.clear();
|
||||
at->maintain();
|
||||
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();
|
||||
at->maintain();
|
||||
}
|
||||
@@ -223,6 +229,9 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
@@ -61,6 +61,11 @@ public:
|
||||
prev_check = 0;
|
||||
sock_connected = 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;
|
||||
}
|
||||
|
||||
@@ -81,8 +86,11 @@ public:
|
||||
}
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
// 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
|
||||
at->maintain();
|
||||
return sock_connected;
|
||||
}
|
||||
@@ -109,7 +117,7 @@ public:
|
||||
rx.clear();
|
||||
at->maintain();
|
||||
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();
|
||||
at->maintain();
|
||||
}
|
||||
@@ -229,8 +237,10 @@ public:
|
||||
stop();
|
||||
TINY_GSM_YIELD();
|
||||
rx.clear();
|
||||
// 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?
|
||||
at->maintain();
|
||||
return sock_connected;
|
||||
}
|
||||
@@ -809,6 +819,7 @@ protected:
|
||||
}
|
||||
streamSkipUntil(','); // Skip mux
|
||||
size_t len = stream.readStringUntil(',').toInt();
|
||||
sockets[mux]->sock_available = len;
|
||||
streamSkipUntil('\"');
|
||||
|
||||
for (size_t i=0; i<len; i++) {
|
||||
@@ -895,7 +906,7 @@ public:
|
||||
TINY_GSM_YIELD();
|
||||
while (stream.available() > 0) {
|
||||
int a = stream.read();
|
||||
if (a < 0) continue;
|
||||
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
||||
data += (char)a;
|
||||
if (r1 && data.endsWith(r1)) {
|
||||
index = 1;
|
||||
|
Reference in New Issue
Block a user