1105 |
kaklik |
1 |
#!/usr/bin/env python
|
|
|
2 |
##################################################
|
|
|
3 |
# Gnuradio Python Flow Graph
|
|
|
4 |
# Title: MLAB ADC Grabber
|
|
|
5 |
# Author: Jakub Kakona
|
|
|
6 |
# Description: Basic software for reading ADC data from ADCdual01A modules trought ML602 development board.
|
|
|
7 |
# Generated: Fri May 2 16:35:23 2014
|
|
|
8 |
##################################################
|
|
|
9 |
|
|
|
10 |
from datetime import datetime
|
|
|
11 |
from gnuradio import blocks
|
|
|
12 |
from gnuradio import eng_notation
|
|
|
13 |
from gnuradio import filter
|
|
|
14 |
from gnuradio import gr
|
|
|
15 |
from gnuradio import wxgui
|
|
|
16 |
from gnuradio.eng_option import eng_option
|
|
|
17 |
from gnuradio.fft import window
|
|
|
18 |
from gnuradio.filter import firdes
|
|
|
19 |
from gnuradio.wxgui import fftsink2
|
|
|
20 |
from gnuradio.wxgui import numbersink2
|
|
|
21 |
from gnuradio.wxgui import scopesink2
|
|
|
22 |
from gnuradio.wxgui import waterfallsink2
|
|
|
23 |
from grc_gnuradio import wxgui as grc_wxgui
|
|
|
24 |
from optparse import OptionParser
|
|
|
25 |
import wx
|
|
|
26 |
|
|
|
27 |
class MLAB_ADC_Grabber(grc_wxgui.top_block_gui):
|
|
|
28 |
|
|
|
29 |
def __init__(self):
|
|
|
30 |
grc_wxgui.top_block_gui.__init__(self, title="MLAB ADC Grabber")
|
|
|
31 |
_icon_path = "/usr/local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
|
|
|
32 |
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
|
|
|
33 |
|
|
|
34 |
##################################################
|
|
|
35 |
# Variables
|
|
|
36 |
##################################################
|
|
|
37 |
self.prefix = prefix = "/home/localuser/gnuradio/"
|
|
|
38 |
self.samp_rate = samp_rate = 5e6
|
|
|
39 |
self.recfile = recfile = prefix + datetime.now().strftime("%Y.%m.%d.%H.%M.%S") + ".dat"
|
|
|
40 |
|
|
|
41 |
##################################################
|
|
|
42 |
# Blocks
|
|
|
43 |
##################################################
|
|
|
44 |
self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
|
|
|
45 |
self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Time wiev")
|
|
|
46 |
self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Frequency wiev")
|
|
|
47 |
self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "numbers")
|
|
|
48 |
self.Add(self.notebook_0)
|
|
|
49 |
self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c(
|
|
|
50 |
self.notebook_0.GetPage(0).GetWin(),
|
|
|
51 |
baseband_freq=0,
|
|
|
52 |
dynamic_range=100,
|
|
|
53 |
ref_level=0,
|
|
|
54 |
ref_scale=2.0,
|
|
|
55 |
sample_rate=samp_rate,
|
|
|
56 |
fft_size=512,
|
|
|
57 |
fft_rate=15,
|
|
|
58 |
average=False,
|
|
|
59 |
avg_alpha=None,
|
|
|
60 |
title="ADC1 Waterfall Plot",
|
|
|
61 |
)
|
|
|
62 |
self.notebook_0.GetPage(0).GridAdd(self.wxgui_waterfallsink2_0_0.win, 1, 1, 1, 1)
|
|
|
63 |
self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
|
|
|
64 |
self.notebook_0.GetPage(0).GetWin(),
|
|
|
65 |
baseband_freq=0,
|
|
|
66 |
dynamic_range=100,
|
|
|
67 |
ref_level=0,
|
|
|
68 |
ref_scale=2.0,
|
|
|
69 |
sample_rate=samp_rate,
|
|
|
70 |
fft_size=512,
|
|
|
71 |
fft_rate=15,
|
|
|
72 |
average=False,
|
|
|
73 |
avg_alpha=None,
|
|
|
74 |
title="ADC2 Waterfall Plot",
|
|
|
75 |
win=window.hanning,
|
|
|
76 |
)
|
|
|
77 |
self.notebook_0.GetPage(0).GridAdd(self.wxgui_waterfallsink2_0.win, 2, 1, 1, 1)
|
|
|
78 |
self.wxgui_scopesink2_1 = scopesink2.scope_sink_f(
|
|
|
79 |
self.notebook_0.GetPage(0).GetWin(),
|
|
|
80 |
title="Scope Plot",
|
|
|
81 |
sample_rate=samp_rate/2,
|
|
|
82 |
v_scale=0,
|
|
|
83 |
v_offset=0,
|
|
|
84 |
t_scale=1e-2,
|
|
|
85 |
ac_couple=False,
|
|
|
86 |
xy_mode=False,
|
|
|
87 |
num_inputs=2,
|
|
|
88 |
trig_mode=wxgui.TRIG_MODE_AUTO,
|
|
|
89 |
y_axis_label="Counts",
|
|
|
90 |
)
|
|
|
91 |
self.notebook_0.GetPage(0).GridAdd(self.wxgui_scopesink2_1.win, 2, 2, 1, 1)
|
|
|
92 |
self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
|
|
|
93 |
self.notebook_0.GetPage(0).GetWin(),
|
|
|
94 |
title="Scope Plot",
|
|
|
95 |
sample_rate=samp_rate,
|
|
|
96 |
v_scale=0,
|
|
|
97 |
v_offset=0,
|
|
|
98 |
t_scale=0,
|
|
|
99 |
ac_couple=False,
|
|
|
100 |
xy_mode=False,
|
|
|
101 |
num_inputs=4,
|
|
|
102 |
trig_mode=wxgui.TRIG_MODE_AUTO,
|
|
|
103 |
y_axis_label="Counts",
|
|
|
104 |
)
|
|
|
105 |
self.notebook_0.GetPage(0).GridAdd(self.wxgui_scopesink2_0.win, 1, 2, 1, 1)
|
|
|
106 |
self.wxgui_numbersink2_1 = numbersink2.number_sink_f(
|
|
|
107 |
self.notebook_0.GetPage(2).GetWin(),
|
|
|
108 |
unit="Units",
|
|
|
109 |
minval=-100,
|
|
|
110 |
maxval=100,
|
|
|
111 |
factor=1.0,
|
|
|
112 |
decimal_places=10,
|
|
|
113 |
ref_level=0,
|
|
|
114 |
sample_rate=samp_rate,
|
|
|
115 |
number_rate=15,
|
|
|
116 |
average=False,
|
|
|
117 |
avg_alpha=None,
|
|
|
118 |
label="Number Plot",
|
|
|
119 |
peak_hold=False,
|
|
|
120 |
show_gauge=True,
|
|
|
121 |
)
|
|
|
122 |
self.notebook_0.GetPage(2).Add(self.wxgui_numbersink2_1.win)
|
|
|
123 |
self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
|
|
|
124 |
self.notebook_0.GetPage(2).GetWin(),
|
|
|
125 |
unit="Units",
|
|
|
126 |
minval=-100,
|
|
|
127 |
maxval=100,
|
|
|
128 |
factor=1.0,
|
|
|
129 |
decimal_places=10,
|
|
|
130 |
ref_level=0,
|
|
|
131 |
sample_rate=samp_rate,
|
|
|
132 |
number_rate=15,
|
|
|
133 |
average=False,
|
|
|
134 |
avg_alpha=None,
|
|
|
135 |
label="Number Plot",
|
|
|
136 |
peak_hold=False,
|
|
|
137 |
show_gauge=True,
|
|
|
138 |
)
|
|
|
139 |
self.notebook_0.GetPage(2).Add(self.wxgui_numbersink2_0.win)
|
|
|
140 |
self.wxgui_fftsink2_1 = fftsink2.fft_sink_c(
|
|
|
141 |
self.notebook_0.GetPage(1).GetWin(),
|
|
|
142 |
baseband_freq=0,
|
|
|
143 |
y_per_div=10,
|
|
|
144 |
y_divs=10,
|
|
|
145 |
ref_level=0,
|
|
|
146 |
ref_scale=2.0,
|
|
|
147 |
sample_rate=samp_rate,
|
|
|
148 |
fft_size=2048,
|
|
|
149 |
fft_rate=15,
|
|
|
150 |
average=False,
|
|
|
151 |
avg_alpha=None,
|
|
|
152 |
title="ADC 1 FFT Plot",
|
|
|
153 |
peak_hold=False,
|
|
|
154 |
win=window.hanning,
|
|
|
155 |
)
|
|
|
156 |
self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win)
|
|
|
157 |
self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
|
|
|
158 |
self.notebook_0.GetPage(1).GetWin(),
|
|
|
159 |
baseband_freq=0,
|
|
|
160 |
y_per_div=10,
|
|
|
161 |
y_divs=10,
|
|
|
162 |
ref_level=0,
|
|
|
163 |
ref_scale=2.0,
|
|
|
164 |
sample_rate=samp_rate,
|
|
|
165 |
fft_size=2048,
|
|
|
166 |
fft_rate=15,
|
|
|
167 |
average=False,
|
|
|
168 |
avg_alpha=None,
|
|
|
169 |
title="ADC 2 FFT Plot",
|
|
|
170 |
peak_hold=False,
|
|
|
171 |
win=window.hanning,
|
|
|
172 |
)
|
|
|
173 |
self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_0.win)
|
|
|
174 |
self.dc_blocker_xx_1 = filter.dc_blocker_cc(32, True)
|
|
|
175 |
self.dc_blocker_xx_0 = filter.dc_blocker_cc(32, True)
|
|
|
176 |
self.blocks_vector_to_streams_0 = blocks.vector_to_streams(gr.sizeof_short*1, 10)
|
|
|
177 |
self.blocks_throttle_2 = blocks.throttle(gr.sizeof_short*10, samp_rate/2)
|
|
|
178 |
self.blocks_short_to_float_2_0 = blocks.short_to_float(1, 1)
|
|
|
179 |
self.blocks_short_to_float_2 = blocks.short_to_float(1, 1)
|
|
|
180 |
self.blocks_short_to_float_1_0 = blocks.short_to_float(1, 1)
|
|
|
181 |
self.blocks_short_to_float_1 = blocks.short_to_float(1, 1)
|
|
|
182 |
self.blocks_short_to_float_0_0 = blocks.short_to_float(1, 1)
|
|
|
183 |
self.blocks_short_to_float_0 = blocks.short_to_float(1, 1)
|
|
|
184 |
self.blocks_interleave_0_2 = blocks.interleave(gr.sizeof_short*1)
|
|
|
185 |
self.blocks_interleave_0_1 = blocks.interleave(gr.sizeof_short*1)
|
|
|
186 |
self.blocks_interleave_0_0 = blocks.interleave(gr.sizeof_short*1)
|
|
|
187 |
self.blocks_interleave_0 = blocks.interleave(gr.sizeof_short*1)
|
|
|
188 |
self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1)
|
|
|
189 |
self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
|
|
|
190 |
self.blocks_file_source_0 = blocks.file_source(gr.sizeof_short*10, "/dev/xillybus_data2_r", False)
|
|
|
191 |
|
|
|
192 |
##################################################
|
|
|
193 |
# Connections
|
|
|
194 |
##################################################
|
|
|
195 |
self.connect((self.blocks_vector_to_streams_0, 2), (self.blocks_interleave_0_2, 0))
|
|
|
196 |
self.connect((self.blocks_vector_to_streams_0, 3), (self.blocks_interleave_0_2, 1))
|
|
|
197 |
self.connect((self.blocks_vector_to_streams_0, 4), (self.blocks_interleave_0_1, 0))
|
|
|
198 |
self.connect((self.blocks_vector_to_streams_0, 5), (self.blocks_interleave_0_1, 1))
|
|
|
199 |
self.connect((self.blocks_vector_to_streams_0, 6), (self.blocks_interleave_0_0, 0))
|
|
|
200 |
self.connect((self.blocks_vector_to_streams_0, 7), (self.blocks_interleave_0_0, 1))
|
|
|
201 |
self.connect((self.blocks_vector_to_streams_0, 8), (self.blocks_interleave_0, 0))
|
|
|
202 |
self.connect((self.blocks_vector_to_streams_0, 9), (self.blocks_interleave_0, 1))
|
|
|
203 |
self.connect((self.blocks_short_to_float_1, 0), (self.blocks_float_to_complex_0, 1))
|
|
|
204 |
self.connect((self.blocks_short_to_float_0, 0), (self.blocks_float_to_complex_0, 0))
|
|
|
205 |
self.connect((self.blocks_short_to_float_0_0, 0), (self.blocks_float_to_complex_0_0, 0))
|
|
|
206 |
self.connect((self.blocks_short_to_float_1_0, 0), (self.blocks_float_to_complex_0_0, 1))
|
|
|
207 |
self.connect((self.blocks_vector_to_streams_0, 0), (self.blocks_short_to_float_2, 0))
|
|
|
208 |
self.connect((self.blocks_vector_to_streams_0, 1), (self.blocks_short_to_float_2_0, 0))
|
|
|
209 |
self.connect((self.blocks_short_to_float_2, 0), (self.wxgui_scopesink2_1, 0))
|
|
|
210 |
self.connect((self.blocks_short_to_float_2_0, 0), (self.wxgui_scopesink2_1, 1))
|
|
|
211 |
self.connect((self.blocks_short_to_float_0_0, 0), (self.wxgui_scopesink2_0, 0))
|
|
|
212 |
self.connect((self.blocks_short_to_float_1_0, 0), (self.wxgui_scopesink2_0, 1))
|
|
|
213 |
self.connect((self.blocks_short_to_float_0, 0), (self.wxgui_scopesink2_0, 2))
|
|
|
214 |
self.connect((self.blocks_short_to_float_1, 0), (self.wxgui_scopesink2_0, 3))
|
|
|
215 |
self.connect((self.blocks_interleave_0_2, 0), (self.blocks_short_to_float_0_0, 0))
|
|
|
216 |
self.connect((self.blocks_interleave_0_1, 0), (self.blocks_short_to_float_1_0, 0))
|
|
|
217 |
self.connect((self.blocks_interleave_0_0, 0), (self.blocks_short_to_float_0, 0))
|
|
|
218 |
self.connect((self.blocks_interleave_0, 0), (self.blocks_short_to_float_1, 0))
|
|
|
219 |
self.connect((self.blocks_throttle_2, 0), (self.blocks_vector_to_streams_0, 0))
|
|
|
220 |
self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_2, 0))
|
|
|
221 |
self.connect((self.blocks_float_to_complex_0_0, 0), (self.dc_blocker_xx_0, 0))
|
|
|
222 |
self.connect((self.dc_blocker_xx_0, 0), (self.wxgui_waterfallsink2_0_0, 0))
|
|
|
223 |
self.connect((self.blocks_float_to_complex_0, 0), (self.dc_blocker_xx_1, 0))
|
|
|
224 |
self.connect((self.blocks_float_to_complex_0_0, 0), (self.wxgui_fftsink2_1, 0))
|
|
|
225 |
self.connect((self.blocks_float_to_complex_0, 0), (self.wxgui_fftsink2_0, 0))
|
|
|
226 |
self.connect((self.blocks_short_to_float_0, 0), (self.wxgui_numbersink2_1, 0))
|
|
|
227 |
self.connect((self.blocks_short_to_float_1, 0), (self.wxgui_numbersink2_0, 0))
|
|
|
228 |
self.connect((self.dc_blocker_xx_1, 0), (self.wxgui_waterfallsink2_0, 0))
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
# QT sink close method reimplementation
|
|
|
232 |
|
|
|
233 |
def get_prefix(self):
|
|
|
234 |
return self.prefix
|
|
|
235 |
|
|
|
236 |
def set_prefix(self, prefix):
|
|
|
237 |
self.prefix = prefix
|
|
|
238 |
self.set_recfile(self.prefix + datetime.now().strftime("%Y.%m.%d.%H.%M.%S") + ".dat")
|
|
|
239 |
|
|
|
240 |
def get_samp_rate(self):
|
|
|
241 |
return self.samp_rate
|
|
|
242 |
|
|
|
243 |
def set_samp_rate(self, samp_rate):
|
|
|
244 |
self.samp_rate = samp_rate
|
|
|
245 |
self.blocks_throttle_2.set_sample_rate(self.samp_rate/2)
|
|
|
246 |
self.wxgui_scopesink2_1.set_sample_rate(self.samp_rate/2)
|
|
|
247 |
self.wxgui_waterfallsink2_0_0.set_sample_rate(self.samp_rate)
|
|
|
248 |
self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate)
|
|
|
249 |
self.wxgui_waterfallsink2_0.set_sample_rate(self.samp_rate)
|
|
|
250 |
self.wxgui_fftsink2_0.set_sample_rate(self.samp_rate)
|
|
|
251 |
self.wxgui_fftsink2_1.set_sample_rate(self.samp_rate)
|
|
|
252 |
|
|
|
253 |
def get_recfile(self):
|
|
|
254 |
return self.recfile
|
|
|
255 |
|
|
|
256 |
def set_recfile(self, recfile):
|
|
|
257 |
self.recfile = recfile
|
|
|
258 |
|
|
|
259 |
if __name__ == '__main__':
|
|
|
260 |
import ctypes
|
|
|
261 |
import sys
|
|
|
262 |
if sys.platform.startswith('linux'):
|
|
|
263 |
try:
|
|
|
264 |
x11 = ctypes.cdll.LoadLibrary('libX11.so')
|
|
|
265 |
x11.XInitThreads()
|
|
|
266 |
except:
|
|
|
267 |
print "Warning: failed to XInitThreads()"
|
|
|
268 |
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
|
|
|
269 |
(options, args) = parser.parse_args()
|
|
|
270 |
tb = MLAB_ADC_Grabber()
|
|
|
271 |
tb.Start(True)
|
|
|
272 |
tb.Wait()
|
|
|
273 |
|