Conversation
* Add Version * Fix /FB * Fix /CG
WalkthroughRefactors H1 POS decoding: adds message version handling, changes fuel field from Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
VRfield handler andversion()formatter method - Fixed
/FBfield to correctly parse as current fuel instead of burned fuel - Fixed
/CGfield 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.
There was a problem hiding this comment.
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
centercase uses 2-space indentation whileloweranduppercases 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; } }
Summary by CodeRabbit
New Features
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.