示例#1
0
    def derandomizer_pp_desync(self, offset):
        """
        Tests the ability of the derandomiser to synchronise when the inverted SYNC is <offset> packets away
        Note: This method itself is not a unit test method.
        """
        assert offset < 8

        useful_data = make_transport_stream()
        src = blocks.vector_source_b(useful_data)
        pad = dvb.pad_mpeg_ts_packet_bp()
        randomizer = dvb.randomizer_pp()
        depad = dvb.depad_mpeg_ts_packet_pb()
        dst = blocks.vector_sink_b()
        self.tb.connect(src, pad, randomizer, depad, dst)
        self.tb.run()
        randomized_data = dst.data()

        src_data = make_fake_transport_stream_packet(offset)
        src_data.extend(randomized_data)

        self.tb = gr.top_block()
        src = blocks.vector_source_b(src_data)
        pad = dvb.pad_mpeg_ts_packet_bp()
        derandomizer = dvb.derandomizer_pp()
        depad = dvb.depad_mpeg_ts_packet_pb()
        dst = blocks.vector_sink_b()

        self.tb.connect(src, pad, derandomizer, depad, dst)
        self.tb.run()
        result_data = dst.data()
        self.assertEqual(tuple(useful_data), result_data[-len(useful_data):])
示例#2
0
    def __init__(self, data_size, enc, dec, threading):
        gr.top_block.__init__(self, "_qa_helper")

        self.puncpat = puncpat = '11'

        self.enc = enc
        self.dec = dec
        self.data_size = data_size
        self.threading = threading

        self.ext_encoder = extended_encoder(enc, threading=self.threading, puncpat=self.puncpat)
        self.ext_decoder= extended_decoder(dec, threading=self.threading, ann=None,
                                           puncpat=self.puncpat, integration_period=10000)

        self.src = blocks.vector_source_b(data_size*[0, 1, 2, 3, 5, 7, 9, 13, 15, 25, 31, 45, 63, 95, 127], False)
        self.unpack = blocks.unpack_k_bits_bb(8)
        self.map = map_bb([-1, 1])
        self.to_float = blocks.char_to_float(1)
        self.snk_input = blocks.vector_sink_b()
        self.snk_output = blocks.vector_sink_b()

        self.connect(self.src, self.unpack, self.ext_encoder)
        self.connect(self.ext_encoder, self.map, self.to_float)
        self.connect(self.to_float, self.ext_decoder)
        self.connect(self.unpack, self.snk_input)
        self.connect(self.ext_decoder, self.snk_output)
示例#3
0
    def test_preamble (self):
        pream_len = 52
        pream = (mapper.preamble_generator(pream_len,511,1033)).get_preamble()
        
        rand_src    = blocks.vector_source_b(map(int, numpy.random.randint(0, 2, 1024)), True)
        head        = blocks.head(gr.sizeof_char*1, 1024)
        src_sink    = blocks.vector_sink_b(1)
        pream_inst  = mapper.preamble_insert_bb(pream_len*10, (pream))
        bit2symb    = mapper.mapper(mapper.BPSK, ([0,1]))
        pream_sync  = mapper.preamble_sync_cc(pream_len*10, (pream), mapper.BPSK, ([0,1]), .97, .90)
        symb2bit    = mapper.demapper(mapper.BPSK, ([0,1]))
        rec_sink    = blocks.vector_sink_b(1)

        self.tb.connect((rand_src, 0), (head, 0))
        self.tb.connect((head, 0), (pream_inst, 0))
        self.tb.connect((head, 0), (src_sink, 0))
        self.tb.connect((pream_inst, 0), (bit2symb, 0))
        self.tb.connect((bit2symb, 0), (pream_sync, 0))
        self.tb.connect((pream_sync, 0), (symb2bit, 0))
        self.tb.connect((symb2bit, 0), (rec_sink, 0))
        
        self.tb.start()
        sleep(1)
        self.tb.stop()
        
        data_space = pream_len*9
        sd = src_sink.data()
        rd = rec_sink.data()
        self.assertEqual(sd[0:data_space],rd[0:data_space])
    def test_001_t (self):
        cipher_name = "aes-128-cbc"
        key = bytearray("aaaaaaaaaaaaaaaa")
        plain=bytearray("testesttesttestt")

        print "Key:   \t{0}, hex: \t{1}".format(key,binascii.hexlify(key))
        print "plain: \t{0}, hex: \t{1}".format(plain,binascii.hexlify(plain))

        cipher_desc = crypto.sym_ciph_desc(cipher_name, False, key)
        src = blocks.vector_source_b(plain)
        tagger = blocks.stream_to_tagged_stream(1, 1, 16, "packet_len")
        enc = crypto.sym_enc_tagged_bb(cipher_desc, "packet_len")
        snk_enc = blocks.vector_sink_b()
        dec = crypto.sym_dec_tagged_bb(cipher_desc, "packet_len")
        snk = blocks.vector_sink_b()

        self.tb.connect(src, tagger, enc, dec, snk)
        self.tb.connect(enc, snk_enc)
        self.tb.run()

        encrypted = bytearray(snk_enc.data())
        decrypted = bytearray(snk.data())

        print "Encrypted hex: {0}".format(binascii.hexlify(encrypted))
        print "Decrypted: \t{0}, hex: \t{1}".format(decrypted, binascii.hexlify(decrypted))

        self.assertEqual(plain, decrypted)
示例#5
0
	def __init__(self):
		gr.top_block.__init__(self, "Wmbus Phy2")

		##################################################
		# Variables
		##################################################
		self.frame = frame = [1,1]

		##################################################
		# Blocks
		##################################################
		self.gr_vector_source_x_0 = blocks.vector_source_b((frame), False, 1)
		self.gr_vector_sink_x_1 = blocks.vector_sink_b(1)
		self.gr_vector_sink_x_0 = blocks.vector_sink_b(1)
		self.gr_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(4, gr.GR_MSB_FIRST)
		self.gr_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(6)
		self.digital_map_bb_1 = digital.map_bb(([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]))
		self.digital_map_bb_0 = digital.map_bb(([16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 3, 16, 1, 2, 16, 16, 16, 16, 7, 16, 16, 0, 16, 16, 5, 6, 16, 4, 16, 16, 16, 16, 16, 16, 11, 16, 9, 10, 16, 16, 15, 16, 16, 8, 16, 16, 16, 16, 13, 14, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16]))

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_vector_source_x_0, 0), (self.gr_pack_k_bits_bb_0, 0))
		self.connect((self.gr_pack_k_bits_bb_0, 0), (self.digital_map_bb_0, 0))
		self.connect((self.digital_map_bb_0, 0), (self.gr_unpacked_to_packed_xx_0, 0))
		self.connect((self.gr_unpacked_to_packed_xx_0, 0), (self.gr_vector_sink_x_0, 0))
		self.connect((self.digital_map_bb_0, 0), (self.digital_map_bb_1, 0))
		self.connect((self.digital_map_bb_1, 0), (self.gr_vector_sink_x_1, 0))
示例#6
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 range(len(dst_data0)):
            dst_data0[i] = int(dst_data0[i])

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

        self.assertEqual(dst_data1, dst_data0)
示例#7
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())
 def setUp (self):
     self.tb = gr.top_block ()
     self.src = blocks.vector_source_b((1,2,3,4,5,6,7,8,9), 1, 9)
     self.demux = drm.partitioning_vbvb(9, (2,3,4))
     self.head = blocks.head(9,2)
     self.snk1 = blocks.vector_sink_b(2)
     self.snk2 = blocks.vector_sink_b(3)
     self.snk3 = blocks.vector_sink_b(4)
     
     self.tb.connect(self.src, self.head, self.demux)
     self.tb.connect((self.demux,0), self.snk1)
     self.tb.connect((self.demux,1), self.snk2)
     self.tb.connect((self.demux,2), self.snk3)
示例#9
0
 def test_additive_scrambler_reset_3bpb(self):
     src_data = (5,)*2000
     src = blocks.vector_source_b(src_data, False)
     scrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 100, 3)
     descrambler = digital.additive_scrambler_bb(0x8a, 0x7f, 7, 100, 3)
     dst = blocks.vector_sink_b()
     dst2 = blocks.vector_sink_b()
     self.tb.connect(src, scrambler, descrambler, dst)
     self.tb.connect(scrambler, dst2)
     self.tb.run()
     if not (src_data == dst.data()):
         self.fail('Not equal.')
     self.assertEqual(src_data, src_data)
示例#10
0
    def test_symbol_demapper_qpsk (self):
        # set up fg
        mode = 3
        segments_A = 1
        constellation_size_A = 4
        segments_B = 11
        constellation_size_B = 4
        segments_C = 1
        constellation_size_C = 4
        
        demapper = isdbt.symbol_demapper(mode, segments_A, constellation_size_A, segments_B, constellation_size_B, segments_C, constellation_size_C)
        #src_data = (0.5 + 0.5j,  0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j,
        #            0.8 + 1.0j, -0.5 + 0.1j,  0.5 - 1.2j, -0.2 - 1.0j) * 48
        src_syms = [
            1 + 1j,  1 - 1j, -1 - 1j, -1 + 1j,
            1 + 1j, -1 + 1j,  1 - 1j, -1 - 1j ]
        src_syms_noisy = [self.add_noise(z) for z in src_syms]
        src_data = src_syms_noisy*48*13
        # normalización sqrt(2) ?
        expected_result_A = \
            (    0,       1,       3,       2,
                 0,       2,       1,       3) * 48*segments_A
        expected_result_B = \
            (    0,       1,       3,       2,
                 0,       2,       1,       3) * 48*segments_B
        expected_result_C = \
            (    0,       1,       3,       2,
                 0,       2,       1,       3) * 48*segments_C

        src = blocks.vector_source_c(src_data*3, False, 384*13)
        dst_A = blocks.vector_sink_b(384*segments_A)
        dst_B = blocks.vector_sink_b(384*segments_B)
        dst_C = blocks.vector_sink_b(384*segments_C)

        self.tb.connect(src,demapper)
        self.tb.connect((demapper,0),dst_A)
        self.tb.connect((demapper,1),dst_B)
        self.tb.connect((demapper,2),dst_C)
        self.tb.run()

        # check data
        actual_result_A = dst_A.data()
        actual_result_B = dst_B.data()
        actual_result_C = dst_C.data()
        #print "actual result", actual_result
        #print "expected result", expected_result
        self.assertFloatTuplesAlmostEqual(expected_result_A*3, actual_result_A)
        self.assertFloatTuplesAlmostEqual(expected_result_B*3, actual_result_B)
        self.assertFloatTuplesAlmostEqual(expected_result_C*3, actual_result_C)
	def test_001_ofdm_coarse_frequency_correct(self):
		fft_length   = 10
		num_carriers = 2
		cp_length    = 3
		src_data0        = [0,1,2,3,4,5,6,7,8,9,1,2,0,5,7,6,0,4,0,6,1,1,1,0.8,0.1,1.3,1,0.7,1,1,0,1,2,3,4,5,6,7,8,9]
		expected_result0 = [7,9,5,6,0.8,1.3,3,5]
		offset           = [3,3,-1,-1,-1,-1,-1,-1]
		frame_index      = [0,0, 0, 0, 0, 0, 1, 1]
		expected_result0 = [complex(expected_result0[i])*cmath.exp(-2j*cmath.pi*offset[i]*cp_length/float(fft_length)*frame_index[i]) for i in range(0,8)]
		src_data1 = [1,1,1,0]
		expected_result1 = (1,1,1,0)
		src0 = blocks.vector_source_c(src_data0)
		src1 = blocks.vector_source_b(src_data1)
		s2v0 = blocks.stream_to_vector(gr.sizeof_gr_complex, fft_length)
		ofdm_coarse_frequency_correct = grdab.ofdm_coarse_frequency_correct(fft_length,num_carriers,cp_length)
		v2s0 = blocks.vector_to_stream(gr.sizeof_gr_complex, num_carriers)
		dst0 = blocks.vector_sink_c()
		dst1 = blocks.vector_sink_b()
		self.tb.connect(src0, s2v0, (ofdm_coarse_frequency_correct,0))
		self.tb.connect(src1, (ofdm_coarse_frequency_correct,1))
		self.tb.connect((ofdm_coarse_frequency_correct,0), v2s0, dst0)
		self.tb.connect((ofdm_coarse_frequency_correct,1), dst1)
		self.tb.run()
		result_data0 = dst0.data()
		result_data1 = dst1.data()
		# print expected_result0
		# print result_data0
		self.assertComplexTuplesAlmostEqual(expected_result0, result_data0, 4)
		self.assertEqual(result_data1, expected_result1)
示例#12
0
 def test_001_t (self):
     # set up fg
     prbs = evert.prbs_b()
     dst  = blocks.vector_sink_b()
     self.tb.connect (prbs, dst)
     self.tb.run ()
     result_data = dst.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_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)
