示例#1
0
    def test_003(self):
        offsets = (6, 3, 8)
        key = pmt.string_to_symbol('key')
        srcid = pmt.string_to_symbol('qa_tag_utils')
        tags = []

        for k in offsets:
            t = gr.tag_t()
            t.offset = k
            t.key = key
            t.value = pmt.from_long(k)
            t.srcid = srcid
            tags.append(t)

        for k, t in zip(sorted(offsets),
                        sorted(tags, key=gr.tag_t_offset_compare_key())):
            self.assertEqual(t.offset, k)
            self.assertTrue(pmt.equal(t.key, key))
            self.assertTrue(pmt.equal(t.value, pmt.from_long(k)))
            self.assertTrue(pmt.equal(t.srcid, srcid))

        tmin = min(tags, key=gr.tag_t_offset_compare_key())
        self.assertEqual(tmin.offset, min(offsets))
        self.assertTrue(pmt.equal(tmin.key, key))
        self.assertTrue(pmt.equal(tmin.value, pmt.from_long(min(offsets))))
        self.assertTrue(pmt.equal(tmin.srcid, srcid))

        tmax = max(tags, key=gr.tag_t_offset_compare_key())
        self.assertEqual(tmax.offset, max(offsets))
        self.assertTrue(pmt.equal(tmax.key, key))
        self.assertTrue(pmt.equal(tmax.value, pmt.from_long(max(offsets))))
        self.assertTrue(pmt.equal(tmax.srcid, srcid))
示例#2
0
 def start(self):
     self.F = open(self.filename, 'rb')
     self.F.seek(0, os.SEEK_END)
     (s,l) = (0,self.F.tell()/self.itemsize)
     self.message_port_pub(pmt.intern("file_range"), 
         pmt.cons(pmt.from_long(s),pmt.from_long(l)))
     return True
 def test_003_12bits_formatter_object (self):
     # 3 PDUs: |           |     |         |
     data   = (1, 2, 3, 4, 1, 2, 1, 2, 3, 4)
     tagname = "packet_len"
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol(tagname)
     tag1.value = pmt.from_long(4)
     tag2 = gr.tag_t()
     tag2.offset = 4
     tag2.key = pmt.string_to_symbol(tagname)
     tag2.value = pmt.from_long(2)
     tag3 = gr.tag_t()
     tag3.offset = 6
     tag3.key = pmt.string_to_symbol(tagname)
     tag3.value = pmt.from_long(4)
     src = blocks.vector_source_b(data, False, 1, (tag1, tag2, tag3))
     formatter_object = digital.packet_header_default(12, tagname)
     header = digital.packet_headergenerator_bb(formatter_object.formatter(), tagname)
     sink = blocks.vector_sink_b()
     self.tb.connect(src, header, sink)
     self.tb.run()
     expected_data = (
         0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
     )
     self.assertEqual(sink.data(), expected_data)
 def test_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.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(n_syms)
     tag2 = gr.tag_t()
     tag2.offset = 0
     tag2.key = pmt.string_to_symbol("packet_len")
     tag2.value = pmt.from_long(len(expected_result))
     src = blocks.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 = blocks.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.symbol_to_string(result_tag.key), "packet_len")
     self.assertEqual(pmt.to_long(result_tag.value), len(expected_result))
 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)
示例#7
0
文件: qa_pdu.py 项目: Appiah/gnuradio
 def test_002_tags_plus_data(self):
     packet_len = 16
     src_data = range(packet_len)
     tag1 = gr.tag_t()
     tag1.offset = 0
     tag1.key = pmt.string_to_symbol('spam')
     tag1.value = pmt.from_long(23)
     tag2 = gr.tag_t()
     tag2.offset = 10 # Must be < packet_len
     tag2.key = pmt.string_to_symbol('eggs')
     tag2.value = pmt.from_long(42)
     src = blocks.vector_source_f(src_data, tags=(tag1, tag2))
     s2ts = blocks.stream_to_tagged_stream(gr.sizeof_float, vlen=1, packet_len=packet_len, len_tag_key="packet_len")
     ts2pdu = blocks.tagged_stream_to_pdu(blocks.float_t, "packet_len")
     dbg = blocks.message_debug()
     self.tb.connect(src, s2ts, ts2pdu)
     self.tb.msg_connect(ts2pdu, "pdus", dbg, "store")
     self.tb.start()
     while dbg.num_messages() < 1:
         time.sleep(0.1)
     self.tb.stop()
     self.tb.wait()
     result_msg = dbg.get_message(0)
     metadata = pmt.to_python(pmt.car(result_msg))
     vector   = pmt.f32vector_elements(pmt.cdr(result_msg))
     self.assertEqual(metadata, {'eggs': 42, 'spam': 23})
     self.assertFloatTuplesAlmostEqual(tuple(vector), src_data)
 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.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(2)
     tag2 = gr.tag_t()
     tag2.offset = 1
     tag2.key = pmt.string_to_symbol("random_tag")
     tag2.value = pmt.from_long(42)
     src = blocks.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 = blocks.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)
示例#9
0
 def int_list_to_pmt(self, items):
     if len(items) == 0:
         return pmt.from_bool(pmt.PMT_F)
     else:
         pmtl = pmt.list1(pmt.from_long(items[0]))
         for i in range(len(items) - 1):
             pmtl = pmt.list_add(pmtl, pmt.from_long(items[i + 1]))
         return pmtl
