Example #1
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");
        }
Example #2
0
        public override Object ReadGameData(Boolean forSpotter)
        {
            lock (this)
            {
                if (!initialised)
                {
                    if (!InitialiseInternal())
                    {
                        throw new GameDataReadException("Failed to initialise shared memory");
                    }
                }
                try
                {
                    if (sdk.IsConnected())
                    {
                        if (sim == null)
                        {
                            sim = new Sim();
                        }
                        if (forSpotter)
                        {
                            return((int)sdk.GetData("CarLeftRight"));
                        }

                        _DriverId = (int)sdk.GetData("PlayerCarIdx");

                        int  newUpdate         = sdk.Header.SessionInfoUpdate;
                        bool hasNewSessionData = false;
                        bool isNewSession      = false;
                        if (newUpdate != lastUpdate)
                        {
                            var sessionNum = TryGetSessionNum();
                            if (sessionNum != null)
                            {
                                string sessionInfoUnFiltred = sdk.GetSessionInfoString();
                                if (sessionInfoUnFiltred == null)
                                {
                                    return(null);
                                }
                                string sessionInfoFiltred = new SessionInfo(sessionInfoUnFiltred).Yaml;
                                isNewSession      = sim.SdkOnSessionInfoUpdated(sessionInfoFiltred, (int)sessionNum, DriverId);
                                lastUpdate        = newUpdate;
                                hasNewSessionData = true;
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        iRacingData irData = new iRacingData(sdk, hasNewSessionData && dumpToFile, isNewSession);

                        sim.SdkOnTelemetryUpdated(irData);

                        iRacingStructWrapper structWrapper = new iRacingStructWrapper();
                        structWrapper.ticksWhenRead = DateTime.UtcNow.Ticks;
                        structWrapper.data          = sim;

                        if (dumpToFile && dataToDump != null)
                        {
                            dataToDump.Add(new iRacingStructDumpWrapper()
                            {
                                ticksWhenRead = structWrapper.ticksWhenRead, data = irData
                            });
                        }
                        return(structWrapper);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    throw new GameDataReadException(ex.Message, ex);
                }
            }
        }