Represents an object from which you can get Telemetry var headers by name
        //Thanks to Stephane Turpin for locking algorithm
        public int getBrakeVibe(TelemetryInfo telem, int trkTol, int trkSens)
        {
            speed = Convert.ToDouble(telem.Speed.Value);
            rpm = Convert.ToDouble(telem.RPM.Value);
            brake = Convert.ToDouble(telem.Brake.Value);

            //Calculates the ratio between the RPM and car speed
            //If RPM is minimum and the car is still moving -> we probably have locked tires
            if (speed > 1) {
                old_ratio = ratio;
                ratio = rpm / speed;
            } else {
                old_ratio = 0;
                ratio = 0;
            }

            //Check if we are pressing the breakes and the ratio is increasing (same RPM and less speed = higher ratio)
            send = 0;
            thres = (double)trkTol / 100D;
            sens = 0.010 - ((double)trkSens / 1000D);

            if (brake > thres) {
                if ((ratio > old_ratio) || (Math.Abs((ratio - old_ratio) / ratio) > sens)) {
                    send = 1;
                }
            }
            return send;
        }
Exemple #2
0
 public void Broadcast(TelemetryInfo telemetryInfo)
 {
     foreach (var item in _MyServers)
     {
         item.Broadcast(telemetryInfo);
     }
 }
        public void fetch(TelemetryInfo telem, iRacingSDK sdk, double fuelVal, Boolean sendTimeReset, Boolean sendTime, double prevFuel)
        {
            Gear = telem.Gear.Value;
            Speed = telem.Speed.Value;
            RPM = Convert.ToInt16(telem.RPM.Value);
            Shift = telem.ShiftIndicatorPct.Value;
            Lap = telem.Lap.Value > 199 ? 199 : telem.Lap.Value;
            Engine = (byte)(Convert.ToString(telem.EngineWarnings.Value).Contains("PitSpeedLimiter") ? 1 : 0);
            DeltaNeg = 0;
            Mins = 0;

            if (fuelVal != 0)
            {
                double tmp = Math.Round(telem.FuelLevel.Value/fuelVal, 2);
                if (tmp > 99.9)
                    Fuel = Convert.ToInt16(Math.Round(tmp));
                else if(tmp > 9.99){
                    Fuel = Convert.ToInt16(Math.Round(tmp * 10));
                    Engine |= 1 << 1;
                }
                else
                {
                    Fuel = Convert.ToInt16(Math.Round(tmp * 100));
                    Engine |= 2 << 1;
                }

            }
            else
            {
                Fuel = Convert.ToInt16(Math.Round(telem.FuelLevelPct.Value * 100));
                Engine |= 3 << 1;
            }

            if (prevFuel != 0)
                Engine |= (1 << 4);
            if (sendTimeReset)
                Engine |= (1 << 5);
            if (sendTime)
            {
                Engine |= (1 << 6);
                float l = Convert.ToSingle(sdk.GetData("LapLastLapTime"));
                if (l > 0)
                {
                    Mins = Convert.ToInt16(Math.Floor(l / 60));
                    int Secs = Convert.ToInt16(Math.Floor(l - (Mins * 60)));
                    int mSecs = Convert.ToInt16(Math.Floor((l - (Secs + (Mins * 60))) * 1000));
                    Delta = (Secs << 9) | mSecs;
                }
            }
            else
            {
                Delta = (int)(Math.Round(Convert.ToSingle(sdk.GetData("LapDeltaToBestLap")) * 1000));
                if (Delta <= 0)
                {
                    DeltaNeg = 1;
                    Delta = Delta * -1;
                }
                Delta = Delta > 9999 ? 9999 : Delta;
            }
        }
 public override void OnTelemetryUpdated(TelemetryInfo info, double updateTime)
 {
     if (updateTime - _lastUpdate > 1)
     {
         _driversView.Refresh();
         _lastUpdate = updateTime;
     }
 }
        public void CalculateSpeed(TelemetryInfo current, double? trackLengthKm)
        {
            if (current == null) return;
            if (trackLengthKm == null) return;

            try
            {
                var t1 = current.SessionTime.Value;
                var t0 = _prevSpeedUpdateTime;
                var time = t1 - t0;

                if (time < SPEED_CALC_INTERVAL)
                {
                    // Ignore
                    return;
                }

                var p1 = current.CarIdxLapDistPct.Value[this.Driver.Id];
                var p0 = _prevSpeedUpdateDist;

                if (p1 < -0.5 || _driver.Live.TrackSurface == TrackSurfaces.NotInWorld)
                {
                    // Not in world?
                    return;
                }

                if (p0 - p1 > 0.5)
                {
                    // Lap crossing
                    p1 += 1;
                }
                var distancePct = p1 - p0;

                var distance = distancePct*trackLengthKm.GetValueOrDefault()*1000; //meters


                if (time >= Double.Epsilon)
                {
                    this.Speed = distance/(time); // m/s
                }
                else
                {
                    if (distance < 0)
                        this.Speed = Double.NegativeInfinity;
                    else
                        this.Speed = Double.PositiveInfinity;
                }
                this.SpeedKph = this.Speed * 3.6;

                _prevSpeedUpdateTime = t1;
                _prevSpeedUpdateDist = p1;
            }
            catch (Exception ex)
            {
                //Log.Instance.LogError("Calculating speed of car " + this.Driver.Id, ex);
                this.Speed = 0;
            }
        }
        public void ParseTelemetry(TelemetryInfo e)
        {
            this.Speed = e.Speed.Value;
            this.Throttle = e.Throttle.Value;
            this.Brake = e.Brake.Value;
            this.Clutch = e.Clutch.Value;
            this.Fuel = e.FuelLevel.Value;
            this.FuelPercentage = e.FuelLevelPct.Value;
            this.FuelPressure = e.FuelPress.Value;

            // TODO: add remaining parameters
        }
        public void ParseTelemetry(TelemetryInfo e)
        {
            this.Lap = e.CarIdxLap.Value[this.Driver.Id];
            this.LapDistance = e.CarIdxLapDistPct.Value[this.Driver.Id];
            this.TrackSurface = e.CarIdxTrackSurface.Value[this.Driver.Id];

            this.Gear = e.CarIdxGear.Value[this.Driver.Id];
            this.Rpm = e.CarIdxRPM.Value[this.Driver.Id];
            this.SteeringAngle = e.CarIdxSteer.Value[this.Driver.Id];

            this.Driver.PitInfo.CalculatePitInfo(e.SessionTime.Value);
        }
