Skip to main content

sunspec/models/
model703.rs

1//! Enter Service
2/// Type alias for [`DerEnterService`].
3pub type Model703 = DerEnterService;
4/// Enter Service
5///
6/// Enter service model.
7#[derive(Debug)]
8#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
9pub struct DerEnterService {
10    /// Permit Enter Service
11    ///
12    /// Permit enter service.
13    pub es: Option<Es>,
14    /// Enter Service Voltage High
15    ///
16    /// Enter service voltage high threshold as percent of normal voltage.
17    pub esv_hi: Option<u16>,
18    /// Enter Service Voltage Low
19    ///
20    /// Enter service voltage low threshold as percent of normal voltage.
21    pub esv_lo: Option<u16>,
22    /// Enter Service Frequency High
23    ///
24    /// Enter service frequency high threshold.
25    pub es_hz_hi: Option<u32>,
26    /// Enter Service Frequency Low
27    ///
28    /// Enter service frequency low threshold.
29    pub es_hz_lo: Option<u32>,
30    /// Enter Service Delay Time
31    ///
32    /// Enter service delay time in seconds.
33    pub es_dly_tms: Option<u32>,
34    /// Enter Service Random Delay
35    ///
36    /// Enter service random delay in seconds.
37    pub es_rnd_tms: Option<u32>,
38    /// Enter Service Ramp Time
39    ///
40    /// Enter service ramp time in seconds.
41    pub es_rmp_tms: Option<u32>,
42    /// Enter Service Delay Remaining
43    ///
44    /// Enter service delay time remaining in seconds.
45    pub es_dly_rem_tms: Option<u32>,
46    /// Voltage Scale Factor
47    ///
48    /// Voltage percentage scale factor.
49    pub v_sf: Option<i16>,
50    /// Frequency Scale Factor
51    ///
52    /// Frequency scale factor.
53    pub hz_sf: Option<i16>,
54}
55#[allow(missing_docs)]
56impl DerEnterService {
57    pub const ES: crate::Point<Self, Option<Es>> = crate::Point::new(0, 1, true);
58    pub const ESV_HI: crate::Point<Self, Option<u16>> = crate::Point::new(1, 1, true);
59    pub const ESV_LO: crate::Point<Self, Option<u16>> = crate::Point::new(2, 1, true);
60    pub const ES_HZ_HI: crate::Point<Self, Option<u32>> = crate::Point::new(3, 2, true);
61    pub const ES_HZ_LO: crate::Point<Self, Option<u32>> = crate::Point::new(5, 2, true);
62    pub const ES_DLY_TMS: crate::Point<Self, Option<u32>> = crate::Point::new(7, 2, true);
63    pub const ES_RND_TMS: crate::Point<Self, Option<u32>> = crate::Point::new(9, 2, true);
64    pub const ES_RMP_TMS: crate::Point<Self, Option<u32>> = crate::Point::new(11, 2, true);
65    pub const ES_DLY_REM_TMS: crate::Point<Self, Option<u32>> = crate::Point::new(13, 2, false);
66    pub const V_SF: crate::Point<Self, Option<i16>> = crate::Point::new(15, 1, false);
67    pub const HZ_SF: crate::Point<Self, Option<i16>> = crate::Point::new(16, 1, false);
68}
69impl crate::Group for DerEnterService {
70    const LEN: u16 = 17;
71}
72impl DerEnterService {
73    fn parse_group(data: &[u16]) -> Result<(&[u16], Self), crate::DecodeError> {
74        let nested_data = data
75            .get(usize::from(<Self as crate::Group>::LEN)..)
76            .unwrap_or(&[]);
77        Ok((
78            nested_data,
79            Self {
80                es: Self::ES.from_data(data)?,
81                esv_hi: Self::ESV_HI.from_data(data)?,
82                esv_lo: Self::ESV_LO.from_data(data)?,
83                es_hz_hi: Self::ES_HZ_HI.from_data(data)?,
84                es_hz_lo: Self::ES_HZ_LO.from_data(data)?,
85                es_dly_tms: Self::ES_DLY_TMS.from_data(data)?,
86                es_rnd_tms: Self::ES_RND_TMS.from_data(data)?,
87                es_rmp_tms: Self::ES_RMP_TMS.from_data(data)?,
88                es_dly_rem_tms: Self::ES_DLY_REM_TMS.from_data(data)?,
89                v_sf: Self::V_SF.from_data(data)?,
90                hz_sf: Self::HZ_SF.from_data(data)?,
91            },
92        ))
93    }
94}
95/// Permit Enter Service
96///
97/// Permit enter service.
98#[derive(Copy, Clone, Debug, Eq, PartialEq)]
99#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
100pub enum Es {
101    #[allow(missing_docs)]
102    Disabled,
103    #[allow(missing_docs)]
104    Enabled,
105    /// Raw enum value not defined by the SunSpec model.
106    Invalid(u16),
107}
108impl crate::EnumValue for Es {
109    type Repr = u16;
110    const INVALID: Self::Repr = 65535;
111    fn from_repr(value: Self::Repr) -> Self {
112        match value {
113            0 => Self::Disabled,
114            1 => Self::Enabled,
115            value => Self::Invalid(value),
116        }
117    }
118    fn to_repr(self) -> Self::Repr {
119        match self {
120            Self::Disabled => 0,
121            Self::Enabled => 1,
122            Self::Invalid(value) => value,
123        }
124    }
125}
126impl crate::FixedSize for Es {
127    const SIZE: u16 = 1u16;
128    const INVALID: Self = Self::Invalid(65535);
129    fn is_invalid(&self) -> bool {
130        matches!(self, Self::Invalid(_))
131    }
132}
133impl crate::Model for DerEnterService {
134    const ID: u16 = 703;
135    fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
136        models.m703
137    }
138    fn parse(data: &[u16]) -> Result<Self, crate::ParseError<Self>> {
139        let (_, model) = Self::parse_group(data)?;
140        Ok(model)
141    }
142}