Some more null pointer checks, fix #186
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -504,21 +504,25 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
|
|||||||
int8_t mux = streamGetIntBefore(',');
|
int8_t mux = streamGetIntBefore(',');
|
||||||
int16_t len = streamGetIntBefore(',');
|
int16_t len = streamGetIntBefore(',');
|
||||||
int16_t len_orig = len;
|
int16_t len_orig = len;
|
||||||
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
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 {
|
||||||
DBG("### Got: ", len, "->", sockets[mux]->rx.free());
|
DBG("### Got: ", len, "->", sockets[mux]->rx.free());
|
||||||
}
|
}
|
||||||
while (len--) { moveCharFromStreamToFifo(mux); }
|
while (len--) {
|
||||||
|
moveCharFromStreamToFifo(mux);
|
||||||
|
}
|
||||||
// TODO(?) Deal with missing characters
|
// TODO(?) Deal with missing characters
|
||||||
if (len_orig > sockets[mux]->available()) {
|
if (len_orig > sockets[mux]->available()) {
|
||||||
DBG("### Fewer characters received than expected: ",
|
DBG("### Fewer characters received than expected: ",
|
||||||
sockets[mux]->available(), " vs ", len_orig);
|
sockets[mux]->available(), " vs ", len_orig);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
data = "";
|
data = "";
|
||||||
} else if (data.endsWith(GF("+TCPCLOSED:"))) {
|
} else if (data.endsWith(GF("+TCPCLOSED:"))) {
|
||||||
int8_t mux = streamGetIntBefore('\n');
|
int8_t mux = streamGetIntBefore('\n');
|
||||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) {
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
sockets[mux]->sock_connected = false;
|
sockets[mux]->sock_connected = false;
|
||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
@@ -529,7 +533,9 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
|
|||||||
finish:
|
finish:
|
||||||
if (!index) {
|
if (!index) {
|
||||||
data.trim();
|
data.trim();
|
||||||
if (data.length()) { DBG("### Unhandled:", data); }
|
if (data.length()) {
|
||||||
|
DBG("### Unhandled:", data);
|
||||||
|
}
|
||||||
data = "";
|
data = "";
|
||||||
}
|
}
|
||||||
// data.replace(GSM_NL, "/");
|
// data.replace(GSM_NL, "/");
|
||||||
@@ -562,6 +568,7 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientA6* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientA6* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -522,6 +522,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
sendAT(GF("+QIRD="), mux, ',', (uint16_t)size);
|
sendAT(GF("+QIRD="), mux, ',', (uint16_t)size);
|
||||||
if (waitResponse(GF("+QIRD:")) != 1) { return 0; }
|
if (waitResponse(GF("+QIRD:")) != 1) { return 0; }
|
||||||
int16_t len = streamGetIntBefore('\n');
|
int16_t len = streamGetIntBefore('\n');
|
||||||
@@ -534,6 +535,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
sendAT(GF("+QIRD="), mux, GF(",0"));
|
sendAT(GF("+QIRD="), mux, GF(",0"));
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
if (waitResponse(GF("+QIRD:")) == 1) {
|
if (waitResponse(GF("+QIRD:")) == 1) {
|
||||||
@@ -675,6 +677,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientBG96* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientBG96* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -315,9 +315,8 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
|
|||||||
// if the status is anything but 3, there are no connections open
|
// if the status is anything but 3, there are no connections open
|
||||||
waitResponse(); // Returns an OK after the status
|
waitResponse(); // Returns an OK after the status
|
||||||
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
||||||
GsmClientESP8266* sock = sockets[muxNo];
|
if (sockets[muxNo]) {
|
||||||
if (sock) {
|
sockets[muxNo]->sock_connected = false;
|
||||||
sock->sock_connected = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -339,9 +338,8 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
|
|||||||
if (has_status == 2) break; // once we get to the ok, stop
|
if (has_status == 2) break; // once we get to the ok, stop
|
||||||
}
|
}
|
||||||
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
||||||
GsmClientESP8266* sock = sockets[muxNo];
|
if (sockets[muxNo]) {
|
||||||
if (sock) {
|
sockets[muxNo]->sock_connected = verified_connections[muxNo];
|
||||||
sock->sock_connected = verified_connections[muxNo];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return verified_connections[mux];
|
return verified_connections[mux];
|
||||||
@@ -391,18 +389,22 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
|
|||||||
int8_t mux = streamGetIntBefore(',');
|
int8_t mux = streamGetIntBefore(',');
|
||||||
int16_t len = streamGetIntBefore(':');
|
int16_t len = streamGetIntBefore(':');
|
||||||
int16_t len_orig = len;
|
int16_t len_orig = len;
|
||||||
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
if (len > sockets[mux]->rx.free()) {
|
if (len > sockets[mux]->rx.free()) {
|
||||||
DBG("### Buffer overflow: ", len, "received vs",
|
DBG("### Buffer overflow: ", len, "received vs",
|
||||||
sockets[mux]->rx.free(), "available");
|
sockets[mux]->rx.free(), "available");
|
||||||
} else {
|
} else {
|
||||||
// DBG("### Got Data: ", len, "on", mux);
|
// DBG("### Got Data: ", len, "on", mux);
|
||||||
}
|
}
|
||||||
while (len--) { moveCharFromStreamToFifo(mux); }
|
while (len--) {
|
||||||
|
moveCharFromStreamToFifo(mux);
|
||||||
|
}
|
||||||
// TODO(SRGDamia1): deal with buffer overflow/missed characters
|
// TODO(SRGDamia1): deal with buffer overflow/missed characters
|
||||||
if (len_orig > sockets[mux]->available()) {
|
if (len_orig > sockets[mux]->available()) {
|
||||||
DBG("### Fewer characters received than expected: ",
|
DBG("### Fewer characters received than expected: ",
|
||||||
sockets[mux]->available(), " vs ", len_orig);
|
sockets[mux]->available(), " vs ", len_orig);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
data = "";
|
data = "";
|
||||||
} else if (data.endsWith(GF("CLOSED"))) {
|
} else if (data.endsWith(GF("CLOSED"))) {
|
||||||
int8_t muxStart =
|
int8_t muxStart =
|
||||||
@@ -443,6 +445,7 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientESP8266* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientESP8266* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -395,22 +395,26 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
|
|||||||
int8_t mux = streamGetIntBefore(',');
|
int8_t mux = streamGetIntBefore(',');
|
||||||
int16_t len = streamGetIntBefore(',');
|
int16_t len = streamGetIntBefore(',');
|
||||||
int16_t len_orig = len;
|
int16_t len_orig = len;
|
||||||
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
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 {
|
||||||
DBG("### Got: ", len, "->", sockets[mux]->rx.free());
|
DBG("### Got: ", len, "->", sockets[mux]->rx.free());
|
||||||
}
|
}
|
||||||
while (len--) { moveCharFromStreamToFifo(mux); }
|
while (len--) {
|
||||||
|
moveCharFromStreamToFifo(mux);
|
||||||
|
}
|
||||||
// TODO(?): Handle lost characters
|
// TODO(?): Handle lost characters
|
||||||
if (len_orig > sockets[mux]->available()) {
|
if (len_orig > sockets[mux]->available()) {
|
||||||
DBG("### Fewer characters received than expected: ",
|
DBG("### Fewer characters received than expected: ",
|
||||||
sockets[mux]->available(), " vs ", len_orig);
|
sockets[mux]->available(), " vs ", len_orig);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
data = "";
|
data = "";
|
||||||
} else if (data.endsWith(GF("+TCPCLOSE:"))) {
|
} else if (data.endsWith(GF("+TCPCLOSE:"))) {
|
||||||
int8_t mux = streamGetIntBefore(',');
|
int8_t mux = streamGetIntBefore(',');
|
||||||
streamSkipUntil('\n');
|
streamSkipUntil('\n');
|
||||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) {
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
sockets[mux]->sock_connected = false;
|
sockets[mux]->sock_connected = false;
|
||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
@@ -454,6 +458,7 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientM590* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientM590* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -445,6 +445,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
// TODO(?): Does this work????
|
// TODO(?): Does this work????
|
||||||
// AT+QIRD=<id>,<sc>,<sid>,<len>
|
// AT+QIRD=<id>,<sc>,<sid>,<len>
|
||||||
// id = GPRS context number = 0, set in GPRS connect
|
// id = GPRS context number = 0, set in GPRS connect
|
||||||
@@ -482,6 +483,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not possible to check the number of characters remaining in buffer
|
||||||
size_t modemGetAvailable(uint8_t) {
|
size_t modemGetAvailable(uint8_t) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -618,6 +620,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientM95* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientM95* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -405,7 +405,8 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
// TODO(?): Does this work????
|
if (!sockets[mux]) return 0;
|
||||||
|
// TODO(?): Does this even work????
|
||||||
// AT+QIRD=<id>,<sc>,<sid>,<len>
|
// AT+QIRD=<id>,<sc>,<sid>,<len>
|
||||||
// id = GPRS context number = 0, set in GPRS connect
|
// id = GPRS context number = 0, set in GPRS connect
|
||||||
// sc = role in connection = 1, client of connection
|
// sc = role in connection = 1, client of connection
|
||||||
@@ -441,6 +442,7 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not possible to check the number of characters remaining in buffer
|
||||||
size_t modemGetAvailable(uint8_t) {
|
size_t modemGetAvailable(uint8_t) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -590,6 +592,7 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientMC60* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientMC60* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -517,6 +517,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
#ifdef TINY_GSM_USE_HEX
|
#ifdef TINY_GSM_USE_HEX
|
||||||
sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size);
|
sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size);
|
||||||
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
||||||
@@ -560,6 +561,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
sendAT(GF("+CIPRXGET=4,"), mux);
|
sendAT(GF("+CIPRXGET=4,"), mux);
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
||||||
@@ -579,15 +581,13 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
|
|||||||
if (waitResponse(GF("+CIPCLOSE:")) != 1) { return false; }
|
if (waitResponse(GF("+CIPCLOSE:")) != 1) { return false; }
|
||||||
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
||||||
// +CIPCLOSE:<link0_state>,<link1_state>,...,<link9_state>
|
// +CIPCLOSE:<link0_state>,<link1_state>,...,<link9_state>
|
||||||
bool thisMuxState = stream.parseInt();
|
bool muxState = stream.parseInt();
|
||||||
// Need to make sure a socket instace for the socket number exists
|
if (sockets[muxNo]) {
|
||||||
// before setting its state
|
sockets[muxNo]->sock_connected = muxState;
|
||||||
GsmClientSim5360* sock = sockets[muxNo];
|
|
||||||
if (sock) {
|
|
||||||
sock->sock_connected = thisMuxState;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitResponse(); // Should be an OK at the end
|
waitResponse(); // Should be an OK at the end
|
||||||
|
if (!sockets[mux]) return false;
|
||||||
return sockets[mux]->sock_connected;
|
return sockets[mux]->sock_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,6 +715,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientSim5360* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientSim5360* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -550,6 +550,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
#ifdef TINY_GSM_USE_HEX
|
#ifdef TINY_GSM_USE_HEX
|
||||||
sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size);
|
sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size);
|
||||||
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
||||||
@@ -597,6 +598,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
sendAT(GF("+CIPRXGET=4,"), mux);
|
sendAT(GF("+CIPRXGET=4,"), mux);
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
||||||
@@ -756,6 +758,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientSim7000* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientSim7000* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -608,6 +608,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
#ifdef TINY_GSM_USE_HEX
|
#ifdef TINY_GSM_USE_HEX
|
||||||
sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size);
|
sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size);
|
||||||
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
||||||
@@ -651,6 +652,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
sendAT(GF("+CIPRXGET=4,"), mux);
|
sendAT(GF("+CIPRXGET=4,"), mux);
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
||||||
@@ -672,15 +674,13 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
|
|||||||
}
|
}
|
||||||
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
||||||
// +CIPCLOSE:<link0_state>,<link1_state>,...,<link9_state>
|
// +CIPCLOSE:<link0_state>,<link1_state>,...,<link9_state>
|
||||||
bool thisMuxState = stream.parseInt();
|
bool muxState = stream.parseInt();
|
||||||
// Need to make sure a socket instace for the socket number exists
|
if (sockets[muxNo]) {
|
||||||
// before setting its state
|
sockets[muxNo]->sock_connected = muxState;
|
||||||
GsmClientSim7600* sock = sockets[muxNo];
|
|
||||||
if (sock) {
|
|
||||||
sock->sock_connected = thisMuxState;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitResponse(); // Should be an OK at the end
|
waitResponse(); // Should be an OK at the end
|
||||||
|
if (!sockets[mux]) return false;
|
||||||
return sockets[mux]->sock_connected;
|
return sockets[mux]->sock_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,6 +808,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientSim7600* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientSim7600* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -528,6 +528,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
#ifdef TINY_GSM_USE_HEX
|
#ifdef TINY_GSM_USE_HEX
|
||||||
sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size);
|
sendAT(GF("+CIPRXGET=3,"), mux, ',', (uint16_t)size);
|
||||||
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
||||||
@@ -575,6 +576,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
sendAT(GF("+CIPRXGET=4,"), mux);
|
sendAT(GF("+CIPRXGET=4,"), mux);
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
if (waitResponse(GF("+CIPRXGET:")) == 1) {
|
||||||
@@ -734,6 +736,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientSim800* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientSim800* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -707,6 +707,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
sendAT(GF("+USORD="), mux, ',', (uint16_t)size);
|
sendAT(GF("+USORD="), mux, ',', (uint16_t)size);
|
||||||
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; }
|
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; }
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip mux
|
||||||
@@ -722,6 +723,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
// NOTE: Querying a closed socket gives an error "operation not allowed"
|
// NOTE: Querying a closed socket gives an error "operation not allowed"
|
||||||
sendAT(GF("+USORD="), mux, ",0");
|
sendAT(GF("+USORD="), mux, ",0");
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
@@ -735,7 +737,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
|
|||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); }
|
if (!result) { sockets[mux]->sock_connected = modemGetConnected(mux); }
|
||||||
// DBG("### AvailablE:", result, "on", mux);
|
// DBG("### Available:", result, "on", mux);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -879,6 +881,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientSaraR4* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientSaraR4* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -649,6 +649,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
sendAT(GF("+USORD="), mux, ',', (uint16_t)size);
|
sendAT(GF("+USORD="), mux, ',', (uint16_t)size);
|
||||||
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; }
|
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; }
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip mux
|
||||||
@@ -664,6 +665,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
|
if (!sockets[mux]) return 0;
|
||||||
// NOTE: Querying a closed socket gives an error "operation not allowed"
|
// NOTE: Querying a closed socket gives an error "operation not allowed"
|
||||||
sendAT(GF("+USORD="), mux, ",0");
|
sendAT(GF("+USORD="), mux, ",0");
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
@@ -812,6 +814,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientUBLOX* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientUBLOX* sockets[TINY_GSM_MUX_COUNT];
|
||||||
const char* gsmNL = GSM_NL;
|
const char* gsmNL = GSM_NL;
|
||||||
|
@@ -332,6 +332,7 @@ class TinyGsmTCP {
|
|||||||
// !stream.available()" and then will wait again in the stream.read()
|
// !stream.available()" and then will wait again in the stream.read()
|
||||||
// function.
|
// function.
|
||||||
inline void moveCharFromStreamToFifo(uint8_t mux) {
|
inline void moveCharFromStreamToFifo(uint8_t mux) {
|
||||||
|
if (!thisModem().sockets[mux]) return;
|
||||||
uint32_t startMillis = millis();
|
uint32_t startMillis = millis();
|
||||||
while (!thisModem().stream.available() &&
|
while (!thisModem().stream.available() &&
|
||||||
(millis() - startMillis < thisModem().sockets[mux]->_timeout)) {
|
(millis() - startMillis < thisModem().sockets[mux]->_timeout)) {
|
||||||
|
Reference in New Issue
Block a user