Exemple #8
0
        private void UpdateDriverTelemetry(TelemetryInfo info)
        {
            // If currently updating list, no need to update telemetry info
            if (_isUpdatingDrivers) return;

            if (_driver != null) _driver.UpdatePrivateInfo(info);
            foreach (var driver in _drivers)
            {
                driver.UpdateLiveInfo(info);
                driver.Live.CalculateSpeed(_previousTelemetry, _telemetry, _sessionData.Track.Length);
            }

            this.CalculateLivePositions();
            this.UpdateTimeDelta();
        }
Exemple #9
0
        private void SdkOnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // Cache previous and current info
            _previousTelemetry = _telemetry;
            _telemetry = e.TelemetryInfo;

            // Check if session changed
            if (_currentSessionNumber == null || (_currentSessionNumber.Value != e.TelemetryInfo.SessionNum.Value))
            {
                _mustUpdateSessionData = true;

                // Session changed, reset session info
                this.ResetSession();
            }

            // Store current session number
            _currentSessionNumber = e.TelemetryInfo.SessionNum.Value;

            // Update session state
            _sessionData.UpdateState(e.TelemetryInfo.SessionState.Value);

            // Update drivers telemetry
            this.UpdateDriverTelemetry(e.TelemetryInfo);

            // Update session data
            this.SessionData.Update(e.TelemetryInfo);

            this.OnTelemetryUpdated(e);
        }
Exemple #10
0
        private void SdkOnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // Cache info
            _telemetry = e.TelemetryInfo;

            _isReplay = e.TelemetryInfo.IsReplayPlaying.Value;

            // Check if session changed
            if (_currentSessionNumber == null || (_currentSessionNumber.Value != e.TelemetryInfo.SessionNum.Value))
            {
                _mustUpdateSessionData = true;

                // Session changed, reset session info
                this.ResetSession();
            }

            // Store current session number
            _currentSessionNumber = e.TelemetryInfo.SessionNum.Value;

            // Get previous state
            var sessionWasFinished = this.SessionData.IsFinished;
            var prevFlags = this.SessionData.Flags;

            // Update session state
            _sessionData.UpdateState(e.TelemetryInfo.SessionState.Value);

            // Update drivers telemetry
            this.UpdateDriverTelemetry(e.TelemetryInfo);

            // Update session data
            this.SessionData.Update(e.TelemetryInfo);

            // Check if flags updated
            this.CheckSessionFlagUpdates(prevFlags, this.SessionData.Flags);

            if (!sessionWasFinished && this.SessionData.IsFinished)
            {
                // If session just finished, get winners
                // Use result position (not live position)
                var winners =
                    Drivers.Where(d => d.CurrentResults != null && d.CurrentResults.ClassPosition == 1).OrderBy(d => d.CurrentResults.Position);
                foreach (var winner in winners)
                {
                    var ev = new WinnerRaceEvent();
                    ev.Driver = winner;
                    ev.SessionTime = _telemetry.SessionTime.Value;
                    ev.Lap = winner.Live.Lap;
                    this.OnRaceEvent(ev);
                }
            }
            this.OnTelemetryUpdated(e);
        }
