Skip to main content

sunspec/models/
model19.rs

1//! PPP Link
2/// PPP Link
3///
4/// Include this model to configure a Point-to-Point Protocol link
5#[derive(Debug)]
6#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
7pub struct Model19 {
8    /// Name
9    ///
10    /// Interface name
11    pub nam: Option<String>,
12    /// Rate
13    ///
14    /// Interface baud rate in bits per second
15    pub rte: u32,
16    /// Bits
17    ///
18    /// Number of data bits per character
19    pub bits: u16,
20    /// Parity
21    ///
22    /// Bitmask value.  Parity setting
23    pub pty: Pty,
24    /// Duplex
25    ///
26    /// Enumerated value.  Duplex mode
27    pub dup: Option<Dup>,
28    /// Flow Control
29    ///
30    /// Flow Control Method
31    pub flw: Option<Flw>,
32    /// Authentication
33    ///
34    /// Enumerated value.  Authentication method
35    pub auth: Option<Auth>,
36    /// Username
37    ///
38    /// Username for authentication
39    pub usr_nam: Option<String>,
40    /// Password
41    ///
42    /// Password for authentication
43    pub pw: Option<String>,
44}
45#[allow(missing_docs)]
46impl Model19 {
47    pub const NAM: crate::Point<Self, Option<String>> = crate::Point::new(0, 4, true);
48    pub const RTE: crate::Point<Self, u32> = crate::Point::new(4, 2, true);
49    pub const BITS: crate::Point<Self, u16> = crate::Point::new(6, 1, true);
50    pub const PTY: crate::Point<Self, Pty> = crate::Point::new(7, 1, true);
51    pub const DUP: crate::Point<Self, Option<Dup>> = crate::Point::new(8, 1, true);
52    pub const FLW: crate::Point<Self, Option<Flw>> = crate::Point::new(9, 1, true);
53    pub const AUTH: crate::Point<Self, Option<Auth>> = crate::Point::new(10, 1, false);
54    pub const USR_NAM: crate::Point<Self, Option<String>> = crate::Point::new(11, 12, false);
55    pub const PW: crate::Point<Self, Option<String>> = crate::Point::new(23, 6, false);
56}
57impl crate::Group for Model19 {
58    const LEN: u16 = 30;
59}
60impl Model19 {
61    fn parse_group(data: &[u16]) -> Result<(&[u16], Self), crate::DecodeError> {
62        let nested_data = data
63            .get(usize::from(<Self as crate::Group>::LEN)..)
64            .unwrap_or(&[]);
65        Ok((
66            nested_data,
67            Self {
68                nam: Self::NAM.from_data(data)?,
69                rte: Self::RTE.from_data(data)?,
70                bits: Self::BITS.from_data(data)?,
71                pty: Self::PTY.from_data(data)?,
72                dup: Self::DUP.from_data(data)?,
73                flw: Self::FLW.from_data(data)?,
74                auth: Self::AUTH.from_data(data)?,
75                usr_nam: Self::USR_NAM.from_data(data)?,
76                pw: Self::PW.from_data(data)?,
77            },
78        ))
79    }
80}
81/// Parity
82///
83/// Bitmask value.  Parity setting
84#[derive(Copy, Clone, Debug, Eq, PartialEq)]
85#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
86pub enum Pty {
87    #[allow(missing_docs)]
88    None,
89    #[allow(missing_docs)]
90    Odd,
91    #[allow(missing_docs)]
92    Even,
93    /// Raw enum value not defined by the SunSpec model.
94    Invalid(u16),
95}
96impl crate::EnumValue for Pty {
97    type Repr = u16;
98    const INVALID: Self::Repr = 65535;
99    fn from_repr(value: Self::Repr) -> Self {
100        match value {
101            0 => Self::None,
102            1 => Self::Odd,
103            2 => Self::Even,
104            value => Self::Invalid(value),
105        }
106    }
107    fn to_repr(self) -> Self::Repr {
108        match self {
109            Self::None => 0,
110            Self::Odd => 1,
111            Self::Even => 2,
112            Self::Invalid(value) => value,
113        }
114    }
115}
116impl crate::FixedSize for Pty {
117    const SIZE: u16 = 1u16;
118    const INVALID: Self = Self::Invalid(65535);
119    fn is_invalid(&self) -> bool {
120        matches!(self, Self::Invalid(_))
121    }
122}
123/// Duplex
124///
125/// Enumerated value.  Duplex mode
126#[derive(Copy, Clone, Debug, Eq, PartialEq)]
127#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
128pub enum Dup {
129    #[allow(missing_docs)]
130    Full,
131    #[allow(missing_docs)]
132    Half,
133    /// Raw enum value not defined by the SunSpec model.
134    Invalid(u16),
135}
136impl crate::EnumValue for Dup {
137    type Repr = u16;
138    const INVALID: Self::Repr = 65535;
139    fn from_repr(value: Self::Repr) -> Self {
140        match value {
141            0 => Self::Full,
142            1 => Self::Half,
143            value => Self::Invalid(value),
144        }
145    }
146    fn to_repr(self) -> Self::Repr {
147        match self {
148            Self::Full => 0,
149            Self::Half => 1,
150            Self::Invalid(value) => value,
151        }
152    }
153}
154impl crate::FixedSize for Dup {
155    const SIZE: u16 = 1u16;
156    const INVALID: Self = Self::Invalid(65535);
157    fn is_invalid(&self) -> bool {
158        matches!(self, Self::Invalid(_))
159    }
160}
161/// Flow Control
162///
163/// Flow Control Method
164#[derive(Copy, Clone, Debug, Eq, PartialEq)]
165#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
166pub enum Flw {
167    #[allow(missing_docs)]
168    None,
169    #[allow(missing_docs)]
170    Hw,
171    #[allow(missing_docs)]
172    Xonxoff,
173    /// Raw enum value not defined by the SunSpec model.
174    Invalid(u16),
175}
176impl crate::EnumValue for Flw {
177    type Repr = u16;
178    const INVALID: Self::Repr = 65535;
179    fn from_repr(value: Self::Repr) -> Self {
180        match value {
181            0 => Self::None,
182            1 => Self::Hw,
183            2 => Self::Xonxoff,
184            value => Self::Invalid(value),
185        }
186    }
187    fn to_repr(self) -> Self::Repr {
188        match self {
189            Self::None => 0,
190            Self::Hw => 1,
191            Self::Xonxoff => 2,
192            Self::Invalid(value) => value,
193        }
194    }
195}
196impl crate::FixedSize for Flw {
197    const SIZE: u16 = 1u16;
198    const INVALID: Self = Self::Invalid(65535);
199    fn is_invalid(&self) -> bool {
200        matches!(self, Self::Invalid(_))
201    }
202}
203/// Authentication
204///
205/// Enumerated value.  Authentication method
206#[derive(Copy, Clone, Debug, Eq, PartialEq)]
207#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
208pub enum Auth {
209    #[allow(missing_docs)]
210    None,
211    #[allow(missing_docs)]
212    Pap,
213    #[allow(missing_docs)]
214    Chap,
215    /// Raw enum value not defined by the SunSpec model.
216    Invalid(u16),
217}
218impl crate::EnumValue for Auth {
219    type Repr = u16;
220    const INVALID: Self::Repr = 65535;
221    fn from_repr(value: Self::Repr) -> Self {
222        match value {
223            0 => Self::None,
224            1 => Self::Pap,
225            2 => Self::Chap,
226            value => Self::Invalid(value),
227        }
228    }
229    fn to_repr(self) -> Self::Repr {
230        match self {
231            Self::None => 0,
232            Self::Pap => 1,
233            Self::Chap => 2,
234            Self::Invalid(value) => value,
235        }
236    }
237}
238impl crate::FixedSize for Auth {
239    const SIZE: u16 = 1u16;
240    const INVALID: Self = Self::Invalid(65535);
241    fn is_invalid(&self) -> bool {
242        matches!(self, Self::Invalid(_))
243    }
244}
245impl crate::Model for Model19 {
246    const ID: u16 = 19;
247    fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
248        models.m19
249    }
250    fn parse(data: &[u16]) -> Result<Self, crate::ParseError<Self>> {
251        let (_, model) = Self::parse_group(data)?;
252        Ok(model)
253    }
254}