示例#15
0
    def test_001_frames(self):
        num_frames = 501
        total_subcarriers = 8
        used_subcarriers = 4
        channel_map = ft.get_channel_map(used_subcarriers, total_subcarriers)
        payload_symbols = 8
        overlap = 4

        preamble = ft.get_preamble(total_subcarriers)
        num_preamble_symbols = len(preamble) // total_subcarriers
        payload = ft.get_payload(payload_symbols, used_subcarriers)
        payload = np.tile(payload, num_frames).flatten()

        src = blocks.vector_source_b(payload, repeat=False)
        framer = fbmc.frame_generator_bvc(used_subcarriers, total_subcarriers, payload_symbols, overlap, channel_map, preamble)
        deframer = fbmc.deframer_vcb(used_subcarriers, total_subcarriers, num_preamble_symbols, payload_symbols, overlap, channel_map)
        snk = blocks.vector_sink_b(1)
        self.tb.connect(src, framer, deframer, snk)
        self.tb.run()

        res = np.array(snk.data())
        print res
        print payload

        self.assertTupleEqual(tuple(payload), tuple(res))
示例#16
0
    def test_001_t(self):
        num_frames = 5
        total_subcarriers = 8
        used_subcarriers = 4
        channel_map = ft.get_channel_map(used_subcarriers, total_subcarriers)
        payload_symbols = 8
        overlap = 4
        num_preamble_symbols = 4

        payload = ft.get_payload(payload_symbols, used_subcarriers)
        frame = ft.get_frame(payload, total_subcarriers, channel_map, payload_symbols, overlap)
        frame = np.tile(frame, num_frames).flatten()
        payload = np.tile(payload, num_frames).flatten()

        # set up fg
        src = blocks.vector_source_c(frame, repeat=False, vlen=total_subcarriers)
        deframer = fbmc.deframer_vcb(used_subcarriers, total_subcarriers, num_preamble_symbols, payload_symbols, overlap, channel_map)
        snk = blocks.vector_sink_b(1)
        self.tb.connect(src, deframer, snk)
        self.tb.run()

        # check data
        res = np.array(snk.data())
        print res
        print payload

        self.assertTupleEqual(tuple(payload), tuple(res))
 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)
示例#18
0
    def test_003 (self):
        # Test that block stops when interacting with streaming interface
        port = str(random.Random().randint(0, 30000) + 10000)
        srcdata = (0x73, 0x75, 0x63, 0x68, 0x74, 0x65, 0x73, 0x74, 0x76, 0x65, 0x72, 0x79, 0x70, 0x61, 0x73, 0x73)
        tag_dict = {"offset": 0}
        tag_dict["key"] = pmt.intern("len")
        tag_dict["value"] = pmt.from_long(8)
        tag1 = gr.python_to_tag(tag_dict)
        tag_dict["offset"] = 8
        tag2 = gr.python_to_tag(tag_dict)
        tags = [tag1, tag2]

        src = blocks.vector_source_b(srcdata, False, 1, tags)
        ts_to_pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, "len")
        pdu_send = blocks.socket_pdu("UDP_CLIENT", "localhost", "4141")
        #pdu_recv = blocks.socket_pdu("UDP_SERVER", "localhost", port)
        pdu_to_ts = blocks.pdu_to_tagged_stream(blocks.byte_t, "len")
        head = blocks.head(gr.sizeof_char, 10)
        sink = blocks.vector_sink_b(1)

        self.tb.connect(src, ts_to_pdu)
        self.tb.msg_connect(ts_to_pdu, "pdus", pdu_send, "pdus")
        # a UDP socket connects pdu_send to pdu_recv
        # TODO: test that the recv socket can be destroyed from downstream
        # that signals DONE. Also that we get the PDUs we sent
        #self.tb.msg_connect(pdu_recv, "pdus", pdu_to_ts, "pdus")
        #self.tb.connect(pdu_to_ts, head, sink)
        self.tb.run()
示例#19
0
    def test_002_one_vector(self):
        print("test_002_one_vector")
        expo = 6
        block_size = 2 ** expo
        num_info_bits = 2 ** (expo - 1)
        max_list_size = 2 ** (expo - 2)
        num_frozen_bits = block_size - num_info_bits
        frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0)
        frozen_bit_values = np.array([0] * num_frozen_bits,)

        bits = np.random.randint(2, size=num_info_bits)
        encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)
        data = encoder.encode(bits)
        gr_data = 2.0 * data - 1.0

        polar_decoder = fec.polar_decoder_sc_list.make(max_list_size, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)
        src = blocks.vector_source_f(gr_data, False)
        dec_block = extended_decoder(polar_decoder, None)
        snk = blocks.vector_sink_b(1)

        self.tb.connect(src, dec_block)
        self.tb.connect(dec_block, snk)
        self.tb.run()

        res = np.array(snk.data()).astype(dtype=int)

        print("\ninput -> result -> bits")
        print(data)
        print(res)
        print(bits)

        self.assertTupleEqual(tuple(res), tuple(bits))
	def test_002_ofdm_remove_first_symbol_vcc(self):
		src_data0        = (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7)
		src_data1        = (1,0,0,1,0,0)
		expected_result0 = (3,4,5,6,7,8,2,3,4,5,6,7)
		expected_result0 = [x+0j for x in expected_result0]
		expected_result1 = (1,0,1,0)
		src0 = blocks.vector_source_c(src_data0)
		src1 = blocks.vector_source_b(src_data1)
		s2v0 = blocks.stream_to_vector(gr.sizeof_gr_complex,3)
		ofdm_remove_first_symbol = grdab.ofdm_remove_first_symbol_vcc(3)
		v2s0 = blocks.vector_to_stream(gr.sizeof_gr_complex,3)
		dst0 = blocks.vector_sink_c()
		dst1 = blocks.vector_sink_b()
		self.tb.connect(src0, s2v0, (ofdm_remove_first_symbol,0))
		self.tb.connect(src1, (ofdm_remove_first_symbol,1))
		self.tb.connect((ofdm_remove_first_symbol,0), v2s0, dst0)
		self.tb.connect((ofdm_remove_first_symbol,1), dst1)
		self.tb.run()
		result_data0 = dst0.data()
		result_data1 = dst1.data()
		# print src_data0
		# print expected_result0
		# print result_data0
		self.assertComplexTuplesAlmostEqual(expected_result0, result_data0, 6)
		self.assertEqual(result_data1, expected_result1)
