Skip to content

Conversation

@AussieScorcher
Copy link
Member

Summary

  • add a fully-managed facility manager with builders, annotations, and subscription helpers tied into the core client
  • expose facility definitions/results/subscriptions plus the facility SimConnect API wrapper and ICAO marshaling helpers
  • add an xUnit test project that exercises definition creation, minimal list requests, facility data collection, and subscription dispatching

Testing

  • dotnet test tests/SimConnect.NET.UnitTests/SimConnect.NET.UnitTests.csproj -p:TargetFrameworks=net8.0 -p:TargetFramework=net8.0

Codex Task

Copilot AI review requested due to automatic review settings November 16, 2025 07:20
Comment on lines +38 to +44
foreach (var result in this.Results)
{
if (result.DataType == dataType)
{
return result;
}
}
/// <param name="fieldName">The field path to add.</param>
/// <returns>The raw SimConnect result.</returns>
public int AddToFacilityDefinition(IntPtr handle, uint definitionId, string fieldName)
=> SimConnectNative.SimConnect_AddToFacilityDefinition(handle, definitionId, fieldName);
/// <param name="region">Optional region code.</param>
/// <returns>The raw SimConnect result.</returns>
public int RequestFacilityData(IntPtr handle, uint definitionId, uint requestId, string icao, string region)
=> SimConnectNative.SimConnect_RequestFacilityData(handle, definitionId, requestId, icao, region ?? string.Empty);
/// <param name="requestId">Client request identifier.</param>
/// <returns>The raw SimConnect result.</returns>
public int RequestFacilitiesList(IntPtr handle, uint type, uint requestId)
=> SimConnectNative.SimConnect_RequestFacilitiesList(handle, type, requestId);
/// <param name="requestId">Client request identifier.</param>
/// <returns>The raw SimConnect result.</returns>
public int RequestFacilitiesListEx1(IntPtr handle, uint type, uint requestId)
=> SimConnectNative.SimConnect_RequestFacilitiesList_EX1(handle, type, requestId);
/// <param name="oldOutRangeRequestId">Request ID for entries leaving range.</param>
/// <returns>The raw SimConnect result.</returns>
public int SubscribeToFacilitiesEx1(IntPtr handle, uint type, uint newInRangeRequestId, uint oldOutRangeRequestId)
=> SimConnectNative.SimConnect_SubscribeToFacilities_EX1(handle, type, newInRangeRequestId, oldOutRangeRequestId);
/// <param name="unsubscribeOldOutRange">Whether to unsubscribe from out-of-range events.</param>
/// <returns>The raw SimConnect result.</returns>
public int UnsubscribeFromFacilitiesEx1(IntPtr handle, uint type, bool unsubscribeNewInRange, bool unsubscribeOldOutRange)
=> SimConnectNative.SimConnect_UnsubscribeToFacilities_EX1(handle, type, unsubscribeNewInRange, unsubscribeOldOutRange);
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive facility management API for SimConnect.NET, enabling developers to query and subscribe to flight simulator facility data (airports, waypoints, VORs, NDBs) using high-level abstractions with async/await patterns.

  • Adds a FacilityManager class with support for custom definitions via builders or attribute annotations
  • Implements minimal facility list requests and detailed facility data retrieval with proper message correlation
  • Provides a subscription mechanism for tracking facilities entering/exiting the user's reality bubble
  • Includes a new xUnit-based test project that verifies core functionality through unit tests with faked API implementations

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
tests/SimConnect.NET.UnitTests/SimConnect.NET.UnitTests.csproj New xUnit test project configuration targeting .NET 8.0
tests/SimConnect.NET.UnitTests/FacilityManagerTests.cs Comprehensive unit tests for facility definitions, requests, and subscriptions
src/SimConnect.NET/Structs/SimConnectIcao.cs Refactored to use byte arrays with encoding helpers for proper ANSI marshaling
src/SimConnect.NET/SimConnectClient.cs Integrated FacilityManager lifecycle and message routing
src/SimConnect.NET/Properties/AssemblyInfo.cs Added InternalsVisibleTo for test assembly access
src/SimConnect.NET/Internal/ISimConnectFacilityApi.cs Abstraction layer for facility P/Invoke calls with testable interface
src/SimConnect.NET/Facilities/FacilitySubscription.cs Disposable subscription handle for in-range facility notifications
src/SimConnect.NET/Facilities/FacilityManager.cs Core manager implementing definition creation, requests, and subscriptions
src/SimConnect.NET/Facilities/FacilityFieldAttribute.cs Attribute for annotating struct fields with facility field paths
src/SimConnect.NET/Facilities/FacilityDefinitionBuilder.cs Fluent builder for creating facility definitions
src/SimConnect.NET/Facilities/FacilityDefinition.cs Immutable definition wrapper with field list and definition ID
src/SimConnect.NET/Facilities/FacilityDataResult.cs Result structure containing raw payload with marshaling helper
src/SimConnect.NET/Facilities/FacilityDataResponse.cs Response container with helper to find specific data types
SimConnect.NET.sln Added new test project to solution configuration

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 426 to 452
private sealed class FacilityMinimalListRequest
{
private readonly TaskCompletionSource<IReadOnlyList<SimConnectFacilityMinimal>> tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
private readonly List<SimConnectFacilityMinimal> buffer = new();
private uint expectedPackets;
private uint receivedPackets;

internal FacilityMinimalListRequest(uint requestId)
{
}

internal Task<IReadOnlyList<SimConnectFacilityMinimal>> Task => this.tcs.Task;

internal bool IsComplete => this.expectedPackets != 0 && this.receivedPackets >= this.expectedPackets;

internal void AddChunk(IReadOnlyList<SimConnectFacilityMinimal> chunk, uint entryNumber, uint outOf)
{
if (chunk.Count > 0)
{
this.buffer.AddRange(chunk);
}

this.receivedPackets++;
this.expectedPackets = outOf == 0 ? 1u : outOf;

if (this.IsComplete)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Minimal list requests never complete for multi-packet responses

The completion logic for minimal facility lists interprets OutOf as the number of packets rather than the total number of facilities. In the SimConnect SIMCONNECT_RECV_FACILITY_MINIMAL_LIST payload, OutOf represents the total facility count and EntryNumber indicates the index of the first facility in this chunk. Here AddChunk only increments receivedPackets by 1 per message and sets expectedPackets = outOf, so a request that returns hundreds of facilities over a handful of packets will wait for outOf packets and the Task never completes. You should track completion based on entryNumber + chunk.Count >= outOf or by counting facilities, not packets.

Useful? React with 👍 / 👎.

@stopbars stopbars deleted a comment from Copilot AI Nov 16, 2025
@AussieScorcher AussieScorcher deleted the codex/add-facility-manager-support-to-simconnect.net branch December 29, 2025 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants