private void buttonForeflight_Click(object sender, EventArgs e) { if (null == foreFlightSender) { IPAddress foreflightIPAddress = null; ForeFlightNetworkOption networkOption = cbForeflightConnectType.Items[cbForeflightConnectType.SelectedIndex] as ForeFlightNetworkOption; switch (networkOption.NetworkType) { case ForeFlightNetworkOption.NetworkTypes.DirectIPv4: foreflightIPAddress = IPAddress.Parse(settings.ForeFlightDirectIp); break; case ForeFlightNetworkOption.NetworkTypes.IPv4NetworkBroadcast: case ForeFlightNetworkOption.NetworkTypes.IPv6LinkLocal: foreflightIPAddress = networkOption.Address; break; } foreFlightSender = new ForeFlightSender(ref flightData, new UdpClient( networkOption.NetworkType == NetworkTypes.IPv6LinkLocal ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork )); foreFlightSender.OnForeFlightSenderError += ForeFlightSender_OnForeFlightSenderError; IPEndPoint endpoint = new IPEndPoint( foreflightIPAddress, ForeFlightSender.DEFAULT_PORT); foreFlightSender.EndPoint = endpoint; foreFlightSender.Start(); SetForeflightControls(ConnectorState.Connected); labelIncompleteData.Visible = !ForeFlightSender.VerifyCompleteFlightData(flightData) && null != foreFlightSender; labelIncompleteData.Invalidate(); } else { foreFlightSender.Stop(); foreFlightSender = null; GC.Collect(); SetForeflightControls(ConnectorState.Disconnected); } }
private void FlightData_OnFlightDataUpdate(object sender, FlightData.FlightDataUpdatedEventArgs e) { if (0 != (e.Field | FlightDataField.Altitude)) { UpdateValueTextBox(tbAltitude, flightData.AltitudeFt, 2, " ft"); } if (0 != (e.Field | FlightDataField.GroundSpeed)) { UpdateValueTextBox(tbGroundSpeed, flightData.GroundSpeedKt, 1, " knots"); } if (0 != (e.Field | FlightDataField.GroundTrack)) { UpdateValueTextBox(tbGroundTrack, flightData.GroundTrackDegrees, 1, "°"); } if (0 != (e.Field | FlightDataField.TrueHeading)) { UpdateValueTextBox(tbHeading, flightData.TrueHeadingDegrees, 1, "°"); } if (0 != (e.Field | FlightDataField.Latitude)) { UpdateValueTextBox(tbLatitude, flightData.Latitude, 4, "°"); } if (0 != (e.Field | FlightDataField.Longitude)) { UpdateValueTextBox(tbLongitude, flightData.Longitude, 4, "°"); } if (0 != (e.Field | FlightDataField.Pitch)) { UpdateValueTextBox(tbPitch, flightData.PitchDegrees, 2, "°"); } if (0 != (e.Field | FlightDataField.Roll)) { UpdateValueTextBox(tbRoll, flightData.RollDegrees, 2, "°"); } labelIncompleteData.Visible = !ForeFlightSender.VerifyCompleteFlightData(flightData) && null != foreFlightSender; labelIncompleteData.Invalidate(); }