示例#21
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.tp = drm.transm_params(1, 3, False, 0, False, 1, 0, 1, 1, 0, False, 24000, "station label", "text message")
     self.src = drm.generate_sdc_b(self.tp)
     self.head = blocks.head(self.tp.sdc().L(), 1)
     self.snk = blocks.vector_sink_b(self.tp.sdc().L())
     self.tb.connect(self.src, self.head, self.snk)
示例#22
0
    def test_004_t (self):
        # Annex O example 4, NRNSC with 0x6f4e SFD
        pkt_src = ieee802154g.mrfsk_source(
            1,      #num_iterations
            4,      #preamble_size
            True,  #fec_en
            False,   #dw
            False,   #crc_type_16
            2,      #payload_type (0x400056)
            7,      #psdu_len  (ignored with payload_type=2)
            0       #delay_bytes
        )
        dst = blocks.vector_sink_b()
        tsink = tag_sink()
        expected_results = ( 0x55, 0x55, 0x55, 0x55, 0x6f, 0x4e,
            0xbf, 0x7f, 0x3f, 0xff, 0xfc, 0xfd, 0xfc, 0xf2, 0x37, 0xaa,
            0xbc, 0xb7, 0x5e, 0x13, 0xa4, 0x5d, 0xb2, 0xf0, 0xb4, 0x3c)

        self.tb.connect(pkt_src, dst)
        self.tb.connect(pkt_src, tsink)
        self.tb.run ()
        result = dst.data()
        #for i in range(tsink.tx_on_at, tsink.tx_off_at):
        #    print "%d: %02x" % (i, result[i])
        result_txon = result[tsink.tx_on_at:tsink.tx_off_at-1];
        #print result_txon
        #print expected_results 
        self.assertEqual(expected_results, result_txon)
示例#23
0
    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)
示例#24
0
 def test_001_t (self):
     # set up fg
     phr = np.random.randint(0,2,size=(12,))
     data = np.array(np.random.randint(0,256, size=(6*3,)))
     data_bin = np.unpackbits(np.array(data,dtype=np.uint8))
     self.src = blocks.vector_source_b(data, False, 1, [])
     self.s2ts = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, 6, "packet_len")
     self.ts2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, "packet_len")
     self.pref = ieee802_15_4.phr_prefixer(phr)
     self.pdu2ts = blocks.pdu_to_tagged_stream(blocks.byte_t, "packet_len")
     self.snk = blocks.vector_sink_b(1)
     self.tb.connect(self.src, self.s2ts, self.ts2pdu)
     self.tb.msg_connect(self.ts2pdu, "pdus", self.pref, "in")
     self.tb.msg_connect(self.pref, "out", self.pdu2ts, "pdus")
     self.tb.connect(self.pdu2ts, self.snk)
     self.tb.start()
     time.sleep(1)
     self.tb.stop()
     # check data
     data_out = self.snk.data()
     # print "input:"
     # for i in data:
     # 	print i
     # print "output:"
     # for i in data_out:
     # 	print data_out
     expected_output = np.concatenate((phr,data_bin[0:6*8], phr, data_bin[6*8:12*8], phr, data_bin[12*8:18*8]))
     self.assertFloatTuplesAlmostEqual(data_out, expected_output)
示例#25
0
    def test_001_t (self):
        count = 2
        interval = 1000
        msg_list = [pmt.string_to_symbol('hello')] * count
        src_data = [1.0] * (count * interval)

        src = blocks.vector_source_f(src_data, False)
        msg_gen = message_generator(msg_list, interval)
        msg_cons = varicode_enc_b()

        dest = blocks.vector_sink_b()

        self.tb.connect(src, msg_gen)
        self.tb.connect(msg_cons, dest)

        self.tb.msg_connect(msg_gen, 'out_port', msg_cons, 'in_port')

        self.tb.run()

        print "Msg Ctr:", msg_gen.msg_ctr
        while msg_gen.msg_ctr < count:
            print "Msg Ctr:", msg_gen.msg_ctr
            time.sleep(0.5)
        print "Msg Ctr:", msg_gen.msg_ctr

        self.tb.stop()
        self.tb.wait()

        print 'Output Data:', dest.data()
 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([random.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)
示例#27
0
    def test_003_stream(self):
        print("test_003_stream")
        nframes = 5
        expo = 8
        block_size = 2 ** expo
        num_info_bits = 2 ** (expo - 1)
        max_list_size = 2 ** (expo - 2)
        num_frozen_bits = block_size - num_info_bits
        frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0)
        frozen_bit_values = np.array([0] * num_frozen_bits,)

        encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)

        ref = np.array([], dtype=int)
        data = np.array([], dtype=int)
        for i in range(nframes):
            b = np.random.randint(2, size=num_info_bits)
            d = encoder.encode(b)
            data = np.append(data, d)
            ref = np.append(ref, b)
        gr_data = 2.0 * data - 1.0

        polar_decoder = fec.polar_decoder_sc_list.make(max_list_size, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)
        src = blocks.vector_source_f(gr_data, False)
        dec_block = extended_decoder(polar_decoder, None)
        snk = blocks.vector_sink_b(1)

        self.tb.connect(src, dec_block)
        self.tb.connect(dec_block, snk)
        self.tb.run()

        res = np.array(snk.data()).astype(dtype=int)
        self.assertTupleEqual(tuple(res), tuple(ref))
示例#28
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)
    def test_002_t (self):
        # CRC-16 test from section 5.2.1.9 in 802.15.4-2011
        pad = (0xff,) * 8
        src_data = pad + (0x55, 0x55, 0x90, 0x4e, 0x10, 0x05, 0x40, 0x00, 0x56, 0x27, 0x9e) + pad
        src_data_list = hex_list_to_binary_list(src_data)
        expected_str = '\x40\x00\x56\x27\x9e'

        rcvd_pktq = gr.msg_queue()

        src = blocks.vector_source_b(src_data_list)
        correlator = digital.correlate_access_code_bb('0101010101011001000001001110', 1)
        framer_sink = ieee802154g.framer_sink_mrfsk(rcvd_pktq)
        vsnk = blocks.vector_sink_b()

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

        # check data
        self.assertEquals(1, rcvd_pktq.count())
        result_msg = rcvd_pktq.delete_head()
        fec = int(result_msg.type())
        self.assertEquals(0, fec)
        phr = int(result_msg.arg1())
        self.assertEquals(0x1005, phr)
        crc_ok = int(result_msg.arg2())
        self.assertEquals(1, crc_ok)
        self.assertEquals(expected_str, result_msg.to_string())
    def test_003_t (self):
        # Annex O.3 example 2: whitening enabled
        pad = (0xff,) * 8
        src_data = pad + (0x55, 0x55, 0x55, 0x90, 0x4e, 0x08, 0x07, 0x4f, 0x70, 0xe5, 0x32, 0x6a, 0x62, 0x60) + pad
        src_data_list = hex_list_to_binary_list(src_data)
        expected_str = '\x40\x00\x56\x5d\x29\xfa\x28'

        rcvd_pktq = gr.msg_queue()

        src = blocks.vector_source_b(src_data_list)
        correlator = digital.correlate_access_code_bb('0101010101011001000001001110', 1)
        framer_sink = ieee802154g.framer_sink_mrfsk(rcvd_pktq)
        vsnk = blocks.vector_sink_b()

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

        # check data
        self.assertEquals(1, rcvd_pktq.count())
        result_msg = rcvd_pktq.delete_head()
        fec = int(result_msg.type())
        self.assertEquals(0, fec)
        phr = int(result_msg.arg1())
        self.assertEquals(0x0807, phr)
        crc_ok = int(result_msg.arg2())
        self.assertEquals(1, crc_ok)
        self.assertEquals(expected_str, result_msg.to_string())
示例#31
0
    def setUp (self):
        self.tb = gr.top_block ()
        
        mib = lte_test.pack_mib(50,0,1.0, 511)
        mib_crc = lte_test.crc_checksum(mib, 2)
        c_encoded = lte_test.convolutional_encoder(mib_crc)
        data = lte_test.nrz_encoding(c_encoded)

        self.src = blocks.vector_source_f(data,False, 120)
        self.vit = bch_viterbi_vfvb()
        self.snk = blocks.vector_sink_b(40)
        
        self.dbgs = blocks.file_sink(120 * gr.sizeof_float, "/home/johannes/tests/viterbi.dat")
        self.tb.connect(self.src, self.dbgs)
        
        # connecting blocks
        self.tb.connect(self.src,self.vit, self.snk)
    def _test_constellation_decoder_cb_qpsk(self):
        cnst = digital.constellation_qpsk()
        src_data = (0.5 + 0.5j, 0.1 - 1.2j, -0.8 - 0.1j, -0.45 + 0.8j,
                    0.8 + 1.0j, -0.5 + 0.1j, 0.1 - 1.2j)
        expected_result = (3, 1, 0, 2, 3, 2, 1)
        src = blocks.vector_source_c(src_data)
        op = digital.constellation_decoder_cb(cnst.base())
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()  # run the graph and wait for it to finish

        actual_result = dst.data()  # fetch the contents of the sink
        # print "actual result", actual_result
        # print "expected result", expected_result
        self.assertFloatTuplesAlmostEqual(expected_result, actual_result)
示例#33
0
    def test_dpll_bb_002(self):
        period = 4
        gain = 0.1

        src_data = 10*((period-1)*[0,] + [1,])
        expected_result = src_data

        src = blocks.vector_source_b(src_data)
        op = analog.dpll_bb(period, gain)
        dst = blocks.vector_sink_b()

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

        result_data = dst.data()
        self.assertComplexTuplesAlmostEqual(expected_result, result_data, 4)
示例#34
0
    def test_003_work_function_unpacked(self):
        is_packed = False
        block_size = 256
        num_info_bits = block_size // 2

        data, ref, polar_encoder = self.get_test_data(block_size,
                                                      num_info_bits, 1,
                                                      is_packed)
        src = blocks.vector_source_b(data, False)
        enc_block = extended_encoder(polar_encoder, None, '11')
        snk = blocks.vector_sink_b(1)

        self.tb.connect(src, enc_block, snk)
        self.tb.run()

        res = np.array(snk.data()).astype(dtype=int)
        self.assertTupleEqual(tuple(res), tuple(ref))
示例#35
0
 def test_001_t(self):
     # set up fg
     src_data = (ord('1'), ord('2'), ord('3'), ord('4'), ord('5'), ord('6'),
                 ord('7'), ord('8'), ord('9'))
     out = (ord('1'), ord('2'), ord('3'), ord('4'), ord('5'), ord('6'),
            ord('7'), ord('8'), ord('9'), 0x29, 0xb1)
     crc = crc_g6_py()
     src = blocks.vector_source_b(src_data)
     snk = blocks.vector_sink_b()
     self.tb.connect(src, crc)
     self.tb.connect(crc, snk)
     print("Start running")
     self.tb.run()
     print("End running")
     result = snk.data()
     print("AssertEqual")
     self.assertEqual(out, result)
示例#36
0
    def __test_aligned(self):
        spread = [0] * 8
        src_data = [
            0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        ]
        expected = (0, 1, 0)
        expected_offset = 0
        # set up fg
        despreader = habets38.despreader(spread, 1)
        src = blocks.vector_source_b(src_data, repeat=False)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, despreader)
        self.tb.connect(despreader, dst)

        self.tb.run()
        self.assertEqual(expected, dst.data())
示例#37
0
    def test_011(self):
        random.seed(0)
        src_data = []
        for i in range(56):
            src_data.append((random.randint(0, 255)))
        src_data = src_data
        expected_results = src_data
        src = blocks.vector_source_b(tuple(src_data), False)
        op1 = blocks.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST)
        op2 = blocks.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op1, op2)
        self.tb.connect(op2, dst)
        self.tb.run()

        self.assertEqual(expected_results[0:201], dst.data())
示例#38
0
    def test_004_big_input(self):
        num_blocks = 30
        block_size = 1024
        num_info_bits = block_size // 8

        data, ref, polar_encoder = self.get_test_data(block_size,
                                                      num_info_bits,
                                                      num_blocks)
        src = blocks.vector_source_b(data, False)
        enc_block = extended_encoder(polar_encoder, None, '11')
        snk = blocks.vector_sink_b(1)

        self.tb.connect(src, enc_block, snk)
        self.tb.run()

        res = np.array(snk.data()).astype(dtype=int)
        self.assertTupleEqual(tuple(res), tuple(ref))
示例#39
0
 def test_004_8bits_formatter_ofdm(self):
     occupied_carriers = ((1, 2, 3, 5, 6, 7), )
     # 3 packets:                       |             |       |           |
     data, tags = self.setup_data_tags(((1, 2, 3, 4), (1, 2), (1, 2, 3, 4)))
     src = blocks.vector_source_b(data, tags=tags)
     formatter_object = digital.packet_header_ofdm(occupied_carriers, 1,
                                                   self.tsb_key)
     self.assertEqual(formatter_object.header_len(), 6)
     self.assertEqual(pmt.symbol_to_string(formatter_object.len_tag_key()),
                      self.tsb_key)
     header = digital.packet_headergenerator_bb(
         formatter_object.formatter(), self.tsb_key)
     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)
