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

async-resol-vbus

A Rust库,用于异步处理RESOL VBus数据

1个不稳定版本

0.1.0 2020年3月22日

#67 in #discovery

MIT/Apache

67KB
1.5K SLoC

async-resol-vbus.rs

async-resol-vbus.rs是一个用于异步处理RESOL VBus数据的Rust库。

贡献者

RESOL、VBus、VBus.net等是RESOL - Elektronische Regelungen GmbH的商标或注册商标。

所有其他商标均为其各自所有者的财产。

许可证

resol-vbus.rs在MIT许可和Apache许可(版本2.0)的条款下分发。

有关详细信息,请参阅LICENSE.txt。


lib.rs:

async-resol-vbus.rs

async-resol-vbus.rs是一个用于异步处理RESOL VBus数据的Rust库。

功能

  • 允许在本地网络中发现VBus-over-TCP设备
  • 连接到或提供VBus-over-TCP服务

计划中,但尚未实现的功能

  • 无(尚无)

示例

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

依赖项

~6–19MB
~221K SLoC