feat(link): ConnectionHub 统一 WiFi/ECAT/BLE 端点与健康态
各页不再各自读写 dcu_esp_ip / dcu_ecat_adapter:deviceLink 提供 wifiBaseUrl/ecatPost/adapter API,OTA/CAN/motor/ecat_load/lab 走同一入口。 连接灯只覆盖在线布尔,保留调用方语义文案。
This commit is contained in:
+18
-12
@@ -3,6 +3,8 @@
|
||||
*/
|
||||
import { showToast } from './common/toast.js';
|
||||
import { escapeHtml } from './common/utils.js';
|
||||
import { getBaseUrl as hubBaseUrl } from './common/base-url.js';
|
||||
import { deviceLink } from './common/device-link.js';
|
||||
|
||||
var state = { fbTimer: null, fbInFlight: false };
|
||||
|
||||
@@ -52,20 +54,15 @@ function cacheElements() {
|
||||
ids.forEach(function (id) { el[id] = document.getElementById(id); });
|
||||
}
|
||||
|
||||
/** WiFi 端点:优先本页输入框,否则 ConnectionHub 共享 IP(dcu_esp_ip)。 */
|
||||
function getBaseUrl() {
|
||||
var ip = '';
|
||||
if (el.monIp && el.monIp.value) {
|
||||
ip = el.monIp.value.trim();
|
||||
} else if (el.toolIp && el.toolIp.value) {
|
||||
ip = el.toolIp.value.trim();
|
||||
} else {
|
||||
try {
|
||||
var saved = localStorage.getItem('dcu_esp_ip');
|
||||
if (saved && saved.trim()) ip = saved.trim();
|
||||
} catch (_) {}
|
||||
if (el.monIp && el.monIp.value && el.monIp.value.trim()) {
|
||||
return 'http://' + el.monIp.value.trim();
|
||||
}
|
||||
if (!ip) ip = '192.168.31.127';
|
||||
return 'http://' + ip;
|
||||
if (el.toolIp && el.toolIp.value && el.toolIp.value.trim()) {
|
||||
return 'http://' + el.toolIp.value.trim();
|
||||
}
|
||||
return hubBaseUrl();
|
||||
}
|
||||
|
||||
function setConnState(ok, text) {
|
||||
@@ -304,6 +301,15 @@ export function initCanMonitor() {
|
||||
setConnState(false, '未连接');
|
||||
if (!state.bound) {
|
||||
state.bound = true;
|
||||
/* ConnectionHub:只覆盖独立页 monConn 灯的布尔;
|
||||
* 嵌入 can.html 时无 monConnPill,不得碰 fbPollStatus(那是 /can/feedback 自己的轮询态)。 */
|
||||
deviceLink.subscribe(function (s) {
|
||||
if (!el.monConnPill) return;
|
||||
if (!s || !s.ts || (Date.now() - s.ts) >= 5000) return;
|
||||
var on = !!(s.links && s.links.esp32 && s.links.esp32.online);
|
||||
el.monConnPill.className = 'pill ' + (on ? 'online' : 'offline');
|
||||
if (el.monConnIndicator) el.monConnIndicator.className = 'conn-indicator ' + (on ? 'ok' : 'err');
|
||||
});
|
||||
if (el.monTestBtn) el.monTestBtn.addEventListener('click', testConnection);
|
||||
if (el.monIp) el.monIp.addEventListener('change', testConnection);
|
||||
/* 嵌入 can.html 时 IP 与发送台共用 */
|
||||
|
||||
Reference in New Issue
Block a user