示例#40
0
 def test_003_t(self):
     vector01 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
                 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)
     expected_result = (0, 0, 3, 0, 0, 0, 7, 0, 0, 0, 11, 4, 0, 0, 15, 8, 1,
                        0, 19, 12, 5, 0, 23, 16, 9, 2, 27, 20, 13, 6, 31,
                        24)
     src = blocks.vector_source_b(vector01, True)
     s2v = blocks.stream_to_vector(gr.sizeof_char, 8)
     time_interleaver = dab.time_interleave_bb(8, [2, 3, 0, 1])
     v2s = blocks.vector_to_stream(gr.sizeof_char, 8)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, s2v, time_interleaver,
                     blocks.head_make(gr.sizeof_char * 8, 4), v2s, dst)
     self.tb.run()
     result = dst.data()
     #print result
     self.assertEqual(expected_result, result)
示例#41
0
 def test_002_t(self):
     srcData = (
         0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00,
         0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
         0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
         0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
         0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
         0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
         0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01,
         0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
         0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
         0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,
         0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
         0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
         0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
         0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01,
         0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
         0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
         0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00,
         0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00,
         0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
         0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
         0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01,
         0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00,
         0x01, 0x01, 0x01, 0x01, 0x01, 0x01)
     refData = (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x02, 0x03,
                0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80,
                0x91, 0xA2, 0xB3, 0xC4, 0xD5, 0xE6, 0xF7, 0x00)
     source = blocks.vector_source_b(srcData)
     deframer = scratch_radio.simple_deframer()
     sink = blocks.vector_sink_b()
     self.tb.connect(source, deframer)
     self.tb.connect(deframer, sink)
     self.tb.run()
     self.assertEqual(refData, sink.data())
示例#42
0
    def test_single_packet_output (self):

        # set up source data
        len_tag_name = "packet_len"
        pad_tag_name = "num_zeros"

        num_zero_pad = 7
        packet_len = 10
        packet_payload = np.array(range(packet_len), dtype=np.uint8)

        header = struct.pack(self.header_fmt, num_zero_pad, packet_len)
        header = np.fromstring(header, dtype=np.uint8)

        # combine header and payload
        frame = np.concatenate((header, packet_payload))

        # declare blocks
        src = blocks.vector_source_b(frame.tolist())
        op = traffic_parser(len_tag_name, pad_tag_name)
        dst = blocks.vector_sink_b()

        # connect flowgraph and run
        self.tb.connect(src, op, dst)
        self.tb.run ()

        # retrieve data
        result_data = np.array(dst.data(), dtype=np.uint8)
        result_tags = dst.tags()
        result_tags = sorted([tag_to_dict(t) for t in result_tags])


        self.assertTrue(np.all(packet_payload == result_data))

        # check tags
        expected_tags = [{"offset":0,
                          "key":len_tag_name,
                          "value":packet_len},
                         {"offset":0,
                          "key":pad_tag_name,
                          "value":num_zero_pad}]

        expected_tags = sorted(expected_tags)


        self.assertListEqual(expected_tags, result_tags)
示例#43
0
    def test_peak2(self):
        #print "\n\nTEST 2"
        tb = self.tb

        n = 10
        data = (
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            9,
            8,
            7,
            6,
            5,
            4,
            3,
            2,
            1,
            0,
        ) + n * (0, )

        expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
                           0, 0, 0, 0) + n * (0, )

        src = blocks.vector_source_f(data, False)
        regen = blocks.peak_detector2_fb(7.0, 1000,
                                         0.001)  # called with a LONG window
        dst = blocks.vector_sink_b()

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

        dst_data = dst.data()

        # here we know that the block will terminate prematurely, so we compare only part of the expected_result
        self.assertEqual(expected_result[0:len(dst_data)], dst_data)
示例#44
0
    def test_001_t(self):
        """Encoder to Decoder - noiseless - no constellation de-mapper"""

        # Parameters
        N = 18444
        K = 6144
        n_ite = 6
        const = [1 - 1]
        flip_llrs = False

        # Input data
        in_vec = [i % 2 for i in range(K)]

        # Flowgraph
        src = blocks.vector_source_b(in_vec)
        enc = blocksattx.turbo_encoder(N, K)
        mapb = digital.map_bb([1, -1])
        c2f = blocks.char_to_float()
        dec = blocksat.turbo_decoder(N, K, n_ite, flip_llrs)
        snk = blocks.vector_sink_b()
        snk_sym = blocks.vector_sink_f()
        snk_llr = blocks.vector_sink_f()
        self.tb.connect(src, enc, mapb, c2f, dec, snk)
        self.tb.connect(c2f, snk_sym)
        self.tb.connect(c2f, snk_llr)
        self.tb.run()

        # NOTE: the above mapping maps bit "0" to symbol +1 and bit "1" to
        # symbol -1. The LLR is obtained directly by converting the symbol to a
        # float, meaning the assumption is that a positive LLR implies bit 0 and
        # negative LLR implies bit 1. This assumption matches with the
        # convention that is adopted in the Turbo Decoder.

        # Collect results
        out_vec = snk.data()
        syms = snk_sym.data()
        llrs = snk_llr.data()
        diff = array(in_vec) - array(out_vec)
        err = [0 if i == 0 else 1 for i in diff]

        self.dump(const, in_vec, syms, llrs, out_vec)
        print('Number of errors: %d' % (sum(err)))

        # Check results
        self.assertEqual(sum(err), 0)
