* Writes received updater to the flash. * This function overrides AutoConnectUploadHandler::_write. * @param buf Buffer address where received update file was stored. * @param size Size to be written. * @return the amount written */
| 242 | * @return the amount written |
| 243 | */ |
| 244 | size_t AutoConnectOTA::_write(const uint8_t *buf, const size_t size) { |
| 245 | size_t wsz = 0; |
| 246 | |
| 247 | #ifdef ARDUINO_ARCH_ESP32 |
| 248 | // Check if an available OTA partition exists. |
| 249 | const esp_partition_t* runningPartition = esp_ota_get_running_partition(); |
| 250 | const esp_partition_t* otaPartition = esp_ota_get_next_update_partition(NULL); |
| 251 | if (!strcmp(runningPartition->label, otaPartition->label)) { |
| 252 | // There is only one app partition. |
| 253 | _setError("No OTA partition"); |
| 254 | } |
| 255 | #endif |
| 256 | |
| 257 | if (_tickerPort != -1) |
| 258 | digitalWrite(_tickerPort, digitalRead(_tickerPort) ^ 0x01); |
| 259 | if (!_err.length()) { |
| 260 | _otaStatus = AC_OTA_PROGRESS; |
| 261 | if (_dest == OTA_DEST_FIRM) { |
| 262 | wsz = Update.write(const_cast<uint8_t*>(buf), size); |
| 263 | if (wsz != size) |
| 264 | _setError(); |
| 265 | } |
| 266 | else { |
| 267 | wsz = _file.write(buf, size); |
| 268 | if (wsz != size) |
| 269 | _setError("Incomplete writing"); |
| 270 | } |
| 271 | } |
| 272 | return wsz; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * All bytes are written, this call writes the config to reboot. |
nothing calls this directly
no outgoing calls
no test coverage detected