Ejemplo n.º 1
0
 // Add Completed valid lap to circuit information
 internal void AddLapInfo(LapRecording lapInfo)
 {
     var me = lapInfo.lapMotion.GetEnumerator();
     var m = me.Current;
     var te = lapInfo.lapTelemetry.GetEnumerator();  // 2..3
     var t = te.Current;
     foreach (var l in lapInfo.lapData)  // 1..2..3
     {
         // l is next frame. If next contextFrame
         if ( (l.context.frameIdentifier < m.context.frameIdentifier) ||
               (l.context.frameIdentifier < t.context.frameIdentifier))
         {
             continue;
         }
         while (me.Current.context.frameIdentifier < l.context.frameIdentifier && me.MoveNext()) ;
         m = me.Current;
         while (te.Current.context.frameIdentifier < l.context.frameIdentifier && te.MoveNext()) ;
         t = te.Current;
         if (m.context.frameIdentifier == t.context.frameIdentifier &&
             m.context.frameIdentifier == l.context.frameIdentifier)
         {
             AnalyzeApex(l.lapData, t.carTelemetry, m.carMotion);
             CircuitLayoutData.AddData(l.lapData, m.carMotion);
         }
     }
 }
Ejemplo n.º 2
0
        internal void AddLap(LapRecording li)
        {
            lapStore.Add(1, li);

            lastMotion    = li.lapMotion.Last().carMotion;
            lastTelemetry = li.lapTelemetry.Last().carTelemetry;
        }
Ejemplo n.º 3
0
 internal void AddSetupData(int lapNumber, PacketHeader context, CarSetupData carSetupData)
 {
     if (currentLapIndex == lapNumber)
     {
         LapRecording rec = GetLap(lapNumber);
         if (carSetupData.fuelLoad > 0)
         {
             rec.Setup = carSetupData;
         }
     }
 }
Ejemplo n.º 4
0
        public CompletedLap(string filename)
        {
            Stream fData = new FileStream(filename, FileMode.Open, FileAccess.Read);

            byte[] data      = new byte[fData.Length];
            long   totalRead = 0;

            while (totalRead < fData.Length)
            {
                totalRead += fData.Read(data, (int)totalRead, (int)fData.Length);
            }

            MemoryStream fIn = new MemoryStream(data);


            int version = PacketHelper.SafeRead <int>(fIn, PacketSize.IntSize);

            if (version != 211)
            {
                // Invalid;
                return;
            }

            lap = new LapRecording()
            {
                lapTelemetry = new List <TelemetryInContext>(),
                lapMotion    = new List <MotionInContext>(),
                lapData      = new List <LapDataInContext>()
            };

            circuitInfo     = PacketHelper.SafeRead <PacketSessionData>(fIn, PacketSize.PacketSessionDataSize);
            playerInfo      = PacketHelper.SafeRead <ParticipantData>(fIn, PacketSize.ParticipantDataSize);
            lap.complete    = PacketHelper.SafeRead <bool>(fIn, PacketSize.BoolSize);
            lap.FirstTiming = PacketHelper.SafeRead <LapData>(fIn, PacketSize.LapDataSize);
            if (version == 210)
            {
                var lapTimeAsFloat = PacketHelper.SafeRead <float>(fIn, PacketSize.FloatSize);
                lap.lapTimeInMs = (UInt32)Math.Round(lapTimeAsFloat * 1000f, 0);
            }
            else
            {
                lap.lapTimeInMs = PacketHelper.SafeRead <UInt32>(fIn, PacketSize.UInt32Size);
            }
            lap.started = PacketHelper.SafeRead <bool>(fIn, PacketSize.BoolSize);
            lap.valid   = PacketHelper.SafeRead <bool>(fIn, PacketSize.BoolSize);
            lap.Setup   = PacketHelper.SafeRead <CarSetupData>(fIn, PacketSize.CarSetupDataSize);
            var timingCount = PacketHelper.SafeRead <int>(fIn, PacketSize.IntSize);

            for (int i = 0; i < timingCount; i++)
            {
                lap.lapMotion.Add(PacketHelper.SafeRead <MotionInContext>(fIn, PacketSize.MotionInContextSize));
            }
            var telemetryCount = PacketHelper.SafeRead <int>(fIn, PacketSize.IntSize);

            for (int i = 0; i < telemetryCount; i++)
            {
                lap.lapTelemetry.Add(PacketHelper.SafeRead <TelemetryInContext>(fIn, PacketSize.TelemetryInContextSize));
            }
            var lapDataCount = PacketHelper.SafeRead <int>(fIn, PacketSize.IntSize);

            for (int i = 0; i < lapDataCount; i++)
            {
                lap.lapData.Add(PacketHelper.SafeRead <LapDataInContext>(fIn, PacketSize.LapDataInContextSize));
            }
            fIn.Close();
        }
Ejemplo n.º 5
0
        internal LapRecording AddLapData(PacketHeader context, LapData lapData)
        {
            LapRecording completedLap = null;

            // uint8 m_resultStatus;
            // Result status - 0 = invalid, 1 = inactive, 2 = active
            // 3 = finished, 4 = disqualified, 5 = not classified
            // 6 = retired
            // Status of driver - 0 = in garage, 1 = flying lap
            // 2 = in lap, 3 = out lap, 4 = on track)
            if (lapData.driverStatus == 0 || lapData.driverStatus == 3 || lapData.driverStatus == 2)
            {
                // In garage
                return(null);
            }
            LapRecording activeLap = GetLap(lapData.currentLapNum);

            if (lapData.resultStatus == 3)
            {
                if (activeLap.lapTime > 0 && activeLap.lapMotion.Count > 100)
                {
                    activeLap.valid    = true;
                    activeLap.complete = true;
                    completedLap       = activeLap;
                }
                else
                {
                    return(null);
                }
            }
            if (currentLapIndex != lapData.currentLapNum)
            {
                // New lap? Starting Lap? Something else?
                if (currentLapIndex > lapData.currentLapNum)
                {
                    currentLapIndex = lapData.currentLapNum;
                }
                else if (currentLapIndex > 0)
                {
                    var previousLap = GetLap(currentLapIndex);

                    var lastLap = previousLap.lapTimings;
                    if (lastLap.currentLapInvalid == 0)
                    {
                        // Sanity check. Packages with ResultStatus 3 are missing, so calculate if it is a valid lap
                        //  by checking sinsible sector and lap times.
                        previousLap.complete =
                            previousLap.started && lastLap.sector1TimeInMS > 0 && lastLap.sector2TimeInMS > 0 &&
                            (lastLap.currentLapTimeInMS) > (lastLap.sector1TimeInMS + lastLap.sector2TimeInMS);
                        if (previousLap.complete)
                        {
                            previousLap.lapTimeInMs = lapData.lastLapTimeInMS;
                            completedLap            = previousLap;
                        }
                    }
                    else
                    {
                        previousLap.valid = false;
                    }
                }
                currentLapIndex = lapData.currentLapNum;
            }
            if (!activeLap.started)
            {
                activeLap.FirstTiming = lapData;
                if (lapData.lapDistance < 10)
                {
                    activeLap.started = true;
                }
            }
            activeLap.lapTimings = lapData;
            activeLap.lapData.Add(new LapDataInContext()
            {
                context = context, lapData = lapData
            });
            // GetLap(lapData.currentLapNum).started |= (lapData.sector == 0);

            return(completedLap);
        }