mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-17 13:01:12 +00:00
feat: show machine name
fix: host node registry not uploaded
This commit is contained in:
@@ -96,17 +96,19 @@
|
||||
<tr>
|
||||
<th>设备ID</th>
|
||||
<th>命名空间</th>
|
||||
<th>机器名称</th>
|
||||
<th>状态</th>
|
||||
</tr>
|
||||
{% for device_id, device_info in host_node_info.devices.items() %}
|
||||
<tr>
|
||||
<td>{{ device_id }}</td>
|
||||
<td>{{ device_info.namespace }}</td>
|
||||
<td>{{ device_info.machine_name }}</td>
|
||||
<td><span class="status-badge online">{{ "在线" if device_info.is_online else "离线" }}</span></td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr>
|
||||
<td colspan="3" class="empty-state">没有发现已管理的设备</td>
|
||||
<td colspan="4" class="empty-state">没有发现已管理的设备</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
@@ -218,6 +220,7 @@
|
||||
<th>Device ID</th>
|
||||
<th>节点名称</th>
|
||||
<th>命名空间</th>
|
||||
<th>机器名称</th>
|
||||
<th>状态项</th>
|
||||
<th>动作数</th>
|
||||
</tr>
|
||||
@@ -227,6 +230,7 @@
|
||||
<td>{{ device_id }}</td>
|
||||
<td>{{ device_info.node_name }}</td>
|
||||
<td>{{ device_info.namespace }}</td>
|
||||
<td>{{ device_info.machine_name|default("本地") }}</td>
|
||||
<td>{{ ros_node_info.device_topics.get(device_id, {})|length }}</td>
|
||||
<td>{{ ros_node_info.device_actions.get(device_id, {})|length }} <span class="toggle-indicator">▼</span></td>
|
||||
</tr>
|
||||
|
||||
@@ -34,6 +34,7 @@ def get_host_node_info() -> Dict[str, Any]:
|
||||
"namespace": namespace,
|
||||
"is_online": f"{namespace}/{device_id}" in host_node._online_devices,
|
||||
"key": f"{namespace}/{device_id}" if namespace.startswith("/") else f"/{namespace}/{device_id}",
|
||||
"machine_name": host_node.device_machine_names.get(device_id, "未知"),
|
||||
}
|
||||
for device_id, namespace in host_node.devices_names.items()
|
||||
}
|
||||
@@ -41,9 +42,7 @@ def get_host_node_info() -> Dict[str, Any]:
|
||||
host_info["subscribed_topics"] = sorted(list(host_node._subscribed_topics))
|
||||
# 获取动作客户端信息
|
||||
for action_id, client in host_node._action_clients.items():
|
||||
host_info["action_clients"] = {
|
||||
action_id: get_action_info(client, full_name=action_id)
|
||||
}
|
||||
host_info["action_clients"] = {action_id: get_action_info(client, full_name=action_id)}
|
||||
|
||||
# 获取设备状态
|
||||
host_info["device_status"] = host_node.device_status
|
||||
|
||||
@@ -12,6 +12,7 @@ from unilabos.app.web.utils.action_utils import get_action_info
|
||||
# 存储 ROS 节点信息的全局变量
|
||||
ros_node_info = {"online_devices": {}, "device_topics": {}, "device_actions": {}}
|
||||
|
||||
|
||||
def get_ros_node_info() -> Dict[str, Any]:
|
||||
"""获取 ROS 节点信息,包括设备节点、发布的状态和动作
|
||||
|
||||
@@ -35,6 +36,13 @@ def update_ros_node_info() -> Dict[str, Any]:
|
||||
|
||||
try:
|
||||
from unilabos.ros.nodes.base_device_node import registered_devices
|
||||
from unilabos.ros.nodes.presets.host_node import HostNode
|
||||
|
||||
# 尝试获取主机节点实例
|
||||
host_node = HostNode.get_instance(0)
|
||||
device_machine_names = {}
|
||||
if host_node:
|
||||
device_machine_names = host_node.device_machine_names
|
||||
|
||||
for device_id, device_info in registered_devices.items():
|
||||
# 设备基本信息
|
||||
@@ -42,6 +50,7 @@ def update_ros_node_info() -> Dict[str, Any]:
|
||||
"node_name": device_info["node_name"],
|
||||
"namespace": device_info["namespace"],
|
||||
"uuid": device_info["uuid"],
|
||||
"machine_name": device_machine_names.get(device_id, "本地"),
|
||||
}
|
||||
|
||||
# 设备话题(状态)信息
|
||||
@@ -55,10 +64,7 @@ def update_ros_node_info() -> Dict[str, Any]:
|
||||
}
|
||||
|
||||
# 设备动作信息
|
||||
result["device_actions"][device_id] = {
|
||||
k: get_action_info(v, k)
|
||||
for k, v in device_info["actions"].items()
|
||||
}
|
||||
result["device_actions"][device_id] = {k: get_action_info(v, k) for k, v in device_info["actions"].items()}
|
||||
# 更新全局变量
|
||||
ros_node_info = result
|
||||
except Exception as e:
|
||||
|
||||
@@ -14,6 +14,7 @@ from rclpy.callback_groups import ReentrantCallbackGroup
|
||||
from rclpy.service import Service
|
||||
from unique_identifier_msgs.msg import UUID
|
||||
|
||||
from unilabos.registry.registry import lab_registry
|
||||
from unilabos.resources.registry import add_schema
|
||||
from unilabos.ros.initialize_device import initialize_device_from_dict
|
||||
from unilabos.ros.msgs.message_converter import (
|
||||
@@ -97,6 +98,7 @@ class HostNode(BaseROS2DeviceNode):
|
||||
# 创建设备、动作客户端和目标存储
|
||||
self.devices_names: Dict[str, str] = {} # 存储设备名称和命名空间的映射
|
||||
self.devices_instances: Dict[str, ROS2DeviceNode] = {} # 存储设备实例
|
||||
self.device_machine_names: Dict[str, str] = {} # 存储设备ID到机器名称的映射
|
||||
self._action_clients: Dict[str, ActionClient] = {} # 用来存储多个ActionClient实例
|
||||
self._action_value_mappings: Dict[str, Dict] = (
|
||||
{}
|
||||
@@ -113,6 +115,10 @@ class HostNode(BaseROS2DeviceNode):
|
||||
self.device_status = {} # 用来存储设备状态
|
||||
self.device_status_timestamps = {} # 用来存储设备状态最后更新时间
|
||||
|
||||
from unilabos.app.mq import mqtt_client
|
||||
for device_config in lab_registry.obtain_registry_device_info():
|
||||
mqtt_client.publish_registry(device_config["id"], device_config)
|
||||
|
||||
# 首次发现网络中的设备
|
||||
self._discover_devices()
|
||||
|
||||
@@ -255,6 +261,7 @@ class HostNode(BaseROS2DeviceNode):
|
||||
return
|
||||
# noinspection PyProtectedMember
|
||||
self.devices_names[device_id] = d._ros_node.namespace
|
||||
self.device_machine_names[device_id] = "本地"
|
||||
self.devices_instances[device_id] = d
|
||||
# noinspection PyProtectedMember
|
||||
for action_name, action_value_mapping in d._ros_node._action_value_mappings.items():
|
||||
@@ -517,10 +524,17 @@ class HostNode(BaseROS2DeviceNode):
|
||||
self.lab_logger().info(f"[Host Node] Node info update request received: {request}")
|
||||
try:
|
||||
from unilabos.app.mq import mqtt_client
|
||||
|
||||
info = json.loads(request.command)
|
||||
machine_name = info["machine_name"]
|
||||
devices_config = info["devices_config"]
|
||||
registry_config = info["registry_config"]
|
||||
|
||||
# 更新设备机器名称映射
|
||||
for device_id in devices_config.keys():
|
||||
self.device_machine_names[device_id] = machine_name
|
||||
self.lab_logger().debug(f"[Host Node] Updated machine name for device {device_id}: {machine_name}")
|
||||
|
||||
for device_config in registry_config:
|
||||
mqtt_client.publish_registry(device_config["id"], device_config)
|
||||
self.lab_logger().info(f"[Host Node] Node info update: {info}")
|
||||
|
||||
Reference in New Issue
Block a user