libosdp 0.2.0

Library implementation of IEC 60839-11-5 OSDP (Open Supervised Device Protocol)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
//
// Copyright (c) 2023-2024 Siddharth Chandrasekaran <sidcha.dev@gmail.com>
//
// SPDX-License-Identifier: Apache-2.0

//! CP interacts with and controls PDs by sending commands to it. These commands
//! are specified by OSDP specification. This module is responsible to handling
//! such commands though [`OsdpCommand`].

use crate::OsdpStatusReport;
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};

use super::ConvertEndian;

/// LED Colors as specified in OSDP for the on_color/off_color parameters.
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum OsdpLedColor {
    /// No Color
    #[default]
    None,

    /// Red Color
    Red,

    /// Green Color
    Green,

    /// Amber Color
    Amber,

    /// Blue Color
    Blue,

    /// Magenta Color
    Magenta,

    /// Cyan Color
    Cyan,
}

impl From<u8> for OsdpLedColor {
    fn from(value: u8) -> Self {
        match value as libosdp_sys::osdp_led_color_e {
            libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_NONE => OsdpLedColor::None,
            libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_RED => OsdpLedColor::Red,
            libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_GREEN => OsdpLedColor::Green,
            libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_AMBER => OsdpLedColor::Amber,
            libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_BLUE => OsdpLedColor::Blue,
            libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_MAGENTA => OsdpLedColor::Magenta,
            libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_CYAN => OsdpLedColor::Cyan,
            _ => panic!("Invalid LED color code"),
        }
    }
}

impl From<OsdpLedColor> for u8 {
    fn from(value: OsdpLedColor) -> Self {
        match value {
            OsdpLedColor::None => libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_NONE as u8,
            OsdpLedColor::Red => libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_RED as u8,
            OsdpLedColor::Green => libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_GREEN as u8,
            OsdpLedColor::Amber => libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_AMBER as u8,
            OsdpLedColor::Blue => libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_BLUE as u8,
            OsdpLedColor::Magenta => libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_MAGENTA as u8,
            OsdpLedColor::Cyan => libosdp_sys::osdp_led_color_e_OSDP_LED_COLOR_CYAN as u8,
        }
    }
}

/// LED params sub-structure. Part of LED command: OsdpCommandLed
#[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,
    ///
    /// temporary:
    ///
    /// 0 - NOP - do not alter this LED's temporary settings
    /// 1 - Cancel any temporary operation and display this LED's permanent state immediately
    /// 2 - Set the temporary state as given and start timer immediately
    ///
    /// permanent:
    ///
    /// 0 - NOP - do not alter this LED's permanent settings
    /// 1 - Set the permanent state as given
    pub control_code: u8,

    /// The ON duration of the flash, in units of 100 ms
    pub on_count: u8,

    /// The OFF duration of the flash, in units of 100 ms
    pub off_count: u8,

    /// Color to set during the ON timer
    pub on_color: OsdpLedColor,

    /// Color to set during the Off timer
    pub off_color: OsdpLedColor,

    /// Time in units of 100 ms (only for temporary mode)
    pub timer_count: u16,
}

impl From<libosdp_sys::osdp_cmd_led_params> for OsdpLedParams {
    fn from(value: libosdp_sys::osdp_cmd_led_params) -> Self {
        OsdpLedParams {
            control_code: value.control_code,
            on_count: value.on_count,
            off_count: value.off_count,
            on_color: value.on_color.into(),
            off_color: value.off_color.into(),
            timer_count: value.timer_count,
        }
    }
}

impl From<OsdpLedParams> for libosdp_sys::osdp_cmd_led_params {
    fn from(value: OsdpLedParams) -> Self {
        libosdp_sys::osdp_cmd_led_params {
            control_code: value.control_code,
            on_count: value.on_count,
            off_count: value.off_count,
            on_color: value.on_color.into(),
            off_color: value.off_color.into(),
            timer_count: value.timer_count,
        }
    }
}

