Skip to content

Commit

Permalink
Add a tool to record and replay sessions (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-lemay authored Mar 7, 2024
1 parent 801b857 commit ed52566
Show file tree
Hide file tree
Showing 11 changed files with 640 additions and 3 deletions.
136 changes: 136 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"f1-packet-recorder",
"f1-telemetry",
"f1-telemetry-common",
"f1-telemetry-display",
Expand Down
17 changes: 17 additions & 0 deletions f1-packet-recorder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "f1-packet-recorder"
version = "0.1.0"
description = "Utility to record and replay sessions."
authors = ["Mathieu Lemay <acidrain1@gmail.com>"]
edition = "2021"

[dependencies]
f1-telemetry = { path = "../f1-telemetry" }
f1-telemetry-common = { path = "../f1-telemetry-common" }
anyhow = "1.0.80"
clap = { version = "4.0.4", features = ["derive", "env"] }
ctrlc = "3.4.2"
log = "0.4.17"
rusqlite = { version = "0.31.0", features = ["bundled"] }
simplelog = "0.12.0"
time = "0.3.11"
86 changes: 86 additions & 0 deletions f1-packet-recorder/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
use anyhow::Result;
use clap::{Args, Parser, Subcommand};
use log::LevelFilter;
use simplelog::{ColorChoice, TerminalMode};

use f1_telemetry_common::logging::LogBuilder;

mod player;
mod recorder;
mod utils;

#[derive(Parser)]
#[command(author, version, about, long_about = None, propagate_version = true)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum Commands {
/// Replay a recorded session
Play(PlayArgs),

/// Record an incoming session
Record(RecordArgs),
}

#[derive(Debug, Args)]
struct PlayArgs {
/// Database file to replay
// #[clap(long, default_value = None)]
file: String,

/// Destination IP address. Leave empty to use broadcast.
#[clap(long, default_value = None)]
destination: Option<String>,

/// Port to write to.
#[clap(long, default_value = "20777")]
port: u16,

/// Loop over the database
#[clap(long = "loop")]
loop_play: bool,

/// Play the packets in realtime or not.
#[clap(long)]
realtime: bool,

/// Real-time playback factor (higher is faster)
#[clap(long, default_value = "1.0")]
realtime_factor: f32,

/// Number of packets to skip at the start of the file
#[clap(long, default_value = "0")]
skip: u64,
}

#[derive(Debug, Args)]
struct RecordArgs {
/// Database file to record to
#[clap(short, long, default_value = None)]
file: String,

/// Host to bind on for the UDP packet listener
#[clap(long, default_value = "0.0.0.0")]
host: String,

/// Port to bind on for the UDP packet listener
#[clap(long, default_value = "20777")]
port: u16,
}

fn main() -> Result<()> {
let cli = Cli::parse();

LogBuilder::new()
.with_term_logger(LevelFilter::Info, TerminalMode::Mixed, ColorChoice::Auto)
.build()
.expect("Error initializing logger.");

match &cli.command {
Commands::Play(args) => player::play(args),
Commands::Record(args) => recorder::record(args),
}
}
Loading

0 comments on commit ed52566

Please sign in to comment.