Skip to content

Commit

Permalink
- Use CultureInfo.InvariantCulture when creating ForeFlight datagram …
Browse files Browse the repository at this point in the history
…strings

- Fix initialization when using UDP broadcast
- Substitute KittyHawk simulator name string when using MSFS
  • Loading branch information
ollyau committed Aug 6, 2021
1 parent 74c0d4a commit 755122f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
7 changes: 4 additions & 3 deletions EFBConnect/ForeFlightUdp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
using System.Text;
Expand Down Expand Up @@ -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
);
Expand All @@ -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
);
Expand All @@ -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,
Expand Down
21 changes: 16 additions & 5 deletions EFBConnect/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Input;
using System.Windows.Threading;

Expand Down Expand Up @@ -28,10 +29,19 @@ public MainViewModel()
_connection = cfg.Get<ConnectionType>("ConnectionType", ConnectionType.Broadcast, true);
_deviceIp = cfg.Get<string>("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.";

Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions EFBConnect/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit 755122f

Please sign in to comment.