示例#10
0
	def work(self, input_items, output_items):
		out = output_items[0]
		self.add_item_tag(0, self.nitems_written(0), pmt.intern("image_width"), pmt.from_long(self.image_width))
		self.add_item_tag(0, self.nitems_written(0), pmt.intern("line_num"), pmt.from_long(self.line_num))
		out[:self.image_width] = self.image_data[self.image_width*self.line_num: self.image_width*(1+self.line_num)]

		self.line_num += 1
		if self.line_num >= self.image_height:
			self.line_num = 0
		return self.image_width
 def test_003_t (self):
     """
     more advanced:
     - 6 symbols per carrier
     - 2 pilots per carrier
     - have enough data for nearly 3 OFDM symbols
     - send that twice
     - add some random tags
     - don't shift
     """
     tx_symbols = list(range(1, 16)); # 15 symbols
     pilot_symbols = ((1j, 2j), (3j, 4j))
     occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),)
     pilot_carriers = ((2, 13), (3, 12))
     expected_result = (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)
     fft_len = 16
     testtag1 = gr.tag_t()
     testtag1.offset = 0
     testtag1.key = pmt.string_to_symbol('tag1')
     testtag1.value = pmt.from_long(0)
     testtag2 = gr.tag_t()
     testtag2.offset = 7 # On the 2nd OFDM symbol
     testtag2.key = pmt.string_to_symbol('tag2')
     testtag2.value = pmt.from_long(0)
     testtag3 = gr.tag_t()
     testtag3.offset = len(tx_symbols)+1 # First OFDM symbol of packet 2
     testtag3.key = pmt.string_to_symbol('tag3')
     testtag3.value = pmt.from_long(0)
     testtag4 = gr.tag_t()
     testtag4.offset = 2*len(tx_symbols)-1 # Last OFDM symbol of packet 2
     testtag4.key = pmt.string_to_symbol('tag4')
     testtag4.value = pmt.from_long(0)
     src = blocks.vector_source_c(tx_symbols * 2, False, 1, (testtag1, testtag2, testtag3, testtag4))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, (),
                    self.tsb_key,
                    False)
     sink = blocks.tsb_vector_sink_c(fft_len)
     self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data()[0], expected_result)
     tags_found = {'tag1': False, 'tag2': False, 'tag3': False, 'tag4': False}
     correct_offsets = {'tag1': 0, 'tag2': 1, 'tag3': 3, 'tag4': 5}
     for tag in sink.tags():
         key = pmt.symbol_to_string(tag.key)
         if key in list(tags_found.keys()):
             tags_found[key] = True
             self.assertEqual(correct_offsets[key], tag.offset)
     self.assertTrue(all(tags_found.values()))
示例#12
0
 def test_003_t (self):
     """
     Like test 1, but twice, plus one fail
     """
     n_zeros = 5
     header = (1, 2, 3)
     header_fail = (-1, -2, -4) # Contents don't really matter
     payload1 = tuple(range(5, 20))
     payload2 = (42,)
     data_signal = (0,) * n_zeros + header + payload1
     trigger_signal = [0,] * len(data_signal) * 2
     trigger_signal[n_zeros] = 1
     trigger_signal[len(data_signal)] = 1
     trigger_signal[len(data_signal)+len(header_fail)+n_zeros] = 1
     tx_signal = data_signal + header_fail + (0,) * n_zeros + header + payload2 + (0,) * 1000
     data_src = blocks.vector_source_f(tx_signal, False)
     trigger_src = blocks.vector_source_b(trigger_signal, False)
     hpd = digital.header_payload_demux(
         len(header), 1, 0, "frame_len", "detect", False, gr.sizeof_float
     )
     self.assertEqual(pmt.length(hpd.message_ports_in()), 1)
     header_sink = blocks.vector_sink_f()
     payload_sink = blocks.vector_sink_f()
     self.tb.connect(data_src,    (hpd, 0))
     self.tb.connect(trigger_src, (hpd, 1))
     self.tb.connect((hpd, 0), header_sink)
     self.tb.connect((hpd, 1), payload_sink)
     self.tb.start()
     time.sleep(.2) # Need this, otherwise, the next message is ignored
     hpd.to_basic_block()._post(
             pmt.intern('header_data'),
             pmt.from_long(len(payload1))
     )
     while len(payload_sink.data()) < len(payload1):
         time.sleep(.2)
     hpd.to_basic_block()._post(
             pmt.intern('header_data'),
             pmt.PMT_F
     )
     # This next command is a bit of a showstopper, but there's no condition to check upon
     # to see if the previous msg handling is finished
     time.sleep(.7)
     hpd.to_basic_block()._post(
             pmt.intern('header_data'),
             pmt.from_long(len(payload2))
     )
     while len(payload_sink.data()) < len(payload1) + len(payload2):
         time.sleep(.2)
     self.tb.stop()
     self.tb.wait()
     self.assertEqual(header_sink.data(),  header + header_fail + header)
     self.assertEqual(payload_sink.data(), payload1 + payload2)
 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,),(3,))
     pilot_symbols = ((1j,),(-1j,))
     tx_data = (1, 2, 3, 4)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_data))
     offsettag = gr.tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.from_long(carr_offset)
     src = blocks.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, True)
     oscillator = analog.sig_source_c(1.0, analog.GR_COS_WAVE, freq_offset, 1.0/fft_len)
     mixer = blocks.multiply_cc()
     rx_fft  = fft.fft_vcc(fft_len, True, (), True)
     sink2 = blocks.vector_sink_c(fft_len)
     self.tb.connect(rx_fft, sink2)
     serializer = digital.ofdm_serializer_vcc(
             alloc, "", 0, "ofdm_sync_carr_offset", True
     )
     sink = blocks.vector_sink_c()
     self.tb.connect(
             src, alloc, tx_ifft,
             blocks.vector_to_stream(gr.sizeof_gr_complex, fft_len),
             (mixer, 0),
             blocks.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()[-len(occupied_carriers[0]):], tx_data, places=4)
示例#14
0
文件: qa_pmt.py 项目: dl1ksv/gnuradio
 def test19(self):
     max_key = pmt.intern("MAX")
     _max = pmt.from_long(self.MAXINT32)
     min_key = pmt.intern("MIN")
     _min = pmt.from_long(self.MININT32)
     d = pmt.make_dict()
     d = pmt.dict_add(d, max_key, _max)
     d = pmt.dict_add(d, min_key, _min)
     s = pmt.serialize_str(d)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(d, deser))
     p_dict = pmt.to_python(deser)
     self.assertEqual(self.MAXINT32, p_dict["MAX"])
     self.assertEqual(self.MININT32, p_dict["MIN"])
