예제 #1
0
        private void Run()
        {
            TelemetryData 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;

                    var           received      = socket.Receive(ref endpoint);
                    var           resp          = Encoding.UTF8.GetString(received);
                    TelemetryData telemetryData = ParseReponse(resp);

                    IsRunning = true;

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

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

            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()
        {
            UdpClient socket = new UdpClient {
                ExclusiveAddressUse = false
            };

            socket.Client.ReceiveBufferSize = 20;
            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 GeneralPurposeTelemetryInfo(telemetryData));
                    RaiseEvent(OnTelemetryUpdate, args);
                    sw.Restart();
                }
                catch (Exception e)
                {
                    LogError("General Purpose Telemetry Provider Exception while processing data", e);
                    IsConnected = false;
                    IsRunning   = false;
                    Thread.Sleep(1000);
                }
            }
            sw.Stop();
            IsConnected = false;
            IsRunning   = false;
        }
예제 #4
0
        private void Run()
        {
            TMData    lastTelemetryData = new TMData();
            Stopwatch sw = new Stopwatch();

            sw.Start();

            while (!isStopped)
            {
                try
                {
                    TMData telemetryData = (TMData)readSharedMemory(typeof(TMData), sharedMemoryFile);
                    IsConnected = true;

                    if (telemetryData.Object.Timestamp != lastTelemetryData.Object.Timestamp)
                    {
                        //Debuglog("Get Data");
                        IsRunning = true;

                        sw.Restart();

                        TelemetryEventArgs args = new TelemetryEventArgs(new TMTelemetryInfo(telemetryData, lastTelemetryData));

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

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

            IsConnected = false;
            IsRunning   = false;
        }
예제 #5
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);
            }
        }
 private void FireDisconnected(TelemetryEventArgs e)
 {
     Disconnected?.Invoke(this, e);
 }
 protected void OnTelemetryUpdate(TelemetryEventArgs e)
 {
     TelemetryUpdate?.Invoke(this, e);
 }
        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;
        }