Struct Telegram

Source
pub struct Telegram {
    pub header: Header,
    pub command: u8,
    pub frame_data: [u8; 21],
}
Expand description

The Telegram type stores information according to the VBus protocol version 3.x.

Telegrams are used to transmit small amount of information (up to 21 bytes of payload).

§The “identity” of Telegram 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 Telegram type also respects the command field. That means that two Telegram with differing timestamp and frame_data fields are still considered “identical”, if the other fields match.

Fields§

§header: Header

The shared Header of all VBus protocol types.

§command: u8

The command of this Telegram.

§frame_data: [u8; 21]

The actual data from the frames attached to this Telegram.

Implementations§

Source§

impl Telegram

Source

pub fn frame_count_from_command(command: u8) -> u8

Get number of frames from a VBus protocol version 3.x command.

§Examples
use resol_vbus::Telegram;

assert_eq!(0, Telegram::frame_count_from_command(0x1F));
assert_eq!(1, Telegram::frame_count_from_command(0x3F));
assert_eq!(2, Telegram::frame_count_from_command(0x5F));
assert_eq!(3, Telegram::frame_count_from_command(0x7F));
Source

pub fn frame_count(&self) -> u8

Get number of 7-byte frames attached to this Telegram.

§Examples
use resol_vbus::{Telegram, Header};
use resol_vbus::utils::utc_timestamp;

let tgram = Telegram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x36,
    },
    command: 0x37,
    frame_data: [0u8; 21],
};

assert_eq!(1, tgram.frame_count());
Source

pub fn valid_frame_data_len(&self) -> usize

Return the length of the valid area of the frame_data.

§Examples
use resol_vbus::{Telegram, Header};
use resol_vbus::utils::utc_timestamp;

let tgram = Telegram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x36,
    },
    command: 0x37,
    frame_data: [0u8; 21],
};

assert_eq!(7, tgram.valid_frame_data_len());
Source

pub fn valid_frame_data(&self) -> &[u8]

Return the valid area of the frame_data immutably.

§Examples
use resol_vbus::{Telegram, Header};
use resol_vbus::utils::utc_timestamp;

let tgram = Telegram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x36,
    },
    command: 0x37,
    frame_data: [0u8; 21],
};

assert_eq!(7, tgram.valid_frame_data().len());
Source

pub fn valid_frame_data_mut(&mut self) -> &mut [u8]

Return the valid area of the frame_data mutably.

§Examples
use resol_vbus::{Telegram, Header};
use resol_vbus::utils::utc_timestamp;

let mut tgram = Telegram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x36,
    },
    command: 0x37,
    frame_data: [0u8; 21],
};

assert_eq!(7, tgram.valid_frame_data_mut().len());
Source

pub fn id_string(&self) -> String

Creates an identification string for this Telegram.

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

  • channel
  • destination_address
  • source_address
  • protocol_version
  • command
§Examples
use resol_vbus::{Telegram, Header};
use resol_vbus::utils::utc_timestamp;

let tgram = Telegram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x36,
    },
    command: 0x17,
    frame_data: [0u8; 21],
};

assert_eq!("11_1213_1415_36_17", tgram.id_string());

Trait Implementations§

Source§

impl AsRef<Header> for Telegram

Source§

fn as_ref(&self) -> &Header

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

impl Clone for Telegram

Source§

fn clone(&self) -> Telegram

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 Telegram

Source§

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

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

impl From<Telegram> for Data

Source§

fn from(tgram: Telegram) -> Data

Converts to this type from the input type.
Source§

impl IdHash for Telegram

Source§

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

Returns an identification hash for this Telegram.

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

  • channel
  • destination_address
  • source_address
  • protocol_version
  • command
§Examples
use resol_vbus::{Header, Telegram, id_hash};
use resol_vbus::utils::utc_timestamp;

let tgram = Telegram {
    header: Header {
        timestamp: utc_timestamp(1485688933),
        channel: 0x11,
        destination_address: 0x1213,
        source_address: 0x1415,
        protocol_version: 0x36,
    },
    command: 0x17,
    frame_data: [0u8; 21],
};

assert_eq!(7671625633196679790, id_hash(&tgram));

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.