fix: rebuild stale CAN map on firmware upgrade (-S6) #8
Reference in New Issue
Block a user
Delete Branch "fix/canmap-rebuild-on-upgrade"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
MapChargerMessages()was usingParam::hwaclimas the "is the saved CAN map still valid" canary.hwaclimhas existed in every firmware version, so on every upgrade the guard always finds it in the persisted flash map and short-circuits —ChargerCAN::MapMessages()never re-runs, and any newAddRecv/AddSendentries inchargercan.cppare dead code on already-flashed hardware.Symptom verified on the -S5 bench via the openinverter web UI's spot-values page (which reads the live in-RAM canMap via the C++ API):
Mapped (in the stale persisted map):
state/uaux/socon 0x211,idc/udcon 0x109,hwaclim,aclim,opmode,version.NOT mapped (despite being in current
chargercan.cpp):tmpobcmax(the -S5 addition), allc1*/c2*/c3*per-module receives (tmp1/2/in,uac,iac,udc,idc,stt,flag), and the CHAdeMO RX block (canenable,idcspnt,udclim,socon 0x102).Downstream effect: the Polarity app's STATUS screen shows 0 A output current, 0 V udc, 0 °C charger temperature, and tmpobcmax=0 on 0x211 byte 7 — because
CalcTotals()is summing per-module values that the firmware never receives.Fix
Param::hwaclim→Param::tmpobcmax. tmpobcmax was added in -S5; it can't appear in any older persisted map, so the rebuild kicks in exactly once on the first boot after upgrading from any pre-S6 firmware.canMap->Clear()so the rebuild starts from a known-clean state instead of trying to deltify on top of the stale map.VERSTRS5→S6so the openinverter web UI labels this distinctly.The original intent of the early-return guard — letting user customizations to the CAN map persist across reboots — is preserved. The guard still kicks in on every boot after the first one with tmpobcmax in the map.
Test plan
make clean && makesucceeds with no new warnings (verified locally; size: 25 416 B text, 2 072 B data, 324 B bss).1.20.R-S6in the version field.tmpobcmaxnow shows a CAN mapping (529/56/8/1 — 0x211 byte 7).c1iac,c1udc,c1idc,c1tmp1,c1tmp2,c1tmpinall show RX-mappings on 0x207/0x227/0x237.idcgo non-zero and per-module temps come alive on the openinverter web UI.If per-module temp probes stay 0 °C even after the rebuild, the Tesla OBC modules themselves aren't broadcasting 0x237/0x239/0x23B on this bench — that's a hardware/module-firmware reality, not anything we can fix in code.
🤖 Generated with Claude Code
Pull request closed