sunspec/models/
model715.rs

1//! DERCtl
2/// DERCtl
3///
4/// DER Control
5#[derive(Debug)]
6#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
7pub struct Model715 {
8    /// Control Mode
9    ///
10    /// DER control mode. Enumeration.
11    ///
12    /// Comments: DER Controls
13    pub loc_rem_ctl: Option<LocRemCtl>,
14    /// DER Heartbeat
15    ///
16    /// Value is incremented every second by the DER with periodic resets to zero.
17    pub der_hb: Option<u32>,
18    /// Controller Heartbeat
19    ///
20    /// Value is incremented every second by the controller with periodic resets to zero.
21    pub controller_hb: Option<u32>,
22    /// Alarm Reset
23    ///
24    /// Used to reset any latched alarms. 1 = Reset.
25    pub alarm_reset: Option<u16>,
26    /// Set Operation
27    ///
28    /// Commands to PCS. Enumerated value.
29    pub op_ctl: Option<OpCtl>,
30}
31#[allow(missing_docs)]
32impl Model715 {
33    pub const LOC_REM_CTL: crate::Point<Self, Option<LocRemCtl>> = crate::Point::new(0, 1, false);
34    pub const DER_HB: crate::Point<Self, Option<u32>> = crate::Point::new(1, 2, false);
35    pub const CONTROLLER_HB: crate::Point<Self, Option<u32>> = crate::Point::new(3, 2, true);
36    pub const ALARM_RESET: crate::Point<Self, Option<u16>> = crate::Point::new(5, 1, true);
37    pub const OP_CTL: crate::Point<Self, Option<OpCtl>> = crate::Point::new(6, 1, true);
38}
39impl crate::Model for Model715 {
40    const ID: u16 = 715;
41    fn from_data(data: &[u16]) -> Result<Self, crate::DecodeError> {
42        Ok(Self {
43            loc_rem_ctl: Self::LOC_REM_CTL.from_data(data)?,
44            der_hb: Self::DER_HB.from_data(data)?,
45            controller_hb: Self::CONTROLLER_HB.from_data(data)?,
46            alarm_reset: Self::ALARM_RESET.from_data(data)?,
47            op_ctl: Self::OP_CTL.from_data(data)?,
48        })
49    }
50    fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
51        models.m715
52    }
53}
54/// Control Mode
55///
56/// DER control mode. Enumeration.
57///
58/// Comments: DER Controls
59#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
60#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
61#[repr(u16)]
62pub enum LocRemCtl {
63    /// Remote Control
64    Remote = 0,
65    /// Local Control
66    ///
67    /// Local mode is required for manual/maintenance operations. Once invoked, it must be explicitly exited for the inverter to be controlled remotely.
68    Local = 1,
69}
70impl crate::Value for LocRemCtl {
71    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
72        let value = u16::decode(data)?;
73        Self::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)
74    }
75    fn encode(self) -> Box<[u16]> {
76        (self as u16).encode()
77    }
78}
79impl crate::Value for Option<LocRemCtl> {
80    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
81        let value = u16::decode(data)?;
82        if value != 65535 {
83            Ok(Some(
84                LocRemCtl::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)?,
85            ))
86        } else {
87            Ok(None)
88        }
89    }
90    fn encode(self) -> Box<[u16]> {
91        if let Some(value) = self {
92            value.encode()
93        } else {
94            65535.encode()
95        }
96    }
97}
98/// Set Operation
99///
100/// Commands to PCS. Enumerated value.
101#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
102#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
103#[repr(u16)]
104pub enum OpCtl {
105    /// Stop the DER
106    Stop = 0,
107    /// Start the DER
108    Start = 1,
109    /// Enter Standby Mode
110    EnterStandby = 2,
111    /// Exit Standby Mode
112    ExitStandby = 3,
113}
114impl crate::Value for OpCtl {
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<OpCtl> {
124    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
125        let value = u16::decode(data)?;
126        if value != 65535 {
127            Ok(Some(
128                OpCtl::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}