Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "vendor"]
path = libosdp-sys/vendor
url = https://github.com/goToMain/libosdp
branch = master
url = https://github.com/rustylocker/libosdp
branch = fix-unused-warnings
2 changes: 1 addition & 1 deletion libosdp-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libosdp-sys"
version = "3.0.8"
version = "3.1.0"
edition = "2021"
authors = ["Siddharth Chandrasekaran <[email protected]>"]
description = "Sys crate for https://github.com/goToMain/libosdp"
Expand Down
1 change: 1 addition & 0 deletions libosdp-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fn main() -> Result<()> {
}

let source_files = vec![
"vendor/utils/src/crc16.c",
"vendor/utils/src/list.c",
"vendor/utils/src/queue.c",
"vendor/utils/src/slab.c",
Expand Down
2 changes: 1 addition & 1 deletion libosdp-sys/vendor
Submodule vendor updated 106 files
5 changes: 3 additions & 2 deletions libosdp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "libosdp"
version = "0.1.9"
version = "0.1.10"
authors = ["Siddharth Chandrasekaran <[email protected]>"]
description = "Library implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol)"
documentation = "https://docs.rs/libosdp"
Expand All @@ -15,9 +15,10 @@ categories = ["development-tools", "embedded"]
[dependencies]
bitflags = "2.4.0"
embedded-io = { version = "0.6.1", features = ["alloc"] }
libosdp-sys = "3.0.8"
libosdp-sys = { version = "3.1.0", path = "../libosdp-sys" }
log = { version = "0.4.20", optional = true }
serde = { version = "1.0.192", features = ["derive", "alloc"], default-features = false }
serde_arrays = "0.2.0"
thiserror = { version = "1.0.50", optional = true }
defmt = { version = "0.3", optional = true, features = ["alloc"] }
itoa = "1.0.11"
Expand Down
5 changes: 5 additions & 0 deletions libosdp/examples/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ impl Channel for OsdpChannel {
// TODO: flush device
Ok(())
}

fn close(&mut self) -> Result<(), ChannelError> {
// TODO: close device
Ok(())
}
}

fn main() -> Result<(), OsdpError> {
Expand Down
5 changes: 5 additions & 0 deletions libosdp/examples/pd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ impl Channel for OsdpChannel {
// TODO: flush device
Ok(())
}

fn close(&mut self) -> Result<(), ChannelError> {
// TODO: close device
Ok(())
}
}

