Struct Specification

Source
pub struct Specification { /* private fields */ }
Expand description

The Specification type contains information about known devices and packets.

§Examples

use resol_vbus::{SpecificationFile, Specification, Language};

let spec = Specification::from_file(SpecificationFile::new_default(), Language::De);

let device_spec = spec.get_device_spec(0x00, 0x7E11, 0x0010);
assert_eq!("00_7E11", device_spec.device_id);
assert_eq!(0, device_spec.channel);
assert_eq!(0x7E11, device_spec.self_address);
assert_eq!(None, device_spec.peer_address);
assert_eq!("DeltaSol MX [Regler]", device_spec.name);

Implementations§

Source§

impl Specification

Source

pub fn from_file(file: SpecificationFile, language: Language) -> Specification

Construct a Specification from a SpecificationFile and a Language.

§Examples
use resol_vbus::{SpecificationFile, Specification, Language};

let spec = Specification::from_file(SpecificationFile::new_default(), Language::De);

// work with the spec...
Source

pub fn get_device_spec( &self, channel: u8, self_address: u16, peer_address: u16, ) -> Rc<DeviceSpec>

Get a DeviceSpec.

§Examples
use resol_vbus::{SpecificationFile, Specification, Language};

let spec = Specification::from_file(SpecificationFile::new_default(), Language::De);

let device_spec = spec.get_device_spec(0x00, 0x7E11, 0x0010);
assert_eq!("00_7E11", device_spec.device_id);
assert_eq!(0, device_spec.channel);
assert_eq!(0x7E11, device_spec.self_address);
assert_eq!(None, device_spec.peer_address);
assert_eq!("DeltaSol MX [Regler]", device_spec.name);
Source

pub fn get_packet_spec( &self, channel: u8, destination_address: u16, source_address: u16, command: u16, ) -> Rc<PacketSpec>

Get a PacketSpec.

§Examples
use resol_vbus::{SpecificationFile, Specification, Language};

let spec = Specification::from_file(SpecificationFile::new_default(), Language::De);

let packet_spec = spec.get_packet_spec(0x00, 0x0010, 0x7E11, 0x0100);
assert_eq!("00_0010_7E11_10_0100", packet_spec.packet_id);
assert_eq!(0, packet_spec.channel);
assert_eq!(0x0010, packet_spec.destination_address);
assert_eq!(0x7E11, packet_spec.source_address);
assert_eq!(0x0100, packet_spec.command);
assert_eq!("DFA", packet_spec.destination_device.name);
assert_eq!("DeltaSol MX [Regler]", packet_spec.source_device.name);
assert_eq!("DeltaSol MX [Regler]", packet_spec.name);
Source

pub fn get_packet_spec_by_id(&self, packet_id: PacketId) -> Rc<PacketSpec>

Get a PacketSpec.

§Examples
use resol_vbus::{SpecificationFile, Specification, Language, PacketId};

let spec = Specification::from_file(SpecificationFile::new_default(), Language::De);

let packet_spec = spec.get_packet_spec_by_id(PacketId(0x00, 0x0010, 0x7E11, 0x0100));
assert_eq!("00_0010_7E11_10_0100", packet_spec.packet_id);
assert_eq!(0, packet_spec.channel);
assert_eq!(0x0010, packet_spec.destination_address);
assert_eq!(0x7E11, packet_spec.source_address);
assert_eq!(0x0100, packet_spec.command);
assert_eq!("DFA", packet_spec.destination_device.name);
assert_eq!("DeltaSol MX [Regler]", packet_spec.source_device.name);
assert_eq!("DeltaSol MX [Regler]", packet_spec.name);
Source

pub fn fields_in_data_set<'a, T>( &'a self, data_set: &'a T, ) -> DataSetPacketFieldIterator<'a, T>
where T: AsRef<[Data]> + 'a,

Returns an iterator that iterates over all known packet fields in the data set.

§Examples
use resol_vbus::{Specification, DataSet};

fn print_fields(spec: &Specification, data_set: &DataSet) {
    let mut last_data_index = None;
    for field in spec.fields_in_data_set(data_set) {
        let current_data_index = Some(field.data_index());
        if last_data_index != current_data_index {
            last_data_index = current_data_index;
            println!("- {}: {}", field.packet_spec().packet_id, field.packet_spec().name);
        }
        println!("    - {}: {}", field.field_spec().field_id, field.field_spec().name);
    }
}
Source

pub fn fmt_timestamp<Tz>( &self, timestamp: &DateTime<Tz>, ) -> RawValueFormatter<'_>
where Tz: TimeZone,

Format a timestamp.

§Examples
use resol_vbus::{SpecificationFile, Specification, Language};
use resol_vbus::utils::utc_timestamp;

let fmt_localized_timestamp = |language| {
    let spec = Specification::from_file(SpecificationFile::new_default(), language);

    format!("{}", spec.fmt_timestamp(&utc_timestamp(1485688933)))
};

assert_eq!("29/01/2017 11:22:13", fmt_localized_timestamp(Language::En));
assert_eq!("29.01.2017 11:22:13", fmt_localized_timestamp(Language::De));
assert_eq!("29/01/2017 11:22:13", fmt_localized_timestamp(Language::Fr));

Trait Implementations§

Source§

impl Debug for Specification

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.