private void Run()
        {
            lastTelemetryData = new TelemetryData();

            UdpClient socket = new UdpClient {
                ExclusiveAddressUse = false
            };

            socket.Client.Bind(new IPEndPoint(IPAddress.Parse(_ipAddr), _portNum));
            var       endpoint = new IPEndPoint(IPAddress.Parse(_ipAddr), _portNum);
            Stopwatch sw       = new Stopwatch();

            sw.Start();
            while (!_isStopped)
            {
                try
                {
                    // get data from game,
                    if (socket.Available == 0)
                    {
                        if (sw.ElapsedMilliseconds > 500)
                        {
                            IsRunning   = false;
                            IsConnected = false;
                            Thread.Sleep(1000);
                        }
                        continue;
                    }
                    IsConnected = true;
                    IsRunning   = true;
                    Byte[]        received      = socket.Receive(ref endpoint);
                    string        resp          = Encoding.UTF8.GetString(received);
                    TelemetryData telemetryData = ParseReponse(resp);

                    TelemetryEventArgs args = new TelemetryEventArgs(new Condor2TelemetryInfo(telemetryData));
                    RaiseEvent(OnTelemetryUpdate, args);
                    lastTelemetryData = telemetryData;
                    sw.Restart();
                }
                catch (Exception e)
                {
                    LogError("Condor2TelemetryProvider Exception while processing data", e);
                    IsConnected = false;
                    IsRunning   = false;
                    Thread.Sleep(1000);
                }
            }
            sw.Stop();
            IsConnected = false;
            IsRunning   = false;
        }
        private void Simconnect_OnRecvSimobjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data)
        {
            // Must be general SimObject information
            switch (data.dwRequestID)
            {
            case (uint)DATA_REQUESTS.FLIGHT_STATUS:
            {
                var flightStatus = data.dwData[0] as FlightStatusStruct?;

                if (flightStatus.HasValue)
                {
                    try
                    {
                        //object obj = data.dwData[0];
                        //AircraftData acData = (AircraftData?)obj ?? default;
                        TelemetryData telemetryData = new TelemetryData
                        {
                            Pitch      = (float)flightStatus.Value.Pitch,
                            Roll       = (float)flightStatus.Value.Bank,
                            Yaw        = (float)flightStatus.Value.Yaw,
                            Surge      = (float)flightStatus.Value.zAccel,
                            Sway       = (float)flightStatus.Value.xAccel,
                            Heave      = (float)flightStatus.Value.yAccel,
                            RollSpeed  = (float)flightStatus.Value.xVelocity,
                            YawSpeed   = (float)flightStatus.Value.yVelocity,
                            PitchSpeed = (float)flightStatus.Value.zVelocity,
                            Speed      = (float)flightStatus.Value.GroundSpeed,
                            RPM        = (float)flightStatus.Value.RPM
                        };

                        IsConnected = true;
                        IsRunning   = true;

                        TelemetryEventArgs args = new TelemetryEventArgs(new TelemetryInfoElem(telemetryData, lastTelemetryData));
                        RaiseEvent(OnTelemetryUpdate, args);
                        lastTelemetryData = telemetryData;
                    }
                    catch (Exception e)
                    {
                        LogError(Name + "TelemetryProvider Exception while receiving data", e);
                        IsConnected = false;
                        IsRunning   = false;
                        Thread.Sleep(1000);
                    }
                }
            }
            break;
            }
        }
        private void Run()
        {
            try
            {
                LogDebug(Name + "TelemetryProvider Run start");
                lastTelemetryData = new TelemetryData();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                LogDebug(Name + "TelemetryProvider Stopwatch start");

                while (!_isStopped)
                {
                    try
                    {
                        if (!SimConnectInitialized)
                        {
                            InitializeSimConnect();
                        }
                        else
                        {
                            var simconnect = simconnectx as SimConnect;
                            simconnect?.ReceiveMessage();
                            sw.Restart();
                            Thread.Sleep(TelemetryUpdateFrequency);
                        }

                        if (sw.ElapsedMilliseconds > 500)
                        {
                            IsRunning = false;
                        }
                    }
                    catch (Exception e)
                    {
                        LogError(Name + "TelemetryProvider Exception while processing data", e);
                        IsConnected = false;
                        IsRunning   = false;
                        Thread.Sleep(1000);
                    }
                }
                _definitionsAdded     = false;
                SimConnectInitialized = false;
                IsConnected           = false;
                IsRunning             = false;
            }
            catch (Exception e)
            {
                LogDebug(Name + " Error: " + e.Message);
            }
        }
