private void Run() { XP11Data data; Session session = new Session(); Stopwatch sw = new Stopwatch(); Stopwatch sSTimer = new Stopwatch(); //softStartTimer float sSMul = 0.0f; //softStartMultiplier (1.0f is the normal ratio for telemetry data), calculated with equation (sSTimer - sSWaitForALign)/sStime float sSTime = 5000f; //softStartTime, amount of milliseconds for the softstart to occur, starting after time sSWaitForAlign. //softStartWaitForAlign, the time it takes for the SFX-100 to elevate to neutral height. //Important: it takes about 3 seconds for the rig to start using telemetry data, if sSWaitForAlign is set below 3 seconds, //somehow the rig jumps directly to the telemetry position. I am not sure what is causing this....5 seconds seems like a secure value //So a total of 10 seconds until the rig is fully aligned to telemetry data. float sSWaitForAlign = 5000f; sw.Start(); UdpClient socket = new UdpClient(); socket.ExclusiveAddressUse = false; socket.Client.Bind(new IPEndPoint(IPAddress.Any, PORTNUM)); Log("Listener started (port: " + PORTNUM.ToString() + ") XP11TelemetryProvider.Thread"); sSTimer.Reset(); sSTimer.Start(); while (!isStopped) { try { // get data from game, if (socket.Available == 0) { if (sw.ElapsedMilliseconds > 500) { IsRunning = false; IsConnected = false; Thread.Sleep(1000); } continue; } else { IsConnected = true; } //Calculate the sofStartMultiplier from where when user presses start + sSWaitForAlign extra time for the SFX-100 to go to neutral position. //The time for the softstart alignment is sSTime. if (sSMul < 1.0f && sSTimer.ElapsedMilliseconds > sSWaitForAlign) { sSMul = (sSTimer.ElapsedMilliseconds - sSWaitForAlign) / sSTime; if (sSMul >= 1.0f) { sSMul = 1.0f; sSTimer.Stop(); } } Byte[] received = socket.Receive(ref _senderIP); data = new XP11Data(received, sSMul); if (data.IsRaceOn == 1) { IsRunning = true; TelemetryEventArgs args = new TelemetryEventArgs(new XP11TelemetryInfo(data, session)); RaiseEvent(OnTelemetryUpdate, args); } else { IsRunning = false; } sw.Restart(); } catch (Exception) { IsConnected = false; IsRunning = false; Thread.Sleep(1000); } } socket.Close(); IsConnected = false; IsRunning = false; }
public XP11TelemetryInfo(XP11Data data, Session session) { this.telemetryData = data; this.session = session; }