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

目录
相关文章
|
7月前
|
安全 数据处理 C++
GNU Radio之OFDM Carrier Allocator底层C++实现
GNU Radio之OFDM Carrier Allocator底层C++实现
142 1
GNU Radio之OFDM Carrier Allocator底层C++实现
|
7月前
|
数据可视化 物联网 Python
GNU Radio简介及流程图搭建
GNU Radio简介及流程图搭建
198 0
|
7月前
解决GNU Radio+USRP实现OFDM收发在接收端QPSK星座图映射无“抖动”问题
解决GNU Radio+USRP实现OFDM收发在接收端QPSK星座图映射无“抖动”问题
189 0
|
7月前
|
Python
GNU Radio创建Zadoff-Chu序列python OOT块
GNU Radio创建Zadoff-Chu序列python OOT块
91 0