当前位置: 首页>>代码示例>>Python>>正文


Python pmt.serialize_str函数代码示例

本文整理汇总了Python中pmt.serialize_str函数的典型用法代码示例。如果您正苦于以下问题:Python serialize_str函数的具体用法?Python serialize_str怎么用?Python serialize_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了serialize_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: postMessage

 def postMessage(self, blk_alias, port, msg):
     '''
     blk_alias: the alias of the block we are posting the message
                to; must have an open message port named 'port'.
                Provide as a string.
     port: The name of the message port we are sending the message to.
           Provide as a string.
     msg: The actual message. Provide this as a PMT of the form
          right for the message port.
     The alias and port names are converted to PMT symbols and
     serialized. The msg is already a PMT and so just serialized.
     '''
     self.thriftclient.radio.postMessage(pmt.serialize_str(pmt.intern(blk_alias)),
                                         pmt.serialize_str(pmt.intern(port)),
                                         pmt.serialize_str(msg));
开发者ID:Andy-Vuong,项目名称:gnuradio,代码行数:15,代码来源:RPCConnectionThrift.py

示例2: test14

 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))
开发者ID:dl1ksv,项目名称:gnuradio,代码行数:7,代码来源:qa_pmt.py

示例3: test17

 def test17(self):
     const = self.MININT32 + 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))
     x_long = pmt.to_long(deser)
     self.assertEqual(const, x_long)
开发者ID:dl1ksv,项目名称:gnuradio,代码行数:8,代码来源:qa_pmt.py

示例4: request

 def request(self, id_str, args=None):
     socks = dict(self.poller_req_out.poll(10))
     if socks.get(self.req_socket) == zmq.POLLOUT:
         self.req_socket.send(pmt.serialize_str(pmt.to_pmt((id_str,args))))
     socks = dict(self.poller_req_in.poll(10))
     if socks.get(self.req_socket) == zmq.POLLIN:
         reply = pmt.to_python(pmt.deserialize_str(self.req_socket.recv()))
         print("[RPC] reply:", reply)
         return reply
开发者ID:danbar,项目名称:gnuradio,代码行数:9,代码来源:rpc_manager.py

示例5: watcher

 def watcher(self):
     self.keep_running = True
     while self.keep_running:
         # poll for calls
         socks = dict(self.poller_rep.poll(10))
         if socks.get(self.rep_socket) == zmq.POLLIN:
             # receive call
             msg = self.rep_socket.recv()
             (id_str, args) = pmt.to_python(pmt.deserialize_str(msg))
             print("[RPC] request:", id_str, ", args:", args)
             reply = self.callback(id_str, args)
             self.rep_socket.send(pmt.serialize_str(pmt.to_pmt(reply)))
开发者ID:danbar,项目名称:gnuradio,代码行数:12,代码来源:rpc_manager.py

示例6: test19

 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"])
开发者ID:dl1ksv,项目名称:gnuradio,代码行数:14,代码来源:qa_pmt.py

示例7: test12

 def test12(self):
     v = pmt.init_c64vector(3, [11 + -101j, -22 + 202j, 33 + -303j])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
开发者ID:232675,项目名称:gnuradio,代码行数:5,代码来源:qa_pmt.py

示例8: test10

 def test10(self):
     v = pmt.init_s32vector(3, [11, -22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
开发者ID:232675,项目名称:gnuradio,代码行数:5,代码来源:qa_pmt.py

示例9: test07

 def test07(self):
     v = pmt.init_u16vector(3, [11, 22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
开发者ID:232675,项目名称:gnuradio,代码行数:5,代码来源:qa_pmt.py

示例10: make_header

def make_header(options, filename):
    extras_present = False
    if options.freq is not None:
        extras_present = True
    # Open the file and make the header
    hdr_filename = filename + '.hdr'
    hdr_file = open(hdr_filename, 'wb')
    header = pmt.make_dict()
    # Fill in header vals
    # TODO - Read this from blocks.METADATA_VERSION
    ver_val = pmt.from_long(long(0))
    rate_val = pmt.from_double(options.sample_rate)
    time_val = pmt.make_tuple(pmt.from_uint64(options.time_sec),
                             pmt.from_double(options.time_fsec))
    ft_to_sz = parse_file_metadata.ftype_to_size
    # Map shortname to properties
    enum_type = SNAME_TO_ENUM[options.format]
    type_props = SNAME_DEFS[enum_type]
    size_val = pmt.from_long(type_props[0])
    cplx_val = pmt.from_bool(type_props[1])
    type_val = pmt.from_long(type_props[2])
    fmt = type_props[2]
    file_samp_len = long(options.length)
    seg_size = long(options.seg_size)
    bytes_val = pmt.from_uint64(long(seg_size*ft_to_sz[fmt]))
    # Set header vals
    header = pmt.dict_add(header, pmt.intern("version"), ver_val)
    header = pmt.dict_add(header, pmt.intern("size"), size_val)
    header = pmt.dict_add(header, pmt.intern("type"), type_val)
    header = pmt.dict_add(header, pmt.intern("cplx"), cplx_val)
    header = pmt.dict_add(header, pmt.intern("rx_time"), time_val)
    header = pmt.dict_add(header, pmt.intern("rx_rate"), rate_val)
    header = pmt.dict_add(header, pmt.intern("bytes"), bytes_val)

    if extras_present:
        freq_key = pmt.intern("rx_freq")
        freq_val = pmt.from_double(options.freq)
        extras = pmt.make_dict()
        extras = pmt.dict_add(extras, freq_key, freq_val)
        extras_str = pmt.serialize_str(extras)
        start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE
                + len(extras_str))
    else:
        start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE)
    header = pmt.dict_add(header, pmt.intern("strt"), start_val)
    num_segments = file_samp_len/seg_size
    if options.verbose:
        print "Wrote %d headers to: %s (Version %d)" % (num_segments+1,
                hdr_filename,pmt.to_long(ver_val))
    for x in range(0,num_segments,1):
        # Serialize and write out file
        if extras_present:
            header_str = pmt.serialize_str(header) + extras_str
        else:
            header_str = pmt.serialize_str(header)
        hdr_file.write(header_str)
        # Update header based on sample rate and segment size
        header = update_timestamp(header,seg_size)
    
    # Last header is special b/c file size is probably not mult. of seg_size
    header = pmt.dict_delete(header,pmt.intern("bytes"))
    bytes_remaining = ft_to_sz[fmt]*(file_samp_len - num_segments*long(seg_size))
    bytes_val = pmt.from_uint64(bytes_remaining)
    header = pmt.dict_add(header,pmt.intern("bytes"),bytes_val)
    # Serialize and write out file
    if extras_present:
        header_str = pmt.serialize_str(header) + extras_str
    else:
        header_str = pmt.serialize_str(header)
    hdr_file.write(header_str)
    hdr_file.close()
开发者ID:garverp,项目名称:recipes,代码行数:71,代码来源:mkheader.py

示例11: test11

 def test11(self):
     v = pmt.init_c32vector(3, [11 + -101j, -22 + 202j, 33 + -303j])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
     self.assertEqual(pmt.uniform_vector_itemsize(v), 8)
开发者ID:dl1ksv,项目名称:gnuradio,代码行数:6,代码来源:qa_pmt.py

示例12: test03

 def test03(self):
     v = pmt.init_f32vector(3, [11, -22, 33])
     s = pmt.serialize_str(v)
     d = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(v, d))
     self.assertEqual(pmt.uniform_vector_itemsize(v), 4)
开发者ID:dl1ksv,项目名称:gnuradio,代码行数:6,代码来源:qa_pmt.py

示例13: test16

 def test16(self):
     const = self.MININT32
     x_pmt = pmt.from_long(const)
     s = pmt.serialize_str(x_pmt)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(x_pmt, deser))
