UNPKG

@z0mt3c/f1-telemetry-client

Version:

[![Node.js CI](https://github.com/z0mt3c/f1-telemetry-client/actions/workflows/node.js.yml/badge.svg)](https://github.com/z0mt3c/f1-telemetry-client/actions/workflows/node.js.yml) [![NPM Release](https://img.shields.io/npm/v/@z0mt3c/f1-telemetry-client.sv

121 lines (120 loc) 5.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PacketSessionDataParser = void 0; const F1Parser_1 = require("../F1Parser"); const MarshalZoneParser_1 = require("./MarshalZoneParser"); const PacketHeaderParser_1 = require("./PacketHeaderParser"); const WeatherForecastSampleParser_1 = require("./WeatherForecastSampleParser"); const binary_parser_1 = require("binary-parser"); class PacketSessionDataParser extends F1Parser_1.F1Parser { constructor(buffer, packetFormat, bigintEnabled) { super(); this.endianess('little') .nest('m_header', { type: new PacketHeaderParser_1.PacketHeaderParser(packetFormat, bigintEnabled), }) .uint8('m_weather') .int8('m_trackTemperature') .int8('m_airTemperature') .uint8('m_totalLaps') .uint16le('m_trackLength') .uint8('m_sessionType') .int8('m_trackId'); if (packetFormat === 2018) { this.uint8('m_era'); } if (packetFormat >= 2019) { this.uint8('m_formula'); } this.uint16le('m_sessionTimeLeft') .uint16le('m_sessionDuration') .uint8('m_pitSpeedLimit') .uint8('m_gamePaused') .uint8('m_isSpectating') .uint8('m_spectatorCarIndex') .uint8('m_sliProNativeSupport') .uint8('m_numMarshalZones') .array('m_marshalZones', { length: 21, type: new MarshalZoneParser_1.MarshalZoneParser() }) .uint8('m_safetyCarStatus') .uint8('m_networkGame'); if (packetFormat >= 2020) { this.uint8('m_numWeatherForecastSamples'); } if (packetFormat === 2020) { this.array('m_weatherForecastSamples', { type: new WeatherForecastSampleParser_1.WeatherForecastSampleParser(packetFormat), length: 20, }); } if (packetFormat >= 2021) { this.array('m_weatherForecastSamples', { type: new WeatherForecastSampleParser_1.WeatherForecastSampleParser(packetFormat), length: 56, }) .uint8('m_forecastAccuracy') .uint8('m_aiDifficulty') .uint32le('m_seasonLinkIdentifier') .uint32le('m_weekendLinkIdentifier') .uint32le('m_sessionLinkIdentifier') .uint8('m_pitStopWindowIdealLap') .uint8('m_pitStopWindowLatestLap') .uint8('m_pitStopRejoinPosition') .uint8('m_steeringAssist') .uint8('m_brakingAssist') .uint8('m_gearboxAssist') .uint8('m_pitAssist') .uint8('m_pitReleaseAssist') .uint8('m_ERSAssist') .uint8('m_DRSAssist') .uint8('m_dynamicRacingLine') .uint8('m_dynamicRacingLineType'); } if (packetFormat >= 2022) { this.uint8('m_gameMode').uint8('m_ruleSet').uint32le('m_timeOfDay').uint8('m_sessionLength'); } if (packetFormat >= 2023) { this.uint8('m_speedUnitsLeadPlayer') .uint8('m_temperatureUnitsLeadPlayer') .uint8('m_speedUnitsSecondaryPlayer') .uint8('m_temperatureUnitsSecondaryPlayer') .uint8('m_numSafetyCarPeriods') .uint8('m_numVirtualSafetyCarPeriods') .uint8('m_numRedFlagPeriods'); } if (packetFormat >= 2024) { this.uint8('m_equalCarPerformance') .uint8('m_recoveryMode') .uint8('m_flashbackLimit') .uint8('m_surfaceType') .uint8('m_lowFuelMode') .uint8('m_raceStarts') .uint8('m_tyreTemperature') .uint8('m_pitLaneTyreSim') .uint8('m_carDamage') .uint8('m_carDamageRate') .uint8('m_collisions') .uint8('m_collisionsOffForFirstLapOnly') .uint8('m_mpUnsafePitRelease') .uint8('m_mpOffForGriefing') .uint8('m_cornerCuttingStringency') .uint8('m_parcFermeRules') .uint8('m_pitStopExperience') .uint8('m_safetyCar') .uint8('m_safetyCarExperience') .uint8('m_formationLap') .uint8('m_formationLapExperience') .uint8('m_redFlags') .uint8('m_affectsLicenceLevelSolo') .uint8('m_affectsLicenceLevelMP') .uint8('m_numSessionsInWeekend') .array('m_weekendStructure', { length: 12, type: new binary_parser_1.Parser().uint8(''), }) .floatle('m_sector2LapDistanceStart') .floatle('m_sector3LapDistanceStart'); } this.data = this.fromBuffer(buffer); } } exports.PacketSessionDataParser = PacketSessionDataParser;