def test_003(self):
        # Test scenario where we have defined a puncture pattern with
        # more bits than the puncsize with a delay. The python code
        # doesn't account for this when creating self.expected, but
        # this should be equivalent to a puncpat of the correct size.

        self.puncsize = 4
        self.puncpat0 = 0x5555  # too many bits set
        self.puncpat1 = 0x55  # num bits = puncsize
        self.delay = 1
        self.sym = 0

        src = blocks.vector_source_b(self.src_data)
        op0 = fec.depuncture_bb(self.puncsize, self.puncpat0, self.delay,
                                self.sym)
        op1 = fec.depuncture_bb(self.puncsize, self.puncpat1, self.delay,
                                self.sym)
        dst0 = blocks.vector_sink_b()
        dst1 = blocks.vector_sink_b()

        self.tb.connect(src, op0, dst0)
        self.tb.connect(src, op1, dst1)
        self.tb.run()

        dst_data0 = list(dst0.data())
        for i in xrange(len(dst_data0)):
            dst_data0[i] = int(dst_data0[i])

        dst_data1 = list(dst1.data())
        for i in xrange(len(dst_data1)):
            dst_data1[i] = int(dst_data1[i])

        self.assertEqual(dst_data1, dst_data0)
Example #2
0
    def test_003(self):
        # Test scenario where we have defined a puncture pattern with
        # more bits than the puncsize with a delay. The python code
        # doesn't account for this when creating self.expected, but
        # this should be equivalent to a puncpat of the correct size.

        self.puncsize = 4
        self.puncpat0 = 0x5555 # too many bits set
        self.puncpat1 = 0x55   # num bits = puncsize
        self.delay = 1

        src = blocks.vector_source_b(self.src_data)
	op0  = fec.puncture_bb(self.puncsize, self.puncpat0, self.delay)
	op1  = fec.puncture_bb(self.puncsize, self.puncpat1, self.delay)
	dst0 = blocks.vector_sink_b()
	dst1 = blocks.vector_sink_b()

	self.tb.connect(src, op0, dst0)
	self.tb.connect(src, op1, dst1)
	self.tb.run()

	dst_data0 = list(dst0.data())
        for i in xrange(len(dst_data0)):
            dst_data0[i] = int(dst_data0[i])

	dst_data1 = list(dst1.data())
        for i in xrange(len(dst_data1)):
            dst_data1[i] = int(dst_data1[i])

        self.assertEqual(dst_data1, dst_data0)
Example #3
0
 def test_027c_fully_unconnected_output(self):
     tb = gr.top_block()
     hb = gr.hier_block2("block",
                         gr.io_signature(1, 1, 1),
                         gr.io_signature(1, 1, 1))
     hsrc = blocks.vector_sink_b()
     hb.connect(hb, hsrc) # wire input internally
     src = blocks.vector_source_b([1, ])
     dst = blocks.vector_sink_b()
     tb.connect(src, hb) # hb's output is not connected internally or externally
     self.assertRaises(RuntimeError,
                       lambda: tb.run())
Example #4
0
 def test_027c_fully_unconnected_output(self):
     tb = gr.top_block()
     hb = gr.hier_block2("block", gr.io_signature(1, 1, 1),
                         gr.io_signature(1, 1, 1))
     hsrc = blocks.vector_sink_b()
     hb.connect(hb, hsrc)  # wire input internally
     src = blocks.vector_source_b([
         1,
     ])
     dst = blocks.vector_sink_b()
     tb.connect(src,
                hb)  # hb's output is not connected internally or externally
     self.assertRaises(RuntimeError, lambda: tb.run())
