From 4a851382af977ceaa2dd73f282c3881e36f2330c Mon Sep 17 00:00:00 2001 From: daoyyy7777 <354528186+daoyyy7777@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:52:51 +0800 Subject: [PATCH 1/2] Test the units used for both telemetry plot channels Signed-off-by: daoyyy7777 <354528186+daoyyy7777@users.noreply.github.com> --- .../test_gps_l1_ca_telemetry_plot_sample.py | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 utils/python/tests/test_gps_l1_ca_telemetry_plot_sample.py diff --git a/utils/python/tests/test_gps_l1_ca_telemetry_plot_sample.py b/utils/python/tests/test_gps_l1_ca_telemetry_plot_sample.py new file mode 100644 index 000000000..75140f000 --- /dev/null +++ b/utils/python/tests/test_gps_l1_ca_telemetry_plot_sample.py @@ -0,0 +1,70 @@ +"""Tests for the units used by the GPS L1 C/A telemetry plots. + +Copyright (C) 2010-2026 (see AUTHORS file for a list of contributors) +SPDX-License-Identifier: GPL-3.0-or-later +""" + +import importlib.util +from pathlib import Path +import struct +import sys +import tempfile +from types import SimpleNamespace +import unittest +from unittest import mock + + +_UTILS_PATH = Path(__file__).resolve().parents[1] +_SPEC = importlib.util.spec_from_file_location( + 'telemetry_plot', _UTILS_PATH / 'gps_l1_ca_telemetry_plot_sample.py') +telemetry_plot = importlib.util.module_from_spec(_SPEC) +with mock.patch.object(sys, 'path', [str(_UTILS_PATH)] + sys.path): + _SPEC.loader.exec_module(telemetry_plot) + + +class TelemetryPlotTest(unittest.TestCase): + def test_current_symbol_tow_uses_dump_seconds(self): + records = { + 0: [(345600.125, 10, 345600.0, 1, 3), + (345600.145, 11, 345600.0, 1, 3)], + 1: [(345601.25, 20, 345600.0, 1, 8), + (345601.27, 21, 345600.0, 1, 8)], + } + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) + for channel, rows in records.items(): + # The decoder writes these scalars separately in native byte + # order. Both TOW fields have already been converted to seconds. + data = b''.join( + struct.pack('=' + fmt, value) + for row in rows + for fmt, value in zip(('d', 'Q', 'd', 'i', 'i'), row)) + (path / f'telemetry{channel}.dat').write_bytes(data) + + args = SimpleNamespace( + input_path=path, file_prefix='telemetry', first_channel=0, + channels=2, channel_a=0, channel_b=1, fig_path=path / 'plots', + output_format='png', show=False) + plotter = mock.Mock() + with mock.patch.object(telemetry_plot, 'parse_args', + return_value=args), \ + mock.patch.object(telemetry_plot, 'apply_publication_style'), \ + mock.patch.object(telemetry_plot, 'plt', plotter): + # Exercise main() and the real binary reader without opening + # figures or requiring an interactive plotting backend. + telemetry_plot.main() + + calls = plotter.plot.call_args_list + self.assertEqual(len(calls), 4) + for channel in (0, 1): + with self.subTest(channel=channel): + self.assertEqual(calls[channel].args[0], + [row[1] for row in records[channel]]) + self.assertEqual(calls[channel].args[1], + [row[0] for row in records[channel]]) + for channel in (0, 1): + self.assertEqual(calls[channel + 2].args[1], [345600.0, 345600.0]) + + +if __name__ == '__main__': + unittest.main() From 33f3618335e151787548594a36edaa91cac95ae9 Mon Sep 17 00:00:00 2001 From: daoyyy7777 <354528186+daoyyy7777@users.noreply.github.com> Date: Thu, 12 Nov 2026 09:55:52 +0800 Subject: [PATCH 2/2] Plot telemetry TOW values in their stored seconds Signed-off-by: daoyyy7777 <354528186+daoyyy7777@users.noreply.github.com> --- utils/python/gps_l1_ca_telemetry_plot_sample.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/python/gps_l1_ca_telemetry_plot_sample.py b/utils/python/gps_l1_ca_telemetry_plot_sample.py index 7f252c611..a2ea6d3b7 100755 --- a/utils/python/gps_l1_ca_telemetry_plot_sample.py +++ b/utils/python/gps_l1_ca_telemetry_plot_sample.py @@ -200,14 +200,15 @@ def main(): plt.gcf().canvas.manager.set_window_title( f"Telem_Current_Symbol_TOW_{args.channel_a}_{args.channel_b}.png" ) + # The dump writer stores seconds; "tow_current_symbol_ms" is a legacy key. plt.plot( data_a["tracking_sample_counter"], - [x / 1000 for x in data_a["tow_current_symbol_ms"]], + data_a["tow_current_symbol_ms"], "b", ) plt.plot( data_b["tracking_sample_counter"], - [x / 1000 for x in data_b["tow_current_symbol_ms"]], + data_b["tow_current_symbol_ms"], "r", ) plt.grid(True)