Exemple #11
0
 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 printTelemInfo(TelemetryInfo telem)
        {
            try
            {
                if (this.chkTelem.Checked) {
                    telemTextBox.Clear();

                    String gr = "";
                    if (telem.Gear.Value == -1)
                        gr = "R";
                    else if (telem.Gear.Value == 0)
                        gr = "N";
                    else
                        gr = Convert.ToString(telem.Gear.Value);

                    telemPrint("Car: " + car);
                    telemPrint("Track: " + track);
                    telemPrint("");
                    telemPrint("Gear: " + gr);
                    telemPrint("RPM: " + Math.Round(telem.RPM.Value));
                    telemPrint("Speed: " + (this.cboSpdUnit.SelectedIndex == 0 ? Math.Round(telem.Speed.Value * 2.23693629, 1) + "MPH" : Math.Round(telem.Speed.Value * (2.23693629 * 1.609344), 1) + "KPH"));
                    telemPrint("");
                    telemPrint("Lap: " + telem.Lap.Value);
                    telemPrint("Total Flying Laps Completed: " + fuelLaps);
                    telemPrint("");
                    telemPrint("Fuel PCT: " + telem.FuelLevelPct.Value * 100);
                    telemPrint("Fuel Lvl (L): " + telem.FuelLevel.Value);
                    telemPrint("Fuel Use on Current Lap (L): " + ((this.prevFuel - telem.FuelLevel.Value)>0 ? Math.Round(this.prevFuel - telem.FuelLevel.Value, 3) : 0));
                    telemPrint("Fuel Use Per Lap Avg(L): " + Math.Round(fuelEst, 5));
                    telemPrint("Laps Left EST: " + Math.Round(telem.FuelLevel.Value / fuelEst, 2));
                    telemPrint("");
                }
            }
            catch (Exception exe)
            {
                ExceptionHelper.writeToLogFile(exe.Message, exe.ToString(), "Print Telemetry", exe.LineNumber(), this.FindForm().Name);
            }
        }
 private void estimateFuel(TelemetryInfo telem)
 {
     if (prevFuel != 0)
     {
         double usg = prevFuel - telem.FuelLevel.Value;
         double tmp = (fuelEst * fuelLaps) + usg;
         fuelLaps += 1;
         fuelEst = tmp / fuelLaps;
         cfg.writeSetting(track + "-" + car, Convert.ToString(fuelEst));
         cfg.writeSetting(track + "-" + car + "-l", Convert.ToString(fuelLaps));
         //console("Recalculate Fuel Usage per Lap to: " + fuelEst);
     }
     prevFuel = telem.FuelLevel.Value;
 }
 public abstract void OnTelemetryUpdated(TelemetryInfo info, double updateTime);
 public TelemetryUpdatedEventArgs(TelemetryInfo info, double time) : base(time)
 {
     _TelemetryInfo = info;
 }
Exemple #16
0
 public void Broadcast(TelemetryInfo telemetryInfo)
 {
     myHub.Clients.All.ReceiveMessage(Math.Round((Convert.ToSingle(telemetryInfo.Speed.Value) * 3600 / 1000), 2, MidpointRounding.AwayFromZero));
 }
 public TelemetryData(TelemetryInfo info, int driverCarIdx)
 {
     this.info = info;
     this.DriverCarIdx = driverCarIdx;
 }
Exemple #18
0
 public void SendTelemetry(TelemetryInfo telemetry)
 {
     Clients.All.SendTelemetry(telemetry);
 }
        private void SdkOnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            _telemetry = e.TelemetryInfo;

            try
            {
                App.Instance.Dispatcher.Invoke(() =>
                {
                    // Handle telemetry update
                    this.UpdateDriverTelemetry(e);

                    // Update session data
                    this.SessionData.Update(e.TelemetryInfo);

                    // Broadcast to windows
                    if (this.TelemetryUpdated != null)
                    {
                        this.TelemetryUpdated(sender, e);
                    }
                });
            }
            catch (Exception ex)
            {
                App.Instance.LogError("Updating telemetry.", ex);
            }

            _previousTelemetry = e.TelemetryInfo;
        }
        public void CalculateSpeed(TelemetryInfo previous, TelemetryInfo current, double? trackLengthKm)
        {
            if (previous == null || current == null) return;
            if (trackLengthKm == null) return;

            try
            {
                var distancePct = current.CarIdxLapDistPct.Value[this.Driver.Id] -
                                  previous.CarIdxLapDistPct.Value[this.Driver.Id];
                var distance = distancePct*trackLengthKm.GetValueOrDefault();

                var time = current.SessionTime.Value - previous.SessionTime.Value;

                if (time >= Double.Epsilon)
                {
                    this.Speed = distance/time;
                }
                else
                {
                    if (distance < 0)
                        this.Speed = Double.NegativeInfinity;
                    else
                        this.Speed = Double.PositiveInfinity;
                }
            }
            catch (Exception ex)
            {
                //Log.Instance.LogError("Calculating speed of car " + this.Driver.Id, ex);
                this.Speed = 0;
            }
        }
