Crate resol_vbus

Source
Expand description

§resol-vbus.rs

A Rust library for processing RESOL VBus data.

§Features

  • Provides types for different VBus data versions
  • Processes live and recorded VBus data streams
  • Converts binary VBus data into human or machine readable format

§Planned, but not yet implemented features

  • Improve filtering and conversion of VBus data fields

§Supported Devices & Services

§Technical Information & Specifications

§Converter for recorded VBus data to CSV.

//! A converter from the binary recorded VBus file format to human-readable CSV.
extern crate resol_vbus;

use std::fs::File;
use std::io::{Read, Write};

use resol_vbus::*;
use resol_vbus::chrono::{Local};


/// Load the VSF file to allow decoding of the payload contained in `Packet` `frame_data` values.
fn load_vsf_file(vsf_filename: &str) -> Specification {
    let mut f = File::open(vsf_filename).unwrap();

    let mut buf = Vec::new();
    let size = f.read_to_end(&mut buf).unwrap();

    let spec_file = SpecificationFile::from_bytes(&buf [0..size]).unwrap();

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

    spec
}


/// Read the "*.vbus" files a second time to convert / process the `DataSet` values within.
fn print_data(file_list: Vec<String>, topology_data_set: DataSet, spec: &Specification) {
    let flr = FileListReader::new(file_list);

    let mut rr = LiveDataRecordingReader::new(flr);

    let mut cumultative_data_set = topology_data_set;

    let mut output = std::io::stdout();

    while let Some(data) = rr.read_data().unwrap() {
        let timestamp = data.as_ref().timestamp;
        let local_timestamp = timestamp.with_timezone(&Local);

        cumultative_data_set.add_data(data);

        write!(output, "{}", local_timestamp).unwrap();

        for field in spec.fields_in_data_set(&cumultative_data_set.as_ref()) {
            write!(output, "\t{}", field.fmt_raw_value(false)).unwrap();
        }

        write!(output, "\n").unwrap();
    }
}


fn main() {
    let vsf_filename = "res/vbus_specification.vsf";

    let file_list = std::env::args().skip(1).map(|arg| arg.to_owned()).collect::<Vec<_>>();

    // Load the VSF file to allow decoding of `Packet` values.
    let spec = load_vsf_file(vsf_filename);

    // Read the "*.vbus" files once to find all unique `Packet` values. This allows to
    // only generate CSV column headers once and keep the column layout stable throughout
    // the conversion.
    let flr = FileListReader::new(file_list.clone());

    let mut rr = LiveDataRecordingReader::new(flr);

    let topology_data_set = rr.read_topology_data_set().unwrap();
    for data in topology_data_set.as_data_slice() {
        println!("{}: {:?}", data.id_string(), data);
    }

    // Read the "*.vbus" files a second time to convert / process the `DataSet` values within.
    print_data(file_list, topology_data_set, &spec);
}

Re-exports§

Modules§

  • Functions in this module can be used to decode byte slices of data conforming to the VBus protocol specification into the respective Data variants.
  • Functions in the module can be used to convert a Data variant into the respective live representation according to the VBus protocol specification.
  • Functions in this module allow to decode a byte stream conforming to the VBus Recording File Format.
  • Functions in the module can be used to convert a Data variant into the respective recorded representation according to the VBus Recording File Format.
  • This module provides the Specification and its associated types to allow interpretation of the fields contained within the frame_data payload of Packet values.
  • A module that parses the contents of a VBus Specification File Version 1 (VSF1).
  • A module containing utitlities functions for processing VBus data.

Structs§

  • A size-adating buffer to store bytes in. The buffer grows when data is stored into it. The contents can then be consumed which results in the buffer dropping the consumed data before new data are appended.
  • A buffering reader that allows to borrow the internal buffer.
  • A DataSet contains a set of unique (non-identical) Data values.
  • The Datagram type stores information according to the VBus protocol version 2.x.
  • A common error type.
  • Chains multiple files together in a single Read object.
  • All VBus data types consist of a Header element.
  • A size-adapting buffer that supports decoding VBus live data. See BlobBuffer for details.
  • Allows reading Data variants from a Read trait object.
  • A RecordingReader for type 0x88 live data recordings.
  • A RecordingWriter for type 0x88 live data recordings.
  • Allows writing the live represenation of Data variants to a Write trait object.
  • The Packet type stores information according to the VBus protocol version 1.x.
  • A tuple of identification information about a field in a Packet value.
  • A tuple of identification information about a Packet value.
  • Allows reading Data variants from a Read trait object.
  • Allows writing the recorded representation of DataSet values to a Write trait object.
  • The Telegram type stores information according to the VBus protocol version 3.x.

Enums§

  • Data is a type that contains one of the supported VBus protocol data variants.
  • Provides information whether a slice of bytes contains a valid blob of data.

Traits§

  • A trait to generate an identification hash for any of the VBus data types.
  • A trait to get a PacketFieldId for a given value.
  • A trait to get a PacketId for a given value.

Functions§

  • Calculate the identification hash for a given VBus data value.

Type Aliases§