コード例 #1
1
ファイル: smartnet2decode.py プロジェクト: Tincer/gr-smartnet
	def __init__(self, options, queue):
		gr.top_block.__init__(self)

		if options.filename is not None:
			self.fs = gr.file_source(gr.sizeof_gr_complex, options.filename)
			self.rate = options.rate

		else:
			self.u = uhd.usrp_source(options.addr,
									 io_type=uhd.io_type.COMPLEX_FLOAT32,
									 num_channels=1)

			if options.subdev is not None:
				self.u.set_subdev_spec(options.subdev, 0)
				
			self.u.set_samp_rate(options.rate)
			self.rate = self.u.get_samp_rate()

			# Set the antenna
			if(options.antenna):
				self.u.set_antenna(options.antenna, 0)
			
			self.centerfreq = options.centerfreq
			print "Tuning to: %fMHz" % (self.centerfreq - options.error)
			if not(self.tune(options.centerfreq - options.error)):
				print "Failed to set initial frequency"

			if options.gain is None: #set to halfway
				g = self.u.get_gain_range()
				options.gain = (g.start()+g.stop()) / 2.0

			print "Setting gain to %i" % options.gain
			self.u.set_gain(options.gain)

			self.u.set_bandwidth(options.bandwidth)

		print "Samples per second is %i" % self.rate

		self._syms_per_sec = 3600;


		options.samples_per_second = self.rate
		options.syms_per_sec = self._syms_per_sec
		options.gain_mu = 0.01
		options.mu=0.5
		options.omega_relative_limit = 0.3
		options.syms_per_sec = self._syms_per_sec
		options.offset = options.centerfreq - options.freq
		print "Control channel offset: %f" % options.offset

		self.demod = fsk_demod(options)
		self.start_correlator = gr.correlate_access_code_tag_bb("10101100",
		                                                        0,
		                                                        "smartnet_preamble") #should mark start of packet
		self.smartnet_deinterleave = smartnet.deinterleave()
		self.smartnet_crc = smartnet.crc(queue)

		if options.filename is None:
			self.connect(self.u, self.demod)
		else:
			self.connect(self.fs, self.demod)

		self.connect(self.demod, self.start_correlator, self.smartnet_deinterleave, self.smartnet_crc)

		#hook up the audio patch
		if options.audio:
			self.audiorate = 48000
			self.audiotaps = gr.firdes.low_pass(1, self.rate, 8000, 2000, gr.firdes.WIN_HANN)
			self.prefilter_decim = int(self.rate / self.audiorate) #might have to use a rational resampler for audio
			print "Prefilter decimation: %i" % self.prefilter_decim
			self.audio_prefilter = gr.freq_xlating_fir_filter_ccf(self.prefilter_decim, #decimation
									      self.audiotaps, #taps
									      0, #freq offset
									      self.rate) #sampling rate

			#on a trunked network where you know you will have good signal, a carrier power squelch works well. real FM receviers use a noise squelch, where
			#the received audio is high-passed above the cutoff and then fed to a reverse squelch. If the power is then BELOW a threshold, open the squelch.
			self.squelch = gr.pwr_squelch_cc(options.squelch, #squelch point
											   alpha = 0.1, #wat
											   ramp = 10, #wat
											   gate = False)

			self.audiodemod = blks2.fm_demod_cf(self.rate/self.prefilter_decim, #rate
							    1, #audio decimation
							    4000, #deviation
							    3000, #audio passband
							    4000, #audio stopband
							    1, #gain
							    75e-6) #deemphasis constant

			#the filtering removes FSK data woobling from the subaudible channel (might be able to combine w/lpf above)
			self.audiofilttaps = gr.firdes.high_pass(1, self.audiorate, 300, 50, gr.firdes.WIN_HANN)
			self.audiofilt = gr.fir_filter_fff(1, self.audiofilttaps)
			self.audiogain = gr.multiply_const_ff(options.volume)
			self.audiosink = audio.sink (self.audiorate, "")
#			self.audiosink = gr.wavfile_sink("test.wav", 1, self.audiorate, 8)

			self.mute()

			if options.filename is None:
				self.connect(self.u, self.audio_prefilter)
			else:
				self.connect(self.fs, self.audio_prefilter)