Exemple #21
0
 internal void UpdatePrivateInfo(TelemetryInfo e)
 {
     this.Private.ParseTelemetry(e);
 }
        public void UpdateSectorTimes(Track track, TelemetryInfo telemetry)
        {
            if (track == null) return;
            if (track.Sectors.Count == 0) return;

            var results = this.CurrentResults;
            if (results != null)
            {
                var sectorcount = track.Sectors.Count;

                // Set arrays
                if (results.SectorTimes == null || results.SectorTimes.Length == 0)
                {
                    results.SectorTimes = track.Sectors.Select(s => s.Copy()).ToArray();
                }

                var p0 = _prevPos;
                var p1 = telemetry.CarIdxLapDistPct.Value[this.Id];
                var dp = p1 - p0;

                if (p1 < -0.5)
                {
                    // Not in world?
                    return;
                }

                var t = telemetry.SessionTime.Value;
                
                // Check lap crossing
                if (p0 - p1 > 0.5) // more than 50% jump in track distance == lap crossing occurred from 0.99xx -> 0.00x
                {
                    this.Live.CurrentSector = 0;
                    this.Live.CurrentFakeSector = 0;
                    p0 -= 1;
                }
                    
                // Check all real sectors
                foreach (var s in results.SectorTimes)
                {
                    if (p1 > s.StartPercentage && p0 <= s.StartPercentage)
                    {
                        // Crossed into new sector
                        var crossTime = (float)(t - (p1 - s.StartPercentage) * dp);

                        // Finish previous
                        var prevNum = s.Number <= 0 ? sectorcount - 1 : s.Number - 1;
                        var sector = results.SectorTimes[prevNum];
                        if (sector != null && sector.EnterSessionTime > 0)
                        {
                            sector.SectorTime = new Laptime((float)(crossTime - sector.EnterSessionTime));
                        }

                        // Begin next sector
                        s.EnterSessionTime = crossTime;

                        this.Live.CurrentSector = s.Number;

                        break;
                    }
                }

                // Check 'fake' sectors (divide track into thirds)
                sectorcount = 3;
                foreach (var s in results.FakeSectorTimes)
                {
                    if (p1 > s.StartPercentage && p0 <= s.StartPercentage)
                    {
                        // Crossed into new sector
                        var crossTime = (float)(t - (p1 - s.StartPercentage) * dp);

                        // Finish previous
                        var prevNum = s.Number <= 0 ? sectorcount - 1 : s.Number - 1;
                        var sector = results.FakeSectorTimes[prevNum];
                        if (sector != null && sector.EnterSessionTime > 0)
                        {
                            sector.SectorTime = new Laptime((float)(crossTime - sector.EnterSessionTime));
                        }

                        // Begin next sector
                        s.EnterSessionTime = crossTime;

                        this.Live.CurrentFakeSector = s.Number;

                        break;
                    }
                }
                
                _prevPos = p1;
            }
        }
 public void ParseTelemetry(TelemetryInfo e)
 {
     this.Lap = e.CarIdxLap.Value[this.Driver.Id];
     this.LapDistance = e.CarIdxLapDistPct.Value[this.Driver.Id];
     this.TrackSurface = e.CarIdxTrackSurface.Value[this.Driver.Id];
 }
Exemple #24
0
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // Grab a copy of the session info
            telemetryInfo = e.TelemetryInfo;

            ReadData();

            // Deal with the session changing
            if (telemetry.Sessions.CurrentSession == null || (telemetry.Sessions.CurrentSession.SessionNum != telemetryInfo.SessionNum.Value))
            {
                _mustUpdateSessionData = true;

                // Session changed, reset session info
                this.ResetSession();
            }
        }
 public override void OnTelemetryUpdated(TelemetryInfo info, double updateTime)
 {
 }
 public void Update(TelemetryInfo telemetry)
 {
     this.SessionTime = telemetry.SessionTime.Value;
     this.TimeRemaining = telemetry.SessionTimeRemain.Value;
 }
Exemple #27
0
 internal void UpdateLiveInfo(TelemetryInfo e)
 {
     this.Live.ParseTelemetry(e);
 }