/// Command to control the behavior of it's on-board LEDs
#[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.
    ///
    /// 0 - self
    /// 1 - fist connected reader
    /// 2 - second connected reader
    /// ....
    pub reader: u8,

    /// LED number to operate on; 0 = first LED, 1 = second LED, etc.
    pub led_number: u8,

    /// Temporary LED activity descriptor. This operation is ephemeral and
    /// interrupts any on going permanent activity.
    pub temporary: OsdpLedParams,

    /// Permanent LED activity descriptor. This operation continues till another
    /// permanent activity overwrites this state.
    pub permanent: OsdpLedParams,
}

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.led_number,
            temporary: value.temporary.into(),
            permanent: value.permanent.into(),
        }
    }
}

impl From<OsdpCommandLed> for libosdp_sys::osdp_cmd_led {
    fn from(value: OsdpCommandLed) -> Self {
        libosdp_sys::osdp_cmd_led {
            reader: value.reader,
            led_number: value.led_number,
            temporary: value.temporary.into(),
            permanent: value.permanent.into(),
        }
    }
}

/// Command to control the behavior of a buzzer in the PD
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandBuzzer {
    /// Reader (another device connected to this PD) for which this command is
    /// issued for.
    ///
    /// 0 - self
    /// 1 - fist connected reader
    /// 2 - second connected reader
    /// ....
    pub reader: u8,

    /// Control code instructs the operation to perform:
    ///
    /// 0 - no tone
    /// 1 - off
    /// 2 - default tone
    /// 3+ - TBD
    pub control_code: u8,

    /// The ON duration of the flash, in units of 100 ms
    pub on_count: u8,

    /// The OFF duration of the flash, in units of 100 ms
    pub off_count: u8,

    /// The number of times to repeat the ON/OFF cycle; Setting this value to 0
    /// indicates the action is to be repeated forever.
    pub rep_count: u8,
}

impl From<libosdp_sys::osdp_cmd_buzzer> for OsdpCommandBuzzer {
    fn from(value: libosdp_sys::osdp_cmd_buzzer) -> Self {
        OsdpCommandBuzzer {
            reader: value.reader,
            control_code: value.control_code,
            on_count: value.on_count,
            off_count: value.off_count,
            rep_count: value.rep_count,
        }
    }
}

impl From<OsdpCommandBuzzer> for libosdp_sys::osdp_cmd_buzzer {
    fn from(value: OsdpCommandBuzzer) -> Self {
        libosdp_sys::osdp_cmd_buzzer {
            reader: value.reader,
            control_code: value.control_code,
            on_count: value.on_count,
            off_count: value.off_count,
            rep_count: value.rep_count,
        }
    }
}

/// 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, Hash)]
pub struct OsdpCommandText {
    /// Reader (another device connected to this PD) for which this command is
    /// issued for.
    ///
    /// 0 - self
    /// 1 - fist connected reader
    /// 2 - second connected reader
    /// ....
    pub reader: u8,

    /// Control code instructs the operation to perform:
    ///
    /// 1 - permanent text, no wrap
    /// 2 - permanent text, with wrap
    /// 3 - temporary text, no wrap
    /// 4 - temporary text, with wrap
    pub control_code: u8,

    /// duration to display temporary text, in seconds
    pub temp_time: u8,

    /// row to display the first character (1 indexed)
    pub offset_row: u8,

    /// column to display the first character (1 indexed)
    pub offset_col: u8,

    /// The string to display (ASCII codes)
    pub data: Vec<u8>,
}

impl From<libosdp_sys::osdp_cmd_text> for OsdpCommandText {
    fn from(value: libosdp_sys::osdp_cmd_text) -> Self {
        let n = value.length as usize;
        let data = value.data[0..n].to_vec();
        OsdpCommandText {
            reader: value.reader,
            control_code: value.control_code,
            temp_time: value.temp_time,
            offset_row: value.offset_row,
            offset_col: value.offset_col,
            data,
        }
    }
}

impl From<OsdpCommandText> for libosdp_sys::osdp_cmd_text {
    fn from(value: OsdpCommandText) -> Self {
        let mut data = [0; libosdp_sys::OSDP_CMD_TEXT_MAX_LEN as usize];
        data[..value.data.len()].copy_from_slice(&value.data[..]);
        libosdp_sys::osdp_cmd_text {
            reader: value.reader,
            control_code: value.control_code,
            temp_time: value.temp_time,
            offset_row: value.offset_row,
            offset_col: value.offset_col,
            length: value.data.len() as u8,
            data,
        }
    }
}

