{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://fa-spec.com/spec/v1/systemdiagram.schema.json",
  "title": "spec-platform/v1 systemdiagram（システム構成図）",
  "description": "機器（devices）と、その間の通信（links）で表す。仕様の正は https://fa-spec.com/json-format の 2 章。",
  "allOf": [{ "$ref": "common.schema.json" }],
  "type": "object",
  "properties": {
    "kind": { "const": "systemdiagram" },
    "machineId": { "type": "string", "description": "装置 ID。PLC ごとのメモリマップ・図の一覧・装置ファイルを装置ごとに分ける。構成図が作る。省略可（無い前の版は、題名と機器の名前から決める）。" },
    "devices": {
      "type": "array",
      "description": "機器。",
      "items": {
        "type": "object",
        "required": ["id", "name"],
        "properties": {
          "id": { "$ref": "common.schema.json#/$defs/id", "description": "この機器の識別子。links から参照される。" },
          "name": { "type": "string", "description": "図に出る名前。" },
          "kind": {
            "enum": ["plc", "hmi", "pc", "servo", "inverter", "robot", "io", "unit", "sensor", "net", "other"],
            "description": "省略すると other。色と形が変わる。"
          },
          "model": { "type": "string", "description": "型式（例 Q06UDHCPU）。" },
          "addr": { "type": "string", "description": "IP アドレスや局番。" },
          "comment": { "type": "string", "description": "備考。" },
          "x": { "type": "number", "description": "図の中の位置。省略可（自動整列で並べる）。" },
          "y": { "type": "number", "description": "図の中の位置。省略可（自動整列で並べる）。" },
          "blocks": { "type": "array", "items": { "$ref": "common.schema.json#/$defs/block" } },
          "location": { "type": "string", "description": "置き場所（制御盤・操作盤・機上中継 BOX など）。同じ置き場所の機器は、図で名前付きの枠に囲まれる。ほかのツールへ渡す機器名には混ぜない。省略可。" },
          "safety": { "type": "boolean", "description": "安全機器（安全 PLC・安全リレー・非常停止・ライトカーテン・安全扉スイッチなど）なら true。省略すると一般の機器。" },
          "controller": { "type": "string", "description": "所属先。リモート I/O（kind が io）は入出力として使う PLC（plc）の devices[].id、I/O ユニット（unit）は連結している PLC か リモート I/O の devices[].id。配線の M に PLC の名前が出て、メモリマップではその中のブロックになる。省略可。" }
        }
      }
    },
    "links": {
      "type": "array",
      "description": "機器どうしの通信。",
      "items": {
        "type": "object",
        "required": ["id", "from", "to"],
        "properties": {
          "id": { "$ref": "common.schema.json#/$defs/id", "description": "この通信の識別子。" },
          "from": { "type": "string", "description": "つなぐ機器の devices[].id。" },
          "to": { "type": "string", "description": "つなぐ機器の devices[].id。" },
          "kind": { "type": "string", "description": "ネットワークの種類（EtherCAT / EtherNet/IP / CC-Link IE / RS-485 など）。文字列をそのまま書く。" },
          "label": { "type": "string", "description": "線に添える文字（例 局番 1）。" },
          "fromAddr": { "type": "string", "description": "from の機器の、この線（ポート）での番地。IP アドレス（/n 付きも）か局番（例 \"192.168.3.39/24\"・\"局番 1\"）。無ければ書かない。機器が 2 つのネットワークに出ているとき、ネットワークごとの番地を書き分ける。" },
          "toAddr": { "type": "string", "description": "to の機器の、この線（ポート）での番地。書き方は fromAddr と同じ。" },
          "dir": { "enum": ["both", "one"], "description": "\"both\"（双方向・既定）か \"one\"（片方向）。" },
          "safety": { "type": "boolean", "description": "安全の通信・安全配線なら true（二重線で描く）。kind が CC-Link IE Safety / FSoE / CIP Safety / PROFIsafe / 安全配線 の線は、書かなくても安全の線。" },
          "style": { "enum": ["bus", "serial", "io", "power"], "description": "その他と、一覧（EtherCAT / EtherNet/IP / CC-Link IE / CC-Link / PROFINET / Modbus TCP / MECHATROLINK / Ethernet / RS-232C / RS-485 / Modbus RTU / USB / デジタル I/O / アナログ I/O / パルス列 / ユニット連結 / CC-Link IE Safety / FSoE / CIP Safety / PROFIsafe / 安全配線）に無い名前の線の描き方。bus（通信・既定）/ serial（シリアル）/ io（配線）/ power（電源。M / S を持たず、通信のつながりに数えない）。一覧にある種類（その他を除く）の線では書かない。" },
          "master": { "type": "string", "description": "マスター側の機器の devices[].id（from か to）。省略するとマスター / スレーブの指定なし。配線（デジタル I/O・アナログ I/O・パルス列・安全配線、style が io / power の線）とユニット連結では使わない。一方が HUB（net）の線では、HUB の先の機器の id も書ける（HUB は素通り）。同じ種類の線で数珠つなぎにした先の機器の id も書ける（PLC ─EtherCAT─ X ─EtherCAT─ Y の X ─ Y の線のマスターは PLC。ほかの PLC の先へは続かない。RS-232C・USB は数珠つなぎにしない）。" },
          "waypoints": { "type": "array", "items": { "$ref": "common.schema.json#/$defs/point" }, "description": "手で整えた線の経路。ふつうは省略する。" }
        }
      }
    },
    "variables": { "type": "array", "items": { "$ref": "common.schema.json#/$defs/variable" }, "description": "メモリマップへ受け渡すときに使う。空でも構わない。" },
    "triggers": { "type": "array", "items": { "$ref": "common.schema.json#/$defs/trigger" }, "description": "タイミングチャートへ受け渡すときに使う。空でも構わない。" }
  }
}
