Compare commits
8 Commits
59990b0e7c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a8c9d5fa0d | |||
| 9c0e879aec | |||
| f49582536b | |||
| 557590f2bf | |||
| 5fdb42b5ed | |||
| 2ca70d556b | |||
| 7cd464bc6a | |||
|
|
906428fc3b |
@@ -91,6 +91,12 @@ USE_TZ = True
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
CORS_ALLOW_ALL_ORIGINS = True
|
||||
CORS_EXPOSE_HEADERS = [
|
||||
'X-Blitz-Frame-Seq',
|
||||
'X-Blitz-Backend-Received-Unix-Ns',
|
||||
'X-Blitz-Frame-Hash',
|
||||
'X-Blitz-BSide-Capture-To-Send-Ms',
|
||||
]
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import json
|
||||
import struct
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
import threading
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -19,8 +22,10 @@ VIDEO_TRAILER_ENDIANNESS = "little"
|
||||
VIDEO_TRAILER_TIMESTAMP_UNIT = "ms"
|
||||
VIDEO_TRAILER_TIMESTAMP_MULTIPLIER_NS = 1_000_000
|
||||
VIDEO_TRAILER_TIMESTAMP_MAX_SKEW_NS = 7 * 24 * 60 * 60 * 1_000_000_000
|
||||
VIDEO_TRAILER_COORDINATE_FORMAT = "float32 little-endian"
|
||||
VIDEO_TRAILER_STRUCT = struct.Struct("<Qff")
|
||||
VIDEO_TRAILER_COORDINATE_FORMAT = (
|
||||
"uint64 timestamp_ms + float64 latitude + float64 longitude + uint32 capture_to_send_ms (little-endian)"
|
||||
)
|
||||
VIDEO_TRAILER_STRUCT = struct.Struct("<QddI")
|
||||
VIDEO_TRAILER_BYTES = VIDEO_TRAILER_STRUCT.size
|
||||
|
||||
CONTROL_PACKET = struct.Struct("<6f")
|
||||
@@ -29,6 +34,9 @@ CONTROL_SOURCE_NATIVE_UDP = "native_udp"
|
||||
CONTROL_SOURCE_WEB = "web"
|
||||
CONTROL_SOURCE_PRIORITY = (CONTROL_SOURCE_NATIVE_UDP, CONTROL_SOURCE_WEB)
|
||||
ZERO_CONTROL_PAYLOAD = CONTROL_PACKET.pack(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
|
||||
BLITZ_RUN_DIR_RAW = os.getenv("BLITZ_RUN_DIR", "").strip()
|
||||
BLITZ_RUN_DIR = Path(BLITZ_RUN_DIR_RAW).expanduser() if BLITZ_RUN_DIR_RAW else None
|
||||
BLITZ_INSTANCE_ID = os.getenv("BLITZ_INSTANCE_ID", "").strip() or f"backend-{os.getpid()}"
|
||||
|
||||
|
||||
def utc_iso_now() -> str:
|
||||
@@ -96,6 +104,7 @@ def load_omnisocket_config() -> dict[str, Any]:
|
||||
transport_cfg = dict(config.get("transport", {}))
|
||||
video_receiver_cfg = dict(config.get("video_receiver", {}))
|
||||
control_sender_cfg = dict(config.get("control_sender", {}))
|
||||
control_ack_receiver_cfg = dict(config.get("control_ack_receiver", {}))
|
||||
control_ingress_cfg = dict(config.get("control_ingress", {}))
|
||||
video_sender_cfg = dict(config.get("video_sender", {}))
|
||||
telemetry_receiver_cfg = dict(config.get("telemetry_receiver", {}))
|
||||
@@ -137,6 +146,15 @@ def load_omnisocket_config() -> dict[str, Any]:
|
||||
str(control_sender_cfg.get("target_peer", "peer-b-ctrl")),
|
||||
)
|
||||
|
||||
control_ack_receiver_cfg["peer_id"] = os.getenv(
|
||||
"OMNISOCKET_CONTROL_ACK_RECEIVER_PEER_ID",
|
||||
str(control_ack_receiver_cfg.get("peer_id", "peer-a-ctrl-ack")),
|
||||
)
|
||||
control_ack_receiver_cfg["expected_sender"] = os.getenv(
|
||||
"OMNISOCKET_CONTROL_ACK_EXPECTED_SENDER",
|
||||
str(control_ack_receiver_cfg.get("expected_sender", "peer-b-ctrl-ack")),
|
||||
)
|
||||
|
||||
video_sender_cfg["peer_id"] = os.getenv(
|
||||
"OMNISOCKET_VIDEO_SENDER_PEER_ID",
|
||||
str(video_sender_cfg.get("peer_id", "peer-b-video")),
|
||||
@@ -190,12 +208,131 @@ def load_omnisocket_config() -> dict[str, Any]:
|
||||
"transport": transport_cfg,
|
||||
"video_receiver": video_receiver_cfg,
|
||||
"control_sender": control_sender_cfg,
|
||||
"control_ack_receiver": control_ack_receiver_cfg,
|
||||
"control_ingress": control_ingress_cfg,
|
||||
"video_sender": video_sender_cfg,
|
||||
"telemetry_receiver": telemetry_receiver_cfg,
|
||||
}
|
||||
|
||||
|
||||
class JsonlRunLogger:
|
||||
def __init__(self, stem_env: str, default_stem: str) -> None:
|
||||
explicit_path = os.getenv(stem_env, "").strip()
|
||||
self._path = Path(explicit_path) if explicit_path else (
|
||||
BLITZ_RUN_DIR / f"{default_stem}.{BLITZ_INSTANCE_ID}.jsonl" if BLITZ_RUN_DIR is not None else None
|
||||
)
|
||||
self._lock = threading.Lock()
|
||||
self._file = None
|
||||
self._buffered_bytes = 0
|
||||
self._current_bytes = 0
|
||||
self._flush_bytes = self._positive_int_env("BLITZ_JSONL_FLUSH_BYTES", 262144)
|
||||
self._flush_interval_ms = self._positive_int_env("BLITZ_JSONL_FLUSH_INTERVAL_MS", 1000)
|
||||
self._max_bytes = self._positive_int_env("BLITZ_JSONL_ROTATE_BYTES", 134217728)
|
||||
self._max_files = self._positive_int_env("BLITZ_JSONL_ROTATE_FILES", 8)
|
||||
self._last_flush_monotonic_ms = self._now_ms()
|
||||
|
||||
if self._path is not None:
|
||||
try:
|
||||
self._path.parent.mkdir(parents=True, exist_ok=True)
|
||||
self._file = self._path.open("a", encoding="utf-8")
|
||||
self._current_bytes = self._path.stat().st_size if self._path.exists() else 0
|
||||
except OSError:
|
||||
self._file = None
|
||||
|
||||
@property
|
||||
def path(self) -> str | None:
|
||||
return str(self._path) if self._path is not None else None
|
||||
|
||||
@property
|
||||
def enabled(self) -> bool:
|
||||
return self._file is not None
|
||||
|
||||
def write(self, payload: dict[str, Any]) -> None:
|
||||
if self._file is None:
|
||||
return
|
||||
line = json.dumps(payload, ensure_ascii=False, separators=(",", ":"))
|
||||
line_bytes = len(line.encode("utf-8")) + 1
|
||||
with self._lock:
|
||||
if self._file is None:
|
||||
return
|
||||
try:
|
||||
self._file.write(line)
|
||||
self._file.write("\n")
|
||||
self._buffered_bytes += line_bytes
|
||||
self._current_bytes += line_bytes
|
||||
now_ms = self._now_ms()
|
||||
if (
|
||||
self._buffered_bytes >= self._flush_bytes
|
||||
or (self._flush_interval_ms > 0 and now_ms - self._last_flush_monotonic_ms >= self._flush_interval_ms)
|
||||
):
|
||||
self._flush_locked(now_ms)
|
||||
if self._max_bytes > 0 and self._max_files > 0 and self._current_bytes >= self._max_bytes:
|
||||
self._rotate_locked()
|
||||
except OSError:
|
||||
if self._file is not None:
|
||||
try:
|
||||
self._file.close()
|
||||
except OSError:
|
||||
pass
|
||||
self._file = None
|
||||
|
||||
def close(self) -> None:
|
||||
with self._lock:
|
||||
if self._file is not None:
|
||||
try:
|
||||
self._flush_locked(self._now_ms())
|
||||
except OSError:
|
||||
pass
|
||||
self._file.close()
|
||||
self._file = None
|
||||
|
||||
def _flush_locked(self, now_ms: int) -> None:
|
||||
if self._file is None:
|
||||
return
|
||||
self._file.flush()
|
||||
self._buffered_bytes = 0
|
||||
self._last_flush_monotonic_ms = now_ms
|
||||
|
||||
def _rotate_locked(self) -> None:
|
||||
if self._path is None or self._file is None or self._max_files <= 0:
|
||||
return
|
||||
self._flush_locked(self._now_ms())
|
||||
self._file.close()
|
||||
self._file = None
|
||||
|
||||
oldest = self._path.with_name(f"{self._path.name}.{self._max_files}")
|
||||
if oldest.exists():
|
||||
oldest.unlink()
|
||||
|
||||
for index in range(self._max_files - 1, 0, -1):
|
||||
src = self._path.with_name(f"{self._path.name}.{index}")
|
||||
if src.exists():
|
||||
dst = self._path.with_name(f"{self._path.name}.{index + 1}")
|
||||
src.replace(dst)
|
||||
|
||||
if self._path.exists():
|
||||
rotated = self._path.with_name(f"{self._path.name}.1")
|
||||
self._path.replace(rotated)
|
||||
|
||||
self._file = self._path.open("a", encoding="utf-8")
|
||||
self._buffered_bytes = 0
|
||||
self._current_bytes = self._path.stat().st_size if self._path.exists() else 0
|
||||
self._last_flush_monotonic_ms = self._now_ms()
|
||||
|
||||
@staticmethod
|
||||
def _now_ms() -> int:
|
||||
return int(time.monotonic() * 1000)
|
||||
|
||||
@staticmethod
|
||||
def _positive_int_env(name: str, default: int) -> int:
|
||||
raw = os.getenv(name, "").strip()
|
||||
try:
|
||||
value = int(raw)
|
||||
except ValueError:
|
||||
return default
|
||||
return value if value > 0 else default
|
||||
|
||||
|
||||
def parse_host_port(bind_addr: str) -> tuple[str, int]:
|
||||
host, port_text = bind_addr.rsplit(":", 1)
|
||||
host = host.strip() or "127.0.0.1"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
@@ -10,6 +11,7 @@ from .common import (
|
||||
CONTROL_PACKET_SIZE,
|
||||
CONTROL_SOURCE_NATIVE_UDP,
|
||||
CONTROL_SOURCE_PRIORITY,
|
||||
JsonlRunLogger,
|
||||
ZERO_CONTROL_PAYLOAD,
|
||||
WORKSPACE_ROOT,
|
||||
load_omnisocket_config,
|
||||
@@ -18,9 +20,139 @@ from .common import (
|
||||
from .video import safe_kcp_stats
|
||||
|
||||
|
||||
class OmniSocketControlSender:
|
||||
def _payload_preview(payload: bytes, limit: int = 160) -> str:
|
||||
if not payload:
|
||||
return ""
|
||||
preview = payload[:limit].decode("utf-8", errors="replace")
|
||||
if len(payload) > limit:
|
||||
return f"{preview}..."
|
||||
return preview
|
||||
|
||||
|
||||
class ControlAckTracker:
|
||||
def __init__(self) -> None:
|
||||
self._lock = threading.Lock()
|
||||
self._event_logger = JsonlRunLogger("BLITZ_A_CONTROL_EVENTS_LOG_PATH", "a-control-events")
|
||||
self._ack_logger = JsonlRunLogger("BLITZ_A_CONTROL_ACKS_LOG_PATH", "a-control-acks")
|
||||
self._pending: dict[int, dict[str, Any]] = {}
|
||||
self._latest_estimate: dict[str, Any] = {
|
||||
"ack_available": False,
|
||||
"updated_at": None,
|
||||
"received_mono_ns": 0,
|
||||
"control_loop_rtt_ms": None,
|
||||
"b_recv_to_persist_ms": None,
|
||||
"control_oneway_network_est_ms": None,
|
||||
"control_to_persist_est_ms": None,
|
||||
"sample_reason": None,
|
||||
}
|
||||
|
||||
def register_send(
|
||||
self,
|
||||
*,
|
||||
message_id: int,
|
||||
issued_at_unix_ns: int,
|
||||
issued_at_mono_ns: int,
|
||||
source: str,
|
||||
payload: bytes,
|
||||
send_call_latency_us: int,
|
||||
) -> None:
|
||||
event = {
|
||||
"ts_unix_nano": issued_at_unix_ns,
|
||||
"message_id": message_id,
|
||||
"issued_at_unix_ns": issued_at_unix_ns,
|
||||
"issued_at_mono_ns": issued_at_mono_ns,
|
||||
"source": source,
|
||||
"command_signature": payload.hex(),
|
||||
"payload_size": len(payload),
|
||||
"send_call_latency_us": send_call_latency_us,
|
||||
}
|
||||
with self._lock:
|
||||
self._pending[message_id] = event
|
||||
self._prune_locked(issued_at_mono_ns)
|
||||
self._event_logger.write(event)
|
||||
|
||||
def handle_ack(self, ack_payload: dict[str, Any], received_unix_ns: int, received_mono_ns: int) -> str:
|
||||
try:
|
||||
message_id = int(ack_payload["message_id"])
|
||||
except (KeyError, TypeError, ValueError):
|
||||
return "invalid_message_id"
|
||||
|
||||
with self._lock:
|
||||
event = self._pending.pop(message_id, None)
|
||||
self._prune_locked(received_mono_ns)
|
||||
|
||||
if event is None:
|
||||
return "pending_missing"
|
||||
|
||||
try:
|
||||
control_loop_rtt_ms = round((received_unix_ns - int(event["issued_at_unix_ns"])) / 1_000_000.0, 3)
|
||||
b_recv_to_persist_ms = round(float(ack_payload.get("b_recv_to_persist_us", 0)) / 1000.0, 3)
|
||||
except (TypeError, ValueError):
|
||||
return "invalid_timing"
|
||||
|
||||
control_oneway_network_est_ms = round(max(0.0, (control_loop_rtt_ms - b_recv_to_persist_ms) / 2.0), 3)
|
||||
control_to_persist_est_ms = round(control_oneway_network_est_ms + b_recv_to_persist_ms, 3)
|
||||
ack_record = {
|
||||
"ts_unix_nano": received_unix_ns,
|
||||
"received_unix_ns": received_unix_ns,
|
||||
"received_mono_ns": received_mono_ns,
|
||||
"message_id": message_id,
|
||||
"ack_phase": str(ack_payload.get("ack_phase") or "persist_end"),
|
||||
"sample_reason": str(ack_payload.get("sample_reason") or ""),
|
||||
"b_recv_to_persist_us": ack_payload.get("b_recv_to_persist_us"),
|
||||
"unix_send_ok": bool(ack_payload.get("unix_send_ok", False)),
|
||||
"issued_at_unix_ns": event["issued_at_unix_ns"],
|
||||
"source": event["source"],
|
||||
"control_loop_rtt_ms": control_loop_rtt_ms,
|
||||
"b_recv_to_persist_ms": b_recv_to_persist_ms,
|
||||
"control_oneway_network_est_ms": control_oneway_network_est_ms,
|
||||
"control_to_persist_est_ms": control_to_persist_est_ms,
|
||||
}
|
||||
self._ack_logger.write(ack_record)
|
||||
with self._lock:
|
||||
self._latest_estimate = {
|
||||
"ack_available": True,
|
||||
"updated_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(received_unix_ns / 1_000_000_000)),
|
||||
"received_mono_ns": received_mono_ns,
|
||||
"control_loop_rtt_ms": control_loop_rtt_ms,
|
||||
"b_recv_to_persist_ms": b_recv_to_persist_ms,
|
||||
"control_oneway_network_est_ms": control_oneway_network_est_ms,
|
||||
"control_to_persist_est_ms": control_to_persist_est_ms,
|
||||
"sample_reason": ack_record["sample_reason"],
|
||||
}
|
||||
return "accepted"
|
||||
|
||||
def get_latest_estimate(self) -> dict[str, Any]:
|
||||
with self._lock:
|
||||
estimate = dict(self._latest_estimate)
|
||||
if int(estimate.get("received_mono_ns", 0) or 0) > 0 and time.monotonic_ns() - int(estimate["received_mono_ns"]) > 10_000_000_000:
|
||||
estimate["ack_available"] = False
|
||||
estimate["control_loop_rtt_ms"] = None
|
||||
estimate["b_recv_to_persist_ms"] = None
|
||||
estimate["control_oneway_network_est_ms"] = None
|
||||
estimate["control_to_persist_est_ms"] = None
|
||||
estimate["sample_reason"] = None
|
||||
estimate.pop("received_mono_ns", None)
|
||||
return estimate
|
||||
|
||||
def close(self) -> None:
|
||||
self._event_logger.close()
|
||||
self._ack_logger.close()
|
||||
|
||||
def _prune_locked(self, now_mono_ns: int) -> None:
|
||||
stale_ids = [
|
||||
message_id
|
||||
for message_id, event in self._pending.items()
|
||||
if now_mono_ns - int(event.get("issued_at_mono_ns", 0)) > 60_000_000_000
|
||||
]
|
||||
for message_id in stale_ids:
|
||||
self._pending.pop(message_id, None)
|
||||
|
||||
|
||||
class OmniSocketControlSender:
|
||||
def __init__(self, ack_tracker: ControlAckTracker) -> None:
|
||||
self._lock = threading.Lock()
|
||||
self._ack_tracker = ack_tracker
|
||||
self._session = None
|
||||
self._session_cls = None
|
||||
self._msg_type_error = None
|
||||
@@ -36,6 +168,7 @@ class OmniSocketControlSender:
|
||||
self._reconnect_count = 0
|
||||
self._ever_connected = False
|
||||
self._registered = False
|
||||
self._supports_send_with_id = False
|
||||
self._load_backend()
|
||||
|
||||
def _load_backend(self) -> None:
|
||||
@@ -92,6 +225,7 @@ class OmniSocketControlSender:
|
||||
self._started = True
|
||||
self._last_error = ""
|
||||
self._registered = bool(dict(session.stats()).get("registered", 0))
|
||||
self._supports_send_with_id = hasattr(session, "send_with_id")
|
||||
if self._ever_connected:
|
||||
self._reconnect_count += 1
|
||||
else:
|
||||
@@ -111,25 +245,35 @@ class OmniSocketControlSender:
|
||||
self._session = None
|
||||
self._started = False
|
||||
self._registered = False
|
||||
self._supports_send_with_id = False
|
||||
if current is not None:
|
||||
try:
|
||||
current.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def send_payload(self, payload: bytes) -> None:
|
||||
def send_payload(self, payload: bytes, *, source: str) -> None:
|
||||
if len(payload) != CONTROL_PACKET_SIZE:
|
||||
raise ValueError(f"expected {CONTROL_PACKET_SIZE} bytes, got {len(payload)}")
|
||||
self.ensure_started()
|
||||
with self._lock:
|
||||
session = self._session
|
||||
target_peer = self._target_peer
|
||||
supports_send_with_id = self._supports_send_with_id
|
||||
|
||||
if session is None:
|
||||
raise RuntimeError("control session is not available")
|
||||
|
||||
try:
|
||||
session.send(to=target_peer, data=payload)
|
||||
issued_at_unix_ns = time.time_ns()
|
||||
issued_at_mono_ns = time.monotonic_ns()
|
||||
send_started_ns = time.perf_counter_ns()
|
||||
message_id: int | None = None
|
||||
if supports_send_with_id:
|
||||
message_id = int(session.send_with_id(to=target_peer, data=payload))
|
||||
else:
|
||||
session.send(to=target_peer, data=payload)
|
||||
send_call_latency_us = max(0, int((time.perf_counter_ns() - send_started_ns) / 1000))
|
||||
except Exception as error:
|
||||
with self._lock:
|
||||
self._send_errors += 1
|
||||
@@ -137,13 +281,22 @@ class OmniSocketControlSender:
|
||||
self._reset_session(session)
|
||||
raise
|
||||
|
||||
if message_id is not None:
|
||||
self._ack_tracker.register_send(
|
||||
message_id=message_id,
|
||||
issued_at_unix_ns=issued_at_unix_ns,
|
||||
issued_at_mono_ns=issued_at_mono_ns,
|
||||
source=source,
|
||||
payload=payload,
|
||||
send_call_latency_us=send_call_latency_us,
|
||||
)
|
||||
with self._lock:
|
||||
self._send_count += 1
|
||||
|
||||
def send_zero_burst(self, count: int) -> None:
|
||||
for _ in range(max(0, count)):
|
||||
try:
|
||||
self.send_payload(ZERO_CONTROL_PAYLOAD)
|
||||
self.send_payload(ZERO_CONTROL_PAYLOAD, source="zero_burst")
|
||||
except Exception:
|
||||
return
|
||||
|
||||
@@ -236,6 +389,250 @@ class OmniSocketControlSender:
|
||||
drain_thread.join(timeout=0.5)
|
||||
|
||||
|
||||
class OmniSocketControlAckReceiver:
|
||||
def __init__(self, ack_tracker: ControlAckTracker) -> None:
|
||||
self._ack_tracker = ack_tracker
|
||||
self._lock = threading.Lock()
|
||||
self._thread: threading.Thread | None = None
|
||||
self._started = False
|
||||
self._session = None
|
||||
self._session_cls = None
|
||||
self._msg_type_text = None
|
||||
self._msg_type_error = None
|
||||
self._control_defaults: dict[str, Any] = {}
|
||||
self._closing = threading.Event()
|
||||
self._last_error = ""
|
||||
self._last_server_error = ""
|
||||
self._registered = False
|
||||
self._reconnect_count = 0
|
||||
self._ever_connected = False
|
||||
self._received_messages = 0
|
||||
self._received_bytes = 0
|
||||
self._accepted_count = 0
|
||||
self._pending_missing_count = 0
|
||||
self._invalid_message_id_count = 0
|
||||
self._invalid_timing_count = 0
|
||||
self._unexpected_message_type_count = 0
|
||||
self._unexpected_sender_count = 0
|
||||
self._sender_mismatch_accepted_count = 0
|
||||
self._payload_decode_errors = 0
|
||||
self._last_msg_type: int | None = None
|
||||
self._last_from_peer = ""
|
||||
self._last_payload_preview = ""
|
||||
self._last_ack_result = ""
|
||||
self._load_backend()
|
||||
|
||||
def _load_backend(self) -> None:
|
||||
try:
|
||||
self._import_backend()
|
||||
except Exception as error: # pragma: no cover
|
||||
self._last_error = f"omnisocket import failed: {error}"
|
||||
|
||||
def _import_backend(self) -> None:
|
||||
try:
|
||||
from omnisocket import CONTROL_DEFAULTS, MSG_TYPE_ERROR, MSG_TYPE_TEXT, Session # type: ignore
|
||||
except ImportError:
|
||||
python_dir = WORKSPACE_ROOT / "OmniSocketGo" / "python"
|
||||
if python_dir.exists():
|
||||
sys.path.insert(0, str(python_dir))
|
||||
from omnisocket import CONTROL_DEFAULTS, MSG_TYPE_ERROR, MSG_TYPE_TEXT, Session # type: ignore
|
||||
|
||||
self._session_cls = Session
|
||||
self._msg_type_text = MSG_TYPE_TEXT
|
||||
self._msg_type_error = MSG_TYPE_ERROR
|
||||
self._control_defaults = dict(CONTROL_DEFAULTS)
|
||||
|
||||
def _connect_session(self):
|
||||
assert self._session_cls is not None
|
||||
|
||||
config = load_omnisocket_config()
|
||||
transport_cfg = config.get("transport", {})
|
||||
ack_cfg = config.get("control_ack_receiver", {})
|
||||
|
||||
session = self._session_cls()
|
||||
session.connect(
|
||||
server_addr=str(transport_cfg.get("server_addr", "127.0.0.1:10909")),
|
||||
peer_id=str(ack_cfg.get("peer_id", "peer-a-ctrl-ack")),
|
||||
relay_via=str(transport_cfg.get("relay_via", "")),
|
||||
bind_ip=str(transport_cfg.get("bind_ip", "")),
|
||||
bind_device=str(transport_cfg.get("bind_device", "")),
|
||||
**self._control_defaults,
|
||||
)
|
||||
return session, str(ack_cfg.get("expected_sender", "peer-b-ctrl-ack"))
|
||||
|
||||
def ensure_started(self) -> None:
|
||||
if self._session_cls is None:
|
||||
return
|
||||
with self._lock:
|
||||
if self._started or self._closing.is_set():
|
||||
return
|
||||
self._started = True
|
||||
self._thread = threading.Thread(target=self._run, name="omnisocket-control-ack", daemon=True)
|
||||
self._thread.start()
|
||||
|
||||
@staticmethod
|
||||
def _looks_like_control_ack(ack_payload: Any) -> bool:
|
||||
if not isinstance(ack_payload, dict):
|
||||
return False
|
||||
if "message_id" not in ack_payload:
|
||||
return False
|
||||
return any(field in ack_payload for field in ("ack_phase", "b_recv_to_persist_us", "unix_send_ok", "sample_reason"))
|
||||
|
||||
@staticmethod
|
||||
def _sender_matches(expected_sender: str, from_peer: str) -> bool:
|
||||
normalized_expected = expected_sender.strip()
|
||||
normalized_from = from_peer.strip()
|
||||
if not normalized_expected:
|
||||
return True
|
||||
return normalized_from == normalized_expected
|
||||
|
||||
def _run(self) -> None:
|
||||
while not self._closing.is_set():
|
||||
expected_sender = ""
|
||||
try:
|
||||
session, expected_sender = self._connect_session()
|
||||
with self._lock:
|
||||
self._session = session
|
||||
self._last_error = ""
|
||||
if self._ever_connected:
|
||||
self._reconnect_count += 1
|
||||
else:
|
||||
self._ever_connected = True
|
||||
|
||||
while not self._closing.is_set():
|
||||
result = session.recv(timeout_ms=1000)
|
||||
if result is None:
|
||||
try:
|
||||
session_stats = dict(session.stats())
|
||||
except Exception:
|
||||
session_stats = {}
|
||||
with self._lock:
|
||||
self._registered = bool(session_stats.get("registered", 0))
|
||||
self._last_server_error = str(session_stats.get("last_server_error", "") or "")
|
||||
continue
|
||||
from_peer, msg_type, payload = result
|
||||
with self._lock:
|
||||
self._received_messages += 1
|
||||
self._received_bytes += len(payload)
|
||||
self._last_from_peer = str(from_peer or "")
|
||||
self._last_msg_type = int(msg_type)
|
||||
self._last_payload_preview = _payload_preview(payload)
|
||||
try:
|
||||
session_stats = dict(session.stats())
|
||||
except Exception:
|
||||
session_stats = {}
|
||||
self._registered = bool(session_stats.get("registered", 0))
|
||||
self._last_server_error = str(session_stats.get("last_server_error", "") or "")
|
||||
if msg_type == self._msg_type_error:
|
||||
with self._lock:
|
||||
self._last_error = f"ack session error from {from_peer}: {payload.decode('utf-8', errors='replace')}"
|
||||
self._last_ack_result = "server_error"
|
||||
continue
|
||||
if msg_type != self._msg_type_text:
|
||||
with self._lock:
|
||||
self._unexpected_message_type_count += 1
|
||||
self._last_ack_result = "unexpected_message_type"
|
||||
continue
|
||||
try:
|
||||
ack_payload = json.loads(payload.decode("utf-8"))
|
||||
except (UnicodeDecodeError, json.JSONDecodeError):
|
||||
with self._lock:
|
||||
self._payload_decode_errors += 1
|
||||
self._last_ack_result = "payload_decode_error"
|
||||
continue
|
||||
sender_matches = self._sender_matches(expected_sender, from_peer)
|
||||
if not sender_matches:
|
||||
with self._lock:
|
||||
self._unexpected_sender_count += 1
|
||||
if not self._looks_like_control_ack(ack_payload):
|
||||
with self._lock:
|
||||
self._last_ack_result = "unexpected_sender"
|
||||
continue
|
||||
ack_result = self._ack_tracker.handle_ack(ack_payload, time.time_ns(), time.monotonic_ns())
|
||||
with self._lock:
|
||||
self._last_ack_result = ack_result
|
||||
if ack_result == "accepted":
|
||||
self._accepted_count += 1
|
||||
if not sender_matches:
|
||||
self._sender_mismatch_accepted_count += 1
|
||||
elif ack_result == "pending_missing":
|
||||
self._pending_missing_count += 1
|
||||
elif ack_result == "invalid_message_id":
|
||||
self._invalid_message_id_count += 1
|
||||
elif ack_result == "invalid_timing":
|
||||
self._invalid_timing_count += 1
|
||||
except Exception as error: # pragma: no cover
|
||||
if not self._closing.is_set():
|
||||
with self._lock:
|
||||
self._last_error = str(error)
|
||||
time.sleep(2)
|
||||
finally:
|
||||
if self._session is not None:
|
||||
try:
|
||||
self._session.close()
|
||||
except Exception:
|
||||
pass
|
||||
with self._lock:
|
||||
self._session = None
|
||||
if self._closing.is_set():
|
||||
self._started = False
|
||||
|
||||
def get_status(self) -> dict[str, Any]:
|
||||
config = load_omnisocket_config().get("control_ack_receiver", {})
|
||||
with self._lock:
|
||||
session = self._session
|
||||
if session is not None:
|
||||
try:
|
||||
session_stats = dict(session.stats())
|
||||
except Exception:
|
||||
session_stats = {}
|
||||
else:
|
||||
session_stats = {}
|
||||
with self._lock:
|
||||
return {
|
||||
"backend_ready": self._session_cls is not None,
|
||||
"started": self._started,
|
||||
"connected": self._session is not None,
|
||||
"registered": bool(session_stats.get("registered", 0) or self._registered),
|
||||
"peer_id": str(config.get("peer_id", "")),
|
||||
"expected_sender": str(config.get("expected_sender", "")),
|
||||
"recv_calls": int(session_stats.get("recv_calls", 0)),
|
||||
"recv_bytes": int(session_stats.get("recv_bytes", 0)),
|
||||
"recv_timeouts": int(session_stats.get("recv_timeouts", 0)),
|
||||
"recv_errors": int(session_stats.get("recv_errors", 0)),
|
||||
"received_messages": self._received_messages,
|
||||
"received_bytes": self._received_bytes,
|
||||
"accepted_count": self._accepted_count,
|
||||
"pending_missing_count": self._pending_missing_count,
|
||||
"invalid_message_id_count": self._invalid_message_id_count,
|
||||
"invalid_timing_count": self._invalid_timing_count,
|
||||
"unexpected_message_type_count": self._unexpected_message_type_count,
|
||||
"unexpected_sender_count": self._unexpected_sender_count,
|
||||
"sender_mismatch_accepted_count": self._sender_mismatch_accepted_count,
|
||||
"payload_decode_errors": self._payload_decode_errors,
|
||||
"last_msg_type": self._last_msg_type,
|
||||
"last_from_peer": self._last_from_peer,
|
||||
"last_payload_preview": self._last_payload_preview,
|
||||
"last_ack_result": self._last_ack_result,
|
||||
"reconnect_count": self._reconnect_count,
|
||||
"last_server_error": str(session_stats.get("last_server_error", "") or self._last_server_error),
|
||||
"last_error": self._last_error,
|
||||
}
|
||||
|
||||
def close(self) -> None:
|
||||
self._closing.set()
|
||||
with self._lock:
|
||||
session = self._session
|
||||
if session is not None:
|
||||
try:
|
||||
session.close()
|
||||
except Exception:
|
||||
pass
|
||||
thread = self._thread
|
||||
if thread is not None and thread.is_alive():
|
||||
thread.join(timeout=0.5)
|
||||
|
||||
|
||||
class ControlArbiter:
|
||||
def __init__(self, sender: OmniSocketControlSender) -> None:
|
||||
self._sender = sender
|
||||
@@ -325,7 +722,7 @@ class ControlArbiter:
|
||||
self._last_error = str(error)
|
||||
elif active_source is not None:
|
||||
try:
|
||||
self._sender.send_payload(payload)
|
||||
self._sender.send_payload(payload, source=active_source)
|
||||
with self._lock:
|
||||
self._last_sent_at = time.monotonic()
|
||||
self._last_error = ""
|
||||
|
||||
@@ -2,26 +2,32 @@ from __future__ import annotations
|
||||
|
||||
import atexit
|
||||
|
||||
from .control import ControlArbiter, NativeUdpControlIngress, OmniSocketControlSender
|
||||
from .control import ControlAckTracker, ControlArbiter, NativeUdpControlIngress, OmniSocketControlAckReceiver, OmniSocketControlSender
|
||||
from .telemetry import GpsDataService, HubTelemetryReceiver, NetworkTelemetryService
|
||||
from .video import OmniSocketVideoReceiver, VideoFrameService
|
||||
from .video import OmniSocketVideoReceiver, VideoDisplayProbeStore, VideoFrameService
|
||||
|
||||
|
||||
_video_receiver = OmniSocketVideoReceiver()
|
||||
_control_sender = OmniSocketControlSender()
|
||||
_control_ack_tracker = ControlAckTracker()
|
||||
_control_sender = OmniSocketControlSender(_control_ack_tracker)
|
||||
_control_ack_receiver = OmniSocketControlAckReceiver(_control_ack_tracker)
|
||||
_hub_telemetry_receiver = HubTelemetryReceiver()
|
||||
_video_display_probe_store = VideoDisplayProbeStore()
|
||||
|
||||
control_arbiter = ControlArbiter(_control_sender)
|
||||
native_control_ingress = NativeUdpControlIngress(control_arbiter)
|
||||
|
||||
video_service = VideoFrameService(_video_receiver)
|
||||
video_service = VideoFrameService(_video_receiver, _video_display_probe_store)
|
||||
gps_service = GpsDataService(_video_receiver)
|
||||
network_service = NetworkTelemetryService(
|
||||
_video_receiver,
|
||||
_control_sender,
|
||||
_control_ack_tracker,
|
||||
_control_ack_receiver,
|
||||
control_arbiter,
|
||||
native_control_ingress,
|
||||
_hub_telemetry_receiver,
|
||||
_video_display_probe_store,
|
||||
)
|
||||
|
||||
|
||||
@@ -30,7 +36,10 @@ def shutdown_monitoring_services() -> None:
|
||||
network_service.close,
|
||||
native_control_ingress.close,
|
||||
control_arbiter.close,
|
||||
_control_ack_receiver.close,
|
||||
_control_ack_tracker.close,
|
||||
_hub_telemetry_receiver.close,
|
||||
_video_display_probe_store.close,
|
||||
_video_receiver.close,
|
||||
_control_sender.close,
|
||||
):
|
||||
|
||||
@@ -2,10 +2,12 @@ from __future__ import annotations
|
||||
|
||||
from collections import deque
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from .common import (
|
||||
@@ -14,13 +16,30 @@ from .common import (
|
||||
load_omnisocket_config,
|
||||
utc_iso_now,
|
||||
)
|
||||
from .control import ControlArbiter, NativeUdpControlIngress, OmniSocketControlSender
|
||||
from .video import FrameTrailerMetadata, OmniSocketVideoReceiver
|
||||
from .control import ControlAckTracker, ControlArbiter, NativeUdpControlIngress, OmniSocketControlAckReceiver, OmniSocketControlSender
|
||||
from .video import FrameTrailerMetadata, OmniSocketVideoReceiver, VideoDisplayProbeStore
|
||||
|
||||
|
||||
LOCAL_SAMPLE_INTERVAL_MS = 500
|
||||
TREND_HISTORY_SIZE = 10
|
||||
TREND_WINDOW_SIZE = 5
|
||||
BLITZ_RUNTIME_DIR = Path(os.getenv("BLITZ_RUNTIME_DIR", "/run/blitz-robot"))
|
||||
WATCHDOG_STATUS_PATH = BLITZ_RUNTIME_DIR / "watchdog.status.json"
|
||||
WATCHDOG_STATUS_STALE_MS = max(int(os.getenv("BLITZ_HEALTH_STALE_SEC", "15")), 1) * 1000
|
||||
WATCHDOG_FAULT_REASON_MAP: dict[str, tuple[str, str | None]] = {
|
||||
"": ("none", None),
|
||||
"none": ("none", None),
|
||||
"camera_missing": ("video_pipeline_stalled", "degraded"),
|
||||
"camera_recovered": ("video_session_recovering", "recovering"),
|
||||
"camera-reappeared-escalated": ("video_session_recovering", "recovering"),
|
||||
"bside_status_stale": ("video_session_recovering", "recovering"),
|
||||
"bside-unhealthy-escalated": ("video_session_recovering", "recovering"),
|
||||
"ros_receiver_unhealthy": ("control_session_recovering", "recovering"),
|
||||
"ros-unhealthy": ("control_session_recovering", "recovering"),
|
||||
"network_or_robot_unreachable": ("network_or_robot_unreachable", "recovering"),
|
||||
"network-recovered-ros-unhealthy": ("control_session_recovering", "recovering"),
|
||||
"network-recovered-escalated": ("network_or_robot_unreachable", "recovering"),
|
||||
}
|
||||
|
||||
|
||||
def _utc_from_epoch(epoch_seconds: float | None) -> str | None:
|
||||
@@ -47,6 +66,19 @@ def _coerce_float(value: Any, default: float = 0.0) -> float:
|
||||
return default
|
||||
|
||||
|
||||
def _load_optional_json(path: Path) -> dict[str, Any] | None:
|
||||
try:
|
||||
if not path.exists():
|
||||
return None
|
||||
with path.open("r", encoding="utf-8") as file:
|
||||
payload = json.load(file)
|
||||
if isinstance(payload, dict):
|
||||
return payload
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
class GpsDataService:
|
||||
def __init__(self, receiver: OmniSocketVideoReceiver) -> None:
|
||||
self._receiver = receiver
|
||||
@@ -73,13 +105,32 @@ class GpsDataService:
|
||||
}
|
||||
|
||||
def _build_payload_from_metadata(self, metadata: FrameTrailerMetadata) -> dict[str, Any]:
|
||||
timestamp_seconds = metadata.timestamp_ns / 1_000_000_000
|
||||
updated_at = _utc_from_epoch(metadata.received_at) or ""
|
||||
if not metadata.has_gps_fix:
|
||||
return {
|
||||
"has_fix": False,
|
||||
"utc_time": "--:--:--",
|
||||
"latitude": None,
|
||||
"longitude": None,
|
||||
"raw_latitude_hex": f"0x{metadata.raw_latitude_hex}",
|
||||
"raw_longitude_hex": f"0x{metadata.raw_longitude_hex}",
|
||||
"satellites": None,
|
||||
"altitude_m": None,
|
||||
"coordinate_system": "WGS84",
|
||||
"source_sentence": "VIDEO_TRAILER",
|
||||
"raw_coordinate_format": VIDEO_TRAILER_COORDINATE_FORMAT,
|
||||
"source_mode": "video-frame-trailer-no-fix",
|
||||
"updated_at": updated_at,
|
||||
}
|
||||
|
||||
timestamp_seconds = metadata.timestamp_ns / 1_000_000_000
|
||||
return {
|
||||
"has_fix": True,
|
||||
"utc_time": datetime.fromtimestamp(timestamp_seconds, timezone.utc).strftime("%H:%M:%S"),
|
||||
"latitude": round(metadata.latitude, 6),
|
||||
"longitude": round(metadata.longitude, 6),
|
||||
"latitude": round(metadata.latitude, 6) if metadata.latitude is not None else None,
|
||||
"longitude": round(metadata.longitude, 6) if metadata.longitude is not None else None,
|
||||
"raw_latitude_hex": f"0x{metadata.raw_latitude_hex}",
|
||||
"raw_longitude_hex": f"0x{metadata.raw_longitude_hex}",
|
||||
"satellites": None,
|
||||
"altitude_m": None,
|
||||
"coordinate_system": "WGS84",
|
||||
@@ -106,7 +157,9 @@ class KcpTrendTracker:
|
||||
"conv": _coerce_int(raw.get("conv")),
|
||||
"rto_ms": _coerce_int(raw.get("rto_ms")),
|
||||
"srtt_ms": _coerce_int(raw.get("srtt_ms")),
|
||||
"min_srtt_ms": _coerce_int(raw.get("min_srtt_ms")),
|
||||
"srttvar_ms": _coerce_int(raw.get("srttvar_ms")),
|
||||
"last_feedback_age_ms": _coerce_int(raw.get("last_feedback_age_ms")),
|
||||
"snd_wnd": snd_wnd,
|
||||
"rmt_wnd": rmt_wnd,
|
||||
"inflight": inflight,
|
||||
@@ -385,15 +438,21 @@ class NetworkTelemetryService:
|
||||
self,
|
||||
video_receiver: OmniSocketVideoReceiver,
|
||||
control_sender: OmniSocketControlSender,
|
||||
control_ack_tracker: ControlAckTracker,
|
||||
control_ack_receiver: OmniSocketControlAckReceiver,
|
||||
control_arbiter: ControlArbiter,
|
||||
native_ingress: NativeUdpControlIngress,
|
||||
hub_receiver: HubTelemetryReceiver,
|
||||
video_display_probe_store: VideoDisplayProbeStore,
|
||||
) -> None:
|
||||
self._video_receiver = video_receiver
|
||||
self._control_sender = control_sender
|
||||
self._control_ack_tracker = control_ack_tracker
|
||||
self._control_ack_receiver = control_ack_receiver
|
||||
self._control_arbiter = control_arbiter
|
||||
self._native_ingress = native_ingress
|
||||
self._hub_receiver = hub_receiver
|
||||
self._video_display_probe_store = video_display_probe_store
|
||||
self._trend_tracker = KcpTrendTracker()
|
||||
self._rate_lock = threading.Lock()
|
||||
self._last_rate_sample: tuple[float, int, int] | None = None
|
||||
@@ -405,6 +464,7 @@ class NetworkTelemetryService:
|
||||
def _ensure_started(self) -> None:
|
||||
self._video_receiver.ensure_started()
|
||||
self._control_arbiter.ensure_started()
|
||||
self._control_ack_receiver.ensure_started()
|
||||
self._native_ingress.ensure_started()
|
||||
self._hub_receiver.ensure_started()
|
||||
with self._rate_lock:
|
||||
@@ -521,6 +581,148 @@ class NetworkTelemetryService:
|
||||
return session
|
||||
return None
|
||||
|
||||
def _derive_robot_health(
|
||||
self,
|
||||
*,
|
||||
video_receiver_status: dict[str, Any],
|
||||
local_control_registered: bool,
|
||||
remote_control_fresh: bool,
|
||||
remote_video_fresh: bool,
|
||||
telemetry_state: dict[str, Any],
|
||||
watchdog_status: dict[str, Any] | None,
|
||||
) -> dict[str, Any]:
|
||||
if watchdog_status is not None:
|
||||
explicit_health = self._derive_robot_health_from_watchdog(watchdog_status)
|
||||
if explicit_health is not None:
|
||||
return explicit_health
|
||||
|
||||
has_recent_frame = bool(video_receiver_status.get("has_recent_frame"))
|
||||
telemetry_connected = bool(telemetry_state.get("connected"))
|
||||
telemetry_stale = bool(telemetry_state.get("stale", True))
|
||||
|
||||
if has_recent_frame and remote_control_fresh and remote_video_fresh:
|
||||
fault_reason = "none"
|
||||
recovery_state = "ok"
|
||||
elif not remote_control_fresh and not remote_video_fresh and not has_recent_frame:
|
||||
fault_reason = "network_or_robot_unreachable"
|
||||
recovery_state = "recovering" if telemetry_connected and not telemetry_stale else "degraded"
|
||||
elif remote_control_fresh and not remote_video_fresh:
|
||||
fault_reason = "video_session_recovering"
|
||||
recovery_state = "recovering"
|
||||
elif not remote_control_fresh and local_control_registered:
|
||||
fault_reason = "control_session_recovering"
|
||||
recovery_state = "recovering"
|
||||
elif remote_control_fresh and not has_recent_frame:
|
||||
fault_reason = "video_pipeline_stalled"
|
||||
recovery_state = "degraded"
|
||||
else:
|
||||
fault_reason = "unknown"
|
||||
recovery_state = "degraded"
|
||||
|
||||
return {
|
||||
"fault_reason": fault_reason,
|
||||
"recovery_state": recovery_state,
|
||||
"confidence": "derived",
|
||||
"updated_at": utc_iso_now(),
|
||||
}
|
||||
|
||||
def _derive_robot_health_from_watchdog(self, watchdog_status: dict[str, Any]) -> dict[str, Any] | None:
|
||||
updated_at_epoch_ms = _coerce_int(watchdog_status.get("updated_at_epoch_ms"))
|
||||
if updated_at_epoch_ms <= 0:
|
||||
return None
|
||||
|
||||
now_epoch_ms = int(time.time() * 1000)
|
||||
if now_epoch_ms - updated_at_epoch_ms > WATCHDOG_STATUS_STALE_MS:
|
||||
return None
|
||||
|
||||
raw_fault_reason = str(watchdog_status.get("fault_reason", "") or "")
|
||||
raw_recovery_state = str(watchdog_status.get("recovery_state", "") or "")
|
||||
normalized_fault_reason = "unknown"
|
||||
normalized_recovery_state = raw_recovery_state or "degraded"
|
||||
mapped_health = WATCHDOG_FAULT_REASON_MAP.get(raw_fault_reason)
|
||||
|
||||
if mapped_health is not None:
|
||||
normalized_fault_reason, recovery_override = mapped_health
|
||||
if recovery_override is not None:
|
||||
normalized_recovery_state = recovery_override
|
||||
if raw_recovery_state == "backoff":
|
||||
normalized_recovery_state = "backoff"
|
||||
|
||||
return {
|
||||
"fault_reason": normalized_fault_reason,
|
||||
"recovery_state": normalized_recovery_state,
|
||||
"confidence": "derived",
|
||||
"updated_at": _utc_from_epoch(updated_at_epoch_ms / 1000.0) or utc_iso_now(),
|
||||
}
|
||||
|
||||
def _derive_latency_estimate(
|
||||
self,
|
||||
*,
|
||||
links: dict[str, dict[str, Any]],
|
||||
video_receiver_status: dict[str, Any],
|
||||
display_probe_status: dict[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
a_to_d_control_raw = links["a_to_d"]["sessions"]["control"]["kcp"].get("srtt_ms")
|
||||
d_to_b_control_raw = links["d_to_b"]["sessions"]["control"]["kcp"].get("srtt_ms")
|
||||
a_to_d_control_min_raw = links["a_to_d"]["sessions"]["control"]["kcp"].get("min_srtt_ms")
|
||||
d_to_b_control_min_raw = links["d_to_b"]["sessions"]["control"]["kcp"].get("min_srtt_ms")
|
||||
a_to_d_video_raw = links["a_to_d"]["sessions"]["video"]["kcp"].get("srtt_ms")
|
||||
d_to_b_video_raw = links["d_to_b"]["sessions"]["video"]["kcp"].get("srtt_ms")
|
||||
|
||||
a_to_d_control = _coerce_float(a_to_d_control_raw) if a_to_d_control_raw is not None else None
|
||||
d_to_b_control = _coerce_float(d_to_b_control_raw) if d_to_b_control_raw is not None else None
|
||||
a_to_d_control_min = _coerce_float(a_to_d_control_min_raw) if a_to_d_control_min_raw is not None else None
|
||||
d_to_b_control_min = _coerce_float(d_to_b_control_min_raw) if d_to_b_control_min_raw is not None else None
|
||||
a_to_d_video = _coerce_float(a_to_d_video_raw) if a_to_d_video_raw is not None else None
|
||||
d_to_b_video = _coerce_float(d_to_b_video_raw) if d_to_b_video_raw is not None else None
|
||||
ack_estimate = self._control_ack_tracker.get_latest_estimate()
|
||||
capture_to_send_raw = video_receiver_status.get("latest_capture_to_send_ms")
|
||||
request_to_paint_raw = display_probe_status.get("request_to_paint_ms")
|
||||
capture_to_send_ms = _coerce_float(capture_to_send_raw) if capture_to_send_raw is not None else None
|
||||
request_to_paint_ms = _coerce_float(request_to_paint_raw) if request_to_paint_raw is not None else None
|
||||
video_network_oneway_est_ms = (
|
||||
round((a_to_d_video + d_to_b_video) / 2.0, 3)
|
||||
if a_to_d_video is not None and d_to_b_video is not None
|
||||
else None
|
||||
)
|
||||
video_partial_est_ms = None
|
||||
if capture_to_send_ms is not None and video_network_oneway_est_ms is not None:
|
||||
video_partial_est_ms = round(capture_to_send_ms + video_network_oneway_est_ms, 3)
|
||||
video_e2e_est_ms = None
|
||||
if video_partial_est_ms is not None and request_to_paint_ms is not None:
|
||||
video_e2e_est_ms = round(video_partial_est_ms + request_to_paint_ms, 3)
|
||||
|
||||
return {
|
||||
"control_loop_rtt_ms": ack_estimate.get("control_loop_rtt_ms"),
|
||||
"control_to_persist_est_ms": ack_estimate.get("control_to_persist_est_ms"),
|
||||
"control_oneway_srtt_est_ms": (
|
||||
round((a_to_d_control + d_to_b_control) / 2.0, 3)
|
||||
if a_to_d_control is not None and d_to_b_control is not None
|
||||
else None
|
||||
),
|
||||
"control_oneway_bestcase_est_ms": (
|
||||
round((a_to_d_control_min + d_to_b_control_min) / 2.0, 3)
|
||||
if a_to_d_control_min is not None and d_to_b_control_min is not None
|
||||
else None
|
||||
),
|
||||
"video_network_oneway_est_ms": video_network_oneway_est_ms,
|
||||
"video_partial_est_ms": video_partial_est_ms,
|
||||
"video_e2e_est_ms": video_e2e_est_ms,
|
||||
"estimate_method": {
|
||||
"control": "ack_loop" if ack_estimate.get("ack_available") else "srtt_fallback",
|
||||
"video": "capture_to_send+srtt/2+request_to_paint" if video_e2e_est_ms is not None else "capture_to_send+srtt/2",
|
||||
},
|
||||
"clock_sync_required": False,
|
||||
"assumptions": [
|
||||
"control one-way estimate uses ACK loop when available",
|
||||
"video one-way estimate uses per-leg SRTT and local paint timing",
|
||||
],
|
||||
"confidence": {
|
||||
"control": "derived_ack" if ack_estimate.get("ack_available") else "fallback_srtt",
|
||||
"video": "derived_local_probe" if video_e2e_est_ms is not None else "partial_without_probe",
|
||||
},
|
||||
}
|
||||
|
||||
def get_latest(self) -> dict[str, Any]:
|
||||
self._ensure_started()
|
||||
|
||||
@@ -533,10 +735,14 @@ class NetworkTelemetryService:
|
||||
control_app = self._control_sender.session_stats()
|
||||
video_kcp = self._video_receiver.session_kcp_stats()
|
||||
control_kcp = self._control_sender.session_kcp_stats()
|
||||
video_receiver_status = self._video_receiver.get_status()
|
||||
arbiter_status = self._control_arbiter.get_status()
|
||||
ingress_status = self._native_ingress.get_status()
|
||||
sender_status = self._control_sender.get_status()
|
||||
ack_receiver_status = self._control_ack_receiver.get_status()
|
||||
ack_status = self._control_ack_tracker.get_latest_estimate()
|
||||
telemetry_state = self._hub_receiver.get_snapshot()
|
||||
display_probe_status = self._video_display_probe_store.get_status()
|
||||
|
||||
total_send_bytes = int(video_app.get("send_bytes", 0)) + int(control_app.get("send_bytes", 0))
|
||||
total_recv_bytes = int(video_app.get("recv_bytes", 0)) + int(control_app.get("recv_bytes", 0))
|
||||
@@ -588,6 +794,9 @@ class NetworkTelemetryService:
|
||||
remote_stale,
|
||||
),
|
||||
}
|
||||
self._video_receiver.update_remote_video_srtt(
|
||||
_coerce_int(remote_sessions["video"]["kcp"].get("srtt_ms")) if remote_sessions["video"]["kcp"].get("srtt_ms") is not None else None
|
||||
)
|
||||
|
||||
links = {
|
||||
"a_to_d": self._build_link("local-a-side", local_updated_at, False, local_sessions),
|
||||
@@ -605,6 +814,21 @@ class NetworkTelemetryService:
|
||||
jitter_ms = primary_kcp.get("srttvar_ms") if primary_session is not None else None
|
||||
local_control_registered = bool(control_app.get("registered", 0))
|
||||
remote_control_fresh = bool(remote_sessions["control"].get("connected")) and not bool(remote_sessions["control"].get("stale"))
|
||||
remote_video_fresh = bool(remote_sessions["video"].get("connected")) and not bool(remote_sessions["video"].get("stale"))
|
||||
watchdog_status = _load_optional_json(WATCHDOG_STATUS_PATH)
|
||||
robot_health = self._derive_robot_health(
|
||||
video_receiver_status=video_receiver_status,
|
||||
local_control_registered=local_control_registered,
|
||||
remote_control_fresh=remote_control_fresh,
|
||||
remote_video_fresh=remote_video_fresh,
|
||||
telemetry_state=telemetry_state,
|
||||
watchdog_status=watchdog_status,
|
||||
)
|
||||
latency_estimate = self._derive_latency_estimate(
|
||||
links=links,
|
||||
video_receiver_status=video_receiver_status,
|
||||
display_probe_status=display_probe_status,
|
||||
)
|
||||
|
||||
if local_control_registered and remote_control_fresh:
|
||||
peer_status = "online"
|
||||
@@ -645,6 +869,12 @@ class NetworkTelemetryService:
|
||||
},
|
||||
},
|
||||
"links": links,
|
||||
"latency_estimate": latency_estimate,
|
||||
"video_freshness": video_receiver_status.get("freshness", {}),
|
||||
"control_ack_status": {
|
||||
**ack_status,
|
||||
"receiver": ack_receiver_status,
|
||||
},
|
||||
"telemetry_receiver": {
|
||||
"hub_connected": bool(telemetry_state.get("connected")),
|
||||
"hub_updated_at": telemetry_state.get("updated_at"),
|
||||
@@ -655,12 +885,14 @@ class NetworkTelemetryService:
|
||||
"last_server_error": str(telemetry_state.get("last_server_error", "") or ""),
|
||||
"reconnect_count": int(telemetry_state.get("reconnect_count", 0)),
|
||||
},
|
||||
"robot_health": robot_health,
|
||||
"ingress": {
|
||||
"native_udp": ingress_status,
|
||||
},
|
||||
"control": {
|
||||
"arbiter": arbiter_status,
|
||||
"sender": sender_status,
|
||||
"ack_receiver": ack_receiver_status,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ urlpatterns = [
|
||||
path("dashboard/", views.dashboard_snapshot, name="dashboard-snapshot"),
|
||||
path("gps/latest/", views.gps_latest, name="gps-latest"),
|
||||
path("network/latest/", views.network_latest, name="network-latest"),
|
||||
path("clock/calibrate/", views.clock_calibration, name="clock-calibration"),
|
||||
path("video/status/", views.video_status, name="video-status"),
|
||||
path("video/frame/", views.video_frame, name="video-frame"),
|
||||
path("video/display-probe/", views.video_display_probe, name="video-display-probe"),
|
||||
path("video/stream/", views.video_stream, name="video-stream"),
|
||||
]
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from collections import deque
|
||||
from dataclasses import dataclass
|
||||
import hashlib
|
||||
import math
|
||||
import struct
|
||||
import sys
|
||||
@@ -13,6 +14,7 @@ from .common import (
|
||||
JPEG_FRAME_DIR,
|
||||
OMNISOCKET_CONFIG_PATH,
|
||||
OMNISOCKET_FRAME_FRESH_SECONDS,
|
||||
JsonlRunLogger,
|
||||
VIDEO_SOURCE_MODE,
|
||||
VIDEO_TIMESTAMP_SAMPLE_SIZE,
|
||||
VIDEO_TRAILER_BYTES,
|
||||
@@ -35,13 +37,190 @@ def safe_kcp_stats(session: Any) -> dict[str, Any]:
|
||||
return {}
|
||||
|
||||
|
||||
class VideoDisplayProbeStore:
|
||||
def __init__(self) -> None:
|
||||
self._lock = threading.Lock()
|
||||
self._logger = JsonlRunLogger("BLITZ_A_VIDEO_DISPLAY_PROBE_LOG_PATH", "a-video-display-probe")
|
||||
self._latest: VideoDisplayProbeStatus = VideoDisplayProbeStatus(
|
||||
updated_at=None,
|
||||
frame_seq=None,
|
||||
frame_hash="",
|
||||
input_to_next_fresh_frame_ms=None,
|
||||
input_to_next_changed_frame_ms=None,
|
||||
input_to_next_paint_ms=None,
|
||||
request_to_paint_ms=None,
|
||||
response_to_paint_ms=None,
|
||||
backend_to_request_ms=None,
|
||||
backend_to_request_ms_raw=None,
|
||||
backend_to_paint_ms=None,
|
||||
backend_to_paint_ms_raw=None,
|
||||
browser_backend_clock_offset_ms=None,
|
||||
browser_backend_clock_rtt_ms=None,
|
||||
browser_backend_clock_sample_count=0,
|
||||
browser_backend_clock_calibrated_at=None,
|
||||
)
|
||||
|
||||
def record_event(self, payload: dict[str, Any]) -> None:
|
||||
backend_received_unix_ns = payload.get("backend_received_unix_ns")
|
||||
request_started_unix_ms = payload.get("request_started_unix_ms")
|
||||
response_received_unix_ms = payload.get("response_received_unix_ms")
|
||||
paint_unix_ms = payload.get("paint_unix_ms")
|
||||
browser_backend_clock_offset_ms = self._coerce_float(payload.get("browser_backend_clock_offset_ms"))
|
||||
browser_backend_clock_rtt_ms = self._coerce_float(payload.get("browser_backend_clock_rtt_ms"))
|
||||
browser_backend_clock_sample_count = self._coerce_int(payload.get("browser_backend_clock_sample_count"))
|
||||
browser_backend_clock_calibrated_at = self._coerce_text(payload.get("browser_backend_clock_calibrated_at"))
|
||||
request_to_paint_ms = self._duration_ms(paint_unix_ms, request_started_unix_ms, clamp_floor_zero=True)
|
||||
response_to_paint_ms = self._duration_ms(paint_unix_ms, response_received_unix_ms, clamp_floor_zero=True)
|
||||
backend_received_unix_ms = None
|
||||
try:
|
||||
if backend_received_unix_ns is not None:
|
||||
backend_received_unix_ms = int(backend_received_unix_ns) / 1_000_000.0
|
||||
except (TypeError, ValueError):
|
||||
backend_received_unix_ms = None
|
||||
backend_received_browser_unix_ms = None
|
||||
if backend_received_unix_ms is not None and browser_backend_clock_offset_ms is not None:
|
||||
backend_received_browser_unix_ms = round(backend_received_unix_ms + browser_backend_clock_offset_ms, 3)
|
||||
backend_to_request_ms_raw = self._duration_ms(request_started_unix_ms, backend_received_unix_ms, clamp_floor_zero=False)
|
||||
backend_to_paint_ms_raw = self._duration_ms(paint_unix_ms, backend_received_unix_ms, clamp_floor_zero=False)
|
||||
backend_to_request_ms = self._duration_ms(
|
||||
request_started_unix_ms,
|
||||
backend_received_browser_unix_ms,
|
||||
clamp_floor_zero=True,
|
||||
)
|
||||
backend_to_paint_ms = self._duration_ms(
|
||||
paint_unix_ms,
|
||||
backend_received_browser_unix_ms,
|
||||
clamp_floor_zero=True,
|
||||
)
|
||||
|
||||
status = VideoDisplayProbeStatus(
|
||||
updated_at=self._coerce_text(payload.get("updated_at")),
|
||||
frame_seq=int(payload["frame_seq"]) if payload.get("frame_seq") is not None else None,
|
||||
frame_hash=str(payload.get("frame_hash") or ""),
|
||||
input_to_next_fresh_frame_ms=self._coerce_float(payload.get("input_to_next_fresh_frame_ms")),
|
||||
input_to_next_changed_frame_ms=self._coerce_float(payload.get("input_to_next_changed_frame_ms")),
|
||||
input_to_next_paint_ms=self._coerce_float(payload.get("input_to_next_paint_ms")),
|
||||
request_to_paint_ms=request_to_paint_ms,
|
||||
response_to_paint_ms=response_to_paint_ms,
|
||||
backend_to_request_ms=backend_to_request_ms,
|
||||
backend_to_request_ms_raw=backend_to_request_ms_raw,
|
||||
backend_to_paint_ms=backend_to_paint_ms,
|
||||
backend_to_paint_ms_raw=backend_to_paint_ms_raw,
|
||||
browser_backend_clock_offset_ms=browser_backend_clock_offset_ms,
|
||||
browser_backend_clock_rtt_ms=browser_backend_clock_rtt_ms,
|
||||
browser_backend_clock_sample_count=browser_backend_clock_sample_count,
|
||||
browser_backend_clock_calibrated_at=browser_backend_clock_calibrated_at,
|
||||
)
|
||||
logged_payload = dict(payload)
|
||||
logged_payload.update(
|
||||
{
|
||||
"request_to_paint_ms": request_to_paint_ms,
|
||||
"response_to_paint_ms": response_to_paint_ms,
|
||||
"backend_received_browser_unix_ms": backend_received_browser_unix_ms,
|
||||
"backend_to_request_ms": backend_to_request_ms,
|
||||
"backend_to_request_ms_raw": backend_to_request_ms_raw,
|
||||
"backend_to_paint_ms": backend_to_paint_ms,
|
||||
"backend_to_paint_ms_raw": backend_to_paint_ms_raw,
|
||||
}
|
||||
)
|
||||
with self._lock:
|
||||
self._latest = status
|
||||
self._logger.write(logged_payload)
|
||||
|
||||
def get_status(self) -> dict[str, Any]:
|
||||
with self._lock:
|
||||
latest = self._latest
|
||||
return {
|
||||
"updated_at": latest.updated_at,
|
||||
"frame_seq": latest.frame_seq,
|
||||
"frame_hash": latest.frame_hash,
|
||||
"input_to_next_fresh_frame_ms": latest.input_to_next_fresh_frame_ms,
|
||||
"input_to_next_changed_frame_ms": latest.input_to_next_changed_frame_ms,
|
||||
"input_to_next_paint_ms": latest.input_to_next_paint_ms,
|
||||
"request_to_paint_ms": latest.request_to_paint_ms,
|
||||
"response_to_paint_ms": latest.response_to_paint_ms,
|
||||
"backend_to_request_ms": latest.backend_to_request_ms,
|
||||
"backend_to_request_ms_raw": latest.backend_to_request_ms_raw,
|
||||
"backend_to_paint_ms": latest.backend_to_paint_ms,
|
||||
"backend_to_paint_ms_raw": latest.backend_to_paint_ms_raw,
|
||||
"browser_backend_clock_offset_ms": latest.browser_backend_clock_offset_ms,
|
||||
"browser_backend_clock_rtt_ms": latest.browser_backend_clock_rtt_ms,
|
||||
"browser_backend_clock_sample_count": latest.browser_backend_clock_sample_count,
|
||||
"browser_backend_clock_calibrated_at": latest.browser_backend_clock_calibrated_at,
|
||||
}
|
||||
|
||||
def close(self) -> None:
|
||||
self._logger.close()
|
||||
|
||||
@staticmethod
|
||||
def _coerce_float(value: Any) -> float | None:
|
||||
try:
|
||||
if value is None:
|
||||
return None
|
||||
return round(float(value), 3)
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _coerce_int(value: Any) -> int:
|
||||
try:
|
||||
if value is None:
|
||||
return 0
|
||||
return int(value)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def _coerce_text(value: Any) -> str | None:
|
||||
text = str(value or "").strip()
|
||||
return text or None
|
||||
|
||||
@classmethod
|
||||
def _duration_ms(cls, end_ms: Any, start_ms: Any, *, clamp_floor_zero: bool) -> float | None:
|
||||
end_value = cls._coerce_float(end_ms)
|
||||
start_value = cls._coerce_float(start_ms)
|
||||
if end_value is None or start_value is None:
|
||||
return None
|
||||
delta = round(end_value - start_value, 3)
|
||||
if clamp_floor_zero:
|
||||
delta = max(0.0, delta)
|
||||
return delta
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FrameTrailerMetadata:
|
||||
timestamp_ns: int
|
||||
latitude: float
|
||||
longitude: float
|
||||
latitude: float | None
|
||||
longitude: float | None
|
||||
capture_to_send_ms: int
|
||||
raw_latitude_hex: str
|
||||
raw_longitude_hex: str
|
||||
received_at: float
|
||||
|
||||
@property
|
||||
def has_gps_fix(self) -> bool:
|
||||
return self.latitude is not None and self.longitude is not None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class VideoDisplayProbeStatus:
|
||||
updated_at: str | None
|
||||
frame_seq: int | None
|
||||
frame_hash: str
|
||||
input_to_next_fresh_frame_ms: float | None
|
||||
input_to_next_changed_frame_ms: float | None
|
||||
input_to_next_paint_ms: float | None
|
||||
request_to_paint_ms: float | None
|
||||
response_to_paint_ms: float | None
|
||||
backend_to_request_ms: float | None
|
||||
backend_to_request_ms_raw: float | None
|
||||
backend_to_paint_ms: float | None
|
||||
backend_to_paint_ms_raw: float | None
|
||||
browser_backend_clock_offset_ms: float | None
|
||||
browser_backend_clock_rtt_ms: float | None
|
||||
browser_backend_clock_sample_count: int
|
||||
browser_backend_clock_calibrated_at: str | None
|
||||
|
||||
|
||||
class OmniSocketVideoReceiver:
|
||||
def __init__(self) -> None:
|
||||
@@ -54,17 +233,31 @@ class OmniSocketVideoReceiver:
|
||||
self._video_defaults: dict[str, Any] = {}
|
||||
self._latest_frame: bytes | None = None
|
||||
self._latest_received_at = 0.0
|
||||
self._latest_backend_received_unix_ns = 0
|
||||
self._latest_backend_received_mono_ns = 0
|
||||
self._latest_sequence: int | None = None
|
||||
self._latest_metadata: FrameTrailerMetadata | None = None
|
||||
self._latest_latency_ms: float | None = None
|
||||
self._latest_sender_clock_delta_ms_raw: float | None = None
|
||||
self._latest_timestamp_unit: str | None = None
|
||||
self._latest_timestamp_endianness: str | None = None
|
||||
self._latency_samples_ms: deque[float] = deque(maxlen=VIDEO_TIMESTAMP_SAMPLE_SIZE)
|
||||
self._sender_clock_delta_samples_ms_raw: deque[float] = deque(maxlen=VIDEO_TIMESTAMP_SAMPLE_SIZE)
|
||||
self._latest_frame_hash = ""
|
||||
self._latest_frame_bytes = 0
|
||||
self._last_frame_hash = ""
|
||||
self._last_sequence: int | None = None
|
||||
self._last_backend_received_mono_ns = 0
|
||||
self._interarrival_ms_samples: deque[float] = deque(maxlen=120)
|
||||
self._repeat_samples: deque[int] = deque(maxlen=120)
|
||||
self._skip_samples: deque[int] = deque(maxlen=120)
|
||||
self._freeze_samples_ms: deque[float] = deque(maxlen=120)
|
||||
self._current_stale_frame_run_length = 0
|
||||
self._latest_remote_video_srtt_ms: int | None = None
|
||||
self._frames_received = 0
|
||||
self._last_error = ""
|
||||
self._reconnect_count = 0
|
||||
self._ever_connected = False
|
||||
self._closing = threading.Event()
|
||||
self._frame_recv_logger = JsonlRunLogger("BLITZ_A_VIDEO_FRAME_RECV_LOG_PATH", "a-video-frame-recv")
|
||||
self._load_backend()
|
||||
|
||||
def _load_backend(self) -> None:
|
||||
@@ -172,25 +365,32 @@ class OmniSocketVideoReceiver:
|
||||
return None
|
||||
|
||||
try:
|
||||
timestamp_ms, latitude, longitude = VIDEO_TRAILER_STRUCT.unpack(trailer)
|
||||
timestamp_ms, latitude, longitude, capture_to_send_ms = VIDEO_TRAILER_STRUCT.unpack(trailer)
|
||||
except struct.error:
|
||||
return None
|
||||
|
||||
if timestamp_ms <= 0:
|
||||
return None
|
||||
if not math.isfinite(latitude) or not math.isfinite(longitude):
|
||||
return None
|
||||
if not (-90.0 <= latitude <= 90.0) or not (-180.0 <= longitude <= 180.0):
|
||||
return None
|
||||
|
||||
timestamp_ns = timestamp_ms * VIDEO_TRAILER_TIMESTAMP_MULTIPLIER_NS
|
||||
if abs(time.time_ns() - timestamp_ns) > VIDEO_TRAILER_TIMESTAMP_MAX_SKEW_NS:
|
||||
return None
|
||||
|
||||
gps_fix_available = (
|
||||
math.isfinite(latitude)
|
||||
and math.isfinite(longitude)
|
||||
and (-90.0 <= latitude <= 90.0)
|
||||
and (-180.0 <= longitude <= 180.0)
|
||||
and not (abs(latitude) < 1e-9 and abs(longitude) < 1e-9)
|
||||
)
|
||||
|
||||
return FrameTrailerMetadata(
|
||||
timestamp_ns=timestamp_ns,
|
||||
latitude=latitude,
|
||||
longitude=longitude,
|
||||
latitude=latitude if gps_fix_available else None,
|
||||
longitude=longitude if gps_fix_available else None,
|
||||
capture_to_send_ms=int(capture_to_send_ms),
|
||||
raw_latitude_hex=trailer[8:16].hex(),
|
||||
raw_longitude_hex=trailer[16:24].hex(),
|
||||
received_at=received_at if received_at is not None else time.time(),
|
||||
)
|
||||
|
||||
@@ -199,6 +399,56 @@ class OmniSocketVideoReceiver:
|
||||
time.time() - self._latest_received_at <= OMNISOCKET_FRAME_FRESH_SECONDS
|
||||
)
|
||||
|
||||
def update_remote_video_srtt(self, srtt_ms: int | None) -> None:
|
||||
with self._lock:
|
||||
self._latest_remote_video_srtt_ms = srtt_ms
|
||||
|
||||
def _freshness_payload_locked(self) -> dict[str, Any]:
|
||||
interarrival_samples = list(self._interarrival_ms_samples)
|
||||
repeat_samples = list(self._repeat_samples)
|
||||
skip_samples = list(self._skip_samples)
|
||||
freeze_samples_ms = list(self._freeze_samples_ms)
|
||||
|
||||
inter_frame_avg_ms = round(sum(interarrival_samples) / len(interarrival_samples), 3) if interarrival_samples else None
|
||||
if interarrival_samples:
|
||||
ordered = sorted(interarrival_samples)
|
||||
p95_index = min(len(ordered) - 1, max(0, math.ceil(len(ordered) * 0.95) - 1))
|
||||
inter_frame_p95_ms = round(ordered[p95_index], 3)
|
||||
else:
|
||||
inter_frame_p95_ms = None
|
||||
|
||||
repeated_frame_ratio = round(sum(repeat_samples) / len(repeat_samples), 4) if repeat_samples else 0.0
|
||||
total_skip = sum(skip_samples)
|
||||
expected_frames = len(skip_samples) + total_skip
|
||||
skip_ratio = round(total_skip / expected_frames, 4) if expected_frames > 0 else 0.0
|
||||
longest_freeze_ms = round(max(freeze_samples_ms), 3) if freeze_samples_ms else 0.0
|
||||
return {
|
||||
"inter_frame_avg_ms": inter_frame_avg_ms,
|
||||
"inter_frame_p95_ms": inter_frame_p95_ms,
|
||||
"repeated_frame_ratio": repeated_frame_ratio,
|
||||
"skip_ratio": skip_ratio,
|
||||
"longest_freeze_ms": longest_freeze_ms,
|
||||
"stale_frame_run_length": self._current_stale_frame_run_length,
|
||||
"relative_freshness_lag_frames": self._current_stale_frame_run_length + (skip_samples[-1] if skip_samples else 0),
|
||||
}
|
||||
|
||||
def _frame_headers_locked(self) -> dict[str, str]:
|
||||
capture_to_send_ms = self._latest_metadata.capture_to_send_ms if self._latest_metadata is not None else None
|
||||
headers: dict[str, str] = {}
|
||||
if self._latest_sequence is not None:
|
||||
headers["X-Blitz-Frame-Seq"] = str(self._latest_sequence)
|
||||
if self._latest_backend_received_unix_ns > 0:
|
||||
headers["X-Blitz-Backend-Received-Unix-Ns"] = str(self._latest_backend_received_unix_ns)
|
||||
if self._latest_frame_hash:
|
||||
headers["X-Blitz-Frame-Hash"] = self._latest_frame_hash
|
||||
if capture_to_send_ms is not None:
|
||||
headers["X-Blitz-BSide-Capture-To-Send-Ms"] = str(capture_to_send_ms)
|
||||
return headers
|
||||
|
||||
def get_latest_frame_headers(self) -> dict[str, str]:
|
||||
snapshot = self.get_latest_frame_snapshot()
|
||||
return snapshot[1] if snapshot is not None else {}
|
||||
|
||||
def _run(self) -> None:
|
||||
while not self._closing.is_set():
|
||||
try:
|
||||
@@ -226,27 +476,81 @@ class OmniSocketVideoReceiver:
|
||||
continue
|
||||
|
||||
received_at = time.time()
|
||||
received_unix_ns = time.time_ns()
|
||||
received_mono_ns = time.monotonic_ns()
|
||||
frame_metadata = self._extract_frame_metadata(frame, received_at=received_at)
|
||||
latency_ms = None
|
||||
sender_clock_delta_ms_raw = None
|
||||
if frame_metadata is not None:
|
||||
latency_ms = round((time.time_ns() - frame_metadata.timestamp_ns) / 1_000_000, 3)
|
||||
sender_clock_delta_ms_raw = round((received_unix_ns - frame_metadata.timestamp_ns) / 1_000_000, 3)
|
||||
unit = VIDEO_TRAILER_TIMESTAMP_UNIT
|
||||
endianness = VIDEO_TRAILER_ENDIANNESS
|
||||
else:
|
||||
unit = None
|
||||
endianness = None
|
||||
frame_sequence = self._extract_sequence(frame)
|
||||
frame_hash = hashlib.blake2s(jpeg_frame, digest_size=8).hexdigest()
|
||||
local_kcp = safe_kcp_stats(session) if self._frame_recv_logger.enabled else {}
|
||||
frame_log_record: dict[str, Any] | None = None
|
||||
|
||||
with self._lock:
|
||||
interarrival_ms = None
|
||||
if self._last_backend_received_mono_ns > 0:
|
||||
interarrival_ms = round((received_mono_ns - self._last_backend_received_mono_ns) / 1_000_000, 3)
|
||||
self._interarrival_ms_samples.append(interarrival_ms)
|
||||
|
||||
sequence_gap = 0
|
||||
if frame_sequence is not None and self._last_sequence is not None and frame_sequence > self._last_sequence:
|
||||
sequence_gap = max(0, frame_sequence - self._last_sequence - 1)
|
||||
|
||||
repeat_flag = bool(self._last_frame_hash) and frame_hash == self._last_frame_hash
|
||||
self._repeat_samples.append(1 if repeat_flag else 0)
|
||||
self._skip_samples.append(sequence_gap)
|
||||
if repeat_flag:
|
||||
self._current_stale_frame_run_length += 1
|
||||
else:
|
||||
self._current_stale_frame_run_length = 0
|
||||
if interarrival_ms is not None and repeat_flag:
|
||||
self._freeze_samples_ms.append(interarrival_ms)
|
||||
elif interarrival_ms is not None:
|
||||
self._freeze_samples_ms.append(0.0)
|
||||
|
||||
self._latest_frame = jpeg_frame
|
||||
self._latest_received_at = received_at
|
||||
self._latest_sequence = self._extract_sequence(frame)
|
||||
self._latest_backend_received_unix_ns = received_unix_ns
|
||||
self._latest_backend_received_mono_ns = received_mono_ns
|
||||
self._latest_sequence = frame_sequence
|
||||
self._last_sequence = frame_sequence
|
||||
self._latest_metadata = frame_metadata
|
||||
self._latest_latency_ms = latency_ms
|
||||
self._latest_sender_clock_delta_ms_raw = sender_clock_delta_ms_raw
|
||||
self._latest_timestamp_unit = unit
|
||||
self._latest_timestamp_endianness = endianness
|
||||
if latency_ms is not None:
|
||||
self._latency_samples_ms.append(latency_ms)
|
||||
self._latest_frame_hash = frame_hash
|
||||
self._latest_frame_bytes = len(jpeg_frame)
|
||||
self._last_frame_hash = frame_hash
|
||||
self._last_backend_received_mono_ns = received_mono_ns
|
||||
if sender_clock_delta_ms_raw is not None:
|
||||
self._sender_clock_delta_samples_ms_raw.append(sender_clock_delta_ms_raw)
|
||||
self._frames_received += 1
|
||||
|
||||
if self._frame_recv_logger.enabled:
|
||||
frame_log_record = {
|
||||
"ts_unix_nano": received_unix_ns,
|
||||
"frame_seq": frame_sequence,
|
||||
"backend_received_unix_ns": received_unix_ns,
|
||||
"backend_received_mono_ns": received_mono_ns,
|
||||
"jpeg_bytes": len(jpeg_frame),
|
||||
"interarrival_ms": interarrival_ms,
|
||||
"sequence_gap": sequence_gap,
|
||||
"repeat_flag": repeat_flag,
|
||||
"skip_count": sequence_gap,
|
||||
"frame_hash": frame_hash,
|
||||
"a_to_d_video_srtt_ms": local_kcp.get("srtt_ms"),
|
||||
"d_to_b_video_srtt_ms": self._latest_remote_video_srtt_ms,
|
||||
"b_side_capture_to_send_ms": frame_metadata.capture_to_send_ms if frame_metadata is not None else None,
|
||||
"sender_clock_delta_ms_raw": sender_clock_delta_ms_raw,
|
||||
}
|
||||
if frame_log_record is not None:
|
||||
self._frame_recv_logger.write(frame_log_record)
|
||||
except Exception as error: # pragma: no cover - runtime integration path
|
||||
if not self._closing.is_set():
|
||||
session_error = ""
|
||||
@@ -269,11 +573,17 @@ class OmniSocketVideoReceiver:
|
||||
self._started = False
|
||||
|
||||
def get_latest_frame(self) -> bytes | None:
|
||||
snapshot = self.get_latest_frame_snapshot()
|
||||
return snapshot[0] if snapshot is not None else None
|
||||
|
||||
def get_latest_frame_snapshot(self) -> tuple[bytes, dict[str, str]] | None:
|
||||
self.ensure_started()
|
||||
with self._lock:
|
||||
if not self._has_fresh_frame_locked():
|
||||
return None
|
||||
return self._latest_frame
|
||||
if self._latest_frame is None:
|
||||
return None
|
||||
return self._latest_frame, self._frame_headers_locked()
|
||||
|
||||
def get_latest_frame_metadata(self) -> FrameTrailerMetadata | None:
|
||||
self.ensure_started()
|
||||
@@ -307,25 +617,28 @@ class OmniSocketVideoReceiver:
|
||||
session_stats = self.session_stats()
|
||||
with self._lock:
|
||||
has_recent_frame = self._has_fresh_frame_locked()
|
||||
if has_recent_frame and self._latest_latency_ms is not None:
|
||||
freshness_status = self._freshness_payload_locked()
|
||||
if has_recent_frame and self._latest_sender_clock_delta_ms_raw is not None:
|
||||
timing_status = {
|
||||
"available": True,
|
||||
"latest_delta_ms": self._latest_latency_ms,
|
||||
"delta_samples_ms": list(reversed(self._latency_samples_ms)),
|
||||
"sample_count": len(self._latency_samples_ms),
|
||||
"sender_clock_delta_ms_raw": self._latest_sender_clock_delta_ms_raw,
|
||||
"sender_clock_delta_samples_ms_raw": list(reversed(self._sender_clock_delta_samples_ms_raw)),
|
||||
"sample_count": len(self._sender_clock_delta_samples_ms_raw),
|
||||
"sample_window_size": VIDEO_TIMESTAMP_SAMPLE_SIZE,
|
||||
"timestamp_unit": self._latest_timestamp_unit,
|
||||
"timestamp_endianness": self._latest_timestamp_endianness,
|
||||
"unsynced_clock": True,
|
||||
}
|
||||
else:
|
||||
timing_status = {
|
||||
"available": False,
|
||||
"latest_delta_ms": None,
|
||||
"delta_samples_ms": [],
|
||||
"sender_clock_delta_ms_raw": None,
|
||||
"sender_clock_delta_samples_ms_raw": [],
|
||||
"sample_count": 0,
|
||||
"sample_window_size": VIDEO_TIMESTAMP_SAMPLE_SIZE,
|
||||
"timestamp_unit": None,
|
||||
"timestamp_endianness": None,
|
||||
"unsynced_clock": True,
|
||||
}
|
||||
return {
|
||||
"backend_ready": self._session_cls is not None,
|
||||
@@ -335,6 +648,11 @@ class OmniSocketVideoReceiver:
|
||||
"has_recent_frame": has_recent_frame,
|
||||
"frames_received": self._frames_received,
|
||||
"latest_sequence": self._latest_sequence,
|
||||
"latest_frame_hash": self._latest_frame_hash,
|
||||
"latest_backend_received_unix_ns": self._latest_backend_received_unix_ns or None,
|
||||
"latest_backend_received_mono_ns": self._latest_backend_received_mono_ns or None,
|
||||
"latest_frame_bytes": self._latest_frame_bytes,
|
||||
"latest_capture_to_send_ms": self._latest_metadata.capture_to_send_ms if self._latest_metadata is not None else None,
|
||||
"reconnect_count": self._reconnect_count,
|
||||
"last_server_error": str(session_stats.get("last_server_error", "") or ""),
|
||||
"last_error": self._last_error,
|
||||
@@ -344,6 +662,7 @@ class OmniSocketVideoReceiver:
|
||||
"peer_id": str(video_cfg.get("peer_id", "")),
|
||||
"buffer_bytes": int(video_cfg.get("buffer_bytes", 0)),
|
||||
"timing": timing_status,
|
||||
"freshness": freshness_status,
|
||||
}
|
||||
|
||||
def close(self) -> None:
|
||||
@@ -358,15 +677,18 @@ class OmniSocketVideoReceiver:
|
||||
thread = self._thread
|
||||
if thread is not None and thread.is_alive():
|
||||
thread.join(timeout=0.5)
|
||||
self._frame_recv_logger.close()
|
||||
|
||||
|
||||
class VideoFrameService:
|
||||
def __init__(self, receiver: OmniSocketVideoReceiver) -> None:
|
||||
def __init__(self, receiver: OmniSocketVideoReceiver, display_probe_store: VideoDisplayProbeStore) -> None:
|
||||
self._receiver = receiver
|
||||
self._display_probe_store = display_probe_store
|
||||
|
||||
def get_status(self) -> dict[str, Any]:
|
||||
receiver_status = self._receiver.get_status()
|
||||
receiver_frame = self._receiver.get_latest_frame()
|
||||
display_probe_status = self._display_probe_store.get_status()
|
||||
|
||||
if receiver_frame is not None:
|
||||
return {
|
||||
@@ -378,6 +700,8 @@ class VideoFrameService:
|
||||
"source_detail": f"peer stream active, frames={receiver_status['frames_received']}",
|
||||
"receiver": receiver_status,
|
||||
"timing": receiver_status["timing"],
|
||||
"freshness": receiver_status.get("freshness", {}),
|
||||
"display_probe": display_probe_status,
|
||||
}
|
||||
|
||||
wait_detail = receiver_status["last_error"] or (
|
||||
@@ -392,6 +716,8 @@ class VideoFrameService:
|
||||
"source_detail": wait_detail,
|
||||
"receiver": receiver_status,
|
||||
"timing": receiver_status["timing"],
|
||||
"freshness": receiver_status.get("freshness", {}),
|
||||
"display_probe": display_probe_status,
|
||||
}
|
||||
|
||||
def get_next_frame(self) -> bytes:
|
||||
@@ -400,6 +726,18 @@ class VideoFrameService:
|
||||
return receiver_frame
|
||||
raise RuntimeError("no live OmniSocket JPEG frame is currently available")
|
||||
|
||||
def get_next_frame_with_headers(self) -> tuple[bytes, dict[str, str]]:
|
||||
snapshot = self._receiver.get_latest_frame_snapshot()
|
||||
if snapshot is not None:
|
||||
return snapshot
|
||||
raise RuntimeError("no live OmniSocket JPEG frame is currently available")
|
||||
|
||||
def get_latest_frame_headers(self) -> dict[str, str]:
|
||||
return self._receiver.get_latest_frame_headers()
|
||||
|
||||
def record_display_probe(self, payload: dict[str, Any]) -> None:
|
||||
self._display_probe_store.record_event(payload)
|
||||
|
||||
def iter_mjpeg(self, fps: float = 6.0) -> Iterator[bytes]:
|
||||
frame_interval = 1.0 / max(1.0, min(fps, 30.0))
|
||||
while True:
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.http import HttpResponse, StreamingHttpResponse
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
@@ -28,31 +32,40 @@ def network_latest(request):
|
||||
return Response(network_service.get_latest())
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
def clock_calibration(request):
|
||||
server_received_unix_ns = time.time_ns()
|
||||
server_sent_unix_ns = time.time_ns()
|
||||
response = Response(
|
||||
{
|
||||
"server_received_unix_ms": round(server_received_unix_ns / 1_000_000.0, 3),
|
||||
"server_sent_unix_ms": round(server_sent_unix_ns / 1_000_000.0, 3),
|
||||
}
|
||||
)
|
||||
response["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
||||
return response
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
def video_status(request):
|
||||
return Response(video_service.get_status())
|
||||
|
||||
|
||||
def video_frame(request):
|
||||
status = video_service.get_status()
|
||||
if not status["available"]:
|
||||
return HttpResponse(
|
||||
status.get("source_detail") or f"JPEG frame directory not found: {status['frame_dir']}",
|
||||
status=503,
|
||||
content_type="text/plain; charset=utf-8",
|
||||
)
|
||||
|
||||
try:
|
||||
frame = video_service.get_next_frame()
|
||||
frame, headers = video_service.get_next_frame_with_headers()
|
||||
except (FileNotFoundError, RuntimeError) as error:
|
||||
status = video_service.get_status()
|
||||
return HttpResponse(
|
||||
str(error),
|
||||
status.get("source_detail") or str(error),
|
||||
status=503,
|
||||
content_type="text/plain; charset=utf-8",
|
||||
)
|
||||
|
||||
response = HttpResponse(frame, content_type="image/jpeg")
|
||||
response["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
||||
for key, value in headers.items():
|
||||
response[key] = value
|
||||
return response
|
||||
|
||||
|
||||
@@ -76,3 +89,18 @@ def video_stream(request):
|
||||
)
|
||||
response["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
||||
return response
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@api_view(["POST"])
|
||||
def video_display_probe(request):
|
||||
try:
|
||||
payload = json.loads(request.body.decode("utf-8"))
|
||||
except (UnicodeDecodeError, json.JSONDecodeError):
|
||||
return Response({"detail": "invalid json"}, status=400)
|
||||
|
||||
if not isinstance(payload, dict):
|
||||
return Response({"detail": "expected json object"}, status=400)
|
||||
|
||||
video_service.record_display_probe(payload)
|
||||
return Response({"ok": True})
|
||||
|
||||
@@ -12,6 +12,10 @@ control_sender:
|
||||
peer_id: "peer-a-ctrl"
|
||||
target_peer: "peer-b-ctrl"
|
||||
|
||||
control_ack_receiver:
|
||||
peer_id: "peer-a-ctrl-ack"
|
||||
expected_sender: "peer-b-ctrl-ack"
|
||||
|
||||
control_ingress:
|
||||
native_udp_bind: "127.0.0.1:10921"
|
||||
source_lease_ms: 300
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { RouterLink, RouterView } from 'vue-router'
|
||||
|
||||
const navItems = [
|
||||
{ to: '/', label: '总览' },
|
||||
{ to: '/video', label: '视频流' },
|
||||
{ to: '/map', label: '地图定位' },
|
||||
{ to: '/network', label: '网络状态' },
|
||||
]
|
||||
import { useLocale } from '@/lib/locale'
|
||||
|
||||
const { t, toggleLocale, nextLocaleLabel } = useLocale()
|
||||
|
||||
const navItems = computed(() => [
|
||||
{ to: '/', label: t('app.nav.overview') },
|
||||
{ to: '/video', label: t('app.nav.video') },
|
||||
{ to: '/map', label: t('app.nav.map') },
|
||||
{ to: '/network', label: t('app.nav.network') },
|
||||
])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -15,21 +20,27 @@ const navItems = [
|
||||
<div class="brand">
|
||||
<p class="brand-mark">RCC</p>
|
||||
<div>
|
||||
<strong>Robot Command Center</strong>
|
||||
<span>机器人竞赛指挥台</span>
|
||||
<strong>{{ t('app.brandTitle') }}</strong>
|
||||
<span>{{ t('app.brandSubtitle') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="nav">
|
||||
<RouterLink
|
||||
v-for="item in navItems"
|
||||
:key="item.to"
|
||||
:to="item.to"
|
||||
class="nav-link"
|
||||
>
|
||||
{{ item.label }}
|
||||
</RouterLink>
|
||||
</nav>
|
||||
<div class="topbar-actions">
|
||||
<nav class="nav">
|
||||
<RouterLink
|
||||
v-for="item in navItems"
|
||||
:key="item.to"
|
||||
:to="item.to"
|
||||
class="nav-link"
|
||||
>
|
||||
{{ item.label }}
|
||||
</RouterLink>
|
||||
</nav>
|
||||
|
||||
<button type="button" class="locale-button" @click="toggleLocale">
|
||||
{{ nextLocaleLabel }}
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="page-body">
|
||||
@@ -128,6 +139,14 @@ const navItems = [
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.topbar-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.nav {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
@@ -135,7 +154,8 @@ const navItems = [
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
.nav-link,
|
||||
.locale-button {
|
||||
padding: 10px 14px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(133, 147, 169, 0.18);
|
||||
@@ -148,7 +168,8 @@ const navItems = [
|
||||
border-color 0.2s ease;
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
.nav-link:hover,
|
||||
.locale-button:hover {
|
||||
transform: translateY(-1px);
|
||||
background: rgba(25, 38, 66, 0.9);
|
||||
}
|
||||
@@ -160,6 +181,13 @@ const navItems = [
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.locale-button {
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.page-body {
|
||||
display: grid;
|
||||
}
|
||||
@@ -170,6 +198,7 @@ const navItems = [
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.topbar-actions,
|
||||
.nav {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
@@ -180,6 +209,7 @@ const navItems = [
|
||||
width: min(100%, calc(100% - 20px));
|
||||
}
|
||||
|
||||
.topbar-actions,
|
||||
.nav {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { useControlInterface } from '@/composables/useControlInterface'
|
||||
import { t } from '@/lib/locale'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
compact?: boolean
|
||||
@@ -51,22 +52,43 @@ const keyClusters = computed(() => {
|
||||
|
||||
const commandBars = computed(() => [
|
||||
{
|
||||
label: 'Forward',
|
||||
label: t('controlFeedback.forward'),
|
||||
value: commandValues.value.lx,
|
||||
max: controlLimits.value.forward,
|
||||
},
|
||||
{
|
||||
label: 'Strafe',
|
||||
label: t('controlFeedback.strafe'),
|
||||
value: commandValues.value.ly,
|
||||
max: controlLimits.value.strafe,
|
||||
},
|
||||
{
|
||||
label: 'Turn',
|
||||
label: t('controlFeedback.turn'),
|
||||
value: commandValues.value.az,
|
||||
max: controlLimits.value.turn,
|
||||
},
|
||||
])
|
||||
|
||||
const tuningSummary = computed(() =>
|
||||
t('controlFeedback.tuningSummary', {
|
||||
forward: controlTuning.value.forward.toFixed(2),
|
||||
strafe: controlTuning.value.strafe.toFixed(2),
|
||||
turn: controlTuning.value.turn.toFixed(2),
|
||||
turbo: controlTuning.value.turbo.toFixed(2),
|
||||
}),
|
||||
)
|
||||
|
||||
const gamepadMeta = computed(() => {
|
||||
if (!gamepadConnected.value) {
|
||||
return t('controlFeedback.gamepadHint')
|
||||
}
|
||||
return t('controlFeedback.gamepadMeta', {
|
||||
index: gamepadIndex.value ?? '--',
|
||||
mapping: gamepadMapping.value || t('control.gamepad.unknownMapping'),
|
||||
})
|
||||
})
|
||||
|
||||
const outgoingCommandText = computed(() => t('controlFeedback.outgoingCommand', { command: commandLabel.value }))
|
||||
|
||||
function meterPosition(value: number, max: number) {
|
||||
const normalized = Math.max(-1, Math.min(1, value / max))
|
||||
return `${50 + normalized * 45}%`
|
||||
@@ -85,7 +107,7 @@ function stickOffset(value: number) {
|
||||
{{ activeSourceLabel }}
|
||||
</div>
|
||||
<div class="input-chip">
|
||||
{{ controlInputModeLabel }} mode
|
||||
{{ t('controlFeedback.modeChip', { mode: controlInputModeLabel }) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-stack">
|
||||
@@ -112,19 +134,18 @@ function stickOffset(value: number) {
|
||||
</div>
|
||||
|
||||
<p class="summary">
|
||||
Tuning: fwd {{ controlTuning.forward.toFixed(2) }} m/s, strafe {{ controlTuning.strafe.toFixed(2) }} m/s,
|
||||
turn {{ controlTuning.turn.toFixed(2) }} rad/s, turbo x{{ controlTuning.turbo.toFixed(2) }}
|
||||
{{ tuningSummary }}
|
||||
</p>
|
||||
|
||||
<div class="feedback-grid" :class="{ compact }">
|
||||
<section class="feedback-card">
|
||||
<div class="card-head">
|
||||
<div>
|
||||
<p class="label">Keyboard</p>
|
||||
<p class="label">{{ t('controlFeedback.keyboard') }}</p>
|
||||
<strong>{{ pressedKeysLabel }}</strong>
|
||||
</div>
|
||||
<span class="mode-chip" :class="{ hot: controlInputMode === 'keyboard' && keyboardActive }">
|
||||
{{ controlInputMode === 'keyboard' ? (keyboardTurbo ? 'Turbo' : 'Selected') : 'Standby' }}
|
||||
{{ controlInputMode === 'keyboard' ? (keyboardTurbo ? t('common.turbo') : t('common.selected')) : t('common.standby') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -143,31 +164,27 @@ function stickOffset(value: number) {
|
||||
<section class="feedback-card">
|
||||
<div class="card-head">
|
||||
<div>
|
||||
<p class="label">Gamepad</p>
|
||||
<strong>{{ gamepadConnected ? gamepadName : 'Waiting for controller' }}</strong>
|
||||
<p class="label">{{ t('controlFeedback.gamepad') }}</p>
|
||||
<strong>{{ gamepadConnected ? gamepadName : t('controlFeedback.waitingForController') }}</strong>
|
||||
</div>
|
||||
<span class="mode-chip" :class="{ hot: controlInputMode === 'gamepad' && gamepadActive }">
|
||||
{{
|
||||
gamepadConnected
|
||||
? controlInputMode === 'gamepad'
|
||||
? 'Selected'
|
||||
: 'Standby'
|
||||
: 'Offline'
|
||||
? t('common.selected')
|
||||
: t('common.standby')
|
||||
: t('common.offline')
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<p class="subtle">
|
||||
{{
|
||||
gamepadConnected
|
||||
? `#${gamepadIndex} / mapping=${gamepadMapping || 'unknown'}`
|
||||
: 'Left stick drives, right stick turns, RB boosts, A stops.'
|
||||
}}
|
||||
{{ gamepadMeta }}
|
||||
</p>
|
||||
|
||||
<div class="sticks">
|
||||
<div class="stick-card">
|
||||
<span>Left stick</span>
|
||||
<span>{{ t('controlFeedback.leftStick') }}</span>
|
||||
<div class="stick-pad">
|
||||
<span class="crosshair crosshair-x" />
|
||||
<span class="crosshair crosshair-y" />
|
||||
@@ -181,7 +198,7 @@ function stickOffset(value: number) {
|
||||
</div>
|
||||
|
||||
<div class="stick-card">
|
||||
<span>Right stick</span>
|
||||
<span>{{ t('controlFeedback.rightStick') }}</span>
|
||||
<div class="stick-pad">
|
||||
<span class="crosshair crosshair-x" />
|
||||
<span class="crosshair crosshair-y" />
|
||||
@@ -209,7 +226,7 @@ function stickOffset(value: number) {
|
||||
</div>
|
||||
|
||||
<p v-if="!compact" class="summary accent">
|
||||
Outgoing command: {{ commandLabel }}
|
||||
{{ outgoingCommandText }}
|
||||
</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -3,14 +3,16 @@ import { computed } from 'vue'
|
||||
|
||||
import ControlFeedback from '@/components/ControlFeedback.vue'
|
||||
import { useControlInterface } from '@/composables/useControlInterface'
|
||||
import { useLocale } from '@/lib/locale'
|
||||
|
||||
const { controlInputMode, controlInputModeLabel, controlTuning, resetControlTuning, setControlInputMode, setControlTuning } =
|
||||
useControlInterface()
|
||||
const { t } = useLocale()
|
||||
|
||||
const inputModes = [
|
||||
{ id: 'keyboard', label: 'Keyboard', detail: 'Use W/S, A/D, Q/E, Shift, and Space.' },
|
||||
{ id: 'gamepad', label: 'Gamepad', detail: 'Use the browser-detected controller only.' },
|
||||
] as const
|
||||
const inputModes = computed(() => [
|
||||
{ id: 'keyboard', label: t('common.keyboard'), detail: t('controlPanel.keyboardDetail') },
|
||||
{ id: 'gamepad', label: t('common.gamepad'), detail: t('controlPanel.gamepadDetail') },
|
||||
] as const)
|
||||
|
||||
const forwardSpeed = computed({
|
||||
get: () => controlTuning.value.forward,
|
||||
@@ -37,24 +39,24 @@ const turboMultiplier = computed({
|
||||
<section class="panel control-panel">
|
||||
<div class="panel-head">
|
||||
<div>
|
||||
<p class="eyebrow">Control</p>
|
||||
<h2>Control Feedback</h2>
|
||||
<p class="eyebrow">{{ t('controlPanel.eyebrow') }}</p>
|
||||
<h2>{{ t('controlPanel.title') }}</h2>
|
||||
</div>
|
||||
<button type="button" class="reset-button" @click="resetControlTuning">
|
||||
Reset Defaults
|
||||
{{ t('controlPanel.resetDefaults') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<section class="mode-panel">
|
||||
<div class="mode-panel-head">
|
||||
<div>
|
||||
<p class="mode-eyebrow">Input Mode</p>
|
||||
<p class="mode-copy">Only one local input mode can control the page at a time.</p>
|
||||
<p class="mode-eyebrow">{{ t('controlPanel.inputModeEyebrow') }}</p>
|
||||
<p class="mode-copy">{{ t('controlPanel.inputModeCopy') }}</p>
|
||||
</div>
|
||||
<strong class="mode-current">{{ controlInputModeLabel }}</strong>
|
||||
</div>
|
||||
|
||||
<div class="mode-toggle" role="radiogroup" aria-label="Control input mode">
|
||||
<div class="mode-toggle" role="radiogroup" :aria-label="t('controlPanel.inputModeEyebrow')">
|
||||
<button
|
||||
v-for="mode in inputModes"
|
||||
:key="mode.id"
|
||||
@@ -72,25 +74,25 @@ const turboMultiplier = computed({
|
||||
|
||||
<div class="tuning-grid">
|
||||
<label class="tuning-field">
|
||||
<span>Forward</span>
|
||||
<span>{{ t('controlPanel.forward') }}</span>
|
||||
<input v-model.number="forwardSpeed" type="number" min="0.05" max="3" step="0.05" />
|
||||
<small>m/s</small>
|
||||
</label>
|
||||
|
||||
<label class="tuning-field">
|
||||
<span>Strafe</span>
|
||||
<span>{{ t('controlPanel.strafe') }}</span>
|
||||
<input v-model.number="strafeSpeed" type="number" min="0.05" max="3" step="0.05" />
|
||||
<small>m/s</small>
|
||||
</label>
|
||||
|
||||
<label class="tuning-field">
|
||||
<span>Turn</span>
|
||||
<span>{{ t('controlPanel.turn') }}</span>
|
||||
<input v-model.number="turnSpeed" type="number" min="0.05" max="3" step="0.05" />
|
||||
<small>rad/s</small>
|
||||
</label>
|
||||
|
||||
<label class="tuning-field">
|
||||
<span>Turbo</span>
|
||||
<span>{{ t('controlPanel.turbo') }}</span>
|
||||
<input v-model.number="turboMultiplier" type="number" min="1" max="3" step="0.1" />
|
||||
<small>x</small>
|
||||
</label>
|
||||
@@ -99,15 +101,13 @@ const turboMultiplier = computed({
|
||||
<ControlFeedback />
|
||||
|
||||
<p class="hint">
|
||||
Keyboard mapping: <code>W/S</code> forward-back, <code>A/D</code> strafe, <code>Q/E</code> turn,
|
||||
<code>Shift</code> turbo, <code>Space</code> stop.
|
||||
{{ t('controlPanel.keyboardHint') }}
|
||||
</p>
|
||||
<p class="hint subtle">
|
||||
Speed tuning is shared by both local input modes and is saved in this browser.
|
||||
{{ t('controlPanel.tuningHint') }}
|
||||
</p>
|
||||
<p class="hint subtle">
|
||||
Browser gamepad mode uses the left stick to drive, the right stick to turn,
|
||||
<code>RB</code> to boost, and <code>A</code> to send stop.
|
||||
{{ t('controlPanel.gamepadHint') }}
|
||||
</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
|
||||
import { formatDateTime, useLocale, type MessageKey } from '@/lib/locale'
|
||||
import type { GpsTelemetry } from '@/types'
|
||||
|
||||
declare global {
|
||||
@@ -16,12 +17,19 @@ const props = defineProps<{
|
||||
gps: GpsTelemetry | null
|
||||
}>()
|
||||
|
||||
const { locale, t } = useLocale()
|
||||
|
||||
const STORAGE_KEY = 'robot_command_center_amap'
|
||||
|
||||
type StatusState = {
|
||||
key: MessageKey
|
||||
params?: Record<string, string | number | null | undefined>
|
||||
}
|
||||
|
||||
const keyInput = ref('')
|
||||
const securityCodeInput = ref('')
|
||||
const statusText = ref('等待加载高德地图。')
|
||||
const amapCoordinateText = ref('暂无')
|
||||
const statusState = ref<StatusState>({ key: 'gpsMap.status.waitingInit' })
|
||||
const amapCoordinateRaw = ref('')
|
||||
const mapElement = ref<HTMLDivElement | null>(null)
|
||||
const mapRunning = ref(false)
|
||||
|
||||
@@ -30,6 +38,12 @@ let mapInstance: any = null
|
||||
let marker: any = null
|
||||
let infoWindow: any = null
|
||||
|
||||
function setStatus(key: MessageKey, params?: Record<string, string | number | null | undefined>) {
|
||||
statusState.value = { key, params }
|
||||
}
|
||||
|
||||
const statusText = computed(() => t(statusState.value.key, statusState.value.params))
|
||||
|
||||
function readSavedCredentials() {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
@@ -53,6 +67,10 @@ function formatNumber(value: number) {
|
||||
return value.toFixed(6)
|
||||
}
|
||||
|
||||
function formatHexText(value: string | null | undefined) {
|
||||
return value || t('gpsMap.noValue')
|
||||
}
|
||||
|
||||
async function loadAmapScript(key: string, securityJsCode: string) {
|
||||
if (window.AMap) {
|
||||
return window.AMap
|
||||
@@ -69,7 +87,7 @@ async function loadAmapScript(key: string, securityJsCode: string) {
|
||||
script.src = `https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(key)}`
|
||||
script.async = true
|
||||
script.onload = () => resolve(window.AMap)
|
||||
script.onerror = () => reject(new Error('高德地图脚本加载失败,请检查 Key / jscode 和网络。'))
|
||||
script.onerror = () => reject(new Error(t('gpsMap.status.loadFailed')))
|
||||
document.head.appendChild(script)
|
||||
})
|
||||
|
||||
@@ -90,7 +108,7 @@ function ensureMap() {
|
||||
|
||||
marker = new window.AMap.Marker({
|
||||
anchor: 'bottom-center',
|
||||
title: 'Robot GPS',
|
||||
title: t('gpsMap.infoTitle'),
|
||||
})
|
||||
|
||||
infoWindow = new window.AMap.InfoWindow({
|
||||
@@ -100,7 +118,7 @@ function ensureMap() {
|
||||
|
||||
function stopMap() {
|
||||
mapRunning.value = false
|
||||
amapCoordinateText.value = '已停止'
|
||||
amapCoordinateRaw.value = ''
|
||||
|
||||
if (infoWindow) {
|
||||
infoWindow.close()
|
||||
@@ -124,7 +142,23 @@ function stopMap() {
|
||||
mapElement.value.innerHTML = ''
|
||||
}
|
||||
|
||||
statusText.value = '已停止高德地图加载与坐标转换。需要时再点击“加载地图”即可。'
|
||||
setStatus('gpsMap.status.stopped')
|
||||
}
|
||||
|
||||
function buildInfoWindowContent(gps: GpsTelemetry, lat: number, lng: number) {
|
||||
const altitudeText = gps.altitude_m == null ? t('common.unknown') : `${gps.altitude_m} m`
|
||||
return [
|
||||
'<div style="min-width: 240px; padding: 6px 2px; line-height: 1.75; font-size: 13px; color: #152033;">',
|
||||
`<div style="margin-bottom: 8px; font-size: 14px; font-weight: 700; color: #0f172a;">${t('gpsMap.infoTitle')}</div>`,
|
||||
`<div><span style="color: #667085;">${t('gpsMap.wgs84')}:</span> <strong style="color: #0f172a;">${formatNumber(gps.latitude!)}, ${formatNumber(gps.longitude!)}</strong></div>`,
|
||||
`<div><span style="color: #667085;">${t('gpsMap.gcj02')}:</span> <strong style="color: #0f172a;">${formatNumber(lat)}, ${formatNumber(lng)}</strong></div>`,
|
||||
`<div><span style="color: #667085;">${t('gpsMap.rawLatHex')}:</span> <strong style="color: #0f172a;">${formatHexText(gps.raw_latitude_hex)}</strong></div>`,
|
||||
`<div><span style="color: #667085;">${t('gpsMap.rawLonHex')}:</span> <strong style="color: #0f172a;">${formatHexText(gps.raw_longitude_hex)}</strong></div>`,
|
||||
`<div><span style="color: #667085;">${t('gpsMap.utcTime')}:</span> <strong style="color: #0f172a;">${gps.utc_time || '--:--:--'}</strong></div>`,
|
||||
`<div><span style="color: #667085;">${t('gpsMap.infoSatellites')}:</span> <strong style="color: #0f172a;">${gps.satellites ?? t('common.unknown')}</strong></div>`,
|
||||
`<div><span style="color: #667085;">${t('gpsMap.infoAltitude')}:</span> <strong style="color: #0f172a;">${altitudeText}</strong></div>`,
|
||||
'</div>',
|
||||
].join('')
|
||||
}
|
||||
|
||||
function updateMap(gps: GpsTelemetry | null) {
|
||||
@@ -133,10 +167,10 @@ function updateMap(gps: GpsTelemetry | null) {
|
||||
}
|
||||
|
||||
if (!gps?.has_fix || gps.latitude == null || gps.longitude == null) {
|
||||
amapCoordinateText.value = '暂无'
|
||||
amapCoordinateRaw.value = ''
|
||||
marker?.setMap(null)
|
||||
infoWindow?.close()
|
||||
statusText.value = gps ? 'GPS 在线,但当前还没有有效定位。' : '等待 GPS 数据。'
|
||||
setStatus(gps ? 'gpsMap.status.noFix' : 'gpsMap.status.waitingGps')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -145,7 +179,7 @@ function updateMap(gps: GpsTelemetry | null) {
|
||||
|
||||
window.AMap.convertFrom([rawLongitude, rawLatitude], 'gps', (status: string, result: any) => {
|
||||
if (status !== 'complete' || !result?.locations?.length) {
|
||||
statusText.value = 'GPS 坐标转换失败。'
|
||||
setStatus('gpsMap.status.convertFailed')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -153,25 +187,14 @@ function updateMap(gps: GpsTelemetry | null) {
|
||||
const lng = typeof point.getLng === 'function' ? point.getLng() : point.lng
|
||||
const lat = typeof point.getLat === 'function' ? point.getLat() : point.lat
|
||||
|
||||
amapCoordinateText.value = `${formatNumber(lat)}, ${formatNumber(lng)}`
|
||||
amapCoordinateRaw.value = `${formatNumber(lat)}, ${formatNumber(lng)}`
|
||||
marker.setPosition([lng, lat])
|
||||
marker.setMap(mapInstance)
|
||||
|
||||
infoWindow.setContent(
|
||||
[
|
||||
'<div style="min-width: 240px; padding: 6px 2px; line-height: 1.75; font-size: 13px; color: #152033;">',
|
||||
'<div style="margin-bottom: 8px; font-size: 14px; font-weight: 700; color: #0f172a;">Robot GPS 定位</div>',
|
||||
`<div><span style="color: #667085;">原始 WGS84:</span> <strong style="color: #0f172a;">${formatNumber(rawLatitude)}, ${formatNumber(rawLongitude)}</strong></div>`,
|
||||
`<div><span style="color: #667085;">高德 GCJ-02:</span> <strong style="color: #0f172a;">${formatNumber(lat)}, ${formatNumber(lng)}</strong></div>`,
|
||||
`<div><span style="color: #667085;">UTC 时间:</span> <strong style="color: #0f172a;">${gps.utc_time || '--:--:--'}</strong></div>`,
|
||||
`<div><span style="color: #667085;">卫星数:</span> <strong style="color: #0f172a;">${gps.satellites ?? '未知'}</strong></div>`,
|
||||
`<div><span style="color: #667085;">海拔:</span> <strong style="color: #0f172a;">${gps.altitude_m ?? '未知'} m</strong></div>`,
|
||||
'</div>',
|
||||
].join(''),
|
||||
)
|
||||
infoWindow.setContent(buildInfoWindowContent(gps, lat, lng))
|
||||
infoWindow.open(mapInstance, [lng, lat])
|
||||
mapInstance.setZoomAndCenter(17, [lng, lat])
|
||||
statusText.value = `地图已刷新,数据源:${gps.source_mode}`
|
||||
setStatus('gpsMap.status.refreshedSource', { source: gps.source_mode })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -180,47 +203,55 @@ async function startMap() {
|
||||
const securityJsCode = securityCodeInput.value.trim()
|
||||
|
||||
if (!key || !securityJsCode) {
|
||||
statusText.value = '请先填写高德 Key 和安全密钥 jscode。'
|
||||
setStatus('gpsMap.status.fillCredentials')
|
||||
return
|
||||
}
|
||||
|
||||
statusText.value = '正在加载高德地图...'
|
||||
setStatus('gpsMap.status.loading')
|
||||
|
||||
try {
|
||||
await loadAmapScript(key, securityJsCode)
|
||||
ensureMap()
|
||||
saveCredentials()
|
||||
mapRunning.value = true
|
||||
statusText.value = '地图已加载。'
|
||||
setStatus('gpsMap.status.loaded')
|
||||
updateMap(props.gps)
|
||||
} catch (error) {
|
||||
statusText.value = error instanceof Error ? error.message : '地图加载失败。'
|
||||
setStatus('gpsMap.status.loadFailed')
|
||||
if (error instanceof Error && error.message) {
|
||||
statusState.value = { key: 'gpsMap.status.loadFailed', params: { message: error.message } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rawCoordinateText = computed(() => {
|
||||
if (!props.gps?.has_fix || props.gps.latitude == null || props.gps.longitude == null) {
|
||||
return '暂无有效定位'
|
||||
return t('gpsMap.noValidFix')
|
||||
}
|
||||
|
||||
return `${formatNumber(props.gps.latitude)}, ${formatNumber(props.gps.longitude)}`
|
||||
})
|
||||
|
||||
const amapCoordinateText = computed(() => amapCoordinateRaw.value || t('gpsMap.noValue'))
|
||||
const rawLatitudeHexText = computed(() => formatHexText(props.gps?.raw_latitude_hex))
|
||||
const rawLongitudeHexText = computed(() => formatHexText(props.gps?.raw_longitude_hex))
|
||||
|
||||
const coordinateMetaText = computed(() => {
|
||||
if (!props.gps) {
|
||||
return t('gpsMap.noValue')
|
||||
}
|
||||
return `${props.gps.coordinate_system} / ${props.gps.raw_coordinate_format}`
|
||||
})
|
||||
|
||||
const metaText = computed(() => {
|
||||
if (!props.gps) {
|
||||
return '暂无'
|
||||
return t('gpsMap.noValue')
|
||||
}
|
||||
const satellites = props.gps.satellites ?? '未知'
|
||||
const altitude = props.gps.altitude_m == null ? '未知' : `${props.gps.altitude_m} m`
|
||||
return `${satellites} 颗 / ${altitude}`
|
||||
const satellites = props.gps.satellites ?? t('common.unknown')
|
||||
const altitude = props.gps.altitude_m == null ? t('common.unknown') : `${props.gps.altitude_m} m`
|
||||
return `${satellites} / ${altitude}`
|
||||
})
|
||||
|
||||
const updatedAtText = computed(() => {
|
||||
if (!props.gps?.updated_at) {
|
||||
return '暂无'
|
||||
}
|
||||
return new Date(props.gps.updated_at).toLocaleString('zh-CN', { hour12: false })
|
||||
})
|
||||
const updatedAtText = computed(() => formatDateTime(props.gps?.updated_at))
|
||||
|
||||
onMounted(() => {
|
||||
const saved = readSavedCredentials()
|
||||
@@ -228,7 +259,7 @@ onMounted(() => {
|
||||
keyInput.value = saved.key ?? ''
|
||||
securityCodeInput.value = saved.securityJsCode ?? ''
|
||||
if (keyInput.value && securityCodeInput.value) {
|
||||
statusText.value = '已恢复高德配置。高德地图不会自动加载,请按需点击“加载地图”。'
|
||||
setStatus('gpsMap.status.restoredConfig')
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -240,62 +271,76 @@ watch(
|
||||
},
|
||||
{ deep: true },
|
||||
)
|
||||
|
||||
watch(
|
||||
() => locale.value,
|
||||
() => {
|
||||
if (mapRunning.value) {
|
||||
updateMap(props.gps)
|
||||
}
|
||||
},
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="panel map-panel">
|
||||
<div class="panel-head">
|
||||
<div>
|
||||
<p class="eyebrow">GPS</p>
|
||||
<h2>地图定位</h2>
|
||||
<p class="eyebrow">{{ t('gpsMap.eyebrow') }}</p>
|
||||
<h2>{{ t('gpsMap.title') }}</h2>
|
||||
</div>
|
||||
<span class="badge">{{ gps?.source_mode ?? 'loading' }}</span>
|
||||
<span class="badge">{{ gps?.source_mode ?? t('common.loading') }}</span>
|
||||
</div>
|
||||
|
||||
<p class="intro">
|
||||
这里复用了你原来 `GeoStream/gps_map.html` 的高德地图思路。后端优先读取
|
||||
`GeoStream/gps_latest.json`,所以你运行 `parse_gps.c` 生成数据后,这里会直接接上。
|
||||
</p>
|
||||
<p class="intro">{{ t('gpsMap.intro') }}</p>
|
||||
|
||||
<div class="credentials">
|
||||
<input v-model="keyInput" type="text" placeholder="高德 Web 端 Key" />
|
||||
<input v-model="securityCodeInput" type="text" placeholder="安全密钥 jscode" />
|
||||
<button type="button" @click="startMap">加载地图</button>
|
||||
<button type="button" class="secondary" @click="stopMap">停止加载</button>
|
||||
<input v-model="keyInput" type="text" :placeholder="t('gpsMap.keyPlaceholder')" />
|
||||
<input v-model="securityCodeInput" type="text" :placeholder="t('gpsMap.jscodePlaceholder')" />
|
||||
<button type="button" @click="startMap">{{ t('gpsMap.loadMap') }}</button>
|
||||
<button type="button" class="secondary" @click="stopMap">{{ t('gpsMap.stopMap') }}</button>
|
||||
</div>
|
||||
|
||||
<div class="status">{{ statusText }}</div>
|
||||
|
||||
<div class="details">
|
||||
<div class="detail-card">
|
||||
<span>原始 WGS84</span>
|
||||
<span>{{ t('gpsMap.wgs84') }}</span>
|
||||
<strong>{{ rawCoordinateText }}</strong>
|
||||
</div>
|
||||
<div class="detail-card">
|
||||
<span>高德 GCJ-02</span>
|
||||
<span>{{ t('gpsMap.gcj02') }}</span>
|
||||
<strong>{{ amapCoordinateText }}</strong>
|
||||
</div>
|
||||
<div class="detail-card">
|
||||
<span>UTC 时间</span>
|
||||
<span>{{ t('gpsMap.rawLatHex') }}</span>
|
||||
<strong class="mono">{{ rawLatitudeHexText }}</strong>
|
||||
</div>
|
||||
<div class="detail-card">
|
||||
<span>{{ t('gpsMap.rawLonHex') }}</span>
|
||||
<strong class="mono">{{ rawLongitudeHexText }}</strong>
|
||||
</div>
|
||||
<div class="detail-card">
|
||||
<span>{{ t('gpsMap.utcTime') }}</span>
|
||||
<strong>{{ gps?.utc_time ?? '--:--:--' }}</strong>
|
||||
</div>
|
||||
<div class="detail-card">
|
||||
<span>卫星 / 海拔</span>
|
||||
<span>{{ t('gpsMap.satAltitude') }}</span>
|
||||
<strong>{{ metaText }}</strong>
|
||||
</div>
|
||||
<div class="detail-card">
|
||||
<span>坐标系</span>
|
||||
<strong>{{ gps?.coordinate_system ?? 'WGS84' }}</strong>
|
||||
<span>{{ t('gpsMap.coordMeta') }}</span>
|
||||
<strong>{{ coordinateMetaText }}</strong>
|
||||
</div>
|
||||
<div class="detail-card">
|
||||
<span>最近刷新</span>
|
||||
<span>{{ t('gpsMap.lastUpdated') }}</span>
|
||||
<strong>{{ updatedAtText }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div ref="mapElement" class="map-canvas" :class="{ stopped: !mapRunning }">
|
||||
<div v-if="!mapRunning" class="map-placeholder">
|
||||
高德地图当前未加载。点击上方“加载地图”后才会开始请求地图与坐标转换服务。
|
||||
{{ t('gpsMap.mapPlaceholder') }}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -397,6 +442,11 @@ h2 {
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.detail-card strong.mono {
|
||||
font-family: 'JetBrains Mono', 'SFMono-Regular', monospace;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.map-canvas {
|
||||
position: relative;
|
||||
min-height: 420px;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { formatDateTime, t } from '@/lib/locale'
|
||||
import type { LinkSessionTelemetry, LinkTelemetry, NetworkTelemetry } from '@/types'
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -20,19 +21,19 @@ const legCards = computed(() => [
|
||||
},
|
||||
])
|
||||
|
||||
const activeSource = computed(() => props.network?.active_control_source ?? 'none')
|
||||
const activeSource = computed(() => formatControlSource(props.network?.active_control_source))
|
||||
|
||||
function formatTime(value?: string | null) {
|
||||
if (!value) {
|
||||
return 'unavailable'
|
||||
}
|
||||
return new Date(value).toLocaleString('zh-CN', { hour12: false })
|
||||
return formatDateTime(value)
|
||||
}
|
||||
|
||||
function formatScalar(value?: number | string | null, suffix = '') {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return '--'
|
||||
}
|
||||
if (typeof value === 'number') {
|
||||
return `${value.toFixed(1)}${suffix}`
|
||||
}
|
||||
return `${value}${suffix}`
|
||||
}
|
||||
|
||||
@@ -42,56 +43,105 @@ function legSessions(link: LinkTelemetry | null): Array<{ name: string; data: Li
|
||||
{ name: 'video', data: link?.sessions?.video ?? null },
|
||||
]
|
||||
}
|
||||
|
||||
function formatControlSource(source?: string | null) {
|
||||
if (source === 'keyboard') return t('common.keyboard')
|
||||
if (source === 'gamepad') return t('common.gamepad')
|
||||
return t('common.none')
|
||||
}
|
||||
|
||||
function formatBoolean(value?: boolean | number | null) {
|
||||
if (value === null || value === undefined) {
|
||||
return t('common.na')
|
||||
}
|
||||
return value ? t('common.yes') : t('common.no')
|
||||
}
|
||||
|
||||
function formatAckMode(ackAvailable?: boolean) {
|
||||
return ackAvailable ? t('common.ackLoop') : t('common.srttFallback')
|
||||
}
|
||||
|
||||
function formatStale(stale?: boolean | null) {
|
||||
if (stale == null) {
|
||||
return t('common.na')
|
||||
}
|
||||
return stale ? t('common.stale') : t('common.fresh')
|
||||
}
|
||||
|
||||
function formatOnline(online?: boolean | null) {
|
||||
if (online == null) {
|
||||
return t('common.na')
|
||||
}
|
||||
return online ? t('common.online') : t('common.idle')
|
||||
}
|
||||
|
||||
function formatSessionName(name: string) {
|
||||
return name === 'control' ? t('common.control') : t('common.video')
|
||||
}
|
||||
|
||||
function formatTrend(value?: string | null) {
|
||||
if (value === 'rising') return t('common.rising')
|
||||
if (value === 'falling') return t('common.falling')
|
||||
return t('common.stable')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="panel network-panel">
|
||||
<div class="panel-head">
|
||||
<div>
|
||||
<p class="eyebrow">Network</p>
|
||||
<h2>Dual-Leg Telemetry</h2>
|
||||
<p class="eyebrow">{{ t('networkPanel.eyebrow') }}</p>
|
||||
<h2>{{ t('networkPanel.title') }}</h2>
|
||||
</div>
|
||||
<span class="badge" :class="{ stale: network?.telemetry_receiver?.hub_stale }">
|
||||
{{ network?.peer_status ?? 'loading' }}
|
||||
{{ network?.peer_status ?? t('networkPanel.loadingPeer') }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="stats">
|
||||
<div class="stat-card">
|
||||
<span>Latency</span>
|
||||
<strong>{{ formatScalar(network?.latency_ms, ' ms') }}</strong>
|
||||
<span>{{ t('networkPanel.controlLoopRtt') }}</span>
|
||||
<strong>{{ formatScalar(network?.latency_estimate?.control_loop_rtt_ms, ' ms') }}</strong>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span>Jitter</span>
|
||||
<strong>{{ formatScalar(network?.jitter_ms, ' ms') }}</strong>
|
||||
<span>{{ t('networkPanel.controlToPersist') }}</span>
|
||||
<strong>{{ formatScalar(network?.latency_estimate?.control_to_persist_est_ms, ' ms') }}</strong>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span>Active Control</span>
|
||||
<strong>{{ activeSource }}</strong>
|
||||
<span>{{ t('networkPanel.controlSrttOneWay') }}</span>
|
||||
<strong>{{ formatScalar(network?.latency_estimate?.control_oneway_srtt_est_ms, ' ms') }}</strong>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span>Lease</span>
|
||||
<strong>{{ formatScalar(network?.control_lease_remaining_ms, ' ms') }}</strong>
|
||||
<span>{{ t('networkPanel.videoOneWayEst') }}</span>
|
||||
<strong>{{ formatScalar(network?.latency_estimate?.video_network_oneway_est_ms, ' ms') }}</strong>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span>TX Rate</span>
|
||||
<span>{{ t('networkPanel.txRate') }}</span>
|
||||
<strong>{{ formatScalar(network?.tx_kbps, ' kbps') }}</strong>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span>RX Rate</span>
|
||||
<span>{{ t('networkPanel.rxRate') }}</span>
|
||||
<strong>{{ formatScalar(network?.rx_kbps, ' kbps') }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="summary telemetry-strip">
|
||||
<p><strong>Transport:</strong> {{ network?.transport ?? 'n/a' }} / {{ network?.source_mode ?? 'n/a' }}</p>
|
||||
<p><strong>Telemetry Peer:</strong> {{ network?.telemetry_receiver?.peer_id ?? 'n/a' }}</p>
|
||||
<p><strong>Telemetry Registered:</strong> {{ network?.telemetry_receiver?.registered ? 'yes' : 'no' }}</p>
|
||||
<p><strong>Hub Freshness:</strong> {{ formatTime(network?.telemetry_receiver?.hub_updated_at) }}</p>
|
||||
<p><strong>Hub State:</strong> {{ network?.telemetry_receiver?.hub_stale ? 'stale' : 'fresh' }}</p>
|
||||
<p><strong>Telemetry Reconnects:</strong> {{ network?.telemetry_receiver?.reconnect_count ?? 0 }}</p>
|
||||
<p v-if="network?.telemetry_receiver?.last_error"><strong>Hub Error:</strong> {{ network?.telemetry_receiver?.last_error }}</p>
|
||||
<p v-if="network?.telemetry_receiver?.last_server_error"><strong>Telemetry Session Error:</strong> {{ network?.telemetry_receiver?.last_server_error }}</p>
|
||||
<p><strong>{{ t('networkPanel.robotFault') }}:</strong> {{ network?.robot_health?.fault_reason ?? t('common.na') }}</p>
|
||||
<p><strong>{{ t('networkPanel.recoveryState') }}:</strong> {{ network?.robot_health?.recovery_state ?? t('common.na') }}</p>
|
||||
<p><strong>{{ t('networkPanel.healthConfidence') }}:</strong> {{ network?.robot_health?.confidence ?? t('common.na') }}</p>
|
||||
<p><strong>{{ t('networkPanel.healthUpdated') }}:</strong> {{ formatTime(network?.robot_health?.updated_at) }}</p>
|
||||
<p><strong>{{ t('networkPanel.transport') }}:</strong> {{ network?.transport ?? t('common.na') }} / {{ network?.source_mode ?? t('common.na') }}</p>
|
||||
<p><strong>{{ t('networkPanel.activeControl') }}:</strong> {{ activeSource }}</p>
|
||||
<p><strong>{{ t('networkPanel.lease') }}:</strong> {{ formatScalar(network?.control_lease_remaining_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('networkPanel.ackMode') }}:</strong> {{ formatAckMode(network?.control_ack_status?.ack_available) }}</p>
|
||||
<p><strong>{{ t('networkPanel.ackUpdated') }}:</strong> {{ formatTime(network?.control_ack_status?.updated_at) }}</p>
|
||||
<p><strong>{{ t('networkPanel.telemetryPeer') }}:</strong> {{ network?.telemetry_receiver?.peer_id ?? t('common.na') }}</p>
|
||||
<p><strong>{{ t('networkPanel.telemetryRegistered') }}:</strong> {{ formatBoolean(network?.telemetry_receiver?.registered) }}</p>
|
||||
<p><strong>{{ t('networkPanel.hubFreshness') }}:</strong> {{ formatTime(network?.telemetry_receiver?.hub_updated_at) }}</p>
|
||||
<p><strong>{{ t('networkPanel.hubState') }}:</strong> {{ formatStale(network?.telemetry_receiver?.hub_stale) }}</p>
|
||||
<p><strong>{{ t('networkPanel.telemetryReconnects') }}:</strong> {{ network?.telemetry_receiver?.reconnect_count ?? 0 }}</p>
|
||||
<p v-if="network?.telemetry_receiver?.last_error"><strong>{{ t('networkPanel.hubError') }}:</strong> {{ network?.telemetry_receiver?.last_error }}</p>
|
||||
<p v-if="network?.telemetry_receiver?.last_server_error"><strong>{{ t('networkPanel.telemetrySessionError') }}:</strong> {{ network?.telemetry_receiver?.last_server_error }}</p>
|
||||
</div>
|
||||
|
||||
<div class="leg-grid">
|
||||
@@ -99,11 +149,11 @@ function legSessions(link: LinkTelemetry | null): Array<{ name: string; data: Li
|
||||
<div class="leg-head">
|
||||
<div>
|
||||
<p class="leg-label">{{ leg.label }}</p>
|
||||
<h3>{{ leg.data?.source ?? 'waiting' }}</h3>
|
||||
<h3>{{ leg.data?.source ?? t('common.waiting') }}</h3>
|
||||
</div>
|
||||
<div class="leg-meta">
|
||||
<span class="mini-badge" :class="{ stale: leg.data?.stale }">
|
||||
{{ leg.data?.stale ? 'stale' : 'fresh' }}
|
||||
{{ formatStale(leg.data?.stale) }}
|
||||
</span>
|
||||
<span class="mini-time">{{ formatTime(leg.data?.updated_at) }}</span>
|
||||
</div>
|
||||
@@ -111,27 +161,27 @@ function legSessions(link: LinkTelemetry | null): Array<{ name: string; data: Li
|
||||
|
||||
<div class="aggregate-grid">
|
||||
<div>
|
||||
<span>Online</span>
|
||||
<span>{{ t('networkPanel.online') }}</span>
|
||||
<strong>{{ leg.data?.aggregate?.online_sessions ?? 0 }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>Max Pressure</span>
|
||||
<span>{{ t('networkPanel.maxPressure') }}</span>
|
||||
<strong>{{ formatScalar(leg.data?.aggregate?.max_window_pressure_pct, '%') }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>Queued</span>
|
||||
<span>{{ t('networkPanel.queued') }}</span>
|
||||
<strong>{{ leg.data?.aggregate?.sum_snd_queue ?? 0 }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>In Flight Buffer</span>
|
||||
<span>{{ t('networkPanel.inFlightBuffer') }}</span>
|
||||
<strong>{{ leg.data?.aggregate?.sum_snd_buffer ?? 0 }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>Retrans Delta</span>
|
||||
<span>{{ t('networkPanel.retransDelta') }}</span>
|
||||
<strong>{{ leg.data?.aggregate?.sum_retrans_delta ?? 0 }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>Repair Rate</span>
|
||||
<span>{{ t('networkPanel.repairRate') }}</span>
|
||||
<strong>{{ formatScalar(leg.data?.aggregate?.repair_rate_pct, '%') }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
@@ -140,36 +190,36 @@ function legSessions(link: LinkTelemetry | null): Array<{ name: string; data: Li
|
||||
<section v-for="session in legSessions(leg.data)" :key="session.name" class="session-card">
|
||||
<div class="session-head">
|
||||
<div>
|
||||
<p class="session-label">{{ session.name }}</p>
|
||||
<h4>{{ session.data?.peer_id ?? 'unassigned' }}</h4>
|
||||
<p class="session-label">{{ formatSessionName(session.name) }}</p>
|
||||
<h4>{{ session.data?.peer_id ?? t('networkPanel.unassigned') }}</h4>
|
||||
</div>
|
||||
<span class="mini-badge" :class="{ stale: session.data?.stale, active: session.data?.connected }">
|
||||
{{ session.data?.connected ? 'online' : 'idle' }}
|
||||
{{ formatOnline(session.data?.connected) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="kv-grid">
|
||||
<p><strong>Updated:</strong> {{ formatTime(session.data?.updated_at) }}</p>
|
||||
<p><strong>SRTT:</strong> {{ formatScalar(session.data?.kcp?.srtt_ms, ' ms') }}</p>
|
||||
<p><strong>RTTVAR:</strong> {{ formatScalar(session.data?.kcp?.srttvar_ms, ' ms') }}</p>
|
||||
<p><strong>RTO:</strong> {{ formatScalar(session.data?.kcp?.rto_ms, ' ms') }}</p>
|
||||
<p><strong>SND WND:</strong> {{ formatScalar(session.data?.kcp?.snd_wnd) }}</p>
|
||||
<p><strong>RMT WND:</strong> {{ formatScalar(session.data?.kcp?.rmt_wnd) }}</p>
|
||||
<p><strong>Inflight:</strong> {{ formatScalar(session.data?.kcp?.inflight) }}</p>
|
||||
<p><strong>Window Limit:</strong> {{ formatScalar(session.data?.kcp?.window_limit) }}</p>
|
||||
<p><strong>Pressure:</strong> {{ formatScalar(session.data?.kcp?.window_pressure_pct, '%') }}</p>
|
||||
<p><strong>SND Queue:</strong> {{ formatScalar(session.data?.kcp?.snd_queue) }} / {{ session.data?.trend?.snd_queue_trend ?? 'stable' }}</p>
|
||||
<p><strong>SND Buffer:</strong> {{ formatScalar(session.data?.kcp?.snd_buffer) }} / {{ session.data?.trend?.snd_buffer_trend ?? 'stable' }}</p>
|
||||
<p><strong>Queue Delta:</strong> {{ formatScalar(session.data?.trend?.snd_queue_delta) }}</p>
|
||||
<p><strong>Buffer Delta:</strong> {{ formatScalar(session.data?.trend?.snd_buffer_delta) }}</p>
|
||||
<p><strong>Retrans:</strong> {{ formatScalar(session.data?.trend?.retrans_delta) }}</p>
|
||||
<p><strong>Fast Retrans:</strong> {{ formatScalar(session.data?.trend?.fast_retrans_delta) }}</p>
|
||||
<p><strong>Lost:</strong> {{ formatScalar(session.data?.trend?.lost_delta) }}</p>
|
||||
<p><strong>Repeat:</strong> {{ formatScalar(session.data?.trend?.repeat_delta) }}</p>
|
||||
<p><strong>Repair Rate:</strong> {{ formatScalar(session.data?.trend?.repair_rate_pct, '%') }}</p>
|
||||
<p v-if="session.data?.app"><strong>App Bytes:</strong> tx={{ session.data.app.send_bytes ?? 0 }} / rx={{ session.data.app.recv_bytes ?? 0 }}</p>
|
||||
<p v-if="session.data?.app"><strong>Registered:</strong> {{ session.data.app.registered ? 'yes' : 'no' }}</p>
|
||||
<p v-if="session.data?.app?.last_server_error"><strong>Server Error:</strong> {{ session.data.app.last_server_error }}</p>
|
||||
<p><strong>{{ t('networkPanel.updated') }}:</strong> {{ formatTime(session.data?.updated_at) }}</p>
|
||||
<p><strong>{{ t('networkPanel.srtt') }}:</strong> {{ formatScalar(session.data?.kcp?.srtt_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('networkPanel.rttvar') }}:</strong> {{ formatScalar(session.data?.kcp?.srttvar_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('networkPanel.rto') }}:</strong> {{ formatScalar(session.data?.kcp?.rto_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('networkPanel.sndWnd') }}:</strong> {{ formatScalar(session.data?.kcp?.snd_wnd) }}</p>
|
||||
<p><strong>{{ t('networkPanel.rmtWnd') }}:</strong> {{ formatScalar(session.data?.kcp?.rmt_wnd) }}</p>
|
||||
<p><strong>{{ t('networkPanel.inflight') }}:</strong> {{ formatScalar(session.data?.kcp?.inflight) }}</p>
|
||||
<p><strong>{{ t('networkPanel.windowLimit') }}:</strong> {{ formatScalar(session.data?.kcp?.window_limit) }}</p>
|
||||
<p><strong>{{ t('networkPanel.pressure') }}:</strong> {{ formatScalar(session.data?.kcp?.window_pressure_pct, '%') }}</p>
|
||||
<p><strong>{{ t('networkPanel.sndQueue') }}:</strong> {{ formatScalar(session.data?.kcp?.snd_queue) }} / {{ formatTrend(session.data?.trend?.snd_queue_trend) }}</p>
|
||||
<p><strong>{{ t('networkPanel.sndBuffer') }}:</strong> {{ formatScalar(session.data?.kcp?.snd_buffer) }} / {{ formatTrend(session.data?.trend?.snd_buffer_trend) }}</p>
|
||||
<p><strong>{{ t('networkPanel.queueDelta') }}:</strong> {{ formatScalar(session.data?.trend?.snd_queue_delta) }}</p>
|
||||
<p><strong>{{ t('networkPanel.bufferDelta') }}:</strong> {{ formatScalar(session.data?.trend?.snd_buffer_delta) }}</p>
|
||||
<p><strong>{{ t('networkPanel.retrans') }}:</strong> {{ formatScalar(session.data?.trend?.retrans_delta) }}</p>
|
||||
<p><strong>{{ t('networkPanel.fastRetrans') }}:</strong> {{ formatScalar(session.data?.trend?.fast_retrans_delta) }}</p>
|
||||
<p><strong>{{ t('networkPanel.lost') }}:</strong> {{ formatScalar(session.data?.trend?.lost_delta) }}</p>
|
||||
<p><strong>{{ t('networkPanel.repeat') }}:</strong> {{ formatScalar(session.data?.trend?.repeat_delta) }}</p>
|
||||
<p><strong>{{ t('networkPanel.repairRate') }}:</strong> {{ formatScalar(session.data?.trend?.repair_rate_pct, '%') }}</p>
|
||||
<p v-if="session.data?.app"><strong>{{ t('networkPanel.appBytes') }}:</strong> tx={{ session.data.app.send_bytes ?? 0 }} / rx={{ session.data.app.recv_bytes ?? 0 }}</p>
|
||||
<p v-if="session.data?.app"><strong>{{ t('networkPanel.registered') }}:</strong> {{ formatBoolean(session.data.app.registered) }}</p>
|
||||
<p v-if="session.data?.app?.last_server_error"><strong>{{ t('networkPanel.serverError') }}:</strong> {{ session.data.app.last_server_error }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
@@ -177,11 +227,15 @@ function legSessions(link: LinkTelemetry | null): Array<{ name: string; data: Li
|
||||
</div>
|
||||
|
||||
<div class="summary">
|
||||
<p><strong>Combined:</strong> sessions={{ network?.combined?.connected_sessions ?? 0 }} send={{ network?.combined?.send_bytes ?? 0 }}B recv={{ network?.combined?.recv_bytes ?? 0 }}B</p>
|
||||
<p><strong>Native UDP:</strong> {{ network?.ingress?.native_udp?.bind_addr ?? 'n/a' }} packets={{ network?.ingress?.native_udp?.packets_received ?? 0 }} invalid={{ network?.ingress?.native_udp?.invalid_packets ?? 0 }}</p>
|
||||
<p><strong>Control Sender:</strong> {{ network?.control?.sender?.peer_id ?? 'n/a' }} -> {{ network?.control?.sender?.target_peer ?? 'n/a' }} sends={{ network?.control?.sender?.send_count ?? 0 }} registered={{ network?.control?.sender?.registered ? 'yes' : 'no' }}</p>
|
||||
<p><strong>Control Reconnects:</strong> {{ network?.control?.sender?.reconnect_count ?? 0 }}</p>
|
||||
<p v-if="network?.control?.sender?.last_server_error"><strong>Control Session Error:</strong> {{ network?.control?.sender?.last_server_error }}</p>
|
||||
<p><strong>{{ t('networkPanel.combined') }}:</strong> sessions={{ network?.combined?.connected_sessions ?? 0 }} send={{ network?.combined?.send_bytes ?? 0 }}B recv={{ network?.combined?.recv_bytes ?? 0 }}B</p>
|
||||
<p><strong>{{ t('networkPanel.videoE2E') }}:</strong> {{ formatScalar(network?.latency_estimate?.video_e2e_est_ms, ' ms') }} / confidence={{ network?.latency_estimate?.confidence?.video ?? t('common.na') }}</p>
|
||||
<p><strong>{{ t('networkPanel.controlEstimateConfidence') }}:</strong> {{ network?.latency_estimate?.confidence?.control ?? t('common.na') }}</p>
|
||||
<p><strong>{{ t('networkPanel.videoFreshness') }}:</strong> {{ t('networkPanel.videoFreshnessRepeat') }}={{ formatScalar((network?.video_freshness?.repeated_frame_ratio ?? 0) * 100, '%') }} {{ t('networkPanel.videoFreshnessSkip') }}={{ formatScalar((network?.video_freshness?.skip_ratio ?? 0) * 100, '%') }} {{ t('networkPanel.videoFreshnessFreeze') }}={{ formatScalar(network?.video_freshness?.longest_freeze_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('networkPanel.nativeUdp') }}:</strong> {{ network?.ingress?.native_udp?.bind_addr ?? t('common.na') }} packets={{ network?.ingress?.native_udp?.packets_received ?? 0 }} invalid={{ network?.ingress?.native_udp?.invalid_packets ?? 0 }}</p>
|
||||
<p><strong>{{ t('networkPanel.controlSender') }}:</strong> {{ network?.control?.sender?.peer_id ?? t('common.na') }} -> {{ network?.control?.sender?.target_peer ?? t('common.na') }} sends={{ network?.control?.sender?.send_count ?? 0 }} registered={{ formatBoolean(network?.control?.sender?.registered) }}</p>
|
||||
<p><strong>{{ t('networkPanel.ackReceiver') }}:</strong> {{ network?.control?.ack_receiver?.peer_id ?? t('common.na') }} reconnects={{ network?.control?.ack_receiver?.reconnect_count ?? 0 }}</p>
|
||||
<p><strong>{{ t('networkPanel.controlReconnects') }}:</strong> {{ network?.control?.sender?.reconnect_count ?? 0 }}</p>
|
||||
<p v-if="network?.control?.sender?.last_server_error"><strong>{{ t('networkPanel.controlSessionError') }}:</strong> {{ network?.control?.sender?.last_server_error }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -1,82 +1,220 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { buildVideoFrameUrl, fetchVideoStatus } from '@/lib/api'
|
||||
import type { VideoStatus } from '@/types'
|
||||
|
||||
import { buildVideoFrameUrl, fetchClockCalibrationSample, fetchVideoStatus, postVideoDisplayProbe } from '@/lib/api'
|
||||
import { t } from '@/lib/locale'
|
||||
import { useOperatorInputTelemetry } from '@/composables/useControlInterface'
|
||||
import type { NetworkTelemetry, VideoStatus } from '@/types'
|
||||
|
||||
const props = defineProps<{
|
||||
video: VideoStatus | null
|
||||
network?: NetworkTelemetry | null
|
||||
}>()
|
||||
|
||||
const STATUS_REFRESH_MS = 300
|
||||
const DISPLAY_PROBE_INTERVAL_MS = 200
|
||||
const CLOCK_CALIBRATION_INTERVAL_MS = 1000
|
||||
const CLOCK_CALIBRATION_SAMPLE_WINDOW = 9
|
||||
const CLOCK_CALIBRATION_STALE_MS = CLOCK_CALIBRATION_INTERVAL_MS * 3
|
||||
|
||||
type PendingInputProbe = {
|
||||
token: number
|
||||
triggeredPerfMs: number
|
||||
baselineFrameSeq: number | null
|
||||
baselineFrameHash: string
|
||||
freshResolved: boolean
|
||||
changedResolved: boolean
|
||||
paintResolved: boolean
|
||||
}
|
||||
|
||||
type ClockCalibrationSnapshot = {
|
||||
offsetMs: number | null
|
||||
rttMs: number | null
|
||||
sampleCount: number
|
||||
updatedAt: string | null
|
||||
}
|
||||
|
||||
const liveVideo = ref<VideoStatus | null>(props.video)
|
||||
const frameUrl = ref(buildVideoFrameUrl(0))
|
||||
const displayVideo = computed(() => liveVideo.value ?? props.video)
|
||||
const currentFps = computed(() => displayVideo.value?.fps ?? 30)
|
||||
const canRequestFrames = computed(() => displayVideo.value?.available === true)
|
||||
const currentFps = computed(() => displayVideo.value?.fps ?? 30)
|
||||
const operatorMetrics = ref({
|
||||
input_to_next_fresh_frame_ms: null as number | null,
|
||||
input_to_next_changed_frame_ms: null as number | null,
|
||||
input_to_next_paint_ms: null as number | null,
|
||||
})
|
||||
|
||||
const {
|
||||
operatorInputSequence,
|
||||
lastOperatorInputPerfMs,
|
||||
} = useOperatorInputTelemetry()
|
||||
|
||||
const freshness = computed(() => displayVideo.value?.freshness)
|
||||
const networkEstimate = computed(() => props.network?.latency_estimate ?? null)
|
||||
const senderClockDebug = computed(() => displayVideo.value?.timing ?? null)
|
||||
const EMPTY_CLOCK_CALIBRATION: ClockCalibrationSnapshot = {
|
||||
offsetMs: null,
|
||||
rttMs: null,
|
||||
sampleCount: 0,
|
||||
updatedAt: null,
|
||||
}
|
||||
const clockCalibration = ref<ClockCalibrationSnapshot>({ ...EMPTY_CLOCK_CALIBRATION })
|
||||
|
||||
const modeLabel = computed(() => {
|
||||
if (!displayVideo.value) {
|
||||
return '正在获取视频状态'
|
||||
return t('videoPanel.mode.loading')
|
||||
}
|
||||
if (displayVideo.value.source_mode === 'omnisocket-jpeg-live') {
|
||||
return `${displayVideo.value.fps} FPS 实时接收`
|
||||
return t('videoPanel.mode.live', { fps: displayVideo.value.fps })
|
||||
}
|
||||
if (displayVideo.value.source_mode === 'omnisocket-waiting') {
|
||||
return '未实时获取真实值'
|
||||
}
|
||||
return `${displayVideo.value.fps} FPS`
|
||||
return displayVideo.value.source_mode
|
||||
})
|
||||
const placeholderText = computed(() => {
|
||||
if (!displayVideo.value) {
|
||||
return '正在获取视频状态...'
|
||||
}
|
||||
return '未实时获取真实值'
|
||||
})
|
||||
const latencyLabels = computed(() => {
|
||||
const sampleWindowSize = displayVideo.value?.timing?.sample_window_size ?? 10
|
||||
const samples = displayVideo.value?.timing?.delta_samples_ms ?? []
|
||||
return Array.from({ length: sampleWindowSize }, (_, index) => samples[index] ?? null)
|
||||
})
|
||||
const timingHeadline = computed(() => {
|
||||
const latest = displayVideo.value?.timing?.latest_delta_ms
|
||||
if (latest == null) {
|
||||
return '等待帧尾时间'
|
||||
}
|
||||
return `最新 ${latest.toFixed(1)} ms`
|
||||
})
|
||||
const timingHint = computed(() => {
|
||||
const timing = displayVideo.value?.timing
|
||||
if (!timing?.available) {
|
||||
return '当前还没有从 JPEG 结尾后的尾字节里解析到时间戳,标签会在收到有效帧尾时间后自动填充。'
|
||||
}
|
||||
|
||||
const unitText = timing.timestamp_unit ? `,单位按 ${timing.timestamp_unit}` : ''
|
||||
const endiannessText = timing.timestamp_endianness
|
||||
? `,字节序按 ${timing.timestamp_endianness}`
|
||||
: ''
|
||||
return `最近 ${timing.sample_window_size} 个差值样本,面板按 ${STATUS_REFRESH_MS} ms 刷新一组${unitText}${endiannessText}。`
|
||||
const timingHeadline = computed(() => {
|
||||
const latest = senderClockDebug.value?.sender_clock_delta_ms_raw
|
||||
if (latest == null) {
|
||||
return t('videoPanel.timing.waiting')
|
||||
}
|
||||
return `${latest.toFixed(1)} ms`
|
||||
})
|
||||
|
||||
const timingHint = computed(() => {
|
||||
const timing = senderClockDebug.value
|
||||
if (!timing?.available) {
|
||||
return t('videoPanel.timing.noTrailer')
|
||||
}
|
||||
return t('videoPanel.timing.rawHint')
|
||||
})
|
||||
|
||||
function formatNumber(value: number | null | undefined, suffix = '') {
|
||||
if (value == null || Number.isNaN(value)) {
|
||||
return '--'
|
||||
}
|
||||
return `${value.toFixed(1)}${suffix}`
|
||||
}
|
||||
|
||||
function wallClockNowMs() {
|
||||
return Date.now()
|
||||
}
|
||||
|
||||
let frameTimer: number | null = null
|
||||
let statusTimer: number | null = null
|
||||
let probeTimer: number | null = null
|
||||
let calibrationTimer: number | null = null
|
||||
let frameKey = 0
|
||||
let probeKey = 0
|
||||
let statusRequestPending = false
|
||||
let probeRequestPending = false
|
||||
let calibrationRequestPending = false
|
||||
let lastObservedFrameSeq: number | null = null
|
||||
let lastObservedFrameHash = ''
|
||||
let pendingInputProbe: PendingInputProbe | null = null
|
||||
let clockOffsetSamples: number[] = []
|
||||
let clockRttSamples: number[] = []
|
||||
|
||||
function boundedMedian(samples: number[]) {
|
||||
if (samples.length === 0) {
|
||||
return null
|
||||
}
|
||||
const sorted = [...samples].sort((left, right) => left - right)
|
||||
const middle = Math.floor(sorted.length / 2)
|
||||
if (sorted.length % 2 === 1) {
|
||||
return sorted[middle] ?? null
|
||||
}
|
||||
const left = sorted[middle - 1]
|
||||
const right = sorted[middle]
|
||||
if (left == null || right == null) {
|
||||
return null
|
||||
}
|
||||
return (left + right) / 2
|
||||
}
|
||||
|
||||
function clearClockCalibration() {
|
||||
clockOffsetSamples = []
|
||||
clockRttSamples = []
|
||||
clockCalibration.value = { ...EMPTY_CLOCK_CALIBRATION }
|
||||
}
|
||||
|
||||
function isClockCalibrationFresh(snapshot: ClockCalibrationSnapshot, nowMs = wallClockNowMs()) {
|
||||
if (snapshot.offsetMs == null || snapshot.rttMs == null || !snapshot.updatedAt) {
|
||||
return false
|
||||
}
|
||||
const updatedAtMs = Date.parse(snapshot.updatedAt)
|
||||
if (!Number.isFinite(updatedAtMs)) {
|
||||
return false
|
||||
}
|
||||
return nowMs - updatedAtMs <= CLOCK_CALIBRATION_STALE_MS
|
||||
}
|
||||
|
||||
function expireClockCalibrationIfStale(nowMs = wallClockNowMs()) {
|
||||
if (clockCalibration.value.sampleCount > 0 && !isClockCalibrationFresh(clockCalibration.value, nowMs)) {
|
||||
clearClockCalibration()
|
||||
}
|
||||
}
|
||||
|
||||
function currentClockCalibration(nowMs = wallClockNowMs()) {
|
||||
expireClockCalibrationIfStale(nowMs)
|
||||
return clockCalibration.value
|
||||
}
|
||||
|
||||
function updateClockCalibration(offsetMs: number, rttMs: number) {
|
||||
clockOffsetSamples.push(offsetMs)
|
||||
clockRttSamples.push(rttMs)
|
||||
if (clockOffsetSamples.length > CLOCK_CALIBRATION_SAMPLE_WINDOW) {
|
||||
clockOffsetSamples = clockOffsetSamples.slice(-CLOCK_CALIBRATION_SAMPLE_WINDOW)
|
||||
}
|
||||
if (clockRttSamples.length > CLOCK_CALIBRATION_SAMPLE_WINDOW) {
|
||||
clockRttSamples = clockRttSamples.slice(-CLOCK_CALIBRATION_SAMPLE_WINDOW)
|
||||
}
|
||||
const medianOffset = boundedMedian(clockOffsetSamples)
|
||||
const medianRtt = boundedMedian(clockRttSamples)
|
||||
clockCalibration.value = {
|
||||
offsetMs: medianOffset == null ? null : Number(medianOffset.toFixed(3)),
|
||||
rttMs: medianRtt == null ? null : Number(medianRtt.toFixed(3)),
|
||||
sampleCount: clockOffsetSamples.length,
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshStatus() {
|
||||
if (statusRequestPending) {
|
||||
return
|
||||
}
|
||||
|
||||
statusRequestPending = true
|
||||
try {
|
||||
liveVideo.value = await fetchVideoStatus()
|
||||
} catch {
|
||||
// 保持当前已显示状态,避免短暂请求失败把面板内容清空。
|
||||
// Keep the last good state.
|
||||
} finally {
|
||||
statusRequestPending = false
|
||||
}
|
||||
}
|
||||
|
||||
async function runClockCalibration() {
|
||||
if (calibrationRequestPending) {
|
||||
return
|
||||
}
|
||||
calibrationRequestPending = true
|
||||
const clientSendUnixMs = wallClockNowMs()
|
||||
expireClockCalibrationIfStale(clientSendUnixMs)
|
||||
try {
|
||||
const sample = await fetchClockCalibrationSample()
|
||||
const clientRecvUnixMs = wallClockNowMs()
|
||||
if (!Number.isFinite(sample.server_received_unix_ms) || !Number.isFinite(sample.server_sent_unix_ms)) {
|
||||
return
|
||||
}
|
||||
const offsetMs = ((clientSendUnixMs - sample.server_received_unix_ms) + (clientRecvUnixMs - sample.server_sent_unix_ms)) / 2
|
||||
const rawRttMs = (clientRecvUnixMs - clientSendUnixMs) - (sample.server_sent_unix_ms - sample.server_received_unix_ms)
|
||||
updateClockCalibration(Number(offsetMs.toFixed(3)), Number(Math.max(0, rawRttMs).toFixed(3)))
|
||||
} catch {
|
||||
// Calibration is best-effort only.
|
||||
} finally {
|
||||
expireClockCalibrationIfStale()
|
||||
calibrationRequestPending = false
|
||||
}
|
||||
}
|
||||
|
||||
function refreshFrame() {
|
||||
if (!canRequestFrames.value) {
|
||||
return
|
||||
@@ -90,16 +228,12 @@ function startFrameLoop() {
|
||||
window.clearInterval(frameTimer)
|
||||
frameTimer = null
|
||||
}
|
||||
|
||||
if (!canRequestFrames.value) {
|
||||
return
|
||||
}
|
||||
|
||||
refreshFrame()
|
||||
const intervalMs = Math.max(33, Math.round(1000 / currentFps.value))
|
||||
frameTimer = window.setInterval(() => {
|
||||
refreshFrame()
|
||||
}, intervalMs)
|
||||
frameTimer = window.setInterval(refreshFrame, intervalMs)
|
||||
}
|
||||
|
||||
function startStatusLoop() {
|
||||
@@ -107,16 +241,161 @@ function startStatusLoop() {
|
||||
window.clearInterval(statusTimer)
|
||||
statusTimer = null
|
||||
}
|
||||
|
||||
void refreshStatus()
|
||||
statusTimer = window.setInterval(() => {
|
||||
void refreshStatus()
|
||||
}, STATUS_REFRESH_MS)
|
||||
}
|
||||
|
||||
function startClockCalibrationLoop() {
|
||||
if (calibrationTimer != null) {
|
||||
window.clearInterval(calibrationTimer)
|
||||
calibrationTimer = null
|
||||
}
|
||||
void runClockCalibration()
|
||||
calibrationTimer = window.setInterval(() => {
|
||||
void runClockCalibration()
|
||||
}, CLOCK_CALIBRATION_INTERVAL_MS)
|
||||
}
|
||||
|
||||
function maybeTrackOperatorInput() {
|
||||
pendingInputProbe = {
|
||||
token: operatorInputSequence.value,
|
||||
triggeredPerfMs: lastOperatorInputPerfMs.value,
|
||||
baselineFrameSeq: lastObservedFrameSeq,
|
||||
baselineFrameHash: lastObservedFrameHash,
|
||||
freshResolved: false,
|
||||
changedResolved: false,
|
||||
paintResolved: false,
|
||||
}
|
||||
}
|
||||
|
||||
async function runDisplayProbe() {
|
||||
if (probeRequestPending || !canRequestFrames.value) {
|
||||
return
|
||||
}
|
||||
|
||||
probeRequestPending = true
|
||||
const requestStartedUnixMs = wallClockNowMs()
|
||||
|
||||
try {
|
||||
probeKey += 1
|
||||
const response = await fetch(buildVideoFrameUrl(probeKey), {
|
||||
cache: 'no-store',
|
||||
})
|
||||
if (!response.ok) {
|
||||
return
|
||||
}
|
||||
|
||||
const frameSeqHeader = response.headers.get('X-Blitz-Frame-Seq')
|
||||
const backendReceivedHeader = response.headers.get('X-Blitz-Backend-Received-Unix-Ns')
|
||||
const frameHashHeader = response.headers.get('X-Blitz-Frame-Hash') ?? ''
|
||||
const frameSeq = frameSeqHeader ? Number(frameSeqHeader) : null
|
||||
const backendReceivedUnixNs = backendReceivedHeader ? Number(backendReceivedHeader) : null
|
||||
const responseReceivedUnixMs = wallClockNowMs()
|
||||
const blob = await response.blob()
|
||||
const objectUrl = URL.createObjectURL(blob)
|
||||
|
||||
try {
|
||||
const probeImage = new Image()
|
||||
probeImage.src = objectUrl
|
||||
await probeImage.decode()
|
||||
const decodedUnixMs = wallClockNowMs()
|
||||
await new Promise<void>((resolve) => {
|
||||
requestAnimationFrame(() => resolve())
|
||||
})
|
||||
const paintUnixMs = wallClockNowMs()
|
||||
|
||||
let inputToNextFreshFrameMs: number | null = null
|
||||
let inputToNextChangedFrameMs: number | null = null
|
||||
let inputToNextPaintMs: number | null = null
|
||||
|
||||
if (pendingInputProbe != null) {
|
||||
if (
|
||||
!pendingInputProbe.freshResolved &&
|
||||
frameSeq != null &&
|
||||
(pendingInputProbe.baselineFrameSeq == null || frameSeq > pendingInputProbe.baselineFrameSeq)
|
||||
) {
|
||||
inputToNextFreshFrameMs = Number((performance.now() - pendingInputProbe.triggeredPerfMs).toFixed(3))
|
||||
pendingInputProbe.freshResolved = true
|
||||
operatorMetrics.value.input_to_next_fresh_frame_ms = inputToNextFreshFrameMs
|
||||
}
|
||||
|
||||
if (
|
||||
!pendingInputProbe.changedResolved &&
|
||||
frameHashHeader &&
|
||||
frameHashHeader !== pendingInputProbe.baselineFrameHash
|
||||
) {
|
||||
inputToNextChangedFrameMs = Number((performance.now() - pendingInputProbe.triggeredPerfMs).toFixed(3))
|
||||
pendingInputProbe.changedResolved = true
|
||||
operatorMetrics.value.input_to_next_changed_frame_ms = inputToNextChangedFrameMs
|
||||
}
|
||||
|
||||
if (!pendingInputProbe.paintResolved) {
|
||||
inputToNextPaintMs = Number((performance.now() - pendingInputProbe.triggeredPerfMs).toFixed(3))
|
||||
pendingInputProbe.paintResolved = true
|
||||
operatorMetrics.value.input_to_next_paint_ms = inputToNextPaintMs
|
||||
}
|
||||
|
||||
if (
|
||||
pendingInputProbe.freshResolved &&
|
||||
pendingInputProbe.changedResolved &&
|
||||
pendingInputProbe.paintResolved
|
||||
) {
|
||||
pendingInputProbe = null
|
||||
}
|
||||
}
|
||||
|
||||
lastObservedFrameSeq = frameSeq
|
||||
lastObservedFrameHash = frameHashHeader
|
||||
const calibration = currentClockCalibration(paintUnixMs)
|
||||
|
||||
await postVideoDisplayProbe({
|
||||
updated_at: new Date().toISOString(),
|
||||
frame_seq: frameSeq,
|
||||
backend_received_unix_ns: backendReceivedUnixNs,
|
||||
frame_hash: frameHashHeader,
|
||||
request_started_unix_ms: Number(requestStartedUnixMs.toFixed(3)),
|
||||
response_received_unix_ms: Number(responseReceivedUnixMs.toFixed(3)),
|
||||
image_decoded_unix_ms: Number(decodedUnixMs.toFixed(3)),
|
||||
paint_unix_ms: Number(paintUnixMs.toFixed(3)),
|
||||
input_to_next_fresh_frame_ms: inputToNextFreshFrameMs,
|
||||
input_to_next_changed_frame_ms: inputToNextChangedFrameMs,
|
||||
input_to_next_paint_ms: inputToNextPaintMs,
|
||||
browser_backend_clock_offset_ms: calibration.offsetMs,
|
||||
browser_backend_clock_rtt_ms: calibration.rttMs,
|
||||
browser_backend_clock_sample_count: calibration.sampleCount,
|
||||
browser_backend_clock_calibrated_at: calibration.updatedAt,
|
||||
})
|
||||
} finally {
|
||||
URL.revokeObjectURL(objectUrl)
|
||||
}
|
||||
} catch {
|
||||
// Probe is best-effort only.
|
||||
} finally {
|
||||
probeRequestPending = false
|
||||
}
|
||||
}
|
||||
|
||||
function startProbeLoop() {
|
||||
if (probeTimer != null) {
|
||||
window.clearInterval(probeTimer)
|
||||
probeTimer = null
|
||||
}
|
||||
if (!canRequestFrames.value) {
|
||||
return
|
||||
}
|
||||
void runDisplayProbe()
|
||||
probeTimer = window.setInterval(() => {
|
||||
void runDisplayProbe()
|
||||
}, DISPLAY_PROBE_INTERVAL_MS)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
startStatusLoop()
|
||||
startFrameLoop()
|
||||
startProbeLoop()
|
||||
startClockCalibrationLoop()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -126,6 +405,12 @@ onUnmounted(() => {
|
||||
if (statusTimer != null) {
|
||||
window.clearInterval(statusTimer)
|
||||
}
|
||||
if (probeTimer != null) {
|
||||
window.clearInterval(probeTimer)
|
||||
}
|
||||
if (calibrationTimer != null) {
|
||||
window.clearInterval(calibrationTimer)
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
@@ -138,18 +423,26 @@ watch(
|
||||
|
||||
watch([currentFps, canRequestFrames], () => {
|
||||
startFrameLoop()
|
||||
startProbeLoop()
|
||||
})
|
||||
|
||||
watch(
|
||||
() => operatorInputSequence.value,
|
||||
() => {
|
||||
maybeTrackOperatorInput()
|
||||
},
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="panel video-panel">
|
||||
<div class="panel-head">
|
||||
<div>
|
||||
<p class="eyebrow">Video</p>
|
||||
<h2>JPEG 视频流</h2>
|
||||
<p class="eyebrow">{{ t('videoPanel.eyebrow') }}</p>
|
||||
<h2>{{ t('videoPanel.title') }}</h2>
|
||||
</div>
|
||||
<span class="badge" :class="{ bad: !displayVideo?.available }">
|
||||
{{ displayVideo?.source_mode ?? 'loading' }}
|
||||
{{ modeLabel }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -158,37 +451,72 @@ watch([currentFps, canRequestFrames], () => {
|
||||
v-if="canRequestFrames"
|
||||
class="video-frame"
|
||||
:src="frameUrl"
|
||||
alt="Robot jpeg frame stream"
|
||||
:alt="t('videoPanel.frameAlt')"
|
||||
/>
|
||||
<div v-else class="video-placeholder">
|
||||
{{ placeholderText }}
|
||||
{{ t('videoPanel.waitingFrames') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stats">
|
||||
<div class="stat-card">
|
||||
<span>帧源</span>
|
||||
<strong>{{ displayVideo?.frame_count ?? '--' }} 张 JPEG</strong>
|
||||
<span>{{ t('videoPanel.stats.frames') }}</span>
|
||||
<strong>{{ displayVideo?.frame_count ?? 0 }}</strong>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span>当前模式</span>
|
||||
<strong>{{ modeLabel }}</strong>
|
||||
<span>{{ t('videoPanel.stats.latestSeq') }}</span>
|
||||
<strong>{{ displayVideo?.receiver?.latest_sequence ?? '--' }}</strong>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span>{{ t('videoPanel.stats.videoE2E') }}</span>
|
||||
<strong>{{ formatNumber(networkEstimate?.video_e2e_est_ms, ' ms') }}</strong>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<span>{{ t('videoPanel.stats.paintDelay') }}</span>
|
||||
<strong>{{ formatNumber(displayVideo?.display_probe?.request_to_paint_ms, ' ms') }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="metric-grid">
|
||||
<div class="metric-group">
|
||||
<h3>{{ t('videoPanel.section.pipeline') }}</h3>
|
||||
<p><strong>{{ t('videoPanel.captureToSend') }}:</strong> {{ formatNumber(displayVideo?.receiver?.latest_capture_to_send_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.networkOneWay') }}:</strong> {{ formatNumber(networkEstimate?.video_network_oneway_est_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.partialEstimate') }}:</strong> {{ formatNumber(networkEstimate?.video_partial_est_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.endToEndEstimate') }}:</strong> {{ formatNumber(networkEstimate?.video_e2e_est_ms, ' ms') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="metric-group">
|
||||
<h3>{{ t('videoPanel.section.freshness') }}</h3>
|
||||
<p><strong>{{ t('videoPanel.interFrameAvg') }}:</strong> {{ formatNumber(freshness?.inter_frame_avg_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.interFrameP95') }}:</strong> {{ formatNumber(freshness?.inter_frame_p95_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.repeatedRatio') }}:</strong> {{ formatNumber((freshness?.repeated_frame_ratio ?? 0) * 100, ' %') }}</p>
|
||||
<p><strong>{{ t('videoPanel.skipRatio') }}:</strong> {{ formatNumber((freshness?.skip_ratio ?? 0) * 100, ' %') }}</p>
|
||||
<p><strong>{{ t('videoPanel.longestFreeze') }}:</strong> {{ formatNumber(freshness?.longest_freeze_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.lagFrames') }}:</strong> {{ freshness?.relative_freshness_lag_frames ?? 0 }}</p>
|
||||
</div>
|
||||
|
||||
<div class="metric-group">
|
||||
<h3>{{ t('videoPanel.section.operator') }}</h3>
|
||||
<p><strong>{{ t('videoPanel.inputToNextSeq') }}:</strong> {{ formatNumber(operatorMetrics.input_to_next_fresh_frame_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.inputToChangedFrame') }}:</strong> {{ formatNumber(operatorMetrics.input_to_next_changed_frame_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.inputToPaint') }}:</strong> {{ formatNumber(operatorMetrics.input_to_next_paint_ms, ' ms') }}</p>
|
||||
<p><strong>{{ t('videoPanel.displayProbeRequestToPaint') }}:</strong> {{ formatNumber(displayVideo?.display_probe?.request_to_paint_ms, ' ms') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="timing-panel">
|
||||
<div class="timing-head">
|
||||
<span>帧尾时间差</span>
|
||||
<span>{{ t('videoPanel.senderClockDelta') }}</span>
|
||||
<strong>{{ timingHeadline }}</strong>
|
||||
</div>
|
||||
<div class="timing-grid">
|
||||
<span
|
||||
v-for="(sample, index) in latencyLabels"
|
||||
v-for="(sample, index) in (senderClockDebug?.sender_clock_delta_samples_ms_raw ?? [])"
|
||||
:key="index"
|
||||
class="timing-label"
|
||||
:class="{ empty: sample == null }"
|
||||
>
|
||||
{{ sample == null ? '--' : `${sample.toFixed(1)} ms` }}
|
||||
{{ `${sample.toFixed(1)} ms` }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="hint subtle">
|
||||
@@ -197,12 +525,7 @@ watch([currentFps, canRequestFrames], () => {
|
||||
</div>
|
||||
|
||||
<p class="hint">
|
||||
这里只有在后端已经收到 OmniSocket 的真实 JPEG 帧时,才会开始逐帧请求并显示画面。
|
||||
如果当前没有真实帧,页面会保持占位提示,不再回退测试视频流。
|
||||
</p>
|
||||
|
||||
<p class="hint subtle">
|
||||
当前帧源状态:{{ displayVideo?.source_detail ?? '暂无' }}
|
||||
{{ displayVideo?.source_detail ?? t('videoPanel.noSourceDetail') }}
|
||||
</p>
|
||||
</section>
|
||||
</template>
|
||||
@@ -224,16 +547,24 @@ watch([currentFps, canRequestFrames], () => {
|
||||
margin: 0 0 4px;
|
||||
color: #5b7aff;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.12em;
|
||||
letter-spacing: 0.08em;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
h2 {
|
||||
h2,
|
||||
h3 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.badge {
|
||||
padding: 8px 12px;
|
||||
border-radius: 999px;
|
||||
@@ -249,11 +580,10 @@ h2 {
|
||||
}
|
||||
|
||||
.video-shell {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border-radius: 20px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(133, 147, 169, 0.28);
|
||||
background: linear-gradient(180deg, #09111f 0%, #050812 100%);
|
||||
background: #050812;
|
||||
}
|
||||
|
||||
.video-frame {
|
||||
@@ -261,115 +591,107 @@ h2 {
|
||||
width: 100%;
|
||||
aspect-ratio: 16 / 9;
|
||||
object-fit: cover;
|
||||
background: #02050d;
|
||||
}
|
||||
|
||||
.video-placeholder {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 100%;
|
||||
aspect-ratio: 16 / 9;
|
||||
padding: 24px;
|
||||
color: #a8b4ce;
|
||||
text-align: center;
|
||||
line-height: 1.7;
|
||||
background:
|
||||
radial-gradient(circle at top, rgba(91, 122, 255, 0.14), transparent 42%),
|
||||
#02050d;
|
||||
color: #95a4c6;
|
||||
}
|
||||
|
||||
.stats,
|
||||
.metric-grid {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
padding: 14px;
|
||||
border-radius: 16px;
|
||||
background: rgba(7, 14, 26, 0.78);
|
||||
border: 1px solid rgba(133, 147, 169, 0.2);
|
||||
.metric-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.stat-card,
|
||||
.metric-group,
|
||||
.timing-panel {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(133, 147, 169, 0.18);
|
||||
background: rgba(7, 14, 26, 0.86);
|
||||
}
|
||||
|
||||
.stat-card span,
|
||||
.metric-group p,
|
||||
.hint {
|
||||
color: #d5dbee;
|
||||
}
|
||||
|
||||
.stat-card span {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #8d99b3;
|
||||
margin-bottom: 6px;
|
||||
font-size: 12px;
|
||||
color: #9aaccc;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.stat-card strong {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.timing-panel {
|
||||
.metric-group {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
border-radius: 18px;
|
||||
background: rgba(7, 14, 26, 0.88);
|
||||
border: 1px solid rgba(133, 147, 169, 0.18);
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.metric-group p {
|
||||
margin: 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.timing-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
color: #cfd7e6;
|
||||
}
|
||||
|
||||
.timing-head span {
|
||||
color: #8d99b3;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.timing-head strong {
|
||||
font-size: 16px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.timing-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.timing-label {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
min-height: 40px;
|
||||
padding: 8px 10px;
|
||||
border-radius: 12px;
|
||||
padding: 6px 8px;
|
||||
border-radius: 8px;
|
||||
background: rgba(91, 122, 255, 0.12);
|
||||
border: 1px solid rgba(91, 122, 255, 0.28);
|
||||
color: #dce4ff;
|
||||
color: #dbe5ff;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.timing-label.empty {
|
||||
background: rgba(133, 147, 169, 0.08);
|
||||
border-color: rgba(133, 147, 169, 0.18);
|
||||
color: #7e8aa5;
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: 0;
|
||||
color: #8d99b3;
|
||||
line-height: 1.65;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.hint.subtle {
|
||||
font-size: 13px;
|
||||
color: #96a5c3;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.stats {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.timing-grid {
|
||||
@media (max-width: 1100px) {
|
||||
.stats,
|
||||
.metric-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.stats,
|
||||
.metric-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
|
||||
import { buildControlWebSocketUrl } from '@/lib/api'
|
||||
import { t } from '@/lib/locale'
|
||||
|
||||
type SocketState = 'connecting' | 'open' | 'closed'
|
||||
type ControlInputMode = 'keyboard' | 'gamepad'
|
||||
@@ -35,7 +36,7 @@ const KEY_LABELS: Record<string, string> = {
|
||||
KeyE: 'E',
|
||||
ShiftLeft: 'Shift',
|
||||
ShiftRight: 'Shift',
|
||||
Space: 'Stop',
|
||||
Space: 'Space',
|
||||
}
|
||||
const GAMEPAD_BUTTON_LABELS = ['A', 'B', 'X', 'Y', 'LB', 'RB', 'LT', 'RT', 'Back', 'Start', 'LS', 'RS']
|
||||
|
||||
@@ -57,15 +58,18 @@ const MAX_TURBO_MULTIPLIER = 3
|
||||
|
||||
const pressedKeys = ref<Set<string>>(new Set())
|
||||
const socketState = ref<SocketState>('connecting')
|
||||
const lastServerMessage = ref('waiting')
|
||||
const lastServerMessageOverride = ref('')
|
||||
const lastServerMessagePreset = ref<'waiting' | 'live'>('waiting')
|
||||
const gamepadSupported = ref(false)
|
||||
const gamepadConnected = ref(false)
|
||||
const gamepadName = ref('No gamepad detected')
|
||||
const gamepadNameRaw = ref('')
|
||||
const gamepadIndex = ref<number | null>(null)
|
||||
const gamepadMapping = ref('')
|
||||
const gamepadAxes = ref<number[]>([0, 0, 0, 0])
|
||||
const gamepadButtonPressed = ref<boolean[]>(Array.from({ length: GAMEPAD_BUTTON_LABELS.length }, () => false))
|
||||
const activeSource = ref<ControlSource>('idle')
|
||||
const operatorInputSequence = ref(0)
|
||||
const lastOperatorInputPerfMs = ref(0)
|
||||
|
||||
function clampValue(value: number, min: number, max: number) {
|
||||
return Math.min(max, Math.max(min, value))
|
||||
@@ -152,6 +156,11 @@ let consumerCount = 0
|
||||
let lastGamepadSignature = ''
|
||||
let lastCommandSignature = ''
|
||||
|
||||
function noteOperatorInput() {
|
||||
operatorInputSequence.value += 1
|
||||
lastOperatorInputPerfMs.value = performance.now()
|
||||
}
|
||||
|
||||
function normalizeAxis(raw: number) {
|
||||
if (Math.abs(raw) < GAMEPAD_DEADZONE) {
|
||||
return 0
|
||||
@@ -366,7 +375,7 @@ function sendCurrentCommand() {
|
||||
socket.send(packCommand(resolvedCommandValues()))
|
||||
}
|
||||
|
||||
function refreshSendLoop(force = false) {
|
||||
function refreshSendLoop(force = false, noteInput = true) {
|
||||
const source = resolvedSource()
|
||||
const values = resolvedCommandValues()
|
||||
const signature = commandSignature(values, source)
|
||||
@@ -375,6 +384,9 @@ function refreshSendLoop(force = false) {
|
||||
return
|
||||
}
|
||||
lastCommandSignature = signature
|
||||
if (noteInput) {
|
||||
noteOperatorInput()
|
||||
}
|
||||
|
||||
stopSendLoop()
|
||||
if (socket == null || socket.readyState !== WebSocket.OPEN) {
|
||||
@@ -434,7 +446,7 @@ function handleKeyup(event: KeyboardEvent) {
|
||||
|
||||
function resetGamepadState() {
|
||||
gamepadConnected.value = false
|
||||
gamepadName.value = 'No gamepad detected'
|
||||
gamepadNameRaw.value = ''
|
||||
gamepadIndex.value = null
|
||||
gamepadMapping.value = ''
|
||||
gamepadAxes.value = [0, 0, 0, 0]
|
||||
@@ -474,9 +486,9 @@ function pollGamepadState() {
|
||||
|
||||
lastGamepadSignature = signature
|
||||
gamepadConnected.value = true
|
||||
gamepadName.value = pad.id || 'Unnamed gamepad'
|
||||
gamepadNameRaw.value = pad.id || ''
|
||||
gamepadIndex.value = pad.index
|
||||
gamepadMapping.value = pad.mapping || 'unknown'
|
||||
gamepadMapping.value = pad.mapping || ''
|
||||
gamepadAxes.value = axes
|
||||
gamepadButtonPressed.value = buttons
|
||||
if (controlInputMode.value === 'gamepad') {
|
||||
@@ -496,18 +508,21 @@ function connectSocket() {
|
||||
|
||||
socket.onopen = () => {
|
||||
socketState.value = 'open'
|
||||
lastServerMessage.value = 'control link live'
|
||||
refreshSendLoop(true)
|
||||
lastServerMessagePreset.value = 'live'
|
||||
lastServerMessageOverride.value = ''
|
||||
refreshSendLoop(true, false)
|
||||
}
|
||||
|
||||
socket.onmessage = (event) => {
|
||||
if (typeof event.data === 'string') {
|
||||
lastServerMessage.value = event.data
|
||||
lastServerMessageOverride.value = event.data
|
||||
}
|
||||
}
|
||||
|
||||
socket.onclose = () => {
|
||||
socketState.value = 'closed'
|
||||
lastServerMessagePreset.value = 'waiting'
|
||||
lastServerMessageOverride.value = ''
|
||||
stopSendLoop()
|
||||
socket = null
|
||||
if (manualClose) {
|
||||
@@ -586,20 +601,27 @@ function unmountConsumer() {
|
||||
}
|
||||
|
||||
const socketLabel = computed(() => {
|
||||
if (socketState.value === 'open') return 'ws open'
|
||||
if (socketState.value === 'connecting') return 'connecting'
|
||||
return 'reconnecting'
|
||||
if (socketState.value === 'open') return t('control.socket.open')
|
||||
if (socketState.value === 'connecting') return t('control.socket.connecting')
|
||||
return t('control.socket.reconnecting')
|
||||
})
|
||||
|
||||
const activeSourceLabel = computed(() => {
|
||||
if (activeSource.value === 'keyboard') return 'Keyboard'
|
||||
if (activeSource.value === 'gamepad') return 'Gamepad'
|
||||
return 'Idle'
|
||||
if (activeSource.value === 'keyboard') return t('common.keyboard')
|
||||
if (activeSource.value === 'gamepad') return t('common.gamepad')
|
||||
return t('common.idle')
|
||||
})
|
||||
|
||||
const controlInputModeLabel = computed(() => {
|
||||
if (controlInputMode.value === 'gamepad') return 'Gamepad'
|
||||
return 'Keyboard'
|
||||
if (controlInputMode.value === 'gamepad') return t('common.gamepad')
|
||||
return t('common.keyboard')
|
||||
})
|
||||
|
||||
const lastServerMessage = computed(() => {
|
||||
if (lastServerMessageOverride.value) {
|
||||
return lastServerMessageOverride.value
|
||||
}
|
||||
return lastServerMessagePreset.value === 'live' ? t('control.server.live') : t('control.server.waiting')
|
||||
})
|
||||
|
||||
const commandValues = computed(() => {
|
||||
@@ -625,12 +647,12 @@ const commandMagnitude = computed(() => {
|
||||
)
|
||||
})
|
||||
|
||||
const pressedKeysLabel = computed(() => Array.from(pressedKeys.value).sort().join(', ') || 'none')
|
||||
const pressedKeysLabel = computed(() => Array.from(pressedKeys.value).sort().join(', ') || t('common.none'))
|
||||
|
||||
const keyboardKeys = computed<KeyFeedback[]>(() =>
|
||||
TRACKED_KEYS.map((code) => ({
|
||||
code,
|
||||
label: KEY_LABELS[code] ?? code,
|
||||
label: code === 'Space' ? t('control.key.stop') : (KEY_LABELS[code] ?? code),
|
||||
pressed: pressedKeys.value.has(code),
|
||||
})),
|
||||
)
|
||||
@@ -657,6 +679,13 @@ const gamepadButtons = computed<ButtonFeedback[]>(() =>
|
||||
})),
|
||||
)
|
||||
|
||||
const gamepadName = computed(() => {
|
||||
if (!gamepadConnected.value) {
|
||||
return t('control.gamepad.none')
|
||||
}
|
||||
return gamepadNameRaw.value || t('control.gamepad.unnamed')
|
||||
})
|
||||
|
||||
const gamepadLeftStick = computed(() => ({
|
||||
x: gamepadAxes.value[0] ?? 0,
|
||||
y: gamepadAxes.value[1] ?? 0,
|
||||
@@ -706,5 +735,14 @@ export function useControlInterface() {
|
||||
gamepadRightStick,
|
||||
gamepadAxes,
|
||||
gamepadActive: computed(() => gamepadActiveInternal()),
|
||||
operatorInputSequence,
|
||||
lastOperatorInputPerfMs,
|
||||
}
|
||||
}
|
||||
|
||||
export function useOperatorInputTelemetry() {
|
||||
return {
|
||||
operatorInputSequence,
|
||||
lastOperatorInputPerfMs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
|
||||
import { fetchDashboardSnapshot } from '@/lib/api'
|
||||
import { t } from '@/lib/locale'
|
||||
import type { GpsTelemetry, NetworkTelemetry, VideoStatus } from '@/types'
|
||||
|
||||
type UseMonitoringDataOptions = {
|
||||
@@ -25,7 +26,7 @@ export function useMonitoringData(options: UseMonitoringDataOptions = {}) {
|
||||
video.value = snapshot.video
|
||||
errorMessage.value = ''
|
||||
} catch (error) {
|
||||
errorMessage.value = error instanceof Error ? error.message : 'Failed to load monitoring data'
|
||||
errorMessage.value = error instanceof Error ? error.message : t('common.requestFailed', { status: '-', statusText: '' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -36,9 +37,9 @@ export function useMonitoringData(options: UseMonitoringDataOptions = {}) {
|
||||
return errorMessage.value
|
||||
}
|
||||
if (loading.value) {
|
||||
return 'Connecting to the Django backend and loading live monitoring data...'
|
||||
return t('monitoring.loading')
|
||||
}
|
||||
return 'Dashboard connected. Video, GPS, and live session telemetry refresh continuously from the unified A-side daemon.'
|
||||
return t('monitoring.connected')
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { DashboardSnapshot, VideoStatus } from '@/types'
|
||||
import { t } from '@/lib/locale'
|
||||
|
||||
const envBaseUrl = import.meta.env.VITE_API_BASE_URL as string | undefined
|
||||
|
||||
@@ -7,7 +8,7 @@ export const API_BASE = (envBaseUrl?.trim() || 'http://127.0.0.1:8001').replace(
|
||||
async function fetchJson<T>(path: string): Promise<T> {
|
||||
const response = await fetch(`${API_BASE}${path}`)
|
||||
if (!response.ok) {
|
||||
throw new Error(`请求失败: ${response.status} ${response.statusText}`)
|
||||
throw new Error(t('common.requestFailed', { status: response.status, statusText: response.statusText }))
|
||||
}
|
||||
return response.json() as Promise<T>
|
||||
}
|
||||
@@ -20,10 +21,36 @@ export function fetchVideoStatus() {
|
||||
return fetchJson<VideoStatus>('/api/video/status/')
|
||||
}
|
||||
|
||||
export async function fetchClockCalibrationSample() {
|
||||
const response = await fetch(`${API_BASE}/api/clock/calibrate/`, {
|
||||
cache: 'no-store',
|
||||
})
|
||||
if (!response.ok) {
|
||||
throw new Error(`clock calibration failed: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
return response.json() as Promise<{
|
||||
server_received_unix_ms: number
|
||||
server_sent_unix_ms: number
|
||||
}>
|
||||
}
|
||||
|
||||
export function buildVideoFrameUrl(frameKey: number) {
|
||||
return `${API_BASE}/api/video/frame/?frame=${frameKey}&t=${Date.now()}`
|
||||
}
|
||||
|
||||
export async function postVideoDisplayProbe(payload: Record<string, unknown>) {
|
||||
const response = await fetch(`${API_BASE}/api/video/display-probe/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
if (!response.ok) {
|
||||
throw new Error(`display probe post failed: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
}
|
||||
|
||||
export function buildControlWebSocketUrl() {
|
||||
const url = new URL(API_BASE, window.location.origin)
|
||||
const basePath = url.pathname.replace(/\/$/, '')
|
||||
|
||||
512
frontend/src/lib/locale.ts
Normal file
512
frontend/src/lib/locale.ts
Normal file
@@ -0,0 +1,512 @@
|
||||
import { computed, readonly, ref } from 'vue'
|
||||
|
||||
export type Locale = 'zh-CN' | 'en-US'
|
||||
|
||||
const LOCALE_STORAGE_KEY = 'robot-command-center.locale'
|
||||
const DEFAULT_LOCALE: Locale = 'zh-CN'
|
||||
|
||||
const zhCNMessages = {
|
||||
'common.loading': '加载中',
|
||||
'common.waiting': '等待中',
|
||||
'common.unavailable': '不可用',
|
||||
'common.unknown': '未知',
|
||||
'common.none': '无',
|
||||
'common.na': 'n/a',
|
||||
'common.yes': '是',
|
||||
'common.no': '否',
|
||||
'common.keyboard': '键盘',
|
||||
'common.gamepad': '手柄',
|
||||
'common.idle': '空闲',
|
||||
'common.control': '控制',
|
||||
'common.video': '视频',
|
||||
'common.online': '在线',
|
||||
'common.offline': '离线',
|
||||
'common.fresh': '新鲜',
|
||||
'common.stale': '过期',
|
||||
'common.stable': '稳定',
|
||||
'common.rising': '上升',
|
||||
'common.falling': '下降',
|
||||
'common.selected': '已选中',
|
||||
'common.standby': '待命',
|
||||
'common.turbo': '加速',
|
||||
'common.ackLoop': 'ACK 闭环',
|
||||
'common.srttFallback': 'SRTT 回退',
|
||||
'common.requestFailed': '请求失败: {status} {statusText}',
|
||||
'app.brandTitle': '机器人指挥中心',
|
||||
'app.brandSubtitle': '远程机器人控制台',
|
||||
'app.nav.overview': '概览',
|
||||
'app.nav.video': '视频',
|
||||
'app.nav.map': '地图定位',
|
||||
'app.nav.network': '网络状态',
|
||||
'app.localeToggle': 'English',
|
||||
'dashboard.eyebrow': '概览',
|
||||
'dashboard.title': '机器人指挥中心',
|
||||
'dashboard.description': 'A 端统一后台进程持续刷新视频、控制仲裁和链路遥测。',
|
||||
'networkView.eyebrow': '网络',
|
||||
'networkView.title': '网络遥测',
|
||||
'networkView.description': '查看 A <-> D 与 D <-> B 两段链路的实时队列、重传、窗口压力和延迟估计。',
|
||||
'videoView.eyebrow': '视频',
|
||||
'videoView.title': '视频监控',
|
||||
'videoView.description': '查看机器人实时 JPEG 视频流、画面新鲜度和端到端延迟估计。',
|
||||
'mapView.eyebrow': '地图',
|
||||
'mapView.title': '地图定位',
|
||||
'mapView.description': '查看机器人最新 GPS 数据,并按需使用高德地图做坐标转换和展示。',
|
||||
'monitoring.loading': '正在连接 Django 后端并加载实时监控数据...',
|
||||
'monitoring.connected': '仪表盘已连接。视频、GPS 和会话遥测正在持续刷新。',
|
||||
'control.socket.open': 'WebSocket 已连接',
|
||||
'control.socket.connecting': '连接中',
|
||||
'control.socket.reconnecting': '重连中',
|
||||
'control.server.waiting': '等待控制链路就绪',
|
||||
'control.server.live': '控制链路已建立',
|
||||
'control.gamepad.none': '未检测到手柄',
|
||||
'control.gamepad.unnamed': '未命名手柄',
|
||||
'control.gamepad.unknownMapping': '未知映射',
|
||||
'control.key.stop': '停止',
|
||||
'controlPanel.eyebrow': '控制',
|
||||
'controlPanel.title': '控制反馈',
|
||||
'controlPanel.resetDefaults': '恢复默认',
|
||||
'controlPanel.inputModeEyebrow': '输入模式',
|
||||
'controlPanel.inputModeCopy': '同一时刻只能有一种本地输入模式控制页面。',
|
||||
'controlPanel.keyboardDetail': '使用 W/S、A/D、Q/E、Shift 和 Space。',
|
||||
'controlPanel.gamepadDetail': '仅使用浏览器识别到的手柄。',
|
||||
'controlPanel.forward': '前进',
|
||||
'controlPanel.strafe': '横移',
|
||||
'controlPanel.turn': '转向',
|
||||
'controlPanel.turbo': '加速',
|
||||
'controlPanel.keyboardHint': '键盘映射: W/S 前后, A/D 横移, Q/E 转向, Shift 加速, Space 停止。',
|
||||
'controlPanel.tuningHint': '速度调节由两种本地输入模式共享,并保存在当前浏览器中。',
|
||||
'controlPanel.gamepadHint': '手柄模式下左摇杆控制移动,右摇杆控制转向,RB 加速,A 发送停止。',
|
||||
'controlFeedback.modeChip': '{mode} 模式',
|
||||
'controlFeedback.forward': '前进',
|
||||
'controlFeedback.strafe': '横移',
|
||||
'controlFeedback.turn': '转向',
|
||||
'controlFeedback.tuningSummary': '调参: 前进 {forward} m/s, 横移 {strafe} m/s, 转向 {turn} rad/s, 加速 x{turbo}',
|
||||
'controlFeedback.keyboard': '键盘',
|
||||
'controlFeedback.gamepad': '手柄',
|
||||
'controlFeedback.waitingForController': '等待手柄接入',
|
||||
'controlFeedback.gamepadMeta': '#{index} / 映射={mapping}',
|
||||
'controlFeedback.gamepadHint': '左摇杆控制移动,右摇杆控制转向,RB 加速,A 停止。',
|
||||
'controlFeedback.leftStick': '左摇杆',
|
||||
'controlFeedback.rightStick': '右摇杆',
|
||||
'controlFeedback.outgoingCommand': '当前发出命令: {command}',
|
||||
'videoPanel.eyebrow': '视频',
|
||||
'videoPanel.title': '实时视频',
|
||||
'videoPanel.frameAlt': '机器人实时画面',
|
||||
'videoPanel.waitingFrames': '等待实时视频帧',
|
||||
'videoPanel.mode.loading': '加载中',
|
||||
'videoPanel.mode.live': '{fps} FPS 实时',
|
||||
'videoPanel.stats.frames': '帧数',
|
||||
'videoPanel.stats.latestSeq': '最新序号',
|
||||
'videoPanel.stats.videoE2E': '视频端到端估计',
|
||||
'videoPanel.stats.paintDelay': '绘制延迟',
|
||||
'videoPanel.section.pipeline': '流水线估计',
|
||||
'videoPanel.section.freshness': '新鲜度',
|
||||
'videoPanel.section.operator': '操作员闭环',
|
||||
'videoPanel.captureToSend': '采集到发送',
|
||||
'videoPanel.networkOneWay': '网络单程',
|
||||
'videoPanel.partialEstimate': '部分估计',
|
||||
'videoPanel.endToEndEstimate': '端到端估计',
|
||||
'videoPanel.interFrameAvg': '帧间平均',
|
||||
'videoPanel.interFrameP95': '帧间 p95',
|
||||
'videoPanel.repeatedRatio': '重复比例',
|
||||
'videoPanel.skipRatio': '跳帧比例',
|
||||
'videoPanel.longestFreeze': '最长卡顿',
|
||||
'videoPanel.lagFrames': '落后帧数',
|
||||
'videoPanel.inputToNextSeq': '输入到下一新序号',
|
||||
'videoPanel.inputToChangedFrame': '输入到下一变化帧',
|
||||
'videoPanel.inputToPaint': '输入到下一次绘制',
|
||||
'videoPanel.displayProbeRequestToPaint': '显示探针请求到绘制',
|
||||
'videoPanel.senderClockDelta': '发送端时钟差',
|
||||
'videoPanel.timing.waiting': '等待中',
|
||||
'videoPanel.timing.noTrailer': '正在等待第一帧带有效 trailer 的视频数据',
|
||||
'videoPanel.timing.rawHint': '这里只显示发送端原始时钟差,设备时钟未同步',
|
||||
'videoPanel.noSourceDetail': '暂无实时视频详情',
|
||||
'networkPanel.eyebrow': '网络',
|
||||
'networkPanel.title': '双段链路遥测',
|
||||
'networkPanel.controlLoopRtt': '控制闭环 RTT',
|
||||
'networkPanel.controlToPersist': '控制到持久化',
|
||||
'networkPanel.controlSrttOneWay': '控制单程 SRTT',
|
||||
'networkPanel.videoOneWayEst': '视频单程估计',
|
||||
'networkPanel.txRate': '发送速率',
|
||||
'networkPanel.rxRate': '接收速率',
|
||||
'networkPanel.robotFault': '机器人故障',
|
||||
'networkPanel.recoveryState': '恢复状态',
|
||||
'networkPanel.healthConfidence': '健康置信度',
|
||||
'networkPanel.healthUpdated': '健康更新时间',
|
||||
'networkPanel.transport': '传输',
|
||||
'networkPanel.activeControl': '当前控制源',
|
||||
'networkPanel.lease': '租约',
|
||||
'networkPanel.ackMode': 'ACK 模式',
|
||||
'networkPanel.ackUpdated': 'ACK 更新时间',
|
||||
'networkPanel.telemetryPeer': '遥测 Peer',
|
||||
'networkPanel.telemetryRegistered': '遥测已注册',
|
||||
'networkPanel.hubFreshness': 'Hub 新鲜度',
|
||||
'networkPanel.hubState': 'Hub 状态',
|
||||
'networkPanel.telemetryReconnects': '遥测重连次数',
|
||||
'networkPanel.hubError': 'Hub 错误',
|
||||
'networkPanel.telemetrySessionError': '遥测会话错误',
|
||||
'networkPanel.online': '在线',
|
||||
'networkPanel.maxPressure': '最大压力',
|
||||
'networkPanel.queued': '排队量',
|
||||
'networkPanel.inFlightBuffer': '在途缓冲',
|
||||
'networkPanel.retransDelta': '重传增量',
|
||||
'networkPanel.repairRate': '修复率',
|
||||
'networkPanel.updated': '更新时间',
|
||||
'networkPanel.srtt': 'SRTT',
|
||||
'networkPanel.rttvar': 'RTTVAR',
|
||||
'networkPanel.rto': 'RTO',
|
||||
'networkPanel.sndWnd': '发送窗口',
|
||||
'networkPanel.rmtWnd': '远端窗口',
|
||||
'networkPanel.inflight': '在途',
|
||||
'networkPanel.windowLimit': '窗口上限',
|
||||
'networkPanel.pressure': '压力',
|
||||
'networkPanel.sndQueue': '发送队列',
|
||||
'networkPanel.sndBuffer': '发送缓冲',
|
||||
'networkPanel.queueDelta': '队列增量',
|
||||
'networkPanel.bufferDelta': '缓冲增量',
|
||||
'networkPanel.retrans': '重传',
|
||||
'networkPanel.fastRetrans': '快速重传',
|
||||
'networkPanel.lost': '丢失',
|
||||
'networkPanel.repeat': '重复',
|
||||
'networkPanel.appBytes': '应用字节',
|
||||
'networkPanel.registered': '已注册',
|
||||
'networkPanel.serverError': '服务端错误',
|
||||
'networkPanel.combined': '总计',
|
||||
'networkPanel.videoE2E': '视频端到端估计',
|
||||
'networkPanel.controlEstimateConfidence': '控制估计置信度',
|
||||
'networkPanel.videoFreshness': '视频新鲜度',
|
||||
'networkPanel.videoFreshnessRepeat': '重复',
|
||||
'networkPanel.videoFreshnessSkip': '跳帧',
|
||||
'networkPanel.videoFreshnessFreeze': '卡顿',
|
||||
'networkPanel.nativeUdp': '原生 UDP',
|
||||
'networkPanel.controlSender': '控制发送端',
|
||||
'networkPanel.ackReceiver': 'ACK 接收端',
|
||||
'networkPanel.controlReconnects': '控制重连次数',
|
||||
'networkPanel.controlSessionError': '控制会话错误',
|
||||
'networkPanel.loadingPeer': '加载中',
|
||||
'networkPanel.unassigned': '未分配',
|
||||
'gpsMap.eyebrow': 'GPS',
|
||||
'gpsMap.title': '地图定位',
|
||||
'gpsMap.intro': '这里展示机器人最新的 GPS 定位,并在需要时调用高德地图做坐标转换。',
|
||||
'gpsMap.keyPlaceholder': '高德 Web 端 Key',
|
||||
'gpsMap.jscodePlaceholder': '安全密钥 jscode',
|
||||
'gpsMap.loadMap': '加载地图',
|
||||
'gpsMap.stopMap': '停止加载',
|
||||
'gpsMap.status.waitingInit': '等待加载高德地图。',
|
||||
'gpsMap.status.fillCredentials': '请先填写高德 Key 和安全密钥 jscode。',
|
||||
'gpsMap.status.loading': '正在加载高德地图...',
|
||||
'gpsMap.status.loaded': '地图已加载。',
|
||||
'gpsMap.status.stopped': '已停止高德地图加载与坐标转换。需要时再点击“加载地图”即可。',
|
||||
'gpsMap.status.waitingGps': '等待 GPS 数据。',
|
||||
'gpsMap.status.noFix': 'GPS 在线,但当前还没有有效定位。',
|
||||
'gpsMap.status.convertFailed': 'GPS 坐标转换失败。',
|
||||
'gpsMap.status.refreshedSource': '地图已刷新,数据源: {source}',
|
||||
'gpsMap.status.restoredConfig': '已恢复高德配置。地图不会自动加载,按需点击“加载地图”。',
|
||||
'gpsMap.status.loadFailed': '地图加载失败。',
|
||||
'gpsMap.mapPlaceholder': '高德地图当前未加载。点击上方“加载地图”后才会开始请求地图与坐标转换服务。',
|
||||
'gpsMap.wgs84': 'WGS84 坐标',
|
||||
'gpsMap.gcj02': '高德 GCJ-02',
|
||||
'gpsMap.rawLatHex': '纬度原始 8 字节',
|
||||
'gpsMap.rawLonHex': '经度原始 8 字节',
|
||||
'gpsMap.utcTime': 'UTC 时间',
|
||||
'gpsMap.satAltitude': '卫星 / 海拔',
|
||||
'gpsMap.coordMeta': '坐标系 / 格式',
|
||||
'gpsMap.lastUpdated': '最近刷新',
|
||||
'gpsMap.noValue': '暂无',
|
||||
'gpsMap.noValidFix': '暂无有效定位',
|
||||
'gpsMap.infoTitle': '机器人 GPS 定位',
|
||||
'gpsMap.infoSatellites': '卫星数',
|
||||
'gpsMap.infoAltitude': '海拔',
|
||||
} as const
|
||||
|
||||
export type MessageKey = keyof typeof zhCNMessages
|
||||
|
||||
const enUSMessages: Record<MessageKey, string> = {
|
||||
'common.loading': 'Loading',
|
||||
'common.waiting': 'Waiting',
|
||||
'common.unavailable': 'Unavailable',
|
||||
'common.unknown': 'Unknown',
|
||||
'common.none': 'None',
|
||||
'common.na': 'n/a',
|
||||
'common.yes': 'Yes',
|
||||
'common.no': 'No',
|
||||
'common.keyboard': 'Keyboard',
|
||||
'common.gamepad': 'Gamepad',
|
||||
'common.idle': 'Idle',
|
||||
'common.control': 'Control',
|
||||
'common.video': 'Video',
|
||||
'common.online': 'Online',
|
||||
'common.offline': 'Offline',
|
||||
'common.fresh': 'Fresh',
|
||||
'common.stale': 'Stale',
|
||||
'common.stable': 'Stable',
|
||||
'common.rising': 'Rising',
|
||||
'common.falling': 'Falling',
|
||||
'common.selected': 'Selected',
|
||||
'common.standby': 'Standby',
|
||||
'common.turbo': 'Turbo',
|
||||
'common.ackLoop': 'ACK loop',
|
||||
'common.srttFallback': 'SRTT fallback',
|
||||
'common.requestFailed': 'Request failed: {status} {statusText}',
|
||||
'app.brandTitle': 'Robot Command Center',
|
||||
'app.brandSubtitle': 'Remote robot command console',
|
||||
'app.nav.overview': 'Overview',
|
||||
'app.nav.video': 'Video',
|
||||
'app.nav.map': 'Map',
|
||||
'app.nav.network': 'Network',
|
||||
'app.localeToggle': '中文',
|
||||
'dashboard.eyebrow': 'Overview',
|
||||
'dashboard.title': 'Robot Command Center',
|
||||
'dashboard.description': 'The A-side unified backend keeps video, control arbitration, and live transport telemetry refreshed.',
|
||||
'networkView.eyebrow': 'Network',
|
||||
'networkView.title': 'Network Telemetry',
|
||||
'networkView.description': 'Inspect queueing, retransmissions, window pressure, and latency estimates for the A <-> D and D <-> B legs.',
|
||||
'videoView.eyebrow': 'Video',
|
||||
'videoView.title': 'Video Monitor',
|
||||
'videoView.description': 'Inspect the live robot JPEG stream, freshness metrics, and end-to-end latency estimates.',
|
||||
'mapView.eyebrow': 'Map',
|
||||
'mapView.title': 'Map Positioning',
|
||||
'mapView.description': 'Inspect the latest robot GPS fix and use AMap for coordinate conversion when needed.',
|
||||
'monitoring.loading': 'Connecting to the Django backend and loading live monitoring data...',
|
||||
'monitoring.connected': 'Dashboard connected. Video, GPS, and session telemetry are refreshing continuously.',
|
||||
'control.socket.open': 'WebSocket open',
|
||||
'control.socket.connecting': 'Connecting',
|
||||
'control.socket.reconnecting': 'Reconnecting',
|
||||
'control.server.waiting': 'Waiting for control link',
|
||||
'control.server.live': 'Control link live',
|
||||
'control.gamepad.none': 'No gamepad detected',
|
||||
'control.gamepad.unnamed': 'Unnamed gamepad',
|
||||
'control.gamepad.unknownMapping': 'unknown',
|
||||
'control.key.stop': 'Stop',
|
||||
'controlPanel.eyebrow': 'Control',
|
||||
'controlPanel.title': 'Control Feedback',
|
||||
'controlPanel.resetDefaults': 'Reset Defaults',
|
||||
'controlPanel.inputModeEyebrow': 'Input Mode',
|
||||
'controlPanel.inputModeCopy': 'Only one local input mode can control the page at a time.',
|
||||
'controlPanel.keyboardDetail': 'Use W/S, A/D, Q/E, Shift, and Space.',
|
||||
'controlPanel.gamepadDetail': 'Use the browser-detected controller only.',
|
||||
'controlPanel.forward': 'Forward',
|
||||
'controlPanel.strafe': 'Strafe',
|
||||
'controlPanel.turn': 'Turn',
|
||||
'controlPanel.turbo': 'Turbo',
|
||||
'controlPanel.keyboardHint': 'Keyboard mapping: W/S forward-back, A/D strafe, Q/E turn, Shift turbo, Space stop.',
|
||||
'controlPanel.tuningHint': 'Speed tuning is shared by both local input modes and saved in this browser.',
|
||||
'controlPanel.gamepadHint': 'Gamepad mode uses the left stick to drive, the right stick to turn, RB to boost, and A to stop.',
|
||||
'controlFeedback.modeChip': '{mode} mode',
|
||||
'controlFeedback.forward': 'Forward',
|
||||
'controlFeedback.strafe': 'Strafe',
|
||||
'controlFeedback.turn': 'Turn',
|
||||
'controlFeedback.tuningSummary': 'Tuning: fwd {forward} m/s, strafe {strafe} m/s, turn {turn} rad/s, turbo x{turbo}',
|
||||
'controlFeedback.keyboard': 'Keyboard',
|
||||
'controlFeedback.gamepad': 'Gamepad',
|
||||
'controlFeedback.waitingForController': 'Waiting for controller',
|
||||
'controlFeedback.gamepadMeta': '#{index} / mapping={mapping}',
|
||||
'controlFeedback.gamepadHint': 'Left stick drives, right stick turns, RB boosts, A stops.',
|
||||
'controlFeedback.leftStick': 'Left stick',
|
||||
'controlFeedback.rightStick': 'Right stick',
|
||||
'controlFeedback.outgoingCommand': 'Outgoing command: {command}',
|
||||
'videoPanel.eyebrow': 'Video',
|
||||
'videoPanel.title': 'Live Video',
|
||||
'videoPanel.frameAlt': 'Robot live frame',
|
||||
'videoPanel.waitingFrames': 'waiting for live video frames',
|
||||
'videoPanel.mode.loading': 'loading',
|
||||
'videoPanel.mode.live': '{fps} FPS live',
|
||||
'videoPanel.stats.frames': 'Frames',
|
||||
'videoPanel.stats.latestSeq': 'Latest Seq',
|
||||
'videoPanel.stats.videoE2E': 'Video E2E Est.',
|
||||
'videoPanel.stats.paintDelay': 'Paint Delay',
|
||||
'videoPanel.section.pipeline': 'Pipeline Estimate',
|
||||
'videoPanel.section.freshness': 'Freshness',
|
||||
'videoPanel.section.operator': 'Operator Loop',
|
||||
'videoPanel.captureToSend': 'Capture to send',
|
||||
'videoPanel.networkOneWay': 'Network one-way',
|
||||
'videoPanel.partialEstimate': 'Partial estimate',
|
||||
'videoPanel.endToEndEstimate': 'End-to-end estimate',
|
||||
'videoPanel.interFrameAvg': 'Inter-frame avg',
|
||||
'videoPanel.interFrameP95': 'Inter-frame p95',
|
||||
'videoPanel.repeatedRatio': 'Repeated ratio',
|
||||
'videoPanel.skipRatio': 'Skip ratio',
|
||||
'videoPanel.longestFreeze': 'Longest freeze',
|
||||
'videoPanel.lagFrames': 'Lag frames',
|
||||
'videoPanel.inputToNextSeq': 'Input to next seq',
|
||||
'videoPanel.inputToChangedFrame': 'Input to changed frame',
|
||||
'videoPanel.inputToPaint': 'Input to paint',
|
||||
'videoPanel.displayProbeRequestToPaint': 'Display probe request-to-paint',
|
||||
'videoPanel.senderClockDelta': 'Sender Clock Delta',
|
||||
'videoPanel.timing.waiting': 'waiting',
|
||||
'videoPanel.timing.noTrailer': 'waiting for the first valid video trailer',
|
||||
'videoPanel.timing.rawHint': 'raw sender clock delta only, unsynced clocks',
|
||||
'videoPanel.noSourceDetail': 'no live video detail available',
|
||||
'networkPanel.eyebrow': 'Network',
|
||||
'networkPanel.title': 'Dual-Leg Telemetry',
|
||||
'networkPanel.controlLoopRtt': 'Control Loop RTT',
|
||||
'networkPanel.controlToPersist': 'Control to Persist',
|
||||
'networkPanel.controlSrttOneWay': 'Control SRTT One-way',
|
||||
'networkPanel.videoOneWayEst': 'Video One-way Est.',
|
||||
'networkPanel.txRate': 'TX Rate',
|
||||
'networkPanel.rxRate': 'RX Rate',
|
||||
'networkPanel.robotFault': 'Robot Fault',
|
||||
'networkPanel.recoveryState': 'Recovery State',
|
||||
'networkPanel.healthConfidence': 'Health Confidence',
|
||||
'networkPanel.healthUpdated': 'Health Updated',
|
||||
'networkPanel.transport': 'Transport',
|
||||
'networkPanel.activeControl': 'Active Control',
|
||||
'networkPanel.lease': 'Lease',
|
||||
'networkPanel.ackMode': 'ACK Mode',
|
||||
'networkPanel.ackUpdated': 'ACK Updated',
|
||||
'networkPanel.telemetryPeer': 'Telemetry Peer',
|
||||
'networkPanel.telemetryRegistered': 'Telemetry Registered',
|
||||
'networkPanel.hubFreshness': 'Hub Freshness',
|
||||
'networkPanel.hubState': 'Hub State',
|
||||
'networkPanel.telemetryReconnects': 'Telemetry Reconnects',
|
||||
'networkPanel.hubError': 'Hub Error',
|
||||
'networkPanel.telemetrySessionError': 'Telemetry Session Error',
|
||||
'networkPanel.online': 'Online',
|
||||
'networkPanel.maxPressure': 'Max Pressure',
|
||||
'networkPanel.queued': 'Queued',
|
||||
'networkPanel.inFlightBuffer': 'In Flight Buffer',
|
||||
'networkPanel.retransDelta': 'Retrans Delta',
|
||||
'networkPanel.repairRate': 'Repair Rate',
|
||||
'networkPanel.updated': 'Updated',
|
||||
'networkPanel.srtt': 'SRTT',
|
||||
'networkPanel.rttvar': 'RTTVAR',
|
||||
'networkPanel.rto': 'RTO',
|
||||
'networkPanel.sndWnd': 'SND WND',
|
||||
'networkPanel.rmtWnd': 'RMT WND',
|
||||
'networkPanel.inflight': 'Inflight',
|
||||
'networkPanel.windowLimit': 'Window Limit',
|
||||
'networkPanel.pressure': 'Pressure',
|
||||
'networkPanel.sndQueue': 'SND Queue',
|
||||
'networkPanel.sndBuffer': 'SND Buffer',
|
||||
'networkPanel.queueDelta': 'Queue Delta',
|
||||
'networkPanel.bufferDelta': 'Buffer Delta',
|
||||
'networkPanel.retrans': 'Retrans',
|
||||
'networkPanel.fastRetrans': 'Fast Retrans',
|
||||
'networkPanel.lost': 'Lost',
|
||||
'networkPanel.repeat': 'Repeat',
|
||||
'networkPanel.appBytes': 'App Bytes',
|
||||
'networkPanel.registered': 'Registered',
|
||||
'networkPanel.serverError': 'Server Error',
|
||||
'networkPanel.combined': 'Combined',
|
||||
'networkPanel.videoE2E': 'Video E2E Est.',
|
||||
'networkPanel.controlEstimateConfidence': 'Control Estimate Confidence',
|
||||
'networkPanel.videoFreshness': 'Video Freshness',
|
||||
'networkPanel.videoFreshnessRepeat': 'repeat',
|
||||
'networkPanel.videoFreshnessSkip': 'skip',
|
||||
'networkPanel.videoFreshnessFreeze': 'freeze',
|
||||
'networkPanel.nativeUdp': 'Native UDP',
|
||||
'networkPanel.controlSender': 'Control Sender',
|
||||
'networkPanel.ackReceiver': 'ACK Receiver',
|
||||
'networkPanel.controlReconnects': 'Control Reconnects',
|
||||
'networkPanel.controlSessionError': 'Control Session Error',
|
||||
'networkPanel.loadingPeer': 'loading',
|
||||
'networkPanel.unassigned': 'unassigned',
|
||||
'gpsMap.eyebrow': 'GPS',
|
||||
'gpsMap.title': 'Map Positioning',
|
||||
'gpsMap.intro': 'This panel displays the latest robot GPS fix and uses AMap for coordinate conversion when needed.',
|
||||
'gpsMap.keyPlaceholder': 'AMap Web Key',
|
||||
'gpsMap.jscodePlaceholder': 'Security jscode',
|
||||
'gpsMap.loadMap': 'Load Map',
|
||||
'gpsMap.stopMap': 'Stop Loading',
|
||||
'gpsMap.status.waitingInit': 'Waiting to load AMap.',
|
||||
'gpsMap.status.fillCredentials': 'Please enter the AMap key and security jscode first.',
|
||||
'gpsMap.status.loading': 'Loading AMap...',
|
||||
'gpsMap.status.loaded': 'Map loaded.',
|
||||
'gpsMap.status.stopped': 'Stopped AMap loading and coordinate conversion. Click "Load Map" again when needed.',
|
||||
'gpsMap.status.waitingGps': 'Waiting for GPS data.',
|
||||
'gpsMap.status.noFix': 'GPS is online, but there is no valid fix yet.',
|
||||
'gpsMap.status.convertFailed': 'GPS coordinate conversion failed.',
|
||||
'gpsMap.status.refreshedSource': 'Map refreshed, source: {source}',
|
||||
'gpsMap.status.restoredConfig': 'Recovered saved AMap config. The map will not auto-load; click "Load Map" when needed.',
|
||||
'gpsMap.status.loadFailed': 'Map loading failed.',
|
||||
'gpsMap.mapPlaceholder': 'AMap is not loaded right now. Click "Load Map" above before requesting map and coordinate conversion services.',
|
||||
'gpsMap.wgs84': 'WGS84 Coordinates',
|
||||
'gpsMap.gcj02': 'AMap GCJ-02',
|
||||
'gpsMap.rawLatHex': 'Raw Latitude 8 Bytes',
|
||||
'gpsMap.rawLonHex': 'Raw Longitude 8 Bytes',
|
||||
'gpsMap.utcTime': 'UTC Time',
|
||||
'gpsMap.satAltitude': 'Satellites / Altitude',
|
||||
'gpsMap.coordMeta': 'Coordinate System / Format',
|
||||
'gpsMap.lastUpdated': 'Last Updated',
|
||||
'gpsMap.noValue': 'Unavailable',
|
||||
'gpsMap.noValidFix': 'No valid fix',
|
||||
'gpsMap.infoTitle': 'Robot GPS Position',
|
||||
'gpsMap.infoSatellites': 'Satellites',
|
||||
'gpsMap.infoAltitude': 'Altitude',
|
||||
}
|
||||
|
||||
const messages: Record<Locale, Record<MessageKey, string>> = {
|
||||
'zh-CN': zhCNMessages,
|
||||
'en-US': enUSMessages,
|
||||
}
|
||||
|
||||
function normalizeLocale(raw: unknown): Locale {
|
||||
return raw === 'en-US' ? 'en-US' : DEFAULT_LOCALE
|
||||
}
|
||||
|
||||
function loadStoredLocale(): Locale {
|
||||
if (typeof window === 'undefined') {
|
||||
return DEFAULT_LOCALE
|
||||
}
|
||||
try {
|
||||
return normalizeLocale(window.localStorage.getItem(LOCALE_STORAGE_KEY))
|
||||
} catch {
|
||||
return DEFAULT_LOCALE
|
||||
}
|
||||
}
|
||||
|
||||
const localeState = ref<Locale>(loadStoredLocale())
|
||||
|
||||
function storeLocale(locale: Locale) {
|
||||
if (typeof window === 'undefined') {
|
||||
return
|
||||
}
|
||||
try {
|
||||
window.localStorage.setItem(LOCALE_STORAGE_KEY, locale)
|
||||
} catch {
|
||||
// Ignore storage failures; locale still works for current session.
|
||||
}
|
||||
}
|
||||
|
||||
function interpolate(template: string, params?: Record<string, string | number | null | undefined>) {
|
||||
if (!params) {
|
||||
return template
|
||||
}
|
||||
return template.replace(/\{(\w+)\}/g, (_, key: string) => String(params[key] ?? ''))
|
||||
}
|
||||
|
||||
export function t(key: MessageKey, params?: Record<string, string | number | null | undefined>) {
|
||||
const template = messages[localeState.value][key] ?? key
|
||||
return interpolate(template, params)
|
||||
}
|
||||
|
||||
export function formatDateTime(value?: string | null) {
|
||||
if (!value) {
|
||||
return t('common.unavailable')
|
||||
}
|
||||
return new Date(value).toLocaleString(localeState.value, { hour12: false })
|
||||
}
|
||||
|
||||
export function setLocale(locale: Locale) {
|
||||
const next = normalizeLocale(locale)
|
||||
if (localeState.value === next) {
|
||||
return
|
||||
}
|
||||
localeState.value = next
|
||||
storeLocale(next)
|
||||
}
|
||||
|
||||
export function toggleLocale() {
|
||||
setLocale(localeState.value === 'zh-CN' ? 'en-US' : 'zh-CN')
|
||||
}
|
||||
|
||||
export function useLocale() {
|
||||
return {
|
||||
locale: readonly(localeState),
|
||||
setLocale,
|
||||
toggleLocale,
|
||||
t,
|
||||
formatDateTime,
|
||||
nextLocaleLabel: computed(() => t('app.localeToggle')),
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ export interface GpsTelemetry {
|
||||
utc_time: string
|
||||
latitude: number | null
|
||||
longitude: number | null
|
||||
raw_latitude_hex?: string
|
||||
raw_longitude_hex?: string
|
||||
satellites: number | null
|
||||
altitude_m: number | null
|
||||
coordinate_system: string
|
||||
@@ -30,7 +32,9 @@ export interface SessionKcpStats {
|
||||
conv?: number
|
||||
rto_ms?: number
|
||||
srtt_ms?: number
|
||||
min_srtt_ms?: number
|
||||
srttvar_ms?: number
|
||||
last_feedback_age_ms?: number
|
||||
snd_wnd?: number
|
||||
rmt_wnd?: number
|
||||
inflight?: number
|
||||
@@ -131,6 +135,16 @@ export interface ControlSenderStatus {
|
||||
last_error: string
|
||||
}
|
||||
|
||||
export interface ControlAckReceiverStatus {
|
||||
backend_ready: boolean
|
||||
started: boolean
|
||||
connected: boolean
|
||||
peer_id: string
|
||||
expected_sender: string
|
||||
reconnect_count: number
|
||||
last_error: string
|
||||
}
|
||||
|
||||
export interface TelemetryReceiverStatus {
|
||||
hub_connected: boolean
|
||||
hub_updated_at: string | null
|
||||
@@ -142,6 +156,54 @@ export interface TelemetryReceiverStatus {
|
||||
reconnect_count: number
|
||||
}
|
||||
|
||||
export interface RobotHealthStatus {
|
||||
fault_reason: string
|
||||
recovery_state: string
|
||||
confidence: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface VideoFreshnessStatus {
|
||||
inter_frame_avg_ms: number | null
|
||||
inter_frame_p95_ms: number | null
|
||||
repeated_frame_ratio: number
|
||||
skip_ratio: number
|
||||
longest_freeze_ms: number
|
||||
stale_frame_run_length: number
|
||||
relative_freshness_lag_frames: number
|
||||
}
|
||||
|
||||
export interface LatencyEstimateStatus {
|
||||
control_loop_rtt_ms: number | null
|
||||
control_to_persist_est_ms: number | null
|
||||
control_oneway_srtt_est_ms: number | null
|
||||
control_oneway_bestcase_est_ms: number | null
|
||||
video_network_oneway_est_ms: number | null
|
||||
video_partial_est_ms: number | null
|
||||
video_e2e_est_ms: number | null
|
||||
estimate_method: {
|
||||
control: string
|
||||
video: string
|
||||
}
|
||||
clock_sync_required: boolean
|
||||
assumptions: string[]
|
||||
confidence: {
|
||||
control: string
|
||||
video: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface ControlAckStatus {
|
||||
ack_available: boolean
|
||||
updated_at: string | null
|
||||
control_loop_rtt_ms: number | null
|
||||
b_recv_to_persist_ms: number | null
|
||||
control_oneway_network_est_ms: number | null
|
||||
control_to_persist_est_ms: number | null
|
||||
sample_reason: string | null
|
||||
receiver: ControlAckReceiverStatus
|
||||
}
|
||||
|
||||
export interface NetworkTelemetry {
|
||||
peer_status: string
|
||||
latency_ms: number | null
|
||||
@@ -169,13 +231,18 @@ export interface NetworkTelemetry {
|
||||
a_to_d: LinkTelemetry
|
||||
d_to_b: LinkTelemetry
|
||||
}
|
||||
latency_estimate: LatencyEstimateStatus
|
||||
video_freshness: VideoFreshnessStatus
|
||||
control_ack_status: ControlAckStatus
|
||||
telemetry_receiver: TelemetryReceiverStatus
|
||||
robot_health: RobotHealthStatus
|
||||
ingress: {
|
||||
native_udp: NativeUdpIngress
|
||||
}
|
||||
control: {
|
||||
arbiter: ControlArbiterStatus
|
||||
sender: ControlSenderStatus
|
||||
ack_receiver: ControlAckReceiverStatus
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,12 +255,32 @@ export interface VideoStatus {
|
||||
source_detail?: string
|
||||
timing?: {
|
||||
available: boolean
|
||||
latest_delta_ms: number | null
|
||||
delta_samples_ms: number[]
|
||||
sender_clock_delta_ms_raw: number | null
|
||||
sender_clock_delta_samples_ms_raw: number[]
|
||||
sample_count: number
|
||||
sample_window_size: number
|
||||
timestamp_unit: string | null
|
||||
timestamp_endianness: string | null
|
||||
unsynced_clock: boolean
|
||||
}
|
||||
freshness?: VideoFreshnessStatus
|
||||
display_probe?: {
|
||||
updated_at: string | null
|
||||
frame_seq: number | null
|
||||
frame_hash: string
|
||||
input_to_next_fresh_frame_ms: number | null
|
||||
input_to_next_changed_frame_ms: number | null
|
||||
input_to_next_paint_ms: number | null
|
||||
request_to_paint_ms: number | null
|
||||
response_to_paint_ms: number | null
|
||||
backend_to_request_ms: number | null
|
||||
backend_to_request_ms_raw: number | null
|
||||
backend_to_paint_ms: number | null
|
||||
backend_to_paint_ms_raw: number | null
|
||||
browser_backend_clock_offset_ms: number | null
|
||||
browser_backend_clock_rtt_ms: number | null
|
||||
browser_backend_clock_sample_count: number
|
||||
browser_backend_clock_calibrated_at: string | null
|
||||
}
|
||||
receiver?: {
|
||||
backend_ready: boolean
|
||||
@@ -203,6 +290,11 @@ export interface VideoStatus {
|
||||
has_recent_frame: boolean
|
||||
frames_received: number
|
||||
latest_sequence: number | null
|
||||
latest_frame_hash?: string
|
||||
latest_backend_received_unix_ns?: number | null
|
||||
latest_backend_received_mono_ns?: number | null
|
||||
latest_frame_bytes?: number
|
||||
latest_capture_to_send_ms?: number | null
|
||||
reconnect_count: number
|
||||
last_server_error: string
|
||||
last_error: string
|
||||
@@ -213,13 +305,15 @@ export interface VideoStatus {
|
||||
buffer_bytes?: number
|
||||
timing?: {
|
||||
available: boolean
|
||||
latest_delta_ms: number | null
|
||||
delta_samples_ms: number[]
|
||||
sender_clock_delta_ms_raw: number | null
|
||||
sender_clock_delta_samples_ms_raw: number[]
|
||||
sample_count: number
|
||||
sample_window_size: number
|
||||
timestamp_unit: string | null
|
||||
timestamp_endianness: string | null
|
||||
unsynced_clock: boolean
|
||||
}
|
||||
freshness?: VideoFreshnessStatus
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import ControlPanel from '@/components/ControlPanel.vue'
|
||||
import GpsMapPanel from '@/components/GpsMapPanel.vue'
|
||||
import NetworkPanel from '@/components/NetworkPanel.vue'
|
||||
import VideoPanel from '@/components/VideoPanel.vue'
|
||||
import { t } from '@/lib/locale'
|
||||
import { useMonitoringData } from '@/composables/useMonitoringData'
|
||||
|
||||
const { gps, network, video, errorMessage, headerStatus } = useMonitoringData()
|
||||
@@ -12,13 +13,10 @@ const { gps, network, video, errorMessage, headerStatus } = useMonitoringData()
|
||||
<div class="page-shell">
|
||||
<header class="hero">
|
||||
<div>
|
||||
<p class="eyebrow">Overview</p>
|
||||
<h1>Robot Command Center</h1>
|
||||
<p class="eyebrow">{{ t('dashboard.eyebrow') }}</p>
|
||||
<h1>{{ t('dashboard.title') }}</h1>
|
||||
</div>
|
||||
<p class="hero-text">
|
||||
The A-side daemon now owns video receive, control ingress arbitration, and live session
|
||||
telemetry in one backend process.
|
||||
</p>
|
||||
<p class="hero-text">{{ t('dashboard.description') }}</p>
|
||||
</header>
|
||||
|
||||
<section class="banner" :class="{ error: !!errorMessage }">
|
||||
@@ -27,7 +25,7 @@ const { gps, network, video, errorMessage, headerStatus } = useMonitoringData()
|
||||
|
||||
<main class="layout">
|
||||
<section class="primary-grid">
|
||||
<VideoPanel :video="video" />
|
||||
<VideoPanel :video="video" :network="network" />
|
||||
<ControlPanel />
|
||||
</section>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import GpsMapPanel from '@/components/GpsMapPanel.vue'
|
||||
import { t } from '@/lib/locale'
|
||||
import { useMonitoringData } from '@/composables/useMonitoringData'
|
||||
|
||||
const { gps, errorMessage, headerStatus } = useMonitoringData({
|
||||
@@ -11,13 +12,10 @@ const { gps, errorMessage, headerStatus } = useMonitoringData({
|
||||
<div class="page-shell">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<p class="eyebrow">Map</p>
|
||||
<h1>地图定位页面</h1>
|
||||
<p class="eyebrow">{{ t('mapView.eyebrow') }}</p>
|
||||
<h1>{{ t('mapView.title') }}</h1>
|
||||
</div>
|
||||
<p class="description">
|
||||
这里整合了 `GeoStream` 的 GPS 展示逻辑。只要原来的 GPS 模块继续写
|
||||
`gps_latest.json`,这个页面就能直接显示实时定位。
|
||||
</p>
|
||||
<p class="description">{{ t('mapView.description') }}</p>
|
||||
</header>
|
||||
|
||||
<section class="banner" :class="{ error: !!errorMessage }">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import NetworkPanel from '@/components/NetworkPanel.vue'
|
||||
import { t } from '@/lib/locale'
|
||||
import { useMonitoringData } from '@/composables/useMonitoringData'
|
||||
|
||||
const { network, errorMessage, headerStatus } = useMonitoringData({
|
||||
@@ -11,14 +12,10 @@ const { network, errorMessage, headerStatus } = useMonitoringData({
|
||||
<div class="page-shell">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<p class="eyebrow">Network</p>
|
||||
<h1>Network Telemetry</h1>
|
||||
<p class="eyebrow">{{ t('networkView.eyebrow') }}</p>
|
||||
<h1>{{ t('networkView.title') }}</h1>
|
||||
</div>
|
||||
<p class="description">
|
||||
Live dual-leg OmniSocket telemetry from the A-side daemon, separating the local `A <-> D`
|
||||
sessions from the hub-reported `D <-> B` leg with queue pressure, retransmission, and stale-link
|
||||
visibility.
|
||||
</p>
|
||||
<p class="description">{{ t('networkView.description') }}</p>
|
||||
</header>
|
||||
|
||||
<section class="banner" :class="{ error: !!errorMessage }">
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import VideoPanel from '@/components/VideoPanel.vue'
|
||||
import { t } from '@/lib/locale'
|
||||
import { useMonitoringData } from '@/composables/useMonitoringData'
|
||||
|
||||
const { video, errorMessage, headerStatus } = useMonitoringData()
|
||||
const { video, network, errorMessage, headerStatus } = useMonitoringData()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-shell">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<p class="eyebrow">Video</p>
|
||||
<h1>视频流页面</h1>
|
||||
<p class="eyebrow">{{ t('videoView.eyebrow') }}</p>
|
||||
<h1>{{ t('videoView.title') }}</h1>
|
||||
</div>
|
||||
<p class="description">这个页面专门用于看逐帧 JPEG 画面。前端会按固定频率请求单张 JPEG,后端每次返回一帧。</p>
|
||||
<p class="description">{{ t('videoView.description') }}</p>
|
||||
</header>
|
||||
|
||||
<section class="banner" :class="{ error: !!errorMessage }">
|
||||
{{ headerStatus }}
|
||||
</section>
|
||||
|
||||
<VideoPanel :video="video" />
|
||||
<VideoPanel :video="video" :network="network" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user