fix: use importlib for radar_protocol import; downgrade noisy log levels to DEBUG
Agent-Logs-Url: https://github.com/NawfalMotii79/PLFM_RADAR/sessions/8acb5f68-51fa-4632-a73b-0188b876bed1 Co-authored-by: JJassonn69 <83615043+JJassonn69@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b394f6bc49
commit
56d0ea2883
@@ -13,9 +13,10 @@ and 'SET'...'END' binary settings protocol has been removed — it was
|
|||||||
incompatible with the FPGA register interface.
|
incompatible with the FPGA register interface.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import importlib.util
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
|
import pathlib
|
||||||
|
import sys
|
||||||
from typing import ClassVar
|
from typing import ClassVar
|
||||||
|
|
||||||
from .models import USB_AVAILABLE
|
from .models import USB_AVAILABLE
|
||||||
@@ -24,18 +25,31 @@ if USB_AVAILABLE:
|
|||||||
import usb.core
|
import usb.core
|
||||||
import usb.util
|
import usb.util
|
||||||
|
|
||||||
# Import production protocol layer — single source of truth for FPGA comms
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
def _load_radar_protocol():
|
||||||
from radar_protocol import ( # noqa: F401 — re-exported for v7 package
|
"""Load radar_protocol.py by absolute path without mutating sys.path."""
|
||||||
FT2232HConnection,
|
mod_name = "radar_protocol"
|
||||||
ReplayConnection,
|
if mod_name in sys.modules:
|
||||||
RadarProtocol,
|
return sys.modules[mod_name]
|
||||||
Opcode,
|
proto_path = pathlib.Path(__file__).resolve().parent.parent / "radar_protocol.py"
|
||||||
RadarAcquisition,
|
spec = importlib.util.spec_from_file_location(mod_name, proto_path)
|
||||||
RadarFrame,
|
mod = importlib.util.module_from_spec(spec)
|
||||||
StatusResponse,
|
sys.modules[mod_name] = mod
|
||||||
DataRecorder,
|
spec.loader.exec_module(mod) # type: ignore[union-attr]
|
||||||
)
|
return mod
|
||||||
|
|
||||||
|
|
||||||
|
_rp = _load_radar_protocol()
|
||||||
|
|
||||||
|
# Re-exported for the v7 package — single source of truth for FPGA comms
|
||||||
|
FT2232HConnection = _rp.FT2232HConnection
|
||||||
|
ReplayConnection = _rp.ReplayConnection
|
||||||
|
RadarProtocol = _rp.RadarProtocol
|
||||||
|
Opcode = _rp.Opcode
|
||||||
|
RadarAcquisition = _rp.RadarAcquisition
|
||||||
|
RadarFrame = _rp.RadarFrame
|
||||||
|
StatusResponse = _rp.StatusResponse
|
||||||
|
DataRecorder = _rp.DataRecorder
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class MapBridge(QObject):
|
|||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def logFromJS(self, message: str):
|
def logFromJS(self, message: str):
|
||||||
logger.info(f"[JS] {message}")
|
logger.debug(f"[JS] {message}")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_ready(self) -> bool:
|
def is_ready(self) -> bool:
|
||||||
@@ -578,10 +578,7 @@ document.addEventListener('DOMContentLoaded', function() {{
|
|||||||
return
|
return
|
||||||
data = [t.to_dict() for t in targets]
|
data = [t.to_dict() for t in targets]
|
||||||
js_payload = json.dumps(data).replace("\\", "\\\\").replace("'", "\\'")
|
js_payload = json.dumps(data).replace("\\", "\\\\").replace("'", "\\'")
|
||||||
logger.info(
|
logger.debug("set_targets: %d targets", len(targets))
|
||||||
"set_targets: %d targets, JSON len=%d, first 200 chars: %s",
|
|
||||||
len(targets), len(js_payload), js_payload[:200],
|
|
||||||
)
|
|
||||||
self._status_label.setText(f"{len(targets)} targets tracked")
|
self._status_label.setText(f"{len(targets)} targets tracked")
|
||||||
self._run_js(f"updateTargets('{js_payload}')")
|
self._run_js(f"updateTargets('{js_payload}')")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user