示例#1
0
        public void Returning_to_pits_does_not_set_previous_lap_as_fastest()
        {
            // set outlap
            var manager = new TelemetryLapManager();

            foreach (var packet in TelemetryLapHelper.CreateOutLap().Packets)
            {
                manager.ProcessIncomingPacket(packet);
            }

            // Add nearly all of a lap
            var firstLap = TelemetryLapHelper.CreatePopulatedLap(lapNumber: 1f, completeLap: true);

            for (var i = 0; i < firstLap.Packets.Count - 2; i++)
            {
                manager.ProcessIncomingPacket(firstLap.Packets[i]);
            }

            Assert.IsNull(manager.FastestLap);

            var garagePacket = new TelemetryPacket {
                Lap = 0f, Speed = 0f, LapDistance = -0.001f
            };

            Assert.IsTrue(garagePacket.IsSittingInPits);
            manager.ProcessIncomingPacket(garagePacket);

            Assert.IsNull(manager.FastestLap);
        }
示例#2
0
 public void SetUp()
 {
     _manager = new TelemetryLapManager();
     foreach (var packet in TelemetryLapHelper.CreateOutLap().Packets)
     {
         _manager.ProcessIncomingPacket(packet);
     }
     foreach (var packet in TelemetryLapHelper.CreatePopulatedLap(lapNumber: 1f).Packets)
     {
         _manager.ProcessIncomingPacket(packet);
     }
 }
示例#3
0
        public void Starting_second_full_lap_sets_fastest_lap()
        {
            var lap = TelemetryLapHelper.CreatePopulatedLap(lapNumber: 2f);

            Assert.AreEqual(1f, _manager.LatestPacket.Lap);
            Assert.IsTrue(lap.IsFirstPacketStartLine);  // Lap we just added must be a full lap
            Assert.IsNull(_manager.FastestLap);

            // Incoming packet is a new lap
            _manager.ProcessIncomingPacket(lap.Packets[0]);

            Assert.IsNotNull(_manager.FastestLap);
            Assert.AreEqual(1, _manager.FastestLap.LapNumber);
            Assert.AreEqual(2f, _manager.LatestPacket.Lap);
        }
示例#4
0
        public void Start_of_first_full_lap_does_not_set_fastest_lap()
        {
            var manager = new TelemetryLapManager();

            foreach (var packet in TelemetryLapHelper.CreateOutLap().Packets)
            {
                manager.ProcessIncomingPacket(packet);
            }

            var fullLap = TelemetryLapHelper.CreatePopulatedLap(lapNumber: 1f);

            Assert.IsTrue(fullLap.IsFirstPacketStartLine);  // Lap we just added must be a full lap

            manager.ProcessIncomingPacket(fullLap.Packets[0]);

            Assert.IsNull(manager.FastestLap);
        }
示例#5
0
        // This method runs continously in the data collection thread.  It
        // waits to receive UDP packets from the game, converts them and writes
        // them to the shared struct variable.
        private void FetchData()
        {
            while (true)
            {
                // Get the data (this will block until we get a packet)
                Byte[] receiveBytes = udpSocket.Receive(ref senderIP);

                // Lock access to the shared struct
                syncMutex.WaitOne();

                TransmissionLabel.BackColor = Color.Green;

                // Convert the bytes received to the shared struct
                latestData = PacketUtilities.ConvertToPacket(receiveBytes);
                manager.ProcessIncomingPacket(latestData);

                //TransmissionLabel.BackColor = Color.Red;

                // Release the lock again
                syncMutex.ReleaseMutex();
            }
        }