def test_002_32bits (self):
     # 3 PDUs: |           |     |         |
     data   = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tagname)
     tag1.value = pmt.pmt_from_long(4)
     tag2 = gr.gr_tag_t()
     tag2.offset = 4
     tag2.key = pmt.pmt_string_to_symbol(tagname)
     tag2.value = pmt.pmt_from_long(2)
     tag3 = gr.gr_tag_t()
     tag3.offset = 6
     tag3.key = pmt.pmt_string_to_symbol(tagname)
     tag3.value = pmt.pmt_from_long(4)
     src = gr.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     header = digital.packet_headergenerator_bb(32, tagname)
     sink = gr.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)
Ejemplo n.º 2
0
 def test_with_tags_2s_rolloff(self):
     " With tags and a 2-sample rolloff "
     fft_len = 8
     cp_len = 2
     tag_name = "length"
     expected_result = (7.0/2,       8, 1, 2, 3, 4, 5, 6, 7, 8, # 1.0/2
                        7.0/2+1.0/2, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1.0/2)
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(2)
     tag2 = gr.gr_tag_t()
     tag2.offset = 1
     tag2.key = pmt.pmt_string_to_symbol("random_tag")
     tag2.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(range(1, fft_len+1) * 2, False, fft_len, (tag, tag2))
     cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, 2, tag_name)
     sink = gr.vector_sink_c()
     self.tb.connect(src, cp, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     tags = [gr.tag_to_python(x) for x in sink.tags()]
     tags = sorted([(x.offset, x.key, x.value) for x in tags])
     expected_tags = [
         (0, tag_name, len(expected_result)),
         (fft_len+cp_len, "random_tag", 42)
     ]
     self.assertEqual(tags, expected_tags)
 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.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tagname)
     tag1.value = pmt.pmt_from_long(4)
     tag2 = gr.gr_tag_t()
     tag2.offset = 4
     tag2.key = pmt.pmt_string_to_symbol(tagname)
     tag2.value = pmt.pmt_from_long(2)
     tag3 = gr.gr_tag_t()
     tag3.offset = 6
     tag3.key = pmt.pmt_string_to_symbol(tagname)
     tag3.value = pmt.pmt_from_long(4)
     src = gr.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.pmt_symbol_to_string(formatter_object.len_tag_key()), tagname)
     header = digital.packet_headergenerator_bb(
         formatter_object.formatter(), tagname)
     sink = gr.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_simple (self):
     """ Very simple functionality testing """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1,) * fft_len * n_syms
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1,) * fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     # Check data
     self.assertEqual(tx_data, sink.data())
     for tag in sink.tags():
         self.assertEqual(pmt.pmt_symbol_to_string(tag.key), len_tag_key)
         self.assertEqual(pmt.pmt_to_long(tag.value), n_syms)
 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.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tagname)
     tag1.value = pmt.pmt_from_long(4)
     tag2 = gr.gr_tag_t()
     tag2.offset = 4
     tag2.key = pmt.pmt_string_to_symbol(tagname)
     tag2.value = pmt.pmt_from_long(2)
     tag3 = gr.gr_tag_t()
     tag3.offset = 6
     tag3.key = pmt.pmt_string_to_symbol(tagname)
     tag3.value = pmt.pmt_from_long(4)
     src = gr.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 = gr.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)
Ejemplo n.º 6
0
 def test_005_packet_len_tag (self):
     """ Standard test """
     fft_len = 16
     tx_symbols = range(1, 16);
     tx_symbols = (0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,  0,
                   0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0,
                   0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0,  0)
     expected_result = tuple(range(1, 16))
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     tag2 = gr.gr_tag_t()
     tag2.offset = 0
     tag2.key = pmt.pmt_string_to_symbol("packet_len")
     tag2.value = pmt.pmt_from_long(len(expected_result))
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, tag2))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "packet_len", 0, False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), "packet_len")
     self.assertEqual(pmt.pmt_to_long(result_tag.value), len(expected_result))
Ejemplo n.º 7
0
 def test_002_with_offset (self):
     """ Standard test, carrier offset """
     fft_len = 16
     tx_symbols = range(1, 16);
     tx_symbols = (0, 0, 1,  1j,  2,  3, 0, 0, 0, 0, 0, 0, 4,  5,  2j, 6,
                   0, 0, 7,  8,  3j,  9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12,
                   0, 0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0,  0,  2j, 0)
     carr_offset = 1 # Compare this with tx_symbols from the previous test
     expected_result = tuple(range(1, 16)) + (0, 0, 0)
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, offsettag))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name, "", 0, False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 2)
     for tag in sink.tags():
         if pmt.pmt_symbol_to_string(tag.key) == tag_name:
             self.assertEqual(pmt.pmt_to_long(tag.value), n_syms * len(occupied_carriers[0]))
Ejemplo n.º 8
0
 def test_001b_simple_skip_nothing(self):
     """
     Same as before, but put a skip-header in there
     """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len, symbols_skipped=1)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1, ) * fft_len * n_syms
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1, ) * fft_len)
     src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run()
     # Check data
     self.assertEqual(tx_data, sink.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.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tagname)
     tag1.value = pmt.pmt_from_long(4)
     tag2 = gr.gr_tag_t()
     tag2.offset = 4
     tag2.key = pmt.pmt_string_to_symbol(tagname)
     tag2.value = pmt.pmt_from_long(2)
     tag3 = gr.gr_tag_t()
     tag3.offset = 6
     tag3.key = pmt.pmt_string_to_symbol(tagname)
     tag3.value = pmt.pmt_from_long(4)
     src = gr.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.pmt_symbol_to_string(formatter_object.len_tag_key()), tagname)
     header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname)
     sink = gr.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_003_12bits_formatter_object(self):
     # 3 PDUs: |           |     |         |
     data = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tagname)
     tag1.value = pmt.pmt_from_long(4)
     tag2 = gr.gr_tag_t()
     tag2.offset = 4
     tag2.key = pmt.pmt_string_to_symbol(tagname)
     tag2.value = pmt.pmt_from_long(2)
     tag3 = gr.gr_tag_t()
     tag3.offset = 6
     tag3.key = pmt.pmt_string_to_symbol(tagname)
     tag3.value = pmt.pmt_from_long(4)
     src = gr.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 = gr.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)