开发者ID:dl1ksv,项目名称:gnuradio,代码行数:6,代码来源:qa_pmt.py

示例14: test_001

    def test_001(self):
        N = 1000
	outfile = "test_out.dat"

        detached = False
        samp_rate = 200000
        key = pmt.intern("samp_rate")
        val = pmt.from_double(samp_rate)
        extras = pmt.make_dict()
        extras = pmt.dict_add(extras, key, val)
        extras_str = pmt.serialize_str(extras)

        data = sig_source_c(samp_rate, 1000, 1, N)
        src  = blocks.vector_source_c(data)
        fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile,
                                     samp_rate, 1,
                                     blocks.GR_FILE_FLOAT, True,
                                     1000000, extras_str, detached)
        fsnk.set_unbuffered(True)

	self.tb.connect(src, fsnk)
	self.tb.run()
        fsnk.close()

        handle = open(outfile, "rb")
        header_str = handle.read(parse_file_metadata.HEADER_LENGTH)
        if(len(header_str) == 0):
            self.assertFalse()

        try:
            header = pmt.deserialize_str(header_str)
        except RuntimeError:
            self.assertFalse()

        info = parse_file_metadata.parse_header(header, False)

        extra_str = handle.read(info["extra_len"])
        self.assertEqual(len(extra_str) > 0, True)

        handle.close()

        try:
            extra = pmt.deserialize_str(extra_str)
        except RuntimeError:
            self.assertFalse()

        extra_info = parse_file_metadata.parse_extra_dict(extra, info, False)

        self.assertEqual(info['rx_rate'], samp_rate)
        self.assertEqual(pmt.to_double(extra_info['samp_rate']), samp_rate)


        # Test file metadata source
        src.rewind()
        fsrc = blocks.file_meta_source(outfile, False)
        vsnk = blocks.vector_sink_c()
        tsnk = blocks.tag_debug(gr.sizeof_gr_complex, "QA")
        ssnk = blocks.vector_sink_c()
        self.tb.disconnect(src, fsnk)
        self.tb.connect(fsrc, vsnk)
        self.tb.connect(fsrc, tsnk)
        self.tb.connect(src, ssnk)
        self.tb.run()

        fsrc.close() 
        # Test to make sure tags with 'samp_rate' and 'rx_rate' keys
        # were generated and received correctly.
        tags = tsnk.current_tags()
        for t in tags:
            if(pmt.eq(t.key, pmt.intern("samp_rate"))):
                self.assertEqual(pmt.to_double(t.value), samp_rate)
            elif(pmt.eq(t.key, pmt.intern("rx_rate"))):
                self.assertEqual(pmt.to_double(t.value), samp_rate)

        # Test that the data portion was extracted and received correctly.
        self.assertComplexTuplesAlmostEqual(vsnk.data(), ssnk.data(), 5)

	os.remove(outfile)
开发者ID:Flamewires,项目名称:gnuradio,代码行数:78,代码来源:qa_file_metadata.py

示例15: _msg_handler

 def _msg_handler(self, msg):
     self._file.write(pmt.serialize_str(msg))
开发者ID:marcusmueller,项目名称:gr-msgtools,代码行数:2,代码来源:msg_file_sink.py


注:本文中的pmt.serialize_str函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。