sunspec/models/
model705.rs

1//! DER Volt-Var
2/// DER Volt-Var
3///
4/// DER Volt-Var model.
5#[derive(Debug)]
6#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
7pub struct Model705 {
8    /// DER Volt-Var Module Enable
9    ///
10    /// Volt-Var control enable.
11    pub ena: Ena,
12    /// Adopt Curve Request
13    ///
14    /// Index of curve points to adopt. First curve index is 1.
15    pub adpt_crv_req: u16,
16    /// Adopt Curve Result
17    ///
18    /// Result of last adopt curve operation.
19    pub adpt_crv_rslt: AdptCrvRslt,
20    /// Number Of Points
21    ///
22    /// Number of curve points supported.
23    pub n_pt: u16,
24    /// Stored Curve Count
25    ///
26    /// Number of stored curves supported.
27    pub n_crv: u16,
28    /// Reversion Timeout
29    ///
30    /// Reversion time in seconds.  0 = No reversion time.
31    pub rvrt_tms: Option<u32>,
32    /// Reversion Time Remaining
33    ///
34    /// Reversion time remaining in seconds.
35    pub rvrt_rem: Option<u32>,
36    /// Reversion Curve
37    ///
38    /// Default curve after reversion timeout.
39    pub rvrt_crv: Option<u16>,
40    /// Voltage Scale Factor
41    ///
42    /// Scale factor for curve voltage points.
43    pub v_sf: i16,
44    /// Var Scale Factor
45    ///
46    /// Scale factor for curve var points.
47    pub dept_ref_sf: i16,
48    /// Open-Loop Scale Factor
49    ///
50    /// Open loop response time scale factor.
51    pub rsp_tms_sf: i16,
52}
53#[allow(missing_docs)]
54impl Model705 {
55    pub const ENA: crate::Point<Self, Ena> = crate::Point::new(0, 1, true);
56    pub const ADPT_CRV_REQ: crate::Point<Self, u16> = crate::Point::new(1, 1, true);
57    pub const ADPT_CRV_RSLT: crate::Point<Self, AdptCrvRslt> = crate::Point::new(2, 1, false);
58    pub const N_PT: crate::Point<Self, u16> = crate::Point::new(3, 1, false);
59    pub const N_CRV: crate::Point<Self, u16> = crate::Point::new(4, 1, false);
60    pub const RVRT_TMS: crate::Point<Self, Option<u32>> = crate::Point::new(5, 2, true);
61    pub const RVRT_REM: crate::Point<Self, Option<u32>> = crate::Point::new(7, 2, false);
62    pub const RVRT_CRV: crate::Point<Self, Option<u16>> = crate::Point::new(9, 1, true);
63    pub const V_SF: crate::Point<Self, i16> = crate::Point::new(10, 1, false);
64    pub const DEPT_REF_SF: crate::Point<Self, i16> = crate::Point::new(11, 1, false);
65    pub const RSP_TMS_SF: crate::Point<Self, i16> = crate::Point::new(12, 1, false);
66}
67impl crate::Model for Model705 {
68    const ID: u16 = 705;
69    fn from_data(data: &[u16]) -> Result<Self, crate::DecodeError> {
70        Ok(Self {
71            ena: Self::ENA.from_data(data)?,
72            adpt_crv_req: Self::ADPT_CRV_REQ.from_data(data)?,
73            adpt_crv_rslt: Self::ADPT_CRV_RSLT.from_data(data)?,
74            n_pt: Self::N_PT.from_data(data)?,
75            n_crv: Self::N_CRV.from_data(data)?,
76            rvrt_tms: Self::RVRT_TMS.from_data(data)?,
77            rvrt_rem: Self::RVRT_REM.from_data(data)?,
78            rvrt_crv: Self::RVRT_CRV.from_data(data)?,
79            v_sf: Self::V_SF.from_data(data)?,
80            dept_ref_sf: Self::DEPT_REF_SF.from_data(data)?,
81            rsp_tms_sf: Self::RSP_TMS_SF.from_data(data)?,
82        })
83    }
84    fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
85        models.m705
86    }
87}
88/// DER Volt-Var Module Enable
89///
90/// Volt-Var control enable.
91#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
92#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
93#[repr(u16)]
94pub enum Ena {
95    /// Disabled
96    ///
97    /// Function is disabled.
98    Disabled = 0,
99    /// Enabled
100    ///
101    /// Function is enabled.
102    Enabled = 1,
103}
104impl crate::Value for Ena {
105    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
106        let value = u16::decode(data)?;
107        Self::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)
108    }
109    fn encode(self) -> Box<[u16]> {
110        (self as u16).encode()
111    }
112}
113impl crate::Value for Option<Ena> {
114    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
115        let value = u16::decode(data)?;
116        if value != 65535 {
117            Ok(Some(
118                Ena::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)?,
119            ))
120        } else {
121            Ok(None)
122        }
123    }
124    fn encode(self) -> Box<[u16]> {
125        if let Some(value) = self {
126            value.encode()
127        } else {
128            65535.encode()
129        }
130    }
131}
132/// Adopt Curve Result
133///
134/// Result of last adopt curve operation.
135#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
136#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
137#[repr(u16)]
138pub enum AdptCrvRslt {
139    /// Update In Progress
140    ///
141    /// Curve update in progress.
142    InProgress = 0,
143    /// Update Complete
144    ///
145    /// Curve update completed successfully.
146    Completed = 1,
147    /// Update Failed
148    ///
149    /// Curve update failed.
150    Failed = 2,
151}
152impl crate::Value for AdptCrvRslt {
153    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
154        let value = u16::decode(data)?;
155        Self::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)
156    }
157    fn encode(self) -> Box<[u16]> {
158        (self as u16).encode()
159    }
160}
161impl crate::Value for Option<AdptCrvRslt> {
162    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
163        let value = u16::decode(data)?;
164        if value != 65535 {
165            Ok(Some(
166                AdptCrvRslt::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)?,
167            ))
168        } else {
169            Ok(None)
170        }
171    }
172    fn encode(self) -> Box<[u16]> {
173        if let Some(value) = self {
174            value.encode()
175        } else {
176            65535.encode()
177        }
178    }
179}