Example #1
0
        /// <summary>
        /// Creates a new instance of the SdkWrapper.
        /// </summary>
        public Sdk()
        {
            context        = SynchronizationContext.Current;
            sdk            = new iRacingSDK();
            EventRaiseType = EventRaiseTypes.CurrentThread;

            readMutex = new Mutex(false);

            TelemetryUpdateFrequency = 60;

            Replay             = new ReplayControl(this);
            Camera             = new CameraControl(this);
            PitCommands        = new PitCommandControl(this);
            Chat               = new ChatControl(this);
            Textures           = new TextureControl(this);
            TelemetryRecording = new TelemetryRecordingControl(this);

            deserializer = new DeserializerBuilder()
                           .IgnoreUnmatchedProperties()
                           .WithTypeConverter(new NumericTypeConverter())
                           .WithTypeConverter(new DoubleUnitTypeConverter())
                           .WithTypeConverter(new BooleanTypeConverter())
                           .WithTypeConverter(new EnumTypeConverter())
                           .WithTypeConverter(new ColorTypeConverter())
                           .WithTypeConverter(new TimeSpanTypeConverter())
                           .Build();
        }
Example #2
0
        private void Update(iRacingSDK sdk, Simulation sim)
        {
            sim.DataMutex.WaitOne();

            var sessionInfoUpdate = sdk.Header.SessionInfoUpdate;
            var updateSessionInfo = false;

            if (sessionInfoUpdate != LastSessionInfoUpdate)
            {
                LastSessionInfoUpdate = sessionInfoUpdate;
                updateSessionInfo     = true;
            }

            string sessionInfo = null;

            if (updateSessionInfo)
            {
                sessionInfo = sdk.GetSessionInfo();
            }

            try
            {
                Update(sim, sessionInfo, updateSessionInfo);
                ((SimEventManager)sim.EventManager).ExecuteEvents();
            }
            finally
            {
                sim.DataMutex.ReleaseMutex();
            }
        }
Example #3
0
 public String init()
 {
     // returns script name and does other initialization
     this.sdk = new iRacingSDK();
     this.sdk.Startup();
     return("helloworld");
 }
Example #4
0
 public void ApiTick(iRacingSDK api)
 {
     foreach (var pair in this.scripts)
     {
         pair.Value.ApiTick(api);
     }
 }
Example #5
0
        /// <summary>
        /// The thread funktion to poll the telemetry data and send TelemetryUpdated events.
        /// </summary>
        private void Run()
        {
            int _lastSessionTick = 0;

            iRacingSDK sdk     = new iRacingSDK();
            Session    session = new Session();

            Stopwatch sw = new Stopwatch();

            sw.Start();

            while (!isStopped)
            {
                try
                {
                    // check if the SDK is connected
                    if (sdk.IsConnected())
                    {
                        IsConnected = true;

                        // check if car is on track and if we got new data
                        if ((bool)sdk.GetData("IsOnTrack") && _lastSessionTick != (int)sdk.GetData("SessionTick"))
                        {
                            IsRunning        = true;
                            _lastSessionTick = (int)sdk.GetData("SessionTick");

                            sw.Restart();

                            TelemetryEventArgs args = new TelemetryEventArgs(new iR60TelemetryInfo(sdk, session));
                            RaiseEvent(OnTelemetryUpdate, args);
                        }
                        else if (sw.ElapsedMilliseconds > 500)
                        {
                            IsRunning = false;
                        }
                    }
                    else
                    {
                        sdk.Startup();

                        IsRunning = false;
                    }
                    Thread.Sleep(SamplePeriod);
                }
                catch (Exception e)
                {
                    LogError("iR60TelemetryProvider Exception while processing data", e);
                    IsConnected = false;
                    IsRunning   = false;
                    Thread.Sleep(1000);
                }
            }

            sdk.Shutdown();

            IsConnected = false;
            IsRunning   = false;
        }
