MustafaMulla29/rp2040-bldc-motor-controller-new
A USB‑C PD–powered RP2040 BLDC motor controller PCB with 3.3 V logic, MCT8329A sensorless commutation, three MOSFET half-bridges, protected power switching, USB data, controls, and motor connectors.
- Version
- 0.3.82
- License
- unset
- Stars
- 0
scripts/check-integration.mjs
/** Verify the package wrapper adds mechanical CAD without changing the board. */
import assert from "node:assert/strict"
import { createHash } from "node:crypto"
import { readFileSync, writeFileSync } from "node:fs"
import { resolve } from "node:path"
import { hashPcbGeometry } from "./assembly-geometry.ts"
const root = resolve(import.meta.dirname, "..")
const bytes = path => readFileSync(resolve(root, path))
const json = path => JSON.parse(bytes(path))
const sha = value => createHash("sha256").update(value).digest("hex")
const boardBytes = bytes("dist/index/circuit.json")
const board = JSON.parse(boardBytes), system = json("dist/system/circuit.json")
const provenance = json("assets/connected-system.provenance.json")
const records = (rows, prefix) => rows.filter(row => row.type.startsWith(prefix))
assert.equal(provenance.pcbGeometrySha256, hashPcbGeometry(board), "Assembly asset is stale; run bun run build:all locally")
assert.equal(provenance.mechanicalAssetSha256, sha(bytes("assets/connected-system.glb")))
assert.deepEqual(records(system, "pcb_"), records(board, "pcb_"), "Package changed the PCB")
// Normalize optional nulls from different native serializer versions, not geometry.
const normalize = rows => JSON.parse(JSON.stringify(rows, (_, v) => v === null ? undefined : v))
assert.deepEqual(normalize(records(system, "schematic_")), normalize(records(board, "schematic_")), "Package changed the schematic")
for (const type of ["source_port", "source_net", "source_trace", "source_component_internal_connection"]) {
assert.deepEqual(system.filter(r => r.type === type), board.filter(r => r.type === type), `Changed ${type}`)
}
assert.equal(system.filter(r => r.type.endsWith("_error")).length, 0)
const assembly = system.find(r => r.type === "source_component" && r.name === "CONNECTED_EXTERNAL_ASSEMBLY")
assert.ok(assembly, "Missing mechanical assembly")
const cad = system.find(r => r.type === "cad_component" && r.source_component_id === assembly.source_component_id)
assert.ok(cad?.model_glb_url?.endsWith("assets/connected-system.glb"))
assert.ok(!cad.pcb_component_id, "Off-board assembly must not create a PCB footprint")
assert.equal(system.filter(r => r.type === "cad_component").length, board.filter(r => r.type === "cad_component").length + 1)
const result = {
status: "PASS", pcbUnchanged: true, schematicUnchanged: true, connectivityUnchanged: true,
nativeErrors: 0, nativePcbBoards: system.filter(r => r.type === "pcb_board").length,
pcbCircuitSha256: sha(boardBytes), integratedCircuitSha256: sha(bytes("dist/system/circuit.json")),
mechanicalAssetSha256: provenance.mechanicalAssetSha256,
nativeMotorLeads: provenance.nativeMotorLeads, rigidAdapters: provenance.rigidAdapters,
nativeUsbCables: provenance.nativeUsbCables,
}
writeFileSync(resolve(root, "dist/system/integration-check.json"), JSON.stringify(result, null, 2) + "\n")
console.log("PASS: one native PCB; identical copper, schematic and connectivity; motor, 3 rigid adapters, 3 leads and 2 USB cables included")