重构UCD模块
This commit is contained in:
@@ -65,7 +65,7 @@ class ConnectionController:
|
|||||||
def list_ucd_devices(self) -> list[str]:
|
def list_ucd_devices(self) -> list[str]:
|
||||||
"""返回 SDK 给出的设备显示字符串列表。"""
|
"""返回 SDK 给出的设备显示字符串列表。"""
|
||||||
try:
|
try:
|
||||||
return self._device.raw_controller.search_device() or []
|
return self._device.search_devices()
|
||||||
except Exception as exc: # noqa: BLE001
|
except Exception as exc: # noqa: BLE001
|
||||||
self._log(f"枚举 UCD 设备失败: {exc}", level="error")
|
self._log(f"枚举 UCD 设备失败: {exc}", level="error")
|
||||||
return []
|
return []
|
||||||
@@ -103,11 +103,6 @@ class ConnectionController:
|
|||||||
self._device.close()
|
self._device.close()
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
pass
|
pass
|
||||||
# 旧 controller.status 也要清零,兼容仍读取它的代码
|
|
||||||
try:
|
|
||||||
self._app.ucd.status = False
|
|
||||||
except Exception: # noqa: BLE001
|
|
||||||
pass
|
|
||||||
self._log("UCD连接已断开", level="info")
|
self._log("UCD连接已断开", level="info")
|
||||||
|
|
||||||
# -- CA 连接 -------------------------------------------------
|
# -- CA 连接 -------------------------------------------------
|
||||||
@@ -347,7 +342,7 @@ def update_connection_indicator(self: "PQAutomationApp", indicator, connected):
|
|||||||
def refresh_connection_indicators(self: "PQAutomationApp"):
|
def refresh_connection_indicators(self: "PQAutomationApp"):
|
||||||
"""根据当前设备状态重画 UCD / CA 指示灯。"""
|
"""根据当前设备状态重画 UCD / CA 指示灯。"""
|
||||||
if hasattr(self, "ucd_status_indicator"):
|
if hasattr(self, "ucd_status_indicator"):
|
||||||
ucd_connected = bool(getattr(self.ucd, "status", False))
|
ucd_connected = self.signal_service.is_connected
|
||||||
_draw_connection_indicator(
|
_draw_connection_indicator(
|
||||||
self.ucd_status_indicator,
|
self.ucd_status_indicator,
|
||||||
"green" if ucd_connected else "gray",
|
"green" if ucd_connected else "gray",
|
||||||
|
|||||||
@@ -330,9 +330,7 @@ def send_fix_pattern(self: "PQAutomationApp", mode):
|
|||||||
if mode == "screen_module":
|
if mode == "screen_module":
|
||||||
format_changed = True
|
format_changed = True
|
||||||
else:
|
else:
|
||||||
format_changed = bool(
|
format_changed = bool(self.signal_service.format_changed)
|
||||||
getattr(getattr(self, "ucd", None), "format_changed", True)
|
|
||||||
)
|
|
||||||
|
|
||||||
# 预热提交:prepare_session 仅 stage 了新的 color/timing/pattern,
|
# 预热提交:prepare_session 仅 stage 了新的 color/timing/pattern,
|
||||||
# 真正的 ``pg.apply()`` 要到第一次发图时才发生。提前发送首个 pattern,
|
# 真正的 ``pg.apply()`` 要到第一次发图时才发生。提前发送首个 pattern,
|
||||||
|
|||||||
@@ -24,14 +24,9 @@ class PatternService:
|
|||||||
def _build_apply_config_error(self, test_type):
|
def _build_apply_config_error(self, test_type):
|
||||||
timing = self.app.config.current_test_types.get(test_type, {}).get("timing", "-")
|
timing = self.app.config.current_test_types.get(test_type, {}).get("timing", "-")
|
||||||
detail = ""
|
detail = ""
|
||||||
try:
|
err = self.app.signal_service.last_error
|
||||||
ctrl = getattr(self.app.signal_service.device, "raw_controller", None)
|
if err:
|
||||||
if ctrl is not None:
|
detail = f", detail={err}"
|
||||||
d = getattr(ctrl, "last_error", None)
|
|
||||||
if d:
|
|
||||||
detail = f", detail={d}"
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return f"UCD profile apply_config failed for {test_type}, timing={timing}{detail}"
|
return f"UCD profile apply_config failed for {test_type}, timing={timing}{detail}"
|
||||||
|
|
||||||
def prepare_session(self, mode, *, test_type=None, log_details=False):
|
def prepare_session(self, mode, *, test_type=None, log_details=False):
|
||||||
|
|||||||
@@ -8,14 +8,13 @@
|
|||||||
|
|
||||||
本层不直接 import UniTAP,也不读取 :mod:`tkinter` 变量;
|
本层不直接 import UniTAP,也不读取 :mod:`tkinter` 变量;
|
||||||
所有输入都是显式参数,便于单测。
|
所有输入都是显式参数,便于单测。
|
||||||
|
|
||||||
|
线程安全由 :class:`UCD323Device` 的设备锁统一保证,本层不再重复加锁。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from contextlib import contextmanager
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
import threading
|
|
||||||
|
|
||||||
from app.ucd_domain import (
|
from app.ucd_domain import (
|
||||||
Colorimetry,
|
Colorimetry,
|
||||||
@@ -26,6 +25,7 @@ from app.ucd_domain import (
|
|||||||
SignalFormat,
|
SignalFormat,
|
||||||
TimingSpec,
|
TimingSpec,
|
||||||
UcdError,
|
UcdError,
|
||||||
|
UcdState,
|
||||||
bit_depth_str_to_bpc,
|
bit_depth_str_to_bpc,
|
||||||
color_space_to_colorimetry,
|
color_space_to_colorimetry,
|
||||||
data_range_to_dynamic_range,
|
data_range_to_dynamic_range,
|
||||||
@@ -36,10 +36,6 @@ from drivers.ucd_driver import IUcdDevice
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
_LOCK_TIMEOUT_SECONDS = 8.0
|
|
||||||
_DEBUG_LOCK_TIMEOUT_SECONDS = 0.3
|
|
||||||
_PATTERN_LOCK_TIMEOUT_SECONDS = 0.8
|
|
||||||
|
|
||||||
|
|
||||||
# ─── 视图字符串 → 值对象 转换工具 ────────────────────────────────
|
# ─── 视图字符串 → 值对象 转换工具 ────────────────────────────────
|
||||||
|
|
||||||
@@ -63,6 +59,23 @@ def build_signal_format(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def build_signal_format_from_profile(
|
||||||
|
*,
|
||||||
|
color_space: str,
|
||||||
|
color_format: str,
|
||||||
|
bpc: int,
|
||||||
|
data_range: str = "Full",
|
||||||
|
) -> SignalFormat:
|
||||||
|
"""从 PQConfig test_type 条目组装 :class:`SignalFormat`。"""
|
||||||
|
bit_depth = f"{int(bpc)}bit"
|
||||||
|
return build_signal_format(
|
||||||
|
color_space=color_space,
|
||||||
|
output_format=color_format,
|
||||||
|
bit_depth=bit_depth,
|
||||||
|
data_range=data_range,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def build_timing(timing_str: str) -> TimingSpec:
|
def build_timing(timing_str: str) -> TimingSpec:
|
||||||
"""``"DMT 3840x2160@60Hz"`` → :class:`TimingSpec`。"""
|
"""``"DMT 3840x2160@60Hz"`` → :class:`TimingSpec`。"""
|
||||||
return parse_timing_str(timing_str)
|
return parse_timing_str(timing_str)
|
||||||
@@ -81,63 +94,11 @@ def image_pattern(path: str) -> PatternSpec:
|
|||||||
|
|
||||||
|
|
||||||
class SignalService:
|
class SignalService:
|
||||||
"""协调 SignalFormat / Timing / Pattern 的写入与提交。
|
"""协调 SignalFormat / Timing / Pattern 的写入与提交。"""
|
||||||
|
|
||||||
使用线程锁串行化所有对外的 ``apply_*`` 调用,避免多个测试线程
|
|
||||||
同时操作 UCD 造成 SDK 状态错乱。
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, device: IUcdDevice, bus: EventBus):
|
def __init__(self, device: IUcdDevice, bus: EventBus):
|
||||||
self._dev = device
|
self._dev = device
|
||||||
self._bus = bus
|
self._bus = bus
|
||||||
self._lock = threading.RLock()
|
|
||||||
self._lock_owner_tid: int | None = None
|
|
||||||
self._lock_owner_name: str | None = None
|
|
||||||
|
|
||||||
def _effective_lock_timeout(self, timeout_override: float | None = None) -> float:
|
|
||||||
"""调试模式下缩短锁等待,避免单步时表现为 UI 长时间无响应。"""
|
|
||||||
if timeout_override is not None:
|
|
||||||
return timeout_override
|
|
||||||
if sys.gettrace() is not None:
|
|
||||||
return _DEBUG_LOCK_TIMEOUT_SECONDS
|
|
||||||
return _LOCK_TIMEOUT_SECONDS
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def _acquire_service_lock(self, op_name: str, timeout_override: float | None = None):
|
|
||||||
timeout = self._effective_lock_timeout(timeout_override)
|
|
||||||
current = threading.current_thread()
|
|
||||||
log.info(
|
|
||||||
"SignalService.%s acquiring lock timeout=%.1fs tid=%s thread=%s owner_tid=%s owner_thread=%s",
|
|
||||||
op_name,
|
|
||||||
timeout,
|
|
||||||
threading.get_ident(),
|
|
||||||
current.name,
|
|
||||||
self._lock_owner_tid,
|
|
||||||
self._lock_owner_name,
|
|
||||||
)
|
|
||||||
acquired = self._lock.acquire(timeout=timeout)
|
|
||||||
if not acquired:
|
|
||||||
raise UcdError(
|
|
||||||
"UCD busy: lock timeout in "
|
|
||||||
f"SignalService.{op_name} ({timeout:.1f}s), "
|
|
||||||
f"owner_tid={self._lock_owner_tid}, owner_thread={self._lock_owner_name}"
|
|
||||||
)
|
|
||||||
prev_owner_tid = self._lock_owner_tid
|
|
||||||
prev_owner_name = self._lock_owner_name
|
|
||||||
self._lock_owner_tid = threading.get_ident()
|
|
||||||
self._lock_owner_name = current.name
|
|
||||||
log.info(
|
|
||||||
"SignalService.%s lock acquired tid=%s thread=%s",
|
|
||||||
op_name,
|
|
||||||
self._lock_owner_tid,
|
|
||||||
self._lock_owner_name,
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
self._lock_owner_tid = prev_owner_tid
|
|
||||||
self._lock_owner_name = prev_owner_name
|
|
||||||
self._lock.release()
|
|
||||||
|
|
||||||
# -- 高层接口 ------------------------------------------------
|
# -- 高层接口 ------------------------------------------------
|
||||||
|
|
||||||
@@ -153,7 +114,6 @@ class SignalService:
|
|||||||
Returns:
|
Returns:
|
||||||
``format_changed``——本次相对上一次 :meth:`apply` 是否变化。
|
``format_changed``——本次相对上一次 :meth:`apply` 是否变化。
|
||||||
"""
|
"""
|
||||||
with self._acquire_service_lock("apply"):
|
|
||||||
log.info(
|
log.info(
|
||||||
"SignalService.apply signal=%s timing=%s pattern=%s",
|
"SignalService.apply signal=%s timing=%s pattern=%s",
|
||||||
signal,
|
signal,
|
||||||
@@ -167,7 +127,6 @@ class SignalService:
|
|||||||
|
|
||||||
def send_pattern(self, pattern: PatternSpec) -> None:
|
def send_pattern(self, pattern: PatternSpec) -> None:
|
||||||
"""在已 configure 的信号上仅更新图案后 apply。"""
|
"""在已 configure 的信号上仅更新图案后 apply。"""
|
||||||
with self._acquire_service_lock("send_pattern", _PATTERN_LOCK_TIMEOUT_SECONDS):
|
|
||||||
log.info("SignalService.send_pattern pattern=%s", pattern.kind.value)
|
log.info("SignalService.send_pattern pattern=%s", pattern.kind.value)
|
||||||
self._dev.set_pattern(pattern)
|
self._dev.set_pattern(pattern)
|
||||||
self._dev.apply()
|
self._dev.apply()
|
||||||
@@ -178,12 +137,6 @@ class SignalService:
|
|||||||
def send_image(self, path: str) -> None:
|
def send_image(self, path: str) -> None:
|
||||||
self.send_pattern(image_pattern(path))
|
self.send_pattern(image_pattern(path))
|
||||||
|
|
||||||
# -- 过渡期 API(Phase 2)-----------------------------------
|
|
||||||
# 现有 GUI 回调以"仅更新信号格式、不切换图案"的方式调用
|
|
||||||
# ``ucd.apply_signal_format(color_space=..., color_format=..., bit_depth=...)``。
|
|
||||||
# 新代码统一通过本方法走 SignalService;内部仍委托给底层
|
|
||||||
# controller 的同名旧接口,迁移完成后将替换为纯净实现。
|
|
||||||
|
|
||||||
def update_signal_format(
|
def update_signal_format(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
@@ -194,23 +147,17 @@ class SignalService:
|
|||||||
max_cll: int | None = None,
|
max_cll: int | None = None,
|
||||||
max_fall: int | None = None,
|
max_fall: int | None = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""仅将信号格式 stage 到 SDK(沿用上一次的 timing),不切换图案。
|
"""仅将信号格式提交到 SDK(沿用上一次的 timing),不切换图案。
|
||||||
|
|
||||||
UI 字符串先经域层解析做参数校验;解析失败抛 :class:`UcdConfigError`。
|
UI 字符串先经域层解析做参数校验;解析失败抛 :class:`UcdConfigError`。
|
||||||
"""
|
"""
|
||||||
# 解析仅做校验;当前实现走 raw controller 的旧 API
|
|
||||||
_ = build_signal_format(
|
_ = build_signal_format(
|
||||||
color_space=color_space,
|
color_space=color_space,
|
||||||
output_format=output_format,
|
output_format=output_format,
|
||||||
bit_depth=bit_depth,
|
bit_depth=bit_depth,
|
||||||
data_range=data_range,
|
data_range=data_range,
|
||||||
)
|
)
|
||||||
ctrl = getattr(self._dev, "raw_controller", None)
|
return self._dev.apply_signal_format(
|
||||||
if ctrl is None:
|
|
||||||
raise UcdError("update_signal_format 暂仅支持 UCD323Device")
|
|
||||||
with self._acquire_service_lock("update_signal_format"):
|
|
||||||
return bool(
|
|
||||||
ctrl.apply_signal_format(
|
|
||||||
color_space=color_space,
|
color_space=color_space,
|
||||||
color_format=output_format,
|
color_format=output_format,
|
||||||
bit_depth=bit_depth,
|
bit_depth=bit_depth,
|
||||||
@@ -218,7 +165,6 @@ class SignalService:
|
|||||||
max_cll=max_cll,
|
max_cll=max_cll,
|
||||||
max_fall=max_fall,
|
max_fall=max_fall,
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# -- 透传给上层的查询 ---------------------------------------
|
# -- 透传给上层的查询 ---------------------------------------
|
||||||
|
|
||||||
@@ -232,54 +178,37 @@ class SignalService:
|
|||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
"""UCD 设备是否已打开。供 GUI 做前置校验。"""
|
"""UCD 设备是否已打开。供 GUI 做前置校验。"""
|
||||||
ctrl = getattr(self._dev, "raw_controller", None)
|
return self._dev.state != UcdState.CLOSED
|
||||||
return bool(ctrl and getattr(ctrl, "status", False))
|
|
||||||
|
|
||||||
# -- 过渡期 API(Phase 5):config 驱动的写入 -----------------
|
@property
|
||||||
# 现有 GUI / Service 通过 ``PQConfig`` 对象描述当次测试参数,
|
def format_changed(self) -> bool:
|
||||||
# 由 :class:`UCDController.set_ucd_params` 翻译为色彩/Timing/Pattern。
|
"""最近一次视频模式提交是否相对上次发生变化。"""
|
||||||
# 在配置层重构落地前,这两个方法作为 SignalService 的统一入口,
|
return self._dev.format_changed
|
||||||
# 让上层不再直接接触 ``self.app.ucd``。
|
|
||||||
|
@property
|
||||||
|
def last_error(self) -> str | None:
|
||||||
|
return self._dev.last_error
|
||||||
|
|
||||||
def apply_config(self, config) -> bool:
|
def apply_config(self, config) -> bool:
|
||||||
"""按 :class:`PQConfig` 写入色彩 / Timing / 当前 Pattern(不 apply 输出)。"""
|
"""按 :class:`PQConfig` 写入色彩 / Timing / 当前 Pattern(不 apply 输出)。"""
|
||||||
ctrl = getattr(self._dev, "raw_controller", None)
|
return bool(self._dev.set_ucd_params(config))
|
||||||
if ctrl is None:
|
|
||||||
raise UcdError("apply_config 暂仅支持 UCD323Device")
|
|
||||||
with self._acquire_service_lock("apply_config"):
|
|
||||||
return bool(ctrl.set_ucd_params(config))
|
|
||||||
|
|
||||||
def send_pattern_params(self, params) -> bool:
|
def send_pattern_params(self, params) -> bool:
|
||||||
"""以 ``params`` 更新当前 pattern 的参数并 apply。"""
|
"""以 ``params`` 更新当前 pattern 的参数并 apply。"""
|
||||||
ctrl = getattr(self._dev, "raw_controller", None)
|
return bool(self._dev.send_current_pattern_params(params))
|
||||||
if ctrl is None:
|
|
||||||
raise UcdError("send_pattern_params 暂仅支持 UCD323Device")
|
|
||||||
with self._acquire_service_lock("send_pattern_params"):
|
|
||||||
return bool(ctrl.send_current_pattern_params(params))
|
|
||||||
|
|
||||||
def apply_and_run(self, config, pattern_params) -> bool:
|
def apply_and_run(self, config, pattern_params) -> bool:
|
||||||
"""``set_ucd_params`` + ``set_pattern`` + ``run`` 的复合操作。
|
"""``set_ucd_params`` + ``set_pattern`` + ``run`` 的复合操作。"""
|
||||||
|
return bool(self._dev.apply_config_and_run(config, pattern_params))
|
||||||
服务于 custom_template_panel 单步流程。
|
|
||||||
"""
|
|
||||||
ctrl = getattr(self._dev, "raw_controller", None)
|
|
||||||
if ctrl is None:
|
|
||||||
raise UcdError("apply_and_run 暂仅支持 UCD323Device")
|
|
||||||
with self._acquire_service_lock("apply_and_run"):
|
|
||||||
if not ctrl.set_ucd_params(config):
|
|
||||||
return False
|
|
||||||
if not ctrl.set_pattern(ctrl.current_pattern, pattern_params):
|
|
||||||
return False
|
|
||||||
return bool(ctrl.run())
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"SignalService",
|
"SignalService",
|
||||||
"build_signal_format",
|
"build_signal_format",
|
||||||
|
"build_signal_format_from_profile",
|
||||||
"build_timing",
|
"build_timing",
|
||||||
"solid_rgb_pattern",
|
"solid_rgb_pattern",
|
||||||
"image_pattern",
|
"image_pattern",
|
||||||
# 重导出常用域类型方便上层 import 一次到位
|
|
||||||
"SignalFormat",
|
"SignalFormat",
|
||||||
"TimingSpec",
|
"TimingSpec",
|
||||||
"PatternSpec",
|
"PatternSpec",
|
||||||
|
|||||||
@@ -157,9 +157,118 @@ def _ensure_checkerboard_image(width, height, grid_size, center_white):
|
|||||||
_IMAGE_CACHE[key] = path
|
_IMAGE_CACHE[key] = path
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def _ld_ucd_params_signature(self: "PQAutomationApp") -> tuple:
|
||||||
|
"""Local Dimming 发图前 UCD 参数签名,用于跳过未变化的重复配置。"""
|
||||||
|
test_type = getattr(self.config, "current_test_type", "screen_module")
|
||||||
|
cfg = self.config.current_test_types.get(test_type, {})
|
||||||
|
timing = cfg.get("timing", "")
|
||||||
|
|
||||||
|
if test_type == "screen_module":
|
||||||
|
color_space = (
|
||||||
|
self.screen_module_color_space_var.get()
|
||||||
|
if hasattr(self, "screen_module_color_space_var")
|
||||||
|
else cfg.get("colorimetry", "sRGB")
|
||||||
|
)
|
||||||
|
data_range = (
|
||||||
|
self.screen_module_data_range_var.get()
|
||||||
|
if hasattr(self, "screen_module_data_range_var")
|
||||||
|
else cfg.get("data_range", "Full")
|
||||||
|
)
|
||||||
|
bit_depth = (
|
||||||
|
self.screen_module_bit_depth_var.get()
|
||||||
|
if hasattr(self, "screen_module_bit_depth_var")
|
||||||
|
else f"{int(cfg.get('bpc', 8))}bit"
|
||||||
|
)
|
||||||
|
output_format = (
|
||||||
|
self.screen_module_output_format_var.get()
|
||||||
|
if hasattr(self, "screen_module_output_format_var")
|
||||||
|
else cfg.get("color_format", "RGB")
|
||||||
|
)
|
||||||
|
elif test_type == "sdr_movie":
|
||||||
|
color_space = (
|
||||||
|
self.sdr_color_space_var.get()
|
||||||
|
if hasattr(self, "sdr_color_space_var")
|
||||||
|
else cfg.get("colorimetry", "sRGB")
|
||||||
|
)
|
||||||
|
data_range = (
|
||||||
|
self.sdr_data_range_var.get()
|
||||||
|
if hasattr(self, "sdr_data_range_var")
|
||||||
|
else cfg.get("data_range", "Full")
|
||||||
|
)
|
||||||
|
bit_depth = (
|
||||||
|
self.sdr_bit_depth_var.get()
|
||||||
|
if hasattr(self, "sdr_bit_depth_var")
|
||||||
|
else f"{int(cfg.get('bpc', 8))}bit"
|
||||||
|
)
|
||||||
|
output_format = (
|
||||||
|
self.sdr_output_format_var.get()
|
||||||
|
if hasattr(self, "sdr_output_format_var")
|
||||||
|
else cfg.get("color_format", "RGB")
|
||||||
|
)
|
||||||
|
elif test_type == "hdr_movie":
|
||||||
|
color_space = (
|
||||||
|
self.hdr_color_space_var.get()
|
||||||
|
if hasattr(self, "hdr_color_space_var")
|
||||||
|
else cfg.get("colorimetry", "sRGB")
|
||||||
|
)
|
||||||
|
data_range = (
|
||||||
|
self.hdr_data_range_var.get()
|
||||||
|
if hasattr(self, "hdr_data_range_var")
|
||||||
|
else cfg.get("data_range", "Full")
|
||||||
|
)
|
||||||
|
bit_depth = (
|
||||||
|
self.hdr_bit_depth_var.get()
|
||||||
|
if hasattr(self, "hdr_bit_depth_var")
|
||||||
|
else f"{int(cfg.get('bpc', 8))}bit"
|
||||||
|
)
|
||||||
|
output_format = (
|
||||||
|
self.hdr_output_format_var.get()
|
||||||
|
if hasattr(self, "hdr_output_format_var")
|
||||||
|
else cfg.get("color_format", "RGB")
|
||||||
|
)
|
||||||
|
max_cll = self.hdr_maxcll_var.get() if hasattr(self, "hdr_maxcll_var") else None
|
||||||
|
max_fall = self.hdr_maxfall_var.get() if hasattr(self, "hdr_maxfall_var") else None
|
||||||
|
return (test_type, timing, color_space, data_range, bit_depth, output_format, max_cll, max_fall)
|
||||||
|
elif test_type == "local_dimming":
|
||||||
|
color_space = (
|
||||||
|
self.local_dimming_color_space_var.get()
|
||||||
|
if hasattr(self, "local_dimming_color_space_var")
|
||||||
|
else cfg.get("colorimetry", "sRGB")
|
||||||
|
)
|
||||||
|
data_range = (
|
||||||
|
self.local_dimming_data_range_var.get()
|
||||||
|
if hasattr(self, "local_dimming_data_range_var")
|
||||||
|
else cfg.get("data_range", "Full")
|
||||||
|
)
|
||||||
|
bit_depth = (
|
||||||
|
self.local_dimming_bit_depth_var.get()
|
||||||
|
if hasattr(self, "local_dimming_bit_depth_var")
|
||||||
|
else f"{int(cfg.get('bpc', 8))}bit"
|
||||||
|
)
|
||||||
|
output_format = (
|
||||||
|
self.local_dimming_output_format_var.get()
|
||||||
|
if hasattr(self, "local_dimming_output_format_var")
|
||||||
|
else cfg.get("color_format", "RGB")
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return (test_type,)
|
||||||
|
|
||||||
|
return (test_type, timing, color_space, data_range, bit_depth, output_format)
|
||||||
|
|
||||||
|
|
||||||
|
def invalidate_ld_ucd_params_cache(self: "PQAutomationApp") -> None:
|
||||||
|
"""信号格式或分辨率变更后,强制下次发图重新写入 UCD 参数。"""
|
||||||
|
self._last_ld_ucd_signature = None
|
||||||
|
|
||||||
|
|
||||||
def _apply_ld_ucd_params(self: "PQAutomationApp") -> bool:
|
def _apply_ld_ucd_params(self: "PQAutomationApp") -> bool:
|
||||||
"""发送 Local Dimming 图案前,按当前测试类型写入 UCD 参数。"""
|
"""发送 Local Dimming 图案前,按当前测试类型写入 UCD 参数。"""
|
||||||
test_type = getattr(self.config, "current_test_type", "screen_module")
|
signature = _ld_ucd_params_signature(self)
|
||||||
|
if getattr(self, "_last_ld_ucd_signature", None) == signature:
|
||||||
|
return True
|
||||||
|
|
||||||
|
test_type = signature[0]
|
||||||
cfg = self.config.current_test_types.get(test_type, {})
|
cfg = self.config.current_test_types.get(test_type, {})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -279,6 +388,7 @@ def _apply_ld_ucd_params(self: "PQAutomationApp") -> bool:
|
|||||||
self._dispatch_ui(self.log_gui.log, "Local Dimming UCD 参数设置失败", "error")
|
self._dispatch_ui(self.log_gui.log, "Local Dimming UCD 参数设置失败", "error")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self._last_ld_ucd_signature = signature
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._dispatch_ui(self.log_gui.log, f"Local Dimming UCD 参数设置异常: {e}", "error")
|
self._dispatch_ui(self.log_gui.log, f"Local Dimming UCD 参数设置异常: {e}", "error")
|
||||||
@@ -914,5 +1024,6 @@ class LocalDimmingMixin:
|
|||||||
clear_ld_records = clear_ld_records
|
clear_ld_records = clear_ld_records
|
||||||
save_local_dimming_results = save_local_dimming_results
|
save_local_dimming_results = save_local_dimming_results
|
||||||
plot_ld_instant_peak_curve = plot_ld_instant_peak_curve
|
plot_ld_instant_peak_curve = plot_ld_instant_peak_curve
|
||||||
|
invalidate_ld_ucd_params_cache = invalidate_ld_ucd_params_cache
|
||||||
|
|
||||||
_insert_ld_tree_item = _insert_ld_tree_item
|
_insert_ld_tree_item = _insert_ld_tree_item
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ def show_custom_result_context_menu(self: "PQAutomationApp", event):
|
|||||||
can_single_step = (
|
can_single_step = (
|
||||||
has_selection
|
has_selection
|
||||||
and self.ca is not None
|
and self.ca is not None
|
||||||
and self.ucd is not None
|
and self.signal_service.is_connected
|
||||||
and not self.testing
|
and not self.testing
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
@@ -259,7 +259,7 @@ def start_custom_row_single_step(self: "PQAutomationApp"):
|
|||||||
if not hasattr(self, "custom_result_tree"):
|
if not hasattr(self, "custom_result_tree"):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.ca is None or self.ucd is None:
|
if self.ca is None or not self.signal_service.is_connected:
|
||||||
messagebox.showerror("错误", "请先连接CA410和信号发生器")
|
messagebox.showerror("错误", "请先连接CA410和信号发生器")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -570,7 +570,7 @@ def append_custom_template_result(self: "PQAutomationApp", row_no, result_data):
|
|||||||
def start_custom_template_test(self: "PQAutomationApp"):
|
def start_custom_template_test(self: "PQAutomationApp"):
|
||||||
"""开始客户模板测试(SDR)"""
|
"""开始客户模板测试(SDR)"""
|
||||||
|
|
||||||
if self.ca is None or self.ucd is None:
|
if self.ca is None or not self.signal_service.is_connected:
|
||||||
messagebox.showerror("错误", "请先连接CA410和信号发生器")
|
messagebox.showerror("错误", "请先连接CA410和信号发生器")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -1077,7 +1077,7 @@ def on_screen_module_signal_format_changed(self: "PQAutomationApp", event=None):
|
|||||||
self.save_pq_config()
|
self.save_pq_config()
|
||||||
return
|
return
|
||||||
|
|
||||||
if getattr(self.ucd, "status", False):
|
if self.signal_service.is_connected:
|
||||||
ok = self.signal_service.update_signal_format(
|
ok = self.signal_service.update_signal_format(
|
||||||
color_space=color_space,
|
color_space=color_space,
|
||||||
data_range=data_range,
|
data_range=data_range,
|
||||||
@@ -1121,7 +1121,7 @@ def on_sdr_output_format_changed(self: "PQAutomationApp", event=None):
|
|||||||
self.log_gui.log("警告: 测试进行中,格式更改将在下次测试时生效", level="error")
|
self.log_gui.log("警告: 测试进行中,格式更改将在下次测试时生效", level="error")
|
||||||
return
|
return
|
||||||
|
|
||||||
if getattr(self.ucd, "status", False):
|
if self.signal_service.is_connected:
|
||||||
ok = self.signal_service.update_signal_format(
|
ok = self.signal_service.update_signal_format(
|
||||||
color_space=self.sdr_color_space_var.get(),
|
color_space=self.sdr_color_space_var.get(),
|
||||||
data_range=self.sdr_data_range_var.get(),
|
data_range=self.sdr_data_range_var.get(),
|
||||||
@@ -1145,7 +1145,7 @@ def on_hdr_output_format_changed(self: "PQAutomationApp", event=None):
|
|||||||
self.log_gui.log("警告: 测试进行中,格式更改将在下次测试时生效", level="error")
|
self.log_gui.log("警告: 测试进行中,格式更改将在下次测试时生效", level="error")
|
||||||
return
|
return
|
||||||
|
|
||||||
if getattr(self.ucd, "status", False):
|
if self.signal_service.is_connected:
|
||||||
ok = self.signal_service.update_signal_format(
|
ok = self.signal_service.update_signal_format(
|
||||||
color_space=self.hdr_color_space_var.get(),
|
color_space=self.hdr_color_space_var.get(),
|
||||||
data_range=self.hdr_data_range_var.get(),
|
data_range=self.hdr_data_range_var.get(),
|
||||||
@@ -1169,6 +1169,9 @@ def on_local_dimming_timing_changed(self: "PQAutomationApp", event=None):
|
|||||||
|
|
||||||
self.config.current_test_types.setdefault("local_dimming", {})["timing"] = selected_timing
|
self.config.current_test_types.setdefault("local_dimming", {})["timing"] = selected_timing
|
||||||
|
|
||||||
|
if hasattr(self, "invalidate_ld_ucd_params_cache"):
|
||||||
|
self.invalidate_ld_ucd_params_cache()
|
||||||
|
|
||||||
if self.testing:
|
if self.testing:
|
||||||
self.log_gui.log("警告: 测试进行中,分辨率更改将在下次测试时生效", level="error")
|
self.log_gui.log("警告: 测试进行中,分辨率更改将在下次测试时生效", level="error")
|
||||||
|
|
||||||
@@ -1191,6 +1194,9 @@ def on_local_dimming_signal_format_changed(self: "PQAutomationApp", event=None):
|
|||||||
ld_cfg["bpc"] = UCDEnum.SignalFormat.BitDepth.get_bit_value(bit_depth)
|
ld_cfg["bpc"] = UCDEnum.SignalFormat.BitDepth.get_bit_value(bit_depth)
|
||||||
ld_cfg["data_range"] = data_range
|
ld_cfg["data_range"] = data_range
|
||||||
|
|
||||||
|
if hasattr(self, "invalidate_ld_ucd_params_cache"):
|
||||||
|
self.invalidate_ld_ucd_params_cache()
|
||||||
|
|
||||||
self.log_gui.log(
|
self.log_gui.log(
|
||||||
(
|
(
|
||||||
"Local Dimming 信号格式已更新: "
|
"Local Dimming 信号格式已更新: "
|
||||||
@@ -1205,7 +1211,7 @@ def on_local_dimming_signal_format_changed(self: "PQAutomationApp", event=None):
|
|||||||
self.save_pq_config()
|
self.save_pq_config()
|
||||||
return
|
return
|
||||||
|
|
||||||
if getattr(self.ucd, "status", False):
|
if self.signal_service.is_connected:
|
||||||
ok = self.signal_service.update_signal_format(
|
ok = self.signal_service.update_signal_format(
|
||||||
color_space=color_space,
|
color_space=color_space,
|
||||||
data_range=data_range,
|
data_range=data_range,
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ APP_VERSION = "106.26.0.0"
|
|||||||
|
|
||||||
|
|
||||||
def is_beta_version(version: str = APP_VERSION) -> bool:
|
def is_beta_version(version: str = APP_VERSION) -> bool:
|
||||||
"""版本号第3、4段均为 '0' 时(格式 x.x.0.0)判定为测试版。"""
|
"""版本号第3、4段均为 '0' 时(格式 x.x.0.x)判定为测试版。"""
|
||||||
parts = version.split(".")
|
parts = version.split(".")
|
||||||
if len(parts) >= 4:
|
if len(parts) >= 4:
|
||||||
return parts[2] == "0" and parts[3] == "0"
|
return parts[2] == "0"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,9 +54,10 @@ class UCDController:
|
|||||||
self._close_device_object(temp_dev)
|
self._close_device_object(temp_dev)
|
||||||
raise role_error
|
raise role_error
|
||||||
|
|
||||||
pg, _ = self.get_tx_modules()
|
pg, ag = self.get_tx_modules()
|
||||||
self.timing_manager = pg.timing_manager
|
self.timing_manager = pg.timing_manager
|
||||||
self.color_info = UniTAP.ColorInfo()
|
self.color_info = UniTAP.ColorInfo()
|
||||||
|
self._stop_audio_output(ag)
|
||||||
self.status = True
|
self.status = True
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -82,6 +83,10 @@ class UCDController:
|
|||||||
"""关闭设备"""
|
"""关闭设备"""
|
||||||
try:
|
try:
|
||||||
if self.dev:
|
if self.dev:
|
||||||
|
try:
|
||||||
|
self._stop_audio_output()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
self._close_device_object(self.dev)
|
self._close_device_object(self.dev)
|
||||||
|
|
||||||
self._reset_state()
|
self._reset_state()
|
||||||
@@ -152,6 +157,28 @@ class UCDController:
|
|||||||
return self.role.dptx.pg, self.role.dptx.ag
|
return self.role.dptx.pg, self.role.dptx.ag
|
||||||
raise ValueError(f"不支持的接口类型: {interface}")
|
raise ValueError(f"不支持的接口类型: {interface}")
|
||||||
|
|
||||||
|
def _stop_audio_output(self, ag=None) -> None:
|
||||||
|
"""关闭 HDMI/DP 音频发生器。PQ 测试仅需视频图案,避免电视持续输出测试音。"""
|
||||||
|
if not self.status or not self.role:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
if ag is None:
|
||||||
|
_, ag = self.get_tx_modules()
|
||||||
|
ag.stop_generate()
|
||||||
|
log.info("UCDController._stop_audio_output done")
|
||||||
|
except Exception:
|
||||||
|
log.exception("UCDController._stop_audio_output failed")
|
||||||
|
|
||||||
|
def _apply_pg_output(self, pg) -> bool:
|
||||||
|
"""提交 PG 输出,并确保音频发生器处于关闭状态。"""
|
||||||
|
try:
|
||||||
|
ok = bool(pg.apply())
|
||||||
|
except Exception:
|
||||||
|
log.exception("UCDController._apply_pg_output pg.apply failed")
|
||||||
|
return False
|
||||||
|
self._stop_audio_output()
|
||||||
|
return ok
|
||||||
|
|
||||||
def _resolve_timing(self, pg=None):
|
def _resolve_timing(self, pg=None):
|
||||||
"""优先从 current_timing 读取 timing,必要时回退到 TX 模块。"""
|
"""优先从 current_timing 读取 timing,必要时回退到 TX 模块。"""
|
||||||
if self.current_timing is not None:
|
if self.current_timing is not None:
|
||||||
@@ -253,9 +280,9 @@ class UCDController:
|
|||||||
self.apply_pattern()
|
self.apply_pattern()
|
||||||
pg, _ = self.get_tx_modules()
|
pg, _ = self.get_tx_modules()
|
||||||
log.info("UCDController.run calling pg.apply()")
|
log.info("UCDController.run calling pg.apply()")
|
||||||
pg.apply()
|
ok = self._apply_pg_output(pg)
|
||||||
log.info("UCDController.run done")
|
log.info("UCDController.run done ok=%s", ok)
|
||||||
return True
|
return ok
|
||||||
|
|
||||||
def send_image_pattern(self, image_path):
|
def send_image_pattern(self, image_path):
|
||||||
"""发送图片 Pattern(依赖当前 timing/color_info 状态)。"""
|
"""发送图片 Pattern(依赖当前 timing/color_info 状态)。"""
|
||||||
@@ -264,10 +291,11 @@ class UCDController:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
pg, _ = self.get_tx_modules()
|
pg, _ = self.get_tx_modules()
|
||||||
|
# 仅切换图案,不重复 set_vm;重复 apply video mode 会触发电视 HDMI 重锁发声。
|
||||||
|
if getattr(self, "_last_sent_config", None) is None:
|
||||||
self.apply_video_mode()
|
self.apply_video_mode()
|
||||||
pg.set_pattern(pattern=image_path)
|
pg.set_pattern(pattern=image_path)
|
||||||
pg.apply()
|
return self._apply_pg_output(pg)
|
||||||
return True
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -323,6 +351,9 @@ class UCDController:
|
|||||||
current_dynamic_range = self.color_info.dynamic_range
|
current_dynamic_range = self.color_info.dynamic_range
|
||||||
|
|
||||||
color_format = UCDEnum.ColorInfo.get_color_format(cf)
|
color_format = UCDEnum.ColorInfo.get_color_format(cf)
|
||||||
|
if color_format is None:
|
||||||
|
fmt_key = UCDEnum.SignalFormat.OutputFormat.get_format_key(cf)
|
||||||
|
color_format = UCDEnum.ColorInfo.get_color_format(fmt_key)
|
||||||
if color_format is None:
|
if color_format is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -369,12 +400,17 @@ class UCDController:
|
|||||||
self.color_info.dynamic_range,
|
self.color_info.dynamic_range,
|
||||||
self.color_info.bpc,
|
self.color_info.bpc,
|
||||||
)
|
)
|
||||||
|
if not self.format_changed:
|
||||||
|
log.info("UCDController.set_video_mode skipped pg.set_vm(): config unchanged")
|
||||||
|
return True
|
||||||
|
|
||||||
video_mode = UniTAP.VideoMode(
|
video_mode = UniTAP.VideoMode(
|
||||||
timing=self.current_timing, color_info=self.color_info
|
timing=self.current_timing, color_info=self.color_info
|
||||||
)
|
)
|
||||||
pg, _ = self.get_tx_modules()
|
pg, _ = self.get_tx_modules()
|
||||||
log.info("UCDController.set_video_mode calling pg.set_vm()")
|
log.info("UCDController.set_video_mode calling pg.set_vm()")
|
||||||
pg.set_vm(vm=video_mode)
|
pg.set_vm(vm=video_mode)
|
||||||
|
self._stop_audio_output()
|
||||||
log.info("UCDController.set_video_mode done")
|
log.info("UCDController.set_video_mode done")
|
||||||
self._last_sent_config = current_config
|
self._last_sent_config = current_config
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
唯一暴露给上层的入口为 :class:`IUcdDevice` 抽象接口,以及实现:
|
唯一暴露给上层的入口为 :class:`IUcdDevice` 抽象接口,以及实现:
|
||||||
:class:`UCD323Device`(生产)和 :class:`FakeUcdDevice`(单测)。
|
:class:`UCD323Device`(生产)和 :class:`FakeUcdDevice`(单测)。
|
||||||
|
|
||||||
Phase 1 实现策略
|
实现策略
|
||||||
-----------------
|
--------
|
||||||
为保证零行为变更,:class:`UCD323Device` 当前**内部委托**给已有的
|
:class:`UCD323Device` 对外暴露完整的 :class:`IUcdDevice` 接口;SDK 调用
|
||||||
:class:`drivers.UCD323_Function.UCDController`。后续 Phase 2 会将
|
当前仍委托给 :class:`drivers.UCD323_Function.UCDController`。
|
||||||
SDK 调用直接搬入本模块,届时可删除旧 ``UCDController`` 文件。
|
上层(Service / GUI)**不得**直接访问 ``UCDController``。
|
||||||
|
后续可将 SDK 调用逐步迁入本模块并删除旧文件。
|
||||||
|
|
||||||
文件分区:
|
文件分区:
|
||||||
§1 DeviceInfo / list_devices
|
§1 DeviceInfo / list_devices
|
||||||
@@ -141,6 +142,45 @@ class IUcdDevice(ABC):
|
|||||||
def current_resolution(self) -> tuple[int, int]:
|
def current_resolution(self) -> tuple[int, int]:
|
||||||
"""读取当前 timing 的 (width, height);未连接时返回默认 (3840, 2160)。"""
|
"""读取当前 timing 的 (width, height);未连接时返回默认 (3840, 2160)。"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def search_devices(self) -> list[str]:
|
||||||
|
"""枚举可用设备的 SDK 显示字符串列表。"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def format_changed(self) -> bool:
|
||||||
|
"""最近一次视频模式提交是否相对上次发生变化。"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def last_error(self) -> str | None:
|
||||||
|
"""最近一次配置/应用失败时的错误描述。"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def apply_signal_format(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
color_space: str | None = None,
|
||||||
|
data_range: str | None = None,
|
||||||
|
bit_depth: str | None = None,
|
||||||
|
color_format: str | None = None,
|
||||||
|
max_cll: int | None = None,
|
||||||
|
max_fall: int | None = None,
|
||||||
|
) -> bool:
|
||||||
|
"""仅更新信号格式(沿用当前 timing),不切换图案。"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def set_ucd_params(self, config) -> bool:
|
||||||
|
"""按 PQConfig stage 色彩 / Timing / Pattern 类型(不 apply 输出)。"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def send_current_pattern_params(self, pattern_params) -> bool:
|
||||||
|
"""更新当前 pattern 参数并 apply 到硬件。"""
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def apply_config_and_run(self, config, pattern_params) -> bool:
|
||||||
|
"""set_ucd_params + set_pattern + run 复合操作。"""
|
||||||
|
|
||||||
|
|
||||||
# ─── §3 UCD323Device 真实实现 ────────────────────────────────────
|
# ─── §3 UCD323Device 真实实现 ────────────────────────────────────
|
||||||
|
|
||||||
@@ -211,14 +251,6 @@ class UCD323Device(IUcdDevice):
|
|||||||
def info(self) -> DeviceInfo | None:
|
def info(self) -> DeviceInfo | None:
|
||||||
return self._info
|
return self._info
|
||||||
|
|
||||||
@property
|
|
||||||
def raw_controller(self) -> "UCDController":
|
|
||||||
"""Phase 1 过渡期:给暂未迁移的旧调用点的逃生通道。
|
|
||||||
|
|
||||||
新代码**不**应使用本属性,迁移完成后即可删除。
|
|
||||||
"""
|
|
||||||
return self._controller
|
|
||||||
|
|
||||||
# -- 生命周期 ------------------------------------------------
|
# -- 生命周期 ------------------------------------------------
|
||||||
|
|
||||||
def open(self, info: DeviceInfo, *, interface: Interface = Interface.HDMI) -> None:
|
def open(self, info: DeviceInfo, *, interface: Interface = Interface.HDMI) -> None:
|
||||||
@@ -336,6 +368,74 @@ class UCD323Device(IUcdDevice):
|
|||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
return (3840, 2160)
|
return (3840, 2160)
|
||||||
|
|
||||||
|
def search_devices(self) -> list[str]:
|
||||||
|
try:
|
||||||
|
return self._controller.search_device() or []
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
raise UcdSdkError("枚举 UCD 设备失败") from exc
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_changed(self) -> bool:
|
||||||
|
return bool(getattr(self._controller, "format_changed", True))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_error(self) -> str | None:
|
||||||
|
err = getattr(self._controller, "last_error", None)
|
||||||
|
return str(err) if err else None
|
||||||
|
|
||||||
|
def apply_signal_format(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
color_space: str | None = None,
|
||||||
|
data_range: str | None = None,
|
||||||
|
bit_depth: str | None = None,
|
||||||
|
color_format: str | None = None,
|
||||||
|
max_cll: int | None = None,
|
||||||
|
max_fall: int | None = None,
|
||||||
|
) -> bool:
|
||||||
|
with self._acquire_device_lock("apply_signal_format"):
|
||||||
|
if self._state == UcdState.CLOSED:
|
||||||
|
raise UcdNotConnected("UCD 未连接,无法 apply_signal_format")
|
||||||
|
return bool(
|
||||||
|
self._controller.apply_signal_format(
|
||||||
|
color_space=color_space,
|
||||||
|
data_range=data_range,
|
||||||
|
bit_depth=bit_depth,
|
||||||
|
color_format=color_format,
|
||||||
|
max_cll=max_cll,
|
||||||
|
max_fall=max_fall,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def set_ucd_params(self, config) -> bool:
|
||||||
|
with self._acquire_device_lock("set_ucd_params"):
|
||||||
|
if self._state == UcdState.CLOSED:
|
||||||
|
raise UcdNotConnected("UCD 未连接,无法 set_ucd_params")
|
||||||
|
return bool(self._controller.set_ucd_params(config))
|
||||||
|
|
||||||
|
def send_current_pattern_params(self, pattern_params) -> bool:
|
||||||
|
with self._acquire_device_lock("send_current_pattern_params"):
|
||||||
|
if self._state == UcdState.CLOSED:
|
||||||
|
raise UcdNotConnected("UCD 未连接,无法 send_current_pattern_params")
|
||||||
|
ok = bool(self._controller.send_current_pattern_params(pattern_params))
|
||||||
|
if ok:
|
||||||
|
self._state = UcdState.APPLIED
|
||||||
|
return ok
|
||||||
|
|
||||||
|
def apply_config_and_run(self, config, pattern_params) -> bool:
|
||||||
|
with self._acquire_device_lock("apply_config_and_run"):
|
||||||
|
if self._state == UcdState.CLOSED:
|
||||||
|
raise UcdNotConnected("UCD 未连接,无法 apply_config_and_run")
|
||||||
|
ctrl = self._controller
|
||||||
|
if not ctrl.set_ucd_params(config):
|
||||||
|
return False
|
||||||
|
if not ctrl.set_pattern(ctrl.current_pattern, pattern_params):
|
||||||
|
return False
|
||||||
|
ok = bool(ctrl.run())
|
||||||
|
if ok:
|
||||||
|
self._state = UcdState.APPLIED
|
||||||
|
return ok
|
||||||
|
|
||||||
# -- 内部辅助 ------------------------------------------------
|
# -- 内部辅助 ------------------------------------------------
|
||||||
|
|
||||||
def _apply_dynamic_range(self, signal: SignalFormat) -> None:
|
def _apply_dynamic_range(self, signal: SignalFormat) -> None:
|
||||||
@@ -387,7 +487,10 @@ class UCD323Device(IUcdDevice):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
pg, _ = self._controller.get_tx_modules()
|
pg, _ = self._controller.get_tx_modules()
|
||||||
pg.apply()
|
if not self._controller._apply_pg_output(pg):
|
||||||
|
raise UcdApplyFailed("controller.apply_pg_output 返回 False")
|
||||||
|
except UcdApplyFailed:
|
||||||
|
raise
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise UcdSdkError("pg.apply() 失败") from exc
|
raise UcdSdkError("pg.apply() 失败") from exc
|
||||||
return True
|
return True
|
||||||
@@ -466,8 +569,8 @@ class FakeUcdDevice(IUcdDevice):
|
|||||||
return (signal, timing) != self._last_applied
|
return (signal, timing) != self._last_applied
|
||||||
|
|
||||||
def set_pattern(self, pattern: PatternSpec) -> None:
|
def set_pattern(self, pattern: PatternSpec) -> None:
|
||||||
if self._state not in (UcdState.CONFIGURED, UcdState.APPLIED):
|
if self._state == UcdState.CLOSED:
|
||||||
raise UcdStateError(f"非法状态 {self._state.name}")
|
raise UcdNotConnected()
|
||||||
self.calls.append(("set_pattern", pattern))
|
self.calls.append(("set_pattern", pattern))
|
||||||
self._pattern = pattern
|
self._pattern = pattern
|
||||||
|
|
||||||
@@ -488,6 +591,44 @@ class FakeUcdDevice(IUcdDevice):
|
|||||||
return (3840, 2160)
|
return (3840, 2160)
|
||||||
return (self._timing.width, self._timing.height)
|
return (self._timing.width, self._timing.height)
|
||||||
|
|
||||||
|
def search_devices(self) -> list[str]:
|
||||||
|
return []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_changed(self) -> bool:
|
||||||
|
return self._last_applied is None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_error(self) -> str | None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def apply_signal_format(self, **kwargs) -> bool:
|
||||||
|
if self._state == UcdState.CLOSED:
|
||||||
|
raise UcdNotConnected()
|
||||||
|
self.calls.append(("apply_signal_format", kwargs))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def set_ucd_params(self, config) -> bool:
|
||||||
|
if self._state == UcdState.CLOSED:
|
||||||
|
raise UcdNotConnected()
|
||||||
|
self.calls.append(("set_ucd_params", config))
|
||||||
|
self._state = UcdState.OPENED
|
||||||
|
return True
|
||||||
|
|
||||||
|
def send_current_pattern_params(self, pattern_params) -> bool:
|
||||||
|
if self._state == UcdState.CLOSED:
|
||||||
|
raise UcdNotConnected()
|
||||||
|
self.calls.append(("send_current_pattern_params", pattern_params))
|
||||||
|
self._state = UcdState.APPLIED
|
||||||
|
return True
|
||||||
|
|
||||||
|
def apply_config_and_run(self, config, pattern_params) -> bool:
|
||||||
|
if self._state == UcdState.CLOSED:
|
||||||
|
raise UcdNotConnected()
|
||||||
|
self.calls.append(("apply_config_and_run", config, pattern_params))
|
||||||
|
self._state = UcdState.APPLIED
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"DeviceInfo",
|
"DeviceInfo",
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import traceback
|
|||||||
import matplotlib
|
import matplotlib
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from app_version import APP_NAME, APP_VERSION, get_app_title
|
from app_version import APP_NAME, APP_VERSION, get_app_title
|
||||||
from drivers.UCD323_Function import UCDController
|
|
||||||
from drivers.ucd_driver import UCD323Device
|
from drivers.ucd_driver import UCD323Device
|
||||||
from app.ucd_domain import EventBus
|
from app.ucd_domain import EventBus
|
||||||
from app.services.ucd_service import SignalService
|
from app.services.ucd_service import SignalService
|
||||||
@@ -100,13 +99,10 @@ class PQAutomationApp(
|
|||||||
|
|
||||||
# 初始化设备连接状态
|
# 初始化设备连接状态
|
||||||
self.ca = None # CA410色度计
|
self.ca = None # CA410色度计
|
||||||
self.ucd = UCDController() # 信号发生器(旧接口,过渡期保留)
|
|
||||||
|
|
||||||
# 新架构:EventBus + 设备抽象 + 服务层。
|
# UCD:EventBus + 设备抽象 + 服务层;上层统一走 signal_service / ucd_device。
|
||||||
# UCD323Device 内部委托 self.ucd,保证零行为变更;
|
|
||||||
# 新代码统一走 self.signal_service。
|
|
||||||
self.event_bus = EventBus()
|
self.event_bus = EventBus()
|
||||||
self.ucd_device = UCD323Device(self.event_bus, self.ucd)
|
self.ucd_device = UCD323Device(self.event_bus)
|
||||||
self.signal_service = SignalService(self.ucd_device, self.event_bus)
|
self.signal_service = SignalService(self.ucd_device, self.event_bus)
|
||||||
|
|
||||||
# 连接控制器:统一管理 CA/UCD 生命周期。
|
# 连接控制器:统一管理 CA/UCD 生命周期。
|
||||||
@@ -467,7 +463,7 @@ class PQAutomationApp(
|
|||||||
|
|
||||||
def _check_start_preconditions(self):
|
def _check_start_preconditions(self):
|
||||||
"""检查开始测试前置条件:设备连接 & 未在测试中。"""
|
"""检查开始测试前置条件:设备连接 & 未在测试中。"""
|
||||||
if self.ca is None or self.ucd is None:
|
if self.ca is None or not self.signal_service.is_connected:
|
||||||
messagebox.showerror("错误", "请先连接CA410和信号发生器")
|
messagebox.showerror("错误", "请先连接CA410和信号发生器")
|
||||||
return False
|
return False
|
||||||
if self.testing:
|
if self.testing:
|
||||||
@@ -808,8 +804,8 @@ class PQAutomationApp(
|
|||||||
print("配置已清理,不再保存")
|
print("配置已清理,不再保存")
|
||||||
|
|
||||||
# 断开设备连接
|
# 断开设备连接
|
||||||
if self.ucd.status:
|
if self.signal_service.is_connected:
|
||||||
self.ucd.close()
|
self.connection.disconnect_ucd()
|
||||||
if self.ca is not None:
|
if self.ca is not None:
|
||||||
self.ca.close()
|
self.ca.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user