{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://xcp-ray.de/schema/project-2.json",
  "title": "XCP-Ray project (.x1p), format 2",
  "description": "An XCP-Ray project: ECUs (XCP) and buses (CAN with DBC, LIN with LDF), displays on pages, DAQ events and the window layout. Paths are relative to the project file. Signals are written \"ECU:NAME\" (an A2L MEASUREMENT or CHARACTERISTIC of the ECU) or \"BUS:Message.Signal\" (a signal of the DBC/LDF of a bus); ECU is the name of the ECU in the project (empty name: the A2L MODULE name), BUS the name of the bus (empty name: the file name of the DBC/LDF without extension). Check a project with `xcpray-cli project check FILE`.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "formatVersion": {"description": "Format of the file; XCP-Ray writes 2.", "type": "integer", "enum": [2]},
    "ecus": {"description": "The XCP ECUs.", "type": "array", "items": {"$ref": "#/$defs/ecu"}},
    "session": {"description": "Format 1 only (one ECU without a name); new files use \"ecus\".", "$ref": "#/$defs/session"},
    "buses": {"description": "CAN buses with a DBC and LIN buses with an LDF (decoding, restbus simulation).", "type": "array", "items": {"$ref": "#/$defs/bus"}},
    "nameDisplay": {"description": "Signals shown with their A2L name or their DISPLAY_IDENTIFIER.", "enum": ["name", "displayIdentifier"]},
    "syncCursors": {"description": "The cursors of all scopes show the same time.", "type": "boolean"},
    "recordingsDir": {"description": "Folder for recordings, relative to the project file.", "type": "string"},
    "events": {"description": "DAQ event channel per signal (\"ECU:NAME\": channel number of the A2L); signals without an entry use the A2L default event or the ECU's default event.", "type": "object", "additionalProperties": {"type": "integer", "minimum": 0, "maximum": 65535}},
    "daqParameters": {"description": "Parameters (\"ECU:NAME\") measured with DAQ like measurements, with their event from \"events\".", "type": "array", "items": {"$ref": "#/$defs/signal"}},
    "triggers": {"description": "Trigger-controlled recording.", "type": "array", "items": {"$ref": "#/$defs/trigger"}},
    "displays": {"description": "The displays (windows) with their signals; each one is on a page.", "type": "array", "items": {"$ref": "#/$defs/display"}},
    "imguiIni": {"description": "The window layout as written by XCP-Ray. Leave it out or empty in a generated project: the displays of a page are then arranged automatically.", "type": "string"},
    "groups": {"description": "Page groups (tabs of the main window that hold pages). Without: one group \"Main\".", "type": "array", "items": {"$ref": "#/$defs/group"}},
    "pages": {"description": "Pages (tabs of a page group); each display names its page. Without: one page with all displays.", "type": "array", "items": {"$ref": "#/$defs/page"}}
  },
  "$defs": {
    "signal": {"description": "\"ECU:NAME\" or \"BUS:Message.Signal\".", "type": "string", "minLength": 1},
    "color": {"description": "\"#RRGGBB\", empty = default.", "type": "string", "pattern": "^(#[0-9A-Fa-f]{6})?$"},
    "canId": {"description": "CAN identifier: a number or a text like \"0x783\".", "type": ["integer", "string"]},
    "ecu": {
      "type": "object",
      "additionalProperties": false,
      "required": ["session"],
      "properties": {
        "name": {"description": "Short name used as the prefix of its signals (\"ECU:NAME\"); empty = the A2L MODULE name. No ':' or '@'.", "type": "string", "pattern": "^[^:@]*$"},
        "session": {"$ref": "#/$defs/session"}
      }
    },
    "session": {
      "description": "Connection of an ECU. Exactly one transport: \"can\" (with interface), \"udp\", \"tcp\" or \"serial\".",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {"type": "string"},
        "a2l": {"description": "The A2L file, relative to the project file.", "type": "string"},
        "can": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "interface": {"description": "e.g. can0, vcan0, PCAN_USBBUS1, Vector:<channel>; empty when another transport is used.", "type": "string"},
            "bitrate": {"type": "integer", "minimum": 1},
            "dataBitrate": {"type": "integer", "minimum": 1},
            "fd": {"type": "boolean"},
            "cmdId": {"$ref": "#/$defs/canId"},
            "resId": {"$ref": "#/$defs/canId"},
            "maxDlcRequired": {"type": "boolean"}
          }
        },
        "udp": {"description": "XCP on UDP/IP.", "type": "object", "additionalProperties": false, "properties": {"host": {"type": "string"}, "port": {"type": "integer", "minimum": 1, "maximum": 65535}}},
        "tcp": {"description": "XCP on TCP/IP.", "type": "object", "additionalProperties": false, "properties": {"host": {"type": "string"}, "port": {"type": "integer", "minimum": 1, "maximum": 65535}}},
        "serial": {"description": "XCP over a serial line.", "type": "object", "additionalProperties": false, "properties": {"port": {"type": "string"}, "baudrate": {"type": "integer", "minimum": 1}, "resetDelayMs": {"type": "integer", "minimum": 0}}},
        "xcp": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "timeoutsMs": {"description": "T1..T7 in ms.", "type": "array", "items": {"type": "integer", "minimum": 0, "maximum": 65535}, "minItems": 7, "maxItems": 7},
            "useShortUpload": {"type": "boolean"},
            "connectAttempts": {"type": "integer", "minimum": 1},
            "queryDaqInfo": {"type": "boolean"},
            "seedKey": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "command": {"type": "string"},
                "resources": {"type": "array", "items": {"enum": ["cal", "daq", "stim", "pgm"]}},
                "timeoutMs": {"type": "integer", "minimum": 0}
              }
            },
            "overrides": {
              "description": "Manual XCP settings that replace those of the ECU and of the A2L.",
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "byteOrder": {"enum": ["Intel", "Motorola"]},
                "addressGranularity": {"enum": [1, 2, 4]},
                "maxCto": {"type": "integer", "minimum": 8, "maximum": 255},
                "maxDto": {"type": "integer", "minimum": 8, "maximum": 65535},
                "dynamic": {"type": "boolean"},
                "maxDaq": {"type": "integer", "minimum": 0, "maximum": 65535},
                "maxEventChannels": {"type": "integer", "minimum": 0, "maximum": 65535},
                "minDaq": {"type": "integer", "minimum": 0, "maximum": 255},
                "identification": {"enum": ["absolute", "relativeByte", "relativeWord", "relativeWordAligned"]},
                "overload": {"enum": ["none", "pid", "event"]},
                "prescaler": {"type": "boolean"},
                "resume": {"type": "boolean"},
                "pidOff": {"type": "boolean"},
                "addressExtensionMode": {"type": "integer", "minimum": 0, "maximum": 255},
                "granularity": {"enum": [1, 2, 4, 8]},
                "maxOdtEntrySize": {"type": "integer", "minimum": 1, "maximum": 255},
                "timestampSize": {"enum": [0, 1, 2, 4]},
                "timestampTickUs": {"type": "number", "exclusiveMinimum": 0},
                "timestampFixed": {"type": "boolean"},
                "events": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "channel": {"type": "integer", "minimum": 0, "maximum": 65535},
                      "name": {"type": "string"},
                      "cycleMs": {"type": "number", "minimum": 0},
                      "maxDaqLists": {"type": "integer", "minimum": 0, "maximum": 255},
                      "priority": {"type": "integer", "minimum": 0, "maximum": 255}
                    }
                  }
                }
              }
            }
          }
        },
        "daq": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "useTimestamps": {"type": "boolean"},
            "maxBusLoad": {"description": "Share of the bus the DAQ lists may use (0..1).", "type": "number", "minimum": 0, "maximum": 1},
            "defaultEvent": {"description": "Event channel for signals without an event of their own.", "type": "integer", "minimum": 0, "maximum": 65535}
          }
        },
        "reconnect": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "policy": {"enum": ["abort", "retry", "retry_forever"]},
            "attempts": {"type": "integer", "minimum": 0},
            "intervalMs": {"type": "integer", "minimum": 0},
            "heartbeatMs": {"type": "integer", "minimum": 0}
          }
        },
        "measurement": {"description": "Signals of the command line measurement (not used by the displays).", "type": "array", "items": {"type": "string"}},
        "pollPeriodMs": {"description": "Period for reading values without DAQ.", "type": "integer", "minimum": 1},
        "enabled": {"description": "false: the ECU stays in the project but is not connected.", "type": "boolean"},
        "resume": {"description": "DAQ configuration stored in the ECU; written by XCP-Ray, do not create it by hand.", "type": "object"}
      }
    },
    "bus": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {"description": "Prefix of its signals (\"BUS:Message.Signal\"); empty = file name of the DBC/LDF without extension. No ':' or '@'.", "type": "string", "pattern": "^[^:@]*$"},
        "type": {"description": "Default \"can\".", "enum": ["can", "lin"]},
        "interface": {"type": "string"},
        "dbc": {"description": "CAN: the DBC, relative to the project file.", "type": "string"},
        "ldf": {"description": "LIN: the LDF, relative to the project file.", "type": "string"},
        "fd": {"type": "boolean"},
        "bitrate": {"description": "CAN: bit/s; LIN: baud. Without: keep the setting of the interface (LIN: the speed of the LDF).", "type": "integer", "minimum": 1},
        "dataBitrate": {"type": "integer", "minimum": 1},
        "enabled": {"type": "boolean"},
        "linMode": {"enum": ["master", "slave"]},
        "schedule": {"description": "LIN master: the schedule table, empty = the first one of the LDF.", "type": "string"},
        "restbus": {
          "description": "Frames the PC sends.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "frames": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "active": {"type": "boolean"},
                  "cycleMs": {"type": "integer", "minimum": 0},
                  "function": {"description": "Lua function of the script called before each transmission.", "type": "string"}
                }
              }
            },
            "values": {"description": "\"Message.Signal\": physical value.", "type": "object", "additionalProperties": {"type": "number"}},
            "script": {"description": "Lua script, relative to the project file.", "type": "string"}
          }
        }
      }
    },
    "trigger": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {"type": "string"},
        "signal": {"description": "\"ECU:NAME\" or \"BUS:Message.Signal\"; empty = not set yet (the trigger never fires).", "type": "string"},
        "condition": {"enum": ["rising", "falling", "crossing", "outside", "equal"]},
        "threshold": {"type": "number"},
        "upper": {"description": "\"outside\": the upper limit (threshold is the lower one).", "type": "number"},
        "preSeconds": {"type": "number", "minimum": 0},
        "postSeconds": {"type": "number", "minimum": 0},
        "maxCount": {"description": "0 = unlimited.", "type": "integer", "minimum": 0},
        "enabled": {"type": "boolean"},
        "exportWindows": {"type": "boolean"},
        "exportFormat": {"enum": ["mf4", "csv"]}
      }
    },
    "axis": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "autoFit": {"type": "boolean"},
        "invert": {"type": "boolean"},
        "opposite": {"type": "boolean"},
        "label": {"type": "boolean"},
        "gridLines": {"type": "boolean"},
        "tickMarks": {"type": "boolean"},
        "tickLabels": {"type": "boolean"},
        "lockMin": {"type": "boolean"},
        "lockMax": {"type": "boolean"},
        "min": {"description": "Kept only with lockMin/lockMax (together with max).", "type": "number"},
        "max": {"type": "number"}
      }
    },
    "display": {
      "description": "A display. Which fields apply depends on \"type\"; the others are ignored.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": {
          "description": "scope: curves over time; numeric: values as rows (also to edit parameters); bars: bar per signal; curve: a CURVE parameter; map: a MAP parameter; array: an array measurement or parameter; console: text of a serial ECU; notes: Markdown text; restbus: frames a bus sends; panel: values on a picture; xy: signals[0] is X, the others Y; histogram; spectrum (FFT).",
          "enum": ["scope", "numeric", "bars", "curve", "map", "array", "console", "notes", "restbus", "panel", "xy", "histogram", "spectrum"]
        },
        "title": {"description": "Window title; empty = named by XCP-Ray when opened (\"Scope 1\", a curve or map after its parameter).", "type": "string"},
        "signals": {"description": "The signals; curve/map/array: the parameter (one).", "type": "array", "items": {"$ref": "#/$defs/signal"}},
        "id": {"description": "Unique number of the display in the project.", "type": "integer", "minimum": 0},
        "page": {"description": "id of its page.", "type": "integer", "minimum": 0},
        "color": {"description": "Tab and title bar color.", "$ref": "#/$defs/color"},
        "seconds": {"description": "scope: visible time span while measuring.", "type": "number", "exclusiveMinimum": 0},
        "cursor": {"description": "scope, spectrum: measurement cursor shown.", "type": "boolean"},
        "axes": {"description": "scope: Y axis per signal, 0 = Y1 .. 9 = Y10.", "type": "object", "additionalProperties": {"type": "integer", "minimum": 0, "maximum": 9}},
        "bands": {"description": "scope: signals (also in \"signals\") shown as a colored state band below the plot instead of a curve; for enumerations and states.", "type": "array", "items": {"$ref": "#/$defs/signal"}},
        "view": {
          "description": "scope: axes, legend and plot settings.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "axes": {"description": "[0] = time axis, [1..10] = Y1..Y10.", "type": "array", "items": {"$ref": "#/$defs/axis"}, "maxItems": 11},
            "legend": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "show": {"type": "boolean"},
                "outside": {"type": "boolean"},
                "horizontal": {"type": "boolean"},
                "location": {"enum": ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "C"]}
              }
            },
            "crosshairs": {"type": "boolean"},
            "mousePosition": {"type": "boolean"},
            "boxSelect": {"type": "boolean"},
            "equal": {"type": "boolean"},
            "steps": {"description": "Samples connected as steps.", "type": "boolean"},
            "stacked": {"description": "Y axes in separate bands.", "type": "boolean"}
          }
        },
        "autoY": {"description": "Old files only (auto fit of Y1..Y3); new files use \"view\".", "type": "array", "items": {"type": "boolean"}},
        "colors": {"description": "numeric: row color per signal.", "type": "object", "additionalProperties": {"$ref": "#/$defs/color"}},
        "limits": {
          "description": "bars: scale and limits per signal.",
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "additionalProperties": false,
            "properties": {"scaleMin": {"type": "number"}, "scaleMax": {"type": "number"}, "min": {"type": "number"}, "max": {"type": "number"}}
          }
        },
        "writable": {"description": "numeric: measurements the user may overwrite.", "type": "array", "items": {"$ref": "#/$defs/signal"}},
        "rowScale": {"description": "numeric: size of a row, 1 = normal.", "type": "object", "additionalProperties": {"type": "number", "exclusiveMinimum": 0}},
        "rowFormat": {"description": "numeric: raw value as dec/hex/bin, or seconds as a time; without: physical value.", "type": "object", "additionalProperties": {"enum": ["dec", "hex", "bin", "time"]}},
        "rowKind": {"description": "numeric: how a row shows its value; without: as text.", "type": "object", "additionalProperties": {"enum": ["bar", "lamp", "switch", "buttons", "dial"]}},
        "ecu": {"description": "console: the serial ECU; restbus: the bus.", "type": "string"},
        "timestamps": {"description": "console: time of day before each line.", "type": "boolean"},
        "view3d": {"description": "map: 3D view instead of the heat map.", "type": "boolean"},
        "fromZero": {"description": "array: bars from 0.", "type": "boolean"},
        "notes": {"description": "notes: the text (Markdown).", "type": "string"},
        "textColor": {"$ref": "#/$defs/color"},
        "background": {"$ref": "#/$defs/color"},
        "panel": {
          "description": "panel: the picture and the elements on it.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "image": {"description": "PNG, JPEG or BMP, relative to the project file.", "type": "string"},
            "items": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "kind": {"enum": ["value", "bar", "lamp", "text"]},
                  "signal": {"description": "Empty for a text.", "type": "string"},
                  "label": {"type": "string"},
                  "x": {"description": "Position and size relative to the picture (0..1).", "type": "number", "minimum": 0, "maximum": 1},
                  "y": {"type": "number", "minimum": 0, "maximum": 1},
                  "w": {"type": "number", "minimum": 0.01, "maximum": 1},
                  "h": {"type": "number", "minimum": 0.01, "maximum": 1},
                  "min": {"type": "number"},
                  "max": {"type": "number"},
                  "threshold": {"description": "lamp: red at or above it.", "type": "number"}
                }
              }
            }
          }
        },
        "analysis": {
          "description": "xy, histogram, spectrum.",
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "range": {"description": "all: the whole recording; scope: the time range of the scope used last; last: the last \"seconds\".", "enum": ["all", "scope", "last"]},
            "density": {"type": "boolean"},
            "gridBins": {"type": "integer", "minimum": 2, "maximum": 200},
            "map": {"description": "xy: a MAP parameter (\"ECU:NAME\") whose support points are the cells.", "type": "string"},
            "gridX": {"type": "array", "items": {"type": "number"}},
            "gridY": {"type": "array", "items": {"type": "number"}},
            "trace": {"type": "boolean"},
            "bins": {"description": "0 = automatic.", "type": "integer", "minimum": 0, "maximum": 1000},
            "percent": {"type": "boolean"},
            "window": {"enum": ["rectangular", "hann", "hamming", "blackman", "flattop"]},
            "segment": {"description": "Samples per FFT, 0 = automatic.", "type": "integer", "minimum": 0},
            "decibel": {"type": "boolean"},
            "logFrequency": {"type": "boolean"}
          }
        }
      }
    },
    "group": {
      "type": "object",
      "additionalProperties": false,
      "properties": {"id": {"type": "integer", "minimum": 0}, "title": {"type": "string"}, "color": {"$ref": "#/$defs/color"}}
    },
    "page": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {"type": "integer", "minimum": 0},
        "title": {"type": "string"},
        "color": {"$ref": "#/$defs/color"},
        "group": {"description": "id of its page group.", "type": "integer", "minimum": 0}
      }
    }
  }
}