Ejemplo n.º 11
0
    def work(self, input_items, output_items):
        num_output_items = len(output_items[0])

        #put code here to fill the output items...

        #make a new tag on the middle element every time work is called
        count = self.nitems_written(0) + num_output_items/2
        key = pmt.pmt_string_to_symbol("example_key")
        value = pmt.pmt_string_to_symbol("example_value")
        self.add_item_tag(0, count, key, value)

        return num_output_items
Ejemplo n.º 12
0
    def work(self, input_items, output_items):
        num_output_items = len(output_items[0])

        #put code here to fill the output items...

        #make a new tag on the middle element every time work is called
        count = self.nitems_written(0) + num_output_items/2
        key = pmt.pmt_string_to_symbol("example_key")
        value = pmt.pmt_string_to_symbol("example_value")
        self.add_item_tag(0, count, key, value)

        return num_output_items
Ejemplo n.º 13
0
 def work(self, input_items, output_items):
     # post all the msgs and be done...
     for msg in self._msgs:
         self.post_msg(
             0,
             pmt.pmt_string_to_symbol("example_key"),
             pmt.pmt_string_to_symbol(msg),
         )
     #FIXME, wait for sink thread to get msgs
     #if we return -1 too quickly, everything kind of shuts down b4 the messages get there...
     import time
     time.sleep(.1)
     return -1
Ejemplo n.º 14
0
 def work(self, input_items, output_items):
     # post all the msgs and be done...
     for msg in self._msgs:
         self.post_msg(
             0,
             pmt.pmt_string_to_symbol("example_key"),
             pmt.pmt_string_to_symbol(msg),
         )
     #FIXME, wait for sink thread to get msgs
     #if we return -1 too quickly, everything kind of shuts down b4 the messages get there...
     import time
     time.sleep(.1)
     return -1
Ejemplo n.º 15
0
    def test_1(self):
        datas = (
            0, 1, 2,  5, 6,     10,          14, 15, 16,
            3, 4,     7, 8, 9,  11, 12, 13,  17
        )
        expected = tuple(range(18))

        tagname = "packet_length"
        len_tags_0 = (
            make_len_tag(0, tagname, 3),
            make_len_tag(3, tagname, 2),
            make_len_tag(5, tagname, 1),
            make_len_tag(6, tagname, 3)
        )
        len_tags_1 = (
            make_len_tag(0, tagname, 2),
            make_len_tag(2, tagname, 3),
            make_len_tag(5, tagname, 3),
            make_len_tag(8, tagname, 1)
        )
        test_tag_0 = gr.gr_tag_t()
        test_tag_0.key = pmt.pmt_string_to_symbol('spam')
        test_tag_0.offset = 4 # On the second '1'
        test_tag_0.value = pmt.to_pmt(42)
        test_tag_1 = gr.gr_tag_t()
        test_tag_1.key = pmt.pmt_string_to_symbol('eggs')
        test_tag_1.offset = 3 # On the first '3' of the 2nd stream
        test_tag_1.value = pmt.to_pmt(23)

        src0 = gr.vector_source_b(datas[0:9], False, 1, len_tags_0 + (test_tag_0,))
        src1 = gr.vector_source_b(datas[9:],  False, 1, len_tags_1 + (test_tag_1,))
        tagged_stream_mux = blocks.tagged_stream_mux(gr.sizeof_char, tagname)
        snk = gr.vector_sink_b()
        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()

        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 = [
                (0, 'packet_length', 5),
                (5, 'packet_length', 5),
                (6, 'spam', 42),
                (8, 'eggs', 23),
                (10, 'packet_length', 4),
                (14, 'packet_length', 4)
        ]
        self.assertEqual(tags, tags_expected)
 def test_002_simpledfe (self):
     """ Use the simple DFE equalizer. """
     fft_len = 8
     #           4   5  6  7   0  1  2   3
     tx_data = [-1, -1, 1, 2, -1, 3, 0, -1, # 0
                -1, -1, 0, 2, -1, 2, 0, -1, # 8
                -1, -1, 3, 0, -1, 1, 0, -1, # 16 (Pilot symbols)
                -1, -1, 1, 1, -1, 0, 2, -1] # 24
     cnst = digital.constellation_qpsk()
     tx_signal = [cnst.map_to_points_v(x)[0] if x != -1 else 0 for x in tx_data]
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((), (), (1, 2, 6, 7), ())
     pilot_symbols = (
             [], [], [cnst.map_to_points_v(x)[0] for x in (1, 0, 3, 0)], []
     )
     equalizer = digital.ofdm_equalizer_simpledfe(
         fft_len, cnst.base(), occupied_carriers, pilot_carriers, pilot_symbols, 0, 0.01
     )
     channel = [
         0, 0,  1,  1, 0,  1,  1, 0,
         0, 0,  1,  1, 0,  1,  1, 0, # These coefficients will be rotated slightly...
         0, 0, 1j, 1j, 0, 1j, 1j, 0, # Go crazy here!
         0, 0, 1j, 1j, 0, 1j, 1j, 0  # ...and again here.
     ]
     for idx in range(fft_len, 2*fft_len):
         channel[idx] = channel[idx-fft_len] * numpy.exp(1j * .1 * numpy.pi * (numpy.random.rand()-.5))
         idx2 = idx+2*fft_len
         channel[idx2] = channel[idx2] * numpy.exp(1j * 0 * numpy.pi * (numpy.random.rand()-.5))
     len_tag_key = "frame_len"
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(4)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, channel[:fft_len])
     src = gr.vector_source_c(numpy.multiply(tx_signal, channel), False, fft_len, (len_tag, chan_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key, True)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     rx_data = [cnst.decision_maker_v((x,)) if x != 0 else -1 for x in sink.data()]
     self.assertEqual(tx_data, rx_data)
     for tag in sink.tags():
         if pmt.pmt_symbol_to_string(tag.key) == len_tag_key:
             self.assertEqual(pmt.pmt_to_long(tag.value), 4)
         if pmt.pmt_symbol_to_string(tag.key) == "ofdm_sync_chan_taps":
             self.assertComplexTuplesAlmostEqual(list(pmt.pmt_c32vector_elements(tag.value)), channel[-fft_len:], places=1)
 def test_004_connect (self):
     """
     Advanced test:
     - Allocator -> IFFT -> Frequency offset -> FFT -> Serializer
     - FFT does shift (moves DC to middle)
     - Make sure input == output
     - Frequency offset is -2 carriers
     """
     fft_len = 8
     n_syms = 1
     carr_offset = -2
     freq_offset = 1.0 / fft_len * carr_offset # Normalized frequency
     occupied_carriers = ((-2, -1, 1, 2),)
     pilot_carriers = ((3,),(5,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = (1, 1, 1, 1)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_data))
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_data, False, 1, (tag, offsettag))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     tx_ifft = fft.fft_vcc(fft_len, False, (1.0/fft_len,)*fft_len)
     oscillator = gr.sig_source_c(1.0, gr.GR_COS_WAVE, freq_offset, 1.0/fft_len)
     mixer = gr.multiply_cc()
     rx_fft  = fft.fft_vcc(fft_len, True, (), True)
     serializer = digital.ofdm_serializer_vcc(
             alloc, "", 0, "ofdm_sync_carr_offset"
     )
     sink = gr.vector_sink_c()
     self.tb.connect(
             src, alloc, tx_ifft,
             gr.vector_to_stream(gr.sizeof_gr_complex, fft_len),
             (mixer, 0),
             gr.stream_to_vector(gr.sizeof_gr_complex, fft_len),
             rx_fft, serializer, sink
     )
     self.tb.connect(oscillator, (mixer, 1))
     self.tb.run ()
     self.assertComplexTuplesAlmostEqual(sink.data(), tx_data, places=5)