示例#15
0
    def work(self, input_items, output_items):
        num_output_items = len(output_items[0])

        output_items[0][:] = 1.0+0j

        count = 0
        key = pmt.string_to_symbol("pa_ramp")
        value = pmt.from_long(1)    # send enable
        self.add_item_tag(0, count, key, value)

        count = self.rd_at
        value = pmt.from_long(0)    # send disable
        self.add_item_tag(0, count, key, value)

        return num_output_items
 def test_001_t (self):
     """
     pretty simple (the carrier allocation is not a practical OFDM configuration!)
     """
     fft_len = 6
     tx_symbols = (1, 2, 3)
     #             ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0
     pilot_symbols = ((1j,),)
     occupied_carriers = ((0, 1, 2),)
     pilot_carriers = ((3,),)
     sync_word = (range(fft_len),)
     expected_result = tuple(sync_word[0] + [1j, 0, 0, 1, 2, 3])
     #                                                 ^ DC carrier
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.vector_source_c(tx_symbols, False, 1, (tag,))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                    occupied_carriers,
                    pilot_carriers,
                    pilot_symbols, sync_word,
                    tag_name)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
示例#17
0
 def handle_msg(self, msg):
     if pmt.dict_has_key(msg, pmt.intern(self.len_tag_key)):
         packet_len = pmt.to_python(msg)[self.len_tag_key]
         msg = pmt.dict_delete(msg, pmt.intern(self.len_tag_key))
         msg = pmt.dict_add(msg, pmt.intern(self.len_tag_key), pmt.from_long(packet_len * 8))
         
     self.message_port_pub(self.msg_buf_out, msg)
示例#18
0
def generate_tag(tag_key, srcid, value, offset):
    tag = gr.tag_t()
    tag.key = pmt.string_to_symbol(tag_key)
    tag.srcid = pmt.string_to_symbol(srcid)
    tag.value = pmt.from_long(value)
    tag.offset = offset
    return tag
示例#19
0
    def write_data(self, msg):
        snr = pmt.to_double(pmt.dict_ref(msg, pmt.intern("snr"), pmt.from_double(0)))
        encoding = pmt.to_long(pmt.dict_ref(msg, pmt.intern("encoding"), pmt.from_long(0)))

        time_now = time() * 1000
        delay = str(time_now - self.last_time)
        self.last_time = time_now


        if self.snr_file != "":
            f_snr = open(self.snr_file, 'a')
            f_snr.write(str(snr) + '\n')
            f_snr.close()

        if self.enc_file != "":
            f_enc = open(self.enc_file, 'a')    
            f_enc.write(str(encoding) + '\n')
            f_enc.close()

        if self.delay_file != "":
            f_delay = open(self.delay_file, 'a')
            f_delay.write(delay + '\n')
            f_delay.close()

        if self.debug:
            print("SNR:" + str(snr))
            print("Encoding:" + str(encoding))
            print("Delay in millis: " + delay)
示例#20
0
    def general_work(self, input_items, output_items):
        inp = input_items[0]
        out = output_items[0]

        window = list(self.stream) + inp.tolist()
        
        alltags = self.get_tags_in_range(0, self.maxtag, self.nitems_read(0) + len(inp), self.syncword_tag)
        for tag in alltags:
            if tag.offset not in self.tags:
                self.maxtag = max(self.maxtag, tag.offset)
                self.tags.append(tag.offset)
        for tag in self.tags:
            if (tag >= self.nitems_read(0) - len(self.stream)) and (tag < self.nitems_read(0) + len(inp) - self.packet_len + 1):
                self.tags.remove(tag)
                start = tag - self.nitems_read(0) + len(self.stream)
                packet = window[start : start + self.packet_len]
                self.data += packet
                self.add_item_tag(0, self.written, self.packetlen_tag, pmt.from_long(self.packet_len))
                self.written += self.packet_len

        self.stream.extend(inp.tolist())

        len_write = min(len(self.data), len(output_items[0]))
        output_items[0][:len_write] = self.data[:len_write]
        self.data = self.data[len_write:]
        self.consume(0, len(inp))
        return len_write
示例#21
0
    def test_001_t(self):
        tkey = 'packet_len'
        tsrc = 'testsrc'
        ptkey = pmt.intern(tkey)
        ptsrc = pmt.intern(tsrc)
        pre_padding = 17
        post_padding = 23
        tag = gr.tag_utils.python_to_tag((0, ptkey, pmt.from_long(128), ptsrc))

        data = np.arange(128) + 1
        data = data.astype(np.complex)

        ref = np.concatenate((np.zeros(pre_padding, dtype=data.dtype),
                              data, np.zeros(post_padding, dtype=data.dtype)))

        src = blocks.vector_source_c(data, tags=(tag, ))
        uut = gfdm.short_burst_shaper(pre_padding, post_padding, tkey)
        snk = blocks.vector_sink_c()
        # set up fg
        self.tb.connect(src, uut, snk)
        self.tb.run()
        # check data
        res = np.array(snk.data())

        self.assertComplexTuplesAlmostEqual(ref, res)
示例#22
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()
示例#23
0
文件: qa_pmt.py 项目: dl1ksv/gnuradio
 def test14(self):
     const = self.MAXINT32 - 1
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
     self.assertEqual(const,pmt.to_long(deser))
示例#24
0
 def test_002_with_offset (self):
     """ Standard test, carrier offset """
     fft_len = 16
     tx_symbols = list(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
     offsettag = gr.tag_t()
     offsettag.offset = 0
     offsettag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offsettag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_symbols, False, fft_len, (offsettag,))
     sink = blocks.tsb_vector_sink_c(tsb_key=self.tsb_key)
     serializer = digital.ofdm_serializer_vcc(
             fft_len,
             occupied_carriers,
             self.tsb_key,
             "", 0,
             "ofdm_sync_carr_offset",
             False
     )
     self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data()[0], expected_result)
     self.assertEqual(len(sink.tags()), 1)
