Skip to main content

sunspec/models/
model63001.rs

1//! SunSpec Test Model 1
2/// SunSpec Test Model 1
3#[derive(Debug)]
4#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
5pub struct Model63001 {
6    #[allow(missing_docs)]
7    pub sunssf_1: Option<i16>,
8    #[allow(missing_docs)]
9    pub sunssf_2: Option<i16>,
10    #[allow(missing_docs)]
11    pub sunssf_3: Option<i16>,
12    #[allow(missing_docs)]
13    pub sunssf_4: Option<i16>,
14    #[allow(missing_docs)]
15    pub int16_1: Option<i16>,
16    #[allow(missing_docs)]
17    pub int16_2: Option<i16>,
18    #[allow(missing_docs)]
19    pub int16_3: Option<i16>,
20    #[allow(missing_docs)]
21    pub int16_4: Option<i16>,
22    #[allow(missing_docs)]
23    pub int16_5: Option<i16>,
24    #[allow(missing_docs)]
25    pub int16_u: Option<i16>,
26    #[allow(missing_docs)]
27    pub uint16_1: Option<u16>,
28    #[allow(missing_docs)]
29    pub uint16_2: Option<u16>,
30    #[allow(missing_docs)]
31    pub uint16_3: Option<u16>,
32    #[allow(missing_docs)]
33    pub uint16_4: Option<u16>,
34    #[allow(missing_docs)]
35    pub uint16_5: Option<u16>,
36    #[allow(missing_docs)]
37    pub uint16_u: Option<u16>,
38    #[allow(missing_docs)]
39    pub acc16: Option<u16>,
40    #[allow(missing_docs)]
41    pub acc16_u: Option<u16>,
42    #[allow(missing_docs)]
43    pub enum16: Option<u16>,
44    #[allow(missing_docs)]
45    pub enum16_u: Option<u16>,
46    #[allow(missing_docs)]
47    pub bitfield16: Option<Bitfield16>,
48    #[allow(missing_docs)]
49    pub bitfield16_u: Option<Bitfield16U>,
50    #[allow(missing_docs)]
51    pub int32_1: Option<i32>,
52    #[allow(missing_docs)]
53    pub int32_2: Option<i32>,
54    #[allow(missing_docs)]
55    pub int32_3: Option<i32>,
56    #[allow(missing_docs)]
57    pub int32_4: Option<i32>,
58    #[allow(missing_docs)]
59    pub int32_5: Option<i32>,
60    #[allow(missing_docs)]
61    pub int32_u: Option<i32>,
62    #[allow(missing_docs)]
63    pub uint32_1: Option<u32>,
64    #[allow(missing_docs)]
65    pub uint32_2: Option<u32>,
66    #[allow(missing_docs)]
67    pub uint32_3: Option<u32>,
68    #[allow(missing_docs)]
69    pub uint32_4: Option<u32>,
70    #[allow(missing_docs)]
71    pub uint32_5: Option<u32>,
72    #[allow(missing_docs)]
73    pub uint32_u: Option<u32>,
74    #[allow(missing_docs)]
75    pub acc32: Option<u32>,
76    #[allow(missing_docs)]
77    pub acc32_u: Option<u32>,
78    #[allow(missing_docs)]
79    pub enum32: Option<u32>,
80    #[allow(missing_docs)]
81    pub enum32_u: Option<u32>,
82    #[allow(missing_docs)]
83    pub bitfield32: Option<Bitfield32>,
84    #[allow(missing_docs)]
85    pub bitfield32_u: Option<Bitfield32U>,
86    #[allow(missing_docs)]
87    pub ipaddr: Option<std::net::Ipv4Addr>,
88    #[allow(missing_docs)]
89    pub ipaddr_u: Option<std::net::Ipv4Addr>,
90    #[allow(missing_docs)]
91    pub int64: Option<i64>,
92    #[allow(missing_docs)]
93    pub int64_u: Option<i64>,
94    #[allow(missing_docs)]
95    pub acc64: Option<u64>,
96    #[allow(missing_docs)]
97    pub acc64_u: Option<u64>,
98    #[allow(missing_docs)]
99    pub ipv6addr: Option<std::net::Ipv6Addr>,
100    #[allow(missing_docs)]
101    pub ipv6addr_u: Option<std::net::Ipv6Addr>,
102    #[allow(missing_docs)]
103    pub float32: Option<f32>,
104    #[allow(missing_docs)]
105    pub float32_u: Option<f32>,
106    #[allow(missing_docs)]
107    pub string: Option<String>,
108    #[allow(missing_docs)]
109    pub string_u: Option<String>,
110    #[allow(missing_docs)]
111    pub sunssf_5: Option<i16>,
112    #[allow(missing_docs)]
113    pub sunssf_6: Option<i16>,
114    #[allow(missing_docs)]
115    pub sunssf_7: Option<i16>,
116    #[allow(missing_docs)]
117    pub repeating: Vec<Repeating>,
118}
119#[allow(missing_docs)]
120impl Model63001 {
121    pub const SUNSSF_1: crate::Point<Self, Option<i16>> = crate::Point::new(0, 1, false);
122    pub const SUNSSF_2: crate::Point<Self, Option<i16>> = crate::Point::new(1, 1, false);
123    pub const SUNSSF_3: crate::Point<Self, Option<i16>> = crate::Point::new(2, 1, false);
124    pub const SUNSSF_4: crate::Point<Self, Option<i16>> = crate::Point::new(3, 1, false);
125    pub const INT16_1: crate::Point<Self, Option<i16>> = crate::Point::new(4, 1, false);
126    pub const INT16_2: crate::Point<Self, Option<i16>> = crate::Point::new(5, 1, false);
127    pub const INT16_3: crate::Point<Self, Option<i16>> = crate::Point::new(6, 1, false);
128    pub const INT16_4: crate::Point<Self, Option<i16>> = crate::Point::new(7, 1, true);
129    pub const INT16_5: crate::Point<Self, Option<i16>> = crate::Point::new(8, 1, false);
130    pub const INT16_U: crate::Point<Self, Option<i16>> = crate::Point::new(9, 1, false);
131    pub const UINT16_1: crate::Point<Self, Option<u16>> = crate::Point::new(10, 1, false);
132    pub const UINT16_2: crate::Point<Self, Option<u16>> = crate::Point::new(11, 1, false);
133    pub const UINT16_3: crate::Point<Self, Option<u16>> = crate::Point::new(12, 1, false);
134    pub const UINT16_4: crate::Point<Self, Option<u16>> = crate::Point::new(13, 1, true);
135    pub const UINT16_5: crate::Point<Self, Option<u16>> = crate::Point::new(14, 1, false);
136    pub const UINT16_U: crate::Point<Self, Option<u16>> = crate::Point::new(15, 1, false);
137    pub const ACC16: crate::Point<Self, Option<u16>> = crate::Point::new(16, 1, false);
138    pub const ACC16_U: crate::Point<Self, Option<u16>> = crate::Point::new(17, 1, false);
139    pub const ENUM16: crate::Point<Self, Option<u16>> = crate::Point::new(18, 1, false);
140    pub const ENUM16_U: crate::Point<Self, Option<u16>> = crate::Point::new(19, 1, false);
141    pub const BITFIELD16: crate::Point<Self, Option<Bitfield16>> = crate::Point::new(20, 1, false);
142    pub const BITFIELD16_U: crate::Point<Self, Option<Bitfield16U>> =
143        crate::Point::new(21, 1, false);
144    pub const INT32_1: crate::Point<Self, Option<i32>> = crate::Point::new(22, 2, false);
145    pub const INT32_2: crate::Point<Self, Option<i32>> = crate::Point::new(24, 2, false);
146    pub const INT32_3: crate::Point<Self, Option<i32>> = crate::Point::new(26, 2, true);
147    pub const INT32_4: crate::Point<Self, Option<i32>> = crate::Point::new(28, 2, false);
148    pub const INT32_5: crate::Point<Self, Option<i32>> = crate::Point::new(30, 2, false);
149    pub const INT32_U: crate::Point<Self, Option<i32>> = crate::Point::new(32, 2, false);
150    pub const UINT32_1: crate::Point<Self, Option<u32>> = crate::Point::new(34, 2, false);
151    pub const UINT32_2: crate::Point<Self, Option<u32>> = crate::Point::new(36, 2, false);
152    pub const UINT32_3: crate::Point<Self, Option<u32>> = crate::Point::new(38, 2, true);
153    pub const UINT32_4: crate::Point<Self, Option<u32>> = crate::Point::new(40, 2, false);
154    pub const UINT32_5: crate::Point<Self, Option<u32>> = crate::Point::new(42, 2, false);
155    pub const UINT32_U: crate::Point<Self, Option<u32>> = crate::Point::new(44, 2, false);
156    pub const ACC32: crate::Point<Self, Option<u32>> = crate::Point::new(46, 2, false);
157    pub const ACC32_U: crate::Point<Self, Option<u32>> = crate::Point::new(48, 2, false);
158    pub const ENUM32: crate::Point<Self, Option<u32>> = crate::Point::new(50, 2, false);
159    pub const ENUM32_U: crate::Point<Self, Option<u32>> = crate::Point::new(52, 2, false);
160    pub const BITFIELD32: crate::Point<Self, Option<Bitfield32>> = crate::Point::new(54, 2, false);
161    pub const BITFIELD32_U: crate::Point<Self, Option<Bitfield32U>> =
162        crate::Point::new(56, 2, false);
163    pub const IPADDR: crate::Point<Self, Option<std::net::Ipv4Addr>> =
164        crate::Point::new(58, 2, true);
165    pub const IPADDR_U: crate::Point<Self, Option<std::net::Ipv4Addr>> =
166        crate::Point::new(60, 2, false);
167    pub const INT64: crate::Point<Self, Option<i64>> = crate::Point::new(62, 4, true);
168    pub const INT64_U: crate::Point<Self, Option<i64>> = crate::Point::new(66, 4, false);
169    pub const ACC64: crate::Point<Self, Option<u64>> = crate::Point::new(70, 4, false);
170    pub const ACC64_U: crate::Point<Self, Option<u64>> = crate::Point::new(74, 4, false);
171    pub const IPV6ADDR: crate::Point<Self, Option<std::net::Ipv6Addr>> =
172        crate::Point::new(78, 8, false);
173    pub const IPV6ADDR_U: crate::Point<Self, Option<std::net::Ipv6Addr>> =
174        crate::Point::new(86, 8, false);
175    pub const FLOAT32: crate::Point<Self, Option<f32>> = crate::Point::new(94, 2, true);
176    pub const FLOAT32_U: crate::Point<Self, Option<f32>> = crate::Point::new(96, 2, false);
177    pub const STRING: crate::Point<Self, Option<String>> = crate::Point::new(98, 16, true);
178    pub const STRING_U: crate::Point<Self, Option<String>> = crate::Point::new(114, 16, false);
179    pub const SUNSSF_5: crate::Point<Self, Option<i16>> = crate::Point::new(130, 1, false);
180    pub const SUNSSF_6: crate::Point<Self, Option<i16>> = crate::Point::new(131, 1, false);
181    pub const SUNSSF_7: crate::Point<Self, Option<i16>> = crate::Point::new(132, 1, false);
182}
183impl crate::Group for Model63001 {
184    const LEN: u16 = 134;
185}
186impl Model63001 {
187    fn parse_group(data: &[u16]) -> Result<(&[u16], Self), crate::DecodeError> {
188        let nested_data = data
189            .get(usize::from(<Self as crate::Group>::LEN)..)
190            .unwrap_or(&[]);
191        let (nested_data, repeating) = Repeating::parse_multiple(nested_data)?;
192        Ok((
193            nested_data,
194            Self {
195                sunssf_1: Self::SUNSSF_1.from_data(data)?,
196                sunssf_2: Self::SUNSSF_2.from_data(data)?,
197                sunssf_3: Self::SUNSSF_3.from_data(data)?,
198                sunssf_4: Self::SUNSSF_4.from_data(data)?,
199                int16_1: Self::INT16_1.from_data(data)?,
200                int16_2: Self::INT16_2.from_data(data)?,
201                int16_3: Self::INT16_3.from_data(data)?,
202                int16_4: Self::INT16_4.from_data(data)?,
203                int16_5: Self::INT16_5.from_data(data)?,
204                int16_u: Self::INT16_U.from_data(data)?,
205                uint16_1: Self::UINT16_1.from_data(data)?,
206                uint16_2: Self::UINT16_2.from_data(data)?,
207                uint16_3: Self::UINT16_3.from_data(data)?,
208                uint16_4: Self::UINT16_4.from_data(data)?,
209                uint16_5: Self::UINT16_5.from_data(data)?,
210                uint16_u: Self::UINT16_U.from_data(data)?,
211                acc16: Self::ACC16.from_data(data)?,
212                acc16_u: Self::ACC16_U.from_data(data)?,
213                enum16: Self::ENUM16.from_data(data)?,
214                enum16_u: Self::ENUM16_U.from_data(data)?,
215                bitfield16: Self::BITFIELD16.from_data(data)?,
216                bitfield16_u: Self::BITFIELD16_U.from_data(data)?,
217                int32_1: Self::INT32_1.from_data(data)?,
218                int32_2: Self::INT32_2.from_data(data)?,
219                int32_3: Self::INT32_3.from_data(data)?,
220                int32_4: Self::INT32_4.from_data(data)?,
221                int32_5: Self::INT32_5.from_data(data)?,
222                int32_u: Self::INT32_U.from_data(data)?,
223                uint32_1: Self::UINT32_1.from_data(data)?,
224                uint32_2: Self::UINT32_2.from_data(data)?,
225                uint32_3: Self::UINT32_3.from_data(data)?,
226                uint32_4: Self::UINT32_4.from_data(data)?,
227                uint32_5: Self::UINT32_5.from_data(data)?,
228                uint32_u: Self::UINT32_U.from_data(data)?,
229                acc32: Self::ACC32.from_data(data)?,
230                acc32_u: Self::ACC32_U.from_data(data)?,
231                enum32: Self::ENUM32.from_data(data)?,
232                enum32_u: Self::ENUM32_U.from_data(data)?,
233                bitfield32: Self::BITFIELD32.from_data(data)?,
234                bitfield32_u: Self::BITFIELD32_U.from_data(data)?,
235                ipaddr: Self::IPADDR.from_data(data)?,
236                ipaddr_u: Self::IPADDR_U.from_data(data)?,
237                int64: Self::INT64.from_data(data)?,
238                int64_u: Self::INT64_U.from_data(data)?,
239                acc64: Self::ACC64.from_data(data)?,
240                acc64_u: Self::ACC64_U.from_data(data)?,
241                ipv6addr: Self::IPV6ADDR.from_data(data)?,
242                ipv6addr_u: Self::IPV6ADDR_U.from_data(data)?,
243                float32: Self::FLOAT32.from_data(data)?,
244                float32_u: Self::FLOAT32_U.from_data(data)?,
245                string: Self::STRING.from_data(data)?,
246                string_u: Self::STRING_U.from_data(data)?,
247                sunssf_5: Self::SUNSSF_5.from_data(data)?,
248                sunssf_6: Self::SUNSSF_6.from_data(data)?,
249                sunssf_7: Self::SUNSSF_7.from_data(data)?,
250                repeating,
251            },
252        ))
253    }
254}
255bitflags::bitflags! {
256    #[allow(missing_docs)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
257    #[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))] pub
258    struct Bitfield16 : u16 {}
259}
260impl crate::Value for Bitfield16 {
261    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
262        let value = u16::decode(data)?;
263        Ok(Self::from_bits_retain(value))
264    }
265    fn encode(self) -> Box<[u16]> {
266        self.bits().encode()
267    }
268}
269impl crate::FixedSize for Bitfield16 {
270    const SIZE: u16 = 1u16;
271    const INVALID: Self = Self::from_bits_retain(65535u16);
272    fn is_invalid(&self) -> bool {
273        self.bits() == 65535u16
274    }
275}
276bitflags::bitflags! {
277    #[allow(missing_docs)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
278    #[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))] pub
279    struct Bitfield16U : u16 {}
280}
281impl crate::Value for Bitfield16U {
282    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
283        let value = u16::decode(data)?;
284        Ok(Self::from_bits_retain(value))
285    }
286    fn encode(self) -> Box<[u16]> {
287        self.bits().encode()
288    }
289}
290impl crate::FixedSize for Bitfield16U {
291    const SIZE: u16 = 1u16;
292    const INVALID: Self = Self::from_bits_retain(65535u16);
293    fn is_invalid(&self) -> bool {
294        self.bits() == 65535u16
295    }
296}
297bitflags::bitflags! {
298    #[allow(missing_docs)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
299    #[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))] pub
300    struct Bitfield32 : u32 {}
301}
302impl crate::Value for Bitfield32 {
303    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
304        let value = u32::decode(data)?;
305        Ok(Self::from_bits_retain(value))
306    }
307    fn encode(self) -> Box<[u16]> {
308        self.bits().encode()
309    }
310}
311impl crate::FixedSize for Bitfield32 {
312    const SIZE: u16 = 2u16;
313    const INVALID: Self = Self::from_bits_retain(4294967295u32);
314    fn is_invalid(&self) -> bool {
315        self.bits() == 4294967295u32
316    }
317}
318bitflags::bitflags! {
319    #[allow(missing_docs)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
320    #[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))] pub
321    struct Bitfield32U : u32 {}
322}
323impl crate::Value for Bitfield32U {
324    fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
325        let value = u32::decode(data)?;
326        Ok(Self::from_bits_retain(value))
327    }
328    fn encode(self) -> Box<[u16]> {
329        self.bits().encode()
330    }
331}
332impl crate::FixedSize for Bitfield32U {
333    const SIZE: u16 = 2u16;
334    const INVALID: Self = Self::from_bits_retain(4294967295u32);
335    fn is_invalid(&self) -> bool {
336        self.bits() == 4294967295u32
337    }
338}
339#[allow(missing_docs)]
340#[derive(Debug)]
341#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
342pub struct Repeating {
343    #[allow(missing_docs)]
344    pub sunssf_8: Option<i16>,
345    #[allow(missing_docs)]
346    pub int16_11: Option<i16>,
347    #[allow(missing_docs)]
348    pub int16_12: Option<i16>,
349    #[allow(missing_docs)]
350    pub int16_u: Option<i16>,
351    #[allow(missing_docs)]
352    pub uint16_11: Option<u16>,
353    #[allow(missing_docs)]
354    pub uint16_12: Option<u16>,
355    #[allow(missing_docs)]
356    pub uint16_13: Option<u16>,
357    #[allow(missing_docs)]
358    pub uint16_u: Option<u16>,
359    #[allow(missing_docs)]
360    pub int32: Option<i32>,
361    #[allow(missing_docs)]
362    pub int32_u: Option<i32>,
363    #[allow(missing_docs)]
364    pub uint32: Option<u32>,
365    #[allow(missing_docs)]
366    pub uint32_u: Option<u32>,
367    #[allow(missing_docs)]
368    pub sunssf_9: Option<i16>,
369}
370#[allow(missing_docs)]
371impl Repeating {
372    pub const SUNSSF_8: crate::Point<Self, Option<i16>> = crate::Point::new(0, 1, false);
373    pub const INT16_11: crate::Point<Self, Option<i16>> = crate::Point::new(1, 1, true);
374    pub const INT16_12: crate::Point<Self, Option<i16>> = crate::Point::new(2, 1, false);
375    pub const INT16_U: crate::Point<Self, Option<i16>> = crate::Point::new(3, 1, false);
376    pub const UINT16_11: crate::Point<Self, Option<u16>> = crate::Point::new(4, 1, true);
377    pub const UINT16_12: crate::Point<Self, Option<u16>> = crate::Point::new(5, 1, false);
378    pub const UINT16_13: crate::Point<Self, Option<u16>> = crate::Point::new(6, 1, false);
379    pub const UINT16_U: crate::Point<Self, Option<u16>> = crate::Point::new(7, 1, false);
380    pub const INT32: crate::Point<Self, Option<i32>> = crate::Point::new(8, 2, true);
381    pub const INT32_U: crate::Point<Self, Option<i32>> = crate::Point::new(10, 2, false);
382    pub const UINT32: crate::Point<Self, Option<u32>> = crate::Point::new(12, 2, true);
383    pub const UINT32_U: crate::Point<Self, Option<u32>> = crate::Point::new(14, 2, false);
384    pub const SUNSSF_9: crate::Point<Self, Option<i16>> = crate::Point::new(16, 1, false);
385}
386impl crate::Group for Repeating {
387    const LEN: u16 = 18;
388}
389impl Repeating {
390    fn parse_group(data: &[u16]) -> Result<(&[u16], Self), crate::DecodeError> {
391        let nested_data = data
392            .get(usize::from(<Self as crate::Group>::LEN)..)
393            .unwrap_or(&[]);
394        Ok((
395            nested_data,
396            Self {
397                sunssf_8: Self::SUNSSF_8.from_data(data)?,
398                int16_11: Self::INT16_11.from_data(data)?,
399                int16_12: Self::INT16_12.from_data(data)?,
400                int16_u: Self::INT16_U.from_data(data)?,
401                uint16_11: Self::UINT16_11.from_data(data)?,
402                uint16_12: Self::UINT16_12.from_data(data)?,
403                uint16_13: Self::UINT16_13.from_data(data)?,
404                uint16_u: Self::UINT16_U.from_data(data)?,
405                int32: Self::INT32.from_data(data)?,
406                int32_u: Self::INT32_U.from_data(data)?,
407                uint32: Self::UINT32.from_data(data)?,
408                uint32_u: Self::UINT32_U.from_data(data)?,
409                sunssf_9: Self::SUNSSF_9.from_data(data)?,
410            },
411        ))
412    }
413    fn parse_multiple(data: &[u16]) -> Result<(&[u16], Vec<Self>), crate::DecodeError> {
414        let group_len = usize::from(<Repeating as crate::Group>::LEN);
415        if group_len == 0 {
416            return Ok((data, Vec::new()));
417        }
418        if data.len() % group_len != 0 {
419            return Err(crate::DecodeError::OutOfBounds);
420        }
421        let group_count = data.len() / group_len;
422        let (data, groups) =
423            (0..group_count).try_fold((data, Vec::new()), |(data, mut groups), _| {
424                let (data, group) = Repeating::parse_group(data)?;
425                groups.push(group);
426                Ok::<_, crate::DecodeError>((data, groups))
427            })?;
428        Ok((data, groups))
429    }
430}
431impl crate::Model for Model63001 {
432    const ID: u16 = 63001;
433    fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
434        models.m63001
435    }
436    fn parse(data: &[u16]) -> Result<Self, crate::ParseError<Self>> {
437        let (_, model) = Self::parse_group(data)?;
438        Ok(model)
439    }
440}