Esempio n. 1
0
    def test_003_crc_equal_unpacked(self):
        """ Test unpacked operation with packed operation
        """
        data = range(35)
        src = blocks.vector_source_b(data)
        unpack1 = blocks.repack_bits_bb(8, 1, self.tsb_key, False,
                                        gr.GR_LSB_FIRST)
        unpack2 = blocks.repack_bits_bb(8, 1, self.tsb_key, False,
                                        gr.GR_LSB_FIRST)
        crc_unpacked = digital.crc32_bb(False, self.tsb_key, False)
        crc_packed = digital.crc32_bb(False, self.tsb_key, True)
        sink1 = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
        sink2 = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)

        self.tb.connect(
            src,
            blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(data),
                                           self.tsb_key), crc_packed, unpack1,
            sink1)
        self.tb.connect(
            src,
            blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(data),
                                           self.tsb_key), unpack2,
            crc_unpacked, sink2)
        self.tb.run()
        self.assertEqual(sink1.data(), sink2.data())
Esempio n. 2
0
 def test_0010_tag_propagation(self):
     """ Make sure tags on the CRC aren't lost. """
     # Data with precalculated CRC
     data = (0, 0, 0, 0, 0, 0, 0, 0,
             1, 0, 0, 0, 0, 0, 0, 0,
             0, 1, 0, 0, 0, 0, 0, 0,
             1, 1, 0, 0, 0, 0, 0, 0,
             0, 0, 1, 0, 0, 0, 0, 0,
             1, 0, 1, 0, 0, 0, 0, 0,
             0, 1, 1, 0, 0, 0, 0, 0,
             1, 1, 1, 0, 0, 0, 0, 0,
             0, 0, 0, 1, 0, 0, 0, 0,
             0, 1, 0, 0, 0, 0, 0, 0,
             1, 1, 0, 0, 0, 0, 1, 0,
             1, 0, 0, 0, 0, 1, 1, 1,
             0, 0, 1, 1, 1, 1, 0, 1)
     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, (testtag, ))
     crc_check = digital.crc32_bb(True, self.tsb_key, False)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(src,
                     blocks.stream_to_tagged_stream(
                         gr.sizeof_char, 1, len(data), self.tsb_key),
                     crc_check, sink)
     self.tb.run()
     self.assertEqual([len(data) - 33, ], [
         tag.offset for tag in sink.tags()
         if pmt.symbol_to_string(tag.key) == 'tag1'
     ])
Esempio n. 3
0
 def test_0010_tag_propagation (self):
     """ Make sure tags on the CRC aren't lost. """
     # Data with precalculated CRC
     data = (
         0, 1, 2, 3, 4, 5, 6, 7, 8,
         0, 1, 0, 0, 0, 0, 0, 0,
         1, 1, 0, 0, 0, 0, 1, 0,
         1, 0, 0, 0, 0, 1, 1, 1,
         0, 0, 1, 1, 1, 1, 0, 1
     ) # 2, 67, 225, 188
     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, (testtag,))
     crc_check = digital.crc32_bb(True, self.tsb_key, False)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(
             src,
             blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(data), self.tsb_key),
             crc_check,
             sink
     )
     self.tb.run()
     self.assertEqual([len(data)-33,], [tag.offset for tag in sink.tags() if pmt.symbol_to_string(tag.key) == 'tag1'])
