public void ParseDynamicSessionInfo(SessionInfo info) { // Parse only session info that could have changed (driver dependent) var query = info["DriverInfo"]["Drivers"]["CarIdx", this.Id]; this.Name = query["UserName"].GetValue(""); this.CustId = Parser.ParseInt(query["UserID"].GetValue("0")); this.ShortName = query["AbbrevName"].GetValue(); this.IRating = Parser.ParseInt(query["IRating"].GetValue()); var licenseLevel = Parser.ParseInt(query["LicLevel"].GetValue()); var licenseSublevel = Parser.ParseInt(query["LicSubLevel"].GetValue()); var licenseColor = Parser.ParseColor(query["LicColor"].GetValue()); this.License = new License(licenseLevel, licenseSublevel, licenseColor); this.IsSpectator = Parser.ParseInt(query["IsSpectator"].GetValue()) == 1; this.HelmetDesign = query["HelmetDesignStr"].GetValue(); this.CarDesign = query["CarDesignStr"].GetValue(); this.SuitDesign = query["SuitDesignStr"].GetValue(); this.CarNumberDesign = query["CarNumberDesignStr"].GetValue(); this.CarSponsor1 = query["CarSponsor_1"].GetValue(); this.CarSponsor2 = query["CarSponsor_2"].GetValue(); this.ClubName = query["ClubName"].GetValue(); this.DivisionName = query["DivisionName"].GetValue(); }
public void Broadcast(SessionInfo sessionInfo) { foreach (var item in _MyServers) { item.Broadcast(sessionInfo); } }
public override void OnSessionInfoUpdated(SessionInfo info, double updateTime) { _drivers.Clear(); // Perhaps should add some locking to prevent entering this loop twice when session info updates very quickly foreach (var driver in Sim.Instance.Drivers) { _drivers.Add(driver); } }
public static Track FromSessionInfo(SessionInfo info) { var track = new Track(); var query = info["WeekendInfo"]; track.Id = Parser.ParseInt(query["TrackID"].GetValue()); track.Name = query["TrackDisplayName"].GetValue(); track.CodeName = query["TrackName"].GetValue(); track.Length = Parser.ParseTrackLength(query["TrackLength"].GetValue()); return track; }
public void Update(SessionInfo info) { this.Track = Track.FromSessionInfo(info); this.EventType = info["WeekendInfo"]["EventType"].GetValue(); this.SubsessionId = Parser.ParseInt(info["WeekendInfo"]["SubSessionID"].GetValue()); var session = info["SessionInfo"]["Sessions"]["SessionNum", Simulator.Instance.CurrentSessionNumber]; var laps = session["SessionLaps"].GetValue(); var time = Parser.ParseSec(session["SessionTime"].GetValue()); this.RaceLaps = laps; this.RaceTime = time; }
public void Update(SessionInfo info) { this.Track = Track.FromSessionInfo(info); var weekend = info["WeekendInfo"]; this.SubsessionId = Parser.ParseInt(weekend["SubSessionID"].GetValue()); this.EventType = weekend["EventType"].GetValue(); var session = info["SessionInfo"]["Sessions"]["SessionNum", Sim.Instance.CurrentSessionNumber]; this.SessionType = session["SessionType"].GetValue(); this.TrackUsageText = session["SessionTrackRubberState"].GetValue(); this.TrackUsage = TrackConditions.TrackUsageFromString(this.TrackUsageText); this.TrackCleanup = weekend["TrackCleanup"].GetValue() == "1"; this.DynamicTrack = weekend["TrackDynamicTrack"].GetValue() == "1"; var laps = session["SessionLaps"].GetValue(); var time = Parser.ParseSec(session["SessionTime"].GetValue()); this.RaceLaps = laps; this.RaceTime = time; }
public static Track FromSessionInfo(SessionInfo info) { var track = new Track(); var query = info["WeekendInfo"]; track.Id = Parser.ParseInt(query["TrackID"].GetValue()); track.Name = query["TrackDisplayName"].GetValue(); track.CodeName = query["TrackName"].GetValue(); track.Length = Parser.ParseTrackLength(query["TrackLength"].GetValue()); track.NightMode = query["WeekendOptions"]["NightMode"].GetValue() == "1"; // Parse sectors track.Sectors.Clear(); query = info["SplitTimeInfo"]["Sectors"]; int nr = 0; while (nr >= 0) { var pctString = query["SectorNum", nr]["SectorStartPct"].GetValue(); float pct; if (string.IsNullOrWhiteSpace(pctString) || !float.TryParse(pctString, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out pct)) { break; } var sector = new Sector(); sector.Number = nr; sector.StartPercentage = pct; track.Sectors.Add(sector); nr++; } return track; }
private static void wrapper_SessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e) { if (currentSessionInfo == null || getSubSessionId(currentSessionInfo) != getSubSessionId(e.SessionInfo)) { SaveCurrentRecording(); currentRecording = new List<RecordedEntry>(); currentSessionInfo = e.SessionInfo; } Debug.WriteLine("Writing entry"); currentRecording.Add(new CompressedSessionInfoEntry(e.SessionInfo.Yaml) { timeStamp = e.UpdateTime }); }
private void UpdateDriverList(SessionInfo info) { _isUpdatingDrivers = true; this.GetDrivers(info); _isUpdatingDrivers = false; this.GetResults(info); }
public void ParseStaticSessionInfo(SessionInfo info) { var query = info["DriverInfo"]["Drivers"]["CarIdx", this.Id]; this.TeamId = int.Parse(query["TeamID"].GetValue("0")); this.TeamName = query["TeamName"].GetValue(); this.CarNumber = query["CarNumber"].GetValue(); this.CarNumberRaw = int.Parse(query["CarNumberRaw"].GetValue("0")); if (this.CarNumber != null) { this.CarNumber = this.CarNumber.TrimStart('\"').TrimEnd('\"'); } this.CarId = Parser.ParseInt(query["CarID"].GetValue()); this.CarName = query["CarPath"].GetValue(); this.CarClassId = Parser.ParseInt(query["CarClassID"].GetValue()); this.CarClassRelSpeed = Parser.ParseInt(query["CarClassRelSpeed"].GetValue()); this.CarClassColor = Parser.ParseColor(query["CarClassColor"].GetValue()); //this.CarClassColor.Freeze(); this.IsPacecar = this.CustId == -1 || this.CarName == PACECAR_NAME; }
public void Broadcast(SessionInfo sessionInfo) { myHub.Clients.All.ReceiveMessage("sessioninfo received !"); }
private Car NewDriver(SessionInfo sessionInfo, int index) { YamlQuery query = sessionInfo["DriverInfo"]["Drivers"]["CarIdx", index]; string name; if (!query["UserName"].TryGetValue(out name)) { // Driver not found return null; } Car car = new Car() { id = index }; car.Name = name; car = UpdateDriver(car, index); return car; }
//private void UpdateOfftrackHistory(List<Offtrack> offtracks) //{ // if (SyncManager.Instance.Status == SyncManager.ConnectionStatus.Connected && // SyncManager.Instance.User != null) // { // Only host sends offtracks // if (SyncManager.Instance.User.IsHost) // { // SyncManager.Instance.State.SetOfftrackHistory(this.Drivers); // Send to server // SyncManager.Instance.SendStateUpdate(SyncCommandHelper.UpdateOfftracks(offtracks)); // } // } //} #endregion #endregion #region Events private void SdkOnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e) { _sessionInfo = e.SessionInfo; try { if (_mustUpdateSessionData) { _sessionData.Update(e.SessionInfo); _timeDelta = new TimeDelta((float)_sessionData.Track.Length * 1000f, 20, 64); _mustUpdateSessionData = false; this.OnStaticInfoChanged(); } App.Instance.Dispatcher.Invoke(() => { // Handle session info update this.UpdateDriverlist(e.SessionInfo); // Broadcast to windows if (this.SessionInfoUpdated != null) { this.SessionInfoUpdated(sender, e); } }); } catch (Exception ex) { App.Instance.LogError("Updating session info.", ex); } }
private void UpdateDriverlist(SessionInfo sessionInfo) { if (_isUpdatingDrivers) return; new Thread(UpdateDriversThread).Start(sessionInfo); }
private void UpdateDriverList(SessionInfo info) { Debug.WriteLine("UpdateDriverList"); _isUpdatingDrivers = true; this.GetDrivers(info); _isUpdatingDrivers = false; this.GetResults(info); }
private void Reset() { _mustUpdateSessionData = true; _mustReloadDrivers = true; _currentSessionNumber = null; _driver = null; _leader = null; _drivers.Clear(); _timeDelta = null; _telemetry = null; _sessionInfo = null; _isUpdatingDrivers = false; }
private void GetDrivers(SessionInfo info) { Debug.WriteLine("GetDrivers"); if (_mustReloadDrivers) { Debug.WriteLine("MustReloadDrivers: true"); _drivers.Clear(); _mustReloadDrivers = false; } // Assume max 70 drivers for (int id = 0; id < 70; id++) { // Find existing driver in list var driver = _drivers.SingleOrDefault(d => d.Id == id); if (driver == null) { driver = Driver.FromSessionInfo(info, id); // If no driver found, end of list reached if (driver == null) break; driver.IsCurrentDriver = false; // Add to list _drivers.Add(driver); } else { // Update and check if driver swap occurred var oldId = driver.CustId; var oldName = driver.Name; driver.ParseDynamicSessionInfo(info); if (oldId != driver.CustId) { var e = new DriverSwapRaceEvent(); e.Driver = driver; e.PreviousDriverId = oldId; e.PreviousDriverName = oldName; e.CurrentDriverId = driver.Id; e.CurrentDriverName = driver.Name; e.SessionTime = _telemetry.SessionTime.Value; e.Lap = driver.Live.Lap; this.OnRaceEvent(e); } } if (_sdk.DriverId == driver.Id) { _driver = driver; _driver.IsCurrentDriver = true; } } }
public void ParseStaticSessionInfo(SessionInfo info) { // Parse only static session info that never changes (car dependent) var query = info["DriverInfo"]["Drivers"]["CarIdx", this.Id]; this.TeamId = Parser.ParseInt(query["TeamID"].GetValue()); this.TeamName = query["TeamName"].GetValue(); this.Car.CarId = Parser.ParseInt(query["CarID"].GetValue()); this.Car.CarNumber = query["CarNumber"].GetValue(); this.Car.CarNumberRaw = Parser.ParseInt(query["CarNumberRaw"].GetValue()); this.Car.CarName = query["CarPath"].GetValue(); this.Car.CarClassId = Parser.ParseInt(query["CarClassID"].GetValue()); this.Car.CarClassRelSpeed = Parser.ParseInt(query["CarClassRelSpeed"].GetValue()); this.Car.CarClassColor = Parser.ParseColor(query["CarClassColor"].GetValue()); this.IsPacecar = this.CustId == -1 || this.Car.CarName == PACECAR_NAME; }
public static Driver FromSessionInfo(SessionInfo info, int carIdx) { var query = info["DriverInfo"]["Drivers"]["CarIdx", carIdx]; string name; if (!query["UserName"].TryGetValue(out name)) { // Driver not found return null; } var driver = new Driver(); driver.Id = carIdx; driver.ParseStaticSessionInfo(info); driver.ParseDynamicSessionInfo(info); return driver; }
private bool Notify(SessionInfo session) { bool notify = false; if (session.IsLowAlert && !session.NotifiedOnLowAlert) { session.NotifiedOnLowAlert = true; notify = true; } else if (session.IsHighAlert && !session.NotifiedOnHighAlert) { session.NotifiedOnHighAlert = true; notify = true; } else if (session.IsFinalAlert && !session.NotifiedOnFinalAlert) { session.NotifiedOnFinalAlert = true; notify = true; } if (notify) { var s = Config<UserSettings>.Instance; if (s.IsSpeechAlertingEnabled) { Speak(session.RemainingTimeSpeech()); } if (s.IsTextAlertingEnabled && IsConnected && IsIRacingWindowForeground()) { Text(session.RemainingTimeText()); } } return notify; }
private static string getSubSessionId(SessionInfo sessionInfo) { return sessionInfo["WeekendInfo"]["SubSessionID"].Value; }
private static void SaveCurrentRecording() { if (currentSessionInfo == null) { return; } var filename = getSubSessionId(currentSessionInfo) + " - " + DateTime.Now.ToString("yyyy-MM-ddTHHMM") + " .dat"; var path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); using (Stream stream = File.Open(Path.Combine(path, filename), FileMode.Create)) { using (GZipStream compressedStream = new GZipStream(stream, CompressionMode.Compress)) { var formatter = new BinaryFormatter(); formatter.Serialize(compressedStream, currentRecording); } } currentSessionInfo = null; AppContext.notifyIcon.ShowBalloonTip(1000, "iRacing Telemetry Recorder", "Recording Saved: " + filename, ToolTipIcon.Info); }
private void GetDrivers(SessionInfo info) { if (_mustReloadDrivers) { _drivers.Clear(); _mustReloadDrivers = false; } // Assume max 70 drivers for (int id = 0; id < 70; id++) { // Find existing driver in list var driver = _drivers.SingleOrDefault(d => d.Id == id); if (driver == null) { driver = Driver.FromSessionInfo(info, id); driver.IsCurrentDriver = false; // If no driver found, end of list reached if (driver == null) break; // Add to list _drivers.Add(driver); } else { // Update and check if driver swap occurred var oldId = driver.CustId; var oldName = driver.Name; driver.ParseDynamicSessionInfo(info); if (oldId != driver.CustId) { var e = new DriverSwapEventArgs(oldId, driver.Id, oldName, driver.Name, driver, _telemetry.SessionTime.Value); this.OnDriverSwap(e); } } if (_sdk.DriverId == driver.Id) { _driver = driver; _driver.IsCurrentDriver = true; } } }
public SessionInfoUpdatedEventArgs(string sessionInfo, double time) : base(time) { _SessionInfo = new SessionInfo(sessionInfo, time); }
private void GetRaceResults(SessionInfo info) { var query = info["SessionInfo"]["Sessions"]["SessionNum", _currentSessionNumber]["ResultsPositions"]; for (int position = 1; position <= _drivers.Count; position++) { var positionQuery = query["Position", position]; string idValue; if (!positionQuery["CarIdx"].TryGetValue(out idValue)) { // Driver not found continue; } // Find driver and update results int id = int.Parse(idValue); var driver = _drivers.SingleOrDefault(d => d.Id == id); if (driver != null) { var previousPosition = driver.Results.Current.ClassPosition; driver.UpdateResultsInfo(_currentSessionNumber.Value, positionQuery, position); if (_telemetry != null) { // Check for new leader if (previousPosition > 1 && driver.Results.Current.ClassPosition == 1) { var e = new LeaderChangeEventArgs(driver, _telemetry.SessionTime.Value); this.OnLeaderChange(e); } // Check for new best lap var bestlap = _sessionData.UpdateFastestLap(driver.CurrentResults.FastestTime, driver); if (bestlap != null) { var e = new FastLapEventArgs(driver, bestlap, _telemetry.SessionTime.Value); this.OnFastLap(e); } } } } }
public void UpdateDrivers(SessionInfo sessionInfo, bool reloadDrivers = false) { if (reloadDrivers) { telemetry.Sessions.CurrentSession.Drivers.ResetDrivers(); } for (int i = 0; i < 70; i++) { // Find existing driver in list var driver = telemetry.Sessions.CurrentSession.Drivers.DriverList.SingleOrDefault(d => d.id == i); if (driver == null) { driver = NewDriver(sessionInfo, i); // If no driver found, end of list reached if (driver == null) break; driver.IsCurrentDriver = false; // Add to list telemetry.Sessions.CurrentSession.Drivers.DriverList.Add(driver); } else { UpdateDriver(driver, i); // Update and check if driver swap occurred /** var oldId = driver.CustId; var oldName = driver.Name; driver.ParseDynamicSessionInfo(info); if (oldId != driver.CustId) { var e = new DriverSwapRaceEvent(); e.Driver = driver; e.PreviousDriverId = oldId; e.PreviousDriverName = oldName; e.CurrentDriverId = driver.Id; e.CurrentDriverName = driver.Name; e.SessionTime = _telemetry.SessionTime.Value; e.Lap = driver.Live.Lap; this.OnRaceEvent(e); }**/ } if (wrapper.DriverId == driver.id) { driver.IsCurrentDriver = true; string lastLapTime = wrapper.GetTelemetryValue<float>("LapLastLapTime").Value.ToString(); driver.LastLapTime = GetBestLApTime(lastLapTime); } } var tt = 56; }
private void GetResults(SessionInfo info) { // If currently updating list, or no session yet, then no need to update result info if (_isUpdatingDrivers) return; if (_currentSessionNumber == null) return; this.GetQualyResults(info); this.GetRaceResults(info); }
private void OnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e) { sessionInfo = e.SessionInfo; // Stop if we don't have a session number yet if (telemetry.Sessions.CurrentSession.SessionNum == null) return; if (_mustUpdateSessionData) { UpdateSessionInformation(); } // if (_mustReloadDrivers) // { UpdateDrivers(sessionInfo); // } }
private void SdkOnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e) { // Cache previous and current info _previousSessionInfo = _sessionInfo; _sessionInfo = e.SessionInfo; // Stop if we don't have a session number yet if (_currentSessionNumber == null) return; if (_mustUpdateSessionData) { _sessionData.Update(e.SessionInfo); _timeDelta = new TimeDelta((float)_sessionData.Track.Length * 1000f, 20, 64); _mustUpdateSessionData = false; this.OnStaticInfoChanged(); } // Update drivers this.UpdateDriverList(e.SessionInfo); this.OnSessionInfoUpdated(e); }
private void GetQualyResults(SessionInfo info) { // TODO: stop if qualy is finished var query = info["QualifyResultsInfo"]["Results"]; for (int position = 0; position < _drivers.Count; position++) { var positionQuery = query["Position", position]; string idValue; if (!positionQuery["CarIdx"].TryGetValue(out idValue)) { // Driver not found continue; } // Find driver and update results int id = int.Parse(idValue); var driver = _drivers.SingleOrDefault(d => d.Id == id); if (driver != null) { driver.UpdateQualyResultsInfo(positionQuery, position); } } }
public abstract void OnSessionInfoUpdated(SessionInfo info, double updateTime);