コード例 #1
0
        private void client_CommandReceived(object sender, IFConnect.CommandReceivedEventArgs e)
        {
            Dispatcher.UIThread.InvokeAsync(() =>
            {
                try
                {
                    // System.Diagnostics.Debug.WriteLine(e.CommandString);
                    var type = typeof(IFAPIStatus).Assembly.GetType(e.Response.Type);

                    if (type == typeof(APIAircraftState))
                    {
                        var state = JsonSerializer.Deserialize <APIAircraftState>(e.CommandString);

                        // convert to fpm
                        state.VerticalSpeed =
                            float.Parse(
                                Convert.ToString(state.VerticalSpeed * 200, CultureInfo.InvariantCulture.NumberFormat),
                                CultureInfo.InvariantCulture
                                .NumberFormat);     // multiply by 200, this somehow gets it accurate..

                        _airplaneStateGrid.DataContext = null;
                        _airplaneStateGrid.DataContext = state;
                        _pAircraftState = state;
                        if (_FMSControl.autoFplDirectActive)
                        {
                            _FMSControl.updateAutoNav(state);
                        }
                        if (_FMSControl.HoldingActive)
                        {
                            _FMSControl.performHold(state);
                        }
                        _AircraftStateControl.AircraftState = state;
                        _AttitudeIndicator.updateAttitude(state.Pitch, state.Bank);
                        updateLandingRoll(state);
                    }
                    else if (type == typeof(GetValueResponse))
                    {
                        var state = JsonSerializer.Deserialize <GetValueResponse>(e.CommandString);

                        Console.WriteLine("{0} -> {1}", state.Parameters[0].Name, state.Parameters[0].Value);
                    }
                    else if (type == typeof(APIATCMessage))
                    {
                        var msg = JsonSerializer.Deserialize <APIATCMessage>(e.CommandString);

                        //Handle the ATC message to control the autopilot if enabled by checkbox
                        _FMSControl.handleAtcMessage(msg, _pAircraftState);

                        // TODO client.ExecuteCommand("Live.GetCurrentCOMFrequencies");
                    }
                    else if (type == typeof(ATCMessageList))
                    {
                        var msg = JsonSerializer.Deserialize <ATCMessageList>(e.CommandString);
                        _atcMessagesDataGrid.Items = msg.ATCMessages;
                    }
                    else if (type == typeof(APIFlightPlan))
                    {
                        var msg = JsonSerializer.Deserialize <APIFlightPlan>(e.CommandString);
                        Console.WriteLine("Flight Plan: {0} items", msg.Waypoints.Length);
                        _FMSControl.FplReceived(msg); //Update FMS with FPL from IF.
                        foreach (var item in msg.Waypoints)
                        {
                            Console.WriteLine(" -> {0} {1} - {2}, {3}", item.Name, item.Code, item.Latitude,
                                              item.Longitude);
                        }
                    }
                    else if (type == typeof(APIAutopilotState))
                    {
                        _FMSControl.APState = Serializer.DeserializeJson <APIAutopilotState>(e.CommandString);
                    }
                }
                catch (NullReferenceException)
                {
                    Console.WriteLine("Disconnected from server!");
                    //Let the client handle the lost connection.
                    //connectionStatus = false;
                }
            });
        }
コード例 #2
0
 private void client_Disconnected(object?sender, IFConnect.CommandReceivedEventArgs commandReceivedEventArgs)
 {
     Dispatcher.UIThread.InvokeAsync(delegate { connectionLost(); });
 }