Exemplo n.º 1
0
        private async void FlightConnector_AircraftStatusUpdated(object sender, AircraftStatusUpdatedEventArgs e)
        {
            if (StreamDeck == null)
            {
                return;
            }

            var lastStatus = status;

            status = e.AircraftStatus;

            switch (action)
            {
            case "tech.flighttracker.streamdeck.master.activate":
                if (e.AircraftStatus.IsAutopilotOn != lastStatus?.IsAutopilotOn)
                {
                    logger.LogInformation("Received AP update: {state}", e.AircraftStatus.IsAutopilotOn);
                    await UpdateImage();
                }
                break;

            case "tech.flighttracker.streamdeck.heading.activate":
                if (e.AircraftStatus.ApHeading != lastStatus?.ApHeading || e.AircraftStatus.IsApHdgOn != lastStatus?.IsApHdgOn)
                {
                    logger.LogInformation("Received HDG update: {IsApHdgOn} {ApHeading}", e.AircraftStatus.IsApHdgOn, e.AircraftStatus.ApHeading);
                    await UpdateImage();
                }
                break;

            case "tech.flighttracker.streamdeck.nav.activate":
                if (e.AircraftStatus.IsApNavOn != lastStatus?.IsApNavOn)
                {
                    logger.LogInformation("Received NAV update: {IsApNavOn}", e.AircraftStatus.IsApNavOn);
                    await UpdateImage();
                }
                break;

            case "tech.flighttracker.streamdeck.approach.activate":
                if (e.AircraftStatus.IsApAprOn != lastStatus?.IsApAprOn)
                {
                    logger.LogInformation("Received APR update: {IsApAprOn}", e.AircraftStatus.IsApAprOn);
                    await UpdateImage();
                }
                break;

            case "tech.flighttracker.streamdeck.altitude.activate":
                if (e.AircraftStatus.ApAltitude != lastStatus?.ApAltitude || e.AircraftStatus.IsApAltOn != lastStatus?.IsApAltOn)
                {
                    logger.LogInformation("Received ALT update: {IsApHdgOn} {ApHeading}", e.AircraftStatus.IsApAltOn, e.AircraftStatus.ApAltitude);
                    await UpdateImage();
                }
                break;
            }
        }
