コード例 #1
0
        void client_CommandReceived(object sender, CommandReceivedEventArgs e)
        {
            Dispatcher.BeginInvoke((Action)(() =>
            {
                var type = typeof(IFAPIStatus).Assembly.GetType(e.Response.Type);

                //System.IO.File.AppendAllText("C:\\IfApi\\IfApiCommandResp.txt", e.Response.Type + ": " + e.CommandString + "\n");
                //if (pCustomCmdSent)
                //{
                //    txtResp.AppendText(e.Response.Type + " " + e.CommandString + "\n\n");
                //    txtResp.ScrollToEnd();
                //    pCustomCmdSent = false;
                //}

                if (type == typeof(APIAircraftState))
                {
                    var state = Serializer.DeserializeJson <APIAircraftState>(e.CommandString);
                    //Console.WriteLine(e.CommandString);
                    //airplaneStateGrid.DataContext = null;
                    //airplaneStateGrid.DataContext = state;
                    pAircraftState = state;
                    if (FMSControl.autoFplDirectActive)
                    {
                        FMSControl.updateAutoNav(state);
                    }
                    AircraftStateControl.AircraftState = state;
                    AttitudeIndicator.updateAttitude(pAircraftState.Pitch, pAircraftState.Bank);
                }
                else if (type == typeof(GetValueResponse))
                {
                    var state = Serializer.DeserializeJson <GetValueResponse>(e.CommandString);

                    Console.WriteLine("{0} -> {1}", state.Parameters[0].Name, state.Parameters[0].Value);
                }
                else if (type == typeof(LiveAirplaneList))
                {
                    var airplaneList = Serializer.DeserializeJson <LiveAirplaneList>(e.CommandString);

                    //airplaneDataGrid.ItemsSource = airplaneList.Airplanes;
                }
                else if (type == typeof(FacilityList))
                {
                    var facilityList = Serializer.DeserializeJson <FacilityList>(e.CommandString);

                    //facilitiesDataGrid.ItemsSource = facilityList.Facilities;
                }
                else if (type == typeof(IFAPIStatus))
                {
                    var status = Serializer.DeserializeJson <IFAPIStatus>(e.CommandString);
                    updateConnectionStatus(status);
                    //versionTextBlock.Text = status.AppVersion;
                    //userNameTextBlock.Text = status.LoggedInUser;
                    //deviceNameTextBlock.Text = status.DeviceName;
                    //displayResolutionTextBlock.Text = string.Format("{0}x{1}", status.DisplayWidth, status.DisplayHeight);
                }
                else if (type == typeof(APIATCMessage))
                {
                    var msg = Serializer.DeserializeJson <APIATCMessage>(e.CommandString);

                    //atcMessagesListBox.Items.Add(msg.Message);

                    client.ExecuteCommand("Live.GetCurrentCOMFrequencies");
                }
                else if (type == typeof(APIFrequencyInfoList))
                {
                    var msg = Serializer.DeserializeJson <APIFrequencyInfoList>(e.CommandString);
                    //frequenciesDataGrid.ItemsSource = msg.Frequencies;
                }
                else if (type == typeof(ATCMessageList))
                {
                    var msg = Serializer.DeserializeJson <ATCMessageList>(e.CommandString);
                    //atcMessagesDataGrid.ItemsSource = msg.ATCMessages;
                }
                else if (type == typeof(APIFlightPlan))
                {
                    var msg = Serializer.DeserializeJson <APIFlightPlan>(e.CommandString);
                    Console.WriteLine("Flight Plan: {0} items", msg.Waypoints.Length);
                    FMSControl.fplReceived(msg);
                    foreach (var item in msg.Waypoints)
                    {
                        Console.WriteLine(" -> {0} {1} - {2}, {3}", item.Name, item.Code, item.Latitude, item.Longitude);
                    }
                }
            }));
        }
コード例 #2
0
        void client_CommandReceived(object sender, CommandReceivedEventArgs e)
        {
            Dispatcher.BeginInvoke((Action)(() =>
            {
                try {
                    var type = typeof(IFAPIStatus).Assembly.GetType(e.Response.Type);

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

                        Console.WriteLine(state.VerticalSpeed);

                        // 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);
                        }
                        AircraftStateControl.AircraftState = state;
                        AttitudeIndicator.updateAttitude(state.Pitch, state.Bank);
                        updateLandingRoll(state);
                    }
                    else if (type == typeof(GetValueResponse))
                    {
                        var state = Serializer.DeserializeJson <GetValueResponse>(e.CommandString);

                        Console.WriteLine("{0} -> {1}", state.Parameters[0].Name, state.Parameters[0].Value);
                    }
                    else if (type == typeof(LiveAirplaneList))
                    {
                        LiveAirplaneList airplaneList = Serializer.DeserializeJson <LiveAirplaneList>(e.CommandString);
                        //airplaneDataGrid.ItemsSource = airplaneList.Airplanes;
                    }
                    else if (type == typeof(FacilityList))
                    {
                        var facilityList = Serializer.DeserializeJson <FacilityList>(e.CommandString);

                        //facilitiesDataGrid.ItemsSource = facilityList.Facilities;
                    }
                    else if (type == typeof(IFAPIStatus))
                    {
                        var status = Serializer.DeserializeJson <IFAPIStatus>(e.CommandString);
                    }
                    else if (type == typeof(APIATCMessage))
                    {
                        var msg = Serializer.DeserializeJson <APIATCMessage>(e.CommandString);
                        // TODO client.ExecuteCommand("Live.GetCurrentCOMFrequencies");
                    }
                    else if (type == typeof(APIFrequencyInfoList))
                    {
                        var msg = Serializer.DeserializeJson <APIFrequencyInfoList>(e.CommandString);
                    }
                    else if (type == typeof(ATCMessageList))
                    {
                        var msg = Serializer.DeserializeJson <ATCMessageList>(e.CommandString);
                        atcMessagesDataGrid.ItemsSource = msg.ATCMessages;
                    }
                    else if (type == typeof(APIFlightPlan))
                    {
                        var msg = Serializer.DeserializeJson <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);
                        }
                    }
                } catch (System.NullReferenceException) {
                    Console.WriteLine("Disconnected from server!");
                    //Let the client handle the lost connection.
                    //connectionStatus = false;
                }
            }));
        }
コード例 #3
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;
                }
            });
        }