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

View File

@ -83,7 +83,7 @@ class UpdaterClass {
Should be equal to the remaining bytes when called
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