|
| 1 | +# Serial/Display Disconnect During Call (#103) |
| 2 | + |
| 3 | +When the display Arduino or serial link disconnects during a call (USB unplug, cable fault), here is the observed behavior. |
| 4 | + |
| 5 | +## Detection |
| 6 | + |
| 7 | +- `millennium_client_check_serial` runs periodically. If no read/write activity for `SERIAL_WATCHDOG_SECONDS` (60s), it sets `serial_healthy = 0`. |
| 8 | +- On the next cycle, reconnect is attempted: `open_serial_port` closes the stale fd and opens the device again. |
| 9 | + |
| 10 | +## What Continues |
| 11 | + |
| 12 | +- **SIP call**: Baresip runs in a separate thread and uses the network. The call continues; audio is independent of the serial link. |
| 13 | +- **Plugin state**: Daemon state, plugin state (e.g. `classic_phone_data`), and display_manager state keep updating via `plugins_tick` / `display_manager_tick`. These run in the main loop regardless of serial. |
| 14 | + |
| 15 | +## Display Re-sync on Reconnect |
| 16 | + |
| 17 | +When `open_serial_port` succeeds: |
| 18 | + |
| 19 | +1. `client->display_dirty = 1` is set if `client->display_message` exists. |
| 20 | +2. `millennium_client_update` writes `display_message` to the display on the next cycle (throttled to ~33ms). |
| 21 | +3. `display_message` is kept current by `display_manager_tick`, which is driven by the main loop. So it contains the latest "Call active | X:XX remaining" (or whatever the plugin last set) even while disconnected. |
| 22 | + |
| 23 | +**Result**: After reconnect, the display shows the correct state (e.g. "Call active | 2:15 remaining") because the SDK re-sends the last display content. |
| 24 | + |
| 25 | +## Buffered Updates While Disconnected |
| 26 | + |
| 27 | +While the serial link is down: |
| 28 | + |
| 29 | +- `millennium_client_write_to_display` still updates `client->display_message` and sets `display_dirty = 1`. |
| 30 | +- The actual `write()` to the fd may fail (broken link), but the in-memory `display_message` is updated. |
| 31 | +- When reconnect succeeds, we have the latest content and re-send it. |
| 32 | + |
| 33 | +## Testing |
| 34 | + |
| 35 | +A scenario test that unplugs the serial mid-call is difficult without hardware. Manual testing: start a call, unplug USB, wait for "Serial link recovered" in logs, verify the display shows current call state. |
0 commit comments