def __init__(self, talkgroup, options):
		gr.hier_block2.__init__(self, "fsk_demod",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature(0, 0, gr.sizeof_char)) # Output signature

		#print "Starting log_receiver init()"
		self.samp_rate = samp_rate = int(options.rate)
		self.samp_per_sym = samp_per_sym = 5+1
		self.decim = decim = 20
		self.xlate_bandwidth = xlate_bandwidth = 24260.0
		self.xlate_offset = xlate_offset = 0
		self.channel_rate = channel_rate = op25.SYMBOL_RATE*samp_per_sym
		self.audio_mul = audio_mul = 2
		self.pre_channel_rate = pre_channel_rate = int(samp_rate/decim)


		self.auto_tune_offset = auto_tune_offset = 0	
		self.audiorate = 44100 #options.audiorate
		self.rate = options.rate
		self.talkgroup = talkgroup
		self.directory = options.directory

		if options.squelch is None:
			options.squelch = 28

		if options.volume is None:
			options.volume = 3.0


		##################################################
		# Message Queues
		##################################################
		op25_fsk4_0_msgq_out = baz_message_callback_0_msgq_in = gr.msg_queue(2)
		op25_decoder_simple_0_msgq_out = op25_traffic_pane_0_msgq_in = gr.msg_queue(2)

		##################################################
		# Blocks
		##################################################

		self.op25_fsk4_0 = op25.op25_fsk4(channel_rate=channel_rate, auto_tune_msgq=op25_fsk4_0_msgq_out,)
		self.op25_decoder_simple_0 = op25.op25_decoder_simple(key="",traffic_msgq=op25_decoder_simple_0_msgq_out,)
		self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf((channel_rate/(2.0 * math.pi * op25.SYMBOL_DEVIATION)))
		self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(decim, 
										       (firdes.low_pass(1, samp_rate, xlate_bandwidth/2, 4000)),
										       0, 
										       samp_rate)
		self.gr_fir_filter_xxx_0 = gr.fir_filter_fff(1, ((1.0/samp_per_sym,)*samp_per_sym))



		
		self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((10.**(audio_mul/10.), ))
		self.blks2_rational_resampler_xxx_1 = blks2.rational_resampler_ccc(
			interpolation=channel_rate,
			decimation=pre_channel_rate,
			taps=None,
			fractional_bw=None,
		)
		self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff(
			interpolation=self.audiorate,
			decimation=8000,
			taps=None,
			fractional_bw=None,
		)
		self.baz_message_callback_0 = message_callback.message_callback(msgq=baz_message_callback_0_msgq_in,	callback=auto_tune_offset	, msg_part="arg1", custom_parts="",	dummy=False)
			

		#here we generate a random filename in the form /tmp/[random].wav, and then use it for the wavstamp block. this avoids collisions later on. remember to clean up these files when deallocating.

		self.tmpfilename = "/tmp/%s.wav" % ("".join([random.choice(string.letters+string.digits) for x in range(8)])) #if this looks glaringly different, it's because i totally cribbed it from a blog.

		self.valve = grc_blks2.valve(gr.sizeof_float, bool(1))


		#open the logfile for appending
		self.timestampfilename = "%s/%i.txt" % (self.directory, self.talkgroup)
		self.timestampfile = open(self.timestampfilename, 'a');

		self.filename = "%s/%i.wav" % (self.directory, self.talkgroup)
		self.audiosink = smartnet.wavsink(self.filename, 1, self.audiorate, 8) #this version allows appending to existing files.

		self.audio_sink_0 = audio.sink(44100, "", True)


		self.timestamp = 0.0

		#print "Finishing logging receiver init()."

		self.mute() #start off muted.



	##################################################
	# Connections
		##################################################
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.blks2_rational_resampler_xxx_1, 0))
		self.connect((self.blks2_rational_resampler_xxx_1, 0), (self.gr_quadrature_demod_cf_0, 0))
		self.connect((self.gr_quadrature_demod_cf_0, 0), (self.gr_fir_filter_xxx_0, 0))
		self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0))

		self.connect((self.gr_fir_filter_xxx_0, 0), (self.op25_fsk4_0, 0))
		self.connect((self.op25_fsk4_0, 0), (self.op25_decoder_simple_0, 0))
		self.connect((self.op25_decoder_simple_0, 0), (self.blks2_rational_resampler_xxx_0, 0))

		## Start
		self.connect(self, (self.gr_freq_xlating_fir_filter_xxx_0, 0))

		## End
		self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0,0))
