Skip to content

Add A339X trim-tank support, STEP imports and FMGC fixes - #153

Open
nbobby07 wants to merge 22 commits into
headwindsim:mainfrom
nbobby07:feat/a339x-fuel-trim
Open

nbobby07 wants to merge 22 commits into
headwindsim:mainfrom
nbobby07:feat/a339x-fuel-trim

Conversation

@nbobby07

@nbobby07 nbobby07 commented Sep 12, 2026 •

Copy link
Copy Markdown

Summary of Changes

Adds six-tank fuel support to the A339X and fixes several problems found while testing refueling, SimBrief imports and FMGC predictions. The trim controller is opt-in while its aircraft-specific behavior is being validated.

Fuel system and trim tank

  • Add the native trim tank at index 6. Allocate its 1,646 US gal from the center tank so total capacity stays at 36,743 US gal.
  • Carry all six tanks through FADEC, Rust mass and moment calculations, tablet refueling and the SD fuel page. Use the simulator's fuel density and preserve the last valid reading when it becomes unavailable.
  • Keep native tank quantities authoritative. Bound engine consumption by available fuel and observe native APU consumption and transfers without subtracting them twice.
  • Add a developer-controlled center/trim transfer path with explicit direction, target and rate. Check donor quantity, receiving capacity, electrical power, pump and valve faults, and ground/refueling inhibits. It starts disabled with a zero flow rate.
  • Preserve the fuel supplied by the simulator at initialization. Add explicit six-tank save/restore, accept valid five-tank saves with an empty trim tank, reject over-capacity data, and preserve the previous save if writing fails.
  • Support REAL, FAST and INSTANT filling and defueling across six tanks, with shared flow limits and batch ordering. Cancel an active request when conditions become ineligible so FADEC can resume fuel consumption.
  • Add bounded fuel diagnostics and transition logging. Remove the unused SimConnect fuel-write definition and rename fuel-state initialization to describe what it actually does.

SimBrief, STEP ALTS and takeoff data

  • Import explicit SimBrief cruise steps after route expansion, matching named and coordinate fixes against the completed route. Keep the initial cruise level separate from later steps.
  • Validate the STEP ALTS sequence and fix same-waypoint edits and step removal. Retain the existing FCU selection and STEP AHEAD flow; planned steps do not command an automatic climb.
  • Add an A339 Performance > Takeoff page for generated SimBrief OFP Runway Analysis results. Show the selected runway's speeds, FLEX, configuration, conditions and original report text.
  • Check aircraft and flight context, runway, result ordering, weight limits and units. Report missing results, overweight cases and network errors clearly. Discard stale responses after flight changes and allow retries after a timeout.
  • Use simulator-compatible browser APIs for the import flow. Imported results remain tied to their original conditions and are entered into the MCDU manually.
  • Fix unit-setting persistence and broadcasts so cached MCDU weight units refresh when the setting changes.
  • Interpolate the inherited speed tables instead of rounding weight up to the next 10-tonne row. Fix control-speed endpoints and scalar interpolation, preserve unrounded minimum-speed margins, and show a data check when required inputs are unavailable. At 230.2 t in CONF 1, the regression case accepts V2 161 kt and rejects 160 kt.

VNAV and compatibility

  • Reject non-finite, stalled, incomplete and infeasible predictions before they become a flight profile. Preserve valid reverse-descent calculations and allow computation to recover when inputs are corrected.
  • Correct cruise-step transitions, descent joins, acceleration clipping and the Mach argument passed to the climb model. Rebuild descent after an ignored step changes the final cruise altitude.
  • Clear stale profiles, speed predictions, guidance targets, margins and T/D flags after failed computation. Clear an old expedite profile when green-dot speed is unavailable.
  • Use signed, phase-specific wind for leg ground-speed predictions. Keep actual computed altitudes or unavailable indications in the flight plan; do not replace them with a forced cruise-level display before departure.
  • Resolve pinned-SDK compatibility issues in the MCDU, ATC departure request, navigation display and shared exports. Use mathjs types with checked result narrowing; 22 reference fuel-prediction results remain unchanged. Remove the redundant drag-factor multiplier of 1.

Build and installation tools

  • Add a Windows build wrapper using the existing pinned image, lockfile and submodules. Record the source revision and fingerprint, run regression checks, and verify the output package hashes. Baseline builds must match the selected baseline revision and unchanged aircraft source.
  • Clean the affected Cargo packages after copying overrides so preserved timestamps cannot reuse binaries from different source.
  • Add scoped installation, backup and restore commands for the aircraft and lock-highlight companion. Verify paths, package identity, dependencies and hashes, require MSFS to be closed, and recover recorded partial installations without replacing unknown or modified files.
  • Keep companion versions consistent. Preserve external dependency declarations and report cross-generation version mismatches separately from missing dependencies.
  • Add a guarded Docker startup helper for the Windows stale-socket failure. Healthy engines are left running; recovery requires Desktop to be fully stopped and preserves the affected runtime directories.
  • Consolidate the architecture, references, validation results and remaining simulator checks in the development documentation.

References

Additional context

This PR targets Headwind main. The large diff includes complete aircraft-specific overrides required by Headwind's copy-based build; the pinned submodules and model assets are unchanged.

