sunspec/models/
model16.rs1#[derive(Debug)]
6#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
7pub struct Model16 {
8 pub nam: Option<String>,
12 pub cfg: Cfg,
16 pub ctl: Ctl,
20 pub addr: String,
24 pub msk: String,
28 pub gw: Option<String>,
32 pub dns1: Option<String>,
36 pub dns2: Option<String>,
40 pub mac: Option<String>,
44 pub lnk_ctl: Option<LnkCtl>,
48}
49#[allow(missing_docs)]
50impl Model16 {
51 pub const NAM: crate::Point<Self, Option<String>> = crate::Point::new(0, 4, true);
52 pub const CFG: crate::Point<Self, Cfg> = crate::Point::new(4, 1, false);
53 pub const CTL: crate::Point<Self, Ctl> = crate::Point::new(5, 1, true);
54 pub const ADDR: crate::Point<Self, String> = crate::Point::new(6, 8, true);
55 pub const MSK: crate::Point<Self, String> = crate::Point::new(14, 8, true);
56 pub const GW: crate::Point<Self, Option<String>> = crate::Point::new(22, 8, true);
57 pub const DNS1: crate::Point<Self, Option<String>> = crate::Point::new(30, 8, true);
58 pub const DNS2: crate::Point<Self, Option<String>> = crate::Point::new(38, 8, true);
59 pub const MAC: crate::Point<Self, Option<String>> = crate::Point::new(46, 4, false);
60 pub const LNK_CTL: crate::Point<Self, Option<LnkCtl>> = crate::Point::new(50, 1, true);
61}
62impl crate::Model for Model16 {
63 const ID: u16 = 16;
64 fn from_data(data: &[u16]) -> Result<Self, crate::DecodeError> {
65 Ok(Self {
66 nam: Self::NAM.from_data(data)?,
67 cfg: Self::CFG.from_data(data)?,
68 ctl: Self::CTL.from_data(data)?,
69 addr: Self::ADDR.from_data(data)?,
70 msk: Self::MSK.from_data(data)?,
71 gw: Self::GW.from_data(data)?,
72 dns1: Self::DNS1.from_data(data)?,
73 dns2: Self::DNS2.from_data(data)?,
74 mac: Self::MAC.from_data(data)?,
75 lnk_ctl: Self::LNK_CTL.from_data(data)?,
76 })
77 }
78 fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
79 models.m16
80 }
81}
82#[derive(Copy, Clone, Debug, Eq, PartialEq, strum::FromRepr)]
86#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
87#[repr(u16)]
88pub enum Cfg {
89 #[allow(missing_docs)]
90 Static = 0,
91 #[allow(missing_docs)]
92 Dhcp = 1,
93}
94impl crate::Value for Cfg {
95 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
96 let value = u16::decode(data)?;
97 Self::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)
98 }
99 fn encode(self) -> Box<[u16]> {
100 (self as u16).encode()
101 }
102}
103impl crate::Value for Option<Cfg> {
104 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
105 let value = u16::decode(data)?;
106 if value != 65535 {
107 Ok(Some(
108 Cfg::from_repr(value).ok_or(crate::DecodeError::InvalidEnumValue)?,
109 ))
110 } else {
111 Ok(None)
112 }
113 }
114 fn encode(self) -> Box<[u16]> {
115 if let Some(value) = self {
116 value.encode()
117 } else {
118 65535.encode()
119 }
120 }
121}
122bitflags::bitflags! {
123 #[doc = " Control"] #[doc = " "] #[doc = " Bitmask value Configure use of services"]
124 #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde",
125 derive(::serde::Serialize, ::serde::Deserialize))] pub struct Ctl : u16 {
126 #[allow(missing_docs)] const EnableDns = 1; #[allow(missing_docs)] const EnableNtp =
127 2; }
128}
129impl crate::Value for Ctl {
130 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
131 let value = u16::decode(data)?;
132 Ok(Self::from_bits_retain(value))
133 }
134 fn encode(self) -> Box<[u16]> {
135 self.bits().encode()
136 }
137}
138impl crate::Value for Option<Ctl> {
139 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
140 let value = u16::decode(data)?;
141 if value != 65535u16 {
142 Ok(Some(Ctl::from_bits_retain(value)))
143 } else {
144 Ok(None)
145 }
146 }
147 fn encode(self) -> Box<[u16]> {
148 if let Some(value) = self {
149 value.encode()
150 } else {
151 65535u16.encode()
152 }
153 }
154}
155bitflags::bitflags! {
156 #[doc = " Link Control"] #[doc = " "] #[doc = " Bitmask value. Link control flags"]
157 #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde",
158 derive(::serde::Serialize, ::serde::Deserialize))] pub struct LnkCtl : u16 {
159 #[allow(missing_docs)] const Autonegotiate = 1; #[allow(missing_docs)] const
160 FullDuplex = 2; #[allow(missing_docs)] const Force10mb = 4; #[allow(missing_docs)]
161 const Force100mb = 8; #[allow(missing_docs)] const Force1gb = 16; }
162}
163impl crate::Value for LnkCtl {
164 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
165 let value = u16::decode(data)?;
166 Ok(Self::from_bits_retain(value))
167 }
168 fn encode(self) -> Box<[u16]> {
169 self.bits().encode()
170 }
171}
172impl crate::Value for Option<LnkCtl> {
173 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
174 let value = u16::decode(data)?;
175 if value != 65535u16 {
176 Ok(Some(LnkCtl::from_bits_retain(value)))
177 } else {
178 Ok(None)
179 }
180 }
181 fn encode(self) -> Box<[u16]> {
182 if let Some(value) = self {
183 value.encode()
184 } else {
185 65535u16.encode()
186 }
187 }
188}