Example #6
0
 public String init()
 {
     // returns script name and does other initialization
     this.sdk = new iRacingSDK();
     this.sdk.Startup();
     this.state    = 0;
     this.position = this.length;
     return("slowmo");
 }
        /// <summary>
        /// Creates a new instance of the SdkWrapper.
        /// </summary>
        public SdkWrapper(int frequency)
        {
            this.context        = SynchronizationContext.Current;
            this.sdk            = new iRacingSDK();
            this.EventRaiseType = EventRaiseTypes.CurrentThread;

            this.TelemetryUpdateFrequency = frequency;
            _DriverId = -1;
        }
        public static int GetNumberOfPages(iRacingSDK.SessionData._DriverInfo driverInfo)
        {
            var numberOfDrivers = driverInfo.CompetingDrivers.Length - 1;
            var numberOfPages = Math.Min(numberOfDrivers / LeaderBoard.DriversPerPage, 3);
            if (((float)numberOfDrivers % LeaderBoard.DriversPerPage) != 0)
                numberOfPages++;

            return numberOfPages;
        }
Example #9
0
        public API(int ticksPerSecond)
        {
            mutex = new Mutex();
            this.ticksPerSecond = ticksPerSecond;

            Cars = new IniFile(Environment.CurrentDirectory + @"\cars.ini"); // TODO Pfad einstellen

            modules = new List <Module>();
            Sdk     = new iRacingSDK();

            Instance = this;
        }
        /// <summary>
        /// Creates a new instance of the SdkWrapper.
        /// </summary>
        public SdkWrapper()
        {
            this.context        = SynchronizationContext.Current;
            this.sdk            = new iRacingSDK();
            this.EventRaiseType = EventRaiseTypes.CurrentThread;

            readMutex = new Mutex(false);

            this.TelemetryUpdateFrequency = 60;
            this.ConnectSleepTime         = 1000;
            _DriverId = -1;
        }
Example #11
0
        protected override Boolean InitialiseInternal()
        {
            lock (this)
            {
                if (!initialised)
                {
                    try
                    {
                        if (sdk == null)
                        {
                            sdk = new iRacingSDK();
                        }
                        sdk.Shutdown();

                        if (!sdk.IsInitialized)
                        {
                            sdk.Startup();
                        }
                        if (sdk.IsConnected())
                        {
                            initialised = true;
                            if (dumpToFile)
                            {
                                dataToDump = new List <iRacingStructDumpWrapper>();
                            }
                            ;
                            int       attempts    = 0;
                            const int maxAttempts = 99;

                            object sessionnum = this.TryGetSessionNum();
                            while (sessionnum == null && attempts <= maxAttempts)
                            {
                                attempts++;
                                sessionnum = this.TryGetSessionNum();
                            }
                            if (attempts >= maxAttempts)
                            {
                                Console.WriteLine("Session num too many attempts");
                            }
                            Console.WriteLine("Initialised iRacing shared memory");
                        }
                    }
                    catch (Exception)
                    {
                        initialised = false;
                    }
                }
                return(initialised);
            }
        }
Example #12
0
        protected TelemetryValue(iRacingSDK sdk, string name)
        {
            if (sdk == null)
            {
                throw new ArgumentNullException("sdk");
            }

            Exists = sdk.VarHeaders.ContainsKey(name);
            if (Exists)
            {
                var header = sdk.VarHeaders[name];
                Name        = name;
                Description = header.Desc;
                Unit        = header.Unit;
                Type        = header.Type;
            }
        }
Example #13
0
        public Form1()
        {
            InitializeComponent();

            _sdk     = new iRacingSDK();
            _wrapper = new SdkWrapper();
            //_wrapper = new iRacingMock.ClassLibrary.Mock("D:\\_20190810_115035.csv");

            //defaultSession = new DefaultSession();
            dash = new Dash(this, _wrapper);
            dash.InitDash();
            new Configurator().StartConfig(ref maxRpm, ref location, ref dash.minRpmPercent, ref dash.shiftLight1Percent, ref dash.shiftLight2Percent, ref dash.redLinePercent, ref fps);

            Location = location;
            _wrapper.TelemetryUpdateFrequency = fps;

            SubscribeToEvents();
            _wrapper.Start();
        }