/// Command to control digital output exposed by the PD.
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandOutput {
    /// The output number this to apply this action.
    ///
    /// 0 - First Output
    /// 1 - Second Output
    /// ....
    pub output_no: u8,

    /// Control code instructs the operation to perform:
    ///
    /// 0 - NOP – do not alter this output
    /// 1 - set the permanent state to OFF, abort timed operation (if any)
    /// 2 - set the permanent state to ON, abort timed operation (if any)
    /// 3 - set the permanent state to OFF, allow timed operation to complete
    /// 4 - set the permanent state to ON, allow timed operation to complete
    /// 5 - set the temporary state to ON, resume perm state on timeout
    /// 6 - set the temporary state to OFF, resume permanent state on timeout
    pub control_code: u8,

    ///  Time in units of 100 ms
    pub timer_count: u16,
}

impl From<libosdp_sys::osdp_cmd_output> for OsdpCommandOutput {
    fn from(value: libosdp_sys::osdp_cmd_output) -> Self {
        OsdpCommandOutput {
            output_no: value.output_no,
            control_code: value.control_code,
            timer_count: value.timer_count,
        }
    }
}

impl From<OsdpCommandOutput> for libosdp_sys::osdp_cmd_output {
    fn from(value: OsdpCommandOutput) -> Self {
        libosdp_sys::osdp_cmd_output {
            output_no: value.output_no,
            control_code: value.control_code,
            timer_count: value.timer_count,
        }
    }
}

/// 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, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpComSet {
    /// 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 {
    fn from(value: libosdp_sys::osdp_cmd_comset) -> Self {
        OsdpComSet {
            address: value.address,
            baud_rate: value.baud_rate,
        }
    }
}

impl From<OsdpComSet> for libosdp_sys::osdp_cmd_comset {
    fn from(value: OsdpComSet) -> Self {
        libosdp_sys::osdp_cmd_comset {
            address: value.address,
            baud_rate: value.baud_rate,
        }
    }
}

/// Command to set secure channel keys to the PD.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct OsdpCommandKeyset {
    key_type: u8,
    /// Key data
    pub data: Vec<u8>,
}

impl OsdpCommandKeyset {
    /// Create a new SCBK KeySet command for a given key
    ///
    /// # Arguments
    ///
    /// * `key` - 16 bytes of secure channel base key
    pub fn new_scbk(key: [u8; 16]) -> Self {
        let data = key.to_vec();
        Self { key_type: 1, data }
    }
}

impl From<libosdp_sys::osdp_cmd_keyset> for OsdpCommandKeyset {
    fn from(value: libosdp_sys::osdp_cmd_keyset) -> Self {
        let n = value.length as usize;
        let data = value.data[0..n].to_vec();
        OsdpCommandKeyset {
            key_type: value.type_,
            data,
        }
    }
}

impl From<OsdpCommandKeyset> for libosdp_sys::osdp_cmd_keyset {
    fn from(value: OsdpCommandKeyset) -> Self {
        let mut data = [0; libosdp_sys::OSDP_CMD_KEYSET_KEY_MAX_LEN as usize];
        data[..value.data.len()].copy_from_slice(&value.data[..]);
        libosdp_sys::osdp_cmd_keyset {
            type_: value.key_type,
            length: value.data.len() as u8,
            data,
        }
    }
}

/// Command to to act as a wrapper for manufacturer specific commands
#[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),

    /// Command data (if any)
    pub data: Vec<u8>,
}

impl From<libosdp_sys::osdp_cmd_mfg> for OsdpCommandMfg {
    fn from(value: libosdp_sys::osdp_cmd_mfg) -> Self {
        let n = value.length as usize;
        let data = value.data[0..n].to_vec();
        let bytes = value.vendor_code.to_le_bytes();
        let vendor_code: (u8, u8, u8) = (bytes[0], bytes[1], bytes[2]);
        OsdpCommandMfg {
            vendor_code,
            data,
        }
    }
}

