uhppote_rs/messages/
mod.rs1mod add_task;
2mod clear_task_list;
3mod clear_time_profiles;
4mod delete_card;
5mod delete_cards;
6mod get_card_by_id;
7mod get_card_by_index;
8mod get_cards;
9mod get_config;
10mod get_door_control_state;
11mod get_event;
12mod get_event_index;
13mod get_listener;
14mod get_status;
15mod get_time;
16mod get_time_profile;
17mod open_door;
18mod put_card;
19mod refresh_task_list;
20mod set_address;
21mod set_door_control_state;
22mod set_event_index;
23mod set_listener;
25mod set_record_special_events;
26mod set_time;
27mod set_time_profile;
28mod utils;
29
30pub use self::utils::request::Request;
31pub use self::utils::request::Response;
32pub use add_task::*;
33use anyhow::bail;
34pub use clear_task_list::*;
35pub use clear_time_profiles::*;
36pub use delete_card::*;
37pub use delete_cards::*;
38pub use get_card_by_id::*;
39pub use get_card_by_index::*;
40pub use get_cards::*;
41pub use get_config::*;
42pub use get_door_control_state::*;
43pub use get_event::*;
44pub use get_event_index::*;
45pub use get_listener::*;
46pub use get_status::*;
47pub use get_time::*;
48pub use get_time_profile::*;
49pub use open_door::*;
50pub use put_card::*;
51pub use refresh_task_list::*;
52pub use set_address::*;
53pub use set_door_control_state::*;
54pub use set_event_index::*;
55pub use set_listener::*;
57pub use set_record_special_events::*;
58pub use set_time::*;
59pub use set_time_profile::*;
60pub use utils::*;
61
62use uhppote_derive::Request;
63use uhppote_derive::Response;
64
65#[derive(Debug)]
66pub enum RequestResponseType {
67 Status = 0x20,
68 SetTime = 0x30,
69 GetTime = 0x32,
70 OpenDoor = 0x40,
71 PutCard = 0x50,
72 DeleteCard = 0x52,
73 DeleteCards = 0x54,
74 GetCards = 0x58,
75 GetCardByID = 0x5a,
76 GetCardByIndex = 0x5c,
77 SetDoorControlState = 0x80,
78 GetDoorControlState = 0x82,
79 SetTimeProfile = 0x88,
80 SetListener = 0x90,
81 GetListener = 0x92,
82 GetConfig = 0x94,
83 SetAddress = 0x96,
84 GetTimeProfile = 0x98,
85 ClearTaskList = 0xa6,
86 AddTask = 0xa8,
87 RefreshTaskList = 0xac,
89 GetEvent = 0xb0,
90 SetEventIndex = 0xb2,
91 GetEventIndex = 0xb4,
92 ClearTimeProfiles = 0x8a,
93 SetRecordSpecialEvents = 0x8e,
94}
95
96impl From<RequestResponseType> for u8 {
97 fn from(t: RequestResponseType) -> Self {
98 t as u8
99 }
100}
101
102impl TryFrom<u8> for RequestResponseType {
103 type Error = anyhow::Error;
104 fn try_from(value: u8) -> anyhow::Result<Self> {
105 match value {
106 0x20 => Ok(RequestResponseType::Status),
107 0x30 => Ok(RequestResponseType::SetTime),
108 0x32 => Ok(RequestResponseType::GetTime),
109 0x40 => Ok(RequestResponseType::OpenDoor),
110 0x50 => Ok(RequestResponseType::PutCard),
111 0x52 => Ok(RequestResponseType::DeleteCard),
112 0x54 => Ok(RequestResponseType::DeleteCards),
113 0x58 => Ok(RequestResponseType::GetCards),
114 0x5a => Ok(RequestResponseType::GetCardByID),
115 0x5c => Ok(RequestResponseType::GetCardByIndex),
116 0x80 => Ok(RequestResponseType::SetDoorControlState),
117 0x82 => Ok(RequestResponseType::GetDoorControlState),
118 0x88 => Ok(RequestResponseType::SetTimeProfile),
119 0x90 => Ok(RequestResponseType::SetListener),
120 0x92 => Ok(RequestResponseType::GetListener),
121 0x94 => Ok(RequestResponseType::GetConfig),
122 0x96 => Ok(RequestResponseType::SetAddress),
123 0x98 => Ok(RequestResponseType::GetTimeProfile),
124 0xa6 => Ok(RequestResponseType::ClearTaskList),
125 0xa8 => Ok(RequestResponseType::AddTask),
126 0xac => Ok(RequestResponseType::RefreshTaskList),
128 0xb0 => Ok(RequestResponseType::GetEvent),
129 0xb2 => Ok(RequestResponseType::SetEventIndex),
130 0xb4 => Ok(RequestResponseType::GetEventIndex),
131 0x8a => Ok(RequestResponseType::ClearTimeProfiles),
132 0x8e => Ok(RequestResponseType::SetRecordSpecialEvents),
133 _ => bail!("Invalid request type: {:x}", value),
134 }
135 }
136}
137
138pub const HEADER: u8 = 0x17;