[−][src]Struct async_resol_vbus::Packet
The Packet
type stores information according to the VBus protocol version 1.x.
Packets are used to transmit larger amount of information (up to 508 bytes of payload) relying on the fact that both sides of the communication know how that payload is structured and how to extract the information out of it.
The "identity" of Packet
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 Packet
type also respects the command
field. That means that two Packet
with differing timestamp
, frame_count
and frame_data
fields are still considered
"identical", if the other fields match.
The payload of Packet
values
The VBus Protocol Specification describes that all the fields used for the Packet
's
"identity" can also be used to determine the structure of the payload contained in the
frame_data
field. The Specification
type can be used to decode the payload
information.
Fields
header: Header
The shared Header
of all VBus protocol types.
command: u16
The command of this Packet
.
frame_count: u8
The number of 4-byte frames attached to this Packet
.
frame_data: [u8; 508]
The actual data from the frames attached to this Packet
.
Methods
impl Packet
[src]
pub fn valid_frame_data_len(&self) -> usize
[src]
Return the length of the valid area of the frame_data
.
Examples
use resol_vbus::{Header, Packet}; use resol_vbus::utils::utc_timestamp; let packet = Packet { header: Header { timestamp: utc_timestamp(1485688933), channel: 0x11, destination_address: 0x1213, source_address: 0x1415, protocol_version: 0x16, }, command: 0x1718, frame_count: 0x19, frame_data: [0u8; 508], }; assert_eq!(100, packet.valid_frame_data_len());
pub fn valid_frame_data(&self) -> &[u8]
[src]
Return the valid area of the frame_data
immutably.
Examples
use resol_vbus::{Header, Packet}; use resol_vbus::utils::utc_timestamp; let packet = Packet { header: Header { timestamp: utc_timestamp(1485688933), channel: 0x11, destination_address: 0x1213, source_address: 0x1415, protocol_version: 0x16, }, command: 0x1718, frame_count: 0x19, frame_data: [0u8; 508], }; assert_eq!(508, packet.frame_data.len()); assert_eq!(100, packet.valid_frame_data().len());
pub fn valid_frame_data_mut(&mut self) -> &mut [u8]
[src]
Return the valid area of the frame_data
mutably.
Examples
use resol_vbus::{Header, Packet}; use resol_vbus::utils::utc_timestamp; let mut packet = Packet { header: Header { timestamp: utc_timestamp(1485688933), channel: 0x11, destination_address: 0x1213, source_address: 0x1415, protocol_version: 0x16, }, command: 0x1718, frame_count: 0x19, frame_data: [0u8; 508], }; assert_eq!(508, packet.frame_data.len()); assert_eq!(100, packet.valid_frame_data_mut().len());
pub fn packet_id(&self) -> PacketId
[src]
Returns identification information about this Packet
.
The result contains all fields that count towards the "identity" of the Packet
with the
exception of the protocol_version
(since it must be 1.x to be a Packet
anyway):
channel
destination_address
source_address
command
Examples
use resol_vbus::{Header, Packet, PacketId}; use resol_vbus::utils::utc_timestamp; let packet = Packet { header: Header { timestamp: utc_timestamp(1485688933), channel: 0x11, destination_address: 0x1213, source_address: 0x1415, protocol_version: 0x16, }, command: 0x1718, frame_count: 0x19, frame_data: [0u8; 508], }; assert_eq!(PacketId(0x11, 0x1213, 0x1415, 0x1718), packet.packet_id());
pub fn id_string(&self) -> String
[src]
Creates an identification string for this Packet
.
The string contains all fields that count towards the "identity" of the Packet
:
channel
destination_address
source_address
protocol_version
command
Examples
use resol_vbus::{Header, Packet}; use resol_vbus::utils::utc_timestamp; let packet = Packet { header: Header { timestamp: utc_timestamp(1485688933), channel: 0x11, destination_address: 0x1213, source_address: 0x1415, protocol_version: 0x16, }, command: 0x1718, frame_count: 0x19, frame_data: [0u8; 508], }; assert_eq!("11_1213_1415_16_1718", packet.id_string());
Trait Implementations
impl AsRef<Header> for Packet
[src]
impl Clone for Packet
[src]
impl Debug for Packet
[src]
impl From<Packet> for Data
[src]
impl IdHash for Packet
[src]
fn id_hash<H>(&self, h: &mut H) where
H: Hasher,
[src]
H: Hasher,
Returns an identification hash for this Packet
.
The hash contains all fields that count towards the "identity" of the Packet
:
channel
destination_address
source_address
protocol_version
command
Examples
use resol_vbus::{Header, Packet, id_hash}; use resol_vbus::utils::utc_timestamp; let packet = Packet { header: Header { timestamp: utc_timestamp(1485688933), channel: 0x11, destination_address: 0x1213, source_address: 0x1415, protocol_version: 0x16, }, command: 0x1718, frame_count: 0x19, frame_data: [0u8; 508], }; assert_eq!(2215810099849021132, id_hash(&packet));
impl ToPacketId for Packet
[src]
fn to_packet_id(&self) -> Result<PacketId, Error>
[src]
Auto Trait Implementations
impl RefUnwindSafe for Packet
impl Send for Packet
impl Sync for Packet
impl Unpin for Packet
impl UnwindSafe for Packet
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,