Skip to main content

SecondaryAddress

Struct SecondaryAddress 

Source
pub struct SecondaryAddress {
    pub digits: [Option<u8>; 8],
    pub manufacturer: Option<Manufacturer>,
    pub version: Option<u8>,
    pub medium: Option<Medium>,
}
Expand description

A secondary address to select, each part optional (a wildcard).

The identification number is eight BCD digits; any digit may be a wildcard (F on the wire). Manufacturer, version and medium are wildcarded as a whole.

Fields§

§digits: [Option<u8>; 8]

The eight digits, most significant first; None is a wildcard.

§manufacturer: Option<Manufacturer>

Manufacturer, or any.

§version: Option<u8>

Version, or any.

§medium: Option<Medium>

Medium, or any.

Implementations§

Source§

impl SecondaryAddress

Source

pub const ANY: Self

Every meter: all wildcards.

Source

pub fn id(number: u32) -> Option<Self>

The meter with this identification number (up to 8 decimal digits), any manufacturer, version and medium. None above 99 999 999.

Source

pub fn exact(address: &Address) -> Self

Exactly this meter: number, manufacturer, version and medium.

Source

pub fn pattern(text: &str) -> Option<Self>

Parse a pattern of 8 characters, digits or F/*/? wildcards, e.g. "1234FFFF". Shorter patterns are padded with wildcards on the right.

Examples found in repository?
examples/master.rs (line 24)
19fn main() {
20    let mut bus = Scripted::default();
21
22    // 1. Read meter 1 completely: SND_NKE, then REQ_UD2 until no more records follow.
23    //    Only telegrams from meter 12345678 count (a swapped meter is caught).
24    let meter = SecondaryAddress::pattern("12345678").unwrap();
25    let mut readout = Readout::new(Target::Primary(1)).expect_meter(meter);
26    while let Some(request) = readout.next_request() {
27        let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
28        let event = if reply.is_empty() { readout.timeout(&reply) } else { readout.reply(&reply) };
29        if let Event::Telegram(app) = event {
30            println!("telegram from {}", app.meter().map_or("?".into(), |m| m.to_string()));
31            for record in app.records().into_iter().flatten().flatten() {
32                println!("  {record}");
33            }
34        }
35    }
36    match readout.outcome() {
37        Some(Outcome::Complete) => println!("complete: {} telegrams\n", readout.telegrams()),
38        Some(other) => println!("not usable: {other}\n"),
39        None => unreachable!("the readout is over"),
40    }
41
42    // 2. Find every meter on the bus by secondary address.
43    let mut search = Search::new();
44    while let Some(request) = search.next_request() {
45        let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
46        let event = if reply.is_empty() { search.timeout(&reply) } else { search.reply(&reply) };
47        match event {
48            Event::Found(meter) => println!("found {meter}"),
49            Event::Unreadable(pattern) => println!("{pattern} answers but does not name itself"),
50            _ => {}
51        }
52    }
53    println!("{} selections", search.selections());
54}
Source

pub fn id_bytes(&self) -> [u8; 4]

The identification number as transmitted (BCD, LSB first, F for wildcards).

Source

pub fn matches(&self, address: &Address) -> bool

Whether address matches.

Source

pub fn to_bytes(&self) -> [u8; 8]

The 8 data bytes of a selection: ID (BCD, LSB first), manufacturer (LE), version, medium; wildcards as F nibbles, FFFF and FF.

Trait Implementations§

Source§

impl Clone for SecondaryAddress

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 SecondaryAddress

Source§

impl Debug for SecondaryAddress

Source§

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

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

impl Display for SecondaryAddress

Source§

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

12345678, 1234FFFF KAM v27 water, wildcards as F.

Source§

impl Eq for SecondaryAddress

Source§

impl Hash for SecondaryAddress

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 PartialEq for SecondaryAddress

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 StructuralPartialEq for SecondaryAddress

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.