mirror of
				https://github.com/KevinMidboe/TinyGSM.git
				synced 2025-10-29 18:00:18 +00:00 
			
		
		
		
	Replace *most* toInt and toFloat's
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
		| @@ -362,10 +362,10 @@ class TinyGsmA6 | ||||
|     sendAT(GF("+CUSD=1,\""), code, GF("\",15")); | ||||
|     if (waitResponse(10000L) != 1) { return ""; } | ||||
|     if (waitResponse(GF(GSM_NL "+CUSD:")) != 1) { return ""; } | ||||
|     stream.readStringUntil('"'); | ||||
|     streamSkipUntil('"'); | ||||
|     String hex = stream.readStringUntil('"'); | ||||
|     stream.readStringUntil(','); | ||||
|     int dcs = stream.readStringUntil('\n').toInt(); | ||||
|     streamSkipUntil(','); | ||||
|     int dcs = streamGetInt('\n'); | ||||
|  | ||||
|     if (dcs == 15) { | ||||
|       return TinyGsmDecodeHex7bit(hex); | ||||
| @@ -407,7 +407,7 @@ class TinyGsmA6 | ||||
|     if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; } | ||||
|     streamSkipUntil(',');  // Skip battery charge status | ||||
|     // Read battery charge level | ||||
|     int res = stream.readStringUntil('\n').toInt(); | ||||
|     int res = streamGetInt('\n'); | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
|     return res; | ||||
| @@ -418,8 +418,8 @@ class TinyGsmA6 | ||||
|                         uint16_t& milliVolts) { | ||||
|     sendAT(GF("+CBC?")); | ||||
|     if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; } | ||||
|     chargeState = stream.readStringUntil(',').toInt(); | ||||
|     percent     = stream.readStringUntil('\n').toInt(); | ||||
|     chargeState = streamGetInt(','); | ||||
|     percent     = streamGetInt('\n'); | ||||
|     milliVolts  = 0; | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
| @@ -439,7 +439,7 @@ class TinyGsmA6 | ||||
|  | ||||
|     sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port); | ||||
|     if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) { return false; } | ||||
|     int newMux = stream.readStringUntil('\n').toInt(); | ||||
|     int newMux = streamGetInt('\n'); | ||||
|  | ||||
|     int rsp = waitResponse((timeout_ms - (millis() - startMillis)), | ||||
|                            GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL), | ||||
| @@ -519,8 +519,8 @@ class TinyGsmA6 | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF("+CIPRCV:"))) { | ||||
|           int mux      = stream.readStringUntil(',').toInt(); | ||||
|           int len      = stream.readStringUntil(',').toInt(); | ||||
|           int mux      = streamGetInt(','); | ||||
|           int len      = streamGetInt(','); | ||||
|           int len_orig = len; | ||||
|           if (len > sockets[mux]->rx.free()) { | ||||
|             DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free()); | ||||
| @@ -535,7 +535,7 @@ class TinyGsmA6 | ||||
|           } | ||||
|           data = ""; | ||||
|         } else if (data.endsWith(GF("+TCPCLOSED:"))) { | ||||
|           int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) { | ||||
|             sockets[mux]->sock_connected = false; | ||||
|           } | ||||
|   | ||||
| @@ -327,9 +327,9 @@ class TinyGsmBG96 | ||||
|  | ||||
|     if (waitResponse(timeout_ms, GF(GSM_NL "+QIOPEN:")) != 1) { return false; } | ||||
|  | ||||
|     if (stream.readStringUntil(',').toInt() != mux) { return false; } | ||||
|     if (streamGetInt(',') != mux) { return false; } | ||||
|     // Read status | ||||
|     rsp = stream.readStringUntil('\n').toInt(); | ||||
|     rsp = streamGetInt('\n'); | ||||
|  | ||||
|     return (0 == rsp); | ||||
|   } | ||||
| @@ -347,7 +347,7 @@ class TinyGsmBG96 | ||||
|   size_t modemRead(size_t size, uint8_t mux) { | ||||
|     sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); | ||||
|     if (waitResponse(GF("+QIRD:")) != 1) { return 0; } | ||||
|     int len = stream.readStringUntil('\n').toInt(); | ||||
|     int len = streamGetInt('\n'); | ||||
|  | ||||
|     for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } | ||||
|     waitResponse(); | ||||
| @@ -362,7 +362,7 @@ class TinyGsmBG96 | ||||
|     if (waitResponse(GF("+QIRD:")) == 1) { | ||||
|       streamSkipUntil(',');  // Skip total received | ||||
|       streamSkipUntil(',');  // Skip have read | ||||
|       result = stream.readStringUntil('\n').toInt(); | ||||
|       result = streamGetInt('\n'); | ||||
|       if (result) { DBG("### DATA AVAILABLE:", result, "on", mux); } | ||||
|       waitResponse(); | ||||
|     } | ||||
| @@ -381,7 +381,7 @@ class TinyGsmBG96 | ||||
|     streamSkipUntil(',');         // Skip remote ip | ||||
|     streamSkipUntil(',');         // Skip remote port | ||||
|     streamSkipUntil(',');         // Skip local port | ||||
|     int res = stream.readStringUntil(',').toInt();  // socket state | ||||
|     int res = streamGetInt(',');  // socket state | ||||
|  | ||||
|     waitResponse(); | ||||
|  | ||||
| @@ -434,23 +434,23 @@ class TinyGsmBG96 | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF(GSM_NL "+QIURC:"))) { | ||||
|           stream.readStringUntil('\"'); | ||||
|           streamSkipUntil('\"'); | ||||
|           String urc = stream.readStringUntil('\"'); | ||||
|           stream.readStringUntil(','); | ||||
|           streamSkipUntil(','); | ||||
|           if (urc == "recv") { | ||||
|             int mux = stream.readStringUntil('\n').toInt(); | ||||
|             int mux = streamGetInt('\n'); | ||||
|             DBG("### URC RECV:", mux); | ||||
|             if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|               sockets[mux]->got_data = true; | ||||
|             } | ||||
|           } else if (urc == "closed") { | ||||
|             int mux = stream.readStringUntil('\n').toInt(); | ||||
|             int mux = streamGetInt('\n'); | ||||
|             DBG("### URC CLOSE:", mux); | ||||
|             if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|               sockets[mux]->sock_connected = false; | ||||
|             } | ||||
|           } else { | ||||
|             stream.readStringUntil('\n'); | ||||
|             streamSkipUntil('\n'); | ||||
|           } | ||||
|           data = ""; | ||||
|         } | ||||
|   | ||||
| @@ -396,7 +396,7 @@ class TinyGsmESP8266 | ||||
|       uint8_t has_status = waitResponse(GF("+CIPSTATUS:"), GFP(GSM_OK), | ||||
|                                         GFP(GSM_ERROR)); | ||||
|       if (has_status == 1) { | ||||
|         int returned_mux = stream.readStringUntil(',').toInt(); | ||||
|         int returned_mux = streamGetInt(','); | ||||
|         streamSkipUntil(',');   // Skip mux | ||||
|         streamSkipUntil(',');   // Skip type | ||||
|         streamSkipUntil(',');   // Skip remote IP | ||||
| @@ -454,8 +454,8 @@ class TinyGsmESP8266 | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF("+IPD,"))) { | ||||
|           int mux      = stream.readStringUntil(',').toInt(); | ||||
|           int len      = stream.readStringUntil(':').toInt(); | ||||
|           int mux      = streamGetInt(','); | ||||
|           int len      = streamGetInt(':'); | ||||
|           int len_orig = len; | ||||
|           if (len > sockets[mux]->rx.free()) { | ||||
|             DBG("### Buffer overflow: ", len, "received vs", | ||||
|   | ||||
| @@ -261,7 +261,7 @@ class TinyGsmM590 | ||||
|   bool isGprsConnectedImpl() { | ||||
|     sendAT(GF("+XIIC?")); | ||||
|     if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return false; } | ||||
|     int res = stream.readStringUntil(',').toInt(); | ||||
|     int res = streamGetInt(','); | ||||
|     waitResponse(); | ||||
|     return res == 1; | ||||
|   } | ||||
| @@ -273,7 +273,7 @@ class TinyGsmM590 | ||||
|   String getLocalIPImpl() { | ||||
|     sendAT(GF("+XIIC?")); | ||||
|     if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return ""; } | ||||
|     stream.readStringUntil(','); | ||||
|     streamSkipUntil(','); | ||||
|     String res = stream.readStringUntil('\n'); | ||||
|     waitResponse(); | ||||
|     res.trim(); | ||||
| @@ -356,7 +356,7 @@ class TinyGsmM590 | ||||
|     stream.write(static_cast<char>(0x0D)); | ||||
|     stream.flush(); | ||||
|     if (waitResponse(30000L, GF(GSM_NL "+TCPSEND:")) != 1) { return 0; } | ||||
|     stream.readStringUntil('\n'); | ||||
|     streamSkipUntil('\n'); | ||||
|     return len; | ||||
|   } | ||||
|  | ||||
| @@ -429,8 +429,8 @@ class TinyGsmM590 | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF("+TCPRECV:"))) { | ||||
|           int mux      = stream.readStringUntil(',').toInt(); | ||||
|           int len      = stream.readStringUntil(',').toInt(); | ||||
|           int mux      = streamGetInt(','); | ||||
|           int len      = streamGetInt(','); | ||||
|           int len_orig = len; | ||||
|           if (len > sockets[mux]->rx.free()) { | ||||
|             DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free()); | ||||
| @@ -445,8 +445,8 @@ class TinyGsmM590 | ||||
|           } | ||||
|           data = ""; | ||||
|         } else if (data.endsWith(GF("+TCPCLOSE:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           stream.readStringUntil('\n'); | ||||
|           int mux = streamGetInt(','); | ||||
|           streamSkipUntil('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT) { | ||||
|             sockets[mux]->sock_connected = false; | ||||
|           } | ||||
|   | ||||
| @@ -339,7 +339,7 @@ class TinyGsmM95 | ||||
|  protected: | ||||
|   String getLocalIPImpl() { | ||||
|     sendAT(GF("+QILOCIP")); | ||||
|     stream.readStringUntil('\n'); | ||||
|     streamSkipUntil('\n'); | ||||
|     String res = stream.readStringUntil('\n'); | ||||
|     res.trim(); | ||||
|     return res; | ||||
| @@ -396,9 +396,9 @@ class TinyGsmM95 | ||||
|     } | ||||
|     streamSkipUntil(',');  // Skip mode | ||||
|     // Read charge of thermistor | ||||
|     // milliVolts = stream.readStringUntil(',').toInt(); | ||||
|     // milliVolts = streamGetInt(','); | ||||
|     streamSkipUntil(',');  // Skip thermistor charge | ||||
|     float temp = stream.readStringUntil('\n').toFloat(); | ||||
|     float temp = streamGetFloat('\n'); | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
|     return temp; | ||||
| @@ -437,7 +437,7 @@ class TinyGsmM95 | ||||
|     //     streamSkipUntil(',');  // Skip total length sent on connection | ||||
|     //     streamSkipUntil(',');  // Skip length already acknowledged by remote | ||||
|     //     // Make sure the total length un-acknowledged is 0 | ||||
|     //     if ( stream.readStringUntil('\n').toInt() == 0 ) { | ||||
|     //     if ( streamGetInt('\n') == 0 ) { | ||||
|     //       allAcknowledged = true; | ||||
|     //     } | ||||
|     //   } | ||||
| @@ -463,7 +463,7 @@ class TinyGsmM95 | ||||
|       streamSkipUntil(',');  // skip port | ||||
|       streamSkipUntil(',');  // skip connection type (TCP/UDP) | ||||
|       // read the real length of the retrieved data | ||||
|       uint16_t len = stream.readStringUntil('\n').toInt(); | ||||
|       uint16_t len = streamGetInt('\n'); | ||||
|       // We have no way of knowing in advance how much data will be in the | ||||
|       // buffer so when data is received we always assume the buffer is | ||||
|       // completely full. Chances are, this is not true and there's really not | ||||
| @@ -500,7 +500,7 @@ class TinyGsmM95 | ||||
|     streamSkipUntil(',');         // Skip remote ip | ||||
|     streamSkipUntil(',');         // Skip remote port | ||||
|     streamSkipUntil(',');         // Skip local port | ||||
|     int res = stream.readStringUntil(',').toInt();  // socket state | ||||
|     int res = streamGetInt(',');  // socket state | ||||
|  | ||||
|     waitResponse(); | ||||
|  | ||||
| @@ -555,7 +555,7 @@ class TinyGsmM95 | ||||
|         } else if (data.endsWith(GF(GSM_NL "+QIRDI:"))) { | ||||
|           streamSkipUntil(',');  // Skip the context | ||||
|           streamSkipUntil(',');  // Skip the role | ||||
|           int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt('\n'); | ||||
|           DBG("### Got Data:", mux); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             // We have no way of knowing how much data actually came in, so | ||||
|   | ||||
| @@ -331,7 +331,7 @@ class TinyGsmMC60 | ||||
|  protected: | ||||
|   String getLocalIPImpl() { | ||||
|     sendAT(GF("+QILOCIP")); | ||||
|     stream.readStringUntil('\n'); | ||||
|     streamSkipUntil('\n'); | ||||
|     String res = stream.readStringUntil('\n'); | ||||
|     res.trim(); | ||||
|     return res; | ||||
| @@ -415,15 +415,13 @@ class TinyGsmMC60 | ||||
|       } else { | ||||
|         streamSkipUntil(','); /** Skip total */ | ||||
|         streamSkipUntil(','); /** Skip acknowledged data size */ | ||||
|         if (stream.readStringUntil('\n').toInt() == 0) { | ||||
|           allAcknowledged = true; | ||||
|         } | ||||
|         if (streamGetInt('\n') == 0) { allAcknowledged = true; } | ||||
|       } | ||||
|     } | ||||
|     waitResponse(5000L); | ||||
|  | ||||
|     // streamSkipUntil(','); // Skip mux | ||||
|     // return stream.readStringUntil('\n').toInt(); | ||||
|     // return streamGetInt('\n'); | ||||
|  | ||||
|     return len;  // TODO(?): verify len/ack | ||||
|   } | ||||
| @@ -444,7 +442,7 @@ class TinyGsmMC60 | ||||
|       streamSkipUntil(',');  // skip port | ||||
|       streamSkipUntil(',');  // skip connection type (TCP/UDP) | ||||
|       // read the real length of the retrieved data | ||||
|       uint16_t len = stream.readStringUntil('\n').toInt(); | ||||
|       uint16_t len = streamGetInt('\n'); | ||||
|       // 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. | ||||
| @@ -480,7 +478,7 @@ class TinyGsmMC60 | ||||
|     streamSkipUntil(',');         // Skip remote ip | ||||
|     streamSkipUntil(',');         // Skip remote port | ||||
|     streamSkipUntil(',');         // Skip local port | ||||
|     int res = stream.readStringUntil(',').toInt();  // socket state | ||||
|     int res = streamGetInt(',');  // socket state | ||||
|  | ||||
|     waitResponse(); | ||||
|  | ||||
| @@ -543,11 +541,11 @@ class TinyGsmMC60 | ||||
|           streamSkipUntil(',');  // Skip the context | ||||
|           streamSkipUntil(',');  // Skip the role | ||||
|           // read the connection id | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           // read the number of packets in the buffer | ||||
|           int num_packets = stream.readStringUntil(',').toInt(); | ||||
|           int num_packets = streamGetInt(','); | ||||
|           // read the length of the current packet | ||||
|           int len_packet = stream.readStringUntil('\n').toInt(); | ||||
|           int len_packet = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->sock_available = len_packet * num_packets; | ||||
|           } | ||||
|   | ||||
| @@ -445,7 +445,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
|     streamSkipUntil(',');  // Skip battery charge status | ||||
|     streamSkipUntil(',');  // Skip battery charge level | ||||
|     // get voltage in VOLTS | ||||
|     float voltage = stream.readStringUntil('\n').toFloat(); | ||||
|     float voltage = streamGetFloat('\n'); | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
|     // Return millivolts | ||||
| @@ -458,10 +458,10 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
|                         uint16_t& milliVolts) { | ||||
|     sendAT(GF("+CBC")); | ||||
|     if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; } | ||||
|     chargeState = stream.readStringUntil(',').toInt(); | ||||
|     percent     = stream.readStringUntil(',').toInt(); | ||||
|     chargeState = streamGetInt(','); | ||||
|     percent     = streamGetInt(','); | ||||
|     // get voltage in VOLTS | ||||
|     float voltage = stream.readStringUntil('\n').toFloat(); | ||||
|     float voltage = streamGetFloat('\n'); | ||||
|     milliVolts    = voltage * 1000; | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
| @@ -476,7 +476,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
|     // Get Temparature Value | ||||
|     sendAT(GF("+CMTE?")); | ||||
|     if (waitResponse(GF(GSM_NL "+CMTE:")) != 1) { return false; } | ||||
|     float res = stream.readStringUntil('\n').toFloat(); | ||||
|     float res = streamGetFloat('\n'); | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
|     return res; | ||||
| @@ -511,7 +511,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     streamSkipUntil(',');  // Skip requested bytes to send | ||||
|     // TODO(?):  make sure requested and confirmed bytes match | ||||
|     return stream.readStringUntil('\n').toInt(); | ||||
|     return streamGetInt('\n'); | ||||
|   } | ||||
|  | ||||
|   size_t modemRead(size_t size, uint8_t mux) { | ||||
| @@ -524,9 +524,9 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
| #endif | ||||
|     streamSkipUntil(',');  // Skip Rx mode 2/normal or 3/HEX | ||||
|     streamSkipUntil(',');  // Skip mux/cid (connecion id) | ||||
|     int len_requested = stream.readStringUntil(',').toInt(); | ||||
|     int len_requested = streamGetInt(','); | ||||
|     //  ^^ Requested number of data bytes (1-1460 bytes)to be read | ||||
|     int len_confirmed = stream.readStringUntil('\n').toInt(); | ||||
|     int len_confirmed = streamGetInt('\n'); | ||||
|     // ^^ The data length which not read in the buffer | ||||
|     for (int i = 0; i < len_requested; i++) { | ||||
|       uint32_t startMillis = millis(); | ||||
| @@ -563,7 +563,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
|     if (waitResponse(GF("+CIPRXGET:")) == 1) { | ||||
|       streamSkipUntil(',');  // Skip mode 4 | ||||
|       streamSkipUntil(',');  // Skip mux | ||||
|       result = stream.readStringUntil('\n').toInt(); | ||||
|       result = streamGetInt('\n'); | ||||
|       waitResponse(); | ||||
|     } | ||||
|     DBG("### Available:", result, "on", mux); | ||||
| @@ -628,9 +628,9 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { | ||||
|           String mode = stream.readStringUntil(','); | ||||
|           if (mode.toInt() == 1) { | ||||
|             int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mode = streamGetInt(','); | ||||
|           if (mode == 1) { | ||||
|             int mux = streamGetInt('\n'); | ||||
|             if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|               sockets[mux]->got_data = true; | ||||
|             } | ||||
| @@ -640,8 +640,8 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
|             data += mode; | ||||
|           } | ||||
|         } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int len = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           int len = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->got_data       = true; | ||||
|             sockets[mux]->sock_available = len; | ||||
| @@ -649,7 +649,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360, READ_AND_CHECK_SIZE, | ||||
|           data = ""; | ||||
|           DBG("### Got Data:", len, "on", mux); | ||||
|         } else if (data.endsWith(GF("+IPCLOSE:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           streamSkipUntil('\n');  // Skip the reason code | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->sock_connected = false; | ||||
|   | ||||
| @@ -436,25 +436,27 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE, | ||||
|     sendAT(GF("+CGNSINF")); | ||||
|     if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) { return false; } | ||||
|  | ||||
|     stream.readStringUntil(',');  // mode | ||||
|     if (stream.readStringUntil(',').toInt() == 1) fix = true; | ||||
|     stream.readStringUntil(',');                                    // utctime | ||||
|     *lat = stream.readStringUntil(',').toFloat();                   // lat | ||||
|     *lon = stream.readStringUntil(',').toFloat();                   // lon | ||||
|     if (alt != NULL) *alt = stream.readStringUntil(',').toFloat();  // lon | ||||
|     if (speed != NULL) *speed = stream.readStringUntil(',').toFloat();  // speed | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     if (vsat != NULL) | ||||
|       *vsat = stream.readStringUntil(',').toInt();  // viewed satelites | ||||
|     if (usat != NULL) | ||||
|       *usat = stream.readStringUntil(',').toInt();  // used satelites | ||||
|     stream.readStringUntil('\n'); | ||||
|     streamSkipUntil(',');                             // GNSS run status | ||||
|     if (streamGetInt(',') == 1) fix = true;           // fix status | ||||
|     streamSkipUntil(',');                             // UTC date & Time | ||||
|     *lat = streamGetFloat(',');                       // Latitude | ||||
|     *lon = streamGetFloat(',');                       // Longitude | ||||
|     if (alt != NULL) *alt = streamGetFloat(',');      // MSL Altitude | ||||
|     if (speed != NULL) *speed = streamGetFloat(',');  // Speed Over Ground | ||||
|     streamSkipUntil(',');                             // Course Over Ground | ||||
|     streamSkipUntil(',');                             // Fix Mode | ||||
|     streamSkipUntil(',');                             // Reserved1 | ||||
|     streamSkipUntil(',');  // Horizontal Dilution Of Precision | ||||
|     streamSkipUntil(',');  // Position Dilution Of Precision | ||||
|     streamSkipUntil(',');  // Vertical Dilution Of Precision | ||||
|     streamSkipUntil(',');  // Reserved2 | ||||
|     if (vsat != NULL) *vsat = streamGetInt(',');  // GNSS Satellites in View | ||||
|     if (usat != NULL) *usat = streamGetInt(',');  // GNSS Satellites Used | ||||
|     streamSkipUntil(',');                         // GLONASS Satellites Used | ||||
|     streamSkipUntil(',');                         // Reserved3 | ||||
|     streamSkipUntil(',');                         // C/N0 max | ||||
|     streamSkipUntil(',');                         // HPA | ||||
|     streamSkipUntil('\n');                        // VPA | ||||
|  | ||||
|     waitResponse(); | ||||
|  | ||||
| @@ -499,7 +501,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE, | ||||
|           break; | ||||
|       } | ||||
|     } | ||||
|     stream.readStringUntil('\n'); | ||||
|     streamSkipUntil('\n'); | ||||
|     waitResponse(); | ||||
|  | ||||
|     if (fix) { | ||||
| @@ -541,7 +543,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE, | ||||
|     stream.flush(); | ||||
|     if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) { return 0; } | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     return stream.readStringUntil('\n').toInt(); | ||||
|     return streamGetInt('\n'); | ||||
|   } | ||||
|  | ||||
|   size_t modemRead(size_t size, uint8_t mux) { | ||||
| @@ -554,9 +556,9 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE, | ||||
| #endif | ||||
|     streamSkipUntil(',');  // Skip Rx mode 2/normal or 3/HEX | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     int len_requested = stream.readStringUntil(',').toInt(); | ||||
|     int len_requested = streamGetInt(','); | ||||
|     //  ^^ Requested number of data bytes (1-1460 bytes)to be read | ||||
|     int len_confirmed = stream.readStringUntil('\n').toInt(); | ||||
|     int len_confirmed = streamGetInt('\n'); | ||||
|     // ^^ Confirmed number of data bytes to be read, which may be less than | ||||
|     // requested. 0 indicates that no data can be read. This is actually be the | ||||
|     // number of bytes that will be remaining after the read | ||||
| @@ -595,7 +597,7 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE, | ||||
|     if (waitResponse(GF("+CIPRXGET:")) == 1) { | ||||
|       streamSkipUntil(',');  // Skip mode 4 | ||||
|       streamSkipUntil(',');  // Skip mux | ||||
|       result = stream.readStringUntil('\n').toInt(); | ||||
|       result = streamGetInt('\n'); | ||||
|       waitResponse(); | ||||
|     } | ||||
|     DBG("### Available:", result, "on", mux); | ||||
| @@ -656,9 +658,9 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE, | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { | ||||
|           String mode = stream.readStringUntil(','); | ||||
|           if (mode.toInt() == 1) { | ||||
|             int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mode = streamGetInt(','); | ||||
|           if (mode == 1) { | ||||
|             int mux = streamGetInt('\n'); | ||||
|             if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|               sockets[mux]->got_data = true; | ||||
|             } | ||||
| @@ -668,8 +670,8 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000, READ_AND_CHECK_SIZE, | ||||
|             data += mode; | ||||
|           } | ||||
|         } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int len = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           int len = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->got_data       = true; | ||||
|             sockets[mux]->sock_available = len; | ||||
|   | ||||
| @@ -410,25 +410,28 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
|     sendAT(GF("+CGNSSINFO")); | ||||
|     if (waitResponse(GF(GSM_NL "+CGNSSINFO:")) != 1) { return false; } | ||||
|  | ||||
|     // stream.readStringUntil(','); // mode | ||||
|     if (stream.readStringUntil(',').toInt() == 1) fix = true; | ||||
|     stream.readStringUntil(',');                                    // gps | ||||
|     stream.readStringUntil(',');                                    // glonass | ||||
|     stream.readStringUntil(',');                                    // beidu | ||||
|     *lat = stream.readStringUntil(',').toFloat();                   // lat | ||||
|     stream.readStringUntil(',');                                    // N/S | ||||
|     *lon = stream.readStringUntil(',').toFloat();                   // lon | ||||
|     stream.readStringUntil(',');                                    // E/W | ||||
|     stream.readStringUntil(',');                                    // date | ||||
|     stream.readStringUntil(',');                                    // UTC time | ||||
|     if (alt != NULL) *alt = stream.readStringUntil(',').toFloat();  // alt | ||||
|     if (speed != NULL) *speed = stream.readStringUntil(',').toFloat();  // speed | ||||
|     stream.readStringUntil(',');  // course | ||||
|     stream.readStringUntil(',');  // time | ||||
|     stream.readStringUntil(',');  // PDOP | ||||
|     stream.readStringUntil(',');  // HDOP | ||||
|     stream.readStringUntil(',');  // VDOP | ||||
|     stream.readStringUntil('\n'); | ||||
|     // streamSkipUntil(','); // mode | ||||
|     if (streamGetInt(',') == 1) | ||||
|       fix = true;          // TODO(?) Shouldn't this be 2=2D Fix or 3=3DFix? | ||||
|     streamSkipUntil(',');  // GPS satellite valid numbers | ||||
|     streamSkipUntil(',');  // GLONASS satellite valid numbers | ||||
|     streamSkipUntil(',');  // BEIDOU satellite valid numbers | ||||
|     *lat = streamGetFloat(',');  // Latitude | ||||
|     streamSkipUntil(',');        // N/S Indicator, N=north or S=south | ||||
|     *lon = streamGetFloat(',');  // Longitude | ||||
|     streamSkipUntil(',');        // E/W Indicator, E=east or W=west | ||||
|     streamSkipUntil(',');        // Date. Output format is ddmmyy | ||||
|     streamSkipUntil(',');        // UTC Time. Output format is hhmmss.s | ||||
|     if (alt != NULL) | ||||
|       *alt = streamGetFloat(',');  // MSL Altitude. Unit is meters | ||||
|     if (speed != NULL) | ||||
|       *speed = streamGetFloat(',');  // Speed Over Ground. Unit is knots. | ||||
|     streamSkipUntil(',');            // Course. Degrees. | ||||
|     streamSkipUntil(',');   // After set, will report GPS every x seconds | ||||
|     streamSkipUntil(',');   // Position Dilution Of Precision | ||||
|     streamSkipUntil(',');   // Horizontal Dilution Of Precision | ||||
|     streamSkipUntil(',');   // Vertical Dilution Of Precision | ||||
|     streamSkipUntil('\n');  // TODO(?) is one more field reported?? | ||||
|  | ||||
|     waitResponse(); | ||||
|  | ||||
| @@ -451,7 +454,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
|     if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return 0; } | ||||
|  | ||||
|     // get voltage in VOLTS | ||||
|     float voltage = stream.readStringUntil('\n').toFloat(); | ||||
|     float voltage = streamGetFloat('\n'); | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
|     // Return millivolts | ||||
| @@ -476,7 +479,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
|     sendAT(GF("+CPMUTEMP")); | ||||
|     if (waitResponse(GF(GSM_NL "+CPMUTEMP:")) != 1) { return 0; } | ||||
|     // return temperature in C | ||||
|     uint16_t res = stream.readStringUntil('\n').toInt(); | ||||
|     uint16_t res = streamGetInt('\n'); | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
|     return res; | ||||
| @@ -511,7 +514,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     streamSkipUntil(',');  // Skip requested bytes to send | ||||
|     // TODO(?):  make sure requested and confirmed bytes match | ||||
|     return stream.readStringUntil('\n').toInt(); | ||||
|     return streamGetInt('\n'); | ||||
|   } | ||||
|  | ||||
|   size_t modemRead(size_t size, uint8_t mux) { | ||||
| @@ -524,9 +527,9 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
| #endif | ||||
|     streamSkipUntil(',');  // Skip Rx mode 2/normal or 3/HEX | ||||
|     streamSkipUntil(',');  // Skip mux/cid (connecion id) | ||||
|     int len_requested = stream.readStringUntil(',').toInt(); | ||||
|     int len_requested = streamGetInt(','); | ||||
|     //  ^^ Requested number of data bytes (1-1460 bytes)to be read | ||||
|     int len_confirmed = stream.readStringUntil('\n').toInt(); | ||||
|     int len_confirmed = streamGetInt('\n'); | ||||
|     // ^^ The data length which not read in the buffer | ||||
|     for (int i = 0; i < len_requested; i++) { | ||||
|       uint32_t startMillis = millis(); | ||||
| @@ -563,7 +566,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
|     if (waitResponse(GF("+CIPRXGET:")) == 1) { | ||||
|       streamSkipUntil(',');  // Skip mode 4 | ||||
|       streamSkipUntil(',');  // Skip mux | ||||
|       result = stream.readStringUntil('\n').toInt(); | ||||
|       result = streamGetInt('\n'); | ||||
|       waitResponse(); | ||||
|     } | ||||
|     DBG("### Available:", result, "on", mux); | ||||
| @@ -630,9 +633,9 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { | ||||
|           String mode = stream.readStringUntil(','); | ||||
|           if (mode.toInt() == 1) { | ||||
|             int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mode = streamGetInt(','); | ||||
|           if (mode == 1) { | ||||
|             int mux = streamGetInt('\n'); | ||||
|             if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|               sockets[mux]->got_data = true; | ||||
|             } | ||||
| @@ -642,8 +645,8 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
|             data += mode; | ||||
|           } | ||||
|         } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int len = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           int len = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->got_data       = true; | ||||
|             sockets[mux]->sock_available = len; | ||||
| @@ -651,7 +654,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600, READ_AND_CHECK_SIZE, | ||||
|           data = ""; | ||||
|           DBG("### Got Data:", len, "on", mux); | ||||
|         } else if (data.endsWith(GF("+IPCLOSE:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           streamSkipUntil('\n');  // Skip the reason code | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->sock_connected = false; | ||||
|   | ||||
| @@ -490,7 +490,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE, | ||||
|     stream.flush(); | ||||
|     if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) { return 0; } | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     return stream.readStringUntil('\n').toInt(); | ||||
|     return streamGetInt('\n'); | ||||
|   } | ||||
|  | ||||
|   size_t modemRead(size_t size, uint8_t mux) { | ||||
| @@ -503,9 +503,9 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE, | ||||
| #endif | ||||
|     streamSkipUntil(',');  // Skip Rx mode 2/normal or 3/HEX | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     int len_requested = stream.readStringUntil(',').toInt(); | ||||
|     int len_requested = streamGetInt(','); | ||||
|     //  ^^ Requested number of data bytes (1-1460 bytes)to be read | ||||
|     int len_confirmed = stream.readStringUntil('\n').toInt(); | ||||
|     int len_confirmed = streamGetInt('\n'); | ||||
|     // ^^ Confirmed number of data bytes to be read, which may be less than | ||||
|     // requested. 0 indicates that no data can be read. This is actually be the | ||||
|     // number of bytes that will be remaining after the read | ||||
| @@ -544,7 +544,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE, | ||||
|     if (waitResponse(GF("+CIPRXGET:")) == 1) { | ||||
|       streamSkipUntil(',');  // Skip mode 4 | ||||
|       streamSkipUntil(',');  // Skip mux | ||||
|       result = stream.readStringUntil('\n').toInt(); | ||||
|       result = streamGetInt('\n'); | ||||
|       waitResponse(); | ||||
|     } | ||||
|     DBG("### Available:", result, "on", mux); | ||||
| @@ -607,9 +607,9 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE, | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) { | ||||
|           String mode = stream.readStringUntil(','); | ||||
|           if (mode.toInt() == 1) { | ||||
|             int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mode = streamGetInt(','); | ||||
|           if (mode == 1) { | ||||
|             int mux = streamGetInt('\n'); | ||||
|             if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|               sockets[mux]->got_data = true; | ||||
|             } | ||||
| @@ -619,8 +619,8 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800, READ_AND_CHECK_SIZE, | ||||
|             data += mode; | ||||
|           } | ||||
|         } else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int len = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           int len = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->got_data       = true; | ||||
|             sockets[mux]->sock_available = len; | ||||
|   | ||||
| @@ -61,25 +61,27 @@ class TinyGsmSim808 : public TinyGsmSim800 { | ||||
|     sendAT(GF("+CGNSINF")); | ||||
|     if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) { return false; } | ||||
|  | ||||
|     stream.readStringUntil(',');  // mode | ||||
|     if (stream.readStringUntil(',').toInt() == 1) fix = true; | ||||
|     stream.readStringUntil(',');                                    // utctime | ||||
|     *lat = stream.readStringUntil(',').toFloat();                   // lat | ||||
|     *lon = stream.readStringUntil(',').toFloat();                   // lon | ||||
|     if (alt != NULL) *alt = stream.readStringUntil(',').toFloat();  // lon | ||||
|     if (speed != NULL) *speed = stream.readStringUntil(',').toFloat();  // speed | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     stream.readStringUntil(','); | ||||
|     if (vsat != NULL) | ||||
|       *vsat = stream.readStringUntil(',').toInt();  // viewed satelites | ||||
|     if (usat != NULL) | ||||
|       *usat = stream.readStringUntil(',').toInt();  // used satelites | ||||
|     stream.readStringUntil('\n'); | ||||
|     streamSkipUntil(',');                             // GNSS run status | ||||
|     if (streamGetInt(',') == 1) fix = true;           // fix status | ||||
|     streamSkipUntil(',');                             // UTC date & Time | ||||
|     *lat = streamGetFloat(',');                       // Latitude | ||||
|     *lon = streamGetFloat(',');                       // Longitude | ||||
|     if (alt != NULL) *alt = streamGetFloat(',');      // MSL Altitude | ||||
|     if (speed != NULL) *speed = streamGetFloat(',');  // Speed Over Ground | ||||
|     streamSkipUntil(',');                             // Course Over Ground | ||||
|     streamSkipUntil(',');                             // Fix Mode | ||||
|     streamSkipUntil(',');                             // Reserved1 | ||||
|     streamSkipUntil(',');  // Horizontal Dilution Of Precision | ||||
|     streamSkipUntil(',');  // Position Dilution Of Precision | ||||
|     streamSkipUntil(',');  // Vertical Dilution Of Precision | ||||
|     streamSkipUntil(',');  // Reserved2 | ||||
|     if (vsat != NULL) *vsat = streamGetInt(',');  // GNSS Satellites in View | ||||
|     if (usat != NULL) *usat = streamGetInt(',');  // GNSS Satellites Used | ||||
|     streamSkipUntil(',');                         // GLONASS Satellites Used | ||||
|     streamSkipUntil(',');                         // Reserved3 | ||||
|     streamSkipUntil(',');                         // C/N0 max | ||||
|     streamSkipUntil(',');                         // HPA | ||||
|     streamSkipUntil('\n');                        // VPA | ||||
|  | ||||
|     waitResponse(); | ||||
|  | ||||
| @@ -121,7 +123,7 @@ class TinyGsmSim808 : public TinyGsmSim800 { | ||||
|           break; | ||||
|       } | ||||
|     } | ||||
|     stream.readStringUntil('\n'); | ||||
|     streamSkipUntil('\n'); | ||||
|     waitResponse(); | ||||
|  | ||||
|     if (fix) { | ||||
|   | ||||
| @@ -304,7 +304,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|     sendAT(GF("+CEREG?")); | ||||
|     if (waitResponse(GF(GSM_NL "+CEREG:")) != 1) { return REG_UNKNOWN; } | ||||
|     streamSkipUntil(','); /* Skip format (0) */ | ||||
|     int status = stream.readStringUntil('\n').toInt(); | ||||
|     int status = streamGetInt('\n'); | ||||
|     waitResponse(); | ||||
|  | ||||
|     // If we're connected on EPS, great! | ||||
| @@ -316,7 +316,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|       sendAT(GF("+CREG?")); | ||||
|       if (waitResponse(GF(GSM_NL "+CREG:")) != 1) { return REG_UNKNOWN; } | ||||
|       streamSkipUntil(','); /* Skip format (0) */ | ||||
|       status = stream.readStringUntil('\n').toInt(); | ||||
|       status = streamGetInt('\n'); | ||||
|       waitResponse(); | ||||
|       return (RegStatus)status; | ||||
|     } | ||||
| @@ -453,7 +453,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|     sendAT(GF("+CIND?")); | ||||
|     if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; } | ||||
|  | ||||
|     int    res     = stream.readStringUntil(',').toInt(); | ||||
|     int    res     = streamGetInt(','); | ||||
|     int8_t percent = res * 20;  // return is 0-5 | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
| @@ -478,7 +478,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|     if (waitResponse(GF(GSM_NL "+UTEMP:")) != 1) { | ||||
|       return static_cast<float>(-9999); | ||||
|     } | ||||
|     int16_t res  = stream.readStringUntil('\n').toInt(); | ||||
|     int16_t res  = streamGetInt('\n'); | ||||
|     float   temp = -9999; | ||||
|     if (res != -1) { temp = (static_cast<float>(res)) / 10; } | ||||
|     return temp; | ||||
| @@ -497,7 +497,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|     sendAT(GF("+USOCR=6")); | ||||
|     // reply is +USOCR: ## of socket created | ||||
|     if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { return false; } | ||||
|     *mux = stream.readStringUntil('\n').toInt(); | ||||
|     *mux = streamGetInt('\n'); | ||||
|     waitResponse(); | ||||
|  | ||||
|     if (ssl) { | ||||
| @@ -531,8 +531,8 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|       sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port, ",1"); | ||||
|       if (waitResponse(timeout_ms - (millis() - startMillis), | ||||
|                        GF(GSM_NL "+UUSOCO:")) == 1) { | ||||
|         stream.readStringUntil(',').toInt();  // skip repeated mux | ||||
|         int connection_status = stream.readStringUntil('\n').toInt(); | ||||
|         streamGetInt(',');  // skip repeated mux | ||||
|         int connection_status = streamGetInt('\n'); | ||||
|         DBG("### Waited", millis() - startMillis, "ms for socket to open"); | ||||
|         return (0 == connection_status); | ||||
|       } else { | ||||
| @@ -557,7 +557,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|     stream.flush(); | ||||
|     if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; } | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     int sent = stream.readStringUntil('\n').toInt(); | ||||
|     int sent = streamGetInt('\n'); | ||||
|     waitResponse();  // sends back OK after the confirmation of number sent | ||||
|     return sent; | ||||
|   } | ||||
| @@ -566,7 +566,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|     sendAT(GF("+USORD="), mux, ',', (uint16_t)size); | ||||
|     if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     int len = stream.readStringUntil(',').toInt(); | ||||
|     int len = streamGetInt(','); | ||||
|     streamSkipUntil('\"'); | ||||
|  | ||||
|     for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } | ||||
| @@ -586,7 +586,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|     // that you have already told to close | ||||
|     if (res == 1) { | ||||
|       streamSkipUntil(',');  // Skip mux | ||||
|       result = stream.readStringUntil('\n').toInt(); | ||||
|       result = streamGetInt('\n'); | ||||
|       // if (result) DBG("### DATA AVAILABLE:", result, "on", mux); | ||||
|       waitResponse(); | ||||
|     } | ||||
| @@ -603,7 +603,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|  | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     streamSkipUntil(',');  // Skip type | ||||
|     int result = stream.readStringUntil('\n').toInt(); | ||||
|     int result = streamGetInt('\n'); | ||||
|     // 0: the socket is in INACTIVE status (it corresponds to CLOSED status | ||||
|     // defined in RFC793 "TCP Protocol Specification" [112]) | ||||
|     // 1: the socket is in LISTEN status | ||||
| @@ -665,8 +665,8 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF("+UUSORD:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int len = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           int len = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->got_data       = true; | ||||
|             sockets[mux]->sock_available = len; | ||||
| @@ -674,15 +674,15 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4, READ_AND_CHECK_SIZE, | ||||
|           data = ""; | ||||
|           DBG("### URC Data Received:", len, "on", mux); | ||||
|         } else if (data.endsWith(GF("+UUSOCL:"))) { | ||||
|           int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->sock_connected = false; | ||||
|           } | ||||
|           data = ""; | ||||
|           DBG("### URC Sock Closed: ", mux); | ||||
|         } else if (data.endsWith(GF("+UUSOCO:"))) { | ||||
|           int mux          = stream.readStringUntil('\n').toInt(); | ||||
|           int socket_error = stream.readStringUntil('\n').toInt(); | ||||
|           int mux          = streamGetInt('\n'); | ||||
|           int socket_error = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux] && | ||||
|               socket_error == 0) { | ||||
|             sockets[mux]->sock_connected = true; | ||||
|   | ||||
| @@ -517,7 +517,7 @@ class TinyGsmSequansMonarch | ||||
|     sendAT(GF("+SQNSRECV="), mux, ',', (uint16_t)size); | ||||
|     if (waitResponse(GF("+SQNSRECV: ")) != 1) { return 0; } | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     int len = stream.readStringUntil('\n').toInt(); | ||||
|     int len = streamGetInt('\n'); | ||||
|     for (int i = 0; i < len; i++) { | ||||
|       uint32_t startMillis = millis(); | ||||
|       while (!stream.available() && | ||||
| @@ -541,7 +541,7 @@ class TinyGsmSequansMonarch | ||||
|       streamSkipUntil(',');        // Skip mux | ||||
|       streamSkipUntil(',');        // Skip total sent | ||||
|       streamSkipUntil(',');        // Skip total received | ||||
|       result = stream.readStringUntil(',').toInt();  // keep data not yet read | ||||
|       result = streamGetInt(',');  // keep data not yet read | ||||
|       waitResponse(); | ||||
|     } | ||||
|     DBG("### Available:", result, "on", mux); | ||||
| @@ -555,7 +555,7 @@ class TinyGsmSequansMonarch | ||||
|     for (int muxNo = 1; muxNo <= TINY_GSM_MUX_COUNT; muxNo++) { | ||||
|       if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+SQNSS: ")) != 2) { break; } | ||||
|       uint8_t status = 0; | ||||
|       // if (stream.readStringUntil(',').toInt() != muxNo) { // check the mux no | ||||
|       // if (streamGetInt(',') != muxNo) { // check the mux no | ||||
|       //   DBG("### Warning: misaligned mux numbers!"); | ||||
|       // } | ||||
|       streamSkipUntil(',');        // skip mux [use muxNo] | ||||
| @@ -623,8 +623,8 @@ class TinyGsmSequansMonarch | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF(GSM_NL "+SQNSRING:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int len = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           int len = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && | ||||
|               sockets[mux % TINY_GSM_MUX_COUNT]) { | ||||
|             sockets[mux % TINY_GSM_MUX_COUNT]->got_data       = true; | ||||
| @@ -633,7 +633,7 @@ class TinyGsmSequansMonarch | ||||
|           data = ""; | ||||
|           DBG("### URC Data Received:", len, "on", mux); | ||||
|         } else if (data.endsWith(GF("SQNSH: "))) { | ||||
|           int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && | ||||
|               sockets[mux % TINY_GSM_MUX_COUNT]) { | ||||
|             sockets[mux % TINY_GSM_MUX_COUNT]->sock_connected = false; | ||||
|   | ||||
| @@ -398,9 +398,7 @@ class TinyGsmUBLOX | ||||
|     // <accuracy> - Target accuracy in meters (1 - 999999) | ||||
|     sendAT(GF("+ULOC=2,2,0,120,1")); | ||||
|     // wait for first "OK" | ||||
|     if (waitResponse(10000L) != 1) { | ||||
|       return ""; | ||||
|     } | ||||
|     if (waitResponse(10000L) != 1) { return ""; } | ||||
|     // wait for the final result - wait full timeout time | ||||
|     if (waitResponse(120000L, GF(GSM_NL "+UULOC:")) != 1) { return ""; } | ||||
|     String res = stream.readStringUntil('\n'); | ||||
| @@ -431,7 +429,7 @@ class TinyGsmUBLOX | ||||
|     sendAT(GF("+CIND?")); | ||||
|     if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; } | ||||
|  | ||||
|     int    res     = stream.readStringUntil(',').toInt(); | ||||
|     int    res     = streamGetInt(','); | ||||
|     int8_t percent = res * 20;  // return is 0-5 | ||||
|     // Wait for final OK | ||||
|     waitResponse(); | ||||
| @@ -464,7 +462,7 @@ class TinyGsmUBLOX | ||||
|         1) {  // reply is +USOCR: ## of socket created | ||||
|       return false; | ||||
|     } | ||||
|     *mux = stream.readStringUntil('\n').toInt(); | ||||
|     *mux = streamGetInt('\n'); | ||||
|     waitResponse(); | ||||
|  | ||||
|     if (ssl) { | ||||
| @@ -495,7 +493,7 @@ class TinyGsmUBLOX | ||||
|     stream.flush(); | ||||
|     if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; } | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     int sent = stream.readStringUntil('\n').toInt(); | ||||
|     int sent = streamGetInt('\n'); | ||||
|     waitResponse();  // sends back OK after the confirmation of number sent | ||||
|     return sent; | ||||
|   } | ||||
| @@ -504,7 +502,7 @@ class TinyGsmUBLOX | ||||
|     sendAT(GF("+USORD="), mux, ',', (uint16_t)size); | ||||
|     if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; } | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     int len = stream.readStringUntil(',').toInt(); | ||||
|     int len = streamGetInt(','); | ||||
|     streamSkipUntil('\"'); | ||||
|  | ||||
|     for (int i = 0; i < len; i++) { moveCharFromStreamToFifo(mux); } | ||||
| @@ -524,7 +522,7 @@ class TinyGsmUBLOX | ||||
|     // that you have already told to close | ||||
|     if (res == 1) { | ||||
|       streamSkipUntil(',');  // Skip mux | ||||
|       result = stream.readStringUntil('\n').toInt(); | ||||
|       result = streamGetInt('\n'); | ||||
|       // if (result) DBG("### DATA AVAILABLE:", result, "on", mux); | ||||
|       waitResponse(); | ||||
|     } | ||||
| @@ -541,7 +539,7 @@ class TinyGsmUBLOX | ||||
|  | ||||
|     streamSkipUntil(',');  // Skip mux | ||||
|     streamSkipUntil(',');  // Skip type | ||||
|     int result = stream.readStringUntil('\n').toInt(); | ||||
|     int result = streamGetInt('\n'); | ||||
|     // 0: the socket is in INACTIVE status (it corresponds to CLOSED status | ||||
|     // defined in RFC793 "TCP Protocol Specification" [112]) | ||||
|     // 1: the socket is in LISTEN status | ||||
| @@ -603,8 +601,8 @@ class TinyGsmUBLOX | ||||
|           index = 5; | ||||
|           goto finish; | ||||
|         } else if (data.endsWith(GF("+UUSORD:"))) { | ||||
|           int mux = stream.readStringUntil(',').toInt(); | ||||
|           int len = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt(','); | ||||
|           int len = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->got_data       = true; | ||||
|             sockets[mux]->sock_available = len; | ||||
| @@ -612,7 +610,7 @@ class TinyGsmUBLOX | ||||
|           data = ""; | ||||
|           DBG("### URC Data Received:", len, "on", mux); | ||||
|         } else if (data.endsWith(GF("+UUSOCL:"))) { | ||||
|           int mux = stream.readStringUntil('\n').toInt(); | ||||
|           int mux = streamGetInt('\n'); | ||||
|           if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { | ||||
|             sockets[mux]->sock_connected = false; | ||||
|           } | ||||
|   | ||||
| @@ -1212,7 +1212,7 @@ class TinyGsmXBee | ||||
|             //   // read remote ip address | ||||
|             //   String remoted_address = | ||||
|             //       stream.readStringUntil('\r');  // read result | ||||
|             //   stream.readStringUntil('\r');      // final carriage return | ||||
|             //   streamSkipUntil('\r');      // final carriage return | ||||
|             // } | ||||
|           } | ||||
|  | ||||
|   | ||||
| @@ -755,7 +755,7 @@ class TinyGsmModem { | ||||
|                                         GF("+CEREG:")); | ||||
|     if (resp != 1 && resp != 2 && resp != 3) { return -1; } | ||||
|     thisModem().streamSkipUntil(','); /* Skip format (0) */ | ||||
|     int status = thisModem().stream.readStringUntil('\n').toInt(); | ||||
|     int status = thisModem().streamGetInt('\n'); | ||||
|     thisModem().waitResponse(); | ||||
|     return status; | ||||
|   } | ||||
| @@ -772,7 +772,7 @@ class TinyGsmModem { | ||||
|   int16_t getSignalQualityImpl() { | ||||
|     thisModem().sendAT(GF("+CSQ")); | ||||
|     if (thisModem().waitResponse(GF("+CSQ:")) != 1) { return 99; } | ||||
|     int res = thisModem().stream.readStringUntil(',').toInt(); | ||||
|     int res = thisModem().streamGetInt(','); | ||||
|     thisModem().waitResponse(); | ||||
|     return res; | ||||
|   } | ||||
| @@ -785,7 +785,7 @@ class TinyGsmModem { | ||||
|   bool isGprsConnectedImpl() { | ||||
|     thisModem().sendAT(GF("+CGATT?")); | ||||
|     if (thisModem().waitResponse(GF("+CGATT:")) != 1) { return false; } | ||||
|     int res = thisModem().stream.readStringUntil('\n').toInt(); | ||||
|     int res = thisModem().streamGetInt('\n'); | ||||
|     thisModem().waitResponse(); | ||||
|     if (res != 1) { return false; } | ||||
|  | ||||
| @@ -975,7 +975,7 @@ class TinyGsmModem { | ||||
|     thisModem().stream.readStringUntil('"'); | ||||
|     String hex = thisModem().stream.readStringUntil('"'); | ||||
|     thisModem().stream.readStringUntil(','); | ||||
|     int dcs = thisModem().stream.readStringUntil('\n').toInt(); | ||||
|     int dcs = thisModem().streamGetInt('\n'); | ||||
|  | ||||
|     if (dcs == 15) { | ||||
|       return TinyGsmDecodeHex8bit(hex); | ||||
| @@ -1118,7 +1118,7 @@ class TinyGsmModem { | ||||
|     thisModem().streamSkipUntil(',');  // Skip battery charge status | ||||
|     thisModem().streamSkipUntil(',');  // Skip battery charge level | ||||
|     // return voltage in mV | ||||
|     uint16_t res = thisModem().stream.readStringUntil(',').toInt(); | ||||
|     uint16_t res = thisModem().streamGetInt(','); | ||||
|     // Wait for final OK | ||||
|     thisModem().waitResponse(); | ||||
|     return res; | ||||
| @@ -1129,7 +1129,7 @@ class TinyGsmModem { | ||||
|     if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } | ||||
|     thisModem().streamSkipUntil(',');  // Skip battery charge status | ||||
|     // Read battery charge level | ||||
|     int res = thisModem().stream.readStringUntil(',').toInt(); | ||||
|     int res = thisModem().streamGetInt(','); | ||||
|     // Wait for final OK | ||||
|     thisModem().waitResponse(); | ||||
|     return res; | ||||
| @@ -1139,7 +1139,7 @@ class TinyGsmModem { | ||||
|     thisModem().sendAT(GF("+CBC")); | ||||
|     if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } | ||||
|     // Read battery charge status | ||||
|     int res = thisModem().stream.readStringUntil(',').toInt(); | ||||
|     int res = thisModem().streamGetInt(','); | ||||
|     // Wait for final OK | ||||
|     thisModem().waitResponse(); | ||||
|     return res; | ||||
| @@ -1149,9 +1149,9 @@ class TinyGsmModem { | ||||
|                         uint16_t& milliVolts) { | ||||
|     thisModem().sendAT(GF("+CBC")); | ||||
|     if (thisModem().waitResponse(GF("+CBC:")) != 1) { return false; } | ||||
|     chargeState = thisModem().stream.readStringUntil(',').toInt(); | ||||
|     percent     = thisModem().stream.readStringUntil(',').toInt(); | ||||
|     milliVolts  = thisModem().stream.readStringUntil('\n').toInt(); | ||||
|     chargeState = thisModem().streamGetInt(','); | ||||
|     percent     = thisModem().streamGetInt(','); | ||||
|     milliVolts  = thisModem().streamGetInt('\n'); | ||||
|     // Wait for final OK | ||||
|     thisModem().waitResponse(); | ||||
|     return true; | ||||
| @@ -1179,11 +1179,29 @@ class TinyGsmModem { | ||||
|     thisModem().streamWrite(tail...); | ||||
|   } | ||||
|  | ||||
|   // template <typename... Args> void sendAT(Args... cmd) { | ||||
|   //   thisModem().streamWrite("AT", cmd..., thisModem().gsmNL); | ||||
|   //   thisModem().stream.flush(); | ||||
|   //   TINY_GSM_YIELD(); /* DBG("### AT:", cmd...); */ | ||||
|   // } | ||||
|   int16_t streamGetInt(char lastChar) { | ||||
|     char   buf[6]; | ||||
|     size_t bytesRead = thisModem().stream.readBytesUntil( | ||||
|         lastChar, buf, static_cast<size_t>(6)); | ||||
|     if (bytesRead) { | ||||
|       int16_t res = atoi(buf); | ||||
|       return res; | ||||
|     } else { | ||||
|       return -9999; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   float streamGetFloat(char lastChar) { | ||||
|     char   buf[12]; | ||||
|     size_t bytesRead = thisModem().stream.readBytesUntil( | ||||
|         lastChar, buf, static_cast<size_t>(12)); | ||||
|     if (bytesRead) { | ||||
|       float res = atof(buf); | ||||
|       return res; | ||||
|     } else { | ||||
|       return static_cast<float>(-9999); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   bool streamSkipUntil(const char c, const uint32_t timeout_ms = 1000L) { | ||||
|     uint32_t startMillis = millis(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user