fix
This commit is contained in:
@ -7,7 +7,7 @@ import sys
|
||||
import threading
|
||||
import time
|
||||
from queue import Empty, Queue
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from typing import Dict, List, Optional, Sequence, Tuple
|
||||
|
||||
import numpy as np
|
||||
|
||||
@ -40,6 +40,7 @@ from rfg_adc_plotter.types import SweepAuxCurves, SweepInfo, SweepPacket
|
||||
|
||||
RAW_PLOT_MAX_POINTS = 4096
|
||||
RAW_WATERFALL_MAX_POINTS = 2048
|
||||
UI_MAX_PACKETS_PER_TICK = 8
|
||||
DEBUG_FRAME_LOG_EVERY = 10
|
||||
|
||||
|
||||
@ -242,6 +243,20 @@ def decimate_curve_for_display(
|
||||
return x_arr[display_idx], y_arr[display_idx]
|
||||
|
||||
|
||||
def coalesce_packets_for_ui(
|
||||
packets: Sequence[SweepPacket],
|
||||
*,
|
||||
max_packets: int = UI_MAX_PACKETS_PER_TICK,
|
||||
) -> Tuple[List[SweepPacket], int]:
|
||||
"""Keep only the newest packets so a burst cannot starve the Qt event loop."""
|
||||
packet_list = list(packets)
|
||||
limit = max(1, int(max_packets))
|
||||
if len(packet_list) <= limit:
|
||||
return packet_list, 0
|
||||
skipped = len(packet_list) - limit
|
||||
return packet_list[-limit:], skipped
|
||||
|
||||
|
||||
def resolve_visible_fft_curves(
|
||||
fft_complex: Optional[np.ndarray],
|
||||
fft_mag: Optional[np.ndarray],
|
||||
@ -1244,6 +1259,7 @@ def run_pyqtgraph(args) -> None:
|
||||
pass
|
||||
|
||||
processed_frames = 0
|
||||
ui_frames_skipped = 0
|
||||
ui_started_at = time.perf_counter()
|
||||
|
||||
def refresh_current_fft_cache(sweep_for_fft: np.ndarray, bins: int) -> None:
|
||||
@ -1257,14 +1273,20 @@ def run_pyqtgraph(args) -> None:
|
||||
runtime.current_fft_db = fft_mag_to_db(runtime.current_fft_mag)
|
||||
|
||||
def drain_queue() -> int:
|
||||
nonlocal processed_frames
|
||||
drained = 0
|
||||
nonlocal processed_frames, ui_frames_skipped
|
||||
pending_packets: List[SweepPacket] = []
|
||||
while True:
|
||||
try:
|
||||
sweep, info, aux_curves = queue.get_nowait()
|
||||
pending_packets.append(queue.get_nowait())
|
||||
except Empty:
|
||||
break
|
||||
drained += 1
|
||||
drained = len(pending_packets)
|
||||
if drained <= 0:
|
||||
return 0
|
||||
|
||||
pending_packets, skipped_packets = coalesce_packets_for_ui(pending_packets)
|
||||
ui_frames_skipped += skipped_packets
|
||||
for sweep, info, aux_curves in pending_packets:
|
||||
base_freqs = np.linspace(SWEEP_FREQ_MIN_GHZ, SWEEP_FREQ_MAX_GHZ, sweep.size, dtype=np.float64)
|
||||
runtime.full_current_aux_curves = None
|
||||
runtime.full_current_fft_source = None
|
||||
@ -1317,7 +1339,7 @@ def run_pyqtgraph(args) -> None:
|
||||
elapsed_s = max(time.perf_counter() - ui_started_at, 1e-9)
|
||||
frames_per_sec = float(processed_frames) / elapsed_s
|
||||
sys.stderr.write(
|
||||
"[debug] ui frames:%d rate:%.2f/s last_sweep:%s ch:%s width:%d queue:%d\n"
|
||||
"[debug] ui frames:%d rate:%.2f/s last_sweep:%s ch:%s width:%d queue:%d dropped:%d\n"
|
||||
% (
|
||||
processed_frames,
|
||||
frames_per_sec,
|
||||
@ -1325,10 +1347,10 @@ def run_pyqtgraph(args) -> None:
|
||||
str(info.get("ch") if isinstance(info, dict) else None),
|
||||
int(getattr(sweep, "size", 0)),
|
||||
int(queue_size),
|
||||
int(ui_frames_skipped),
|
||||
)
|
||||
)
|
||||
if drained > 0:
|
||||
update_physical_axes()
|
||||
update_physical_axes()
|
||||
return drained
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user