Ejemplo n.º 18
0
 def test_with_tags_2s_rolloff(self):
     " With tags and a 2-sample rolloff "
     fft_len = 8
     cp_len = 2
     tag_name = "length"
     expected_result = (
         7.0 / 2,
         8,
         1,
         2,
         3,
         4,
         5,
         6,
         7,
         8,  # 1.0/2
         7.0 / 2 + 1.0 / 2,
         8,
         1,
         2,
         3,
         4,
         5,
         6,
         7,
         8,
         1.0 / 2)
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(2)
     tag2 = gr.gr_tag_t()
     tag2.offset = 1
     tag2.key = pmt.pmt_string_to_symbol("random_tag")
     tag2.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(
         range(1, fft_len + 1) * 2, False, fft_len, (tag, tag2))
     cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, 2,
                                       tag_name)
     sink = gr.vector_sink_c()
     self.tb.connect(src, cp, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     tags = [gr.tag_to_python(x) for x in sink.tags()]
     tags = sorted([(x.offset, x.key, x.value) for x in tags])
     expected_tags = [(0, tag_name, len(expected_result)),
                      (fft_len + cp_len, "random_tag", 42)]
     self.assertEqual(tags, expected_tags)
 def test_001b_shifted (self):
     """ Same as before, but shifted, because that's the normal mode in OFDM Rx """
     fft_len = 16
     tx_symbols = (
         0, 0, 0, 0, 0,  0,  1,  2,    0,   3, 4,   5,  0, 0, 0, 0,
         0, 0, 0, 0, 6, 1j,  7,  8,    0,   9, 10, 1j, 11, 0, 0, 0,
         0, 0, 0, 0, 0, 12, 13, 14,    0,  15, 16, 17,  0, 0, 0, 0,
     )
     expected_result = tuple(range(18))
     occupied_carriers = ((13, 14, 15, 1, 2, 3), (-4, -2, -1, 1, 2, 4),)
     n_syms = len(tx_symbols)/fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag,))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(result_tag.value), n_syms * len(occupied_carriers[0]))
Ejemplo n.º 20
0
    def test_001_t (self):
        """
        First header: Packet length 4, packet num 0
        Second header: Packet 2, packet num 1
        Third header: Invalid (parity bit does not check) (would be len 4, num 2)
        """
        encoded_headers = (
            #   | Number of bytes                    | 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,  1, 0, 0, 0
        )
        packet_len_tagname = "packet_len"

        random_tag = gr.gr_tag_t()
        random_tag.offset = 5
        random_tag.key = pmt.pmt_string_to_symbol("foo")
        random_tag.value = pmt.pmt_from_long(42)
        src = gr.vector_source_b(encoded_headers, tags=(random_tag,))
        parser = digital.packet_headerparser_b(32, packet_len_tagname)
        sink = gr.message_debug()
        self.tb.connect(src, parser)
        self.tb.msg_connect(parser, "header_data", sink, "store")
        self.tb.start()
        time.sleep(1)
        self.tb.stop()
        self.tb.wait()
        self.assertEqual(sink.num_messages(), 3)
        msg1 = pmt.to_python(sink.get_message(0))
        msg2 = pmt.to_python(sink.get_message(1))
        msg3 = pmt.to_python(sink.get_message(2))
        self.assertEqual(msg1, {'packet_len': 4, 'packet_num': 0, 'foo': 42})
        self.assertEqual(msg2, {'packet_len': 2, 'packet_num': 1})
        self.assertEqual(msg3, False)
Ejemplo n.º 21
0
 def test_003_connect (self):
     """ Connect carrier_allocator to ofdm_serializer,
         make sure output==input """
     fft_len = 8
     n_syms = 10
     occupied_carriers = ((1, 2, 6, 7),)
     pilot_carriers = ((3,),(5,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = tuple([numpy.random.randint(0, 10) for x in range(4 * n_syms)])
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_data))
     src = gr.vector_source_c(tx_data, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     serializer = digital.ofdm_serializer_vcc(alloc)
     sink = gr.vector_sink_c()
     self.tb.connect(src, alloc, serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), tx_data)
 def test_002_t (self):
     """
     same, but using negative carrier indices
     """
     fft_len = 6
     tx_symbols = (1, 2, 3)
     pilot_symbols = ((1j,),)
     occupied_carriers = ((-1, 1, 2),)
     pilot_carriers = ((3,),)
     expected_result = (0, 2, 3, 1j, 0, 1)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_symbols))
     src = gr.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
