diff --git a/rfg_adc_plotter/cli.py b/rfg_adc_plotter/cli.py index edd50c4..6172d28 100644 --- a/rfg_adc_plotter/cli.py +++ b/rfg_adc_plotter/cli.py @@ -76,7 +76,7 @@ def build_parser() -> argparse.ArgumentParser: default=True, help=( "Новый бинарный протокол: точка несет пару int32 (avg_1, avg_2), " - "а свип считается как 10**(avg_1*0.001) - 10**(avg_2*0.001)" + "а свип считается как |10**(avg_1*0.001) - 10**(avg_2*0.001)|" ), ) parser.add_argument( diff --git a/rfg_adc_plotter/io/sweep_parser_core.py b/rfg_adc_plotter/io/sweep_parser_core.py index e9bc9b2..2772709 100644 --- a/rfg_adc_plotter/io/sweep_parser_core.py +++ b/rfg_adc_plotter/io/sweep_parser_core.py @@ -27,7 +27,9 @@ def log_value_to_linear(value: int) -> float: def log_pair_to_sweep(avg_1: int, avg_2: int) -> float: - return (log_value_to_linear(avg_1) - log_value_to_linear(avg_2)) * LOG_POSTSCALER + value_1 = log_value_to_linear(avg_1) + value_2 = log_value_to_linear(avg_2) + return abs(value_1 - value_2) * LOG_POSTSCALER class AsciiSweepParser: diff --git a/tests/test_sweep_parser_core.py b/tests/test_sweep_parser_core.py index 73a81a5..04c2f42 100644 --- a/tests/test_sweep_parser_core.py +++ b/tests/test_sweep_parser_core.py @@ -108,6 +108,9 @@ class SweepParserCoreTests(unittest.TestCase): self.assertAlmostEqual(events[1].y, log_pair_to_sweep(1500, 700), places=6) self.assertEqual(events[1].aux, (1500.0, 700.0)) + def test_log_pair_to_sweep_is_order_independent(self): + self.assertAlmostEqual(log_pair_to_sweep(1500, 700), log_pair_to_sweep(700, 1500), places=6) + def test_logscale_16bit_parser_uses_last_start_channel(self): parser = LogScale16BitX2BinaryParser() stream = _pack_log16_start(2) + _pack_log16_point(1, 100, 90)