Beispiel #1
0
    def test_002(self):
        offset = 10
        key = pmt.string_to_symbol('key')
        value = pmt.from_long(23)
        srcid = pmt.from_bool(False)

        format_dict = {
            'offset': offset,
            'key': key,
            'value': value,
            'srcid': srcid
        }
        format_list = [offset, key, value, srcid]
        format_tuple = (offset, key, value, srcid)

        t_dict = gr.python_to_tag(format_dict)
        t_list = gr.python_to_tag(format_list)
        t_tuple = gr.python_to_tag(format_tuple)

        self.assertTrue(pmt.equal(t_dict.key, key))
        self.assertTrue(pmt.equal(t_dict.value, value))
        self.assertEqual(t_dict.offset, offset)

        self.assertTrue(pmt.equal(t_list.key, key))
        self.assertTrue(pmt.equal(t_list.value, value))
        self.assertEqual(t_list.offset, offset)

        self.assertTrue(pmt.equal(t_tuple.key, key))
        self.assertTrue(pmt.equal(t_tuple.value, value))
        self.assertEqual(t_tuple.offset, offset)
    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()
Beispiel #3
0
def make_length_tag(offset, length):
    return gr.python_to_tag({
        'offset': offset,
        'key': pmt.intern('packet_len'),
        'value': pmt.from_long(length),
        'srcid': pmt.intern('qa_burst_shaper')
    })
Beispiel #4
0
def make_tag(offset, key, value):
    return gr.python_to_tag({
        'offset': offset,
        'key': pmt.intern(key),
        'value': value,
        'srcid': pmt.intern('qa_burst_shaper')
    })
Beispiel #5
0
        def work(self, input_items, output_items):
            in0 = input_items[0]
            out = output_items[0]
            ninput_items = len(in0)
            noutput_items = min(ninput_items, len(out))
            out[:noutput_items] = in0[:noutput_items]

            if self.tag_stream:
                tag = gr.python_to_tag({
                    "offset": self.nitems_read(0)+ninput_items,
                    "key": self.stream_tag_key,
                    "value": self.stream_tag_value,
                    "srcid": self.stream_tag_srcid,
                })
                self.add_item_tag(0, tag)
                self.tag_stream = False

            return noutput_items
 def setUp(self):
     self.syncword_tag = 'syncword'
     self.packetlen_tag = 'packet_len'
     self.packet_len = 100
     self.data = np.arange(3000, dtype='uint8')
     self.tag_positions = [50, 213, 217, 230, 1530, 1531]
     tags = [gr.python_to_tag((j, pmt.intern(self.syncword_tag),
                               pmt.intern('sync'), pmt.intern('test_src')))
             for j in self.tag_positions]
     self.source = blocks.vector_source_b(self.data, False, 1, tags)
     self.tag2pdu = blocks.tagged_stream_to_pdu(byte_t,
                                                self.packetlen_tag)
     self.debug = blocks.message_debug()
     self.tagger = fixedlen_tagger(self.syncword_tag, self.packetlen_tag,
                                   self.packet_len, np.byte)
     self.tb = gr.top_block()
     self.tb.connect(self.source, self.tagger, self.tag2pdu)
     self.tb.msg_connect((self.tag2pdu, 'pdus'), (self.debug, 'store'))
Beispiel #7
0
def phy_tag(offset=0,
            key='phy',
            nitems=0,
            rate=0,
            flag=0,
            rx_time=0,
            payload_sample_index=0):
    tag = gr.python_to_tag({
        'offset':
        offset,
        'key':
        pmt.intern(key),
        'srcid':
        pmt.from_bool(False),
        'value':
        phy_tag_create(nitems=nitems,
                       rate=rate,
                       flag=flag,
                       rx_time=rx_time,
                       payload_sample_index=payload_sample_index)
    })
    return tag