MCPcopy Create free account
hub / github.com/BruceDevices/firmware / crc32File

Function crc32File

src/core/sd_functions.cpp:456–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

454}
455
456String crc32File(FS &fs, String filepath) {
457 if (!fs.exists(filepath)) return "";
458 String txt = readSmallFile(fs, filepath);
459 // derived from
460 // https://techoverflow.net/2022/08/05/how-to-compute-crc32-with-ethernet-polynomial-0x04c11db7-on-esp32-crc-h/
461 uint32_t romCRC =
462 (~esp_rom_crc32_le((uint32_t)~(0xffffffff), (const uint8_t *)txt.c_str(), txt.length())) ^ 0xffffffff;
463
464 char s[18] = {0};
465 char crcBytes[4] = {0};
466 memcpy(crcBytes, &romCRC, sizeof(uint32_t));
467 snprintf(s, sizeof(s), "%02X%02X%02X%02X\n", crcBytes[3], crcBytes[2], crcBytes[1], crcBytes[0]);
468 return (String(s));
469}
470
471/***************************************************************************************
472** Function name: sortList

Callers 2

loopSDFunction · 0.85
crc32CallbackFunction · 0.85

Calls 1

readSmallFileFunction · 0.85

Tested by

no test coverage detected