Skip to content

fix(ferroamp_modbus): leave out a NaN or infinite float (2.2.2) - #274

Merged
frahlg merged 1 commit into
mainfrom
ferroamp-nan
Nov 22, 2026
Merged

frahlg merged 1 commit into
mainfrom
ferroamp-nan

Conversation

@frahlg

@frahlg frahlg commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #270, found in its review.

What was wrong

ferroamp_modbus decodes the EnergyHub's word-swapped float32 values with
decode_f32_ws_at. It returned 0 for NaN and infinity, which the EnergyHub
uses 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_be returns nil for NaN and infinity, and decode_f32_ws_at
    returns nil when a word is missing. A real 0.0 is still 0.
  • Every caller goes through a new f32_at(regs, idx, scale). It returns
    nil 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.
  • The rules from fix(victron, ferroamp_modbus): no meter or PV zeros from failed reads (2.2.1) #270 still hold. The meter goes out only with its grid
    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.
  • The battery reads now also leave out a reply that is missing a word.
    They used to decode the gap as 0.

Tests

drivers/tests/test_ferroamp_modbus_nan.py, 7 harness scenarios:

  • NaN grid power sends no meter reading.
  • Infinite PV power sends no PV reading.
  • NaN on one phase leaves out that phase's voltage and watts, and keeps
    the other phases.
  • NaN frequency and a -infinity export counter are left out.
  • NaN battery power and SoC are left out, and the energy counters stay.
  • Float32's largest value times 1000 is dropped.
  • A real 0.0 is kept.

Six fail on main. "Real zero kept" passes there and checks behaviour that
must 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 check on main 9ad7090: 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T12:56:59.459696Z 20d7285 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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>
@frahlg
frahlg merged commit 94c5e0e into main Nov 22, 2026
5 checks passed
@frahlg
frahlg deleted the ferroamp-nan branch November 22, 2026 12:59
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