#			self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audioresamp, self.audiosink)
			self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audiosink)
コード例 #2
0
	def __init__(self, options, queue):
		gr.top_block.__init__(self)

		self.u = uhd.usrp_source(options.addr,
								 io_type=uhd.io_type.COMPLEX_FLOAT32,
								 num_channels=1)

		if options.subdev is not None:
			self.u.set_subdev_spec(options.subdev, 0)
		self.u.set_samp_rate(options.rate)
		self.rate = self.u.get_samp_rate()

		# Set the antenna
		if(options.antenna):
			self.u.set_antenna(options.antenna, 0)
		
		self.centerfreq = options.centerfreq
		print "Tuning to: %fMHz" % (self.centerfreq - options.error)
		if not(self.tune(options.centerfreq - options.error)):
			print "Failed to set initial frequency"

		if options.gain is None: #set to halfway
			g = self.u.get_gain_range()
			options.gain = (g.start()+g.stop()) / 2.0

		print "Setting gain to %i" % options.gain
		self.u.set_gain(options.gain)

		self.u.set_bandwidth(options.bandwidth)
		
		print "Samples per second is %i" % self.rate

		self._syms_per_sec = 3600;

		options.audiorate = 11025
		options.rate = self.rate

		options.samples_per_second = self.rate #yeah i know it's on the list
		options.syms_per_sec = self._syms_per_sec
		options.gain_mu = 0.01
		options.mu=0.5
		options.omega_relative_limit = 0.3
		options.syms_per_sec = self._syms_per_sec
		options.offset = options.centerfreq - options.freq
		print "Control channel offset: %f" % options.offset

		self.demod = fsk_demod(options)
		self.start_correlator = digital.correlate_access_code_bb("10101100",0) #should mark start of packet
		self.smartnet_sync = smartnet.sync()
		self.smartnet_deinterleave = smartnet.deinterleave()
		self.smartnet_parity = smartnet.parity()
		self.smartnet_crc = smartnet.crc()
		self.smartnet_packetize = smartnet.packetize()
		self.parse = smartnet.parse(queue) #packet-based. this simply posts lightly-formatted messages to the queue.

		self.connect(self.u, self.demod)

		self.connect(self.demod, self.start_correlator, self.smartnet_sync, self.smartnet_deinterleave, self.smartnet_parity, self.smartnet_crc, self.smartnet_packetize, self.parse)
コード例 #3
0
	def __init__(self, options, queue):
		gr.top_block.__init__(self)

		self.u = usrp.source_c()
		self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
		self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
		print "Using RX d'board %s" % self.subdev.side_and_name()
		self.u.set_decim_rate(options.decim)
		self.centerfreq = options.centerfreq
		print "Tuning to: %fMHz" % (self.centerfreq - options.error)
		if not(self.tune(options.centerfreq - options.error)):
			print "Failed to set initial frequency"
	
		if options.gain is None: #set to halfway
			g = self.subdev.gain_range()
			options.gain = (g[0]+g[1]) / 2.0

		print "Setting gain to %i" % options.gain
		self.subdev.set_gain(options.gain)

		if self.subdev.name() == "DBS Rx":
			self.subdev.set_bw(options.bandwidth) #only for DBSRX
			print "Setting DBS RX bandwidth to %fMHz" % float(options.bandwidth / 1e6)

		self.rate = self.u.adc_rate() / options.decim
		
		print "Samples per second is %i" % self.rate

		self._syms_per_sec = 3600;

		options.audiorate = 11025
		options.rate = self.rate

		options.samples_per_second = self.rate #yeah i know it's on the list
		options.syms_per_sec = self._syms_per_sec
		options.gain_mu = 0.01
		options.mu=0.5
		options.omega_relative_limit = 0.3
		options.syms_per_sec = self._syms_per_sec
		options.offset = options.centerfreq - options.freq
		print "Control channel offset: %f" % options.offset

		self.demod = fsk_demod(options)
		self.start_correlator = gr.correlate_access_code_bb("10101100",0) #should mark start of packet
		self.smartnet_sync = smartnet.sync()
		self.smartnet_deinterleave = smartnet.deinterleave()
		self.smartnet_parity = smartnet.parity()
		self.smartnet_crc = smartnet.crc()
		self.smartnet_packetize = smartnet.packetize()
		self.parse = smartnet.parse(queue) #packet-based. this simply posts lightly-formatted messages to the queue.

		self.connect(self.u, self.demod)

		self.connect(self.demod, self.start_correlator, self.smartnet_sync, self.smartnet_deinterleave, self.smartnet_parity, self.smartnet_crc, self.smartnet_packetize, self.parse)
コード例 #4
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self)

        self.u = usrp.source_c()
        self.u.set_mux(
            usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
        print "Using RX d'board %s" % self.subdev.side_and_name()
        self.u.set_decim_rate(options.decim)
        self.centerfreq = options.centerfreq
        print "Tuning to: %fMHz" % (self.centerfreq - options.error)
        if not (self.tune(options.centerfreq - options.error)):
            print "Failed to set initial frequency"

        if options.gain is None:  #set to halfway
            g = self.subdev.gain_range()
            options.gain = (g[0] + g[1]) / 2.0

        print "Setting gain to %i" % options.gain
        self.subdev.set_gain(options.gain)

        if self.subdev.name() == "DBS Rx":
            self.subdev.set_bw(options.bandwidth)  #only for DBSRX
            print "Setting DBS RX bandwidth to %fMHz" % float(
                options.bandwidth / 1e6)

        self.rate = self.u.adc_rate() / options.decim

        print "Samples per second is %i" % self.rate

        self._syms_per_sec = 3600

        options.audiorate = 11025
        options.rate = self.rate

        options.samples_per_second = self.rate  #yeah i know it's on the list
        options.syms_per_sec = self._syms_per_sec
        options.gain_mu = 0.01
        options.mu = 0.5
        options.omega_relative_limit = 0.3
        options.syms_per_sec = self._syms_per_sec
        options.offset = options.centerfreq - options.freq
        print "Control channel offset: %f" % options.offset

        self.demod = fsk_demod(options)
        self.start_correlator = gr.correlate_access_code_bb(
            "10101100", 0)  #should mark start of packet
        self.smartnet_sync = smartnet.sync()
        self.smartnet_deinterleave = smartnet.deinterleave()
        self.smartnet_parity = smartnet.parity()
        self.smartnet_crc = smartnet.crc()
        self.smartnet_packetize = smartnet.packetize()
        self.parse = smartnet.parse(
            queue
        )  #packet-based. this simply posts lightly-formatted messages to the queue.

        self.connect(self.u, self.demod)

        self.connect(self.demod, self.start_correlator, self.smartnet_sync,
                     self.smartnet_deinterleave, self.smartnet_parity,
                     self.smartnet_crc, self.smartnet_packetize, self.parse)
コード例 #5
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self)

        if options.filename is not None:
            self.fs = gr.file_source(gr.sizeof_gr_complex, options.filename)
            self.rate = options.rate

        else:
            self.u = uhd.usrp_source(options.addr,
                                     io_type=uhd.io_type.COMPLEX_FLOAT32,
                                     num_channels=1)

            if options.subdev is not None:
                self.u.set_subdev_spec(options.subdev, 0)

            self.u.set_samp_rate(options.rate)
            self.rate = self.u.get_samp_rate()

            # Set the antenna
            if (options.antenna):
                self.u.set_antenna(options.antenna, 0)

            self.centerfreq = options.centerfreq
            print "Tuning to: %fMHz" % (self.centerfreq - options.error)
            if not (self.tune(options.centerfreq - options.error)):
                print "Failed to set initial frequency"

            if options.gain is None:  #set to halfway
                g = self.u.get_gain_range()
                options.gain = (g.start() + g.stop()) / 2.0

            print "Setting gain to %i" % options.gain
            self.u.set_gain(options.gain)

            self.u.set_bandwidth(options.bandwidth)

        print "Samples per second is %i" % self.rate

        self._syms_per_sec = 3600

        options.samples_per_second = self.rate
        options.syms_per_sec = self._syms_per_sec
        options.gain_mu = 0.01
        options.mu = 0.5
        options.omega_relative_limit = 0.3
        options.syms_per_sec = self._syms_per_sec
        options.offset = options.centerfreq - options.freq
        print "Control channel offset: %f" % options.offset

        self.demod = fsk_demod(options)
        self.start_correlator = gr.correlate_access_code_tag_bb(
            "10101100", 0, "smartnet_preamble")  #should mark start of packet
        self.smartnet_deinterleave = smartnet.deinterleave()
        self.smartnet_crc = smartnet.crc(queue)

        if options.filename is None:
            self.connect(self.u, self.demod)
        else:
            self.connect(self.fs, self.demod)

        self.connect(self.demod, self.start_correlator,
                     self.smartnet_deinterleave, self.smartnet_crc)

        #hook up the audio patch
        if options.audio:
            self.audiorate = 48000
            self.audiotaps = gr.firdes.low_pass(1, self.rate, 8000, 2000,
                                                gr.firdes.WIN_HANN)
            self.prefilter_decim = int(
                self.rate / self.audiorate
            )  #might have to use a rational resampler for audio
            print "Prefilter decimation: %i" % self.prefilter_decim
            self.audio_prefilter = gr.freq_xlating_fir_filter_ccf(
                self.prefilter_decim,  #decimation
                self.audiotaps,  #taps
                0,  #freq offset
                self.rate)  #sampling rate

            #on a trunked network where you know you will have good signal, a carrier power squelch works well. real FM receviers use a noise squelch, where
            #the received audio is high-passed above the cutoff and then fed to a reverse squelch. If the power is then BELOW a threshold, open the squelch.
            self.squelch = gr.pwr_squelch_cc(
                options.squelch,  #squelch point
                alpha=0.1,  #wat
                ramp=10,  #wat
                gate=False)

            self.audiodemod = blks2.fm_demod_cf(
                self.rate / self.prefilter_decim,  #rate
                1,  #audio decimation
                4000,  #deviation
                3000,  #audio passband
                4000,  #audio stopband
                1,  #gain
                75e-6)  #deemphasis constant

            #the filtering removes FSK data woobling from the subaudible channel (might be able to combine w/lpf above)
            self.audiofilttaps = gr.firdes.high_pass(1, self.audiorate, 300,
                                                     50, gr.firdes.WIN_HANN)
            self.audiofilt = gr.fir_filter_fff(1, self.audiofilttaps)
            self.audiogain = gr.multiply_const_ff(options.volume)
            self.audiosink = audio.sink(self.audiorate, "")
            #			self.audiosink = gr.wavfile_sink("test.wav", 1, self.audiorate, 8)

            self.mute()

            if options.filename is None:
                self.connect(self.u, self.audio_prefilter)
            else:
                self.connect(self.fs, self.audio_prefilter)

