ve_direct/lib.rs
1#![cfg(not(doctest))]
2
3//! Victron Energy Direct protocol parser and converter.
4//! Project provides parser for protocol packets and converter for standardizing units and translation of the packet
5
6//! # Example
7//! ```
8//! use tokio::io::AsyncReadExt;
9//! use tokio_serial::SerialPortBuilderExt;
10//! use std::time::Duration;
11//! use crate::converter::convert;
12//! use crate::parser::Parser;
13//!
14//! #[tokio::main]
15//! async fn main() -> tokio_serial::Result<()> {
16//! // initialize serial port
17//! let mut port = tokio_serial::new("/dev/serial0", 19200)
18//! .timeout(Duration::from_secs(5))
19//! .open_native_async()?;
20//!
21//! // initialize buffer and parser
22//! let mut buf: Vec<u8> = vec![0; 2048];
23//! let mut parser = Parser::new();
24//!
25//! loop{
26//! // read loop
27//! if let Ok(r) = port.read(&mut buf).await {
28//! // data from serial port are served in chunks so it takes couple loops to get one packet parsed
29//! if let Ok(parsed) = parser.parse_slice(&buf[..r]) {
30//! // when it is parsed do conversion
31//! println!("{:?}", convert(parsed));
32//! }
33//! }
34//! }
35//! }
36//! ```
37
38pub mod converter;
39pub mod parser;
40
41#[cfg(test)]
42mod tests;
43
44pub use self::converter::convert;
45pub use self::converter::models::*;
46pub use self::parser::models::*;
47pub use self::parser::Parser;