GNU Radio中流图的动态配置

How can I reconfigure a flow graph? How do I use lock(), unlock()?¶

A running flow graph is static, and can't be changed. There are two ways to implement reconfigurability:

  • Use lock() / unlock()
  • Create blocks that react dynamically

Using lock() and unlock(), you will actually stop the flow graph, and can then disconnect and re-connect blocks. In the following example, the flow graph will run for a second,
the stop the execution (lock), disconnect the source, connect a different one, and resume. The resulting file will first have data from the vector source, then lots of zeros.

#!/usr/bin/env python
import time
from gnuradio import gr
from gnuradio import blocks

def main():
    tb = gr.top_block()
    src1 = blocks.vector_source_f(range(16), repeat=True)
    throttle = blocks.throttle(gr.sizeof_float, 1e6)
    sink = blocks.file_sink(gr.sizeof_float, 'out.dat')
    tb.connect(src1, throttle, sink)
    tb.start()
    time.sleep(1)
    print "Locking flowgraph..."
    tb.lock()
    tb.disconnect(src1)
    src2 = blocks.null_source(gr.sizeof_float)
    tb.connect(src2, throttle)
    print "Unlocking flowgraph..."
    tb.unlock()
    time.sleep(2)
    tb.stop()
    tb.wait()

if __name__ == "__main__":
    main()

Note that this is not meant for sample-precision timing, but rather for situations where time does not really matter.

If sample-timing is an issue, use general blocks to react to certain events. In the following example, we assume that you have written a general block which stops reading from the
first sink at a given time, and then seamlessly switches over to the second input:

#!/usr/bin/env python
import time
from gnuradio import gr
from gnuradio import blocks
import my_awesome_oot_module as myoot # This is your custom module

def main():
    tb = gr.top_block()
    src1 = blocks.vector_source_f(range(16), repeat=True)
    src2 = blocks.null_source(gr.sizeof_float)
    switch = myoot.switch() # This is your custom block
    throttle = blocks.throttle(gr.sizeof_float, 1e6)
    sink = blocks.file_sink(gr.sizeof_float, 'out.dat')
    tb.connect(src1, switch, throttle, sink)
    tb.connect(src2, (switch, 1))
    tb.start()
    time.sleep(2)
    tb.stop()
    tb.wait()

if __name__ == "__main__":
    main()

There are many blocks that react to input data, or incoming tags.

参考:http://gnuradio.org/redmine/projects/gnuradio/wiki/FAQ#How-can-I-reconfigure-a-flow-graph-How-do-I-use-lock-unlock

时间: 2024-11-02 01:17:02

GNU Radio中流图的动态配置的相关文章

GNU Radio中的数据元(Metadata)

A stream of samples is much more interesting when there is parsable metadata connected to that stream, such as the time of reception, centre frequency, sampling rate or even protocol-specific information such as node identification. In GNU Radio, add

GNU Radio中协议数据包的传递方式

All the blocks presented so far operate as "infinite stream" blocks, i.e., they simply continue working as long as items are fed into their inputs. The low pass filter is a good example: Every new item is interpreted as a new sample, and the out

GNU  Radio 中OFDM  Tunnel 详解

(在gnuradio3.4中确实有文中的例子,而且也在相应的目录下,在gnuradio3.7.1中,基于GMSK的是在/usr/local/share/gnuradio/examples/digital/narrowband目录下,基于OFDM的是在/usr/local/share/gnuradio/examples/digital/ofdm目录下,本文讲的应该是在3.4下的,但看了3.7的感觉大同小异) OFDM Tunnel是GNU Radio中很经典的例子.Tunnel有两个,一个是基于G

.NET下基于组件的分布式系统动态配置

动态|分布式 摘要 动态配置为基于组件的分布式系统提供了一种在线演化的强大机制.本文提出了一种在MS Dot Net环境下建立一个可动态配置的分布式应用系统的策略. 关键字 组件.AOP.动态配置 引言 随着分布式系统在各个关键业务中起到越来越多的作用,如银行系统.基础通信系统,而这些业务是需要长时间不间断运行的,因此对系统的演化必需是在线进行的.本文提出了一种在MS Dot Net Framework环境下实现基于组件的分布式系统的动态配置策略. 对分布式系统描述 基于组件技术的分布式系统可以

GNU Radio message

前面介绍过GNU Radio中协议数据包的传递方式之一--消息机制.仔细研究GNU Radio的源代码会发现,其中的消息机制是很重要的.几乎在所有实际的发送.接收中都会用到消息(message):在GRC中的packet_encoder和packet_decoder.pkt.py中的pkd_mod和pkd_demod以及packet.py中的packet_encoder和packet_decoder.packet_mod.packet_demod等等都用到了message_source和mess

GNU/Linux中动态库的搜索路径的指定方法汇总

动态链接时.执行时搜索路径顺序: 1.编译目标代码时使用-L指定的动态库搜索路径: 2.环境变量LD_LIBRARY_PATH指定的动态库搜索路径: 3.配置文件/etc/ld.so.conf中指定的动态库搜索路径: 4.默认的动态库搜索路径/lib: 5.默认的动态库搜索路径/usr/lib. 以上的3-5步中,不再需要手动地指定动态库搜索路径了, 有一个可以进行配置更新默认的搜索路径的命令: ldconfig ldconfig命令的用途,主要是在默认搜寻目录(/lib和/usr/lib)以及

Mule中如何用表达式动态配置服务提供端的地址

问题描述 求大大关注!动态配置服务提供端的地址 解决方案 解决方案二:你个大豆或!!!!解决方案三:你个大豆或!!!!解决方案四:这个问题我也不知道,答案满意吗?

[转]GNU Radio Companion - GRC

GNU Radio Companion - GRC 注:该文档适应于捆绑 GNU Radio 的 GRC,它不适应任何独立发行本的 GRC.如果想使用 GRC 0.70 请参阅 GNU Radio Companion (Old) . GNU Radio Companion (GRC) 是一个用来产生信号流程图及流程图源代码的图形化工具.它目前是由 Josh Blum 构建.   新特性  同稳定版 GRC 0.70 不同的,GRC 目前有哪些新特性? 捆绑式发行(Bundled)- GRC 目前

如何在Ubuntu上安装GNU radio

首先,我不得不说在Ubuntu上面安装GNU radio,对于初学者来说还真不是一件简单的事情.本人从最开始的一点点都不懂到最后熟悉.了解,成功安装GNU radio整整花了大概3天的时间.现在把自己在这个过程中学到的东西分享给大家,希望对大家有帮助. 安装GNU radio一般有两种方法:1. 通过脚本文件自动安装:2. 自己下载相应的版本文件,自行编译安装.第一种方法属于自动安装,不能让我们具体了解安装的过程,不利于以后的学习.而且这种方法往往也不容易成功,需要等待很久的时间,受到很多因素的