/// <summary>
        /// The thread funktion to poll the telemetry data and send TelemetryUpdated events.
        /// </summary>
        private void Run()
        {
            ACAPI     lastTelemetryData = new ACAPI();
            Stopwatch sw = new Stopwatch();

            sw.Start();

            while (!isStopped)
            {
                try
                {
                    // get data from game,
                    // if an exception will be thrown, we could not retrieve the data because the game
                    // is not running or something went wrong
                    ACAPI telemetryData = (ACAPI)readSharedMemory(typeof(ACAPI), sharedMemoryFile);
                    // otherwise we are connected
                    IsConnected = true;

                    if (telemetryData.PacketId != lastTelemetryData.PacketId)
                    {
                        IsRunning = true;

                        sw.Restart();

                        TelemetryEventArgs args = new TelemetryEventArgs(
                            new ACTelemetryInfo(telemetryData, lastTelemetryData));
                        RaiseEvent(OnTelemetryUpdate, args);

                        lastTelemetryData = telemetryData;
                    }
                    else if (sw.ElapsedMilliseconds > 500)
                    {
                        IsRunning = false;
                    }

                    Thread.Sleep(SamplePeriod);
                }
                catch (Exception e)
                {
                    LogError("ACTelemetryProvider Exception while processing data", e);
                    IsConnected = false;
                    IsRunning   = false;
                    Thread.Sleep(1000);
                }
            }

            IsConnected = false;
            IsRunning   = false;
        }
Beispiel #2
0
 public ACTelemetryInfo(ACAPI telemetryData, ACAPI lastTelemetryData)
 {
     _telemetryData     = telemetryData;
     _lastTelemetryData = lastTelemetryData;
 }