Ejemplo n.º 4
0
        private void Simconnect_OnRecvSimobjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data)
        {
            try
            {
                // Must be general SimObject information
                if (data.dwRequestID == (uint)DATA_REQUESTS.FLIGHT_STATUS)
                {
                    var flightStatus = data.dwData[0] as FlightStatusStruct?;

                    if (!flightStatus.HasValue)
                    {
                        return;
                    }
                    TelemetryData telemetryData = new TelemetryData
                    {
                        Pitch           = flightStatus.Value.Pitch,
                        Roll            = flightStatus.Value.Bank,
                        Yaw             = flightStatus.Value.Yaw,
                        Surge           = flightStatus.Value.zAccel,
                        Sway            = flightStatus.Value.xAccel,
                        Heave           = flightStatus.Value.yAccel,
                        RollSpeed       = flightStatus.Value.zVelocity,
                        YawSpeed        = flightStatus.Value.yVelocity,
                        PitchSpeed      = flightStatus.Value.xVelocity,
                        RPM             = flightStatus.Value.RPM,
                        AngleOfAttack   = flightStatus.Value.AngleOfAttack,
                        AngleOfSideslip = flightStatus.Value.AngleOfSideslip,
                        AirSpeedTrue    = flightStatus.Value.AirSpeedTrue
                    };

                    IsConnected = true;
                    IsRunning   = true;

                    TelemetryEventArgs args = new TelemetryEventArgs(new TelemetryInfoElem(telemetryData, _lastTelemetryData)); RaiseEvent(OnTelemetryUpdate, args);
                    _lastTelemetryData = telemetryData;
                }
            }
            catch (Exception e)
            {
                LogError(Name + "TelemetryProvider Exception while receiving data:" + e.Message);
                IsConnected = false;
                IsRunning   = false;
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 5
0
        private TelemetryData ParseReponse(string resp)
        {
            TelemetryData telemetryData = new TelemetryData();

            string[] lines = resp.Split(';');
            if (lines.Length < 11)
            {
                return(telemetryData);
            }
            telemetryData.Pitch       = float.Parse(lines[0], CultureInfo.InvariantCulture);
            telemetryData.Roll        = float.Parse(lines[1], CultureInfo.InvariantCulture);
            telemetryData.Yaw         = float.Parse(lines[2], CultureInfo.InvariantCulture);
            telemetryData.Sway        = float.Parse(lines[3], CultureInfo.InvariantCulture);
            telemetryData.Surge       = float.Parse(lines[5], CultureInfo.InvariantCulture);
            telemetryData.Heave       = float.Parse(lines[8], CultureInfo.InvariantCulture);
            telemetryData.AirSpeed    = float.Parse(lines[9], CultureInfo.InvariantCulture);
            telemetryData.GroundSpeed = float.Parse(lines[10], CultureInfo.InvariantCulture);

            return(telemetryData);
        }
        private TelemetryData ParseReponse(string resp)
        {
            TelemetryData telemetryData = new TelemetryData();

            var lines = resp.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            if (lines.Length <= 0)
            {
                return(telemetryData);
            }
            var dict = new Dictionary <string, double>();

            foreach (var line  in lines)
            {
                var tmpLineItems = line.Split('=');
                if (tmpLineItems.Length == 2)
                {
                    dict.Add(tmpLineItems[0], Convert.ToDouble(tmpLineItems[1], CultureInfo.InvariantCulture));
                }
            }

            dict.TryGetValue("pitch", out var tmpPitch);
            telemetryData.Pitch = tmpPitch;

            dict.TryGetValue("roll", out var tmpRoll);
            telemetryData.Roll = tmpRoll;

            dict.TryGetValue("surge", out var tmpSurge);
            telemetryData.Surge = tmpSurge;

            dict.TryGetValue("yaw", out var tmpYaw);
            telemetryData.Yaw = tmpYaw;

            dict.TryGetValue("heave", out var tmpHeave);
            telemetryData.Heave = tmpHeave;
            return(telemetryData);
        }
Ejemplo n.º 7
0
 public GeneralPurposeTelemetryInfo(TelemetryData telemetryData)
 {
     _telemetryData = telemetryData;
 }
Ejemplo n.º 8
0
        private void Run()
        {
            try
            {
                LogDebug(Name + "TelemetryProvider Run start");
                _lastTelemetryData = new TelemetryData();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                LogDebug(Name + "TelemetryProvider Stopwatch start");
                while (!_isStopped)
                {
                    try
                    {
                        if (!_simConnectInitialized)
                        {
                            InitializeSimConnect();
                        }
                        else
                        {
                            _simconnect?.ReceiveMessage();

                            if (!_disableRateThrottle)
                            {
                                if (_autoCalculateRateLimiter)
                                {
                                    var sleepMs = (int)(1000 / TelemetryUpdateFrequency - sw.ElapsedMilliseconds);
                                    if (sleepMs > 0)
                                    {
                                        Thread.Sleep(sleepMs);
                                    }
                                }
                                else
                                {
                                    Thread.Sleep(_fixedRateLimiter);
                                }

                                if (sw.ElapsedMilliseconds > 500)
                                {
                                    IsRunning = false;
                                }
                            }
                            sw.Restart();
                        }
                    }
                    catch (Exception e)
                    {
                        LogError(Name + "TelemetryProvider Exception while processing data", e);
                        IsConnected = false;
                        IsRunning   = false;
                        Thread.Sleep(1000);
                    }
                }

                if (!_connectionClosed)
                {
                    CloseConnection();
                }
                _simConnectInitialized = false;
                IsConnected            = false;
                IsRunning         = false;
                _connectionClosed = false;
            }
            catch (Exception e)
            {
                LogDebug(Name + " Error: " + e.Message);
            }
        }
Ejemplo n.º 9
0
 public TelemetryInfoElem(TelemetryData telemetryData, TelemetryData lastTelemetryData)
 {
     _telemetryData = telemetryData;
 }
Ejemplo n.º 10
0
 public AeroflyFS2TelemetryInfo(TelemetryData telemetryData, TelemetryData lastTelemetryData)
 {
     _telemetryData = telemetryData;
 }
        private void Run()
        {
            TelemetryData lastTelemetryData = new TelemetryData();
            Stopwatch     sw = new Stopwatch();
            Stopwatch     swAddressHelper = new Stopwatch();

            sw.Start();
            swAddressHelper.Start();

            while (!_isStopped)
            {
                if (sw.ElapsedMilliseconds > 500)
                {
                    IsRunning = false;
                    Thread.Sleep(1000);
                }

                try
                {
                    if (_baseProcess == -1 || _adressesLoaded == false)
                    {
                        IsConnected = false;
                        try
                        {
                            _baseProcess    = -1;
                            _adressesLoaded = false;
                            InternalGameStart();
                        }
                        catch (Exception ex)
                        {
                            LogDebug("Error:" + ex.Message);
                        }
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        if (swAddressHelper.ElapsedMilliseconds > 1000)
                        {
                            GetDataAddresses();
                            swAddressHelper.Restart();
                        }


                        TelemetryData telemetryData = new TelemetryData();

                        // Flying
                        var Surge = GetSingle(_surgeAddress);
                        var Sway  = GetSingle(_swayAddress);
                        var Heave = GetSingle(_heaveAddress);
                        var Pitch = GetSingle(_pitchAddress);
                        var Roll  = GetSingle(_rollAddress);
                        var Yaw   = GetSingle(_yawAddress);
                        var Speed = GetSingle(_speedAddress);


                        if (Surge + Sway + Heave + Pitch + Roll + Yaw == 0.0)
                        {
                            // Driving
                            Surge = (float)(GetSingle(_surgeAddressSRV) / 9.80665);
                            Sway  = (float)(GetSingle(_swayAddressSRV) / 9.80665);
                            Heave = (float)(GetSingle(_heaveAddressSRV) / 9.80665);
                            Pitch = GetSingle(_pitchAddressSRV);
                            Roll  = GetSingle(_rollAddressSRV);
                            Yaw   = GetSingle(_yawAddressSRV);
                            Speed = GetSingle(_speedAddressSRV);
                        }


                        telemetryData.Surge = Surge;
                        telemetryData.Sway  = Sway;
                        telemetryData.Heave = Heave;
                        telemetryData.Pitch = Pitch;
                        telemetryData.Roll  = Roll;
                        telemetryData.Yaw   = Yaw;
                        telemetryData.Speed = Speed;

                        IsConnected = true;
                        IsRunning   = true;



                        TelemetryEventArgs args = new TelemetryEventArgs(new TelemetryInfoElem(telemetryData, lastTelemetryData));
                        RaiseEvent(OnTelemetryUpdate, args);
                        lastTelemetryData = telemetryData;
                        sw.Restart();


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

            IsConnected = false;
            IsRunning   = false;
        }
 public Condor2TelemetryInfo(TelemetryData telemetryData)
 {
     _telemetryData = telemetryData;
 }
        private TelemetryData ParseReponse(string resp)
        {
            TelemetryData telemetryData = new TelemetryData();

            string[] lines = resp.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            if (lines.Length > 15)
            {
                //var dict = new Dictionary<string, float>();
                var dict = new Dictionary <string, double>();
                // Todo: Einlesen in dictionary
                foreach (var line  in lines)
                {
                    var tmpLineItems = line.Split('=');
                    if (tmpLineItems.Length == 2)
                    {
                        //dict.Add(tmpLineItems[0], float.Parse(tmpLineItems[1], CultureInfo.InvariantCulture));
                        dict.Add(tmpLineItems[0], Convert.ToDouble(tmpLineItems[1], CultureInfo.InvariantCulture));
                    }
                }

                dict.TryGetValue("time", out var tmpTime);
                telemetryData.Time = tmpTime;

                dict.TryGetValue("airspeed", out var tmpAirspeed);
                telemetryData.AirSpeed = tmpAirspeed;

                dict.TryGetValue("altitude", out var tmpAltitude);
                telemetryData.Altitude = tmpAltitude;

                dict.TryGetValue("vario", out var tmpVario);
                telemetryData.Vario = tmpVario;

                dict.TryGetValue("evario", out var tmpEvario);
                telemetryData.Evario = tmpEvario;

                dict.TryGetValue("nettovario", out var tmpNettovario);
                telemetryData.Nettovario = tmpNettovario;

                dict.TryGetValue("integrator", out var tmpIntegrator);
                telemetryData.Integrator = tmpIntegrator;

                dict.TryGetValue("compass", out var tmpCompass);
                telemetryData.Compass = tmpCompass;

                dict.TryGetValue("slipball", out var tmpSlipball);
                telemetryData.SlipBall = tmpSlipball;

                dict.TryGetValue("turnrate", out var tmpTurnrate);
                telemetryData.TurnRate = tmpTurnrate;

                dict.TryGetValue("yawstringangle", out var tmpYawstringangle);
                telemetryData.YawStringAngle = tmpYawstringangle;

                dict.TryGetValue("yaw", out var tmpYaw);
                telemetryData.Yaw = tmpYaw;

                dict.TryGetValue("pitch", out var tmpPitch);
                telemetryData.Pitch = tmpPitch;

                dict.TryGetValue("bank", out var tmpRoll);
                telemetryData.Roll = tmpRoll;

                dict.TryGetValue("quaternionx", out var tmpQuaternionx);
                telemetryData.Quaternionx = tmpQuaternionx;

                dict.TryGetValue("quaterniony", out var tmpQuaterniony);
                telemetryData.Quaterniony = tmpQuaterniony;

                dict.TryGetValue("quaternionz", out var tmpQuaternionz);
                telemetryData.Quaternionz = tmpQuaternionz;

                dict.TryGetValue("quaternionw", out var tmpQuaternionw);
                telemetryData.Quaternionw = tmpQuaternionw;

                dict.TryGetValue("ax", out var tmpAx);
                telemetryData.Surge = tmpAx;

                dict.TryGetValue("ay", out var tmpAy);
                telemetryData.Sway = tmpAy;

                dict.TryGetValue("az", out var tmpAz);
                telemetryData.Heave = tmpAz;

                dict.TryGetValue("vx", out var tmpVx);
                telemetryData.SpeedX = tmpVx;

                dict.TryGetValue("vy", out var tmpVy);
                telemetryData.SpeedY = tmpVy;

                dict.TryGetValue("vz", out var tmpVz);
                telemetryData.SpeedZ = tmpVz;

                dict.TryGetValue("rollrate", out var tmpRollrate);
                telemetryData.RollRate = tmpRollrate;

                dict.TryGetValue("pitchrate", out var tmpPitchrate);
                telemetryData.PitchRate = tmpPitchrate;

                dict.TryGetValue("yawrate", out var tmpYawrate);
                telemetryData.YawRate = tmpYawrate;

                dict.TryGetValue("gforce", out var tmpGforce);
                telemetryData.Gforce = tmpGforce;

                dict.TryGetValue("height", out var tmpHeight);
                telemetryData.Height = tmpHeight;

                dict.TryGetValue("wheelheight", out var tmpWheelheight);
                telemetryData.Wheelheight = tmpWheelheight;

                dict.TryGetValue("turbulencestrength", out var tmpTurbulencestrength);
                telemetryData.Turbulencestrength = tmpTurbulencestrength;

                dict.TryGetValue("surfaceroughness", out var tmpSurfaceroughness);
                telemetryData.Surfaceroughness = tmpSurfaceroughness;

                // Surge alternative calculation
                if (telemetryData.AirSpeed + telemetryData.Time > 0)
                {
                    if ((telemetryData.Time - lastTelemetryData.Time) > 0)
                    {
                        telemetryData.SurgeAlternative = ((dict["airspeed"] - lastTelemetryData.AirSpeed) / (telemetryData.Time - lastTelemetryData.Time)) / 100;
                        LogDebug("Current time: " + telemetryData.Time + " Last time: " + lastTelemetryData.Time + " Current Speed: " + dict["airspeed"] + " Last Speed: " + lastTelemetryData.AirSpeed + " Current SurgeAlternative: " + telemetryData.SurgeAlternative + " Last SurgeAlternative: " + lastTelemetryData.SurgeAlternative);
                    }
                    else
                    {
                        telemetryData.SurgeAlternative = lastTelemetryData.SurgeAlternative;
                        LogDebug("Division by zero / Using last value for SurgeAlternative");
                    }
                }
                else
                {
                    LogDebug("Airspeed and Time not > 0");
                }
            }

            return(telemetryData);
        }