MCPcopy Create free account
hub / github.com/Heltec-Aaron-Lee/WiFi_Kit_series / runUpdate

Method runUpdate

libraries/HTTPUpdate/src/HTTPUpdate.cpp:442–496  ·  view source on GitHub ↗

* write Update to flash * @param in Stream& * @param size uint32_t * @param md5 String * @return true if Update ok */

Source from the content-addressed store, hash-verified

440 * @return true if Update ok
441 */
442bool HTTPUpdate::runUpdate(Stream &in, uint32_t size, String md5, int command) {
443 if (!_updater) {
444 return false;
445 }
446
447 StreamString error;
448
449 if (_cbProgress) {
450 _updater->onProgress(_cbProgress);
451 }
452
453 if (!_updater->begin(size, command, _ledPin, _ledOn)) {
454 _lastError = _updater->getError();
455 _updater->printError(error);
456 error.trim(); // remove line ending
457 log_e("Update.begin failed! (%s)\n", error.c_str());
458 return false;
459 }
460
461 if (_cbProgress) {
462 _cbProgress(0, size);
463 }
464
465 if (md5.length()) {
466 if (!_updater->setMD5(md5.c_str())) {
467 _lastError = HTTP_UE_SERVER_FAULTY_MD5;
468 log_e("Update.setMD5 failed! (%s)\n", md5.c_str());
469 return false;
470 }
471 }
472
473 // To do: the SHA256 could be checked if the server sends it
474
475 if (_updater->writeStream(in) != size) {
476 _lastError = _updater->getError();
477 _updater->printError(error);
478 error.trim(); // remove line ending
479 log_e("Update.writeStream failed! (%s)\n", error.c_str());
480 return false;
481 }
482
483 if (_cbProgress) {
484 _cbProgress(size, size);
485 }
486
487 if (!_updater->end()) {
488 _lastError = _updater->getError();
489 _updater->printError(error);
490 error.trim(); // remove line ending
491 log_e("Update.end failed! (%s)\n", error.c_str());
492 return false;
493 }
494
495 return true;
496}
497
498#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE)
499HTTPUpdate httpUpdate;

Callers

nothing calls this directly

Calls 9

onProgressMethod · 0.80
getErrorMethod · 0.80
printErrorMethod · 0.80
c_strMethod · 0.80
setMD5Method · 0.80
beginMethod · 0.45
trimMethod · 0.45
lengthMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected