Struct Datagram

Source
pub struct Datagram {
    pub header: Header,
    pub command: u16,
    pub param16: i16,
    pub param32: i32,
}
Expand description

The Datagram type stores information according to the VBus protocol version 2.x.

Datagrams are used to issue simple commands with limited amount of payload (like e.g. getting or setting a parameter).

§The “identity” of Datagram values

As described in the corresponding section of the Header struct VBus data types use some of their fields as part of their “identity”. In addition to the fields used by the Header type the Datagram type also respects the command and (under some conditions) the param16 fields. That means that two Datagram with differing timestamp, param32 and (under some conditions) param16 fields are still considered “identical”, if the other fields match.

Fields§

§header: Header

The shared Header of all VBus protocol types.

§command: u16

The command of this Datagram.

§param16: i16

The 16-bit parameter attached to this Datagram.

§param32: i32

The 32-bit parameter attached to this Datagram.

Implementations§

Source§

impl Datagram

Source

pub fn id_string(&self) -> String

Creates an identification string for this Datagram.

The string contains all fields that count towards the “identity” of the Datagram:

  • channel
  • destination_address
  • source_address
  • protocol_version
  • command
  • param16 (if command equals 0x0900)
§Examples
use resol_vbus::{Header, Datagram};
use resol_vbus::utils::utc_timestamp;

let dgram1 = Datagram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x26,
    },
    command: 0x1718,
    param16: 0x191a,
    param32: 0x1b1c1d1e,
};

let dgram2 = Datagram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x26,
    },
    command: 0x0900,
    param16: 0x191a,
    param32: 0x1b1c1d1e,
};

assert_eq!("11_1213_1415_26_1718_0000", dgram1.id_string());
assert_eq!("11_1213_1415_26_0900_191A", dgram2.id_string());

Trait Implementations§

Source§

impl AsRef<Header> for Datagram

Source§

fn as_ref(&self) -> &Header

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Datagram

Source§

fn clone(&self) -> Datagram

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Datagram

Source§

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

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

impl From<Datagram> for Data

Source§

fn from(dgram: Datagram) -> Data

Converts to this type from the input type.
Source§

impl IdHash for Datagram

Source§

fn id_hash<H>(&self, h: &mut H)
where H: Hasher,

Returns an identification hash for this Datagram.

The hash contains all fields that count towards the “identity” of the Datagram:

  • channel
  • destination_address
  • source_address
  • protocol_version
  • command
  • param16 (if command equals 0x0900)
§Examples
use resol_vbus::{Header, Datagram, id_hash};
use resol_vbus::utils::utc_timestamp;

let dgram = Datagram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x26,
    },
    command: 0x1718,
    param16: 0x191a,
    param32: 0x1b1c1d1e,
};

assert_eq!(2264775891674525017, id_hash(&dgram));

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.