mirror of
https://github.com/italicsjenga/fh5-telemetry-watcher.git
synced 2024-12-23 14:11:33 +11:00
ok it works lol
This commit is contained in:
parent
d6a755bb74
commit
cbe2e07969
34
Cargo.lock
generated
34
Cargo.lock
generated
|
@ -19,6 +19,15 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bincode"
|
||||||
|
version = "1.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
|
@ -86,12 +95,6 @@ dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itoa"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
@ -161,12 +164,6 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ryu"
|
|
||||||
version = "1.0.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.136"
|
version = "1.0.136"
|
||||||
|
@ -187,17 +184,6 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_json"
|
|
||||||
version = "1.0.79"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
|
|
||||||
dependencies = [
|
|
||||||
"itoa",
|
|
||||||
"ryu",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
|
@ -219,9 +205,9 @@ dependencies = [
|
||||||
name = "telemetry"
|
name = "telemetry"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bincode",
|
||||||
"clap",
|
"clap",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -8,4 +8,4 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "3.1.1", features = ["derive"] }
|
clap = { version = "3.1.1", features = ["derive"] }
|
||||||
serde = { version = "1.0.136", features = ["derive"] }
|
serde = { version = "1.0.136", features = ["derive"] }
|
||||||
serde_json = "1.0.79"
|
bincode = "1.3.3"
|
166
src/main.rs
166
src/main.rs
|
@ -1,17 +1,120 @@
|
||||||
|
use std::net;
|
||||||
|
use std::net::UdpSocket;
|
||||||
|
|
||||||
|
use bincode;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[clap(short, long, default_value = "")]
|
#[clap(short, long, default_value = "")]
|
||||||
folder: String,
|
folder: String,
|
||||||
|
|
||||||
|
#[clap(short, long, default_value_t = 9999)]
|
||||||
|
port: i32,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
verbose: bool,
|
||||||
|
|
||||||
|
#[clap(short, long)]
|
||||||
|
errors: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Telemetry {
|
struct Telemetry {
|
||||||
is_race_on: bool,
|
// is_race_on: i32,
|
||||||
time_stamp_ms: u64,
|
// timestamp_ms: u32,
|
||||||
|
// engine_max_rpm: f32,
|
||||||
|
// engine_idle_rpm: f32,
|
||||||
|
// current_engine_rpm: f32,
|
||||||
|
// acceleration_x: f32,
|
||||||
|
// acceleration_y: f32,
|
||||||
|
// acceleration_z: f32,
|
||||||
|
// velocity_x: f32,
|
||||||
|
// velocity_y: f32,
|
||||||
|
// velocity_z: f32,
|
||||||
|
// angular_velocity_x: f32,
|
||||||
|
// angular_velocity_y: f32,
|
||||||
|
// angular_velocity_z: f32,
|
||||||
|
// yaw: f32,
|
||||||
|
// pitch: f32,
|
||||||
|
// roll: f32,
|
||||||
|
// normalized_suspension_travel_front_left: f32,
|
||||||
|
// normalized_suspension_travel_front_right: f32,
|
||||||
|
// normalized_suspension_travel_rear_left: f32,
|
||||||
|
// normalized_suspension_travel_rear_right: f32,
|
||||||
|
// tire_slip_ratio_front_left: f32,
|
||||||
|
// tire_slip_ratio_front_right: f32,
|
||||||
|
// tire_slip_ratio_rear_left: f32,
|
||||||
|
// tire_slip_ratio_rear_right: f32,
|
||||||
|
// wheel_rotation_speed_front_left: f32,
|
||||||
|
// wheel_rotation_speed_front_right: f32,
|
||||||
|
// wheel_rotation_speed_rear_left: f32,
|
||||||
|
// wheel_rotation_speed_rear_right: f32,
|
||||||
|
// wheel_on_rumble_strip_front_left: i32,
|
||||||
|
// wheel_on_rumble_strip_front_right: i32,
|
||||||
|
// wheel_on_rumble_strip_rear_left: i32,
|
||||||
|
// wheel_on_rumble_strip_rear_right: i32,
|
||||||
|
// wheel_in_puddle_depth_front_left: f32,
|
||||||
|
// wheel_in_puddle_depth_front_right: f32,
|
||||||
|
// wheel_in_puddle_depth_rear_left: f32,
|
||||||
|
// wheel_in_puddle_depth_rear_right: f32,
|
||||||
|
// surface_rumble_front_left: f32,
|
||||||
|
// surface_rumble_front_right: f32,
|
||||||
|
// surface_rumble_rear_left: f32,
|
||||||
|
// surface_rumble_rear_right: f32,
|
||||||
|
// tire_slip_angle_front_left: f32,
|
||||||
|
// tire_slip_angle_front_right: f32,
|
||||||
|
// tire_slip_angle_rear_left: f32,
|
||||||
|
// tire_slip_angle_rear_right: f32,
|
||||||
|
// tire_combined_slip_front_left: f32,
|
||||||
|
// tire_combined_slip_front_right: f32,
|
||||||
|
// tire_combined_slip_rear_left: f32,
|
||||||
|
// tire_combined_slip_rear_right: f32,
|
||||||
|
// suspension_travel_meters_front_left: f32,
|
||||||
|
// suspension_travel_meters_front_right: f32,
|
||||||
|
// suspension_travel_meters_rear_left: f32,
|
||||||
|
// suspension_travel_meters_rear_right: f32,
|
||||||
|
// car_ordinal: i32,
|
||||||
|
// car_class: i32,
|
||||||
|
// car_performance_index: i32,
|
||||||
|
// drivetrain_type: i32,
|
||||||
|
// num_cylinders: i32,
|
||||||
|
// horizon_placeholder1: u32,
|
||||||
|
// horizon_placeholder2: u32,
|
||||||
|
// horizon_placeholder3: u32,
|
||||||
|
// position_x: f32,
|
||||||
|
// position_y: f32,
|
||||||
|
// position_z: f32,
|
||||||
|
// speed: f32,
|
||||||
|
// power: f32,
|
||||||
|
// torque: f32,
|
||||||
|
// tire_temp_front_left: f32,
|
||||||
|
// tire_temp_front_right: f32,
|
||||||
|
// tire_temp_rear_left: f32,
|
||||||
|
// tire_temp_rear_right: f32,
|
||||||
|
// boost: f32,
|
||||||
|
// fuel: f32,
|
||||||
|
// distance_traveled: f32,
|
||||||
|
// best_lap: f32,
|
||||||
|
// last_lap: f32,
|
||||||
|
// current_lap: f32,
|
||||||
|
// current_race_time: f32,
|
||||||
|
// lap_number: u16,
|
||||||
|
// race_position: u8,
|
||||||
|
// accel: u8,
|
||||||
|
// brake: u8,
|
||||||
|
// clutch: u8,
|
||||||
|
// hand_brake: u8,
|
||||||
|
// gear: u8,
|
||||||
|
// steer: i8,
|
||||||
|
// normalized_driving_line: i8,
|
||||||
|
// normalized_ai_brake_difference: i8,
|
||||||
|
|
||||||
|
// BORDER
|
||||||
|
is_race_on: i32,
|
||||||
|
time_stamp_ms: u32,
|
||||||
engine_max_rpm: f32,
|
engine_max_rpm: f32,
|
||||||
engine_idle_rpm: f32,
|
engine_idle_rpm: f32,
|
||||||
current_engine_rpm: f32,
|
current_engine_rpm: f32,
|
||||||
|
@ -68,14 +171,14 @@ struct Telemetry {
|
||||||
drivetrai32ype: i32,
|
drivetrai32ype: i32,
|
||||||
num_cylinders: i32,
|
num_cylinders: i32,
|
||||||
car_type: i32,
|
car_type: i32,
|
||||||
unknown1: i8,
|
unknown1: u8,
|
||||||
unknown2: i8,
|
unknown2: u8,
|
||||||
unknown3: i8,
|
unknown3: u8,
|
||||||
unknown4: i8,
|
unknown4: u8,
|
||||||
unknown5: i8,
|
unknown5: u8,
|
||||||
unknown6: i8,
|
unknown6: u8,
|
||||||
unknown7: i8,
|
unknown7: u8,
|
||||||
unknown8: i8,
|
unknown8: u8,
|
||||||
car_ordinal: i32,
|
car_ordinal: i32,
|
||||||
position_x: f32,
|
position_x: f32,
|
||||||
position_y: f32,
|
position_y: f32,
|
||||||
|
@ -95,19 +198,46 @@ struct Telemetry {
|
||||||
current_lap: f32,
|
current_lap: f32,
|
||||||
current_race_time: f32,
|
current_race_time: f32,
|
||||||
lap_number: i16,
|
lap_number: i16,
|
||||||
race_position: i8,
|
race_position: u8,
|
||||||
accel: i8,
|
accel: u8,
|
||||||
brake: i8,
|
brake: u8,
|
||||||
clutch: i8,
|
clutch: u8,
|
||||||
handbrake: i8,
|
handbrake: u8,
|
||||||
gear: i8,
|
gear: u8,
|
||||||
steer: i8,
|
steer: i8,
|
||||||
normalized_driving_line: i8,
|
normalized_driving_line: i8,
|
||||||
normalized_ai_brake_difference: i8,
|
normalized_ai_brake_difference: i8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn listen(socket: &net::UdpSocket, mut buffer: &mut [u8]) -> usize {
|
||||||
|
let (number_of_bytes, _) = socket.recv_from(&mut buffer).expect("no data received");
|
||||||
|
number_of_bytes
|
||||||
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
let ip = format!("0.0.0.0:{}", args.port.to_string());
|
||||||
|
|
||||||
println!("Folder: {}", args.folder);
|
if args.verbose {
|
||||||
|
if args.folder != "" {
|
||||||
|
println!("Folder: {}", args.folder);
|
||||||
|
} else {
|
||||||
|
println!("No folder specified - not saving logs");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let socket = UdpSocket::bind(ip).expect("couldnt bind");
|
||||||
|
let mut buf = [0; 500];
|
||||||
|
|
||||||
|
while listen(&socket, &mut buf) != 0 {
|
||||||
|
let deserialised: Telemetry = bincode::deserialize(&buf).expect("couldnt deser");
|
||||||
|
if deserialised.current_engine_rpm == 0.0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if args.verbose {
|
||||||
|
println!(
|
||||||
|
"Gear: {}, RPM: {}",
|
||||||
|
deserialised.gear, deserialised.current_engine_rpm
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue