diff --git a/RFG_ADC_dataplotter.py b/RFG_ADC_dataplotter.py index 6bc43a7..e0bdd49 100755 --- a/RFG_ADC_dataplotter.py +++ b/RFG_ADC_dataplotter.py @@ -4,7 +4,7 @@ Формат строк: - "Sweep_start" — начало нового свипа (предыдущий считается завершённым) - - "stp X Y" — точка (индекс X, значение Y), все целые со знаком + - "s X Y" — точка (индекс X, значение Y), все целые со знаком Отрисовываются два графика: - Левый: последний полученный свип (Y vs X) @@ -248,14 +248,17 @@ class SweepReader(threading.Thread): self._stop = stop_event self._src: Optional[SerialLineSource] = None self._fancy = bool(fancy) + self._max_width: int = 0 def _finalize_current(self, xs, ys): if not xs: return max_x = max(xs) width = max_x + 1 + self._max_width = max(self._max_width, width) + target_width = self._max_width if self._fancy else width # Быстрый векторизованный путь - sweep = np.full((width,), np.nan, dtype=np.float32) + sweep = np.full((target_width,), np.nan, dtype=np.float32) try: idx = np.asarray(xs, dtype=np.int64) vals = np.asarray(ys, dtype=np.float32) @@ -263,9 +266,9 @@ class SweepReader(threading.Thread): except Exception: # Запасной путь for x, y in zip(xs, ys): - if 0 <= x < width: + if 0 <= x < target_width: sweep[x] = float(y) - # Дополнительная обработка пропусков: при --fancy заполняем внутренние разрывы + # Дополнительная обработка пропусков: при --fancy заполняем внутренние разрывы, края и дотягиваем до максимальной длины if self._fancy: try: known = ~np.isnan(sweep) @@ -276,6 +279,12 @@ class SweepReader(threading.Thread): if i1 - i0 > 1: avg = (sweep[i0] + sweep[i1]) * 0.5 sweep[i0 + 1 : i1] = avg + first_idx = int(known_idx[0]) + last_idx = int(known_idx[-1]) + if first_idx > 0: + sweep[:first_idx] = sweep[first_idx] + if last_idx < sweep.size - 1: + sweep[last_idx + 1 :] = sweep[last_idx] except Exception: # В случае ошибки просто оставляем как есть pass @@ -342,10 +351,10 @@ class SweepReader(threading.Thread): ys.clear() continue - # stp X Y (оба целые со знаком). Разделяем по любым пробелам/табам. + # s X Y (оба целые со знаком). Разделяем по любым пробелам/табам. if len(line) >= 3: parts = line.split() - if len(parts) >= 3 and parts[0].lower() == b"stp": + if len(parts) >= 3 and parts[0].lower() == b"s": try: x = int(parts[1], 10) y = int(parts[2], 10) # поддержка знака: "+…" и "-…"