f1_game_packet_parser/packets/
session_history.rs

1use super::u8_to_usize;
2use crate::constants::{ActualTyreCompound, LapValid, VisualTyreCompound};
3
4use binrw::BinRead;
5use serde::{Deserialize, Serialize};
6
7pub(super) const MAX_NUM_LAPS: usize = 100;
8pub(super) const MAX_NUM_TYRE_STINTS: usize = 8;
9
10#[non_exhaustive]
11#[derive(
12    BinRead, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize,
13)]
14#[br(little, import(packet_format: u16))]
15pub struct LapHistoryData {
16    /// Lap time in milliseconds.
17    pub lap_time_ms: u32,
18    /// Sector 1 time milliseconds part.
19    pub sector1_time_ms_part: u16,
20    /// Sector 1 whole minute part.
21    /// Available from the 2023 format onwards.
22    #[br(if(packet_format >= 2023))]
23    pub sector1_time_minutes_part: u8,
24    /// Sector 2 time milliseconds part.
25    pub sector2_time_ms_part: u16,
26    /// Sector 2 whole minute part.
27    /// Available from the 2023 format onwards.
28    #[br(if(packet_format >= 2023))]
29    pub sector2_time_minutes_part: u8,
30    /// Sector 3 time milliseconds part.
31    pub sector3_time_ms_part: u16,
32    /// Sector 3 whole minute part.
33    /// Available from the 2023 format onwards.
34    #[br(if(packet_format >= 2023))]
35    pub sector3_time_minutes: u8,
36    /// Bitmap of lap validity across all sectors and overall.
37    #[br(map(LapValid::from_bits_retain))]
38    pub lap_valid_bit_flags: LapValid,
39}
40
41#[non_exhaustive]
42#[derive(
43    BinRead, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize,
44)]
45#[br(little, import(_packet_format: u16))]
46pub struct TyreStintHistoryData {
47    /// Lap the tyre usage ends on (255 if current tyre).
48    #[br(map(u8_to_usize))]
49    pub end_lap: usize,
50    /// Actual tyre compound used.
51    pub actual_tyre_compound: ActualTyreCompound,
52    /// Visual tyre compound used.
53    pub visual_tyre_compound: VisualTyreCompound,
54}
55
56pub(super) fn get_lap_history_raw_size(packet_format: u16) -> usize {
57    if packet_format >= 2023 {
58        14
59    } else {
60        11
61    }
62}