Example #14
0
        /// <summary>
        /// Creates a new instance of the SdkWrapper.
        /// </summary>
        public SdkWrapper()
        {
            this.context        = SynchronizationContext.Current;
            this.sdk            = new iRacingSDK();
            this.EventRaiseType = EventRaiseTypes.CurrentThread;

            readMutex = new Mutex(false);

            this.TelemetryUpdateFrequency = 60;
            this.ConnectSleepTime         = 1000;
            _DriverId = -1;

            this.Replay             = new ReplayControl(this);
            this.Camera             = new CameraControl(this);
            this.PitCommands        = new PitCommandControl(this);
            this.Chat               = new ChatControl(this);
            this.Textures           = new TextureControl(this);
            this.TelemetryRecording = new TelemetryRecordingControl(this);
        }
Example #15
0
        internal bool UpdateData(ref iRacingSDK sdk, Simulation sim)
        {
            if (!sdk.IsInitialized)
            {
                return(false);
            }

            if (!sdk.IsConnected())
            {
                sdk.Shutdown();
                return(false);
            }

            if (sdk.GetData("SessionNum") == null)
            {
                sdk = new iRacingSDK();
                return(true);
            }

            Update(sdk, sim);
            return(true);
        }
Example #16
0
        public override void Dispose()
        {
            lock (this)
            {
                if (sdk != null)
                {
                    sdk.Shutdown();
                    sdk = null;
                }
                if (sim != null)
                {
                    sim = null;
                }

                if (initialised)
                {
                    lastUpdate  = -1;
                    _DriverId   = -1;
                    initialised = false;
                    Console.WriteLine("Disconnected from iRacing Shared Memory");
                }
            }
        }
Example #17
0
    public void ApiTick(iRacingSDK api)
    {
        if (this.position < length)
        {
            switch (this.state)
            {
            case 1:
                api.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, this.max_value - ease(this.position) + 1, 1);
                break;

            case -1:
                api.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, ease(this.position), 1);
                break;

            default:
                break;
            }
        }
        else if (this.position >= length + 10 && this.state != 0)
        {
            Console.WriteLine("Finished..." + this.state);
            if (this.state == 1)
            {
                api.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, 1, 0);
            }
            else if (this.state == -1)
            {
                api.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, this.max_value, 1);
            }
            this.state = 0;
        }

        if (this.state != 0)
        {
            position++;
        }
    }
Example #18
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }

            Bookmarks myBookmarks  = new Bookmarks();;
            Bookmark  thisEvent    = null;
            int       currentIndex = 0;
            int       CurrentFrame = 0;
            bool      run          = true;

            using (StreamReader sw = new StreamReader(args[0], Encoding.UTF8))
            {
                System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(myBookmarks.GetType());
                myBookmarks = x.Deserialize(sw) as Bookmarks;
            }

            Console.WriteLine("Waiting for iRacing to come up ....");
            sdk = new iRacingSDK();
            while (!Console.KeyAvailable && run)
            {
                //Check if the SDK is connected
                if (sdk.IsConnected())
                {
                    while (sdk.GetData("SessionNum") == null)
                    {
                        Console.WriteLine("Waiting for Session...");
                        Thread.Sleep(200); // Allow other windows to initialize more faster
                    }

                    thisEvent = myBookmarks.List[currentIndex];

                    switch (thisEvent.BookmarkType)
                    {
                    case BookmarkType.Start:
                        ReplaySeek(thisEvent);
                        currentIndex++;
                        break;

                    case BookmarkType.Play:
                        CurrentFrame = (Int32)sdk.GetData("ReplayFrameNum");
                        if (CurrentFrame < thisEvent.ReplayPos)
                        {
                            continue;
                        }
                        sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.CamSwitchNum, thisEvent.DriverIdx, thisEvent.CamIdx);
                        SetPlaySpeed(thisEvent.PlaySpeed);
                        currentIndex++;
                        break;

                    case BookmarkType.Stop:
                        CurrentFrame = (Int32)sdk.GetData("ReplayFrameNum");
                        if (CurrentFrame < thisEvent.ReplayPos)
                        {
                            continue;
                        }
                        sdk.BroadcastMessage(iRSDKSharp.BroadcastMessageTypes.ReplaySetPlaySpeed, 0, 0);
                        Console.WriteLine("End");
                        run = false;
                        break;

                    default:
                        run = false;
                        break;
                    }
                }
                else
                {
                    if (sdk.Startup())
                    {
                        Console.WriteLine("iRacing up and running.");
                    }
                    else
                    {
                        Thread.Sleep(2000);
                    }
                }
            }
            sdk.Shutdown();
        }