Example #5
0
    def helper(self, v0, v1, fft_length, preamble):
        tb = self.tb
        src0 = blocks.vector_source_c(v0)
        src1 = blocks.vector_source_b(v1)

        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length)

        # print "len(v) = %d" % (len(v))

        op = digital.ofdm_insert_preamble(fft_length, preamble)

        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_length)
        dst0 = blocks.vector_sink_c()
        dst1 = blocks.vector_sink_b()

        tb.connect(src0, s2v, (op, 0))
        tb.connect(src1, (op, 1))
        tb.connect((op, 0), v2s, dst0)
        tb.connect((op, 1), dst1)

        tb.run()
        r0 = dst0.data()
        r0v = []
        for i in range(len(r0) // fft_length):
            r0v.append(r0[i * fft_length:(i + 1) * fft_length])

        r1 = dst1.data()
        self.assertEqual(len(r0v), len(r1))
        return (r1, r0v)
    def helper(self, v0, v1, fft_length, preamble):
        tb = self.tb
        src0 = blocks.vector_source_c(v0)
        src1 = blocks.vector_source_b(v1)
        
        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length)

        # print "len(v) = %d" % (len(v))

        op = digital.ofdm_insert_preamble(fft_length, preamble)

        v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, fft_length)
        dst0 = blocks.vector_sink_c()
        dst1 = blocks.vector_sink_b()

        tb.connect(src0, s2v, (op, 0))
        tb.connect(src1, (op, 1))
        tb.connect((op, 0), v2s, dst0)
        tb.connect((op, 1), dst1)

        tb.run()
        r0 = dst0.data()
        r0v = []
        for i in range(len(r0)//fft_length):
            r0v.append(r0[i*fft_length:(i+1)*fft_length])
            
        r1 = dst1.data()
        self.assertEqual(len(r0v), len(r1))
        return (r1, r0v)
Example #7
0
    def test_004(self):
        # Test normal operation of the depuncture block without
        # specifying the fill symbol (defaults to 127).

        self.puncsize = 8
        self.puncpat = 0xEF
        self.delay = 0
        self.sym = 127
        self.puncholes = 1

        self.depuncture_setup()

        src = blocks.vector_source_b(self.src_data)
	op  = fec.depuncture_bb(self.puncsize, self.puncpat,
                                self.delay)
	dst = blocks.vector_sink_b()

	self.tb.connect(src, op, dst)
	self.tb.run()

	dst_data = list(dst.data())
        for i in xrange(len(dst_data)):
            dst_data[i] = int(dst_data[i])

        self.assertEqual(self.expected, dst_data)
Example #8
0
    def test_002(self):
        # Test scenario where we have defined a puncture pattern with
        # more bits than the puncsize.

        self.puncsize = 4
        self.puncpat = 0x5555
        self.delay = 0
        self.sym = 0
        self.puncholes = 2

        self.depuncture_setup()

        src = blocks.vector_source_b(self.src_data)
	op  = fec.depuncture_bb(self.puncsize, self.puncpat,
                                self.delay, self.sym)
	dst = blocks.vector_sink_b()

	self.tb.connect(src, op, dst)
	self.tb.run()

	dst_data = list(dst.data())
        for i in xrange(len(dst_data)):
            dst_data[i] = int(dst_data[i])

        self.assertEqual(self.expected, dst_data)
Example #9
0
 def test_001_detect(self):
     """ Send two bursts, with zeros in between, and check
     they are both detected at the correct position and no
     false alarms occur """
     n_zeros = 15
     fft_len = 32
     cp_len = 4
     sig_len = (fft_len + cp_len) * 10
     sync_symbol = [(random.randint(0, 1) * 2) - 1
                    for x in range(fft_len / 2)] * 2
     tx_signal = [0,] * n_zeros + \
                 sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     tx_signal = tx_signal * 2
     add = blocks.add_cc()
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     sink_freq = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0))
     self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01),
                     (add, 1))
     self.tb.connect(add, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     sig1_detect = sink_detect.data()[0:len(tx_signal) / 2]
     sig2_detect = sink_detect.data()[len(tx_signal) / 2:]
     self.assertTrue(
         abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertTrue(
         abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertEqual(numpy.sum(sig1_detect), 1)
     self.assertEqual(numpy.sum(sig2_detect), 1)
 def test_003_12bits_formatter_object (self):
     # 3 PDUs: |           |     |         |
     data   = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tagname)
     tag1.value = pmt.from_long(4)
     tag2 = gr.tag_t()
     tag2.offset = 4
     tag2.key = pmt.string_to_symbol(tagname)
     tag2.value = pmt.from_long(2)
     tag3 = gr.tag_t()
     tag3.offset = 6
     tag3.key = pmt.string_to_symbol(tagname)
     tag3.value = pmt.from_long(4)
     src = blocks.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     formatter_object = digital.packet_header_default(12, tagname)
     header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname)
     sink = blocks.vector_sink_b()
     self.tb.connect(src, header, sink)
     self.tb.run()
     expected_data = (
         0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
     )
     self.assertEqual(sink.data(), expected_data)
 def test_002_32bits (self):
     # 3 PDUs: |           |     |         |
     data   = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tagname)
     tag1.value = pmt.from_long(4)
     tag2 = gr.tag_t()
     tag2.offset = 4
     tag2.key = pmt.string_to_symbol(tagname)
     tag2.value = pmt.from_long(2)
     tag3 = gr.tag_t()
     tag3.offset = 6
     tag3.key = pmt.string_to_symbol(tagname)
     tag3.value = pmt.from_long(4)
     src = blocks.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     header = digital.packet_headergenerator_bb(32, tagname)
     sink = blocks.vector_sink_b()
     self.tb.connect(src, header, sink)
     self.tb.run()
     expected_data = (
         #   | Number of symbols                  | Packet number                                  | Parity
             0, 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,  1, 0, 0, 0,
             0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0,
             0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0
     )
     self.assertEqual(sink.data(), expected_data)
 def test_004_8bits_formatter_ofdm (self):
     occupied_carriers = ((1, 2, 3, 5, 6, 7),)
     # 3 PDUs: |           |     |         |
     data   = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tagname)
     tag1.value = pmt.from_long(4)
     tag2 = gr.tag_t()
     tag2.offset = 4
     tag2.key = pmt.string_to_symbol(tagname)
     tag2.value = pmt.from_long(2)
     tag3 = gr.tag_t()
     tag3.offset = 6
     tag3.key = pmt.string_to_symbol(tagname)
     tag3.value = pmt.from_long(4)
     src = blocks.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     formatter_object = digital.packet_header_ofdm(occupied_carriers, 1, tagname)
     self.assertEqual(formatter_object.header_len(), 6)
     self.assertEqual(pmt.symbol_to_string(formatter_object.len_tag_key()), tagname)
     header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname)
     sink = blocks.vector_sink_b()
     self.tb.connect(src, header, sink)
     self.tb.run()
     expected_data = (
         0, 0, 1, 0, 0, 0,
         0, 1, 0, 0, 0, 0,
         0, 0, 1, 0, 0, 0
     )
     self.assertEqual(sink.data(), expected_data)
 def test_004_ofdm_packets (self):
     """
     Send several bursts using ofdm_tx, see if the number of detects is correct.
     Burst lengths and content are random.
     """
     n_bursts = 42
     fft_len = 64
     cp_len = 16
     # Here, coarse freq offset is allowed
     max_freq_offset = 2*numpy.pi/fft_len * 4
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     tx_signal = []
     packets = []
     tagname = "packet_length"
     min_packet_length = 10
     max_packet_length = 50
     sync_sequence = [random.randint(0, 1)*2-1 for x in range(fft_len/2)]
     for i in xrange(n_bursts):
         packet_length = random.randint(min_packet_length,
                                        max_packet_length+1)
         packet = [random.randint(0, 255) for i in range(packet_length)]
         packets.append(packet)
     data, tags = tagged_streams.packets_to_vectors(packets, tagname, vlen=1)
     total_length = len(data)
     src = blocks.vector_source_b(data, False, 1, tags)
     mod = ofdm_tx(packet_length_tag_key=tagname)
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     sink_freq   = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     noise_level = 0.005
     channel = channels.channel_model(noise_level, freq_offset / 2 / numpy.pi)
     self.tb.connect(src, mod, channel, sync, sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     self.assertEqual(numpy.sum(sink_detect.data()), n_bursts)
 def __init__(self, constellation, differential, data_length=None, src_data=None, freq_offset=True):
     """
     Args:
         constellation: a constellation object
         differential: whether differential encoding is used
         data_length: the number of bits of data to use
         src_data: a list of the bits to use
         freq_offset: whether to use a frequency offset in the channel
     """
     super(rec_test_tb, self).__init__()
     # Transmission Blocks
     if src_data is None:
         self.src_data = tuple([rndm.randint(0, 1) for i in range(0, data_length)])
     else:
         self.src_data = src_data
     packer = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     src = blocks.vector_source_b(self.src_data)
     mod = generic_mod(constellation, differential=differential)
     # Channel
     if freq_offset:
         channel = channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET)
     else:
         channel = channel_model(NOISE_VOLTAGE, 0, TIMING_OFFSET)
     # Receiver Blocks
     if freq_offset:
         demod = generic_demod(constellation, differential=differential, freq_bw=FREQ_BW, phase_bw=PHASE_BW)
     else:
         demod = generic_demod(constellation, differential=differential, freq_bw=0, phase_bw=0)
     self.dst = blocks.vector_sink_b()
     self.connect(src, packer, mod, channel, demod, self.dst)
