{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://synacl.com/protocol/v1/schemas/bus-capture.json",
  "title": "Logic-analyser capture",
  "description": "The result of a `bus/capture` gateway command, on `<prefix>/bus/capture`: one digital capture of the RS485 receive line (the UART RX pad, sampled by the ESP32 RMT peripheral alongside the UART at `tickNs` resolution), echoing the command's `correlationId`. The waveform is run-length encoded: `first` is the line level of the first run and `d` is the base64 of little-endian unsigned 16-bit run lengths in ticks, alternating levels from `first` onward (run 0 at `first`, run 1 at the other level, …); a run longer than 65535 ticks is clamped. The reference firmware records at most 1024 runs (8 RMT memory blocks — about one 100-byte 8N1 frame at 9600 baud) and stops on idle, on overflow (`trunc: true`) or at the command's `maxMs`; one capture is one message. From it the app measures the real baud (the shortest stable run), decodes start / data / parity / stop bits and shows framing or parity errors beside the frame the tap saw. Polling is paused while the capture is armed. Relayed live as `gw:bus:capture`; never stored. Digital only, 0.1 µs at best: ringing and analogue faults need a scope.",
  "type": "object",
  "required": [
    "correlationId",
    "tickNs",
    "first",
    "n",
    "trunc",
    "d"
  ],
  "properties": {
    "correlationId": {
      "description": "Copied from the `bus/capture` command.",
      "type": "string",
      "maxLength": 64
    },
    "tickNs": {
      "description": "Nanoseconds per tick: 100 (0.1 µs, RMT clk_div 8) for 9600 baud and above, 1000 (1 µs, clk_div 80) below.",
      "type": "integer",
      "minimum": 1
    },
    "first": {
      "description": "Logic level of the first run, 0 or 1. An idle RS485 RX line reads 1 (mark), so a capture that started on a start bit begins at 0.",
      "type": "integer",
      "enum": [
        0,
        1
      ]
    },
    "n": {
      "description": "Number of runs encoded in `d` (`d` decodes to exactly 2·n bytes).",
      "type": "integer",
      "minimum": 0
    },
    "trunc": {
      "description": "True when the capture stopped on buffer overflow rather than on idle or `maxMs`: the tail is missing.",
      "type": "boolean"
    },
    "d": {
      "description": "Base64 (standard alphabet, padded) of `n` little-endian uint16 run lengths in ticks. At most 4096 characters (about 1500 runs).",
      "type": "string",
      "maxLength": 4096,
      "pattern": "^[A-Za-z0-9+/]*={0,2}$"
    },
    "ts": {
      "description": "Epoch milliseconds (gateway clock).",
      "type": "integer",
      "minimum": 0
    }
  },
  "additionalProperties": false
}