#			self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audioresamp, self.audiosink)
            self.connect(self.audio_prefilter, self.squelch, self.audiodemod,
                         self.audiofilt, self.audiogain, self.audiosink)
コード例 #6
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self)

        if options.filename is not None:
            self.fs = gr.file_source(gr.sizeof_gr_complex, options.filename)
            self.rate = options.rate

        else:
            #self.u = uhd.usrp_source(options.addr,
            #						 io_type=uhd.io_type.COMPLEX_FLOAT32,
            #						 num_channels=1)

            self.rtl = osmosdr.source_c(args="nchan=" + str(1) + " " + "")
            self.rtl.set_sample_rate(options.rate)
            self.rate = options.rate  #self.rtl.get_samp_rate()
            self.rtl.set_center_freq(options.centerfreq, 0)
            #self.rtl.set_freq_corr(options.ppm, 0)

            self.centerfreq = options.centerfreq
            print "Tuning to: %fMHz" % (self.centerfreq - options.error)
            if not (self.tune(options.centerfreq - options.error)):
                print "Failed to set initial frequency"

            if options.gain is None:
                options.gain = 10
            if options.bbgain is None:
                options.bbgain = 25
            if options.ifgain is None:
                options.ifgain = 25

            print "Setting RF gain to %i" % options.gain
            print "Setting BB gain to %i" % options.bbgain
            print "Setting IF gain to %i" % options.ifgain

            self.rtl.set_gain(options.gain, 0)
            self.rtl.set_if_gain(options.ifgain, 0)
            self.rtl.set_bb_gain(options.bbgain, 0)
            #self.rtl.set_gain_mode(1,0)

        print "Samples per second is %i" % self.rate

        self._syms_per_sec = 3600

        options.samples_per_second = self.rate
        options.syms_per_sec = self._syms_per_sec
        options.gain_mu = 0.01
        options.mu = 0.5
        options.omega_relative_limit = 0.3
        options.syms_per_sec = self._syms_per_sec
        options.offset = options.centerfreq - options.freq
        print "Control channel offset: %f" % options.offset

        self.offset = gr.sig_source_c(self.rate, gr.GR_SIN_WAVE,
                                      options.offset, 1.0, 0.0)

        # for some reason using the xlating filter to do the offset makes thing barf with the HackRF, Multiply CC seems to work

        options.offset = 0

        self.mixer = gr.multiply_cc()

        self.demod = fsk_demod(options)
        self.start_correlator = gr.correlate_access_code_tag_bb(
            "10101100", 0, "smartnet_preamble")  #should mark start of packet
        self.smartnet_deinterleave = smartnet.deinterleave()
        self.smartnet_crc = smartnet.crc(queue)

        #rerate = float(self.rate / float(first_decim)) / float(7200)
        #print "resampling factor: %f\n" % rerate

        #if rerate.is_integer():
        #    print "using pfb decimator\n"
        #    self.resamp = blks2.pfb_decimator_ccf(int(rerate))
        #else:
        #    print "using pfb resampler\n"
        #    self.resamp = blks2.pfb_arb_resampler_ccf(1 / rerate)

        if options.filename is None:
            #self.connect(self.u, self.demod)
            self.connect(self.rtl, (self.mixer, 0))
            self.connect(self.offset, (self.mixer, 1))
            self.connect(self.mixer, self.demod)
            #    self.connect(self.rtl, self.demod)
        else:
            self.connect(self.fs, self.demod)

        self.connect(self.demod, self.start_correlator,
                     self.smartnet_deinterleave, self.smartnet_crc)

        #hook up the audio patch
        if options.audio:
            self.audiorate = 48000
            self.audiotaps = gr.firdes.low_pass(1, self.rate, 8000, 2000,
                                                gr.firdes.WIN_HANN)
            self.prefilter_decim = int(
                self.rate / self.audiorate
            )  #might have to use a rational resampler for audio
            print "Prefilter decimation: %i" % self.prefilter_decim
            self.audio_prefilter = gr.freq_xlating_fir_filter_ccf(
                self.prefilter_decim,  #decimation
                self.audiotaps,  #taps
                0,  #freq offset
                self.rate)  #sampling rate

            #on a trunked network where you know you will have good signal, a carrier power squelch works well. real FM receviers use a noise squelch, where
            #the received audio is high-passed above the cutoff and then fed to a reverse squelch. If the power is then BELOW a threshold, open the squelch.
            #self.squelch = gr.pwr_squelch_cc(options.squelch, #squelch point
            #								   alpha = 0.1, #wat
            #								   ramp = 10, #wat
            #								   gate = False)

            self.audiodemod = blks2.fm_demod_cf(
                self.rate / self.prefilter_decim,  #rate
                1,  #audio decimation
                4000,  #deviation
                3000,  #audio passband
                4000,  #audio stopband
                1,  #gain
                75e-6)  #deemphasis constant

            #the filtering removes FSK data woobling from the subaudible channel (might be able to combine w/lpf above)
            self.audiofilttaps = gr.firdes.high_pass(1, self.audiorate, 300,
                                                     50, gr.firdes.WIN_HANN)
            self.audiofilt = gr.fir_filter_fff(1, self.audiofilttaps)
            self.audiogain = gr.multiply_const_ff(options.volume)
            self.audiosink = audio.sink(self.audiorate, "")
            #			self.audiosink = gr.wavfile_sink("test.wav", 1, self.audiorate, 8)

            #self.mute()

            if options.filename is None:
                #self.connect(self.u, self.audio_prefilter)
                self.connect(self.rtl, self.audio_prefilter)
            else:
                self.connect(self.fs, self.audio_prefilter)