Example #19
0
        public void initialize()
        {
            sdk = new iRacingSDK();
            sdk.Startup();

            // check connection
            if (sdk.IsConnected())
            {
                String yaml = sdk.GetSessionInfo();

                // caridx
                Int32 start = yaml.IndexOf("DriverCarIdx: ") + "DriverCarIdx: ".Length;
                Int32 end   = yaml.IndexOf("\n", start);
                carIdx = Int32.Parse(yaml.Substring(start, end - start));

                // carname
                start = yaml.IndexOf("CarIdx: " + carIdx.ToString(), start);
                start = yaml.IndexOf("CarPath: ", start) + "CarPath: ".Length;
                end   = yaml.IndexOf("\n", start);
                if (start < 0)
                {
                    carname = "unknown";
                }
                else
                {
                    carname = yaml.Substring(start, end - start);
                }

                // track name
                start = yaml.IndexOf("TrackName: ") + "TrackName: ".Length;
                end   = yaml.IndexOf("\n", start);
                if (start < 0)
                {
                    trackname = "unknown";
                }
                else
                {
                    trackname = yaml.Substring(start, end - start);
                }

                // track length
                start = yaml.IndexOf("TrackLength: ") + "TrackLength: ".Length;
                end   = yaml.IndexOf("km\n", start);
                String dbg = yaml.Substring(start, end - start);
                trackLength = (Int32)(Single.Parse(yaml.Substring(start, end - start)) * 1000);

                // session types
                RegexOptions    options = RegexOptions.IgnoreCase | RegexOptions.Compiled;
                MatchCollection sessionNums, sessionTypes;
                Regex           optionRegex = new Regex(@"SessionNum: (\d+)", options);

                // Get matches of pattern in yaml
                sessionNums = optionRegex.Matches(yaml);

                optionRegex  = new Regex(@"SessionType: (\w+)", options);
                sessionTypes = optionRegex.Matches(yaml);

                Int32 currentSessionNum = (Int32)sdk.GetData("SessionNum");

                // Iterate matches
                for (Int32 ctr = 0; ctr < Math.Min(sessionNums.Count, sessionTypes.Count); ctr++)
                {
                    if (Int32.Parse(sessionNums[ctr].Value.Substring(12)) == currentSessionNum)
                    {
                        switch (sessionTypes[ctr].Value.Substring(13).Trim())
                        {
                        case "Practice":
                            sessiontype = iRacing.SessionTypes.practice;
                            break;

                        case "Qualify":
                            sessiontype = iRacing.SessionTypes.qualify;
                            break;

                        case "Race":
                            sessiontype = iRacing.SessionTypes.race;
                            break;

                        default:
                            sessiontype = iRacing.SessionTypes.invalid;
                            break;
                        }
                    }
                }

                // reset laptimes
                lapStartTime = (Double)sdk.GetData("ReplaySessionTime");
                lapTimeValid = false;

                // fuel consumption, last 5 lap rolling
                fuelcons    = new Single[fuelconslaps];
                fuelconsPtr = 0;

                // init timedelta
                timedelta = new TimeDelta(trackLength);
                timedelta.SaveBestLap(carIdx);
                LoadBestLap();

                init = true;
            }
            else // retry next tick
            {
                init = false;
            }
        }
