Skip to content

Commit 7f0a646

Browse files
Add initial implementation of SimConnect.NET tests and core structures
- Created SimConnectVersionBaseType struct to represent version data. - Added SimConnect.dll binary to the project. - Introduced StyleCop configuration for code style enforcement. - Implemented test project for SimConnect.NET with .NET 8 targeting. - Developed comprehensive tests for AI object management, aircraft data, connection lifecycle, performance, and SimVar operations. - Established a test runner to execute and report results of all tests. - Included detailed logging and error handling in tests for better diagnostics.
0 parents  commit 7f0a646

97 files changed

Lines changed: 7389 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.cs]
11+
dotnet_style_qualification_for_field = false:suggestion
12+
dotnet_style_qualification_for_property = false:suggestion

.github/copilot-instructions.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# SimConnect.NET AI Coding Agent Instructions
2+
3+
## Project Overview
4+
5+
SimConnect.NET is a managed C# wrapper for Microsoft Flight Simulator's SimConnect SDK, providing async/await patterns and high-level abstractions for flight simulation data access.
6+
7+
## Architecture & Core Components
8+
9+
### Three-Layer Design Pattern
10+
11+
- **SimConnectClient**: Main entry point, manages connection lifecycle and background message processing
12+
- **Manager Layer**: Domain-specific managers (`SimVarManager`, `AircraftDataManager`, `SimObjectManager`)
13+
- **Native Layer**: P/Invoke bindings in `SimConnectNative.cs` with ANSI string marshaling
14+
15+
### Key Manager Responsibilities
16+
17+
- **SimVarManager**: Dynamic SimVar operations with automatic data definition caching and async request handling
18+
- **AircraftDataManager**: High-level aircraft data aggregation (uses concurrent requests for efficiency)
19+
- **SimObjectManager**: AI object creation and lifecycle management
20+
21+
### Message Processing Pattern
22+
23+
The client runs a background message loop (`StartMessageProcessingLoopAsync`) with adaptive polling delays that routes messages based on `SimConnectRecvId` enum values. Each manager processes relevant messages via their own handlers.
24+
25+
## Development Conventions
26+
27+
### Code Style (StyleCop Enforced)
28+
29+
- All public members require XML documentation with company copyright headers
30+
- Using directives outside namespace, newline at EOF required
31+
- `TreatWarningsAsErrors=true` in all projects except tests
32+
- File headers: `// <copyright file="FileName.cs" company="AussieScorcher">`
33+
34+
### Async Patterns
35+
36+
```csharp
37+
// Concurrent requests for efficiency
38+
var tasks = new[] {
39+
simVarManager.GetAsync<double>("VAR1", "unit"),
40+
simVarManager.GetAsync<double>("VAR2", "unit")
41+
};
42+
await Task.WhenAll(tasks);
43+
```
44+
45+
### Error Handling
46+
47+
- Use `SimConnectException` with `SimConnectError` enum for SimConnect-specific failures
48+
- `ObjectDisposedException.ThrowIf(disposed, nameof(Class))` for disposal checks
49+
- Debug.WriteLine for non-critical errors to avoid breaking message loops
50+
51+
## Build & Test Workflow
52+
53+
### Multi-targeting & Dependencies
54+
55+
- Projects target both .NET 8.0 and 9.0 (`<TargetFrameworks>net8.0;net9.0</TargetFrameworks>`)
56+
- `SimConnect.dll` is bundled in `lib/` and copied to output (`CopyToOutputDirectory>PreserveNewest`)
57+
- NuGet package generation enabled with `GeneratePackageOnBuild=true`
58+
59+
### Test Structure
60+
61+
- Tests implement `ISimConnectTest` interface with Name/Description/Category properties
62+
- Tests assume client is already connected and focus on specific functionality
63+
- No traditional test framework - custom test runner in `TestRunner.cs`
64+
- StyleCop disabled for test projects (`RunAnalyzersDuringBuild>false`)
65+
66+
### Build Commands
67+
68+
```bash
69+
dotnet restore && dotnet build --configuration Release
70+
dotnet pack src/SimConnect.NET/SimConnect.NET.csproj --output ./artifacts
71+
```
72+
73+
## SimVar Integration Patterns
74+
75+
### Registry vs Dynamic Definitions
76+
77+
- `SimVarRegistry.Get(name)` for predefined SimVars with type validation
78+
- Dynamic definitions created automatically for unregistered SimVars
79+
- Data definitions cached by `(Name, Unit)` tuple to avoid recreating
80+
81+
### Type Inference & Marshaling
82+
83+
- Automatic `SimConnectDataType` inference from .NET types (int→Integer32, double→FloatDouble)
84+
- Boolean conversion: SimConnect int values (0/1) ↔ .NET bool
85+
- String handling with ANSI marshaling and configurable buffer sizes
86+
87+
## Common Integration Points
88+
89+
### P/Invoke Conventions
90+
91+
- All SimConnect functions use ANSI string marshaling (`[MarshalAs(UnmanagedType.LPStr)]`)
92+
- Suppress CA2101 warning for ANSI marshaling requirement
93+
- IntPtr handle management with proper disposal patterns
94+
95+
### Concurrent Request Handling
96+
97+
- Request/Response correlation via unique IDs (`nextRequestId`, `nextDefinitionId`)
98+
- `ConcurrentDictionary<uint, object>` for pending request tracking
99+
- TaskCompletionSource pattern for async request completion
100+
101+
When implementing new features, follow the established manager pattern, maintain StyleCop compliance, and use concurrent async patterns for SimVar operations.

