f1_game_packet_parser/packets/
laps.rs

1use super::u8_to_bool;
2use crate::constants::{DriverStatus, PitStatus, ResultStatus, Sector};
3
4use binrw::BinRead;
5use serde::{Deserialize, Serialize};
6
7/// Lap data for a car on track.
8#[non_exhaustive]
9#[derive(BinRead, PartialEq, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize)]
10#[br(little, import(packet_format: u16))]
11pub struct LapData {
12    /// Last lap time in milliseconds.
13    pub last_lap_time_ms: u32,
14    /// Current lap time in milliseconds.
15    pub current_lap_time_ms: u32,
16    /// Current sector 1 time millisecond part.
17    pub sector1_time_ms_part: u16,
18    /// Sector 1 whole minute part.
19    /// Available from the 2023 format onwards.
20    #[br(if(packet_format >= 2023))]
21    pub sector1_time_minutes_part: u8,
22    /// Current sector 2 time millisecond part.
23    pub sector2_time_ms_part: u16,
24    /// Sector 2 whole minute part.
25    /// Available from the 2023 format onwards.
26    #[br(if(packet_format >= 2023))]
27    pub sector2_time_minutes_part: u8,
28    /// Time delta to car in front in milliseconds.
29    /// Available from the 2023 format onwards.
30    #[br(if(packet_format >= 2023))]
31    pub delta_to_car_in_front_ms_part: u16,
32    /// Time delta to car in front whole minute part.
33    /// Available from the 2024 format onwards.
34    #[br(if(packet_format >= 2024))]
35    pub delta_to_car_in_front_minutes_part: u8,
36    /// Time delta to race leader in milliseconds.
37    /// Available from the 2023 format onwards.
38    #[br(if(packet_format >= 2023))]
39    pub delta_to_race_leader_ms: u16,
40    /// Time delta to car in front whole minute part.
41    /// Available from the 2024 format onwards.
42    #[br(if(packet_format >= 2024))]
43    pub delta_to_race_leader_minutes_part: u8,
44    /// The distance the vehicle is around current lap in metres.
45    /// It may be negative if the start/finish line hasn’t been crossed yet.
46    pub lap_distance: f32,
47    /// The total distance the vehicle has gone around in this session in metres.
48    /// It may be negative if the start/finish line hasn’t been crossed yet.
49    pub total_distance: f32,
50    /// Delta for the safety car in seconds.
51    pub safety_car_delta: f32,
52    /// Car's race position.
53    pub car_position: u8,
54    /// Current lap number.
55    pub current_lap_num: u8,
56    /// Car's pit status.
57    pub pit_status: PitStatus,
58    /// Number of pit stops taken in this race.
59    pub num_pit_stops: u8,
60    /// Zero-based number of the sector the driver is currently going through.
61    pub sector: Sector,
62    /// Whether the current lap is invalid.
63    #[br(try_map(u8_to_bool))]
64    pub current_lap_invalid: bool,
65    /// Accumulated time penalties to be added in seconds.
66    pub penalties: u8,
67    /// Accumulated number of warnings issued.
68    pub total_warnings: u8,
69    /// Accumulated number of corner cutting warnings issued.
70    /// Available from the 2023 format onwards.
71    #[br(if(packet_format >= 2023))]
72    pub corner_cutting_warnings: u8,
73    /// Number of unserved drive through penalties left to serve.
74    pub num_unserved_drive_through_pens: u8,
75    /// Number of unserved stop-go penalties left to serve.
76    pub num_unserved_stop_go_pens: u8,
77    /// The grid position the vehicle started the race in.
78    pub grid_position: u8,
79    /// Status of the driver.
80    pub driver_status: DriverStatus,
81    /// Status of the driver's result.
82    pub result_status: ResultStatus,
83    /// Whether the pit lane timer is active.
84    #[br(try_map(u8_to_bool))]
85    pub pit_lane_timer_active: bool,
86    /// Current time spent in the pit lane in milliseconds.
87    pub pit_lane_time_in_lane_ms: u16,
88    /// Time of the actual pit stop in milliseconds.
89    pub pit_stop_timer_ms: u16,
90    /// Whether the car should serve a penalty at this stop.
91    #[br(try_map(u8_to_bool))]
92    pub pit_stop_should_serve_pen: bool,
93    /// Fastest speed through speed trap for this car in kilometres per hour.
94    /// Available from the 2024 format onwards.
95    #[br(if(packet_format >= 2024))]
96    pub speed_trap_fastest_speed: f32,
97    /// Number of the lap the fastest speed was achieved on
98    /// (255 means "not set").
99    /// Available from the 2024 format onwards.
100    #[br(if(packet_format >= 2024))]
101    pub speed_trap_fastest_lap: u8,
102}