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 -7
View File
@@ -87,14 +87,20 @@ typedef struct {
float load_current; /* A, NAN if no load output */
} victronble_solar_charger_t;
/** Battery monitor time-to-go value meaning "not available". */
#define VICTRONBLE_TTG_NA 0xFFFFu
typedef struct {
float voltage; /* V */
float current; /* A */
float temperature; /* degC, NAN unless aux mode = temperature */
float aux_voltage; /* V, NAN unless aux mode = aux voltage */
uint16_t remaining_minutes; /* time-to-go; 0xFFFF = not available */
float consumed_ah; /* Ah, negative = consumed */
float soc; /* % */
float voltage; /* V, NAN if not available */
float current; /* A, NAN if not available */
float temperature; /* degC, NAN unless aux mode = temperature
* and a reading is available */
float aux_voltage; /* V, NAN unless aux mode = aux voltage
* and a reading is available */
uint16_t remaining_minutes; /* time-to-go; VICTRONBLE_TTG_NA = not
* available (e.g. idle or not synced) */
float consumed_ah; /* Ah, negative = consumed; NAN if n/a */
float soc; /* %, NAN if not available (not synced) */
uint8_t aux_mode; /* 0=aux V, 1=midpoint, 2=temperature, 3=none */
uint16_t alarm; /* raw 16-bit alarm bitmask */
} victronble_battery_monitor_t;