コード例 #1
0
ファイル: pmt_to_python.py プロジェクト: JLWebber/grextras
def pmt_to_dict(p):
    d = dict()
    items = pmt.pmt_dict_items(p)
    for i in range(pmt.pmt_length(items)):
        pair = pmt.pmt_nth(i, items)
        k = pmt.pmt_car(pair)
        v = pmt.pmt_cdr(pair)
        d[pmt_to_python(k)] = pmt_to_python(v)
    return d
コード例 #2
0
def pmt_to_dict(p):
    d = dict()
    items = pmt.pmt_dict_items(p)
    for i in range(pmt.pmt_length(items)):
        pair = pmt.pmt_nth(i, items)
        k = pmt.pmt_car(pair)
        v = pmt.pmt_cdr(pair)
        d[pmt_to_python(k)] = pmt_to_python(v)
    return d
コード例 #3
0
ファイル: qa_pdu.py プロジェクト: denzfarid/gnuradio
    def test_000(self):
        # Just run some data through and make sure it doesn't puke.
        src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

        src = blocks.pdu_to_tagged_stream(blocks.byte_t)
        snk3 = blocks.tagged_stream_to_pdu(blocks.byte_t)
        snk2 = gr.vector_sink_b()
        snk = gr.tag_debug(1, "test")
        snk.set_display(False)

        dbg = gr.message_debug()

        # Test that the right number of ports exist.
        pi = snk3.message_ports_in()
        po = snk3.message_ports_out()
        self.assertEqual(pmt.pmt_length(pi), 0)
        self.assertEqual(pmt.pmt_length(po), 1)

        time.sleep(0.1)
        self.tb.connect(src, snk)
        self.tb.connect(src, snk2)
        self.tb.connect(src, snk3)
        self.tb.msg_connect(snk3, "pdus", dbg, "store")
        self.tb.start()

        # make our reference and message pmts
        port = pmt.pmt_intern("pdus")
        msg = pmt.pmt_cons(pmt.PMT_NIL, pmt.pmt_make_u8vector(16, 0xFF))

        # post the message
        src.to_basic_block()._post(port, msg)  # eww, what's that smell?

        while dbg.num_messages() < 1:
            time.sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # Get the vector of data from the vector sink
        result_data = snk2.data()

        # Get the vector of data from the message sink
        # Convert the message PMT as a pair into its vector
        result_msg = dbg.get_message(0)
        msg_vec = pmt.pmt_cdr(result_msg)
        #pmt.pmt_print(msg_vec)

        # Convert the PMT vector into a Python list
        msg_data = []
        for i in xrange(16):
            msg_data.append(pmt.pmt_u8vector_ref(msg_vec, i))

        actual_data = 16 * [
            0xFF,
        ]
        self.assertEqual(actual_data, list(result_data))
        self.assertEqual(actual_data, msg_data)
コード例 #4
0
ファイル: qa_pdu.py プロジェクト: denzfarid/gnuradio
    def test_000(self):
        # Just run some data through and make sure it doesn't puke.
        src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

        src = blocks.pdu_to_tagged_stream(blocks.byte_t)
        snk3 = blocks.tagged_stream_to_pdu(blocks.byte_t)
        snk2 = gr.vector_sink_b()
        snk = gr.tag_debug(1, "test")
        snk.set_display(False)

        dbg = gr.message_debug()

        # Test that the right number of ports exist.
        pi = snk3.message_ports_in()
        po = snk3.message_ports_out()
        self.assertEqual(pmt.pmt_length(pi), 0)
        self.assertEqual(pmt.pmt_length(po), 1)

        time.sleep(0.1)
        self.tb.connect(src, snk)
        self.tb.connect(src, snk2)
        self.tb.connect(src, snk3)
        self.tb.msg_connect(snk3, "pdus", dbg, "store")
        self.tb.start()

        # make our reference and message pmts
        port = pmt.pmt_intern("pdus")
        msg = pmt.pmt_cons( pmt.PMT_NIL, pmt.pmt_make_u8vector(16, 0xFF))

        # post the message
        src.to_basic_block()._post(port, msg) # eww, what's that smell?

        while dbg.num_messages() < 1:
            time.sleep(0.5)
        self.tb.stop()
        self.tb.wait()

        # Get the vector of data from the vector sink
        result_data = snk2.data()

        # Get the vector of data from the message sink
        # Convert the message PMT as a pair into its vector
        result_msg = dbg.get_message(0)
        msg_vec = pmt.pmt_cdr(result_msg)
        #pmt.pmt_print(msg_vec)

        # Convert the PMT vector into a Python list
        msg_data = []
        for i in xrange(16):
            msg_data.append(pmt.pmt_u8vector_ref(msg_vec, i))

        actual_data = 16*[0xFF,]
        self.assertEqual(actual_data, list(result_data))
        self.assertEqual(actual_data, msg_data)
コード例 #5
0
ファイル: pmt_rpc.py プロジェクト: extrasyllmit/extrasy
    def handle_request(self, pdu ):
        if pmt.pmt_is_pair(pdu):
        
            # get the first and last elements of the pair
            fcn_name = pmt.to_python(pmt.pmt_car(pdu))
            request = pmt.to_python(pmt.pmt_cdr(pdu))
            
        #try to parse the request
        try:
            args, kwargs = request
            if args is None: args = tuple()
            if kwargs is None: kwargs = dict()
        except:
            err = 'cannot parse request for %s, expected tuple of args, kwargs'%fcn_name
            print err
            #return request, None, err
            return

        #exec python code and squash down to objects
        args = map(self._exec_arg, args)
        for key, val in kwargs.iteritems():
            kwargs[key] = self._exec_arg(val)

        #fly through dots to get the fcn pointer
        try:
            fcn_ptr = self._obj
            for name in fcn_name.split('.'):
                fcn_ptr = getattr(fcn_ptr, name)
        except:
            err = 'cannot find function %s in %s'%(fcn_name, self._obj)
            print err
            #return request, None, err
            return
        
        #try to execute the request
        try:
            ret = fcn_ptr(*args, **kwargs)
        except Exception as ex:
            err = 'cannot execute request for %s, got error %s'%(fcn_name, ex)
            print err
            #return request, None, err
            return
        
        #return the sucess result
        #return request, ret, None
        self.message_port_pub(self.OUT_PORT, pmt.from_python(ret)) 
コード例 #6
0
def parse_extra_dict(p, info, VERBOSE=False):
    if(pmt.pmt_is_dict(p) is False):
        sys.stderr.write("Extra header is not a PMT dictionary: invalid or corrupt data file.\n")
        sys.exit(1)

    items = pmt.pmt_dict_items(p)
    nitems = pmt.pmt_length(items)
    for i in xrange(nitems):
        item = pmt.pmt_nth(i, items)
        key = pmt.pmt_symbol_to_string(pmt.pmt_car(item))
        val = pmt.pmt_cdr(item)
        info[key] = val
        if(VERBOSE):
            print "{0}: ".format(key)
            pmt.pmt_print(val)

    return info