版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、gnu radio软件无线电benchmark程序发送接收文件测试笔记在gnu radio软件无线电程序中,benchmark程序可以发射900mhz,接收 900mhz的无线电信号。具体做法是,把两台装有basic子板的usrp1母板分别 连上两台电脑的usb端口上,接通电源,在ubuntu操作系统下,在其屮一台电 脑的终端提示符下键入:“ cd /usr/local/share/gnuradio/example/digital/z, 进入benchmark程序的目录,再键入:/benchmark_tx. py -f 900m 这时候,和这台五脑usb端口连接的usrp母板上的lftx子板通
2、过电线就会发送 一个900mhz的无线电信号,电脑显示器显示: 表示正在发射无线电信号。这时,在另外的一台电脑上的终端提示符下键入: “ cd /usr/1 ocaul/share/grmradio/example/digital/z,进入benchmark程序的目录,再键入:/benchmark rx.py -f 900m" 这时候,和这台电脑usb端口连接的usrp母板上的lftx子板通过电线就会收到 一个900mhz的无线电信号,电脑显示器显示: ok=true pktno二1202 n_rcvd=l n_right=o 表明接收信号正常。现在的问题是要从这个电脑发送一个文件到
3、另外一个电脑,我查找了相 关资料发现,benchmark具有发送文件的功能,但是开源程序里没有这项功能, 需要用户根据自己的需要修改程序来达到发送接收文件的功能。我通过研究发 现,修改程序后,可以把这台电脑的aa. txt文件的"hello “字符发送到另外一 台电脑的tt. txt文件屮。具体做法是,在发送端电脑的 ,z/usr/local/share/gnuradio/cxaniplc/digitar,目录下新建 aa. txt, tt txt 两 个文本文件,在aa. txt中输入"hello"并保存,然后在终端下输入:“vi benchmark_tx. p
4、y 在vi编辑器下打开benchmark_tx. py程序,在第124行 "tb. start ()# start f 1 owgraph", 后输入“f二open('7usr、/local/shar、e/gnin、adio/examples/digital/aa. txt"," r)"“lines=f. readlines() ”两行新程序,第一行程序是以只读方式打开眈txt文件,第二行程序的作用是 以毎行阅读的方式读出aa. txt中的文本内容,然后再赋值给"lines"数组,接着 把第140行程序"p
5、ayload 二 struct, pack(,ih* , pktno & oxffff) + data " 改为"payload = str(options.num ) + str(lines)" 这步的作用是,去掉了打包发送pkno函数的功能,而加入发送lines函数和 options, num函数的功能。现在说一下options, num函数是从哪来的。首先把程序的第95彳亍至第100 行,改为parser. add_option (/z-e,z, "-discontinuous", act ion 二 s tore_t rue&q
6、uot;, defaul t 二 fell se,help二cnable discontinous transmission (bursts of 5 packets),z)parser, add option (-"-from f ile,z, dest二from f 订e,default二none,help二use intput file for packet contents")parser, add option(-t,"-to_file,z, dest二to_f订e,default二none,help二output file for modulated
7、samples")parser, add option(-nunt, type二indest二nunt, default二1 000,help二scnd message")parser, add option("-e", "-f订e", dest二filename", help二write report to ftle,metavar二file”)parser. add_option (-"-pdbk,action=/zstore_true,/, dest二pdcl", defauit二false, he
8、lp二气tite pdbk data to oracle db)parser, add option(-"-zdbk/z, action=/zstore_true/z,dest二zdcl, default=false, help二气rite zdbk data to oracle db)简单说一下,在终端输入“benchmark_tx-f 900m-n 1500”时,程序以900mhz 的频率发送数组options, num屮的数字1500和lines数组,因为parser. add_option(/z-nz,, "-numz,, type二int,dest二nunf: d
9、efault=1000, help二send message'7) 定义了一个属性是num的option, num函数通过提示符-n xxx来返回一个值给 option, num数组,上面其他程序的作用是定义了在终端提示符下发送文件 接收文件-t,写入给数据库-p,读取数据库-z,其他功能这里暂时不 讨论。修改完成后保存文件,退岀vi编辑器。下来在接收端的电脑上的z,/usr/local/sharc/gnuradio/cxeiniplc/digiteil/narrowbeind" r 录卜新建 aa. txt, tt. txt两个空白文本文件,然后在终端下输入:“vi ben
10、chmark rx. py/z在vi编辑器下打开benchmark_rx. py程序,把第79行到第98行的内容改为 global n_rcvd, n_ri ghtglobal n_d3t3 def main():global nrcvd, nrightglobal n_datan_rcvd 二 0n_right = 0n_data = str ()def rx_callback(ok, payload):global ncvd, n_rightglobal n_data(pkt no,)二 struct, un pack (j !it , payload0:2) n_data = paylo
11、ad0:4096 f=open (zz/usr/local/share/gnuradio/examples/digital/tt.txt , w )f. write (payload)n_rcvd +二 1if ok:nright +二 1print = %5s pktno 二 %4d n_rcvd = %4d n_right =%4d n_data = %5s" % (ok, pktno, n_rcvd, n_right, n_data)其中, ndata = payload0:4096 定义变量n_data用来显示接收的options, num数组和lines数组。还有上述f二o
12、pcn("/usr/local/share/gnuradio/cxamplcs/digital/nar rowband/tt. txt",f.write(payload)两行程序实现了以写入方式打开tt. txt文木文件,然后把接收的payload数组 写入tt. txt中。保存修改退岀vi编辑器后,在发送端的电脑 /usr/local/share/gnuradio/example/digital 的 目 录下键入 ./benchmark tx. py -f 900m -n 1900后,电脑显不表示发送正常,然后在接收端电脑/usr/local/share/grmradio
13、/example/digital 的 目 录下键入/benchmark tx. py -f 900m电脑显示ok = true pktno 二 12598 n_rcvd =458n_right 二 458 n_data =1900' hellon,表示接收正常。用“ctrl+c”键停止接收,打开接收端电脑 /usr/local/share/gnuradio/example/digital/的目录下的 tt. txt 文件,发现 原来是空文件的tt. txt,出现'hellon'显示,表示发送接收正常说明发送 端电脑上的aa. txt文件屮的“hello”字符已经传送到接
14、收端电脑的tt. txt文 件中。给发送端电脑的aa. txt文件中添加字符,如把“hello”改为“hello python” ,接收端点脑上的tt. txt文件中显示"'hello pythonn',表明接 受正常,当aa. txt中字符的长度超过3571个字节吋,接收端就会显示乱码,因 为每次程序只能发送低于3571字节的文本,一旦文本超过了 3571字节,发送 的信息量太大就会使程序读入数据出错,接收端就会收到乱码,耍传送更多字节 的文本就要修改程序,这个问题还在研究,现在不做讨论。下面测试一下能不能用其他子板正常发送接收文木。把上面的两个 basic子板换成
15、两个wbx子板,wbx子板上都连有天线。测试后发现接收端的 tt. txt就会显示乱码和误码。例如 原来发送aa. txt文本中的hcllo,接收到 的tt. txt文本却是为welp&*%。造成这个结果的原因是wbx子板靠天线发送 信号,而lfrx子板是通过屏蔽线传输信号。wbx子板发送无线电后,由于空间 中的干扰,无线电信号在传输中会产牛衰减和变化,另外的wbx子板接收到的无 线电信号就会和发送的无线电信号不同。要想传输的内容不发生变化,就要修改 程序,使每次只发送一个数据,这样接收就不容易产生误码和乱码。修改程序后, 把 benchmark_tx. py 中的"payl
16、oad = data + str (lines) + chr (options .num & oxff)" 改为"payload 二 str(1ines) " 作用是只把lines的值赋给发送函数paload,相当于只发送了 lines数组。同 时把发送端电脑的aa. txt文件里的“hello”改为“h” ,只发送一个字符h, 减少了传送的数据量,此时运行接收./benchmark rx. py -f 9oom和发送 "/bcnchmark_tx. py -f 9oom发现接收端电脑的tt. txt文本显示' h'表明接收成功
17、附件:benchmark rx. py 源码# !/usr/bi n/pytho n#!/usr/bin/env python# copyright 2010,2011,2013 free software foundation, inc.# this file is part of gnu radio# gnu radio is free software; you can redistribute it and/or modify# it under the terms of the gnu general public license as published by# the free
18、software foundation; either version 3, or (at your option)#any later version.# gnu radio is distributed in the hope that it will be useful,# but without any warranty; without even the implied warranty of# merchantability or fitness for a particular purpose. see the# gnu general public license for mo
19、re details.# you should have received a copy of the gnu general public license# along with gnu radio; see the file copying. if not, write to# the free software foundation, inc., 51 franklin street,# boston, ma 02110-1301, usa.#from gnuradio import gr, grufrom gnuradio import blocksfrom gn uradio imp
20、ort eng .notationfrom gnuradio.eng_option import eng_optionfrom optparse import optionparser# from gr-digitalfrom gnuradio import digital# from current dirfrom receive_path import receive_pathfrom uhdjnterface import uhd_receiverimport structimport sys#import os#print os.getpid()#rawjnputf'attac
21、h and press enter:')class my_top_block(gr.top_block):def _init_(self, demodulator, rx_callback, options):gr.top_block._init_(self)if(options.rx_freq is not none):# work-around to get the modulation's bits_per_symbolargs = demodulator.extract_kwargs_from_opti on s(opti ons) symbol_rate = opti
22、o ns.bitrate / demodulator!* *args).bits_per_symbol() self.source = uhd_receiver(options.args, symbol_rate,optionssamples_per_symbol, options.rx_freq, options.lo_offset, options.rx_gain, options.spec, options.antenna, options.clock_sourcez options.verbose)optio ns.samples_per_symbol = self.source._s
23、pselif(options.from_file is not none):sys.stderr.write(hreading samples from l%sl.nn” % (options.from_file) self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else:sys.stderr.write(11no source defined, pulling samples from null source.nnh) self.source = blocks. null_source(gr.
24、sizeof_gr_complex)# set up receive path# do this after for any adjustments to the options that may# occur in the sinks (specifically the uhd sink)self.rxpath = receive_path(demodulator, rx_callback, options)self.connect(self.source, self.rxpath)#/#main#/global n_rcvd, n_rightdef main():global n_rcvd
25、, n_rightglobal c_revn _rcvd = 0night = 0def rx_callback(ok, payload):#di ngyi rx_callback han shu ,zuo yong shi xianshi jieshoushujubaoglobal n_rcvd, n_rightglobal c_rev #dingyi c_rev wei jieshou hanshu(pktnoj = struct.unpack(,!hl/ payload0:2)(c_rev,) = struct.unpack('h: payload0:2)#c_rev jiesh
26、ou xinhaon_ rcvd += 1讦ok:n _right += 1print nok = %5s pktno = %4d n_rcvd = %4d n_right = %4d c_rev = %4ct % ( ok, pkt no, n_rcvd, n_right?c_rev)demods = digital.modulation_utils.type_l_demods()# create options parser:parser = optionparser (option_class=eng_option, conflict_handler二,'resolve”) ex
27、pert_grp = parser.add_optio n_ groupfxpert")parser.add_option"一modulation舄 type=,choiceh/ choices=demods.keys(), default='pskhelp="select modulation from: %s default=%default"% (', '.join(demods.keys(),)parser.add_option(""/'-from-file", default=non
28、e,help=ninput file of samples to demodm)receive_path.add_options(parsec expert_grp) uhd_receiver.add_opti on s(parser)for mod in demods.values():mod.add_options(expert_grp)(options, args) = parser.parse_args ()if len(args) != 0:parser.print_help(sys.stderr)sys.exit(l)if options.from_file is none:if
29、options.rx_freq is none:sys.stderr.write(nyou must specify -f freq or -freq freqnh) parser.print_help(sys.stderr)sys.exit(l)# build the graphtb = my_top_block(demodsoptions.modulation, rx_callback, options)r = gr.e nable_realtime_scheduling()if r != gr.rt_ok:print mwarning: failed to enable realtime
30、 scheduling.”tb.start() tb.wait()# start flow graph# wait for it to finish if _name_ = '_main_*:try:main()except keyboardlnterrupt:passbenchmark_tx.py 源码# !/usr/bi n/pytho n#!/usr/bin/env python# copyright 2010,2011,2013 free software foundation, inc.# this file is part of gnu radio# gnu radio i
31、s free software; you can redistribute it and/or modify# it under the terms of the gnu general public license as published by# the free software foundation; either version 3, or (at your option)# any later version.# gnu radio is distributed in the hope that it will be useful,# but without any warrant
32、y; without even the implied warranty of# merchantability or fitness for a particular purpose. see the# gnu general public license for more details.# you should have received a copy of the gnu general public license# along with gnu radio; see the file copying. if not, write to# the free software foun
33、dation, inc., 51 franklin street,# boston, ma 02110-1301, usa.#from gnuradio import grfrom gnuradio import blocksfrom gn uradio import eng .notationfrom gnuradio.eng_option import eng_optionfrom optparse import optionparser#diaoyong minglinghang chuli canshu# from gr-digitalfrom gnuradio import digi
34、tal# from current dirfrom transmit_path import transmit_pathfrom uhd_interface import uhd_transmitterimport time, struct, sys #import os#print os.getpid()#raw_input(*attach and press enter1)class my_top_block(gr.top_block):def _init_(self, modulator, options):gr.top_block._init_(self)if(options.tx_f
35、req is not none):# work-around to get the modulation's bits_per_symbolargs = modulator.extract_kwargs_from_opti on s(options) symbol_rate = options.bitrate / modulator(*args).bits_per_symbol()self.sink = uhd_transmitter(options.args, symbol_rate,options.samples_per_symbol, options.tx_freq, optio
36、ns.lo_offset, options.tx_gain,options.spec, options.antenna, options.clock_source, options.verbose)optio ns.samples_per_symbol = self.si nk_spseliffoptions.to_file is not none):sys.stderr.write(nsaving samples to %stnn" % (options.to_file) self.sink = blocks.file_sink(gr.sizeof_gr_complex, opti
37、ons.to_file) else:sys.stderr.write("no sink defined, dumping samples to null sinknrt) self.sink = blocks, nu ll_si nk(gr.sizeof_gr_complex)# do this after for any adjustments to the options that may# occur in the sinks (specifically the uhd sink) self.txpath = transmit_path(modulator; options)s
38、elf.connectfself.txpath, self.sink)#/#main#/def main():def send_pkt(payload: eof=false):#dingyi fasong hanshureturn tb.txpath.send_pkt(payloact eof)mods = digital.modulatio n_ utils.type_l_mods()parser = optionparser(option_class=eng_option, conflict_handler'resolve”) expert_grp = parser.add_opt
39、i on_ group(hexperth)parser.add_option”一modulation: type=,choiceh, choices二mods.keys(), default='psk',help="select modulation from: %s default=%default"% (', '.join(mods.keys(),)parser.add_option("-s", "-size", type="eng_float"/ default=1500/he
40、lp="set packet size default=%default") parser.add_option(',-m,/ ''-megabytes11, type=heng_float"/ default=l.o,help二”set megabytes to transmit default=%defaulth) parser.add_option(”ef discontinuous", action=,lstore_true'l/ default=false, help=henable discontinous t
41、ransmission (bursts of 5 packets)") parser.add_option("-w"/"-from_file",dest='from_file, default=none, help=huse intput file for packet contents") parser.add_option(n-t,7,-to_file"/dest=,to_file'/ default=nonezhelp=moutput file for modulated samples'1) parser.add_option("-n"/"-num,type="int",dest="num,default=1000/help=hsend message11)parser.add_option(,lp,'/ '一pdbk蔦 action二”store_true,:dest=hpdcr',defau
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年星级酒店管理师职业资格考试模拟试卷(含答案)
- 中级注册安全工程师化工安全实务题库带答案
- 电焊条压涂工创新应用知识考核试卷含答案
- 气动元件制造工安全检查能力考核试卷含答案
- 综合布线装维员岗前班组安全考核试卷含答案
- 稀土色层工岗前发展趋势考核试卷含答案
- 精制盐工安全知识竞赛知识考核试卷含答案
- 爬行类养殖工合规化水平考核试卷含答案
- 燃气输配场站运行工诚信品质评优考核试卷含答案
- 贝类养殖工创新思维水平考核试卷含答案
- 医疗器械生产车间质量安全风险管控清单
- 高甘油三酯血症管理专家共识(2025版)
- 体育场馆安全生产管理台账
- 2026年(完整版)院前急救知识培训题(含答案)
- 2026年行测类题库及答案详解
- 东航校招的在线测评题目2026
- 初中七年级语文《小圣施威降大圣》教学设计
- 2026语文新教材 1第24课《我将无我不负人民》
- 2026安徽省考评员培训考试题库及答案
- 2024 人身保险伤残评定及代码
- 统编五年级上册《航天员写给孩子的信》课件
评论
0/150
提交评论