1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Merge pull request #6117 from PurpleAir/master

Improve timeout in Updater.
This commit is contained in:
Develo 2021-04-04 22:21:10 -04:00 committed by GitHub
commit bde6ab1df2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,7 @@
#include "Updater.h" #include "Updater.h"
#include "eboot_command.h" #include "eboot_command.h"
#include <esp8266_peri.h> #include <esp8266_peri.h>
#include <PolledTimeout.h>
#include "StackThunk.h" #include "StackThunk.h"
//#define DEBUG_UPDATER Serial //#define DEBUG_UPDATER Serial
@ -476,7 +477,7 @@ bool UpdaterClass::_verifyEnd() {
return false; return false;
} }
size_t UpdaterClass::writeStream(Stream &data) { size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) {
size_t written = 0; size_t written = 0;
size_t toRead = 0; size_t toRead = 0;
if(hasError() || !isRunning()) if(hasError() || !isRunning())
@ -489,6 +490,7 @@ size_t UpdaterClass::writeStream(Stream &data) {
_reset(); _reset();
return 0; return 0;
} }
esp8266::polledTimeout::oneShotMs timeOut(streamTimeout);
if (_progress_callback) { if (_progress_callback) {
_progress_callback(0, _size); _progress_callback(0, _size);
} }
@ -506,13 +508,15 @@ size_t UpdaterClass::writeStream(Stream &data) {
} }
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead); toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
if(toRead == 0) { //Timeout if(toRead == 0) { //Timeout
delay(100); if (timeOut) {
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
if(toRead == 0) { //Timeout
_currentAddress = (_startAddress + _size); _currentAddress = (_startAddress + _size);
_setError(UPDATE_ERROR_STREAM); _setError(UPDATE_ERROR_STREAM);
_reset();
return written; return written;
} }
delay(100);
} else {
timeOut.reset();
} }
if(_ledPin != -1) { if(_ledPin != -1) {
digitalWrite(_ledPin, !_ledOn); // Switch LED off digitalWrite(_ledPin, !_ledOn); // Switch LED off

View File

@ -83,7 +83,7 @@ class UpdaterClass {
Should be equal to the remaining bytes when called Should be equal to the remaining bytes when called
Usable for slow streams like Serial Usable for slow streams like Serial
*/ */
size_t writeStream(Stream &data); size_t writeStream(Stream &data, uint16_t streamTimeout = 60000);
/* /*
If all bytes are written If all bytes are written