public static void Sample()
        {
            var iracing = new iRacingConnection();

            Trace.WriteLine("Moving to 4 minutes before end of replay");

            iracing.Replay.MoveToFrame(4 * 60 * 60, ReplayPositionMode.End);
            iracing.Replay.SetSpeed(2);
            Thread.Sleep(3000);

            int lastCount = 0;

            foreach (var data in iracing.GetDataFeed().AtSpeed(8)
                .WithFinishingStatus()
                .TakeUntil(5.Seconds()).After(data => data.Telemetry.RaceCars.All( c => c.HasSeenCheckeredFlag || c.HasRetired ))
                .TakeUntil(2.Seconds()).AfterReplayPaused()
                )
            {
                var count = data.Telemetry.RaceCars.Count(c => c.HasSeenCheckeredFlag || c.HasRetired);

                if (lastCount != count)
                {
                    foreach( var x in data.Telemetry.RaceCars)
                        Trace.WriteLine(string.Format("{0,20}\tHasSeenCheckedFlag: {1}\tHasRetired: {2}", x.Details.UserName, x.HasSeenCheckeredFlag, x.HasRetired));

                    Trace.WriteLine(string.Format("{0} finishers", count));
                }
                lastCount = count;
            }

            iracing.Replay.SetSpeed(0);
            Trace.WriteLine("Finished.");
        }
        static IEnumerable <DataSample> _GetBufferedDataFeed(iRacingConnection iRacingConnection, int maxBufferLength)
        {
            var  que           = new ConcurrentQueue <DataSample>();
            bool cancelRequest = false;

            var t = new Task(() => EnqueueSamples(que, iRacingConnection, maxBufferLength, ref cancelRequest));

            t.Start();

            try
            {
                DataSample data;

                while (true)
                {
                    if (que.TryDequeue(out data))
                    {
                        yield return(data);
                    }
                }
            }
            finally
            {
                cancelRequest = true;
                t.Wait(200);
                t.Dispose();
            }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iracing.Replay.MoveToStartOfRace();
            iracing.Replay.SetSpeed(8);

            var time = new TimeSpan();
            iracing.Replay.SetSpeed(1);



            foreach (var data in iracing.GetDataFeed().WithFinishingStatus())
            {
                if( data.Telemetry.SessionTimeSpan > time)
                {
                    MyListener.Clear();

                    
   

                    foreach (var c in data.Telemetry.Cars.Where(c => !c.Details.IsPaceCar))
                        Trace.WriteLine(string.Format("{0,-20}\tCheckedFlag: {1}\tRetired: {2}\tData:{3}", c.Details.UserName, c.HasSeenCheckeredFlag, c.HasRetired, c.HasData));

                    Trace.WriteLine("");
                    Trace.WriteLine(string.Format("IsFinalLap: {0}, LeaderHasFinished: {1}", data.Telemetry.IsFinalLap, data.Telemetry.LeaderHasFinished));
                    Trace.WriteLine("");
                    Trace.WriteLine("");

                    time = data.Telemetry.SessionTimeSpan + (5*8).Seconds();
                }
            }
        }
        /// <summary>
        /// Demonstrate the use of the GetQueuedDataFeed
        /// This method is similiar to GetDataFeed, except it buffers the DataSamples from iRacing
        /// This allow loops that occasionally take a little longer then 1/60th of a second.
        /// But it also means that the DataSamples yield into the enumeration may be a little out of date.
        /// </summary>
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iracing.Replay.MoveToStart();
            iracing.Replay.SetSpeed(1);

            var lastSector = new LapSector();
            var i = 0;

            foreach (var data in iracing.GetBufferedDataFeed(10))
            {
                if (data.Telemetry.RaceLapSector != lastSector)
                    Trace.WriteLine(string.Format("Lap: {0} Sector: {1}", data.Telemetry.RaceLapSector.LapNumber, data.Telemetry.RaceLapSector.Sector));

                if (i > 1)
                    Debug.Assert(data.LastSample != null, "LastSample should not be null");

                lastSector = data.Telemetry.RaceLapSector;

                if (i++ % 10 == 1)
                {
                    Trace.WriteLine("Pausing retrieval of data samples - simulating work");
                    Thread.Sleep(100);
                }
            }
        }
        static IEnumerable<DataSample> _GetBufferedDataFeed(iRacingConnection iRacingConnection, int maxBufferLength)
        {
            var que = new ConcurrentQueue<DataSample>();
            bool cancelRequest = false;

            var t = new Task(() => EnqueueSamples(que, iRacingConnection, maxBufferLength, ref cancelRequest));
            t.Start();

            try
            {
                DataSample data;

                while (true)
                {
                    if (que.TryDequeue(out data))
                        yield return data;
                }
            }
            finally
            {
                cancelRequest = true;
                t.Wait(200);
                t.Dispose();
            }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();
            var ieventRacing = new iRacingEvents();

            ieventRacing.Connected += ieventRacing_Connected;
            ieventRacing.Disconnected += ieventRacing_Disconnected;
            ieventRacing.StartListening();

            iracing.Connected += iracing_Connected;
            iracing.Disconnected += iracing_Disconnected;

            try
            {
                var i = 0;

                foreach (var d in iracing.GetDataFeed())
                {
                    if (i++ % 600 == 0)
                        Trace.WriteLine(string.Format("Data Stream IsConnected = {0}", d.IsConnected));
                }
            }
            finally
            {
                ieventRacing.StopListening();
            }
        }
        static void EnqueueSamples(ConcurrentQueue<DataSample> que, iRacingConnection samples, int maxBufferLength, ref bool cancelRequest)
        {
            foreach (var data in samples.GetRawDataFeed())
            {
                if (cancelRequest)
                    return;

                if (que.Count < maxBufferLength)
                    que.Enqueue(data);
                else
                    Debug.WriteLine(string.Format("Dropped DataSample {0}.", data.Telemetry.TickCount));
            }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();
            var i = 0;

            foreach (var data in iracing.GetDataFeed())
                if (i++ % 100 == 0)
                {
                    Trace.WriteLine("Processing Time: {0} micro seconds".F(iracing.ProcessingTime));
                    Trace.WriteLine("Waiting Time: {0} micro seconds".F(iracing.WaitingTime));
                    Trace.WriteLine("Yield Time: {0} micro seconds".F(iracing.YieldTime));
                    Trace.WriteLine("");
                }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            var data = iracing.GetDataFeed()
                .WithCorrectedPercentages()
                .AtSpeed(16)
                .RaceOnly()
                .First(d => d.Telemetry.SessionState == SessionState.Racing);

            var raceStartFrameNumber = data.Telemetry.ReplayFrameNum - (60 * 20);

            iRacing.Replay.MoveToFrame(raceStartFrameNumber);

            Trace.WriteLine("Sample Finished");
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iRacing.Replay.MoveToStartOfRace();
            iRacing.Replay.MoveToFrame(-600, ReplayPositionMode.Current);
            
            var incidentSamples = iRacing.GetDataFeed().RaceIncidents2(100);

            foreach( var i in incidentSamples)
            {
                Trace.WriteLine(string.Format("Found new incident at frame {0} for {1}", i.Telemetry.SessionTimeSpan, i.Telemetry.CamCar.Details.UserName), "DEBUG");
            }

            Trace.WriteLine("Sample Finished");
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            TraceInfo.WriteLine("Clearing tire change");
            iracing.PitCommand.ClearTireChange();
            Thread.Sleep(2000);

            TraceInfo.WriteLine("Changing left front");
            iracing.PitCommand.ChangeLeftFrontTire(120);
            Thread.Sleep(2000);


            TraceInfo.WriteLine("Setting fueld to 20");
            iracing.PitCommand.SetFuel(20);
            Thread.Sleep(2000);
        }
        public static void Sample()
        {
            FastLap lastFastestLap = null;
            var iracing = new iRacingConnection();

            Trace.WriteLine("Moving to start of race");
            iracing.Replay.MoveToStartOfRace();
            Trace.WriteLine("Watching for fastest laps");

            foreach (var data in iracing.GetDataFeed().AtSpeed(16).WithFastestLaps())
            {
                if (lastFastestLap != data.Telemetry.FastestLap)
                    Trace.WriteLine(string.Format("{0} - {1}", data.Telemetry.FastestLap.Driver.UserName, data.Telemetry.FastestLap.Time));

                lastFastestLap = data.Telemetry.FastestLap;
            }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iracing.Replay.MoveToStartOfRace();
            iracing.Replay.SetSpeed(1);

            var i = 0;

            foreach (var data in iracing.GetDataFeed()
                .WithCorrectedPercentages()
                .WithCorrectedDistances()
                .WithFinishingStatus())
            {
                i++;
                if( i % 200 == 0)
                {
                    MyListener.Clear();

                    var car = data.Telemetry.Cars
                        .Where(c => c.TotalDistance > 0)
                        .Where(c => !c.HasSeenCheckeredFlag)
                        .Where(c => !c.Details.IsPaceCar)
                        .Where(c => c.HasData)
                        .Where(c => c.Details.Driver != null)
                        .Where(c => c.TrackSurface == TrackLocation.OnTrack)
                        .OrderByDescending(c => c.TotalDistance)
                        .ThenBy(c => c.OfficialPostion == 0 ? int.MaxValue : c.OfficialPostion)
                        .FirstOrDefault();

                    Trace.WriteLine("=============================================================");
                    Trace.WriteLine(string.Format("Next Finisher is {0}", car == null ? "null" : car.Details.UserName));

                    Trace.WriteLine("Driver Distances");
                    Trace.WriteLine("================");

                    Trace.WriteLine("RaceDistance: {0}".F(data.Telemetry.RaceDistance));
                    Trace.WriteLine("");

                    foreach (var c in data.Telemetry.Cars.OrderByDescending(d => d.TotalDistance).ThenBy(c => c.OfficialPostion == 0 ? int.MaxValue : c.OfficialPostion))
                        Trace.WriteLine(string.Format("{0}, dist: {1}, pos: {2}, official pos: {3}", c.Details.UserName, c.TotalDistance, c.Position, c.OfficialPostion));
                }
            }
        }
        static void EnqueueSamples(ConcurrentQueue <DataSample> que, iRacingConnection samples, int maxBufferLength, ref bool cancelRequest)
        {
            foreach (var data in samples.GetRawDataFeed())
            {
                if (cancelRequest)
                {
                    return;
                }

                if (que.Count < maxBufferLength)
                {
                    que.Enqueue(data);
                }
                else
                {
                    Debug.WriteLine(string.Format("Dropped DataSample {0}.", data.Telemetry.TickCount));
                }
            }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iracing.Replay.MoveToStartOfRace();
            iracing.Replay.SetSpeed(16);
            
            var lastSector = new LapSector();

            foreach (var data in iRacing.GetDataFeed().AtSpeed(16))
            {
                if (data.Telemetry.RaceLapSector != lastSector)
                    Trace.WriteLine(string.Format("Lap: {0} Sector: {1}", data.Telemetry.RaceLapSector.LapNumber, data.Telemetry.RaceLapSector.Sector));

                lastSector = data.Telemetry.RaceLapSector;

                Thread.Sleep(2);
            }
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            foreach (var data in iracing.GetDataFeed()
                .WithCorrectedPercentages()
                .WithCorrectedDistances()
                .WithPitStopCounts())
            {

                var tele = data.Telemetry;

                Trace.WriteLine(data.Telemetry.ToString());

                //Trace.WriteLine(data.SessionData.Raw);

                System.Diagnostics.Debugger.Break();

            }
        }
        public static void Sample()
        {
            var instance1 = new iRacingEvents();
            instance1.NewData += instance1_NewData;
            instance1.StartListening();

            var iracingInstance = new iRacingConnection();

            var start = DateTime.Now;
            foreach (var data in iracingInstance.GetDataFeed())
            {
                if (DateTime.Now - start > TimeSpan.FromSeconds(1))
                    break;

                traceMessages.Enqueue(string.Format("Enumerable Data Tick {0}", data.Telemetry.TickCount));
            }

            instance1.StopListening();

            foreach (var m in traceMessages)
                Trace.WriteLine(m);
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            Trace.WriteLine("Moving to start of race");
            iracing.Replay.MoveToStartOfRace();
            Trace.WriteLine("Watching first 2 laps + plus 5 seconds");

            int lastLap = -1;

            foreach (var data in iracing.GetDataFeed().AtSpeed(8)
                .TakeUntil(20.Seconds()).Of(data => data.Telemetry.RaceLaps == 2)
                .TakeUntil(20.Seconds()).AfterReplayPaused())
            {
                if (lastLap != data.Telemetry.RaceLaps)
                    Trace.WriteLine(string.Format("Lap: {0}", data.Telemetry.RaceLaps));
            
                lastLap = data.Telemetry.RaceLaps;
            }

            iracing.Replay.SetSpeed(0);
            Trace.WriteLine("Finished.");
        }
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iracing.Replay.MoveToStartOfRace();
            iracing.Replay.SetSpeed(16);

            foreach (var data in iRacing.GetDataFeed().AtSpeed(2))
            {
                Trace.WriteLine("Session State: {0}".F(data.Telemetry.SessionState));
                Trace.WriteLine("Session Flags: {0}".F(data.Telemetry.SessionFlags));

                Trace.WriteLine("Pace Car Location: {0}".F(data.Telemetry.CarIdxTrackSurface[0]));
                Trace.WriteLine("Under pace car: {0}".F(data.Telemetry.UnderPaceCar));

                Trace.WriteLine("Position:{0}".F(data.Telemetry.PlayerCarPosition));

                Trace.WriteLine("Session Flags: {0}".F(data.Telemetry.SessionFlags.ToString()));
                Trace.WriteLine("Engine Warnings: {0}".F(data.Telemetry.EngineWarnings.ToString()));

                Trace.WriteLine("\n\n");
                Thread.Sleep(2000);
            }
        }
Exemple #20
0
 static iRacing()
 {
     instance = new iRacingConnection();
     eventInstance = new iRacingEvents();
 }
 /// <summary>
 /// Similiar to GetDataFeed, except DataSample can be buffered upto maxBufferLength to asist in reducing loss of data packets
 /// Therefore, DataSamples yield from this enumeration may have a higher latency of values.
 /// </summary>
 /// <param name="iRacingConnection"></param>
 /// <param name="maxBufferLength"></param>
 /// <returns></returns>
 public static IEnumerable <DataSample> GetBufferedDataFeed(this iRacingConnection iRacingConnection, int maxBufferLength = 10)
 {
     return(_GetBufferedDataFeed(iRacingConnection, maxBufferLength).WithLastSample());
 }
Exemple #22
0
 public Replay(iRacingConnection iRacingInstance)
 {
     this.iRacingInstance = iRacingInstance;
 }
Exemple #23
0
 public NoWaitReplay(iRacingConnection iRacingInstance)
     : base(iRacingInstance)
 {
 }
Exemple #24
0
 static iRacing()
 {
     instance      = new iRacingConnection();
     eventInstance = new iRacingEvents();
 }