Struct resol_vbus::specification::Specification[][src]

pub struct Specification { /* fields omitted */ }
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

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

Get the SpecificationFile that was used to construct this Specification.

Get the Language that was used to construct this Specification.

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);

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);

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);

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);
    }
}

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));

Get Unit by its unit code.

Examples

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

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

assert_eq!(UnitId(62), spec.unit_by_unit_code("DegreesCelsius").unwrap().unit_id);
assert!(spec.unit_by_unit_code("SomeUnknownUnitCode").is_none());

Convert a value from one Unit to another.

Examples

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

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

let src_unit = spec.unit_by_unit_code("DegreesCelsius").unwrap();
let dst_unit = spec.unit_by_unit_code("DegreesFahrenheit").unwrap();
assert_eq!(Ok(32.0), spec.convert_value(0.0, src_unit, dst_unit));

Trait Implementations

Formats the value using the given formatter. Read more

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

Performs the conversion.

Performs the conversion.

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.