-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvid.py
203 lines (180 loc) · 7.12 KB
/
vid.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Vid
# Generated: Fri Aug 19 13:31:28 2016
##################################################
if __name__ == '__main__':
import ctypes
import sys
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
from gnuradio import analog
from gnuradio import blocks
from gnuradio import digital
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from gnuradio.wxgui import forms
from grc_gnuradio import blks2 as grc_blks2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import threading
import time
import wx
class vid(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Vid")
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
##################################################
# Variables
##################################################
self.variable_slider_1 = variable_slider_1 = 500
self.variable_slider_0 = variable_slider_0 = 0
self.snr = snr = 0
self.samp_rate = samp_rate = 32000
##################################################
# Blocks
##################################################
_variable_slider_1_sizer = wx.BoxSizer(wx.VERTICAL)
self._variable_slider_1_text_box = forms.text_box(
parent=self.GetWin(),
sizer=_variable_slider_1_sizer,
value=self.variable_slider_1,
callback=self.set_variable_slider_1,
label="signal",
converter=forms.float_converter(),
proportion=0,
)
self._variable_slider_1_slider = forms.slider(
parent=self.GetWin(),
sizer=_variable_slider_1_sizer,
value=self.variable_slider_1,
callback=self.set_variable_slider_1,
minimum=0,
maximum=1000,
num_steps=100,
style=wx.SL_HORIZONTAL,
cast=float,
proportion=1,
)
self.Add(_variable_slider_1_sizer)
_variable_slider_0_sizer = wx.BoxSizer(wx.VERTICAL)
self._variable_slider_0_text_box = forms.text_box(
parent=self.GetWin(),
sizer=_variable_slider_0_sizer,
value=self.variable_slider_0,
callback=self.set_variable_slider_0,
label="noise",
converter=forms.float_converter(),
proportion=0,
)
self._variable_slider_0_slider = forms.slider(
parent=self.GetWin(),
sizer=_variable_slider_0_sizer,
value=self.variable_slider_0,
callback=self.set_variable_slider_0,
minimum=0,
maximum=100,
num_steps=100,
style=wx.SL_HORIZONTAL,
cast=float,
proportion=1,
)
self.Add(_variable_slider_0_sizer)
def _snr_probe():
while True:
val = self.my_block_0.get_number()
try:
self.set_snr(val)
except AttributeError:
pass
time.sleep(1.0 / (10))
_snr_thread = threading.Thread(target=_snr_probe)
_snr_thread.daemon = True
_snr_thread.start()
self.digital_gmsk_mod_0 = digital.gmsk_mod(
samples_per_symbol=2,
bt=0.35,
verbose=False,
log=False,
)
self.digital_gmsk_demod_0 = digital.gmsk_demod(
samples_per_symbol=2,
gain_mu=0.175,
mu=0.5,
omega_relative_limit=0.005,
freq_error=0.0,
verbose=False,
log=False,
)
self.blocks_probe_signal_x_0 = blocks.probe_signal_f()
self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0)
self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((500, ))
self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "video1.ts", False)
self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, "video2.ts", False)
self.blocks_file_sink_0.set_unbuffered(False)
self.blocks_add_xx_0 = blocks.add_vcc(1)
self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b(grc_blks2.packet_encoder(
samples_per_symbol=2,
bits_per_symbol=1,
preamble="",
access_code="",
pad_for_usrp=True,
),
payload_length=0,
)
self.blks2_packet_decoder_0 = grc_blks2.packet_demod_c(grc_blks2.packet_decoder(
access_code="",
threshold=-1,
callback=lambda ok, payload: self.blks2_packet_decoder_0.recv_pkt(ok, payload),
),
)
self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 0, 0)
self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 2500)
##################################################
# Connections
##################################################
self.connect((self.analog_const_source_x_0, 0), (self.blocks_nlog10_ff_0, 0))
self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
self.connect((self.blks2_packet_decoder_0, 0), (self.blocks_file_sink_0, 0))
self.connect((self.blks2_packet_encoder_0, 0), (self.digital_gmsk_mod_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.digital_gmsk_demod_0, 0))
self.connect((self.blocks_file_source_0, 0), (self.blks2_packet_encoder_0, 0))
self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 0))
self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_probe_signal_x_0, 0))
self.connect((self.digital_gmsk_demod_0, 0), (self.blks2_packet_decoder_0, 0))
self.connect((self.digital_gmsk_mod_0, 0), (self.blocks_multiply_const_vxx_0, 0))
def get_variable_slider_1(self):
return self.variable_slider_1
def set_variable_slider_1(self, variable_slider_1):
self.variable_slider_1 = variable_slider_1
self._variable_slider_1_slider.set_value(self.variable_slider_1)
self._variable_slider_1_text_box.set_value(self.variable_slider_1)
def get_variable_slider_0(self):
return self.variable_slider_0
def set_variable_slider_0(self, variable_slider_0):
self.variable_slider_0 = variable_slider_0
self._variable_slider_0_slider.set_value(self.variable_slider_0)
self._variable_slider_0_text_box.set_value(self.variable_slider_0)
def get_snr(self):
return self.snr
def set_snr(self, snr):
self.snr = snr
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
def main(top_block_cls=vid, options=None):
tb = top_block_cls()
tb.Start(True)
tb.Wait()
if __name__ == '__main__':
main()