Example #15
0
    def test_002(self):
        # Test scenario where we have defined a puncture pattern with
        # more bits than the puncsize.

        self.puncsize = 4
        self.puncpat = 0x5555
        self.delay = 0
        self.sym = 0
        self.puncholes = 2

        self.depuncture_setup()

        src = blocks.vector_source_b(self.src_data)
        op = fec.depuncture_bb(self.puncsize, self.puncpat, self.delay,
                               self.sym)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op, dst)
        self.tb.run()

        dst_data = list(dst.data())
        for i in xrange(len(dst_data)):
            dst_data[i] = int(dst_data[i])

        self.assertEqual(self.expected, dst_data)
    def test_00(self):
        expected_result = (
            0x00, 0x11, 0x22, 0x33,
            0x44, 0x55, 0x66, 0x77,
            0x88, 0x99, 0xaa, 0xbb,
            0xcc, 0xdd, 0xee, 0xff)

        # Filter taps to expand the data to oversample by 8
        # Just using a RRC for some basic filter shape
        taps = filter.firdes.root_raised_cosine(8, 8, 1.0, 0.5, 21)
        
        src = blocks.vector_source_b(expected_result)
        frame = digital.simple_framer(4)
        unpack = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        expand = filter.interp_fir_filter_fff(8, taps)
        b2f = blocks.char_to_float()
        mult2 = blocks.multiply_const_ff(2)
        sub1 = blocks.add_const_ff(-1)
        op = digital.simple_correlator(4)
        dst = blocks.vector_sink_b()
        self.tb.connect(src, frame, unpack, b2f, mult2, sub1, expand)
        self.tb.connect(expand, op, dst)
        self.tb.run()
        result_data = dst.data()

        self.assertEqual(expected_result, result_data)
