예제 #1
0
        private DCSData ParseReponse(string resp)
        {
            DCSData telemetryData = new DCSData();

            string[] tokens = resp.Split(';');
            if (tokens.Length == 15)
            {
                telemetryData.time = float.Parse(tokens[0], CultureInfo.InvariantCulture);

                telemetryData.pitch = float.Parse(tokens[1], CultureInfo.InvariantCulture);
                telemetryData.roll  = float.Parse(tokens[2], CultureInfo.InvariantCulture);
                telemetryData.yaw   = float.Parse(tokens[3], CultureInfo.InvariantCulture);

                telemetryData.pitchrate = float.Parse(tokens[4], CultureInfo.InvariantCulture);
                telemetryData.rollrate  = float.Parse(tokens[5], CultureInfo.InvariantCulture);
                telemetryData.yawrate   = float.Parse(tokens[6], CultureInfo.InvariantCulture);

                telemetryData.pitchroc = float.Parse(tokens[7], CultureInfo.InvariantCulture);
                telemetryData.rollroc  = float.Parse(tokens[8], CultureInfo.InvariantCulture);
                telemetryData.yawroc   = float.Parse(tokens[9], CultureInfo.InvariantCulture);

                telemetryData.sway  = float.Parse(tokens[10], CultureInfo.InvariantCulture);
                telemetryData.heave = float.Parse(tokens[11], CultureInfo.InvariantCulture);
                telemetryData.surge = float.Parse(tokens[12], CultureInfo.InvariantCulture);

                telemetryData.airspeed = float.Parse(tokens[13], CultureInfo.InvariantCulture);
                telemetryData.aoa      = float.Parse(tokens[14], CultureInfo.InvariantCulture);
            }

            return(telemetryData);
        }
        private DCSData pareseReponse(string resp)
        {
            DCSData telemetryData = new DCSData();

            string[] tokens = resp.Split(';');
            if (tokens.Length == 4)
            {
                telemetryData.time  = float.Parse(tokens[0], CultureInfo.InvariantCulture);
                telemetryData.pitch = float.Parse(tokens[1], CultureInfo.InvariantCulture);
                telemetryData.roll  = float.Parse(tokens[2], CultureInfo.InvariantCulture);
                telemetryData.yaw   = float.Parse(tokens[3], CultureInfo.InvariantCulture);
            }

            return(telemetryData);
        }
예제 #3
0
 public DCSTelemetryInfo(DCSData telemetryData, DCSData lastTelemetryData, Session session)
 {
     this.telemetryData     = telemetryData;
     this.lastTelemetryData = lastTelemetryData;
     this.session           = session;
 }
예제 #4
0
 public DCSTelemetryInfo(DCSData telemetryData, DCSData lastTelemetryData)
 {
     this.telemetryData     = telemetryData;
     this.lastTelemetryData = lastTelemetryData;
 }
        /// <summary>
        /// The thread funktion to poll the telemetry data and send TelemetryUpdated events.
        /// </summary>
        private void Run()
        {
            DCSData   lastTelemetryData = new DCSData();
            Stopwatch sw = new Stopwatch();

            sw.Start();

            UdpClient socket = new UdpClient();

            socket.ExclusiveAddressUse = false;
            socket.Client.Bind(new IPEndPoint(IPAddress.Any, PORTNUM));

            Log("Listener thread started (IP: " + IP + ":" + PORTNUM.ToString() + ") DCSTelemetryProvider.Thread");

            while (!isStopped)
            {
                try
                {
                    // get data from game,
                    if (socket.Available == 0)
                    {
                        if (sw.ElapsedMilliseconds > 500)
                        {
                            IsRunning   = false;
                            IsConnected = false;
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            Thread.Sleep(1);
                        }
                        continue;
                    }
                    else
                    {
                        IsConnected = true;
                    }

                    Byte[] received = socket.Receive(ref _senderIP);
                    string resp     = Encoding.UTF8.GetString(received);
                    //LogDebug(resp);

                    DCSData telemetryData = pareseReponse(resp);

                    IsRunning = true;

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

                    sw.Restart();
                    Thread.Sleep(SamplePeriod);
                }
                catch (Exception)
                {
                    IsConnected = false;
                    IsRunning   = false;
                    Thread.Sleep(1000);
                }
            }
            IsConnected = false;
            IsRunning   = false;

            try
            {
                socket.Close();
            }
            catch (Exception) { }

            Log("Listener thread stopped, DCSTelemetryProvider.Thread");
        }