Battery monitor: "not available" values decode as NAN

Each battery monitor field has a reserved "not available" raw value:
voltage 0x7FFF, aux 0xFFFF, current 0x3FFFFF, consumed Ah 0xFFFFF and
SOC 0x3FF. The parser decoded them as readings, so an unsynchronised
shunt reported SOC 102.3 % and an unavailable current came out as
-0.001 A after sign extension. They are now NAN in the C core.
Time-to-go stays an integer, with 0xFFFF named VICTRONBLE_TTG_NA. The
Arduino wrapper maps the new NANs to 0, as it already did for aux.

Adds a host test vector with every field not available, and notes in
the README that a battery monitor has now been decoded live on Zephyr
(ESP32-S3, Heltec WiFi LoRa 32 V3).
This commit is contained in:
scottp committed 2026-11-11 13:13:57 +11:00
1 parent 318e221170
commit 560ea24f60
9 files changed
+108 -31

No files matched your search

+13
View File
@@ -72,6 +72,19 @@ int main(void)
CHECK(feq(rec.u.batmon.consumed_ah, -50.0f));
CHECK(feq(rec.u.batmon.soc, 85.5f));
/* --- battery monitor, every field not available --- */
CHECK(decode(VEC_BATMON_NA, sizeof(VEC_BATMON_NA), key, &rec) == VICTRONBLE_OK);
CHECK(rec.type == VICTRONBLE_DEV_BATTERY_MONITOR);
CHECK(rec.u.batmon.remaining_minutes == VICTRONBLE_TTG_NA);
CHECK(isnan(rec.u.batmon.voltage));
CHECK(rec.u.batmon.alarm == 0);
CHECK(rec.u.batmon.aux_mode == 0);
CHECK(isnan(rec.u.batmon.aux_voltage));
CHECK(isnan(rec.u.batmon.temperature));
CHECK(isnan(rec.u.batmon.current));
CHECK(isnan(rec.u.batmon.consumed_ah));
CHECK(isnan(rec.u.batmon.soc));
/* --- inverter --- */
CHECK(decode(VEC_INVERTER, sizeof(VEC_INVERTER), key, &rec) == VICTRONBLE_OK);
CHECK(rec.type == VICTRONBLE_DEV_INVERTER);