update crc6 check as well, seperate commit to check that test results are stable
This commit is contained in:
@@ -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
|
||||
/// the data to determine if the crc is valid.
|
||||
pub fn check_crc6(data: u32, crc: u8) -> bool {
|
||||
let mut working_data: u32 = data << 6 | crc as u32;
|
||||
let mut polynom: u32 = 0x43 << 25;
|
||||
let mut mask: u32 = 0x40 << 25;
|
||||
while working_data >= 0x40 {
|
||||
if working_data & mask != 0 {
|
||||
working_data ^= polynom;
|
||||
let mut check_crc: u8 = 0x00;
|
||||
for pos in 0..32 {
|
||||
if ((data >> (31-pos)) & 0x1) ^ ((check_crc >> 5) & 0x1) as u32 != 0 {
|
||||
check_crc = ((check_crc << 1) ^ 0x03) & 0x3F;
|
||||
} else {
|
||||
polynom >>= 1;
|
||||
mask >>= 1;
|
||||
check_crc = (check_crc << 1) & 0x3F;
|
||||
}
|
||||
}
|
||||
working_data == 0x00000000
|
||||
check_crc == crc
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user