Repository navigation
fix: generate the subfield-gated components on event.data - #92
Merged
Merged
Conversation
The Profile declares three component sets that apply only under an event subfield: gear change (rear_gear_num, rear_gear, front_gear_num, front_gear), Varia radar threat (level, count, average and maximum approach speed) and sport point (score, opponent_score). The generator dropped all three: gen/profile.py had the components, bits and accumulate columns commented out and never attached FieldComponent entries to the SubField objects it built, and the message template emitted SubField without components=. The runtime already prefers components on the active subfield, so with nothing attached event.data decoded as one packed uint32 and the gear and radar fields stayed empty. Parse the subfield Components rows and emit them from the template. Destination ids are resolved from a pre-pass over the Messages sheet because a destination field (front_gear) is declared after the data row that packs it. Regenerated output adds the components to event_message.py and leaves the main-field component registry unchanged, since its key is the packing field and cannot express a gate. Coverage is constructive: no committed fixture carries event 33/42/43/75, so the tests build messages and wire bytes for front and rear gear change, radar threat (approach speeds at scale 1/10), sport point and an inactive event gate. Tests: new expansion cases fail against the pre-change generated file; a decoded gear-change record still re-encodes byte-for-byte, all 23 committed .fit fixtures round-trip identically, and the full suite, ruff and mypy pass. Amp-Thread-ID: https://ampcode.com/threads/T-01a1f7e0-479c-740e-8086-4ee691ef3352
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #92 +/- ##
==========================================
+ Coverage 93.35% 93.43% +0.07%
==========================================
Files 46 46
Lines 2771 2771
Branches 440 440
==========================================
+ Hits 2587 2589 +2
+ Misses 105 104 -1
+ Partials 79 78 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
The bundled Profile (21.222.0) declares three component sets that apply only under an
eventsubfield value, all packing intoevent.data:gear_change_data(event= 42/43)rear_gear_num,rear_gear,front_gear_num,front_gear(8 bits each)radar_threat_alert(event= 75)radar_threat_level_max,radar_threat_count,radar_threat_avg_approach_speed,radar_threat_max_approach_speed(8 bits; speeds at scale 1/10)sport_point(event= 33)score,opponent_score(16 bits each)The generator emitted none of them, in two places:
fit_tool/gen/profile.pyhad thecomponents/bits/accumulatecolumns commented out, so noFieldComponentwas ever attached to theSubFieldobjects it built.fit_tool/gen/templates/template_message.jinjaemittedSubField(...)without acomponents=argument.fit_tool/gen/component_registry.pyonly ever produced main-field sources, and that is correct for it: its key is the packing field, which cannot express a gate. The runtime was never the problem —components_for_field()already prefers components on the active subfield. With nothing attached it expanded nothing, so a Di2/eTap gear-change or Varia radar-threat event decodedevent.dataas a single packeduint32and the gear and radar fields read as empty.What changed
gen/profile.pyparses the subfieldComponentsrows (per-component scale, offset, bit width, accumulate) and attaches them to theSubField. Destination ids come from a pre-pass over the Messages sheet because a destination field (front_gear) is declared after thedatarow that packs it.gen/gen_profile.pysets a per-messagehas_subfield_componentsflag; the template emits the component list and importsFieldComponentonly in messages that need it.uv run gen-profile. Generated output diff is exactly two files:profile/messages/event_message.pygains the three component sets above (no other message module changes), andprofile/component_registry.pychanges only its header comment. A second generation run is byte-identical.Coverage is constructed, not real-device
No committed fixture carries event 33/42/43/75 — the fixtures'
eventvalues are 0, 1, 3, 4, 9 and 41. Every gear-change, radar-threat and sport-point case here is a constructed message or constructed wire bytes, so a reviewer should not read this as real-device coverage. A Di2/eTap or Varia file would be a valuable fixture to add later.Tests and results
uv run pytest: 493 passed, 1 skipped (the skip is the live Garmin JS interop test, unchanged).uv run ruff check fit_tool: clean.uv run mypy: clean..fitfixtures still decode and re-encode byte-identically.test_components.TestProfileSubfieldGatedComponents: front and rear gear change, radar threat (raw 100/250 → 10.0/25.0 m/s, proving the per-component scale), sport point 16+16, an inactiveeventgate that must not expand, and a wire decode of a constructed gear-change record that asserts expansion plus a byte-identical re-encode. Five of these fail against the pre-change generated file.test_profile.TestProfileSubfieldComponents: the generator attaches the three sets with the Profile's destination ids, bit widths and scales.Caller-visible notes
event.datakeeps its packed value; the gear/radar/score fields are added alongside and marked as expanded.datavalue; there is no pack-on-encode path.News fragment:
news/+subfield-gated-components.bugfix.