Ejemplo n.º 23
0
 def test_001_simple(self):
     """ Standard test """
     fft_len = 16
     tx_symbols = (0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, 0, 7,
                   8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, 0, 13, 1j,
                   14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0, 0)
     expected_result = tuple(range(1, 16)) + (0, 0, 0)
     occupied_carriers = (
         (1, 3, 4, 11, 12, 14),
         (1, 2, 4, 11, 13, 14),
     )
     n_syms = len(tx_symbols) / fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, ))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers,
                                              tag_name, "", 0, "", False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 1)
     result_tag = sink.tags()[0]
     self.assertEqual(pmt.pmt_symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(result_tag.value),
                      n_syms * len(occupied_carriers[0]))
Ejemplo n.º 24
0
 def test_004_connect (self):
     """
     Advanced test:
     - Allocator -> IFFT -> Frequency offset -> FFT -> Serializer
     - FFT does shift (moves DC to middle)
     - Make sure input == output
     - Frequency offset is -2 carriers
     """
     fft_len = 8
     n_syms = 2
     carr_offset = -2
     freq_offset = 2 * numpy.pi * carr_offset / fft_len # If the sampling rate == 1
     occupied_carriers = ((1, 2, -2, -1),)
     pilot_carriers = ((3,),(5,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = tuple([numpy.random.randint(0, 10) for x in range(4 * n_syms)])
     #tx_data = (1,) * occupied_carriers[0] * n_syms
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_data))
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_data, False, 1, (tag, offsettag))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols,
                    tag_name)
     tx_ifft = fft.fft_vcc(fft_len, False, ())
     offset_sig = gr.sig_source_c(1.0, gr.GR_COS_WAVE, freq_offset, 1.0)
     mixer = gr.multiply_cc()
     rx_fft  = fft.fft_vcc(fft_len, True, (), True)
     serializer = digital.ofdm_serializer_vcc(alloc)
     sink = gr.vector_sink_c()
     self.tb.connect(
             src, alloc, tx_ifft,
             gr.vector_to_stream(gr.sizeof_gr_complex, fft_len),
             (mixer, 0),
             gr.stream_to_vector(gr.sizeof_gr_complex, fft_len),
             rx_fft, serializer, sink
     )
     self.tb.connect(offset_sig, (mixer, 1))
     self.tb.run ()
Ejemplo n.º 25
0
 def test_001c_carrier_offset_no_cp(self):
     """
     Same as before, but put a carrier offset in there
     """
     fft_len = 8
     cp_len = 0
     n_syms = 1
     carr_offset = 1
     occupied_carriers = ((-2, -1, 1, 2), )
     tx_data = (
         0,
         0,
         0,
         -1j,
         -1j,
         0,
         -1j,
         -1j,
     )
     # The rx'd signal is shifted
     rx_expected = (0, 0, 1, 1, 0, 1, 1, 0) * n_syms
     equalizer = digital.ofdm_equalizer_static(fft_len, occupied_carriers)
     len_tag_key = "frame_len"
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     # Note: this is shifted to the correct position!
     chan_tag.value = pmt.pmt_init_c32vector(
         fft_len, (0, 0, -1j, -1j, 0, -1j, -1j, 0))
     offset_tag = gr.gr_tag_t()
     offset_tag.offset = 0
     offset_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offset_tag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_data, False, fft_len,
                              (len_tag, chan_tag, offset_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len,
                                            len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run()
     # Check data
     self.assertComplexTuplesAlmostEqual(rx_expected, sink.data(), places=4)
Ejemplo n.º 26
0
    def work(self, input_items, output_items):
        while True:
            try: msg = self._msgq.delete_head()
            except: return -1
            print "msg_rx"

            msg = pmt.pmt_string_to_symbol(msg.to_string())
            self.message_port_pub(pmt.intern('out'),msg)
Ejemplo n.º 27
0
 def test_004_connect(self):
     """
     Advanced test:
     - Allocator -> IFFT -> Frequency offset -> FFT -> Serializer
     - FFT does shift (moves DC to middle)
     - Make sure input == output
     - Frequency offset is -2 carriers
     """
     fft_len = 8
     n_syms = 1
     carr_offset = -2
     freq_offset = 1.0 / fft_len * carr_offset  # Normalized frequency
     occupied_carriers = ((-2, -1, 1, 2), )
     pilot_carriers = ((3, ), (5, ))
     pilot_symbols = ((1j, ), (-1j, ))
     tx_data = (1, 1, 1, 1)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_data))
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_data, False, 1, (tag, offsettag))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers,
                                                pilot_carriers,
                                                pilot_symbols, tag_name)
     tx_ifft = fft.fft_vcc(fft_len, False, (1.0 / fft_len, ) * fft_len)
     oscillator = gr.sig_source_c(1.0, gr.GR_COS_WAVE, freq_offset,
                                  1.0 / fft_len)
     mixer = gr.multiply_cc()
     rx_fft = fft.fft_vcc(fft_len, True, (), True)
     serializer = digital.ofdm_serializer_vcc(alloc, "", 0,
                                              "ofdm_sync_carr_offset")
     sink = gr.vector_sink_c()
     self.tb.connect(src, alloc, tx_ifft,
                     gr.vector_to_stream(gr.sizeof_gr_complex,
                                         fft_len), (mixer, 0),
                     gr.stream_to_vector(gr.sizeof_gr_complex, fft_len),
                     rx_fft, serializer, sink)
     self.tb.connect(oscillator, (mixer, 1))
     self.tb.run()
     self.assertComplexTuplesAlmostEqual(sink.data(), tx_data, places=5)