Example #17
0
 def test_004_8bits_formatter_ofdm(self):
     occupied_carriers = ((1, 2, 3, 5, 6, 7), )
     # 3 PDUs: |           |     |         |
     data = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tagname)
     tag1.value = pmt.from_long(4)
     tag2 = gr.tag_t()
     tag2.offset = 4
     tag2.key = pmt.string_to_symbol(tagname)
     tag2.value = pmt.from_long(2)
     tag3 = gr.tag_t()
     tag3.offset = 6
     tag3.key = pmt.string_to_symbol(tagname)
     tag3.value = pmt.from_long(4)
     src = blocks.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     formatter_object = digital.packet_header_ofdm(occupied_carriers, 1,
                                                   tagname)
     self.assertEqual(formatter_object.header_len(), 6)
     self.assertEqual(pmt.symbol_to_string(formatter_object.len_tag_key()),
                      tagname)
     header = digital.packet_headergenerator_bb(
         formatter_object.formatter(), tagname)
     sink = blocks.vector_sink_b()
     self.tb.connect(src, header, sink)
     self.tb.run()
     expected_data = (0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0)
     self.assertEqual(sink.data(), expected_data)
 def test_001_detect (self):
     """ Send two bursts, with zeros in between, and check
     they are both detected at the correct position and no
     false alarms occur """
     n_zeros = 15
     fft_len = 32
     cp_len = 4
     sig_len = (fft_len + cp_len) * 10
     sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
     tx_signal = [0,] * n_zeros + \
                 sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     tx_signal = tx_signal * 2
     add = blocks.add_cc()
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     sink_freq   = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0))
     self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01), (add, 1))
     self.tb.connect(add, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     sig1_detect = sink_detect.data()[0:len(tx_signal)/2]
     sig2_detect = sink_detect.data()[len(tx_signal)/2:]
     self.assertTrue(abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertTrue(abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertEqual(numpy.sum(sig1_detect), 1)
     self.assertEqual(numpy.sum(sig2_detect), 1)
    def test_003_multiburst (self):
        """ Send several bursts, see if the number of detects is correct.
        Burst lengths and content are random.
        """
        n_bursts = 42
        fft_len = 32
        cp_len = 4
        tx_signal = []
        for i in xrange(n_bursts):
            sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
            tx_signal += [0,] * random.randint(0, 2*fft_len) + \
                         sync_symbol[-cp_len:] + \
                         sync_symbol + \
                         [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))]
        add = blocks.add_cc()
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq   = blocks.vector_sink_f()
        sink_detect = blocks.vector_sink_b()
        channel = channels.channel_model(0.005)
        self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
        self.tb.connect((sync, 0), sink_freq)
        self.tb.connect((sync, 1), sink_detect)
        self.tb.run()
        n_bursts_detected = numpy.sum(sink_detect.data())
        # We allow for one false alarm or missed burst
        self.assertTrue(abs(n_bursts_detected - n_bursts) <= 1,
                msg="""Because of statistics, it is possible (though unlikely)
that the number of detected bursts differs slightly. If the number of detects is
off by one or two, run the test again and see what happen.
Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts)
        )
Example #20
0
 def test_003_12bits_formatter_object(self):
     # 3 PDUs: |           |     |         |
     data = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tagname)
     tag1.value = pmt.from_long(4)
     tag2 = gr.tag_t()
     tag2.offset = 4
     tag2.key = pmt.string_to_symbol(tagname)
     tag2.value = pmt.from_long(2)
     tag3 = gr.tag_t()
     tag3.offset = 6
     tag3.key = pmt.string_to_symbol(tagname)
     tag3.value = pmt.from_long(4)
     src = blocks.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     formatter_object = digital.packet_header_default(12, tagname)
     header = digital.packet_headergenerator_bb(
         formatter_object.formatter(), tagname)
     sink = blocks.vector_sink_b()
     self.tb.connect(src, header, sink)
     self.tb.run()
     expected_data = (0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
                      0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)
     self.assertEqual(sink.data(), expected_data)
Example #21
0
    def test_002(self):

        code = tuple(string_to_1_0_list(default_access_code))
        access_code = to_1_0_string(code)
        header = tuple(
            2 * [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0])  # len=2
        pad = (0, ) * 100
        src_data = code + header + (0, 1, 0, 0, 1, 0, 0, 0) + (0, 1, 0, 0, 1,
                                                               0, 0, 1) + pad
        expected_data = 'HI'

        rcvd_pktq = gr.msg_queue()

        src = blocks.vector_source_b(src_data)
        correlator = digital.correlate_access_code_bb(access_code, 0)
        framer_sink = digital.framer_sink_1(rcvd_pktq)
        vsnk = blocks.vector_sink_b()

        self.tb.connect(src, correlator, framer_sink)
        self.tb.connect(correlator, vsnk)
        self.tb.run()

        result_data = rcvd_pktq.delete_head()
        result_data = result_data.to_string()
        self.assertEqual(expected_data, result_data)
Example #22
0
    def test_003_multiburst(self):
        """ Send several bursts, see if the number of detects is correct.
        Burst lengths and content are random.
        """
        n_bursts = 42
        fft_len = 32
        cp_len = 4
        tx_signal = []
        for i in xrange(n_bursts):
            sync_symbol = [(random.randint(0, 1) * 2) - 1
                           for x in range(fft_len / 2)] * 2
            tx_signal += [0,] * random.randint(0, 2*fft_len) + \
                         sync_symbol[-cp_len:] + \
                         sync_symbol + \
                         [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))]
        add = blocks.add_cc()
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq = blocks.vector_sink_f()
        sink_detect = blocks.vector_sink_b()
        channel = channels.channel_model(0.005)
        self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
        self.tb.connect((sync, 0), sink_freq)
        self.tb.connect((sync, 1), sink_detect)
        self.tb.run()
        n_bursts_detected = numpy.sum(sink_detect.data())
        # We allow for one false alarm or missed burst
        self.assertTrue(
            abs(n_bursts_detected - n_bursts) <= 1,
            msg="""Because of statistics, it is possible (though unlikely)
that the number of detected bursts differs slightly. If the number of detects is
off by one or two, run the test again and see what happen.
Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts))
Example #23
0
    def test_regen2(self):
        tb = self.tb

        data = 200*[0,]
        data[9] = 1
        data[99] = 1

        expected_result = 200*[0,]
        expected_result[9]   = 1
        expected_result[19]  = 1
        expected_result[29]  = 1
        expected_result[39]  = 1

        expected_result[99]  = 1
        expected_result[109]  = 1
        expected_result[119]  = 1
        expected_result[129]  = 1

        src = blocks.vector_source_b(data, False)
        regen = blocks.regenerate_bb(10, 3)
        dst = blocks.vector_sink_b()

        tb.connect(src, regen)
        tb.connect(regen, dst)
        tb.run ()

        dst_data = dst.data()

        self.assertEqual(tuple(expected_result), dst_data)
Example #24
0
 def test_300(self):
     input_data = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
     src = blocks.vector_source_b(input_data)
     dst = blocks.vector_sink_b()
     tb = gr.top_block()
     tb.connect(src, dst)
     tb.run()
     self.assertEquals(input_data, dst.data())
Example #25
0
    def test_300(self):
        input_data = (0,1,2,3,4,5,6,7,8,9)
        src = blocks.vector_source_b(input_data)
        dst = blocks.vector_sink_b()
	tb = gr.top_block()
        tb.connect(src, dst)
        tb.run()
        self.assertEquals(input_data, dst.data())
Example #26
0
 def test_003(self):
     src_data = expected_results = map(lambda x: random.randint(0,3), range(10));
     src = blocks.vector_source_b( src_data );
     pack = blocks.pack_k_bits_bb(2);
     unpack = blocks.unpack_k_bits_bb(2);
     snk = blocks.vector_sink_b();
     self.tb.connect(src,unpack,pack,snk);
     self.tb.run()
     self.assertEqual(list(expected_results), list(snk.data()));
 def test_float_to_char_scale(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (5, 10, 15, 20, 25)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_char(1, 5)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Example #28
0
 def test_001(self):
     src_data =              (1,0,1,1,0,1,1,0)
     expected_results =      (1,0,1,1,0,1,1,0)
     src = blocks.vector_source_b(src_data,False)
     op = blocks.pack_k_bits_bb(1)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_results, dst.data())
