forza_dataout_parse

Crates.ioforza_dataout_parse
lib.rsforza_dataout_parse
version0.2.0
sourcesrc
created_at2024-03-01 03:45:19.311639
updated_at2024-03-10 14:30:01.863228
descriptionThis package will help you parse Forza Motorsport `data out` upd packet.
homepagehttps://github.com/SuFIND/forza_dataout_parse
repositoryhttps://github.com/SuFIND/forza_dataout_parse
max_upload_size
id1158454
size18,430
(SuFIND)

documentation

README

Forza_dataout_parse

This is a rust library specifically designed for parsing Forza DataOut output messages, currently supporting parsing of messages from the Forza MotorSport Dash.

Install

Edit Cargo.toml

  1. edit your Cargo.toml
  2. add forza_dataout_parse follow [dependencies]. like:
    [dependencies]
    # ...
    forza_dataout_parse = "x"
    
  3. exec shell
    cargo update
    

OR Use shell command

cd /your/project/path
cargo add forza_dataout_parse

How to use

This is a simple demo to listen ForzaMotorsport UPD.

use std::net::UdpSocket;
use std::thread;
use std::time::Duration;
use std::io::{self, Write};
extern crate forza_dataout_parse;
use forza_dataout_parse::dash_parser;

fn main() {
    let socket = UdpSocket::bind("0.0.0.0:5300").expect("Couldn't bind to address");
    let stdout = io::stdout();
    let mut handle = stdout.lock();

    loop {
        let mut buffer = [0; 1024];
        match socket.recv_from(&mut buffer) {
            Ok((amt, _)) => {                
                let datagram = dash_parser::parse(&buffer[..amt]);
                
                if datagram.is_race_on == 1 {
                    print!("\rspeed = {:#?}, current_lap={:#?}", datagram.get_speed_by_kmh(), datagram.current_lap);
                    // println!("{:#?}", datagram.accel);
                    let _ = handle.flush();
                }
                thread::sleep(Duration::from_micros(10));
            }
            Err(e) => {
                eprintln!("Error receiving data: {}", e);
                thread::sleep(Duration::from_micros(10));
                continue;
            }
        }
    }
}

feature map

  • 😄support to_json() and serialization power by serde @0.1.1
  • 👌basic parse for dash datagram @0.1.0
Commit count: 0

cargo fmt