Esempio n. 4
0
    def test_with_reset(self):
        input1 = (10, 0, 1, 2)
        #input1= [0, 0, 0, 0, 1, 0, 1, 0]
        #input2 = [ 0, 0, 0, 0, 0, 0, 0, 0]
        #input3 = [ 0, 0, 0, 0, 0, 0, 0, 1]
        #input4 = [0, 0, 0, 0, 0, 0, 1, 0]

        output1 = (245, 225, 28, 152)
        #output1 = [1, 1, 1, 1, 0, 1, 0, 1]
        #output2 = [1, 1, 1, 0, 0, 0, 0, 1]
        #output3 = [0, 0, 0, 1, 1, 1, 0, 0]
        #output4 = [1, 0, 0, 1, 1, 0, 0, 0]

        src = blocks.vector_source_b(input1)
        src.set_max_noutput_items(2)
        src.set_min_output_buffer(2)
        src.set_max_output_buffer(2)

        src_tagged = blocks.stream_to_tagged_stream(gr.sizeof_char, 1,
                                                    len(input1), self.tsb_key)
        src_tagged.set_max_noutput_items(2)
        src_tagged.set_min_output_buffer(2)
        src_tagged.set_max_output_buffer(2)

        pn9 = pn9_whitening(True)

        dst = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)

        self.tb.connect(src, src_tagged, pn9, dst)
        self.tb.run()

        self.assertEquals(dst.data()[0], output1)
 def test_1(self):
     packets0 = (
         (0, 1, 2),  (5, 6),     (10,),         (14, 15, 16,)
     )
     packets1 = (
         (3, 4),     (7, 8, 9),  (11, 12, 13),  (17,)
     )
     expected = ((0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13), (14, 15, 16, 17))
     data0, tags0 = self.setup_data_tags(packets0)
     data1, tags1 = self.setup_data_tags(packets1)
     tags0.append(make_tag('spam', 42, 4))
     tags1.append(make_tag('eggs', 23, 3))
     src0 = blocks.vector_source_b(data0, tags=tags0)
     src1 = blocks.vector_source_b(data1, tags=tags1)
     tagged_stream_mux = blocks.tagged_stream_mux(gr.sizeof_char, self.tsb_key)
     snk = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(src0, (tagged_stream_mux, 0))
     self.tb.connect(src1, (tagged_stream_mux, 1))
     self.tb.connect(tagged_stream_mux, snk)
     self.tb.run()
     # Check
     self.assertEqual(expected, snk.data())
     tags = [gr.tag_to_python(x) for x in snk.tags()]
     tags = sorted([(x.offset, x.key, x.value) for x in tags])
     tags_expected = [
             (6, 'spam', 42),
             (8, 'eggs', 23),
     ]
     self.assertEqual(tags, tags_expected)
Esempio n. 6
0
 def test_1(self):
     packets0 = ((0, 1, 2), (5, 6), (10, ), (
         14,
         15,
         16,
     ))
     packets1 = ((3, 4), (7, 8, 9), (11, 12, 13), (17, ))
     expected = ((0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13),
                 (14, 15, 16, 17))
     data0, tags0 = self.setup_data_tags(packets0)
     data1, tags1 = self.setup_data_tags(packets1)
     tags0.append(make_tag('spam', 42, 4))
     tags1.append(make_tag('eggs', 23, 3))
     src0 = blocks.vector_source_b(data0, tags=tags0)
     src1 = blocks.vector_source_b(data1, tags=tags1)
     tagged_stream_mux = blocks.tagged_stream_mux(gr.sizeof_char,
                                                  self.tsb_key)
     snk = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(src0, (tagged_stream_mux, 0))
     self.tb.connect(src1, (tagged_stream_mux, 1))
     self.tb.connect(tagged_stream_mux, snk)
     self.tb.run()
     # Check
     self.assertEqual(expected, snk.data())
     tags = [gr.tag_to_python(x) for x in snk.tags()]
     tags = sorted([(x.offset, x.key, x.value) for x in tags])
     tags_expected = [
         (6, 'spam', 42),
         (8, 'eggs', 23),
     ]
     self.assertEqual(tags, tags_expected)
