@@ -47,19 +47,17 @@ Arduino_ESP32_OTA::Arduino_ESP32_OTA()
47
47
48
48
Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin ()
49
49
{
50
+ /* initialize private variables */
51
+ otaInit ();
50
52
51
53
/* ... initialize CRC ... */
52
- _crc32 = 0xFFFFFFFF ;
54
+ crc32Init () ;
53
55
54
56
if (!isCapable ()) {
55
57
DEBUG_ERROR (" %s: board is not capable to perform OTA" , __FUNCTION__);
56
58
return Error::NoOtaStorage;
57
59
}
58
60
59
- /* initialize private variables */
60
- _ota_size = 0 ;
61
- _ota_header = {0 };
62
-
63
61
if (Update.isRunning ()) {
64
62
Update.abort ();
65
63
DEBUG_DEBUG (" %s: Aborting running update" , __FUNCTION__);
@@ -98,7 +96,7 @@ uint8_t Arduino_ESP32_OTA::read_byte_from_network()
98
96
}
99
97
if (_client->available ()) {
100
98
const uint8_t data = _client->read ();
101
- _crc32 = crc_update (_crc32, & data, 1 );
99
+ crc32Update ( data);
102
100
return data;
103
101
}
104
102
}
@@ -268,10 +266,10 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
268
266
269
267
Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::update ()
270
268
{
271
- /* ... then finalise ... */
272
- _crc32 ^= 0xFFFFFFFF ;
269
+ /* ... then finalize ... */
270
+ crc32Finalize () ;
273
271
274
- if (_crc32 != _ota_header. header . crc32 ) {
272
+ if (! crc32Verify () ) {
275
273
DEBUG_ERROR (" %s: CRC32 mismatch" , __FUNCTION__);
276
274
return Error::OtaHeaderCrc;
277
275
}
@@ -295,3 +293,33 @@ bool Arduino_ESP32_OTA::isCapable()
295
293
const esp_partition_t * ota_1 = esp_partition_find_first (ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL );
296
294
return ((ota_0 != nullptr ) && (ota_1 != nullptr ));
297
295
}
296
+
297
+ /* *****************************************************************************
298
+ PROTECTED MEMBER FUNCTIONS
299
+ ******************************************************************************/
300
+
301
+ void Arduino_ESP32_OTA::otaInit ()
302
+ {
303
+ _ota_size = 0 ;
304
+ _ota_header = {0 };
305
+ }
306
+
307
+ void Arduino_ESP32_OTA::crc32Init ()
308
+ {
309
+ _crc32 = 0xFFFFFFFF ;
310
+ }
311
+
312
+ void Arduino_ESP32_OTA::crc32Update (const uint8_t data)
313
+ {
314
+ _crc32 = crc_update (_crc32, &data, 1 );
315
+ }
316
+
317
+ void Arduino_ESP32_OTA::crc32Finalize ()
318
+ {
319
+ _crc32 ^= 0xFFFFFFFF ;
320
+ }
321
+
322
+ bool Arduino_ESP32_OTA::crc32Verify ()
323
+ {
324
+ return (_crc32 == _ota_header.header .crc32 );
325
+ }
0 commit comments