imrishabh18/pedometer

This code defines and assembles a simple radio receiver hardware circuit using specific imported capacitors, inductors, RF connectors, and oscillator components with precise footprints and schematic attributes.

Version
1.1.3
License
unset
Stars
0

scripts/check-programming.ts

import fs from "node:fs";
import { createHash } from "node:crypto";
import { PcbConnectivityMap } from "circuit-json-to-connectivity-map";
const bytes=fs.readFileSync("dist/index/circuit.json");
const c:any[]=JSON.parse(bytes.toString());
const pcb=new PcbConnectivityMap(c);
const sourceComponent=(ref:string)=>c.find(e=>e.type==="source_component"&&e.name===ref);
const sourcePort=(ref:string,pin:number)=>c.find(e=>e.type==="source_port"&&e.source_component_id===sourceComponent(ref)?.source_component_id&&e.pin_number===pin);
const port=(ref:string,pin:number)=>c.find(e=>e.type==="pcb_port"&&e.source_port_id===sourcePort(ref,pin)?.source_port_id)?.pcb_port_id;
const net=(ref:string,pin:number)=>{
 const id=sourcePort(ref,pin)?.source_port_id;
 const trace=c.find(e=>e.type==="source_trace"&&e.connected_source_port_ids?.includes(id));
 return c.find(e=>e.type==="source_net"&&trace?.connected_source_net_ids?.includes(e.source_net_id))?.name;
};
const connections=[
 {name:"VTREF",connectorPin:1,mcuPin:11,net:"VDD_2V5"},
 {name:"SWDIO",connectorPin:2,mcuPin:7,net:"SWDIO"},
 {name:"SWCLK",connectorPin:3,mcuPin:8,net:"SWCLK"},
 {name:"GND",connectorPin:4,mcuPin:25,net:"GND"},
 {name:"RESET_N",connectorPin:5,mcuPin:13,net:"RESET_N"},
];
for(const item of connections){
 if(net("J4",item.connectorPin)!==item.net||net("U1",item.mcuPin)!==item.net)throw new Error(`${item.name}: incorrect source pin map`);
 const a=pcb.getAllTracesConnectedToPort(port("J4",item.connectorPin));
 const b=pcb.getAllTracesConnectedToPort(port("U1",item.mcuPin));
 if(!a.some(x=>b.some(y=>pcb.areTracesConnected(x.pcb_trace_id,y.pcb_trace_id))))throw new Error(`${item.name}: no physical copper path from J4 to MCU`);
}
if(net("R14",1)!=="VDD_2V5"||net("R14",2)!=="RESET_N"||net("C24",1)!=="RESET_N"||net("C24",2)!=="GND")throw new Error("Reset bias network mismatch");
const report={checkedAt:new Date().toISOString(),circuitSha256:createHash("sha256").update(bytes).digest("hex"),result:"PASS",mcu:"CC2340R52E0RGER",targetVoltageV:2.5,connections,scope:"Source pin map and routed copper continuity; hardware flash/readback requires an assembled prototype."};
fs.writeFileSync("review/programming-check.json",JSON.stringify(report,null,2));
console.log("PASS: all five J4 programming connections reach the MCU through routed copper; reset bias verified.");