4898 |
kaklik |
1 |
#!/usr/bin/env python2 |
|
|
2 |
# -*- coding: utf-8 -*- |
|
|
3 |
################################################## |
|
|
4 |
# GNU Radio Python Flow Graph |
|
|
5 |
# Title: Acpmeter |
|
|
6 |
# Generated: Tue Dec 20 08:12:39 2016 |
|
|
7 |
################################################## |
|
|
8 |
|
|
|
9 |
if __name__ == '__main__': |
|
|
10 |
import ctypes |
|
|
11 |
import sys |
|
|
12 |
if sys.platform.startswith('linux'): |
|
|
13 |
try: |
|
|
14 |
x11 = ctypes.cdll.LoadLibrary('libX11.so') |
|
|
15 |
x11.XInitThreads() |
|
|
16 |
except: |
|
|
17 |
print "Warning: failed to XInitThreads()" |
|
|
18 |
|
|
|
19 |
from gnuradio import blocks |
|
|
20 |
from gnuradio import eng_notation |
|
|
21 |
from gnuradio import filter |
|
|
22 |
from gnuradio import gr |
|
|
23 |
from gnuradio import wxgui |
|
|
24 |
from gnuradio.eng_option import eng_option |
|
|
25 |
from gnuradio.filter import firdes |
|
|
26 |
from gnuradio.wxgui import scopesink2 |
|
|
27 |
from grc_gnuradio import blks2 as grc_blks2 |
|
|
28 |
from grc_gnuradio import wxgui as grc_wxgui |
|
|
29 |
from optparse import OptionParser |
|
|
30 |
import wx |
|
|
31 |
|
|
|
32 |
|
|
|
33 |
class ACPmeter(grc_wxgui.top_block_gui): |
|
|
34 |
|
|
|
35 |
def __init__(self): |
|
|
36 |
grc_wxgui.top_block_gui.__init__(self, title="Acpmeter") |
|
|
37 |
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" |
|
|
38 |
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) |
|
|
39 |
|
|
|
40 |
################################################## |
|
|
41 |
# Variables |
|
|
42 |
################################################## |
|
|
43 |
self.samp_rate = samp_rate = 96000 |
|
|
44 |
|
|
|
45 |
################################################## |
|
|
46 |
# Blocks |
|
|
47 |
################################################## |
|
|
48 |
self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( |
|
|
49 |
self.GetWin(), |
|
|
50 |
title="Scope Plot", |
|
|
51 |
sample_rate=9600, |
|
|
52 |
v_scale=0, |
|
|
53 |
v_offset=0, |
|
|
54 |
t_scale=0, |
|
|
55 |
ac_couple=False, |
|
|
56 |
xy_mode=False, |
|
|
57 |
num_inputs=1, |
|
|
58 |
trig_mode=wxgui.TRIG_MODE_AUTO, |
|
|
59 |
y_axis_label="Power [Watts]", |
|
|
60 |
) |
|
|
61 |
self.Add(self.wxgui_scopesink2_0.win) |
|
|
62 |
self.fir_filter_xxx_0 = filter.fir_filter_fff(10, (firdes.low_pass(1, samp_rate, 100, 100, firdes.WIN_BLACKMAN_HARRIS))) |
|
|
63 |
self.fir_filter_xxx_0.declare_sample_delay(0) |
|
|
64 |
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) |
|
|
65 |
self.blocks_rms_xx_0 = blocks.rms_ff(0.1) |
|
|
66 |
self.blocks_multiply_xx_0 = blocks.multiply_vff(1) |
|
|
67 |
self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((1, )) |
|
|
68 |
self.blocks_complex_to_float_0 = blocks.complex_to_float(1) |
|
|
69 |
self.blocks_abs_xx_0 = blocks.abs_ff(1) |
|
|
70 |
self.blks2_tcp_source_0 = grc_blks2.tcp_source( |
|
|
71 |
itemsize=gr.sizeof_gr_complex*1, |
|
|
72 |
addr="127.0.0.1", |
|
|
73 |
port=3701, |
|
|
74 |
server=False, |
|
|
75 |
) |
|
|
76 |
|
|
|
77 |
################################################## |
|
|
78 |
# Connections |
|
|
79 |
################################################## |
|
|
80 |
self.connect((self.blks2_tcp_source_0, 0), (self.blocks_throttle_0, 0)) |
|
|
81 |
self.connect((self.blocks_abs_xx_0, 0), (self.blocks_rms_xx_0, 0)) |
|
|
82 |
self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0)) |
|
|
83 |
self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_xx_0, 1)) |
|
|
84 |
self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0)) |
|
|
85 |
self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_abs_xx_0, 0)) |
|
|
86 |
self.connect((self.blocks_rms_xx_0, 0), (self.fir_filter_xxx_0, 0)) |
|
|
87 |
self.connect((self.blocks_throttle_0, 0), (self.blocks_complex_to_float_0, 0)) |
|
|
88 |
self.connect((self.fir_filter_xxx_0, 0), (self.wxgui_scopesink2_0, 0)) |
|
|
89 |
|
|
|
90 |
def get_samp_rate(self): |
|
|
91 |
return self.samp_rate |
|
|
92 |
|
|
|
93 |
def set_samp_rate(self, samp_rate): |
|
|
94 |
self.samp_rate = samp_rate |
|
|
95 |
self.blocks_throttle_0.set_sample_rate(self.samp_rate) |
|
|
96 |
self.fir_filter_xxx_0.set_taps((firdes.low_pass(1, self.samp_rate, 100, 100, firdes.WIN_BLACKMAN_HARRIS))) |
|
|
97 |
|
|
|
98 |
|
|
|
99 |
def main(top_block_cls=ACPmeter, options=None): |
|
|
100 |
|
|
|
101 |
tb = top_block_cls() |
|
|
102 |
tb.Start(True) |
|
|
103 |
tb.Wait() |
|
|
104 |
|
|
|
105 |
|
|
|
106 |
if __name__ == '__main__': |
|
|
107 |
main() |