Initial public NavFrame release with global regional package pipeline

This commit is contained in:
dasemu committed 2026-09-30 17:34:58 +02:00
commit d863f2b940
143 files changed
+17906

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
# NavFrame NaviLite protocol contract
Based on Pillion commit `6647af22f035ad74dc98f0e2a29e0c8a769a1caa`; attribution and scope are documented in [NAVILITE_RESEARCH.md](NAVILITE_RESEARCH.md) and `third_party/pillion/`. This is an experimental interoperability adaptation, unaffiliated with Yamaha or Garmin. The owner confirmed both NavFrame test and synthetic images on a 2026 MT-07 using a Xiaomi 11 Lite 5G NE / Android 14. Long-duration stability remains unverified.
## RFCOMM stream packet
| Offset | Bytes | Field |
|---:|---:|---|
| 0 | 4 | ASCII `nAl@` = `6E 41 6C 40` |
| 4 | 1 | version `01` |
| 5 | 1 | frameType, outgoing `06` |
| 6 | 1 | serviceType |
| 7 | 4 | payload length, UInt32 little endian |
| 11 | 1 | payloadDataType: value=0, pointer=1 |
| 12 | 4 | CRC UInt32 little endian |
| 16 | n | payload |
CRC-32/MPEG-2 is calculated over header bytes 0–11 concatenated with the payload, excluding the CRC itself. Polynomial `04C11DB7`, init `FFFFFFFF`, no reflection, xor-out 0. Standard vector `123456789` → `0376E6E7`. The implementation validates packet size (1 MiB), CRC, and version. The size limit is a defensive implementation bound, not a demonstrated protocol maximum. RFCOMM is a byte stream: one read may contain part of a packet or multiple packets.
## Handshake
1. Connect an insecure RFCOMM socket to the selected already-paired device, UUID `00007220-0000-1000-8000-00805F9B34FB`.
2. Wait for ESN_UPDATE service 66.
3. Send ESN_ACK service 81, value, `01 00`.
4. Send AUTH_REQUEST service 33, pointer, `1C 07 00 01 00 00 00 00`.
5. Wait for SEC_DATA service 83. Payload is an ASCII part number followed by a 4-byte nonce; each byte is obfuscated with XOR `0A`.
6. Send SEC_DATA_ACK service 84, pointer, the last 4 bytes XOR `0A`. Require at least 4 bytes before extracting them.
7. Send the following setup. Outgoing frameType is 6 for every packet.
| Order | Service | PDT | Payload hex |
|---:|---:|---:|---|
| 1 | 2 NAV_STATUS | 0 | `00 00` |
| 2 | 31 DAY_NIGHT | 0 | `01 00` |
| 3 | 10 HOME | 0 | `00 00` |
| 4 | 11 OFFICE | 0 | `00 00` |
| 5 | 13 GPS | 0 | `01 00` |
| 6 | 12 APP_SETTING | 0 | `00 00` |
| 7 | 14 ZOOM | 1 | `07 19 06 00 30 2E 32 20 6D 69` |
| 8 | 3 ROAD | 1 | empty |
| 9 | 17 SPEED_LIMIT | 1 | `00 00 00 00 03 6D 70 68` |
| 10 | 13 GPS | 0 | `01 00` |
| 11 | 12 APP_SETTING | 0 | `01 00` |
These values reproduce the observed upstream session, including scale/unit labels in miles. NavFrame's own image may show metric values; the detailed semantics of these metadata are unverified.
## Image and send cycle
Service 0, frameType 6, pointer 1, payload `03 | seq UInt16LE | JPEG`. Sequence starts at 1 and wraps to 0 after 65535. The JPEG is generated by NavFrame at baseline 480×240; it is not a phone-screen capture. Only one frame may be in flight: `sendFrame` writes the packet and waits for IMAGE_ACK service 80 before the next frame. ACK payload format/correlation is not demonstrated; as in Pillion, the implementation filters on service 80. Other services are consumed without executing commands. An ACK confirms protocol exchange acceptance, not that an image was visibly drawn on the TFT.
Connection, handshake, and ACK timeouts and cancellation close the socket, unblock I/O, and set ERROR; `disconnect` closes directly without waiting for a held mutex. The initial version required an explicit reconnect; after ERROR, transport can call `connect()` again with a new socket, full handshake, and reset sequence. Automatic pairing and additional commands are not implemented. The transport has no continuously running reader while no sends occur; it detects a remote close on the next send. Therefore the session keepalive policy needs periodic checks; without them, CONNECTED may remain visible until another send.
## Android API
`NaviLiteTransport(context, deviceAddress)` implements `dev.navframe.core.TftTransport`: `connect`, `disconnect`, `sendFrame`, and `connectionState`. Android 12+ requires runtime `BLUETOOTH_CONNECT`; legacy Bluetooth permissions apply through Android 11. The app selects from paired devices. CONNECTED means setup was sent; only observing the TFT confirms M1.
## Local verification
JVM codec tests cover standard and captured CRC, captured/independent framing, fragmentation, concatenation, resynchronization, UInt32 limits, truncation, version, nonce, and image sequence. The complete handshake and setup were manually compared with the pinned `core/Handshake.kt`; an automated end-to-end session/stream test is still missing. The owner physically confirmed the handshake and test/synthetic images on the specified MT-07 2026. Timeout and cancellation paths were reviewed by control-flow analysis and still need real Bluetooth close/recovery validation.
## Static session, keepalive, and recovery
The owner reported connection drops after long intervals without sends; duration and cause have not been measured. Pillion repeatedly sends the latest JPEG without image deduplication; no separate ping/heartbeat is documented. The initial conservative policy is to resend the cached latest JPEG every 1 second, with a new sequence and normal ACK. This does not change the wire format or require a redraw. This provisional interval requires testing with the target motorcycle.
`connect()` closes any prior socket, increments a generation, and performs full authentication. `disconnect()` invalidates the generation and closes immediately, including during connect/read. Android recovery should use a single session job to serialize connect/send/retry, retain the latest frame, use bounded retry backoff, and stop on STOP; stale callbacks must not reopen sockets. Permission failures and Bluetooth-off state need user intervention/configuration rather than rapid retries. Backoff policy is not a NaviLite protocol property.
## Screen-off behavior: Android requirements
Continuous Bluetooth sending belongs in a `connectedDevice` foreground service with `FOREGROUND_SERVICE`, the foreground-service type permission, and the runtime Bluetooth permission. GPS adds the `location` type. MediaProjection is not part of this architecture. This follows Android's [foreground-service type](https://developer.android.com/develop/background-work/services/fgs/service-types) and [background start restrictions](https://developer.android.com/develop/background-work/services/fgs/restrictions-bg-start); start from visible user interaction.
A foreground service does not keep the CPU awake. If suspension interrupts timers/keepalive, use a `PARTIAL_WAKE_LOCK` only during the user-requested active session, without turning on the display. Renew a protective timeout only while the session remains active and release on STOP, destroy, cancellation, or terminal failure. Keep acquisition/release under one owner. Android recommends choosing the lightest mechanism and reserving wake locks for work that cannot be suspended: [keep-device-awake guidance](https://developer.android.com/develop/background-work/background-tasks/awake) and [wake-lock release](https://developer.android.com/develop/background-work/background-tasks/awake/wakelock/release).
A wake lock addresses ordinary suspension; it does **not** guarantee execution during Doze. Android documents that Doze ignores wake locks for apps that are not exempt. Test screen-off and Doze behavior, and distinguish Xiaomi policy from CCU behavior. Do not assume a battery exemption or request one automatically. See [Doze and App Standby](https://developer.android.com/training/monitoring-device-state/doze-standby).
Keepalive stability, automatic reconnect, and wake-lock behavior need further integration/screen-off tests. Codec tests do not verify them. M1 confirms initial image transport, not GPS navigation or battery behavior.