Files
MicrOBU/obu-firmware/test/host/Makefile
T
Ashin Walpola 9f77f9f0e4 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.
2026-10-28 16:48:18 +01:00

69 lines
2.4 KiB
Makefile

# Host-side tests for obu-firmware. See README.md: needs gcc and make on PATH (MSYS2 UCRT64), and
# asn1tools under `py -3.11` for the replay check.
#
# make build and run everything: chain, replay, fuzz
# 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
BUILD = build
EXE = $(if $(filter Windows_NT,$(OS)),.exe,)
RECORDINGS = $(wildcard ../../../its-g5-receiver-firmware/recordings/*.pcap)
FUZZ_ITER = 2000000
FUZZ_SEED = 1
# -Werror: these sources must stay warning-free on the host compiler too.
# UBSan in trap mode needs no runtime library, so it works on MinGW; a trap shows up as a crash.
CFLAGS = -std=c11 -O2 -g -Wall -Wextra -Wpedantic -Werror -I$(FW) \
-fsanitize=undefined -fsanitize-undefined-trap-on-error
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 battery clean
all: check
check: chain replay fuzz battery
$(BUILD):
mkdir -p $@
$(BUILD)/%$(EXE): %.c $(DEPS) | $(BUILD)
$(CC) $(CFLAGS) -o $@ $< test_util.c $(FW_SRCS)
# The pcap goes through pcap_gn_tally.py as a second, independent parser of the same frames.
chain: $(BUILD)/test_chain$(EXE)
$(BUILD)/test_chain$(EXE) $(BUILD)/test_chain.pcap
$(PYTHON) ../pcap_gn_tally.py $(BUILD)/test_chain.pcap
replay: $(BUILD)/test_replay$(EXE)
ifeq ($(RECORDINGS),)
@echo "replay: no recordings in ../../../its-g5-receiver-firmware/recordings, skipped"
else
$(BUILD)/test_replay$(EXE) $(BUILD)/replay.tsv $(RECORDINGS)
$(PYTHON_ASN1) check_replay.py $(BUILD)/replay.tsv $(RECORDINGS)
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)