From 755122f8ba7e44c760050947a71bfe34dcc3e03a Mon Sep 17 00:00:00 2001 From: Orion Date: Thu, 5 Aug 2021 20:17:41 -0700 Subject: [PATCH] - Use CultureInfo.InvariantCulture when creating ForeFlight datagram strings - Fix initialization when using UDP broadcast - Substitute KittyHawk simulator name string when using MSFS --- EFBConnect/ForeFlightUdp.cs | 7 ++++--- EFBConnect/MainViewModel.cs | 21 ++++++++++++++++----- EFBConnect/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/EFBConnect/ForeFlightUdp.cs b/EFBConnect/ForeFlightUdp.cs index c56802f..14fe7cb 100644 --- a/EFBConnect/ForeFlightUdp.cs +++ b/EFBConnect/ForeFlightUdp.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Net; using System.Net.Sockets; using System.Text; @@ -54,7 +55,7 @@ public void Send(Position p) { if (udpSocket != null) { - var posDatagram = string.Format( + var posDatagram = string.Format(CultureInfo.InvariantCulture, "XGPS{0},{1:0.#####},{2:0.#####},{3:0.#},{4:0.###},{5:0.#}", simIdent, p.Longitude, p.Latitude, p.Altitude, p.GroundTrack, p.GroundSpeed ); @@ -70,7 +71,7 @@ public void Send(Attitude a) { if (udpSocket != null) { - var attDatagram = string.Format( + var attDatagram = string.Format(CultureInfo.InvariantCulture, "XATT{0},{1:0.#},{2:0.#},{3:0.#}", simIdent, a.TrueHeading, -a.Pitch, -a.Bank ); @@ -86,7 +87,7 @@ public void Send(TrafficInfo t, uint dwObjectID) { if (udpSocket != null) { - var trafficDatagram = string.Format( + var trafficDatagram = string.Format(CultureInfo.InvariantCulture, "XTRAFFIC{0},{1},{2:0.#####},{3:0.#####},{4:0.#},{5:0.#},{6},{7:0.###},{8:0.#},{9}", simIdent, dwObjectID, t.Latitude, t.Longitude, t.Altitude, t.VerticalSpeed, t.OnGround ? 0 : 1, t.TrueHeading, t.GroundVelocity, diff --git a/EFBConnect/MainViewModel.cs b/EFBConnect/MainViewModel.cs index 8c7cdf5..7d31c74 100644 --- a/EFBConnect/MainViewModel.cs +++ b/EFBConnect/MainViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Windows.Input; using System.Windows.Threading; @@ -28,10 +29,19 @@ public MainViewModel() _connection = cfg.Get("ConnectionType", ConnectionType.Broadcast, true); _deviceIp = cfg.Get("IPAddress", null, true); - if (!string.IsNullOrEmpty(_deviceIp)) + switch (_connection) { - SetIP(_deviceIp); - } + case ConnectionType.IPAddress: + SetIP( string.IsNullOrWhiteSpace( _deviceIp ) ? null : _deviceIp ); + break; + case ConnectionType.Broadcast: + SetIP( null ); + break; + default: + var message = $"Unknown ConnectionType '{Enum.GetName( typeof( ConnectionType ), _connection )}'"; + Log.Instance.Error( message ); + throw new InvalidOperationException( message ); + } ConnectionStatus = "Disconnected from flight simulator."; @@ -53,7 +63,8 @@ private void Simulator_PropertyChanged(object sender, System.ComponentModel.Prop if (efbConnect.Connected) { timer.Stop(); - ConnectionStatus = $"Connected to {efbConnect.SimulatorName}."; + var name = efbConnect.SimulatorName == "KittyHawk" ? "Microsoft Flight Simulator" : efbConnect.SimulatorName; + ConnectionStatus = $"Connected to {name}."; } else { @@ -105,7 +116,7 @@ private bool SetIP(string value) System.Net.IPAddress ipValue; if (!string.IsNullOrEmpty(value) && System.Net.IPAddress.TryParse(value, out ipValue)) { - CurrentIpSetting = string.Format("IP Address ({0})", value); + CurrentIpSetting = string.Format(CultureInfo.InvariantCulture, "IP Address ({0})", value); ForeFlightUdp.Instance.SetDestination(ipValue); return true; } diff --git a/EFBConnect/Properties/AssemblyInfo.cs b/EFBConnect/Properties/AssemblyInfo.cs index 38ca3ee..d7b7d07 100644 --- a/EFBConnect/Properties/AssemblyInfo.cs +++ b/EFBConnect/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.0.0")] -[assembly: AssemblyFileVersion("1.1.0.0")] +[assembly: AssemblyVersion("1.1.1.0")] +[assembly: AssemblyFileVersion("1.1.1.0")]