-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder_smart.py
executable file
·161 lines (140 loc) · 6.65 KB
/
decoder_smart.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Top Block
# Generated: Fri Dec 23 10:35:25 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 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 scopesink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import osmosdr
import time
import wx
from decoders import decoder_smart
import math
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.samp_rate = samp_rate = 2000000
self.freq_transition = freq_transition = 10000
self.freq_offset = freq_offset = 0
self.freq_cutoff = freq_cutoff = 50000
self.freq_center = freq_center = 433913000
self.fsk_deviation_hz = fsk_deviation_hz = 32000
##################################################
# Blocks
##################################################
self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
self.GetWin(),
title="Scope Plot",
sample_rate=samp_rate,
size=(1920/2,1060/2),
v_scale=0.2,
v_offset=0.6,
t_scale=0.001,
ac_couple=False,
xy_mode=False,
num_inputs=2,
trig_mode=wxgui.TRIG_MODE_AUTO,
y_axis_label="signal",
)
self.wxgui_scopesink2_0.set_trigger_level(0.1)
self.Add(self.wxgui_scopesink2_0.win)
self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
self.osmosdr_source_0.set_sample_rate(samp_rate)
self.osmosdr_source_0.set_center_freq(freq_center, 0)
self.osmosdr_source_0.set_freq_corr(0, 0)
self.osmosdr_source_0.set_dc_offset_mode(0, 0)
self.osmosdr_source_0.set_iq_balance_mode(0, 0)
self.osmosdr_source_0.set_gain_mode(False, 0)
self.osmosdr_source_0.set_gain(14, 0)
self.osmosdr_source_0.set_if_gain(40, 0)
self.osmosdr_source_0.set_bb_gain(20, 0)
self.osmosdr_source_0.set_antenna("", 0)
self.osmosdr_source_0.set_bandwidth(0, 0)
self.low_pass_filter_1 = filter.fir_filter_fff(1, firdes.low_pass(
1, samp_rate, 20000, 20000, firdes.WIN_HAMMING, 6.76))
self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass(
1, samp_rate, freq_cutoff, freq_transition, firdes.WIN_HAMMING, 6.76))
self.dc_blocker_xx_0 = filter.dc_blocker_cc(32, True)
self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq_offset, 1, 0)
self.decoder = decoder_smart(samp_rate)
self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(samp_rate/(2*math.pi*fsk_deviation_hz/8.0))
self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)
##################################################
# Connections
##################################################
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0))
self.connect((self.low_pass_filter_0, 0), (self.analog_quadrature_demod_cf_0, 0))
self.connect((self.analog_quadrature_demod_cf_0, 0), (self.low_pass_filter_1, 0))
self.connect((self.low_pass_filter_1, 0), (self.wxgui_scopesink2_0, 0))
self.connect((self.low_pass_filter_1, 0), (self.decoder, 0))
self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0))
self.connect((self.dc_blocker_xx_0, 0), (self.blocks_multiply_xx_0, 1))
self.connect((self.osmosdr_source_0, 0), (self.dc_blocker_xx_0, 0))
self.connect((self.low_pass_filter_0, 0), (self.blocks_complex_to_mag_0, 0))
self.connect((self.blocks_complex_to_mag_0, 0), (self.decoder, 1))
self.connect((self.blocks_complex_to_mag_0, 0), (self.wxgui_scopesink2_0, 1))
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_0.set_sampling_freq(self.samp_rate)
self.analog_quadrature_demod_cf_0.set_gain(self.samp_rate/(2*math.pi*self.fsk_deviation_hz/8.0))
self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, self.freq_cutoff, self.freq_transition, firdes.WIN_HAMMING, 6.76))
self.low_pass_filter_1.set_taps(firdes.low_pass(1, self.samp_rate, 20000, 20000, firdes.WIN_HAMMING, 6.76))
self.osmosdr_source_0.set_sample_rate(self.samp_rate)
self.decoder.set_sample_rate(self.samp_rate)
self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate)
def get_freq_transition(self):
return self.freq_transition
def set_freq_transition(self, freq_transition):
self.freq_transition = freq_transition
self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, self.freq_cutoff, self.freq_transition, firdes.WIN_HAMMING, 6.76))
def get_freq_offset(self):
return self.freq_offset
def set_freq_offset(self, freq_offset):
self.freq_offset = freq_offset
self.analog_sig_source_x_0.set_frequency(self.freq_offset)
def get_freq_cutoff(self):
return self.freq_cutoff
def set_freq_cutoff(self, freq_cutoff):
self.freq_cutoff = freq_cutoff
self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, self.freq_cutoff, self.freq_transition, firdes.WIN_HAMMING, 6.76))
def get_freq_center(self):
return self.freq_center
def set_freq_center(self, freq_center):
self.freq_center = freq_center
self.osmosdr_source_0.set_center_freq(self.freq_center, 0)
def main(top_block_cls=top_block, options=None):
tb = top_block_cls()
tb.Start(True)
tb.Wait()
if __name__ == '__main__':
main()