Ejemplo n.º 28
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, 230, 166, 39, 8)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(data))
     testtag = gr.gr_tag_t()
     testtag.offset = len(data)-1
     testtag.key = pmt.pmt_string_to_symbol('tag1')
     testtag.value = pmt.pmt_from_long(0)
     src = gr.vector_source_b(data, False, 1, (tag, testtag))
     crc_check = digital.crc32_bb(True, tag_name)
     sink = gr.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.pmt_symbol_to_string(tag.key) == 'tag1'])
Ejemplo n.º 29
0
def make_lengthtags(lengths, offsets, tagname='length', vlen=1):
    tags = []
    assert (len(offsets) == len(lengths))
    for offset, length in zip(offsets, lengths):
        tag = gr.gr_tag_t()
        tag.offset = offset / vlen
        tag.key = pmt.pmt_string_to_symbol(tagname)
        tag.value = pmt.pmt_from_long(length / vlen)
        tags.append(tag)
    return tags
Ejemplo n.º 30
0
    def work(self, input_items, output_items):
        while True:
            try:
                msg = self._msgq.delete_head()
            except:
                return -1
            print "msg_rx"

            msg = pmt.pmt_string_to_symbol(msg.to_string())
            self.message_port_pub(pmt.intern('out'), msg)
 def test_001_simple (self):
     """ Very simple functionality testing:
     - static equalizer
     - init channel state with all ones
     - transmit all ones
     - make sure we rx all ones
     - Tag check: put in frame length tag and one other random tag,
                  make sure they're propagated
     """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1,) * fft_len * n_syms
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1,) * fft_len)
     random_tag = gr.gr_tag_t()
     random_tag.offset = 1
     random_tag.key = pmt.pmt_string_to_symbol("foo")
     random_tag.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag, random_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     # Check data
     self.assertEqual(tx_data, sink.data())
     # Check tags
     tag_dict = dict()
     for tag in sink.tags():
         ptag = gr.tag_to_python(tag)
         tag_dict[ptag.key] = ptag.value
     expected_dict = {
             'frame_len': n_syms,
             'foo': 42
     }
     self.assertEqual(tag_dict, expected_dict)
Ejemplo n.º 32
0
def make_lengthtags(lengths, offsets, tagname='length', vlen=1):
    tags = []
    assert(len(offsets) == len(lengths))
    for offset, length in zip(offsets, lengths):
        tag = gr.gr_tag_t()
        tag.offset = offset/vlen
        tag.key = pmt.pmt_string_to_symbol(tagname)
        tag.value = pmt.pmt_from_long(length/vlen)
        tags.append(tag)
    return tags
Ejemplo n.º 33
0
 def test_001_t (self):
     tag = gr.gr_tag_t()
     tag.key = pmt.pmt_string_to_symbol('key')
     tag.value = pmt.pmt_from_long(42)
     tag.offset = 0
     src = blocks.vector_source_f(range(20), False, 1, (tag,))
     gate = blocks.tag_gate(gr.sizeof_float, False)
     sink = blocks.vector_sink_f()
     self.tb.run ()
     self.assertEqual(len(sink.tags()), 0)
