MCPcopy Create free account
hub / github.com/SmingHub/Sming / doUpgrade

Function doUpgrade

samples/Basic_Ota/app/application.cpp:51–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void doUpgrade()
52{
53 Serial.println(F("Updating..."));
54
55 // need a clean object, otherwise if run before and failed will not run again
56 otaUpdater = std::make_unique<Ota::Network::HttpUpgrader>();
57
58 // select rom slot to flash
59 auto part = ota.getNextBootPartition();
60
61 /*
62 * Applications should always include a sanity check to ensure partitions being updated are
63 * not in use. This should always included the application partition but should also consider
64 * filing system partitions, etc. which may be actively in use.
65 */
66 if(part == ota.getRunningPartition()) {
67 Serial << F("May be running in temporary mode. Please reboot and try again.") << endl;
68 return;
69 }
70
71#ifndef RBOOT_TWO_ROMS
72 // flash rom to position indicated in the rBoot config rom table
73 otaUpdater->addItem(ROM_0_URL, part);
74#else
75 // flash appropriate ROM
76 otaUpdater->addItem((ota.getSlot(part) == 0) ? ROM_0_URL : ROM_1_URL, part);
77#endif
78
79 ota.begin(part);
80
81 auto spiffsPart = findSpiffsPartition(part);
82 if(spiffsPart) {
83 // use user supplied values (defaults for 4mb flash in hardware config)
84 otaUpdater->addItem(SPIFFS_URL, spiffsPart,
85 new Storage::PartitionStream(spiffsPart, Storage::Mode::BlockErase));
86 }
87
88 // request switch and reboot on success
89 //otaUpdater->switchToRom(slot);
90 // and/or set a callback (called on failure or success without switching requested)
91 otaUpdater->setCallback(upgradeCallback);
92
93 // start update
94 otaUpdater->start();
95}
96
97void doSwitch()
98{

Callers 1

handleCommandFunction · 0.85

Calls 10

findSpiffsPartitionFunction · 0.85
printlnMethod · 0.80
getSlotMethod · 0.80
FFunction · 0.50
getNextBootPartitionMethod · 0.45
getRunningPartitionMethod · 0.45
addItemMethod · 0.45
beginMethod · 0.45
setCallbackMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected