mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-10 17:55:12 +00:00
Update recipe.yaml fix: figure_resource use call_async in all service to avoid deadlock fix: prcxi import error 临时兼容错误的driver写法 fix protocol node fix filter protocol bugfixes on organic protocols fix and remove redundant info feat: 新增use_remote_resource参数 fix all protocol_compilers and remove deprecated devices feat: 优化protocol node节点运行日志 fix pumps and liquid_handler handle feat: workstation example add: prcxi res fix: startup slow fix: prcxi_res fix: discard_tips fix: discard_tips error fix: drop_tips not using auto resource select feat: 添加ChinWe设备控制类,支持串口通信和电机控制功能 (#79) feat: add trace log level modify default discovery_interval to 15s fix: working dir error when input config path feat: report publish topic when error fix: workstation handlers and vessel_id parsing Cleanup registry to be easy-understanding (#76) * delete deprecated mock devices * rename categories * combine chromatographic devices * rename rviz simulation nodes * organic virtual devices * parse vessel_id * run registry completion before merge --------- Co-authored-by: Xuwznln <18435084+Xuwznln@users.noreply.github.com>
86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
import argparse
|
|
import time
|
|
|
|
from unilabos.registry.registry import build_registry
|
|
|
|
from unilabos.app.main import load_config_from_file
|
|
from unilabos.utils.log import logger
|
|
|
|
|
|
def register_devices_and_resources(mqtt_client, lab_registry):
|
|
"""
|
|
注册设备和资源到 MQTT
|
|
"""
|
|
logger.info("[UniLab Register] 开始注册设备和资源...")
|
|
|
|
# 注册设备信息
|
|
for device_info in lab_registry.obtain_registry_device_info():
|
|
mqtt_client.publish_registry(device_info["id"], device_info, False)
|
|
logger.debug(f"[UniLab Register] 注册设备: {device_info['id']}")
|
|
|
|
# # 注册资源信息
|
|
# for resource_info in lab_registry.obtain_registry_resource_info():
|
|
# mqtt_client.publish_registry(resource_info["id"], resource_info, False)
|
|
# logger.debug(f"[UniLab Register] 注册资源: {resource_info['id']}")
|
|
|
|
# 注册资源信息 - 使用HTTP方式
|
|
from unilabos.app.web.client import http_client
|
|
|
|
resources_to_register = {}
|
|
for resource_info in lab_registry.obtain_registry_resource_info():
|
|
resources_to_register[resource_info["id"]] = resource_info
|
|
logger.debug(f"[UniLab Register] 准备注册资源: {resource_info['id']}")
|
|
|
|
if resources_to_register:
|
|
start_time = time.time()
|
|
response = http_client.resource_registry(resources_to_register)
|
|
cost_time = time.time() - start_time
|
|
if response.status_code in [200, 201]:
|
|
logger.info(f"[UniLab Register] 成功通过HTTP注册 {len(resources_to_register)} 个资源 {cost_time}ms")
|
|
else:
|
|
logger.error(f"[UniLab Register] HTTP注册资源失败: {response.status_code}, {response.text} {cost_time}ms")
|
|
logger.info("[UniLab Register] 设备和资源注册完成.")
|
|
|
|
|
|
def main():
|
|
"""
|
|
命令行入口函数
|
|
"""
|
|
parser = argparse.ArgumentParser(description="注册设备和资源到 MQTT")
|
|
parser.add_argument(
|
|
"--registry",
|
|
type=str,
|
|
default=None,
|
|
action="append",
|
|
help="注册表路径",
|
|
)
|
|
parser.add_argument(
|
|
"--config",
|
|
type=str,
|
|
default=None,
|
|
help="配置文件路径,支持.py格式的Python配置文件",
|
|
)
|
|
parser.add_argument(
|
|
"--complete_registry",
|
|
action="store_true",
|
|
default=False,
|
|
help="是否补全注册表",
|
|
)
|
|
args = parser.parse_args()
|
|
load_config_from_file(args.config)
|
|
# 构建注册表
|
|
build_registry(args.registry, args.complete_registry, True)
|
|
from unilabos.app.mq import mqtt_client
|
|
|
|
# 连接mqtt
|
|
mqtt_client.start()
|
|
|
|
from unilabos.registry.registry import lab_registry
|
|
|
|
# 注册设备和资源
|
|
register_devices_and_resources(mqtt_client, lab_registry)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|