Example #29
0
 def test_float_to_uchar(self):
     src_data = (1.0, -2.0, 3.0, -4.0, 256.0)
     expected_data = (1, 0, 3, 0, 255)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_uchar()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Example #30
0
 def test_short_to_char(self):
     src_data = (256, 512, 768, 1024, 1280)
     expected_data = (1, 2, 3, 4, 5)
     src = blocks.vector_source_s(src_data)
     op = blocks.short_to_char()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Example #31
0
 def test_float_to_char_identity(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (1, 2, 3, 4, 5)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_char()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Example #32
0
 def test_float_to_char_scale(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (5, 10, 15, 20, 25)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_char(1, 5)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
 def test_short_to_char(self):
     src_data = (256, 512, 768, 1024, 1280)
     expected_data = (1, 2, 3, 4, 5)
     src = blocks.vector_source_s(src_data)
     op = blocks.short_to_char()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
 def test_float_to_uchar(self):
     src_data = (1.0, -2.0, 3.0, -4.0, 256.0)
     expected_data = (1, 0, 3, 0, 255)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_uchar()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Example #35
0
 def help_bb(self, src_data, exp_data, op):
     for s in zip(range(len(src_data)), src_data):
         src = blocks.vector_source_b(s[1])
         self.tb.connect(src, (op, s[0]))
     dst = blocks.vector_sink_b()
     self.tb.connect(op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(exp_data, result_data)
Example #36
0
 def test_001_t (self):
     #                  | Spur spike 1     | Plateau                  | Spur spike 2
     test_signal  = (0, 1, .2, .4, .6, .8, 1, 1, 1, 1, 1, .8, .6, .4, 1, 0)
     expected_sig = (0, 0,  0,  0,  0,  0, 0, 0, 1, 0, 0,  0,  0,  0, 0, 0)
     #                                           | Center of Plateau
     sink = blocks.vector_sink_b()
     self.tb.connect(blocks.vector_source_f(test_signal), blocks.plateau_detector_fb(5), sink)
     self.tb.run ()
     self.assertEqual(expected_sig, sink.data())
Example #37
0
 def test_scrambler_descrambler(self):
     src_data = (1,)*1000
     src = blocks.vector_source_b(src_data, False)
     scrambler = digital.scrambler_bb(0x8a, 0x7F, 7)     # CCSDS 7-bit scrambler
     descrambler = digital.descrambler_bb(0x8a, 0x7F, 7)
     dst = blocks.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
Example #38
0
 def test_and_const_bb(self):
     src_data = (1, 2, 3, 0x50, 0x11)
     expected_result = (0, 2, 2, 0x00, 0x00)
     src = blocks.vector_source_b(src_data)
     op = blocks.and_const_bb(0xAA)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(dst.data(), expected_result)
Example #39
0
 def test_029_singleton_disconnect(self):
     tb = gr.top_block()
     src = blocks.vector_source_b([1, ])
     dst = blocks.vector_sink_b()
     tb.connect(src, dst)
     tb.disconnect(src)   # Singleton disconnect
     tb.connect(src, dst)
     tb.run()
     self.assertEquals(dst.data(), (1,))
 def help_bb (self, src_data, exp_data, op):
     for s in zip (range (len (src_data)), src_data):
         src = blocks.vector_source_b (s[1])
         self.tb.connect (src, (op, s[0]))
     dst = blocks.vector_sink_b ()
     self.tb.connect (op, dst)
     self.tb.run ()
     result_data = dst.data ()
     self.assertEqual (exp_data, result_data)
 def test_and_const_bb (self):
     src_data =        (1,  2, 3,  0x50,   0x11)
     expected_result = (0,  2, 2,  0x00,   0x00)
     src = blocks.vector_source_b(src_data)
     op = blocks.and_const_bb (0xAA)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(dst.data(), expected_result)
Example #42
0
 def test_additive_scrambler_reset(self):
     src_data = (1,)*1000
     src = blocks.vector_source_b(src_data, False)
     scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 100)
     descrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 100)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, scrambler, descrambler, dst)
     self.tb.run()
     self.assertEqual(src_data, dst.data())
 def test_float_to_char_identity(self):
     src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
     expected_data = (1, 2, 3, 4, 5)
     src = blocks.vector_source_f(src_data)
     op = blocks.float_to_char()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(expected_data, dst.data())
