| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912 |
- const VERIFIED = "cross_verified";
- const POWER_NET = /^(?:GND|AGND|DGND|PGND|EARTH|VCC|VDD|VBAT|PWR|\+)/i;
- const RTL_PORT = /^[A-Za-z_][A-Za-z0-9_$]*(?:\[[0-9]+\])?$/;
- const RESISTOR_REF = /^r(\d+)$/i;
- const RESISTOR_PAD = /^r(\d+)\.(\d+)$/i;
- const BALL_PREFIX = /^ball:(.+)$/i;
- const NET_PREFIX = /^net:(.+)$/i;
- const VALUE_PREFIX = /^value:(.+)$/i;
- const ENDPOINT = /^u\d+\.[a-z]+\d+$/i;
- const ANNOTATION_RESISTOR = /(?<![A-Za-z0-9.])R(\d+)\b/g;
- const VALUE_GRAMMAR = /^(?:\d+(?:\.\d+)?[rRkKmM]\d*|\d+[rRkKmM]|\d+(?:\.\d+)?(?:ohm|ohms|Ω)?)$/i;
- const PACKAGE_OR_DNP = /^(?:0603|0805|0402|1206|1210|2010|2512|dnp|nc|n\/?c)$/i;
- const CAPABILITY_ALIASES = {
- pwm: ["pwm", "pwm_output"],
- gpio_output: ["gpio_output", "digital_output"],
- gpio_input: ["gpio_input", "digital_input"],
- tach: ["tach", "tach_input"],
- fan_tach: ["fan_tach", "tach_input"],
- presence: ["presence", "presence_input"],
- };
- function text(value) {
- return value == null ? "" : String(value);
- }
- function normalized(value) {
- return text(value).trim().toLocaleLowerCase();
- }
- function naturalCompare(left, right) {
- return text(left).localeCompare(text(right), undefined, {numeric: true, sensitivity: "base"});
- }
- function capabilities(pin) {
- return Array.isArray(pin?.fpga?.capabilities) ? pin.fpga.capabilities.map(text) : [];
- }
- function baseBlockers(pin) {
- const blockers = [];
- if (pin?.evidence_tier !== VERIFIED || pin?.fpga?.evidence_tier !== VERIFIED) {
- blockers.push("unverified");
- }
- if (!pin?.fpga?.ball || !pin?.fpga?.io_standard) blockers.push("missing_fpga_assignment");
- if (pin?.mechanical === true || pin?.electrical !== true) blockers.push("mechanical_or_non_electrical");
- if (pin?.pad_role !== "contact") blockers.push("not_connector_contact");
- if (["power", "ground"].includes(pin?.function_category) || POWER_NET.test(text(pin?.net))) {
- blockers.push("power_or_ground");
- }
- if (pin?.reserved === true) blockers.push("reserved");
- if (pin?.fixed_load_conflict === true) blockers.push("fixed_load_conflict");
- if (["", "unknown"].includes(normalized(pin?.external_level))) blockers.push("external_level_unknown");
- return blockers;
- }
- export function connectorPinGroups(touchpoint) {
- const pins = Array.isArray(touchpoint?.pins) ? touchpoint.pins : [];
- const connector = touchpoint?.connector;
- const reviewed = connector?.review_status === VERIFIED;
- const grid = reviewed && Array.isArray(connector?.contact_grid) ? connector.contact_grid : [];
- const byNumber = new Map(
- pins
- .filter((pin) => pin?.pad_role === "contact" && text(pin?.number))
- .map((pin) => [text(pin.number), pin]),
- );
- const contactRows = grid.map((row) =>
- (Array.isArray(row) ? row : []).map((number) => byNumber.get(text(number))).filter(Boolean),
- );
- return {
- contactRows,
- contacts: contactRows.flat(),
- auxiliary: pins.filter((pin) => pin?.pad_role !== "contact"),
- };
- }
- function pinSearchFields(touchpoint, pin, boardVersion = "v2_0") {
- const programming = pin?.programming ?? {};
- const logical = resolveLogicalPin(touchpoint, pin, boardVersion);
- return [
- ["pin", `${touchpoint.reference}.${pin.number}`],
- ["reference", touchpoint.reference],
- ["pin_number", pin.number],
- ["net", pin.net],
- ["summary", pin.summary],
- ["function", pin.function_category],
- ["direction", pin.direction],
- ["external_level", pin.external_level],
- ["fpga_ball", pin.fpga?.ball],
- ["board_signal", pin.fpga?.board_signal],
- ["capability", capabilities(pin).join(" ")],
- ["mcu_device", pin.mcu?.device],
- ["mcu_family", pin.mcu?.family],
- ["mcu_pin", pin.mcu?.device && pin.mcu?.pin ? `${pin.mcu.device}.${pin.mcu.pin}` : ""],
- ["mcu_signal", pin.mcu?.signal],
- ["mcu_capability", Array.isArray(pin.mcu?.capabilities) ? pin.mcu.capabilities.join(" ") : ""],
- ["path", Array.isArray(pin.path) ? pin.path.join(" ") : ""],
- ["programming_conclusion", programming.conclusion],
- ["network_explanation", programming.network_explanation],
- ["hdl_guidance", programming.hdl_guidance],
- ["connection_guidance", Array.isArray(programming.connection_guidance) ? programming.connection_guidance.join(" ") : ""],
- ["programming_constraints", Array.isArray(programming.constraints) ? programming.constraints.join(" ") : ""],
- ["programming_risks", Array.isArray(programming.risks) ? programming.risks.join(" ") : ""],
- ["peripheral_tag", Array.isArray(logical?.tags) ? logical.tags.join(" ") : ""],
- ["logical_pin", logical?.displayBadge],
- ["peripheral_role", logical?.peripheralRole],
- ["pin_definition", logical?.pinDefinition],
- ];
- }
- /**
- * Safe reference / identity match: exact, or prefix only when the next char is not a digit.
- * Prevents R12 ⊆ R1225 false positives.
- */
- export function identityMatch(candidate, query) {
- const value = normalized(candidate);
- const needle = normalized(query);
- if (!value || !needle) return 0;
- if (value === needle) return 3;
- if (value.startsWith(needle)) {
- const next = value.charAt(needle.length);
- if (!next || !/\d/.test(next)) return 2;
- return 0;
- }
- return 0;
- }
- function fieldScore(field, value, query, {allowIncludes = true} = {}) {
- const candidate = normalized(value);
- if (!candidate) return 0;
- if (field === "peripheral_tag") {
- const tokens = candidate.split(/\s+/).filter(Boolean);
- if (tokens.includes(query)) return 960;
- return 0;
- }
- const weights = {
- pin: 1200,
- reference: 1000,
- resistor: 1600,
- resistor_pad: 1500,
- value: 1400,
- fpga_ball: 900,
- mcu_pin: 900,
- mcu_signal: 840,
- mcu_device: 800,
- mcu_family: 780,
- mcu_capability: 720,
- net: 850,
- board_signal: 820,
- function: 760,
- logical_pin: 740,
- capability: 720,
- peripheral_role: 710,
- pin_number: 620,
- pin_definition: 520,
- summary: 500,
- path: 460,
- programming_conclusion: 700,
- network_explanation: 610,
- hdl_guidance: 590,
- connection_guidance: 570,
- programming_constraints: 540,
- programming_risks: 480,
- external_level: 420,
- direction: 360,
- };
- const weight = weights[field] ?? 200;
- if (field === "reference" || field === "resistor" || field === "resistor_pad" || field === "pin") {
- const grade = identityMatch(candidate, query);
- if (grade === 3) return weight;
- if (grade === 2) return weight - 120;
- return 0;
- }
- if (field === "fpga_ball") {
- // Identifiers: exact / token boundary only — never bare includes.
- if (candidate === query) return weight;
- return 0;
- }
- if (candidate === query) return weight;
- if (candidate.startsWith(query)) return weight - 120;
- if (allowIncludes && candidate.includes(query)) return weight - 240;
- return 0;
- }
- function resultId(type, reference, pinNumber = null) {
- return pinNumber == null ? `${type}:${reference}` : `${type}:${reference}.${pinNumber}`;
- }
- export function buildBoardIndex(data) {
- const resistorByReference = new Map();
- const resistorPadById = new Map();
- const valueTokenIndex = new Map();
- const netMembers = new Map();
- const relatedByPinId = new Map();
- const pushNet = (net, member) => {
- const key = text(net);
- if (!key) return;
- if (!netMembers.has(key)) netMembers.set(key, []);
- netMembers.get(key).push(member);
- };
- for (const resistor of data?.resistors ?? []) {
- const reference = text(resistor.reference);
- resistorByReference.set(reference, resistor);
- resistorByReference.set(normalized(reference), resistor);
- for (const token of resistor.value_tokens ?? []) {
- const key = normalized(token);
- if (!key) continue;
- if (!valueTokenIndex.has(key)) valueTokenIndex.set(key, []);
- valueTokenIndex.get(key).push(resistor);
- }
- for (const pad of resistor.pads ?? []) {
- const padId = text(pad.id) || `${reference}.pad-${pad.number}`;
- resistorPadById.set(padId, {resistor, pad});
- resistorPadById.set(`${reference}.${pad.number}`, {resistor, pad});
- pushNet(pad.net, {
- kind: "resistor_pad",
- reference,
- pinNumber: text(pad.number),
- touchpoint: null,
- resistor,
- pin: pad,
- });
- }
- }
- for (const touchpoint of data?.touchpoints ?? []) {
- for (const pin of touchpoint.pins ?? []) {
- pushNet(pin.net, {
- kind: "touchpoint",
- reference: touchpoint.reference,
- pinNumber: text(pin.number),
- touchpoint,
- resistor: null,
- pin,
- });
- if (Array.isArray(pin.related_resistors) && pin.related_resistors.length) {
- relatedByPinId.set(text(pin.id), pin.related_resistors);
- }
- }
- }
- for (const members of netMembers.values()) {
- members.sort((left, right) => {
- const referenceOrder = naturalCompare(left.reference, right.reference);
- return referenceOrder || naturalCompare(left.pinNumber, right.pinNumber);
- });
- }
- return {
- resistorByReference,
- resistorPadById,
- valueTokenIndex,
- netMembers,
- relatedByPinId,
- evidenceConflicts: Array.isArray(data?.evidence_conflicts) ? data.evidence_conflicts : [],
- };
- }
- function looksLikeResistanceToken(raw) {
- const needle = text(raw).trim();
- if (!needle) return false;
- if (PACKAGE_OR_DNP.test(needle)) return false;
- if (!VALUE_GRAMMAR.test(needle)) return false;
- if (/^\d{1,2}$/.test(needle)) return false; // short bare numbers need value: or 22R
- // Bare package-sized integers like 0805 already rejected; reject 4-digit bare
- // numbers that look like imperial package codes when no unit suffix present.
- if (/^\d{4}$/.test(needle) && !/[rRkKmM]|ohm|Ω/i.test(needle)) return false;
- return true;
- }
- /** Resolve exact net name from board index; case-sensitive first, then CI. */
- export function resolveExactNetName(data, query) {
- const raw = text(query).trim();
- if (!raw) return null;
- const index = buildBoardIndex(data);
- if (index.netMembers.has(raw)) return raw;
- const needle = normalized(raw);
- for (const name of index.netMembers.keys()) {
- if (normalized(name) === needle) return name;
- }
- return null;
- }
- export function parseBoardQuery(query) {
- const raw = text(query).trim();
- const needle = normalized(raw);
- if (!needle) return {kind: "empty", raw, needle};
- const ball = BALL_PREFIX.exec(raw);
- if (ball) return {kind: "ball", raw, needle: normalized(ball[1]), value: ball[1].trim()};
- const net = NET_PREFIX.exec(raw);
- if (net) return {kind: "net", raw, needle: normalized(net[1]), value: net[1].trim()};
- const value = VALUE_PREFIX.exec(raw);
- if (value) return {kind: "value", raw, needle: normalized(value[1]), value: value[1].trim()};
- const pad = RESISTOR_PAD.exec(needle);
- if (pad) {
- return {
- kind: "resistor_pad",
- raw,
- needle,
- reference: `R${pad[1]}`,
- padNumber: pad[2],
- };
- }
- const ref = RESISTOR_REF.exec(needle);
- if (ref) {
- return {
- kind: "resistor_ref",
- raw,
- needle,
- reference: `R${ref[1]}`,
- };
- }
- if (ENDPOINT.test(needle)) {
- return {kind: "endpoint", raw, needle, value: raw};
- }
- if (looksLikeResistanceToken(raw)) {
- return {kind: "value", raw, needle, value: raw};
- }
- return {kind: "text", raw, needle};
- }
- function sortResults(results) {
- const typeOrder = {
- resistor: 0,
- resistor_pad: 1,
- evidence_conflict: 2,
- touchpoint: 3,
- pin: 4,
- };
- return results.sort((left, right) => {
- if (right.score !== left.score) return right.score - left.score;
- const leftType = typeOrder[left.type] ?? 9;
- const rightType = typeOrder[right.type] ?? 9;
- if (leftType !== rightType) return leftType - rightType;
- const referenceOrder = naturalCompare(left.reference, right.reference);
- if (referenceOrder) return referenceOrder;
- return naturalCompare(left.pinNumber, right.pinNumber);
- });
- }
- function searchTouchpoints(data, needle, {ballOnly = false, endpoint = null} = {}) {
- const results = [];
- const boardVersion = normalizeBoardVersion(null, data);
- for (const touchpoint of data?.touchpoints ?? []) {
- if (!ballOnly && !endpoint) {
- const touchpointFields = [
- ["reference", touchpoint.reference],
- ["summary", touchpoint.summary],
- ["function", touchpoint.category],
- ];
- let touchpointScore = 0;
- let touchpointField = "";
- for (const [field, value] of touchpointFields) {
- const score = fieldScore(field, value, needle);
- if (score > touchpointScore) {
- touchpointScore = score;
- touchpointField = field;
- }
- }
- if (touchpointScore) {
- results.push({
- id: resultId("touchpoint", touchpoint.reference),
- type: "touchpoint",
- reference: touchpoint.reference,
- pinNumber: null,
- touchpoint,
- resistor: null,
- pin: null,
- matchedField: touchpointField,
- score: touchpointScore + 20,
- });
- }
- }
- for (const pin of touchpoint.pins ?? []) {
- let score = 0;
- let matchedField = "";
- if (ballOnly) {
- const ballScore = fieldScore("fpga_ball", pin.fpga?.ball, needle, {allowIncludes: false});
- if (!ballScore) continue;
- score = ballScore;
- matchedField = "fpga_ball";
- } else if (endpoint) {
- const endpointNeedle = normalized(endpoint);
- const candidates = [
- ["fpga_ball", `u3.${text(pin.fpga?.ball)}`],
- ["path", Array.isArray(pin.path) ? pin.path.join(" ") : ""],
- ["board_signal", pin.fpga?.board_signal],
- ["pin", `${touchpoint.reference}.${pin.number}`],
- ];
- for (const [field, value] of candidates) {
- const candidate = normalized(value);
- if (!candidate) continue;
- if (candidate === endpointNeedle || candidate.split(/[^a-z0-9_.]+/).includes(endpointNeedle)) {
- const candidateScore = field === "fpga_ball" ? 950 : 700;
- if (candidateScore > score) {
- score = candidateScore;
- matchedField = field;
- }
- }
- }
- if (!score) continue;
- } else {
- for (const [field, value] of pinSearchFields(touchpoint, pin, boardVersion)) {
- const candidateScore = fieldScore(field, value, needle, {
- allowIncludes: field !== "fpga_ball" && field !== "reference" && field !== "pin",
- });
- if (candidateScore > score) {
- score = candidateScore;
- matchedField = field;
- }
- }
- if (!score) continue;
- if (baseBlockers(pin).length === 0) score += 40;
- }
- results.push({
- id: resultId("pin", touchpoint.reference, text(pin.number)),
- type: "pin",
- reference: touchpoint.reference,
- pinNumber: text(pin.number),
- touchpoint,
- resistor: null,
- pin,
- matchedField,
- score,
- });
- }
- }
- return results;
- }
- function pushNetMemberResults(results, members, score = 1400) {
- for (const member of members) {
- const isResistor = member.kind === "resistor_pad";
- results.push({
- id: resultId(isResistor ? "resistor_pad" : "pin", member.reference, member.pinNumber),
- type: isResistor ? "resistor_pad" : "pin",
- reference: member.reference,
- pinNumber: member.pinNumber,
- touchpoint: member.touchpoint,
- resistor: member.resistor,
- pin: member.pin,
- matchedField: "net",
- score,
- assemblyStatus: member.resistor?.assembly_status || null,
- });
- }
- }
- export function searchBoard(data, query) {
- let parsed = parseBoardQuery(query);
- if (parsed.kind === "empty") return [];
- const index = buildBoardIndex(data);
- let results = [];
- // Bare string that exactly equals an existing net → exact net query (same as net:).
- if (parsed.kind === "text") {
- const exactNet = resolveExactNetName(data, parsed.raw);
- if (exactNet) {
- parsed = {kind: "net", raw: parsed.raw, needle: normalized(exactNet), value: exactNet};
- }
- }
- if (parsed.kind === "resistor_pad") {
- const hit = index.resistorPadById.get(`${parsed.reference}.${parsed.padNumber}`);
- if (hit) {
- results.push({
- id: resultId("resistor_pad", parsed.reference, parsed.padNumber),
- type: "resistor_pad",
- reference: parsed.reference,
- pinNumber: parsed.padNumber,
- touchpoint: null,
- resistor: hit.resistor,
- pin: hit.pad,
- matchedField: "resistor_pad",
- score: 1550,
- });
- }
- return sortResults(results);
- }
- if (parsed.kind === "resistor_ref") {
- const resistor = index.resistorByReference.get(parsed.reference)
- || index.resistorByReference.get(normalized(parsed.reference));
- if (resistor) {
- results.push({
- id: resultId("resistor", parsed.reference),
- type: "resistor",
- reference: parsed.reference,
- pinNumber: null,
- touchpoint: null,
- resistor,
- pin: null,
- matchedField: "resistor",
- score: 1600,
- });
- }
- return sortResults(results);
- }
- if (parsed.kind === "ball") {
- return sortResults(searchTouchpoints(data, parsed.needle, {ballOnly: true}));
- }
- if (parsed.kind === "endpoint") {
- return sortResults(searchTouchpoints(data, parsed.needle, {endpoint: parsed.value}));
- }
- if (parsed.kind === "net") {
- const members =
- index.netMembers.get(text(parsed.value))
- || index.netMembers.get(parsed.value)
- || [];
- pushNetMemberResults(results, members, 1400);
- if (!results.length) {
- for (const [net, rows] of index.netMembers.entries()) {
- if (normalized(net) !== parsed.needle) continue;
- pushNetMemberResults(results, rows, 1400);
- }
- }
- return sortResults(results);
- }
- if (parsed.kind === "value") {
- const seen = new Set();
- const addResistor = (resistor, score = 1400) => {
- const reference = text(resistor.reference);
- if (seen.has(reference)) return;
- seen.add(reference);
- const notFitted = resistor.assembly_status === "not_fitted";
- results.push({
- id: resultId("resistor", reference),
- type: "resistor",
- reference,
- pinNumber: null,
- touchpoint: null,
- resistor,
- pin: null,
- matchedField: "value",
- score: notFitted ? score - 200 : score,
- assemblyStatus: resistor.assembly_status || "unknown",
- notFitted,
- });
- };
- for (const resistor of index.valueTokenIndex.get(parsed.needle) ?? []) {
- addResistor(resistor, 1450);
- }
- for (const resistor of data?.resistors ?? []) {
- for (const token of resistor.value_tokens ?? []) {
- if (normalized(token) === parsed.needle) addResistor(resistor, 1450);
- }
- if (normalized(resistor.component_value) === parsed.needle) addResistor(resistor, 1400);
- }
- return sortResults(results);
- }
- // Free-text (non-exact-net): touchpoints/pins; value tokens; never bare R# here.
- results = searchTouchpoints(data, parsed.needle);
- for (const resistor of index.valueTokenIndex.get(parsed.needle) ?? []) {
- results.push({
- id: resultId("resistor", resistor.reference),
- type: "resistor",
- reference: resistor.reference,
- pinNumber: null,
- touchpoint: null,
- resistor,
- pin: null,
- matchedField: "value",
- score: resistor.assembly_status === "not_fitted" ? 1100 : 1300,
- assemblyStatus: resistor.assembly_status || "unknown",
- notFitted: resistor.assembly_status === "not_fitted",
- });
- }
- for (const conflict of index.evidenceConflicts) {
- const hay = normalized([
- conflict.subject_reference,
- conflict.summary,
- ...(conflict.claims || []).map((claim) => JSON.stringify(claim)),
- ].join(" "));
- if (hay.includes(parsed.needle) && conflict.status === "unresolved") {
- results.push({
- id: resultId("evidence_conflict", conflict.subject_reference || conflict.id),
- type: "evidence_conflict",
- reference: conflict.subject_reference || conflict.id,
- pinNumber: null,
- touchpoint: null,
- resistor: index.resistorByReference.get(conflict.subject_reference) || null,
- pin: null,
- matchedField: "evidence_conflict",
- score: 200,
- evidenceConflict: conflict,
- });
- }
- }
- return sortResults(results);
- }
- /** Compatibility: touchpoint pins only (does not include resistor pads). */
- export function sameNetPins(data, net) {
- const wanted = text(net);
- if (!wanted) return [];
- const matches = [];
- for (const touchpoint of data?.touchpoints ?? []) {
- for (const pin of touchpoint.pins ?? []) {
- if (pin.net === wanted) {
- matches.push({
- kind: "touchpoint",
- reference: touchpoint.reference,
- pinNumber: text(pin.number),
- touchpoint,
- resistor: null,
- pin,
- });
- }
- }
- }
- return matches.sort((left, right) => {
- const referenceOrder = naturalCompare(left.reference, right.reference);
- return referenceOrder || naturalCompare(left.pinNumber, right.pinNumber);
- });
- }
- /** Touchpoint pins + resistor pads sharing the PCB net. */
- export function sameNetMembers(data, net) {
- const wanted = text(net);
- if (!wanted) return [];
- const index = buildBoardIndex(data);
- const members = index.netMembers.get(wanted) || [];
- if (members.length) return members.map((item) => ({...item}));
- // Case-insensitive fallback
- for (const [name, rows] of index.netMembers.entries()) {
- if (normalized(name) === normalized(wanted)) {
- return rows.map((item) => ({...item}));
- }
- }
- return [];
- }
- export function extractPathResistors(data, ...texts) {
- const index = new Map((data?.resistors ?? []).map((item) => [text(item.reference), item]));
- const ordered = [];
- const seen = new Set();
- for (const value of texts) {
- const chunks = Array.isArray(value) ? value : [value];
- for (const chunk of chunks) {
- const source = text(chunk);
- if (!source) continue;
- ANNOTATION_RESISTOR.lastIndex = 0;
- let match;
- while ((match = ANNOTATION_RESISTOR.exec(source))) {
- const reference = `R${match[1]}`;
- if (seen.has(reference)) continue;
- seen.add(reference);
- const resistor = index.get(reference);
- if (!resistor) {
- throw new Error(`annotation resistor ${reference} missing from resistor index`);
- }
- ordered.push(resistor);
- }
- }
- }
- return ordered;
- }
- export function findCandidates(data, capability) {
- const wanted = normalized(capability);
- if (!wanted) return [];
- const acceptedCapabilities = new Set(
- (CAPABILITY_ALIASES[wanted] ?? [wanted]).map(normalized),
- );
- const candidates = [];
- for (const touchpoint of data?.touchpoints ?? []) {
- for (const pin of touchpoint.pins ?? []) {
- const pinCapabilities = capabilities(pin).map(normalized);
- if (!pinCapabilities.some((item) => acceptedCapabilities.has(item))) continue;
- if (wanted === "gpio" && !["gpio", "direct_gpio"].includes(normalized(pin.function_category))) {
- continue;
- }
- if (baseBlockers(pin).length) continue;
- const purpose = text(pin.summary).trim();
- const polarity = normalized(pin.polarity);
- const details = [];
- if (purpose) details.push(`用途 ${purpose}`);
- if (polarity && polarity !== "unknown") details.push(`极性 ${pin.polarity}`);
- candidates.push({
- reference: touchpoint.reference,
- touchpoint,
- pin,
- reason: `${details.length ? `${details.join(";")};` : ""}能力 ${capability} 匹配;已验证 FPGA 路径至 ${pin.fpga.ball};外部电平 ${pin.external_level}。`,
- warning: "只证明物理可用性,仍需检查当前工程约束冲突。",
- });
- }
- }
- return candidates.sort((left, right) => {
- const categoryMatchLeft = normalized(left.pin.function_category) === wanted ? 1 : 0;
- const categoryMatchRight = normalized(right.pin.function_category) === wanted ? 1 : 0;
- if (categoryMatchRight !== categoryMatchLeft) return categoryMatchRight - categoryMatchLeft;
- const referenceOrder = naturalCompare(left.reference, right.reference);
- return referenceOrder || naturalCompare(left.pin.number, right.pin.number);
- });
- }
- export function isValidRtlPortName(name) {
- return RTL_PORT.test(text(name));
- }
- /** Back SVG export uses KiCad --mirror about the vertical/Y axis (left-right flip). */
- export const BACK_MIRROR_AXIS = "y";
- export function mirrorBoardX(x, boardWidth) {
- const width = Number(boardWidth);
- const value = Number(x);
- if (!Number.isFinite(width) || !Number.isFinite(value)) return value;
- return width - value;
- }
- export function displayPoint(point, boardWidth, viewingSide) {
- const x = Number(point?.x);
- const y = Number(point?.y);
- if (viewingSide !== "back") return {x, y};
- return {x: mirrorBoardX(x, boardWidth), y};
- }
- export function displayBounds(bounds, boardWidth, viewingSide) {
- const x = Number(bounds?.x);
- const y = Number(bounds?.y);
- const width = Number(bounds?.width);
- const height = Number(bounds?.height);
- if (viewingSide !== "back") {
- return {x, y, width, height};
- }
- return {
- x: mirrorBoardX(x + width, boardWidth),
- y,
- width,
- height,
- };
- }
- export function itemVisibleOnSide(item, viewingSide) {
- return (item?.side || "front") === viewingSide;
- }
- export function generateAdcSnippet(pin, rtlPortName, runtimeStatus = {}) {
- if (runtimeStatus.adcCopyEnabled !== true) {
- throw new Error("源数据已过期,ADC 复制已关闭。");
- }
- if (!isValidRtlPortName(rtlPortName)) {
- throw new Error("生成 ADC 前请输入合法的 RTL 端口名。");
- }
- if (baseBlockers(pin).length) {
- throw new Error("此针脚不具备 ADC 生成资格。");
- }
- const ball = text(pin.fpga.ball);
- const ioStandard = text(pin.fpga.io_standard);
- if (!/^[A-Z]+[0-9]+$/.test(ball) || !/^[A-Za-z0-9_.+-]+$/.test(ioStandard)) {
- throw new Error("已验证 FPGA 分配包含不安全的 ADC 值。");
- }
- const assignments = [`LOCATION = ${ball}`, `IOSTANDARD = ${ioStandard}`];
- if (pin.adc_pulltype != null) {
- const pulltype = text(pin.adc_pulltype);
- if (!/^[A-Z][A-Z0-9_]*$/.test(pulltype)) {
- throw new Error("人工注释的 PULLTYPE 包含不安全值。");
- }
- assignments.push(`PULLTYPE = ${pulltype}`);
- }
- return `set_pin_assignment { ${rtlPortName} } { ${assignments.join("; ")}; }`;
- }
- export const PERIPHERAL_TYPE_ORDER = [
- "ALL",
- "PTC",
- "FAN",
- "UART",
- "JTAG",
- "MOTOR",
- "LIMIT",
- "TEMP",
- "SSR",
- "GPIO",
- "MCU",
- "POWER",
- ];
- export const PERIPHERAL_TYPE_LABELS = {
- ALL: "全部外设",
- PTC: "PTC 加热",
- FAN: "FAN 风扇",
- UART: "UART 串口",
- JTAG: "JTAG / SWD",
- MOTOR: "步进电机",
- LIMIT: "限位开关",
- TEMP: "温度探头",
- SSR: "SSR 继电器",
- GPIO: "GPIO 扩展",
- MCU: "MCU 接口",
- POWER: "电源 / 测点",
- };
- const V12_V11_PTC_CONNECTOR_MAP = {
- "CON18.1": {tag: "PTC1", idx: 0, ball: "F16", heat: "HEAT1", v11Role: "PTC1 (通道0)"},
- "CON18.3": {tag: "PTC2", idx: 1, ball: "G16", heat: "HEAT2", v11Role: "PTC2 (通道1)"},
- "CON18.5": {tag: "PTC3", idx: 2, ball: "T4", heat: "HEAT3", v11Role: "PTC3 (通道2)"},
- "CON18.7": {tag: "PTC4", idx: 3, ball: "R5", heat: "HEAT4", v11Role: "PTC4 (通道3)"},
- "CON18.9": {tag: "PTC5", idx: 4, ball: "T6", heat: "HEAT5", v11Role: "PTC5 (通道4)"},
- "CON18.11": {tag: "PTC6", idx: 5, ball: "R7", heat: "HEAT6", v11Role: "PTC6 (通道5)"},
- "CON18.13": {tag: "PTC6", idx: 5, ball: "R7", heat: "HEAT6", v11Role: "PTC6 (通道5 并联针)"},
- "CON27.1": {tag: "PTC7", idx: 6, ball: "M1", heat: "HEAT7", v11Role: "PTC7 (通道6)"},
- "CON27.3": {tag: "PTC8", idx: 7, ball: "N1", heat: "HEAT8", v11Role: "PTC8 (通道7)"},
- "CON27.5": {tag: "PTC9", idx: 8, ball: "P1", heat: "HEAT9", v11Role: "PTC9 (通道8)"},
- "CON27.7": {tag: "PTC10", idx: 9, ball: "R1", heat: "HEAT10", v11Role: "PTC10 (通道9)"},
- "CON27.9": {tag: "PTC11", idx: 10, ball: "T2", heat: "HEAT11", v11Role: "PTC11 (通道10)"},
- "CON27.11": {tag: "PTC12", idx: 11, ball: "R3", heat: "HEAT12", v11Role: "PTC12 (通道11)"},
- "CON27.13": {tag: "PTC12", idx: 11, ball: "R3", heat: "HEAT12", v11Role: "PTC12 (通道11 并联针)"},
- "CON28.1": {tag: "PTC13", idx: 12, ball: "P16", heat: "HEAT13", v11Role: "PTC13 (通道12)"},
- "CON28.3": {tag: "PTC14", idx: 13, ball: "R16", heat: "HEAT14", v11Role: "PTC14 (通道13)"},
- "CON28.5": {tag: "PTC15", idx: 14, ball: "M16", heat: "HEAT15", v11Role: "PTC15 (通道14)"},
- "CON28.7": {tag: "PTC16", idx: 15, ball: "N16", heat: "HEAT16", v11Role: "PTC16 (通道15)"},
- "CON28.9": {tag: "PTC17", idx: 16, ball: "P8", heat: "HEAT17", v11Role: "PTC17 (通道16)"},
- "CON28.11": {tag: "PTC18", idx: 17, ball: "P7", heat: "HEAT18", v11Role: "PTC18 (通道17)"},
- "CON28.13": {tag: "PTC18", idx: 17, ball: "P7", heat: "HEAT18", v11Role: "PTC18 (通道17 并联针)"},
- "CON29.1": {tag: "PTC19", idx: 18, ball: "T9", heat: "HEAT19", v11Role: "PTC19 (通道18)"},
- "CON29.3": {tag: "PTC20", idx: 19, ball: "P9", heat: "HEAT20", v11Role: "PTC20 (通道19)"},
- "CON29.5": {tag: "PTC21", idx: 20, ball: "P10", heat: "HEAT21", v11Role: "PTC21 (通道20)"},
- "CON29.7": {tag: "PTC22", idx: 21, ball: "R10", heat: "HEAT22", v11Role: "PTC22 (通道21)"},
- "CON29.9": {tag: "PTC23", idx: 22, ball: "T13", heat: "HEAT23", v11Role: "PTC23 (通道22)"},
- "CON29.11": {tag: "PTC24", idx: 23, ball: "T12", heat: "HEAT24", v11Role: "PTC24 (通道23)"},
- "CON29.13": {tag: "PTC24", idx: 23, ball: "T12", heat: "HEAT24", v11Role: "PTC24 (通道23 并联针)"},
- };
- const V20_PTC_CONNECTOR_MAP = {
- "CON147.1": {tag: "PTC1", idx: 0, ball: "F16", net: "PTC1", role: "1#腔 PTC1 (通道0)"},
- "CON147.3": {tag: "PTC2", idx: 1, ball: "G16", net: "PTC2", role: "1#腔 PTC2 (通道1)"},
- "CON147.5": {tag: "PTC3", idx: 2, ball: "T4", net: "PTC3", role: "1#腔 PTC3 (通道2)"},
- "CON147.7": {tag: "PTC4", idx: 3, ball: "R5", net: "PTC4", role: "1#腔 PTC4 (通道3)"},
- "CON147.9": {tag: "PTC5", idx: 4, ball: "T6", net: "PTC5", role: "1#腔 PTC5 (通道4)"},
- "CON147.11": {tag: "PTC6", idx: 5, ball: "R7", net: "PTC6", role: "1#腔 PTC6 (通道5)"},
- "CON147.13": {tag: "PTC7_SPARE", idx: 26, ball: "M1", net: "PTC7", role: "1#腔预留 PTC7 (U3.M1 空余)"},
- "CON147.15": {tag: "PTC8_SPARE", idx: 27, ball: "N1", net: "PTC8", role: "1#腔预留 PTC8 (U3.N1 空余)"},
- "CON147.17": {tag: "PTC9_SPARE", idx: 28, ball: "P1", net: "PTC9", role: "1#腔预留 PTC9 (U3.P1 空余)"},
- "CON147.19": {tag: "PTC10_SPARE", idx: 29, ball: "R1", net: "PTC10", role: "1#腔预留 PTC10 (U3.R1 空余)"},
- "CON148.1": {tag: "PTC7", altTag: "PTC11", idx: 6, ball: "T2", net: "PTC11", role: "2#腔 PTC11 (逻辑PTC7 / 通道6)"},
- "CON148.3": {tag: "PTC8", altTag: "PTC12", idx: 7, ball: "R3", net: "PTC12", role: "2#腔 PTC12 (逻辑PTC8 / 通道7)"},
- "CON148.5": {tag: "PTC9", altTag: "PTC13", idx: 8, ball: "P16", net: "PTC13", role: "2#腔 PTC13 (逻辑PTC9 / 通道8)"},
- "CON148.7": {tag: "PTC10", altTag: "PTC14", idx: 9, ball: "R16", net: "PTC14", role: "2#腔 PTC14 (逻辑PTC10 / 通道9)"},
- "CON148.9": {tag: "PTC11", altTag: "PTC15", idx: 10, ball: "M16", net: "PTC15", role: "2#腔 PTC15 (逻辑PTC11 / 通道10)"},
- "CON148.11": {tag: "PTC12", altTag: "PTC16", idx: 11, ball: "N16", net: "PTC16", role: "2#腔 PTC16 (逻辑PTC12 / 通道11)"},
- "CON148.13": {tag: "PTC17_SPARE", idx: 30, ball: "P8", net: "PTC17", role: "2#腔预留 PTC17 (U3.P8 空余)"},
- "CON148.15": {tag: "PTC18_SPARE", idx: 31, ball: "P7", net: "PTC18", role: "2#腔预留 PTC18 (U3.P7 空余)"},
- "CON148.17": {tag: "PTC19_SPARE", idx: 32, ball: "T9", net: "PTC19", role: "2#腔预留 PTC19 (U3.T9 空余)"},
- "CON148.19": {tag: "PTC20_SPARE", idx: 33, ball: "P9", net: "PTC20", role: "2#腔预留 PTC20 (U3.P9 空余)"},
- "CON149.1": {tag: "PTC13", altTag: "PTC21", idx: 12, ball: "P10", net: "PTC21", role: "3#腔 PTC21 (逻辑PTC13 / 通道12)"},
- "CON149.3": {tag: "PTC14", altTag: "PTC22", idx: 13, ball: "R10", net: "PTC22", role: "3#腔 PTC22 (逻辑PTC14 / 通道13)"},
- "CON149.5": {tag: "PTC15", altTag: "PTC23", idx: 14, ball: "T13", net: "PTC23", role: "3#腔 PTC23 (逻辑PTC15 / 通道14)"},
- "CON149.7": {tag: "PTC16", altTag: "PTC24", idx: 15, ball: "T12", net: "PTC24", role: "3#腔 PTC24 (逻辑PTC16 / 通道15)"},
- "CON149.9": {tag: "PTC17", altTag: "PTC25", idx: 16, ball: "L3", net: "PTC25", role: "3#腔 PTC25 (逻辑PTC17 / 通道16)"},
- "CON149.11": {tag: "PTC18", altTag: "PTC26", idx: 17, ball: "N2", net: "PTC26", role: "3#腔 PTC26 (逻辑PTC18 / 通道17)"},
- "CON149.13": {tag: "PTC27_SPARE", idx: 34, ball: "P2", net: "PTC27", role: "预留 PTC27(当前固件未绑定)"},
- "CON149.15": {tag: "PTC28_SPARE", idx: 35, ball: "M3", net: "PTC28", role: "3#腔预留 PTC28 (U3.M3 空余)"},
- "CON149.17": {tag: "PTC29_SPARE", idx: 36, ball: "L5", net: "PTC29", role: "3#腔预留 PTC29 (U3.L5 空余)"},
- "CON149.19": {tag: "PTC19", altTag: "PTC30", idx: 18, ball: "K5", net: "PTC30", role: "4#腔 PTC30(通道18)"},
- "CON150.1": {tag: "PTC20", altTag: "PTC31", idx: 19, ball: "L4", net: "PTC31", role: "4#腔 PTC31(通道19)"},
- "CON150.3": {tag: "PTC20", altTag: "PTC31", idx: 19, ball: "L4", net: "PTC31", role: "4#腔 PTC31(通道19)"},
- "CON150.5": {tag: "PTC21", altTag: "PTC32", idx: 20, ball: "H4", net: "PTC32", role: "4#腔 PTC32(通道20)"},
- "CON150.7": {tag: "PTC21", altTag: "PTC32", idx: 20, ball: "H4", net: "PTC32", role: "4#腔 PTC32(通道20)"},
- "CON150.9": {tag: "PTC22", altTag: "PTC33", idx: 21, ball: "J6", net: "PTC33", role: "4#腔 PTC33(通道21)"},
- "CON150.11": {tag: "PTC22", altTag: "PTC33", idx: 21, ball: "J6", net: "PTC33", role: "4#腔 PTC33(通道21)"},
- "CON150.13": {tag: "PTC23", altTag: "PTC34", idx: 22, ball: "H5", net: "PTC34", role: "4#腔 PTC34(通道22)"},
- "CON150.15": {tag: "PTC23", altTag: "PTC34", idx: 22, ball: "H5", net: "PTC34", role: "4#腔 PTC34(通道22)"},
- "CON150.17": {tag: "PTC24", altTag: "PTC35", idx: 23, ball: "C15", net: "PTC35", role: "4#腔 PTC35(通道23)"},
- "CON150.19": {tag: "PTC24", altTag: "PTC35", idx: 23, ball: "C15", net: "PTC35", role: "4#腔 PTC35(通道23)"},
- };
- const V12_MOTOR_MAP = {
- "CON104": {"axis": 0, "tag": "M1", "stepPin": "2", "stepBall": "C12", "dirPin": "3", "dirBall": "B12", "stepNet": "PUL1", "dirNet": "DIR1"},
- "CON105": {"axis": 1, "tag": "M2", "stepPin": "2", "stepBall": "L12", "dirPin": "3", "dirBall": "J11", "stepNet": "PUL2", "dirNet": "DIR2"},
- "CON106": {"axis": 2, "tag": "M3", "stepPin": "2", "stepBall": "L14", "dirPin": "3", "dirBall": "K14", "stepNet": "PUL3", "dirNet": "DIR3"},
- "CON113": {"axis": 3, "tag": "M4", "stepPin": "2", "stepBall": "G14", "dirPin": "3", "dirBall": "G15", "stepNet": "PUL10", "dirNet": "DIR10"},
- "CON107": {"axis": 4, "tag": "M5", "stepPin": "2", "stepBall": "L13", "dirPin": "3", "dirBall": "K11", "stepNet": "PUL4", "dirNet": "DIR4"},
- "CON108": {"axis": 5, "tag": "M6", "stepPin": "2", "stepBall": "K12", "dirPin": "3", "dirBall": "K13", "stepNet": "PUL5", "dirNet": "DIR5"},
- "CON109": {"axis": 6, "tag": "M7", "stepPin": "2", "stepBall": "J14", "dirPin": "3", "dirBall": "J12", "stepNet": "PUL6", "dirNet": "DIR6"},
- "CON114": {"axis": 7, "tag": "M8", "stepPin": "2", "stepBall": "G13", "dirPin": "3", "dirBall": "F14", "stepNet": "PUL11", "dirNet": "DIR11"},
- "CON110": {"axis": 8, "tag": "M9", "stepPin": "2", "stepBall": "H13", "dirPin": "3", "dirBall": "J13", "stepNet": "PUL7", "dirNet": "DIR7"},
- "CON111": {"axis": 9, "tag": "M10", "stepPin": "2", "stepBall": "H11", "dirPin": "3", "dirBall": "H12", "stepNet": "PUL8", "dirNet": "DIR8"},
- "CON112": {"axis": 10, "tag": "M11", "stepPin": "2", "stepBall": "G11", "dirPin": "3", "dirBall": "H14", "stepNet": "PUL9", "dirNet": "DIR9"},
- "CON115": {"axis": 11, "tag": "M12", "stepPin": "2", "stepBall": "F12", "dirPin": "3", "dirBall": "D15", "stepNet": "PUL12", "dirNet": "DIR12"},
- };
- const V12_LIMIT_MAP = {
- "CON12.1": {"axis": 0, "tag": "LS1", "rtl": "limit_lower_raw[0]", "ball": "A5", "role": "轴0(M1) 下限位 LS1"},
- "CON12.3": {"axis": 1, "tag": "LS2", "rtl": "limit_lower_raw[1]", "ball": "C8", "role": "轴1(M2) 下限位 LS2"},
- "CON126.1": {"axis": 2, "tag": "LS3", "rtl": "limit_lower_raw[2]", "ball": "D7", "role": "轴2(M3) 下限位 LS3"},
- "CON126.3": {"axis": 3, "tag": "LS4", "rtl": "limit_lower_raw[3]", "ball": "A4", "role": "轴3(M4) 下限位 LS4"},
- "CON127.1": {"axis": 4, "tag": "LS5", "rtl": "limit_lower_raw[4]", "ball": "A3", "role": "轴4(M5) 下限位 LS5"},
- "CON127.3": {"axis": 5, "tag": "LS6", "rtl": "limit_lower_raw[5]", "ball": "A12", "role": "轴5(M6) 下限位 LS6"},
- "CON128.1": {"axis": 6, "tag": "LS7", "rtl": "limit_lower_raw[6]", "ball": "L16", "role": "轴6(M7) 下限位 LS7"},
- "CON128.3": {"axis": 7, "tag": "LS8", "rtl": "limit_lower_raw[7]", "ball": "K15", "role": "轴7(M8) 下限位 LS8"},
- "CON129.1": {"axis": 8, "tag": "LS9", "rtl": "limit_lower_raw[8]", "ball": "K16", "role": "轴8(M9) 下限位 LS9"},
- "CON129.3": {"axis": 9, "tag": "LS10", "rtl": "limit_lower_raw[9]", "ball": "H15", "role": "轴9(M10) 下限位 LS10"},
- "CON138.1": {"axis": 10, "tag": "LS11", "rtl": "limit_lower_raw[10]", "ball": "T3", "role": "轴10(M11) 下限位 LS11"},
- "CON138.3": {"axis": 11, "tag": "LS12", "rtl": "limit_lower_raw[11]", "ball": "P4", "role": "轴11(M12) 下限位 LS12"},
- "CON12.2": {"axis": 0, "tag": "HS1", "rtl": "limit_upper_raw[0]", "ball": "B6", "role": "轴0(M1) 上限位 HS1"},
- "CON12.4": {"axis": 1, "tag": "HS2", "rtl": "limit_upper_raw[1]", "ball": "A8", "role": "轴1(M2) 上限位 HS2"},
- "CON126.2": {"axis": 2, "tag": "HS3", "rtl": "limit_upper_raw[2]", "ball": "E7", "role": "轴2(M3) 上限位 HS3"},
- "CON126.4": {"axis": 3, "tag": "HS4", "rtl": "limit_upper_raw[3]", "ball": "C5", "role": "轴3(M4) 上限位 HS4"},
- "CON127.2": {"axis": 4, "tag": "HS5", "rtl": "limit_upper_raw[4]", "ball": "B4", "role": "轴4(M5) 上限位 HS5"},
- "CON127.4": {"axis": 5, "tag": "HS6", "rtl": "limit_upper_raw[5]", "ball": "B11", "role": "轴5(M6) 上限位 HS6"},
- "CON128.2": {"axis": 6, "tag": "HS7", "rtl": "limit_upper_raw[6]", "ball": "L15", "role": "轴6(M7) 上限位 HS7"},
- "CON128.4": {"axis": 7, "tag": "HS8", "rtl": "limit_upper_raw[7]", "ball": "J16", "role": "轴7(M8) 上限位 HS8"},
- "CON129.2": {"axis": 8, "tag": "HS9", "rtl": "limit_upper_raw[8]", "ball": "J15", "role": "轴8(M9) 上限位 HS9"},
- "CON129.4": {"axis": 9, "tag": "HS10", "rtl": "limit_upper_raw[9]", "ball": "H16", "role": "轴9(M10) 上限位 HS10"},
- "CON138.2": {"axis": 10, "tag": "HS11", "rtl": "limit_upper_raw[10]", "ball": "R4", "role": "轴10(M11) 上限位 HS11"},
- "CON138.4": {"axis": 11, "tag": "HS12", "rtl": "limit_upper_raw[11]", "ball": "T5", "role": "轴11(M12) 上限位 HS12"},
- };
- function normalizeBoardVersion(boardVersion, data) {
- const v = text(boardVersion).trim().toLowerCase();
- if (v === "v2_0" || v === "v2_0_fan" || v === "v1_2" || v === "v1_1") return v;
- const id = `${text(data?.board?.id)} ${text(data?.board?.name)}`.toLowerCase();
- if (id.includes("fan")) return "v2_0_fan";
- if (id.includes("v2")) return "v2_0";
- if (id.includes("v1.2") || id.includes("v1_2") || id.includes("20260717")) return "v1_2";
- return "v1_1";
- }
- /**
- * Add reviewed project roles to board JSON facts. Inferred paths remain inferred; this is not a continuity measurement.
- */
- export function resolveLogicalPin(touchpoint, pin, boardVersion = "v2_0") {
- const result = describeLogicalPin(touchpoint, pin, boardVersion);
- // The connector net remains a board JSON fact, independent of project role labels.
- result.boardSignal = text(pin?.net).trim() || result.boardSignal;
- const nativeBall = text(pin?.fpga?.ball).trim();
- const describedBall = /^U3\.([A-Z]+[0-9]+)$/.exec(result.physicalPin || "")?.[1];
- if (nativeBall && describedBall && nativeBall !== describedBall) {
- return {
- ...result,
- physicalPin: `U3.${nativeBall}`,
- logicalSignal: "板数据与项目角色表冲突,未绑定角色",
- pinDefinition: `板数据标注 U3.${nativeBall};项目角色表预期 U3.${describedBall},请核对当前 ADC 与原生网表。`,
- displayBadge: `FPGA U3.${nativeBall} · 映射冲突`,
- isUsed: false,
- };
- }
- return result;
- }
- function describeLogicalPin(touchpoint, pin, boardVersion = "v2_0") {
- const ver = normalizeBoardVersion(boardVersion);
- const ref = text(touchpoint?.reference).trim();
- const pnum = text(pin?.number).trim();
- const key = `${ref}.${pnum}`;
- const ball = text(pin?.fpga?.ball).trim();
- const boardSig = text(pin?.fpga?.board_signal).trim();
- const mcuDev = text(pin?.mcu?.device).trim();
- const mcuPin = text(pin?.mcu?.pin).trim();
- const mcuSig = text(pin?.mcu?.signal).trim();
- const net = text(pin?.net).trim();
- // Mechanical / Shield pads
- if (pin?.mechanical === true || pin?.pad_role === "shield" || pin?.pad_role === "mechanical" || pnum.startsWith("SH")) {
- return {
- chip: "MECHANICAL",
- physicalPin: "SHIELD/GND",
- logicalSignal: "GND_SHIELD (外壳固定焊盘)",
- boardSignal: net || "GND",
- peripheralRole: "机械屏蔽固定脚",
- pinDefinition: text(pin?.summary) || `${key} 机械固定与屏蔽接地焊盘`,
- displayBadge: "非逻辑管脚 · 机械屏蔽/GND",
- tags: ["GND"],
- isUsed: false,
- };
- }
- // JTAG (J3 across V1.2 / V1.1 / V2.0)
- if (ref === "J3") {
- const j3Map = {
- "1": {ball: "A7", rtl: "jtag_tck", sig: "FPGA_TCK", def: "FPGA JTAG 时钟输入 (TCK, R63 串联)"},
- "3": {ball: "C6", rtl: "jtag_tdo", sig: "FPGA_TDO", def: "FPGA JTAG 数据输出 (TDO, R65 串联)"},
- "5": {ball: "B8", rtl: "jtag_tms", sig: "FPGA_TMS", def: "FPGA JTAG 模式选择 (TMS, R67 串联)"},
- "9": {ball: "A6", rtl: "jtag_tdi", sig: "FPGA_TDI", def: "FPGA JTAG 数据输入 (TDI, R69 串联)"},
- "4": {ball: "", rtl: "VREF_+3V3", sig: "+3V3_VREF", def: "JTAG 下载器目标电平参考 (+3.3V 经 R61/R62)"},
- "2": {ball: "", rtl: "GND", sig: "GND", def: "JTAG 信号参考地 (0V GND)"},
- "10": {ball: "", rtl: "GND", sig: "GND", def: "JTAG 信号参考地 (0V GND)"},
- }[pnum];
- if (j3Map?.ball) {
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${j3Map.ball}`,
- logicalSignal: `${j3Map.rtl} (${j3Map.sig})`,
- boardSignal: j3Map.sig,
- peripheralRole: `JTAG ${j3Map.rtl.replace("jtag_", "").toUpperCase()}`,
- pinDefinition: j3Map.def,
- displayBadge: `FPGA U3.${j3Map.ball} · ${j3Map.rtl} (${j3Map.sig})`,
- tags: ["JTAG", j3Map.rtl.toUpperCase()],
- isUsed: true,
- };
- }
- return {
- chip: pnum === "4" ? "POWER" : (["2", "10"].includes(pnum) ? "GND" : "NC"),
- physicalPin: pnum === "4" ? "+3.3V" : (["2", "10"].includes(pnum) ? "GND" : "NC"),
- logicalSignal: j3Map ? j3Map.rtl : "NC (空脚)",
- boardSignal: net,
- peripheralRole: "JTAG 辅助针脚",
- pinDefinition: j3Map ? j3Map.def : `${key} JTAG 空脚 (NC)`,
- displayBadge: j3Map ? `板级参考 · ${j3Map.rtl}` : "NC · 未连接",
- tags: ["JTAG"],
- isUsed: true,
- };
- }
- // J25 MCU SWD (V1.2, V1.1, V2.0 - 5-pin header)
- if (ref === "J25") {
- const j25Map = {
- "1": {chip: "GND", phys: "GND", rtl: "GND", def: "板载 MCU SWD 调试参考地 (0V)"},
- "2": {chip: "MCU U27", phys: "U27.37", rtl: "PA14 / JTCK_SWCLK", def: "MCU SWD 时钟输入 (SWCLK, 经 R798)"},
- "3": {chip: "MCU U27", phys: "U27.34", rtl: "PA13 / JTMS_SWDIO", def: "MCU SWD 双向数据 (SWDIO, 经 R797)"},
- "4": {chip: "POWER", phys: "+3.3V", rtl: "VCC_3V3", def: "MCU SWD 目标参考电压 (+3.3V)"},
- "5": {chip: "MCU U27", phys: "U27.7", rtl: "NRST (MCU_RST#)", def: "MCU 硬件复位脚 (低有效, 经 R796)"},
- };
- const entry = j25Map[pnum];
- if (entry) {
- return {
- chip: entry.chip,
- physicalPin: entry.phys,
- logicalSignal: entry.rtl,
- boardSignal: net,
- peripheralRole: "MCU SWD 调试",
- pinDefinition: entry.def,
- displayBadge: `${entry.chip} ${entry.phys} · ${entry.rtl}`,
- tags: ["JTAG", "SWD", "MCU"],
- isUsed: false,
- };
- }
- }
- // Board-specific active peripheral mappings
- if (ver === "v2_0") {
- if (key === "CON12.3") {
- return {
- chip: "FPGA U3",
- physicalPin: "U3.K2",
- logicalSignal: "host_ttl_tx (EX_GPIO1)",
- boardSignal: "EX_GPIO1_TX",
- peripheralRole: "Host TTL TX (6400 V2.0 主通信口)",
- pinDefinition: "CPLD TTL 串口发送端 (3.3V LVCMOS, 经 R1875 0R 到 CON12.3;外部接收端须另接线)",
- displayBadge: "FPGA U3.K2 · host_ttl_tx (EX_GPIO1)",
- tags: ["UART", "HOST_TTL", "TTL"],
- isUsed: true,
- };
- }
- if (key === "CON12.4") {
- return {
- chip: "FPGA U3",
- physicalPin: "U3.J4",
- logicalSignal: "host_ttl_rx (EX_GPIO2)",
- boardSignal: "EX_GPIO2_RX",
- peripheralRole: "Host TTL RX (6400 V2.0 主通信口)",
- pinDefinition: "CPLD TTL 串口接收端 (3.3V LVCMOS, 经 R1876 0R 到 CON12.4;外部发送端须另接线)",
- displayBadge: "FPGA U3.J4 · host_ttl_rx (EX_GPIO2)",
- tags: ["UART", "HOST_TTL", "TTL"],
- isUsed: true,
- };
- }
- if (key === "CON103.1" || key === "CON103.2") {
- const isTx = pnum === "1";
- return {
- chip: "MCU U27 & CP2102 U33",
- physicalPin: isTx ? "U27.12 (PA2)" : "U27.13 (PA3)",
- logicalSignal: isTx ? "MCU_UART1_TX (PA2 / 电气图 TX1)" : "MCU_UART1_RX (PA3 / 电气图 RX1)",
- boardSignal: isTx ? "MCU_UART1_TX_CON" : "MCU_UART1_RX_CON",
- peripheralRole: isTx ? "板载 STM32 MCU 串口 TX (电气图标 -CON103)" : "板载 STM32 MCU 串口 RX (电气图标 -CON103)",
- pinDefinition: isTx
- ? "原生 BRD 网表经 R1029 接板载 STM32 U27.12 (PA2) 及经 R1921 接 CP2102 U33(电气图第4/9页标为 -CON103 TX1 接 -U6-2 P1.26 RX1;直连 FPGA U3.K2 的为 CON12.3)"
- : "原生 BRD 网表经 R1030 接板载 STM32 U27.13 (PA3) 及经 R1920 接 CP2102 U33(电气图第4/9页标为 -CON103 RX1 接 -U6-2 P1.25 TX1;直连 FPGA U3.J4 的为 CON12.4)",
- displayBadge: `MCU U27.${isTx ? "12 (PA2)" : "13 (PA3)"} · ${isTx ? "MCU_UART1_TX" : "MCU_UART1_RX"} [板载MCU]`,
- tags: ["UART", "MCU", "CON103"],
- isUsed: false,
- };
- }
- if (key === "CON134.1" || key === "CON134.2") {
- const isTx = pnum === "1";
- return {
- chip: "FPGA U3",
- physicalPin: isTx ? "U3.T14" : "U3.R13",
- logicalSignal: isTx ? "host_rs232_tx (RS232_TX)" : "host_rs232_rx (RS232_RX)",
- boardSignal: isTx ? "HOST_RS232_TX" : "HOST_RS232_RX",
- peripheralRole: isTx ? "Host RS232 TX" : "Host RS232 RX",
- pinDefinition: isTx ? "Host RS232 发送端 (经 U22 TRSF3232E 电平转换, 921600 8N1)" : "Host RS232 接收端 (经 U22 TRSF3232E 电平转换, 921600 8N1)",
- displayBadge: `FPGA U3.${isTx ? "T14" : "R13"} · ${isTx ? "host_rs232_tx" : "host_rs232_rx"}`,
- tags: ["UART", "HOST_RS232", "RS232"],
- isUsed: true,
- };
- }
- if (key === "CON77.1" || key === "CON77.2") {
- const isTx = pnum === "1";
- return {
- chip: "FPGA U3",
- physicalPin: isTx ? "U3.L10" : "U3.M9",
- logicalSignal: isTx ? "bmc_tx (BMC_TX)" : "bmc_rx (BMC_RX)",
- boardSignal: isTx ? "BMC_RS232_TX" : "BMC_RS232_RX",
- peripheralRole: isTx ? "BMC RS232 TX" : "BMC RS232 RX",
- pinDefinition: isTx ? "BMC 测温轮询串口发送端 (经 U22, 115200 8N1)" : "BMC 测温轮询串口接收端 (经 U22, 115200 8N1)",
- displayBadge: `FPGA U3.${isTx ? "L10" : "M9"} · ${isTx ? "bmc_tx (BMC_TX)" : "bmc_rx (BMC_RX)"}`,
- tags: ["UART", "BMC", "BMC_RS232"],
- isUsed: true,
- };
- }
- if (ref === "CON170" && (pnum === "3" || pnum === "6")) {
- const isTx = pnum === "3";
- return {
- chip: "FPGA U3",
- physicalPin: isTx ? "U3.L10" : "U3.M9",
- logicalSignal: isTx ? "bmc_tx (UART1_TX / RJ45备用)" : "bmc_rx (UART1_RX / RJ45备用)",
- boardSignal: isTx ? "RS232_TX1_RJ45" : "RS232_RX1_RJ45",
- peripheralRole: isTx ? "RJ45 BMC RS232 TX 备用口 (CON170.3)" : "RJ45 BMC RS232 RX 备用口 (CON170.6)",
- pinDefinition: isTx
- ? "RJ45 备用 BMC RS232 发送端 (经 R1898 并联 CON77.1 ↔ U22 ↔ R818 ↔ U3.L10)"
- : "RJ45 备用 BMC RS232 接收端 (经 R1899 并联 CON77.2 ↔ U22 ↔ R819 ↔ U3.M9)",
- displayBadge: `FPGA U3.${isTx ? "L10" : "M9"} · ${isTx ? "bmc_tx" : "bmc_rx"} [RJ45备用]`,
- tags: ["UART", "BMC", "CON170"],
- isUsed: false,
- };
- }
- if (key in V20_PTC_CONNECTOR_MAP) {
- const ptc = V20_PTC_CONNECTOR_MAP[key];
- const rtlPort = ptc.idx < 24 ? `ptc_pwm_out[${ptc.idx}]` : "未绑定输出";
- const tags = ["PTC", ptc.tag];
- if (ptc.altTag) tags.push(ptc.altTag);
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${ptc.ball}`,
- logicalSignal: `${rtlPort} (${ptc.net})`,
- boardSignal: ptc.net,
- peripheralRole: ptc.role,
- pinDefinition: `24V PTC 加热功率输出 (${ptc.role}, 500Hz 高有效 PWM)`,
- displayBadge: `FPGA U3.${ptc.ball} · ${rtlPort} (${ptc.tag}/${ptc.net})`,
- tags,
- isUsed: ptc.idx < 24,
- };
- }
- const v20FanMap = {
- "CON155.5": {tag: "FAN1", alt: "Front0", rtl: "fan_front_out[0]", ball: "P12", role: "1#腔新风/进风双风扇 PWM (Front0)"},
- "CON155.6": {tag: "FAN5", alt: "Rear0", rtl: "fan_rear_out[0]", ball: "A10", role: "1#腔排风/出风单风扇 PWM (Rear0)"},
- "CON155.11": {tag: "FAN2", alt: "Front1", rtl: "fan_front_out[1]", ball: "D8", role: "2#腔新风/进风双风扇 PWM (Front1)"},
- "CON155.12": {tag: "FAN6", alt: "Rear1", rtl: "fan_rear_out[1]", ball: "C7", role: "2#腔排风/出风单风扇 PWM (Rear1)"},
- "CON154.5": {tag: "FAN3", alt: "Front2", rtl: "fan_front_out[2]", ball: "C4", role: "3#腔新风/进风双风扇 PWM (Front2)"},
- "CON154.6": {tag: "FAN7", alt: "Rear2", rtl: "fan_rear_out[2]", ball: "B5", role: "3#腔排风/出风单风扇 PWM (Rear2)"},
- "CON154.11": {tag: "FAN4", alt: "Front3", rtl: "fan_front_out[3]", ball: "B1", role: "4#腔新风/进风双风扇 PWM (Front3)"},
- "CON154.12": {tag: "FAN8", alt: "Rear3", rtl: "fan_rear_out[3]", ball: "A14", role: "4#腔排风/出风单风扇 PWM (Rear3)"},
- };
- if (key in v20FanMap) {
- const f = v20FanMap[key];
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${f.ball}`,
- logicalSignal: `${f.rtl} (${f.alt})`,
- boardSignal: f.alt,
- peripheralRole: f.role,
- pinDefinition: `${f.role} (500Hz PWM;连接器高电平为ON,FPGA球位低电平为ON,经主板 2N7002 NMOS 反相, FAN_BOARD_INVERT_MASK=8'hFF)`,
- displayBadge: `FPGA U3.${f.ball} · ${f.rtl} (${f.alt}/${f.tag})`,
- tags: ["FAN", f.tag, f.alt.toUpperCase()],
- isUsed: true,
- };
- }
- const v20SsrMap = {
- "CON165.1": {tag: "SSR1", rtl: "ssr1_out (ssr_ctrl_out[0])", ball: "F3", role: "SSR1 固态继电器常开控制 (-1-7E 110W/24V)"},
- "CON165.2": {tag: "SSR2", rtl: "ssr2_out (ssr_ctrl_out[1])", ball: "F1", role: "SSR2 固态继电器常开控制 (-2-7E 220W/24V)"},
- "CON165.4": {tag: "SSR4", rtl: "ssr4_out (ssr_ctrl_out[2])", ball: "G4", role: "SSR4 固态继电器常开控制 (-4-7E 110W/24V)"},
- };
- if (key in v20SsrMap) {
- const s = v20SsrMap[key];
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${s.ball}`,
- logicalSignal: `${s.rtl} (${s.tag})`,
- boardSignal: `${s.tag}_CTRL`,
- peripheralRole: s.role,
- pinDefinition: `${s.role} (配置完成后固定输出 1'b1 高电平使能主回路)`,
- displayBadge: `FPGA U3.${s.ball} · ${s.rtl} (${s.tag})`,
- tags: ["SSR", s.tag],
- isUsed: true,
- };
- }
- const v20Con159Map = {
- "CON159.1": {tag: "M1", net: "PUL1 (X1-S)", ball: "C12", role: "1轴 -M1 (1#前部风门) STEP 脉冲 (X1-S → -U1 X-STEP)"},
- "CON159.2": {tag: "M1", net: "DIR1 (X1-D)", ball: "B12", role: "1轴 -M1 (1#前部风门) DIR 方向 (X1-D → -U1 X-DIR)"},
- "CON159.3": {tag: "M2", net: "PUL2 (Y1-S)", ball: "L12", role: "2轴 -M2 (1#后部风门) STEP 脉冲 (Y1-S → -U1 Y-STEP)"},
- "CON159.4": {tag: "M2", net: "DIR2 (Y1-D)", ball: "J11", role: "2轴 -M2 (1#后部风门) DIR 方向 (Y1-D → -U1 Y-DIR)"},
- "CON159.5": {tag: "M3", net: "PUL3 (Z1-S)", ball: "L14", role: "3轴 -M3 (1#顶部风门) STEP 脉冲 (Z1-S → -U1 Z-STEP)"},
- "CON159.6": {tag: "M3", net: "DIR3 (Z1-D)", ball: "K14", role: "3轴 -M3 (1#顶部风门) DIR 方向 (Z1-D → -U1 Z-DIR)"},
- "CON159.7": {tag: "M4", net: "PUL4 (A1-S)", ball: "L13", role: "轴4 -M4 (2#前部风门) STEP 脉冲 (A1-S → -U1 A-STEP)"},
- "CON159.8": {tag: "M4", net: "DIR4 (A1-D)", ball: "K11", role: "轴4 -M4 (2#前部风门) DIR 方向 (A1-D → -U1 A-DIR)"},
- "CON159.9": {tag: "MOTOR_EN", net: "ENA1", ball: "F3", role: "-U1 步进驱动板使能 ENA1 (与 CON165.1 SSR1 共用 U3.F3)"},
- };
- if (key in v20Con159Map) {
- const m = v20Con159Map[key];
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${m.ball}`,
- logicalSignal: `${m.net} (6400 协议空余 / 电气图第3页 -U1)`,
- boardSignal: net || m.net,
- peripheralRole: m.role,
- pinDefinition: `电气图第3/4页 ${m.role} ↔ FPGA U3.${m.ball}(6400 32B 热控协议未启用步进轴)`,
- displayBadge: `FPGA U3.${m.ball} · ${m.net} [第3页风门步进 / 协议空余]`,
- tags: ["MOTOR", m.tag, "CON159"],
- isUsed: false,
- };
- }
- }
- // V2.0 Fan Expansion Board
- if (ver === "v2_0_fan") {
- if (ball) {
- return {
- chip: "主板 FPGA U3 (直通)",
- physicalPin: `U3.${ball}`,
- logicalSignal: `${boardSig} (经 CON168 无源直通)`,
- boardSignal: net,
- peripheralRole: `${ref}.${pnum} 风扇 PWM 信号`,
- pinDefinition: `风扇子板无源直通 PWM 信号 (${ref}.${pnum} ↔ 主板 FPGA U3.${ball})`,
- displayBadge: `主板 FPGA U3.${ball} · ${boardSig} (无源直通)`,
- tags: ["FAN", ref],
- isUsed: true,
- };
- }
- }
- // V1.2 (MRDIMM / 8000) & V1.1 (6400)
- if (ver === "v1_2" || ver === "v1_1") {
- // MRDIMM dev 2.1.0: direct 3.3 V GPIO pins, not the 12 V KEYLED power output.
- if (ver === "v1_2" && ref === "CON140" && (pnum === "1" || pnum === "2")) {
- const isTx = pnum === "1";
- const b = isTx ? "T11" : "P13";
- const signal = isTx ? "host_ttl_tx" : "host_ttl_rx";
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${b}`,
- logicalSignal: signal,
- boardSignal: net,
- peripheralRole: `MRDIMM Host TTL ${isTx ? "TX" : "RX"}`,
- pinDefinition: `CON140.${pnum} 经 ${isTx ? "R1261" : "R1262"} 0Ω 直连 U3.${b},3.3V;3/4脚仍为GPIO,无信号地。共地另接 CON77.3/4。`,
- displayBadge: `FPGA U3.${b} · ${signal}`,
- tags: ["UART", "HOST_TTL", "TTL", "CON140"],
- isUsed: true,
- };
- }
- if (ver === "v1_2" && ref === "CON146" && (pnum === "1" || pnum === "3")) {
- return {
- chip: "BOARD",
- physicalPin: pnum === "1" ? "12V KEYLED功率输出" : "KEY3按键输入",
- logicalSignal: "当前固件未绑定",
- boardSignal: net,
- peripheralRole: "KEY/LED座,不能用作Host TTL",
- pinDefinition: pnum === "1"
- ? "H6 经 NMOS+PMOS 控制 +12V KEYLED_V3,输出有1µF和100nF电容;不是3.3V TTL。"
- : "N7 按键输入含10kΩ上拉及100nF电容;当前Host RX使用CON140.2。",
- displayBadge: "CON146 · 非Host串口",
- tags: ["KEYLED"],
- isUsed: false,
- };
- }
- // V1.1 Host TTL on CON30
- if (ver === "v1_1" && ref === "CON30" && (pnum === "3" || pnum === "4")) {
- const isTx = pnum === "4";
- return {
- chip: "FPGA U3",
- physicalPin: isTx ? "U3.A10" : "U3.B9",
- logicalSignal: isTx ? "host_ttl_tx (FAN_GPIO4)" : "host_ttl_rx (FAN_GPIO3)",
- boardSignal: isTx ? "MOTOR_EN_N / FAN_GPIO4" : "FAN_GPIO3",
- peripheralRole: isTx ? "6400 V1.1 Host TTL TX (活动串口)" : "6400 V1.1 Host TTL RX (活动串口)",
- pinDefinition: isTx
- ? "6400 V1.1 Host TTL 串口发送端 (FPGA U3.A10 → CON30.4, 3.3V LVCMOS)"
- : "6400 V1.1 Host TTL 串口接收端 (CON30.3 → FPGA U3.B9, 3.3V LVCMOS)",
- displayBadge: isTx
- ? "FPGA U3.A10 · host_ttl_tx (FAN_GPIO4)"
- : "FPGA U3.B9 · host_ttl_rx (FAN_GPIO3)",
- tags: ["UART", "HOST_TTL", "TTL", "CON30"],
- isUsed: true,
- };
- }
- // Host RS232 CON78 & BMC RS232 CON77
- if (ref === "CON78" && (pnum === "1" || pnum === "2")) {
- const isTx = pnum === "1";
- return {
- chip: "FPGA U3",
- physicalPin: isTx ? "U3.M10" : "U3.N11",
- logicalSignal: isTx ? "host_rs232_tx (UART2_TX)" : "host_rs232_rx (UART2_RX)",
- boardSignal: isTx ? "UART2_TX" : "UART2_RX",
- peripheralRole: isTx ? "Host RS232 TX (CON78.1)" : "Host RS232 RX (CON78.2)",
- pinDefinition: isTx
- ? "Host RS232 发送端 (U3.M10 → U23 RS232 收发器(V1.2 BOM: TRSF3232E) → CON78.1)"
- : "Host RS232 接收端 (CON78.2 → U23 RS232 收发器(V1.2 BOM: TRSF3232E) → U3.N11)",
- displayBadge: `FPGA U3.${isTx ? "M10" : "N11"} · ${isTx ? "host_rs232_tx (UART2_TX)" : "host_rs232_rx (UART2_RX)"}`,
- tags: ["UART", "HOST_RS232", "RS232"],
- isUsed: true,
- };
- }
- if (ref === "CON77" && (pnum === "1" || pnum === "2")) {
- const isTx = pnum === "1";
- return {
- chip: "FPGA U3",
- physicalPin: isTx ? "U3.L10" : "U3.M9",
- logicalSignal: isTx ? "bmc_tx (UART1_TX)" : "bmc_rx (UART1_RX)",
- boardSignal: isTx ? "UART1_TX" : "UART1_RX",
- peripheralRole: isTx ? "BMC RS232 TX (CON77.1)" : "BMC RS232 RX (CON77.2)",
- pinDefinition: isTx
- ? "BMC 测温轮询串口发送端 (U3.L10 → U22 RS232 收发器(V1.2 BOM: TRSF3232E) → CON77.1, 115200 8N1)"
- : "BMC 测温轮询串口接收端 (CON77.2 → U22 RS232 收发器(V1.2 BOM: TRSF3232E) → U3.M9, 115200 8N1)",
- displayBadge: `FPGA U3.${isTx ? "L10" : "M9"} · ${isTx ? "bmc_tx (UART1_TX)" : "bmc_rx (UART1_RX)"}`,
- tags: ["UART", "BMC", "BMC_RS232"],
- isUsed: true,
- };
- }
- // PTC on V1.2 / V1.1 (CON18, CON27, CON28, CON29)
- if (key in V12_V11_PTC_CONNECTOR_MAP) {
- const ptc = V12_V11_PTC_CONNECTOR_MAP[key];
- const isUsed = true;
- const rtlPort = ver === "v1_1"
- ? `ptc_pwm_out[${ptc.idx}]`
- : `ptc_pwm_out[${ptc.idx}] (逻辑PTC${Math.floor(ptc.idx / 6)})`;
- const role = ver === "v1_1" ? ptc.v11Role : `PTC${ptc.idx + 1} (腔${Math.floor(ptc.idx / 6) + 1},逻辑PTC${Math.floor(ptc.idx / 6)})`;
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${ptc.ball}`,
- logicalSignal: `${rtlPort} (${ptc.heat})`,
- boardSignal: ptc.heat,
- peripheralRole: role,
- pinDefinition: `+12V PTC 高边 MOS 功率输出 (${role}, 500Hz 高有效 PWM)`,
- displayBadge: `FPGA U3.${ptc.ball} · ${rtlPort}`,
- tags: ["PTC", ptc.tag],
- isUsed,
- };
- }
- // Current MRDIMM four buffered PWM channels; FG stays a board fact, not sampled by this protocol.
- const v12ActiveFans = {
- "CON25.7": {axis: 0, ball: "B1"},
- "CON8.7": {axis: 1, ball: "C4"},
- "CON24.7": {axis: 2, ball: "B5"},
- "CON26.7": {axis: 3, ball: "A14"},
- };
- if (ver === "v1_2" && key in v12ActiveFans) {
- const f = v12ActiveFans[key];
- const rtl = `fan_pwm_out[${f.axis}]`;
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${f.ball}`,
- logicalSignal: rtl,
- boardSignal: net,
- peripheralRole: `MRDIMM 腔${f.axis + 1} FAN${f.axis + 1} PWM`,
- pinDefinition: "500Hz PWM;主板MMBT2222 NPN反相,连接器高电平为ON、FPGA球位低电平为ON。",
- displayBadge: `FPGA U3.${f.ball} · ${rtl}`,
- tags: ["FAN", `FAN${f.axis + 1}`],
- isUsed: true,
- };
- }
- // V1.1 Active Fans (Front0..3 on CON25/CON8/CON24/CON26; Rear0..3 on CON64/CON66/CON62/CON60)
- const v11ActiveFans = {
- "CON25.7": {tag: "FAN1", alt: "Front0", rtl: "fan_front_out[0]", ball: "B1", sig: "FAN_PWM3", role: "6400 V1.1 Front0 前风扇 PWM (板级反相)"},
- "CON8.7": {tag: "FAN2", alt: "Front1", rtl: "fan_front_out[1]", ball: "C4", sig: "FAN_PWM1", role: "6400 V1.1 Front1 前风扇 PWM (板级反相)"},
- "CON24.7": {tag: "FAN3", alt: "Front2", rtl: "fan_front_out[2]", ball: "B5", sig: "FAN_PWM2", role: "6400 V1.1 Front2 前风扇 PWM (板级反相)"},
- "CON26.7": {tag: "FAN4", alt: "Front3", rtl: "fan_front_out[3]", ball: "A14", sig: "FAN_PWM4", role: "6400 V1.1 Front3 前风扇 PWM (板级反相)"},
- "CON64.4": {tag: "FAN5", alt: "Rear0", rtl: "fan_rear_out[0]", ball: "P15", sig: "FAN_GPIO44", role: "6400 V1.1 Rear0 后风扇 PWM (同相)"},
- "CON66.4": {tag: "FAN6", alt: "Rear1", rtl: "fan_rear_out[1]", ball: "N15", sig: "FAN_GPIO46", role: "6400 V1.1 Rear1 后风扇 PWM (同相)"},
- "CON62.4": {tag: "FAN7", alt: "Rear2", rtl: "fan_rear_out[2]", ball: "M14", sig: "FAN_GPIO42", role: "6400 V1.1 Rear2 后风扇 PWM (同相)"},
- "CON60.4": {tag: "FAN8", alt: "Rear3", rtl: "fan_rear_out[3]", ball: "P5", sig: "FAN_GPIO40", role: "6400 V1.1 Rear3 后风扇 PWM (同相)"},
- };
- if (ver === "v1_1" && key in v11ActiveFans) {
- const f = v11ActiveFans[key];
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${f.ball}`,
- logicalSignal: `${f.rtl} (${f.sig})`,
- boardSignal: f.sig,
- peripheralRole: f.role,
- pinDefinition: `${f.role} (500Hz PWM, FAN_BOARD_INVERT_MASK=8'h0F)`,
- displayBadge: `FPGA U3.${f.ball} · ${f.rtl} (${f.alt}/${f.tag})`,
- tags: ["FAN", f.tag, f.alt.toUpperCase()],
- isUsed: true,
- };
- }
- // V1.2 12 buffered axes in generator order, plus global enable CON120
- if (ver === "v1_2" && ref in V12_MOTOR_MAP) {
- const m = V12_MOTOR_MAP[ref];
- if (pnum === m.stepPin || pnum === m.dirPin) {
- const isStep = pnum === m.stepPin;
- const b = isStep ? m.stepBall : m.dirBall;
- const rtl = isStep ? `motor_step_gate[${m.axis}]` : `motor_dir_gate[${m.axis}]`;
- const snet = isStep ? m.stepNet : m.dirNet;
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${b}`,
- logicalSignal: `${rtl} (${snet})`,
- boardSignal: snet,
- peripheralRole: `${m.tag} (轴${m.axis}) ${isStep ? "STEP 脉冲" : "DIR 方向"}`,
- pinDefinition: `步进电机 ${m.tag} (轴${m.axis}) ${isStep ? "STEP 输出(2N7002 NMOS开漏;FPGA上升沿计步,对应座端下拉)" : "DIR 输出(2N7002 NMOS开漏反相)"}`,
- displayBadge: `FPGA U3.${b} · ${rtl} (${m.tag}_${isStep ? "STEP" : "DIR"})`,
- tags: ["MOTOR", m.tag],
- isUsed: true,
- };
- }
- }
- if (ver === "v1_2" && key === "CON120.2") {
- return {
- chip: "FPGA U3",
- physicalPin: "U3.C11",
- logicalSignal: "motor_en_n (MOTOR_EN_N)",
- boardSignal: "MOTOR_EN_N",
- peripheralRole: "步进电机全局使能 (MOTOR_EN)",
- pinDefinition: "电机驱动使能控制 (FPGA U3.C11 常驱高 1'b1 → Q145 2N7002 NMOS拉低座端 EN 保持有效)",
- displayBadge: "FPGA U3.C11 · motor_en_n (MOTOR_EN_N)",
- tags: ["MOTOR", "MOTOR_EN"],
- isUsed: true,
- };
- }
- // CON126/127 now carry active limit inputs; do not overwrite them as old X/Y/Z motor outputs.
- // V1.2 active limits: CON12/126/127/128/129/138
- if (ver === "v1_2" && key in V12_LIMIT_MAP) {
- const lim = V12_LIMIT_MAP[key];
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${lim.ball}`,
- logicalSignal: `${lim.rtl} (${lim.tag})`,
- boardSignal: boardSig || net,
- peripheralRole: lim.role,
- pinDefinition: `${lim.role} (3.3V 限位输入, 2FF 同步, 高电平有效阻断对应方向 STEP)`,
- displayBadge: `FPGA U3.${lim.ball} · ${lim.rtl} (${lim.tag})`,
- tags: ["LIMIT", lim.tag, `M${lim.axis + 1}`],
- isUsed: true,
- };
- }
- }
- // CT7428 Temperature Sensor Connectors (CON53, 55, 56, 57, 79..98 across all boards)
- if (/^CON(53|55|56|57|79|8[0-9]|9[0-8])$/.test(ref)) {
- const chOrder = [
- "CON53", "CON55", "CON56", "CON57", "CON79", "CON80", "CON81", "CON82",
- "CON83", "CON85", "CON87", "CON89", "CON84", "CON86", "CON88", "CON90",
- "CON91", "CON93", "CON95", "CON97", "CON92", "CON94", "CON96", "CON98",
- ];
- const v20ProbeRole = {
- CON53: "1#腔室进风温度",
- CON55: "1#腔室出风温度",
- CON56: "2#腔室进风温度",
- CON57: "2#腔室出风温度",
- CON79: "3#腔室进风温度",
- CON80: "3#腔室出风温度",
- CON81: "4#腔室进风温度",
- CON82: "4#腔室出风温度",
- }[ref];
- const chIdx = chOrder.indexOf(ref) + 1;
- const ctBalls = ver === "v1_1" ? "M8/N9(历史profile)" : "B14/A15";
- const chipName = chIdx <= 8 ? "U6" : (chIdx <= 16 ? "U24" : "U25");
- const upperNet = net.toUpperCase();
- const isGndPin = upperNet.includes("GND") || pin?.function_category === "ground" || text(pin?.external_level) === "0V";
- if (!isGndPin && (pnum === "1" || pnum === "2" || pnum === "3")) {
- const isDp = pnum === "1";
- const rolePrefix = ver === "v2_0" && v20ProbeRole ? `${v20ProbeRole} · ` : "";
- return {
- chip: `CT7428 ${chipName} ↔ FPGA U3`,
- physicalPin: `U3.${ctBalls} (SCL/SDA)`,
- logicalSignal: `temp_scl/temp_sda (${ctBalls}) → ${chipName}_CH${(chIdx-1)%8+1}_${isDp ? "DP" : "DN"}`,
- boardSignal: net || `${chipName}_CH${chIdx}_${isDp ? "DP" : "DN"}`,
- peripheralRole: `${rolePrefix}温度探头 CH${chIdx} ${isDp ? "DP+" : "DN-"}`,
- pinDefinition: `${rolePrefix}CT7428 (${chipName}) 远端二极管测温差分输入 ${isDp ? "DP+" : "DN-"} (经 I2C U3.${ctBalls};MRDIMM板载MCU须将I2C0 GPIO设高阻)`,
- displayBadge: `FPGA U3.${ctBalls} (temp_scl/temp_sda) ← ${chipName} CH${(chIdx-1)%8+1}`,
- tags: ["TEMP", `TEMP${chIdx}`],
- isUsed: true,
- };
- }
- }
- // Generic FPGA-mapped pin fallback
- if (ball) {
- const sig = boardSig || net || `${ref}_${pnum}`;
- const isSpare = text(touchpoint?.summary).includes("空余") || text(pin?.summary).includes("空余") || text(touchpoint?.summary).includes("非产品");
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${ball}`,
- logicalSignal: `${sig} (板级映射;以当前ADC为准)`,
- boardSignal: sig,
- peripheralRole: text(pin?.summary) || `${key} (${sig})`,
- pinDefinition: text(pin?.programming?.conclusion) || text(pin?.summary) || `${key} → FPGA U3.${ball} (${sig})`,
- displayBadge: `FPGA U3.${ball} · ${sig}${isSpare ? " [空余]" : ""}`,
- tags: ["GPIO"],
- isUsed: false,
- };
- }
- // Generic MCU-mapped pin fallback
- if (mcuDev && mcuPin) {
- return {
- chip: `MCU ${mcuDev}`,
- physicalPin: `${mcuDev}.${mcuPin}`,
- logicalSignal: `${mcuSig || net} (${text(pin?.mcu?.family) || "板载MCU"})`,
- boardSignal: mcuSig || net,
- peripheralRole: text(pin?.summary) || `${key} → MCU ${mcuDev}.${mcuPin}`,
- pinDefinition: text(pin?.programming?.conclusion) || text(pin?.summary) || `直连板载 MCU ${mcuDev}.${mcuPin} (${mcuSig}),非 FPGA 管脚`,
- displayBadge: `MCU ${mcuDev}.${mcuPin} · ${mcuSig || net} [板载MCU]`,
- tags: ["MCU"],
- isUsed: false,
- };
- }
- // Power / Ground fallback
- const upperNet = net.toUpperCase();
- const isGnd = upperNet.includes("GND") || pin?.function_category === "ground" || text(pin?.external_level) === "0V";
- return {
- chip: isGnd ? "GND" : "POWER/BOARD",
- physicalPin: isGnd ? "GND (0V)" : (net || text(pin?.external_level) || "BOARD"),
- logicalSignal: isGnd ? "GND (参考地)" : `${net || "BOARD_NET"} (${text(pin?.external_level) || "板级网络"})`,
- boardSignal: net,
- peripheralRole: isGnd ? "电源/信号地 (GND)" : (text(pin?.summary) || `${key} (${net})`),
- pinDefinition: text(pin?.summary) || (isGnd ? `${key} 板级公共参考地 (0V GND)` : `${key} 板级电源或外围网络 (${net})`),
- displayBadge: isGnd ? "GND · 0V 参考地" : `板级网络 · ${net || text(pin?.external_level) || "电源"}`,
- tags: [isGnd ? "GND" : "POWER"],
- isUsed: false,
- };
- }
- /**
- * Classify a touchpoint/connector into its peripheral type, usage status (used vs spare),
- * quick-filter tags, and enriched pin rows with explicit FPGA/MCU logical pin mappings.
- */
- export function classifyTouchpointPeripheral(touchpoint, boardVersion = "v2_0") {
- const ver = normalizeBoardVersion(boardVersion);
- const ref = text(touchpoint?.reference).trim();
- const summary = text(touchpoint?.summary).trim();
- const rawPins = (touchpoint?.pins ?? []).filter(
- (p) => p?.mechanical !== true && p?.pad_role !== "shield" && p?.pad_role !== "mechanical" && !text(p?.number).startsWith("SH"),
- );
- const resolvedPins = rawPins.map((pin) => {
- const logical = resolveLogicalPin(touchpoint, pin, ver);
- return {
- pin,
- pinNumber: text(pin?.number),
- net: text(pin?.net),
- direction: text(pin?.direction),
- level: text(pin?.external_level),
- logical,
- };
- });
- const tags = new Set([ref]);
- for (const rp of resolvedPins) {
- for (const t of rp.logical.tags ?? []) {
- tags.add(t);
- }
- }
- let peripheralType = "GPIO";
- let isUsed = false;
- let roleTitle = summary || ref;
- if (ver === "v2_0") {
- if (["CON147", "CON148", "CON149", "CON150"].includes(ref)) {
- peripheralType = "PTC";
- isUsed = true;
- } else if (["CON154", "CON155"].includes(ref)) {
- peripheralType = "FAN";
- isUsed = true;
- } else if (["CON156", "CON157", "CON158"].includes(ref)) {
- peripheralType = "FAN";
- isUsed = false;
- } else if (["CON12", "CON134", "CON77"].includes(ref)) {
- peripheralType = "UART";
- isUsed = true;
- } else if (["CON70", "CON103", "CON170"].includes(ref)) {
- peripheralType = "UART";
- isUsed = false;
- } else if (["CON165", "CON164"].includes(ref)) {
- peripheralType = "SSR";
- isUsed = true;
- } else if (/^CON(53|55|56|57|79|80|81|82)$/.test(ref)) {
- peripheralType = "TEMP";
- isUsed = true;
- } else if (["CON159", "CON160", "CON161", "CON162", "CON163"].includes(ref)) {
- peripheralType = "MOTOR";
- isUsed = false;
- } else if (["J3", "J19", "J25"].includes(ref)) {
- peripheralType = "JTAG";
- isUsed = ref !== "J25";
- } else if (["CON168", "CON172", "J29", "J30"].includes(ref)) {
- peripheralType = "MCU";
- isUsed = false;
- } else if (["CON173", "CON174"].includes(ref) || ref.startsWith("PL") || ref.startsWith("TP")) {
- peripheralType = "POWER";
- isUsed = true;
- } else {
- peripheralType = "GPIO";
- isUsed = false;
- }
- } else if (ver === "v2_0_fan") {
- if (["CON168", "CON8", "CON169", "CON170", "CON171"].includes(ref)) {
- peripheralType = "FAN";
- isUsed = true;
- } else {
- peripheralType = "POWER";
- isUsed = true;
- }
- } else if (ver === "v1_2") {
- if (["CON18", "CON27", "CON28", "CON29"].includes(ref)) {
- peripheralType = "PTC";
- isUsed = true;
- } else if (["CON25", "CON8", "CON24", "CON26"].includes(ref)) {
- peripheralType = "FAN";
- isUsed = true;
- } else if (["CON31", "CON32", "CON33", "CON34", "CON35", "CON68"].includes(ref)) {
- peripheralType = "FAN";
- isUsed = false;
- } else if (["CON140", "CON78", "CON77"].includes(ref)) {
- peripheralType = "UART";
- isUsed = true;
- } else if (["CON70", "CON102", "CON103", "CON134", "CON135"].includes(ref)) {
- peripheralType = "UART";
- isUsed = false;
- } else if (ref in V12_MOTOR_MAP || ref === "CON120") {
- peripheralType = "MOTOR";
- isUsed = true;
- } else if (["CON116", "CON117", "CON118", "CON119", "CON124", "CON125", "CON142"].includes(ref)) {
- peripheralType = "MOTOR";
- isUsed = false;
- } else if (["CON12", "CON126", "CON127", "CON128", "CON129", "CON138"].includes(ref)) {
- peripheralType = "LIMIT";
- isUsed = true;
- } else if (["J3", "J19", "J25"].includes(ref)) {
- peripheralType = "JTAG";
- isUsed = ref !== "J25";
- } else if (/^CON(53|55|56|57|79|8[0-9]|9[0-8])$/.test(ref)) {
- peripheralType = "TEMP";
- isUsed = true;
- } else if (["CON101", "CON130", "CON131", "CON132", "CON133", "J29", "J30"].includes(ref)) {
- peripheralType = "MCU";
- isUsed = false;
- } else if (["CON2", "CON23"].includes(ref) || ref.startsWith("PL") || ref.startsWith("TP")) {
- peripheralType = "POWER";
- isUsed = true;
- } else {
- peripheralType = "GPIO";
- isUsed = false;
- }
- } else {
- // v1_1 (6400 V1.1)
- if (["CON18", "CON27", "CON28", "CON29"].includes(ref)) {
- peripheralType = "PTC";
- isUsed = true;
- } else if (["CON25", "CON8", "CON24", "CON26", "CON64", "CON66", "CON62", "CON60"].includes(ref)) {
- peripheralType = "FAN";
- isUsed = true;
- } else if (["CON31", "CON32", "CON33", "CON34", "CON35", "CON68"].includes(ref)) {
- peripheralType = "FAN";
- isUsed = false;
- } else if (["CON30", "CON78", "CON77"].includes(ref)) {
- peripheralType = "UART";
- isUsed = true;
- } else if (["CON70"].includes(ref)) {
- peripheralType = "UART";
- isUsed = false;
- } else if (["J3", "J19", "J25"].includes(ref)) {
- peripheralType = "JTAG";
- isUsed = ref !== "J25";
- } else if (/^CON(53|55|56|57|79|8[0-9]|9[0-8])$/.test(ref)) {
- peripheralType = "TEMP";
- isUsed = true;
- } else if (["CON2", "CON23"].includes(ref) || ref.startsWith("PL") || ref.startsWith("TP")) {
- peripheralType = "POWER";
- isUsed = true;
- } else {
- peripheralType = "GPIO";
- isUsed = false;
- }
- }
- // Mark mechanical mounting holes (J8, J9, J11..18, J20..22, J26..27) as non-used mechanical
- if (/^J(8|9|11|12|13|14|17|18|20|21|22|26|27)$/.test(ref)) {
- peripheralType = "POWER";
- isUsed = false;
- }
- const isSpareConnector = !isUsed && (ref.startsWith("CON") || ref.startsWith("J"));
- if (isSpareConnector) {
- tags.add("SPARE");
- tags.add("空余插座");
- }
- return {
- reference: ref,
- touchpoint,
- peripheralType,
- peripheralLabel: PERIPHERAL_TYPE_LABELS[peripheralType] ?? peripheralType,
- isUsed,
- isSpareConnector,
- roleTitle,
- tags: Array.from(tags),
- pins: resolvedPins,
- };
- }
- /**
- * Build the complete peripheral & logical pin catalog for a board dataset.
- */
- export function buildPeripheralIndex(data, boardVersion = "v2_0") {
- const ver = normalizeBoardVersion(boardVersion, data);
- const items = (data?.touchpoints ?? [])
- .map((tp) => classifyTouchpointPeripheral(tp, ver))
- .sort((a, b) => {
- if (a.isUsed !== b.isUsed) return a.isUsed ? -1 : 1;
- const typeIdxA = PERIPHERAL_TYPE_ORDER.indexOf(a.peripheralType);
- const typeIdxB = PERIPHERAL_TYPE_ORDER.indexOf(b.peripheralType);
- if (typeIdxA !== typeIdxB) return typeIdxA - typeIdxB;
- return naturalCompare(a.reference, b.reference);
- });
- const categoryCounts = {ALL: items.length};
- for (const cat of PERIPHERAL_TYPE_ORDER) {
- if (cat !== "ALL") categoryCounts[cat] = 0;
- }
- let usedCount = 0;
- let spareCount = 0;
- for (const item of items) {
- categoryCounts[item.peripheralType] = (categoryCounts[item.peripheralType] ?? 0) + 1;
- if (item.isUsed) usedCount += 1;
- if (item.isSpareConnector) spareCount += 1;
- }
- // Build quick-jump chips tailored to the board
- const quickChips = [];
- if (ver === "v1_2") {
- quickChips.push(
- {label: "HOST TTL (CON140)", category: "UART", query: "CON140"},
- {label: "HOST RS232 (CON78)", category: "UART", query: "CON78"},
- {label: "BMC RS232 (CON77)", category: "UART", query: "CON77"},
- {label: "JTAG (J3)", category: "JTAG", query: "J3"},
- {label: "PTC1..6 (CON18)", category: "PTC", query: "CON18"},
- {label: "PTC7..12 (CON27)", category: "PTC", query: "CON27"},
- {label: "FAN1..4 (全部风扇)", category: "FAN", usage: "used", query: ""},
- {label: "电机 M1..M12", category: "MOTOR", usage: "used", query: ""},
- {label: "限位 LS1..12/HS1..12", category: "LIMIT", usage: "used", query: ""},
- {label: "空余插座", category: "ALL", usage: "spare", query: ""},
- );
- } else if (ver === "v2_0") {
- quickChips.push(
- {label: "HOST TTL (CON12)", category: "UART", query: "CON12"},
- {label: "HOST RS232 (CON134)", category: "UART", query: "CON134"},
- {label: "BMC RS232 (CON77)", category: "UART", query: "CON77"},
- {label: "JTAG (J3)", category: "JTAG", query: "J3"},
- {label: "PTC1", category: "PTC", query: "PTC1"},
- {label: "PTC 1#腔 (CON147)", category: "PTC", query: "CON147"},
- {label: "PTC 2#腔 (CON148)", category: "PTC", query: "CON148"},
- {label: "PTC 3#腔 (CON149)", category: "PTC", query: "CON149"},
- {label: "PTC 4#腔 (CON150)", category: "PTC", query: "CON150"},
- {label: "FAN 全部风扇", category: "FAN", usage: "used", query: ""},
- {label: "SSR 继电器 (CON165)", category: "SSR", query: "CON165"},
- {label: "JTAG / SWD", category: "JTAG", query: ""},
- {label: "空余插座", category: "ALL", usage: "spare", query: ""},
- );
- } else if (ver === "v2_0_fan") {
- quickChips.push(
- {label: "控制输入 (CON168)", category: "FAN", query: "CON168"},
- {label: "FAN1 (CON8)", category: "FAN", query: "CON8"},
- {label: "FAN2 (CON169)", category: "FAN", query: "CON169"},
- {label: "FAN3 (CON170)", category: "FAN", query: "CON170"},
- {label: "FAN4 (CON171)", category: "FAN", query: "CON171"},
- {label: "+12V 电源 (CON2/172)", category: "POWER", query: ""},
- );
- } else {
- quickChips.push(
- {label: "HOST TTL (CON30)", category: "UART", query: "CON30"},
- {label: "HOST RS232 (CON78)", category: "UART", query: "CON78"},
- {label: "BMC RS232 (CON77)", category: "UART", query: "CON77"},
- {label: "JTAG (J3)", category: "JTAG", query: "J3"},
- {label: "PTC1", category: "PTC", query: "PTC1"},
- {label: "PTC1..24 全部", category: "PTC", usage: "used", query: ""},
- {label: "FAN 前/后全部", category: "FAN", usage: "used", query: ""},
- {label: "空余插座", category: "ALL", usage: "spare", query: ""},
- );
- }
- return {
- boardVersion: ver,
- items,
- categoryCounts,
- usedCount,
- spareCount,
- quickChips,
- };
- }
- /**
- * Filter the peripheral catalog by category, usage ("all" | "used" | "spare"), and query string.
- */
- export function filterPeripheralCatalog(data, boardVersion = "v2_0", options = {}) {
- const index = buildPeripheralIndex(data, boardVersion);
- const category = text(options.category || "ALL").toUpperCase();
- const usage = text(options.usage || "all").toLowerCase();
- const rawQuery = text(options.query || "").trim();
- const needle = normalized(rawQuery);
- const exactTag = rawQuery.toUpperCase();
- const filtered = index.items.filter((item) => {
- if (category !== "ALL" && item.peripheralType !== category) return false;
- if (usage === "used" && !item.isUsed) return false;
- if (usage === "spare" && !item.isSpareConnector) return false;
- if (!needle) return true;
- // Check exact tag match first (e.g., "PTC1" should not match "PTC10" if exact tag exists)
- if (/^(PTC|FAN|M|LS|HS|SSR|TEMP)\d+$/i.test(rawQuery)) {
- const hasExactTag = item.tags.some((t) => t.toUpperCase() === exactTag) ||
- item.pins.some((p) => (p.logical.tags ?? []).some((t) => t.toUpperCase() === exactTag));
- if (hasExactTag) return true;
- return false;
- }
- const haystack = normalized([
- item.reference,
- item.peripheralType,
- item.peripheralLabel,
- item.roleTitle,
- ...item.tags,
- ...item.pins.flatMap((p) => [
- `${item.reference}.${p.pinNumber}`,
- p.net,
- p.logical.physicalPin,
- p.logical.logicalSignal,
- p.logical.boardSignal,
- p.logical.peripheralRole,
- p.logical.pinDefinition,
- p.logical.displayBadge,
- ]),
- ].join(" "));
- return haystack.includes(needle);
- });
- // If filtering by specific pin tag (like PTC1, M1, LS1), highlight matching pins
- const matchingItems = filtered.map((item) => {
- if (!needle) return {...item, matchedPinNumbers: []};
- const matchedPinNumbers = item.pins
- .filter((p) => {
- if (/^(PTC|FAN|M|LS|HS|SSR|TEMP)\d+$/i.test(rawQuery)) {
- return (p.logical.tags ?? []).some((t) => t.toUpperCase() === exactTag);
- }
- const pinHaystack = normalized([
- `${item.reference}.${p.pinNumber}`,
- p.net,
- p.logical.physicalPin,
- p.logical.logicalSignal,
- p.logical.boardSignal,
- p.logical.peripheralRole,
- p.logical.pinDefinition,
- p.logical.displayBadge,
- ].join(" "));
- return pinHaystack.includes(needle);
- })
- .map((p) => p.pinNumber);
- return {...item, matchedPinNumbers};
- });
- return {
- ...index,
- filteredItems: matchingItems,
- };
- }
|