The trim position and actuator model still need calibration. This does not implement an automatic Airbus CG schedule, and FCOM conformity has not been established. The tablet imports SimBrief results; a native calculator that recomputes performance for changed weight, weather and configuration is still outstanding. The inherited performance tables also need aircraft-specific validation.

The ordinary Docker Desktop launcher can still hit its upstream startup bug. The project helper handles the checked recovery case without a factory reset.

Testing instructions

Run from the repository root with PowerShell 7.2+, Docker and the pinned submodules initialized:

./scripts/fuel-trim/Build-A339X.ps1
# Reuse dependencies after the first setup:
./scripts/fuel-trim/Build-A339X.ps1 -SkipSetup

The build runs the C++ fuel and persistence checks, JavaScript regressions, focused Rust fuel tests, and Windows deployment and baseline-preflight checks before packaging.

Validation at 2ff3d882:

  • Full instrument and WASM build passed. Package validation checked 855 aircraft files and three companion files.
  • All 67 JavaScript checks and seven focused Rust fuel tests passed. C++ model/persistence checks passed, including 50,000 fixed-seed fuel updates. Deployment, rollback, partial-install recovery and baseline-preflight checks passed.
  • MCDU typechecking passed with no diagnostics. The A339 EFB configuration retains three existing shared A320/SU95 errors; the standalone common EFB configuration reports five. Changed TypeScript files passed lint, and the four checked legacy files introduced no new lint diagnostics.
  • The earlier full Rust library comparison recorded 448 passing / 17 failing / 9 ignored at baseline and 454 passing / 15 failing / 9 ignored after the fuel changes. No new failing test names were introduced. Remaining failures concern air conditioning, payload assumptions and flap tests; the full Rust suite is not green.
  • The new behavior has not yet been validated in the simulator. The VNAV numerical sweep and mocked instrument tests do not establish aircraft performance accuracy.

For simulator testing:

  1. Compare native quantities, total fuel, gross weight and displays for all six tanks at cold-and-dark, running and saved-flight starts. Check each refueling mode, asymmetric loads and interrupted requests.
  2. Check engine burn and APU consumption separately. Exercise the opt-in trim path, its quantity limits and electrical/pump/valve failures, then disable it. Compare native CG movement with the diagnostics.
  3. Generate an OFP with Detailed Navlog, Plan Stepclimbs and Runway Analysis. Import the flight, compare STEP ALTS with the OFP, edit/remove steps, and initiate a planned climb through the FCU.
  4. Import the takeoff report and compare its runway, conditions, weight, configuration and results with SimBrief. Verify missing data, timeout/retry and flight-change handling.
  5. Recheck KSEA 16L at 230.2 t, CONF 1, V1/VR/V2 148/155/161 kt, FLEX 45 C, OAT 19 C, QNH 29.97 inHg, wind 300/04 and dry runway. Match the aircraft loading and configuration to the report before checking the MCDU warning behavior.
  6. Exercise climb, cruise, step and descent predictions with valid and missing inputs. Failed computation must clear stale guidance and recover after corrected inputs.

The validation guide includes the detailed scenarios, tolerances and known baseline failures.

How to download the PR for Testing

Automated package builds may require approval from a Headwind maintainer before they run. Until a successful CI artifact is available, build the branch locally using the commands above. A successful local build prints a validated artifact path under .fuel-trim-local/artifacts.

With MSFS closed and a verified .fuel-trim-local/deployment.json, install that specific artifact:

./scripts/fuel-trim/Deploy-A339X.ps1 -ArtifactPath '<validated artifact path>' -WhatIf
./scripts/fuel-trim/Deploy-A339X.ps1 -ArtifactPath '<validated artifact path>'

The installer preserves the previous aircraft and prints the deployment record needed for restore. No aircraft binaries are attached to this PR.

Keep native tank quantities authoritative and split trim capacity from center without increasing total fuel. Add bounded consumption, physical transfer faults, native mass and CG reads, and deterministic tests.

Legacy INI restoration is explicit on the ground. Reject malformed or over-capacity saves without redistributing fuel; preserve prior files on failed writes. Automatic CG scheduling remains unsupported.
Include all six native tanks in EFB allocation, refueling and SD indications. Mark external fuel batches so FADEC waits for native readback, and inhibit EFB refueling airborne.
Require verified local dependencies, but report cross-generation version differences without inventing runtime minimum semantics. Preserve manifest declarations and exact bundled package consistency.
Use the Headwind datastore event for typed changes as well as legacy changes. Reproduce stale MCDU weight units with two instrument contexts and verify bidirectional updates and persisted reload.
Expose runway-specific A339 OFP results without enabling the unfinished A320-derived model. Validate flight context and preserve original units. Document the missing standalone calculation API and native calculator gap.
Interpolate takeoff stall-speed checks at the entered weight.
Reject impossible VNAV results, clear stale guidance, repair interpolation and SDK compatibility, and remove the unsupported preflight altitude display override.
Cancel ineligible refueling, reject partial VNAV profiles, and report unusable takeoff results accurately. Validate baseline source and recover only recorded partial installs. Remove dead definitions and consolidate validation notes.
@nbobby07
nbobby07 marked this pull request as ready for review September 12, 2026 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant