예제 #1
0
        public void OnTelemetryUpdate(Object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // there is apparently nothing in the telemetry data to tell us the session identifier
            // (meaning the session id that would be displayed in iRacing results); the session
            // identifers in the telemetry seem be as follows:
            //   SessionNum      --> an index into the Sessions in the SessionInfo
            //   SessionUniqueId --> I've only seen the number 1 so far in an official practice
            // this means we can't know the sessionLogPath until it has been calculated by the
            // first session info update so can log no telemetry updates until that occurs; in
            // practice this seems to be fine
            if (record && sessionLogPath != null)
            {
                // NOTE: we only record fields which we've exposed in ITelemetryInfo for two reasons.
                // First, there is no way to simply get a copy of the whole binary record from iRSDKSharp,
                // so we'd have to loop across all the fields by name and read each one (we do a subset of
                // this of course in the solution below, but only on a smallish number of fields).
                // A second reason is simply to keep our session log file as small as possible.
                using (BinaryWriter w = AppendBinary(sessionLogPath))
                {
                    w.Write(2); // telemetry update record identifier
                    w.Write(e.TelemetryInfo.SessionFlags.Value.Value);
                    w.Write(e.TelemetryInfo.SessionNum.Value);
                    w.Write(e.TelemetryInfo.SessionUniqueID.Value);
                    w.Write(e.TelemetryInfo.SessionTimeRemain.Value);
                    w.Write(wrapper.GetTelemetryValue <int>("SessionLapsRemain").Value);
                }
            }

            telemetryUpdateHandlers.ForEach(
                h => h.Invoke(sender, new TelemetryUpdatedEventProxy(
                                  new TelemetryInfoProxy(wrapper, e.TelemetryInfo))));
        }
예제 #2
0
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            var replayFrame    = e.TelemetryInfo.ReplayFrameNum.Value;
            var replayEndFrame = wrapper.GetTelemetryValue <int>("ReplayFrameNumEnd").Value;
            var sum            = replayFrame + replayEndFrame;

            label1.Text = "ReplayFrameNum: " + replayFrame
                          + "\n\nReplayFrameNumEnd: " + replayEndFrame
                          + "\n\nSum: " + sum
                          + "\n\nSessionTime: " + e.TelemetryInfo.SessionTime.Value
                          + "\n\nReplaySessionTime: " + e.TelemetryInfo.ReplaySessionTime.Value;


            progressBar1.Minimum = 0;
            progressBar1.Maximum = sum;
            progressBar1.Value   = replayFrame;
        }
예제 #3
0
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (m_maxFuel < 0.1)
            {
                m_wrapper.RequestSessionInfoUpdate();
            }

            var inPits = m_wrapper.GetTelemetryValue <bool>("OnPitRoad").Value;

            m_is_metric_units = m_wrapper.GetTelemetryValue <int>("DisplayUnits").Value == 1;
            var sessionState = e.TelemetryInfo.SessionState.Value;
            var lastLapId    = e.TelemetryInfo.LapCompleted.Value;

            var flag = e.TelemetryInfo.SessionFlags.Value;

            if (flag.Contains(SessionFlags.Green) && !m_isGreen)
            {
                m_isGreen = true;
                m_logger.Debug("Green Flag!");
            }
            else if (flag.Contains(SessionFlags.Caution) || flag.Contains(SessionFlags.CautionWaving) && m_isGreen)
            {
                m_isGreen = false;
                m_logger.Debug("Caution Flag!");
            }

            m_sessionRemainingTime = e.TelemetryInfo.SessionTimeRemain.Value;
            UpdateFuelCalc(e);

            if (lastLapId > 0 && m_lastLapCompleted != lastLapId)
            {
                m_lastLapCompleted = lastLapId;
                OnNewLap(e, inPits, sessionState);
            }

            if (m_inPits != inPits)
            {
                OnPitEntry(e, inPits, sessionState);
            }

            UpdateLabels();
        }
예제 #4
0
        // Event handler called when the telemetry is updated
        private void wrapper_TelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (connection.isOpen())
            {
                dataPacket data = new dataPacket(console);
                data.fetch(e.TelemetryInfo, wrapper.Sdk, fuelEst, chkBrake.Checked ? brk.getBrakeVibe(e.TelemetryInfo, trkTol.Value, trkSens.Value) : 0,
                           sendTimeReset, sendTime, prevFuel);
                connection.send(data.compile(this.cboSpdUnit.SelectedIndex == 0, this.trkIntensity.Value));
                sendTime      = false;
                sendTimeReset = false;

                float ll = Convert.ToSingle(wrapper.Sdk.GetData("LapLastLapTime"));

                if (ll != prevLapTime)
                {
                    if (prevFuel != 0 && ll > 0)
                    {
                        sendTime    = true;
                        prevLapTime = ll;
                    }
                }

                if (e.TelemetryInfo.Lap.Value > prevLap)
                {
                    sendTimeReset = true;
                    estimateFuel(e.TelemetryInfo);
                    prevLap = e.TelemetryInfo.Lap.Value;
                }

                if (wrapper.GetTelemetryValue <Boolean[]>("CarIdxOnPitRoad").Value[driverID])
                {
                    prevFuel = 0;
                }
            }

            if (ticker % 5 == 0)
            {
                printTelemInfo(e.TelemetryInfo);
                ticker += 1;
            }

            if (ticker == 40)
            {
                ticker = 0;
            }
            else
            {
                ticker += 1;
            }
        }
예제 #5
0
        // Event handler called when the telemetry is updated
        // This happens (max) 60 times per second
        private void wrapper_TelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            telemetryLabel.Text = string.Format("Telemetry (last updated {0})", DateTime.Now.TimeOfDay.ToString());

            // Let's just write some random values:
            StringBuilder sb = new StringBuilder();

            this.TelemetryExample(sb, e);
            this.ArrayExample(sb, e);
            this.BitfieldsExample(sb, e);

            // Get a (fictional) value that is not covered in the TelemetryInfo properties
            var fictionalObject = wrapper.GetTelemetryValue <int>("VariableName");
            var fictionalValue  = fictionalObject.Value;

            telemetryTextBox.Text = sb.ToString();
        }
예제 #6
0
        /// <summary>
        /// Called when [telemetry updated].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="SdkWrapper.TelemetryUpdatedEventArgs"/> instance containing the event data.</param>
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            _ti = e.TelemetryInfo;

            if (_currentSessionNumber == null || (_currentSessionNumber.Value != _ti.SessionNum.Value))
            {
                _forceSessionUpdate = true;
            }

            _currentSessionNumber = _ti.SessionNum.Value;

            if (_ti.IsInGarage.Value == false && _ti.IsOnTrack.Value == false)
            {
                _telemetryData.Car.InCar = false;
            }
            else
            {
                _telemetryData.Car.InCar = true;
            }
            _telemetryData.Engine.RPM        = _ti.RPM.Value;
            _telemetryData.Car.Speed         = ConvertSpeedToMPH(_ti.Speed.Value);
            _telemetryData.Car.Gear          = _ti.Gear.Value;
            _telemetryData.Car.FuelRemaining = _ti.FuelLevel.Value;
            if (_ti.FuelLevelPct.Value != 0)
            {
                _telemetryData.Car.FuelCapacity = (100 / (_ti.FuelLevelPct.Value * 100)) * _ti.FuelLevel.Value;
            }
            else
            {
                _telemetryData.Car.FuelCapacity = 0;
            }

            _telemetryData.Timing.CurrentLapTime = _wrapper.GetTelemetryValue <float>("LapCurrentLapTime").Value;

            _telemetryData.Engine.WaterTemp = _ti.WaterTemp.Value;

            _timingData.RaceInfo.SessionTime = _ti.SessionTime.Value;
        }
예제 #7
0
        // Event handler called when the telemetry is updated
        private void wrapper_TelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            try
            {
                if (connection.isOpen())
                {
                    if (!connection.isFake())
                    {
                        dataPacket data = new dataPacket(console);
                        data.fetch(e.TelemetryInfo, wrapper.Sdk, fuelEst, sendTimeReset, sendTime, prevFuel);
                        connection.send(data.compile(this.cboSpdUnit.SelectedIndex == 0, this.trkIntensity.Value));

                        sendTime      = false;
                        sendTimeReset = false;

                        float ll = Convert.ToSingle(wrapper.Sdk.GetData("LapLastLapTime"));

                        if (ll != prevLapTime)
                        {
                            if (prevFuel != 0 && ll > 0)
                            {
                                sendTime    = true;
                                prevLapTime = ll;
                            }
                        }
                    }


                    if (e.TelemetryInfo.Lap.Value > prevLap)
                    {
                        estimateFuel(e.TelemetryInfo);
                        prevLap       = e.TelemetryInfo.Lap.Value;
                        sendTimeReset = true;
                    }

                    if (wrapper.GetTelemetryValue <Boolean[]>("CarIdxOnPitRoad").Value[driverID])
                    {
                        prevFuel = 0;
                    }
                }

                if (ticker % 5 == 0)
                {
                    printTelemInfo(e.TelemetryInfo);
                    ticker += 1;
                }

                if (ticker == 40)
                {
                    ticker = 0;
                }
                else
                {
                    ticker += 1;
                }
            }
            catch (Exception exe)
            {
                ExceptionHelper.writeToLogFile(exe.Message, exe.ToString(), "Update Arduino", exe.LineNumber(), this.FindForm().Name);
            }
        }
예제 #8
0
        protected override string getTelemetryValue(string name, string type, string clazz)
        {
            string result = "";

            try {
                if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(type))
                {
                    switch (type)
                    {
                    case "int":
                        int value = wrapper.GetTelemetryValue <int>(name).Value;
                        if (name.Equals("Gear", StringComparison.InvariantCultureIgnoreCase))
                        {
                            //return reverse symbol
                            if (value < 0)
                            {
                                return("R");
                            }
                        }
                        result = value.ToString();
                        break;

                    case "float":
                        result = wrapper.GetTelemetryValue <float>(name).Value.ToString();
                        break;

                    case "bool":
                        result = wrapper.GetTelemetryValue <bool>(name).Value.ToString();
                        break;

                    case "double":
                        result = wrapper.GetTelemetryValue <double>(name).Value.ToString();
                        break;

                    case "bitfield":
                        result = wrapper.GetTelemetryValue <byte>(name).Value.ToString();
                        break;

                    //todo: add handler for arrays
                    case "kmh":
                        result = ((int)Math.Floor(wrapper.GetTelemetryValue <float>(name).Value * 3.6)).ToString();
                        break;

                    case "time":
                        float    seconds  = wrapper.GetTelemetryValue <float>(name).Value;
                        TimeSpan interval = TimeSpan.FromSeconds(seconds);
                        result = interval.ToString(@"mm\.ss\.fff");
                        break;

                    case "dtime":
                        double   dseconds  = wrapper.GetTelemetryValue <double>(name).Value;
                        TimeSpan dinterval = TimeSpan.FromSeconds(dseconds);
                        result = dinterval.ToString(@"mm\.ss\.fff");
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                logger.LogExceptionToFile(e);
            }

            return(result);
        }
예제 #9
0
파일: Form1.cs 프로젝트: gearysw/IrFuelCalc
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (m_maxFuel < 0.1)
            {
                m_wrapper.RequestSessionInfoUpdate();
            }

            var inPits       = m_wrapper.GetTelemetryValue <bool>("OnPitRoad").Value;
            var sessionState = e.TelemetryInfo.SessionState.Value;
            var lastLapId    = e.TelemetryInfo.LapCompleted.Value;

            if (lastLapId > 0 && m_lastLapCompleted != lastLapId)
            {
                m_lastLapCompleted     = lastLapId;
                m_sessionRemainingTime = e.TelemetryInfo.SessionTimeRemain.Value;

                var fuelLevel = e.TelemetryInfo.FuelLevel.Value;
                var laptime   = m_wrapper.GetTelemetryValue <float>("LapLastLapTime").Value;
                var flag      = e.TelemetryInfo.SessionFlags.Value;

                m_logger.Debug("Lap Completed {0}", m_lastLapCompleted);
                m_logger.Debug("\t- Time: {0}", laptime);
                m_logger.Debug("\t- Fuel Level: {0}", fuelLevel);

                if (m_lastFuelLevel >= fuelLevel && !inPits)
                {
                    var fuelDelta = m_lastFuelLevel - fuelLevel;
                    if (!cbOnlyGreen.Checked || (cbOnlyGreen.Checked && sessionState == SessionStates.Racing && flag.Contains(SessionFlags.Green)))
                    {
                        m_lapTimes.Add(laptime);
                        m_fuelUsages.Add(fuelDelta);
                    }

                    m_fuelLastLap    = fuelDelta;
                    m_averageLapTime = GetAvg(m_lapTimes.Where(l => l > 0.0));
                    m_fuelPerLap     = GetAvg(m_fuelUsages);

                    var avgFuel = m_fuelPerLap * (double)nudFuelMult.Value;

                    m_estimatedLaps     = (int)Math.Ceiling(m_sessionRemainingTime / m_averageLapTime);
                    m_totalFuelRequired = avgFuel * (m_estimatedLaps + (int)nudLapOffset.Value);
                    m_estimatedStops    = (int)Math.Ceiling(m_totalFuelRequired / m_maxFuel);

                    var totalFuelThisStop = m_totalFuelRequired / m_estimatedStops;
                    m_fuelToAdd = (int)Math.Ceiling(totalFuelThisStop - e.TelemetryInfo.FuelLevel.Value);

                    m_logger.Debug("\t- Fuel Delta: {0}", fuelDelta);
                    m_logger.Debug("\t- Avg Laptime: {0}", m_averageLapTime);
                    m_logger.Debug("\t- Avg Fuel Delta: {0}", m_fuelPerLap);

                    m_logger.Debug("\t- Laps Remaining: {0}", m_estimatedLaps);
                    m_logger.Debug("\t- Total Fuel Required: {0}", m_totalFuelRequired);
                    m_logger.Debug("\t- Stops Remaining: {0}", m_estimatedStops);
                }

                m_lastFuelLevel = fuelLevel;

                UpdateLabels();
            }

            if (m_inPits != inPits)
            {
                var oldInPits = m_inPits;
                m_inPits = inPits;

                if (!oldInPits)
                {
                    // Entering pit, send off command to set fuel.
                    m_logger.Debug("Entering Pits");

                    if (m_sessionRemainingTime > 0 && m_averageLapTime > 0 && m_fuelPerLap > 0 && sessionState == SessionStates.Racing)
                    {
                        var fuelThisStop = (int)Math.Ceiling((m_totalFuelRequired / m_estimatedStops) - e.TelemetryInfo.FuelLevel.Value);
                        m_logger.Debug("\t- Adding {0} litres of fuel", fuelThisStop);

                        if (m_autoFuel)
                        {
                            m_logger.Debug("\t- AutoFuel enabled.");
                            m_wrapper.PitCommands.AddFuel(fuelThisStop);
                        }
                        else
                        {
                            m_logger.Debug("\t- AutoFuel disabled.");
                        }
                    }
                }
            }
        }