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
use crate::app::measurement::*;
use crate::app::variations::{Group2Var3, Group4Var3};

impl Group2Var3 {
    pub(crate) fn to_measurement(self, cto: Option<Time>) -> BinaryInput {
        let flags = Flags::new(self.flags);
        BinaryInput {
            value: flags.state(),
            flags,
            time: cto.and_then(|x| x.checked_add(self.time)),
        }
    }
}

impl Group4Var3 {
    pub(crate) fn to_measurement(self, cto: Option<Time>) -> DoubleBitBinaryInput {
        let flags = Flags::new(self.flags);
        DoubleBitBinaryInput {
            value: flags.double_bit_state(),
            flags,
            time: cto.and_then(|x| x.checked_add(self.time)),
        }
    }
}

impl From<bool> for BinaryInput {
    fn from(x: bool) -> Self {
        Self {
            value: x,
            flags: Flags::ONLINE,
            time: None,
        }
    }
}

impl From<bool> for BinaryOutputStatus {
    fn from(x: bool) -> Self {
        Self {
            value: x,
            flags: Flags::ONLINE,
            time: None,
        }
    }
}

impl From<DoubleBit> for DoubleBitBinaryInput {
    fn from(x: DoubleBit) -> Self {
        Self {
            value: x,
            flags: Flags::ONLINE,
            time: None,
        }
    }
}