More quectel fixes

This commit is contained in:
Sara Damiano
2019-09-06 18:06:11 -04:00
parent 7087a31e6e
commit aeb7579fd2
6 changed files with 104 additions and 56 deletions

View File

@@ -68,7 +68,6 @@ public:
this->mux = mux;
sock_available = 0;
sock_connected = false;
got_data = false;
at->sockets[mux] = this;
@@ -114,7 +113,6 @@ private:
uint8_t mux;
uint16_t sock_available;
bool sock_connected;
bool got_data;
RxFifo rx;
};
@@ -381,14 +379,10 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return false;
}
//Set Method to Handle Received TCP/IP Data - Retrieve Data by Command
sendAT(GF("+QINDI=1"));
if (waitResponse() != 1) {
return false;
}
//Request an IP header for received data ("IPD(data length):")
sendAT(GF("+QIHEAD=1"));
//Set Method to Handle Received TCP/IP Data
// Mode=2 - Output a notification statement:
// “+QIRDI: <id>,<sc>,<sid>,<num>,<len>,< tlen>”
sendAT(GF("+QINDI=2"));
if (waitResponse() != 1) {
return false;
}
@@ -638,22 +632,34 @@ protected:
// sid = index of connection - mux
// len = maximum length of data to send
sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size);
// sendAT(GF("+QIRD="), mux, ',', (uint16_t)size);
if (waitResponse(GF("+QIRD:")) != 1) {
return 0;
// If it replies only OK for the write command, it means there is no
// received data in the buffer of the connection.
int res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR));
if (res == 1) {
streamSkipUntil(':'); // skip IP address
streamSkipUntil(','); // skip port
streamSkipUntil(','); // skip connection type (TCP/UDP)
// read the real length of the retrieved data
uint16_t len = stream.readStringUntil('\n').toInt();
// It's possible that the real length available is less than expected
// This is quite likely if the buffer is broken into packets - which may
// be different sizes.
// If so, make sure we make sure we re-set the amount of data available.
if (len < size) {
sockets[mux]->sock_available = len;
}
for (uint16_t i=0; i<len; i++) {
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
sockets[mux]->sock_available--;
// ^^ One less character available after moving from modem's FIFO to our FIFO
}
waitResponse();
DBG("### READ:", len, "from", mux);
return len;
} else {
sockets[mux]->sock_available = 0;
return 0;
}
streamSkipUntil(':'); // skip IP address
streamSkipUntil(','); // skip port
streamSkipUntil(','); // skip connection type (TCP/UDP)
int len = stream.readStringUntil('\n').toInt(); // read length
for (int i=0; i<len; i++) {
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
sockets[mux]->sock_available--;
// ^^ One less character available after moving from modem's FIFO to our FIFO
}
waitResponse();
DBG("### READ:", len, "from", mux);
return len;
}
bool modemGetConnected(uint8_t mux) {
@@ -725,14 +731,20 @@ TINY_GSM_MODEM_STREAM_UTILITIES()
index = 6;
goto finish;
} else if (data.endsWith(GF(GSM_NL "+QIRD:"))) { // TODO: QIRD? or QIRDI?
// +QIRDI: <id>,<sc>,<sid>,<num>,<len>,< tlen>
streamSkipUntil(','); // Skip the context
streamSkipUntil(','); // Skip the role
int mux = stream.readStringUntil('\n').toInt();
DBG("### Got Data:", mux);
// read the connection id
int mux = stream.readStringUntil(',').toInt();
// read the number of packets in the buffer
int num_packets = stream.readStringUntil(',').toInt();
// read the length of the current packet
int len_packet = stream.readStringUntil('\n').toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true;
sockets[mux]->sock_available = len_packet*num_packets;
}
data = "";
DBG("### Got Data:", len, "on", mux);
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
int nl = data.lastIndexOf(GSM_NL, data.length()-8);
int coma = data.indexOf(',', nl+2);