-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
81 lines (65 loc) · 2.23 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using FlightSimApi;
using System;
using System.Threading.Tasks;
namespace MSFSGPS
{
internal enum Definitions
{
Attitude,
Position,
}
#pragma warning disable CS0649
[SimConnectType(Definitions.Attitude, samplingFrequency: 100)]
internal struct Attitude
{
[SimConnectValue("PLANE HEADING DEGREES TRUE", "Degrees")]
public double Heading;
[SimConnectValue("PLANE PITCH DEGREES", "Degrees")]
public double Pitch;
[SimConnectValue("PLANE BANK DEGREES", "Degrees")]
public double Bank;
}
[SimConnectType(Definitions.Position, samplingFrequency: 1000)]
internal struct Position
{
[SimConnectValue("PLANE LONGITUDE", "Degrees")]
public double Longitude;
[SimConnectValue("PLANE LATITUDE", "Degrees")]
public double Latitude;
[SimConnectValue("PLANE ALTITUDE", "Meters")]
public double Altitude;
[SimConnectValue("GPS GROUND TRUE TRACK", "Degrees")]
public double GroundTrack;
[SimConnectValue("GPS GROUND SPEED")]
public double GroundSpeed;
}
#pragma warning restore CS0649
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Waiting for flight simulator...");
var api = new SimConnectApi();
using var gpsBroadcaster = new GpsBroadcaster();
api.RegisterType<Attitude>();
api.RegisterType<Position>();
api.RegisterHandler<Attitude>(gpsBroadcaster.BroadcastAttitudeData);
api.RegisterHandler<Position>(gpsBroadcaster.BroadcastPosition);
api.Start();
var lastConnectedState = false;
while (true)
{
if (lastConnectedState != api.IsConnected)
{
lastConnectedState = api.IsConnected;
Console.WriteLine($"{(api.IsConnected ? "Connected" : "Disconnected")} at {DateTime.UtcNow}");
if (!api.IsConnected)
{
Console.WriteLine("MSFSGPS will automatically reconnect...");
}
}
await Task.Delay(1000);
}
}
}
}