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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/// Solar Module
///
/// A solar module model supporting DC-DC converter
///
/// Notes: Integer
#[derive(Debug)]
pub struct Model502 {
    /// Current scale factor
    pub a_sf: Option<i16>,
    /// Voltage scale factor
    pub v_sf: Option<i16>,
    /// Power scale factor
    pub w_sf: Option<i16>,
    /// Energy scale factor
    pub wh_sf: Option<i16>,
    /// Status
    ///
    /// Enumerated value.  Module Status Code
    pub stat: u16,
    /// Vendor Status
    ///
    /// Module Vendor Status Code
    pub statvend: Option<u16>,
    /// Events
    ///
    /// Bitmask value.  Module Event Flags
    pub evt: u32,
    /// Vendor Module Event Flags
    ///
    /// Vendor specific flags
    pub evtvend: Option<u32>,
    /// Control
    ///
    /// Module Control
    pub ctl: Option<u16>,
    /// Vendor Control
    ///
    /// Vendor Module Control
    pub ctlvend: Option<u32>,
    /// Control Value
    ///
    /// Module Control Value
    pub ctlval: Option<i32>,
    /// Timestamp
    ///
    /// Time in seconds since 2000 epoch
    pub tms: Option<u32>,
    /// Output Current
    ///
    /// Output Current
    pub outa: Option<i16>,
    /// Output Voltage
    ///
    /// Output Voltage
    pub outv: Option<i16>,
    /// Output Energy
    ///
    /// Output Energy
    pub outwh: Option<u32>,
    /// Output Power
    ///
    /// Output Power
    pub outpw: Option<i16>,
    /// Temp
    ///
    /// Module Temperature
    pub tmp: Option<i16>,
    /// Input Current
    ///
    /// Input Current
    pub ina: Option<i16>,
    /// Input Voltage
    ///
    /// Input Voltage
    pub inv: Option<i16>,
    /// Input Energy
    ///
    /// Input Energy
    pub inwh: Option<u32>,
    /// Input Power
    ///
    /// Input Power
    pub inw: Option<i16>,
}

#[allow(missing_docs)]

impl Model502 {
    pub const A_SF: crate::PointDef<Self, i16> = crate::PointDef::new(0, 1, false);
    pub const V_SF: crate::PointDef<Self, i16> = crate::PointDef::new(1, 1, false);
    pub const W_SF: crate::PointDef<Self, i16> = crate::PointDef::new(2, 1, false);
    pub const WH_SF: crate::PointDef<Self, i16> = crate::PointDef::new(3, 1, false);
    pub const STAT: crate::PointDef<Self, u16> = crate::PointDef::new(4, 1, false);
    pub const STATVEND: crate::PointDef<Self, u16> = crate::PointDef::new(5, 1, false);
    pub const EVT: crate::PointDef<Self, u32> = crate::PointDef::new(6, 2, false);
    pub const EVTVEND: crate::PointDef<Self, u32> = crate::PointDef::new(8, 2, false);
    pub const CTL: crate::PointDef<Self, u16> = crate::PointDef::new(10, 1, true);
    pub const CTLVEND: crate::PointDef<Self, u32> = crate::PointDef::new(11, 2, true);
    pub const CTLVAL: crate::PointDef<Self, i32> = crate::PointDef::new(13, 2, true);
    pub const TMS: crate::PointDef<Self, u32> = crate::PointDef::new(15, 2, false);
    pub const OUTA: crate::PointDef<Self, i16> = crate::PointDef::new(17, 1, false);
    pub const OUTV: crate::PointDef<Self, i16> = crate::PointDef::new(18, 1, false);
    pub const OUTWH: crate::PointDef<Self, u32> = crate::PointDef::new(19, 2, false);
    pub const OUTPW: crate::PointDef<Self, i16> = crate::PointDef::new(21, 1, false);
    pub const TMP: crate::PointDef<Self, i16> = crate::PointDef::new(22, 1, false);
    pub const INA: crate::PointDef<Self, i16> = crate::PointDef::new(23, 1, false);
    pub const INV: crate::PointDef<Self, i16> = crate::PointDef::new(24, 1, false);
    pub const INWH: crate::PointDef<Self, u32> = crate::PointDef::new(25, 2, false);
    pub const INW: crate::PointDef<Self, i16> = crate::PointDef::new(27, 1, false);
}

impl crate::Model for Model502 {
    const ID: u16 = 502;
    fn from_data(data: &[u16]) -> Result<Self, crate::ReadModelError> {
        Ok(Self {
            a_sf: Self::A_SF.from_data(data)?,
            v_sf: Self::V_SF.from_data(data)?,
            w_sf: Self::W_SF.from_data(data)?,
            wh_sf: Self::WH_SF.from_data(data)?,
            stat: Self::STAT
                .from_data(data)?
                .ok_or(crate::ReadPointError::MissingMandatoryValue)?,
            statvend: Self::STATVEND.from_data(data)?,
            evt: Self::EVT
                .from_data(data)?
                .ok_or(crate::ReadPointError::MissingMandatoryValue)?,
            evtvend: Self::EVTVEND.from_data(data)?,
            ctl: Self::CTL.from_data(data)?,
            ctlvend: Self::CTLVEND.from_data(data)?,
            ctlval: Self::CTLVAL.from_data(data)?,
            tms: Self::TMS.from_data(data)?,
            outa: Self::OUTA.from_data(data)?,
            outv: Self::OUTV.from_data(data)?,
            outwh: Self::OUTWH.from_data(data)?,
            outpw: Self::OUTPW.from_data(data)?,
            tmp: Self::TMP.from_data(data)?,
            ina: Self::INA.from_data(data)?,
            inv: Self::INV.from_data(data)?,
            inwh: Self::INWH.from_data(data)?,
            inw: Self::INW.from_data(data)?,
        })
    }
}