Monitor the XIAO's battery and make the XIAO the production board

The production OBU is now a Seeed XIAO ESP32-C5 (8 MB flash, one native
USB-C port) on a LiPo with no protection board. The firmware reads the
cell on GPIO6 (divider switched by GPIO26) every 5 s, sends it in STATUS
(battery_mv and battery_flags, octets 103-105; decoders accept 103 or
>= 106 octets), warns below 3.50 V and deep-sleeps below 3.30 V when no
phone is on USB, waking every 5 min to check the cell again. Thresholds
are in Kconfig; host test `make battery`.

The app shows voltage, a rough percentage and the low/critical state on
the ESP32-C5 card and in the top bar. With several bonded micrOBUs (a
replaced board stays bonded), the BLE link tries the one that last
connected first and moves on to the next after each failure.

tools/station_status_watch.py reads STATUS from the native port.
This commit is contained in:
Ashin Walpola
2026-10-28 16:48:18 +01:00
parent d0fcb45a55
commit 9f77f9f0e4
28 changed files with 955 additions and 31 deletions
+13 -3
View File
@@ -2,13 +2,14 @@
# asn1tools under `py -3.11` for the replay check.
#
# make build and run everything: chain, replay, fuzz
# make chain | replay | fuzz one of them
# make chain | replay | fuzz | battery one of them
# make fuzz FUZZ_ITER=50000000 FUZZ_SEED=7 a longer or different fuzz run
# make clean remove build/
#
# The firmware sources are compiled straight from ../../main, never copied.
CC = gcc
CXX = g++
PYTHON = python
PYTHON_ASN1 = py -3.11
FW = ../../main
@@ -26,11 +27,11 @@ CFLAGS = -std=c11 -O2 -g -Wall -Wextra -Wpedantic -Werror -I$(FW) \
FW_SRCS = $(FW)/geonet.c $(FW)/dot11p.c $(FW)/gn_unwrap.c
DEPS = test_util.c test_util.h $(FW_SRCS) $(wildcard $(FW)/*.h)
.PHONY: all check chain replay fuzz clean
.PHONY: all check chain replay fuzz battery clean
all: check
check: chain replay fuzz
check: chain replay fuzz battery
$(BUILD):
mkdir -p $@
@@ -54,5 +55,14 @@ endif
fuzz: $(BUILD)/fuzz_gn_unwrap$(EXE)
$(BUILD)/fuzz_gn_unwrap$(EXE) $(FUZZ_ITER) $(FUZZ_SEED) $(RECORDINGS)
# Battery policy and the STATUS battery fields: C++17, so its own flags.
CXXFLAGS = -std=c++17 -O2 -g -Wall -Wextra -Wpedantic -Werror -I$(FW)
$(BUILD)/test_battery$(EXE): test_battery.cpp $(FW)/battery_monitor.hpp $(FW)/link_protocol.cpp $(FW)/link_protocol.hpp | $(BUILD)
$(CXX) $(CXXFLAGS) -o $@ test_battery.cpp $(FW)/link_protocol.cpp
battery: $(BUILD)/test_battery$(EXE)
$(BUILD)/test_battery$(EXE)
clean:
rm -rf $(BUILD)