pixalynx/nrf9151-gps-tracker
A compact 44×32 mm, 4-layer nRF9151 LTE-M/NB-IoT/GNSS tracker PCB with nPM1300 LiPo/USB-C power, nano-SIM/eSIM switching, nRF7002 Wi‑Fi scanning, accelerometer, antennas, buzzer, LEDs, SOS button, and SWD/debug connectors.
- Version
- 0.1.4
- License
- unset
- Stars
- 0
scripts/errors.py
#!/usr/bin/env python3
"""List every *error* element of dist/<entry>/circuit.json with element ids resolved to component.pin names.
Usage: python3 scripts/errors.py [entry=index] [--warnings]"""
import json, re, sys
entry = next((a for a in sys.argv[1:] if not a.startswith('--')), 'index')
d = json.load(open(f'dist/{entry}/circuit.json'))
src = {c['source_component_id']: c['name'] for c in d if c['type'] == 'source_component'}
comp = {c['pcb_component_id']: src.get(c['source_component_id'], '?') for c in d if c['type'] == 'pcb_component'}
ports = {c['pcb_port_id']: c for c in d if c['type'] == 'pcb_port'}
sp = {c['source_port_id']: c['name'] for c in d if c['type'] == 'source_port'}
names = {}
for c in d:
for k in ('pcb_smtpad_id', 'pcb_plated_hole_id', 'pcb_hole_id', 'pcb_courtyard_rect_id', 'pcb_courtyard_outline_id', 'pcb_via_id', 'pcb_trace_id'):
if k in c and c.get('type', '').startswith(k[:-3].replace('_id', '')) or (k in c and c['type'] == k[:-3]):
owner = comp.get(c.get('pcb_component_id'), '')
pin = sp.get(ports[c['pcb_port_id']]['source_port_id'], '') if c.get('pcb_port_id') in ports else ''
names[c[k]] = f"{owner}.{pin}" if pin else (owner or c[k])
kinds = ('error',) + (('warning',) if '--warnings' in sys.argv else ())
n = 0
for e in d:
if any(k in e['type'] for k in kinds):
msg = e.get('message', '')
msg = re.sub(r'pcb_(smtpad|plated_hole|hole|courtyard_rect|courtyard_outline|via|trace)_\d+', lambda m: names.get(m.group(0), m.group(0)), msg)
print(e['type'].replace('pcb_', ''), '|', msg[:200]); n += 1
print(f'-- {n} item(s)')