Add stop with timeout and implement where applicable

This commit is contained in:
Sara Damiano
2019-06-11 16:00:35 -04:00
parent 0502ee435f
commit 86356f5323
13 changed files with 76 additions and 156 deletions

View File

@@ -275,7 +275,7 @@ String TinyGsmDecodeHex16bit(String &instr) {
}
// Returns the number of characters avaialable in the TinyGSM fifo
// Returns the number of characters available in the TinyGSM fifo
// Assumes the modem chip has no internal fifo
#define TINY_GSM_CLIENT_AVAILABLE_NO_MODEM_FIFO() \
virtual int available() { \
@@ -395,6 +395,24 @@ String TinyGsmDecodeHex16bit(String &instr) {
}
// Read and dump anything remaining in the modem's internal buffer.
// Using this in the client stop() function.
// The socket will appear open in response to connected() even after it
// closes until all data is read from the buffer.
// Doing it this way allows the external mcu to find and get all of the data
// that it wants from the socket even if it was closed externally.
#define TINY_GSM_CLIENT_DUMP_MODEM_BUFFER() \
TINY_GSM_YIELD(); \
rx.clear(); \
at->maintain(); \
unsigned long startMillis = millis(); \
while (sock_available > 0 && (millis() - startMillis < maxWaitMs)) { \
at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux); \
rx.clear(); \
at->maintain(); \
}
// The peek, flush, and connected functions
#define TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED() \
virtual int peek() { return -1; } /* TODO */ \