Gnuradio创建OOT自定义模块的三种方式

2024-01-20 23:50

本文主要是介绍Gnuradio创建OOT自定义模块的三种方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本文内容、所用开发板、配件等仅限与研发和学习使用,如有侵权,请联系我们进行删除!

目录

一、概要

二、实验环境

三、实验内容

1、方式一:grc 中直接添加“Python Block”

2、方式二:使用gr_modtool添加python定义的OOT block

3、方式三:使用gr_modtool添加C++定义的OOT block

4、实验结果

四、参考链接


一、概要

OOT模块是指Gnuradio中并不包含的模块资源,用户根据需求自己定义来制作。编写OOT模块的方法多种,下面用简单的例子分别进行介绍。

二、实验环境

ubuntu 20.04 ; gnuradio 3.8 ; uhd 4.1.0

三、实验内容

下面以自定义一个2倍乘法器的grc oot block,即将输入的每个数据值都乘以2为例,简单介绍一下如何生成OOT block。

1、方式一:grc 中直接添加“Python Block”

打开gnruadio,在右边的模块搜索栏中直接搜索“Python Block”,然后添加到流图中。然后双击该模块,并对代码进行自定义的修改。

import numpy as np
from gnuradio import grclass blk(gr.sync_block):  # other base classes are basic_block, decim_block, interp_blockdef __init__(self):  # only default arguments heregr.sync_block.__init__(self,name='mult_2_grc',   in_sig=[np.complex64],out_sig=[np.complex64])def work(self, input_items, output_items):"""example: multiply with 2"""output_items[0][:] = input_items[0] * 2return len(output_items[0])

2、方式二:使用gr_modtool添加python定义的OOT block

打开终端,收入一下命令,使用gr_modtool创建一个molude,即许多blocks的集合目录,然后进入该目录中,添加一个python block。

1. gr_modtool newmod ootBlocks  //添加新的modlue
2. cd gr-ootBlocks/             //进入产生的目录
3. gr_modtool add mult_2_py     //添加oot blockGNU Radio module name identified: ootBlocks('sink', 'source', 'sync', 'decimator', 'interpolator', 'general',     'tagged_stream', 'hier', 'noblock')Enter block type: sync    Language (python/cpp): python  //这里使用pythonLanguage: PythonBlock/code identifier: mult_2_pyPlease specify the copyright holder: Enter valid argument list, including default arguments: Add Python QA code? [Y/n] nAdding file 'python/mult_2_py.py'...Adding file 'grc/ootBlocks_mult_2_py.block.yml'...Editing grc/CMakeLists.txt...
4. cd python/                    CMakeLists.txt  __init__.py  mult_2_py.py
5. gedit mult_2_py.py          //编辑后代码如下图所示
6. cd ../grc
7. gedit  ootBlocks_mult_2_py.block.yml  //编辑后的代码如下图所示
8. mkdir build/ && cd build/ && cmake ../ && make 
9. sudo make install && sudo ldconfig     //编译安装

编辑后的python代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy
from gnuradio import grclass mult_2_py(gr.sync_block):def __init__(self):gr.sync_block.__init__(self,name="mult_2_py",in_sig=[np.complex64],out_sig=[np.complex64])def work(self, input_items, output_items):in0 = input_items[0]out = output_items[0]out[:] = in0 * 2return len(output_items[0])

编辑后的yml文件

id: ootBlocks_mult_2_py
label: mult_2_py
category: '[ootBlocks]'templates:imports: import ootBlocksmake: ootBlocks.mult_2_py()inputs:
- label: indomain: streamdtype: complexoutputs:
- label: outdomain: streamdtype: complexfile_format: 1

3、方式三:使用gr_modtool添加C++定义的OOT block

在gr-ootBlocks中再添加一个用C++实现的OOT block.

1. gr_modtool add mult_2_cpp   //再添加一个oot block('sink', 'source', 'sync', 'decimator', 'interpolator', 'general',  'tagged_stream', 'hier', 'noblock')Enter block type: syncLanguage (python/cpp): cpp  //这里选择cppLanguage: C++Block/code identifier: mult_2_cppPlease specify the copyright holder: Enter valid argument list, including default arguments: Add Python QA code? [Y/n] nAdd C++ QA code? [Y/n] nAdding file 'lib/mult_2_cpp_impl.h'...Adding file 'lib/mult_2_cpp_impl.cc'...Adding file 'include/ootBlocks/mult_2_cpp.h'...Editing swig/ootBlocks_swig.i...Adding file 'grc/ootBlocks_mult_2_cpp.block.yml'...Editing grc/CMakeLists.txt...
2. gedit lib/mult_2_cpp_impl.cc  //修改实现自定义的功能,代码如下
3. gedit grc/ootBlocks_mult_2_cpp.block.yml //代码如下
4. 然后再次编译安装

