Skip to content

Commit 2840552

Browse files
Merge branch 'goToMain:master' into additional-pub
2 parents de3b196 + e1b435c commit 2840552

File tree

8 files changed

+37
-35
lines changed

8 files changed

+37
-35
lines changed

libosdp/src/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use core::ffi::c_void;
2020

2121
/// OSDP channel errors
22-
#[derive(Clone, Debug)]
22+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
2323
pub enum ChannelError {
2424
/// Channel is temporarily unavailable (could have blocked until it was
2525
/// ready but LibOSDP required channel to be non-blocking so return "I would

libosdp/src/commands.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
1313
use super::ConvertEndian;
1414

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

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

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

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

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

296296
/// Command to control digital output exposed by the PD.
297-
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
297+
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
298298
pub struct OsdpCommandOutput {
299299
/// The output number this to apply this action.
300300
///
@@ -341,7 +341,7 @@ impl From<OsdpCommandOutput> for libosdp_sys::osdp_cmd_output {
341341
/// Command to set the communication parameters for the PD. The effects of this
342342
/// command is expected to be be stored in PD's non-volatile memory as the CP
343343
/// will expect the PD to be in this state moving forward.
344-
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
344+
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
345345
pub struct OsdpComSet {
346346
address: u8,
347347
baud_rate: u32,
@@ -379,7 +379,7 @@ impl From<OsdpComSet> for libosdp_sys::osdp_cmd_comset {
379379
}
380380

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

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

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

502502
/// CP interacts with and controls PDs by sending commands to it. The commands
503503
/// in this enum are specified by OSDP specification.
504-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
504+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
505505
pub enum OsdpCommand {
506506
/// Command to control the behavior of it’s on-board LEDs
507507
Led(OsdpCommandLed),
@@ -546,7 +546,7 @@ impl From<OsdpCommand> for libosdp_sys::osdp_cmd {
546546
OsdpCommand::Buzzer(c) => libosdp_sys::osdp_cmd {
547547
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_BUZZER,
548548
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
549-
buzzer: c.clone().into(),
549+
buzzer: c.into(),
550550
},
551551
},
552552
OsdpCommand::Text(c) => libosdp_sys::osdp_cmd {
@@ -558,13 +558,13 @@ impl From<OsdpCommand> for libosdp_sys::osdp_cmd {
558558
OsdpCommand::Output(c) => libosdp_sys::osdp_cmd {
559559
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_OUTPUT,
560560
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
561-
output: c.clone().into(),
561+
output: c.into(),
562562
},
563563
},
564564
OsdpCommand::ComSet(c) => libosdp_sys::osdp_cmd {
565565
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_COMSET,
566566
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
567-
comset: c.clone().into(),
567+
comset: c.into(),
568568
},
569569
},
570570
OsdpCommand::KeySet(c) => libosdp_sys::osdp_cmd {
@@ -582,13 +582,13 @@ impl From<OsdpCommand> for libosdp_sys::osdp_cmd {
582582
OsdpCommand::FileTx(c) => libosdp_sys::osdp_cmd {
583583
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_FILE_TX,
584584
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
585-
file_tx: c.clone().into(),
585+
file_tx: c.into(),
586586
},
587587
},
588588
OsdpCommand::Status(c) => libosdp_sys::osdp_cmd {
589589
id: libosdp_sys::osdp_cmd_e_OSDP_CMD_STATUS,
590590
__bindgen_anon_1: libosdp_sys::osdp_cmd__bindgen_ty_1 {
591-
status: c.clone().into(),
591+
status: c.into(),
592592
},
593593
},
594594
}

libosdp/src/events.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Result<T> = core::result::Result<T, OsdpError>;
1717

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

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

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

242-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
243242
/// Status report type
243+
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
244244
pub enum OsdpStatusReportType {
245245
/// Input status report
246246
Input,
@@ -299,7 +299,7 @@ impl From<OsdpStatusReportType> for libosdp_sys::osdp_status_report_type {
299299
/// number of items as described in the corresponding capability codes,
300300
/// - PdCapability::OutputControl
301301
/// - PdCapability::ContactStatusMonitoring
302-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
302+
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
303303
pub struct OsdpStatusReport {
304304
type_: OsdpStatusReportType,
305305
nr_entries: usize,
@@ -389,7 +389,7 @@ impl From<OsdpEvent> for libosdp_sys::osdp_event {
389389
OsdpEvent::Status(e) => libosdp_sys::osdp_event {
390390
type_: libosdp_sys::osdp_event_type_OSDP_EVENT_STATUS,
391391
__bindgen_anon_1: libosdp_sys::osdp_event__bindgen_ty_1 {
392-
status: e.clone().into(),
392+
status: e.into(),
393393
},
394394
},
395395
}

libosdp/src/pdcap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::str::FromStr;
88
use crate::OsdpError;
99

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

6969
/// OSDP defined PD capabilities. PDs expose/advertise features they support to
7070
/// the CP by means of "capabilities".
71-
#[derive(Clone, Debug)]
71+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7272
pub enum PdCapability {
7373
/// This function indicates the ability to monitor the status of a switch
7474
/// using a two-wire electrical connection between the PD and the switch.

libosdp/src/pdid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use super::ConvertEndian;
77

88
/// PD ID information advertised by the PD.
9-
#[derive(Clone, Debug, Default)]
9+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
1010
pub struct PdId {
1111
/// 1-Byte Manufacturer's version number
1212
pub version: i32,

libosdp/src/pdinfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use alloc::ffi::CString;
88
use crate::{Channel, OsdpError, OsdpFlag, PdCapability, PdId};
99

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

@@ -147,7 +147,7 @@ impl PdInfo {
147147
baud_rate: self.baud_rate,
148148
address: self.address,
149149
flags: self.flags.bits() as i32,
150-
id: self.id.clone().into(),
150+
id: self.id.into(),
151151
cap: self.cap.as_ptr(),
152152
channel: self.channel.take().unwrap().into(),
153153
scbk,

libosdp/tests/file_transfer.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ use std::os::unix::prelude::FileExt;
2828
use std::os::windows::fs::FileExt;
2929

3030
/// OSDP file transfer context
31-
#[derive(Debug)]
31+
#[derive(Debug, Default)]
3232
pub struct OsdpFileManager {
3333
files: HashMap<i32, PathBuf>,
3434
file: Option<File>,
3535
}
3636

3737
impl OsdpFileManager {
3838
pub fn new() -> Self {
39-
Self {
40-
files: HashMap::new(),
41-
file: None,
42-
}
39+
Self::default()
4340
}
4441

4542
pub fn register_file(&mut self, id: i32, path: &str) {

osdpctl/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn vec_to_array<T, const N: usize>(v: Vec<T>) -> [T; N] {
2424
.unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len()))
2525
}
2626

27+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2728
pub struct KeyStore {
2829
store: PathBuf,
2930
}
@@ -82,6 +83,7 @@ impl KeyStore {
8283
}
8384
}
8485

86+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
8587
pub struct PdData {
8688
pub name: String,
8789
channel: String,
@@ -90,6 +92,7 @@ pub struct PdData {
9092
flags: OsdpFlag,
9193
}
9294

95+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
9396
pub struct CpConfig {
9497
pub runtime_dir: PathBuf,
9598
pub name: String,
@@ -158,6 +161,7 @@ impl CpConfig {
158161
}
159162
}
160163

164+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
161165
pub struct PdConfig {
162166
pub runtime_dir: PathBuf,
163167
pub name: String,
@@ -255,6 +259,7 @@ impl PdConfig {
255259
}
256260
}
257261

262+
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
258263
pub enum DeviceConfig {
259264
CpConfig(CpConfig),
260265
PdConfig(PdConfig),

0 commit comments

Comments
 (0)