diff --git a/rfg_vna_viewer.py b/rfg_vna_viewer.py index 36049c0..f0c1a3c 100644 --- a/rfg_vna_viewer.py +++ b/rfg_vna_viewer.py @@ -29,6 +29,7 @@ READ_CHUNK = 65536 MARKER_MAIN = 0x000A MARKER_REF = 0x00A8 +MAX_SWEEP_POINTS = 4096 # safety limit — force finalize if dict grows past this DATA_PATH = "/tmp/ttyADC_data" @@ -105,6 +106,11 @@ class SweepAccumulator: sweeps.append(sw) self._main[step] = (_i16(w2), _i16(w3)) self._last_main_step = step + # Safety: force finalize if accumulator grew too large + if len(self._main) >= MAX_SWEEP_POINTS: + sw = self._finalize() + if sw is not None: + sweeps.append(sw) del buf[:8] continue @@ -204,8 +210,8 @@ def process_main(main_ch1, main_ch2, ref_amplitude, ref_phase_aligned): # Normalize ch1/ch2 individually by ref amplitude ref_amp_safe = np.where(ref_amplitude > 1e-12, ref_amplitude, 1e-12) - norm_ch1 = ch1_v#ref_amp_safe - norm_ch2 = ch2_v#/ ref_amp_safe + norm_ch1 = ch1_v / ref_amp_safe + norm_ch2 = ch2_v / ref_amp_safe # Build normalized complex signal and subtract ref phase z_norm = (norm_ch1 + 1j * norm_ch2) * np.exp(-1j * ref_phase_aligned) @@ -298,6 +304,9 @@ def make_update(reader, accumulator, curves): sweep = sweeps[-1] # latest complete sweep n = sweep["num_points"] + print(f"[VNA] sweeps_in_batch={len(sweeps)} points={n} " + f"main_ch1_range=[{sweep['main_ch1'].min():.0f}..{sweep['main_ch1'].max():.0f}] " + f"ref_ch1_range=[{sweep['ref_ch1'].min():.0f}..{sweep['ref_ch1'].max():.0f}]") if n < 2: return