Exemplo n.º 2
0
        private async void FlightConnector_AircraftStatusUpdated(object sender, AircraftStatusUpdatedEventArgs e)
        {
            if (viewModel.IsTracking)
            {
                e.AircraftStatus.Callsign        = viewModel.Callsign;
                e.AircraftStatus.TransponderMode = viewModel.TransponderIdent ? TransponderMode.Ident : TransponderMode.ModeC;

                if (hub?.ConnectionId != null && DateTime.Now - lastStatusSent > TimeSpan.FromMilliseconds(MinimumUpdatePeriod))
                {
                    route.Add(new AircraftStatusBrief(e.AircraftStatus));

                    lastStatusSent = DateTime.Now;
                    await hub.SendAsync("UpdateAircraft", e.AircraftStatus);

                    lastStatusSent = DateTime.Now;

                    if (viewModel.TransponderIdent)
                    {
                        viewModel.TransponderIdent = false;
                    }
                }

                viewModel.AircraftStatus = e.AircraftStatus;

                try
                {
                    if (viewModel.BroadcastUDP)
                    {
                        await udpBroadcastLogic.SendGpsAsync(e.AircraftStatus);

                        await udpBroadcastLogic.SendAttitudeAsync(e.AircraftStatus);
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Cannot send network package!");
                }
            }
        }
Exemplo n.º 3
0
        private async void FlightConnector_AircraftStatusUpdated(object sender, AircraftStatusUpdatedEventArgs e)
        {
            if (StreamDeck == null)
            {
                return;
            }

            var lastStatus = status;

            status = e.AircraftStatus;

            switch (settings?.Type)
            {
            case PresetFunction.Avionics:
                if (e.AircraftStatus.IsAvMasterOn != lastStatus?.IsAvMasterOn)
                {
                    logger.LogInformation("Received AV Master update: {state}", e.AircraftStatus.IsAvMasterOn);
                    await UpdateImage();
                }
                break;

            case PresetFunction.ApMaster:
                if (e.AircraftStatus.IsAutopilotOn != lastStatus?.IsAutopilotOn)
                {
                    logger.LogInformation("Received AP update: {state}", e.AircraftStatus.IsAutopilotOn);
                    await UpdateImage();
                }
                break;

            case PresetFunction.Heading:
                if (e.AircraftStatus.ApHeading != lastStatus?.ApHeading || e.AircraftStatus.IsApHdgOn != lastStatus?.IsApHdgOn)
                {
                    logger.LogInformation("Received HDG update: {IsApHdgOn} {ApHeading}", e.AircraftStatus.IsApHdgOn, e.AircraftStatus.ApHeading);
                    await UpdateImage();
                }
                break;

            case PresetFunction.Nav:
                if (e.AircraftStatus.IsApNavOn != lastStatus?.IsApNavOn)
                {
                    logger.LogInformation("Received NAV update: {IsApNavOn}", e.AircraftStatus.IsApNavOn);
                    await UpdateImage();
                }
                break;

            case PresetFunction.Altitude:
                if (e.AircraftStatus.ApAltitude != lastStatus?.ApAltitude || e.AircraftStatus.IsApAltOn != lastStatus?.IsApAltOn)
                {
                    logger.LogInformation("Received ALT update: {IsApAltOn} {ApAltitude}", e.AircraftStatus.IsApAltOn, e.AircraftStatus.ApAltitude);
                    await UpdateImage();
                }
                break;

            case PresetFunction.VerticalSpeed:
                if (e.AircraftStatus.ApVs != lastStatus?.ApVs || e.AircraftStatus.IsApVsOn != lastStatus?.IsApVsOn)
                {
                    logger.LogInformation("Received VS update: {IsApVsOn} {ApVerticalSpeed}", e.AircraftStatus.IsApVsOn, e.AircraftStatus.ApVs);
                    await UpdateImage();
                }
                break;

            case PresetFunction.FLC:
                if (e.AircraftStatus.ApAirspeed != lastStatus?.ApAirspeed || e.AircraftStatus.IsApFlcOn != lastStatus?.IsApFlcOn)
                {
                    logger.LogInformation("Received FLC update: {IsApFlcOn}", e.AircraftStatus.IsApFlcOn);
                    await UpdateImage();
                }
                break;

            case PresetFunction.Approach:
                if (e.AircraftStatus.IsApAprOn != lastStatus?.IsApAprOn)
                {
                    logger.LogInformation("Received APR update: {IsApAprOn}", e.AircraftStatus.IsApAprOn);
                    await UpdateImage();
                }
                break;
            }
        }
Exemplo n.º 4
0
        private async void FlightConnector_AircraftStatusUpdated(object sender, AircraftStatusUpdatedEventArgs e)
        {
            if (viewModel.IsTracking)
            {
                e.AircraftStatus.Callsign        = viewModel.Callsign;
                e.AircraftStatus.TransponderMode = viewModel.TransponderIdent ? TransponderMode.Ident : TransponderMode.ModeC;

                if (DateTime.Now - lastStatusSent > TimeSpan.FromMilliseconds(MinimumUpdatePeriod))
                {
                    if (hub?.ConnectionId != null)
                    {
                        route.Add(new AircraftStatusBrief(e.AircraftStatus));

                        lastStatusSent = DateTime.Now;
                        await hub.SendAsync("UpdateAircraft", e.AircraftStatus);

                        lastStatusSent = DateTime.Now;

                        if (viewModel.TransponderIdent)
                        {
                            viewModel.TransponderIdent = false;
                        }
                    }

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();
                    var     minDistance = 0d;
                    Airport minAirport  = null;
                    foreach (var airport in airports.Values)
                    {
                        var distance = GpsHelper.CalculateDistance(e.AircraftStatus.Latitude, e.AircraftStatus.Longitude, airport.Latitude, airport.Longitude);
                        if (minAirport == null || minDistance > distance)
                        {
                            minDistance = distance;
                            minAirport  = airport;
                        }
                    }
                    if (minAirport != null)
                    {
                        viewModel.NearestAirport = minAirport;
                    }
                    //Debug.WriteLine($"Found closest airport in {stopwatch.ElapsedMilliseconds}ms");
                    stopwatch.Stop();
                }

                viewModel.AircraftStatus = e.AircraftStatus;

                try
                {
                    if (viewModel.BroadcastUDP)
                    {
                        await udpBroadcastLogic.SendGpsAsync(e.AircraftStatus);

                        await udpBroadcastLogic.SendAttitudeAsync(e.AircraftStatus);
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Cannot send network package!");
                }
            }
        }