impl From<OsdpCommandMfg> for libosdp_sys::osdp_cmd_mfg {
    fn from(value: OsdpCommandMfg) -> Self {
        let mut data = [0; libosdp_sys::OSDP_CMD_MFG_MAX_DATALEN as usize];
        data[..value.data.len()].copy_from_slice(&value.data[..]);
        libosdp_sys::osdp_cmd_mfg {
            vendor_code: value.vendor_code.as_le(),
            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 {
    /// 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 {
    fn from(value: libosdp_sys::osdp_cmd_file_tx) -> Self {
        OsdpCommandFileTx {
            id: value.id,
            flags: value.flags,
        }
    }
}

impl From<OsdpCommandFileTx> for libosdp_sys::osdp_cmd_file_tx {
    fn from(value: OsdpCommandFileTx) -> Self {
        libosdp_sys::osdp_cmd_file_tx {
            id: value.id,
            flags: value.flags,
        }
    }
}

/// 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, Hash)]
pub enum OsdpCommand {
    /// Command to control the behavior of it’s on-board LEDs
    Led(OsdpCommandLed),

    /// Command to control the behavior of a buzzer in the PD
    Buzzer(OsdpCommandBuzzer),

    /// Command to manipulate the on-board display unit (Can be LED, LCD,
    /// 7-Segment, etc.,) on the PD
    Text(OsdpCommandText),

    /// Command to control digital output exposed by the PD
    Output(OsdpCommandOutput),

    /// 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),

    /// Command to to act as a wrapper for manufacturer specific commands
    Mfg(OsdpCommandMfg),

    /// Command to kick-off a file transfer to the PD
    FileTx(OsdpCommandFileTx),

    /// Command to query status from the PD
    Status(OsdpStatusReport),
}

impl From<OsdpCommand> for libosdp_sys::osdp_cmd {
    fn from(value: OsdpCommand) -> Self {
        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() },
            },
        }
    }
}

impl From<libosdp_sys::osdp_cmd> for OsdpCommand {
    fn from(value: libosdp_sys::osdp_cmd) -> Self {
        match value.id {
            libosdp_sys::osdp_cmd_e_OSDP_CMD_LED => {
                OsdpCommand::Led(unsafe { value.__bindgen_anon_1.led.into() })
            }
            libosdp_sys::osdp_cmd_e_OSDP_CMD_BUZZER => {
                OsdpCommand::Buzzer(unsafe { value.__bindgen_anon_1.buzzer.into() })
            }
            libosdp_sys::osdp_cmd_e_OSDP_CMD_TEXT => {
                OsdpCommand::Text(unsafe { value.__bindgen_anon_1.text.into() })
            }
            libosdp_sys::osdp_cmd_e_OSDP_CMD_OUTPUT => {
                OsdpCommand::Output(unsafe { value.__bindgen_anon_1.output.into() })
            }
            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() })
            }
            libosdp_sys::osdp_cmd_e_OSDP_CMD_MFG => {
                OsdpCommand::Mfg(unsafe { value.__bindgen_anon_1.mfg.into() })
            }
            libosdp_sys::osdp_cmd_e_OSDP_CMD_FILE_TX => {
                OsdpCommand::FileTx(unsafe { value.__bindgen_anon_1.file_tx.into() })
            }
            libosdp_sys::osdp_cmd_e_OSDP_CMD_STATUS => {
                OsdpCommand::Status(unsafe { value.__bindgen_anon_1.status.into() })
            }
            _ => panic!("Unknown event"),
        }
    }
}

#[cfg(test)]
mod tests {
    use crate::OsdpCommandMfg;
    use libosdp_sys::osdp_cmd_mfg;

    #[test]
    fn test_command_mfg() {
        let cmd = OsdpCommandMfg {
            vendor_code: (0x05, 0x07, 0x09),
            data: vec![0x55, 0xAA],
        };
        let cmd_struct: osdp_cmd_mfg = cmd.clone().into();

        assert_eq!(cmd_struct.vendor_code, 0x90705);
        assert_eq!(cmd_struct.length, 2);
        assert_eq!(cmd_struct.data[0], 0x55);
        assert_eq!(cmd_struct.data[1], 0xAA);

        assert_eq!(cmd, cmd_struct.into());
    }
}