From b9768f5fc966ed336266eae3a5ab48249ad40f06 Mon Sep 17 00:00:00 2001 From: Sympatron GmbH <35803463+Sympatron@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:25:00 +0100 Subject: [PATCH 1/2] Fix all Weigand typos --- libosdp-sys/Cargo.toml | 2 +- libosdp/Cargo.toml | 2 +- libosdp/src/events.rs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libosdp-sys/Cargo.toml b/libosdp-sys/Cargo.toml index 38753dd..b7fea3f 100644 --- a/libosdp-sys/Cargo.toml +++ b/libosdp-sys/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://libosdp.sidcha.dev/" readme = "README.md" repository = "https://github.com/goToMain/libosdp-rs" license = "Apache-2.0" -keywords = ["osdp", "libosdp", "acs", "sia", "weigand"] +keywords = ["osdp", "libosdp", "acs", "sia", "wiegand"] categories = ["development-tools", "embedded"] [build-dependencies] diff --git a/libosdp/Cargo.toml b/libosdp/Cargo.toml index ef39242..0bc0cd4 100644 --- a/libosdp/Cargo.toml +++ b/libosdp/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://libosdp.sidcha.dev/" readme = "README.md" repository = "https://github.com/goToMain/libosdp-rs" license = "Apache-2.0" -keywords = ["osdp", "libosdp", "acs", "sia", "weigand"] +keywords = ["osdp", "libosdp", "acs", "sia", "wiegand"] categories = ["development-tools", "embedded"] [dependencies] diff --git a/libosdp/src/events.rs b/libosdp/src/events.rs index 637b50f..137497e 100644 --- a/libosdp/src/events.rs +++ b/libosdp/src/events.rs @@ -27,7 +27,7 @@ pub enum OsdpCardFormats { /// Card format is not specified Unspecified, - /// Weigand format + /// Wiegand format Wiegand, /// Ascii format @@ -87,7 +87,7 @@ pub struct OsdpEventCardRead { pub direction: bool, /// Number of valid data bits in [`OsdpEventCardRead::data`] when the card - /// format is [`OsdpCardFormats::Weigand`]. For all other formats, this + /// format is [`OsdpCardFormats::Wiegand`]. For all other formats, this /// field is set to zero. pub nr_bits: usize, @@ -107,8 +107,8 @@ impl OsdpEventCardRead { } } - /// Create a Weigand card read event for self and direction set to forward - pub fn new_weigand(nr_bits: usize, data: Vec) -> Result { + /// Create a Wiegand card read event for self and direction set to forward + pub fn new_wiegand(nr_bits: usize, data: Vec) -> Result { if nr_bits > data.len() * 8 { return Err(OsdpError::Command); } @@ -449,7 +449,7 @@ mod tests { assert_eq!(event, event_struct.into()); - let event = OsdpEventCardRead::new_weigand(15, vec![0x55, 0xAA]).unwrap(); + let event = OsdpEventCardRead::new_wiegand(15, vec![0x55, 0xAA]).unwrap(); let event_struct: osdp_event_cardread = event.clone().into(); assert_eq!(event_struct.length, 15); From 93285ff3e859e87c858c870d28d0051a2b33939f Mon Sep 17 00:00:00 2001 From: Sympatron GmbH <35803463+Sympatron@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:36:38 +0100 Subject: [PATCH 2/2] Fix card data length for "raw bit array" Only formatted ASCII data is counted in bytes. All raw formats count in bits. --- libosdp/src/events.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libosdp/src/events.rs b/libosdp/src/events.rs index 137497e..3b30b2b 100644 --- a/libosdp/src/events.rs +++ b/libosdp/src/events.rs @@ -87,7 +87,7 @@ pub struct OsdpEventCardRead { pub direction: bool, /// Number of valid data bits in [`OsdpEventCardRead::data`] when the card - /// format is [`OsdpCardFormats::Wiegand`]. For all other formats, this + /// format is not [`OsdpCardFormats::Ascii`]. For [`OsdpCardFormats::Ascii`], this /// field is set to zero. pub nr_bits: usize, @@ -128,8 +128,8 @@ impl From for OsdpEventCardRead { let format = value.format.into(); let len = value.length as usize; let (nr_bits, nr_bytes) = match format { - OsdpCardFormats::Wiegand => (len, (len + 7) / 8), - _ => (0, len), + OsdpCardFormats::Ascii => (0, len), + _ => (len, len.div_ceil(8)), }; let data = value.data[0..nr_bytes].to_vec(); OsdpEventCardRead { @@ -146,8 +146,8 @@ impl From for libosdp_sys::osdp_event_cardread { fn from(value: OsdpEventCardRead) -> Self { let mut data = [0; libosdp_sys::OSDP_EVENT_CARDREAD_MAX_DATALEN as usize]; let length = match value.format { - OsdpCardFormats::Wiegand => value.nr_bits as i32, - _ => value.data.len() as i32, + OsdpCardFormats::Ascii => value.data.len() as i32, + _ => value.nr_bits as i32, }; data[..value.data.len()].copy_from_slice(&value.data[..]); libosdp_sys::osdp_event_cardread {