Crates.io | forza_dataout_parse |
lib.rs | forza_dataout_parse |
version | 0.2.0 |
source | src |
created_at | 2024-03-01 03:45:19.311639 |
updated_at | 2024-03-10 14:30:01.863228 |
description | This package will help you parse Forza Motorsport `data out` upd packet. |
homepage | https://github.com/SuFIND/forza_dataout_parse |
repository | https://github.com/SuFIND/forza_dataout_parse |
max_upload_size | |
id | 1158454 |
size | 18,430 |
This is a rust library specifically designed for parsing Forza DataOut output messages, currently supporting parsing of messages from the Forza MotorSport Dash.
Cargo.toml
forza_dataout_parse
follow [dependencies]
. like:
[dependencies]
# ...
forza_dataout_parse = "x"
cargo update
cd /your/project/path
cargo add forza_dataout_parse
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;
}
}
}
}