Example #20
0
 public iR60TelemetryInfo(iRacingSDK sdk, Session session)
 {
     _sdk     = sdk;
     _session = session;
 }
 public static int GetPageNumber(iRacingSDK.SessionData._DriverInfo driverInfo, float pagePeriod)
 {
     var numberOfPages = GetNumberOfPages(driverInfo);
     var page = (int)Math.Floor(pagePeriod * numberOfPages);
     return Math.Min(page, numberOfPages - 1);
 }
Example #22
0
        public void initialize()
        {
            sdk = new iRacingSDK();
            sdk.Startup();

            // check connection
            if (sdk.IsConnected())
            {
                String yaml = sdk.GetSessionInfo();

                // caridx
                Int32 start = yaml.IndexOf("DriverCarIdx: ") + "DriverCarIdx: ".Length;
                Int32 end = yaml.IndexOf("\n", start);
                carIdx = Int32.Parse(yaml.Substring(start, end - start));

                // carname
                start = yaml.IndexOf("CarIdx: " + carIdx.ToString(), start);
                start = yaml.IndexOf("CarPath: ", start) + "CarPath: ".Length;
                end = yaml.IndexOf("\n", start);
                if (start < 0)
                    carname = "unknown";
                else
                    carname = yaml.Substring(start, end - start);

                // track name
                start = yaml.IndexOf("TrackName: ") + "TrackName: ".Length;
                end = yaml.IndexOf("\n", start);
                if (start < 0)
                    trackname = "unknown";
                else
                    trackname = yaml.Substring(start, end - start);

                // track length
                start = yaml.IndexOf("TrackLength: ") + "TrackLength: ".Length;
                end = yaml.IndexOf("km\n", start);
                String dbg = yaml.Substring(start, end - start);
                trackLength = (Int32)(Single.Parse(yaml.Substring(start, end - start)) * 1000);

                // session types
                RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Compiled;
                MatchCollection sessionNums, sessionTypes;
                Regex optionRegex = new Regex(@"SessionNum: (\d+)", options);

                // Get matches of pattern in yaml
                sessionNums = optionRegex.Matches(yaml);

                optionRegex = new Regex(@"SessionType: (\w+)", options);
                sessionTypes = optionRegex.Matches(yaml);

                Int32 currentSessionNum = (Int32)sdk.GetData("SessionNum");

                // Iterate matches
                for (Int32 ctr = 0; ctr < Math.Min(sessionNums.Count, sessionTypes.Count); ctr++)
                {
                    if (Int32.Parse(sessionNums[ctr].Value.Substring(12)) == currentSessionNum)
                    {
                        switch (sessionTypes[ctr].Value.Substring(13).Trim())
                        {
                            case "Practice":
                                sessiontype = iRacing.SessionTypes.practice;
                                break;
                            case "Qualify":
                                sessiontype = iRacing.SessionTypes.qualify;
                                break;
                            case "Race":
                                sessiontype = iRacing.SessionTypes.race;
                                break;
                            default:
                                sessiontype = iRacing.SessionTypes.invalid;
                                break;
                        }
                    }
                }

                // reset laptimes
                lapStartTime = (Double)sdk.GetData("ReplaySessionTime");
                lapTimeValid = false;

                // fuel consumption, last 5 lap rolling
                fuelcons = new Single[fuelconslaps];
                fuelconsPtr = 0;

                // init timedelta
                timedelta = new TimeDelta(trackLength);
                timedelta.SaveBestLap(carIdx);
                LoadBestLap();

                init = true;
            }
            else // retry next tick
            {
                init = false;
            }
        }
