-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a tool to record and replay sessions (#16)
- Loading branch information
1 parent
801b857
commit ed52566
Showing
11 changed files
with
640 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
Oops, something went wrong.