Refactor radar system

This commit is contained in:
Ayzen
2026-10-05 16:46:28 +03:00
parent 515049d2ed
commit 8f097dfa2e
179 changed files with 8212 additions and 6676 deletions
+15 -8
View File
@@ -4,6 +4,7 @@ from __future__ import annotations
from dataclasses import dataclass
import logging
import math
logger = logging.getLogger(__name__)
@@ -121,17 +122,13 @@ def _build_frequency_grid(model: GeneratorSweepConfig) -> tuple[int, ...]:
if has_step:
_validate_positive_int(step_hz, "generator_sweep.step_hz")
frequencies: list[int] = []
current_hz = start_hz
while current_hz < stop_hz:
frequencies.append(current_hz)
current_hz += step_hz
if not frequencies or frequencies[-1] != stop_hz:
frequencies.append(stop_hz)
return tuple(frequencies)
_require((stop_hz - start_hz + step_hz - 1) // step_hz + 1 <= 1_000_000,
"generator sweep grid must not exceed 1000000 frequencies")
return (*range(start_hz, stop_hz, step_hz), stop_hz)
_validate_positive_int(points, "generator_sweep.points")
_require(points >= 2, "generator_sweep.points must be >= 2 when start_hz != stop_hz")
_require(points <= 1_000_000, "generator sweep grid must not exceed 1000000 frequencies")
span_hz = stop_hz - start_hz
frequencies = tuple(
int(round(start_hz + (span_hz * index) / float(points - 1)))
@@ -148,6 +145,16 @@ def _build_frequency_grid(model: GeneratorSweepConfig) -> tuple[int, ...]:
def resolve_generator_sweep_config(model: GeneratorSweepConfig) -> ResolvedGeneratorSweepConfig:
"""Validate and resolve runtime configuration for generator sweep mode."""
for name in ("points", "settle_timeout_ms", "post_lock_delay_us", "pwm_frequency_hz",
"sweep_start_pin", "curr_step_pin", "pwm_pin", "curr_step_initial_level",
"strict_protocol_version", "port"):
value = getattr(model, name)
_require(type(value) is int, f"generator_sweep.{name} must be an integer")
for name in ("start_hz", "stop_hz", "step_hz", "hold_time_ms", "status_poll_ms", "power_dbm", "pwm_duty_cycle"):
value = getattr(model, name)
_require(type(value) in (int, float) and math.isfinite(value),
f"generator_sweep.{name} must be a finite number")
_require(model.points >= 0 and model.step_hz >= 0, "generator_sweep points and step_hz must be >= 0")
log_level = _resolve_log_level(model.log_level)
frequencies_hz = _build_frequency_grid(model)
hold_time_ms = float(model.hold_time_ms)