#			self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audioresamp, self.audiosink)
#	real		self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audiosink)
            self.connect(self.audio_prefilter, self.audiodemod, self.audiofilt,
                         self.audiogain, self.audiosink)
コード例 #7
0
	def __init__(self, options, queue):
		gr.top_block.__init__(self)

		if options.filename is not None:
			self.fs = gr.file_source(gr.sizeof_gr_complex, options.filename)
			self.rate = options.rate

		else:
			#self.u = uhd.usrp_source(options.addr,
			#						 io_type=uhd.io_type.COMPLEX_FLOAT32,
			#						 num_channels=1)

                    
                    self.rtl = osmosdr.source_c( args="nchan=" + str(1) + " " + ""  )
                    self.rtl.set_sample_rate(options.rate)
                    self.rate = options.rate #self.rtl.get_samp_rate()
                    self.rtl.set_center_freq(options.centerfreq, 0)
                    #self.rtl.set_freq_corr(options.ppm, 0)
                    
		
                    self.centerfreq = options.centerfreq
                    print "Tuning to: %fMHz" % (self.centerfreq - options.error)
                    if not(self.tune(options.centerfreq - options.error)):
			print "Failed to set initial frequency"

                    if options.gain is None: 
			options.gain = 10
                    if options.bbgain is None: 
			options.bbgain = 25
                    if options.ifgain is None: 
			options.ifgain = 25


                    print "Setting RF gain to %i" % options.gain
                    print "Setting BB gain to %i" % options.bbgain
                    print "Setting IF gain to %i" % options.ifgain

                    self.rtl.set_gain(options.gain, 0) 
                    self.rtl.set_if_gain(options.ifgain,0)
                    self.rtl.set_bb_gain(options.bbgain,0)
                    #self.rtl.set_gain_mode(1,0)

		print "Samples per second is %i" % self.rate

		self._syms_per_sec = 3600;


		options.samples_per_second = self.rate
		options.syms_per_sec = self._syms_per_sec
		options.gain_mu = 0.01
		options.mu=0.5
		options.omega_relative_limit = 0.3
		options.syms_per_sec = self._syms_per_sec
		options.offset = options.centerfreq - options.freq
		print "Control channel offset: %f" % options.offset

                self.offset = gr.sig_source_c(self.rate, gr.GR_SIN_WAVE,
                                              options.offset, 1.0, 0.0)
		
		# for some reason using the xlating filter to do the offset makes thing barf with the HackRF, Multiply CC seems to work

		options.offset = 0

                self.mixer = gr.multiply_cc()

		self.demod = fsk_demod(options)
		self.start_correlator = gr.correlate_access_code_tag_bb("10101100",
		                                                        0,
		                                                        "smartnet_preamble") #should mark start of packet
		self.smartnet_deinterleave = smartnet.deinterleave()
		self.smartnet_crc = smartnet.crc(queue)

                #rerate = float(self.rate / float(first_decim)) / float(7200)
                #print "resampling factor: %f\n" % rerate
                
                #if rerate.is_integer():
                #    print "using pfb decimator\n"
                #    self.resamp = blks2.pfb_decimator_ccf(int(rerate))
                #else:
                #    print "using pfb resampler\n"
                #    self.resamp = blks2.pfb_arb_resampler_ccf(1 / rerate)

		if options.filename is None:
			#self.connect(self.u, self.demod)
                    self.connect(self.rtl, (self.mixer, 0))
                    self.connect(self.offset, (self.mixer, 1))                    
                    self.connect(self.mixer, self.demod)
                    #    self.connect(self.rtl, self.demod)
		else:
			self.connect(self.fs, self.demod)

		self.connect(self.demod, self.start_correlator, self.smartnet_deinterleave, self.smartnet_crc)

		#hook up the audio patch
		if options.audio:
			self.audiorate = 48000
			self.audiotaps = gr.firdes.low_pass(1, self.rate, 8000, 2000, gr.firdes.WIN_HANN)
			self.prefilter_decim = int(self.rate / self.audiorate) #might have to use a rational resampler for audio
			print "Prefilter decimation: %i" % self.prefilter_decim
			self.audio_prefilter = gr.freq_xlating_fir_filter_ccf(self.prefilter_decim, #decimation
									      self.audiotaps, #taps
									      0, #freq offset
									      self.rate) #sampling rate

			#on a trunked network where you know you will have good signal, a carrier power squelch works well. real FM receviers use a noise squelch, where
			#the received audio is high-passed above the cutoff and then fed to a reverse squelch. If the power is then BELOW a threshold, open the squelch.
			#self.squelch = gr.pwr_squelch_cc(options.squelch, #squelch point
			#								   alpha = 0.1, #wat
			#								   ramp = 10, #wat
			#								   gate = False)

			self.audiodemod = blks2.fm_demod_cf(self.rate/self.prefilter_decim, #rate
							    1, #audio decimation
							    4000, #deviation
							    3000, #audio passband
							    4000, #audio stopband
							    1, #gain
							    75e-6) #deemphasis constant

			#the filtering removes FSK data woobling from the subaudible channel (might be able to combine w/lpf above)
			self.audiofilttaps = gr.firdes.high_pass(1, self.audiorate, 300, 50, gr.firdes.WIN_HANN)
			self.audiofilt = gr.fir_filter_fff(1, self.audiofilttaps)
			self.audiogain = gr.multiply_const_ff(options.volume)
			self.audiosink = audio.sink (self.audiorate, "")
