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

+14
View File
@@ -76,6 +76,19 @@ batmon = pad21(pack_bits([
(855, 10), # SOC, 0.1 %
]))
# Battery monitor before it has synchronised, with nothing on aux: every
# field carries Victron's "not available" value.
batmon_na = pad21(pack_bits([
(0xFFFF, 16), # TTG n/a
(0x7FFF, 16), # voltage n/a
(0x0000, 16), # no alarms
(0xFFFF, 16), # aux n/a
(0, 2), # aux mode = aux voltage
(0x3FFFFF, 22), # current n/a
(0xFFFFF, 20), # consumed n/a
(0x3FF, 10), # SOC n/a
]))
# Inverter: inverting, 25.86 V, -12.34 A, -230 W, overload alarm.
inverter = pad21(bytes([9, 0]) + le16(2586) + le16(-1234 & 0xFFFF) +
((-230) & 0xFFFFFF).to_bytes(3, "little") + bytes([0x08]))
@@ -97,6 +110,7 @@ accharger = pad21(pack_bits([
VECTORS = [
("solar", frame(0x01, 0xA060, 0x00, 0x1234, solar)),
("batmon", frame(0x02, 0xA389, 0x00, 0xBEEF, batmon)),
("batmon_na", frame(0x02, 0xA389, 0x00, 0xBEF0, batmon_na)),
("inverter", frame(0x03, 0xA2FA, 0x00, 0x0001, inverter)),
("dcdc", frame(0x04, 0xA3C0, 0x00, 0xFFFF, dcdc)),
("accharger", frame(0x08, 0xA339, 0x00, 0x00C8, accharger)),
+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);
+1
View File
@@ -6,6 +6,7 @@ static const char VEC_KEY_HEX[] = "0df4d0395b7d5d4f5a0d0af52e1b4c1e";
static const uint8_t VEC_SOLAR[] = { 0xe1, 0x02, 0x10, 0x60, 0xa0, 0x00, 0x01, 0x34, 0x12, 0x0d, 0x53, 0xb0, 0x25, 0x4c, 0x65, 0xd3, 0x4a, 0x92, 0x34, 0x70, 0x3a, 0x6c, 0x19, 0x73, 0x7e, 0x65, 0xf6, 0xa4, 0x42, 0xd0, 0x56 };
static const uint8_t VEC_BATMON[] = { 0xe1, 0x02, 0x10, 0x89, 0xa3, 0x00, 0x02, 0xef, 0xbe, 0x0d, 0x41, 0x08, 0x53, 0x2f, 0x0d, 0x44, 0xa5, 0x1c, 0x62, 0xa0, 0x51, 0xe9, 0x7c, 0x1f, 0xae, 0x2f, 0xe9, 0xe8, 0x2a, 0x0e, 0x15 };
static const uint8_t VEC_BATMON_NA[] = { 0xe1, 0x02, 0x10, 0x89, 0xa3, 0x00, 0x02, 0xf0, 0xbe, 0x0d, 0xdc, 0x6c, 0x19, 0x76, 0x1d, 0x5f, 0x39, 0xab, 0x97, 0x5e, 0x4c, 0xf0, 0x85, 0x67, 0xd5, 0xaa, 0x19, 0x98, 0xac, 0xf6, 0xf5 };
static const uint8_t VEC_INVERTER[] = { 0xe1, 0x02, 0x10, 0xfa, 0xa2, 0x00, 0x03, 0x01, 0x00, 0x0d, 0xf6, 0x2d, 0x11, 0x5e, 0x6f, 0x60, 0x17, 0x3f, 0x62, 0xeb, 0x75, 0xfe, 0x67, 0x69, 0xef, 0x59, 0x71, 0xb6, 0xb6, 0xd4, 0x2c };
static const uint8_t VEC_DCDC[] = { 0xe1, 0x02, 0x10, 0xc0, 0xa3, 0x00, 0x04, 0xff, 0xff, 0x0d, 0x66, 0xcc, 0x80, 0x55, 0xf1, 0x96, 0xe8, 0xb8, 0x15, 0x7f, 0x76, 0xd2, 0x4a, 0x5c, 0xeb, 0xf2, 0xbb, 0x6c, 0x9f, 0x58, 0x08 };
static const uint8_t VEC_ACCHARGER[] = { 0xe1, 0x02, 0x10, 0x39, 0xa3, 0x00, 0x08, 0xc8, 0x00, 0x0d, 0x10, 0xc5, 0xcd, 0xca, 0xbb, 0x29, 0x20, 0xda, 0xf8, 0x1e, 0xae, 0xf6, 0x8e, 0xce, 0xd4, 0xec, 0xb5, 0x6b, 0xa9, 0x99, 0x4a };