67 行
3.4 KiB
Python
67 行
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
u"""补线器:在**现有铜**之上只布没接完的那几个网(不动其它任何线)。
|
||
|
||
# 刀片 90×68 起:只在服务器上算(CLAUDE.md),入口
|
||
MODE=repair bash .claude/r2/remote_blade.sh +12V_F +5V # `$` 写成 `@`
|
||
# 服务器上实际跑的是:
|
||
DCDC_ROUTE_SERVER=1 pypy3 .claude/r2/repair_route.py --cache +12V_F +5V
|
||
|
||
`--cache`:现有铜取 `_blade_routes.json`(布线缓存),补完把**合并后的完整缓存**写到
|
||
`_blade_routes.repaired.json`(比过再手动拷成 `_blade_routes.json`,然后 `router.py --push`)。
|
||
不带 `--cache` 是 M6 的老用法:现有铜从 `_m6_board_copper.json`(板上读回)来,结果写 `_m6_repair.json`。
|
||
|
||
现有铜按网名打进占用图 —— 同网可穿,所以 A* 从没接上的焊盘出发,碰到本网已有的铜就算到了。
|
||
"""
|
||
import io, json, os, sys, math
|
||
sys.stdout.reconfigure(encoding='utf-8')
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
sys.path.insert(0, os.path.dirname(HERE)); sys.path.insert(0, HERE)
|
||
import router as RT
|
||
import pcb_rules as R
|
||
|
||
if not os.environ.get('DCDC_ROUTE_SERVER'):
|
||
sys.exit(u'⛔ 补线(A*)只在 10.5.5.13 上跑(CLAUDE.md):MODE=repair bash .claude/r2/remote_blade.sh <网名...>')
|
||
|
||
CACHE_MODE = '--cache' in sys.argv
|
||
NETS = [a.replace('@', '$') for a in sys.argv[1:] if not a.startswith('--')] or \
|
||
['VDAC', '$1N147', '$1N156', 'EFUSE_PG', '$1N165', 'VO', '+3V3', 'VBUS', 'SDA']
|
||
src = '_blade_routes.json' if CACHE_MODE else '_m6_board_copper.json'
|
||
cp = json.load(io.open(os.path.join(HERE, src), encoding='utf-8'))
|
||
segs = [tuple(s) for s in cp['segs']]
|
||
vias = [tuple(v) for v in cp['vias']]
|
||
pads = RT.load_pads()
|
||
auto = R.resolve_auto()
|
||
# 固定障碍的过孔:M6 读回的板上只有 GND 缝合孔;缓存里另有 D± 构造的两个孔(plan_all 同样把它们记进 board_vias)
|
||
fixed = ('GND',) + (RT.DP_NETS if CACHE_MODE else ())
|
||
board_vias = [(v[0], v[1], v[2], RT.VIA_D) for v in vias if v[2] in fixed]
|
||
_fs, _fv, launch = RT.finger_escape()
|
||
bypad = {}
|
||
for p in pads:
|
||
if p[0] == 'J1' or not p[7] or p[7] in RT.SKIP:
|
||
continue
|
||
bypad.setdefault(p[7], []).append(p)
|
||
for net, pts in launch.items():
|
||
for (lay, x, y) in pts:
|
||
bypad.setdefault(net, []).append(['J1', 'launch', x, y, 0.3, 0.3, lay, net, 'RECT'])
|
||
print(u'补 %s(现有铜:%s,%d 段 / %d 孔)' % (' '.join(NETS), src, len(segs), len(vias)))
|
||
n0, v0 = len(segs), len(vias)
|
||
logs = RT.route_groups(bypad, pads, segs, vias, board_vias, auto,
|
||
priority=tuple(NETS), only=set(NETS))
|
||
new_s, new_v = segs[n0:], vias[v0:]
|
||
print(u'新增 %d 段 / %d 孔' % (len(new_s), len(new_v)))
|
||
for m in logs:
|
||
print(u' [!] ' + m)
|
||
left = RT.check_connected(pads, segs, vias)
|
||
print(u'连通性复查(布线器口径,会误报,以 blade_conn.py 为准):%s' % (u'全通' if not left else left))
|
||
if CACHE_MODE:
|
||
out = {'segs': [list(s) for s in segs], 'vias': [list(v) for v in vias],
|
||
'logs': list(logs) + [u'[连通性] ' + m for m in left], 'repaired': NETS}
|
||
json.dump(out, io.open(os.path.join(HERE, '_blade_routes.repaired.json'), 'w', encoding='utf-8'),
|
||
ensure_ascii=False)
|
||
print(u'已写 _blade_routes.repaired.json(合并后的完整缓存)')
|
||
else:
|
||
json.dump({'segs': new_s, 'vias': new_v},
|
||
io.open(os.path.join(HERE, '_m6_repair.json'), 'w', encoding='utf-8'))
|
||
if '--push' in sys.argv and new_s:
|
||
RT.push(new_s, new_v)
|