Esempio n. 7
0
 def test_001_t(self):
     len_tag_key = "header_len"
     debug_tag_key = "test"
     payload_key = "packet_size"
     own_id = 4
     maxS = 3
     header_one = [20]
     header_two = [17]
     header_three = [132]
     header_four = [20, 20]
     header_five = [20]
     header_six = [20]
     src_data = header_one + header_two + header_three + header_four
     src_data = src_data + header_five + header_six
     src_tags = make_tags(len_tag_key, debug_tag_key, payload_key)
     #blocks
     src = blocks.vector_source_b(src_data, repeat=False, tags=src_tags)
     parser = ownHeader.parse_short_bb(len_tag_key, payload_key, own_id,
                                       maxS)
     dest = blocks.tsb_vector_sink_b(1, len_tag_key)
     #connection
     self.tb.connect(src, parser, dest)
     self.tb.run()
     # retrieve data
     dest_data = dest.data()
     dest_tags = dest.tags()
     #testing
     #receiver data
     self.assertEqual(len(dest_data), 6)
     self.assertEqual(dest_data, ((1, ), (0, ), (0, ), (0, ), (1, ), (1, )))
     #tags
     tags = [gr.tag_to_python(x) for x in dest_tags]
     self.assertEqual(len(tags), 4)
     zero = []
     four = []
     five = []
     rest = []
     for tag in tags:
         if tag.offset == 0:
             zero.append(tag)
         elif tag.offset == 4:
             four.append(tag)
         elif tag.offset == 5:
             five.append(tag)
         else:
             rest.appned(tag)
     self.assertEqual(len(rest), 0)
     self.assertEqual(len(zero), 1)
     self.assertEqual(len(four), 2)
     self.assertEqual(len(five), 1)
     self.assertEqual(zero[0].value, 1)
     for tag in four:
         if tag.key == debug_tag_key:
             self.assertEqual(tag.value, 400)
         elif tag.key == payload_key:
             self.assertEqual(tag.value, 1)
         else:
             self.assertEqual(False, True)
     self.assertEqual(five[0].value, 1)
Esempio n. 8
0
    def test_002_t(self):
        # FORTH & BACK
        input1 = (49, 50, 51, 52, 53, 54, 55, 56, 57)  # Unicode 1-9
        input1_tagger = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(input1), self.tsb_key)
        src = blocks.vector_source_b(input1)
        crc = crc_tagged_stream(False, self.tsb_key)
        crc_check = crc_tagged_stream(True, self.tsb_key)
        dst = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)

        self.tb.connect(src, input1_tagger, crc, crc_check, dst)
        self.tb.run()
        self.assertEquals(dst.data()[0], input1)
 def test_001_t(self):
     len_tag_key = "packet_len"
     receiver_key = 'recv_id'
     pay_len_key = "pay_len"
     debug_key = "test"
     tag_debug = gr.tag_t()
     tag_debug.key = pmt.intern(debug_key)
     tag_debug.value = pmt.from_long(400)
     tag_debug.offset = 2
     tag1 = gr.tag_t()
     tag1.key = pmt.intern(len_tag_key)
     tag1.value = pmt.from_long(2)
     tag1.offset = 0
     tag2 = gr.tag_t()
     tag2.key = pmt.intern(len_tag_key)
     tag2.value = pmt.from_long(2)
     tag2.offset = 2
     tag1r = gr.tag_t()
     tag1r.key = pmt.intern(receiver_key)
     tag1r.value = pmt.from_long(3)
     tag1r.offset = 0
     tag2r = gr.tag_t()
     tag2r.key = pmt.intern(receiver_key)
     tag2r.value = pmt.from_long(3)
     tag2r.offset = 2
     tag1l = gr.tag_t()
     tag1l.key = pmt.intern(pay_len_key)
     tag1l.value = pmt.from_long(2)
     tag1l.offset = 0
     tag2l = gr.tag_t()
     tag2l.key = pmt.intern(pay_len_key)
     tag2l.value = pmt.from_long(2)
     tag2l.offset = 2
     packet1 = [10, 10]
     packet2 = [10, 20]
     src_data = packet1 + packet2
     src_tags = tuple([tag_debug, tag1, tag2, tag1l, tag1r, tag2l, tag2r])
     #blocks
     source = blocks.vector_source_b(src_data, repeat=False, tags=src_tags)
     dest = blocks.tsb_vector_sink_b(tsb_key="packet_len")
     gen = ownHeader.generate_short_bb(len_tag_key, pay_len_key,
                                       receiver_key)
     #connections
     self.tb.connect(source, gen, dest)
     self.tb.run()
     #retrieve fdata
     dest_data = dest.data()
     dest_tags = dest.tags()
     # check data
     self.assertEqual(len(dest_data), 2)
     self.assertEqual(dest_data[0], (35, ))
     self.assertEqual(dest_data[1], (35, ))
     self.assertEqual(len(dest_tags), 0)
