|
@@ -1,412 +1,354 @@
|
|
|
-// XJKJ-STL Web Interface (gRPC-Web client)
|
|
|
|
|
-(function () {
|
|
|
|
|
- let currentStationId = "S1";
|
|
|
|
|
- let solOffsets = {}; // station_id -> offset
|
|
|
|
|
- let isPolling = false;
|
|
|
|
|
- let autoScroll = true;
|
|
|
|
|
-
|
|
|
|
|
- // gRPC-Web client call
|
|
|
|
|
- async function callGrpc(methodName, payload = {}) {
|
|
|
|
|
- const url = `/stl.v1.BenchService/${methodName}`;
|
|
|
|
|
|
|
+// UI state stays local. All device actions and records belong to BenchService.
|
|
|
|
|
+(() => {
|
|
|
|
|
+ const $ = id => document.getElementById(id);
|
|
|
|
|
+ const escape = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
|
|
|
+ let stationId = 'S1', stations = [], recipes = [], history = [], historySelection = '';
|
|
|
|
|
+ let selectedRun = '', polling = false, selectionRevision = 0, connected = false;
|
|
|
|
|
+ let startStation = '', targetRun = '', currentMode = '';
|
|
|
|
|
+ const logs = new Map(), pending = new Map();
|
|
|
|
|
+ const stamp = () => new Date().toLocaleTimeString();
|
|
|
|
|
+ const id = () => `web-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
|
|
|
+ const current = () => stations.find(s => s.station_id === stationId);
|
|
|
|
|
+ const operator = () => $('start-operator').value.trim() || 'operator';
|
|
|
|
|
+ const decode = value => Uint8Array.from(atob(value || ''), c => c.charCodeAt(0));
|
|
|
|
|
+ function encode(bytes) {
|
|
|
|
|
+ let text = '';
|
|
|
|
|
+ for (let i = 0; i < bytes.length; i += 8192) text += String.fromCharCode(...bytes.subarray(i, i + 8192));
|
|
|
|
|
+ return btoa(text);
|
|
|
|
|
+ }
|
|
|
|
|
+ function status(text, error = false) {
|
|
|
|
|
+ $('action-status').textContent = text;
|
|
|
|
|
+ $('action-status').classList.toggle('error', error);
|
|
|
|
|
+ }
|
|
|
|
|
+ function enable(button, allowed) { $(button).disabled = !allowed || $(button).dataset.busy === '1'; }
|
|
|
|
|
+ function time(ms) { return Number(ms) > 0 ? new Date(Number(ms)).toLocaleString() : '未知'; }
|
|
|
|
|
+ function temp(measurement) {
|
|
|
|
|
+ if (typeof measurement?.value_c !== 'number') return '--°C';
|
|
|
|
|
+ if (measurement.quality === 'valid') return `${measurement.value_c.toFixed(1)}°C`;
|
|
|
|
|
+ if (measurement.source === 'bmc_sdr' && measurement.quality === 'unverified') return `${measurement.value_c.toFixed(1)}°C (BMC报告)`;
|
|
|
|
|
+ return '--°C';
|
|
|
|
|
+ }
|
|
|
|
|
+ function runLog(runId) {
|
|
|
|
|
+ if (!logs.has(runId)) logs.set(runId, {offset: 0, text: '', decoder: new TextDecoder(), events: [], eventCursor: 0});
|
|
|
|
|
+ return logs.get(runId);
|
|
|
|
|
+ }
|
|
|
|
|
+ async function callGrpc(method, payload = {}) {
|
|
|
|
|
+ const controller = new AbortController();
|
|
|
|
|
+ const timer = setTimeout(() => controller.abort(), 20000);
|
|
|
try {
|
|
try {
|
|
|
- const resp = await fetch(url, {
|
|
|
|
|
- method: "POST",
|
|
|
|
|
- headers: {
|
|
|
|
|
- "Content-Type": "application/grpc-web+json",
|
|
|
|
|
- "X-Grpc-Web": "1",
|
|
|
|
|
- },
|
|
|
|
|
- body: JSON.stringify(payload),
|
|
|
|
|
|
|
+ const token = sessionStorage.getItem('stl_api_token');
|
|
|
|
|
+ const payloadBytes = new TextEncoder().encode(JSON.stringify(payload));
|
|
|
|
|
+ const frame = new Uint8Array(5 + payloadBytes.length);
|
|
|
|
|
+ new DataView(frame.buffer).setUint32(1, payloadBytes.length); frame.set(payloadBytes, 5);
|
|
|
|
|
+ const response = await fetch(`/stl.v1.BenchService/${method}`, {
|
|
|
|
|
+ method: 'POST', headers: {'Content-Type': 'application/grpc-web+json', 'X-Grpc-Web': '1', ...(token ? {Authorization: `Bearer ${token}`} : {})},
|
|
|
|
|
+ body: frame, signal: controller.signal,
|
|
|
});
|
|
});
|
|
|
- const grpcStatus = resp.headers.get("grpc-status");
|
|
|
|
|
- if (grpcStatus && grpcStatus !== "0") {
|
|
|
|
|
- const msg = decodeURIComponent(resp.headers.get("grpc-message") || "RPC Error");
|
|
|
|
|
- throw new Error(msg);
|
|
|
|
|
|
|
+ if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
|
|
|
|
+ const bytes = new Uint8Array(await response.arrayBuffer()), view = new DataView(bytes.buffer);
|
|
|
|
|
+ let data = null, trailers = null, offset = 0;
|
|
|
|
|
+ while (offset < bytes.length) {
|
|
|
|
|
+ if (bytes.length - offset < 5) throw new Error('gRPC-Web 响应帧不完整');
|
|
|
|
|
+ const flags = bytes[offset], length = view.getUint32(offset + 1); offset += 5;
|
|
|
|
|
+ if (offset + length > bytes.length) throw new Error('gRPC-Web 响应数据不完整');
|
|
|
|
|
+ const text = new TextDecoder().decode(bytes.subarray(offset, offset + length)); offset += length;
|
|
|
|
|
+ if (flags === 128) {
|
|
|
|
|
+ trailers = Object.fromEntries(text.trim().split(/\r?\n/).filter(Boolean).map(line => {
|
|
|
|
|
+ const colon = line.indexOf(':'); return [line.slice(0, colon).toLowerCase(), line.slice(colon + 1).trim()];
|
|
|
|
|
+ }));
|
|
|
|
|
+ } else if (flags === 0 && data === null) { data = JSON.parse(text); }
|
|
|
|
|
+ else throw new Error('不支持的 gRPC-Web 响应帧');
|
|
|
}
|
|
}
|
|
|
- return await resp.json();
|
|
|
|
|
- } catch (err) {
|
|
|
|
|
- console.warn(`gRPC call ${methodName} error:`, err);
|
|
|
|
|
- throw err;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!trailers || trailers['grpc-status'] !== '0') {
|
|
|
|
|
+ throw new Error(decodeURIComponent(trailers?.['grpc-message'] || 'gRPC 状态缺失'));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (data === null) throw new Error('缺少 gRPC 响应消息');
|
|
|
|
|
+ return data;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ if (error.name === 'AbortError') throw new Error('请求超时;写操作可能已被接受,请查看工位和操作状态,勿重复点击');
|
|
|
|
|
+ throw error;
|
|
|
|
|
+ } finally { clearTimeout(timer); }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Formatting helpers
|
|
|
|
|
- function fmtTime(timestampMs) {
|
|
|
|
|
- if (!timestampMs) return "--:--:--";
|
|
|
|
|
- const d = new Date(timestampMs);
|
|
|
|
|
- return d.toTimeString().split(" ")[0];
|
|
|
|
|
|
|
+ async function command(method, request, label) {
|
|
|
|
|
+ const result = await callGrpc(method, {command_id: id(), operator: operator(), ...request});
|
|
|
|
|
+ pending.set(result.command_id, {label, station: stationId});
|
|
|
|
|
+ showCommand(result, label);
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Update System Info
|
|
|
|
|
- async function loadSystemInfo() {
|
|
|
|
|
- try {
|
|
|
|
|
- const info = await callGrpc("GetSystemInfo", {});
|
|
|
|
|
- document.getElementById("sys-version").textContent = info.version || "v0.1.1";
|
|
|
|
|
- document.getElementById("sys-commit").textContent = (info.git_commit || "994e0b1").substring(0, 7);
|
|
|
|
|
- const isSim = info.mode === "simulated";
|
|
|
|
|
- const modeBadge = document.getElementById("sys-mode");
|
|
|
|
|
- modeBadge.textContent = isSim ? "仿真模拟" : "硬件实机";
|
|
|
|
|
- modeBadge.style.backgroundColor = isSim ? "#7c3aed" : "#059669";
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- // Offline fallback
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ function showCommand(result, label) {
|
|
|
|
|
+ const meanings = {accepted: '已接受,后台执行中', running: '执行中', succeeded: '执行成功', failed: '执行失败', interrupted: '已中断'};
|
|
|
|
|
+ status(`${label}:${meanings[result.state] || result.state}${result.detail ? ' — ' + result.detail : ''}`, ['failed', 'interrupted'].includes(result.state));
|
|
|
|
|
+ if (['succeeded', 'failed', 'interrupted'].includes(result.state)) pending.delete(result.command_id);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Update Recipes
|
|
|
|
|
- async function loadRecipes() {
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await callGrpc("ListRecipes", {});
|
|
|
|
|
- const select = document.getElementById("start-recipe");
|
|
|
|
|
- select.innerHTML = "";
|
|
|
|
|
- const recipes = res.recipes || [];
|
|
|
|
|
- for (const r of recipes) {
|
|
|
|
|
- const opt = document.createElement("option");
|
|
|
|
|
- opt.value = r.recipe_id;
|
|
|
|
|
- opt.textContent = `${r.recipe_id} (${r.description || "标准测试"})`;
|
|
|
|
|
- select.appendChild(opt);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (e) {}
|
|
|
|
|
|
|
+ async function action(button, task) {
|
|
|
|
|
+ const element = $(button);
|
|
|
|
|
+ if (element.dataset.busy === '1') return;
|
|
|
|
|
+ element.dataset.busy = '1'; element.disabled = true;
|
|
|
|
|
+ try { await task(); } catch (error) { status(error.message, true); }
|
|
|
|
|
+ finally { element.dataset.busy = ''; element.disabled = false; renderDetail(); await poll(); }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Render 4 Station Cards
|
|
|
|
|
- function renderStationCards(stations) {
|
|
|
|
|
- const container = document.getElementById("stations-grid");
|
|
|
|
|
- container.innerHTML = "";
|
|
|
|
|
-
|
|
|
|
|
- for (const s of stations) {
|
|
|
|
|
- const card = document.createElement("div");
|
|
|
|
|
- const isSelected = s.station_id === currentStationId;
|
|
|
|
|
- card.className = `station-card ${isSelected ? "active" : ""}`;
|
|
|
|
|
- card.onclick = () => selectStation(s.station_id);
|
|
|
|
|
-
|
|
|
|
|
- const isOffline = s.supply_state === "unknown" && s.mode !== "simulated" && !s.run_id;
|
|
|
|
|
- let statusTag = (s.phase || "IDLE").toUpperCase();
|
|
|
|
|
- let tagClass = "tag-idle";
|
|
|
|
|
- if (s.phase === "running" || s.phase === "uip" || s.phase === "rmt" || s.phase === "mt" || s.phase === "amt") {
|
|
|
|
|
- tagClass = "tag-running";
|
|
|
|
|
- } else if (s.verdict === "pass") {
|
|
|
|
|
- tagClass = "tag-completed";
|
|
|
|
|
- } else if (s.verdict === "fail") {
|
|
|
|
|
- tagClass = "tag-failed";
|
|
|
|
|
- } else if (isOffline) {
|
|
|
|
|
- tagClass = "tag-offline";
|
|
|
|
|
- statusTag = "OFFLINE";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const hoodTemp = s.temperature?.hood_air?.value_c !== undefined
|
|
|
|
|
- ? `${s.temperature.hood_air.value_c.toFixed(1)}°C`
|
|
|
|
|
- : "--°C";
|
|
|
|
|
- const targetTemp = s.temperature?.applied_target_c !== undefined
|
|
|
|
|
- ? `${s.temperature.applied_target_c.toFixed(1)}°C`
|
|
|
|
|
- : (s.temperature?.requested_target_c !== undefined ? `${s.temperature.requested_target_c.toFixed(1)}°C` : "--°C");
|
|
|
|
|
-
|
|
|
|
|
- card.innerHTML = `
|
|
|
|
|
- <div class="station-card-header">
|
|
|
|
|
- <span class="station-name">${s.name || s.station_id}</span>
|
|
|
|
|
- <span class="station-status-tag ${tagClass}">${statusTag}</span>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="station-info-row">
|
|
|
|
|
- <span>BMC IP:</span>
|
|
|
|
|
- <span class="station-info-val">${s.bmc_address || "未配置"}</span>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="station-info-row">
|
|
|
|
|
- <span>当前任务:</span>
|
|
|
|
|
- <span class="station-info-val">${s.run_id ? s.run_id.substring(0, 16) : "无"}</span>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="station-info-row">
|
|
|
|
|
- <span>腔体温度 / 目标:</span>
|
|
|
|
|
- <span class="station-info-val">${hoodTemp} / ${targetTemp}</span>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="station-info-row">
|
|
|
|
|
- <span>主板供电 / SOL:</span>
|
|
|
|
|
- <span class="station-info-val">${s.server_power || "unknown"} / ${s.sol_state || "offline"}</span>
|
|
|
|
|
- </div>
|
|
|
|
|
- `;
|
|
|
|
|
- container.appendChild(card);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ function bind(button, task) { $(button).onclick = () => action(button, task); }
|
|
|
|
|
+ function activeRun() {
|
|
|
|
|
+ const run = current()?.run_id;
|
|
|
|
|
+ if (!run) throw new Error('当前工位没有活动测试');
|
|
|
|
|
+ return run;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Render 24-channel memory slot grid
|
|
|
|
|
- function renderDimmGrid(station) {
|
|
|
|
|
- const cpu0Container = document.getElementById("cpu0-grid");
|
|
|
|
|
- const cpu1Container = document.getElementById("cpu1-grid");
|
|
|
|
|
- cpu0Container.innerHTML = "";
|
|
|
|
|
- cpu1Container.innerHTML = "";
|
|
|
|
|
-
|
|
|
|
|
- const dimmReadings = (station.temperature && station.temperature.dimms) || [];
|
|
|
|
|
- const channels = station.channels || [];
|
|
|
|
|
-
|
|
|
|
|
- // Map channels to dictionary
|
|
|
|
|
- const slotMap = {};
|
|
|
|
|
- for (const d of dimmReadings) {
|
|
|
|
|
- const key = `N${d.cpu}.C${d.channel}`;
|
|
|
|
|
- slotMap[key] = d;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Generate 12 channels for CPU0 and 12 for CPU1
|
|
|
|
|
|
|
+ function channel(value) {
|
|
|
|
|
+ const text = String(value ?? '');
|
|
|
|
|
+ return /^[A-L]$/i.test(text) ? text.toUpperCase().charCodeAt(0) - 65 : Number(text);
|
|
|
|
|
+ }
|
|
|
|
|
+ function renderCards() {
|
|
|
|
|
+ $('stations-grid').innerHTML = stations.map(s => {
|
|
|
|
|
+ const state = s.phase || 'unknown';
|
|
|
|
|
+ const unavailable = s.mode !== 'simulated' && !s.bmc_address;
|
|
|
|
|
+ const kind = unavailable ? 'offline' : s.verdict === 'fail' ? 'failed' : s.run_id ? 'running' : 'idle';
|
|
|
|
|
+ const target = s.temperature?.applied_target_c;
|
|
|
|
|
+ return `<div class="station-card ${s.station_id === stationId ? 'active' : ''}" data-id="${escape(s.station_id)}">
|
|
|
|
|
+ <div class="station-card-header"><span class="station-name">${escape(s.name || s.station_id)}</span><span class="station-status-tag tag-${kind}">${escape(unavailable ? '未配置' : state)}</span></div>
|
|
|
|
|
+ <div class="station-info-row"><span>BMC / 状态</span><span>${escape(s.bmc_address || '未配置')} / ${escape(s.bmc_state || 'unknown')}</span></div>
|
|
|
|
|
+ <div class="station-info-row"><span>当前测试</span><span>${escape(s.run_id?.slice(0, 18) || '无')}</span></div>
|
|
|
|
|
+ <div class="station-info-row"><span>罩内温度 / 已设DIMM目标</span><span>${temp(s.temperature?.hood_air)} / ${typeof target === 'number' ? target.toFixed(1) + '°C' : '未知'}</span></div>
|
|
|
|
|
+ <div class="station-info-row"><span>主板 / 总供电</span><span>${escape(s.server_power || 'unknown')} / ${escape(s.supply_state || 'unknown')}</span></div>
|
|
|
|
|
+ <div class="station-info-row"><span>结论 / 更新时间</span><span>${escape(s.verdict || 'pending')} / ${time(s.updated_unix_ms)}</span></div>
|
|
|
|
|
+ </div>`;
|
|
|
|
|
+ }).join('');
|
|
|
|
|
+ document.querySelectorAll('.station-card').forEach(card => { card.onclick = () => selectStation(card.dataset.id); });
|
|
|
|
|
+ }
|
|
|
|
|
+ function renderDimms(s) {
|
|
|
for (let cpu = 0; cpu < 2; cpu++) {
|
|
for (let cpu = 0; cpu < 2; cpu++) {
|
|
|
- const container = cpu === 0 ? cpu0Container : cpu1Container;
|
|
|
|
|
- for (let ch = 0; ch < 12; ch++) {
|
|
|
|
|
- const key = `N${cpu}.C${ch}`;
|
|
|
|
|
- const slotEl = document.createElement("div");
|
|
|
|
|
- slotEl.className = "dimm-slot";
|
|
|
|
|
-
|
|
|
|
|
- const reading = slotMap[key];
|
|
|
|
|
- const chInfo = channels.find(c => c.cpu === cpu && (c.channel == ch || c.channel === `0${ch}` || c.channel === String(ch)));
|
|
|
|
|
-
|
|
|
|
|
- let tempText = "--°C";
|
|
|
|
|
- let tempClass = "temp-none";
|
|
|
|
|
- if (reading && reading.value_c !== undefined) {
|
|
|
|
|
- const val = reading.value_c;
|
|
|
|
|
- tempText = `${val.toFixed(1)}°C`;
|
|
|
|
|
- if (val < 65) tempClass = "temp-cold";
|
|
|
|
|
- else if (val <= 80) tempClass = "temp-warm";
|
|
|
|
|
- else tempClass = "temp-hot";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const snText = (chInfo && chInfo.sns && chInfo.sns.length > 0) ? chInfo.sns[0] : `CH${String(ch).padStart(2, "0")}`;
|
|
|
|
|
-
|
|
|
|
|
- slotEl.innerHTML = `
|
|
|
|
|
- <div class="slot-name">${key}.D0</div>
|
|
|
|
|
- <div class="slot-temp ${tempClass}">${tempText}</div>
|
|
|
|
|
- <div class="slot-sn" title="${snText}">${snText}</div>
|
|
|
|
|
- `;
|
|
|
|
|
- container.appendChild(slotEl);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $(`cpu${cpu}-grid`).innerHTML = Array.from({length: 12}, (_, ch) => {
|
|
|
|
|
+ const reading = (s.temperature?.dimms || []).find(d => Number(d.cpu) === cpu && channel(d.channel) === ch);
|
|
|
|
|
+ const info = (s.channels || []).find(c => Number(c.cpu ?? 0) === cpu && channel(c.channel) === ch);
|
|
|
|
|
+ const valid = reading?.quality === 'valid' && typeof reading.value_c === 'number';
|
|
|
|
|
+ const color = !valid ? 'none' : reading.value_c < 65 ? 'cold' : reading.value_c <= 80 ? 'warm' : 'hot';
|
|
|
|
|
+ const sn = (info?.sns || []).join(', ') || '未登记';
|
|
|
|
|
+ return `<div class="dimm-slot ${info?.state === 'fail' ? 'channel-fail' : ''}" title="${escape(`${reading?.source || '无温度来源'} / ${time(reading?.observed_unix_ms)}`)}">
|
|
|
|
|
+ <div class="slot-name">CPU${cpu} / ${String.fromCharCode(65 + ch)}</div><div class="slot-temp temp-${color}">${temp(reading)}</div>
|
|
|
|
|
+ <div class="slot-sn" title="${escape(sn)}">${escape(sn)}</div><div class="slot-quality">${escape(info?.state || 'unknown')} · 错误 ${escape(info?.error_count || '0')} · ${escape(reading?.source === 'bmc_sdr' && reading?.quality === 'unverified' ? 'BMC 报告值,采样时间未知' : reading?.quality || 'unknown')}</div></div>`;
|
|
|
|
|
+ }).join('');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Update Detail View
|
|
|
|
|
- function updateDetailView(station) {
|
|
|
|
|
- if (!station) return;
|
|
|
|
|
- document.getElementById("detail-station-tag").textContent = `${station.station_id} (${station.name || "测试工位"})`;
|
|
|
|
|
- document.getElementById("detail-phase-tag").textContent = (station.phase || "IDLE").toUpperCase();
|
|
|
|
|
- document.getElementById("detail-run-id").textContent = station.run_id ? `RUN: ${station.run_id}` : "无活跃测试";
|
|
|
|
|
-
|
|
|
|
|
- // Manual Confirm Bar
|
|
|
|
|
- const confirmBar = document.getElementById("manual-confirm-bar");
|
|
|
|
|
- if (station.pending_instruction) {
|
|
|
|
|
- confirmBar.classList.remove("hidden");
|
|
|
|
|
- document.getElementById("manual-confirm-msg").textContent = `[${station.pending_step_id}] ${station.pending_instruction}`;
|
|
|
|
|
- } else {
|
|
|
|
|
- confirmBar.classList.add("hidden");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Console Lock Badge
|
|
|
|
|
- const lockBadge = document.getElementById("console-lock-badge");
|
|
|
|
|
- if (station.control_mode === "manual") {
|
|
|
|
|
- lockBadge.textContent = "独占写入锁: 人工控制中";
|
|
|
|
|
- lockBadge.style.backgroundColor = "#d97706";
|
|
|
|
|
- } else {
|
|
|
|
|
- lockBadge.textContent = "独占写入锁: 自动流程锁定";
|
|
|
|
|
- lockBadge.style.backgroundColor = "#475569";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const solBadge = document.getElementById("sol-state-badge");
|
|
|
|
|
- solBadge.textContent = (station.sol_state || "OFFLINE").toUpperCase();
|
|
|
|
|
- solBadge.style.backgroundColor = station.sol_state === "online" ? "#059669" : "#64748b";
|
|
|
|
|
-
|
|
|
|
|
- renderDimmGrid(station);
|
|
|
|
|
|
|
+ function renderDetail() {
|
|
|
|
|
+ const s = current();
|
|
|
|
|
+ const active = connected && !!s?.run_id;
|
|
|
|
|
+ enable('btn-open-start', connected && !!s && !s.run_id && (s.mode === 'simulated' || !!s.bmc_address));
|
|
|
|
|
+ enable('btn-open-target', active);
|
|
|
|
|
+ enable('btn-stop-run', active);
|
|
|
|
|
+ enable('btn-confirm-stage', connected && !!s?.pending_step_id);
|
|
|
|
|
+ enable('btn-sol-mode', active && !s.pending_step_id);
|
|
|
|
|
+ enable('btn-send-sol', active && s.control_mode === 'manual');
|
|
|
|
|
+ enable('btn-send-enter', active && s.control_mode === 'manual');
|
|
|
|
|
+ $('sol-input-cmd').disabled = !active || s?.control_mode !== 'manual';
|
|
|
|
|
+ for (const button of ['btn-download-sol', 'btn-download-report', 'btn-import-artifact']) enable(button, connected && !!selectedRun);
|
|
|
|
|
+ if (!s) return;
|
|
|
|
|
+ $('detail-station-tag').textContent = `${s.station_id} (${s.name || ''})`;
|
|
|
|
|
+ $('detail-phase-tag').textContent = s.phase || 'unknown';
|
|
|
|
|
+ $('detail-run-id').textContent = s.run_id ? `活动测试:${s.run_id}` : '无活动测试';
|
|
|
|
|
+ $('manual-confirm-bar').classList.toggle('hidden', !s.pending_instruction);
|
|
|
|
|
+ $('manual-confirm-msg').textContent = `[${s.pending_step_id || ''}] ${s.pending_instruction || ''}`;
|
|
|
|
|
+ const power = ['power_on', 'power_off'].includes(s.pending_step_id);
|
|
|
|
|
+ $('confirm-evidence').classList.toggle('hidden', power);
|
|
|
|
|
+ $('btn-confirm-stage').textContent = power ? (s.pending_step_id === 'power_on' ? '已接通整套供电' : '已切断整套供电') : '确认此步骤完成';
|
|
|
|
|
+ $('console-lock-badge').textContent = s.run_id ? (s.control_mode === 'manual' ? '人工控制' : '自动流程') : '无活动会话';
|
|
|
|
|
+ $('btn-sol-mode').textContent = s.control_mode === 'manual' ? '恢复自动' : '人工接管';
|
|
|
|
|
+ $('sol-state-badge').textContent = s.sol_state || 'unknown';
|
|
|
|
|
+ renderDimms(s);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Read SOL Stream
|
|
|
|
|
- async function pollSol(stationId, runId) {
|
|
|
|
|
- if (!stationId) return;
|
|
|
|
|
- const term = document.getElementById("sol-terminal");
|
|
|
|
|
- const offset = solOffsets[stationId] || 0;
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await callGrpc("ReadSol", {
|
|
|
|
|
- run_id: runId || "",
|
|
|
|
|
- offset: offset,
|
|
|
|
|
- max_bytes: 32768,
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- if (res && res.data) {
|
|
|
|
|
- // Base64 decode binary SOL chunk
|
|
|
|
|
- const raw = atob(res.data);
|
|
|
|
|
- term.textContent += raw;
|
|
|
|
|
- solOffsets[stationId] = res.next_offset || (offset + raw.length);
|
|
|
|
|
-
|
|
|
|
|
- if (autoScroll) {
|
|
|
|
|
- term.scrollTop = term.scrollHeight;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (e) {}
|
|
|
|
|
|
|
+ function renderLog() {
|
|
|
|
|
+ const state = selectedRun ? runLog(selectedRun) : null;
|
|
|
|
|
+ $('sol-terminal').textContent = state?.text || (selectedRun ? '等待本轮 SOL 数据…' : '尚无测试记录');
|
|
|
|
|
+ if ($('chk-autoscroll').checked) $('sol-terminal').scrollTop = $('sol-terminal').scrollHeight;
|
|
|
|
|
+ $('events-tbody').innerHTML = (state?.events || []).slice(-100).reverse().map(ev =>
|
|
|
|
|
+ `<tr><td>${time(ev.observed_unix_ms)}</td><td>${escape(ev.station_id)}</td><td>${escape(ev.phase)}</td><td>${escape(ev.severity)}</td><td>${escape(ev.kind)}</td><td>${escape(ev.message)}</td></tr>`).join('');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Poll Events
|
|
|
|
|
- async function pollEvents() {
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await callGrpc("ListEvents", { station_id: currentStationId, limit: 10 });
|
|
|
|
|
- const tbody = document.getElementById("events-tbody");
|
|
|
|
|
- tbody.innerHTML = "";
|
|
|
|
|
- const events = res.events || [];
|
|
|
|
|
- for (const ev of events) {
|
|
|
|
|
- const tr = document.createElement("tr");
|
|
|
|
|
- const sevColor = ev.severity === "error" ? "#ef4444" : (ev.severity === "warning" ? "#f59e0b" : "#94a3b8");
|
|
|
|
|
- tr.innerHTML = `
|
|
|
|
|
- <td>${fmtTime(ev.timestamp_unix_ms)}</td>
|
|
|
|
|
- <td>${ev.station_id || "--"}</td>
|
|
|
|
|
- <td>${ev.phase || "--"}</td>
|
|
|
|
|
- <td style="color:${sevColor};font-weight:600">${(ev.severity || "info").toUpperCase()}</td>
|
|
|
|
|
- <td>${ev.kind || "--"}</td>
|
|
|
|
|
- <td>${ev.message || ""}</td>
|
|
|
|
|
- `;
|
|
|
|
|
- tbody.appendChild(tr);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (e) {}
|
|
|
|
|
|
|
+ function updateSelectedRun() {
|
|
|
|
|
+ const next = historySelection || current()?.run_id || current()?.last_run_id || '';
|
|
|
|
|
+ if (next !== selectedRun) { selectedRun = next; selectionRevision++; renderLog(); }
|
|
|
|
|
+ }
|
|
|
|
|
+ async function selectStation(next) {
|
|
|
|
|
+ stationId = next; historySelection = ''; history = []; selectedRun = ''; selectionRevision++;
|
|
|
|
|
+ $('modal-start-run').classList.add('hidden'); $('modal-target-temp').classList.add('hidden');
|
|
|
|
|
+ $('history-run').innerHTML = '<option value="">当前 / 最近一轮</option>';
|
|
|
|
|
+ $('run-summary').textContent = '读取记录中…'; $('artifact-list').textContent = '';
|
|
|
|
|
+ updateSelectedRun(); renderCards(); renderDetail(); renderLog();
|
|
|
|
|
+ await refreshHistory(); await poll();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Main Polling Loop
|
|
|
|
|
- async function pollTick() {
|
|
|
|
|
- if (isPolling) return;
|
|
|
|
|
- isPolling = true;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ async function refreshHistory() {
|
|
|
|
|
+ const selectedStation = stationId;
|
|
|
|
|
+ const result = await callGrpc('ListRuns', {station_id: selectedStation, limit: 50});
|
|
|
|
|
+ if (stationId !== selectedStation) return;
|
|
|
|
|
+ history = result.runs || [];
|
|
|
|
|
+ $('history-run').innerHTML = '<option value="">当前 / 最近一轮</option>' + history.map(run =>
|
|
|
|
|
+ `<option value="${escape(run.run_id)}">${escape(run.batch_no)} · ${time(run.created_unix_ms)} · ${escape(run.state)} · ${escape(run.run_id)}</option>`).join('');
|
|
|
|
|
+ if (!history.some(run => run.run_id === historySelection)) historySelection = '';
|
|
|
|
|
+ $('history-run').value = historySelection;
|
|
|
|
|
+ updateSelectedRun(); renderDetail();
|
|
|
|
|
+ }
|
|
|
|
|
+ async function pollRecords() {
|
|
|
|
|
+ const runId = selectedRun, revision = selectionRevision;
|
|
|
|
|
+ if (!runId) { $('run-summary').textContent = '尚无测试记录'; $('artifact-list').textContent = '无文件'; return; }
|
|
|
|
|
+ const state = runLog(runId);
|
|
|
|
|
+ const [chunk, events, report] = await Promise.all([
|
|
|
|
|
+ callGrpc('ReadSol', {run_id: runId, offset: state.offset, max_bytes: 65536}),
|
|
|
|
|
+ callGrpc('ListEvents', {run_id: runId, after_event_id: state.eventCursor, limit: 100}),
|
|
|
|
|
+ callGrpc('GetRunReport', {run_id: runId}),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ if (revision !== selectionRevision || selectedRun !== runId) return;
|
|
|
|
|
+ if (chunk.data) state.text = (state.text + state.decoder.decode(decode(chunk.data), {stream: true})).slice(-250000);
|
|
|
|
|
+ state.offset = chunk.next_offset || state.offset;
|
|
|
|
|
+ state.events = state.events.concat(events.events || []).slice(-100);
|
|
|
|
|
+ state.eventCursor = events.next_after_event_id || state.eventCursor;
|
|
|
|
|
+ renderLog();
|
|
|
|
|
+ const r = report.run;
|
|
|
|
|
+ $('run-summary').textContent = `${r.run_id} | 工单 ${r.work_order} | 批次 ${r.batch_no} | ${r.state} / ${r.verdict} | 总供电 ${r.supply_state} | 资料 ${r.artifact_state}\n${report.interpretation || ''}${(report.missing_artifact_kinds || []).length ? ';待补:' + report.missing_artifact_kinds.join(', ') : ''}`;
|
|
|
|
|
+ $('artifact-list').innerHTML = (report.artifacts || []).map(a => `<button class="btn btn-xs artifact-download" data-id="${escape(a.artifact_id)}" data-name="${escape(a.filename)}">下载 ${escape(a.filename)} (${escape(a.size_bytes)} B)</button>`).join('') || '本轮尚无导入文件';
|
|
|
|
|
+ document.querySelectorAll('.artifact-download').forEach(button => { button.onclick = () => downloadArtifact(button.dataset.id, button.dataset.name).catch(e => status(e.message, true)); });
|
|
|
|
|
+ }
|
|
|
|
|
+ async function poll() {
|
|
|
|
|
+ if (polling) return;
|
|
|
|
|
+ polling = true;
|
|
|
try {
|
|
try {
|
|
|
- document.getElementById("sys-heartbeat").textContent = new Date().toTimeString().split(" ")[0];
|
|
|
|
|
- const listRes = await callGrpc("ListStations", {});
|
|
|
|
|
- const stations = listRes.stations || [];
|
|
|
|
|
- renderStationCards(stations);
|
|
|
|
|
-
|
|
|
|
|
- const activeStation = stations.find(s => s.station_id === currentStationId) || stations[0];
|
|
|
|
|
- if (activeStation) {
|
|
|
|
|
- updateDetailView(activeStation);
|
|
|
|
|
- await pollSol(activeStation.station_id, activeStation.run_id);
|
|
|
|
|
|
|
+ const [info, list] = await Promise.all([callGrpc('GetSystemInfo'), callGrpc('ListStations')]);
|
|
|
|
|
+ if (!connected) status('已连接后端;选择工位操作,未知值保持未知。');
|
|
|
|
|
+ connected = true; currentMode = info.mode;
|
|
|
|
|
+ $('sys-version').textContent = info.version || '未知';
|
|
|
|
|
+ $('sys-commit').textContent = info.commit ? info.commit.slice(0, 7) : '未知';
|
|
|
|
|
+ $('sys-mode').textContent = info.mode === 'simulated' ? '仿真模拟' : info.mode === 'hardware' ? '硬件实机' : (info.mode || '未知');
|
|
|
|
|
+ $('sys-heartbeat').textContent = stamp(); $('refresh-indicator').textContent = '已连接 · 定时读取';
|
|
|
|
|
+ stations = list.stations || [];
|
|
|
|
|
+ if (!current() && stations.length) stationId = stations[0].station_id;
|
|
|
|
|
+ updateSelectedRun(); renderCards(); renderDetail();
|
|
|
|
|
+ for (const [key, item] of Array.from(pending)) {
|
|
|
|
|
+ const result = await callGrpc('GetCommand', {command_id: key});
|
|
|
|
|
+ showCommand(result, `${item.station} ${item.label}`);
|
|
|
}
|
|
}
|
|
|
- await pollEvents();
|
|
|
|
|
- } catch (err) {
|
|
|
|
|
- console.warn("Polling tick exception:", err);
|
|
|
|
|
- } finally {
|
|
|
|
|
- isPolling = false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try { await pollRecords(); } catch (e) { status(`读取记录失败:${e.message}`, true); }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ connected = false; $('refresh-indicator').textContent = '连接失败 · 显示上次数据';
|
|
|
|
|
+ status(`后端连接失败:${error.message}`, true); renderDetail();
|
|
|
|
|
+ } finally { polling = false; }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // Station Select
|
|
|
|
|
- function selectStation(stationId) {
|
|
|
|
|
- currentStationId = stationId;
|
|
|
|
|
- document.getElementById("sol-terminal").textContent = `--- 切换至工位 ${stationId} 控制台 ---\n`;
|
|
|
|
|
- solOffsets[stationId] = 0;
|
|
|
|
|
- pollTick();
|
|
|
|
|
|
|
+ function recipeSummary() {
|
|
|
|
|
+ const recipe = recipes.find(r => r.recipe_id === $('start-recipe').value);
|
|
|
|
|
+ $('start-target-c').value = recipe?.dimm_target_c ?? '';
|
|
|
|
|
+ $('recipe-summary').textContent = recipe ? `预热环境目标 ${recipe.preheat_air_c}°C;RMT ${recipe.run_rmt ? '开' : '关'} / AMT ${recipe.run_amt ? '开' : '关'} / MT ${recipe.run_mt ? '开' : '关'}` : '没有可用配方';
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // UI Event Handlers
|
|
|
|
|
- document.getElementById("chk-autoscroll").onchange = (e) => {
|
|
|
|
|
- autoScroll = e.target.checked;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- document.getElementById("btn-clear-sol").onclick = () => {
|
|
|
|
|
- document.getElementById("sol-terminal").textContent = "";
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- // Send SOL command
|
|
|
|
|
- async function sendSolCommand() {
|
|
|
|
|
- const input = document.getElementById("sol-input-cmd");
|
|
|
|
|
- const cmd = input.value;
|
|
|
|
|
- if (!cmd) return;
|
|
|
|
|
- input.value = "";
|
|
|
|
|
- try {
|
|
|
|
|
- // Encode string to base64
|
|
|
|
|
- const b64 = btoa(cmd + "\r\n");
|
|
|
|
|
- await callGrpc("WriteSol", {
|
|
|
|
|
- station_id: currentStationId,
|
|
|
|
|
- data: b64,
|
|
|
|
|
- });
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- alert("发送命令失败: " + e.message);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ function parseDimms() {
|
|
|
|
|
+ const lines = $('start-dimms').value.trim().split(/\r?\n/).filter(Boolean);
|
|
|
|
|
+ if (!lines.length) throw new Error('请登记实际内存 SN 和位置');
|
|
|
|
|
+ return lines.map((line, index) => {
|
|
|
|
|
+ const fields = line.split(',').map(v => v.trim());
|
|
|
|
|
+ if (fields.length !== 4 || !['0', '1'].includes(fields[0]) || !Number.isInteger(channel(fields[1])) || channel(fields[1]) < 0 || channel(fields[1]) > 11 || !fields[2] || !fields[3]) throw new Error(`第 ${index + 1} 行应为 CPU(0或1),通道(A-L或0-11),槽位,SN`);
|
|
|
|
|
+ return {cpu: Number(fields[0]), channel: String(channel(fields[1])), slot: fields[2], sn: fields[3]};
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- document.getElementById("btn-send-sol").onclick = sendSolCommand;
|
|
|
|
|
- document.getElementById("sol-input-cmd").onkeydown = (e) => {
|
|
|
|
|
- if (e.key === "Enter") sendSolCommand();
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- // Modals
|
|
|
|
|
- const modalStart = document.getElementById("modal-start-run");
|
|
|
|
|
- const modalTemp = document.getElementById("modal-target-temp");
|
|
|
|
|
-
|
|
|
|
|
- document.getElementById("btn-open-start").onclick = () => modalStart.classList.remove("hidden");
|
|
|
|
|
- document.getElementById("btn-close-modal-start").onclick = () => modalStart.classList.add("hidden");
|
|
|
|
|
- document.getElementById("btn-cancel-start").onclick = () => modalStart.classList.add("hidden");
|
|
|
|
|
-
|
|
|
|
|
- document.getElementById("btn-open-target").onclick = () => modalTemp.classList.remove("hidden");
|
|
|
|
|
- document.getElementById("btn-close-modal-temp").onclick = () => modalTemp.classList.add("hidden");
|
|
|
|
|
- document.getElementById("btn-cancel-temp").onclick = () => modalTemp.classList.add("hidden");
|
|
|
|
|
-
|
|
|
|
|
- // Start Run Confirm
|
|
|
|
|
- document.getElementById("btn-confirm-start-run").onclick = async () => {
|
|
|
|
|
- const wo = document.getElementById("start-wo").value.trim();
|
|
|
|
|
- const batch = document.getElementById("start-batch").value.trim();
|
|
|
|
|
- const operator = document.getElementById("start-operator").value.trim();
|
|
|
|
|
- const recipeId = document.getElementById("start-recipe").value;
|
|
|
|
|
- const targetC = parseFloat(document.getElementById("start-target-c").value) || 70.0;
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- await callGrpc("StartRun", {
|
|
|
|
|
- station_id: currentStationId,
|
|
|
|
|
- work_order: wo,
|
|
|
|
|
- batch_no: batch,
|
|
|
|
|
- operator: operator,
|
|
|
|
|
- recipe_id: recipeId,
|
|
|
|
|
- target_temperature_c: targetC,
|
|
|
|
|
- });
|
|
|
|
|
- modalStart.classList.add("hidden");
|
|
|
|
|
- pollTick();
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- alert("启动测试失败: " + e.message);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- // Stop Run
|
|
|
|
|
- document.getElementById("btn-stop-run").onclick = async () => {
|
|
|
|
|
- if (!confirm(`确定停止工位 ${currentStationId} 的当前测试并切断供电吗?`)) return;
|
|
|
|
|
- try {
|
|
|
|
|
- await callGrpc("StopRun", {
|
|
|
|
|
- station_id: currentStationId,
|
|
|
|
|
- reason: "operator_stopped",
|
|
|
|
|
- });
|
|
|
|
|
- pollTick();
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- alert("停止测试失败: " + e.message);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- // Save Target Temperature
|
|
|
|
|
- document.getElementById("btn-save-temp").onclick = async () => {
|
|
|
|
|
- const val = parseFloat(document.getElementById("input-new-target-c").value);
|
|
|
|
|
- if (isNaN(val) || val < 0 || val > 100) {
|
|
|
|
|
- alert("温度必须在 0 ~ 100 °C 之间");
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ bind('btn-open-start', async () => {
|
|
|
|
|
+ startStation = stationId;
|
|
|
|
|
+ recipes = (await callGrpc('ListRecipes')).recipes || [];
|
|
|
|
|
+ $('start-recipe').innerHTML = recipes.map(r => `<option value="${escape(r.recipe_id)}">${escape(r.name || r.recipe_id)}</option>`).join('');
|
|
|
|
|
+ recipeSummary(); $('modal-start-run').classList.remove('hidden');
|
|
|
|
|
+ });
|
|
|
|
|
+ $('start-recipe').onchange = recipeSummary;
|
|
|
|
|
+ for (const key of ['btn-close-modal-start', 'btn-cancel-start']) $(key).onclick = () => $('modal-start-run').classList.add('hidden');
|
|
|
|
|
+ bind('btn-confirm-start-run', async () => {
|
|
|
|
|
+ if (stationId !== startStation) throw new Error('工位已切换,请重新打开开始窗口');
|
|
|
|
|
+ const work_order = $('start-wo').value.trim(), batch_no = $('start-batch').value.trim();
|
|
|
|
|
+ if (!work_order || !batch_no || !$('start-operator').value.trim() || !$('start-recipe').value) throw new Error('请填写工单、批次、操作员并选择配方');
|
|
|
|
|
+ historySelection = '';
|
|
|
|
|
+ await command('StartRun', {station_id: startStation, work_order, batch_no, recipe_id: $('start-recipe').value, dimms: parseDimms()}, '开始测试');
|
|
|
|
|
+ $('modal-start-run').classList.add('hidden'); await refreshHistory();
|
|
|
|
|
+ });
|
|
|
|
|
+ bind('btn-stop-run', async () => {
|
|
|
|
|
+ const run_id = activeRun();
|
|
|
|
|
+ if (!confirm(`停止 ${stationId} 当前测试并执行收尾?总供电状态以反馈/人工断电确认为准。`)) return;
|
|
|
|
|
+ await command('StopRun', {run_id, reason: 'operator_stopped'}, '停止测试');
|
|
|
|
|
+ });
|
|
|
|
|
+ bind('btn-open-target', async () => {
|
|
|
|
|
+ targetRun = activeRun();
|
|
|
|
|
+ $('input-new-target-c').value = current().temperature?.requested_target_c ?? '';
|
|
|
|
|
+ $('modal-target-temp').classList.remove('hidden');
|
|
|
|
|
+ });
|
|
|
|
|
+ for (const key of ['btn-close-modal-temp', 'btn-cancel-temp']) $(key).onclick = () => $('modal-target-temp').classList.add('hidden');
|
|
|
|
|
+ bind('btn-save-temp', async () => {
|
|
|
|
|
+ if (targetRun !== activeRun()) throw new Error('当前测试已改变,请重新打开目标温度窗口');
|
|
|
|
|
+ const target_c = Number($('input-new-target-c').value);
|
|
|
|
|
+ if (!$('input-new-target-c').value || !Number.isFinite(target_c)) throw new Error('请输入有效温度');
|
|
|
|
|
+ await command('SetTargetTemperature', {run_id: targetRun, target_c}, '修改 DIMM 目标');
|
|
|
|
|
+ $('modal-target-temp').classList.add('hidden');
|
|
|
|
|
+ });
|
|
|
|
|
+ bind('btn-confirm-stage', async () => {
|
|
|
|
|
+ const s = current();
|
|
|
|
|
+ if (!s?.pending_step_id) throw new Error('当前没有待确认步骤');
|
|
|
|
|
+ if (['power_on', 'power_off'].includes(s.pending_step_id)) {
|
|
|
|
|
+ await command('ConfirmPower', {station_id: s.station_id, expected_run_id: s.run_id || '', supply_on: s.pending_step_id === 'power_on'}, '确认整套供电');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const evidence = $('confirm-evidence').value.trim();
|
|
|
|
|
+ if (!evidence) throw new Error('请填写实际观察到的结果');
|
|
|
|
|
+ await command('ConfirmStage', {run_id: activeRun(), step_id: s.pending_step_id, evidence, succeeded: true}, '确认步骤');
|
|
|
|
|
+ $('confirm-evidence').value = '';
|
|
|
}
|
|
}
|
|
|
- try {
|
|
|
|
|
- await callGrpc("SetTargetTemperature", {
|
|
|
|
|
- station_id: currentStationId,
|
|
|
|
|
- target_c: val,
|
|
|
|
|
- });
|
|
|
|
|
- modalTemp.classList.add("hidden");
|
|
|
|
|
- pollTick();
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- alert("设定目标温度失败: " + e.message);
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ bind('btn-sol-mode', async () => {
|
|
|
|
|
+ await command('SetSolMode', {run_id: activeRun(), mode: current().control_mode === 'manual' ? 'auto' : 'manual'}, '切换控制模式');
|
|
|
|
|
+ });
|
|
|
|
|
+ async function sendSol(empty = false) {
|
|
|
|
|
+ const text = $('sol-input-cmd').value;
|
|
|
|
|
+ if (!empty && !text) throw new Error('请输入命令;如需空回车请使用右侧按钮');
|
|
|
|
|
+ await command('WriteSol', {run_id: activeRun(), data: encode(new TextEncoder().encode((empty ? '' : text) + '\r'))}, '发送 SOL');
|
|
|
|
|
+ if (!empty) $('sol-input-cmd').value = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ bind('btn-send-sol', () => sendSol()); bind('btn-send-enter', () => sendSol(true));
|
|
|
|
|
+ $('sol-input-cmd').onkeydown = event => { if (event.key === 'Enter') { event.preventDefault(); $('btn-send-sol').click(); } };
|
|
|
|
|
+ $('btn-clear-sol').onclick = () => { if (selectedRun) runLog(selectedRun).text = ''; renderLog(); };
|
|
|
|
|
+ $('history-run').onchange = () => { historySelection = $('history-run').value; updateSelectedRun(); renderDetail(); poll(); };
|
|
|
|
|
+ bind('btn-refresh-history', refreshHistory);
|
|
|
|
|
+ function saveFile(name, data, type = 'application/octet-stream') {
|
|
|
|
|
+ const url = URL.createObjectURL(new Blob([data], {type}));
|
|
|
|
|
+ const anchor = document.createElement('a'); anchor.href = url; anchor.download = name; anchor.click();
|
|
|
|
|
+ setTimeout(() => URL.revokeObjectURL(url), 10000);
|
|
|
|
|
+ }
|
|
|
|
|
+ async function readFile(method, request) {
|
|
|
|
|
+ const chunks = []; let offset = 0;
|
|
|
|
|
+ while (true) {
|
|
|
|
|
+ const part = await callGrpc(method, {...request, offset, max_bytes: 262144});
|
|
|
|
|
+ chunks.push(decode(part.data));
|
|
|
|
|
+ const next = Number(part.next_offset);
|
|
|
|
|
+ if (part.eof) break;
|
|
|
|
|
+ if (!(next > Number(offset))) throw new Error('下载未推进,请重试');
|
|
|
|
|
+ offset = next;
|
|
|
}
|
|
}
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- // Confirm Stage
|
|
|
|
|
- document.getElementById("btn-confirm-stage").onclick = async () => {
|
|
|
|
|
- try {
|
|
|
|
|
- await callGrpc("ConfirmStage", {
|
|
|
|
|
- station_id: currentStationId,
|
|
|
|
|
- });
|
|
|
|
|
- pollTick();
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- alert("确认阶段失败: " + e.message);
|
|
|
|
|
|
|
+ return new Blob(chunks);
|
|
|
|
|
+ }
|
|
|
|
|
+ bind('btn-download-sol', async () => {
|
|
|
|
|
+ const run_id = selectedRun;
|
|
|
|
|
+ saveFile(`${run_id}-sol.bin`, await readFile('ReadSol', {run_id})); status('原始 SOL 日志已下载');
|
|
|
|
|
+ });
|
|
|
|
|
+ bind('btn-download-report', async () => {
|
|
|
|
|
+ const run_id = selectedRun, report = await callGrpc('GetRunReport', {run_id});
|
|
|
|
|
+ saveFile(`${run_id}-report.json`, JSON.stringify(report, null, 2), 'application/json'); status('报告已下载');
|
|
|
|
|
+ });
|
|
|
|
|
+ async function downloadArtifact(artifact_id, name) {
|
|
|
|
|
+ saveFile(name, await readFile('ReadArtifact', {artifact_id})); status(`已下载 ${name}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ bind('btn-import-artifact', async () => {
|
|
|
|
|
+ const run_id = selectedRun, file = $('artifact-file').files[0];
|
|
|
|
|
+ if (!run_id || !file) throw new Error('请选择测试记录和结果文件');
|
|
|
|
|
+ if (file.size > 256 * 1024 * 1024) throw new Error('单文件不能超过 256 MiB');
|
|
|
|
|
+ const bytes = new Uint8Array(await file.arrayBuffer());
|
|
|
|
|
+ const sha256 = await window.stlSha256(bytes), upload_id = id();
|
|
|
|
|
+ let upload = await callGrpc('BeginArtifact', {upload_id, run_id, filename: file.name, kind: $('artifact-kind').value, total_bytes: file.size, operator: operator()});
|
|
|
|
|
+ while (Number(upload.next_offset || 0) < bytes.length) {
|
|
|
|
|
+ const offset = Number(upload.next_offset || 0);
|
|
|
|
|
+ upload = await callGrpc('UploadArtifactChunk', {upload_id, offset, data: encode(bytes.subarray(offset, offset + 196608))});
|
|
|
|
|
+ if (!(Number(upload.next_offset) > offset)) throw new Error('上传未推进');
|
|
|
|
|
+ status(`导入 ${file.name} → ${run_id}:${Math.round(Number(upload.next_offset) / bytes.length * 100)}%`);
|
|
|
}
|
|
}
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- // Initialize
|
|
|
|
|
- window.addEventListener("load", async () => {
|
|
|
|
|
- await loadSystemInfo();
|
|
|
|
|
- await loadRecipes();
|
|
|
|
|
- await pollTick();
|
|
|
|
|
- setInterval(pollTick, 1500);
|
|
|
|
|
|
|
+ await callGrpc('FinishArtifact', {upload_id, sha256});
|
|
|
|
|
+ status(`已导入 ${file.name} 到 ${run_id}`); $('artifact-file').value = '';
|
|
|
|
|
+ });
|
|
|
|
|
+ window.addEventListener('load', async () => {
|
|
|
|
|
+ renderDetail(); await poll();
|
|
|
|
|
+ try { await refreshHistory(); } catch (e) { status(e.message, true); }
|
|
|
|
|
+ setInterval(poll, 1500);
|
|
|
});
|
|
});
|
|
|
})();
|
|
})();
|