Repository navigation
fix(ferroamp_modbus): leave out a NaN or infinite float (2.2.2) - #274
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
decode_f32_ws_at turned a NaN or infinite reply, the EnergyHub's "not present", into 0, so a NaN grid power went out as a 0 W meter and a NaN SoC as an empty pack. It now returns nil, as it does for a reply missing a word, and every caller goes through f32_at, which also drops a value that becomes infinite after scaling. Harness tests for NaN and infinity on the meter, PV and battery fail on main. Not checked on hardware. Refs #258 Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Follow-up to #270, found in its review.
What was wrong
ferroamp_modbusdecodes the EnergyHub's word-swapped float32 values withdecode_f32_ws_at. It returned 0 for NaN and infinity, which the EnergyHubuses for "not present", and also for a reply missing a word. So a NaN grid
power went out as a 0 W meter, a site in balance, and a NaN SoC as an empty
pack. docs/WRITING-A-DRIVER.md, "Never fabricate": a zero means the device
said zero.
Change (ferroamp_modbus 2.2.2)
decode_f32_bereturns nil for NaN and infinity, anddecode_f32_ws_atreturns nil when a word is missing. A real 0.0 is still 0.
f32_at(regs, idx, scale). It returnsnil for a missing or non-finite value and checks again after scaling.
Per "Numbers", float32's largest value times 1000 is infinite where Lua
numbers are 32-bit floats.
power and PV only with its solar power. Each per-phase watt figure needs
that phase's voltage and current. The battery sends whatever answered.
They used to decode the gap as 0.
Tests
drivers/tests/test_ferroamp_modbus_nan.py, 7 harness scenarios:the other phases.
Six fail on
main. "Real zero kept" passes there and checks behaviour thatmust not change.
make test-driver ID=ferroamp_modbus: 72 passed, 4 skipped.make invented-number-report ID=ferroamp_modbus: nothing invented.make absent-register-report ID=ferroamp_modbus: every register settles.make checkonmain9ad7090: 5278 passed, 928 skipped.Not verified on hardware
Not run against a real EnergyHub. Ferroamp's Modbus map does not say which
registers answer NaN or infinity, or when. This change treats both as "not
present" wherever they come.
Refs #258
🤖 Generated with Claude Code