示例#1
0
        public string PrintTelemetryToCsvContent(byte driver_index)
        {
            CsvFile csv = new CsvFile();


            #region "Write headers"

            //Write headers
            DataRow dr_header = csv.AddNewRow();

            //Time
            dr_header.Values.Add("Session Time");

            //Motion packet
            dr_header.Values.Add("Position X");
            dr_header.Values.Add("Position Y");
            dr_header.Values.Add("Position Z");
            dr_header.Values.Add("Velocity X");
            dr_header.Values.Add("Velocity Y");
            dr_header.Values.Add("Velocity Z");
            dr_header.Values.Add("Forward Direction X");
            dr_header.Values.Add("Forward Direction Y");
            dr_header.Values.Add("Forward Direction Z");
            dr_header.Values.Add("Right Direction X");
            dr_header.Values.Add("Right Direction Y");
            dr_header.Values.Add("Right Direction Z");
            dr_header.Values.Add("Lateral G Force");
            dr_header.Values.Add("Longitudinal G Force");
            dr_header.Values.Add("Vertical G Force");
            dr_header.Values.Add("Yaw");
            dr_header.Values.Add("Pitch");
            dr_header.Values.Add("Roll");

            //Motion packet (only for player data, not for other drivers. Will be blank if requesting for other players)
            dr_header.Values.Add("Suspension Position - Rear Left");
            dr_header.Values.Add("Suspension Position - Rear Right");
            dr_header.Values.Add("Suspennsion Position - Front Left");
            dr_header.Values.Add("Suspension Position - Front Right");
            dr_header.Values.Add("Suspension Velocity - Rear Left");
            dr_header.Values.Add("Suspension Velocity - Rear Right");
            dr_header.Values.Add("Suspension Velocity - Front Left");
            dr_header.Values.Add("Suspension Velocity - Front Right");
            dr_header.Values.Add("Suspension Acceleration - Rear Left");
            dr_header.Values.Add("Suspension Acceleration - Rear Right");
            dr_header.Values.Add("Suspension Acceleration - Front Left");
            dr_header.Values.Add("Suspension Acceleration - Front Right");
            dr_header.Values.Add("Wheel Speed - Rear Left");
            dr_header.Values.Add("Wheel Speed - Rear Right");
            dr_header.Values.Add("Wheel Speed - Front Left");
            dr_header.Values.Add("Wheel Speed - Front Right");
            dr_header.Values.Add("Wheel Slip - Rear Left");
            dr_header.Values.Add("Wheel Slip - Rear Right");
            dr_header.Values.Add("Wheel Slip - Front Left");
            dr_header.Values.Add("Wheel Slip - Front Right");
            dr_header.Values.Add("Local Velocity X");
            dr_header.Values.Add("Local Velocity Y");
            dr_header.Values.Add("Local Velocity Z");
            dr_header.Values.Add("Angular Velocity X");
            dr_header.Values.Add("Angular Velocity Y");
            dr_header.Values.Add("Angular Velocity Z");
            dr_header.Values.Add("Angular Acceleration X");
            dr_header.Values.Add("Angular Acceleration Y");
            dr_header.Values.Add("Angular Acceleration Z");
            dr_header.Values.Add("Front Wheels Angle");

            //Lap Packet
            dr_header.Values.Add("Lap Distance");
            dr_header.Values.Add("Total Distance");
            dr_header.Values.Add("Safety Car Delta");
            dr_header.Values.Add("Car Race Position");
            dr_header.Values.Add("Current Lap Number");
            dr_header.Values.Add("Pit Status");
            dr_header.Values.Add("Sector");
            dr_header.Values.Add("Current Lap Invalid");
            dr_header.Values.Add("Driver Status");



            //Telemetry Packet
            dr_header.Values.Add("Speed KPH");
            dr_header.Values.Add("Speed MPH");
            dr_header.Values.Add("Throttle");
            dr_header.Values.Add("Steer");
            dr_header.Values.Add("Brake");
            dr_header.Values.Add("Clutch");
            dr_header.Values.Add("Gear");
            dr_header.Values.Add("Engine RPM");
            dr_header.Values.Add("DRS Active");
            dr_header.Values.Add("Rev Lights Percentage");
            dr_header.Values.Add("Brake Temperature - Rear Left");
            dr_header.Values.Add("Brake Temperature - Rear Right");
            dr_header.Values.Add("Brake Temperature - Front Left");
            dr_header.Values.Add("Brake Temperature - Front Right");
            dr_header.Values.Add("Tyre Surface Temperature - Rear Left");
            dr_header.Values.Add("Tyre Surface Temperature - Rear Right");
            dr_header.Values.Add("Tyre Surface Temperature - Front Left");
            dr_header.Values.Add("Tyre Surface Temperature - Front Right");
            dr_header.Values.Add("Tyre Inner Temperature - Rear Left");
            dr_header.Values.Add("Tyre Inner Temperature - Rear Right");
            dr_header.Values.Add("Tyre Inner Temperature - Front Left");
            dr_header.Values.Add("Tyre Inner Temperature - Front Right");
            dr_header.Values.Add("Engine Temperature Celsius");
            dr_header.Values.Add("Tyre Pressure - Rear Left");
            dr_header.Values.Add("Tyre Pressure - Rear Right");
            dr_header.Values.Add("Tyre Pressure - Front Left");
            dr_header.Values.Add("Tyre Pressure - Front Right");
            dr_header.Values.Add("Surface Type - Rear Left");
            dr_header.Values.Add("Surface Type - Rear Right");
            dr_header.Values.Add("Surface Type - Front Left");
            dr_header.Values.Add("Surface Type - Front Right");

            //Car Status
            dr_header.Values.Add("Traction Control Level");
            dr_header.Values.Add("Anti Lock Brakes Active");
            dr_header.Values.Add("Fuel Mix");
            dr_header.Values.Add("Front Brake Bias Percentage");
            dr_header.Values.Add("Pit Limiter Active");
            dr_header.Values.Add("Fuel In Tank");
            dr_header.Values.Add("Max Fuel Capacity");
            dr_header.Values.Add("Fuel Remaining in Laps");
            dr_header.Values.Add("Max RPM");
            dr_header.Values.Add("Idle RPM");
            dr_header.Values.Add("Max Gears");
            dr_header.Values.Add("DRS Allowed");
            dr_header.Values.Add("DRS Activation Distance");
            dr_header.Values.Add("Tyre Wear - Rear Left");
            dr_header.Values.Add("Tyre Wear - Rear Right");
            dr_header.Values.Add("Tyre Wear - Front Left");
            dr_header.Values.Add("Tyre Wear - Front Right");
            dr_header.Values.Add("Actual Tyre Compound");
            dr_header.Values.Add("Visual Tyre Compound");
            dr_header.Values.Add("Tyre Age in Laps");
            dr_header.Values.Add("Tyre Damage Percentage - Rear Left");
            dr_header.Values.Add("Tyre Damage Percentage - Rear Right");
            dr_header.Values.Add("Tyre Damage Percentage - Front Left");
            dr_header.Values.Add("Tyre Damage Percentage - Front Right");
            dr_header.Values.Add("Front Left Wing Damage Percentage");
            dr_header.Values.Add("Front Right Wing Damage Percentage");
            dr_header.Values.Add("Rear Wing Damage Percentage");
            dr_header.Values.Add("DRS Failure");
            dr_header.Values.Add("Engine Damage Percentage");
            dr_header.Values.Add("Gear Box Damage Percentage");
            dr_header.Values.Add("FIA Flag");
            dr_header.Values.Add("ERS Stored Energy Joules");
            dr_header.Values.Add("ERS Deploy Mode");
            dr_header.Values.Add("ERS Harvested This Lap by MGUK");
            dr_header.Values.Add("ERS Harvested This Lap by MGUH");
            dr_header.Values.Add("ERS Deployed This Lap");
            #endregion

            //Write the data
            foreach (PacketFrame frame in Frames)
            {
                //Create the new row
                DataRow row = csv.AddNewRow();

                //Write the session time
                row.Values.Add(frame.Telemetry.SessionTime.ToString());

                //Write Write motion data
                MotionPacket.CarMotionData cmd = frame.Motion.FieldMotionData[driver_index];
                row.Values.Add(cmd.PositionX.ToString());
                row.Values.Add(cmd.PositionY.ToString());
                row.Values.Add(cmd.PositionZ.ToString());
                row.Values.Add(cmd.VelocityX.ToString());
                row.Values.Add(cmd.VelocityY.ToString());
                row.Values.Add(cmd.VelocityZ.ToString());
                row.Values.Add(cmd.ForwardDirectionX.ToString());
                row.Values.Add(cmd.ForwardDirectionY.ToString());
                row.Values.Add(cmd.ForwardDirectionZ.ToString());
                row.Values.Add(cmd.RightDirectionX.ToString());
                row.Values.Add(cmd.RightDirectionY.ToString());
                row.Values.Add(cmd.RightDirectionZ.ToString());
                row.Values.Add(cmd.gForceLateral.ToString());
                row.Values.Add(cmd.gForceLongitudinal.ToString());
                row.Values.Add(cmd.gForceVertical.ToString());
                row.Values.Add(cmd.Yaw.ToString());
                row.Values.Add(cmd.Pitch.ToString());
                row.Values.Add(cmd.Roll.ToString());

                //Write motion data player-specific (if they are requesting for the player, return the data. Otherwise, return 0's!)
                if (driver_index == frame.Motion.PlayerCarIndex)
                {
                    row.Values.Add(frame.Motion.SuspensionPosition.RearLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionPosition.RearRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionPosition.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionPosition.FrontRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionVelocity.RearLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionVelocity.RearRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionVelocity.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionVelocity.FrontRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionAcceleration.RearLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionAcceleration.RearRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionAcceleration.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionAcceleration.FrontRight.ToString());
                    row.Values.Add(frame.Motion.WheelSpeed.RearLeft.ToString());
                    row.Values.Add(frame.Motion.WheelSpeed.RearRight.ToString());
                    row.Values.Add(frame.Motion.WheelSpeed.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.WheelSpeed.FrontRight.ToString());
                    row.Values.Add(frame.Motion.WheelSlip.RearLeft.ToString());
                    row.Values.Add(frame.Motion.WheelSlip.RearRight.ToString());
                    row.Values.Add(frame.Motion.WheelSlip.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.WheelSlip.FrontRight.ToString());
                    row.Values.Add(frame.Motion.VelocityX.ToString());
                    row.Values.Add(frame.Motion.VelocityY.ToString());
                    row.Values.Add(frame.Motion.VelocityZ.ToString());
                    row.Values.Add(frame.Motion.AngularVelocityX.ToString());
                    row.Values.Add(frame.Motion.AngularVelocityY.ToString());
                    row.Values.Add(frame.Motion.AngularVelocityZ.ToString());
                    row.Values.Add(frame.Motion.AngularAccelerationX.ToString());
                    row.Values.Add(frame.Motion.AngularAccelerationY.ToString());
                    row.Values.Add(frame.Motion.AngularAccelerationZ.ToString());
                    row.Values.Add(frame.Motion.FrontWheelAngle.ToString());
                }
                else
                {
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                }


                //Lap Packet
                LapPacket.LapData ld = frame.Lap.FieldLapData[driver_index];
                row.Values.Add(ld.LapDistance.ToString());
                row.Values.Add(ld.TotalDistance.ToString());
                row.Values.Add(ld.SafetyCarDelta.ToString());
                row.Values.Add(ld.CarPosition.ToString());
                row.Values.Add(ld.CurrentLapNumber.ToString());
                row.Values.Add(ld.CurrentPitStatus.ToString());
                row.Values.Add(ld.Sector.ToString());
                row.Values.Add(ld.CurrentLapInvalid.ToString());
                row.Values.Add(ld.CurrentDriverStatus.ToString());

                //Telemetry packet
                TelemetryPacket.CarTelemetryData ctd = frame.Telemetry.FieldTelemetryData[driver_index];
                row.Values.Add(ctd.SpeedKph.ToString());
                row.Values.Add(ctd.SpeedMph.ToString());
                row.Values.Add(ctd.Throttle.ToString());
                row.Values.Add(ctd.Steer.ToString());
                row.Values.Add(ctd.Brake.ToString());
                row.Values.Add(ctd.Clutch.ToString());
                row.Values.Add(ctd.Gear.ToString());
                row.Values.Add(ctd.EngineRpm.ToString());
                row.Values.Add(ctd.DrsActive.ToString());
                row.Values.Add(ctd.RevLightsPercentage.ToString());
                row.Values.Add(ctd.BrakeTemperature.RearLeft.ToString());
                row.Values.Add(ctd.BrakeTemperature.RearRight.ToString());
                row.Values.Add(ctd.BrakeTemperature.FrontLeft.ToString());
                row.Values.Add(ctd.BrakeTemperature.FrontRight.ToString());
                row.Values.Add(ctd.TyreSurfaceTemperature.RearLeft.ToString());
                row.Values.Add(ctd.TyreSurfaceTemperature.RearRight.ToString());
                row.Values.Add(ctd.TyreSurfaceTemperature.FrontLeft.ToString());
                row.Values.Add(ctd.TyreSurfaceTemperature.FrontRight.ToString());
                row.Values.Add(ctd.TyreInnerTemperature.RearLeft.ToString());
                row.Values.Add(ctd.TyreInnerTemperature.RearRight.ToString());
                row.Values.Add(ctd.TyreInnerTemperature.FrontLeft.ToString());
                row.Values.Add(ctd.TyreInnerTemperature.FrontRight.ToString());
                row.Values.Add(ctd.EngineTemperature.ToString());
                row.Values.Add(ctd.TyrePressure.RearLeft.ToString());
                row.Values.Add(ctd.TyrePressure.RearRight.ToString());
                row.Values.Add(ctd.TyrePressure.FrontLeft.ToString());
                row.Values.Add(ctd.TyrePressure.FrontRight.ToString());
                row.Values.Add(ctd.SurfaceType_RearLeft.ToString());
                row.Values.Add(ctd.SurfaceType_RearRight.ToString());
                row.Values.Add(ctd.SurfaceType_FrontLeft.ToString());
                row.Values.Add(ctd.SurfaceType_FrontRight.ToString());

                //Car status
                CarStatusPacket.CarStatusData csd = frame.CarStatus.FieldCarStatusData[driver_index];
                row.Values.Add(csd.TractionControlStatus.ToString());
                row.Values.Add(csd.AntiLockBrakesOn.ToString());
                row.Values.Add(csd.SelectedFuelMix.ToString());
                row.Values.Add(csd.FrontBrakeBiasPercentage.ToString());
                row.Values.Add(csd.PitLimiterOn.ToString());
                row.Values.Add(csd.FuelLevel.ToString());
                row.Values.Add(csd.FuelCapacity.ToString());
                row.Values.Add(csd.FuelRemainingLaps.ToString());
                row.Values.Add(csd.MaxRpm.ToString());
                row.Values.Add(csd.IdleRpm.ToString());
                row.Values.Add(csd.MaxGears.ToString());
                row.Values.Add(csd.DrsAllowed.ToString());
                row.Values.Add(csd.DrsActivationDistance.ToString());
                row.Values.Add(csd.TyreWearPercentage.RearLeft.ToString());
                row.Values.Add(csd.TyreWearPercentage.RearRight.ToString());
                row.Values.Add(csd.TyreWearPercentage.FrontLeft.ToString());
                row.Values.Add(csd.TyreWearPercentage.FrontRight.ToString());
                row.Values.Add(csd.EquippedTyreCompound.ToString());
                row.Values.Add(csd.EquippedVisualTyreCompoundId.ToString());
                row.Values.Add(csd.TyreAgeLaps.ToString());
                row.Values.Add(csd.TyreDamagePercentage.RearLeft.ToString());
                row.Values.Add(csd.TyreDamagePercentage.RearRight.ToString());
                row.Values.Add(csd.TyreDamagePercentage.FrontLeft.ToString());
                row.Values.Add(csd.TyreDamagePercentage.FrontRight.ToString());
                row.Values.Add(csd.FrontLeftWingDamagePercent.ToString());
                row.Values.Add(csd.FrontRightWingDamagePercent.ToString());
                row.Values.Add(csd.RearWingDamagePercent.ToString());
                row.Values.Add(csd.DrsFailure.ToString());
                row.Values.Add(csd.EngineDamagePercent.ToString());
                row.Values.Add(csd.GearBoxDamagePercent.ToString());
                row.Values.Add(csd.VehicleFiaFlag.ToString());
                row.Values.Add(csd.ErsStoredEnergyJoules.ToString());
                row.Values.Add(csd.SelectedErsDeployMode.ToString());
                row.Values.Add(csd.ErsHarvestedThisLapByMGUK.ToString());
                row.Values.Add(csd.ErsHarvestedThisLapByMGUH.ToString());
                row.Values.Add(csd.ErsDeployedThisLap.ToString());
            }

            return(csv.GenerateAsCsvFileContent());
        }