.github/dependabot.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
updates:
3+
# NuGet package updates
4+
- package-ecosystem: "nuget"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
commit-message:
9+
prefix: "chore(deps):"
10+
open-pull-requests-limit: 5
11+
enable-beta-ecosystems: true
12+
13+
# GitHub Actions workflow updates
14+
- package-ecosystem: "github-actions"
15+
directory: "/"
16+
schedule:
17+
interval: "weekly"
18+
commit-message:
19+
prefix: "chore(deps):"
20+
open-pull-requests-limit: 5

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup .NET SDK
17+
uses: actions/setup-dotnet@v4
18+
with:
19+
dotnet-version: "9.0.x"
20+
21+
- name: Restore dependencies
22+
run: dotnet restore
23+
24+
- name: Build
25+
run: dotnet build --no-restore --configuration Release
26+
27+
- name: Pack SimConnect.NET
28+
run: dotnet pack src/SimConnect.NET/SimConnect.NET.csproj \
29+
--no-build \
30+
--configuration Release \
31+
--output ./artifacts
32+
33+
- name: Upload package artifact
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: simconnectnet-packages
37+
path: ./artifacts/*.nupkg

.gitignore

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Build output directories
2+
bin/
3+
obj/
4+
out/
5+
6+
# User-specific files
7+
*.user
8+
*.userosscache
9+
*.suo
10+
*.sln.docstates
11+
12+
# IDE directories
13+
.vs/
14+
.vscode/
15+
.idea/
16+
17+
# Build results
18+
[Dd]ebug/
19+
[Dd]ebugPublic/
20+
[Rr]elease/
21+
[Rr]eleases/
22+
x64/
23+
x86/
24+
bld/
25+
[Bb]in/
26+
[Oo]bj/
27+
[Ll]og/
28+
29+
# NuGet packages and package cache
30+
*.nupkg
31+
*.snupkg
32+
.nuget/
33+
packages/
34+
project.lock.json
35+
project.fragment.lock.json
36+
artifacts/
37+
38+
# MSBuild Binary and Structured Log
39+
*.binlog
40+
41+
# Visual Studio cache/options
42+
.vs/
43+
.vscode/
44+
*.tmp_proj
45+
*_wpftmp.csproj
46+
*.log
47+
*.vspscc
48+
*.vssscc
49+
.builds
50+
*.pidb
51+
*.svclog
52+
*.scc
53+
54+
# Common binary file extensions
55+
*.dll
56+
*.exe
57+
*.pdb
58+
*.lib
59+
*.exp
60+
61+
# EXCEPT: Keep the bundled SimConnect.dll that's part of the project
62+
!src/SimConnect.NET/lib/SimConnect.dll
63+
64+
# Application files
65+
*.app
66+
*.ipa
67+
*.deb
68+
*.dmg
69+
*.rpm
70+
*.msi
71+
*.msm
72+
*.msp
73+
*.txz
74+
75+
# Temporary files
76+
*.tmp
77+
*.temp
78+
*.cache
79+
*.swp
80+
*.swo
81+
*~
82+
83+
# OS files
84+
.DS_Store
85+
.DS_Store?
86+
._*
87+
.Spotlight-V100
88+
.Trashes
89+
ehthumbs.db
90+
Thumbs.db

Directory.Build.props

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Version>0.0.1-alpha</Version>
4+
<Authors>AussieScorcher</Authors>
5+
<Company>AussieScorcher</Company>
6+
<Copyright>Copyright (c) AussieScorcher. All rights reserved.</Copyright>
7+
<RepositoryUrl>https://github.com/AussieScorcher/SimConnect.NET</RepositoryUrl>
8+
<LangVersion>latest</LangVersion>
9+
<Nullable>enable</Nullable>
10+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
11+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
12+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
13+
<PackageProjectUrl>https://github.com/AussieScorcher/SimConnect.NET</PackageProjectUrl>
14+
</PropertyGroup>
15+
<ItemGroup>
16+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="all" />
17+
</ItemGroup>
18+
</Project>

LICENCE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2025 AussieScorcher
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SimConnect.NET
2+
3+
🚧 **Work In Progress** 🚧
4+
5+
A simple async C# wrapper for Microsoft Flight Simulator's SimConnect SDK.
6+
7+
## What it does
8+
9+
- Connect to Microsoft Flight Simulator
10+
- Read aircraft data (position, speed, altitude, etc.)
11+
- Set aircraft parameters
12+
- Create AI objects
13+
14+
## Quick Start
15+
16+
```csharp
17+
var client = new SimConnectClient();
18+
await client.ConnectAsync();
19+
20+
// Get some aircraft data
21+
var altitude = await client.Aircraft.GetAltitudeAsync();
22+
var speed = await client.Aircraft.GetIndicatedAirspeedAsync();
23+
24+
await client.DisconnectAsync();
25+
```
26+
27+
## Status
28+
29+
- ✅ Basic connection and data reading
30+
- ✅ Aircraft position and motion data
31+
- ⏳ More SimVar support
32+
- ⏳ Event handling
33+
- ⏳ Better error handling
34+
- ⏳ Documentation
35+
36+
## Requirements
37+
38+
- .NET 8.0 or 9.0
39+
- Microsoft Flight Simulator (for testing)
40+
41+
## Build
42+
43+
```bash
44+
dotnet build
45+
```

SimConnect.NET.sln

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72D-47B6-A68D-7590B98EB39B}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimConnect.NET", "src\SimConnect.NET\SimConnect.NET.csproj", "{4252A45B-8C7E-487B-9670-53935D9CD06A}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimConnect.NET.Tests.Net8", "tests\SimConnect.NET.Tests.Net8\SimConnect.NET.Tests.Net8.csproj", "{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Debug|x64 = Debug|x64
18+
Debug|x86 = Debug|x86
19+
Release|Any CPU = Release|Any CPU
20+
Release|x64 = Release|x64
21+
Release|x86 = Release|x86
22+
EndGlobalSection
23+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
24+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Debug|x64.ActiveCfg = Debug|Any CPU
27+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Debug|x64.Build.0 = Debug|Any CPU
28+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Debug|x86.ActiveCfg = Debug|Any CPU
29+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Debug|x86.Build.0 = Debug|Any CPU
30+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Release|x64.ActiveCfg = Release|Any CPU
33+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Release|x64.Build.0 = Release|Any CPU
34+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Release|x86.ActiveCfg = Release|Any CPU
35+
{4252A45B-8C7E-487B-9670-53935D9CD06A}.Release|x86.Build.0 = Release|Any CPU
36+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
38+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Debug|x64.ActiveCfg = Debug|Any CPU
39+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Debug|x64.Build.0 = Debug|Any CPU
40+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Debug|x86.ActiveCfg = Debug|Any CPU
41+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Debug|x86.Build.0 = Debug|Any CPU
42+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Release|x64.ActiveCfg = Release|Any CPU
45+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Release|x64.Build.0 = Release|Any CPU
46+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Release|x86.ActiveCfg = Release|Any CPU
47+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB}.Release|x86.Build.0 = Release|Any CPU
48+
EndGlobalSection
49+
GlobalSection(SolutionProperties) = preSolution
50+
HideSolutionNode = FALSE
51+
EndGlobalSection
52+
GlobalSection(NestedProjects) = preSolution
53+
{4252A45B-8C7E-487B-9670-53935D9CD06A} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
54+
{38DFE777-B0F1-DC77-6E04-6DAEFC6F00DB} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
55+
EndGlobalSection
56+
GlobalSection(ExtensibilityGlobals) = postSolution
57+
SolutionGuid = {D38737E6-D81A-4DDE-9278-DE960E039FEB}
58+
EndGlobalSection
59+
EndGlobal

0 commit comments

Comments
 (0)