Example #44
0
 def test_copy(self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     src = blocks.vector_source_b(src_data)
     op = blocks.copy(gr.sizeof_char)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     dst_data = dst.data()
     self.assertEqual(expected_result, dst_data)
Example #45
0
 def test_copy(self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     src = blocks.vector_source_b(src_data)
     op = blocks.copy(gr.sizeof_char)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     dst_data = dst.data()
     self.assertEqual(expected_result, dst_data)
Example #46
0
    def __init__(self):
        """
        """

        v2s = blocks.vector_to_stream(gr.sizeof_char,
                                      atsc.sizeof_atsc_mpeg_packet)
        self.sink = blocks.vector_sink_b()
        gr.hier_block2.__init__(self, "vector_sink_ts", v2s.input_signature(),
                                gr.io_signature(0, 0, 0))
        self.connect(self, v2s, self.sink)
Example #47
0
 def test_001(self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_data = (5, 10)
     src = blocks.vector_source_b(src_data)
     op = blocks.keep_one_in_n(gr.sizeof_char, 5)
     dst = blocks.vector_sink_b()
     print "HERE"
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(dst.data(), expected_data)
Example #48
0
    def __init__(self):
        """
        """

        v2s = blocks.vector_to_stream(gr.sizeof_char, atsc.sizeof_atsc_mpeg_packet)
        self.sink = blocks.vector_sink_b()
	gr.hier_block2.__init__(self, "vector_sink_ts",
				v2s.input_signature(),
				gr.io_signature(0, 0, 0))
        self.connect(self, v2s, self.sink)
Example #49
0
 def test_001(self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_data = (5, 10)
     src = blocks.vector_source_b(src_data);
     op = blocks.keep_one_in_n(gr.sizeof_char, 5)
     dst = blocks.vector_sink_b()
     print "HERE"
     self.tb.connect(src, op, dst)
     self.tb.run()
     self.assertEqual(dst.data(), expected_data)
Example #50
0
    def test_000(self):
        # Just run some data through and make sure it doesn't puke.
        src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

        src = blocks.pdu_to_tagged_stream(blocks.byte_t)
        snk3 = blocks.tagged_stream_to_pdu(blocks.byte_t)
        snk2 = blocks.vector_sink_b()
        snk = blocks.tag_debug(1, "test")
        snk.set_display(False)

        dbg = blocks.message_debug()

        # Test that the right number of ports exist.
        pi = snk3.message_ports_in()
        po = snk3.message_ports_out()
        self.assertEqual(pmt.length(pi), 0)
        self.assertEqual(pmt.length(po), 1)

        self.tb.connect(src, snk)
        self.tb.connect(src, snk2)
        self.tb.connect(src, snk3)
        self.tb.msg_connect(snk3, "pdus", dbg, "store")
        self.tb.start()

        # make our reference and message pmts
        port = pmt.intern("pdus")
        msg = pmt.cons(pmt.PMT_NIL, pmt.make_u8vector(16, 0xFF))

        # post the message
        src.to_basic_block()._post(port, msg)  # eww, what's that smell?

        while dbg.num_messages() < 1:
            time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        # Get the vector of data from the vector sink
        result_data = snk2.data()

        # Get the vector of data from the message sink
        # Convert the message PMT as a pair into its vector
        result_msg = dbg.get_message(0)
        msg_vec = pmt.cdr(result_msg)
        #pmt.print(msg_vec)

        # Convert the PMT vector into a Python list
        msg_data = []
        for i in xrange(16):
            msg_data.append(pmt.u8vector_ref(msg_vec, i))

        actual_data = 16 * [
            0xFF,
        ]
        self.assertEqual(actual_data, list(result_data))
        self.assertEqual(actual_data, msg_data)
Example #51
0
    def test_001(self):
        self.maxDiff = None
        tb = gr.top_block()
        src = blocks.vector_source_b(range(0, 100))

        # itemsize, M, N, offset
        km2 = blocks.keep_m_in_n(1, 1, 2, 0)
        km3 = blocks.keep_m_in_n(1, 1, 3, 1)
        km7 = blocks.keep_m_in_n(1, 1, 7, 2)
        snk2 = blocks.vector_sink_b()
        snk3 = blocks.vector_sink_b()
        snk7 = blocks.vector_sink_b()
        tb.connect(src, km2, snk2)
        tb.connect(src, km3, snk3)
        tb.connect(src, km7, snk7)
        tb.run()

        self.assertEqual(range(0, 100, 2), list(snk2.data()))
        self.assertEqual(range(1, 100, 3), list(snk3.data()))
        self.assertEqual(range(2, 100, 7), list(snk7.data()))
Example #52
0
 def test_029_singleton_disconnect(self):
     tb = gr.top_block()
     src = blocks.vector_source_b([
         1,
     ])
     dst = blocks.vector_sink_b()
     tb.connect(src, dst)
     tb.disconnect(src)  # Singleton disconnect
     tb.connect(src, dst)
     tb.run()
     self.assertEquals(dst.data(), (1, ))
Example #53
0
    def helper(self, symbols):
        src_data = [0, 1, 2, 3, 0, 1, 2, 3]
        expected_data = map(lambda x: symbols[x], src_data)
        src = blocks.vector_source_b(src_data)
        op = digital.map_bb(symbols)
        dst = blocks.vector_sink_b()
        self.tb.connect(src, op, dst)
        self.tb.run()

        result_data = list(dst.data())
        self.assertEqual(expected_data, result_data)
Example #54
0
    def test_004(self):
        src_data = (0x11, )
        expected_results = (0, 4)
        src = blocks.vector_source_b(src_data, False)
        op = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        self.assertEqual(expected_results, dst.data())
Example #55
0
    def test_006(self):
        src_data = (0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0)
        expected_results = (0x82, 0x5a)
        src = blocks.vector_source_b(src_data, False)
        op = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        self.assertEqual(expected_results, dst.data())
Example #56
0
 def __init__(self, samples, len_tag_key, channel=None, prepend_zeros=100):
     gr.top_block.__init__(self, "ofdm_rx")
     if prepend_zeros:
         samples = (0,) * prepend_zeros + tuple(samples)
     src = blocks.vector_source_c(tuple(samples) + (0,) * 1000)
     self.rx = ofdm_rx(frame_length_tag_key=len_tag_key, debug_log=LOG_DEBUG_INFO)
     if channel is not None:
         self.connect(src, channel, self.rx)
     else:
         self.connect(src, self.rx)
     self.sink = blocks.vector_sink_b()
     self.connect(self.rx, self.sink)