Struct resol_vbus::Datagram
source · 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
impl Datagram
sourcepub fn id_string(&self) -> String
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
(ifcommand
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 IdHash for Datagram
impl IdHash for Datagram
source§fn id_hash<H: Hasher>(&self, h: &mut H)
fn id_hash<H: Hasher>(&self, h: &mut H)
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
(ifcommand
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));