sunspec/models/
model133.rs1#[derive(Debug)]
8#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
9pub struct Model133 {
10 pub act_schd: ActSchd,
14 pub mod_ena: ModEna,
18 pub n_schd: u16,
22 pub n_pts: u16,
26}
27#[allow(missing_docs)]
28impl Model133 {
29 pub const ACT_SCHD: crate::Point<Self, ActSchd> = crate::Point::new(0, 2, true);
30 pub const MOD_ENA: crate::Point<Self, ModEna> = crate::Point::new(2, 1, true);
31 pub const N_SCHD: crate::Point<Self, u16> = crate::Point::new(3, 1, false);
32 pub const N_PTS: crate::Point<Self, u16> = crate::Point::new(4, 1, false);
33}
34impl crate::Model for Model133 {
35 const ID: u16 = 133;
36 fn from_data(data: &[u16]) -> Result<Self, crate::DecodeError> {
37 Ok(Self {
38 act_schd: Self::ACT_SCHD.from_data(data)?,
39 mod_ena: Self::MOD_ENA.from_data(data)?,
40 n_schd: Self::N_SCHD.from_data(data)?,
41 n_pts: Self::N_PTS.from_data(data)?,
42 })
43 }
44 fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
45 models.m133
46 }
47}
48bitflags::bitflags! {
49 #[doc = " ActSchd"] #[doc = " "] #[doc = " Bitfield of active schedules"]
50 #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde",
51 derive(::serde::Serialize, ::serde::Deserialize))] pub struct ActSchd : u32 {
52 #[allow(missing_docs)] const Sched1 = 1; #[allow(missing_docs)] const Sched2 = 2;
53 #[allow(missing_docs)] const Sched3 = 4; #[allow(missing_docs)] const Sched4 = 8;
54 #[allow(missing_docs)] const Sched5 = 16; #[allow(missing_docs)] const Sched6 = 32;
55 #[allow(missing_docs)] const Sched7 = 64; #[allow(missing_docs)] const Sched8 = 128;
56 #[allow(missing_docs)] const Sched9 = 256; #[allow(missing_docs)] const Sched10 =
57 512; #[allow(missing_docs)] const Sched12 = 1024; #[allow(missing_docs)] const
58 Sched13 = 2048; #[allow(missing_docs)] const Sched14 = 4096; #[allow(missing_docs)]
59 const Sched15 = 8192; #[allow(missing_docs)] const Sched16 = 16384;
60 #[allow(missing_docs)] const Sched17 = 32768; #[allow(missing_docs)] const Sched18 =
61 65536; #[allow(missing_docs)] const Sched19 = 131072; #[allow(missing_docs)] const
62 Sched20 = 262144; #[allow(missing_docs)] const Sched21 = 524288;
63 #[allow(missing_docs)] const Sched22 = 2097152; #[allow(missing_docs)] const Sched23
64 = 4194304; #[allow(missing_docs)] const Sched24 = 8388608; #[allow(missing_docs)]
65 const Sched25 = 16777216; #[allow(missing_docs)] const Sched26 = 33554432;
66 #[allow(missing_docs)] const Sched27 = 67108864; #[allow(missing_docs)] const Sched28
67 = 134217728; #[allow(missing_docs)] const Sched29 = 268435456; #[allow(missing_docs)]
68 const Sched30 = 536870912; #[allow(missing_docs)] const Sched31 = 1073741824;
69 #[allow(missing_docs)] const Sched32 = 2147483648; }
70}
71impl crate::Value for ActSchd {
72 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
73 let value = u32::decode(data)?;
74 Ok(Self::from_bits_retain(value))
75 }
76 fn encode(self) -> Box<[u16]> {
77 self.bits().encode()
78 }
79}
80impl crate::Value for Option<ActSchd> {
81 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
82 let value = u32::decode(data)?;
83 if value != 4294967295u32 {
84 Ok(Some(ActSchd::from_bits_retain(value)))
85 } else {
86 Ok(None)
87 }
88 }
89 fn encode(self) -> Box<[u16]> {
90 if let Some(value) = self {
91 value.encode()
92 } else {
93 4294967295u32.encode()
94 }
95 }
96}
97bitflags::bitflags! {
98 #[doc = " ModEna"] #[doc = " "] #[doc = " Is basic scheduling active."]
99 #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde",
100 derive(::serde::Serialize, ::serde::Deserialize))] pub struct ModEna : u16 {
101 #[allow(missing_docs)] const Enabled = 1; }
102}
103impl crate::Value for ModEna {
104 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
105 let value = u16::decode(data)?;
106 Ok(Self::from_bits_retain(value))
107 }
108 fn encode(self) -> Box<[u16]> {
109 self.bits().encode()
110 }
111}
112impl crate::Value for Option<ModEna> {
113 fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
114 let value = u16::decode(data)?;
115 if value != 65535u16 {
116 Ok(Some(ModEna::from_bits_retain(value)))
117 } else {
118 Ok(None)
119 }
120 }
121 fn encode(self) -> Box<[u16]> {
122 if let Some(value) = self {
123 value.encode()
124 } else {
125 65535u16.encode()
126 }
127 }
128}