Skip to content

Fix H1 parsing#310

Merged
makrsmark merged 2 commits intoairframesio:masterfrom
makrsmark:bugfix/h1-fuel
Jan 31, 2026
Merged

Fix H1 parsing#310
makrsmark merged 2 commits intoairframesio:masterfrom
makrsmark:bugfix/h1-fuel

Conversation

@makrsmark
Copy link
Collaborator

@makrsmark makrsmark commented Jan 30, 2026

  • Add Version
  • Fix /FB
  • Fix /CG

Summary by CodeRabbit

  • New Features

    • Added message version display.
    • Enhanced center-of-gravity reporting with center, lower and upper values.
  • Bug Fixes

    • Corrected fuel field used in parsing.
    • Removed erroneous route tail from formatted output.
  • Tests

    • Updated test expectations to match revised fields and adjusted formatting.

✏️ Tip: You can customize this high-level summary in your review settings.

* Add Version
* Fix /FB
* Fix /CG
@makrsmark makrsmark requested a review from Copilot January 30, 2026 21:20
@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

Walkthrough

Refactors H1 POS decoding: adds message version handling, changes fuel field from fuel_burned to fuel_on_board, and replaces mac/trim CG handling with position-specific cg formatting (center, lower, upper). Tests updated to reflect these renamed/raw fields and adjusted formatted/remaining expectations.

Changes

Cohort / File(s) Summary
Tests
lib/plugins/Label_1J_2J_FTX.test.ts, lib/plugins/Label_2P_POS.test.ts, lib/plugins/Label_H1_POS.test.ts
Updated assertions to use raw.fuel_on_board, added raw.version (3.2) checks, adjusted formatted.items counts and remaining.text expectations to remove route/version fragments.
H1 Helper
lib/utils/h1_helper.ts
Switched FB handling from burnedFuel to currentFuel, added VR handling (divide value by 10 before version formatting), and refactored processCenterOfGravity to call ResultFormatter.cg for center/lower/upper with presence guards.
Result Formatter
lib/utils/result_formatter.ts
Added static cg(decodeResult, value, type) to set center_of_gravity/cg_lower_limit/cg_upper_limit and append formatted items; added static version(decodeResult, value) to store raw.version and append a "Message Version" formatted item.

Sequence Diagram

sequenceDiagram
    participant Decoder as H1 Decoder
    participant Helper as h1_helper
    participant Formatter as ResultFormatter
    participant Raw as DecodeResult.raw
    participant Formatted as DecodeResult.formatted

    Decoder->>Helper: processCenterOfGravity(data)
    alt single element
        Helper->>Formatter: cg(decodeResult, data[0], "center")
    else three elements
        Helper->>Formatter: cg(decodeResult, data[0], "center")
        Helper->>Formatter: cg(decodeResult, data[1], "lower")
        Helper->>Formatter: cg(decodeResult, data[2], "upper")
    end
    Formatter->>Raw: set center_of_gravity / cg_lower_limit / cg_upper_limit
    Formatter->>Formatted: push formatted CG items

    Decoder->>Helper: handle FB field
    Helper->>Formatter: currentFuel(decodeResult, value)
    Formatter->>Raw: set fuel_on_board
    Formatter->>Formatted: push fuel formatted item

    Decoder->>Helper: handle VR field
    Helper->>Formatter: version(decodeResult, value / 10)
    Formatter->>Raw: set version
    Formatter->>Formatted: push "Message Version" item
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • kevinelliott
  • fredclausen

"I hopped through code with nimble paws,
CG split neat into center and claws.
Fuel on board and version in tow,
Tests updated — the pipelines go! 🐇✨"

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix H1 parsing' directly relates to the main changes—adding Version field and fixing /FB and /CG parsing in H1 messages.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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 fixes H1 message parsing by correcting field interpretations and adding version support. The changes address incorrect mapping of fuel and center of gravity fields, and introduce proper handling for message version information.

Changes:

  • Added version parsing support with new VR field handler and version() formatter method
  • Fixed /FB field to correctly parse as current fuel instead of burned fuel
  • Fixed /CG field to support center of gravity with optional lower/upper limits instead of MAC/trim

Reviewed changes

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

Show a summary per file
File Description
lib/utils/result_formatter.ts Added cg() method for center of gravity parsing with three type variations and version() method for message version
lib/utils/h1_helper.ts Corrected FB field to use currentFuel(), added VR field handler for version, and updated CG processing to use new cg() method with limit support
lib/plugins/Label_H1_POS.test.ts Updated test expectations to reflect corrected field names and added version field verification
lib/plugins/Label_2P_POS.test.ts Updated test expectations for fuel field name change and version field addition
lib/plugins/Label_1J_2J_FTX.test.ts Updated test expectations for fuel field name change and version field addition

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@lib/utils/h1_helper.ts`:
- Around line 248-250: The guard currently checks the array `data` instead of
its first element, causing the single-element branch to run even when the
element is empty; update the condition before calling
ResultFormatter.cg(decodeResult, parseInt(data[0], 10) / 10) to verify the first
element is present/non-empty (e.g., check `data[0]` or `data.length && data[0]
!== ''`) so you only parse when the element contains a value.
🧹 Nitpick comments (1)
lib/utils/result_formatter.ts (1)

462-492: Inconsistent indentation in switch cases.

The center case uses 2-space indentation while lower and upper cases use 4-space indentation. This should be consistent throughout.

🔧 Proposed fix for consistent indentation
   static cg(decodeResult: DecodeResult, value: number, type: "center" | "lower" | "upper" = "center") {
     switch(type) {
       case "center":
         decodeResult.raw.center_of_gravity = value;
         decodeResult.formatted.items.push({
           type: "center_of_gravity",
           code: "CG",
           label: "Center of Gravity",
           value: `${decodeResult.raw.center_of_gravity} %`,
         });
         break;
-        case "lower":
-            decodeResult.raw.cg_lower_limit = value;
-            decodeResult.formatted.items.push({
-              type: "cg_lower_limit",
-              code: "CG_LOWER",
-              label: "Center of Gravity Lower Limit",
-              value: `${decodeResult.raw.cg_lower_limit} %`,
-            });
-            break;
-        case "upper":
-            decodeResult.raw.cg_upper_limit = value;
-            decodeResult.formatted.items.push({
-              type: "cg_upper_limit",
-              code: "CG_UPPER",
-              label: "Center of Gravity Upper Limit",
-              value: `${decodeResult.raw.cg_upper_limit} %`,
-            });
-            break;
+      case "lower":
+        decodeResult.raw.cg_lower_limit = value;
+        decodeResult.formatted.items.push({
+          type: "cg_lower_limit",
+          code: "CG_LOWER",
+          label: "Center of Gravity Lower Limit",
+          value: `${decodeResult.raw.cg_lower_limit} %`,
+        });
+        break;
+      case "upper":
+        decodeResult.raw.cg_upper_limit = value;
+        decodeResult.formatted.items.push({
+          type: "cg_upper_limit",
+          code: "CG_UPPER",
+          label: "Center of Gravity Upper Limit",
+          value: `${decodeResult.raw.cg_upper_limit} %`,
+        });
+        break;
     }
   }

@makrsmark makrsmark merged commit f752714 into airframesio:master Jan 31, 2026
6 checks passed
@makrsmark makrsmark deleted the bugfix/h1-fuel branch January 31, 2026 00:42
@coderabbitai coderabbitai bot mentioned this pull request Feb 9, 2026
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