diff options
author | rear1019 <rear1019@posteo.de> | 2020-01-03 13:36:49 +0100 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2020-01-03 22:59:59 -0800 |
commit | fddb0d4ebe36516ee7caa3ebf25cf411b62db6c0 (patch) | |
tree | 10bd8c60317185c51428b3eff10d87988c0c7cef | |
parent | 5d5d4efcf33d2651a3dcc1fbc3b019cd5f1d25a4 (diff) |
additive_scrambler: Fix count based reset
Count based reset in the additive scrambler may be delayed by a single
byte as reported in [1]. This happens whenever the work() function of
the block is called: The first value of reset_index in work() is d_count
- d_bytes where d_count is the number of bytes to output before a reset
and d_bytes is the number of bytes produced after a previous reset (in
the previous work() call). The very first reset is delayed by one byte
due to zero-based counting in work()’s loop /and/ a check of the reset
condition (i == reset_index) /after/ outputting a byte. (All following
resets are performed at the correct interval after 4 bytes.)
Example: With d_count = 4 and d_bytes = 0 the first reset is performed
at i = 4, but only after a fifth byte has been output.
Fix this error by checking the reset condition /before/ outputting a
byte. This removes different handling of tag and count based reset,
introduced by commit e3ad82e6d9 as a fix for delayed tag based reset
[2]. The fix for tag based reset should have been applied to the count
based reset as well (resulting in the same code as of this commit). The
error in count based reset has not been detected due to wrong QA code
(see previous commit).
Fixes #2926.
[1] https://github.com/gnuradio/gnuradio/issues/2926
[2] https://github.com/gnuradio/gnuradio/issues/1198
-rw-r--r-- | gr-digital/lib/additive_scrambler_bb_impl.cc | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/gr-digital/lib/additive_scrambler_bb_impl.cc b/gr-digital/lib/additive_scrambler_bb_impl.cc index af87ebc6bb..ae7bf5172e 100644 --- a/gr-digital/lib/additive_scrambler_bb_impl.cc +++ b/gr-digital/lib/additive_scrambler_bb_impl.cc @@ -109,35 +109,19 @@ int additive_scrambler_bb_impl::work(int noutput_items, unsigned char* out = (unsigned char*)output_items[0]; int reset_index = _get_next_reset_index(noutput_items); - if (d_count >= 0) { - for (int i = 0; i < noutput_items; i++) { - unsigned char scramble_byte = 0x00; - for (int k = 0; k < d_bits_per_byte; k++) { - scramble_byte ^= (d_lfsr.next_bit() << k); - } - out[i] = in[i] ^ scramble_byte; - d_bytes++; - if (i == reset_index) { - d_lfsr.reset(); - d_bytes = 0; - reset_index = _get_next_reset_index(noutput_items, reset_index); - } + for (int i = 0; i < noutput_items; i++) { + // Reset should occur at/before the item associated with the tag. + if (i == reset_index) { + d_lfsr.reset(); + d_bytes = 0; + reset_index = _get_next_reset_index(noutput_items, reset_index); } - } else { - for (int i = 0; i < noutput_items; i++) { - // Reset should occur at/before the item associated with the tag. - if (i == reset_index) { - d_lfsr.reset(); - d_bytes = 0; - reset_index = _get_next_reset_index(noutput_items, reset_index); - } - unsigned char scramble_byte = 0x00; - for (int k = 0; k < d_bits_per_byte; k++) { - scramble_byte ^= (d_lfsr.next_bit() << k); - } - out[i] = in[i] ^ scramble_byte; - d_bytes++; + unsigned char scramble_byte = 0x00; + for (int k = 0; k < d_bits_per_byte; k++) { + scramble_byte ^= (d_lfsr.next_bit() << k); } + out[i] = in[i] ^ scramble_byte; + d_bytes++; } return noutput_items; |