import fs from 'node:fs' import assert from 'node:assert/strict' // Independent copy of the published Y50 path. No publication or device call. const [snapshotPath, outputPath, summaryPath] = process.argv.slice(2) if (!snapshotPath || !outputPath) throw new Error('Usage: node build_large_frame_scan.mjs [summary.json]') const snapshot = JSON.parse(fs.readFileSync(snapshotPath, 'utf8').replace(/^\uFEFF/, '')) assert.equal(snapshot.published.id, 'a02ccea8e279e8c9caf0acb6d6cb1dc9', 'Review another source version first') const original = JSON.parse(snapshot.published.flowData) const mapping = { LM302: 'LM402', LM304: 'LM404', LM306: 'LM406', LM308: 'LM408' } const reverse = Object.fromEntries(Object.entries(mapping).map(([a,b]) => [b,a])) function remap(value, names) { if (typeof value === 'string') return value.replace(/LM(?:302|304|306|308|402|404|406|408)/g, name => names[name] || name) if (Array.isArray(value)) return value.map(v => remap(v,names)) if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key,v]) => [remap(key,names),remap(v,names)])) return value } assert(!JSON.stringify(original).includes('LM402') && !JSON.stringify(original).includes('LM404') && !JSON.stringify(original).includes('LM406') && !JSON.stringify(original).includes('LM408')) const graph = remap(original, mapping) assert.deepEqual(remap(graph, reverse), original, 'Only station identifiers and their corresponding labels/parameter names may change') assert.equal(graph.nodes.length, 291) const byId = new Map(graph.nodes.map(n => [n.id,n])), order = [] for (let n=graph.nodes.find(n=>n.type==='start'); n;) { assert(!order.includes(n), 'Unexpected root cycle'); order.push(n) const edges=graph.edges.filter(e=>e.sourceNodeId===n.id); assert(edges.length<=1) n=edges.length?byId.get(edges[0].targetNodeId):null } const stations=order.filter(n=>n.properties.action==='AGV_MOVE_TO_STATION').map(n=>n.properties.nodeParams.find(p=>p.name==='stationId').input) assert.deepEqual(stations,['LM402','LM404','LM406','LM408']) assert(!JSON.stringify(graph).match(/LM30[2468]/)) assert.deepEqual(graph.edges,original.edges) for(const n of graph.nodes.filter(n=>n.properties.action==='SCANNER_PARAMETERS')) { const body=JSON.parse(n.properties.nodeParams.find(p=>p.name==='requestJson').input) assert.equal(body.pointDistance,0.7); assert.equal(body.brightness,17) } fs.writeFileSync(outputPath,JSON.stringify(graph,null,2)) const summary={name:'大车架扫描路径',stations,nodes:graph.nodes.length,inputCount:graph.nodes.find(n=>n.type==='start').properties.inputParams.length,onlyStationNamesChanged:true,published:false,deviceCommandsSent:0} if(summaryPath)fs.writeFileSync(summaryPath,JSON.stringify(summary,null,2)) console.log(JSON.stringify(summary))