update crc6 check as well, seperate commit to check that test results are stable

This commit is contained in:
2026-03-25 13:54:47 +01:00
parent 6b82ddcd74
commit 3641331da2
+6 -9
View File
@@ -365,18 +365,15 @@ pub fn calc_crc6(data: u32) -> u8 {
/// This function is the mirror piece to the crc6 calculation, it checks a crc value against /// This function is the mirror piece to the crc6 calculation, it checks a crc value against
/// the data to determine if the crc is valid. /// the data to determine if the crc is valid.
pub fn check_crc6(data: u32, crc: u8) -> bool { pub fn check_crc6(data: u32, crc: u8) -> bool {
let mut working_data: u32 = data << 6 | crc as u32; let mut check_crc: u8 = 0x00;
let mut polynom: u32 = 0x43 << 25; for pos in 0..32 {
let mut mask: u32 = 0x40 << 25; if ((data >> (31-pos)) & 0x1) ^ ((check_crc >> 5) & 0x1) as u32 != 0 {
while working_data >= 0x40 { check_crc = ((check_crc << 1) ^ 0x03) & 0x3F;
if working_data & mask != 0 {
working_data ^= polynom;
} else { } else {
polynom >>= 1; check_crc = (check_crc << 1) & 0x3F;
mask >>= 1;
} }
} }
working_data == 0x00000000 check_crc == crc
} }
#[cfg(test)] #[cfg(test)]