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