Gnuradio(3.10)创建OOT自定义模块--USRP X410软件无线电平台开发

本文主要是介绍Gnuradio(3.10)创建OOT自定义模块--USRP X410软件无线电平台开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

  • 平台环境
  • 一、OOT模块(Out-Of-Tree Module)
  • 二、创建OOT模块
    • 1.利用gr_modtool创建模块框架文件
    • 2.编写一个C++模块(名称为square_ff)
    • 3.在OOT module中继续添加一个模块(名称为square2_ff)
  • 三、运行测试
  • 总结


平台环境

环境平台:PC win10 + 虚拟机Vmware15.5(Ubuntu21.04)+ Gnuradio 3.10.0.0git

一、OOT模块(Out-Of-Tree Module)

OOT模块是指Gnuradio中并不包含的模块资源,用户根据需求自己定义来制作。编写OOT模块的方法多种,推荐采用gr_modtool工具(安装Gnuradio时默认已安装)。

二、创建OOT模块

参考链接:https://wiki.gnuradio.org/index.php/OutOfTreeModules

1.利用gr_modtool创建模块框架文件

执行指令如下:
$ gr_modtool newmod howto
在这里插入图片描述
创建文件夹名称为"gr-howto"的模块工程文件如上图,gr-howto文件夹中包含若干个文件,其中lib和include文件存放着C++文件和头文件,python文件夹存放单元测试文件和python模块文件。对于Gnuradio 3.8及以前版本,还会包含swig文件,其内部文件负责着C++和python文件的接口和联合封装,在3.9后的版本中,不再使用swig,而是采用pybind11,相关文件存放在python的binding文件夹里。
app文件夹存放已经装载在Gnuradio和编译完成的模块应用文件;grc文件中存放着一个关键的yml文件(GR3.8版本前为xml文件),是已经编辑好的OOT模块与Gnuradio接口桥梁。
OOT涉及关键文件关系如下图:
在这里插入图片描述

2.编写一个C++模块(名称为square_ff)

(1)通过gr_modtool工具添加block相关文件。
举例设计一个block,作用是将输入的single float数据计算平方,再输出single float数据,block命名为square_ff,尾缀的"ff"表示输入输出参数都是float(‘f’)。该模块作为gr-howto Python module目录下的模块之一,python调用该block时可以如下语句:
Import howto
Sqr = howto.square_ff()
通过 gr_modtool 工具创建模块文件,依次输入指令如下图:
在这里插入图片描述
注意Gnuradio版本不同,文件结构也有区别(左侧图为Gnuradio3.8版本,右侧为3.9及以上版本):
在这里插入图片描述“-t general’'表示block type是通用类型,”-l cpp square_ff"表示文件类型为cpp(c++语言,也可采用python设计),block名称为square_ff。
当前可以没有版权指定名(默认为gr-module的作者),这里输入gnuradio.org,也无默认参数default arguments。选择python QA code而不选择C++ QA code,QA程序用作编写block的功能测试。
(2)编写QA测试文件(GR3.9以上版本)
QA文件在gr-howto/python文件夹下,名称为qa_square_ff.py.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2021 gnuradio.org.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#from gnuradio import gr, gr_unittest
from gnuradio import blockstry:from howto import square_ff
except ImportError:import osimport sysdirname, filename = os.path.split(os.path.abspath(__file__))sys.path.append(os.path.join(dirname, "bindings"))from howto import square_ffclass qa_square_ff(gr_unittest.TestCase):def setUp(self):self.tb = gr.top_block()def tearDown(self):self.tb = Nonedef test_instance(self):# FIXME: Test will fail until you pass sensible arguments to the constructorinstance = square_ff()def test_001_square_ff(self):      src_data = (-3, 4, -5.5, 2, 3)expected_result = (9, 16, 30.25, 4, 9)src = blocks.vector_source_f(src_data)sqr = square_ff()dst = blocks.vector_sink_f()self.tb.connect(src, sqr)self.tb.connect(sqr,dst)self.tb.run()result_data = dst.data()self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)# check dataif __name__ == '__main__':gr_unittest.run(qa_square_ff, "qa_square_ff.yaml")

(3) 编写block C++文件
OOT的C++描述文件位于gr-howto/lib文件夹下,名称为square_ff_impl.cc和square_ff_impl.h。其中,.h文件已经生成完备,通常不需要修改。
square_ff_impl.cc修改后完整文件如下:

/* -*- c++ -*- */
/** Copyright 2021 gnuradio.org.** SPDX-License-Identifier: GPL-3.0-or-later*/#include "square_ff_impl.h"
#include <gnuradio/io_signature.h>namespace gr {
namespace howto {using input_type = float;
using output_type = float;
square_ff::sptr square_ff::make() { return gnuradio::make_block_sptr<square_ff_impl>(); }/** The private constructor*/
square_ff_impl::square_ff_impl(): gr::block("square_ff",gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */, sizeof(input_type)),gr::io_signature::make(1 /* min outputs */, 1 /*max outputs */, sizeof(output_type)))
{
}/** Our virtual destructor.*/
square_ff_impl::~square_ff_impl() {}void square_ff_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required)
{/* <+forecast+> e.g. ninput_items_required[0] = noutput_items */ninput_items_required[0] = noutput_items;
}int square_ff_impl::general_work(int noutput_items,gr_vector_int& ninput_items,gr_vector_const_void_star& input_items,gr_vector_void_star& output_items)
{const float *in = (const float *) input_items[0];float *out = (float *) output_items[0];for(int i = 0; i < noutput_items; i++) {out[i] = in[i] * in[i];}// Tell runtime system how many input items we consumed on// each input stream.consume_each (noutput_items);// Tell runtime system how many output items we produced.return noutput_items;
}} /* namespace howto */
} /* namespace gr */

