mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-07 15:35:10 +00:00
修复必须两次启动edge后端才有节点生成的bug
新增resources报送
This commit is contained in:
@@ -25,7 +25,20 @@ class Registry:
|
||||
self.ResourceCreateFromOuterEasy = self._replace_type_with_class(
|
||||
"ResourceCreateFromOuterEasy", "host_node", f"动作 create_resource"
|
||||
)
|
||||
self.device_type_registry = {
|
||||
self.device_type_registry = {}
|
||||
self.resource_type_registry = {}
|
||||
self._setup_called = False # 跟踪setup是否已调用
|
||||
# 其他状态变量
|
||||
# self.is_host_mode = False # 移至BasicConfig中
|
||||
|
||||
def setup(self):
|
||||
# 检查是否已调用过setup
|
||||
if self._setup_called:
|
||||
logger.critical("[UniLab Registry] setup方法已被调用过,不允许多次调用")
|
||||
return
|
||||
|
||||
from unilabos.app.web.utils.action_utils import get_yaml_from_goal_type
|
||||
self.device_type_registry.update({
|
||||
"host_node": {
|
||||
"description": "UniLabOS主机节点",
|
||||
"class": {
|
||||
@@ -34,7 +47,7 @@ class Registry:
|
||||
"status_types": {},
|
||||
"action_value_mappings": {
|
||||
"create_resource_detailed": {
|
||||
"type": msg_converter_manager.search_class("ResourceCreateFromOuter"),
|
||||
"type": self.ResourceCreateFromOuter,
|
||||
"goal": {
|
||||
"resources": "resources",
|
||||
"device_ids": "device_ids",
|
||||
@@ -43,13 +56,14 @@ class Registry:
|
||||
"other_calling_params": "other_calling_params",
|
||||
},
|
||||
"feedback": {},
|
||||
"result": {
|
||||
"success": "success"
|
||||
},
|
||||
"schema": ros_action_to_json_schema(self.ResourceCreateFromOuter)
|
||||
"result": {"success": "success"},
|
||||
"schema": ros_action_to_json_schema(self.ResourceCreateFromOuter),
|
||||
"goal_default": yaml.safe_load(
|
||||
io.StringIO(get_yaml_from_goal_type(self.ResourceCreateFromOuter.Goal))
|
||||
)
|
||||
},
|
||||
"create_resource": {
|
||||
"type": msg_converter_manager.search_class("ResourceCreateFromOuterEasy"),
|
||||
"type": self.ResourceCreateFromOuterEasy,
|
||||
"goal": {
|
||||
"res_id": "res_id",
|
||||
"class_name": "class_name",
|
||||
@@ -62,35 +76,20 @@ class Registry:
|
||||
"slot_on_deck": "slot_on_deck",
|
||||
},
|
||||
"feedback": {},
|
||||
"result": {
|
||||
"success": "success"
|
||||
},
|
||||
"schema": ros_action_to_json_schema(self.ResourceCreateFromOuterEasy)
|
||||
}
|
||||
}
|
||||
"result": {"success": "success"},
|
||||
"schema": ros_action_to_json_schema(self.ResourceCreateFromOuterEasy),
|
||||
"goal_default": yaml.safe_load(
|
||||
io.StringIO(get_yaml_from_goal_type(self.ResourceCreateFromOuterEasy.Goal))
|
||||
)
|
||||
},
|
||||
},
|
||||
},
|
||||
"schema": {
|
||||
"properties": {},
|
||||
"additionalProperties": False,
|
||||
"type": "object"
|
||||
},
|
||||
"file_path": "/"
|
||||
"icon": "icon_device.webp",
|
||||
"registry_type": "device",
|
||||
"schema": {"properties": {}, "additionalProperties": False, "type": "object"},
|
||||
"file_path": "/",
|
||||
}
|
||||
}
|
||||
self.resource_type_registry = {}
|
||||
self._setup_called = False # 跟踪setup是否已调用
|
||||
# 其他状态变量
|
||||
# self.is_host_mode = False # 移至BasicConfig中
|
||||
|
||||
def setup(self):
|
||||
# 检查是否已调用过setup
|
||||
if self._setup_called:
|
||||
logger.critical("[UniLab Registry] setup方法已被调用过,不允许多次调用")
|
||||
return
|
||||
|
||||
# 标记setup已被调用
|
||||
self._setup_called = True
|
||||
|
||||
})
|
||||
logger.debug(f"[UniLab Registry] ----------Setup----------")
|
||||
self.registry_paths = [Path(path).absolute() for path in self.registry_paths]
|
||||
for i, path in enumerate(self.registry_paths):
|
||||
@@ -100,6 +99,8 @@ class Registry:
|
||||
self.load_device_types(path)
|
||||
self.load_resource_types(path)
|
||||
logger.info("[UniLab Registry] 注册表设置完成")
|
||||
# 标记setup已被调用
|
||||
self._setup_called = True
|
||||
|
||||
def load_resource_types(self, path: os.PathLike):
|
||||
abs_path = Path(path).absolute()
|
||||
@@ -115,6 +116,9 @@ class Registry:
|
||||
resource_info["file_path"] = str(file.absolute()).replace("\\", "/")
|
||||
if "description" not in resource_info:
|
||||
resource_info["description"] = ""
|
||||
if "icon" not in resource_info:
|
||||
resource_info["icon"] = ""
|
||||
resource_info["registry_type"] = "resource"
|
||||
self.resource_type_registry.update(data)
|
||||
logger.debug(
|
||||
f"[UniLab Registry] Resource-{current_resource_number} File-{i+1}/{len(files)} "
|
||||
@@ -164,6 +168,7 @@ class Registry:
|
||||
)
|
||||
current_device_number = len(self.device_type_registry) + 1
|
||||
from unilabos.app.web.utils.action_utils import get_yaml_from_goal_type
|
||||
|
||||
for i, file in enumerate(files):
|
||||
data = yaml.safe_load(open(file, encoding="utf-8"))
|
||||
if data:
|
||||
@@ -173,6 +178,9 @@ class Registry:
|
||||
device_config["file_path"] = str(file.absolute()).replace("\\", "/")
|
||||
if "description" not in device_config:
|
||||
device_config["description"] = ""
|
||||
if "icon" not in device_config:
|
||||
device_config["icon"] = ""
|
||||
device_config["registry_type"] = "device"
|
||||
if "class" in device_config:
|
||||
# 处理状态类型
|
||||
if "status_types" in device_config["class"]:
|
||||
@@ -189,7 +197,9 @@ class Registry:
|
||||
action_config["type"], device_id, f"动作 {action_name}"
|
||||
)
|
||||
if action_config["type"] is not None:
|
||||
action_config["goal_default"] = yaml.safe_load(io.StringIO(get_yaml_from_goal_type(action_config["type"].Goal)))
|
||||
action_config["goal_default"] = yaml.safe_load(
|
||||
io.StringIO(get_yaml_from_goal_type(action_config["type"].Goal))
|
||||
)
|
||||
action_config["schema"] = ros_action_to_json_schema(action_config["type"])
|
||||
else:
|
||||
logger.warning(
|
||||
@@ -212,13 +222,17 @@ class Registry:
|
||||
def obtain_registry_device_info(self):
|
||||
devices = []
|
||||
for device_id, device_info in self.device_type_registry.items():
|
||||
msg = {
|
||||
"id": device_id,
|
||||
**device_info
|
||||
}
|
||||
msg = {"id": device_id, **device_info}
|
||||
devices.append(msg)
|
||||
return devices
|
||||
|
||||
def obtain_registry_resource_info(self):
|
||||
resources = []
|
||||
for resource_id, resource_info in self.resource_type_registry.items():
|
||||
msg = {"id": resource_id, **resource_info}
|
||||
resources.append(msg)
|
||||
return resources
|
||||
|
||||
|
||||
# 全局单例实例
|
||||
lab_registry = Registry()
|
||||
|
||||
Reference in New Issue
Block a user