Merged -r9556:9560 from jcorgan/scr into trunk. Adds gr.scrambler_bb and gr.descramb...
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 12 Sep 2008 02:54:22 +0000 (02:54 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 12 Sep 2008 02:54:22 +0000 (02:54 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9561 221aa14e-8319-0410-a670-987f0aec2ac5

13 files changed:
gnuradio-core/src/lib/general/Makefile.am
gnuradio-core/src/lib/general/general.i
gnuradio-core/src/lib/general/gr_descrambler_bb.cc [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_descrambler_bb.h [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_descrambler_bb.i [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_scrambler_bb.cc [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_scrambler_bb.h [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_scrambler_bb.i [new file with mode: 0644]
gnuradio-core/src/lib/general/gri_lfsr.h
gnuradio-core/src/lib/general/qa_gri_lfsr.cc
gnuradio-core/src/lib/general/qa_gri_lfsr.h
gnuradio-core/src/python/gnuradio/gr/Makefile.am
gnuradio-core/src/python/gnuradio/gr/qa_scrambler.py [new file with mode: 0755]

index 8ee9001833d5d948a269d9fb68b53038459a6167..0243632532dbe53354488a7e433d70ad295d47d2 100644 (file)
@@ -163,7 +163,9 @@ libgeneral_la_SOURCES =             \
        gri_short_to_float.cc           \
        gri_uchar_to_float.cc           \
        malloc16.c                      \
-       gr_unpack_k_bits_bb.cc
+       gr_unpack_k_bits_bb.cc          \
+       gr_descrambler_bb.cc            \
+       gr_scrambler_bb.cc
 
 libgeneral_qa_la_SOURCES =             \
        qa_general.cc                   \
@@ -320,7 +322,9 @@ grinclude_HEADERS =                         \
        gri_uchar_to_float.h            \
        malloc16.h                      \
        random.h                        \
-       gr_unpack_k_bits_bb.h
+       gr_unpack_k_bits_bb.h           \
+       gr_descrambler_bb.h             \
+       gr_scrambler_bb.h
 
 
 noinst_HEADERS =                       \
@@ -448,7 +452,9 @@ swiginclude_HEADERS =                       \
        gri_agc_cc.i                    \
        gri_agc_ff.i                    \
        gri_agc2_cc.i                   \
-       gri_agc2_ff.i                   
+       gri_agc2_ff.i                   \
+       gr_descrambler_bb.i             \
+       gr_scrambler_bb.i
 
 
 CLEANFILES = $(BUILT_SOURCES) *.pyc
index 435271f797f010dad49403f512e18a61ca8f6110..8326b27b04d6fd04ab61084b0784236c5db0f609 100644 (file)
 #include <gr_cpfsk_bc.h>
 #include <gr_encode_ccsds_27_bb.h>
 #include <gr_decode_ccsds_27_fb.h>
+#include <gr_descrambler_bb.h>
+#include <gr_scrambler_bb.h>
 %}
 
 %include "gr_nop.i"
 %include "gr_cpfsk_bc.i"
 %include "gr_encode_ccsds_27_bb.i"
 %include "gr_decode_ccsds_27_fb.i"
+%include "gr_descrambler_bb.i"
+%include "gr_scrambler_bb.i"
diff --git a/gnuradio-core/src/lib/general/gr_descrambler_bb.cc b/gnuradio-core/src/lib/general/gr_descrambler_bb.cc
new file mode 100644 (file)
index 0000000..e173a8a
--- /dev/null
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_descrambler_bb.h>
+#include <gr_io_signature.h>
+
+gr_descrambler_bb_sptr
+gr_make_descrambler_bb(int mask, int seed, int len)
+{
+  return gr_descrambler_bb_sptr(new gr_descrambler_bb(mask, seed, len));
+}
+
+gr_descrambler_bb::gr_descrambler_bb(int mask, int seed, int len)
+  : gr_sync_block("descrambler_bb",
+                 gr_make_io_signature (1, 1, sizeof (unsigned char)),
+                 gr_make_io_signature (1, 1, sizeof (unsigned char))),
+    d_lfsr(mask, seed, len)
+{
+}
+
+int
+gr_descrambler_bb::work(int noutput_items,
+                     gr_vector_const_void_star &input_items,
+                     gr_vector_void_star &output_items)
+{
+  const unsigned char *in = (const unsigned char *) input_items[0];
+  unsigned char *out = (unsigned char *) output_items[0];
+
+  for (int i = 0; i < noutput_items; i++)
+    out[i] = d_lfsr.next_bit_descramble(in[i]);
+  
+  return noutput_items;
+}
diff --git a/gnuradio-core/src/lib/general/gr_descrambler_bb.h b/gnuradio-core/src/lib/general/gr_descrambler_bb.h
new file mode 100644 (file)
index 0000000..4fd8f4a
--- /dev/null
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef INCLUDED_GR_DESCRAMBLER_BB_H
+#define INCLUDED_GR_DESCRAMBLER_BB_H
+
+#include <gr_sync_block.h>
+#include "gri_lfsr.h"
+
+class gr_descrambler_bb;
+typedef boost::shared_ptr<gr_descrambler_bb> gr_descrambler_bb_sptr;
+
+gr_descrambler_bb_sptr gr_make_descrambler_bb(int mask, int seed, int len);
+
+/*!
+ * \brief Descramble an input stream using an LFSR
+ * 
+ * \param mask     Polynomial mask for LFSR
+ * \param seed     Initial shift register contents
+ * \param len      Shift register length
+ *
+ * \ingroup misc
+ */
+
+class gr_descrambler_bb : public gr_sync_block
+{
+  friend gr_descrambler_bb_sptr gr_make_descrambler_bb(int mask, int seed, int len);
+
+  gri_lfsr d_lfsr;
+
+  gr_descrambler_bb(int mask, int seed, int len);
+
+public:
+  int work(int noutput_items,
+          gr_vector_const_void_star &input_items,
+          gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_GR_DESCRAMBLER_BB_H */
diff --git a/gnuradio-core/src/lib/general/gr_descrambler_bb.i b/gnuradio-core/src/lib/general/gr_descrambler_bb.i
new file mode 100644 (file)
index 0000000..e93c50c
--- /dev/null
@@ -0,0 +1,31 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,descrambler_bb);
+
+gr_descrambler_bb_sptr gr_make_descrambler_bb(int mask, int seed, int len);
+
+class gr_descrambler_bb : public gr_sync_block
+{
+private:
+  gr_descrambler_bb(int mask, int seed, int len);
+};
diff --git a/gnuradio-core/src/lib/general/gr_scrambler_bb.cc b/gnuradio-core/src/lib/general/gr_scrambler_bb.cc
new file mode 100644 (file)
index 0000000..42f7090
--- /dev/null
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_scrambler_bb.h>
+#include <gr_io_signature.h>
+
+gr_scrambler_bb_sptr
+gr_make_scrambler_bb(int mask, int seed, int len)
+{
+  return gr_scrambler_bb_sptr(new gr_scrambler_bb(mask, seed, len));
+}
+
+gr_scrambler_bb::gr_scrambler_bb(int mask, int seed, int len)
+  : gr_sync_block("scrambler_bb",
+                 gr_make_io_signature (1, 1, sizeof (unsigned char)),
+                 gr_make_io_signature (1, 1, sizeof (unsigned char))),
+    d_lfsr(mask, seed, len)
+{
+}
+
+int
+gr_scrambler_bb::work(int noutput_items,
+                     gr_vector_const_void_star &input_items,
+                     gr_vector_void_star &output_items)
+{
+  const unsigned char *in = (const unsigned char *) input_items[0];
+  unsigned char *out = (unsigned char *) output_items[0];
+
+  for (int i = 0; i < noutput_items; i++)
+    out[i] = d_lfsr.next_bit_scramble(in[i]);
+  
+  return noutput_items;
+}
diff --git a/gnuradio-core/src/lib/general/gr_scrambler_bb.h b/gnuradio-core/src/lib/general/gr_scrambler_bb.h
new file mode 100644 (file)
index 0000000..a01b08d
--- /dev/null
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef INCLUDED_GR_SCRAMBLER_BB_H
+#define INCLUDED_GR_SCRAMBLER_BB_H
+
+#include <gr_sync_block.h>
+#include "gri_lfsr.h"
+
+class gr_scrambler_bb;
+typedef boost::shared_ptr<gr_scrambler_bb> gr_scrambler_bb_sptr;
+
+gr_scrambler_bb_sptr gr_make_scrambler_bb(int mask, int seed, int len);
+
+/*!
+ * \brief Scramble an input stream using an LFSR
+ * 
+ * \param mask     Polynomial mask for LFSR
+ * \param seed     Initial shift register contents
+ * \param len      Shift register length
+ *
+ * \ingroup misc
+ */
+
+class gr_scrambler_bb : public gr_sync_block
+{
+  friend gr_scrambler_bb_sptr gr_make_scrambler_bb(int mask, int seed, int len);
+
+  gri_lfsr d_lfsr;
+
+  gr_scrambler_bb(int mask, int seed, int len);
+
+public:
+  int work(int noutput_items,
+          gr_vector_const_void_star &input_items,
+          gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_GR_SCRAMBLER_BB_H */
diff --git a/gnuradio-core/src/lib/general/gr_scrambler_bb.i b/gnuradio-core/src/lib/general/gr_scrambler_bb.i
new file mode 100644 (file)
index 0000000..9a607c4
--- /dev/null
@@ -0,0 +1,31 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,scrambler_bb);
+
+gr_scrambler_bb_sptr gr_make_scrambler_bb(int mask, int seed, int len);
+
+class gr_scrambler_bb : public gr_sync_block
+{
+private:
+  gr_scrambler_bb(int mask, int seed, int len);
+};
index 29873698c178c8198bc5be4c59c7eb88c7cae1ac..b6eee76793f393824455cf2972e4ef70af3bfba5 100644 (file)
  *
  *
  *
- *  next_bit() - performs once cycle of the lfsr,
- *               generating the new high order bit from the mask
- *               and returning the low order bit which has been
- *               shifted out of the register.
+ *  next_bit() - Standard LFSR operation
+ * 
+ *      Perform one cycle of the LFSR.  The output bit is taken from
+ *      the shift register LSB.  The shift register MSB is assigned from
+ *      the modulo 2 sum of the masked shift register.
+ *             
+ *  next_bit_scramble(unsigned char input) - Scramble an input stream
+ * 
+ *      Perform one cycle of the LFSR.  The output bit is taken from
+ *      the shift register LSB.  The shift register MSB is assigned from
+ *      the modulo 2 sum of the masked shift register and the input LSB.
+ *
+ *  next_bit_descramble(unsigned char input) - Descramble an input stream
  *
+ *      Perform one cycle of the LFSR.  The output bit is taken from 
+ *      the modulo-2 sum of the masked shift register and the input LSB.
+ *      The shift register MSB is assigned from the LSB of the input.
+ *
+ * See http://en.wikipedia.org/wiki/Scrambler for operation of these
+ * last two functions (see multiplicative scrambler.)
  *
  */
 
-
 class gri_lfsr
 {
  private:
@@ -92,12 +106,27 @@ class gri_lfsr
   }
 
   unsigned char next_bit() {
-    unsigned char bit = d_shift_register & 1;
+    unsigned char output = d_shift_register & 1;
     unsigned char newbit = popCount( d_shift_register & d_mask )%2;
     d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
-    return bit;
+    return output;
+  }
+
+  unsigned char next_bit_scramble(unsigned char input) {
+    unsigned char output = d_shift_register & 1;
+    unsigned char newbit = (popCount( d_shift_register & d_mask )%2)^(input & 1);
+    d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
+    return output;
+  }
+
+  unsigned char next_bit_descramble(unsigned char input) {
+    unsigned char output = (popCount( d_shift_register & d_mask )%2)^(input & 1);
+    unsigned char newbit = input & 1;
+    d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
+    return output;
   }
 
+
   /*!
    * Rotate the register through x number of bits
    * where we are just throwing away the results to get queued up correctly
index 9a72bf8d96f159bca798e5ba73b73ac9f6f4d82f..2d4346aceca0a4cff074e1b65d56bcf6caff3584 100644 (file)
@@ -54,3 +54,87 @@ qa_gri_lfsr::test_lfsr ()
   CPPUNIT_ASSERT_THROW(gri_lfsr(mask, seed, 32), std::invalid_argument);
 }
 
+void
+qa_gri_lfsr::test_scrambler()
+{
+  // CCSDS 7-bit scrambler
+  int mask = 0x8A; // 1+x^4+X^6 
+  int seed = 0x7F;
+  int length = 7;
+
+  gri_lfsr scrambler(mask, seed, length);
+
+  // Impulse (1 and 126 more zeroes)
+  unsigned char src[] = 
+    { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0 }; // flush bits
+  
+  // Impulse response (including leading bits)
+  unsigned char expected[] =
+    { 1, 1, 1, 1, 1, 1, 1, 
+      0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 
+      0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 
+      0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 
+      0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 
+      1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 
+      0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 
+      1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 
+      1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, };
+
+  int len = sizeof(src);
+  unsigned char actual[len];
+
+  for (int i = 0; i < len; i++)
+    actual[i] = scrambler.next_bit_scramble(src[i]);
+
+  CPPUNIT_ASSERT(memcmp(expected, actual, len) == 0);
+}
+
+void
+qa_gri_lfsr::test_descrambler()
+{
+  // CCSDS 7-bit scrambler
+  int mask = 0x8A;
+  int seed = 0x7F;
+  int length = 7;
+
+  gri_lfsr descrambler(mask, seed, length);
+
+  // Scrambled sequence (impulse response)
+  unsigned char src[] =
+    { 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 
+      0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 
+      0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 
+      0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 
+      1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 
+      0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 
+      1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 
+      1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0 }; 
+
+  // Original (garbage while synchronizing, them impulse)
+  unsigned char expected[] = 
+    { 0, 1, 0, 0, 1, 0,
+      1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+      0, 0, 0, 0, 0, 0, 0, 0, 0 };
+  
+  int len = sizeof(src);
+  unsigned char actual[len];
+
+  for (int i = 0; i < len; i++)
+    actual[i] = descrambler.next_bit_descramble(src[i]);
+
+  CPPUNIT_ASSERT(memcmp(expected, actual, len) == 0);
+}
index f65943a905a454b6d85efecd355ba2ffffb1dfb4..2a1b92e9c91d13f9f18f67bedab48ef5abf4760c 100644 (file)
@@ -29,10 +29,14 @@ class qa_gri_lfsr : public CppUnit::TestCase {
 
   CPPUNIT_TEST_SUITE(qa_gri_lfsr);
   CPPUNIT_TEST(test_lfsr);
+  CPPUNIT_TEST(test_scrambler);
+  CPPUNIT_TEST(test_descrambler);
   CPPUNIT_TEST_SUITE_END();
 
  private:
   void test_lfsr();
+  void test_scrambler();
+  void test_descrambler();
 };
 
 #endif /* _QA_GRI_LFSR_H_ */
index db8e2b382dacbb543f063e427392293640f4e2c7..8b07e4ae1c22a451ec618d3509416904030d39ab 100644 (file)
@@ -92,6 +92,5 @@ noinst_PYTHON =                       \
        qa_single_pole_iir_cc.py        \
        qa_skiphead.py                  \
        qa_unpack_k_bits.py             \
-       qa_repeat.py
-
-CLEANFILES = *.pyc
+       qa_repeat.py                    \
+       qa_scrambler.py
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_scrambler.py b/gnuradio-core/src/python/gnuradio/gr/qa_scrambler.py
new file mode 100755 (executable)
index 0000000..76b0e62
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+from gnuradio import gr, gr_unittest
+
+class test_scrambler(gr_unittest.TestCase):
+
+    def setUp (self):
+        self.tb = gr.top_block()
+
+    def tearDown(self):
+        self.tb = None
+
+    def test_scrambler_descrambler(self):
+        src_data = (1,)*1000
+        src = gr.vector_source_b(src_data, False)
+        scrambler = gr.scrambler_bb(0x8a, 0x7F, 7)     # CCSDS 7-bit scrambler
+        descrambler = gr.descrambler_bb(0x8a, 0x7F, 7) 
+        dst = gr.vector_sink_b()
+        self.tb.connect(src, scrambler, descrambler, dst)
+        self.tb.run()
+        self.assertEqual(tuple(src_data[:-8]), dst.data()[8:]) # skip garbage during synchronization
+
+if __name__ == '__main__':
+    gr_unittest.main ()