square_ff_impl.h:

/* -*- c++ -*- */
/** Copyright 2021 
gnuradio.org.** SPDX-License-Identifier: GPL-3.0-or-later*/#ifndef INCLUDED_HOWTO_SQUARE_FF_IMPL_H
#define INCLUDED_HOWTO_SQUARE_FF_IMPL_H#include <howto/square_ff.h>namespace gr {
namespace howto {class square_ff_impl : public square_ff
{
private:// Nothing to declare in this block.public:square_ff_impl();~square_ff_impl();// Where all the action really happensvoid forecast(int noutput_items, gr_vector_int& ninput_items_required);int general_work(int noutput_items,gr_vector_int& ninput_items,gr_vector_const_void_star& input_items,gr_vector_void_star& output_items);
};} // namespace howto
} // namespace gr#endif /* INCLUDED_HOWTO_SQUARE_FF_IMPL_H */

(4) 进行编译和测试:gr-howto module文件夹下依次输入如下指令
$mkdir build
$cd build
$cmake . ./
在这里插入图片描述
再执行make:
$make
make完成后即可进行QA测试文件的测试:
$make test
在这里插入图片描述
一切正常,测试成功,如果出现错误,可使用 $ctest -V,查看具体错误报告。
(5)安装module和block至Gnuradio
$ gr_modtool makeyaml square_ff
运行指令,自动更新yml文件,更新后通常还需要一些修改。
在这里插入图片描述
注意:gr_modtool更新生成的yml文件,其中的注释必须要删除!!!
在这里插入图片描述修改后的yaml文件如下:

id: howto_square_ff
label: square_ff
category: '[howto]'
templates:imports: import howtomake: howto.square_ff()
inputs:
- label: indomain: streamdtype: floatmultiplicity: 1 
outputs:
- label: outdomain: streamdtype: floatmultiplicity: 1 
file_format: 1

回到build路径下,进行OOT的安装指令(只有安装后才能在Gnuradio界面显示)
$sudo make install
$sudo ldconfig
安装完后打开Gnuradio界面,可以看到右侧module栏增加了howto,包含block square_ff。
在这里插入图片描述
至此单个block的设计和安装过程结束。

3.在OOT module中继续添加一个模块(名称为square2_ff)

(1)在gr-howto文件夹下执行指令:
$ gr_modtool add square2_ff
该模块与上述的square_ff的模块类型不同,是Sync,即输入输出流数据比例是1:1,也可看做general通用类型的子类,在cpp代码上也有一些区别。
执行步骤同上:
在这里插入图片描述
此次添加的新模块需要执行(修改原block的源码也需要):
$gr_modtool bind square2_ff
在这里插入图片描述
补充:当.cc源文件调用一些malloc等std库时,可能存在版本问题报错,如下:
在这里插入图片描述
Ubuntu21.10下,GNU Radio3.10git 在进行OOT block的绑定时,执行gr_modtool bind …指令,报错如上图:
通过终端命令:python3 -c “import pygccxml; print(pygccxml.version)”
可以看到已经pygccxml的版本为2.2.1(最新版),可通过卸载pygccxml,解决上述问题,运行指令:
$ pip uninstall pygccxml
在这里插入图片描述

再次运行gr_modtool指令,成功bind。