修改后的cpp文件

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif#include <gnuradio/io_signature.h>
#include "mult_2_cpp_impl.h"namespace gr {namespace ootBlocks {mult_2_cpp::sptrmult_2_cpp::make(){return gnuradio::get_initial_sptr(new mult_2_cpp_impl());}mult_2_cpp_impl::mult_2_cpp_impl(): gr::sync_block("mult_2_cpp",gr::io_signature::make(1, 1, sizeof(gr_complex)),gr::io_signature::make(1, 1, sizeof(gr_complex))){}mult_2_cpp_impl::~mult_2_cpp_impl(){}intmult_2_cpp_impl::work(int noutput_items,gr_vector_const_void_star &input_items,gr_vector_void_star &output_items){const gr_complex *in = (const gr_complex *) input_items[0];gr_complex *out = (gr_complex *) output_items[0];for(int index = 0; index < noutput_items; index++) {out[index] = in[index] * (gr_complex)2;}return noutput_items;}} /* namespace ootBlocks */
} /* namespace gr */

修改后的yml文件

id: ootBlocks_mult_2_cpp
label: mult_2_cpp
category: '[ootBlocks]'templates:imports: import ootBlocksmake: ootBlocks.mult_2_cpp()inputs:
- label: indomain: streamdtype: complexoutputs:
- label: out    domain: streamdtype: complexfile_format: 1

4、实验结果

可见,三组图都是一模一样的幅度为2的正弦波重合在一起,相较与收入的幅度扩大了2倍。实验结果符合预期!

四、参考链接

1、http://www.highmesh.cn/

2、 OutOfTreeModules - GNU Radio

3、https://blog.csdn.net/qq_41300075/article/details/121411905

这篇关于Gnuradio创建OOT自定义模块的三种方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

SpringBoot中@Value注入静态变量方式

《SpringBoot中@Value注入静态变量方式》SpringBoot中静态变量无法直接用@Value注入,需通过setter方法,@Value(${})从属性文件获取值,@Value(#{})用... 目录项目场景解决方案注解说明1、@Value("${}")使用示例2、@Value("#{}"php

SpringBoot分段处理List集合多线程批量插入数据方式

《SpringBoot分段处理List集合多线程批量插入数据方式》文章介绍如何处理大数据量List批量插入数据库的优化方案:通过拆分List并分配独立线程处理,结合Spring线程池与异步方法提升效率... 目录项目场景解决方案1.实体类2.Mapper3.spring容器注入线程池bejsan对象4.创建

Python中logging模块用法示例总结

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

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

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

JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法

《JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法》:本文主要介绍JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法,每种方法结合实例代码给大家介绍的非常... 目录引言:为什么"相等"判断如此重要?方法1:使用some()+includes()(适合小数组)方法2

HTTP 与 SpringBoot 参数提交与接收协议方式

《HTTP与SpringBoot参数提交与接收协议方式》HTTP参数提交方式包括URL查询、表单、JSON/XML、路径变量、头部、Cookie、GraphQL、WebSocket和SSE,依据... 目录HTTP 协议支持多种参数提交方式,主要取决于请求方法(Method)和内容类型(Content-Ty

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

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

使用shardingsphere实现mysql数据库分片方式

《使用shardingsphere实现mysql数据库分片方式》本文介绍如何使用ShardingSphere-JDBC在SpringBoot中实现MySQL水平分库,涵盖分片策略、路由算法及零侵入配置... 目录一、ShardingSphere 简介1.1 对比1.2 核心概念1.3 Sharding-Sp

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

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

python中的显式声明类型参数使用方式

《python中的显式声明类型参数使用方式》文章探讨了Python3.10+版本中类型注解的使用,指出FastAPI官方示例强调显式声明参数类型,通过|操作符替代Union/Optional,可提升代... 目录背景python函数显式声明的类型汇总基本类型集合类型Optional and Union(py