diff --git a/Release/database/XNSim.db b/Release/database/XNSim.db index 031aa43..c852265 100644 Binary files a/Release/database/XNSim.db and b/Release/database/XNSim.db differ diff --git a/XNSimHtml/components/run-simulation.js b/XNSimHtml/components/run-simulation.js index 2c6185f..9e83259 100644 --- a/XNSimHtml/components/run-simulation.js +++ b/XNSimHtml/components/run-simulation.js @@ -519,7 +519,6 @@ class RunSimulation extends HTMLElement { this.eventSource.addEventListener('status', (event) => { try { const data = JSON.parse(event.data); - console.log('收到状态事件:', data); if (data.running === false) { // 仿真已经不存在或已结束 @@ -548,7 +547,6 @@ class RunSimulation extends HTMLElement { this.eventSource.addEventListener('completed', (event) => { try { const data = JSON.parse(event.data); - console.log('收到完成事件:', data); // 添加日志 if (data.success) { this.showSuccess('仿真执行成功'); @@ -567,7 +565,6 @@ class RunSimulation extends HTMLElement { this.eventSource.addEventListener('error', (event) => { try { const data = JSON.parse(event.data); - console.log('收到错误事件:', data); // 添加日志 this.showError(`仿真错误: ${data.message}`); // 重置UI @@ -581,7 +578,6 @@ class RunSimulation extends HTMLElement { this.eventSource.addEventListener('terminated', (event) => { try { const data = JSON.parse(event.data); - console.log('收到终止事件:', data); // 添加日志 this.showMessage(`仿真已终止: ${data.message}`); // 在输出框中添加终止信息 @@ -599,7 +595,6 @@ class RunSimulation extends HTMLElement { this.eventSource.addEventListener('timeout', (event) => { try { const data = JSON.parse(event.data); - console.log('收到超时事件:', data); // 添加日志 this.showError(`仿真超时: ${data.message}`); // 在输出框中添加超时信息 diff --git a/XNSimHtml/components/simulation-monitor.js b/XNSimHtml/components/simulation-monitor.js index d7fcd0d..cf4fcef 100644 --- a/XNSimHtml/components/simulation-monitor.js +++ b/XNSimHtml/components/simulation-monitor.js @@ -63,7 +63,6 @@ class SimulationMonitor extends HTMLElement { const systemResponse = await fetch('/api/system-monitor/system-info'); const systemData = await systemResponse.json(); this.systemInfo = systemData.data; - console.log('系统信息:', this.systemInfo); // 获取线程信息 const threadResponse = await fetch('/api/system-monitor/thread-info'); @@ -79,6 +78,51 @@ class SimulationMonitor extends HTMLElement { } } + getStatusDisplay(status) { + switch (status) { + case 0: + return { text: '未运行', color: '#999999' }; + case 1: + return { text: '运行中', color: '#4CAF50' }; + case 2: + return { text: '暂停中', color: '#FF9800' }; + case 3: + return { text: '错误', color: '#f44336' }; + default: + return { text: '未知状态', color: '#f44336' }; + } + } + + getCoreStatusDisplay(status) { + switch (status) { + case 0: + return { text: '未加载', color: '#999999' }; + case 1: + return { text: '初始化完成', color: '#FFC107' }; + case 2: + return { text: '正常', color: '#4CAF50' }; + case 3: + return { text: '异常', color: '#f44336' }; + default: + return { text: '未知状态', color: '#f44336' }; + } + } + + getThreadStatusDisplay(status) { + switch (status) { + case 0: + return { text: '未运行', color: '#999999' }; + case 1: + return { text: '运行中', color: '#4CAF50' }; + case 2: + return { text: '暂停中', color: '#FF9800' }; + case 3: + return { text: '错误', color: '#f44336' }; + default: + return { text: '未知状态', color: '#f44336' }; + } + } + updateUI() { const input = this.shadowRoot.querySelector('.domain-input'); const startButton = this.shadowRoot.querySelector('.start-button'); @@ -115,27 +159,45 @@ class SimulationMonitor extends HTMLElement { engineInfo.innerHTML = `
- ${engineInfoFields.map(field => ` -
-
${field.label}
-
${this.monitorStatus.isMonitoring && this.systemInfo?.engineInfo ? - (this.systemInfo.engineInfo[field.key] || '未知') : - (field.key === 'status' ? '未运行' : '未知')}
-
- `).join('')} + ${engineInfoFields.map(field => { + let value = '未知'; + let color = '#666'; + + if (this.monitorStatus.isMonitoring && this.systemInfo?.engineInfo) { + if (field.key === 'status') { + const status = this.systemInfo.engineInfo[field.key]; + const statusInfo = this.getStatusDisplay(status); + value = statusInfo.text; + color = statusInfo.color; + } else { + value = this.systemInfo.engineInfo[field.key] || '未知'; + } + } else if (field.key === 'status') { + const statusInfo = this.getStatusDisplay(0); + value = statusInfo.text; + color = statusInfo.color; + } + + return ` +
+
${field.label}
+
${value}
+
+ `; + }).join('')}
`; // 更新核心状态 const coreStatusFields = [ - { label: '主框架状态', key: 'fwStatus' }, - { label: '时间管理器状态', key: 'tmStatus' }, - { label: '事件管理器状态', key: 'emStatus' }, - { label: '环境管理器状态', key: 'sdStatus' }, - { label: '线程管理器状态', key: 'thmStatus' }, - { label: '模型管理器状态', key: 'mmStatus' }, - { label: '服务管理器状态', key: 'smStatus' }, - { label: 'DDS管理器状态', key: 'dmStatus' } + { label: '主框架状态', key: 'fw' }, + { label: '时间管理器状态', key: 'tm' }, + { label: '事件管理器状态', key: 'em' }, + { label: '环境管理器状态', key: 'sd' }, + { label: '线程管理器状态', key: 'thm' }, + { label: '模型管理器状态', key: 'mm' }, + { label: '服务管理器状态', key: 'sm' }, + { label: 'DDS管理器状态', key: 'dm' } ]; // 确保coreStatus元素存在 @@ -147,35 +209,47 @@ class SimulationMonitor extends HTMLElement { // 无论是否有数据,都显示状态项 coreStatus.innerHTML = `
- ${coreStatusFields.map(field => ` -
-
${field.label}
-
${this.monitorStatus.isMonitoring && this.systemInfo?.coreStatus ? - (this.systemInfo.coreStatus[field.key] || '未知') : '未知'}
-
- `).join('')} + ${coreStatusFields.map(field => { + const status = this.monitorStatus.isMonitoring && this.systemInfo?.coreStatus ? + this.systemInfo.coreStatus[field.key] : 0; + const statusInfo = this.getCoreStatusDisplay(status); + return ` +
+
${field.label}
+
${statusInfo.text}
+
+ `; + }).join('')}
`; // 更新线程表格 if (this.monitorStatus.isMonitoring && this.threadInfo && Array.isArray(this.threadInfo)) { - threadTableBody.innerHTML = this.threadInfo.map(thread => ` - - ${thread.name || '未知'} - ${thread.id || '未知'} - ${thread.status || '未知'} - ${thread.priority || '未知'} - ${thread.runCount || '0'} - ${(thread.currentFrequency || 0).toFixed(2)} - ${(thread.setFrequency || 0).toFixed(2)} - ${(thread.currentPeriod || 0).toFixed(2)} - - `).join(''); + threadTableBody.innerHTML = this.threadInfo.map(thread => { + const statusInfo = this.getThreadStatusDisplay(thread.status); + return ` + + ${thread.name || '未知'} + ${thread.id || '未知'} + ${statusInfo.text} + ${thread.priority || '未知'} + ${thread.runCount || '0'} + ${(thread.setFrequency || 0).toFixed(2)} + ${(thread.avgFrequency || 0).toFixed(2)} + ${(thread.maxFrequency || 0).toFixed(2)} + ${(thread.minFrequency || 0).toFixed(2)} + ${(thread.setPeriod || 0).toFixed(2)} + ${(thread.avgPeriod || 0).toFixed(2)} + ${(thread.maxPeriod || 0).toFixed(2)} + ${(thread.minPeriod || 0).toFixed(2)} + + `; + }).join(''); // 更新图表数据 this.updateChartData(); } else { - threadTableBody.innerHTML = '暂无线程信息'; + threadTableBody.innerHTML = '暂无线程信息'; // 清空图表数据 if (this.chart) { this.chart.data.labels = []; @@ -569,9 +643,14 @@ class SimulationMonitor extends HTMLElement { 状态 优先级 运行次数 - 当前频率(Hz) - 设置频率(Hz) - 当前周期(ms) + 设定频率(Hz) + 平均频率(Hz) + 最大频率(Hz) + 最小频率(Hz) + 设定周期(ms) + 平均周期(ms) + 最大周期(ms) + 最小周期(ms)