#			self.audiosink = gr.wavfile_sink("test.wav", 1, self.audiorate, 8)

			#self.mute()

			if options.filename is None:
				#self.connect(self.u, self.audio_prefilter)
                                self.connect(self.rtl, self.audio_prefilter)
			else:
				self.connect(self.fs, self.audio_prefilter)

#			self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audioresamp, self.audiosink)
#	real		self.connect(self.audio_prefilter, self.squelch, self.audiodemod, self.audiofilt, self.audiogain, self.audiosink)
			self.connect(self.audio_prefilter, self.audiodemod, self.audiofilt, self.audiogain, self.audiosink)
コード例 #8
0
	def __init__(self, options, queue):
		gr.top_block.__init__(self)
                
                
		self.rtl = osmosdr.source_c( args="nchan=" + str(1) + " " + ""  )
		self.rtl.set_sample_rate(options.rate)
		self.rtl.set_center_freq(options.centerfreq, 0)
		self.rtl.set_freq_corr(options.ppm, 0)
		self.rtl.set_gain_mode(1, 0)
		
		self.centerfreq = options.centerfreq
		print "Tuning to: %fMHz" % (self.centerfreq - options.error)
		if not(self.tune(options.centerfreq - options.error)):
			print "Failed to set initial frequency"

		if options.gain is None: 
			options.gain = 10
		if options.bbgain is None: 
			options.bbgain = 25
		if options.ifgain is None: 
			options.ifgain = 25


		print "Setting RF gain to %i" % options.gain
		print "Setting BB gain to %i" % options.bbgain
		print "Setting IF gain to %i" % options.ifgain

		self.rtl.set_gain(options.gain, 0) 
		self.rtl.set_if_gain(options.ifgain,0)
		self.rtl.set_bb_gain(options.bbgain,0)
		
                self.rate = options.rate
		
		print "Samples per second is %i" % self.rate

		self._syms_per_sec = 3600;

		options.audiorate = 11025
		options.rate = self.rate

		options.samples_per_second = self.rate #yeah i know it's on the list
		options.syms_per_sec = self._syms_per_sec
		options.gain_mu = 0.01
		options.mu=0.5
		options.omega_relative_limit = 0.3
		options.syms_per_sec = self._syms_per_sec
		options.offset = options.centerfreq - options.freq
		print "Control channel offset: %f" % options.offset


                self.offset = gr.sig_source_c(self.rate, gr.GR_SIN_WAVE,
                                              options.offset, 1.0, 0.0)
		
		# for some reason using the xlating filter to do the offset makes thing barf with the HackRF, Multiply CC seems to work

		options.offset = 0

                self.mixer = gr.multiply_cc()

		self.demod = fsk_demod(options)

		self.start_correlator = gr.correlate_access_code_tag_bb("10101100",
                                                            0,
                                                            "smartnet_preamble") #should mark start of packet



		self.smartnet_deinterleave = smartnet.deinterleave()
		self.smartnet_crc = smartnet.crc(queue)

		
                self.connect(self.rtl, (self.mixer, 0))
                self.connect(self.offset, (self.mixer, 1))                    
                self.connect(self.mixer, self.demod)

		self.connect(self.demod, self.start_correlator, self.smartnet_deinterleave, self.smartnet_crc)
