private void HandleSample(DataSample sample) { if (!_hasSentSessionData) { _hasSentSessionData = true; NewSessionInfo?.Invoke(SessionInfo.FromSessionData(sample.SessionData)); } _subject.OnNext(new TelemetryUpdate { MyCar = MyCarState.FromDataSample(sample), CompetitorStates = CarState.FromSample(sample) }); }
internal static IEnumerable <CarState> FromSample(DataSample data) { var result = new List <CarState>(); var t = data.Telemetry; for (var i = 0; i < t.CarDetails.Length; i++) { if (!t.HasData(i) || t.CarDetails[i].IsPaceCar) { continue; } var driverInfo = t.CarDetails[i].Driver; var competitorState = new CarState { CarIdx = i, Position = t.CarIdxPosition[i], PositionInClass = t.CarIdxClassPosition[i], Lap = t.CarIdxLap[i], LapCompleted = t.CarIdxLapCompleted[i], IsInPits = t.CarIdxOnPitRoad[i], DriverName = driverInfo.UserName, DriverID = driverInfo.UserID, TeamID = driverInfo.TeamID }; if (t.CarIdxPitStopCount != null) { competitorState.PitStopCount = t.CarIdxPitStopCount[i]; } if (t.HasRetired != null) { competitorState.HasRetired = t.HasRetired[i]; } result.Add(competitorState); } return(result); }