Skip to main content

bacnet_types/constructed/
event_notification.rs

1//! The parameters of an event notification (Clauses 13.8 and 13.9) and its
2//! event values: what a notification service request carries and what an
3//! Event Log record holds (Clause 12.27.13). The encoding crate frames them on
4//! the wire.
5
6#[cfg(not(feature = "std"))]
7use alloc::{string::String, vec::Vec};
8
9use super::{
10    BACnetDeviceObjectPropertyReference, BACnetDeviceObjectReference, BACnetPropertyStates,
11    BACnetPropertyValue,
12};
13use crate::enums::{
14    AccessEvent, EventState, EventType, LifeSafetyMode, LifeSafetyOperation, LifeSafetyState,
15    NotifyType, Reliability, TimerState, TimerTransition,
16};
17use crate::primitives::{BACnetTimeStamp, Date, ObjectIdentifier, StatusFlags, Time};
18
19// ---------------------------------------------------------------------------
20// EventNotificationRequest
21// ---------------------------------------------------------------------------
22
23/// ConfirmedEventNotification / UnconfirmedEventNotification request parameters.
24///
25/// The same members, from the process identifier through the event values,
26/// make up the notification an Event Log record holds.
27#[derive(Debug, Clone, PartialEq)]
28pub struct EventNotificationRequest {
29    /// Process identifier of the notification recipient.
30    pub process_identifier: u32,
31    /// Device that generated the event.
32    pub initiating_device_identifier: ObjectIdentifier,
33    /// Object that triggered the event.
34    pub event_object_identifier: ObjectIdentifier,
35    /// Timestamp of the event transition.
36    pub timestamp: BACnetTimeStamp,
37    /// Notification class for routing.
38    pub notification_class: u32,
39    /// Priority (0-255).
40    pub priority: u8,
41    /// Event algorithm that produced the notification.
42    pub event_type: EventType,
43    /// Optional message text (\[7\]).
44    pub message_text: Option<String>,
45    /// Whether this is an alarm, an event, or an acknowledgment notification.
46    pub notify_type: NotifyType,
47    /// Whether the recipient must acknowledge.
48    pub ack_required: bool,
49    /// Event state before this transition. Not encoded for ACK_NOTIFICATION; decode sets
50    /// NORMAL when the field is absent.
51    pub from_state: EventState,
52    /// Event state after this transition.
53    pub to_state: EventState,
54    /// Optional event values (tag \[12\]).
55    pub event_values: Option<NotificationParameters>,
56}
57
58// ---------------------------------------------------------------------------
59// NotificationParameters
60// ---------------------------------------------------------------------------
61
62/// Notification parameter variants for eventValues.
63#[derive(Debug, Clone, PartialEq)]
64pub enum NotificationParameters {
65    /// \[0\] Change of bitstring.
66    ChangeOfBitstring {
67        /// Monitored bitstring value as `(unused_bits, data)`.
68        referenced_bitstring: (u8, Vec<u8>),
69        /// Status flags of the monitored object.
70        status_flags: StatusFlags,
71    },
72    /// \[1\] Change of state.
73    ChangeOfState {
74        /// New BACnetPropertyStates value that triggered the notification.
75        new_state: BACnetPropertyStates,
76        /// Status flags of the monitored object.
77        status_flags: StatusFlags,
78    },
79    /// \[2\] Change of value.
80    ChangeOfValue {
81        /// New value (changed bits or a REAL) that triggered the notification.
82        new_value: ChangeOfValueChoice,
83        /// Status flags of the monitored object.
84        status_flags: StatusFlags,
85    },
86    /// \[3\] Command failure. Value byte vectors contain encoded BACnet TLVs.
87    CommandFailure {
88        /// Commanded value as encoded BACnet bytes.
89        command_value: Vec<u8>,
90        /// Status flags of the monitored object.
91        status_flags: StatusFlags,
92        /// Feedback value that disagreed with the command, as encoded BACnet bytes.
93        feedback_value: Vec<u8>,
94    },
95    /// \[4\] Floating limit.
96    FloatingLimit {
97        /// Current value of the monitored property (not the setpoint reference).
98        reference_value: f32,
99        /// Status flags of the monitored object.
100        status_flags: StatusFlags,
101        /// Setpoint the reference value is tracked against.
102        setpoint_value: f32,
103        /// Differential limit (distance from the setpoint) that was exceeded.
104        error_limit: f32,
105    },
106    /// \[5\] Out of range.
107    OutOfRange {
108        /// Monitored value that crossed a limit.
109        exceeding_value: f32,
110        /// Status flags of the monitored object.
111        status_flags: StatusFlags,
112        /// Deadband applied to the limit comparison, in the monitored value's units.
113        deadband: f32,
114        /// The limit that was exceeded, in the monitored value's units.
115        exceeded_limit: f32,
116    },
117    /// \[6\] Complex event type.
118    ComplexEventType {
119        /// Reported property values; each holds encoded BACnet bytes and an optional priority.
120        property_values: Vec<BACnetPropertyValue>,
121    },
122    /// \[8\] Change of life safety.
123    ChangeOfLifeSafety {
124        /// Life safety state the object entered.
125        new_state: LifeSafetyState,
126        /// Life safety mode in effect.
127        new_mode: LifeSafetyMode,
128        /// Status flags of the monitored object.
129        status_flags: StatusFlags,
130        /// Operation the object expects from an operator.
131        operation_expected: LifeSafetyOperation,
132    },
133    /// \[9\] Extended (vendor-defined). `parameters` contains encoded BACnet TLVs.
134    Extended {
135        /// Vendor identifier that defines the extended event type.
136        vendor_id: u16,
137        /// Vendor-specific extended event type number.
138        extended_event_type: u32,
139        /// Vendor-defined parameters as encoded BACnet bytes.
140        parameters: Vec<u8>,
141    },
142    /// \[10\] Buffer ready.
143    BufferReady {
144        /// Reference to the log buffer property that has records ready.
145        buffer_property: BACnetDeviceObjectPropertyReference,
146        /// Total record count at the previous notification for this buffer.
147        previous_notification: u32,
148        /// Total record count now.
149        current_notification: u32,
150    },
151    /// \[11\] Unsigned range.
152    UnsignedRange {
153        /// Monitored value that crossed a limit.
154        exceeding_value: u64,
155        /// Status flags of the monitored object.
156        status_flags: StatusFlags,
157        /// The limit that was exceeded.
158        exceeded_limit: u64,
159    },
160    /// \[13\] Access event. Authentication-factor bytes contain its three inner context fields.
161    AccessEvent {
162        /// Access event describing what happened.
163        access_event: AccessEvent,
164        /// Status flags of the monitored object.
165        status_flags: StatusFlags,
166        /// Counter distinguishing access events, carried as the `access-event-tag` field.
167        access_event_tag: u32,
168        /// Time of the access event; a BACnetTimeStamp on the wire, of which only the date-time
169        /// choice is accepted.
170        access_event_time: (Date, Time),
171        /// Credential object (with optional device) that was presented.
172        access_credential: BACnetDeviceObjectReference,
173        /// Optional authentication factor as encoded BACnet bytes; `None` when absent.
174        authentication_factor: Option<Vec<u8>>,
175    },
176    /// \[14\] Double out of range.
177    DoubleOutOfRange {
178        /// Monitored value that crossed a limit.
179        exceeding_value: f64,
180        /// Status flags of the monitored object.
181        status_flags: StatusFlags,
182        /// Deadband applied to the limit comparison, in the monitored value's units.
183        deadband: f64,
184        /// The limit that was exceeded, in the monitored value's units.
185        exceeded_limit: f64,
186    },
187    /// \[15\] Signed out of range.
188    SignedOutOfRange {
189        /// Monitored value that crossed a limit.
190        exceeding_value: i32,
191        /// Status flags of the monitored object.
192        status_flags: StatusFlags,
193        /// Deadband applied to the limit comparison (unsigned).
194        deadband: u64,
195        /// The limit that was exceeded.
196        exceeded_limit: i32,
197    },
198    /// \[16\] Unsigned out of range.
199    UnsignedOutOfRange {
200        /// Monitored value that crossed a limit.
201        exceeding_value: u64,
202        /// Status flags of the monitored object.
203        status_flags: StatusFlags,
204        /// Deadband applied to the limit comparison.
205        deadband: u64,
206        /// The limit that was exceeded.
207        exceeded_limit: u64,
208    },
209    /// \[17\] Change of characterstring.
210    ChangeOfCharacterstring {
211        /// New value of the monitored character string.
212        changed_value: String,
213        /// Status flags of the monitored object.
214        status_flags: StatusFlags,
215        /// The configured alarm string that the new value matched.
216        alarm_value: String,
217    },
218    /// \[18\] Change of status flags. `present_value` preserves absent and present-empty context \[0\].
219    ChangeOfStatusFlags {
220        /// Present value as encoded BACnet bytes; `None` when the field is absent.
221        present_value: Option<Vec<u8>>,
222        /// Status flags of the referenced object.
223        referenced_flags: StatusFlags,
224    },
225    /// \[19\] Change of reliability. `property_values` contains encoded BACnet TLVs.
226    ChangeOfReliability {
227        /// Reliability value that triggered the notification.
228        reliability: Reliability,
229        /// Status flags of the monitored object.
230        status_flags: StatusFlags,
231        /// Properties relevant to the reliability change, as encoded BACnet bytes.
232        property_values: Vec<u8>,
233    },
234    /// \[21\] Change of discrete value. `new_value` contains encoded BACnet TLVs.
235    ChangeOfDiscreteValue {
236        /// New discrete value as encoded BACnet bytes.
237        new_value: Vec<u8>,
238        /// Status flags of the monitored object.
239        status_flags: StatusFlags,
240    },
241    /// \[22\] Change of timer.
242    ChangeOfTimer {
243        /// State the timer entered.
244        new_state: TimerState,
245        /// Status flags of the monitored object.
246        status_flags: StatusFlags,
247        /// Date and time of the timer update.
248        update_time: (Date, Time),
249        /// Transition of the last state change; `None` when absent.
250        last_state_change: Option<TimerTransition>,
251        /// Initial timeout configured for the timer; `None` when absent.
252        initial_timeout: Option<u32>,
253        /// Date and time when the timer expires; `None` when absent.
254        expiration_time: Option<(Date, Time)>,
255    },
256}
257
258/// CHOICE within ChangeOfValue notification parameters.
259#[derive(Debug, Clone, PartialEq)]
260pub enum ChangeOfValueChoice {
261    /// Bitstring value that changed.
262    ChangedBits {
263        /// Number of unused trailing bits in the last byte of `data`.
264        unused_bits: u8,
265        /// Bitstring content bytes.
266        data: Vec<u8>,
267    },
268    /// REAL value that changed.
269    ChangedValue(f32),
270}