open_protocol/messages/
alarm.rs

1use chrono::{DateTime, Local};
2use open_protocol_codec_proc_macro::{OpenProtocolDecode, OpenProtocolEncode, OpenProtocolMessage};
3
4#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode)]
5pub enum ToolReadyStatus {
6    #[default]
7    #[open_protocol_value(number = 0)]
8    NOK,
9    #[open_protocol_value(number = 1)]
10    OK
11}
12
13#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode)]
14pub enum ControllerReadyStatus {
15    #[default]
16    #[open_protocol_value(number = 0)]
17    NOK,
18    #[open_protocol_value(number = 1)]
19    OK
20}
21
22#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode)]
23pub enum AlarmStatus {
24    #[default]
25    #[open_protocol_value(number = 0)]
26    NoAlarm,
27    #[open_protocol_value(number = 1)]
28    AlarmActive
29}
30
31/// A subscription request for alarms in the controller.
32#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
33#[open_protocol_message(MID = 70, revision = 1)]
34pub struct MID0070rev1 {
35    // No additional fields for this MID.
36}
37
38/// This message is sent when an alarm appears in the controller.
39/// It includes the alarm code, controller/tool status, and timestamp.
40#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
41#[open_protocol_message(MID = 71, revision = 1)]
42pub struct MID0071rev1 {
43    /// The alarm error code.
44    #[open_protocol_field(length = 4)]
45    pub error_code: String,
46
47    /// Controller ready status (1=OK, 0=NOK).
48    #[open_protocol_field(length = 1)]
49    pub controller_ready_status: ControllerReadyStatus,
50
51    /// Tool ready status (1=OK, 0=NOK).
52    #[open_protocol_field(length = 1)]
53    pub tool_ready_status: ToolReadyStatus,
54
55    /// Timestamp for the alarm (YYYY-MM-DD:HH:MM:SS).
56    #[open_protocol_field(length = 19)]
57    pub timestamp: DateTime<Local>,
58}
59
60/// Acknowledgment for MID 0071 Alarm.
61#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
62#[open_protocol_message(MID = 72, revision = 1)]
63pub struct MID0072rev1 {
64    // No additional fields for this MID.
65}
66
67/// Cancels a previously subscribed alarm notification.
68#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
69#[open_protocol_message(MID = 73, revision = 1)]
70pub struct MID0073rev1 {
71    // No additional fields for this MID.
72}
73
74/// The controller informs that the alarm has been acknowledged.
75#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
76#[open_protocol_message(MID = 74, revision = 1)]
77pub struct MID0074rev1 {
78    /// The alarm error code that was acknowledged.
79    #[open_protocol_field(length = 4)]
80    pub error_code: String,
81}
82
83/// Acknowledges receipt of MID 0074 Alarm Acknowledged on Controller.
84#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
85#[open_protocol_message(MID = 75, revision = 1)]
86pub struct MID0075rev1 {
87    // No additional fields for this MID.
88}
89
90/// Provides the status of an alarm after subscription.
91/// This message is used to inform the integrator of active alarms.
92#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
93#[open_protocol_message(MID = 76, revision = 1)]
94pub struct MID0076rev1 {
95    /// Alarm status (0=no alarm, 1=alarm active).
96    #[open_protocol_field(length = 1)]
97    pub alarm_status: AlarmStatus,
98
99    /// The alarm error code.
100    #[open_protocol_field(length = 4)]
101    pub error_code: String,
102
103    /// Controller ready status (1=OK, 0=NOK).
104    #[open_protocol_field(length = 1)]
105    pub controller_ready_status: ControllerReadyStatus,
106
107    /// Tool ready status (1=OK, 0=NOK).
108    #[open_protocol_field(length = 1)]
109    pub tool_ready_status: ToolReadyStatus,
110
111    /// Timestamp of the alarm (YYYY-MM-DD:HH:MM:SS).
112    #[open_protocol_field(length = 19)]
113    pub timestamp: DateTime<Local>,
114}
115
116/// Acknowledges receipt of MID 0076 Alarm Status.
117#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
118#[open_protocol_message(MID = 77, revision = 1)]
119pub struct MID0077rev1 {
120    // No additional fields for this MID.
121}
122
123/// The integrator remotely acknowledges the current alarm on the controller.
124#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
125#[open_protocol_message(MID = 78, revision = 1)]
126pub struct MID0078rev1 {
127    /// The alarm error code to acknowledge remotely.
128    #[open_protocol_field(length = 4)]
129    pub error_code: String,
130}
131
132/// An alarm has appeared in the controller.
133/// This message replaces the old MID 0071.
134#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
135#[open_protocol_message(MID = 1000, revision = 1)]
136pub struct MID1000rev1 {
137    /// The alarm error code.
138    #[open_protocol_field(length = 5)]
139    pub error_code: String,
140
141    /// Timestamp for the alarm (YYYY-MM-DD:HH:MM:SS).
142    #[open_protocol_field(length = 19)]
143    pub timestamp: DateTime<Local>,
144
145    /// The number of variable data fields included in this message.
146    #[open_protocol_field(length = 3)]
147    pub number_of_data_fields: u16,
148
149    /// The variable data fields associated with the alarm.
150    #[open_protocol_field(list, amount = "number_of_data_fields")]
151    pub data_fields: Vec<u8>,
152}
153
154/// Acknowledges receipt of MID 1000 Alarm.
155#[derive(Debug, Default, Eq, PartialEq, OpenProtocolEncode, OpenProtocolDecode, OpenProtocolMessage)]
156#[open_protocol_message(MID = 1001, revision = 1)]
157pub struct MID1001rev1 {
158    // No additional fields for this MID.
159}