"""Factory for single-radar Python acquisition services.""" from __future__ import annotations import logging from typing import Protocol from python_app.hardware_full.rph_radar.service import RphRadarService from python_app.hardware_full.librevna_driver.models import SweepResult from python_app.hardware_full.librevna_service import LibreVnaService from python_app.models.dataset_model import ComboKey from python_app.models.run_config_schema import RadarSweepModel, RunConfigModel logger = logging.getLogger(__name__) class SingleRadarService(Protocol): """Common API used by single-radar workflows.""" def open(self) -> None: """Open radar connection.""" def close(self) -> None: """Close radar connection.""" def configure(self, sweep: RadarSweepModel) -> None: """Apply sweep settings.""" def read_device_limits(self) -> dict[str, float | int]: """Read device capability limits.""" ... def prepare_combo(self, combo: ComboKey) -> None: """Select the simulated path or discard buffered data after switching.""" def acquire(self) -> SweepResult: """Acquire one sweep.""" ... def create_single_radar_service(config: RunConfigModel) -> SingleRadarService: """Create the Python service for a non-matrix-radar config.""" if config.is_multi_device: raise RuntimeError( "single-radar service factory does not support matrix radars; " "use create_matrix_radar_service instead" ) model = config.radar.model or RunConfigModel.LIBREVNA_MODEL logger.debug("Creating single-radar service for model=%s (driver_mode=%s)", model, config.radar.driver_mode) if model == RunConfigModel.LIBREVNA_MODEL: if config.radar.driver_mode == "mock": from python_app.hardware_full.point_target_mock_service import PointTargetMockService return PointTargetMockService(config) return LibreVnaService(serial=config.radar.serial or None) if model == RunConfigModel.RPH_RADAR_MODEL: if config.radar.driver_mode != "native": raise RuntimeError("RadioPhotonic radar (RPH) requires radar.driver_mode='native'") return RphRadarService(config) raise RuntimeError(f"Unsupported single-radar model: {model}")