示例#45
0
 def test_001_t(self):
     src_data01 = (0x1D, 0x13, 0x06, 0x00, 0x00, 0x01, 0x0B, 0x00, 0x00,
                   0x05, 0x03, 0x00, 0x00, 0x09, 0x07, 0x00, 0x00, 0x04,
                   0x09, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x02, 0x08,
                   0x00, 0x00, 0x0A, 0x00, 0x00)
     expected_result = (0x1D, 0x13, 0x06, 0x00, 0x00, 0x01, 0x0B, 0x00,
                        0x00, 0x05, 0x03, 0x00, 0x00, 0x09, 0x07, 0x00,
                        0x00, 0x04, 0x09, 0x00, 0x00, 0x0C, 0x02, 0x00,
                        0x00, 0x02, 0x08, 0x00, 0x00, 0x0A, 0xE4, 0x9C)
     src = blocks.vector_source_b(src_data01)
     s2v = blocks.stream_to_vector(gr.sizeof_char, 32)
     crc16 = grdab.crc16_bb(32, 0x1021, 0xffff)
     v2s = blocks.vector_to_stream(gr.sizeof_char, 32)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, s2v, crc16, v2s, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(expected_result, result_data)
 def test_001_t(self):
     self.samp_rate = samp_rate = 32000
     src_data = (1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
                 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0)
     bitpattern = (1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1)
     expected_result = (0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0)
     epa = extract_payload.extract_payload(bitpattern, len(expected_result),
                                           len(bitpattern))
     src = blocks.vector_source_b(src_data, False, 1, [])
     snk = blocks.vector_sink_b(1, 0)
     thr = blocks.throttle(gr.sizeof_char * 1, samp_rate, True)
     self.tb.connect((thr, 0), (epa, 0))
     self.tb.connect((src, 0), (thr, 0))
     self.tb.connect((epa, 0), (snk, 0))
     self.tb.run()
     result_data = snk.data()
     #print(result_data)
     self.assertEqual(expected_result, result_data)
 def test_001(self):
     pad = [
         0,
     ] * 64
     #           0  0  0  1  0  0  0  1
     src_data = [1, 0, 1, 1, 1, 1, 0, 1, 1] + pad + [
         0,
     ] * 7
     expected_result = pad + [1, 0, 1, 1, 3, 1, 0, 1, 1, 2] + [
         0,
     ] * 6
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_bb("1011", 0)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(expected_result, result_data)
示例#48
0
    def run_interleaving_test(self, data, expected, rate):
        # set source block
        tags = [swifi.phy_tag(offset=0, key='phy', rate=rate)]
        source = blocks.vector_source_b(data, repeat=False, vlen=1, tags=tags)

        # set interleaving
        interleaver = swifi.interleaver(True, 'phy')

        # set sink for comparing result
        sink = blocks.vector_sink_b()

        # connect blocks together
        self.tb.connect(source, interleaver, sink)

        self.tb.run()

        # check
        self.assertEqual(sink.data(), tuple(expected))
 def test_001(self):
     payload = "test packet"     # payload length is 11 bytes
     header = "\x00\xd0\x00\xd0" # header contains packet length, twice (bit-swapped)
     packet = header + payload
     pad = (0,) * 64
     src_data = (0, 0, 1, 1, 1, 1, 0, 1, 1) + tuple(string_to_1_0_list(packet)) + pad
     expected = tuple(map(int, src_data[9+32:-len(pad)]))
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_bb_ts("1011", 0, "sync")
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.data()
     result_tags = dst.tags()
     self.assertEqual(len(result_data), len(payload)*8)
     self.assertEqual(result_tags[0].offset, 0)
     self.assertEqual(pmt.to_long(result_tags[0].value), len(payload)*8)
     self.assertEqual(result_data, expected)
示例#50
0
    def test_001_t(self):
        chaos_values = (1 + 0j, 0 + 1j, -1 + 0j, 0 - 1j)
        expected_result = (0, 1, 0, 0, 1, 1)
        zero = chaos_values + tuple(map(lambda v: -v, chaos_values))
        one = 2 * chaos_values
        src_data = zero + one + zero + zero + one + one

        src = blocks.vector_source_c(src_data)
        demod = chaos.dcsk_demod_cb(len(chaos_values), 0)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, demod, dst)

        self.tb.run()

        result_data = dst.data()

        self.assertFloatTuplesAlmostEqual(expected_result, result_data)
示例#51
0
 def test_005_tag_propagation (self):
     """ Make sure tags on the CRC aren't lost. """
     data = (0, 1, 2, 3, 4, 5, 6, 7, 8, 2, 67, 225, 188)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(data))
     testtag = gr.tag_t()
     testtag.offset = len(data)-1
     testtag.key = pmt.string_to_symbol('tag1')
     testtag.value = pmt.from_long(0)
     src = blocks.vector_source_b(data, False, 1, (tag, testtag))
     crc_check = digital.crc32_bb(True, tag_name)
     sink = blocks.vector_sink_b()
     self.tb.connect(src, crc_check, sink)
     self.tb.run()
     self.assertEqual([len(data)-5,], [tag.offset for tag in sink.tags() if pmt.symbol_to_string(tag.key) == 'tag1'])
示例#52
0
 def test_010_t(self):
     preamble = [2, 4, 8, 16]
     pre_len = len(preamble)
     src_data = (2, 4, 8, 16, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1,
                 1, 2, 4, 8, 16, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1,
                 1, 0)
     #expected_result = (0, 0, 0, 255, 255, 255, 255, 255, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 255, 255, 255, 255, 255, 1, 0, 1, 0, 1, 0, 1, 0)
     expected_result = (31, 173, 15, 31, 170, 150)
     src = blocks.vector_source_b(src_data)
     dst = blocks.vector_sink_b()
     pck = blocks.pack_k_bits_bb(8)
     dtct = frame_detection.preamble_detector_bb(preamble, pre_len, 16, 8)
     self.maxDiff = None
     self.tb.connect(src, dtct)
     self.tb.connect(dtct, pck, dst)
     self.tb.run()
     result_data = dst.data()
     self.assertEqual(expected_result, result_data)
 def test_hard_decision(self):
     for constellation, differential in tested_constellations():
         if differential:
             rs = constellation.rotational_symmetry()
             rotations = [exp(i*2*pi*(0+1j)/rs) for i in range(0, rs)]
         else:
             rotations = [None]
         for rotation in rotations:
             src = blocks.vector_source_b(self.src_data)
             content = mod_demod(constellation, differential, rotation)
             dst = blocks.vector_sink_b()
             self.tb = gr.top_block()
             self.tb.connect(src, content, dst)
             self.tb.run()
             data = dst.data()
             # Don't worry about cut off data for now.
             first = constellation.bits_per_symbol()
             self.assertEqual(self.src_data[first:len(data)], data[first:])
    def run_depuncturing_test(self, rate, data, expected):
        # set source block
        tags = [swifi.phy_tag(offset=0, key='phy', rate=rate)]
        source = blocks.vector_source_b(data, repeat=False, vlen=1, tags=tags)

        # set scrambler and descrambler
        depuncture = swifi.bit_inserter('phy')

        # set sink for comparing result
        sink = blocks.vector_sink_b()

        # connect blocks together
        self.tb.connect(source, depuncture, sink)

        self.tb.run()

        # check
        self.assertEqual(sink.data(), tuple(expected))
