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

相关文章

基于 Cursor 开发 Spring Boot 项目详细攻略

《基于Cursor开发SpringBoot项目详细攻略》Cursor是集成GPT4、Claude3.5等LLM的VSCode类AI编程工具,支持SpringBoot项目开发全流程,涵盖环境配... 目录cursor是什么?基于 Cursor 开发 Spring Boot 项目完整指南1. 环境准备2. 创建

Python中logging模块用法示例总结

《Python中logging模块用法示例总结》在Python中logging模块是一个强大的日志记录工具,它允许用户将程序运行期间产生的日志信息输出到控制台或者写入到文件中,:本文主要介绍Pyt... 目录前言一. 基本使用1. 五种日志等级2.  设置报告等级3. 自定义格式4. C语言风格的格式化方法

SpringBoot 多环境开发实战(从配置、管理与控制)

《SpringBoot多环境开发实战(从配置、管理与控制)》本文详解SpringBoot多环境配置,涵盖单文件YAML、多文件模式、MavenProfile分组及激活策略,通过优先级控制灵活切换环境... 目录一、多环境开发基础(单文件 YAML 版)(一)配置原理与优势(二)实操示例二、多环境开发多文件版

Vite 打包目录结构自定义配置小结

《Vite打包目录结构自定义配置小结》在Vite工程开发中,默认打包后的dist目录资源常集中在asset目录下,不利于资源管理,本文基于Rollup配置原理,本文就来介绍一下通过Vite配置自定义... 目录一、实现原理二、具体配置步骤1. 基础配置文件2. 配置说明(1)js 资源分离(2)非 JS 资

使用docker搭建嵌入式Linux开发环境

《使用docker搭建嵌入式Linux开发环境》本文主要介绍了使用docker搭建嵌入式Linux开发环境,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录1、前言2、安装docker3、编写容器管理脚本4、创建容器1、前言在日常开发全志、rk等不同

Python 基于http.server模块实现简单http服务的代码举例

《Python基于http.server模块实现简单http服务的代码举例》Pythonhttp.server模块通过继承BaseHTTPRequestHandler处理HTTP请求,使用Threa... 目录测试环境代码实现相关介绍模块简介类及相关函数简介参考链接测试环境win11专业版python

Python实战之SEO优化自动化工具开发指南

《Python实战之SEO优化自动化工具开发指南》在数字化营销时代,搜索引擎优化(SEO)已成为网站获取流量的重要手段,本文将带您使用Python开发一套完整的SEO自动化工具,需要的可以了解下... 目录前言项目概述技术栈选择核心模块实现1. 关键词研究模块2. 网站技术seo检测模块3. 内容优化分析模

Spring创建Bean的八种主要方式详解

《Spring创建Bean的八种主要方式详解》Spring(尤其是SpringBoot)提供了多种方式来让容器创建和管理Bean,@Component、@Configuration+@Bean、@En... 目录引言一、Spring 创建 Bean 的 8 种主要方式1. @Component 及其衍生注解

基于Java开发一个极简版敏感词检测工具

《基于Java开发一个极简版敏感词检测工具》这篇文章主要为大家详细介绍了如何基于Java开发一个极简版敏感词检测工具,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下... 目录你是否还在为敏感词检测头疼一、极简版Java敏感词检测工具的3大核心优势1.1 优势1:DFA算法驱动,效率提升10

聊聊springboot中如何自定义消息转换器

《聊聊springboot中如何自定义消息转换器》SpringBoot通过HttpMessageConverter处理HTTP数据转换,支持多种媒体类型,接下来通过本文给大家介绍springboot中... 目录核心接口springboot默认提供的转换器如何自定义消息转换器Spring Boot 中的消息