[WORK] Link View: связи по разъёмам (HDMI/USB/USB-C/VCH/LAN/3.5mm), порты с источником (даташит/извлечено/роль), запрет UVC86 HDMI+MVC

This commit is contained in:
root committed 2026-11-06 16:02:51 +03:00
1 parent b433314eae
commit daffbe41dd
5 files changed
+582 -24

No files matched your search

+82
View File
@@ -57,6 +57,7 @@ class Data:
self.protocols = load_yaml("protocols.yaml")
self.mounts = load_yaml("mounts.yaml")
self.iface = load_yaml("interfaces_verified.yaml")
self.iface_auto = load_yaml("interfaces.yaml")
self.dante = load_yaml("dante.yaml")
self.devices = {norm(d["name"]): {"name": d["name"], "role": d.get("role", "unknown")}
for d in self.cat.get("devices") or []}
@@ -75,8 +76,11 @@ class Data:
for x in self.dante.get("dante_devices") or []:
self.feats.setdefault(norm(x.get("device")), set()).add("Dante")
self.iface_map = {}
self.iface_auto_map = {}
for x in (self.iface.get("devices") or []):
self.iface_map[norm(x["device"])] = x
for x in (self.iface_auto.get("devices") or []):
self.iface_auto_map[norm(x["device"])] = x
self.mounts_map = {}
for e in self.mounts.get("edges") or []:
self.mounts_map.setdefault(norm(e["host"]), []).append(e["mount"])
@@ -237,6 +241,81 @@ class Data:
return {"host": self.devices[hk]["name"], "host_role": host_role,
"positions": out}
# какие разъёмы соединяются между собой
LINKABLE = {
("HDMI", "HDMI"): "видео",
("USB", "USB"): "данные",
("USB-C", "USB-C"): "данные + видео",
("USB", "USB-C"): "данные (через переходник)",
("VCH", "VCH"): "аудио + питание",
("LAN", "LAN"): "сеть / PoE",
("3.5mm", "3.5mm"): "аналоговый звук",
("DP", "DP"): "видео",
}
# запреты из официальных даташитов
FORBIDDEN = [
{"device": "UVC86", "port": "HDMI", "host_contains": "mvc",
"reason": "HDMI-выход UVC86 совместим с VCS, но НЕ с MVC (даташит)"},
]
def device_ports(self, name):
"""Порты: проверенные -> извлечённые -> по роли. Возвращает (in, out, source)."""
k = norm(name)
if k in self.iface_map:
v = self.iface_map[k]
return (v.get("in") or ["—"], v.get("out") or ["—"], "verified")
if k in self.iface_auto_map:
v = self.iface_auto_map[k]
ins = [p for p in (v.get("in") or []) if p]
outs = [p for p in (v.get("out") or []) if p]
if ins or outs:
return (ins or ["—"], outs or ["—"], "auto")
ins, outs = self.ports(name)
return (ins, outs, "role")
def link_plan(self, host_key, items):
"""План связей: каждый аксессуар -> хост, по совместимости разъёмов."""
hk = norm(host_key)
host = self.devices.get(hk, {}).get("name", host_key)
h_in, h_out, h_src = self.device_ports(host)
links = []
for row in items:
model = row[0] if isinstance(row, (list, tuple)) else row
acc_in, acc_out, src = self.device_ports(model)
link = {"device": model, "host": host, "ok": False,
"from_port": None, "to_port": None, "type": None,
"source": src, "reason": None}
# ищем пару: выход аксессуара -> вход хоста (и наоборот)
pairs = []
for a in acc_out:
for b in h_in:
if (a, b) in self.LINKABLE:
pairs.append((a, b, self.LINKABLE[(a, b)]))
elif (b, a) in self.LINKABLE:
pairs.append((a, b, self.LINKABLE[(b, a)]))
for a in h_out:
for b in acc_in:
if (a, b) in self.LINKABLE:
pairs.append((a, b, self.LINKABLE[(a, b)]))
if pairs:
p = pairs[0]
link.update({"ok": True, "from_port": p[0], "to_port": p[1],
"type": p[2]})
else:
link["reason"] = ("нет совместимого разъёма: %s in=%s out=%s / хост in=%s out=%s"
% (model, ",".join(acc_in) or "-", ",".join(acc_out) or "-",
",".join(h_in) or "-", ",".join(h_out) or "-"))
# запреты
for fb in self.FORBIDDEN:
if norm(fb["device"]) == norm(model) and \
fb["host_contains"] in norm(host) and \
(link.get("from_port") == fb["port"] or link.get("to_port") == fb["port"]):
link.update({"ok": False, "forbidden": True, "reason": fb["reason"]})
links.append(link)
return {"host": host, "host_ports": {"in": h_in, "out": h_out, "source": h_src},
"links": links}
# ── проверка ёмкости хоста ──
def capacity(self, host_key, items):
"""items: [[model, qty], ...]. Проверяет порты VCH, лимиты, питание."""
@@ -498,6 +577,9 @@ class H(BaseHTTPRequestHandler):
if p == "/api/positions":
return self._out(D.positions(q.get("host", [""])[0],
[x for x in q.get("need", []) if x]))
if p == "/api/links":
items = [x for x in q.get("item", []) if x]
return self._out(D.link_plan(q.get("host", [""])[0], items))
if p == "/api/capacity":
items = []
for raw in q.get("item", []):
+54 -24
View File
@@ -216,34 +216,64 @@ async function capacity(){
${c.notes.length?`<div class="muted" style="margin-top:6px">${c.notes.join('<br>')}</div>`:''}
${c.missing_power.length?`<div class="box">нет данных о питании: ${c.missing_power.join(', ')}</div>`:''}`;
}
function scheme(){
const hk=$('#host').value, name=HOSTS.find(h=>h.key===hk)?.name||hk;
const nodes=[{model:name,role:'Хост',qty:1,central:true,ins:['LAN'],outs:['HDMI','USB','VCH']}];
Object.keys(SEL).forEach(k=>nodes.push({model:k,role:SEL[k].role,qty:SEL[k].qty,ins:['LAN'],
outs:[/амер|исплей/i.test(SEL[k].role)?'HDMI':/ронштейн/i.test(SEL[k].role)?'—':'USB']}));
draw({nodes});
async function scheme(){
const hk=$('#host').value, host=HOSTS.find(h=>h.key===hk)?.name||hk;
const ks=Object.keys(SEL);
const q=ks.map(k=>'item='+encodeURIComponent(k)).join('&');
const lp=await J(`/api/links?host=${hk}&${q}`);
renderLinks(lp);
$('#schemecard').classList.remove('hidden');
drawLinks(lp, host);
}
const COLOR={HDMI:'#2f81f7',USB:'#3fb950',VCH:'#a371f7',LAN:'#d29922','—':'#8b949e'};
function draw(sc){
function renderLinks(lp){
const ok=lp.links.filter(l=>l.ok).length, bad=lp.links.filter(l=>!l.ok);
let html=`<div class="kv" style="margin-bottom:8px">
<div>порты хоста (вход)</div><div><b>${(lp.host_ports.in||[]).join(', ')||'—'}</b></div>
<div>порты хоста (выход)</div><div><b>${(lp.host_ports.out||[]).join(', ')||'—'}</b></div>
<div>источник портов</div><div><b>${lp.host_ports.source==='verified'?'даташит':lp.host_ports.source==='auto'?'извлечено':'по роли'}</b></div>
</div>
<div class="box ${ok===lp.links.length?'ok':''}">
связей собрано: <b>${ok}</b> из ${lp.links.length}
${bad.length?`<br>✗ ${bad.map(l=>l.device+': '+(l.reason||'нет пары')).join('<br>✗ ')}`:''}
</div>`;
$('#schemecard').querySelector('h3').innerHTML='Link View — связи по разъёмам';
let extra=document.getElementById('linkinfo');
if(!extra){extra=document.createElement('div');extra.id='linkinfo';$('#schemecard').appendChild(extra);}
extra.innerHTML=html;
}
const COLOR={HDMI:'#2f81f7',USB:'#3fb950','USB-C':'#3fb950',VCH:'#a371f7',LAN:'#d29922','3.5mm':'#8b949e',DP:'#a371f7',PHOENIX:'#8b949e','—':'#484f58'};
function drawLinks(lp, hostname){
const svg=$('#svg');svg.innerHTML='';
const c=sc.nodes.find(n=>n.central)||sc.nodes[0], others=sc.nodes.filter(n=>n!==c);
const W=960,H=460,cx=W/2,cy=H/2,bw=170,bh=80;
const cx=480,cy=230,bw=180,bh=90;
const good=lp.links.filter(l=>l.ok), bad=lp.links.filter(l=>!l.ok);
const all=lp.links;
let s='';
others.forEach((n,i)=>{const a=(2*Math.PI*i)/Math.max(others.length,1)-Math.PI/2;
const x=cx+320*Math.cos(a),y=cy+160*Math.sin(a);
s+=`<path d="M ${cx+bw/2} ${cy} C ${cx+110} ${cy}, ${x-130} ${y}, ${x-bw/2} ${y}" fill="none" stroke="${COLOR[(n.outs||['—'])[0]]||'#8b949e'}" stroke-width="2" opacity=".85"/>`;});
others.forEach((n,i)=>{const a=(2*Math.PI*i)/Math.max(others.length,1)-Math.PI/2;
const x=cx+320*Math.cos(a),y=cy+160*Math.sin(a);s+=box(n,x-bw/2,y-36,bw,72);});
s+=box(c,cx-bw/2,cy-bh/2,bw,bh,true);svg.innerHTML=s;
}
function box(n,x,y,w,h,central){
let s=`<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="10" fill="${central?'#132239':'#161b22'}" stroke="${central?'#2f81f7':'#30363d'}" stroke-width="${central?2:1.2}"/>`;
s+=`<text x="${x+11}" y="${y+19}" fill="#e6edf3" font-size="12" font-weight="600">${esc(n.model).slice(0,23)}</text>`;
s+=`<text x="${x+11}" y="${y+33}" fill="#8b949e" font-size="10">${esc(n.role)}${n.qty>1?' ×'+n.qty:''}</text>`;
let a=y+48;(n.ins||[]).forEach(p=>{s+=`<circle cx="${x}" cy="${a}" r="4" fill="${COLOR[p]||'#8b949e'}"/><text x="${x+9}" y="${a+3.5}" fill="#8b949e" font-size="9">in ${esc(p)}</text>`;a+=12;});
let b=y+48;(n.outs||[]).forEach(p=>{s+=`<circle cx="${x+w}" cy="${b}" r="4" fill="${COLOR[p]||'#8b949e'}"/><text x="${x+w-9}" y="${b+3.5}" fill="#8b949e" font-size="9" text-anchor="end">out ${esc(p)}</text>`;b+=12;});
return s;
// хост
s+=`<rect x="${cx-bw/2}" y="${cy-bh/2}" width="${bw}" height="${bh}" rx="10" fill="#132239" stroke="#2f81f7" stroke-width="2"/>`;
s+=`<text x="${cx-bw/2+12}" y="${cy-bh/2+20}" fill="#e6edf3" font-size="12.5" font-weight="600">${esc(hostname).slice(0,24)}</text>`;
s+=`<text x="${cx-bw/2+12}" y="${cy-bh/2+34}" fill="#8b949e" font-size="10">хост · ${lp.host_ports.source}</text>`;
// порты хоста
(lp.host_ports.in||[]).slice(0,4).forEach((p,i)=>{
const y=cy-bh/2+52+i*12;
s+=`<circle cx="${cx-bw/2}" cy="${y}" r="4" fill="${COLOR[p]||'#8b949e'}"/><text x="${cx-bw/2+9}" y="${y+3.5}" fill="#8b949e" font-size="9">in ${esc(p)}</text>`;
});
(lp.host_ports.out||[]).slice(0,4).forEach((p,i)=>{
const y=cy-bh/2+52+i*12;
s+=`<circle cx="${cx+bw/2}" cy="${y}" r="4" fill="${COLOR[p]||'#8b949e'}"/><text x="${cx+bw/2-9}" y="${y+3.5}" fill="#8b949e" font-size="9" text-anchor="end">out ${esc(p)}</text>`;
});
// аксессуары
all.forEach((l,i)=>{
const a=(2*Math.PI*i)/Math.max(all.length,1)-Math.PI/2;
const x=cx+300*Math.cos(a), y=cy+150*Math.sin(a);
const col=l.ok?(COLOR[l.from_port]||'#3fb950'):'#f85149';
const dash=l.ok?'':'stroke-dasharray="5 4"';
s+=`<path d="M ${cx} ${cy} L ${x} ${y}" stroke="${col}" stroke-width="2" ${dash} opacity=".8" fill="none"/>`;
s+=`<rect x="${x-78}" y="${y-26}" width="156" height="52" rx="9" fill="#161b22" stroke="${col}" stroke-width="1.3"/>`;
s+=`<text x="${x}" y="${y-7}" text-anchor="middle" fill="#e6edf3" font-size="11.5" font-weight="600">${esc(l.device).slice(0,22)}</text>`;
s+=`<text x="${x}" y="${y+8}" text-anchor="middle" fill="#8b949e" font-size="9.5">${l.ok?esc(l.from_port)+' → '+esc(l.to_port):'нет пары'}</text>`;
s+=`<text x="${x}" y="${y+19}" text-anchor="middle" fill="#8b949e" font-size="9">${l.source==='verified'?'даташит':l.source==='auto'?'извлечено':'по роли'}</text>`;
});
svg.innerHTML=s;
}
function esc(s){return String(s).replace(/[<>&]/g,c=>({'<':'&lt;','>':'&gt;','&':'&amp;'}[c]))}
boot();