示例#25
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.tag_t()
     random_tag.offset = 5
     random_tag.key = pmt.string_to_symbol("foo")
     random_tag.value = pmt.from_long(42)
     src = blocks.vector_source_b(encoded_headers, tags=(random_tag,))
     parser = digital.packet_headerparser_b(32, packet_len_tagname)
     sink = blocks.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)
 def test_001_t2 (self):
     """
     pretty simple (same as before, but odd fft len)
     """
     fft_len = 5
     tx_symbols = (1, 2, 3)
     #             ^ this gets mapped to the DC carrier because occupied_carriers[0][0] == 0
     occupied_carriers = ((0, 1, 2),)
     pilot_carriers = ((-2,),)
     pilot_symbols = ((1j,),)
     expected_result = (1j, 0, 1, 2, 3)
     #                         ^ DC carrier
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.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 = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
示例#27
0
	def work(self, input_items, output_items):
		if self.eof:
			return -1
		out = output_items[0]
		self.add_item_tag(0, self.nitems_written(0), pmt.intern("image_width"), pmt.from_long(self.image_width))
		self.add_item_tag(0, self.nitems_written(0), pmt.intern("line_num"), pmt.from_long(self.line_num))
		out[:self.image_width] = self.image_data[self.image_width*self.line_num: self.image_width*(1+self.line_num)]

		self.line_num += 1
		if self.line_num >= self.image_height:
			self.line_num = 0
			if self.repeatmode == 0:
				self.eof = True
			if self.repeatmode == 2:
				self.load_image()
		return self.image_width
 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 = (1j, 0, 1, 0, 2, 3)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     src = blocks.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 = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, sink)
     self.tb.run ()
     self.assertEqual(sink.data(), expected_result)
 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.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(n_syms)
     src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag,))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, tag_name)
     sink = blocks.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.symbol_to_string(result_tag.key), tag_name)
     self.assertEqual(pmt.to_long(result_tag.value), n_syms * len(occupied_carriers[0]))
示例#30
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'])
示例#31
0
 def test_with_tags_2s_rolloff(self):
     " With tags and a 2-sample rolloff "
     fft_len = 8
     cp_len = 2
     tag_name = "ts_last"
     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
     ]
     tag2 = gr.tag_t()
     tag2.offset = 1
     tag2.key = pmt.string_to_symbol("random_tag")
     tag2.value = pmt.from_long(42)
     src = blocks.vector_source_c(
         list(range(1, fft_len + 1)) * 2, False, fft_len, (tag2, ))
     cp = digital.ofdm_cyclic_prefixer(fft_len, fft_len + cp_len, 2,
                                       tag_name)
     sink = blocks.tsb_vector_sink_c(tsb_key=tag_name)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, 2,
                                        tag_name), cp, sink)
     self.tb.run()
     self.assertEqual(sink.data()[0], 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 = [(fft_len + cp_len, "random_tag", 42)]
     self.assertEqual(tags, expected_tags)
示例#32
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.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(data))
     src = blocks.vector_source_b(data, False, 1, (tag,))
     crc = digital.crc32_bb(False, tag_name)
     crc_check = digital.crc32_bb(True, tag_name)
     sink = blocks.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())
示例#33
0
    def work(self, input_items, output_items):
        """example: multiply with constant"""
        if np.any(input_items[0][:] > 0):
            for i in range(1, len(input_items[0])):
                if (self.prev == 0) and (input_items[0][i] == 1):
                    self.example_param = 1
                if (self.prev == 1):
                    self.example_param = self.example_param + 1
                if (self.prev == 1 and input_items[0][i] == 0):
                    sys.stdout.write("%i: %i \n" %
                                     (self.chan, self.example_param))
                    self.message_port_pub(pmt.intern('msg_out'),
                                          pmt.from_long(self.chan))
                self.prev = input_items[0][i]

        #output_items[0][:] = self.example_param
        return len(input_items[0])
示例#34
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.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(data))
     src = blocks.vector_source_b(data, False, 1, (tag,))
     crc = digital.crc32_bb(False, tag_name)
     crc_check = digital.crc32_bb(True, tag_name)
     corruptor = blocks.add_const_bb(1)
     sink = blocks.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)
 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)
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     # Note: this is shifted to the correct position!
     chan_tag.value = pmt.init_c32vector(fft_len,
                                         (0, 0, -1j, -1j, 0, -1j, -1j, 0))
     offset_tag = gr.tag_t()
     offset_tag.offset = 0
     offset_tag.key = pmt.string_to_symbol("ofdm_sync_carr_offset")
     offset_tag.value = pmt.from_long(carr_offset)
     src = blocks.vector_source_c(tx_data, False, fft_len,
                                  (chan_tag, offset_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), cp_len,
                                            self.tsb_key)
     sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len,
                                        n_syms, self.tsb_key), eq, sink)
     self.tb.run()
     # Check data
     self.assertComplexTuplesAlmostEqual(rx_expected,
                                         sink.data()[0],
                                         places=4)
示例#36
0
    def valueChanged(self, new_value):
        if int(self.scaleFactor) != 1:
            new_value = new_value * self.scaleFactor

        if self.varCallback is not None:
            self.varCallback(new_value)

        if self.isFloat:
            self.message_port_pub(
                pmt.intern("value"),
                pmt.cons(pmt.intern(self.outputmsgname),
                         pmt.from_double(new_value)))
        else:
            self.message_port_pub(
                pmt.intern("value"),
                pmt.cons(pmt.intern(self.outputmsgname),
                         pmt.from_long(new_value)))
