# TeleBike wire protocol (v1)

One UDP datagram per sensor sample, phone -> PC. Same payload over USB tethering, Wi-Fi,
or Bluetooth (over BT the same bytes are written as a serial stream, one packet per line).

## Packet: plain ASCII text, one line

```
TB1,<seq>,<t_ms>,<roll>,<pitch>,<yaw>,<gx>,<gy>,<gz>
```

| Field | Type | Units | Notes |
|-------|------|-------|-------|
| `TB1` | literal | | Magic + protocol version |
| `seq` | uint32 | | Packet counter, wraps. Receiver drops out-of-order packets |
| `t_ms` | int64 | ms | Phone monotonic time of the sample |
| `roll` | float | degrees | Handlebar tilt left(-)/right(+). Bike lean |
| `pitch` | float | degrees | Pivot pole tilt toward rider(-)/away(+). Body lean |
| `yaw` | float | degrees | Rotation about the pivot pole, left(-)/right(+). Handlebar turn. Relative to last re-center |
| `gx gy gz` | float | deg/s | Raw gyro rates, for optional PC-side filtering |

Floats are printed with 3 decimals. Example:

```
TB1,1042,538201,-12.345,3.210,0.875,-1.020,0.113,4.400
```

## Control packets (PC -> phone, optional)

```
TBC,recenter
```

Phone treats the current orientation as neutral. The phone also exposes a re-center button.

## Discovery (Wi-Fi)

PC receiver replies to a UDP broadcast `TBD?` on the data port with `TBD!<hostname>`.

## Defaults

- UDP port: **41818**
- Sample rate: `SENSOR_DELAY_GAME` (~50 Hz) minimum; 100 Hz preferred.
