From 68bac23bcbc1ddeacf634c14ae7bb663fc2915cd Mon Sep 17 00:00:00 2001 From: kalmancito Date: Tue, 4 Aug 2026 00:35:03 +0200 Subject: [PATCH] Fix sign convention in SBAS message timestamp correction The symbol alignment term of compute_message_timestamp() used the opposite sign convention to the sample alignment term. In both aligners, true means the non-shifted hypothesis won (no correction) and false means the shifted one won (-1 unit), so the symbol term must be (symbol_aligned ? 0 : -1). Two of the unit tests added along with that function were failing as a result, which is what broke the check step of the CI on all three platforms. Also express the correction bound in whole code periods rather than comparing doubles at an exact boundary: the worst case is 3 code periods (1 from the sample-pairing ambiguity plus 2 from the symbol-pairing one), not 2, and the floating-point comparison was fragile at that boundary. Co-Authored-By: Claude Opus 5 --- .../sbas_l1_telemetry_decoder_gs.cc | 2 +- .../sbas_l1_telemetry_decoder_test.cc | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_gs.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_gs.cc index 54dd303f5..69581c905 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_gs.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/sbas_l1_telemetry_decoder_gs.cc @@ -129,7 +129,7 @@ double sbas_l1_telemetry_decoder_gs::compute_message_timestamp(double first_bit_ // Residual sub-bit correction: which of the two possible sample/symbol // alignments was chosen shifts the true message start by a few samples // with respect to the first bit's own timestamp. - const int32_t offset_samples = (sample_aligned ? 0 : -1) + D_SAMPLES_PER_SYMBOL * (symbol_aligned ? -1 : 0); + const int32_t offset_samples = (sample_aligned ? 0 : -1) + D_SAMPLES_PER_SYMBOL * (symbol_aligned ? 0 : -1); return first_bit_stamp_s + static_cast(offset_samples) * SBAS_L1_CODE_PERIOD_S; } diff --git a/tests/unit-tests/signal-processing-blocks/telemetry_decoder/sbas_l1_telemetry_decoder_test.cc b/tests/unit-tests/signal-processing-blocks/telemetry_decoder/sbas_l1_telemetry_decoder_test.cc index 2c04ef862..aac495880 100644 --- a/tests/unit-tests/signal-processing-blocks/telemetry_decoder/sbas_l1_telemetry_decoder_test.cc +++ b/tests/unit-tests/signal-processing-blocks/telemetry_decoder/sbas_l1_telemetry_decoder_test.cc @@ -18,6 +18,8 @@ #include "SBAS_L1.h" #include "sbas_l1_telemetry_decoder_gs.h" #include +#include +#include TEST(SbasL1TelemetryDecoderTest, TimestampMatchesFirstBitWhenFullyAligned) { @@ -32,18 +34,22 @@ TEST(SbasL1TelemetryDecoderTest, TimestampMatchesFirstBitWhenFullyAligned) TEST(SbasL1TelemetryDecoderTest, TimestampCorrectionIsBoundedBySymbolPeriod) { - // The residual sample/symbol alignment correction must never exceed one - // encoded symbol period: it only resolves a small, sub-bit ambiguity, not - // the block-level offset that used to cause ~1 s errors. + // The correction is always a whole number of code periods, and spans at + // most one code period (sample-pairing ambiguity) plus one symbol, i.e. + // two code periods (bit-pairing ambiguity). It only resolves a small + // sub-bit ambiguity, not the block-level offset that used to cause ~1 s + // errors. const double first_bit_stamp_s = 1000.0; - const double max_correction_s = 2.0 * SBAS_L1_CODE_PERIOD_S; // 1 symbol = 2 code periods + const int64_t max_correction_code_periods = 3; for (const bool sample_aligned : {false, true}) { for (const bool symbol_aligned : {false, true}) { const double message_stamp_s = sbas_l1_telemetry_decoder_gs::compute_message_timestamp(first_bit_stamp_s, sample_aligned, symbol_aligned); - EXPECT_NEAR(first_bit_stamp_s, message_stamp_s, max_correction_s); + const int64_t correction_code_periods = std::llround((first_bit_stamp_s - message_stamp_s) / SBAS_L1_CODE_PERIOD_S); + EXPECT_GE(correction_code_periods, 0); + EXPECT_LE(correction_code_periods, max_correction_code_periods); } } }