1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-11 15:22:13 +03:00

Allman now (#6080)

* switch restyle script for CI

* remove confirmation

* restyle with allman
This commit is contained in:
Allman-astyler
2019-05-13 16:41:34 +02:00
committed by david gauchard
parent 625c3a62c4
commit 98125f8860
255 changed files with 51238 additions and 42984 deletions

View File

@ -31,8 +31,9 @@
#endif
// Abstract class to implement whatever signing hash desired
class UpdaterHashClass {
public:
class UpdaterHashClass
{
public:
virtual void begin() = 0;
virtual void add(const void *data, uint32_t len) = 0;
virtual void end() = 0;
@ -41,144 +42,197 @@ class UpdaterHashClass {
};
// Abstract class to implement a signature verifier
class UpdaterVerifyClass {
public:
class UpdaterVerifyClass
{
public:
virtual uint32_t length() = 0; // How many bytes of signature are expected
virtual bool verify(UpdaterHashClass *hash, const void *signature, uint32_t signatureLen) = 0; // Verify, return "true" on success
};
class UpdaterClass {
public:
class UpdaterClass
{
public:
typedef std::function<void(size_t, size_t)> THandlerFunction_Progress;
UpdaterClass();
/* Optionally add a cryptographic signature verification hash and method */
void installSignature(UpdaterHashClass *hash, UpdaterVerifyClass *verify) { _hash = hash; _verify = verify; }
void installSignature(UpdaterHashClass *hash, UpdaterVerifyClass *verify)
{
_hash = hash;
_verify = verify;
}
/*
Call this to check the space needed for the update
Will return false if there is not enough space
Call this to check the space needed for the update
Will return false if there is not enough space
*/
bool begin(size_t size, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW);
/*
Run Updater from asynchronous callbacs
Run Updater from asynchronous callbacs
*/
void runAsync(bool async){ _async = async; }
void runAsync(bool async)
{
_async = async;
}
/*
Writes a buffer to the flash and increments the address
Returns the amount written
Writes a buffer to the flash and increments the address
Returns the amount written
*/
size_t write(uint8_t *data, size_t len);
/*
Writes the remaining bytes from the Stream to the flash
Uses readBytes() and sets UPDATE_ERROR_STREAM on timeout
Returns the bytes written
Should be equal to the remaining bytes when called
Usable for slow streams like Serial
Writes the remaining bytes from the Stream to the flash
Uses readBytes() and sets UPDATE_ERROR_STREAM on timeout
Returns the bytes written
Should be equal to the remaining bytes when called
Usable for slow streams like Serial
*/
size_t writeStream(Stream &data);
/*
If all bytes are written
this call will write the config to eboot
and return true
If there is already an update running but is not finished and !evenIfRemaining
or there is an error
this will clear everything and return false
the last error is available through getError()
evenIfRemaining is helpful when you update without knowing the final size first
If all bytes are written
this call will write the config to eboot
and return true
If there is already an update running but is not finished and !evenIfRemaining
or there is an error
this will clear everything and return false
the last error is available through getError()
evenIfRemaining is helpful when you update without knowing the final size first
*/
bool end(bool evenIfRemaining = false);
/*
Prints the last error to an output stream
Prints the last error to an output stream
*/
void printError(Print &out);
/*
sets the expected MD5 for the firmware (hexString)
sets the expected MD5 for the firmware (hexString)
*/
bool setMD5(const char * expected_md5);
/*
returns the MD5 String of the sucessfully ended firmware
returns the MD5 String of the sucessfully ended firmware
*/
String md5String(void){ return _md5.toString(); }
String md5String(void)
{
return _md5.toString();
}
/*
populated the result with the md5 bytes of the sucessfully ended firmware
populated the result with the md5 bytes of the sucessfully ended firmware
*/
void md5(uint8_t * result){ return _md5.getBytes(result); }
void md5(uint8_t * result)
{
return _md5.getBytes(result);
}
/*
This callback will be called when Updater is receiving data
This callback will be called when Updater is receiving data
*/
UpdaterClass& onProgress(THandlerFunction_Progress fn);
//Helpers
uint8_t getError(){ return _error; }
void clearError(){ _error = UPDATE_ERROR_OK; }
bool hasError(){ return _error != UPDATE_ERROR_OK; }
bool isRunning(){ return _size > 0; }
bool isFinished(){ return _currentAddress == (_startAddress + _size); }
size_t size(){ return _size; }
size_t progress(){ return _currentAddress - _startAddress; }
size_t remaining(){ return _size - (_currentAddress - _startAddress); }
/*
Template to write from objects that expose
available() and read(uint8_t*, size_t) methods
faster than the writeStream method
writes only what is available
*/
template<typename T>
size_t write(T &data){
size_t written = 0;
if (hasError() || !isRunning())
return 0;
size_t available = data.available();
while(available) {
if(_bufferLen + available > remaining()){
available = remaining() - _bufferLen;
}
if(_bufferLen + available > _bufferSize) {
size_t toBuff = _bufferSize - _bufferLen;
data.read(_buffer + _bufferLen, toBuff);
_bufferLen += toBuff;
if(!_writeBuffer())
return written;
written += toBuff;
} else {
data.read(_buffer + _bufferLen, available);
_bufferLen += available;
written += available;
if(_bufferLen == remaining()) {
if(!_writeBuffer()) {
return written;
}
}
}
if(remaining() == 0)
return written;
delay(1);
available = data.available();
}
return written;
uint8_t getError()
{
return _error;
}
void clearError()
{
_error = UPDATE_ERROR_OK;
}
bool hasError()
{
return _error != UPDATE_ERROR_OK;
}
bool isRunning()
{
return _size > 0;
}
bool isFinished()
{
return _currentAddress == (_startAddress + _size);
}
size_t size()
{
return _size;
}
size_t progress()
{
return _currentAddress - _startAddress;
}
size_t remaining()
{
return _size - (_currentAddress - _startAddress);
}
private:
/*
Template to write from objects that expose
available() and read(uint8_t*, size_t) methods
faster than the writeStream method
writes only what is available
*/
template<typename T>
size_t write(T &data)
{
size_t written = 0;
if (hasError() || !isRunning())
{
return 0;
}
size_t available = data.available();
while (available)
{
if (_bufferLen + available > remaining())
{
available = remaining() - _bufferLen;
}
if (_bufferLen + available > _bufferSize)
{
size_t toBuff = _bufferSize - _bufferLen;
data.read(_buffer + _bufferLen, toBuff);
_bufferLen += toBuff;
if (!_writeBuffer())
{
return written;
}
written += toBuff;
}
else
{
data.read(_buffer + _bufferLen, available);
_bufferLen += available;
written += available;
if (_bufferLen == remaining())
{
if (!_writeBuffer())
{
return written;
}
}
}
if (remaining() == 0)
{
return written;
}
delay(1);
available = data.available();
}
return written;
}
private:
void _reset();
bool _writeBuffer();
bool _verifyHeader(uint8_t data);
bool _verifyEnd();
void _setError(int error);
void _setError(int error);
bool _async;
uint8_t _error;