#parser #converter #translator


Victron Energy Direct protocol parser and units converter

8 releases

0.1.7 Sep 15, 2022
0.1.6 Sep 15, 2022

#1833 in Parser implementations

45 downloads per month

MIT license

1.5K SLoC


Victron Energy Direct protocol parser and units converter

Parser takes raw input from uart serial port and outputs parsed map of fields, then it is passed through to converter for standardization and translation


Victron Energy Direct protocol parser and converter. Project provides parser for protocol packets and converter for standardizing units and translation of the packet


use tokio::io::AsyncReadExt;
use tokio_serial::SerialPortBuilderExt;
use std::time::Duration;
use crate::converter::convert;
use crate::parser::Parser;

async fn main() -> tokio_serial::Result<()> {
// initialize serial port
    let mut port = tokio_serial::new("/dev/serial0", 19200)

    // initialize buffer and parser
    let mut buf: Vec<u8> = vec![0; 2048];
    let mut parser = Parser::new();

        // read loop
        if let Ok(r) = port.read(&mut buf).await {
            // data from serial port are served in chunks so it takes couple loops to get one packet parsed
            if let Ok(parsed) = parser.parse_slice(&buf[..r]) {
                // when it is parsed do conversion
                println!("{:?}", convert(parsed));


~67K SLoC