Three features against one RAM budget
400 geofences, 10,000 driver IDs and two data connections at once, on a tracker already short on RAM. I estimated each before writing code, and each hit a different limit: free RAM, boot time, or room for one TLS session.
Tracker firmware runs on a fixed amount of RAM, and most of it is already taken. Three requests each needed more of it. A client wanted 400 geofences, each a 15-point polygon. Another project needed the driver ID list to hold 10,000 entries. A customer needed two data connections on different APNs, open at the same time.
I wrote an estimate for each before writing any code: 154 h of firmware work plus 40 h for the configuration tool, 60 h, and 116 h. Each one hit a different wall: free RAM, boot time, and room for only one TLS session.
Geofences: measure, then cut
Every polygon point lives in RAM. With 400 zones, I measured 42 kB of free RAM at 10 points per polygon, and 24 kB at 15. That was an early measurement, and it was dangerously low.
Coordinates come with six decimal places, about 10 cm, and were stored as doubles. I pushed for 32-bit floats instead: half the bytes per coordinate, and a little less precision. I also pushed back on per-zone names as scope creep. It still didn’t fit, so I removed reserved features the build never used, and shortened a rarely used list to free 2.4 kB.
What the cuts broke
Trimming had removed some base parameters by mistake, so the immobilizer re-locked after unlock. I restored them. The #ifndef blocks I added to save RAM overlapped and changed an IO default, so an alarm event was always on. I patched that. And the configuration tool still treated coordinates as doubles, so every config showed unsaved changes. I updated it to float.
10,000 driver IDs: boot was the problem
A driver touches an ID key to the 1-Wire reader, and the firmware checks it against the list for the immobilizer. With 10,000 entries the feature worked, but boot took about 100 s, against a 30 s limit. I made the list load faster at boot, and cut RAM and BSS use so the list fit.
Two connections, one TLS session
The firmware assumed there was only ever one data connection. The estimate is where the real limit showed up: there was RAM for one TLS session, not two. So I reworked the core network API to handle two PDP contexts. Both connections stay up, and secure traffic goes to one server at a time, so one TLS session is enough.
In testing, the backup connection was torn down and rebuilt on every send. The network rejected that, and the modem got stuck in a restart loop. I fixed the backup handling in several places and removed the settings-refresh loop.
Conclusion
Geofences: QA confirmed “400 zones configurable and polygons working”, and the build fits in RAM. Driver IDs: boot went from about 100 s to under 30 s, on two tracker models. Two connections: the customer accepted the design, which touches about 30 files across the network API and two modem drivers.
On a device this full, every feature costs something else. Here it was precision, unused features and a second TLS session. And cutting RAM breaks things too, so cuts need testing like any new feature.