[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9557 - gnuradio/branches/developers/jcorgan/scr/gnura
From: |
jcorgan |
Subject: |
[Commit-gnuradio] r9557 - gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general |
Date: |
Thu, 11 Sep 2008 19:09:51 -0600 (MDT) |
Author: jcorgan
Date: 2008-09-11 19:09:42 -0600 (Thu, 11 Sep 2008)
New Revision: 9557
Modified:
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/gri_lfsr.h
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/qa_gri_lfsr.cc
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/qa_gri_lfsr.h
Log:
Added scrambler and descrambler operations to gri_lfsr
Modified:
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/gri_lfsr.h
===================================================================
---
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/gri_lfsr.h
2008-09-11 20:00:47 UTC (rev 9556)
+++
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/gri_lfsr.h
2008-09-12 01:09:42 UTC (rev 9557)
@@ -58,15 +58,29 @@
*
*
*
- * 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,29 @@
}
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);
+ //printf("reg=%08X in=%1d out=%1d new=%1d ", d_shift_register, input,
output, newbit);
+ d_shift_register = ((d_shift_register>>1) |
(newbit<<d_shift_register_length));
+ //printf("reg=%08X\n", d_shift_register);
+ 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
Modified:
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/qa_gri_lfsr.cc
===================================================================
---
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/qa_gri_lfsr.cc
2008-09-11 20:00:47 UTC (rev 9556)
+++
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/qa_gri_lfsr.cc
2008-09-12 01:09:42 UTC (rev 9557)
@@ -54,3 +54,87 @@
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; // 1+x^4+X^6
+ 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);
+}
Modified:
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/qa_gri_lfsr.h
===================================================================
---
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/qa_gri_lfsr.h
2008-09-11 20:00:47 UTC (rev 9556)
+++
gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general/qa_gri_lfsr.h
2008-09-12 01:09:42 UTC (rev 9557)
@@ -29,10 +29,14 @@
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_ */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9557 - gnuradio/branches/developers/jcorgan/scr/gnuradio-core/src/lib/general,
jcorgan <=