Struct resol_vbus::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§

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§

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.

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§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.