-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fixes #6, setting Local as default location for writing SimConnect.cfg * Added all simulation variables and units as documented by the SimVarWatcher example in the MSFS SDK * Verified that bundled SimConnect binaries in SDK 0.10.0 is the same as in this release.
- Loading branch information
1 parent
f743f93
commit 1465543
Showing
17 changed files
with
3,066 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/CTrue.FsConnect.ExampleConsole/CTrue.FsConnect.ExampleConsole.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net472</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<PlatformTarget>x64</PlatformTarget> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<PlatformTarget>x64</PlatformTarget> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CTrue.FsConnect\CTrue.FsConnect.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Microsoft.FlightSimulator.SimConnect"> | ||
<HintPath>..\Dependencies\SimConnect\lib\net40\Microsoft.FlightSimulator.SimConnect.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\Dependencies\SimConnect\build\SimConnect.dll" Visible="false"> | ||
<Link>%(FileName)%(Extension)</Link> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
using CTrue.FsConnect; | ||
using Microsoft.FlightSimulator.SimConnect; | ||
|
||
namespace FsConnectTest | ||
{ | ||
public enum Requests | ||
{ | ||
PlaneInfo = 0 | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] | ||
public struct PlaneInfoResponse | ||
{ | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] | ||
public String Title; | ||
public double Latitude; | ||
public double Longitude; | ||
public double Altitude; | ||
public double Heading; | ||
public double SpeedMpS; | ||
public double SpeedKnots; | ||
} | ||
|
||
public class FsConnectTestConsole | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
string hostName = "localhost"; | ||
uint port = 500; | ||
|
||
// Also supports "somehostname 1234" | ||
if(args.Length == 2) | ||
{ | ||
hostName = args[0]; | ||
port = uint.Parse(args[1]); | ||
} | ||
|
||
FsConnect fsConnect = new FsConnect(); | ||
|
||
// Specify where the SimConnect.cfg should be written to | ||
fsConnect.SimConnectFileLocation = SimConnectFileLocation.Local; | ||
|
||
// Creates a SimConnect.cfg and connect to Flight Simulator using this configuration. | ||
fsConnect.Connect("TestApp", hostName, port, SimConnectProtocol.Ipv4); | ||
|
||
// Other alternatives, use existing SimConfig.cfg and specify config index: | ||
// fsConnect.Connect(1); | ||
// or | ||
// fsConnect.Connect(); | ||
|
||
fsConnect.FsDataReceived += HandleReceivedFsData; | ||
|
||
List<SimProperty> definition = new List<SimProperty>(); | ||
|
||
// Consult the SDK for valid sim variable names, units and whether they can be written to. | ||
definition.Add(new SimProperty("Title", null, SIMCONNECT_DATATYPE.STRING256)); | ||
definition.Add(new SimProperty("Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64)); | ||
definition.Add(new SimProperty("Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64)); | ||
|
||
// Can also use predefined enums for sim variables and units (incomplete) | ||
definition.Add(new SimProperty(FsSimVar.PlaneAltitude, FsUnit.Feet, SIMCONNECT_DATATYPE.FLOAT64)); | ||
definition.Add(new SimProperty(FsSimVar.PlaneHeadingDegreesTrue, FsUnit.Degrees, SIMCONNECT_DATATYPE.FLOAT64)); | ||
definition.Add(new SimProperty(FsSimVar.AirspeedTrue, FsUnit.MeterPerSecond, SIMCONNECT_DATATYPE.FLOAT64)); | ||
definition.Add(new SimProperty(FsSimVar.AirspeedTrue, FsUnit.Knot, SIMCONNECT_DATATYPE.FLOAT64)); | ||
|
||
fsConnect.RegisterDataDefinition<PlaneInfoResponse>(Requests.PlaneInfo, definition); | ||
|
||
fsConnect.RequestData(Requests.PlaneInfo); | ||
Console.ReadKey(); | ||
fsConnect.Disconnect(); | ||
} | ||
|
||
private static void HandleReceivedFsData(object sender, FsDataReceivedEventArgs e) | ||
{ | ||
if (e.RequestId == (uint)Requests.PlaneInfo) | ||
{ | ||
PlaneInfoResponse r = (PlaneInfoResponse)e.Data; | ||
Console.WriteLine($"{r.Latitude:F4} {r.Longitude:F4} {r.Altitude:F1}ft {r.Heading:F1}deg {r.SpeedMpS:F0}m/s {r.SpeedKnots:F0}kt"); | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/CTrue.FsConnect.ExampleConsole/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"profiles": { | ||
"CTrue.FsConnect.ExampleConsole": { | ||
"commandName": "Project", | ||
"commandLineArgs": "localhost 500" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.