Simplify using of UnbufferedSerial(Serial), USBCDC, TCP, SMTP, NTP Fork : https://github.com/YSI-LPS/lib_Transmission
Dependents: lib_Transmission_Serial_example 2022_TICE_Electrolyse lib_Transmission_TCP_example
Revision 29:0d321d298d37, committed 2022-01-05
- Comitter:
- YSI
- Date:
- Wed Jan 05 12:48:55 2022 +0000
- Parent:
- 28:24f7e0ddf6f5
- Commit message:
- serial_event out of memory debug.; smtp error retry for ever.
Changed in this revision
lib_Transmission.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/lib_Transmission.cpp Fri Sep 17 08:53:40 2021 +0000 +++ b/lib_Transmission.cpp Wed Jan 05 12:48:55 2022 +0000 @@ -246,17 +246,22 @@ void Transmission::serial_event(void) { - char caractere; + static char buffer[TRANSMISSION_BUFFER_SIZE] = {0}; static uint16_t size = 0; - static char buffer[TRANSMISSION_BUFFER_SIZE] = {0}; + char caractere; _serial->read(&caractere, 1); - if((caractere == '\n') || (size == (TRANSMISSION_BUFFER_SIZE-1))) + if(caractere == '\n') { buffer[size] = '\0'; size = 0; if(_processing) _queue.call(this, &Transmission::preprocessing, buffer, SERIAL_DELIVERY); } - else if((caractere > 31) && (caractere < 127) && (size < (TRANSMISSION_BUFFER_SIZE-1))) buffer[size++] = caractere; + else if((caractere > 31) && (caractere < 127)) + { + if(size >= (TRANSMISSION_BUFFER_SIZE-1)) + for(int i = 0; i < size; i++) buffer[i] = (i < size-1)?buffer[i+1]:caractere; + else buffer[size++] = caractere; + } } Transmission::enum_trans_status Transmission::recv(void) @@ -384,19 +389,17 @@ } eth_error("clientSMTP_close", clientSMTP.close()); } - static int smtp_error = 0; if(from.empty()) return code == "220250250250221"; - else if((code == "220250250250354250221") || (code == "220250250250354")) smtp_error = 0; - else if(smtp_error < 5) + else if((code == "220250250250354250221") || (code == "220250250250354")) return true; + else { - smtp_error++; #if MBED_MAJOR_VERSION > 5 _queue.call_in(60s, this, &Transmission::smtp, mail, from, subject, data, server); #else _queue.call_in(60000, this, &Transmission::smtp, mail, from, subject, data, server); #endif } - return !smtp_error; + return false; } time_t Transmission::ntp(const char* server)