Exemple #1
0
        private void Simconnect_OnRecvSimobjectDataBytypeAsync(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
        {
            // Must be general SimObject information
            switch (data.dwRequestID)
            {
            case (uint)DATA_REQUESTS.AIRCRAFT_DATA:
            {
                // Handle this when aircraft is changed
                var aircraftData = data.dwData[0] as AircraftDataStruct?;

                if (aircraftData.HasValue)
                {
                    logger.LogInformation("Aircraft data received.");

                    var result = new AircraftData
                    {
                        Type  = aircraftData.Value.Type,
                        Model = aircraftData.Value.Model,
                        Title = aircraftData.Value.Title,
                        EstimatedCruiseSpeed = aircraftData.Value.EstimatedCruiseSpeed
                    };
                    AircraftDataUpdated?.Invoke(this, new AircraftDataUpdatedEventArgs(result));

                    aircraftDataTcs?.TrySetResult(result);
                    aircraftDataTcs = null;
                }
            }
            break;
            }
        }
Exemple #2
0
        private void Simconnect_OnRecvSimobjectDataBytypeAsync(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
        {
            switch (data.dwRequestID)
            {
            case (uint)DATA_REQUESTS.AIRCRAFT_DATA:
            {
                var aircraftData = data.dwData[0] as AircraftDataStruct?;

                if (aircraftData.HasValue)
                {
                    var result = new AircraftData
                    {
                        Type  = aircraftData.Value.Type,
                        Model = aircraftData.Value.Model,
                        Title = aircraftData.Value.Title,
                        EstimatedCruiseSpeed = aircraftData.Value.EstimatedCruiseSpeed
                    };
                    AircraftDataUpdated?.Invoke(this, new AircraftDataUpdatedEventArgs(result));

                    aircraftDataTcs?.TrySetResult(result);
                    aircraftDataTcs = null;
                }
            }
            break;
            }
        }
Exemple #3
0
        private async void simconnect_OnRecvSimobjectDataBytypeAsync(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data)
        {
            // Must be general SimObject information
            switch (data.dwRequestID)
            {
            case (uint)DATA_REQUESTS.AIRCRAFT_DATA:
            {
                var aircraftData = data.dwData[0] as AircraftDataStruct?;

                if (aircraftData.HasValue)
                {
                    var dto = new AircraftData
                    {
                        Title        = aircraftData.Value.Title,
                        Type         = aircraftData.Value.AtcType,
                        Model        = aircraftData.Value.AtcModel,
                        TailNumber   = aircraftData.Value.AtcId,
                        Airline      = aircraftData.Value.AtcAirline,
                        FlightNumber = aircraftData.Value.AtcFlightNumber
                    };

                    AircraftDataUpdated?.Invoke(this, new AircraftDataUpdatedEventArgs(dto));
                }
                else
                {
                    // Cast failed
                    logger.LogError("Cannot cast to AircraftDataStruct!");
                }
            }
            break;

            case (uint)DATA_REQUESTS.FLIGHT_PLAN_STATUS:
            {
                var flightPlan = data.dwData[0] as FlightPlanStruct?;
            }
            break;

            case (uint)DATA_REQUESTS.FLIGHT_STATUS:
            {
                var flightStatus = data.dwData[0] as FlightStatusStruct?;

                if (flightStatus.HasValue)
                {
                    FlightStatusUpdated?.Invoke(this, new FlightStatusUpdatedEventArgs(
                                                    new ClientFlightStatus
                        {
                            SimTime             = flightStatus.Value.SimTime,
                            SimRate             = flightStatus.Value.SimRate,
                            Latitude            = flightStatus.Value.Latitude,
                            Longitude           = flightStatus.Value.Longitude,
                            Altitude            = flightStatus.Value.Altitude,
                            AltitudeAboveGround = flightStatus.Value.AltitudeAboveGround,
                            Pitch             = flightStatus.Value.Pitch,
                            Bank              = flightStatus.Value.Bank,
                            Heading           = flightStatus.Value.MagneticHeading,
                            TrueHeading       = flightStatus.Value.TrueHeading,
                            GroundSpeed       = flightStatus.Value.GroundSpeed,
                            IndicatedAirSpeed = flightStatus.Value.IndicatedAirSpeed,
                            VerticalSpeed     = flightStatus.Value.VerticalSpeed,
                            FuelTotalQuantity = flightStatus.Value.FuelTotalQuantity,
                            IsOnGround        = flightStatus.Value.IsOnGround == 1,
                            StallWarning      = flightStatus.Value.StallWarning == 1,
                            OverspeedWarning  = flightStatus.Value.OverspeedWarning == 1,
                            IsAutopilotOn     = flightStatus.Value.IsAutopilotOn == 1
                        }));
                }
                else
                {
                    // Cast failed
                    logger.LogError("Cannot cast to FlightStatusStruct!");
                }

                await Task.Delay(StatusDelayMilliseconds);

                simconnect?.RequestDataOnSimObjectType(DATA_REQUESTS.FLIGHT_STATUS, DEFINITIONS.FlightStatus, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);
            }
            break;
            }
        }