Example #23
0
        public iRacingData(iRacingSDK sdk, bool hasNewSessionData, bool isNewSession)
        {
            if (hasNewSessionData)
            {
                SessionInfo = new SessionInfo(sdk.GetSessionInfoString()).Yaml;
            }
            else
            {
                SessionInfo = "";
            }

            SessionInfoUpdate = sdk.Header.SessionInfoUpdate;
            IsNewSession      = isNewSession;

            SessionTime                  = (System.Double)sdk.GetData("SessionTime");
            SessionTick                  = (System.Int32)sdk.GetData("SessionTick");
            SessionNum                   = (System.Int32)sdk.GetData("SessionNum");
            SessionState                 = (SessionStates)sdk.GetData("SessionState");
            SessionFlags                 = (int)sdk.GetData("SessionFlags");
            SessionTimeRemain            = (System.Double)sdk.GetData("SessionTimeRemain");
            SessionLapsRemain            = (System.Int32)sdk.GetData("SessionLapsRemain");
            SessionLapsRemainEx          = (System.Int32)sdk.GetData("SessionLapsRemainEx");
            DisplayUnits                 = (DisplayUnits)sdk.GetData("DisplayUnits");
            DriverMarker                 = (System.Boolean)sdk.GetData("DriverMarker");
            PushToPass                   = (System.Boolean)sdk.GetData("PushToPass");
            IsOnTrack                    = (System.Boolean)sdk.GetData("IsOnTrack");
            PlayerCarPosition            = (System.Int32)sdk.GetData("PlayerCarPosition");
            PlayerCarClassPosition       = (System.Int32)sdk.GetData("PlayerCarClassPosition");
            PlayerTrackSurface           = (TrackSurfaces)sdk.GetData("PlayerTrackSurface");
            PlayerTrackSurfaceMaterial   = (TrackSurfaceMaterial)sdk.GetData("PlayerTrackSurfaceMaterial");
            PlayerCarIdx                 = (System.Int32)sdk.GetData("PlayerCarIdx");
            PlayerCarTeamIncidentCount   = (System.Int32)sdk.GetData("PlayerCarTeamIncidentCount");
            PlayerCarMyIncidentCount     = (System.Int32)sdk.GetData("PlayerCarMyIncidentCount");
            PlayerCarDriverIncidentCount = (System.Int32)sdk.GetData("PlayerCarDriverIncidentCount");
            CarIdxLap                    = (System.Int32[])sdk.GetData("CarIdxLap");
            CarIdxLapCompleted           = (System.Int32[])sdk.GetData("CarIdxLapCompleted");
            CarIdxLapDistPct             = (System.Single[])sdk.GetData("CarIdxLapDistPct");
            CarIdxTrackSurface           = (TrackSurfaces[])sdk.GetData("CarIdxTrackSurface");
            CarIdxTrackSurfaceMaterial   = (TrackSurfaceMaterial[])sdk.GetData("CarIdxTrackSurfaceMaterial");
            CarIdxOnPitRoad              = (System.Boolean[])sdk.GetData("CarIdxOnPitRoad");
            CarIdxPosition               = (System.Int32[])sdk.GetData("CarIdxPosition");
            CarIdxClassPosition          = (System.Int32[])sdk.GetData("CarIdxClassPosition");
            CarIdxF2Time                 = (System.Single[])sdk.GetData("CarIdxF2Time");
            CarIdxEstTime                = (System.Single[])sdk.GetData("CarIdxEstTime");
            OnPitRoad                    = (System.Boolean)sdk.GetData("OnPitRoad");
            CarIdxRPM                    = (System.Single[])sdk.GetData("CarIdxRPM");
            CarIdxGear                   = (System.Int32[])sdk.GetData("CarIdxGear");
            Throttle          = (System.Single)sdk.GetData("Throttle");
            Brake             = (System.Single)sdk.GetData("Brake");
            Clutch            = (System.Single)sdk.GetData("Clutch");
            Gear              = (System.Int32)sdk.GetData("Gear");
            RPM               = (System.Single)sdk.GetData("RPM");
            Lap               = (System.Int32)sdk.GetData("Lap");
            LapCompleted      = (System.Int32)sdk.GetData("LapCompleted");
            LapDist           = (System.Single)sdk.GetData("LapDist");
            LapDistPct        = (System.Single)sdk.GetData("LapDistPct");
            RaceLaps          = (System.Int32)sdk.GetData("RaceLaps");
            LapBestLap        = (System.Int32)sdk.GetData("LapBestLap");
            LapBestLapTime    = (System.Single)sdk.GetData("LapBestLapTime");
            LapLastLapTime    = (System.Single)sdk.GetData("LapLastLapTime");
            LapCurrentLapTime = (System.Single)sdk.GetData("LapCurrentLapTime");
            TrackTemp         = (System.Single)sdk.GetData("TrackTemp");
            TrackTempCrew     = (System.Single)sdk.GetData("TrackTempCrew");
            AirTemp           = (System.Single)sdk.GetData("AirTemp");
            WeatherType       = (WeatherType)sdk.GetData("WeatherType");
            Skies             = (Skies)sdk.GetData("Skies");
            AirDensity        = (System.Single)sdk.GetData("AirDensity");
            AirPressure       = (System.Single)sdk.GetData("AirPressure");
            WindVel           = (System.Single)sdk.GetData("WindVel");
            WindDir           = (System.Single)sdk.GetData("WindDir");
            RelativeHumidity  = (System.Single)sdk.GetData("RelativeHumidity");
            CarLeftRight      = (System.Int32)sdk.GetData("CarLeftRight");
            PitRepairLeft     = (System.Single)sdk.GetData("PitRepairLeft");
            PitOptRepairLeft  = (System.Single)sdk.GetData("PitOptRepairLeft");
            IsOnTrackCar      = (System.Boolean)sdk.GetData("IsOnTrackCar");
            IsInGarage        = (System.Boolean)sdk.GetData("IsInGarage");
            EngineWarnings    = (EngineWarnings)(int)sdk.GetData("EngineWarnings");
            FuelLevel         = (System.Single)sdk.GetData("FuelLevel");
            FuelLevelPct      = (System.Single)sdk.GetData("FuelLevelPct");
            WaterTemp         = (System.Single)sdk.GetData("WaterTemp");
            WaterLevel        = (System.Single)sdk.GetData("WaterLevel");
            FuelPress         = (System.Single)sdk.GetData("FuelPress");
            FuelUsePerHour    = (System.Single)sdk.GetData("FuelUsePerHour");
            OilTemp           = (System.Single)sdk.GetData("OilTemp");
            OilPress          = (System.Single)sdk.GetData("OilPress");
            OilLevel          = (System.Single)sdk.GetData("OilLevel");
            Speed             = (System.Single)sdk.GetData("Speed");
            IsReplayPlaying   = (System.Boolean)sdk.GetData("IsReplayPlaying");

            RRcoldPressure = (System.Single)sdk.GetData("RRcoldPressure");
            RRtempCL       = (System.Single)sdk.GetData("RRtempCL");
            RRtempCM       = (System.Single)sdk.GetData("RRtempCM");
            RRtempCR       = (System.Single)sdk.GetData("RRtempCR");
            RRwearL        = (System.Single)sdk.GetData("RRwearL");
            RRwearM        = (System.Single)sdk.GetData("RRwearM");
            RRwearR        = (System.Single)sdk.GetData("RRwearR");
            LRcoldPressure = (System.Single)sdk.GetData("LRcoldPressure");
            LRtempCL       = (System.Single)sdk.GetData("LRtempCL");
            LRtempCM       = (System.Single)sdk.GetData("LRtempCM");
            LRtempCR       = (System.Single)sdk.GetData("LRtempCR");
            LRwearL        = (System.Single)sdk.GetData("LRwearL");
            LRwearM        = (System.Single)sdk.GetData("LRwearM");
            LRwearR        = (System.Single)sdk.GetData("LRwearR");
            RFcoldPressure = (System.Single)sdk.GetData("RFcoldPressure");
            RFtempCL       = (System.Single)sdk.GetData("RFtempCL");
            RFtempCM       = (System.Single)sdk.GetData("RFtempCM");
            RFtempCR       = (System.Single)sdk.GetData("RFtempCR");
            RFwearL        = (System.Single)sdk.GetData("RFwearL");
            RFwearM        = (System.Single)sdk.GetData("RFwearM");
            RFwearR        = (System.Single)sdk.GetData("RFwearR");
            LFcoldPressure = (System.Single)sdk.GetData("LFcoldPressure");
            LFtempCL       = (System.Single)sdk.GetData("LFtempCL");
            LFtempCM       = (System.Single)sdk.GetData("LFtempCM");
            LFtempCR       = (System.Single)sdk.GetData("LFtempCR");
            LFwearL        = (System.Single)sdk.GetData("LFwearL");
            LFwearM        = (System.Single)sdk.GetData("LFwearM");
            LFwearR        = (System.Single)sdk.GetData("LFwearR");

            Pitch   = (System.Single)sdk.GetData("Pitch");
            Yaw     = (System.Single)sdk.GetData("Yaw");
            Roll    = (System.Single)sdk.GetData("Roll");
            Voltage = (System.Single)sdk.GetData("Voltage");
        }
 public TelemetryInfo(iRacingSDK sdk)
 {
     this.sdk = sdk;
 }
