f1_game_packet_parser/packets/
session.rs1use crate::constants::{MarshalZoneFlag, TemperatureChange, Weather};
2use binrw::BinRead;
3use serde::{Deserialize, Serialize};
4
5pub(super) const MAX_NUM_MARSHAL_ZONES: usize = 21;
6pub(super) const MARSHAL_ZONE_RAW_SIZE: usize = 5;
7pub(super) const FORECAST_SAMPLE_RAW_SIZE: usize = 8;
8pub(super) const MAX_AI_DIFFICULTY: u8 = 110;
9pub(super) const MAX_NUM_SESSIONS: usize = 12;
10
11#[non_exhaustive]
13#[derive(BinRead, PartialEq, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize)]
14#[br(
15 little,
16 import(_packet_format: u16),
17 assert(
18 (0.0..1.0).contains(&zone_start),
19 "Marshal zone has an invalid zone start value: {}",
20 zone_start
21 )
22)]
23pub struct MarshalZone {
24 pub zone_start: f32,
26 pub zone_flag: MarshalZoneFlag,
28}
29
30#[non_exhaustive]
31#[derive(
33 BinRead, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize,
34)]
35#[br(
36 little,
37 import(_packet_format: u16),
38 assert(
39 rain_percentage <= 100,
40 "Weather forecast sample has an invalid rain percentage value: {}",
41 rain_percentage
42 )
43)]
44pub struct WeatherForecastSample {
45 pub session_type: u8,
49 pub time_offset: u8,
51 pub weather: Weather,
53 pub track_temperature: i8,
55 pub track_temperature_change: TemperatureChange,
57 pub air_temperature: i8,
59 pub air_temperature_change: TemperatureChange,
61 pub rain_percentage: u8,
63}
64
65pub(super) fn check_num_forecast_samples(packet_format: u16, num_samples: usize) -> bool {
66 num_samples <= get_max_num_samples(packet_format)
67}
68
69pub(super) fn get_forecast_samples_padding(
70 packet_format: u16,
71 num_samples: usize,
72) -> usize {
73 (get_max_num_samples(packet_format) - num_samples) * FORECAST_SAMPLE_RAW_SIZE
74}
75
76fn get_max_num_samples(packet_format: u16) -> usize {
77 if packet_format >= 2024 {
78 64
79 } else {
80 56
81 }
82}