boot-plan-controls.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. // Boot plans & Multi-Profile Test Queue (ICT + RMT + AMT + MT full profile library & batch runner)
  2. (() => {
  3. const $ = id => document.getElementById(id);
  4. const esc = v => String(v ?? '').replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
  5. const stages = [
  6. ['uip1','ICT Stage 1','自动应用 ICT Stage 1 内存/电压/时序/RMT 参数并发送 exit 继续'],
  7. ['amt','AMT 测试菜单','按 AMT 页配置执行 tp 测试序列或发送 exit 跳过'],
  8. ['uip2','ICT Stage 2','自动应用 ICT Stage 2 参数并发送 exit 进入 DXE / UEFI'],
  9. ['uefi','UEFI 阶段','等待或继续进入 MT 内存测试'],
  10. ['mt','MT 内存测试','通过标准 PXE 自动运行 118.efi (mt86.cfg) 或在 Shell 启动'],
  11. ];
  12. document.querySelector('[data-page="testing"]').insertAdjacentHTML('afterend','<button class="workspace-tab" role="tab" data-page="plan">5. Profile 库与多计划队列</button>');
  13. document.querySelector('.phase-actions-panel').insertAdjacentHTML('beforebegin',`
  14. <section class="firmware-panel task-batch-panel" data-pages="plan" aria-labelledby="task-batch-title">
  15. <div class="panel-heading">
  16. <div>
  17. <h3 id="task-batch-title">测试 Profile 配置库 & 多计划循环测试队列</h3>
  18. <p>标准三步使用流程:<strong>① 在第 2/3/4 页配置好 ICT、AMT、MT 详细参数并保存</strong> → <strong>② 在下方将当前完整配置保存为一个命名 Profile</strong> → <strong>③ 组合多个 Profile 与各自重复次数,一键启动多计划循环测试队列</strong>(每轮日志与 JSON 报告独立落盘)。</p>
  19. </div>
  20. <span class="badge" id="task-batch-state-badge">空闲</span>
  21. </div>
  22. <div style="background:#f8fafc;border:1px solid #dbe4ee;border-radius:8px;padding:12px;margin-bottom:14px">
  23. <div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;margin-bottom:8px">
  24. <strong>第一步:当前工位已保存的 ICT / AMT / MT 详细配置快照(将被打包进新 Profile)</strong>
  25. <div style="display:flex;gap:6px">
  26. <button type="button" class="btn btn-quiet btn-xs" data-plan-nav="uip">去改 2. ICT 参数</button>
  27. <button type="button" class="btn btn-quiet btn-xs" data-plan-nav="amt">去改 3. AMT 参数</button>
  28. <button type="button" class="btn btn-quiet btn-xs" data-plan-nav="testing">去改 4. PXE/MT 参数</button>
  29. </div>
  30. </div>
  31. <div id="tb-current-config-preview" style="display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:8px;font-size:13px"></div>
  32. <div class="connection-form-grid" style="margin-top:10px">
  33. <label>保存为 Profile 名称<input id="tb-profile-name" value="Profile-1 (ICT+AMT+MT)" placeholder="如:低温5600-快测 / 高温VDD1100" spellcheck="false"></label>
  34. <label>默认循环次数 (Repeat · 0=无限连续压测)<input id="tb-profile-repeat" type="number" min="0" value="1"></label>
  35. <label>目标温度 (℃ · 0=不控温)<input id="tb-profile-temp" type="number" min="0" max="254" value="70"></label>
  36. <label>AMT 快捷模式覆盖<select id="tb-profile-amt-mode">
  37. <option value="current">沿用第 3 页已保存的 AMT 详细配置</option>
  38. <option value="fast24">24 项算法极速全覆盖 (tp end_step=0 · 短地址快测)</option>
  39. <option value="tp0">仅跑 AMT 第 1 项 (tp 0,1,0,0,0,255 · 极速验证)</option>
  40. <option value="all24">跑 AMT 全量 24 项完整长度</option>
  41. <option value="skip">本 Profile 跳过 AMT (发送 exit)</option>
  42. </select></label>
  43. <label>MT (118.efi) 快捷覆盖<select id="tb-profile-mt-mode">
  44. <option value="current">沿用第 4 页已保存的 PXE/MT 详细配置</option>
  45. <option value="fast64m">短地址极速验证 (TSTLIST=0..25 · 仅测 64MB 区间)</option>
  46. <option value="test0_64m">仅测 Test 0 + 64MB 短地址 (10秒极速)</option>
  47. <option value="test0_all">仅测 Test 0 (全内存)</option>
  48. <option value="skip">本 Profile 跳过 MT (到 UEFI Shell 即完成)</option>
  49. </select></label>
  50. </div>
  51. <div class="plan-checks" style="margin-top:8px">
  52. <label class="check-label"><input id="tb-profile-rmt" type="checkbox" checked>在本 Profile 中开启 ICT RMT 裕量扫描 (<code>rmt enable</code>)</label>
  53. </div>
  54. <div class="form-actions" style="margin-top:8px">
  55. <button type="button" class="btn btn-primary btn-sm" id="btn-tb-save-library">保存到后端 Profile 库</button>
  56. <button type="button" class="btn btn-secondary btn-sm" id="btn-tb-add-profile">直接加入右侧待执行测试队列</button>
  57. <span class="field-note" id="tb-library-status"></span>
  58. </div>
  59. <details class="raw-uip-editor" style="margin-top:10px" id="quick-task-creator">
  60. <summary><strong>快捷 15 参数任务创建器 & 跨工位批量指派(无需逐页跳转即可快速构建 Profile 并下发多工位)</strong></summary>
  61. <div class="connection-form-grid" style="margin-top:8px">
  62. <label>任务名称<input id="qt-name" value="高温标准测试" spellcheck="false"></label>
  63. <label>目标温度 (℃)<input id="qt-temp" type="number" min="0" max="254" value="70"></label>
  64. <label>DDR5 频率 (MT/s)<input id="qt-datarate" placeholder="留空=按SPD默认,如 5600 / 6400" spellcheck="false"></label>
  65. <label>VDD 电压 (mV)<input id="qt-vdd" placeholder="留空=1100" spellcheck="false"></label>
  66. <label>VDDQ 电压 (mV)<input id="qt-vddq" placeholder="留空=1100" spellcheck="false"></label>
  67. <label>VPP 电压 (mV)<input id="qt-vpp" placeholder="留空=1800" spellcheck="false"></label>
  68. <label>RMT 裕量<select id="qt-rmt"><option value="enable">开启 RMT</option><option value="backside">RMT + Backside</option><option value="disable">跳过 RMT</option></select></label>
  69. <label>AMT 模式<select id="qt-amt"><option value="all24">全量 24 项</option><option value="fast24">24 项极速 (end_step=0)</option><option value="tp0">仅第 1 项</option><option value="skip">跳过 AMT</option></select></label>
  70. <label>MT 测试项 (TSTLIST)<input id="qt-mt-tstlist" value="0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25" spellcheck="false"></label>
  71. <label>MT 地址范围<select id="qt-mt-range"><option value="all">全部内存</option><option value="custom">64MB 短地址快测</option><option value="skip">跳过 MT</option></select></label>
  72. <label>MT 轮数 (NUMPASS)<input id="qt-mt-numpass" type="number" min="1" value="1"></label>
  73. <label>循环次数 (0=无限连续)<input id="qt-repeat" type="number" min="0" value="1"></label>
  74. <label class="check-label"><input type="checkbox" id="qt-errhandle" checked>开启 Error Handle WA (<code>errhandle disable</code>)</label>
  75. <label class="check-label"><input type="checkbox" id="qt-stop-fail" checked>遇 FAIL 即停机</label>
  76. <label>死机超时后处理动作<select id="qt-hang-action"><option value="stop" selected>停机保留死机现场(默认)</option><option value="retry_current_task">自动重启重做当前未完成任务</option><option value="restart_full_plan">自动重启重做整个计划</option></select></label>
  77. </div>
  78. <div style="margin-top:8px;display:flex;flex-wrap:wrap;align-items:center;gap:8px;font-size:12px">
  79. <strong>指派目标工位:</strong>
  80. <div id="qt-target-stations" style="display:flex;flex-wrap:wrap;gap:8px"></div>
  81. <button type="button" class="btn btn-primary btn-xs" id="btn-qt-dispatch-stations">一键保存并下发到所选工位</button>
  82. <button type="button" class="btn btn-secondary btn-xs" id="btn-qt-save-only">仅保存为当前工位 Profile</button>
  83. </div>
  84. </details>
  85. </div>
  86. <div class="plan-layout">
  87. <div class="plan-editor">
  88. <div class="subpanel-title">
  89. <h4>第二步:工位已保存的 Profile 库(可查看详细 ICT/AMT/MT 参数、加载回编辑器或加入队列)</h4>
  90. <span class="badge" id="tb-library-count">0 个已存 Profile</span>
  91. </div>
  92. <div id="tb-saved-profiles-list" style="display:grid;gap:8px;margin-bottom:14px"></div>
  93. <div class="subpanel-title" style="border-top:1px solid #e2e8f0;padding-top:10px">
  94. <h4>第三步:待执行的多计划组合队列(按顺序依次执行各 Profile 指定次数)</h4>
  95. <span class="field-note" id="tb-draft-summary">待下发队列:0 组 Profile</span>
  96. </div>
  97. <div id="tb-draft-list" style="margin-top:8px;display:grid;gap:6px"></div>
  98. <div class="plan-checks" style="margin-top:8px;display:flex;flex-wrap:wrap;gap:12px;align-items:center">
  99. <label class="check-label"><input id="tb-stop-on-fail" type="checkbox" checked>任一轮次出现测试 FAIL / BLOCK 时立即停止后续队列</label>
  100. <label style="font-size:12px;display:inline-flex;align-items:center;gap:6px">死机超时后处理
  101. <select id="tb-hang-action">
  102. <option value="stop" selected>停机保留死机现场(默认)</option>
  103. <option value="retry_current_task">自动重启并重做当前未完成完整任务</option>
  104. <option value="restart_full_plan">自动重启并从头重做整个多计划队列</option>
  105. </select>
  106. </label>
  107. <label style="font-size:12px;display:inline-flex;align-items:center;gap:4px">连续死机停机阈值(0=不限) <input id="tb-max-consecutive-hangs" type="number" min="0" value="2" style="width:58px;padding:2px 4px"> 次</label>
  108. <label class="check-label" title="仅工程视图可用:高温罩未连接时允许跳过在线检查强行开测"><input id="tb-skip-thermal-check" type="checkbox">工程模式跳过高温罩在线校验</label>
  109. </div>
  110. <div class="form-actions" style="margin-top:8px">
  111. <button type="button" class="btn btn-quiet btn-sm" id="btn-tb-clear-draft">清空待下发队列</button>
  112. </div>
  113. </div>
  114. <aside class="plan-live-card">
  115. <div class="subpanel-title"><h3>多计划队列运行控制(后端持久化托管)</h3><span class="badge" id="tb-live-progress">0 / 0 轮</span></div>
  116. <strong id="tb-live-title" class="execution-stage">尚无活动批次队列</strong>
  117. <p id="tb-live-detail" class="execution-reason">从左侧 Profile 库添加组合(如 Profile-A × 2 次 + Profile-B × 0 无限循环)后,点击下方按钮立即由后端自动按序重启执行,关闭浏览器不中断。</p>
  118. <div class="plan-launch-actions" style="display:grid;gap:6px">
  119. <button type="button" class="btn btn-primary" id="btn-tb-submit-start">提交并立即重启执行多计划队列</button>
  120. </div>
  121. <div class="form-actions">
  122. <button type="button" class="btn btn-secondary" id="btn-tb-pause">暂停队列</button>
  123. <button type="button" class="btn btn-primary" id="btn-tb-resume">继续队列</button>
  124. <button type="button" class="btn btn-quiet" id="btn-tb-stop">停止队列</button>
  125. </div>
  126. </aside>
  127. </div>
  128. <div style="margin-top:14px">
  129. <h4 style="margin:6px 0">各轮测试执行进度与独立落盘归档记录</h4>
  130. <div class="events-container"><table class="events-table"><thead><tr><th>轮次编号</th><th>执行 Profile</th><th>循环进度</th><th>启动 ID</th><th>状态 / 结论</th><th>独立归档路径 (sol.raw / sol.clean.log / summary.json)</th></tr></thead><tbody id="tb-runs-tbody"><tr><td colspan="6">尚无批次运行记录</td></tr></tbody></table></div>
  131. </div>
  132. </section>
  133. <section class="firmware-panel startup-plan-panel" data-pages="plan" aria-labelledby="plan-title" style="margin-top:16px">
  134. <div class="panel-heading"><div><h3 id="plan-title">单次启动计划控制(按当前激活配置单轮运行)</h3><p>配置单次开机各阶段(ICT Stage 1 / AMT / ICT Stage 2 / UEFI / MT)自动或手动执行方式。</p></div><span class="badge" id="boot-plan-save-state">读取中</span></div>
  135. <div class="plan-layout"><div class="plan-editor">
  136. <label class="plan-preset-label">执行模式<select id="boot-plan-preset"><option value="auto">全自动执行</option><option value="custom">按阶段自定义</option><option value="manual">全手动(仅观察串口)</option></select></label><p class="field-note hidden" id="boot-plan-preset-note"></p>
  137. <div class="plan-stage-table">${stages.map(([key,name,note]) => `<div class="plan-stage-row"><div><strong>${name}</strong><small>${note}</small></div><select data-plan-stage="${key}" aria-label="${name}执行方式"><option value="auto">自动执行</option><option value="manual">手动操作</option></select></div>`).join('')}</div>
  138. <div class="plan-checks"><label class="check-label"><input id="boot-plan-mt-enabled" type="checkbox">到达 UEFI 后继续执行 MT 内存测试</label><label class="check-label"><input id="boot-plan-use-in-runs" type="checkbox">高温测试轮次默认使用此启动计划</label></div>
  139. <div class="form-actions"><button class="btn btn-primary" id="btn-save-boot-plan">保存启动计划</button><button class="btn btn-quiet" id="btn-reload-boot-plan">重置</button><span class="field-note" id="boot-plan-edit-note"></span></div>
  140. </div><aside class="plan-live-card"><div class="subpanel-title"><h3>单轮运行控制</h3><span class="badge" id="boot-execution-state">未开始</span></div><strong id="boot-execution-stage" class="execution-stage">等待启动</strong><p id="boot-execution-reason" class="execution-reason"></p><div id="boot-execution-identity" class="execution-identifiers"></div><div class="plan-launch-actions"><button class="btn btn-primary" id="btn-restart-boot-plan">重启并单轮执行</button><button class="btn btn-secondary" id="btn-start-boot-plan">从当前阶段开始</button></div><div class="form-actions"><button class="btn btn-secondary" id="btn-pause-boot-plan">暂停 / 人工接管</button><button class="btn btn-primary" id="btn-resume-boot-plan">继续执行</button><button class="btn btn-quiet" id="btn-stop-boot-plan">停止计划</button></div><p id="boot-plan-launch-note" class="field-note"></p><button class="inline-link hidden" id="btn-plan-open-input">跳转当前阶段</button></aside></div>
  141. <div id="boot-plan-dependencies" class="plan-dependencies"></div>
  142. <details class="observation-details"><summary>单轮计划执行记录 <span id="boot-execution-count">0 条</span></summary><ol id="boot-execution-history"><li>无记录</li></ol></details>
  143. </section>
  144. <section class="firmware-panel thermal-policy-panel" data-pages="plan" aria-labelledby="thermal-policy-title" style="margin-top:16px">
  145. <div class="panel-heading">
  146. <div>
  147. <h3 id="thermal-policy-title">6400 高温罩后端闭环自动联动策略(按工位持久化)</h3>
  148. <p>后端自动执行完整温控闭环:开测前校验高温罩在线状态(产线视图强制拦截,工程视图可勾选跳过)→ DDR Training 完成后自动发送 <code>0x01</code> 加热至目标温度 → 多轮中间轮次 PASS 发送 <code>0x08 01</code> 保温 → 最终完成、FAIL、卡死超时、掉电或手动停止时自动发送 <code>0x08 00</code> 吹扫降温。</p>
  149. </div>
  150. <span class="badge" id="th-policy-badge">待加载</span>
  151. </div>
  152. <div class="connection-form-grid" style="margin-top:8px">
  153. <label class="check-label"><input id="th-policy-auto" type="checkbox" checked><strong>启用测试流程自动联动高温罩控温</strong></label>
  154. <label>自动加热目标温度 (℃, 0~254)<input id="th-policy-target" type="number" min="0" max="254" value="70"></label>
  155. <label class="check-label"><input id="th-policy-require-online" type="checkbox" checked>开测前强制校验高温罩在线(产线拦截 / 工程可跳过)</label>
  156. </div>
  157. <div class="form-actions" style="margin-top:8px">
  158. <button type="button" class="btn btn-primary btn-sm" id="btn-save-thermal-policy">保存高温罩联动策略</button>
  159. <span class="field-note" id="th-policy-note">配置实时写入后端工位设置。</span>
  160. </div>
  161. </section>
  162. <section class="firmware-panel watchdog-config-panel" data-pages="plan" aria-labelledby="watchdog-panel-title" style="margin-top:16px">
  163. <div class="panel-heading">
  164. <div>
  165. <h3 id="watchdog-panel-title">防卡死超时检测与死机恢复策略(三种处理模式 · 按工位持久化)</h3>
  166. <p><strong>超时触发后自动记录死机前日志并向高温罩发 <code>0x08 00</code> 吹扫降温,并按所选模式处理:</strong><br>
  167. ① <code>stop</code>(默认):停机并保留死机现场,不发 BMC 重启;<br>
  168. ② <code>retry_current_task</code>:自动复位主板并重新执行当前未完成的完整任务/轮次(单轮计划与多计划队列均支持);<br>
  169. ③ <code>restart_full_plan</code>:自动复位主板并从头重新执行整个测试计划(回到第 1 个 Profile 第 1 轮)。</p>
  170. </div>
  171. <span class="badge connected" id="wd-live-badge">保护已启用</span>
  172. </div>
  173. <div class="connection-form-grid" style="margin-top:8px">
  174. <label class="check-label"><input id="wd-enabled" type="checkbox" checked><strong>启用阶段防卡死超时检测与双断超时保护</strong></label>
  175. <label>BMC+2200 双断超时上限 (秒)<input id="wd-link-lost-s" type="number" min="6" value="240"></label>
  176. <label>Boot/Training/RMT 静默超时 (秒)<input id="wd-dense-silence-s" type="number" min="5" value="150"></label>
  177. <label>AMT 内存诊断静默超时 (秒)<input id="wd-amt-silence-s" type="number" min="5" value="420"></label>
  178. <label>MT (MemTest86) 静默超时 (秒)<input id="wd-mt-silence-s" type="number" min="5" value="480"></label>
  179. <label>MT 单轮总时长上限 (秒 · 0=不限)<input id="wd-mt-max-dur-s" type="number" min="0" value="3600"></label>
  180. <label>死机超时后处理模式 (<code>hang_action</code>)
  181. <select id="wd-hang-action">
  182. <option value="stop" selected>停机保留死机现场 (stop)</option>
  183. <option value="retry_current_task">重启并重做当前未完成任务 (retry_current_task)</option>
  184. <option value="restart_full_plan">重启并重做整个测试计划 (restart_full_plan)</option>
  185. </select>
  186. </label>
  187. <label>连续死机停机上限 (次 · 0=不限)<input id="wd-max-hangs" type="number" min="0" value="2"></label>
  188. </div>
  189. <div class="form-actions" style="margin-top:10px">
  190. <button type="button" class="btn btn-primary btn-sm" id="btn-save-watchdog">保存防卡死与断联保护参数</button>
  191. <span class="field-note" id="wd-status-note">waiting_user / paused / 停机换条 / 手动模式提示符下自动豁免防卡死超时计时。</span>
  192. </div>
  193. </section>`);
  194. let api, formStation = '', tbSeq = 1, wdDirty = false, wdFormStation = '', thPolDirty = false, thPolStation = '';
  195. const drafts = new Map(), tbDrafts = new Map();
  196. const getTbDraft = () => {
  197. const id = api ? api.stationId() : 'S1';
  198. if (!tbDrafts.has(id)) tbDrafts.set(id, []);
  199. return tbDrafts.get(id);
  200. };
  201. const clone = x => JSON.parse(JSON.stringify(x));
  202. const defaults = () => ({preset:'manual',stages:Object.fromEntries(stages.map(([key]) => [key,'manual'])),mt_enabled:false,use_in_runs:false});
  203. const control = () => window.stlFirmware.snapshot(api.stationId());
  204. const current = () => drafts.get(api.stationId());
  205. const stateNames = {idle:'尚未开始',queued:'已排队',running:'自动观察 / 执行',waiting_boot:'等待新启动',waiting_user:'等待人工操作',paused:'已暂停 / 人工接管',completed:'已完成',blocked:'流程被阻止',failed:'执行失败',stopped:'自动执行已停止'};
  206. const stageNames = Object.fromEntries(stages.map(([key,name]) => [key,name]));
  207. function enable(id, yes, reason='') { const b=$(id); if(!b)return; b.disabled=!yes || b.dataset.busy==='1'; b.title=yes?'':reason; }
  208. async function awaitCommand(method,args,name) {
  209. let item=await api.command(method,args,name); const deadline=Date.now()+20000;
  210. while (!['succeeded','failed','interrupted'].includes(item.state)) {
  211. if(Date.now()>deadline) throw new Error('操作仍在后端队列中,请查看操作队列;没有重新发送。');
  212. await new Promise(resolve=>setTimeout(resolve,180));
  213. try { item=await api.callApi('GetQueueItem',{command_id:item.command_id}); }
  214. catch(error) { if(!/NOT_FOUND|not found/i.test(error.message))throw error; }
  215. }
  216. if(item.state!=='succeeded')throw new Error(item.detail || item.error_code || '操作未完成');
  217. return item;
  218. }
  219. function summarizeProfile(p) {
  220. const uipOvs = (p.uip_overrides || []).filter(x => x.mode === 'override');
  221. const uipRaws = p.uip_raw_commands || [];
  222. const ictText = uipOvs.map(x => `${x.id}=${x.value}`).concat(uipRaws).join(', ') || '全部默认';
  223. const amt = p.amt || p.amt_settings || {};
  224. const runAmt = p.run_amt !== undefined ? p.run_amt : amt.action === 'run';
  225. const amtOvs = (amt.overrides || []).map(x => `${x.name} ${x.value}`.trim()).join('; ');
  226. const amtText = !runAmt ? '跳过 (exit)' : `${amt.test_command || 'amemdiag 1'}${amtOvs ? ' · ' + amtOvs : ' · 默认全量'}`;
  227. const mt = p.mt || p.mt_selection || {};
  228. const runMt = p.run_mt !== undefined ? p.run_mt : true;
  229. const mtRange = mt.memory_range === 'custom' ? `${mt.addr_lim_lo || '0x0'}~${mt.addr_lim_hi || ''}` : '全内存';
  230. const mtText = !runMt ? '跳过' : `TSTLIST=${mt.tstlist || (mt.only_tests ? mt.only_tests.join(',') : '0..25')} · ${mtRange}`;
  231. return { ictText, amtText, mtText, uipCount: uipOvs.length + uipRaws.length };
  232. }
  233. function fill() {
  234. const d=current();if(!d)return;
  235. $('boot-plan-preset').value=d.plan.preset;
  236. for(const select of document.querySelectorAll('[data-plan-stage]'))select.value=d.plan.stages[select.dataset.planStage] || 'manual';
  237. $('boot-plan-mt-enabled').checked=!!d.plan.mt_enabled;
  238. $('boot-plan-use-in-runs').checked=!!d.plan.use_in_runs;
  239. }
  240. function edit() {
  241. const d=current();if(!d)return;
  242. d.plan={preset:$('boot-plan-preset').value,stages:Object.fromEntries([...document.querySelectorAll('[data-plan-stage]')].map(s=>[s.dataset.planStage,s.value])),mt_enabled:$('boot-plan-mt-enabled').checked,use_in_runs:$('boot-plan-use-in-runs').checked};
  243. d.dirty=true;render();
  244. }
  245. function render() {
  246. if(!api)return;
  247. const c=control();if(!c.boot_plan)return;
  248. const id=api.stationId(), saved=JSON.stringify(c.boot_plan);
  249. if(!drafts.has(id))drafts.set(id,{plan:{...defaults(),...clone(c.boot_plan)},saved,dirty:false});
  250. const d=current();
  251. if(!d.dirty && d.saved!==saved){d.plan={...defaults(),...clone(c.boot_plan)};d.saved=saved;formStation='';}
  252. if(formStation!==id){formStation=id;fill();}
  253. const custom=d.plan.preset==='custom';
  254. for(const select of document.querySelectorAll('[data-plan-stage]'))select.disabled=!custom || ['uefi','mt'].includes(select.dataset.planStage)&&!d.plan.mt_enabled;
  255. $('boot-plan-preset-note').textContent={auto:'自动执行每个可操作节点;测试开关和参数取各参数页已保存的设置。',custom:'只在选择“等待我操作”的节点停下,其余节点按已保存参数自动执行。',manual:'各输入节点由你手动操作,后端持续观察并保存输出。'}[d.plan.preset] || '';
  256. $('boot-plan-save-state').textContent=d.dirty?'有未保存修改':'已保存配置';
  257. $('boot-plan-edit-note').textContent=d.dirty?'此处修改尚未保存;执行仍以已保存配置为准。':'保存不会立即写固件;执行时复制一份配置快照。';
  258. const x=c.boot_execution || {}, state=x.state || 'idle', live=['running','waiting_boot','waiting_user','paused'].includes(state);
  259. $('boot-execution-state').textContent=stateNames[state] || state;
  260. $('boot-execution-state').classList.toggle('error',['failed','blocked'].includes(state));
  261. $('boot-execution-stage').textContent=stageNames[x.current_stage] || x.current_stage || '等待开始计划';
  262. $('boot-execution-reason').textContent=x.waiting_reason || x.error || (state==='completed'?'本次启动计划已结束,后端继续采集状态。':state==='paused'?'可在参数页或控制台手动操作,完成后点“继续计划”。':state==='running'?'后端按实际固件输出推进,不需要保持页面打开。':'保存好配置后,选择重启执行或从当前节点开始。');
  263. $('boot-execution-identity').textContent=[x.id&&'执行 '+x.id,c.firmware?.boot_id&&'启动 '+c.firmware.boot_id].filter(Boolean).join(' · ');
  264. const unsaved=[d.dirty&&'启动计划',window.stlFirmware.isDirty?.()&&'ICT / MT',window.stlAmt?.isDirty?.()&&'AMT'].filter(Boolean);
  265. const launch=api.connected()&&!live&&!unsaved.length&&!api.station()?.run_id;
  266. const reason=unsaved.length?'请先保存:'+unsaved.join('、'):api.station()?.run_id?'当前高温轮次正在使用服务器':'当前已有计划在执行';
  267. enable('btn-restart-boot-plan',launch,reason);enable('btn-start-boot-plan',launch,reason);
  268. enable('btn-save-boot-plan',api.connected());enable('btn-reload-boot-plan',api.connected());
  269. enable('btn-pause-boot-plan',api.connected()&&['running','waiting_boot','waiting_user'].includes(state));
  270. enable('btn-resume-boot-plan',api.connected()&&state==='paused');enable('btn-stop-boot-plan',api.connected()&&live);
  271. $('boot-plan-launch-note').textContent=unsaved.length?'未保存:'+unsaved.join('、')+'。请先保存对应页面。':!c.capabilities?.bmc_power?'未启用 BMC 电源控制:开始计划后按后端提示人工开机 / 复位。停止自动执行不会关闭电源。':'停止自动执行只停止后续自动命令;不代替测试程序退出或主板关机。';
  272. const fw=c.firmware_settings || {}, rmt=(fw.uip_overrides||[]).find(v=>v.id==='rmt'&&v.mode==='override');
  273. $('boot-plan-dependencies').innerHTML=[['uip','ICT / RMT',`${(fw.uip_overrides||[]).filter(v=>v.mode==='override').length} 项覆盖 · RMT ${rmt?.value || '默认 / 不覆盖'}`],['amt','AMT',`${c.amt_settings?.action==='run'?'执行测试':'退出菜单'} · ${(c.amt_settings?.overrides||[]).length} 项配置`],['testing','PXE / 外部 MT',d.plan.mt_enabled?(fw.mt_selection?.efi_path || '118.efi'):'未启用 · 到 UEFI 结束']].map(([page,title,text])=>`<button class="plan-dependency" data-plan-nav="${page}"><strong>${title}</strong><span>${esc(text)}</span><small>查看已保存参数 →</small></button>`).join('');
  274. for(const button of document.querySelectorAll('[data-plan-nav]'))button.onclick=()=>window.stlNavigation.show(button.dataset.planNav);
  275. const history=Array.isArray(x.history)?x.history:[];
  276. $('boot-execution-count').textContent=history.length+' 条';
  277. $('boot-execution-history').innerHTML=history.slice(-40).reverse().map(row=>`<li><time>${api.time(row.observed_unix_ms || row.unix_ms || row.created_unix_ms)}</time><span>${esc(row.stage || row.action || row.kind || '')}</span><code>${esc(row.message || row.detail || JSON.stringify(row))}</code></li>`).join('') || '<li>尚无本次计划记录</li>';
  278. renderTaskBatch(c);
  279. }
  280. function renderTaskBatch(c) {
  281. const fw = c.firmware_settings || {}, amtSaved = c.amt_settings || {}, pxeCfg = c.pxe_control?.mt86_cfg || {};
  282. const curSummary = summarizeProfile({
  283. uip_overrides: fw.uip_overrides || [],
  284. uip_raw_commands: fw.uip_raw_commands || [],
  285. amt: amtSaved,
  286. mt: { ...pxeCfg, ...(fw.mt_selection || {}) },
  287. });
  288. if ($('tb-current-config-preview')) {
  289. $('tb-current-config-preview').innerHTML = `
  290. <div style="background:#fff;padding:8px 10px;border:1px solid #e2e8f0;border-radius:6px"><strong>ICT 阶段配置 (${curSummary.uipCount} 项)</strong><div style="color:#475569;margin-top:4px;word-break:break-all">${esc(curSummary.ictText)}</div></div>
  291. <div style="background:#fff;padding:8px 10px;border:1px solid #e2e8f0;border-radius:6px"><strong>AMT 阶段配置</strong><div style="color:#475569;margin-top:4px;word-break:break-all">${esc(curSummary.amtText)}</div></div>
  292. <div style="background:#fff;padding:8px 10px;border:1px solid #e2e8f0;border-radius:6px"><strong>PXE / MT 阶段配置</strong><div style="color:#475569;margin-top:4px;word-break:break-all">${esc(curSummary.mtText)}</div></div>
  293. `;
  294. }
  295. const savedProfiles = Array.isArray(c.saved_profiles) ? c.saved_profiles : [];
  296. if ($('tb-library-count')) $('tb-library-count').textContent = `${savedProfiles.length} 个已存 Profile`;
  297. if ($('tb-saved-profiles-list')) {
  298. $('tb-saved-profiles-list').innerHTML = savedProfiles.map((p, idx) => {
  299. const s = summarizeProfile(p);
  300. return `<div style="padding:8px 10px;background:#fff;border:1px solid #cbd5e1;border-radius:6px;font-size:13px">
  301. <div style="display:flex;justify-content:space-between;align-items:center;gap:6px;flex-wrap:wrap">
  302. <strong>${esc(p.name || 'Profile-' + (idx + 1))} <span class="badge">默认 ${Number(p.repeat) === 0 ? '无限循环' : '×' + esc(p.repeat || 1) + ' 次'}</span>${p.target_temp_c ? ` <span class="badge">${esc(p.target_temp_c)}℃</span>` : ''}</strong>
  303. <div style="display:flex;gap:4px">
  304. <button type="button" class="btn btn-secondary btn-xs" data-prof-enqueue="${idx}">+ 加入待执行队列</button>
  305. <button type="button" class="btn btn-quiet btn-xs" data-prof-load="${esc(p.profile_id || p.name)}">加载到当前编辑器</button>
  306. <button type="button" class="btn btn-quiet btn-xs" data-prof-del="${esc(p.profile_id || p.name)}">删除</button>
  307. </div>
  308. </div>
  309. <div style="color:#475569;margin-top:4px;font-size:12px">
  310. <span><b>ICT:</b> ${esc(s.ictText)}</span> · <span><b>AMT:</b> ${esc(s.amtText)}</span> · <span><b>MT:</b> ${esc(s.mtText)}</span>
  311. </div>
  312. </div>`;
  313. }).join('') || '<p class="field-note">当前工位尚未保存命名 Profile。在上方输入名称并点“保存到后端 Profile 库”即可永久保存。</p>';
  314. document.querySelectorAll('[data-prof-enqueue]').forEach(btn => {
  315. btn.onclick = () => {
  316. const p = savedProfiles[Number(btn.dataset.profEnqueue)];
  317. if (p) {
  318. getTbDraft().push(clone(p));
  319. renderTaskBatch(control());
  320. }
  321. };
  322. });
  323. document.querySelectorAll('[data-prof-load]').forEach(btn => {
  324. btn.onclick = async () => {
  325. const pid = btn.dataset.profLoad;
  326. await awaitCommand('LoadProfileToWorkspace', { station_id: api.stationId(), profile_id: pid }, `加载 Profile ${pid}`);
  327. window.stlFirmware?.resetDrafts?.();
  328. window.stlAmt?.resetDrafts?.();
  329. await window.stlFirmware.refresh();
  330. api.status(`已将 Profile ${pid} 加载为当前工位激活配置。`);
  331. };
  332. });
  333. document.querySelectorAll('[data-prof-del]').forEach(btn => {
  334. btn.onclick = async () => {
  335. const pid = btn.dataset.profDel;
  336. const ok = window.stlUi ? await window.stlUi.confirm('删除 Profile', `确认永久删除工位 ${api.stationId()} 的测试配置 "${pid}" 吗?`, '确认删除', true) : true;
  337. if (!ok) return;
  338. await awaitCommand('DeleteProfile', { station_id: api.stationId(), profile_id: pid, name: pid }, `删除 Profile ${pid}`);
  339. await window.stlFirmware.refresh();
  340. };
  341. });
  342. }
  343. const list = getTbDraft();
  344. const hasInfinite = list.some(p => Number(p.repeat) === 0);
  345. const totalDraftRuns = list.reduce((acc, p) => acc + (Number(p.repeat) === 0 ? 0 : Number(p.repeat || 1)), 0);
  346. if ($('tb-draft-summary')) $('tb-draft-summary').textContent = hasInfinite ? `待下发队列:${list.length} 组 Profile · 含无限连续压测项` : `待下发队列:${list.length} 组 Profile · 合计将连续执行 ${totalDraftRuns} 轮测试`;
  347. if ($('tb-draft-list')) {
  348. $('tb-draft-list').innerHTML = list.map((p, idx) => {
  349. const s = summarizeProfile(p);
  350. return `<div style="display:flex;justify-content:space-between;align-items:center;padding:6px 10px;background:#f0f9ff;border:1px solid #bae6fd;border-radius:6px;font-size:13px;gap:8px">
  351. <div>
  352. <strong>步骤 #${idx + 1}:${esc(p.name)}</strong>
  353. <div style="font-size:12px;color:#334155">ICT: ${esc(s.ictText)} | AMT: ${esc(s.amtText)} | MT: ${esc(s.mtText)}</div>
  354. </div>
  355. <div style="display:flex;align-items:center;gap:6px;white-space:nowrap">
  356. <label style="font-size:12px">重复次数(0=无限) <input type="number" min="0" value="${esc(p.repeat ?? 1)}" data-tb-rep="${idx}" style="width:62px;padding:2px 4px"></label>
  357. <button type="button" class="btn btn-quiet btn-xs" data-tb-del="${idx}">移除</button>
  358. </div>
  359. </div>`;
  360. }).join('') || '<p class="field-note">队列为空:可从上方 Profile 库点“+ 加入待执行队列”,或点“直接加入右侧待执行测试队列”。</p>';
  361. document.querySelectorAll('[data-tb-del]').forEach(btn => {
  362. btn.onclick = () => { list.splice(Number(btn.dataset.tbDel), 1); renderTaskBatch(control()); };
  363. });
  364. document.querySelectorAll('[data-tb-rep]').forEach(inp => {
  365. inp.onchange = () => {
  366. const i = Number(inp.dataset.tbRep);
  367. if (list[i]) list[i].repeat = Math.max(0, Number(inp.value ?? 1));
  368. renderTaskBatch(control());
  369. };
  370. });
  371. }
  372. // Sync cross-station assign checkboxes dynamically
  373. const qtBox = $('qt-target-stations');
  374. if (qtBox) {
  375. const allSt = window.stlStore?.get('stations') || [];
  376. const sig = JSON.stringify(allSt.map(x => x.station_id));
  377. if (qtBox.dataset.sig !== sig) {
  378. const checkedPrev = new Set([...qtBox.querySelectorAll('input:checked')].map(i => i.value));
  379. qtBox.dataset.sig = sig;
  380. qtBox.innerHTML = allSt.map(st => {
  381. const chk = checkedPrev.size ? checkedPrev.has(st.station_id) : st.station_id === api.stationId();
  382. return `<label class="check-label"><input type="checkbox" class="qt-station-cb" value="${esc(st.station_id)}" ${chk ? 'checked' : ''}>${esc(st.station_id)}</label>`;
  383. }).join('');
  384. }
  385. }
  386. const tb = c.task_batch || {}, tbState = tb.state || 'idle';
  387. const done = Number(tb.total_runs_completed || 0), planned = Number(tb.total_runs_planned || 0);
  388. if ($('task-batch-state-badge')) {
  389. $('task-batch-state-badge').textContent = stateNames[tbState] || tbState;
  390. $('task-batch-state-badge').classList.toggle('error', ['failed', 'blocked'].includes(tbState));
  391. }
  392. if ($('tb-live-progress')) $('tb-live-progress').textContent = `${done} / ${planned} 轮`;
  393. if ($('tb-live-title')) {
  394. $('tb-live-title').textContent = tb.batch_id ? `${tb.current_profile_name || 'Profile'} (第 ${tb.current_repeat || 1}/${tb.current_profile_repeats || 1} 次)` : '尚无活动批次队列';
  395. }
  396. if ($('tb-live-detail')) {
  397. const fmtElapsed = api.formatElapsed ? api.formatElapsed(c.elapsed_ms || 0) : `${Math.floor((Number(c.elapsed_ms || 0)) / 1000)}s`;
  398. $('tb-live-detail').textContent = tb.batch_id ? `批次编号 ${tb.batch_id} · 状态 ${stateNames[tbState] || tbState} · 已完成 ${done}/${planned} 轮 · 总用时 ${fmtElapsed}` : '添加 1 组或多组 Profile 后,点击下方按钮立即按序自动重启并执行。';
  399. }
  400. const tbRuns = Array.isArray(tb.runs) ? tb.runs : [];
  401. const histRuns = Array.isArray(c.task_history) ? c.task_history : [];
  402. const seenIds = new Set(tbRuns.map(r => r.run_id).filter(Boolean));
  403. const runs = tbRuns.length
  404. ? histRuns.filter(r => r.run_id && !seenIds.has(r.run_id)).concat(tbRuns).slice(-20)
  405. : histRuns.slice(-20);
  406. if ($('tb-runs-tbody')) {
  407. $('tb-runs-tbody').innerHTML = runs.slice().reverse().map(r => {
  408. const fTag = r.fault_code ? ` <span class="badge error" style="font-size:11px">${esc(r.fault_code)}${r.hang_scene_preserved ? '·保现场' : ''}</span>` : '';
  409. const gTag = r.serial_gap_detected ? ` <span class="badge" style="font-size:11px;background:#fef3c7;color:#92400e">serial_gap</span>` : '';
  410. return `<tr>
  411. <td><code>${esc(r.run_id || '-')}</code></td>
  412. <td><strong>${esc(r.profile_name || '-')}</strong></td>
  413. <td>第 ${esc(r.repeat_index || 1)} / ${esc(r.repeat_total || 1)} 次</td>
  414. <td><code>${esc(r.boot_id || '-')}</code></td>
  415. <td><span class="badge ${r.verdict === 'pass' ? 'connected' : r.verdict === 'fail' ? 'error' : ''}">${esc(r.verdict || r.state || '-')}</span>${fTag}${gTag}</td>
  416. <td><small>${esc(r.log_path || r.log_raw_path || r.summary_path || '运行中 (完成后自动归档 sol.raw & summary.json)')}</small></td>
  417. </tr>`;
  418. }).join('') || '<tr><td colspan="6">尚无批次运行记录</td></tr>';
  419. }
  420. const curSid = api.stationId();
  421. const thPol = c.thermal_policy || {};
  422. if ($('th-policy-badge')) {
  423. const en = thPol.auto_enabled !== false;
  424. $('th-policy-badge').textContent = en ? `自动控温 ${thPol.target_temp_c ?? 70}℃ · ${thPol.require_online !== false ? '开测校验在线' : '允许离线开测'}` : '自动联动已关闭';
  425. $('th-policy-badge').classList.toggle('connected', en);
  426. }
  427. if (thPolStation !== curSid) { thPolStation = curSid; thPolDirty = false; }
  428. if ($('th-policy-auto') && !thPolDirty) {
  429. $('th-policy-auto').checked = thPol.auto_enabled !== false;
  430. if ($('th-policy-target')) $('th-policy-target').value = Number(thPol.target_temp_c ?? 70);
  431. if ($('th-policy-require-online')) $('th-policy-require-online').checked = thPol.require_online !== false;
  432. }
  433. const wd = c.watchdog || {};
  434. if ($('wd-live-badge')) {
  435. const en = wd.enabled !== false;
  436. $('wd-live-badge').textContent = !en ? '已关闭' : wd.fault_code ? `已触发: ${wd.fault_code}` : `启用中 · 双断 ${Math.round((wd.link_lost_timeout_ms || 240000)/1000)}s / 密集阶段 ${Math.round((wd.dense_stage_silence_timeout_ms || 150000)/1000)}s`;
  437. $('wd-live-badge').classList.toggle('connected', en && !wd.fault_code);
  438. $('wd-live-badge').classList.toggle('error', !!wd.fault_code);
  439. }
  440. if (wdFormStation !== curSid) { wdFormStation = curSid; wdDirty = false; }
  441. if ($('wd-enabled') && !wdDirty) {
  442. $('wd-enabled').checked = wd.enabled !== false;
  443. if ($('wd-link-lost-s')) $('wd-link-lost-s').value = Math.round(Number(wd.link_lost_timeout_ms || 240000) / 1000);
  444. if ($('wd-dense-silence-s')) $('wd-dense-silence-s').value = Math.round(Number(wd.dense_stage_silence_timeout_ms || 150000) / 1000);
  445. if ($('wd-amt-silence-s')) $('wd-amt-silence-s').value = Math.round(Number(wd.amt_silence_timeout_ms || 420000) / 1000);
  446. if ($('wd-mt-silence-s')) $('wd-mt-silence-s').value = Math.round(Number(wd.mt_silence_timeout_ms || 480000) / 1000);
  447. if ($('wd-mt-max-dur-s')) $('wd-mt-max-dur-s').value = Math.round(Number(wd.mt_max_duration_ms || 3600000) / 1000);
  448. const act = wd.hang_action || (wd.reboot_on_hang ? 'retry_current_task' : 'stop');
  449. if ($('wd-hang-action')) $('wd-hang-action').value = act;
  450. if ($('tb-hang-action')) $('tb-hang-action').value = act;
  451. if ($('wd-max-hangs')) $('wd-max-hangs').value = Number(wd.max_consecutive_hangs ?? 2);
  452. if ($('tb-max-consecutive-hangs')) $('tb-max-consecutive-hangs').value = Number(wd.max_consecutive_hangs ?? 2);
  453. }
  454. }
  455. async function runWithThermalCheck(method, args, label) {
  456. try {
  457. return await awaitCommand(method, args, label);
  458. } catch (err) {
  459. const isThOffline = err?.code === 'THERMAL_OFFLINE' || /THERMAL_OFFLINE|高温罩未连接/.test(err?.message || '');
  460. if (isThOffline && window.stlUi?.getMode?.() === 'engineering' && !args.skip_thermal_check) {
  461. const ok = await window.stlUi.confirm('高温罩未连接(工程模式可选跳过)', `${err.message}\n\n当前处于工程视图,是否跳过高温罩在线校验并继续启动测试?`, '跳过校验并启动', false);
  462. if (ok) {
  463. return await awaitCommand(method, { ...args, skip_thermal_check: true }, `${label} (跳过温控校验)`);
  464. }
  465. }
  466. throw err;
  467. }
  468. }
  469. function init(services) {
  470. api=services;
  471. $('boot-plan-preset').onchange=()=>{const value=$('boot-plan-preset').value;if(value!=='custom')for(const s of document.querySelectorAll('[data-plan-stage]'))s.value=value==='auto'?'auto':'manual';edit();};
  472. for(const input of document.querySelectorAll('[data-plan-stage],#boot-plan-mt-enabled,#boot-plan-use-in-runs'))input.onchange=edit;
  473. for(const wid of ['wd-enabled','wd-link-lost-s','wd-dense-silence-s','wd-amt-silence-s','wd-mt-silence-s','wd-mt-max-dur-s','wd-hang-action','wd-max-hangs']) {
  474. if ($(wid)) for (const evt of ['input','change']) $(wid).addEventListener(evt, () => { wdDirty = true; });
  475. }
  476. for(const tid of ['th-policy-auto','th-policy-target','th-policy-require-online']) {
  477. if ($(tid)) for (const evt of ['input','change']) $(tid).addEventListener(evt, () => { thPolDirty = true; });
  478. }
  479. api.bind('btn-save-boot-plan',async()=>{const id=api.stationId(), d=current();if(!d)throw new Error('等待配置加载');const plan=clone(d.plan);await awaitCommand('SaveBootPlan',{station_id:id,plan},'保存启动计划');d.dirty=false;formStation='';await window.stlFirmware.refresh();api.status('启动计划已保存,尚未开始执行。');});
  480. api.bind('btn-reload-boot-plan',async()=>{const id=api.stationId();await window.stlFirmware.refresh();drafts.delete(id);formStation='';render();});
  481. for(const [id,action,name] of [['btn-restart-boot-plan','restart','重启并执行已保存计划'],['btn-start-boot-plan','start','从当前阶段执行计划'],['btn-pause-boot-plan','pause','暂停计划并人工接管'],['btn-resume-boot-plan','resume','继续启动计划'],['btn-stop-boot-plan','stop','停止自动执行']]) {
  482. api.bind(id, async () => {
  483. if (['start','restart'].includes(action)) {
  484. api.useLiveConsole?.();
  485. const skipCheck = window.stlUi?.getMode?.() === 'engineering' && !!$('tb-skip-thermal-check')?.checked;
  486. return runWithThermalCheck('ControlBootPlan', { station_id: api.stationId(), action, skip_thermal_check: skipCheck }, name);
  487. }
  488. return api.command('ControlBootPlan', { action }, name);
  489. });
  490. }
  491. $('btn-plan-open-input').onclick=()=>{api.useLiveConsole?.();const x=control(),p=x.firmware?.console_prompt?.kind || x.boot_execution?.current_stage;window.stlNavigation.show(p==='amt'?'amt':['uip','uip1','uip2'].includes(p)?'uip':'testing');};
  492. const buildProfileFromForm = () => {
  493. const c = control(), fw = c.firmware_settings || {}, amtSaved = clone(c.amt_settings || {}), pxeCfg = c.pxe_control?.mt86_cfg || {};
  494. const name = ($('tb-profile-name')?.value || '').trim() || `Profile-${tbSeq++}`;
  495. const repeat = Math.max(0, Number($('tb-profile-repeat')?.value ?? 1));
  496. const targetTempC = Math.max(0, Math.min(254, Number($('tb-profile-temp')?.value ?? 70)));
  497. const amtMode = $('tb-profile-amt-mode')?.value || 'current';
  498. const mtMode = $('tb-profile-mt-mode')?.value || 'current';
  499. const runRmt = $('tb-profile-rmt') ? $('tb-profile-rmt').checked : true;
  500. let runAmt = true;
  501. const amt = { ...amtSaved, test_command: amtSaved.test_command || 'amemdiag 1', exit_after: true };
  502. if (amtMode === 'skip') {
  503. runAmt = false;
  504. amt.action = 'skip';
  505. } else if (amtMode === 'fast24') {
  506. runAmt = true;
  507. amt.action = 'run';
  508. amt.tp_end_step = 0;
  509. amt.only_tests = Array.from({ length: 24 }, (_, i) => i + 1);
  510. amt.overrides = (amt.overrides || []).filter(x => x.name !== 'tp');
  511. } else if (amtMode === 'tp0') {
  512. runAmt = true;
  513. amt.action = 'run';
  514. amt.tp_end_step = 0;
  515. amt.only_tests = [1];
  516. amt.overrides = [{ name: 'tp', value: '0,1,0,0,0,255' }];
  517. } else if (amtMode === 'all24') {
  518. runAmt = true;
  519. amt.action = 'run';
  520. amt.overrides = (amt.overrides || []).filter(x => x.name !== 'tp');
  521. } else {
  522. runAmt = amt.action === 'run';
  523. }
  524. let runMt = true;
  525. const mt = { ...pxeCfg, ...(fw.mt_selection || {}), efi_path: 'FS0:\\EFI\\118.efi', exit_mode: 2 };
  526. if (mtMode === 'skip') {
  527. runMt = false;
  528. } else if (mtMode === 'fast64m') {
  529. mt.tstlist = '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25';
  530. mt.memory_range = 'custom';
  531. mt.addr_lim_lo = '0x10000000';
  532. mt.addr_lim_hi = '0x14000000';
  533. } else if (mtMode === 'test0_64m') {
  534. mt.tstlist = '0';
  535. mt.memory_range = 'custom';
  536. mt.addr_lim_lo = '0x10000000';
  537. mt.addr_lim_hi = '0x14000000';
  538. } else if (mtMode === 'test0_all') {
  539. mt.tstlist = '0';
  540. mt.memory_range = 'all';
  541. }
  542. return {
  543. profile_id: `PRF-${Date.now()}`,
  544. name,
  545. repeat,
  546. target_temp_c: targetTempC,
  547. thermal_auto_enabled: targetTempC > 0,
  548. require_thermal_online: targetTempC > 0,
  549. run_rmt: runRmt,
  550. run_amt: runAmt,
  551. run_mt: runMt,
  552. uip_overrides: clone(fw.uip_overrides || []),
  553. uip_raw_commands: clone(fw.uip_raw_commands || []),
  554. amt,
  555. mt,
  556. };
  557. };
  558. const buildQuickProfile = () => {
  559. const name = ($('qt-name')?.value || '').trim() || `Quick-${Date.now()}`;
  560. const targetTempC = Math.max(0, Math.min(254, Number($('qt-temp')?.value ?? 70)));
  561. const repeat = Math.max(0, Number($('qt-repeat')?.value ?? 1));
  562. const rmtVal = $('qt-rmt')?.value || 'enable';
  563. const uip_overrides = [];
  564. if ($('qt-errhandle')?.checked) uip_overrides.push({ id: 'errhandle', mode: 'override', value: 'disable' });
  565. if (rmtVal !== 'disable') uip_overrides.push({ id: 'rmt', mode: 'override', value: rmtVal });
  566. const dr = ($('qt-datarate')?.value || '').trim();
  567. if (dr) uip_overrides.push({ id: 'datarate', mode: 'override', value: dr });
  568. const vdd = ($('qt-vdd')?.value || '').trim();
  569. if (vdd) uip_overrides.push({ id: 'vol.mem.vdd', mode: 'override', value: vdd });
  570. const vddq = ($('qt-vddq')?.value || '').trim();
  571. if (vddq) uip_overrides.push({ id: 'vol.mem.vddq', mode: 'override', value: vddq });
  572. const vpp = ($('qt-vpp')?.value || '').trim();
  573. if (vpp) uip_overrides.push({ id: 'vol.mem.vpp', mode: 'override', value: vpp });
  574. const amtMode = $('qt-amt')?.value || 'all24';
  575. const amt = { action: amtMode === 'skip' ? 'skip' : 'run', test_command: 'amemdiag 1', exit_after: true, overrides: [] };
  576. if (amtMode === 'fast24') { amt.tp_end_step = 0; amt.only_tests = Array.from({ length: 24 }, (_, i) => i + 1); }
  577. else if (amtMode === 'tp0') { amt.tp_end_step = 0; amt.only_tests = [1]; amt.overrides = [{ name: 'tp', value: '0,1,0,0,0,255' }]; }
  578. const mtRange = $('qt-mt-range')?.value || 'all';
  579. const mt = {
  580. efi_path: 'FS0:\\EFI\\118.efi',
  581. exit_mode: 2,
  582. tstlist: ($('qt-mt-tstlist')?.value || '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25').trim(),
  583. numpass: Math.max(1, Number($('qt-mt-numpass')?.value || 1)),
  584. memory_range: mtRange === 'custom' ? 'custom' : 'all',
  585. ...(mtRange === 'custom' ? { addr_lim_lo: '0x10000000', addr_lim_hi: '0x14000000' } : {}),
  586. };
  587. return {
  588. profile_id: `QPRF-${Date.now()}`,
  589. name,
  590. repeat,
  591. target_temp_c: targetTempC,
  592. thermal_auto_enabled: targetTempC > 0,
  593. require_thermal_online: targetTempC > 0,
  594. run_rmt: rmtVal !== 'disable',
  595. run_amt: amtMode !== 'skip',
  596. run_mt: mtRange !== 'skip',
  597. uip_overrides,
  598. uip_raw_commands: [],
  599. amt,
  600. mt,
  601. };
  602. };
  603. if ($('btn-qt-save-only')) {
  604. api.bind('btn-qt-save-only', async () => {
  605. const profile = buildQuickProfile();
  606. await awaitCommand('SaveProfile', { station_id: api.stationId(), profile }, `快捷保存 Profile ${profile.name}`);
  607. await window.stlFirmware.refresh();
  608. render();
  609. api.status(`快捷任务配置「${profile.name}」已存入 ${api.stationId()} Profile 库。`);
  610. });
  611. }
  612. if ($('btn-qt-dispatch-stations')) {
  613. api.bind('btn-qt-dispatch-stations', async () => {
  614. const targets = [...document.querySelectorAll('.qt-station-cb:checked')].map(c => c.value);
  615. if (!targets.length) throw new Error('请至少勾选 1 个目标工位');
  616. const profile = buildQuickProfile();
  617. const stopOnFail = $('qt-stop-fail') ? $('qt-stop-fail').checked : true;
  618. const hangAction = $('qt-hang-action')?.value || 'stop';
  619. const skipCheck = window.stlUi?.getMode?.() === 'engineering' && !!$('tb-skip-thermal-check')?.checked;
  620. const errs = [];
  621. for (const sid of targets) {
  622. try {
  623. await awaitCommand('SaveProfile', { station_id: sid, profile }, `保存 Profile 至 ${sid}`);
  624. await awaitCommand('ConfigureThermalPolicy', {
  625. station_id: sid,
  626. thermal_policy: { auto_enabled: profile.target_temp_c > 0, target_temp_c: profile.target_temp_c, require_online: profile.target_temp_c > 0 },
  627. }, profile.target_temp_c > 0 ? `配置 ${sid} 目标温度` : `关闭 ${sid} 自动温控`);
  628. await runWithThermalCheck('SubmitTaskBatch', { station_id: sid, profiles: [profile], stop_on_fail: stopOnFail, hang_action: hangAction, reboot_on_hang: hangAction !== 'stop', auto_start: true, skip_thermal_check: skipCheck }, `下发并启动 ${sid}`);
  629. } catch (e) {
  630. errs.push(`${sid}: ${e.message}`);
  631. }
  632. }
  633. await window.stlFirmware.refresh();
  634. render();
  635. if (errs.length) throw new Error(`部分工位下发失败:${errs.join(';')}`);
  636. api.status(`已将「${profile.name}」成功下发并启动至 ${targets.join(', ')}。`);
  637. });
  638. }
  639. if ($('btn-save-thermal-policy')) {
  640. api.bind('btn-save-thermal-policy', async () => {
  641. const thermal_policy = {
  642. auto_enabled: $('th-policy-auto') ? $('th-policy-auto').checked : true,
  643. target_temp_c: Math.max(0, Math.min(254, Number($('th-policy-target')?.value ?? 70))),
  644. require_online: $('th-policy-require-online') ? $('th-policy-require-online').checked : true,
  645. };
  646. await awaitCommand('ConfigureThermalPolicy', { station_id: api.stationId(), thermal_policy }, '保存高温罩闭环联动策略');
  647. thPolDirty = false;
  648. await window.stlFirmware.refresh();
  649. render();
  650. api.status(`高温罩闭环联动策略已保存(自动=${thermal_policy.auto_enabled ? '开' : '关'},目标=${thermal_policy.target_temp_c}℃)。`);
  651. });
  652. }
  653. if ($('btn-tb-save-library')) {
  654. api.bind('btn-tb-save-library', async () => {
  655. const profile = buildProfileFromForm();
  656. await awaitCommand('SaveProfile', { station_id: api.stationId(), profile }, `保存 Profile ${profile.name}`);
  657. await window.stlFirmware.refresh();
  658. if ($('tb-library-status')) $('tb-library-status').textContent = `已存入后端 Profile 库:${profile.name}`;
  659. render();
  660. });
  661. }
  662. if ($('btn-tb-add-profile')) {
  663. $('btn-tb-add-profile').onclick = () => {
  664. const p = buildProfileFromForm();
  665. getTbDraft().push(p);
  666. tbSeq += 1;
  667. if ($('tb-profile-name')) $('tb-profile-name').value = `Profile-${tbSeq}`;
  668. renderTaskBatch(control());
  669. };
  670. }
  671. if ($('btn-tb-clear-draft')) {
  672. $('btn-tb-clear-draft').onclick = () => {
  673. tbDrafts.set(api.stationId(), []);
  674. renderTaskBatch(control());
  675. };
  676. }
  677. if ($('btn-save-watchdog')) {
  678. api.bind('btn-save-watchdog', async () => {
  679. const hangAction = $('wd-hang-action')?.value || 'stop';
  680. const maxHangs = Math.max(0, Number($('wd-max-hangs')?.value ?? 2));
  681. const watchdog = {
  682. enabled: $('wd-enabled') ? $('wd-enabled').checked : true,
  683. link_lost_timeout_s: Math.max(6, Number($('wd-link-lost-s')?.value || 240)),
  684. dense_stage_silence_timeout_s: Math.max(5, Number($('wd-dense-silence-s')?.value || 150)),
  685. amt_silence_timeout_s: Math.max(5, Number($('wd-amt-silence-s')?.value || 420)),
  686. mt_silence_timeout_s: Math.max(5, Number($('wd-mt-silence-s')?.value || 480)),
  687. mt_max_duration_s: Math.max(0, Number($('wd-mt-max-dur-s')?.value || 3600)),
  688. hang_action: hangAction,
  689. reboot_on_hang: hangAction !== 'stop',
  690. max_consecutive_hangs: maxHangs,
  691. reset_consecutive_hangs: true,
  692. };
  693. if ($('tb-hang-action')) $('tb-hang-action').value = hangAction;
  694. if ($('tb-max-consecutive-hangs')) $('tb-max-consecutive-hangs').value = maxHangs;
  695. await awaitCommand('ConfigureWatchdog', { station_id: api.stationId(), watchdog, reset_consecutive_hangs: true }, '保存防卡死与死机恢复参数');
  696. wdDirty = false;
  697. await window.stlFirmware.refresh();
  698. render();
  699. api.status('防卡死超时检测与死机恢复模式已保存并持久化。');
  700. });
  701. }
  702. if ($('btn-tb-submit-start')) {
  703. api.bind('btn-tb-submit-start', async () => {
  704. const list = getTbDraft();
  705. const profiles = list.length ? clone(list) : [buildProfileFromForm()];
  706. const stopOnFail = $('tb-stop-on-fail') ? $('tb-stop-on-fail').checked : true;
  707. const hangAction = $('tb-hang-action')?.value || 'stop';
  708. const maxConsecutiveHangs = Math.max(0, Number($('tb-max-consecutive-hangs')?.value ?? 2));
  709. const skipCheck = window.stlUi?.getMode?.() === 'engineering' && !!$('tb-skip-thermal-check')?.checked;
  710. api.useLiveConsole?.();
  711. await runWithThermalCheck('SubmitTaskBatch', { station_id: api.stationId(), profiles, stop_on_fail: stopOnFail, hang_action: hangAction, reboot_on_hang: hangAction !== 'stop', max_consecutive_hangs: maxConsecutiveHangs, auto_start: true, skip_thermal_check: skipCheck }, '提交并启动多计划测试队列');
  712. await window.stlFirmware.refresh();
  713. render();
  714. });
  715. }
  716. for (const [btnId, act, label] of [['btn-tb-pause', 'pause', '暂停任务队列'], ['btn-tb-resume', 'resume', '继续任务队列'], ['btn-tb-stop', 'stop', '停止任务队列']]) {
  717. if ($(btnId)) api.bind(btnId, async () => {
  718. await api.command('ControlTaskBatch', { station_id: api.stationId(), action: act }, label);
  719. await window.stlFirmware.refresh();
  720. render();
  721. });
  722. }
  723. }
  724. window.stlBootPlan={init,render,awaitCommand,runWithThermalCheck,isDirty:()=>!!current()?.dirty};
  725. })();