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
.
pub fn get_device_spec(
&self,
channel: u8,
self_address: u16,
peer_address: u16
) -> Rc<DeviceSpec>
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);
pub fn get_packet_spec(
&self,
channel: u8,
destination_address: u16,
source_address: u16,
command: u16
) -> Rc<PacketSpec>
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);
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);
pub fn fields_in_data_set<'a, T: AsRef<[Data]> + 'a>(
&'a self,
data_set: &'a T
) -> DataSetPacketFieldIterator<'a, T>ⓘNotable traits for DataSetPacketFieldIterator<'a, T>impl<'a, T: AsRef<[Data]> + 'a> Iterator for DataSetPacketFieldIterator<'a, T> type Item = DataSetPacketField<'a, T>;
pub fn fields_in_data_set<'a, T: AsRef<[Data]> + 'a>(
&'a self,
data_set: &'a T
) -> DataSetPacketFieldIterator<'a, T>ⓘNotable traits for DataSetPacketFieldIterator<'a, T>impl<'a, T: AsRef<[Data]> + 'a> Iterator for DataSetPacketFieldIterator<'a, T> type Item = DataSetPacketField<'a, T>;
Notable traits for DataSetPacketFieldIterator<'a, T>
impl<'a, T: AsRef<[Data]> + 'a> Iterator for DataSetPacketFieldIterator<'a, T> type Item = DataSetPacketField<'a, T>;
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));