Skip to main content

sunspec/models/
model64020.rs

1//! Mersen GreenString
2/// Mersen GreenString
3#[derive(Debug)]
4#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
5pub struct Model64020 {
6    /// Aux 0 temperature
7    pub aux0_tmp: Option<i16>,
8    /// Aux 1 temperature
9    pub aux1_tmp: Option<i16>,
10    /// Aux 2 temperature
11    pub aux2_tmp: Option<i16>,
12    /// Aux 3 temperature
13    pub aux3_tmp: Option<i16>,
14    /// Aux 4 temperature
15    pub aux4_tmp: Option<i16>,
16    /// Probe Temperature
17    pub probe_tmp: i16,
18    /// Main Temperature
19    pub main_tmp: i16,
20    /// Voltage scale factor for the sensors
21    pub sensor_v_sf: i16,
22    /// Current scale factor for the sensors
23    pub sensor_a_sf: i16,
24    /// Frequency scale factor for the sensors
25    pub sensor_hz_sf: i16,
26    /// Sensor1 Voltage
27    ///
28    /// scale of 0-10V
29    pub sensor1_voltage: Option<i16>,
30    /// Sensor2 Voltage
31    ///
32    /// scale of 0-10V
33    pub sensor2_voltage: Option<i16>,
34    /// Sensor3 Voltage
35    ///
36    /// scale of 0-10V
37    pub sensor3_voltage: Option<i16>,
38    /// Sensor4 Voltage
39    ///
40    /// scale of 0-10V
41    pub sensor4_voltage: Option<i16>,
42    /// Sensor5 Voltage
43    ///
44    /// scale of 0-10V
45    pub sensor5_voltage: Option<i16>,
46    /// Sensor6 Voltage
47    ///
48    /// scale of 0-10V
49    pub sensor6_voltage: Option<i16>,
50    /// Sensor7 Voltage
51    ///
52    /// scale of 0-10V
53    pub sensor7_voltage: Option<i16>,
54    /// Sensor1 Current
55    ///
56    /// scale of 4-20mA
57    pub sensor1_current: Option<i16>,
58    /// Sensor2 Current
59    ///
60    /// in 4-20mA or 4-20mA
61    pub sensor2_current: Option<i16>,
62    /// Sensor3 Current
63    ///
64    /// in 4-20mA or 4-20mA
65    pub sensor3_current: Option<i16>,
66    /// Sensor4 Current
67    ///
68    /// in 4-20mA or 4-20mA
69    pub sensor4_current: Option<i16>,
70    /// Sensor5 Current
71    ///
72    /// in 4-20mA or 4-20mA
73    pub sensor5_current: Option<i16>,
74    /// Sensor6 Current
75    ///
76    /// in 4-20mA or 4-20mA
77    pub sensor6_current: Option<i16>,
78    /// Sensor7 Current
79    ///
80    /// in 4-20mA or 4-20mA
81    pub sensor7_current: Option<i16>,
82    /// Sensor8 frequency
83    ///
84    /// frequency in Hz
85    pub sensor8: Option<u16>,
86    /// Relay 1 state
87    pub relay1: Option<u16>,
88    /// Relay 2 state
89    pub relay2: Option<u16>,
90    /// Relay 3 state
91    pub relay3: Option<u16>,
92    /// Reset the accumulators
93    ///
94    /// always 0 in reading, used the code 0xC0DA during the writing for resetting them
95    pub reset_accumulators: Option<u16>,
96    /// Reset the system
97    ///
98    /// always 0 in reading, used the code 0xC0DA during the writing for resetting the system
99    pub reset: Option<u16>,
100    #[allow(missing_docs)]
101    pub repeating: Vec<Repeating>,
102}
103#[allow(missing_docs)]
104impl Model64020 {
105    pub const AUX0_TMP: crate::Point<Self, Option<i16>> = crate::Point::new(0, 1, false);
106    pub const AUX1_TMP: crate::Point<Self, Option<i16>> = crate::Point::new(1, 1, false);
107    pub const AUX2_TMP: crate::Point<Self, Option<i16>> = crate::Point::new(2, 1, false);
108    pub const AUX3_TMP: crate::Point<Self, Option<i16>> = crate::Point::new(3, 1, false);
109    pub const AUX4_TMP: crate::Point<Self, Option<i16>> = crate::Point::new(4, 1, false);
110    pub const PROBE_TMP: crate::Point<Self, i16> = crate::Point::new(5, 1, false);
111    pub const MAIN_TMP: crate::Point<Self, i16> = crate::Point::new(6, 1, false);
112    pub const SENSOR_V_SF: crate::Point<Self, i16> = crate::Point::new(7, 1, false);
113    pub const SENSOR_A_SF: crate::Point<Self, i16> = crate::Point::new(8, 1, false);
114    pub const SENSOR_HZ_SF: crate::Point<Self, i16> = crate::Point::new(9, 1, false);
115    pub const SENSOR1_VOLTAGE: crate::Point<Self, Option<i16>> = crate::Point::new(10, 1, false);
116    pub const SENSOR2_VOLTAGE: crate::Point<Self, Option<i16>> = crate::Point::new(11, 1, false);
117    pub const SENSOR3_VOLTAGE: crate::Point<Self, Option<i16>> = crate::Point::new(12, 1, false);
118    pub const SENSOR4_VOLTAGE: crate::Point<Self, Option<i16>> = crate::Point::new(13, 1, false);
119    pub const SENSOR5_VOLTAGE: crate::Point<Self, Option<i16>> = crate::Point::new(14, 1, false);
120    pub const SENSOR6_VOLTAGE: crate::Point<Self, Option<i16>> = crate::Point::new(15, 1, false);
121    pub const SENSOR7_VOLTAGE: crate::Point<Self, Option<i16>> = crate::Point::new(16, 1, false);
122    pub const SENSOR1_CURRENT: crate::Point<Self, Option<i16>> = crate::Point::new(17, 1, false);
123    pub const SENSOR2_CURRENT: crate::Point<Self, Option<i16>> = crate::Point::new(18, 1, false);
124    pub const SENSOR3_CURRENT: crate::Point<Self, Option<i16>> = crate::Point::new(19, 1, false);
125    pub const SENSOR4_CURRENT: crate::Point<Self, Option<i16>> = crate::Point::new(20, 1, false);
126    pub const SENSOR5_CURRENT: crate::Point<Self, Option<i16>> = crate::Point::new(21, 1, false);
127    pub const SENSOR6_CURRENT: crate::Point<Self, Option<i16>> = crate::Point::new(22, 1, false);
128    pub const SENSOR7_CURRENT: crate::Point<Self, Option<i16>> = crate::Point::new(23, 1, false);
129    pub const SENSOR8: crate::Point<Self, Option<u16>> = crate::Point::new(24, 1, false);
130    pub const RELAY1: crate::Point<Self, Option<u16>> = crate::Point::new(25, 1, false);
131    pub const RELAY2: crate::Point<Self, Option<u16>> = crate::Point::new(26, 1, false);
132    pub const RELAY3: crate::Point<Self, Option<u16>> = crate::Point::new(27, 1, false);
133    pub const RESET_ACCUMULATORS: crate::Point<Self, Option<u16>> = crate::Point::new(28, 1, false);
134    pub const RESET: crate::Point<Self, Option<u16>> = crate::Point::new(29, 1, false);
135}
136impl crate::Group for Model64020 {
137    const LEN: u16 = 30;
138}
139impl Model64020 {
140    fn parse_group(data: &[u16]) -> Result<(&[u16], Self), crate::DecodeError> {
141        let nested_data = data
142            .get(usize::from(<Self as crate::Group>::LEN)..)
143            .unwrap_or(&[]);
144        let (nested_data, repeating) = Repeating::parse_multiple(nested_data)?;
145        Ok((
146            nested_data,
147            Self {
148                aux0_tmp: Self::AUX0_TMP.from_data(data)?,
149                aux1_tmp: Self::AUX1_TMP.from_data(data)?,
150                aux2_tmp: Self::AUX2_TMP.from_data(data)?,
151                aux3_tmp: Self::AUX3_TMP.from_data(data)?,
152                aux4_tmp: Self::AUX4_TMP.from_data(data)?,
153                probe_tmp: Self::PROBE_TMP.from_data(data)?,
154                main_tmp: Self::MAIN_TMP.from_data(data)?,
155                sensor_v_sf: Self::SENSOR_V_SF.from_data(data)?,
156                sensor_a_sf: Self::SENSOR_A_SF.from_data(data)?,
157                sensor_hz_sf: Self::SENSOR_HZ_SF.from_data(data)?,
158                sensor1_voltage: Self::SENSOR1_VOLTAGE.from_data(data)?,
159                sensor2_voltage: Self::SENSOR2_VOLTAGE.from_data(data)?,
160                sensor3_voltage: Self::SENSOR3_VOLTAGE.from_data(data)?,
161                sensor4_voltage: Self::SENSOR4_VOLTAGE.from_data(data)?,
162                sensor5_voltage: Self::SENSOR5_VOLTAGE.from_data(data)?,
163                sensor6_voltage: Self::SENSOR6_VOLTAGE.from_data(data)?,
164                sensor7_voltage: Self::SENSOR7_VOLTAGE.from_data(data)?,
165                sensor1_current: Self::SENSOR1_CURRENT.from_data(data)?,
166                sensor2_current: Self::SENSOR2_CURRENT.from_data(data)?,
167                sensor3_current: Self::SENSOR3_CURRENT.from_data(data)?,
168                sensor4_current: Self::SENSOR4_CURRENT.from_data(data)?,
169                sensor5_current: Self::SENSOR5_CURRENT.from_data(data)?,
170                sensor6_current: Self::SENSOR6_CURRENT.from_data(data)?,
171                sensor7_current: Self::SENSOR7_CURRENT.from_data(data)?,
172                sensor8: Self::SENSOR8.from_data(data)?,
173                relay1: Self::RELAY1.from_data(data)?,
174                relay2: Self::RELAY2.from_data(data)?,
175                relay3: Self::RELAY3.from_data(data)?,
176                reset_accumulators: Self::RESET_ACCUMULATORS.from_data(data)?,
177                reset: Self::RESET.from_data(data)?,
178                repeating,
179            },
180        ))
181    }
182}
183#[allow(missing_docs)]
184#[derive(Debug)]
185#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
186pub struct Repeating {
187    /// Serial number
188    ///
189    /// strings of 16 characters
190    pub serial_number: String,
191    /// Firmware version
192    ///
193    /// string of 11 characters
194    pub firmware: String,
195    /// Hardware version
196    pub hardware: u16,
197}
198#[allow(missing_docs)]
199impl Repeating {
200    pub const SERIAL_NUMBER: crate::Point<Self, String> = crate::Point::new(0, 9, false);
201    pub const FIRMWARE: crate::Point<Self, String> = crate::Point::new(9, 6, false);
202    pub const HARDWARE: crate::Point<Self, u16> = crate::Point::new(15, 1, false);
203}
204impl crate::Group for Repeating {
205    const LEN: u16 = 16;
206}
207impl Repeating {
208    fn parse_group(data: &[u16]) -> Result<(&[u16], Self), crate::DecodeError> {
209        let nested_data = data
210            .get(usize::from(<Self as crate::Group>::LEN)..)
211            .unwrap_or(&[]);
212        Ok((
213            nested_data,
214            Self {
215                serial_number: Self::SERIAL_NUMBER.from_data(data)?,
216                firmware: Self::FIRMWARE.from_data(data)?,
217                hardware: Self::HARDWARE.from_data(data)?,
218            },
219        ))
220    }
221    fn parse_multiple(data: &[u16]) -> Result<(&[u16], Vec<Self>), crate::DecodeError> {
222        let group_len = usize::from(<Repeating as crate::Group>::LEN);
223        if group_len == 0 {
224            return Ok((data, Vec::new()));
225        }
226        if data.len() % group_len != 0 {
227            return Err(crate::DecodeError::OutOfBounds);
228        }
229        let group_count = data.len() / group_len;
230        let (data, groups) =
231            (0..group_count).try_fold((data, Vec::new()), |(data, mut groups), _| {
232                let (data, group) = Repeating::parse_group(data)?;
233                groups.push(group);
234                Ok::<_, crate::DecodeError>((data, groups))
235            })?;
236        Ok((data, groups))
237    }
238}
239impl crate::Model for Model64020 {
240    const ID: u16 = 64020;
241    fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
242        models.m64020
243    }
244    fn parse(data: &[u16]) -> Result<Self, crate::ParseError<Self>> {
245        let (_, model) = Self::parse_group(data)?;
246        Ok(model)
247    }
248}