示例#37
0
    def work(self, input_items, output_items):
        out = output_items[0]
        slpack = self._slClient.slconn.collect()
        try:
            seqnum = slpack.getSequenceNumber()
            trace = slpack.getTrace()
        except:
            out[:] = []
            return 0

        # print "sending slpack(id:%d): %d samples, len(out)=%d" % \
        #     (seqnum, len(trace.data), len(out))
        out[:len(trace.data)] = numpy.float32(trace.data)

        # https://gnuradio.org/doc/doxygen/page_python_blocks.html
        # https://github.com/guruofquality/grextras/wiki/Blocks-Coding-Guide
        # add_item_tag(which_output, abs_offset, key, value, srcid)

        # add a packet length tag
        abs_offset = self.nitems_written + 0
        key = pmt.string_to_symbol("packet_len")
        value = pmt.from_long(len(trace.data))
        srcid = pmt.string_to_symbol(self._channel)
        self.add_item_tag(0, abs_offset, key, value, srcid)

        # add a tag to manage time
        abs_offset = self.nitems_written + 0
        key = pmt.string_to_symbol("rx_time")
        value = pmt.from_double(trace.stats['starttime'].timestamp)
        srcid = pmt.string_to_symbol(self._channel)
        self.add_item_tag(0, abs_offset, key, value, srcid)
        # print "starttime ", trace.stats['starttime'].timestamp

        # add a tag to manage sample rate change
        abs_offset = self.nitems_written + 0
        key = pmt.string_to_symbol("rx_rate")
        fech = 1. / trace.stats['delta']
        value = pmt.from_double(fech)
        srcid = pmt.string_to_symbol(self._channel)
        self.add_item_tag(0, abs_offset, key, value, srcid)
        # print "fech ", 1./trace.stats['delta']

        self.samp_rate = fech
        self.nitems_written += len(trace.data)

        return len(trace.data)
示例#38
0
    def newValue(self, curValue, curIndex):
        p_val = pmt.from_float(curValue)
        p_index = pmt.from_long(curIndex)

        if curValue != self.lastValue:
            try:
                self.varCallback(curValue)
            except:
                pass

            self.message_port_pub(pmt.intern("value"),
                                  pmt.cons(pmt.intern("value"), p_val))

            self.lastValue = curValue

        self.message_port_pub(pmt.intern("index"),
                              pmt.cons(pmt.intern("index"), p_index))
