main
John Lauer
Correct R7 clamp fault power on board27; publish exact resistor assets, simulations and forming-study evidence without…
11c16d0
"""Isolate the R7 fault-power correction; preserve every copper/net/model object."""
from pathlib import Path
import copy,hashlib,json,shutil
import sexp
root=Path(__file__).resolve().parents[1];out=root/'checkpoints/r7-fault-review';out.mkdir(exist_ok=True)
source=root/'aiflow/run/board-26.kicad_pcb';board=out/'r7-candidate.kicad_pcb'
for folder in ['3d','lib']:shutil.copytree(root/'aiflow/run'/folder,out/folder,dirs_exist_ok=True)
shutil.copyfile(root/'aiflow/run/fp-lib-table',out/'fp-lib-table')
for ext in ['kicad_pro','kicad_dru']:shutil.copyfile(source.with_suffix('.'+ext),board.with_suffix('.'+ext))
for f in (root/'kicad').glob('*.kicad_sch'):shutil.copyfile(f,out/f.name)
shutil.copyfile(root/'kicad/sym-lib-table',out/'sym-lib-table')
rows=[]
for source,dest,tag in [(source,board,'footprint'),(root/'kicad/servo.kicad_sch',out/'servo.kicad_sch','symbol')]:
t=sexp.parse(source.read_text());old=copy.deepcopy(t)
fp=next(f for f in sexp.find(t,tag) if any(p[1:3]==['Reference','R7'] for p in sexp.find(f,'property')))
props={p[1]:p for p in sexp.find(fp,'property')};assert props['Value'][2]=='1k' and props['MPN'][2]=='CR0402-FX-1001GLF'
props['Value'][2]='4.7k';props['MPN'][2]='ERJ-2RKF4701X';dest.write_text(sexp.dump(t)+'\n');assert sexp.parse(dest.read_text())==t
props['Value'][2]='1k';props['MPN'][2]='CR0402-FX-1001GLF';assert t==old
rows.append({'source':str(source.relative_to(root)),'sourceSha256':hashlib.sha256(source.read_bytes()).hexdigest(),'candidate':str(dest.relative_to(root)),'candidateSha256':hashlib.sha256(dest.read_bytes()).hexdigest(),'onlyValueAndMpnChanged':True})
(out/'selection-review.json').write_text(json.dumps({'adopted':False,'change':{'reference':'R7','old':'1k CR0402-FX-1001GLF 0.0625W','candidate':'4.7k ERJ-2RKF4701X 0.1W'},'files':rows,'copperNetsModelsAndPadsUnchanged':True,'scope':'Fault-power design correction candidate; native, dynamic, temperature and assembly qualification remain separate'},indent=2)+'\n')
print(json.dumps({'candidate':str(board),'onlyValueAndMpnChanged':True}))