int64 StringUtil::CRC32(CStrRef input) { return string_crc32(input, input.size()); }
int64_t StringUtil::CRC32(CStrRef input) { return string_crc32(input.data(), input.size()); }
irom app_action_t application_function_ota_send(const string_t *src, string_t *dst) { int chunk_offset, chunk_length, remote_chunk_length; uint32_t crc, remote_crc; app_action_t action; if((ota_state != state_write) && (ota_state != state_verify)) { string_cat(dst, "OTA: not active\n"); ota_state = state_inactive; return(app_action_error); } if(parse_int(1, src, &remote_chunk_length, 0) != parse_ok) { string_cat(dst, "OTA: missing chunk length\n"); ota_state = state_inactive; return(app_action_error); } if(parse_int(2, src, &remote_crc, 0) != parse_ok) { string_cat(dst, "OTA: missing crc\n"); ota_state = state_inactive; return(app_action_error); } if((chunk_offset = string_sep(src, 0, 3, ' ')) < 0) { string_cat(dst, "OTA: missing data chunk\n"); ota_state = state_inactive; return(app_action_error); } if((chunk_length = string_length(src) - chunk_offset) != remote_chunk_length) { string_format(dst, "OTA: chunk length mismatch: %d != %d\n", remote_chunk_length, chunk_length); ota_state = state_inactive; return(app_action_error); } if((crc = string_crc32(src, chunk_offset, chunk_length)) != remote_crc) { string_format(dst, "OTA: CRC mismatch %08x != %08x\n", remote_crc, crc); ota_state = state_inactive; return(app_action_error); } string_splice(&buffer_4k, src, chunk_offset, chunk_length); if(string_length(&buffer_4k) > 0x1000) { string_format(dst, "OTA: unaligned %u\n", string_length(&buffer_4k)); ota_state = state_inactive; return(app_action_error); } if((string_length(&buffer_4k) == 0x1000) && ((action = flash_write_verify(src, dst)) != app_action_normal)) { ota_state = state_inactive; return(action); } string_format(dst, "ACK %d\n", received); return(app_action_normal); }