sunspec/models/
model128.rs

1//! Dynamic Reactive Current
2/// Dynamic Reactive Current
3///
4/// Dynamic Reactive Current
5///
6/// Notes: Ref 3: 8.10.1.2; Ref 4: 12
7#[derive(Debug)]
8#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
9pub struct Model128 {
10    /// ArGraMod
11    ///
12    /// Indicates if gradients trend toward zero at the edges of the deadband or trend toward zero at the center of the deadband.
13    pub ar_gra_mod: ArGraMod,
14    /// ArGraSag
15    ///
16    /// The gradient used to increase capacitive dynamic current. A value of 0 indicates no additional reactive current support.
17    pub ar_gra_sag: u16,
18    /// ArGraSwell
19    ///
20    /// The gradient used to increase inductive dynamic current.  A value of 0 indicates no additional reactive current support.
21    pub ar_gra_swell: u16,
22    /// ModEna
23    ///
24    /// Activate dynamic reactive current model
25    pub mod_ena: ModEna,
26    /// FilTms
27    ///
28    /// The time window used to calculate the moving average voltage.
29    pub fil_tms: Option<u16>,
30    /// DbVMin
31    ///
32    /// The lower delta voltage limit for which negative voltage deviations less than this value no dynamic vars are produced.
33    pub db_v_min: Option<u16>,
34    /// DbVMax
35    ///
36    /// The upper delta voltage limit for which positive voltage deviations less than this value no dynamic current produced.
37    pub db_v_max: Option<u16>,
38    /// BlkZnV
39    ///
40    /// Block zone voltage which defines a lower voltage boundary below which no dynamic current is produced.
41    pub blk_zn_v: Option<u16>,
42    /// HysBlkZnV
43    ///
44    /// Hysteresis voltage used with BlkZnV.
45    pub hys_blk_zn_v: Option<u16>,
46    /// BlkZnTmms
47    ///
48    /// Block zone time the time before which reactive current support remains active regardless of how low the voltage drops.
49    pub blk_zn_tmms: Option<u16>,
50    /// HoldTmms
51    ///
52    /// Hold time during which reactive current support continues after the average voltage has entered the dead zone.
53    pub hold_tmms: Option<u16>,
54    /// ArGra_SF
55    ///
56    /// Scale factor for the gradients.
57    pub ar_gra_sf: i16,
58    /// VRefPct_SF
59    ///
60    /// Scale factor for the voltage zone and limit settings.
61    pub v_ref_pct_sf: Option<i16>,
62}
63#[allow(missing_docs)]
64impl Model128 {
65    pub const AR_GRA_MOD: crate::Point<Self, ArGraMod> = crate::Point::new(0, 1, true);
66    pub const AR_GRA_SAG: crate::Point<Self, u16> = crate::Point::new(1, 1, true);
67    pub const AR_GRA_SWELL: crate::Point<Self, u16> = crate::Point::new(2, 1, true);
68    pub const MOD_ENA: crate::Point<Self, ModEna> = crate::Point::new(3, 1, true);
69    pub const FIL_TMS: crate::Point<Self, Option<u16>> = crate::Point::new(4, 1, true);
70    pub const DB_V_MIN: crate::Point<Self, Option<u16>> = crate::Point::new(5, 1, true);
71    pub const DB_V_MAX: crate::Point<Self, Option<u16>> = crate::Point::new(6, 1, true);
72    pub const BLK_ZN_V: crate::Point<Self, Option<u16>> = crate::Point::new(7, 1, true);
73    pub const HYS_BLK_ZN_V: crate::Point<Self, Option<u16>> = crate::Point::new(8, 1, true);
74    pub const BLK_ZN_TMMS: crate::Point<Self, Option<u16>> = crate::Point::new(9, 1, true);
75    pub const HOLD_TMMS: crate::Point<Self, Option<u16>> = crate::Point::new(10, 1, true);
76    pub const AR_GRA_SF: crate::Point<Self, i16> = crate::Point::new(11, 1, false);
77    pub const V_REF_PCT_SF: crate::Point<Self, Option<i16>> = crate::Point::new(12, 1, false);
78}
79impl crate::Model for Model128 {
80    const ID: u16 = 128;
81    fn from_data(data: &[u16]) -> Result<Self, crate::DecodeError> {
82        Ok(Self {
83            ar_gra_mod: Self::AR_GRA_MOD.from_data(data)?,
84            ar_gra_sag: Self::AR_GRA_SAG.from_data(data)?,
85            ar_gra_swell: Self::AR_GRA_SWELL.from_data(data)?,
86            mod_ena: Self::MOD_ENA.from_data(data)?,
87            fil_tms: Self::FIL_TMS.from_data(data)?,
88            db_v_min: Self::DB_V_MIN.from_data(data)?,
89            db_v_max: Self::DB_V_MAX.from_data(data)?,
90            blk_zn_v: Self::BLK_ZN_V.from_data(data)?,
91            hys_blk_zn_v: Self::HYS_BLK_ZN_V.from_data(data)?,
92            blk_zn_tmms: Self::BLK_ZN_TMMS.from_data(data)?,
93            hold_tmms: Self::HOLD_TMMS.from_data(data)?,
94            ar_gra_sf: Self::AR_GRA_SF.from_data(data)?,
95            v_ref_pct_sf: Self::V_REF_PCT_SF.from_data(data)?,
96        })
97    }
98    fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
99        models.m128
100    }
101}
102/// ArGraMod
103///
104/// Indicates if gradients trend toward zero at the edges of the deadband or trend toward zero at the center of the deadband.
105#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
106#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
107#[repr(u16)]
108pub enum ArGraMod {
109    #[allow(missing_docs)]
110    Edge = 0,
111    #[allow(missing_docs)]
112    Center = 1,
113}
114impl crate::Value for ArGraMod {
115    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
116        let value = u16::decode(data)?;
117        Self::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)
118    }
119    fn encode(self) -> Box<[u16]> {
120        (self as u16).encode()
121    }
122}
123impl crate::Value for Option<ArGraMod> {
124    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
125        let value = u16::decode(data)?;
126        if value != 65535 {
127            Ok(Some(
128                ArGraMod::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)?,
129            ))
130        } else {
131            Ok(None)
132        }
133    }
134    fn encode(self) -> Box<[u16]> {
135        if let Some(value) = self {
136            value.encode()
137        } else {
138            65535.encode()
139        }
140    }
141}
142bitflags::bitflags! {
143    #[doc = " ModEna"] #[doc = " "] #[doc = " Activate dynamic reactive current model"]
144    #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde",
145    derive(::serde::Serialize, ::serde::Deserialize))] pub struct ModEna : u16 {
146    #[allow(missing_docs)] const Enabled = 1; }
147}
148impl crate::Value for ModEna {
149    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
150        let value = u16::decode(data)?;
151        Ok(Self::from_bits_retain(value))
152    }
153    fn encode(self) -> Box<[u16]> {
154        self.bits().encode()
155    }
156}
157impl crate::Value for Option<ModEna> {
158    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
159        let value = u16::decode(data)?;
160        if value != 65535u16 {
161            Ok(Some(ModEna::from_bits_retain(value)))
162        } else {
163            Ok(None)
164        }
165    }
166    fn encode(self) -> Box<[u16]> {
167        if let Some(value) = self {
168            value.encode()
169        } else {
170            65535u16.encode()
171        }
172    }
173}