Rework radar system
This commit is contained in:
@@ -8,7 +8,7 @@ import threading
|
||||
import time
|
||||
from typing import Callable, Protocol, TypeVar
|
||||
|
||||
from .enums import HardwareFamily, PacketType, SyncMode
|
||||
from .enums import HardwareFamily, PacketType
|
||||
from .exceptions import (
|
||||
DeviceDisconnectedError,
|
||||
NackError,
|
||||
@@ -69,9 +69,6 @@ class LibreVNASession:
|
||||
self._device_status: DeviceStatus | None = None
|
||||
self._hardware_family: HardwareFamily = HardwareFamily.UNKNOWN
|
||||
|
||||
self._default_sync_mode = SyncMode.DISABLED
|
||||
self._default_sync_master = False
|
||||
|
||||
@property
|
||||
def is_connected(self) -> bool:
|
||||
"""Return `True` when USB connection is active."""
|
||||
@@ -87,21 +84,6 @@ class LibreVNASession:
|
||||
"""Hardware family inferred from `DeviceInfo` packet."""
|
||||
return self._hardware_family
|
||||
|
||||
@property
|
||||
def default_sync_mode(self) -> SyncMode:
|
||||
"""Default sync mode used by controllers when settings do not override."""
|
||||
return self._default_sync_mode
|
||||
|
||||
@property
|
||||
def default_sync_master(self) -> bool:
|
||||
"""Default sync master flag used by controllers."""
|
||||
return self._default_sync_master
|
||||
|
||||
def set_default_sync(self, mode: SyncMode, master: bool) -> None:
|
||||
"""Set session-level default synchronization settings."""
|
||||
self._default_sync_mode = mode
|
||||
self._default_sync_master = master
|
||||
|
||||
@staticmethod
|
||||
def list_devices() -> list[USBDeviceDescriptor]:
|
||||
"""Enumerate available direct-USB LibreVNA devices."""
|
||||
@@ -241,6 +223,7 @@ class LibreVNASession:
|
||||
timeout_s: float,
|
||||
payload_type: type[TPacketPayload],
|
||||
payload_error: str,
|
||||
progress_timeout_s: float | None = None,
|
||||
) -> list[TPacketPayload]:
|
||||
"""Collect one sweep from point zero, returning points in ascending order.
|
||||
|
||||
@@ -251,11 +234,14 @@ class LibreVNASession:
|
||||
raise ValueError("expected_points must be > 0")
|
||||
|
||||
deadline = time.monotonic() + timeout_s
|
||||
progress_timeout_s = timeout_s if progress_timeout_s is None else progress_timeout_s
|
||||
progress_deadline = time.monotonic() + progress_timeout_s
|
||||
previous_point: int | None = None
|
||||
collected: list[TPacketPayload | None] = [None] * expected_points
|
||||
received = 0
|
||||
|
||||
while received < expected_points:
|
||||
remaining = deadline - time.monotonic()
|
||||
remaining = min(deadline, progress_deadline) - time.monotonic()
|
||||
if remaining <= 0:
|
||||
break
|
||||
|
||||
@@ -270,6 +256,10 @@ class LibreVNASession:
|
||||
f"Received out-of-range point index {point_number}, expected 0..{expected_points - 1}"
|
||||
)
|
||||
|
||||
if point_number != previous_point:
|
||||
progress_deadline = time.monotonic() + progress_timeout_s
|
||||
previous_point = point_number
|
||||
|
||||
if point_number == 0:
|
||||
collected = [None] * expected_points
|
||||
received = 0
|
||||
|
||||
Reference in New Issue
Block a user