示例#39
0
    def test_001_t(self):
        n_frames = 20
        timeslots = 9
        subcarriers = 128
        active_subcarriers = 110
        cp_len = subcarriers // 2
        smap = get_subcarrier_map(subcarriers, active_subcarriers)
        seed = 4711
        ftype = 'rrc'
        falpha = .5
        tag_key = 'frame_start'

        preamble, x_preamble = mapped_preamble(seed, ftype, falpha, active_subcarriers, subcarriers, smap, 2, cp_len, cp_len // 2)
        block_len = timeslots * subcarriers
        offset = len(preamble) + cp_len
        frame_len = len(preamble) + timeslots * subcarriers + cp_len

        data = np.array([], dtype=complex)
        ref = np.array([], dtype=complex)
        tags = []
        print('frame_len: ', frame_len)
        for i in range(n_frames):
            d_block = modulate_mapped_gfdm_block(get_random_qpsk(timeslots * active_subcarriers), timeslots, subcarriers, active_subcarriers, 2, falpha)
            frame = pinch_cp_add_block(d_block, timeslots, subcarriers, cp_len, cp_len // 2)
            frame = np.concatenate((preamble, frame))
            r = frame[offset:offset + block_len]
            ref = np.concatenate((ref, r))
            tag = gr.tag_t()
            tag.key = pmt.string_to_symbol(tag_key)
            tag.offset = len(data)
            tag.srcid = pmt.string_to_symbol('qa')
            tag.value = pmt.from_long(block_len)
            tags.append(tag)
            data = np.concatenate((data, frame))

        src = blocks.vector_source_c(data, False, 1, tags)
        cp_rm = gfdm.remove_prefix_cc(frame_len, block_len, offset, tag_key)
        snk = blocks.vector_sink_c()
        self.tb.connect(src, cp_rm, snk)
        self.tb.run()

        # # check data
        res = np.array(snk.data())
        tags = snk.tags()
        self.assertComplexTuplesAlmostEqual(res, ref, 5)
示例#40
0
    def work(self, input_items, output_items):
        # there has to be a better way to write this function. do that later
        s = input_items[0][0]
        l = input_items[1][0]
        sig = input_items[2][0]

        wndw = [1] * 161
        wndw[0] = 0.5
        wndw[160] = 0.5

        sig_wndw = [1] * 81
        sig_wndw[0] = 0.5
        sig_wndw[80] = 0.5

        # SHORT FIELD
        s = self.periodic_extend(s, 161)
        s = self.window(s, wndw)

        # LONG FIELD
        l = self.periodic_extend(l, len(l) * 2)
        end_val = l[0]
        l = self.cyclic_extend(l, len(l) / 4)
        l = np.append(l, [end_val])
        l = self.window(l, wndw)

        # SIGNAL FIELD
        end_val = sig[0]
        sig = self.cyclic_extend(sig, len(sig) / 4)
        sig = np.append(sig, [end_val])
        sig = self.window(sig, sig_wndw)

        # COMBINING PARTS
        combined = np.array([], dtype=np.complex64)
        combined = np.append(combined, s[:-1])
        combined = np.append(combined, [s[-1] + l[0]])
        combined = np.append(combined, l[1:-1])
        combined = np.append(combined, [l[-1] + sig[0]])
        combined = np.append(combined, sig[1:])

        self.add_item_tag(0,
                          self.nitems_written(0) + 1, pmt.intern("packet_len"),
                          pmt.from_long(len(combined)))
        out = output_items[0]
        out[:] = combined
        return len(output_items[0])
示例#41
0
    def test_001_basic_io(self):
        self.tb.start()
        # provide two non PDU inputs and one PDU input
        self.add_sys_time.to_basic_block()._post(
            pmt.intern("pdu"), pmt.intern("BAD PDU"))
        self.add_sys_time.to_basic_block()._post(pmt.intern("pdu"),
                                                 pmt.cons(pmt.from_long(4), pmt.PMT_NIL))
        self.add_sys_time.to_basic_block()._post(pmt.intern("pdu"),
                                                 pmt.cons(pmt.make_dict(), pmt.init_f32vector(1, [0.0])))
        self.waitFor(lambda: self.debug.num_messages() >=
                     1, timeout=1.0, poll_interval=0.01)
        self.tb.stop()
        self.tb.wait()

        # make sure we got one message and it has a systime key
        self.assertEqual(1, self.debug.num_messages())
        self.assertTrue(pmt.dict_has_key(
            pmt.car(self.debug.get_message(0)), pmt.intern('systime')))
示例#42
0
    def test_001_t(self):
        """
        test 256 bit packet
        """
        # set up fg
        data_in = range(256)  # np.random.randint(0, 2, size=256)
        key = pmt.intern("len_tag")
        val = pmt.from_long(256)
        tag = gr.tag_utils.python_to_tag((0, key, val))
        self.src = blocks.vector_source_f(data_in, False, 1, [tag])
        self.deintlvr = lpwan.dsss_deinterleaver_ff("len_tag")
        self.snk = blocks.vector_sink_f(1)
        self.tb.connect(self.src, self.deintlvr, self.snk)
        self.tb.run()

        # check data
        self.assertFloatTuplesAlmostEqual(dsss_const.intlvr_seq_256,
                                          self.snk.data()[0:256])
示例#43
0
    def timer_tick(self):

        cmd = pmt.make_dict()
        if self.count == 0:
            cmd = pmt.dict_add(cmd, pmt.intern('chan'),
                               pmt.to_pmt(self.uhd_channel))
            cmd = pmt.dict_add(cmd, pmt.intern('freq'),
                               pmt.to_pmt(self.freq_list[self.current_idx]))
            self.count = 10
            self.current_idx += 1
            self.current_idx %= len(self.freq_list)
        else:
            self.count -= 1

        cmd = pmt.dict_add(cmd, pmt.intern('tag'), pmt.from_long(1))
        self.message_port_pub(pmt.intern(self.msg_port_name), cmd)
        self.timer = Timer(self.switching_interval / 10.0, self.timer_tick)
        self.timer.start()
示例#44
0
    def test_001(self):
        #Test the overflow buffer in pdu_to_tagged_stream
        src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
        src = blocks.pdu_to_tagged_stream(blocks.float_t)
        snk = blocks.vector_sink_f()

        self.tb.connect(src, snk)
        port = pmt.intern("pdus")

        msg = pmt.cons( pmt.PMT_NIL, pmt.init_f32vector(10, src_data))
        src.to_basic_block()._post(port, msg)
        src.to_basic_block()._post(pmt.intern("system"),
                pmt.cons(pmt.intern("done"), pmt.from_long(1)))

        self.tb.start()
        self.tb.wait()

        self.assertEqual(src_data, list(snk.data()) )
    def setUp (self):
        self.tb = gr.top_block()

        # origin data is equal to timestamps
        samp_rate = 1.

        # data [lost items 0, 1, ..., 9], 10, 11, ..., 19
        data_with_overflows = np.arange(10,20)

        # Overflow tag
        overflow = gr.tag_utils.python_to_tag(
            (0, pmt.intern("overflows"), pmt.from_long(10), pmt.intern("src0")))

        self.src = blocks.vector_source_c(data=data_with_overflows, repeat=False, vlen=1, tags=[overflow,])
        self.dut = corrsounder.sequence_gate_cc(3, samp_rate)
        self.dst = blocks.vector_sink_c(vlen=1)

        self.tb.connect(self.src, self.dut, self.dst)
 def test_002_t(self):
     """
     once again, but this time add a sync word
     """
     fft_len = 6
     sync_word = (0, ) * fft_len
     tx_symbols = (1, 2, 3, 4, 5, 6)
     pilot_symbols = ((1j, ), )
     occupied_carriers = ((-1, 1, 2), )
     pilot_carriers = ((3, ), )
     expected_result = sync_word + (1j, 0, 1, 0, 2, 3) + (1j, 0, 4, 0, 5, 6)
     tag_name = "len"
     tag = gr.tag_t()
     tag.offset = 0
     tag.key = pmt.string_to_symbol(tag_name)
     tag.value = pmt.from_long(len(tx_symbols))
     special_tag1 = gr.tag_t()
     special_tag1.offset = 0
     special_tag1.key = pmt.string_to_symbol("spam")
     special_tag1.value = pmt.to_pmt(23)
     special_tag2 = gr.tag_t()
     special_tag2.offset = 4
     special_tag2.key = pmt.string_to_symbol("eggs")
     special_tag2.value = pmt.to_pmt(42)
     src = blocks.vector_source_c(tx_symbols, False, 1,
                                  (tag, special_tag1, special_tag2))
     alloc = digital.ofdm_carrier_allocator_cvc(fft_len,
                                                occupied_carriers,
                                                pilot_carriers,
                                                pilot_symbols,
                                                sync_words=(sync_word, ),
                                                len_tag_key=tag_name)
     sink = blocks.vector_sink_c(fft_len)
     self.tb.connect(src, alloc, 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])
     tags_expected = [
         (0, 'len', 3),
         (0, 'spam', 23),
         (2, 'eggs', 42),
     ]
     self.assertEqual(tags, tags_expected)
示例#47
0
def make_tags(len_tag_key, debug_key, payload_key):
    debug_tag = gr.tag_t()
    debug_tag.key = pmt.intern(debug_key)
    debug_tag.value = pmt.from_long(400)
    debug_tag.offset = 5
    remove_tag = gr.tag_t()
    remove_tag.key = pmt.intern(payload_key)
    remove_tag.value = pmt.from_long(400)
    remove_tag.offset = 6
    tags = [debug_tag, remove_tag]
    tag1 = gr.tag_t()
    tag1.key = pmt.intern(len_tag_key)
    tag1.value = pmt.from_long(1)
    tag1.offset = 0
    tags.append(tag1)
    tag2 = gr.tag_t()
    tag2.key = pmt.intern(len_tag_key)
    tag2.value = pmt.from_long(1)
    tag2.offset = 1
    tags.append(tag2)
    tag3 = gr.tag_t()
    tag3.key = pmt.intern(len_tag_key)
    tag3.value = pmt.from_long(1)
    tag3.offset = 2
    tags.append(tag3)
    tag4 = gr.tag_t()
    tag4.key = pmt.intern(len_tag_key)
    tag4.value = pmt.from_long(2)
    tag4.offset = 3
    tags.append(tag4)
    tag5 = gr.tag_t()
    tag5.key = pmt.intern(len_tag_key)
    tag5.value = pmt.from_long(1)
    tag5.offset = 5
    tags.append(tag5)
    tag6 = gr.tag_t()
    tag6.key = pmt.intern(len_tag_key)
    tag6.value = pmt.from_long(1)
    tag6.offset = 6
    tags.append(tag6)
    return tuple(tags)
示例#48
0
    def variable_changed(self, value):
        try:
            if type(value) == float:
                p = pmt.from_double(value)
            elif type(value) == int:
                p = pmt.from_long(value)
            elif type(value) == bool:
                p = pmt.from_bool(value)
            elif type(value) == str:
                p = pmt.intern(value)
            else:
                p = pmt.to_pmt(value)

            self.message_port_pub(pmt.intern("msgout"),
                                  pmt.cons(pmt.intern(self.pairname), p))

        except Exception as e:
            gr.log.error("Unable to convert " + repr(value) +
                         " to PDU, no message will be emitted (reason: %s)" % repr(e))
示例#49
0
    def test_001_t(self):
        tags = []
        # ref = []
        nt = int(time.time() * 1e9)
        for i in range(5):
            d = [
                i * 500,
                pmt.intern('time'),
                pmt.from_long(nt),
                pmt.intern('testsource')
            ]
            t = gr.tag_utils.python_to_tag(d)
            tags.append(t)

        debugger = latency.tag_timestamp_debug(8, "time", "tester")
        src = blocks.vector_source_c([0.j] * 10000, False, 1, tags)
        self.tb.connect(src, debugger)
        # set up fg
        self.tb.run()
示例#50
0
    def tearDown(self):
        self.tb.msg_connect((self.encode, 'out'), (self.decode, 'in'))
        self.tb.msg_connect((self.decode, 'out'), (self.dbg, 'store'))

        pdu = pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(len(self.data),
                                                      self.data))
        self.encode.to_basic_block()._post(pmt.intern('in'), pdu)
        self.encode.to_basic_block()._post(
            pmt.intern('system'), pmt.cons(pmt.intern('done'),
                                           pmt.from_long(1)))

        self.tb.start()
        self.tb.wait()

        result = pmt.u8vector_elements(pmt.cdr(self.dbg.get_message(0)))
        np.testing.assert_equal(self.data, result,
                                'Decoded data does not match encoder input')

        self.tb = None
 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
     tx_data = (1,) * fft_len * n_syms
     chan_tag = gr.tag_t()
     chan_tag.offset = 0
     chan_tag.key = pmt.string_to_symbol("ofdm_sync_chan_taps")
     chan_tag.value = pmt.init_c32vector(fft_len, (1,) * fft_len)
     random_tag = gr.tag_t()
     random_tag.offset = 1
     random_tag.key = pmt.string_to_symbol("foo")
     random_tag.value = pmt.from_long(42)
     src = blocks.vector_source_c(tx_data, False, fft_len, (chan_tag, random_tag))
     eq = digital.ofdm_frame_equalizer_vcvc(equalizer.base(), 0, self.tsb_key)
     sink = blocks.tsb_vector_sink_c(fft_len, tsb_key=self.tsb_key)
     self.tb.connect(
         src,
         blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key),
         eq,
         sink
     )
     self.tb.run ()
     # Check data
     self.assertEqual(tx_data, sink.data()[0])
     # Check tags
     tag_dict = dict()
     for tag in sink.tags():
         ptag = gr.tag_to_python(tag)
         tag_dict[ptag.key] = ptag.value
     expected_dict = {
         'foo': 42
     }
     self.assertEqual(tag_dict, expected_dict)
