[][src]Crate resol_vbus

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

pub use chrono;
pub use crate::specification::Specification;
pub use crate::specification_file::Language;
pub use crate::specification_file::SpecificationFile;

Modules

live_data_decoder

Functions in this module can be used to decode byte slices of data conforming to the VBus protocol specification into the respective Data variants.

live_data_encoder

Functions in the module can be used to convert a Data variant into the respective live representation according to the VBus protocol specification.

recording_decoder

Functions in this module allow to decode a byte stream conforming to the VBus Recording File Format.

recording_encoder

Functions in the module can be used to convert a Data variant into the respective recorded representation according to the VBus Recording File Format.

specification

This module provides the Specification and its associated types to allow interpretation of the fields contained within the frame_data payload of Packet values.

specification_file

A module that parses the contents of a VBus Specification File Version 1 (VSF1).

utils

A module containing utitlities functions for processing VBus data.

Structs

BlobBuffer

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.

BlobReader

A buffering reader that allows to borrow the internal buffer.

DataSet

A DataSet contains a set of unique (non-identical) Data values.

Datagram

The Datagram type stores information according to the VBus protocol version 2.x.

Error

A common error type.

FileListReader

Chains multiple files together in a single Read object.

Header

All VBus data types consist of a Header element.

LiveDataBuffer

A size-adapting buffer that supports decoding VBus live data. See BlobBuffer for details.

LiveDataReader

Allows reading Data variants from a Read trait object.

LiveDataRecordingReader

A RecordingReader for type 0x88 live data recordings.

LiveDataRecordingWriter

A RecordingWriter for type 0x88 live data recordings.

LiveDataWriter

Allows writing the live represenation of Data variants to a Write trait object.

Packet

The Packet type stores information according to the VBus protocol version 1.x.

PacketFieldId

A tuple of identification information about a field in a Packet value.

PacketId

A tuple of identification information about a Packet value.

RecordingReader

Allows reading Data variants from a Read trait object.

RecordingWriter

Allows writing the recorded representation of DataSet values to a Write trait object.

Telegram

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

Enums

Data

Data is a type that contains one of the supported VBus protocol data variants.

StreamBlobLength

Provides information whether a slice of bytes contains a valid blob of data.

Traits

IdHash

A trait to generate an identification hash for any of the VBus data types.

ToPacketFieldId

A trait to get a PacketFieldId for a given value.

ToPacketId

A trait to get a PacketId for a given value.

Functions

id_hash

Calculate the identification hash for a given VBus data value.

Type Definitions

Result

A common result type.