| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006 |
- 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}, 20Hz 统一高有效 PWM, 50ms周期)`,
- displayBadge: `FPGA U3.${ptc.ball} · ${rtlPort} (${ptc.tag}/${ptc.net})`,
- tags,
- isUsed: ptc.idx < 24,
- };
- }
- const v20FanMap = {
- "CON154.5": {tag: "FAN1", alt: "Front0", rtl: "fan_front_out[0]", ball: "C4", role: "1#腔新风/进风双风扇 PWM (Front0)"},
- "CON154.6": {tag: "FAN5", alt: "Rear0", rtl: "fan_rear_out[0]", ball: "B5", role: "1#腔排风/出风单风扇 PWM (Rear0)"},
- "CON154.11": {tag: "FAN2", alt: "Front1", rtl: "fan_front_out[1]", ball: "B1", role: "2#腔新风/进风双风扇 PWM (Front1)"},
- "CON154.12": {tag: "FAN6", alt: "Rear1", rtl: "fan_rear_out[1]", ball: "A14", role: "2#腔排风/出风单风扇 PWM (Rear1)"},
- "CON155.5": {tag: "FAN3", alt: "Front2", rtl: "fan_front_out[2]", ball: "P12", role: "3#腔新风/进风双风扇 PWM (Front2)"},
- "CON155.6": {tag: "FAN7", alt: "Rear2", rtl: "fan_rear_out[2]", ball: "A10", role: "3#腔排风/出风单风扇 PWM (Rear2)"},
- "CON155.11": {tag: "FAN4", alt: "Front3", rtl: "fan_front_out[3]", ball: "D8", role: "4#腔新风/进风双风扇 PWM (Front3)"},
- "CON155.12": {tag: "FAN8", alt: "Rear3", rtl: "fan_rear_out[3]", ball: "C7", 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} (20Hz 统一 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.14": {tag: "SSR1", rtl: "ssr1_out", ball: "E14", role: "SSR1 腔1加热布 20Hz PWM 控制 (-1-7E 110W/24V,CON_PE14→R1698/R1860→CPLD_GPIO64)"},
- "CON165.13": {tag: "SSR2", rtl: "ssr2_out", ball: "E8", role: "SSR2 腔2+3共用加热布 20Hz PWM 控制 (-2-7E 220W/24V,CON_PE13→R1695/R1859→ADC0_CH7)"},
- "CON165.11": {tag: "SSR4", rtl: "ssr4_out", ball: "D9", role: "SSR4 腔4加热布 20Hz PWM 控制 (-4-7E 110W/24V,CON_PE11→R1694/R1857→ADC0_CH5)"},
- };
- 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} (电气图 V3.0 第4页对齐;20Hz 统一 PWM 50ms周期,默认/看门狗输出 0%)`,
- displayBadge: `FPGA U3.${s.ball} · ${s.rtl} (${s.tag})`,
- tags: ["SSR", s.tag],
- isUsed: true,
- };
- }
- const v20BtnMap = {
- "CON165.10": {tag: "EPB1", rtl: "estop_btn_in", ball: "F8", byteIdx: 86, role: "急停按钮 EPB1 检测 (IO10/CON_PE10→R1696/R1856→ADC0_CH0)", extra: "无 CPLD 安全联锁(外部电路直接失效开关罩),仅透传"},
- "CON165.9": {tag: "SB1", rtl: "hood_open_btn_in", ball: "C11", byteIdx: 87, role: "开罩按钮 SB1 检测 (IO9/CON_PE9→R1693/R1855→BANK0_GPIO2)", extra: "不主动上报"},
- "CON165.8": {tag: "SB2", rtl: "hood_close_btn_in", ball: "A11", byteIdx: 88, role: "合罩按钮 SB2 检测 (IO8/CON_PE8→R1692/R1854→BANK0_GPIO1)", extra: "不主动上报"},
- };
- if (key in v20BtnMap) {
- const b = v20BtnMap[key];
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${b.ball}`,
- logicalSignal: `${b.rtl} (${b.tag})`,
- boardSignal: net || b.tag,
- peripheralRole: b.role,
- pinDefinition: `${b.role};外部上拉电阻未贴装,约束配 LVCMOS33 + 内部 PULLDOWN(未按下/无电=0x00,按下高电平=0x01),仅 GET_ALL 写入回包第 ${b.byteIdx} 字节(${b.extra})`,
- displayBadge: `FPGA U3.${b.ball} · ${b.rtl} (${b.tag})`,
- tags: ["SSR", "GPIO", b.tag, "BUTTON"],
- isUsed: true,
- };
- }
- if (key === "CON165.12") {
- return {
- chip: "NC",
- physicalPin: "NC (V3.0 空脚)",
- logicalSignal: "未连接 (已取消旧版暂绑 U3.F7)",
- boardSignal: net || "CON_PE12",
- peripheralRole: "CON165.12 空脚 (NC)",
- pinDefinition: "电气图 V3.0 第4页确认 CON165.12 为空脚,不再沿用旧版暂绑的 U3.F7。",
- displayBadge: "NC · V3.0 空脚",
- tags: ["SSR"],
- isUsed: false,
- };
- }
- if (key === "CON165.1" || key === "CON165.2" || key === "CON165.4") {
- const retiredBall = key === "CON165.1" ? "F3" : (key === "CON165.2" ? "F1" : "G4");
- const idx = key === "CON165.1" ? 0 : (key === "CON165.2" ? 1 : 2);
- return {
- chip: "FPGA U3",
- physicalPin: `U3.${retiredBall}`,
- logicalSignal: `ssr_unused_zero[${idx}] (固定低电平)`,
- boardSignal: net,
- peripheralRole: "旧版废弃 SSR 引脚 (钳位低电平)",
- pinDefinition: `旧版 SSR 引脚 U3.${retiredBall},现由 ssr_unused_zero[${idx}] 固定输出 0。`,
- displayBadge: `FPGA U3.${retiredBall} · ssr_unused_zero[${idx}]`,
- tags: ["SSR"],
- isUsed: false,
- };
- }
- if (key === "CON146.1") {
- return {
- chip: "FPGA U3",
- physicalPin: "U3.H6",
- logicalSignal: "buzzer_out (KEYLED_V3 +24V 蜂鸣器)",
- boardSignal: "KEYLED_V3",
- peripheralRole: "MCU 触发蜂鸣器 +24V 高边驱动 (4000Hz 80% 占空比)",
- pinDefinition: "CON146.1 KEYLED_V3 (+24V 高边输出) ← Q10620/Q10621 ← R1297/R1301 ← U3.H6;SET_ALL 第 35 字节控制(0x00 关闭、0x01 开启输出 4000Hz 80% 占空比方波:6250拍周期/5000高/1250低),GET_DATA 第 89 字节回读,复位/看门狗保持低电平;非 TTL。",
- displayBadge: "FPGA U3.H6 · buzzer_out (4000Hz 80%)",
- tags: ["BUZZER", "KEYLED", "CON146"],
- 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 === "CON140" && pnum === "3") {
- return {
- chip: "FPGA U3",
- physicalPin: "U3.L3",
- logicalSignal: "hood_switch_in (EX_GPIO31)",
- boardSignal: net,
- peripheralRole: "MRDIMM 高温罩开关输入 (GET_ALL 字节63)",
- pinDefinition: "CON140.3 经 R1263 接 U3.L3 (LVCMOS33 + PULLDOWN, 非 GND);仅 GET_ALL 时采样放进第 63 字节。",
- displayBadge: "FPGA U3.L3 · hood_switch_in",
- tags: ["GPIO", "CON140"],
- isUsed: true,
- };
- }
- if (ver === "v1_2" && ref === "CON146" && (pnum === "1" || pnum === "3")) {
- if (pnum === "1") {
- return {
- chip: "FPGA U3",
- physicalPin: "U3.H6",
- logicalSignal: "buzzer_out (12V KEYLED_V3 蜂鸣器)",
- boardSignal: net,
- peripheralRole: "MCU 触发蜂鸣器 12V 高边输出(不能用作 Host TTL)",
- pinDefinition: "U3.H6 经 NMOS+PMOS 控制 +12V KEYLED_V3(4000Hz 80% 占空比方波:6250拍周期/5000高/1250低;SET_ALL 字节68 / GET_DATA 字节64),输出有1µF和100nF电容;不是3.3V TTL。",
- displayBadge: "FPGA U3.H6 · buzzer_out (12V 蜂鸣器 / 非TTL)",
- tags: ["KEYLED", "BUZZER"],
- isUsed: true,
- };
- }
- return {
- chip: "BOARD",
- physicalPin: "KEY3按键输入",
- logicalSignal: "当前固件未绑定",
- boardSignal: net,
- peripheralRole: "KEY/LED座,不能用作Host TTL",
- pinDefinition: "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}, 20Hz 统一高有效 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: "20Hz 统一 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 (ref === "CON146") {
- peripheralType = "GPIO";
- 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 (ref === "CON146") {
- peripheralType = "GPIO";
- isUsed = true;
- } 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 (ref === "CON146") {
- peripheralType = "GPIO";
- 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: "蜂鸣器 4kHz (CON146)", category: "GPIO", query: "CON146"},
- {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,
- };
- }
|