GPS buffer and report

The store-and-forward layer that lets the GPS Pro log for hours with the modem off. Positions go into a ring of binary files; once per 422 interval the whole ring is compressed (when the MicroPython build has a writable deflate), base64-encoded and sent as the GPSBuffer= field of one report request. The record layout is specified in GPS buffer record.

Ring buffer

gpspro.firmware_core.log_gps_point(fix, flags=0)[source]

Append one packed GPS_REC_SIZE-byte record to the current ring-buffer slot. No fix -> no write. Rotates to the next slot (evicting its old content) once the current slot reaches GPS_BUF_MAX_LINES records.

flags is a debug bitfield stored verbatim in the record’s last byte:

bit0 (0x01) = moving, bit1 (0x02) = alarm, bit2 (0x04) = forced wake.

gpspro.firmware_core.read_gps_buffer_bytes()[source]

Concatenate every buffered slot’s packed records, oldest slot first.

gpspro.firmware_core.clear_gps_buffer()[source]
gpspro.firmware_core.ensure_buffer_format()[source]

Drop any buffered points written in a different record layout than the one this firmware packs (GPS_REC_SIZE). After an OTA update that changed the format — e.g. adding the speed byte (12 -> 13) — the old records must not be concatenated with new ones into a single GPSBuffer blob, or the server decoder would misalign on the size boundary. Run once at startup.

gpspro.firmware_core._gps_buf_path(slot)[source]

Encoding

gpspro.firmware_core.gzip_bytes(data)[source]

Zlib-compress data with the ‘deflate’ module. Falls back to sending the raw bytes unmodified if that module isn’t available on this build.

gpspro.firmware_core.encode_gps_buffer(raw)[source]

Zip (best-effort) then ALWAYS base64 the result before it goes into GPSBuffer=”…”. The wire format embeds this inside a single unescaped text line ending in ‘”,’ — packed binary GPS records (or compressed output, if compression ever becomes available) are, past a few dozen bytes, almost certain to contain a stray ‘r’/’n’/’”’ byte by chance, which would truncate the line early and the server sees a malformed request (this is exactly what caused the 400 Bad Request). Base64’s alphabet never contains any of those three bytes, so this is always line-safe.

Report request / response

gpspro.firmware_core.build_higps_data()[source]
gpspro.firmware_core.higps_report_url(bat_percent)[source]
gpspro.firmware_core.handle_server_response(response)[source]

Example (verbatim from the firmware source):

Parse a command the server pushed back and apply it. Confirmed against
live logs from another device on the same backend:
  *SET,422,60   -> device applies db['422']='60', then acks
  *GET,421$     -> device reads db['421'], then acks with that value
Both SET and GET ack with the SAME shape (see higps_ack_url()) — GET
just echoes the current value instead of a newly-written one. Markers
can carry a trailing '$' as well as the leading '*' (matches the old
set_set()/set_get() dispatch, which stripped '$' before splitting).
Returns (param_id, value) to ack, or None if there's nothing to ack.
gpspro.firmware_core.higps_ack_url(param_id, value)[source]

Example (verbatim from the firmware source):

Same skeleton as higps_report_url() but with 'set=<id>,<value>;'
instead of 'data=' — confirmed shape from live server logs:
'IMEI=...&set=422,60;&er=&rt=0&t=1&fw=3_6_0&'