Skip to main content

Obis

Struct Obis 

Source
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

Source

pub const ENERGY_IMPORT: Self

1-0:1.8.0*255: active energy imported (A+), total.

Source

pub const ENERGY_IMPORT_T1: Self

1-0:1.8.1*255: active energy imported, tariff 1.

Source

pub const ENERGY_IMPORT_T2: Self

1-0:1.8.2*255: active energy imported, tariff 2.

Source

pub const ENERGY_EXPORT: Self

1-0:2.8.0*255: active energy exported (A−), total.

Source

pub const ENERGY_EXPORT_T1: Self

1-0:2.8.1*255: active energy exported, tariff 1.

Source

pub const ENERGY_EXPORT_T2: Self

1-0:2.8.2*255: active energy exported, tariff 2.

Source

pub const POWER: Self

1-0:16.7.0*255: active power, sum of phases (positive = import).

Source

pub const POWER_L1: Self

1-0:36.7.0*255: active power, phase L1.

Source

pub const POWER_L2: Self

1-0:56.7.0*255: active power, phase L2.

Source

pub const POWER_L3: Self

1-0:76.7.0*255: active power, phase L3.

Source

pub const CURRENT_L1: Self

1-0:31.7.0*255: current, phase L1.

Source

pub const CURRENT_L2: Self

1-0:51.7.0*255: current, phase L2.

Source

pub const CURRENT_L3: Self

1-0:71.7.0*255: current, phase L3.

Source

pub const VOLTAGE_L1: Self

1-0:32.7.0*255: voltage, phase L1.

Source

pub const VOLTAGE_L2: Self

1-0:52.7.0*255: voltage, phase L2.

Source

pub const VOLTAGE_L3: Self

1-0:72.7.0*255: voltage, phase L3.

Source

pub const FREQUENCY: Self

1-0:14.7.0*255: supply frequency.

Source

pub const DEVICE_ID: Self

1-0:0.0.9*255: the device identifier (server ID).

Source

pub const SERIAL: Self

1-0:96.1.0*255: the meter’s serial number (server ID on newer meters).

Source

pub const STATUS: Self

1-0:96.5.0*255: the operating status word.

Source

pub const MANUFACTURER: Self

129-129:199.130.3*255: the manufacturer identifier.

Source

pub const MANUFACTURER_ALT: Self

1-0:96.50.1*1: the manufacturer identifier as newer meters label it.

Source

pub const PUBLIC_KEY: Self

129-129:199.130.5*255: the meter’s public key (for signed readings).

Source

pub const FIRMWARE: Self

1-0:0.2.0*0: the firmware version.

Source

pub const fn new(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8) -> Self

The OBIS code A-B:C.D.E*F.

Source

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?
examples/decode.rs (line 283)
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}
Source

pub fn name(&self) -> Option<&'static str>

What the code means, for the codes a German meter commonly sends.

Examples found in repository?
examples/decode.rs (line 277)
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}

Trait Implementations§

Source§

impl Clone for Obis

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Obis

Source§

impl Debug for Obis

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Obis

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Obis

Source§

impl From<Obis> for [u8; 6]

Source§

fn from(obis: Obis) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 6]> for Obis

Source§

fn from(bytes: [u8; 6]) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Obis

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Error>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Obis

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Obis

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Obis

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Obis

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Obis

Source§

impl TryFrom<&[u8]> for Obis

Six bytes, or Error::ObisLength.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(bytes: &[u8]) -> Result<Self, Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Forget for Obis

§

impl Freeze for Obis

§

impl Move for Obis

§

impl RefUnwindSafe for Obis

§

impl Send for Obis

§

impl Sync for Obis

§

impl Unpin for Obis

§

impl UnsafeUnpin for Obis

§

impl UnwindSafe for Obis

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.