Ejemplo n.º 34
0
 def test_001_offset_2sym(self):
     """ Add a frequency offset, check if it's correctly detected.
     Also add some random tags and see if they come out at the correct
     position. """
     fft_len = 16
     carr_offset = -2
     sync_symbol1 = (0, 0, 0, 1, 0, 1, 0, -1, 0, 1, 0, -1, 0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     data_symbol = (0, 0, 0, 1, -1, 1, -1, 1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol("test_tag_1")
     tag1.value = pmt.pmt_from_long(23)
     tag2 = gr.gr_tag_t()
     tag2.offset = 2
     tag2.key = pmt.pmt_string_to_symbol("test_tag_2")
     tag2.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(tx_data, False, fft_len, (tag1, tag2))
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     detected_tags = {
         'ofdm_sync_carr_offset': False,
         'test_tag_1': False,
         'test_tag_2': False
     }
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'test_tag_1':
             self.assertEqual(tag.offset, 0)
         if pmt.pmt_symbol_to_string(tag.key) == 'test_tag_2':
             self.assertEqual(tag.offset, 0)
         detected_tags[pmt.pmt_symbol_to_string(tag.key)] = True
     self.assertTrue(all(detected_tags.values()))
Ejemplo n.º 35
0
 def test_001_offset_2sym (self):
     """ Add a frequency offset, check if it's correctly detected.
     Also add some random tags and see if they come out at the correct
     position. """
     fft_len = 16
     carr_offset = -2
     sync_symbol1 = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol("test_tag_1")
     tag1.value = pmt.pmt_from_long(23)
     tag2 = gr.gr_tag_t()
     tag2.offset = 2
     tag2.key = pmt.pmt_string_to_symbol("test_tag_2")
     tag2.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(tx_data, False, fft_len, (tag1, tag2))
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     detected_tags = {
             'ofdm_sync_carr_offset': False,
             'test_tag_1': False,
             'test_tag_2': False
     }
     for tag in tags:
         if pmt.pmt_symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.pmt_to_long(tag.value)
             self.assertEqual(pmt.pmt_to_long(tag.value), carr_offset)
         if pmt.pmt_symbol_to_string(tag.key) == 'test_tag_1':
             self.assertEqual(tag.offset, 0)
         if pmt.pmt_symbol_to_string(tag.key) == 'test_tag_2':
             self.assertEqual(tag.offset, 0)
         detected_tags[pmt.pmt_symbol_to_string(tag.key)] = True
     self.assertTrue(all(detected_tags.values()))
Ejemplo n.º 36
0
 def test_001_simple(self):
     """ Very simple functionality testing:
     - static equalizer
     - init channel state with all ones
     - transmit all ones
     - make sure we rx all ones
     - Tag check: put in frame length tag and one other random tag,
                  make sure they're propagated
     """
     fft_len = 8
     equalizer = digital.ofdm_equalizer_static(fft_len)
     n_syms = 3
     len_tag_key = "frame_len"
     tx_data = (1, ) * fft_len * n_syms
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, (1, ) * fft_len)
     random_tag = gr.gr_tag_t()
     random_tag.offset = 1
     random_tag.key = pmt.pmt_string_to_symbol("foo")
     random_tag.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(tx_data, False, fft_len,
                              (len_tag, chan_tag, random_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0,
                                            len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run()
     # Check data
     self.assertEqual(tx_data, sink.data())
     # Check tags
     tag_dict = dict()
     for tag in sink.tags():
         ptag = gr.tag_to_python(tag)
         tag_dict[ptag.key] = ptag.value
     expected_dict = {'frame_len': n_syms, 'foo': 42}
     self.assertEqual(tag_dict, expected_dict)
Ejemplo n.º 37
0
def make_len_tags(tupl, key):
    tags = []
    tag = gr.gr_tag_t()
    tag.key = pmt.pmt_string_to_symbol(key)
    n_read = 0
    for element in tupl:
        tag.offset = n_read
        n_read += len(element)
        tag.value = pmt.to_pmt(len(element))
        tags.append(tag)
    return tags
Ejemplo n.º 38
0
def make_len_tags(tupl, key):
    tags = []
    tag = gr.gr_tag_t()
    tag.key = pmt.pmt_string_to_symbol(key)
    n_read = 0
    for element in tupl:
        tag.offset = n_read
        n_read += len(element)
        tag.value = pmt.to_pmt(len(element))
        tags.append(tag)
    return tags
 def test_001_offset_2sym (self):
     """ Add a frequency offset, check if it's correctly detected.
     Also add some random tags and see if they come out at the correct
     position. """
     fft_len = 16
     carr_offset = -2
     sync_symbol1 = (0, 0, 0, 1,  0, 1,  0, -1, 0, 1,  0, -1,  0, 1, 0, 0)
     sync_symbol2 = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     data_symbol  = (0, 0, 0, 1, -1, 1, -1,  1, 0, 1, -1, -1, -1, 1, 0, 0)
     tx_data = shift_tuple(sync_symbol1, carr_offset) + \
               shift_tuple(sync_symbol2, carr_offset) + \
               shift_tuple(data_symbol, carr_offset)
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol("test_tag_1")
     tag1.value = pmt.pmt_from_long(23)
     tag2 = gr.gr_tag_t()
     tag2.offset = 2
     tag2.key = pmt.pmt_string_to_symbol("test_tag_2")
     tag2.value = pmt.pmt_from_long(42)
     src = gr.vector_source_c(tx_data, False, fft_len, (tag1, tag2))
     chanest = digital.ofdm_chanest_vcvc(sync_symbol1, sync_symbol2, 1)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, chanest, sink)
     self.tb.run()
     self.assertEqual(shift_tuple(sink.data(), -carr_offset), data_symbol)
     tags = sink.tags()
     ptags = {}
     for tag in tags:
         ptag = gr.tag_to_python(tag)
         ptags[ptag.key] = (ptag.value, ptag.offset)
         if ptag.key == 'ofdm_sync_chan_taps':
             ptags[ptag.key] = (None, ptag.offset)
     expected_tags = {
             'ofdm_sync_carr_offset': (-2, 0),
             'ofdm_sync_chan_taps': (None, 0),
             'test_tag_1': (23, 0),
             'test_tag_2': (42, 0),
     }
     self.assertEqual(ptags, expected_tags)
Ejemplo n.º 40
0
 def test_003_crc_correct_lentag (self):
     tag_name = "length"
     pack_len = 8
     packets = range(pack_len*2)
     tag1 = gr.gr_tag_t()
     tag1.offset = 0
     tag1.key = pmt.pmt_string_to_symbol(tag_name)
     tag1.value = pmt.pmt_from_long(pack_len)
     tag2 = gr.gr_tag_t()
     tag2.offset = pack_len
     tag2.key = pmt.pmt_string_to_symbol(tag_name)
     tag2.value = pmt.pmt_from_long(pack_len)
     testtag1 = gr.gr_tag_t()
     testtag1.offset = 1
     testtag1.key = pmt.pmt_string_to_symbol("tag1")
     testtag1.value = pmt.pmt_from_long(0)
     testtag2 = gr.gr_tag_t()
     testtag2.offset = pack_len
     testtag2.key = pmt.pmt_string_to_symbol("tag2")
     testtag2.value = pmt.pmt_from_long(0)
     testtag3 = gr.gr_tag_t()
     testtag3.offset = len(packets)-1
     testtag3.key = pmt.pmt_string_to_symbol("tag3")
     testtag3.value = pmt.pmt_from_long(0)
     src = gr.vector_source_b(packets, False, 1, (tag1, tag2, testtag1, testtag2, testtag3))
     crc = digital.crc32_bb(False, tag_name)
     sink = gr.vector_sink_b()
     self.tb.connect(src, crc, sink)
     self.tb.run()
     self.assertEqual(len(sink.data()), 2*(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.pmt_symbol_to_string(tag.key)
         if key in correct_offsets.keys():
             tags_found[key] = True
             self.assertEqual(correct_offsets[key], tag.offset)
         if key == tag_name:
             self.assertTrue(tag.offset == 0 or tag.offset == pack_len+4)
     self.assertTrue(all(tags_found.values()))
Ejemplo n.º 41
0
def packets_to_vectors(packets, lengthtagname, vlen=1):
    tags = []
    data = []
    offset = 0
    for packet in packets:
        data.extend(packet)
        tag = gr.gr_tag_t()
        tag.offset = offset / vlen
        tag.key = pmt.pmt_string_to_symbol(lengthtagname)
        tag.value = pmt.pmt_from_long(len(packet) / vlen)
        tags.append(tag)
        offset = offset + len(packet)
    return data, tags
Ejemplo n.º 42
0
def packets_to_vectors(packets, lengthtagname, vlen=1):
    tags = []
    data = []
    offset = 0
    for packet in packets:
        data.extend(packet)
        tag = gr.gr_tag_t()
        tag.offset = offset/vlen
        tag.key = pmt.pmt_string_to_symbol(lengthtagname)
        tag.value = pmt.pmt_from_long(len(packet)/vlen)
        tags.append(tag)
        offset = offset + len(packet)
    return data, tags
 def test_001c_carrier_offset_cp (self):
     """
     Same as before, but put a carrier offset in there and a CP
     """
     fft_len = 8
     cp_len = 2
     n_syms = 3
     # cp_len/fft_len == 1/4, therefore, the phase is rotated by
     # carr_offset * \pi/2 in every symbol
     occupied_carriers = ((-2, -1, 1, 2),)
     carr_offset = -1
     tx_data = (
             0,-1j,-1j, 0,-1j,-1j, 0, 0,
             0, -1, -1, 0, -1, -1, 0, 0,
             0, 1j, 1j, 0, 1j, 1j, 0, 0,
     )
     # Rx'd signal is corrected
     rx_expected = (0, 0, 1, 1, 0, 1, 1, 0) * n_syms
     equalizer = digital.ofdm_equalizer_static(fft_len, occupied_carriers)
     len_tag_key = "frame_len"
     len_tag = gr.gr_tag_t()
     len_tag.offset = 0
     len_tag.key = pmt.pmt_string_to_symbol(len_tag_key)
     len_tag.value = pmt.pmt_from_long(n_syms)
     chan_tag = gr.gr_tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.pmt_init_c32vector(fft_len, (0, 0, 1, 1, 0, 1, 1, 0))
     offset_tag = gr.gr_tag_t()
     offset_tag.offset = 0
     offset_tag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offset_tag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_data, False, fft_len, (len_tag, chan_tag, offset_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len, len_tag_key)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, eq, sink)
     self.tb.run ()
     # Check data
     self.assertComplexTuplesAlmostEqual(rx_expected, sink.data(), places=4)
Ejemplo n.º 44
0
 def work(self, input_items, output_items):
     while True:
         try: msg = self._msgq.delete_head()
         except: return -1
         ok, payload = packet_utils.unmake_packet(msg.to_string(), int(msg.arg1()))
         if ok:
             payload = numpy.fromstring(payload, numpy.uint8)
             try: blob = self._mgr.acquire(True) #block
             except: return -1
             pmt.pmt_blob_resize(blob, len(payload))
             pmt.pmt_blob_rw_data(blob)[:] = payload
             self.post_msg(0, pmt.pmt_string_to_symbol("ok"), blob)
         else:
             a = 0
Ejemplo n.º 45
0
    def work(self, input_items, output_items):
        self.state = SEARCH_EOB_IN

        in0 = input_items[0]
        out = output_items[0]

        out[:] = in0[:]

        nread = self.nitems_read(0)  #number of items read on port 0
        ninput_items = len(input_items[0])

        #read all tags associated with port 0 for items in this work function
        tags = self.get_tags_in_range(0, nread, nread + ninput_items)

        num_items = min(len(input_items[0]), len(output_items[0]))

        if (len(input_items[0]) > len(output_items[0])):
            print "Burst Gate: Output items small. Might be bad."

        source = pmt.pmt_string_to_symbol("")

        for tag in tags:
            if pmt.pmt_symbol_to_string(tag.key) == "tx_eob":
                self.state = FOUND_EOB_IN
            else:
                self.add_item_tag(0, tag.offset, tag.key, tag.value, source)

        if self.state == FOUND_EOB_IN:
            item_index = num_items  #which output item gets the tag?
            offset = self.nitems_written(0) + item_index
            key = pmt.pmt_string_to_symbol("tx_eob")

            value = pmt.pmt_string_to_symbol("")
            source = pmt.pmt_string_to_symbol("")
            self.add_item_tag(0, offset - 1, key, pmt.PMT_T, source)

        return len(out)
Ejemplo n.º 46
0
 def test_002_with_offset(self):
     """ Standard test, carrier offset """
     fft_len = 16
     tx_symbols = range(1, 16)
     tx_symbols = (0, 0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, 0,
                   7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, 0, 13,
                   1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0)
     carr_offset = 1  # Compare this with tx_symbols from the previous test
     expected_result = tuple(range(1, 16)) + (0, 0, 0)
     occupied_carriers = (
         (1, 3, 4, 11, 12, 14),
         (1, 2, 4, 11, 13, 14),
     )
     n_syms = len(tx_symbols) / fft_len
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(n_syms)
     offsettag = gr.gr_tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.pmt_string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.pmt_from_long(carr_offset)
     src = gr.vector_source_c(tx_symbols, False, fft_len, (tag, offsettag))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers,
                                              tag_name, "", 0,
                                              "ofdm_sync_carr_offset",
                                              False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, serializer, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
     self.assertEqual(len(sink.tags()), 2)
     for tag in sink.tags():
         if pmt.pmt_symbol_to_string(tag.key) == tag_name:
             self.assertEqual(pmt.pmt_to_long(tag.value),
                              n_syms * len(occupied_carriers[0]))
Ejemplo n.º 47
0
    def test_1(self):
        datas = (0, 1, 2, 5, 6, 10, 14, 15, 16, 3, 4, 7, 8, 9, 11, 12, 13, 17)
        expected = tuple(range(18))

        tagname = "packet_length"
        len_tags_0 = (make_len_tag(0, tagname, 3), make_len_tag(3, tagname, 2),
                      make_len_tag(5, tagname, 1), make_len_tag(6, tagname, 3))
        len_tags_1 = (make_len_tag(0, tagname, 2), make_len_tag(2, tagname, 3),
                      make_len_tag(5, tagname, 3), make_len_tag(8, tagname, 1))
        test_tag_0 = gr.gr_tag_t()
        test_tag_0.key = pmt.pmt_string_to_symbol('spam')
        test_tag_0.offset = 4  # On the second '1'
        test_tag_0.value = pmt.to_pmt(42)
        test_tag_1 = gr.gr_tag_t()
        test_tag_1.key = pmt.pmt_string_to_symbol('eggs')
        test_tag_1.offset = 3  # On the first '3' of the 2nd stream
        test_tag_1.value = pmt.to_pmt(23)

        src0 = gr.vector_source_b(datas[0:9], False, 1,
                                  len_tags_0 + (test_tag_0, ))
        src1 = gr.vector_source_b(datas[9:], False, 1,
                                  len_tags_1 + (test_tag_1, ))
        tagged_stream_mux = blocks.tagged_stream_mux(gr.sizeof_char, tagname)
        snk = gr.vector_sink_b()
        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()

        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 = [(0, 'packet_length', 5), (5, 'packet_length', 5),
                         (6, 'spam', 42), (8, 'eggs', 23),
                         (10, 'packet_length', 4), (14, 'packet_length', 4)]
        self.assertEqual(tags, tags_expected)
Ejemplo n.º 48
0
    def work(self, input_items, output_items):
        self.state = SEARCH_EOB_IN

        in0 = input_items[0]
        out = output_items[0]

        out[:] = in0[:]

        nread = self.nitems_read(0) #number of items read on port 0
        ninput_items = len(input_items[0])

        #read all tags associated with port 0 for items in this work function
        tags = self.get_tags_in_range(0, nread, nread+ninput_items)

        num_items = min(len(input_items[0]), len(output_items[0]))

        if (len(input_items[0]) > len(output_items[0])):
            print "Burst Gate: Output items small. Might be bad."

        source = pmt.pmt_string_to_symbol("")

        for tag in tags:
            if pmt.pmt_symbol_to_string(tag.key) == "tx_eob":
                self.state = FOUND_EOB_IN
            else:
                self.add_item_tag(0, tag.offset, tag.key, tag.value, source)

        if self.state == FOUND_EOB_IN:
            item_index = num_items #which output item gets the tag?
            offset = self.nitems_written(0) + item_index
            key = pmt.pmt_string_to_symbol("tx_eob")

            value = pmt.pmt_string_to_symbol("")
            source = pmt.pmt_string_to_symbol("")
            self.add_item_tag(0, offset - 1, key, pmt.PMT_T, source)

        return len(out)
Ejemplo n.º 49
0
 def test_001_crc_len (self):
     """ Make sure the output of a CRC set is 4 bytes longer than the input. """
     data = range(16)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(data))
     src = gr.vector_source_b(data, False, 1, (tag,))
     crc = digital.crc32_bb(False, tag_name)
     sink = gr.vector_sink_b()
     self.tb.connect(src, 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()))
Ejemplo n.º 50
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)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(data))
     src = gr.vector_source_b(data, False, 1, (tag,))
     crc = digital.crc32_bb(False, tag_name)
     crc_check = digital.crc32_bb(True, tag_name)
     corruptor = gr.add_const_bb(1)
     sink = gr.vector_sink_b()
     self.tb.connect(src, crc, corruptor, crc_check, sink)
     self.tb.run()
     # crc_check will drop invalid packets
     self.assertEqual(len(sink.data()), 0)
