• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pmt.serialize_str函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: propagate_headers

def propagate_headers(options, args):
    infile = args[0]
    outfile = args[1]
    infile_hdr = infile + ".hdr"
    outfile_hdr = outfile + ".hdr"
    sample_cnt_end = 0
    sample_offset = long(options.start)
    # Open input header
    try:
        handle_in = open(infile_hdr, "rb")
    except IOError:
        sys.stderr.write("Unable to open input file header\n")
        sys.exit(1)
    # Open output header
    try:
        handle_out = open(outfile_hdr, "wb")
    except IOError:
        sys.stderr.write("Unable to open output file header\n")
        sys.exit(1)

    # Read first header separately to get file type
    hdr_in, hdr_extra_in, handle_in = read_single_header(handle_in)
    info_in = parse_file_metadata.parse_header(hdr_in, False)
    sample_cnt_end += info_in["nitems"]
    # Parse file type - ensure support for it
    shortname_intype = find_shortname(info_in["cplx"], info_in["type"], info_in["size"])
    if shortname_intype == SNAME_TO_ENUM["unknown"]:
        sys.stderr.write("Unsupported data type\n")
        sys.exit(1)
    if options.output_type == "unknown":
        shortname_outtype = shortname_intype
    else:
        shortname_outtype = SNAME_TO_ENUM[options.output_type]

    # Calc sample_len from file size if not specified
    if options.nsamples is not None:
        sample_len = long(options.nsamples)
    else:
        sample_len = os.path.getsize(infile) / SNAME_DEFS[shortname_intype][0]
    final_index = sample_offset + sample_len

    # Search input headers until we find the correct one
    while sample_cnt_end <= sample_offset:
        hdr_in, hdr_extra_in, handle_in = read_single_header(handle_in)
        info_in = parse_file_metadata.parse_header(hdr_in, False)
        sample_cnt_end += info_in["nitems"]
    time_in = info_in["rx_time"]
    # Starting sample of current segment
    sample_cnt_start = sample_cnt_end - info_in["nitems"]
    # Interpolate new timestamp
    delta = sample_offset - sample_cnt_start
    new_ts = time_in + delta / info_in["rx_rate"]
    # Calc new segment size (samples)
    if sample_cnt_end > final_index:
        first_seg_len = final_index - sample_offset
    else:
        first_seg_len = sample_cnt_end - sample_offset

    # Write the first output header
    hdr_out = hdr_in
    new_secs = long(new_ts)
    new_fracs = new_ts - new_secs
    time_val = pmt.make_tuple(pmt.from_uint64(new_secs), pmt.from_double(new_fracs))
    size_val = pmt.from_long(SNAME_DEFS[shortname_outtype][0])
    bytes_val = pmt.from_uint64(first_seg_len * SNAME_DEFS[shortname_outtype][0])
    type_val = pmt.from_long(SNAME_DEFS[shortname_outtype][2])
    hdr_out = pmt.dict_add(hdr_out, pmt.intern("rx_time"), time_val)
    hdr_out = pmt.dict_add(hdr_out, pmt.intern("bytes"), bytes_val)
    hdr_out = pmt.dict_add(hdr_out, pmt.intern("type"), type_val)
    hdr_out = pmt.dict_add(hdr_out, pmt.intern("size"), size_val)
    hdr_out_str = pmt.serialize_str(hdr_out) + pmt.serialize_str(hdr_extra_in)
    handle_out.write(hdr_out_str)

    # Continue reading headers, modifying, and writing
    last_seg_len = info_in["nitems"]
    print "sample_cnt_end=%d,final_index=%d" % (sample_cnt_end, final_index)
    # Iterate through remaining headers
    while sample_cnt_end < final_index:
        hdr_in, hdr_extra_in, handle_in = read_single_header(handle_in)
        info_in = parse_file_metadata.parse_header(hdr_in, False)
        nitems = info_in["nitems"]
        sample_cnt_start = sample_cnt_end
        sample_cnt_end += nitems
        hdr_out = hdr_in
        # For last header, adjust segment length accordingly
        if sample_cnt_end > final_index:
            last_seg_len = final_index - sample_cnt_start
        else:
            last_seg_len = nitems
        size_val = pmt.from_long(SNAME_DEFS[shortname_outtype][0])
        bytes_val = pmt.from_uint64(last_seg_len * SNAME_DEFS[shortname_outtype][0])
        type_val = pmt.from_long(SNAME_DEFS[shortname_outtype][2])
        hdr_out = pmt.dict_add(hdr_out, pmt.intern("bytes"), bytes_val)
        hdr_out = pmt.dict_add(hdr_out, pmt.intern("type"), type_val)
        hdr_out = pmt.dict_add(hdr_out, pmt.intern("size"), size_val)
        hdr_out_str = pmt.serialize_str(hdr_out) + pmt.serialize_str(hdr_extra_in)
        handle_out.write(hdr_out_str)

    if options.verbose:
        print "Input File:" + infile
#.........这里部分代码省略.........
开发者ID:garverp,项目名称:recipes,代码行数:101,代码来源:fileman.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pmt.string_to_symbol函数代码示例发布时间:2022-05-27
下一篇:
Python pmt.intern函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap