from pathlib import Path
import fitz,re,csv
R=Path(__file__).resolve().parent;p=fitz.open(R/'NXP_PCA9956B_Rev1p2.pdf');rows=[]
pattern=r'(GND|PD|FLT|PU|VDD)\s+(GND|PD|FLT|PU|VDD)\s+(GND|PD|FLT|PU|VDD)\s+(\d+)\s+([0-9A-F]{2})\s+[01]{7}(?:\[\d\])?\s+([0-9A-F]{2})h'
for i in range(6,10):
 for m in re.finditer(pattern,p[i].get_text()):rows.append((*m.groups(),str(i+1)))
states={'GND':0,'PD':1,'FLT':2,'PU':3,'VDD':4};assert len(rows)==125
for ad2,ad1,ad0,dec,hx,wr,page in rows:
 address=1+25*states[ad2]+5*states[ad1]+states[ad0]
 assert address==int(dec)==int(hx,16) and int(wr,16)==address*2
with (R/'manufacturer_address_table_check.csv').open() as f:stored=list(csv.reader(f))[1:]
assert stored==[list(r) for r in rows]
print('PASS:all125 manufacturer address rows match quinary mapping; saved CSV reproduces from actual PDF')