Esempio n. 10
0
    def test_001_t (self):
        # ADDING CRC
        input1 = (49, 50, 51, 52, 53, 54, 55, 56, 57) # Unicode 1-9
        input1_tagger = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(input1), self.tsb_key)
        src = blocks.vector_source_b(input1)
        crc = crc_tagged_stream(False, self.tsb_key)
        dst = blocks.tsb_vector_sink_b(tsb_key = self.tsb_key)
        output1 = (49, 50, 51, 52, 53, 54, 55, 56, 57, 177, 41) #unicode 0x29B1

        self.tb.connect(src, input1_tagger, crc, dst)
        self.tb.run ()
        self.assertEquals(dst.data()[0], output1)
    def test_001_t(self):
        src_data = [193 for x in range(12)]
        src_tags = make_tags(0)
        source = blocks.vector_source_b(src_data, repeat=False, tags=src_tags)
        dest = blocks.tsb_vector_sink_b(tsb_key="packet_len")
        header = ownHeader.generate_header_bb("packet_len")
        self.tb.connect(source, header, dest)
        self.tb.run()

        result_data = dest.data()[0]

        self.assertEqual(len(result_data), 6)
        self.assertEqual(result_data, tuple([1, 1, 1, 0, 0, 0]))
Esempio n. 12
0
 def test_001_crc_len(self):
     """ Make sure the output of a CRC set is 4 bytes longer than the input. """
     data = list(range(16))
     src = blocks.vector_source_b(data)
     crc = digital.crc32_bb(False, self.tsb_key)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_char, 1,
                                        len(data), self.tsb_key), crc, sink)
     self.tb.run()
     # Check that the packets before crc_check are 4 bytes longer that the input.
     self.assertEqual(len(data) + 4, len(sink.data()[0]))
Esempio n. 13
0
    def test_002_crc_equal_unpacked (self):
        """ Test unpacked operation with packed operation
        """
        data = (0, 1, 2, 3, 4, 5, 6, 7, 8)
        src = blocks.vector_source_b(data)
        unpack1 = blocks.repack_bits_bb(8, 1, self.tsb_key, False, gr.GR_LSB_FIRST)
        unpack2 = blocks.repack_bits_bb(8, 1, self.tsb_key, False, gr.GR_LSB_FIRST)
        crc_unpacked = digital.crc32_bb(False, self.tsb_key, False)
        crc_packed = digital.crc32_bb(False, self.tsb_key, True)
        sink1 = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
        sink2 = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)

        self.tb.connect(src,
                        blocks.stream_to_tagged_stream(
                            gr.sizeof_char, 1, len(data), self.tsb_key),
                        crc_packed, unpack1, sink1)
        self.tb.connect(src,
                        blocks.stream_to_tagged_stream(
                            gr.sizeof_char, 1, len(data), self.tsb_key),
                        unpack2, crc_unpacked, sink2)
        self.tb.run()
        self.assertEqual(sink1.data(), sink2.data())
Esempio n. 14
0
 def test_001_crc_len(self):
     """ Make sure the output of a CRC set is 4 bytes longer than the input. """
     data = list(range(16))
     src = blocks.vector_source_b(data)
     crc = digital.crc32_bb(False, self.tsb_key)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_char, 1,
                                        len(data), self.tsb_key), crc, sink)
     self.tb.run()
     # Check that the packets before crc_check are 4 bytes longer that the input.
     self.assertEqual(len(data) + 4, len(sink.data()[0]))