コード例 #9
0
    def __init__(self, options, args, queue):
        gr.top_block.__init__(self)

        self.options = options
        self.args = args
        self.rate = int(options.rate)
        
        if options.filename is None and options.udp is None and not options.rtlsdr:
          #UHD source by default
          from gnuradio import uhd
          self.u = uhd.single_usrp_source(options.args, uhd.io_type_t.COMPLEX_FLOAT32, 1)
          time_spec = uhd.time_spec(0.0)
          self.u.set_time_now(time_spec)
        
          #if(options.rx_subdev_spec is None):
          #  options.rx_subdev_spec = ""
          #self.u.set_subdev_spec(options.rx_subdev_spec)
          if not options.antenna is None:
            self.u.set_antenna(options.antenna)
        
          self.u.set_samp_rate(rate)
          self.rate = int(self.u.get_samp_rate()) #retrieve actual
        
          if options.gain is None: #set to halfway
            g = self.u.get_gain_range()
            options.gain = (g.start()+g.stop()) / 2.0
        
          if not(self.tune(options.freq)):
            print "Failed to set initial frequency"
        
          print "Setting gain to %i" % options.gain
          self.u.set_gain(options.gain)
          print "Gain is %i" % self.u.get_gain()
          
        elif options.rtlsdr: #RTLSDR dongle
            import osmosdr
            self.u = osmosdr.source_c(options.args)
            self.u.set_sample_rate(2.4e6) #fixed for RTL dongles
            if not self.u.set_center_freq(options.centerfreq - options.error):
                print "Failed to set initial frequency"
        
            self.u.set_gain_mode(0) #manual gain mode
            if options.gain is None:
                options.gain = 25#34
                
            self.u.set_gain(options.gain)
            print "Gain is %i" % self.u.get_gain()
        
            use_resampler = True
            self.rate=2.4e6
                    
        else:
          if options.filename is not None:
            self.u = gr.file_source(gr.sizeof_gr_complex, options.filename)
          elif options.udp is not None:
            self.u = gr.udp_source(gr.sizeof_gr_complex, "localhost", options.udp)
          else:
            raise Exception("No valid source selected")
        
        
        print "Samples per second is %i" % self.rate
        
        self._syms_per_sec = 3600;
        
        options.audiorate = 11025
        options.rate = self.rate
        
        options.samples_per_second = self.rate #yeah i know it's on the list
        options.syms_per_sec = self._syms_per_sec
        options.gain_mu = 0.01
        options.mu=0.5
        options.omega_relative_limit = 0.3
        options.syms_per_sec = self._syms_per_sec
        options.offset = options.centerfreq - options.freq
        print "Control channel offset: %f" % options.offset
        
        self.demod = fsk_demod(options)
        self.start_correlator = gr.correlate_access_code_tag_bb("10101100",0,"smartnet_preamble") #should mark start of packet #digital.
        #self.start_correlator = digital.correlate_access_code_bb("10101100",0) #should mark start of packet #digital.
#        self.smartnet_sync = smartnet.sync()
        self.smartnet_deinterleave = smartnet.deinterleave()
#        self.smartnet_parity = smartnet.parity()
        self.smartnet_crc = smartnet.crc(queue)
#        self.smartnet_packetize = smartnet.packetize()
#        self.parse = smartnet.parse(queue) #packet-based. this simply posts lightly-formatted messages to the queue.
        
        self.connect(self.u, self.demod)
                                                        #self.smartnet_sync,        self.smartnet_parity,
        self.connect(self.demod, self.start_correlator,  self.smartnet_deinterleave,  self.smartnet_crc)#, self.smartnet_packetize, self.parse)