Inheritance: ITelemetryObject
 public TelemetryLapComplete(Aggregates.Telemetry tel, TelemetryDriver driver, Lap lap)
 {
     Telemetry = tel;
     Driver = driver;
     Lap = lap;
 }
Exemple #2
0
        protected virtual void UpdateDrivers()
        {
            if (Session.Cars != _drivers.Count)
            {
                var driversAdded = new List<TelemetryDriver>();
                var driversRemoved = new List<TelemetryDriver>();

                // Get a new list of drivers
                var driverList = Memory.Get("Simulator").ReadAs<int[]>("Drivers");
                var validDriverList = driverList.Where(x => Provider.CheckDriverQuick(Memory, x)).ToArray();
                var playerDriverPtr = Memory.Get("Simulator").ReadAs<int>("CarPlayer");
                // Update the drivers.))
                foreach (var validDriverPtr in validDriverList)
                {
                    if (Drivers.Any(x => x.BaseAddress == validDriverPtr))
                        continue;

                    var isPlayer = validDriverPtr == playerDriverPtr;
                    var memPool = Memory.Get("DriverTemplate").Clone("Driver " + validDriverPtr, validDriverPtr);
                    Provider.CreateDriver((MemoryPool)memPool, isPlayer);

                    Memory.Add(memPool);

                    var td = new TelemetryDriver(memPool);
                    _drivers.Add(td);
                    driversAdded.Add(td);

                    if (isPlayer)
                        _player = td;
                }

                foreach (var driver in _drivers)
                {
                    if (!validDriverList.Any(x => x == driver.BaseAddress))
                    {
                        // This driver is now invalid
                        driversRemoved.Add(driver);
                    }

                }

                for (int i = 0; i < driversRemoved.Count; i++)
                {
                    Memory.Remove(driversRemoved[i].Pool);
                    _drivers.Remove(driversRemoved[i]);

                    if (driversRemoved[i] == _player)
                        _player = null;
                }

                if (driversAdded.Count > 0)
                    GlobalEvents.Fire(new DriversAdded(this, driversAdded), true);
                if (driversRemoved.Count > 0)
                    GlobalEvents.Fire(new DriversRemoved(this, driversAdded), true);
            }
        }
        public void RecordTestData()
        {
            float[] rpmWave;
            float[] speedWave;
            GetWaves(out rpmWave, out speedWave);
            int index = 0;

            var provider = new MemoryProvider(null);
            var fakePool = new MemoryPool("Driver", MemoryAddress.StaticAbsolute, 0, 0);
            fakePool.Add(new MemoryFieldFunc<float>("Speed", (pool) => speedWave[index], true));
            fakePool.Add(new MemoryFieldFunc<float>("RPM", (pool) => rpmWave[index++], true));
            fakePool.Add(new MemoryFieldConstant<bool>("IsAI", false));
            fakePool.Add(new MemoryFieldConstant<bool>("IsPlayer", true));
            provider.Add(fakePool);

            var fakeDriver = new TelemetryDriver(fakePool);
            var fakeDrivers = new List<TelemetryDriver>(new[] {fakeDriver});

            TelemetryLogger logger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, true, true, true));
            logger.SetDatasource(provider);
            logger.SetAnnotater( new TelemetryArchive());
            GlobalEvents.Fire(new SessionStarted(), true);
            GlobalEvents.Fire(new DriversAdded(null, fakeDrivers), true);

            for(int i = 0 ; i  <1024;i++)
                logger.Update(i*25);

            GlobalEvents.Fire(new SessionStopped(), true);
            Thread.Sleep(500);

            ZipStorer checkFile = ZipStorer.Open("tmp.zip", FileAccess.Read);

            var files = checkFile.ReadCentralDir();
            Assert.AreEqual(3, files.Count);
            Assert.AreEqual(1024 * 2 * 12 + 2 * 8, files.Where(x => x.FilenameInZip.Contains("Data.bin")).FirstOrDefault().FileSize);
            Assert.AreEqual(1024*8, files.Where(x => x.FilenameInZip.Contains("Time.bin")).FirstOrDefault().FileSize);
        }
        public void LapTests()
        {
            var lapsRecorded = new List<Lap>();

            GlobalEvents.Hook<TelemetryLapComplete>(lap => lapsRecorded.Add(lap.Lap),true);

            float[] rpmWave;
            float[] speedWave;
            GetWaves(out rpmWave, out speedWave);
            int index = 0;

            var provider = new MemoryProvider(null);
            var fakePool = new MemoryPool("Driver", MemoryAddress.StaticAbsolute, 0, 0);
            fakePool.Add(new MemoryFieldFunc<float>("Speed", (pool) => speedWave[index], true));
            fakePool.Add(new MemoryFieldFunc<float>("RPM", (pool) => rpmWave[index++], true));
            fakePool.Add(new MemoryFieldFunc<float>("Laps", (pool) =>
                                                                {
                                                                    if(index <= 100)
                                                                        return 0;
                                                                    if (index > 100 && index <= 225)
                                                                        return 1;
                                                                    if (index > 225 && index <= 325)
                                                                        return 2;
                                                                    if (index > 325 && index <= 500)
                                                                        return 3;
                                                                    if (index > 500 && index <= 575)
                                                                        return 4;
                                                                    if (index > 575 && index <= 1024)
                                                                        return 5;

                                                                        return -1;
                                                                }, true));
            fakePool.Add(new MemoryFieldConstant<bool>("IsAI", false));
            fakePool.Add(new MemoryFieldConstant<bool>("IsPlayer", true));
            provider.Add(fakePool);

            var fakeDriver = new TelemetryDriver(fakePool);
            var fakeDrivers = new List<TelemetryDriver>(new[] { fakeDriver });

            var logger = new TelemetryLogger("testSim", new TelemetryLoggerConfiguration(true, true, true, true));
            logger.SetDatasource(provider);
            //logger.SetAnnotater(new TelemetryArchive());
            GlobalEvents.Fire(new SessionStarted(), true);
            GlobalEvents.Fire(new DriversAdded(null, fakeDrivers), true);

            for (int i = 0; i < 1024; i++)
                logger.Update(i * 25);

            GlobalEvents.Fire(new SessionStopped(), true);
            Thread.Sleep(500);

            Assert.AreEqual(6, lapsRecorded.Count);
            Assert.AreEqual(0, lapsRecorded[0].LapNumber);
            Assert.AreEqual(1, lapsRecorded[1].LapNumber);
            Assert.AreEqual(2, lapsRecorded[2].LapNumber);
            Assert.AreEqual(3, lapsRecorded[3].LapNumber);
            Assert.AreEqual(4, lapsRecorded[4].LapNumber);
            Assert.AreEqual(5, lapsRecorded[5].LapNumber);

            Assert.AreEqual(100, lapsRecorded[0].Total);
            Assert.AreEqual(125, lapsRecorded[1].Total);
            Assert.AreEqual(100, lapsRecorded[2].Total);
            Assert.AreEqual(175, lapsRecorded[3].Total);
            Assert.AreEqual(75, lapsRecorded[4].Total);
            Assert.AreEqual(-1, lapsRecorded[5].Total);
        }