我有一个简单的“拨号音” GRC应用程序,我正在通过一个简单的python网络服务器运行,当我运行此应用程序并调用freq方法时,必须在运行如下脚本之前设置变量值:
tb.set_samp_rate(32e3)
所以,我想知道的是,我是否可以在Web服务器页面上使用某种动态按钮或滑块,以便在程序运行时用来调整参数。意思是要从网页实时控制GNU无线电流程图的变量(如采样率,中心频率,解调器类型等)。
有可能吗?
这是我的网络服务器脚本:
import SimpleHTTPServer
import SocketServer
from dial_tone_modified import dial_tone_modified
tb = dial_tone_modified()
tb.set_samp_rate(32e3)
tb.start()
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print("Server at PORT ",PORT)
httpd.serve_forever()
tb.stop()
tb.wait()
这是我的GRC python代码:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Dial Tone Modified
# Generated: Mon Jul 15 11:15:28 2019
##################################################
from gnuradio import analog
from gnuradio import audio
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
class dial_tone_modified(gr.top_block):
def __init__(self):
gr.top_block.__init__(self, "Dial Tone Modified")
##################################################
# Variables
##################################################
self.samp_rate_0 = samp_rate_0 = 32000
self.samp_rate = samp_rate = 32000
##################################################
# Blocks
##################################################
self.blocks_add_xx = blocks.add_vff(1)
self.audio_sink = audio.sink(32000, '', True)
self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 440, .4, 0)
self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 350, .4, 0)
self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, 0.005, -42)
##################################################
# Connections
##################################################
self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx, 2))
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx, 0))
self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx, 1))
self.connect((self.blocks_add_xx, 0), (self.audio_sink, 0))
def get_samp_rate_0(self):
return self.samp_rate_0
def set_samp_rate_0(self, samp_rate_0):
self.samp_rate_0 = samp_rate_0
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.analog_sig_source_x_1.set_sampling_freq(self.samp_rate)
self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
def main(top_block_cls=dial_tone_modified, options=None):
tb = dial_tone_modified()
tb.start()
try:
raw_input('Press Enter to quit: ')
except EOFError:
pass
tb.stop()
tb.wait()
if __name__ == '__main__':
main()