pub struct Obis(pub [u8; 6]);Expand description
An OBIS code (IEC 62056-61): the six-byte name of a measured quantity.
Displays as A-B:C.D.E*F, e.g. 1-0:1.8.0*255 for imported active energy, and
parses from that form, from A-B:C.D.E (F = 255) and from the short C.D.E printed
on meters (A = 1, B = 0, F = 255):
use sml_kit::Obis;
assert_eq!("1-0:1.8.0*255".parse(), Ok(Obis::ENERGY_IMPORT));
assert_eq!("1.8.0".parse(), Ok(Obis::ENERGY_IMPORT));
assert_eq!(Obis::ENERGY_IMPORT.name(), Some("active energy import (A+), total"));Tuple Fields§
§0: [u8; 6]Implementations§
Source§impl Obis
impl Obis
Sourcepub const ENERGY_IMPORT: Self
pub const ENERGY_IMPORT: Self
1-0:1.8.0*255: active energy imported (A+), total.
Sourcepub const ENERGY_IMPORT_T1: Self
pub const ENERGY_IMPORT_T1: Self
1-0:1.8.1*255: active energy imported, tariff 1.
Sourcepub const ENERGY_IMPORT_T2: Self
pub const ENERGY_IMPORT_T2: Self
1-0:1.8.2*255: active energy imported, tariff 2.
Sourcepub const ENERGY_EXPORT: Self
pub const ENERGY_EXPORT: Self
1-0:2.8.0*255: active energy exported (A−), total.
Sourcepub const ENERGY_EXPORT_T1: Self
pub const ENERGY_EXPORT_T1: Self
1-0:2.8.1*255: active energy exported, tariff 1.
Sourcepub const ENERGY_EXPORT_T2: Self
pub const ENERGY_EXPORT_T2: Self
1-0:2.8.2*255: active energy exported, tariff 2.
Sourcepub const CURRENT_L1: Self
pub const CURRENT_L1: Self
1-0:31.7.0*255: current, phase L1.
Sourcepub const CURRENT_L2: Self
pub const CURRENT_L2: Self
1-0:51.7.0*255: current, phase L2.
Sourcepub const CURRENT_L3: Self
pub const CURRENT_L3: Self
1-0:71.7.0*255: current, phase L3.
Sourcepub const VOLTAGE_L1: Self
pub const VOLTAGE_L1: Self
1-0:32.7.0*255: voltage, phase L1.
Sourcepub const VOLTAGE_L2: Self
pub const VOLTAGE_L2: Self
1-0:52.7.0*255: voltage, phase L2.
Sourcepub const VOLTAGE_L3: Self
pub const VOLTAGE_L3: Self
1-0:72.7.0*255: voltage, phase L3.
Sourcepub const MANUFACTURER: Self
pub const MANUFACTURER: Self
129-129:199.130.3*255: the manufacturer identifier.
Sourcepub const MANUFACTURER_ALT: Self
pub const MANUFACTURER_ALT: Self
1-0:96.50.1*1: the manufacturer identifier as newer meters label it.
Sourcepub const PUBLIC_KEY: Self
pub const PUBLIC_KEY: Self
129-129:199.130.5*255: the meter’s public key (for signed readings).
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
The OBIS code in bytes, which must be exactly six bytes long.
Examples found in repository?
282fn tree(t: &sml_kit::Tree<'_>, depth: usize) {
283 let name = Obis::from_bytes(t.name).map_or_else(
284 |_| hex(t.name),
285 |o| format!("{o}{}", o.name().map(|n| format!(" ({n})")).unwrap_or_default()),
286 );
287 let value = match t.value {
288 None => String::new(),
289 Some(sml_kit::ProcParValue::Value(SmlValue::Bytes(b))) => format!("= {}", text(b)),
290 Some(sml_kit::ProcParValue::Value(v)) => format!("= {v:?}"),
291 Some(sml_kit::ProcParValue::Entry(e)) => format!(
292 "= {}{}",
293 e.quantity().map_or_else(|| format!("{:?}", e.value), |q| q.to_string()),
294 if e.value_signature.is_some() { " (signed, not verified)" } else { "" }
295 ),
296 Some(sml_kit::ProcParValue::Period(p)) => {
297 format!("= {}", p.quantity().map_or_else(|| format!("{:?}", p.value), |q| q.to_string()))
298 }
299 Some(sml_kit::ProcParValue::Time(t)) => format!("= {t}"),
300 Some(sml_kit::ProcParValue::Tupel(t)) => {
301 format!("= A+ {} A- {}", t.a_plus.quantity(), t.a_minus.quantity())
302 }
303 };
304 println!("{:indent$}{name} {value}", "", indent = 2 * depth + 1);
305 for child in t.children.into_iter().flatten() {
306 match child {
307 Ok(c) => tree(&c, depth + 1),
308 Err(e) => eprintln!("{:indent$}child error: {e}", "", indent = 2 * depth + 3),
309 }
310 }
311}Sourcepub fn name(&self) -> Option<&'static str>
pub fn name(&self) -> Option<&'static str>
What the code means, for the codes a German meter commonly sends.
Examples found in repository?
260fn line(e: &ListEntry<'_>) -> String {
261 let value = match (e.quantity(), e.value) {
262 (Some(q), _) => q.to_string(),
263 (None, SmlValue::Bytes(b)) if [Obis::DEVICE_ID, Obis::SERIAL].contains(&e.obis) => {
264 ServerId::new(b).to_string()
265 }
266 // Printable ASCII is shown quoted and escaped; nothing a meter sends reaches the
267 // terminal as a control character.
268 (None, SmlValue::Bytes(b))
269 if !b.is_empty() && b.iter().all(|c| c.is_ascii_graphic() || *c == b' ') =>
270 {
271 format!("\"{}\"", b.escape_ascii())
272 }
273 (None, SmlValue::Bytes(b)) => b.iter().map(|c| format!("{c:02x}")).collect(),
274 (None, SmlValue::Time(t)) => t.to_string(),
275 (None, other) => format!("{other:?}"),
276 };
277 let name = e.obis.name().unwrap_or("");
278 format!("{:<24} {:<36} {value}", e.obis.to_string(), name)
279}
280
281/// Print a parameter tree, one node per line, indented by depth.
282fn tree(t: &sml_kit::Tree<'_>, depth: usize) {
283 let name = Obis::from_bytes(t.name).map_or_else(
284 |_| hex(t.name),
285 |o| format!("{o}{}", o.name().map(|n| format!(" ({n})")).unwrap_or_default()),
286 );
287 let value = match t.value {
288 None => String::new(),
289 Some(sml_kit::ProcParValue::Value(SmlValue::Bytes(b))) => format!("= {}", text(b)),
290 Some(sml_kit::ProcParValue::Value(v)) => format!("= {v:?}"),
291 Some(sml_kit::ProcParValue::Entry(e)) => format!(
292 "= {}{}",
293 e.quantity().map_or_else(|| format!("{:?}", e.value), |q| q.to_string()),
294 if e.value_signature.is_some() { " (signed, not verified)" } else { "" }
295 ),
296 Some(sml_kit::ProcParValue::Period(p)) => {
297 format!("= {}", p.quantity().map_or_else(|| format!("{:?}", p.value), |q| q.to_string()))
298 }
299 Some(sml_kit::ProcParValue::Time(t)) => format!("= {t}"),
300 Some(sml_kit::ProcParValue::Tupel(t)) => {
301 format!("= A+ {} A- {}", t.a_plus.quantity(), t.a_minus.quantity())
302 }
303 };
304 println!("{:indent$}{name} {value}", "", indent = 2 * depth + 1);
305 for child in t.children.into_iter().flatten() {
306 match child {
307 Ok(c) => tree(&c, depth + 1),
308 Err(e) => eprintln!("{:indent$}child error: {e}", "", indent = 2 * depth + 3),
309 }
310 }
311}