Esempio n. 15
0
 def test_002_crc_equal(self):
     """ Go through CRC set / CRC check and make sure the output
     is the same as the input. """
     data = (0, 1, 2, 3, 4, 5, 6, 7, 8)
     src = blocks.vector_source_b(data)
     crc = digital.crc32_bb(False, self.tsb_key)
     crc_check = digital.crc32_bb(True, self.tsb_key)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(src,
                     blocks.stream_to_tagged_stream(
                         gr.sizeof_char, 1, len(data), self.tsb_key), crc,
                     crc_check, sink)
     self.tb.run()
     # Check that the packets after crc_check are the same as input.
     self.assertEqual(data, sink.data()[0])
Esempio n. 16
0
 def test_009_fail(self):
     """ Corrupt the data and make sure it fails CRC test. """
     data = (0, 1, 2, 3, 4, 5, 6, 7)
     src = blocks.vector_source_b(data)
     crc = digital.crc32_bb(False, self.tsb_key, False)
     crc_check = digital.crc32_bb(True, self.tsb_key, False)
     corruptor = blocks.add_const_bb(1)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(src,
                     blocks.stream_to_tagged_stream(
                         gr.sizeof_char, 1, len(data), self.tsb_key), crc,
                     corruptor, crc_check, sink)
     self.tb.run()
     # crc_check will drop invalid packets
     self.assertEqual(len(sink.data()), 0)
Esempio n. 17
0
 def test_004_fail(self):
     """ Corrupt the data and make sure it fails CRC test. """
     data = [0, 1, 2, 3, 4, 5, 6, 7]
     src = blocks.vector_source_b(data)
     crc = digital.crc32_bb(False, self.tsb_key)
     crc_check = digital.crc32_bb(True, self.tsb_key)
     corruptor = blocks.add_const_bb(1)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(src,
                     blocks.stream_to_tagged_stream(
                         gr.sizeof_char, 1, len(data), self.tsb_key), crc,
                     corruptor, crc_check, sink)
     self.tb.run()
     # crc_check will drop invalid packets
     self.assertEqual(len(sink.data()), 0)
Esempio n. 18
0
 def test_002_crc_equal(self):
     """ Go through CRC set / CRC check and make sure the output
     is the same as the input. """
     data = [0, 1, 2, 3, 4, 5, 6, 7, 8]
     src = blocks.vector_source_b(data)
     crc = digital.crc32_bb(False, self.tsb_key)
     crc_check = digital.crc32_bb(True, self.tsb_key)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(src,
                     blocks.stream_to_tagged_stream(
                         gr.sizeof_char, 1, len(data), self.tsb_key), crc,
                     crc_check, sink)
     self.tb.run()
     # Check that the packets after crc_check are the same as input.
     self.assertEqual(data, sink.data()[0])
Esempio n. 19
0
 def test_005_three_with_tags_trailing(self):
     """ 3 -> 8, trailing bits """
     src_data = (0b101, ) + (0b111, ) * 4 + (0b001, )
     expected_data = (0b11111101, 0b11111111)
     k = 3
     l = 8
     src = blocks.vector_source_b(src_data, False, 1)
     repack = blocks.repack_bits_bb(k, l, self.tsb_key, True)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(src_data),
                                        self.tsb_key), repack, sink)
     self.tb.run()
     self.assertEqual(len(sink.data()), 1)
     self.assertEqual(sink.data()[0], expected_data)
Esempio n. 20
0
    def test_001_t (self):
        src_data  = [180 for x in range(13)]
        src_data2 = [193 for x in range(13)]
        src_tags = make_tags(0) + make_tags(13)
        source = blocks.vector_source_b(src_data,repeat = False, tags = src_tags)        
        dest   = blocks.tsb_vector_sink_b(tsb_key="packet_l")
        header = ownHeader.append_header_bb("packet_l")
        tagger = blocks.stream_to_tagged_stream(gr.sizeof_char,1, len(src_data), "packet_l")
        self.tb.connect(source,tagger,header)
        self.tb.connect(header,dest)
        self.tb.run ()

        result_data = dest.data()
        result_tags = dest.tags()

        self.assertEqual(len(result_data[0]),len(src_data)+6)
        self.assertEqual(result_data[0], tuple([1,1,1,0,0,0] + src_data))