Пример #2
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Op25 Grc")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self._config_freq_config = ConfigParser.ConfigParser()
        self._config_freq_config.read(".grc_op25")
        try:
            config_freq = self._config_freq_config.getfloat("main", "freq")
        except:
            config_freq = 489075000
        self.config_freq = config_freq
        self.freq = freq = config_freq
        self._config_xlate_offset_config = ConfigParser.ConfigParser()
        self._config_xlate_offset_config.read(".grc_op25")
        try:
            config_xlate_offset = self._config_xlate_offset_config.getfloat(
                "main", "xlate_offset")
        except:
            config_xlate_offset = 0
        self.config_xlate_offset = config_xlate_offset
        self.click_freq = click_freq = freq - config_xlate_offset
        self.xlate_offset_fine = xlate_offset_fine = 0
        self.xlate_offset = xlate_offset = freq - click_freq
        self.samp_rate = samp_rate = 2000000
        self.samp_per_sym = samp_per_sym = 6
        self.decim = decim = 20
        self._config_xlate_bandwidth_config = ConfigParser.ConfigParser()
        self._config_xlate_bandwidth_config.read(".grc_op25")
        try:
            config_xlate_bandwidth = self._config_xlate_bandwidth_config.getfloat(
                "main", "xlate_bandwidth")
        except:
            config_xlate_bandwidth = 24000
        self.config_xlate_bandwidth = config_xlate_bandwidth
        self.auto_tune_offset = auto_tune_offset = 0
        self.xlate_bandwidth = xlate_bandwidth = config_xlate_bandwidth
        self.variable_static_text_0 = variable_static_text_0 = freq + xlate_offset + xlate_offset_fine + auto_tune_offset
        self.pre_channel_rate = pre_channel_rate = samp_rate / decim
        self.gain = gain = 20
        self.fine_click_freq = fine_click_freq = 0
        self.channel_rate = channel_rate = op25.SYMBOL_RATE * samp_per_sym
        self.auto_tune_offset_freq = auto_tune_offset_freq = auto_tune_offset * op25.SYMBOL_DEVIATION
        self.audio_mul = audio_mul = 0

        ##################################################
        # Message Queues
        ##################################################
        op25_decoder_simple_0_msgq_out = op25_traffic_pane_0_msgq_in = gr.msg_queue(
            2)
        op25_fsk4_0_msgq_out = baz_message_callback_0_msgq_in = gr.msg_queue(2)

        ##################################################
        # Blocks
        ##################################################
        _xlate_offset_fine_sizer = wx.BoxSizer(wx.VERTICAL)
        self._xlate_offset_fine_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_xlate_offset_fine_sizer,
            value=self.xlate_offset_fine,
            callback=self.set_xlate_offset_fine,
            label="Fine Offset",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._xlate_offset_fine_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_xlate_offset_fine_sizer,
            value=self.xlate_offset_fine,
            callback=self.set_xlate_offset_fine,
            minimum=-10000,
            maximum=10000,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_xlate_offset_fine_sizer)
        self._xlate_offset_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.xlate_offset,
            callback=self.set_xlate_offset,
            label="Xlate Offset",
            converter=forms.float_converter(),
        )
        self.Add(self._xlate_offset_text_box)
        _xlate_bandwidth_sizer = wx.BoxSizer(wx.VERTICAL)
        self._xlate_bandwidth_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_xlate_bandwidth_sizer,
            value=self.xlate_bandwidth,
            callback=self.set_xlate_bandwidth,
            label="Xlate BW",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._xlate_bandwidth_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_xlate_bandwidth_sizer,
            value=self.xlate_bandwidth,
            callback=self.set_xlate_bandwidth,
            minimum=5000,
            maximum=50000,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_xlate_bandwidth_sizer)
        self.nb = self.nb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "BB-1")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "BB-2")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Xlate-1")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Xlate-2")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "4FSK")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Dibits")
        self.nb.AddPage(grc_wxgui.Panel(self.nb), "Traffic")
        self.Add(self.nb)
        _gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_gain_sizer,
            value=self.gain,
            callback=self.set_gain,
            label="Gain",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_gain_sizer,
            value=self.gain,
            callback=self.set_gain,
            minimum=0,
            maximum=50,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_gain_sizer)
        self._freq_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.freq,
            callback=self.set_freq,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.Add(self._freq_text_box)
        self._auto_tune_offset_freq_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.auto_tune_offset_freq,
            callback=self.set_auto_tune_offset_freq,
            label="Auto tune",
            converter=forms.float_converter(),
        )
        self.Add(self._auto_tune_offset_freq_static_text)
        _audio_mul_sizer = wx.BoxSizer(wx.VERTICAL)
        self._audio_mul_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_audio_mul_sizer,
            value=self.audio_mul,
            callback=self.set_audio_mul,
            label="Audio mul",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._audio_mul_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_audio_mul_sizer,
            value=self.audio_mul,
            callback=self.set_audio_mul,
            minimum=-30,
            maximum=10,
            num_steps=40,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_audio_mul_sizer)
        self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c(
            self.nb.GetPage(3).GetWin(),
            baseband_freq=0,
            dynamic_range=100,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=channel_rate,
            fft_size=512,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Waterfall Plot",
        )
        self.nb.GetPage(3).Add(self.wxgui_waterfallsink2_0_0.win)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
            self.nb.GetPage(1).GetWin(),
            baseband_freq=freq,
            dynamic_range=100,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=512,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Waterfall Plot",
        )
        self.nb.GetPage(1).Add(self.wxgui_waterfallsink2_0.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_f(
            self.nb.GetPage(4).GetWin(),
            title="Scope Plot",
            sample_rate=channel_rate,
            v_scale=1.5,
            v_offset=0,
            t_scale=0.05,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.nb.GetPage(4).Add(self.wxgui_scopesink2_1.win)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
            self.nb.GetPage(5).GetWin(),
            title="Scope Plot",
            sample_rate=op25.SYMBOL_RATE,
            v_scale=1,
            v_offset=0,
            t_scale=0.05,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.nb.GetPage(5).Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c(
            self.nb.GetPage(2).GetWin(),
            baseband_freq=fine_click_freq,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=channel_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        self.nb.GetPage(2).Add(self.wxgui_fftsink2_0_0.win)

        def wxgui_fftsink2_0_0_callback(x, y):
            self.set_fine_click_freq(x)

        self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.nb.GetPage(0).GetWin(),
            baseband_freq=freq,
            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=True,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        self.nb.GetPage(0).Add(self.wxgui_fftsink2_0.win)

        def wxgui_fftsink2_0_callback(x, y):
            self.set_click_freq(x)

        self.wxgui_fftsink2_0.set_callback(wxgui_fftsink2_0_callback)
        self._variable_static_text_0_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.variable_static_text_0,
            callback=self.set_variable_static_text_0,
            label="Final freq",
            converter=forms.float_converter(),
        )
        self.Add(self._variable_static_text_0_static_text)
        self.osmosdr_source_c_0 = osmosdr.source_c(args="nchan=" + str(1) +
                                                   " " + "hackrf=0")
        self.osmosdr_source_c_0.set_sample_rate(samp_rate)
        self.osmosdr_source_c_0.set_center_freq(freq, 0)
        self.osmosdr_source_c_0.set_freq_corr(0, 0)
        self.osmosdr_source_c_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_c_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_c_0.set_gain_mode(0, 0)
        self.osmosdr_source_c_0.set_gain(14, 0)
        self.osmosdr_source_c_0.set_if_gain(gain, 0)
        self.osmosdr_source_c_0.set_bb_gain(gain, 0)
        self.osmosdr_source_c_0.set_antenna("", 0)
        self.osmosdr_source_c_0.set_bandwidth(0, 0)

        self.op25_traffic_pane_0 = op25_traffic_pane.TrafficPane(
            parent=self.nb.GetPage(6).GetWin(),
            msgq=op25_traffic_pane_0_msgq_in)
        self.nb.GetPage(6).Add(self.op25_traffic_pane_0)
        self.op25_fsk4_0 = op25.op25_fsk4(
            channel_rate=channel_rate,
            auto_tune_msgq=op25_fsk4_0_msgq_out,
        )
        self.op25_decoder_simple_0 = op25.op25_decoder_simple(
            key="",
            traffic_msgq=op25_decoder_simple_0_msgq_out,
        )
        self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf(
            (channel_rate / (2.0 * math.pi * op25.SYMBOL_DEVIATION)))
        self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(
            decim, (firdes.low_pass(1, samp_rate, xlate_bandwidth / 2, 6000)),
            xlate_offset + xlate_offset_fine - fine_click_freq -
            auto_tune_offset_freq, samp_rate)
        self.gr_fir_filter_xxx_0 = gr.fir_filter_fff(
            1, ((1.0 / samp_per_sym, ) * samp_per_sym))
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff(
            (10.**(audio_mul / 10.), ))
        self.blks2_rational_resampler_xxx_1 = blks2.rational_resampler_ccc(
            interpolation=channel_rate,
            decimation=pre_channel_rate,
            taps=None,
            fractional_bw=None,
        )
        self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff(
            interpolation=44100,
            decimation=8000,
            taps=None,
            fractional_bw=None,
        )
        self.baz_message_callback_0 = message_callback.message_callback(
            msgq=baz_message_callback_0_msgq_in,
            callback=auto_tune_offset,
            msg_part="arg1",
            custom_parts="",
            dummy=False)

        self.audio_sink_0 = audio.sink(44100, "", True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0),
                     (self.blks2_rational_resampler_xxx_1, 0))
        self.connect((self.blks2_rational_resampler_xxx_1, 0),
                     (self.wxgui_fftsink2_0_0, 0))
        self.connect((self.blks2_rational_resampler_xxx_1, 0),
                     (self.wxgui_waterfallsink2_0_0, 0))
        self.connect((self.blks2_rational_resampler_xxx_1, 0),
                     (self.gr_quadrature_demod_cf_0, 0))
        self.connect((self.gr_quadrature_demod_cf_0, 0),
                     (self.gr_fir_filter_xxx_0, 0))
        self.connect((self.gr_fir_filter_xxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.blks2_rational_resampler_xxx_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.audio_sink_0, 0))
        self.connect((self.gr_fir_filter_xxx_0, 0), (self.op25_fsk4_0, 0))
        self.connect((self.op25_decoder_simple_0, 0),
                     (self.blks2_rational_resampler_xxx_0, 0))
        self.connect((self.op25_fsk4_0, 0), (self.wxgui_scopesink2_0, 0))
        self.connect((self.osmosdr_source_c_0, 0),
                     (self.wxgui_waterfallsink2_0, 0))
        self.connect((self.osmosdr_source_c_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.osmosdr_source_c_0, 0),
                     (self.gr_freq_xlating_fir_filter_xxx_0, 0))
        self.connect((self.op25_fsk4_0, 0), (self.op25_decoder_simple_0, 0))