(2) 依次修改文件:qa_square2_ff.py,square2_ff_impl.cc,howto_square2_ff.block.yml,完整代码依次如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2021 gnuradio.org.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
from gnuradio import gr, gr_unittest
from gnuradio import blocks
try:from howto import square2_ff
except ImportError:import osimport sysdirname, filename = os.path.split(os.path.abspath(__file__))sys.path.append(os.path.join(dirname, "bindings"))from howto import square2_ffclass qa_square2_ff(gr_unittest.TestCase):def setUp(self):self.tb = gr.top_block()def tearDown(self):self.tb = Nonedef test_instance(self):# FIXME: Test will fail until you pass sensible arguments to the constructorinstance = square2_ff()def test_001_square2_ff(self):      src_data = (-3, 4, -5.5, 2, 3)expected_result = (9, 16, 30.25, 4, 9)src = blocks.vector_source_f(src_data)sqr = square2_ff()dst = blocks.vector_sink_f()self.tb.connect(src, sqr)self.tb.connect(sqr,dst)self.tb.run()result_data = dst.data()self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)# check dataif __name__ == '__main__':gr_unittest.run(qa_square2_ff)
/* -*- c++ -*- */
/** Copyright 2021 
gnuradio.org.** SPDX-License-Identifier: GPL-3.0-or-later*/#include "square2_ff_impl.h"
#include <gnuradio/io_signature.h>namespace gr {
namespace howto {using input_type = float;
using output_type = float;
square2_ff::sptr square2_ff::make() { return gnuradio::make_block_sptr<square2_ff_impl>(); }
/** The private constructor*/
square2_ff_impl::square2_ff_impl(): gr::sync_block("square2_ff",gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */, sizeof(input_type)),gr::io_signature::make(1 /* min outputs */, 1 /*max outputs */, sizeof(output_type)))
{
}/** Our virtual destructor.*/
square2_ff_impl::~square2_ff_impl() {}int square2_ff_impl::work(int noutput_items,gr_vector_const_void_star& input_items,gr_vector_void_star& output_items)
{const float *in = (const float *) input_items[0];float *out = (float *) output_items[0];for(int i = 0; i < noutput_items; i++) {out[i] = in[i] * in[i];}return noutput_items;
}} /* namespace howto */
} /* namespace gr */
id: howto_square2_ff
label: square2_ff
category: '[howto]'
templates:imports: import howtomake: howto.square2_ff()
inputs:
- label: indomain: streamdtype: floatmultiplicity: 1 
outputs:
- label: outdomain: streamdtype: floatmultiplicity: 1 
file_format: 1

(3) 进入build文件夹,依次执行命令:
$cmake . ./
$make
执行make过程中就遇到如下错误:
在这里插入图片描述Pydoc.h文件是gr_modtool工具自动产生的,提示#include包含错误,怀疑是square2_ff作为后续block添加,可能与之前已经执行过的make指令冲突,因此想到一种极端方法,清空删除build内的所有文件,再重新执行make的一套指令(因square_ff已经调试确认无误,重新make也不会影响square_ff)。
$cmake . ./
$make
$make test
再次测试,测试通过
在这里插入图片描述
(4) 再进行OOT的安装,因已经修改了yml文件,可以直接执行如下指令:
$sudo make install
$sudo ldconfig
至此完成所有安装工作!!!Gnuradio软件界面可以看到两个block均存在,且可正常使用。
在这里插入图片描述

三、运行测试

流程图及运行结果如下(signal1和2重合,两个block运行结果一致)
在这里插入图片描述

总结

对于OOT模块创建,module下添加单个block很顺利,但添加多个block模块时,按上述方法略为复杂,还需继续根据官方步骤完善。

这篇关于Gnuradio(3.10)创建OOT自定义模块--USRP X410软件无线电平台开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/627749

相关文章

Spring Security基于数据库的ABAC属性权限模型实战开发教程

《SpringSecurity基于数据库的ABAC属性权限模型实战开发教程》:本文主要介绍SpringSecurity基于数据库的ABAC属性权限模型实战开发教程,本文给大家介绍的非常详细,对大... 目录1. 前言2. 权限决策依据RBACABAC综合对比3. 数据库表结构说明4. 实战开始5. MyBA

使用Python开发一个简单的本地图片服务器

《使用Python开发一个简单的本地图片服务器》本文介绍了如何结合wxPython构建的图形用户界面GUI和Python内建的Web服务器功能,在本地网络中搭建一个私人的,即开即用的网页相册,文中的示... 目录项目目标核心技术栈代码深度解析完整代码工作流程主要功能与优势潜在改进与思考运行结果总结你是否曾经

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定

idea中创建新类时自动添加注释的实现

《idea中创建新类时自动添加注释的实现》在每次使用idea创建一个新类时,过了一段时间发现看不懂这个类是用来干嘛的,为了解决这个问题,我们可以设置在创建一个新类时自动添加注释,帮助我们理解这个类的用... 目录前言:详细操作:步骤一:点击上方的 文件(File),点击&nbmyHIgsp;设置(Setti

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark

如何自定义Nginx JSON日志格式配置

《如何自定义NginxJSON日志格式配置》Nginx作为最流行的Web服务器之一,其灵活的日志配置能力允许我们根据需求定制日志格式,本文将详细介绍如何配置Nginx以JSON格式记录访问日志,这种... 目录前言为什么选择jsON格式日志?配置步骤详解1. 安装Nginx服务2. 自定义JSON日志格式各

Python使用date模块进行日期处理的终极指南

《Python使用date模块进行日期处理的终极指南》在处理与时间相关的数据时,Python的date模块是开发者最趁手的工具之一,本文将用通俗的语言,结合真实案例,带您掌握date模块的六大核心功能... 目录引言一、date模块的核心功能1.1 日期表示1.2 日期计算1.3 日期比较二、六大常用方法详

利用Go语言开发文件操作工具轻松处理所有文件

《利用Go语言开发文件操作工具轻松处理所有文件》在后端开发中,文件操作是一个非常常见但又容易出错的场景,本文小编要向大家介绍一个强大的Go语言文件操作工具库,它能帮你轻松处理各种文件操作场景... 目录为什么需要这个工具?核心功能详解1. 文件/目录存javascript在性检查2. 批量创建目录3. 文件