|
@@ -0,0 +1,969 @@
|
|
|
|
|
+// thermal-console.js — High-Performance Zero-Lag MCU 24-Ch Thermal Console & Stream Recorder UI (v0.8.1.20)
|
|
|
|
|
+(() => {
|
|
|
|
|
+ const MAX_POINTS = 720;
|
|
|
|
|
+ const SERIES_META = [
|
|
|
|
|
+ { key: 'target', label: '目标温度', color: '#cf4b52', dashed: true },
|
|
|
|
|
+ { key: 'bmc_avg', label: 'MCU BMC均温', color: '#0d8b80', dashed: false },
|
|
|
|
|
+ { key: 'bmc_max', label: 'MCU BMC最高', color: '#e67e22', dashed: false },
|
|
|
|
|
+ { key: 'ct_avg', label: 'CT7428腔均温', color: '#2980b9', dashed: false },
|
|
|
|
|
+ { key: 'ipmi_avg', label: 'IPMI内存均温', color: '#8e44ad', dashed: false },
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ const el = id => document.getElementById(id);
|
|
|
|
|
+ const rootPanel = document.querySelector('.thermal-console-panel');
|
|
|
|
|
+ if (!rootPanel) return;
|
|
|
|
|
+
|
|
|
|
|
+ let sinceSeq = 0;
|
|
|
|
|
+ let chartRing = [];
|
|
|
|
|
+ let pollInFlight = false;
|
|
|
|
|
+ let pollTimer = null;
|
|
|
|
|
+ let rafPending = false;
|
|
|
|
|
+ let hoverRatio = null;
|
|
|
|
|
+ let prefsSyncedOnce = false;
|
|
|
|
|
+ let lastFilesSig = '';
|
|
|
|
|
+ let lastAsciiSig = '';
|
|
|
|
|
+ let lastFrameSig = '';
|
|
|
|
|
+ const enabledSeries = new Set(['target', 'bmc_avg', 'bmc_max', 'ct_avg', 'ipmi_avg']);
|
|
|
|
|
+
|
|
|
|
|
+ // Pre-build fixed DOM cells once (zero DOM node creation during multi-day runs!)
|
|
|
|
|
+ const ctCells = [];
|
|
|
|
|
+ const ctGrid = el('th-ct8-grid');
|
|
|
|
|
+ for (let i = 0; i < 8; i++) {
|
|
|
|
|
+ const d = document.createElement('div');
|
|
|
|
|
+ d.className = 'th-ct-cell';
|
|
|
|
|
+ const sp = document.createElement('span');
|
|
|
|
|
+ sp.textContent = `CT0${i + 1}`;
|
|
|
|
|
+ const st = document.createElement('strong');
|
|
|
|
|
+ st.textContent = '--';
|
|
|
|
|
+ d.append(sp, st);
|
|
|
|
|
+ ctGrid.appendChild(d);
|
|
|
|
|
+ ctCells.push({ val: st, prev: '' });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const slotCells = [];
|
|
|
|
|
+ const bmcGrid = el('th-bmc24-grid');
|
|
|
|
|
+ for (let i = 0; i < 24; i++) {
|
|
|
|
|
+ const cpu = i < 12 ? 0 : 1;
|
|
|
|
|
+ const ch = String.fromCharCode(65 + (i % 12));
|
|
|
|
|
+ const card = document.createElement('div');
|
|
|
|
|
+ card.className = 'th-slot-card';
|
|
|
|
|
+ const top = document.createElement('div');
|
|
|
|
|
+ top.className = 'th-slot-top';
|
|
|
|
|
+ const lbl = document.createElement('span');
|
|
|
|
|
+ lbl.textContent = `CH${String(i + 1).padStart(2, '0')} · CPU${cpu}_${ch}`;
|
|
|
|
|
+ const diffSpan = document.createElement('span');
|
|
|
|
|
+ diffSpan.textContent = '';
|
|
|
|
|
+ top.append(lbl, diffSpan);
|
|
|
|
|
+
|
|
|
|
|
+ const vals = document.createElement('div');
|
|
|
|
|
+ vals.className = 'th-slot-vals';
|
|
|
|
|
+ const mcuStrong = document.createElement('span');
|
|
|
|
|
+ mcuStrong.className = 'th-slot-mcu';
|
|
|
|
|
+ mcuStrong.textContent = 'MCU: --';
|
|
|
|
|
+ const ipmiSpan = document.createElement('span');
|
|
|
|
|
+ ipmiSpan.className = 'th-slot-ipmi';
|
|
|
|
|
+ ipmiSpan.textContent = 'IPMI: --';
|
|
|
|
|
+ vals.append(mcuStrong, ipmiSpan);
|
|
|
|
|
+
|
|
|
|
|
+ card.append(top, vals);
|
|
|
|
|
+ bmcGrid.appendChild(card);
|
|
|
|
|
+ slotCells.push({ card, mcuStrong, ipmiSpan, diffSpan, prevCls: 'th-slot-card', prevMcu: '', prevIpmi: '', prevDiff: '' });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function setTextIfChanged(node, text) {
|
|
|
|
|
+ if (node && node.textContent !== text) node.textContent = text;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function setStatus(msg, isError = false) {
|
|
|
|
|
+ const bar = el('action-status');
|
|
|
|
|
+ if (!bar) return;
|
|
|
|
|
+ bar.textContent = msg;
|
|
|
|
|
+ bar.classList.toggle('error', Boolean(isError));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function fmtBytes(b) {
|
|
|
|
|
+ const n = Number(b) || 0;
|
|
|
|
|
+ if (n < 1024) return `${n} B`;
|
|
|
|
|
+ if (n < 1048576) return `${(n / 1024).toFixed(1)} KB`;
|
|
|
|
|
+ return `${(n / 1048576).toFixed(2)} MB`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function fmtTimeShort(ms) {
|
|
|
|
|
+ if (!ms) return '--:--:--';
|
|
|
|
|
+ const d = new Date(ms);
|
|
|
|
|
+ return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function stateLabel(st) {
|
|
|
|
|
+ switch (st) {
|
|
|
|
|
+ case 'disconnected': return '未连接';
|
|
|
|
|
+ case 'offline': return '串口已开 · 等待0xF0';
|
|
|
|
|
+ case 'cpld_lost': return 'CPLD采集失联';
|
|
|
|
|
+ case 'preheating': return '预加热升温中';
|
|
|
|
|
+ case 'pid': return 'PID闭环控温中';
|
|
|
|
|
+ case 'manual': return '手动出力保持';
|
|
|
|
|
+ case 'cooling_purge': return '风扇余温吹扫中';
|
|
|
|
|
+ case 'idle': return '在线待机 (0W)';
|
|
|
|
|
+ default: return st || '未知';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async function callThermalAction(action, extra = {}) {
|
|
|
|
|
+ const params = Object.assign({
|
|
|
|
|
+ action,
|
|
|
|
|
+ station_id: el('th-bound-station')?.value || 'S1',
|
|
|
|
|
+ }, extra);
|
|
|
|
|
+ return window.stlTransport.call('ThermalAction', params, 10000);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function updateModeVisibility() {
|
|
|
|
|
+ const mode = el('th-conn-mode').value;
|
|
|
|
|
+ el('th-serial-wrap').classList.toggle('hidden', mode !== 'serial');
|
|
|
|
|
+ el('th-tcp-wrap').classList.toggle('hidden', mode !== 'tcp');
|
|
|
|
|
+ }
|
|
|
|
|
+ el('th-conn-mode').addEventListener('change', updateModeVisibility);
|
|
|
|
|
+ updateModeVisibility();
|
|
|
|
|
+
|
|
|
|
|
+ async function scanPorts(silent = false) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await callThermalAction('scan_ports');
|
|
|
|
|
+ const ports = Array.isArray(res?.ports) ? res.ports : [];
|
|
|
|
|
+ const dl = el('th-serial-datalist');
|
|
|
|
|
+ dl.replaceChildren();
|
|
|
|
|
+ for (const p of ports) {
|
|
|
|
|
+ const opt = document.createElement('option');
|
|
|
|
|
+ opt.value = p.path;
|
|
|
|
|
+ opt.label = p.label || p.path;
|
|
|
|
|
+ dl.appendChild(opt);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ports.length > 0 && !el('th-serial-path').value) {
|
|
|
|
|
+ const usb = ports.find(p => String(p.resolved_path || p.path).includes('ttyUSB')) || ports[0];
|
|
|
|
|
+ el('th-serial-path').value = usb.resolved_path || usb.path;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!silent) {
|
|
|
|
|
+ setStatus(ports.length
|
|
|
|
|
+ ? `已扫描到 ${ports.length} 个串口入口: ${ports.map(p => p.path).join(', ')}`
|
|
|
|
|
+ : '当前未扫描到 USB 串口设备,可切换为「离线虚拟仿真 (Mock)」测试全部功能');
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ if (!silent) setStatus(`扫描串口失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-scan-ports').addEventListener('click', () => scanPorts(false));
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-connect').addEventListener('click', async () => {
|
|
|
|
|
+ const mode = el('th-conn-mode').value;
|
|
|
|
|
+ const payload = {
|
|
|
|
|
+ mode,
|
|
|
|
|
+ serial_path: el('th-serial-path').value.trim() || '/dev/ttyUSB0',
|
|
|
|
|
+ serial_baud: 115200,
|
|
|
|
|
+ tcp_host: el('th-tcp-host').value.trim() || '127.0.0.1',
|
|
|
|
|
+ tcp_port: Number(el('th-tcp-port').value) || 4002,
|
|
|
|
|
+ };
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('connect', payload);
|
|
|
|
|
+ setStatus(`高温罩连接成功 (${mode === 'serial' ? payload.serial_path : mode}),正在读取 UID / 固件版本 / 实时温度...`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`连接高温罩失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-disconnect').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('disconnect');
|
|
|
|
|
+ setStatus('已断开 MCU 高温罩连接');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`断开失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('th-bound-station').addEventListener('change', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('bind_station', { station_id: el('th-bound-station').value });
|
|
|
|
|
+ setStatus(`已切换高温罩关联工位至 ${el('th-bound-station').value}`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`切换关联工位失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-zero-probe').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await callThermalAction('zero_power_probe');
|
|
|
|
|
+ setStatus(`零功率安全链路体检完成 (0W 不动加热/风扇) · PID应答: ${res?.text || 'OK'}`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`零功率自检失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-estop').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('emergency_stop');
|
|
|
|
|
+ setStatus('已执行一键紧急全停:35路占空比清零 + 停止预热/PID (0x05) + 锁死全部加热块 (0x0A)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`紧急全停命令异常: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-save-safety').addEventListener('click', async () => {
|
|
|
|
|
+ const leaseSec = Number(el('th-safety-lease').value) || 0;
|
|
|
|
|
+ const cutoff = Number(el('th-overtemp-cutoff').value) || 95;
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('configure_safety', { lease_sec: leaseSec, overtemp_cutoff_c: cutoff });
|
|
|
|
|
+ setStatus(`远程安全护栏已更新:看门狗=${leaseSec > 0 ? leaseSec + '秒' : '不限时'},超温熔断=${cutoff}℃`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`保存安全护栏失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('th-safety-lease').addEventListener('change', () => el('btn-th-save-safety').click());
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-renew-lease').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await callThermalAction('renew_lease');
|
|
|
|
|
+ setStatus(`远程安全限时看门狗已续期重置 (${res?.lease_remaining_sec || 0} 秒)`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`续期失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ document.querySelectorAll('.th-preset-btn').forEach(btn => {
|
|
|
|
|
+ btn.addEventListener('click', () => {
|
|
|
|
|
+ el('th-target-input').value = btn.dataset.temp;
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-set-temp').addEventListener('click', async () => {
|
|
|
|
|
+ const targetC = Math.round(Number(el('th-target-input').value));
|
|
|
|
|
+ if (!Number.isFinite(targetC) || targetC < 0 || targetC > 254) {
|
|
|
|
|
+ setStatus('目标温度必须为 0 ~ 254 之间的整数 ℃', true);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('set_temp', {
|
|
|
|
|
+ target_c: targetC,
|
|
|
|
|
+ auto_pre_stop: el('th-chk-auto-prestop').checked,
|
|
|
|
|
+ direct_pid: el('th-chk-direct-pid').checked,
|
|
|
|
|
+ });
|
|
|
|
|
+ setStatus(`已向 MCU 下发设温开启指令: ${targetC}℃ (0x01)`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`设温失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-skip-preheat').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('skip_preheat');
|
|
|
|
|
+ setStatus('已下发跳过预加热进入 PID 闭环指令 (0x06)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`跳过预加热失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-start-pid').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('start_pid');
|
|
|
|
|
+ setStatus('已下发直接开启 PID 闭环指令 (0x07)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`开启 PID 失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-stop-preheat').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('stop_preheat');
|
|
|
|
|
+ setStatus('已停止预加热与 PID 闭环,32路输出已清零 (0x05)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`停止控温失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-finish-purge').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('finish_control', { cooling_purge: true });
|
|
|
|
|
+ setStatus('已结束控温并开启 8 路风扇 100% 余温吹扫散热 (0x08 00)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`控温结束命令失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-finish-nopurge').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('finish_control', { cooling_purge: false });
|
|
|
|
|
+ setStatus('已结束控温并清零输出,不开启风扇吹扫 (0x08 01)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`控温结束命令失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-stop-heaters').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('stop_heaters');
|
|
|
|
|
+ setStatus('已紧急停止并锁存禁用全部 24 路加热块 (0x0A)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`锁死加热块失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-stop-fans').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('stop_fans');
|
|
|
|
|
+ setStatus('已停止并锁存禁用全部风扇 (0x0B)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`锁死风扇失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Recording controls
|
|
|
|
|
+ async function syncRecordPrefs() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('configure_polling', {
|
|
|
|
|
+ record_interval_ms: Number(el('th-rec-interval').value) || 1000,
|
|
|
|
|
+ auto_record_on_heat: el('th-chk-auto-rec').checked,
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch {}
|
|
|
|
|
+ }
|
|
|
|
|
+ el('th-rec-interval').addEventListener('change', syncRecordPrefs);
|
|
|
|
|
+ el('th-chk-auto-rec').addEventListener('change', syncRecordPrefs);
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-rec-start').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await callThermalAction('start_record', {
|
|
|
|
|
+ tag: el('th-rec-tag').value.trim(),
|
|
|
|
|
+ note: el('th-mark-input').value.trim(),
|
|
|
|
|
+ record_interval_ms: Number(el('th-rec-interval').value) || 1000,
|
|
|
|
|
+ });
|
|
|
|
|
+ setStatus(`已开始本地全量流式记录: ${res?.csv_filename || ''}`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`启动记录失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-rec-stop').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await callThermalAction('stop_record');
|
|
|
|
|
+ setStatus(res?.csv_filename
|
|
|
|
|
+ ? `已停止并完成刷盘: ${res.csv_filename} (共 ${res.rows_written || 0} 行)`
|
|
|
|
|
+ : '当前没有正在运行的记录会话');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`停止记录失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-add-mark').addEventListener('click', async () => {
|
|
|
|
|
+ const note = el('th-mark-input').value.trim();
|
|
|
|
|
+ if (!note) {
|
|
|
|
|
+ setStatus('请先输入打标备注内容', true);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('add_mark', { note });
|
|
|
|
|
+ setStatus(`已写入测试打标备注: ${note}`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`打标失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Auxiliary remote debug actions
|
|
|
|
|
+ el('btn-th-whisper-fan-test').addEventListener('click', async () => {
|
|
|
|
|
+ const btn = el('btn-th-whisper-fan-test');
|
|
|
|
|
+ btn.disabled = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('manual_duty', {
|
|
|
|
|
+ ptc_all: 0,
|
|
|
|
|
+ ssr_all: 0,
|
|
|
|
|
+ fan_in_all: 15,
|
|
|
|
|
+ fan_out_all: 0,
|
|
|
|
|
+ keepalive: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ setStatus('0W 加热 · 15% 进风微风点测已开启,将在 2 秒后自动归零...');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ await new Promise(r => setTimeout(r, 2000));
|
|
|
|
|
+ await callThermalAction('manual_duty', {
|
|
|
|
|
+ ptc_all: 0,
|
|
|
|
|
+ ssr_all: 0,
|
|
|
|
|
+ fan_in_all: 0,
|
|
|
|
|
+ fan_out_all: 0,
|
|
|
|
|
+ keepalive: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ await callThermalAction('stop_preheat');
|
|
|
|
|
+ setStatus('0W 微风 2 秒闭环点测已完成,全部 35 路输出已自动恢复归零!');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`微风闭环点测异常: ${err.message}`, true);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ btn.disabled = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-pid-read').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await callThermalAction('pid_calibrate', { expr: '' });
|
|
|
|
|
+ setStatus(`PID 回读成功: ${res?.text || ''}`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`PID 回读失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-pid-write').addEventListener('click', async () => {
|
|
|
|
|
+ const expr = el('th-pid-expr').value.trim();
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await callThermalAction('pid_calibrate', { expr });
|
|
|
|
|
+ setStatus(`PID 标定成功: ${res?.text || ''}`);
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`PID 标定失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-man-apply').addEventListener('click', async () => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('manual_duty', {
|
|
|
|
|
+ ptc_all: Number(el('th-man-ptc').value) || 0,
|
|
|
|
|
+ fan_in_all: Number(el('th-man-fan-in').value) || 0,
|
|
|
|
|
+ fan_out_all: Number(el('th-man-fan-out').value) || 0,
|
|
|
|
|
+ ssr_all: Number(el('th-man-ssr').value) || 0,
|
|
|
|
|
+ keepalive: el('th-man-keepalive').checked,
|
|
|
|
|
+ });
|
|
|
|
|
+ setStatus('已下发 35 路手动占空比 (0x46)');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`下发手动占空比失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ el('btn-th-man-zero').addEventListener('click', async () => {
|
|
|
|
|
+ el('th-man-ptc').value = '0';
|
|
|
|
|
+ el('th-man-fan-in').value = '0';
|
|
|
|
|
+ el('th-man-fan-out').value = '0';
|
|
|
|
|
+ el('th-man-ssr').value = '0';
|
|
|
|
|
+ el('th-man-keepalive').checked = false;
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('manual_duty', {
|
|
|
|
|
+ ptc_all: 0, fan_in_all: 0, fan_out_all: 0, ssr_all: 0, keepalive: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ setStatus('35 路手动占空比已全部归零');
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`归零失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Series visibility checkboxes
|
|
|
|
|
+ document.querySelectorAll('.th-chart-legend input[data-series]').forEach(chk => {
|
|
|
|
|
+ chk.addEventListener('change', () => {
|
|
|
|
|
+ if (chk.checked) enabledSeries.add(chk.dataset.series);
|
|
|
|
|
+ else enabledSeries.delete(chk.dataset.series);
|
|
|
|
|
+ scheduleChartDraw();
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Canvas hover crosshair
|
|
|
|
|
+ const canvas = el('th-trend-canvas');
|
|
|
|
|
+ const tooltip = el('th-canvas-tooltip');
|
|
|
|
|
+ canvas.addEventListener('mousemove', ev => {
|
|
|
|
|
+ const rect = canvas.getBoundingClientRect();
|
|
|
|
|
+ const padL = 44, padR = 14;
|
|
|
|
|
+ const plotW = Math.max(1, rect.width - padL - padR);
|
|
|
|
|
+ const x = ev.clientX - rect.left - padL;
|
|
|
|
|
+ if (x < 0 || x > plotW || chartRing.length === 0) {
|
|
|
|
|
+ hoverRatio = null;
|
|
|
|
|
+ tooltip.classList.add('hidden');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ hoverRatio = Math.min(1, Math.max(0, x / plotW));
|
|
|
|
|
+ }
|
|
|
|
|
+ scheduleChartDraw();
|
|
|
|
|
+ });
|
|
|
|
|
+ canvas.addEventListener('mouseleave', () => {
|
|
|
|
|
+ hoverRatio = null;
|
|
|
|
|
+ tooltip.classList.add('hidden');
|
|
|
|
|
+ scheduleChartDraw();
|
|
|
|
|
+ });
|
|
|
|
|
+ window.addEventListener('resize', scheduleChartDraw);
|
|
|
|
|
+
|
|
|
|
|
+ function scheduleChartDraw() {
|
|
|
|
|
+ if (rafPending || document.body.dataset.currentPage !== 'thermal') return;
|
|
|
|
|
+ rafPending = true;
|
|
|
|
|
+ requestAnimationFrame(() => {
|
|
|
|
|
+ rafPending = false;
|
|
|
|
|
+ drawTrendChart();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function drawTrendChart() {
|
|
|
|
|
+ const rect = canvas.parentElement.getBoundingClientRect();
|
|
|
|
|
+ if (rect.width < 40 || rect.height < 40) return;
|
|
|
|
|
+ const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
|
|
|
+ const w = Math.floor(rect.width);
|
|
|
|
|
+ const h = Math.floor(rect.height);
|
|
|
|
|
+ if (canvas.width !== w * dpr || canvas.height !== h * dpr) {
|
|
|
|
|
+ canvas.width = w * dpr;
|
|
|
|
|
+ canvas.height = h * dpr;
|
|
|
|
|
+ }
|
|
|
|
|
+ const ctx = canvas.getContext('2d');
|
|
|
|
|
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
|
|
|
+ ctx.clearRect(0, 0, w, h);
|
|
|
|
|
+
|
|
|
|
|
+ const padL = 44, padR = 14, padT = 14, padB = 26;
|
|
|
|
|
+ const plotW = w - padL - padR;
|
|
|
|
|
+ const plotH = h - padT - padB;
|
|
|
|
|
+
|
|
|
|
|
+ if (chartRing.length === 0) {
|
|
|
|
|
+ ctx.fillStyle = '#8b9ca8';
|
|
|
|
|
+ ctx.font = '12px sans-serif';
|
|
|
|
|
+ ctx.textAlign = 'center';
|
|
|
|
|
+ ctx.fillText('连接高温罩(或开启服务器 IPMI / 开始记录)后实时绘制温度曲线', w / 2, h / 2);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let minY = Infinity, maxY = -Infinity;
|
|
|
|
|
+ for (let i = 0; i < chartRing.length; i++) {
|
|
|
|
|
+ const p = chartRing[i];
|
|
|
|
|
+ for (const s of SERIES_META) {
|
|
|
|
|
+ if (!enabledSeries.has(s.key)) continue;
|
|
|
|
|
+ const v = p[s.key];
|
|
|
|
|
+ if (typeof v === 'number' && Number.isFinite(v)) {
|
|
|
|
|
+ if (v < minY) minY = v;
|
|
|
|
|
+ if (v > maxY) maxY = v;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!Number.isFinite(minY) || !Number.isFinite(maxY)) {
|
|
|
|
|
+ minY = 20;
|
|
|
|
|
+ maxY = 80;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ minY = Math.floor(Math.max(0, minY - 4) / 5) * 5;
|
|
|
|
|
+ maxY = Math.ceil((maxY + 4) / 5) * 5;
|
|
|
|
|
+ if (maxY - minY < 15) maxY = minY + 15;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Horizontal grid & Y labels
|
|
|
|
|
+ ctx.strokeStyle = '#e7eff3';
|
|
|
|
|
+ ctx.lineWidth = 1;
|
|
|
|
|
+ ctx.fillStyle = '#738896';
|
|
|
|
|
+ ctx.font = '11px monospace';
|
|
|
|
|
+ ctx.textAlign = 'right';
|
|
|
|
|
+ const steps = 4;
|
|
|
|
|
+ for (let k = 0; k <= steps; k++) {
|
|
|
|
|
+ const val = minY + ((maxY - minY) * (steps - k)) / steps;
|
|
|
|
|
+ const y = padT + (plotH * k) / steps;
|
|
|
|
|
+ ctx.beginPath();
|
|
|
|
|
+ ctx.moveTo(padL, y);
|
|
|
|
|
+ ctx.lineTo(padL + plotW, y);
|
|
|
|
|
+ ctx.stroke();
|
|
|
|
|
+ ctx.fillText(`${Math.round(val)}°`, padL - 6, y + 4);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Time X labels
|
|
|
|
|
+ const n = chartRing.length;
|
|
|
|
|
+ const xOf = idx => padL + (n <= 1 ? plotW / 2 : (idx / (n - 1)) * plotW);
|
|
|
|
|
+ const yOf = val => padT + plotH - ((val - minY) / (maxY - minY)) * plotH;
|
|
|
|
|
+
|
|
|
|
|
+ ctx.textAlign = 'center';
|
|
|
|
|
+ const tickCount = Math.min(5, n);
|
|
|
|
|
+ for (let t = 0; t < tickCount; t++) {
|
|
|
|
|
+ const idx = tickCount === 1 ? 0 : Math.round((t * (n - 1)) / (tickCount - 1));
|
|
|
|
|
+ ctx.fillText(fmtTimeShort(chartRing[idx].t), xOf(idx), h - 7);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Series polylines
|
|
|
|
|
+ for (const s of SERIES_META) {
|
|
|
|
|
+ if (!enabledSeries.has(s.key)) continue;
|
|
|
|
|
+ ctx.save();
|
|
|
|
|
+ ctx.strokeStyle = s.color;
|
|
|
|
|
+ ctx.lineWidth = s.key === 'bmc_avg' ? 2.2 : 1.6;
|
|
|
|
|
+ if (s.dashed) ctx.setLineDash([5, 4]);
|
|
|
|
|
+ ctx.beginPath();
|
|
|
|
|
+ let penDown = false;
|
|
|
|
|
+ for (let i = 0; i < n; i++) {
|
|
|
|
|
+ const v = chartRing[i][s.key];
|
|
|
|
|
+ if (typeof v === 'number' && Number.isFinite(v)) {
|
|
|
|
|
+ const px = xOf(i);
|
|
|
|
|
+ const py = yOf(v);
|
|
|
|
|
+ if (!penDown) {
|
|
|
|
|
+ ctx.moveTo(px, py);
|
|
|
|
|
+ penDown = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ctx.lineTo(px, py);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ penDown = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ctx.stroke();
|
|
|
|
|
+ ctx.restore();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Hover crosshair
|
|
|
|
|
+ if (hoverRatio !== null && n > 0) {
|
|
|
|
|
+ const idx = Math.min(n - 1, Math.max(0, Math.round(hoverRatio * (n - 1))));
|
|
|
|
|
+ const pt = chartRing[idx];
|
|
|
|
|
+ const hx = xOf(idx);
|
|
|
|
|
+ ctx.save();
|
|
|
|
|
+ ctx.strokeStyle = '#95a8b6';
|
|
|
|
|
+ ctx.setLineDash([3, 3]);
|
|
|
|
|
+ ctx.beginPath();
|
|
|
|
|
+ ctx.moveTo(hx, padT);
|
|
|
|
|
+ ctx.lineTo(hx, padT + plotH);
|
|
|
|
|
+ ctx.stroke();
|
|
|
|
|
+ ctx.restore();
|
|
|
|
|
+
|
|
|
|
|
+ const parts = [`时间: ${fmtTimeShort(pt.t)} (${pt.phase || 'idle'})`];
|
|
|
|
|
+ if (pt.target != null) parts.push(`目标: ${pt.target}℃`);
|
|
|
|
|
+ if (pt.bmc_avg != null) parts.push(`MCU均/高: ${pt.bmc_avg} / ${pt.bmc_max ?? '--'}℃`);
|
|
|
|
|
+ if (pt.ct_avg != null) parts.push(`CT腔均: ${pt.ct_avg}℃`);
|
|
|
|
|
+ if (pt.ipmi_avg != null) parts.push(`IPMI均: ${pt.ipmi_avg}℃`);
|
|
|
|
|
+ setTextIfChanged(tooltip, parts.join(' | '));
|
|
|
|
|
+ tooltip.classList.remove('hidden');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function setPill(id, text, tone) {
|
|
|
|
|
+ const node = el(id);
|
|
|
|
|
+ if (!node) return;
|
|
|
|
|
+ setTextIfChanged(node, text);
|
|
|
|
|
+ const cls = tone ? `th-pill is-${tone}` : 'th-pill';
|
|
|
|
|
+ if (node.className !== cls) node.className = cls;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function renderSnapshot(snap) {
|
|
|
|
|
+ const conn = snap.connection || {};
|
|
|
|
|
+ const mcu = snap.mcu || {};
|
|
|
|
|
+ const flags = mcu.flags || {};
|
|
|
|
|
+ const stats = snap.stats || {};
|
|
|
|
|
+ const act = snap.actuators || {};
|
|
|
|
|
+ const safety = snap.safety || {};
|
|
|
|
|
+ const rec = snap.recorder || {};
|
|
|
|
|
+ const stCtx = snap.station_context || {};
|
|
|
|
|
+
|
|
|
|
|
+ // Sync saved prefs once on initial load without overwriting user's active typing
|
|
|
|
|
+ if (!prefsSyncedOnce) {
|
|
|
|
|
+ prefsSyncedOnce = true;
|
|
|
|
|
+ if (conn.serial_path) el('th-serial-path').value = conn.serial_path;
|
|
|
|
|
+ if (conn.tcp_host) el('th-tcp-host').value = conn.tcp_host;
|
|
|
|
|
+ if (conn.tcp_port) el('th-tcp-port').value = String(conn.tcp_port);
|
|
|
|
|
+ if (stCtx.station_id) el('th-bound-station').value = stCtx.station_id;
|
|
|
|
|
+ if (mcu.last_set_target_c != null) el('th-target-input').value = String(mcu.last_set_target_c);
|
|
|
|
|
+ if (rec.interval_ms) el('th-rec-interval').value = String(rec.interval_ms);
|
|
|
|
|
+ if (typeof rec.auto_record_on_heat === 'boolean') el('th-chk-auto-rec').checked = rec.auto_record_on_heat;
|
|
|
|
|
+ if (safety.lease_sec != null) {
|
|
|
|
|
+ const ls = String(safety.lease_sec);
|
|
|
|
|
+ if ([...el('th-safety-lease').options].some(o => o.value === ls)) {
|
|
|
|
|
+ el('th-safety-lease').value = ls;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (safety.overtemp_cutoff_c != null) el('th-overtemp-cutoff').value = String(safety.overtemp_cutoff_c);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Overview quick badge
|
|
|
|
|
+ const ovBadge = el('ov-thermal-badge');
|
|
|
|
|
+ if (ovBadge) {
|
|
|
|
|
+ if (conn.mode === 'disconnected') {
|
|
|
|
|
+ setTextIfChanged(ovBadge, rec.active ? '未连接 · 记录中' : '未连接');
|
|
|
|
|
+ ovBadge.className = 'badge';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const bAvg = stats.mcu_bmc_avg ?? stats.ct_avg;
|
|
|
|
|
+ const tStr = mcu.target_c != null ? `/${mcu.target_c}℃` : '';
|
|
|
|
|
+ const recMark = rec.active ? ' · REC' : '';
|
|
|
|
|
+ setTextIfChanged(
|
|
|
|
|
+ ovBadge,
|
|
|
|
|
+ `${stateLabel(mcu.state)} ${bAvg != null ? bAvg + '℃' : '--'}${tStr}${recMark}`
|
|
|
|
|
+ );
|
|
|
|
|
+ ovBadge.className = conn.online ? 'badge connected' : 'badge error';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Status strip pills
|
|
|
|
|
+ const modeDesc = conn.mode === 'serial'
|
|
|
|
|
+ ? `串口 ${conn.serial_path}`
|
|
|
|
|
+ : conn.mode === 'mock'
|
|
|
|
|
+ ? '虚拟仿真 Mock'
|
|
|
|
|
+ : conn.mode === 'tcp'
|
|
|
|
|
+ ? `TCP ${conn.tcp_host}:${conn.tcp_port}`
|
|
|
|
|
+ : '未连接';
|
|
|
|
|
+ setPill('th-pill-online', `链路: ${modeDesc}${conn.online ? ' (在线)' : ''}`, conn.online ? 'ok' : (conn.mode === 'disconnected' ? '' : 'err'));
|
|
|
|
|
+ setPill('th-pill-state', `状态: ${stateLabel(mcu.state)}`, (flags.preheating || flags.pid_running) ? 'active' : (flags.cpld_lost ? 'err' : ''));
|
|
|
|
|
+ setPill('th-pill-cpld', `CPLD: ${!conn.online ? '--' : (flags.cpld_lost ? '失联告警!' : '正常在线')}`, !conn.online ? '' : (flags.cpld_lost ? 'err' : 'ok'));
|
|
|
|
|
+ setPill('th-pill-preheat', `预加热: ${flags.preheating ? '运行中' : '否'}`, flags.preheating ? 'warn' : '');
|
|
|
|
|
+ setPill('th-pill-pid', `PID闭环: ${flags.pid_running ? '控温中' : '否'}`, flags.pid_running ? 'active' : '');
|
|
|
|
|
+ setPill('th-pill-hlatch', `加热锁存: ${flags.heater_latched_off ? '已锁死禁用' : '正常'}`, flags.heater_latched_off ? 'warn' : '');
|
|
|
|
|
+ setPill('th-pill-flatch', `风扇锁存: ${flags.fan_latched_off ? '已锁死禁用' : '正常'}`, flags.fan_latched_off ? 'warn' : '');
|
|
|
|
|
+ setPill('th-pill-bmc', `BMC温度源: ${!conn.online ? '--' : (flags.bmc_not_ready ? '待就绪(全FF)' : '已就绪')}`, !conn.online ? '' : (flags.bmc_not_ready ? 'warn' : 'ok'));
|
|
|
|
|
+ setPill('th-pill-manual', `手动保持: ${flags.manual_hold ? '运行中' : '否'}`, flags.manual_hold ? 'warn' : '');
|
|
|
|
|
+
|
|
|
|
|
+ const bi = mcu.boot_info;
|
|
|
|
|
+ const fwStr = bi ? `${bi.app_version || '--'} (${bi.product_id_hex || ''})` : '--';
|
|
|
|
|
+ setTextIfChanged(
|
|
|
|
|
+ el('th-hw-identity'),
|
|
|
|
|
+ `UID: ${mcu.uid_hex || '--'} · 固件: ${fwStr} · RX:${conn.rx_frames_ok || 0} TX:${conn.tx_frames_sent || 0} CRC错:${conn.crc_errors || 0}`
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // Safety bar
|
|
|
|
|
+ const leaseNode = el('th-lease-countdown');
|
|
|
|
|
+ if (safety.overtemp_tripped) {
|
|
|
|
|
+ setTextIfChanged(leaseNode, `已触发超温熔断保护 (>=${safety.overtemp_cutoff_c}℃)!`);
|
|
|
|
|
+ leaseNode.className = 'badge error';
|
|
|
|
|
+ } else if (safety.lease_active) {
|
|
|
|
|
+ setTextIfChanged(leaseNode, `看门狗倒计时: ${safety.lease_remaining_sec}s`);
|
|
|
|
|
+ leaseNode.className = safety.lease_remaining_sec <= 60 ? 'badge error' : 'badge connected';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setTextIfChanged(leaseNode, safety.lease_sec > 0 ? `看门狗待命 (${safety.lease_sec}s)` : '看门狗已设为不限时');
|
|
|
|
|
+ leaseNode.className = 'badge';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ setTextIfChanged(el('th-target-badge'), `当前目标: ${mcu.target_c != null ? mcu.target_c + ' ℃' : '--'}`);
|
|
|
|
|
+ setTextIfChanged(el('th-pid-current'), mcu.pid_text || '--');
|
|
|
|
|
+
|
|
|
|
|
+ // Actuators live feedback
|
|
|
|
|
+ const ssrArr = Array.isArray(act.ssr_applied) ? act.ssr_applied : [0, 0, 0];
|
|
|
|
|
+ const ffArr = Array.isArray(act.fan_front_applied) ? act.fan_front_applied : [0, 0, 0, 0];
|
|
|
|
|
+ const frArr = Array.isArray(act.fan_rear_applied) ? act.fan_rear_applied : [0, 0, 0, 0];
|
|
|
|
|
+ const ptcAvg = Number(act.ptc_avg_duty || 0);
|
|
|
|
|
+ setTextIfChanged(el('th-act-ssr'), conn.online ? `${ssrArr.join(' / ')} %` : '--');
|
|
|
|
|
+ setTextIfChanged(el('th-act-ptc'), conn.online ? `${ptcAvg.toFixed(1)} %` : '--');
|
|
|
|
|
+ setTextIfChanged(el('th-act-fan-f'), conn.online ? `${ffArr.join('/')} %` : '--');
|
|
|
|
|
+ setTextIfChanged(el('th-act-fan-r'), conn.online ? `${frArr.join('/')} %` : '--');
|
|
|
|
|
+ setTextIfChanged(el('th-act-ct0'), act.ct0_board_c != null ? `${act.ct0_board_c} ℃` : '--');
|
|
|
|
|
+ el('th-act-ssr').parentElement.classList.toggle('is-hot', conn.online && ssrArr.some(v => v > 0));
|
|
|
|
|
+ el('th-act-ptc').parentElement.classList.toggle('is-hot', conn.online && ptcAvg > 0);
|
|
|
|
|
+ setTextIfChanged(
|
|
|
|
|
+ el('th-diag-note'),
|
|
|
|
|
+ act.diag_line ? `CPLD/I2C 诊断: ${act.diag_line}` : (conn.online ? '等待 MCU [SNAP]/[DIAG] 周期状态行...' : '连接后实时显示 24PTC / 8风扇 / 3SSR 真实占空比')
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // Recorder panel
|
|
|
|
|
+ const recBadge = el('th-rec-badge');
|
|
|
|
|
+ const dlCur = el('btn-th-rec-download-cur');
|
|
|
|
|
+ if (rec.active) {
|
|
|
|
|
+ setTextIfChanged(recBadge, `记录中 · ${rec.rows_written || 0} 行`);
|
|
|
|
|
+ recBadge.className = 'badge connected';
|
|
|
|
|
+ if (rec.download_url) {
|
|
|
|
|
+ dlCur.href = rec.download_url;
|
|
|
|
|
+ dlCur.classList.remove('hidden');
|
|
|
|
|
+ }
|
|
|
|
|
+ setTextIfChanged(
|
|
|
|
|
+ el('th-rec-stats'),
|
|
|
|
|
+ `正在写入: ${rec.csv_filename} (分卷 #${rec.part_index || 1}) · 已写 ${rec.rows_written || 0} 行 (${fmtBytes(rec.bytes_written)}) · 标签备注: ${rec.note || '无'}`
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setTextIfChanged(recBadge, '未记录');
|
|
|
|
|
+ recBadge.className = 'badge';
|
|
|
|
|
+ dlCur.classList.add('hidden');
|
|
|
|
|
+ setTextIfChanged(
|
|
|
|
|
+ el('th-rec-stats'),
|
|
|
|
|
+ '落盘目录: data/thermal-logs/ · 包含 MCU 24路 + CT 8路 + 服务器 IPMI 24路 + 功率占空比 + 测试阶段共 106 列 (UTF-8 BOM 直接用 Excel 打开)'
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Files table (diffed by signature so buttons never flicker!)
|
|
|
|
|
+ const files = Array.isArray(rec.files) ? rec.files : [];
|
|
|
|
|
+ const filesSig = files
|
|
|
|
|
+ .map(f => `${f.filename}:${f.active ? Math.floor((f.size_bytes || 0) / 16384) : f.size_bytes}:${f.active}`)
|
|
|
|
|
+ .join('|');
|
|
|
|
|
+ if (filesSig !== lastFilesSig) {
|
|
|
|
|
+ lastFilesSig = filesSig;
|
|
|
|
|
+ const tbody = el('th-files-tbody');
|
|
|
|
|
+ tbody.replaceChildren();
|
|
|
|
|
+ if (files.length === 0) {
|
|
|
|
|
+ const tr = document.createElement('tr');
|
|
|
|
|
+ const td = document.createElement('td');
|
|
|
|
|
+ td.colSpan = 5;
|
|
|
|
|
+ td.textContent = '暂无本地记录文件(点击「开始本地记录」或开启控温自动生成)';
|
|
|
|
|
+ tr.appendChild(td);
|
|
|
|
|
+ tbody.appendChild(tr);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ for (const f of files.slice(0, 30)) {
|
|
|
|
|
+ const tr = document.createElement('tr');
|
|
|
|
|
+ const tdName = document.createElement('td');
|
|
|
|
|
+ tdName.style.fontFamily = 'var(--mono)';
|
|
|
|
|
+ tdName.textContent = f.filename + (f.active ? ' (写入中)' : '');
|
|
|
|
|
+
|
|
|
|
|
+ const tdKind = document.createElement('td');
|
|
|
|
|
+ tdKind.textContent = f.kind === 'csv' ? '全量 CSV' : '事件 JSONL';
|
|
|
|
|
+
|
|
|
|
|
+ const tdSize = document.createElement('td');
|
|
|
|
|
+ tdSize.textContent = fmtBytes(f.size_bytes);
|
|
|
|
|
+
|
|
|
|
|
+ const tdTime = document.createElement('td');
|
|
|
|
|
+ tdTime.textContent = (f.modified_str || '').slice(5, 19);
|
|
|
|
|
+
|
|
|
|
|
+ const tdAct = document.createElement('td');
|
|
|
|
|
+ const a = document.createElement('a');
|
|
|
|
|
+ a.className = 'btn btn-xs';
|
|
|
|
|
+ a.href = f.download_url;
|
|
|
|
|
+ a.download = f.filename;
|
|
|
|
|
+ a.textContent = '下载';
|
|
|
|
|
+ tdAct.appendChild(a);
|
|
|
|
|
+ if (!f.active) {
|
|
|
|
|
+ const delBtn = document.createElement('button');
|
|
|
|
|
+ delBtn.type = 'button';
|
|
|
|
|
+ delBtn.className = 'btn btn-xs';
|
|
|
|
|
+ delBtn.style.marginLeft = '5px';
|
|
|
|
|
+ delBtn.textContent = '删除';
|
|
|
|
|
+ delBtn.addEventListener('click', async () => {
|
|
|
|
|
+ if (!confirm(`确认删除本地记录文件 ${f.filename} 吗?`)) return;
|
|
|
|
|
+ try {
|
|
|
|
|
+ await callThermalAction('delete_log', { filename: f.filename });
|
|
|
|
|
+ lastFilesSig = '';
|
|
|
|
|
+ await pollConsole(true);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ setStatus(`删除失败: ${err.message}`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ tdAct.appendChild(delBtn);
|
|
|
|
|
+ }
|
|
|
|
|
+ tr.append(tdName, tdKind, tdSize, tdTime, tdAct);
|
|
|
|
|
+ tbody.appendChild(tr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Stats summary & 24-ch + 8-ch grids
|
|
|
|
|
+ setTextIfChanged(
|
|
|
|
|
+ el('th-stats-summary'),
|
|
|
|
|
+ `MCU BMC(${stats.mcu_bmc_valid || 0}/24): 均 ${stats.mcu_bmc_avg ?? '--'}℃ [低 ${stats.mcu_bmc_min ?? '--'} ~ 高 ${stats.mcu_bmc_max ?? '--'}℃, 温差 ${stats.mcu_bmc_spread ?? '--'}℃] · ` +
|
|
|
|
|
+ `CT7428(${stats.ct_valid || 0}/8): 均 ${stats.ct_avg ?? '--'}℃ [高 ${stats.ct_max ?? '--'}℃] · ` +
|
|
|
|
|
+ `服务器IPMI(${stats.ipmi_valid || 0}/24): 均 ${stats.ipmi_avg ?? '--'}℃ [高 ${stats.ipmi_max ?? '--'}℃]`
|
|
|
|
|
+ );
|
|
|
|
|
+ setTextIfChanged(
|
|
|
|
|
+ el('th-station-sync-note'),
|
|
|
|
|
+ `关联工位 ${stCtx.station_id || 'S1'} · 阶段: ${stCtx.phase || 'idle'} · 任务: ${stCtx.task_status || 'not_started'} · 电源: ${stCtx.server_power || '--'} · 累计错误: ${stCtx.stage_error_total || 0}`
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ const ctArr = Array.isArray(snap.ct7428_8) ? snap.ct7428_8 : [];
|
|
|
|
|
+ for (let i = 0; i < 8; i++) {
|
|
|
|
|
+ const v = ctArr[i];
|
|
|
|
|
+ const txt = v != null ? `${v} ℃` : '--';
|
|
|
|
|
+ if (ctCells[i].prev !== txt) {
|
|
|
|
|
+ ctCells[i].prev = txt;
|
|
|
|
|
+ ctCells[i].val.textContent = txt;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const mcuArr = Array.isArray(snap.mcu_bmc_24) ? snap.mcu_bmc_24 : [];
|
|
|
|
|
+ const ipmiArr = Array.isArray(snap.ipmi_dimm_24) ? snap.ipmi_dimm_24 : [];
|
|
|
|
|
+ for (let i = 0; i < 24; i++) {
|
|
|
|
|
+ const cell = slotCells[i];
|
|
|
|
|
+ const mv = mcuArr[i];
|
|
|
|
|
+ const iv = ipmiArr[i];
|
|
|
|
|
+ const mTxt = mv != null ? `MCU: ${mv}℃` : 'MCU: --';
|
|
|
|
|
+ const iTxt = iv != null ? `IPMI: ${Number(iv).toFixed(1)}℃` : 'IPMI: --';
|
|
|
|
|
+ const dTxt = (mv != null && iv != null) ? `Δ${(mv - iv >= 0 ? '+' : '') + (mv - iv).toFixed(1)}` : '';
|
|
|
|
|
+ const maxT = Math.max(mv ?? -1, iv ?? -1);
|
|
|
|
|
+ const cls = maxT > 80
|
|
|
|
|
+ ? 'th-slot-card is-hot'
|
|
|
|
|
+ : maxT >= 65
|
|
|
|
|
+ ? 'th-slot-card is-warn'
|
|
|
|
|
+ : maxT >= 0
|
|
|
|
|
+ ? 'th-slot-card is-valid'
|
|
|
|
|
+ : 'th-slot-card';
|
|
|
|
|
+ if (cell.prevCls !== cls) { cell.prevCls = cls; cell.card.className = cls; }
|
|
|
|
|
+ if (cell.prevMcu !== mTxt) { cell.prevMcu = mTxt; cell.mcuStrong.textContent = mTxt; }
|
|
|
|
|
+ if (cell.prevIpmi !== iTxt) { cell.prevIpmi = iTxt; cell.ipmiSpan.textContent = iTxt; }
|
|
|
|
|
+ if (cell.prevDiff !== dTxt) { cell.prevDiff = dTxt; cell.diffSpan.textContent = dTxt; }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Incremental ring buffer update (O(1) bounded at 720 points)
|
|
|
|
|
+ if (snap.reset_ring) {
|
|
|
|
|
+ chartRing = Array.isArray(snap.points_delta) ? snap.points_delta.slice(-MAX_POINTS) : [];
|
|
|
|
|
+ } else if (Array.isArray(snap.points_delta) && snap.points_delta.length > 0) {
|
|
|
|
|
+ for (const pt of snap.points_delta) {
|
|
|
|
|
+ chartRing.push(pt);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (chartRing.length > MAX_POINTS) {
|
|
|
|
|
+ chartRing.splice(0, chartRing.length - MAX_POINTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (typeof snap.latest_point_seq === 'number') {
|
|
|
|
|
+ sinceSeq = snap.latest_point_seq;
|
|
|
|
|
+ }
|
|
|
|
|
+ scheduleChartDraw();
|
|
|
|
|
+
|
|
|
|
|
+ // Debug logs (only rendered when drawer is open)
|
|
|
|
|
+ if (el('th-debug-drawer').open) {
|
|
|
|
|
+ const ascii = Array.isArray(snap.ascii_logs) ? snap.ascii_logs : [];
|
|
|
|
|
+ const aSig = ascii.length ? `${ascii[0].unix_ms}:${ascii.length}` : 'empty';
|
|
|
|
|
+ if (aSig !== lastAsciiSig) {
|
|
|
|
|
+ lastAsciiSig = aSig;
|
|
|
|
|
+ el('th-ascii-log-pre').textContent = ascii.length
|
|
|
|
|
+ ? ascii.slice(0, 45).map(a => `[${(a.time_str || '').slice(11, 23)}] ${a.line}`).join('\n')
|
|
|
|
|
+ : '暂无 MCU 串口 ASCII 输出...';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const evs = Array.isArray(snap.events) ? snap.events.slice(0, 20) : [];
|
|
|
|
|
+ const frms = Array.isArray(snap.frames) ? snap.frames.slice(0, 25) : [];
|
|
|
|
|
+ const fSig = `${evs[0]?.unix_ms || 0}:${frms[0]?.unix_ms || 0}:${frms.length}`;
|
|
|
|
|
+ if (fSig !== lastFrameSig) {
|
|
|
|
|
+ lastFrameSig = fSig;
|
|
|
|
|
+ const evTxt = evs.map(e => `[事件 ${(e.time_str || '').slice(11, 19)} ${e.level}] ${e.message}`).join('\n');
|
|
|
|
|
+ const frTxt = frms.map(f => `[${f.dir} ${f.cmd} ${f.len}B] ${f.hex}`).join('\n');
|
|
|
|
|
+ el('th-frame-log-pre').textContent = [evTxt, frTxt].filter(Boolean).join('\n--- 最近协议报文 ---\n') || '暂无事件与协议帧...';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async function pollConsole(forceIncludeDebug = false) {
|
|
|
|
|
+ if (pollInFlight || document.hidden) return;
|
|
|
|
|
+ pollInFlight = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const onThermalPage = document.body.dataset.currentPage === 'thermal';
|
|
|
|
|
+ const includeFrames = Boolean(forceIncludeDebug || (onThermalPage && el('th-debug-drawer')?.open));
|
|
|
|
|
+ const snap = await window.stlTransport.call('GetThermalConsole', {
|
|
|
|
|
+ since_seq: sinceSeq,
|
|
|
|
|
+ include_frames: includeFrames,
|
|
|
|
|
+ }, 8000);
|
|
|
|
|
+ if (snap) renderSnapshot(snap);
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // Transport layer handles reconnects gracefully
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ pollInFlight = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function resetPollTimer() {
|
|
|
|
|
+ if (pollTimer) clearInterval(pollTimer);
|
|
|
|
|
+ const onThermalPage = document.body.dataset.currentPage === 'thermal';
|
|
|
|
|
+ pollTimer = setInterval(() => pollConsole(false), onThermalPage ? 1000 : 3500);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ window.addEventListener('stl:page-change', ev => {
|
|
|
|
|
+ resetPollTimer();
|
|
|
|
|
+ if (ev.detail?.page === 'thermal') {
|
|
|
|
|
+ scanPorts(true);
|
|
|
|
|
+ pollConsole(false);
|
|
|
|
|
+ scheduleChartDraw();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ document.addEventListener('visibilitychange', () => {
|
|
|
|
|
+ if (!document.hidden) pollConsole(false);
|
|
|
|
|
+ });
|
|
|
|
|
+ el('th-debug-drawer').addEventListener('toggle', () => {
|
|
|
|
|
+ if (el('th-debug-drawer').open) pollConsole(true);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Initial bootstrap
|
|
|
|
|
+ resetPollTimer();
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ scanPorts(true);
|
|
|
|
|
+ pollConsole(false);
|
|
|
|
|
+ }, 300);
|
|
|
|
|
+})();
|