示例#55
0
 def test_001_t(self):
     # set up fg
     self.src = blocks.vector_source_b(range(12), False, 1, [])
     self.s2ts = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, 4,
                                                "packet_len")
     self.ts2pdu = blocks.tagged_stream_to_pdu(blocks.byte_t, "packet_len")
     self.zeropadding = ieee802_15_4.zeropadding_b(2)
     self.snk = blocks.vector_sink_b(1)
     self.tb.connect(self.src, self.s2ts, self.ts2pdu)
     self.tb.msg_connect(self.ts2pdu, "pdus", self.zeropadding, "in")
     self.tb.connect(self.zeropadding, self.snk)
     self.tb.start()
     time.sleep(1)
     self.tb.stop()
     # check data
     data = self.snk.data()
     self.assertFloatTuplesAlmostEqual(
         data, (0, 1, 2, 3, 0, 0, 4, 5, 6, 7, 0, 0, 8, 9, 10, 11, 0, 0))
 def test_003(self):
     # Test mouldation and demodulation
     bits = np.array([0, 0, 0, 1, 1, 0, 1, 1], dtype=np.int8)
     expected = np.array([1 + 1j, -1 + 1j, -1 - 1j, 1 - 1j]) / np.sqrt(2)
     src = blocks.vector_source_b(bits)
     mod, demod = Modulator(), Demoulator()
     dest_bits = blocks.vector_sink_b()
     dest_signal = blocks.vector_sink_c()
     tb = gr.top_block()
     tb.connect(src, mod)
     tb.connect(mod, dest_signal)
     tb.connect(mod, demod)
     tb.connect(demod, dest_bits)
     tb.run()
     gr_signal = dest_signal.data()
     func_signal = modulate_bits(bits.reshape((-1, bits_per_symbol)))
     gr_bits = dest_bits.data()
     func_bits = demodulate_signal(func_signal)
示例#57
0
	def run(self):
		"""
		Parameter FREQUENCY ignored
		"""
		self.init()
		try:
			osmosdr_source = osmosdr.source( args="numchan=" + str(1) + " " + self.config.option(SDRModule.SDR_ARGS).value)
		except:
			return
		osmosdr_source.set_sample_rate(self.samp_rate)
		osmosdr_source.set_center_freq(2.408e9, 0)
		osmosdr_source.set_freq_corr(0, 0)
		osmosdr_source.set_dc_offset_mode(0, 0)
		osmosdr_source.set_iq_balance_mode(0, 0)
		osmosdr_source.set_gain_mode(False, 0)
		osmosdr_source.set_gain(10, 0)
		osmosdr_source.set_if_gain(20, 0)
		osmosdr_source.set_bb_gain(20, 0)
		osmosdr_source.set_antenna('', 0)
		osmosdr_source.set_bandwidth(0, 0)
		container = gr.top_block()
		digital_gmsk_demod_0 = digital.gmsk_demod(samples_per_symbol=self.samp_syms,gain_mu=0.175,mu=0.5,omega_relative_limit=0.005,freq_error=0.0,verbose=False,log=False,)
		digital_correlate_access_code_xx_ts_0 = digital.correlate_access_code_bb_ts(bin(0xaaaaa)[2:], 4, 'ninco')
		blocks_vector_sink_x_0 = blocks.vector_sink_b(1)
		blocks_repack_bits_bb_0 = blocks.repack_bits_bb(1, 8, "", False, gr.GR_MSB_FIRST)
		container.connect((blocks_repack_bits_bb_0, 0), (blocks_vector_sink_x_0, 0))
		container.connect((digital_correlate_access_code_xx_ts_0, 0), (blocks_repack_bits_bb_0, 0))
		container.connect((digital_gmsk_demod_0, 0), (digital_correlate_access_code_xx_ts_0, 0))
		container.connect((osmosdr_source, 0), (digital_gmsk_demod_0, 0))
		container.start()
		time.sleep(self.timeout)
		data = list(blocks_vector_sink_x_0.data())
		indexes = self.find_sub_list([0xaa, 0xaa], data)
		if len(indexes) > 0:
			self.logger.success("Possible captured IDs")
			for idx in indexes:
				mark = idx[0]
				self.logger.success(", ".join(hex(x)[2:].zfill(2) for x in data[mark:mark + 10]))
				break
		else:
			self.logger.warning("No IDs found. ")
		container.stop()
		container.wait()
		osmosdr_source.disconnect_all()
    def __init__(self):
        gr.top_block.__init__(self, "Bluetooth LE Receiver")

        ##################################################
        # Variables
        ##################################################
        self.transition_width = transition_width = 300e3
        self.sample_rate = sample_rate = 4e6
        self.data_rate = data_rate = 1e6
        self.cutoff_freq = cutoff_freq = 2e6
        self.ble_channel_spacing = ble_channel_spacing = 2e6
        self.ble_channel = ble_channel = 12
        self.ble_base_freq = ble_base_freq = 2402e6
        self.squelch_threshold = squelch_threshold = -110
        self.sensivity = sensivity = 1.0
        self.rf_gain = rf_gain = 74
        self.lowpass_filter = lowpass_filter = firdes.low_pass(
            1, sample_rate, cutoff_freq, transition_width, firdes.WIN_HAMMING,
            6.76)
        self.gfsk_sps = gfsk_sps = int(sample_rate / data_rate)
        self.gfsk_omega_limit = gfsk_omega_limit = 0.035
        self.gfsk_mu = gfsk_mu = 0.5
        self.gfsk_gain_mu = gfsk_gain_mu = 0.8
        self.freq_offset = freq_offset = 0
        self.freq = freq = ble_base_freq + (ble_channel_spacing * ble_channel)
        self.filename = filename = "/Users/mmohamoud/software_defined_radios/ble_collect/demoded_data_lewis_test"

        ##################################################
        # Blocks
        ##################################################
        self.blocks_vector_sink_x_0 = blocks.vector_sink_b(1, 1024)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, 28e4,
                                                 True)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char * 1,
                                                       filename, True)
        self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_vector_sink_x_0, 0))
示例#59
0
    def test_peak1(self):
        #print "\n\nTEST 1"
        tb = self.tb

        n = 10
        data = (
            0,
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            9,
            8,
            7,
            6,
            5,
            4,
            3,
            2,
            1,
            0,
        ) + n * (0, )

        expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
                           0, 0, 0, 0) + n * (0, )

        src = blocks.vector_source_f(data, False)
        regen = blocks.peak_detector2_fb(7.0, 25, 0.001)
        dst = blocks.vector_sink_b()

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

        dst_data = dst.data()

        self.assertEqual(expected_result, dst_data)
示例#60
0
 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)