Ejemplo n.º 51
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)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(data))
     src = gr.vector_source_b(data, False, 1, (tag,))
     crc = digital.crc32_bb(False, tag_name)
     crc_check = digital.crc32_bb(True, tag_name)
     sink = gr.vector_sink_b()
     self.tb.connect(src, crc, crc_check, sink)
     self.tb.run()
     # Check that the packets after crc_check are the same as input.
     self.assertEqual(data, sink.data())
 def test_002_t(self):
     """
     same, but using negative carrier indices
     """
     fft_len = 6
     tx_symbols = (1, 2, 3)
     pilot_symbols = ((1j, ), )
     occupied_carriers = ((-1, 1, 2), )
     pilot_carriers = ((3, ), )
     expected_result = (0, 2, 3, 1j, 0, 1)
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_symbols))
     src = gr.vector_source_c(tx_symbols, False, 1, (tag, ))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers,
                                                pilot_carriers,
                                                pilot_symbols, tag_name)
     sink = gr.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run()
     self.assertEqual(sink.data(), expected_result)
Ejemplo n.º 53
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
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(src_data))
     src = gr.vector_source_b(src_data, False, 1, (tag,))
     repack = blocks.repack_bits_bb(k, l, tag_name, True)
     sink = gr.vector_sink_b()
     self.tb.connect(src, repack, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_data)
     try:
         out_tag = sink.tags()[0]
     except:
         self.assertFail()
     self.assertEqual(out_tag.offset, 0)
     self.assertEqual(pmt.pmt_symbol_to_string(out_tag.key), tag_name)
     self.assertEqual(pmt.pmt_to_long(out_tag.value), len(expected_data))
