Skip to main content

Application

Struct Application 

Source
pub struct Application<'a> {
    pub ell: Option<Ell>,
    pub afl: Option<Afl>,
    pub ci: u8,
    pub header: Header,
    pub authenticity: Authenticity,
    pub body: Body<'a>,
    /* private fields */
}
Expand description

A parsed telegram above the link layer.

Fields§

§ell: Option<Ell>

The extended link layer, if present.

§afl: Option<Afl>

The authentication and fragmentation layer, if present.

§ci: u8

The transport layer’s CI, or the ELL’s while the ELL is still encrypted.

§header: Header

The transport header.

§authenticity: Authenticity

What was cryptographically verified.

§body: Body<'a>

The payload.

Implementations§

Source§

impl<'a> Application<'a>

Source

pub fn parse(ci: u8, data: &'a [u8]) -> Result<Self>

Parse the bytes after a CI field: a wired telegram, or a wireless one when the link-layer address does not matter (it is needed for a mode-5 short header and the ELL: use Application::parse_with_link).

Examples found in repository?
examples/readout.rs (line 18)
14fn main() -> Result<(), mbus_kit::Error> {
15    let Some((Frame::Long { ci, data, .. }, _)) = Frame::parse(&TELEGRAM)? else {
16        return Err(mbus_kit::Error::UnexpectedEnd);
17    };
18    let app = Application::parse(ci, data)?;
19    if let Header::Long(h) = app.header {
20        println!(
21            "{} meter {:08} by {}, version {}",
22            h.address.medium,
23            h.address.id_number().unwrap_or(0),
24            h.address.manufacturer,
25            h.address.version
26        );
27    }
28    if let Body::Records(records) = app.body {
29        for record in records {
30            // e.g. "volume flow · maximum · storage 5 — 0.113 m³/h"
31            println!("  {}", record?);
32        }
33    }
34    Ok(())
35}

Parse the bytes after a CI field of a wireless telegram from link.

Source

pub const fn meter(&self) -> Option<Address>

The meter: the long header’s address if there is one (a meter behind a radio adapter or gateway), the link layer’s otherwise.

Examples found in repository?
examples/master.rs (line 27)
18fn main() {
19    let mut bus = Scripted::default();
20
21    // 1. Read meter 1 completely: SND_NKE, then REQ_UD2 until no more records follow.
22    let mut readout = Readout::new(Target::Primary(1));
23    while let Some(request) = readout.next_request() {
24        let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
25        let event = if reply.is_empty() { readout.timeout(&reply) } else { readout.reply(&reply) };
26        if let Event::Telegram(app) = event {
27            println!("telegram from {}", app.meter().map_or("?".into(), |m| m.to_string()));
28            for record in app.records().into_iter().flatten().flatten() {
29                println!("  {record}");
30            }
31        }
32    }
33    println!("{} telegrams\n", readout.telegrams());
34
35    // 2. Find every meter on the bus by secondary address.
36    let mut search = Search::new();
37    while let Some(request) = search.next_request() {
38        let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
39        let event = if reply.is_empty() { search.timeout(&reply) } else { search.reply(&reply) };
40        if let Event::Found(meter) = event {
41            println!("found {meter}");
42        }
43    }
44    println!("{} selections", search.selections());
45}
Source

pub fn expand<'o, F: Formats + ?Sized>( &self, formats: &F, out: &'o mut [u8], ) -> Result<Application<'o>>

A compact frame expanded with a layout from formats into out, as an application with the same meter, header and authenticity and the full records (Compact::expand); any other body is Error::UnsupportedCi.

Source

pub fn records(&self) -> Option<Records<'a>>

The records, if the body is plain records.

Examples found in repository?
examples/master.rs (line 28)
18fn main() {
19    let mut bus = Scripted::default();
20
21    // 1. Read meter 1 completely: SND_NKE, then REQ_UD2 until no more records follow.
22    let mut readout = Readout::new(Target::Primary(1));
23    while let Some(request) = readout.next_request() {
24        let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
25        let event = if reply.is_empty() { readout.timeout(&reply) } else { readout.reply(&reply) };
26        if let Event::Telegram(app) = event {
27            println!("telegram from {}", app.meter().map_or("?".into(), |m| m.to_string()));
28            for record in app.records().into_iter().flatten().flatten() {
29                println!("  {record}");
30            }
31        }
32    }
33    println!("{} telegrams\n", readout.telegrams());
34
35    // 2. Find every meter on the bus by secondary address.
36    let mut search = Search::new();
37    while let Some(request) = search.next_request() {
38        let reply = bus.transfer(request.bytes(), request.timeout_ms(Baud::B2400));
39        let event = if reply.is_empty() { search.timeout(&reply) } else { search.reply(&reply) };
40        if let Event::Found(meter) = event {
41            println!("found {meter}");
42        }
43    }
44    println!("{} selections", search.selections());
45}

Trait Implementations§

Source§

impl<'a> Clone for Application<'a>

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<'a> Debug for Application<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Application<'a>

§

impl<'a> Freeze for Application<'a>

§

impl<'a> Move for Application<'a>

§

impl<'a> RefUnwindSafe for Application<'a>

§

impl<'a> Send for Application<'a>

§

impl<'a> Sync for Application<'a>

§

impl<'a> Unpin for Application<'a>

§

impl<'a> UnsafeUnpin for Application<'a>

§

impl<'a> UnwindSafe for Application<'a>

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, 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.