fn main() -> Result<(), OsdpError> {
Expand Down
10 changes: 10 additions & 0 deletions libosdp/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ pub trait Channel: Send {
/// Flush this output stream, ensuring that all intermediately buffered
/// contents reach their destination.
fn flush(&mut self) -> Result<(), ChannelError>;

/// Close this output stream
fn close(&mut self) -> Result<(), ChannelError>;
}

impl core::fmt::Debug for dyn Channel {
Expand Down Expand Up @@ -112,6 +115,12 @@ unsafe extern "C" fn raw_flush(data: *mut c_void) {
let _ = channel.as_mut().flush();
}

unsafe extern "C" fn raw_close(data: *mut c_void) {
let channel: *mut Box<dyn Channel> = data as *mut _;
let channel = channel.as_mut().unwrap();
let _ = channel.as_mut().close();
}

impl From<Box<dyn Channel>> for libosdp_sys::osdp_channel {
fn from(val: Box<dyn Channel>) -> Self {
let id = val.get_id();
Expand All @@ -122,6 +131,7 @@ impl From<Box<dyn Channel>> for libosdp_sys::osdp_channel {
recv: Some(raw_read),
send: Some(raw_write),
flush: Some(raw_flush),
close: Some(raw_close),
}
}
}
80 changes: 39 additions & 41 deletions libosdp/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl From<libosdp_sys::osdp_cmd_led> for OsdpCommandLed {
fn from(value: libosdp_sys::osdp_cmd_led) -> Self {
OsdpCommandLed {
reader: value.reader,
led_number: value.reader,
led_number: value.led_number,
temporary: value.temporary.into(),
permanent: value.permanent.into(),
}
Expand Down Expand Up @@ -344,21 +344,11 @@ impl From<OsdpCommandOutput> for libosdp_sys::osdp_cmd_output {
/// will expect the PD to be in this state moving forward.
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpComSet {
address: u8,
baud_rate: u32,
}

impl OsdpComSet {
/// Create an instance of OsdpComSet command
///
/// # Arguments
///
/// * `address` - address to which this PD will respond after this command
/// * `baud_rate` - Serial communication speed; only acceptable values are,
/// 9600/19200/38400/57600/115200/230400
pub fn new(address: u8, baud_rate: u32) -> Self {
Self { address, baud_rate }
}
/// Unit ID to which this PD will respond after the change takes effect.
pub address: u8,
/// Baud rate.
/// Valid values: 9600, 19200, 38400, 115200, 230400.
pub baud_rate: u32,
}

impl From<libosdp_sys::osdp_cmd_comset> for OsdpComSet {
Expand Down Expand Up @@ -428,9 +418,6 @@ pub struct OsdpCommandMfg {
/// 3-byte IEEE assigned OUI used as vendor code
pub vendor_code: (u8, u8, u8),

/// 1-byte manufacturer defined command ID
pub command: u8,

/// Command data (if any)
pub data: Vec<u8>,
}
Expand All @@ -443,7 +430,6 @@ impl From<libosdp_sys::osdp_cmd_mfg> for OsdpCommandMfg {
let vendor_code: (u8, u8, u8) = (bytes[0], bytes[1], bytes[2]);
OsdpCommandMfg {
vendor_code,
command: value.command,
data,
}
}
Expand All @@ -455,31 +441,25 @@ impl From<OsdpCommandMfg> for libosdp_sys::osdp_cmd_mfg {
data[..value.data.len()].copy_from_slice(&value.data[..]);
libosdp_sys::osdp_cmd_mfg {
vendor_code: value.vendor_code.as_le(),
command: value.command,
length: value.data.len() as u8,
data,
}
}
}

/// File transfer command flag used to cancel ongoing transfers (not sent on OSDP channel).
pub const OSDP_CMD_FILE_TX_FLAG_CANCEL: u32 = 1 << 31;

/// Command to kick-off a file transfer to the PD.
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandFileTx {
id: i32,
flags: u32,
}

impl OsdpCommandFileTx {
/// Create an instance of OsdpCommandFileTx.
///
/// # Arguments
///
/// * `id` - The ID of the file; these are pre-shared between the CP and PD
/// * `flags` - Reserved and set to zero by OSDP spec; bit-31 used by
/// libOSDP to cancel ongoing transfers (it is not sent on OSDP channel)
pub fn new(id: i32, flags: u32) -> Self {
Self { id, flags }
}
/// Pre-agreed file ID between CP and PD
pub id: i32,
/// Reserved and set to zero by OSDP spec.
/// Note that the upper bits are used by libosdp internally (IOW, not sent
/// over the OSDP bus). Currently the following flags are defined:
/// - OSDP_CMD_FILE_TX_FLAG_CANCEL
pub flags: u32,
}

impl From<libosdp_sys::osdp_cmd_file_tx> for OsdpCommandFileTx {
Expand Down Expand Up @@ -517,11 +497,14 @@ pub enum OsdpCommand {
/// Command to control digital output exposed by the PD
Output(OsdpCommandOutput),

/// Command to set the communication parameters for the PD. The effects
/// of this command is expected to be be stored in PD’s non-volatile memory
/// as the CP will expect the PD to be in this state moving forward
/// Command to request setting the communication parameters for the PD.
ComSet(OsdpComSet),

/// Set communication parameter completed.
/// The effects of this command is expected to be be stored in PD’s non-volatile
/// memory as the CP will expect the PD to be in this state moving forward
ComSetDone(OsdpComSet),

/// Command to set secure channel keys to the PD
KeySet(OsdpCommandKeyset),

Expand All @@ -540,46 +523,60 @@ impl From<OsdpCommand> for libosdp_sys::osdp_cmd {
match value {
OsdpCommand::Led(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_LED,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
led: c.clone().into(),
},
},
OsdpCommand::Buzzer(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_BUZZER,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 { buzzer: c.into() },
},
OsdpCommand::Text(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_TEXT,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
text: c.clone().into(),
},
},
OsdpCommand::Output(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_OUTPUT,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 { output: c.into() },
},
OsdpCommand::ComSet(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_COMSET,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 { comset: c.into() },
},
OsdpCommand::ComSetDone(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_COMSET_DONE,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 { comset: c.into() },
},
OsdpCommand::KeySet(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_KEYSET,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
keyset: c.clone().into(),
},
},
OsdpCommand::Mfg(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_MFG,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
mfg: c.clone().into(),
},
},
OsdpCommand::FileTx(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_FILE_TX,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 { file_tx: c.into() },
},
OsdpCommand::Status(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_STATUS,
flags: 0,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 { status: c.into() },
},
}
Expand All @@ -604,6 +601,9 @@ impl From<libosdp_sys::osdp_cmd> for OsdpCommand {
libosdp_sys::osdp_cmd_e_OSDP_CMD_COMSET => {
OsdpCommand::ComSet(unsafe { value.__bindgen_anon_1.comset.into() })
}
libosdp_sys::osdp_cmd_e_OSDP_CMD_COMSET_DONE => {
OsdpCommand::ComSetDone(unsafe { value.__bindgen_anon_1.comset.into() })
}
libosdp_sys::osdp_cmd_e_OSDP_CMD_KEYSET => {
OsdpCommand::KeySet(unsafe { value.__bindgen_anon_1.keyset.into() })
}
Expand All @@ -630,13 +630,11 @@ mod tests {
fn test_command_mfg() {
let cmd = OsdpCommandMfg {
vendor_code: (0x05, 0x07, 0x09),
command: 0x47,
data: vec![0x55, 0xAA],
};
let cmd_struct: osdp_cmd_mfg = cmd.clone().into();

assert_eq!(cmd_struct.vendor_code, 0x90705);
assert_eq!(cmd_struct.command, 0x47);
assert_eq!(cmd_struct.length, 2);
assert_eq!(cmd_struct.data[0], 0x55);
assert_eq!(cmd_struct.data[1], 0xAA);
Expand Down
Loading