How to test source blocks in gnuradio

吃可爱长大的小学妹 提交于 2019-12-08 06:19:25
djanderson

A couple of things:

By default a flowgraph will run until it's told to stop. So that's why your memory is being chewed up. GNU Radio is throwing std::bad_alloc because you keep stuffing things in the vector_sink and eventually it runs out of RAM.

You need to stop the flowgraph. There are a couple ways to do that:

  • Return WORK_DONE (-1) from the work function of the block. That's appropriate for when the block has a finite amount of data to serve and then signal it's done. Check out vector_source as an example.

  • Use the head block, which will copy N samples and then return WORK_DONE for you. This is useful for unit tests.

Last note: once you get that working, your test will still fail (unless you request head to only copy 1 sample) because as you've written it, your source block will fill its entire output buffer with zeros each time it's called:

>>> import numpy as np
>>> out = np.empty(10, dtype=float)
>>> out[:] = 0
>>> out
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

so just make sure your expected array has the same number samples that you request from head:

>>> from gnuradio import gr, blocks
>>> n = 1000
>>> head = blocks.head(gr.sizeof_float, n)
>>> expected = np.zeros(n)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!