diff --git a/XNSimHtml/components/simulation-monitor.js b/XNSimHtml/components/simulation-monitor.js
index 67241b2..b3f40a5 100644
--- a/XNSimHtml/components/simulation-monitor.js
+++ b/XNSimHtml/components/simulation-monitor.js
@@ -116,14 +116,9 @@ class SimulationMonitor extends HTMLElement {
// 修改 startMonitoring 方法
async startMonitoring() {
- const domainId = this.shadowRoot.querySelector('.domain-input').value.trim();
- this.domainId = domainId;
-
- // 验证域ID是否为有效的数字字符串
- if (!/^\d+$/.test(domainId)) {
- console.error('域ID必须是有效的数字');
- return;
- }
+ const savedSelection = localStorage.getItem('xnsim-selection');
+ const selection = savedSelection ? JSON.parse(savedSelection) : {};
+ const confID = selection.configurationId;
// 如果已经在监控中,直接返回
if (this.monitorStatus.isMonitoring) {
@@ -132,6 +127,20 @@ class SimulationMonitor extends HTMLElement {
}
try {
+ // 获取构型参数
+ const configResponse = await fetch(`/api/configurations/${confID}`);
+ if (!configResponse.ok) {
+ throw new Error('获取构型参数失败');
+ }
+ const configData = await configResponse.json();
+
+ // 从构型参数中提取域ID
+ const domainId = configData.DomainID;
+ if (!domainId) {
+ throw new Error('构型参数中未找到有效的域ID');
+ }
+ this.domainId = domainId;
+
// 首先检查DDS监控状态
const ddsStatusResponse = await fetch('/api/dds-monitor/status');
const ddsStatusData = await ddsStatusResponse.json();
@@ -276,7 +285,6 @@ class SimulationMonitor extends HTMLElement {
}
updateUI() {
- const input = this.shadowRoot.querySelector('.domain-input');
const startButton = this.shadowRoot.querySelector('.start-button');
const stopButton = this.shadowRoot.querySelector('.stop-button');
const statusDisplay = this.shadowRoot.querySelector('.status-display');
@@ -285,11 +293,9 @@ class SimulationMonitor extends HTMLElement {
const threadTableBody = this.shadowRoot.querySelector('#thread-table-body');
if (this.monitorStatus.isMonitoring) {
- input.disabled = true;
startButton.disabled = true;
stopButton.disabled = false;
} else {
- input.disabled = false;
startButton.disabled = false;
stopButton.disabled = true;
}
@@ -301,82 +307,53 @@ class SimulationMonitor extends HTMLElement {
}
// 更新引擎信息
- const engineInfoFields = [
- { label: '引擎名称', key: 'name' },
- { label: '引擎ID', key: 'id' },
- { label: '引擎状态', key: 'status' },
- { label: '引擎亲和性', key: 'affinity' },
- { label: '线程数', key: 'threadCount' }
- ];
-
- engineInfo.innerHTML = `
-
- ${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 engineInfoItems = engineInfo.querySelectorAll('.status-item');
+ engineInfoItems.forEach(item => {
+ const label = item.querySelector('.status-label').textContent;
+ const valueElement = item.querySelector('.status-value');
+
+ switch(label) {
+ case '引擎名称':
+ valueElement.textContent = this.systemInfo?.engineInfo?.name || 'XNSim';
+ valueElement.style.color = '#666';
+ break;
+ case '引擎ID':
+ valueElement.textContent = this.systemInfo?.engineInfo?.id || '未知';
+ valueElement.style.color = '#666';
+ break;
+ case '引擎状态':
+ const statusInfo = this.getStatusDisplay(this.systemInfo?.engineInfo?.status || 0);
+ valueElement.textContent = statusInfo.text;
+ valueElement.style.color = statusInfo.color;
+ break;
+ case '引擎亲和性':
+ valueElement.textContent = this.systemInfo?.engineInfo?.affinity || '未知';
+ valueElement.style.color = '#666';
+ break;
+ case '线程数':
+ valueElement.textContent = this.systemInfo?.engineInfo?.threadCount || '未知';
+ valueElement.style.color = '#666';
+ break;
+ }
+ });
// 更新核心状态
- const coreStatusFields = [
- { 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元素存在
- if (!coreStatus) {
- console.error('找不到核心状态元素');
- return;
- }
-
- // 无论是否有数据,都显示状态项
- coreStatus.innerHTML = `
-
- ${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('')}
-
- `;
+ const coreStatusItems = coreStatus.querySelectorAll('.status-item');
+ coreStatusItems.forEach(item => {
+ const label = item.querySelector('.status-label').textContent;
+ const valueElement = item.querySelector('.status-value');
+ const key = this.getCoreStatusKey(label);
+
+ if (key) {
+ const status = this.systemInfo?.coreStatus?.[key] || 0;
+ const statusInfo = this.getCoreStatusDisplay(status);
+ valueElement.textContent = statusInfo.text;
+ valueElement.style.color = statusInfo.color;
+ }
+ });
// 更新线程表格
- if (this.monitorStatus.isMonitoring && this.threadInfo && Array.isArray(this.threadInfo)) {
+ if (this.threadInfo && Array.isArray(this.threadInfo)) {
threadTableBody.innerHTML = this.threadInfo.map(thread => {
const statusInfo = this.getThreadStatusDisplay(thread.status);
return `
@@ -411,6 +388,20 @@ class SimulationMonitor extends HTMLElement {
}
}
+ getCoreStatusKey(label) {
+ const keyMap = {
+ '主框架状态': 'fw',
+ '时间管理器状态': 'tm',
+ '事件管理器状态': 'em',
+ '环境管理器状态': 'sd',
+ '线程管理器状态': 'thm',
+ '模型管理器状态': 'mm',
+ '服务管理器状态': 'sm',
+ 'DDS管理器状态': 'dm'
+ };
+ return keyMap[label];
+ }
+
async stopMonitoring() {
try {
const response = await fetch('/api/system-monitor/stop', {
@@ -419,6 +410,30 @@ class SimulationMonitor extends HTMLElement {
const data = await response.json();
if (response.ok) {
this.monitorStatus = data.status;
+ // 立即停止状态检查
+ this.stopStatusCheck();
+ // 清空数据
+ this.systemInfo = {
+ engineInfo: {
+ name: 'XNSim',
+ id: '未知',
+ status: 0,
+ affinity: '未知',
+ threadCount: '未知'
+ },
+ coreStatus: {
+ fw: 0,
+ tm: 0,
+ em: 0,
+ sd: 0,
+ thm: 0,
+ mm: 0,
+ sm: 0,
+ dm: 0
+ }
+ };
+ this.threadInfo = null;
+ // 更新UI
this.updateUI();
} else {
console.error('停止监控失败:', data.error);
@@ -505,19 +520,6 @@ class SimulationMonitor extends HTMLElement {
white-space: nowrap;
}
- .domain-input {
- padding: 8px 12px;
- border: 1px solid #ddd;
- border-radius: 4px;
- font-size: 14px;
- width: 200px;
- }
-
- .domain-input:disabled {
- background-color: #f5f5f5;
- cursor: not-allowed;
- }
-
.control-button {
padding: 8px 16px;
border: none;
@@ -712,10 +714,6 @@ class SimulationMonitor extends HTMLElement {