Skip to main content

bacnet_types/constructed/
lighting.rs

1//! The constructed value of a Lighting Output's Lighting_Command (Clause
2//! 12.54).
3
4use crate::enums::LightingOperation;
5
6/// `BACnetLightingCommand` (Clause 21): a lighting operation and the
7/// parameters it may carry.
8///
9/// A Lighting Output serves the last one written as Lighting_Command, and a
10/// Channel can pass one to its members (Clause 12.53). On the wire it is a
11/// SEQUENCE of primitive context tags in ascending order: the operation `[0]`,
12/// then whichever of the target level `[1]`, ramp rate `[2]`, step increment
13/// `[3]` (each a REAL), fade time `[4]` and priority `[5]` (each an Unsigned)
14/// are present. The `bacnet-encoding` crate owns the codec.
15///
16/// The type holds any values that fit its fields. Which fields an operation
17/// uses, and their ranges, are for the object that takes the command to
18/// check; a Lighting Output does so on every write (Table 12-67).
19///
20/// ```
21/// use bacnet_types::constructed::BACnetLightingCommand;
22/// use bacnet_types::enums::LightingOperation;
23///
24/// // Fade to 40 % over two seconds at priority 8.
25/// let fade = BACnetLightingCommand {
26///     target_level: Some(40.0),
27///     fade_time: Some(2_000),
28///     priority: Some(8),
29///     ..BACnetLightingCommand::new(LightingOperation::FADE_TO)
30/// };
31/// assert_eq!(fade.ramp_rate, None);
32/// ```
33#[derive(Debug, Clone, Copy, PartialEq)]
34pub struct BACnetLightingCommand {
35    /// Context tag 0: the operation requested.
36    pub operation: LightingOperation,
37    /// Context tag 1: the level to fade or ramp to, in percent.
38    pub target_level: Option<f32>,
39    /// Context tag 2: the ramp rate, in percent per second.
40    pub ramp_rate: Option<f32>,
41    /// Context tag 3: the amount a step changes the level by, in percent.
42    pub step_increment: Option<f32>,
43    /// Context tag 4: how long a fade takes, in milliseconds.
44    pub fade_time: Option<u32>,
45    /// Context tag 5: the priority the command acts at, 1 (highest) to 16.
46    pub priority: Option<u8>,
47}
48
49impl BACnetLightingCommand {
50    /// A command for `operation` that carries no other field.
51    pub const fn new(operation: LightingOperation) -> Self {
52        Self {
53            operation,
54            target_level: None,
55            ramp_rate: None,
56            step_increment: None,
57            fade_time: None,
58            priority: None,
59        }
60    }
61}