pub struct ServerId<'a>(/* private fields */);Expand description
A device’s server ID: the bytes a meter names itself with in OpenResponse,
GetListResponse and Attention.
German meters use 10 bytes (DIN 43863-5): a type byte, the medium (1 =
electricity), the three-letter FLAG manufacturer code, a production block and a
big-endian serial number. Such an ID displays the way it is printed on the meter:
use sml_kit::ServerId;
let id = ServerId::new(&[0x0a, 0x01, b'I', b'S', b'K', 0x00, 0x04, 0x7a, 0x55, 0x44]);
assert_eq!(id.manufacturer(), Some("ISK"));
assert_eq!(id.serial(), Some(75_126_084));
assert_eq!(id.to_string(), "1 ISK00 75126084");
// Anything else is shown as hex, never as raw text.
assert_eq!(ServerId::new(&[0xde, 0xad]).to_string(), "dead");The block is shown as two hex digits (it is BCD on the meters seen so far). The layout comes from public captures, not from the DIN text itself.
Implementations§
Source§impl<'a> ServerId<'a>
impl<'a> ServerId<'a>
Sourcepub const fn new(bytes: &'a [u8]) -> Self
pub const fn new(bytes: &'a [u8]) -> Self
A server ID over bytes.
Examples found in repository?
examples/decode.rs (line 264)
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}Sourcepub fn manufacturer(&self) -> Option<&'a str>
pub fn manufacturer(&self) -> Option<&'a str>
The FLAG manufacturer code (e.g. "EMH", "ISK", "DZG"), for a standard ID.
Trait Implementations§
impl<'a> Copy for ServerId<'a>
impl<'a> Eq for ServerId<'a>
Source§impl<'a> Ord for ServerId<'a>
impl<'a> Ord for ServerId<'a>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<'a> PartialOrd for ServerId<'a>
impl<'a> PartialOrd for ServerId<'a>
impl<'a> StructuralPartialEq for ServerId<'a>
Auto Trait Implementations§
impl<'a> Forget for ServerId<'a>
impl<'a> Freeze for ServerId<'a>
impl<'a> Move for ServerId<'a>
impl<'a> RefUnwindSafe for ServerId<'a>
impl<'a> Send for ServerId<'a>
impl<'a> Sync for ServerId<'a>
impl<'a> Unpin for ServerId<'a>
impl<'a> UnsafeUnpin for ServerId<'a>where
&'a [u8]: UnsafeUnpin,
impl<'a> UnwindSafe for ServerId<'a>where
&'a [u8]: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more