Esempio n. 21
0
 def test_003_crc_correct_lentag (self):
     tag_name = "length"
     pack_len = 8
     packets = range(pack_len*2)
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tag_name)
     tag1.value = pmt.from_long(pack_len)
     tag2 = gr.tag_t()
     tag2.offset = pack_len
     tag2.key = pmt.string_to_symbol(tag_name)
     tag2.value = pmt.from_long(pack_len)
     testtag1 = gr.tag_t()
     testtag1.offset = 1
     testtag1.key = pmt.string_to_symbol("tag1")
     testtag1.value = pmt.from_long(0)
     testtag2 = gr.tag_t()
     testtag2.offset = pack_len
     testtag2.key = pmt.string_to_symbol("tag2")
     testtag2.value = pmt.from_long(0)
     testtag3 = gr.tag_t()
     testtag3.offset = len(packets)-1
     testtag3.key = pmt.string_to_symbol("tag3")
     testtag3.value = pmt.from_long(0)
     src = blocks.vector_source_b(packets, False, 1, (testtag1, testtag2, testtag3))
     crc = digital.crc32_bb(False, self.tsb_key)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(
             src,
             blocks.stream_to_tagged_stream(gr.sizeof_char, 1, pack_len, self.tsb_key),
             crc,
             sink
     )
     self.tb.run()
     self.assertEqual(len(sink.data()), 2)
     self.assertEqual(len(sink.data()[0]), (pack_len+4))
     self.assertEqual(len(sink.data()[1]), (pack_len+4))
     correct_offsets = {'tag1': 1, 'tag2': 12, 'tag3': 19}
     tags_found = {'tag1': False, 'tag2': False, 'tag3': False}
     for tag in sink.tags():
         key = pmt.symbol_to_string(tag.key)
         if key in correct_offsets.keys():
             tags_found[key] = True
             self.assertEqual(correct_offsets[key], tag.offset)
     self.assertTrue(all(tags_found.values()))
Esempio n. 22
0
 def test_005_three_with_tags_trailing (self):
     """ 3 -> 8, trailing bits """
     src_data = (0b101,) + (0b111,) * 4 + (0b001,)
     expected_data = (0b11111101, 0b11111111)
     k = 3
     l = 8
     src = blocks.vector_source_b(src_data, False, 1)
     repack = blocks.repack_bits_bb(k, l, self.tsb_key, True)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(src_data), self.tsb_key),
         repack,
         sink
     )
     self.tb.run ()
     self.assertEqual(len(sink.data()), 1)
     self.assertEqual(sink.data()[0], expected_data)
Esempio n. 23
0
 def test_004_three_with_tags (self):
     """ 8 -> 3 """
     src_data = [0b11111101, 0b11111111]
     expected_data = [0b101,] + [0b111,] * 4 + [0b001,]
     k = 8
     l = 3
     src = blocks.vector_source_b(src_data, False, 1)
     repack = blocks.repack_bits_bb(k, l, self.tsb_key)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_char, 1, len(src_data), self.tsb_key),
         repack,
         sink
     )
     self.tb.run ()
     self.assertEqual(len(sink.data()), 1)
     self.assertEqual(sink.data()[0], expected_data)
