文件
phonerail/.claude/port_audit.py
zhou yang和Claude Opus 5 efcba30a0c R2 底板改 4 层(D15):规则 / 几何 / 背面摆位 / 4 层布线与铺铜,已下发
- 规则:铜层 2→4,差分 0.28/0.18,间距 0.15,过孔 0.3/0.2(rules_base)
- 几何:98×98 板框 + 4×M3,槽阵居中,L1 12V 大铜 + 指头(pcb_base)
- 摆位:五插槽留 L1,其余 133 件翻到 L4;背面镜像规则实测;Hub 放走廊 2、
  东移 2.5 mm;扇出圈 / 小件间距 1.5(去耦例外)/ 9 A 过孔阵禁区(place_base)
- 叠层按用户决定改为 L1 槽面 / L2 整层 +3V3 / L3 整层 GND / L4 器件面
- 布线:D± 七对按构造布通(USB3 掉头、USB1/2 北去掉头、USB4/5 东绕、
  J23 桥),+3V3 / GND / +12V 平面网每脚一孔,0.125 网格 + PathFinder
  开关(route_base、remote_route.ps1);剩 37 个网待手工补
- 铺铜:4 层重写,入口链自南向北切段 + 断面校核(pour_base);
  已下发布线 / 缝合孔 / 铜面轮廓,填铜未成功(待查)
- 工具:plot_base / plot_routes / shot_base,board_check 通孔两层都算

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0168Bu6SEx3cXXCJLkdnE6zB
2026-09-10 21:02:10 +08:00

144 行
6.0 KiB
Python