Example #25
0
        public void fetch(TelemetryInfo telem, iRacingSDK sdk, double fuelVal, int brake, 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;
            }
            Engine |= (byte)(brake << 3);

            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;
            }
        }
Example #26
0
        private static string callbackCamera = "TV1";   // camera group to switch to when the client requests it
        static void Main(string[] args)
        {
            sdk = new iRacingSDK();
            int lastUpdate = -1;

            //setup WebSocketServer
            var allSockets = new List <IWebSocketConnection>();
            var server     = new WebSocketServer("ws://localhost:8181");

            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    Console.WriteLine("Client Connected");
                    allSockets.Add(socket);
                };
                socket.OnClose = () =>
                {
                    Console.WriteLine("Client Disconnected");
                    allSockets.Remove(socket);
                };
                socket.OnMessage = message =>
                {
                    Console.WriteLine("Received -> " + message);
                    int groupNum = cameras[callbackCamera];
                    sdk.BroadcastMessage(BroadcastMessageTypes.CamSwitchNum, Convert.ToInt32(message), groupNum, 0);
                };
            });

            while (true)
            {
                if (sdk.IsConnected())
                {
                    //If it is connected then see if the Session Info has been updated
                    int newUpdate = sdk.Header.SessionInfoUpdate;
                    if (telemData.getTrackId() == 0)
                    {
                        telemData.setTrackId(Convert.ToInt32(YamlParser.Parse(sdk.GetSessionInfo(), "WeekendInfo:TrackID:")));
                        DiscoverCameras();
                    }

                    if (newUpdate != lastUpdate)
                    {
                        // Session Info updated (e.g. perhaps a client has connected/disconnected)
                        lastUpdate = newUpdate;
                        // Update the current Driver list
                        string yaml = sdk.GetSessionInfo();
                        length = yaml.Length;
                        start  = yaml.IndexOf("DriverInfo:\n", 0, length);
                        end    = yaml.IndexOf("\n\n", start, length - start);
                        string DriverInfo = yaml.Substring(start, end - start);
                        ParseDrivers(DriverInfo);
                    }
                    UpdateDriverPositions(drivers);
                    foreach (var socket in allSockets.ToList())
                    {
                        Console.WriteLine("Broadcast sent...");
                        Console.WriteLine(telemData.toJson());
                        socket.Send(telemData.toJson());
                    }
                }
                else if (sdk.IsInitialized)
                {
                    drivers.Clear();
                    cameras.Clear();
                    telemData.setTrackId(0);
                    sdk.Shutdown();
                    lastUpdate = -1;
                }
                else
                {
                    drivers.Clear();
                    cameras.Clear();
                    telemData.setTrackId(0);
                    Console.WriteLine("NOT CONNECTED!");
                    sdk.Startup();
                }
                System.Threading.Thread.Sleep(1000);
            }
        }
Example #27
0
 public void ApiTick(iRacingSDK api)
 {
 }
Example #28
0
 public TelemetryData(iRacingSDK sdk)
 {
     this.sdk = sdk;
 }
Example #29
0
 public void initialize()
 {
     sdk = new iRacingSDK();
 }
 public TelemetryInfoOffline(iRacingSDK sdk)
     : base(sdk)
 {
 }