Ejemplo n.º 54
0
 def test_003_connect(self):
     """ Connect carrier_allocator to ofdm_serializer,
         make sure output==input """
     fft_len = 8
     n_syms = 10
     occupied_carriers = ((1, 2, 6, 7), )
     pilot_carriers = ((3, ), (5, ))
     pilot_symbols = ((1j, ), (-1j, ))
     tx_data = tuple(
         [numpy.random.randint(0, 10) for x in range(4 * n_syms)])
     tag_name = "len"
     tag = gr.gr_tag_t()
     tag.offset = 0
     tag.key = pmt.pmt_string_to_symbol(tag_name)
     tag.value = pmt.pmt_from_long(len(tx_data))
     src = gr.vector_source_c(tx_data, False, 1, (tag, ))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len, occupied_carriers,
                                                pilot_carriers,
                                                pilot_symbols, tag_name)
     serializer = digital.ofdm_serializer_vcc(alloc, "", 0, "", False)
     sink = gr.vector_sink_c()
     self.tb.connect(src, alloc, serializer, sink)
     self.tb.run()
     self.assertEqual(sink.data(), tx_data)
Ejemplo n.º 55
0
def make_len_tag(offset, key, value):
    tag = gr.gr_tag_t()
    tag.offset = offset
    tag.key = pmt.pmt_string_to_symbol(key)
    tag.value = pmt.to_pmt(value)
    return tag