impl Transit_U26 constructor

This commit is contained in:
2026-03-22 17:39:30 +01:00
parent a71ac0c43e
commit bcaf76de12
+9 -2
View File
@@ -130,6 +130,14 @@ impl TryFrom<u32> for Stored_U26 {
/// | 26 bits u26 value | 6 bits crc value |
pub struct Transit_U26(u32);
impl Transit_U26 {
pub fn new(value: u32) -> Self {
assert!(value <= U26_MAX_VALUE);
let crc6 = calc_crc6(value);
Self((value << 6) | (crc6 & 0x3F) as u32)
}
}
impl From<Transit_U26> for u32 {
fn from(value: Transit_U26) -> Self {
value.0 & U26_VALUE_MASK >> 6
@@ -143,7 +151,7 @@ impl TryFrom<u32> for Transit_U26 {
if value > U26_MAX_VALUE {
Err(U26Error::Overflow)
} else {
todo!()
Ok(Transit_U26::new(value))
}
}
}
@@ -324,7 +332,6 @@ pub fn check_hemming(data: u32, hemming: u8) -> Result<(), HemmingCorrectionValu
/// - All single-bit errors
/// - All double-bit errors
/// - Random errors with a probability of 2^-6 = 0.015625 of going undetected
#[cfg(test)]
pub fn calc_crc6(data: u32) -> u8 {
let mut working_data: u32 = data << 6;
let mut polynom: u32 = 0x43 << 25;