sunspec/models/
model120.rs

1//! Nameplate
2/// Nameplate
3///
4/// Inverter Controls Nameplate Ratings
5///
6/// Notes: Ref 3: 8.14.3.2, Ref 4: 17
7#[derive(Debug)]
8#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
9pub struct Model120 {
10    /// DERTyp
11    ///
12    /// Type of DER device. Default value is 4 to indicate PV device.
13    pub der_typ: DerTyp,
14    /// WRtg
15    ///
16    /// Continuous power output capability of the inverter.
17    pub w_rtg: u16,
18    /// WRtg_SF
19    ///
20    /// Scale factor
21    pub w_rtg_sf: i16,
22    /// VARtg
23    ///
24    /// Continuous Volt-Ampere capability of the inverter.
25    pub va_rtg: u16,
26    /// VARtg_SF
27    ///
28    /// Scale factor
29    pub va_rtg_sf: i16,
30    /// VArRtgQ1
31    ///
32    /// Continuous VAR capability of the inverter in quadrant 1.
33    pub v_ar_rtg_q1: i16,
34    /// VArRtgQ2
35    ///
36    /// Continuous VAR capability of the inverter in quadrant 2.
37    pub v_ar_rtg_q2: i16,
38    /// VArRtgQ3
39    ///
40    /// Continuous VAR capability of the inverter in quadrant 3.
41    pub v_ar_rtg_q3: i16,
42    /// VArRtgQ4
43    ///
44    /// Continuous VAR capability of the inverter in quadrant 4.
45    pub v_ar_rtg_q4: i16,
46    /// VArRtg_SF
47    ///
48    /// Scale factor
49    pub v_ar_rtg_sf: i16,
50    /// ARtg
51    ///
52    /// Maximum RMS AC current level capability of the inverter.
53    ///
54    /// Notes: Sum of all connected phases.  Current rating under nominal voltage under nominal power factor.
55    pub a_rtg: u16,
56    /// ARtg_SF
57    ///
58    /// Scale factor
59    pub a_rtg_sf: i16,
60    /// PFRtgQ1
61    ///
62    /// Minimum power factor capability of the inverter in quadrant 1.
63    ///
64    /// Notes: EEI sign convention.
65    pub pf_rtg_q1: i16,
66    /// PFRtgQ2
67    ///
68    /// Minimum power factor capability of the inverter in quadrant 2.
69    ///
70    /// Notes: EEI sign convention.
71    pub pf_rtg_q2: i16,
72    /// PFRtgQ3
73    ///
74    /// Minimum power factor capability of the inverter in quadrant 3.
75    ///
76    /// Notes: EEI sign convention.
77    pub pf_rtg_q3: i16,
78    /// PFRtgQ4
79    ///
80    /// Minimum power factor capability of the inverter in quadrant 4.
81    ///
82    /// Notes: EEI sign convention.
83    pub pf_rtg_q4: i16,
84    /// PFRtg_SF
85    ///
86    /// Scale factor
87    pub pf_rtg_sf: i16,
88    /// WHRtg
89    ///
90    /// Nominal energy rating of storage device.
91    pub wh_rtg: Option<u16>,
92    /// WHRtg_SF
93    ///
94    /// Scale factor
95    pub wh_rtg_sf: Option<i16>,
96    /// AhrRtg
97    ///
98    /// The usable capacity of the battery.  Maximum charge minus minimum charge from a technology capability perspective (Amp-hour capacity rating).
99    pub ahr_rtg: Option<u16>,
100    /// AhrRtg_SF
101    ///
102    /// Scale factor for amp-hour rating.
103    pub ahr_rtg_sf: Option<i16>,
104    /// MaxChaRte
105    ///
106    /// Maximum rate of energy transfer into the storage device.
107    pub max_cha_rte: Option<u16>,
108    /// MaxChaRte_SF
109    ///
110    /// Scale factor
111    pub max_cha_rte_sf: Option<i16>,
112    /// MaxDisChaRte
113    ///
114    /// Maximum rate of energy transfer out of the storage device.
115    pub max_dis_cha_rte: Option<u16>,
116    /// MaxDisChaRte_SF
117    ///
118    /// Scale factor
119    pub max_dis_cha_rte_sf: Option<i16>,
120}
121#[allow(missing_docs)]
122impl Model120 {
123    pub const DER_TYP: crate::Point<Self, DerTyp> = crate::Point::new(0, 1, false);
124    pub const W_RTG: crate::Point<Self, u16> = crate::Point::new(1, 1, false);
125    pub const W_RTG_SF: crate::Point<Self, i16> = crate::Point::new(2, 1, false);
126    pub const VA_RTG: crate::Point<Self, u16> = crate::Point::new(3, 1, false);
127    pub const VA_RTG_SF: crate::Point<Self, i16> = crate::Point::new(4, 1, false);
128    pub const V_AR_RTG_Q1: crate::Point<Self, i16> = crate::Point::new(5, 1, false);
129    pub const V_AR_RTG_Q2: crate::Point<Self, i16> = crate::Point::new(6, 1, false);
130    pub const V_AR_RTG_Q3: crate::Point<Self, i16> = crate::Point::new(7, 1, false);
131    pub const V_AR_RTG_Q4: crate::Point<Self, i16> = crate::Point::new(8, 1, false);
132    pub const V_AR_RTG_SF: crate::Point<Self, i16> = crate::Point::new(9, 1, false);
133    pub const A_RTG: crate::Point<Self, u16> = crate::Point::new(10, 1, false);
134    pub const A_RTG_SF: crate::Point<Self, i16> = crate::Point::new(11, 1, false);
135    pub const PF_RTG_Q1: crate::Point<Self, i16> = crate::Point::new(12, 1, false);
136    pub const PF_RTG_Q2: crate::Point<Self, i16> = crate::Point::new(13, 1, false);
137    pub const PF_RTG_Q3: crate::Point<Self, i16> = crate::Point::new(14, 1, false);
138    pub const PF_RTG_Q4: crate::Point<Self, i16> = crate::Point::new(15, 1, false);
139    pub const PF_RTG_SF: crate::Point<Self, i16> = crate::Point::new(16, 1, false);
140    pub const WH_RTG: crate::Point<Self, Option<u16>> = crate::Point::new(17, 1, false);
141    pub const WH_RTG_SF: crate::Point<Self, Option<i16>> = crate::Point::new(18, 1, false);
142    pub const AHR_RTG: crate::Point<Self, Option<u16>> = crate::Point::new(19, 1, false);
143    pub const AHR_RTG_SF: crate::Point<Self, Option<i16>> = crate::Point::new(20, 1, false);
144    pub const MAX_CHA_RTE: crate::Point<Self, Option<u16>> = crate::Point::new(21, 1, false);
145    pub const MAX_CHA_RTE_SF: crate::Point<Self, Option<i16>> = crate::Point::new(22, 1, false);
146    pub const MAX_DIS_CHA_RTE: crate::Point<Self, Option<u16>> = crate::Point::new(23, 1, false);
147    pub const MAX_DIS_CHA_RTE_SF: crate::Point<Self, Option<i16>> = crate::Point::new(24, 1, false);
148}
149impl crate::Model for Model120 {
150    const ID: u16 = 120;
151    fn from_data(data: &[u16]) -> Result<Self, crate::DecodeError> {
152        Ok(Self {
153            der_typ: Self::DER_TYP.from_data(data)?,
154            w_rtg: Self::W_RTG.from_data(data)?,
155            w_rtg_sf: Self::W_RTG_SF.from_data(data)?,
156            va_rtg: Self::VA_RTG.from_data(data)?,
157            va_rtg_sf: Self::VA_RTG_SF.from_data(data)?,
158            v_ar_rtg_q1: Self::V_AR_RTG_Q1.from_data(data)?,
159            v_ar_rtg_q2: Self::V_AR_RTG_Q2.from_data(data)?,
160            v_ar_rtg_q3: Self::V_AR_RTG_Q3.from_data(data)?,
161            v_ar_rtg_q4: Self::V_AR_RTG_Q4.from_data(data)?,
162            v_ar_rtg_sf: Self::V_AR_RTG_SF.from_data(data)?,
163            a_rtg: Self::A_RTG.from_data(data)?,
164            a_rtg_sf: Self::A_RTG_SF.from_data(data)?,
165            pf_rtg_q1: Self::PF_RTG_Q1.from_data(data)?,
166            pf_rtg_q2: Self::PF_RTG_Q2.from_data(data)?,
167            pf_rtg_q3: Self::PF_RTG_Q3.from_data(data)?,
168            pf_rtg_q4: Self::PF_RTG_Q4.from_data(data)?,
169            pf_rtg_sf: Self::PF_RTG_SF.from_data(data)?,
170            wh_rtg: Self::WH_RTG.from_data(data)?,
171            wh_rtg_sf: Self::WH_RTG_SF.from_data(data)?,
172            ahr_rtg: Self::AHR_RTG.from_data(data)?,
173            ahr_rtg_sf: Self::AHR_RTG_SF.from_data(data)?,
174            max_cha_rte: Self::MAX_CHA_RTE.from_data(data)?,
175            max_cha_rte_sf: Self::MAX_CHA_RTE_SF.from_data(data)?,
176            max_dis_cha_rte: Self::MAX_DIS_CHA_RTE.from_data(data)?,
177            max_dis_cha_rte_sf: Self::MAX_DIS_CHA_RTE_SF.from_data(data)?,
178        })
179    }
180    fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
181        models.m120
182    }
183}
184/// DERTyp
185///
186/// Type of DER device. Default value is 4 to indicate PV device.
187#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
188#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
189#[repr(u16)]
190pub enum DerTyp {
191    #[allow(missing_docs)]
192    Pv = 4,
193    #[allow(missing_docs)]
194    PvStor = 82,
195}
196impl crate::Value for DerTyp {
197    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
198        let value = u16::decode(data)?;
199        Self::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)
200    }
201    fn encode(self) -> Box<[u16]> {
202        (self as u16).encode()
203    }
204}
205impl crate::Value for Option<DerTyp> {
206    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
207        let value = u16::decode(data)?;
208        if value != 65535 {
209            Ok(Some(
210                DerTyp::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)?,
211            ))
212        } else {
213            Ok(None)
214        }
215    }
216    fn encode(self) -> Box<[u16]> {
217        if let Some(value) = self {
218            value.encode()
219        } else {
220            65535.encode()
221        }
222    }
223}