示例#2
0
        //For position, race lap number, qualifying driver status
        public void FeedLapData(LapPacket.LapData ld, float session_time)
        {
            Position                = ld.CarPosition;
            Race_LapNumber          = ld.CurrentLapNumber;
            Qualifying_DriverStatus = ld.CurrentDriverStatus;


            //Only run this stuff once we have seen at least one lap data before. This is for comparison purposes.
            if (LastSeenLapData != null)
            {
                //If it is Qualifying
                if (ThisSessionType != SessionPacket.SessionType.Race && ThisSessionType != SessionPacket.SessionType.Race2) //If it is NOT a race
                {
                    //Plug in the driver status
                    Qualifying_DriverStatus = ld.CurrentDriverStatus;

                    //If we just started a new lap and it is our best lap so far, plug in all of the times
                    if (ld.CurrentLapNumber != LastSeenLapData.CurrentLapNumber) //It is a new lap we just started
                    {
                        if (ld.LastLapTime == ld.BestLapTimeSeconds)             //If the last lap (the one we just finished) is the fastest lap we have seen so far, update the s1, s2, s3, and lap time
                        {
                            Qualifying_Sector1Time = (float)LastSeenLapData.Sector1TimeMilliseconds / 1000f;
                            Qualifying_Sector2Time = (float)LastSeenLapData.Sector2TimeMilliseconds / 1000f;
                            Qualifying_Sector3Time = ld.LastLapTime - Qualifying_Sector1Time - Qualifying_Sector2Time;
                            Qualifying_LapTime     = ld.LastLapTime;
                        }
                    }
                }
                else //If it is a race
                {
                    //Lap number
                    Race_LapNumber = ld.CurrentLapNumber;

                    //Did we just start a new lap? If we did, plug in the last lap time
                    if (ld.CurrentLapNumber != LastSeenLapData.CurrentLapNumber)
                    {
                        Race_LastLapTime = ld.LastLapTime;
                    }

                    //Plug in pit status
                    Race_PitStatus = ld.CurrentPitStatus;

                    //Increment the pit count? If the last one we saw they were in the pit lane but now they are on track, increase it
                    if (LastSeenLapData.CurrentPitStatus == PitStatus.PitLane && ld.CurrentPitStatus == PitStatus.OnTrack)
                    {
                        Race_PitCount = Race_PitCount + 1;
                    }



                    //Update Gap Ahead
                    if (Position == 1) //If we are in first place, just set the time to 0!
                    {
                        Race_GapAhead = 0;
                    }
                    else
                    {
                        if (UpdatingGapAhead == false) //If we are not updating the gap aheaed right mow, let's check to see if it is time to
                        {
                            float time_since_last_update = session_time - LastUpdatedGapAheadAtSessionTime;
                            if (time_since_last_update > UpdateGapAheadEverySeconds)                      //Is it time to?
                            {
                                MeasuringSnapshot_DriverAheadDistance      = Current_DriverAheadDistance; //Mark down the driver ahead's current lap distance
                                MeasuringSnapshot_SnapshottedAtSessionTime = session_time;                //Mark down the current session time.
                                UpdatingGapAhead = true;                                                  //Mark it as we are currently updating the gap ahead
                            }
                        }
                        else //We are currently in the process of updating the gap ahead. Check to see if our car has ecclipsed or equalled the last measured car ahead time
                        {
                            if (ld.TotalDistance >= MeasuringSnapshot_DriverAheadDistance) //If we eclipsed or equalled it
                            {
                                Race_GapAhead = session_time - MeasuringSnapshot_SnapshottedAtSessionTime; //Get the gap ahead. (This is how long it took us to get to the driver ahead's position)
                                LastUpdatedGapAheadAtSessionTime = session_time;                           //Mark that we just did that just now
                                UpdatingGapAhead = false;
                            }
                        }
                    }
                }
            }

            //Do the internal log updating for next time
            LastSeenLapData = ld;
        }