# -*- coding: utf-8 -*-
u"""全工程扫一遍「旗/端口的引脚有没有真的接在导线端点上」。
/c/Python314/python .claude/port_audit.py
## 为什么需要它(2026-09-03 踩到的第三种断线)
`verify_sch.py` 判端口连接的条件是「引脚**落在导线上**」。这个条件太松:
EasyEDA Pro 只在**导线端点**处认连接,引脚压在一条导线的**中段**是不连的 ——
渲染出来看着完全正常,DRC 不报,`verify_sch --nets` 也算它连上。
实测证据(P1-INPUT,U13 INA226):
| 端口 | 引脚坐标 | 落在 | PCB 里的网络 |
|---|---|---|---|
| SDA | (910, 380) | 导线 **端点** `[910,380 → 910,570]` | `SDA` ✅ |
| SCL | (920, 340) | 导线 **中段** `[920,320 → 920,570]` | `$1N257` ❌ |
后果:U13 的 SCL 没接上 I²C 总线,**输入侧检流整片芯片是死的**,
而且因为 A0 就搭在这个节点上,地址 0x43 也无从谈起。
## 三种「几何过、电气不过」的断法(本工程都真踩过)
1. **零长度导线**:端口引脚与元件引脚同坐标,中间那段导线长度为 0(skill §8a)。
2. **中段搭接**:端口引脚压在导线中段而非端点(本文件抓的就是这个)。
3. **只有名字没有线**:旗/端口悬空,`verify_sch` 的「无网络名」那一条能抓。
## 判定口径
- `端点` —— 引脚与某条导线的首/末点重合 → 正常。
- `顶点` —— 引脚与折线的中间顶点重合 → **可疑**(同样不是端点)。
- `中段` —— 引脚落在某段的内部 → **可疑**。
- `悬空` —— 压根不在任何导线上 → 可疑(除非它和元件引脚同坐标,那是第 1 类)。
坐标单位是原理图的 0.01 inch,全工程都吸附在 5 的倍数上,所以容差取 0.6 足够。
"""
import io, json, os, sys
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
from eda import run
TOL = 0.6
_CACHE = json.load(io.open(os.path.join(HERE, 'eda-parts.json'), encoding='utf-8'))
# 默认扫下板;`--board Board2` 扫载板(两块板的页表都在 eda-parts.json 里)
# `--r2 BLADE` / `--r2 BASE` 扫 R2 刀片式工程(页表在 .claude/r2/r2-uuids.json)——
# ⚠ 它只按 uuid 打开文档,不切工程:跑之前先让客户端停在 PhoneRail-R2 上。
if '--r2' in sys.argv:
_b = sys.argv[sys.argv.index('--r2') + 1]
PAGES = json.load(io.open(os.path.join(HERE, 'r2', 'r2-uuids.json'),
encoding='utf-8'))['boards'][_b]['pages']
elif '--board' in sys.argv:
_b = sys.argv[sys.argv.index('--board') + 1]
PAGES = _CACHE['schematic_boards'][_b]['pages']
else:
PAGES = _CACHE['pages']
JS = u"""
await eda.dmt_EditorControl.openDocument('%s');
await new Promise(r => setTimeout(r, 1200));
const polys = [];
for (const w of await eda.sch_PrimitiveWire.getAll()) {
const l = w.getState_Line();
if (!l || l.length < 4) continue;
// ⚠ getState_Line() 返回的是**端点对**(每 4 个数一段),不是折线路径。
// 当折线解析会凭空造出斜线段,进而把 197 个好的 GND 旗误报成可疑。
for (let i = 0; i + 3 < l.length; i += 4)
polys.push([[Math.round(l[i]), Math.round(l[i+1])], [Math.round(l[i+2]), Math.round(l[i+3])]]);
}
const ports = [], pins = [];
for (const c of await eda.sch_PrimitiveComponent.getAll()) {
const t = c.getState_ComponentType();
let nn = null; try { nn = c.getState_Net ? c.getState_Net() : null; } catch (e) {}
const ps = await c.getAllPins();
for (const q of (ps || [])) {
const rec = [Math.round(q.getState_X()), Math.round(q.getState_Y())];
if (t === 'netport' || t === 'netflag') ports.push({t, net: nn, d: c.getState_Designator() || '', x: rec[0], y: rec[1]});
else pins.push({d: c.getState_Designator() || '', n: q.getState_PinNumber(), x: rec[0], y: rec[1]});
}
}
return {polys, ports, pins};
"""
def near(ax, ay, bx, by):
return abs(ax - bx) <= TOL and abs(ay - by) <= TOL
def on_seg(px, py, ax, ay, bx, by):
u"""点在线段内部(不含两端)。只处理水平/垂直/斜的一般情况。"""
dx, dy = bx - ax, by - ay
if abs(dx) <= TOL and abs(dy) <= TOL:
return False
cross = (px - ax) * dy - (py - ay) * dx
if abs(cross) > TOL * max(1.0, (dx * dx + dy * dy) ** 0.5):
return False
dot = (px - ax) * dx + (py - ay) * dy
L2 = dx * dx + dy * dy
return TOL < dot < L2 - TOL
def classify(p, segs, pins):
u"""端点 = 连;其余三种都是真断线。"""
for a, b in segs:
if near(p['x'], p['y'], *a) or near(p['x'], p['y'], *b):
return u'端点'
for a, b in segs:
if on_seg(p['x'], p['y'], a[0], a[1], b[0], b[1]):
return u'中段'
for q in pins:
if near(p['x'], p['y'], q['x'], q['y']):
return u'压引脚'
return u'悬空'
def main():
bad = []
total = 0
for name, uuid in PAGES.items():
r = run(JS % uuid, timeout=120)
if not r.get('success'):
print(u'%-12s 读失败: %s' % (name, json.dumps(r, ensure_ascii=False)[:200]))
continue
d = r['result']
rows = []
for p in d['ports']:
total += 1
k = classify(p, [(s[0], s[1]) for s in d['polys']], d['pins'])
if k != u'端点':
rows.append((k, p))
print(u'%-12s 旗/端口 %3d 个,可疑 %d' % (name, len(d['ports']), len(rows)))
for k, p in sorted(rows, key=lambda kp: (kp[0], kp[1]["net"] or "", kp[1]["x"], kp[1]["y"])):
print(u' %-4s %-12s (%s) @ (%d, %d)' % (k, p['net'] or u'(无名)', p['t'], p['x'], p['y']))
bad.append((name, k, p))
print(u'')
print(u'合计 %d 个旗/端口,可疑 %d 个。' % (total, len(bad)))
if bad:
print(u'「中段」「顶点」「悬空」都是真断线;「压引脚」是零长度导线(skill §8a)。')
sys.exit(1 if bad else 0)
if __name__ == '__main__':
main()