Skip to content

Commit

Permalink
Merge pull request #9 from CommanderStorm/additional-derives
Browse files Browse the repository at this point in the history
Added additional derivable traits
  • Loading branch information
sidcha authored Aug 18, 2024
2 parents 07a99ef + 2f20f95 commit e1b435c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion libosdp/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use core::ffi::c_void;

/// OSDP channel errors
#[derive(Clone, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ChannelError {
/// Channel is temporarily unavailable (could have blocked until it was
/// ready but LibOSDP required channel to be non-blocking so return "I would
Expand Down
32 changes: 16 additions & 16 deletions libosdp/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
use super::ConvertEndian;

/// LED Colors as specified in OSDP for the on_color/off_color parameters.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum OsdpLedColor {
/// No Color
#[default]
Expand Down Expand Up @@ -68,7 +68,7 @@ impl From<OsdpLedColor> for u8 {
}

/// LED params sub-structure. Part of LED command: OsdpCommandLed
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpLedParams {
/// Control code serves different purposes based on which member of
/// [`OsdpCommandLed`] it is used with. They are,
Expand Down Expand Up @@ -128,7 +128,7 @@ impl From<OsdpLedParams> for libosdp_sys::osdp_cmd_led_params {
}

/// Command to control the behavior of it's on-board LEDs
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandLed {
/// Reader (another device connected to this PD) for which this command is
/// issued for.
Expand Down Expand Up @@ -174,7 +174,7 @@ impl From<OsdpCommandLed> for libosdp_sys::osdp_cmd_led {
}

/// Command to control the behavior of a buzzer in the PD
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandBuzzer {
/// Reader (another device connected to this PD) for which this command is
/// issued for.
Expand Down Expand Up @@ -230,7 +230,7 @@ impl From<OsdpCommandBuzzer> for libosdp_sys::osdp_cmd_buzzer {

/// Command to manipulate the on-board display unit (Can be LED, LCD, 7-Segment,
/// etc.,) on the PD.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandText {
/// Reader (another device connected to this PD) for which this command is
/// issued for.
Expand Down Expand Up @@ -294,7 +294,7 @@ impl From<OsdpCommandText> for libosdp_sys::osdp_cmd_text {
}

/// Command to control digital output exposed by the PD.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandOutput {
/// The output number this to apply this action.
///
Expand Down Expand Up @@ -341,7 +341,7 @@ impl From<OsdpCommandOutput> for libosdp_sys::osdp_cmd_output {
/// 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.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpComSet {
address: u8,
baud_rate: u32,
Expand Down Expand Up @@ -379,7 +379,7 @@ impl From<OsdpComSet> for libosdp_sys::osdp_cmd_comset {
}

/// Command to set secure channel keys to the PD.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandKeyset {
key_type: u8,
/// Key data
Expand Down Expand Up @@ -422,7 +422,7 @@ impl From<OsdpCommandKeyset> for libosdp_sys::osdp_cmd_keyset {
}

/// Command to to act as a wrapper for manufacturer specific commands
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandMfg {
/// 3-byte IEEE assigned OUI used as vendor code
pub vendor_code: (u8, u8, u8),
Expand Down Expand Up @@ -462,7 +462,7 @@ impl From<OsdpCommandMfg> for libosdp_sys::osdp_cmd_mfg {
}

/// Command to kick-off a file transfer to the PD.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandFileTx {
id: i32,
flags: u32,
Expand Down Expand Up @@ -501,7 +501,7 @@ impl From<OsdpCommandFileTx> for libosdp_sys::osdp_cmd_file_tx {

/// CP interacts with and controls PDs by sending commands to it. The commands
/// in this enum are specified by OSDP specification.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum OsdpCommand {
/// Command to control the behavior of it’s on-board LEDs
Led(OsdpCommandLed),
Expand Down Expand Up @@ -546,7 +546,7 @@ impl From<OsdpCommand> for libosdp_sys::osdp_cmd {
OsdpCommand::Buzzer(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_BUZZER,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
buzzer: c.clone().into(),
buzzer: c.into(),
},
},
OsdpCommand::Text(c) => libosdp_sys::osdp_cmd {
Expand All @@ -558,13 +558,13 @@ impl From<OsdpCommand> for libosdp_sys::osdp_cmd {
OsdpCommand::Output(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_OUTPUT,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
output: c.clone().into(),
output: c.into(),
},
},
OsdpCommand::ComSet(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_COMSET,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
comset: c.clone().into(),
comset: c.into(),
},
},
OsdpCommand::KeySet(c) => libosdp_sys::osdp_cmd {
Expand All @@ -582,13 +582,13 @@ impl From<OsdpCommand> for libosdp_sys::osdp_cmd {
OsdpCommand::FileTx(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_FILE_TX,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
file_tx: c.clone().into(),
file_tx: c.into(),
},
},
OsdpCommand::Status(c) => libosdp_sys::osdp_cmd {
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_STATUS,
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
status: c.clone().into(),
status: c.into(),
},
},
}
Expand Down
14 changes: 7 additions & 7 deletions libosdp/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Result<T> = core::result::Result<T, OsdpError>;

/// Various card formats that a PD can support. This is sent to CP when a PD
/// must report a card read
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum OsdpCardFormats {
/// Card format is not specified
Unspecified,
Expand Down Expand Up @@ -60,7 +60,7 @@ impl From<OsdpCardFormats> for libosdp_sys::osdp_event_cardread_format_e {
}

/// Event that describes card read activity on the PD
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpEventCardRead {
/// Reader (another device connected to this PD) which caused this event
///
Expand Down Expand Up @@ -146,7 +146,7 @@ impl From<OsdpEventCardRead> for libosdp_sys::osdp_event_cardread {
data[..value.data.len()].copy_from_slice(&value.data[..]);
libosdp_sys::osdp_event_cardread {
reader_no: value.reader_no,
format: value.format.clone().into(),
format: value.format.into(),
direction: value.direction as i32,
length,
data,
Expand Down Expand Up @@ -200,7 +200,7 @@ impl From<OsdpEventKeyPress> for libosdp_sys::osdp_event_keypress {
}

/// Event to transport a Manufacturer specific command's response.
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpEventMfgReply {
/// 3-byte IEEE assigned OUI used as vendor code
pub vendor_code: (u8, u8, u8),
Expand Down Expand Up @@ -239,8 +239,8 @@ impl From<OsdpEventMfgReply> for libosdp_sys::osdp_event_mfgrep {
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
/// Status report type
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum OsdpStatusReportType {
/// Input status report
Input,
Expand Down Expand Up @@ -299,7 +299,7 @@ impl From<OsdpStatusReportType> for libosdp_sys::osdp_status_report_type {
/// number of items as described in the corresponding capability codes,
/// - PdCapability::OutputControl
/// - PdCapability::ContactStatusMonitoring
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpStatusReport {
type_: OsdpStatusReportType,
nr_entries: usize,
Expand Down Expand Up @@ -389,7 +389,7 @@ impl From<OsdpEvent> for libosdp_sys::osdp_event {
OsdpEvent::Status(e) => libosdp_sys::osdp_event {
type_: libosdp_sys::osdp_event_type_OSDP_EVENT_STATUS,
__bindgen_anon_1: libosdp_sys::osdp_event__bindgen_ty_1 {
status: e.clone().into(),
status: e.into(),
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions libosdp/src/pdcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::str::FromStr;
use crate::OsdpError;

/// PD capability entity to be used inside [`PdCapability`]
#[derive(Clone, Debug, Default)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct PdCapEntity {
compliance: u8,
num_items: u8,
Expand Down Expand Up @@ -68,7 +68,7 @@ impl FromStr for PdCapEntity {

/// OSDP defined PD capabilities. PDs expose/advertise features they support to
/// the CP by means of "capabilities".
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum PdCapability {
/// This function indicates the ability to monitor the status of a switch
/// using a two-wire electrical connection between the PD and the switch.
Expand Down
2 changes: 1 addition & 1 deletion libosdp/src/pdid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use super::ConvertEndian;

/// PD ID information advertised by the PD.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct PdId {
/// 1-Byte Manufacturer's version number
pub version: i32,
Expand Down
6 changes: 3 additions & 3 deletions libosdp/src/pdinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use alloc::ffi::CString;
use crate::{Channel, OsdpError, OsdpFlag, PdCapability, PdId};

/// OSDP PD Information. This struct is used to describe a PD to LibOSDP
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct PdInfo {
name: CString,
address: i32,
Expand Down Expand Up @@ -82,7 +82,7 @@ impl PdInfoBuilder {
/// received a `CMD_ID`. For CP mode, this field is ignored, but PD mode
/// must set
pub fn id(mut self, id: &PdId) -> PdInfoBuilder {
self.id = id.clone();
self.id = *id;
self
}

Expand Down Expand Up @@ -147,7 +147,7 @@ impl PdInfo {
baud_rate: self.baud_rate,
address: self.address,
flags: self.flags.bits() as i32,
id: self.id.clone().into(),
id: self.id.into(),
cap: self.cap.as_ptr(),
channel: self.channel.take().unwrap().into(),
scbk,
Expand Down
7 changes: 2 additions & 5 deletions libosdp/tests/file_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ use std::os::unix::prelude::FileExt;
use std::os::windows::fs::FileExt;

/// OSDP file transfer context
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct OsdpFileManager {
files: HashMap<i32, PathBuf>,
file: Option<File>,
}

impl OsdpFileManager {
pub fn new() -> Self {
Self {
files: HashMap::new(),
file: None,
}
Self::default()
}

pub fn register_file(&mut self, id: i32, path: &str) {
Expand Down
5 changes: 5 additions & 0 deletions osdpctl/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn vec_to_array<T, const N: usize>(v: Vec<T>) -> [T; N] {
.unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len()))
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct KeyStore {
store: PathBuf,
}
Expand Down Expand Up @@ -82,6 +83,7 @@ impl KeyStore {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct PdData {
pub name: String,
channel: String,
Expand All @@ -90,6 +92,7 @@ pub struct PdData {
flags: OsdpFlag,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct CpConfig {
pub runtime_dir: PathBuf,
pub name: String,
Expand Down Expand Up @@ -158,6 +161,7 @@ impl CpConfig {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct PdConfig {
pub runtime_dir: PathBuf,
pub name: String,
Expand Down Expand Up @@ -255,6 +259,7 @@ impl PdConfig {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum DeviceConfig {
CpConfig(CpConfig),
PdConfig(PdConfig),
Expand Down

0 comments on commit e1b435c

Please sign in to comment.