/
top_block.py
executable file
·182 lines (165 loc) · 6.25 KB
/
top_block.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: Top Block
# Generated: Sat Aug 9 12:30:05 2014
##################################################
from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.fft import window
from gnuradio.filter import firdes
from gnuradio.wxgui import fftsink2
from gnuradio.wxgui import numbersink2
from grc_gnuradio import blks2 as grc_blks2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import osmosdr
import wx
class top_block(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Top Block")
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
##################################################
# Variables
##################################################
self.threshold = threshold = -40
self.samp_rate = samp_rate = 2000000
self.freq = freq = 446093750
##################################################
# Blocks
##################################################
self.wxgui_numbersink2_0_0 = numbersink2.number_sink_f(
self.GetWin(),
unit="Units",
minval=-100,
maxval=100,
factor=1.0,
decimal_places=10,
ref_level=0,
sample_rate=samp_rate,
number_rate=15,
average=False,
avg_alpha=None,
label="Number Plot",
peak_hold=False,
show_gauge=True,
)
self.Add(self.wxgui_numbersink2_0_0.win)
self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
self.GetWin(),
unit="Units",
minval=-100,
maxval=100,
factor=1.0,
decimal_places=10,
ref_level=0,
sample_rate=samp_rate,
number_rate=15,
average=False,
avg_alpha=None,
label="Number Plot",
peak_hold=False,
show_gauge=True,
)
self.Add(self.wxgui_numbersink2_0.win)
self.wxgui_fftsink2_2 = fftsink2.fft_sink_c(
self.GetWin(),
baseband_freq=0,
y_per_div=10,
y_divs=10,
ref_level=0,
ref_scale=2.0,
sample_rate=samp_rate,
fft_size=1024,
fft_rate=30,
average=False,
avg_alpha=None,
title="FFT Plot",
peak_hold=False,
)
self.Add(self.wxgui_fftsink2_2.win)
self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
self.rtlsdr_source_0.set_sample_rate(samp_rate)
self.rtlsdr_source_0.set_center_freq(freq, 0)
self.rtlsdr_source_0.set_freq_corr(0, 0)
self.rtlsdr_source_0.set_dc_offset_mode(2, 0)
self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
self.rtlsdr_source_0.set_gain_mode(0, 0)
self.rtlsdr_source_0.set_gain(42, 0)
self.rtlsdr_source_0.set_if_gain(20, 0)
self.rtlsdr_source_0.set_bb_gain(20, 0)
self.rtlsdr_source_0.set_antenna("", 0)
self.rtlsdr_source_0.set_bandwidth(0, 0)
self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
interpolation=48,
decimation=200,
taps=None,
fractional_bw=None,
)
self.blocks_threshold_ff_0 = blocks.threshold_ff(threshold-1, threshold, 0)
self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((100, ))
self.blocks_float_to_int_0 = blocks.float_to_int(1, 1)
self.blocks_add_const_vxx_0 = blocks.add_const_vii((40, ))
self.blks2_tcp_sink_0 = grc_blks2.tcp_sink(
itemsize=gr.sizeof_int*1,
addr="127.0.0.1",
port=50000,
server=False,
)
self.analog_am_demod_cf_0 = analog.am_demod_cf(
channel_rate=200e3,
audio_decim=1,
audio_pass=5000,
audio_stop=5500,
)
##################################################
# Connections
##################################################
self.connect((self.blocks_add_const_vxx_0, 0), (self.blks2_tcp_sink_0, 0))
self.connect((self.blocks_float_to_int_0, 0), (self.blocks_add_const_vxx_0, 0))
self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_float_to_int_0, 0))
self.connect((self.blocks_threshold_ff_0, 0), (self.wxgui_numbersink2_0_0, 0))
self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_threshold_ff_0, 0))
self.connect((self.rtlsdr_source_0, 0), (self.analog_am_demod_cf_0, 0))
self.connect((self.analog_am_demod_cf_0, 0), (self.rational_resampler_xxx_0, 0))
self.connect((self.blocks_multiply_const_vxx_0, 0), (self.wxgui_numbersink2_0, 0))
self.connect((self.rtlsdr_source_0, 0), (self.wxgui_fftsink2_2, 0))
self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
# QT sink close method reimplementation
def get_threshold(self):
return self.threshold
def set_threshold(self, threshold):
self.threshold = threshold
self.blocks_threshold_ff_0.set_hi(self.threshold)
self.blocks_threshold_ff_0.set_lo(self.threshold-1)
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.rtlsdr_source_0.set_sample_rate(self.samp_rate)
self.wxgui_fftsink2_2.set_sample_rate(self.samp_rate)
def get_freq(self):
return self.freq
def set_freq(self, freq):
self.freq = freq
self.rtlsdr_source_0.set_center_freq(self.freq, 0)
if __name__ == '__main__':
import ctypes
import os
if os.name == 'posix':
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
(options, args) = parser.parse_args()
tb = top_block()
tb.Start(True)
tb.Wait()