示例#52
0
    def test_000(self):
        num_msgs = 10
        msg_interval = 1000
        msg_list = []
        for i in range(num_msgs):
            msg_list.append(pmt.from_long(i))

        # Create vector source with dummy data to trigger messages
        src_data = []
        for i in range(num_msgs * msg_interval):
            src_data.append(float(i))
        src = blocks.vector_source_f(src_data, False)
        msg_gen = message_generator(msg_list, msg_interval)
        msg_cons = message_consumer()

        # Connect vector source to message gen
        self.tb.connect(src, msg_gen)

        # Connect message generator to message consumer
        self.tb.msg_connect(msg_gen, 'out_port', msg_cons, 'in_port')

        # Verify that the messgae port query functions work
        self.assertEqual(
            pmt.symbol_to_string(pmt.vector_ref(msg_gen.message_ports_out(),
                                                0)), 'out_port')
        self.assertEqual(
            pmt.symbol_to_string(pmt.vector_ref(msg_cons.message_ports_in(),
                                                0)), 'in_port')

        # Run to verify message passing
        self.tb.start()

        # Wait for all messages to be sent
        while msg_gen.msg_ctr < num_msgs:
            time.sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # Verify that the message consumer got all the messages
        self.assertEqual(num_msgs, len(msg_cons.msg_list))
        for i in range(num_msgs):
            self.assertTrue(pmt.equal(msg_list[i], msg_cons.msg_list[i]))