Esempio n. 24
0
 def test_003_crc_correct_lentag(self):
     tag_name = "length"
     pack_len = 8
     packets = list(range(pack_len*2))
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tag_name)
     tag1.value = pmt.from_long(pack_len)
     tag2 = gr.tag_t()
     tag2.offset = pack_len
     tag2.key = pmt.string_to_symbol(tag_name)
     tag2.value = pmt.from_long(pack_len)
     testtag1 = gr.tag_t()
     testtag1.offset = 1
     testtag1.key = pmt.string_to_symbol("tag1")
     testtag1.value = pmt.from_long(0)
     testtag2 = gr.tag_t()
     testtag2.offset = pack_len
     testtag2.key = pmt.string_to_symbol("tag2")
     testtag2.value = pmt.from_long(0)
     testtag3 = gr.tag_t()
     testtag3.offset = len(packets) - 1
     testtag3.key = pmt.string_to_symbol("tag3")
     testtag3.value = pmt.from_long(0)
     src = blocks.vector_source_b(packets, False, 1,
                                  (testtag1, testtag2, testtag3))
     crc = digital.crc32_bb(False, self.tsb_key)
     sink = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)
     self.tb.connect(src,
                     blocks.stream_to_tagged_stream(
                         gr.sizeof_char, 1, pack_len, self.tsb_key), crc,
                     sink)
     self.tb.run()
     self.assertEqual(len(sink.data()), 2)
     self.assertEqual(len(sink.data()[0]), (pack_len + 4))
     self.assertEqual(len(sink.data()[1]), (pack_len + 4))
     correct_offsets = {'tag1': 1, 'tag2': 12, 'tag3': 19}
     tags_found = {'tag1': False, 'tag2': False, 'tag3': False}
     for tag in sink.tags():
         key = pmt.symbol_to_string(tag.key)
         if key in list(correct_offsets.keys()):
             tags_found[key] = True
             self.assertEqual(correct_offsets[key], tag.offset)
     self.assertTrue(all(tags_found.values()))
Esempio n. 25
0
    def test_001_t (self):
        len_tag_key       = "packet_len"
        len_frame_tag_key = "frame_length"
        maxS              = 3
        ownID             = 2
        maxPad            = 1
        header_one        = [2,0,1,2,0,0]
        header_two        = [100,1,1,2,0,0] #too long
        header_three      = [1,2,1,3,0,0]  #wrong receiver 
        header_four       = [1,0,1,2,10,0] #too much padding 
        src_data          = header_one + header_two + header_three + header_four
        src_tags          = make_tags(len_tag_key, len_frame_tag_key)
        src               = blocks.vector_source_b(src_data, repeat = False, tags = src_tags)
        parser            = ownHeader.parse_header_bb(len_tag_key,len_frame_tag_key,  maxS, ownID, maxPad)
        dest              = blocks.tsb_vector_sink_b(1,len_tag_key)
        self.tb.connect(src,parser,dest)
        self.tb.run ()
        dest_data = dest.data()
        dest_tags = dest.tags()

        self.assertEqual(len(dest_data),4)
        self.assertEqual(dest_data, ((1,),(0,),(0,),(0,),))
        tags = [gr.tag_to_python(x) for x in dest_tags]
        self.assertEqual(len(tags),6)
        zero  = []
        one   = []
        two   = []
        three = []
        for tag in tags:
            if tag.offset ==0:
                zero.append(tag)
            elif tag.offset ==1:
                one.append(tag)
            elif tag.offset == 2:
                two.append(tag)
            else :
                three.append(tag)
        self.assertEqual(len(zero),6)
Esempio n. 26
0
    def test_001_t(self):
        input1 = (10, 0, 1, 2)
        #input1= [0, 0, 0, 0, 1, 0, 1, 0]
        #input2 = [ 0, 0, 0, 0, 0, 0, 0, 0]
        #input3 = [ 0, 0, 0, 0, 0, 0, 0, 1]
        #input4 = [0, 0, 0, 0, 0, 0, 1, 0]

        output1 = (245, 225, 28, 152)
        #output1 = [1, 1, 1, 1, 0, 1, 0, 1]
        #output2 = [1, 1, 1, 0, 0, 0, 0, 1]
        #output3 = [0, 0, 0, 1, 1, 1, 0, 0]
        #output4 = [1, 0, 0, 1, 1, 0, 0, 0]

        src = blocks.vector_source_b(input1)
        src_tagged = blocks.stream_to_tagged_stream(gr.sizeof_char, 1,
                                                    len(input1), self.tsb_key)
        pn9 = pn9_whitening(False)
        dst = blocks.tsb_vector_sink_b(tsb_key=self.tsb_key)

        self.tb.connect(src, src_tagged, pn9, dst)
        self.tb.run()

        self.assertEquals(dst.data()[0], output1)