首页 > 编程语言 >gnuradio笔记[1]-内嵌python代码块

gnuradio笔记[1]-内嵌python代码块

时间:2023-12-21 23:34:59浏览次数:25  
标签:__ 内嵌 gnuradio GNU python self Python Radio block

摘要

在GNU Radio中简单使用内嵌python代码块实现输出内容到文件.

超链接

解决无法编辑代码块内代码

原理简介

GNU Radio简介

[https://wiki.gnuradio.org/index.php?title=What_Is_GNU_Radio]
GNU Radio is a free & open-source software development toolkit that provides signal processing blocks to implement software radios. It can be used with readily-available low-cost external RF hardware to create software-defined radios, or without hardware in a simulation-like environment. It is widely used in research, industry, academia, government, and hobbyist environments to support both wireless communications research and real-world radio systems.
GNU Radio is a framework that enables users to design, simulate, and deploy highly capable real-world radio systems. It is a highly modular, "flowgraph"-oriented framework that comes with a comprehensive library of processing blocks that can be readily combined to make complex signal processing applications. GNU Radio has been used for a huge array of real-world radio applications, including audio processing, mobile communications, tracking satellites, radar systems, GSM networks, Digital Radio Mondiale, and much more - all in computer software. It is, by itself, not a solution to talk to any specific hardware. Nor does it provide out-of-the-box applications for specific radio communications standards (e.g., 802.11, ZigBee, LTE, etc.,), but it can be (and has been) used to develop implementations of basically any band-limited communication standard.

GNU Radio是一个免费开源的软件开发工具包,提供信号处理块来实现软件无线电。它可以与现成的低成本外部RF硬件一起使用,以创建软件定义的无线电,或者在没有硬件的情况下在类似模拟的环境中使用。它广泛应用于研究、工业、学术、政府和业余爱好者环境,以支持无线通信研究和现实世界的无线电系统。
GNU Radio是一个框架,使用户能够设计、模拟和部署高性能的现实无线电系统。它是一个高度模块化的、面向“流图”的框架,带有全面的处理块库,可以很容易地组合起来,制作复杂的信号处理应用程序。GNU Radio已被用于大量的现实无线电应用,包括音频处理、移动通信、跟踪卫星、雷达系统、GSM网络、数字无线电世界等等,所有这些都在计算机软件中。它本身并不是与任何特定硬件通信的解决方案。它也没有为特定的无线电通信标准(如802.11、ZigBee、LTE等)提供开箱即用的应用程序,但它可以(并且已经)用于开发基本上任何带限通信标准的实现。

GNU Radio使用基于流图的可视化方式开发,支持内嵌代码.

python代码块简介

[https://wiki.gnuradio.org/index.php/Embedded_Python_Block]
This block allows you to create a new (custom) block in Python without needing to make and install an Out of Tree (OOT) Module. When you add the block to your flowgraph, the pre-populated code simply takes the input stream and multiplies it by a constant. Note that the structure of this Python block matches the structure of an OOT Python block. It's essentially a Python OOT block built into a grc flowgraph.

"""
Embedded Python Blocks:

Each time this file is saved, GRC will instantiate the first class it finds
to get ports and parameters of your block. The arguments to __init__  will
be the parameters. All of them are required to have default values!
"""

import numpy as np
from gnuradio import gr


class blk(gr.sync_block):  # other base classes are basic_block, decim_block, interp_block
    """Embedded Python Block example - a simple multiply const"""

    def __init__(self, example_param=1.0):  # only default arguments here
        """arguments to this function show up as parameters in GRC"""
        gr.sync_block.__init__(
            self,
            name='Embedded Python Block',   # will show up in GRC
            in_sig=[np.complex64],
            out_sig=[np.complex64]
        )
        # if an attribute with the same name as a parameter is found,
        # a callback is registered (properties work, too).
        self.example_param = example_param

    def work(self, input_items, output_items):
        """example: multiply with constant"""
        output_items[0][:] = input_items[0] * self.example_param
        return len(output_items[0])

参数:
The parameters for this block are simply those of your embedded Python block itself.

Note that every parameter needs a default value. For example, in the code above, note line:

def __init__(self, example_param=1.0):  # only default arguments here
#If you don't have any parameters, change that line of code to

def __init__(self):
#If you have a vector length equal to a variable of your block, note that the default value must be "hardcoded".

实现

连线

注意
输入输出类型要匹配,如都是byte,否则连线会变成红色.

代码块代码

"""
Embedded Python Block demo
"""

#  epy_block_0.py
#  created 10/17/2019

import numpy as np
from gnuradio import gr

import pmt

textboxValue = ""

class my_sync_block(gr.sync_block):
    """
    reads input from a message port
    outputs text
    """
    def __init__(self):
        gr.sync_block.__init__(self,
            name = "Embedded Python demo",
            in_sig = None,
            out_sig = [np.byte])
        self.message_port_register_in(pmt.intern('msg_in'))
        self.message_port_register_out(pmt.intern('clear_input'))
        self.set_msg_handler(pmt.intern('msg_in'), self.handle_msg)

    def handle_msg(self, msg):
        global textboxValue

        textboxValue = pmt.symbol_to_string (msg)
        # print (textboxValue)
    
    def work(self, input_items, output_items):
        global textboxValue

        # get length of string
        _len = len(textboxValue)
        if (_len > 0):
            # terminate with LF
            textboxValue += "\n"
            _len += 1
            # store elements in output array
            for x in range(_len):
                output_items[0][x] = ord(textboxValue[x])
            textboxValue = ""
            self.message_port_pub(pmt.intern('clear_input'), pmt.intern(''))
            return (_len)
        else:
            return (0)

效果

标签:__,内嵌,gnuradio,GNU,python,self,Python,Radio,block
From: https://www.cnblogs.com/qsbye/p/17920347.html

相关文章

  • Python Selenium WebDriver 使用教程
    ​ 1、安装Selenium使用SeleniumWebDriver需要先安装需要安装Selenium库,安装使用的pip在命令如下,pipinstallselenium2、安装浏览器驱动程序SeleniumWebDriver需要特定浏览器的驱动程序,使用的浏览器来下载相应的驱动程序,以便后续在代码中引用。下载地址:ChromeWebDri......
  • Python之PyAutoGUI的使用
    PyAutoGUI是Python的一个库,使用示例如下。一、移动到某个坐标点进行点击importpyautoguiprint(pyautogui.position())pyautogui.moveTo(56,18,duration=1)pyautogui.click()二、依照图片相似度移动到某个图片的位置进行点击importpyautoguipos=pyautogui.locateO......
  • python初试三
    在之前的程序中,我们直接生成一个字符串,作为http回复,返回给客户端。这一过程中使用了django.http.HttpResponse()。在这样的一种回复生成过程中,我们实际上将数据和视图的格式混合了到上面的字符串中。看似方便,却为我们的管理带来困难。想像一个成熟的网站,其显示格式会有许多重复的......
  • 【Python】【OpenCV】定位条形码(一)
    先上代码:1defbarcode(image):2gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)3blur=cv2.GaussianBlur(gray,(5,5),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)4cv2.imshow('GaussianBlur',blur)5kernel_x=numpy.array([......
  • Python 中迭代器与生成器:深度解析与实用指南
    Python作为一门强大而灵活的编程语言,提供了许多高效的工具来处理数据集合。在这些工具中,迭代器(Iterators)和生成器(Generators)是两个重要的概念,它们在数据遍历和惰性计算方面发挥着重要作用。本文将深入探讨Python迭代器和生成器的概念、用法以及它们之间的区别。1.什么是迭代器?迭代......
  • python之动态生成列表和重复数据处理
    动态生成列表:range(起始,终点,步长)方法:print(list(range(1,6)))结果:[1,2,3,4,5]print(list(range(1,22,2)))结果:[1,3,5,7,9,11,13,15,17,19,21]列表解析法生成列表:语法包含三部分:表达式用于计算列表中元素的值、循环语句用于获得循环元素、条件判断语句形式1:列......
  • 解决GNU Radio的内嵌代码块无法打开代码编辑器
    摘要解决GNURadio的内嵌代码块无法打开编辑器的问题.通过修改py脚本实现使用VSCode编辑内嵌代码.问题描述环境:系统macOS13.5GNURadioCompanion3.10.8.0(Python3.10.13)代码块选择应用程序是空的选择应用程序是空的实现修改/Users/workspace/rad......
  • python钉钉机器人运维脚本监控实例
    面是关于“Python钉钉机器人运维脚本监控实例”的完整攻略:目录介绍使用步骤配置机器人运行脚本示例说明监控服务器CPU使用率监控服务器磁盘空间总结介绍钉钉机器人是钉钉提供的一种形式化的通信渠道,可以通过代码来调用钉钉机器人的API,实现以机器人的形式向钉钉群组......
  • opencv图像处理机器学习真实项目教程(python实现)3图像处理基础
    3图像处理基础在本章中,我们将介绍图像处理中的各种操作,首先是基于平移的操作,如旋转和调整大小。读者将学习如何使用OpenCV旋转和调整图像大小,以及如何控制生成图像的大小和方向。本章接着介绍了图像的算术运算,如加法、减法和除法。本章继续以图像运算为主题,介绍图像的位运算,如......
  • Python代码中的偏函数
    技术背景在数学中我们都学过偏导数\(\frac{\partialf(x,y)}{\partialx}\),而这里我们提到的偏函数,指的是\(f(y)(x)\)。也就是说,在代码实现的过程中,虽然我们实现的一个函数可能带有很多个变量,但是可以用偏函数的形式把其中一些不需要拆分和变化的变量转变为固有变量。比较典型的......