feat: 根据激光测算中心坐标

This commit is contained in:
2026-06-01 17:39:28 +08:00
parent c754dff4ad
commit 801453fbdb
3 changed files with 256 additions and 20 deletions

View File

@@ -1856,7 +1856,39 @@ class NetworkManager:
)
# 立即返回已入队确认
self.safe_enqueue({"result": "log_upload_queued"}, 2)
elif logged_in and msg_type == 201:
if self.logger:
self.logger.info(f"[LASER] cmd201:{body}")
raw_x = body.get("x")
raw_y = body.get("y")
try:
from laser_manager import laser_manager
ix, iy = laser_manager.set_hardcoded_laser_point(
raw_x, raw_y
)
self.safe_enqueue(
{
"cmd": 201,
"result": "laser_point_set",
"x": ix,
"y": iy,
},
2,
)
self.logger.info(
f"[LASER] cmd201 硬编码激光点=({ix}, {iy})"
)
except Exception as e:
self.logger.error(f"[LASER] cmd201 失败: {e}")
self.safe_enqueue(
{
"cmd": 201,
"result": "laser_point_set_failed",
"reason": str(e),
},
2,
)
hardware_manager.start_idle_timer()
# 处理业务指令
elif logged_in and isinstance(body, dict):
inner_cmd = None
@@ -2000,7 +2032,41 @@ class NetworkManager:
self._upload_log_file,
(upload_url, wifi_ssid, wifi_password, include_rotated, max_files, archive_format)
)
elif inner_cmd == 200:
from laser_manager import laser_manager
try:
laser_manager.turn_on_laser()
if self.logger:
self.logger.info("[LASER] cmd200 已发送开激光指令")
except Exception as e:
if self.logger:
self.logger.warning(f"[LASER] cmd200 开激光异常: {e}")
try:
from laser_detector import get_stable_laser_point
time.sleep_ms(500)
result = get_stable_laser_point(timeout_ms=60000)
if result:
x, y = result
self.safe_enqueue({
"cmd": 200,
"result": "laser_detect_ok",
"x": x,
"y": y,
}, 2)
if self.logger:
self.logger.info(f"[LASER] cmd200 检测结果: ({x}, {y})")
else:
self.safe_enqueue({
"cmd": 200,
"result": "laser_detect_failed",
}, 2)
if self.logger:
self.logger.warning("[LASER] cmd200 检测失败")
except Exception as e:
if self.logger:
self.logger.error(f"[LASER] cmd200 检测异常: {e}")
time.sleep_ms(500)
else: # data的结构不是 dict
self.logger.info(f"[NET] body={body}, {time.time()}")
else: