#processing #asynchronous #data #resol #devices #v-bus #discovery

async-resol-vbus

A Rust library for processing RESOL VBus data asynchronously

1 unstable release

0.1.0 Mar 22, 2020

#3 in #asynchronously

MIT/Apache

67KB
1.5K SLoC

async-resol-vbus.rs

A Rust library for processing RESOL VBus data asynchronously.

Contributors

RESOL, VBus, VBus.net and others are trademarks or registered trademarks of RESOL - Elektronische Regelungen GmbH.

All other trademarks are the property of their respective owners.

License

resol-vbus.rs is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE.txt for details.


lib.rs:

async-resol-vbus.rs

A Rust library for processing RESOL VBus data asynchronously.

Features

  • Allows discovery of VBus-over-TCP devices in a local network
  • Connect to or provide VBus-over-TCP services

Planned, but not yet implemented features

  • none (yet)

Examples

use std::fs::File;

use async_std::{
    net::{SocketAddr, TcpStream},
    prelude::*,
};

use resol_vbus::{DataSet, RecordingWriter};

use async_resol_vbus::{Result, LiveDataStream, TcpClientHandshake};

fn main() -> Result<()> {
    async_std::task::block_on(async {
        // Create an recording file and hand it to a `RecordingWriter`
        let file = File::create("test.vbus")?;
        let mut rw = RecordingWriter::new(file);
    
        // Parse the address of the DL2 to connect to
        let addr = "192.168.13.45:7053".parse::<SocketAddr>()?;

        let stream = TcpStream::connect(addr).await?;

        let mut hs = TcpClientHandshake::start(stream).await?;
        hs.send_pass_command("vbus").await?;
        let stream = hs.send_data_command().await?;

        let (reader, writer) = (&stream, &stream);

        let mut stream = LiveDataStream::new(reader, writer, 0, 0x0020);

        while let Some(data) = stream.receive_any_data(60000).await? {
            println!("{}", data.id_string());

            // Add `Data` value into `DataSet` to be stored
            let mut data_set = DataSet::new();
            data_set.timestamp = data.as_ref().timestamp;
            data_set.add_data(data);

            // Write the `DataSet` into the `RecordingWriter` for permanent storage
            rw.write_data_set(&data_set)
                .expect("Unable to write data set");
        }

        Ok(())
    })
}

Dependencies

~6–17MB
~218K SLoC