示例#53
0
    def test_001_t(self):
        # set up fg
        Range = (2, 4, 22, 23)
        velocity = (3, 12, 19, 19)
        power = (10, 10, 10, 1)  # last value is thrown away with merging peaks
        pmt_time = pmt.list2(
            pmt.string_to_symbol('rx_time'),
            pmt.make_tuple(pmt.from_long(-1), pmt.from_double(0)))
        pmt_axisx = pmt.list2(pmt.string_to_symbol('axis_x'),
                              pmt.init_f32vector(len(Range), Range))
        pmt_axisy = pmt.list2(pmt.string_to_symbol('axis_y'),
                              pmt.init_f32vector(len(velocity), velocity))
        pmt_power = pmt.list2(pmt.string_to_symbol('power'),
                              pmt.init_f32vector(len(power), power))
        pmt_in = pmt.list4(pmt_time, pmt_axisx, pmt_axisy, pmt_power)

        src = blocks.message_strobe(pmt_in, 300)
        est = radar.estimator_ofdm('range', 30, (0, 40, -40, 10), 'velocity',
                                   20, (-5, 5))
        snk = blocks.message_debug()
        self.tb.msg_connect(src, "strobe", est, "Msg in")
        self.tb.msg_connect(est, "Msg out", snk, "store")
        self.tb.msg_connect(est, "Msg out", snk, "print")

        self.tb.start()
        sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # get ref data
        ref_range = (0 + 40 * 2 / 15.0, 0 + 40 * 4 / 15.0,
                     -40 + 50 * (22 - 15) / 15.0)
        ref_velocity = (-5 + 10 * 3 / 20.0, -5 + 10 * 12 / 20.0,
                        -5 + 10 * 19 / 20.0)

        # check data
        msg = snk.get_message(0)
        val_range = pmt.f32vector_elements(pmt.nth(1, pmt.nth(1, msg)))
        val_velocity = pmt.f32vector_elements(pmt.nth(1, pmt.nth(2, msg)))
        print val_range
        self.assertFloatTuplesAlmostEqual(val_velocity, ref_velocity, 4)
        self.assertFloatTuplesAlmostEqual(val_range, ref_range, 4)
示例#54
0
    def work(self, input_items, output_items):
        out = output_items[0]
        produced = long(0)

        # print(self.insert_tag)
        # print(self.offset)
        for o in range(0, len(out)):
            if self.insert_tag:
                self.add_item_tag(0, self.offset + long(o),
                                  pmt.intern("packet_len"),
                                  pmt.from_long(self.packet_len))
                # print("a tag was inserted into the stream. offset: {}".format(self.offset))
                self.insert_tag = False

            if len(self.buffer) > 0:
                out[o] = self.buffer[0]
                self.buffer = self.buffer[1:]
                produced += 1
        self.offset += produced
        return produced
示例#55
0
    def test_001_t(self):

        data_in = [0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1]
        data_expected_result = [0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1]
        l = len(data_in)

        key = pmt.intern("len_tag")
        val = pmt.from_long(l)
        tag = gr.tag_utils.python_to_tag([0, key, val])

        # set up fg
        self.src = blocks.vector_source_b(data_in, False, 1, [tag])
        self.diffcoding = lpwan.dsss_diff_coding_bb("len_tag")
        self.snk = blocks.vector_sink_b(1)
        self.tb.connect(self.src, self.diffcoding, self.snk)

        self.tb.run()
        # check data
        self.assertFloatTuplesAlmostEqual(data_expected_result,
                                          self.snk.data())
示例#56
0
    def test_002_t(self):
        """
        test 384 bit packet with interleaver
        """
        # set up fg
        data_in = np.random.randint(0, 2, size=384)
        key = pmt.intern("len_tag")
        val = pmt.from_long(384)
        tag = gr.tag_utils.python_to_tag((0, key, val))
        self.src = blocks.vector_source_b(data_in, False, 1, [tag])
        self.intlvr = lpwan.dsss_interleaver_bb("len_tag")
        self.cast = blocks.char_to_float()
        self.deintlvr = lpwan.dsss_deinterleaver_ff("len_tag")
        self.snk = blocks.vector_sink_f(1)
        self.tb.connect(self.src, self.intlvr, self.cast, self.deintlvr,
                        self.snk)
        self.tb.run()

        # check data
        self.assertFloatTuplesAlmostEqual(data_in, self.snk.data())
示例#57
0
 def onBtnClicked(self, pressed):
     if type(self.msgValue) == int:
         self.message_port_pub(
             pmt.intern("pressed"),
             pmt.cons(pmt.intern(self.msgName),
                      pmt.from_long(self.msgValue)))
     elif type(self.msgValue) == float:
         self.message_port_pub(
             pmt.intern("pressed"),
             pmt.cons(pmt.intern(self.msgName),
                      pmt.from_float(self.msgValue)))
     elif type(self.msgValue) == str:
         self.message_port_pub(
             pmt.intern("pressed"),
             pmt.cons(pmt.intern(self.msgName), pmt.intern(self.msgValue)))
     elif type(self.msgValue) == bool:
         self.message_port_pub(
             pmt.intern("pressed"),
             pmt.cons(pmt.intern(self.msgName),
                      pmt.from_bool(self.msgValue)))
示例#58
0
 def test_005_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, 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)
     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) - 5, ], [
         tag.offset for tag in sink.tags()
         if pmt.symbol_to_string(tag.key) == 'tag1'
     ])
 def test_005_packet_len_tag (self):
     """ Standard test """
     fft_len = 16
     tx_symbols = list(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
     packet_len_tsb_key = "packet_len"
     tag2 = gr.tag_t()
     tag2.offset = 0
     tag2.key = pmt.string_to_symbol("packet_len")
     tag2.value = pmt.from_long(len(expected_result))
     src = blocks.vector_source_c(tx_symbols, False, fft_len, (tag2,))
     serializer = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, self.tsb_key, packet_len_tsb_key , 0, "", False)
     sink = blocks.tsb_vector_sink_c(tsb_key=packet_len_tsb_key)
     self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, fft_len, n_syms, self.tsb_key), serializer, sink)
     self.tb.run ()
     self.assertEqual(sink.data()[0], expected_result)
 def addStatus(self, key, value):
     if isinstance(value, (int, long)):
         self.message = pmt.dict_add(self.message,
                                     pmt.string_to_symbol(key),
                                     pmt.from_long(value))
     elif isinstance(value, basestring):
         self.message = pmt.dict_add(self.message,
                                     pmt.string_to_symbol(key),
                                     pmt.string_to_symbol(value))
     elif isinstance(value, float):
         self.message = pmt.dict_add(self.message,
                                     pmt.string_to_symbol(key),
                                     pmt.from_double(value))
     elif isinstance(value, (tuple)):
         self.message = pmt.dict_add(self.message,
                                     pmt.string_to_symbol(key),
                                     pmt.init_u16vector(2, value))
     elif isinstance(value, (list)):
         self.message = pmt.dict_add(self.message,
                                     pmt.string_to_symbol(key),
                                     pmt.init_u16vector(2, value))