Exemplo n.º 1
0
    def __init__(self, options):
        gr.top_block.__init__(self, "mhp")

        self.lfsr = lfsr.p25p2_lfsr(options.nac, options.sysid, options.wacn)
        xor_mask = ''
        for c in self.lfsr.xorsyms:
            xor_mask += chr(c)

        IN = blocks.file_source(gr.sizeof_char, options.input_file)

        slotid = options.tdma_slotid
        msgq = gr.msg_queue(2)
        do_msgq  = False

        wireshark_host = ''
        udp_port = 0
        verbosity = 100
        do_imbe = 1
        do_output = 1
        do_msgq = 0
        rx_q = gr.msg_queue(1)
        do_audio_output = 1
        phase2_tdma = 1
        
        FRAMER = op25_repeater.p25_frame_assembler(wireshark_host, udp_port, verbosity, do_imbe, do_output, do_msgq, rx_q, do_audio_output, phase2_tdma)
        FRAMER.set_xormask(xor_mask)

        S2F = blocks.short_to_float()
        M = blocks.multiply_const_ff(1.0 / 32767.0)

        SINK = audio.sink(8000, 'plughw:0,0')
        
        self.connect(IN, FRAMER, S2F, M, SINK)
Exemplo n.º 2
0
    def __init__(self):
        gr.top_block.__init__(self)
        parser = OptionParser(option_class=eng_option)
        parser.add_option("-a", "--audio-input", type="string", default="")
        parser.add_option("-A", "--audio-output", type="string", default="")
        parser.add_option("-f", "--factor", type="eng_float", default=1)
        parser.add_option("-i", "--do-interp", action="store_true", default=False, help="enable output interpolator")
        parser.add_option("-s", "--sample-rate", type="int", default=48000, help="input sample rate")
        parser.add_option("-S", "--stretch", type="int", default=0, help="flex amt")
        parser.add_option("-y", "--symbol-rate", type="int", default=4800, help="input symbol rate")
        parser.add_option("-v", "--verbose", action="store_true", default=False, help="dump demodulation data")
        (options, args) = parser.parse_args()
 
        sample_rate = options.sample_rate
        symbol_rate = options.symbol_rate

        IN = audio.source(sample_rate, options.audio_input)
        audio_output_rate = 8000
        if options.do_interp:
            audio_output_rate = 48000
        OUT = audio.sink(audio_output_rate, options.audio_output)

        symbol_decim = 1
        symbol_coeffs = gr.firdes.root_raised_cosine(1.0,	# gain
                                          sample_rate ,	# sampling rate
                                          symbol_rate,  # symbol rate
                                          0.2,     	# width of trans. band
                                          500) 		# filter type 
        SYMBOL_FILTER = gr.fir_filter_fff (symbol_decim, symbol_coeffs)
        AMP = gr.multiply_const_ff(options.factor)
        msgq = gr.msg_queue(2)
        FSK4 = op25.fsk4_demod_ff(msgq, sample_rate, symbol_rate)
        levels = levels = [-2.0, 0.0, 2.0, 4.0]
        SLICER = repeater.fsk4_slicer_fb(levels)
        framer_msgq = gr.msg_queue(2)
        DECODE = repeater.p25_frame_assembler('',	# udp hostname
                                              0,	# udp port no.
                                              options.verbose,	#debug
                                              True,	# do_imbe
                                              True,	# do_output
                                              False,	# do_msgq
                                              framer_msgq)
        IMBE = repeater.vocoder(False,                 # 0=Decode,True=Encode
                                  options.verbose,      # Verbose flag
                                  options.stretch,      # flex amount
                                  "",                   # udp ip address
                                  0,                    # udp port
                                  False)                # dump raw u vectors

        CVT = gr.short_to_float()
        if options.do_interp:
            interp_taps = gr.firdes.low_pass(1.0, 48000, 4000, 4000 * 0.1, gr.firdes.WIN_HANN)
            INTERP = gr.interp_fir_filter_fff(48000 // 8000, interp_taps)
        AMP2 = gr.multiply_const_ff(1.0 / 32767.0)

        self.connect(IN, AMP, SYMBOL_FILTER, FSK4, SLICER, DECODE, IMBE, CVT, AMP2)
        if options.do_interp:
            self.connect(AMP2, INTERP, OUT)
        else:
            self.connect(AMP2, OUT)
    def __init__(self):
        gr.top_block.__init__(self, "grc_cc1111_test_local_loop")

        ##################################################
        # Variables
        ##################################################
        self.symbole_rate = symbole_rate = 80000
        self.samp_rate = samp_rate = 2e6
        self.samp_per_sym = samp_per_sym = int(samp_rate / symbole_rate)
        self.preamble = preamble = '0101010101010101'
        self.myqueue_out = myqueue_out = gr.msg_queue(2)
        self.myqueue_in = myqueue_in = gr.msg_queue(2)
        self.bit_per_sym = bit_per_sym = 1
        self.access_code = access_code = '11010011100100011101001110010001'

        ##################################################
        # Blocks
        ##################################################
        self.digital_gmsk_mod_0 = digital.gmsk_mod(
        	samples_per_symbol=int(samp_per_sym),
        	bt=0.5,
        	verbose=False,
        	log=False,
        )
        self.digital_correlate_access_code_bb_0_0 = digital.correlate_access_code_bb(access_code, 1)
        self.digital_clock_recovery_mm_xx_0_0 = digital.clock_recovery_mm_ff(samp_per_sym*(1+0.0), 0.25*0.175*0.175, 0.5, 0.175, 0.005)
        self.digital_binary_slicer_fb_0_0_0 = digital.binary_slicer_fb()
        self.cc1111_cc1111_packet_encoder_0 = cc1111.cc1111_packet_mod_base(cc1111.cc1111_packet_encoder(
                        samples_per_symbol=samp_per_sym,
                        bits_per_symbol=bit_per_sym,
                        preamble=preamble,
                        access_code=access_code,
                        pad_for_usrp=True,
        		do_whitening=True,
        		add_crc=True
                ),
        	source_queue=myqueue_in
        	)
        self.cc1111_cc1111_packet_decoder_0 = cc1111.cc1111_packet_decoder(myqueue_out,True, True, False, True)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate,True)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char*1)
        self.analog_quadrature_demod_cf_0_0 = analog.quadrature_demod_cf(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.digital_clock_recovery_mm_xx_0_0, 0), (self.digital_binary_slicer_fb_0_0_0, 0))
        self.connect((self.analog_quadrature_demod_cf_0_0, 0), (self.digital_clock_recovery_mm_xx_0_0, 0))
        self.connect((self.digital_binary_slicer_fb_0_0_0, 0), (self.digital_correlate_access_code_bb_0_0, 0))
        self.connect((self.digital_gmsk_mod_0, 0), (self.analog_quadrature_demod_cf_0_0, 0))
        self.connect((self.digital_correlate_access_code_bb_0_0, 0), (self.cc1111_cc1111_packet_decoder_0, 0))
        self.connect((self.cc1111_cc1111_packet_decoder_0, 0), (self.blocks_null_sink_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.digital_gmsk_mod_0, 0))
        self.connect((self.cc1111_cc1111_packet_encoder_0, 0), (self.blocks_throttle_0, 0))
Exemplo n.º 4
0
    def __init__(self, demodulator, options, access_code=None, callback=None, threshold=-1, use_coding=0, logging=-1):
        """
	Hierarchical block for demodulating and deframing packets.

	The input is the complex modulated signal at baseband.
        Demodulated packets are sent to the handler.

        @param demodulator: instance of demodulator class (gr_block or hier_block2)
        @type demodulator: complex baseband in
        @param access_code: AKA sync vector
        @type access_code: string of 1's and 0's
        @param callback:  function of two args: ok, payload
        @type callback: ok: bool; payload: string
        @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default)
        @type threshold: int
	"""

	gr.hier_block2.__init__(self, "demod_pkts",
				gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
				gr.io_signature(0, 0, 0))                    # Output signature

        self._demodulator = demodulator
        if access_code is None:
            access_code = packet_utils.default_access_code
        if not packet_utils.is_1_0_string(access_code):
            raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)
        self._access_code = access_code

        #just added to take coding from benchmark_rx
        self._use_coding = use_coding
        self._logging = logging
        self._options = options
        
        
            
        
        # added to simplify logging
        self._threshold = options.access_code_threshold


        if threshold == -1:
            threshold = 4              # FIXME raise exception

        self._rcvd_pktq = gr.msg_queue()          # holds packets from the PHY
        self._time_pktq = gr.msg_queue()          # holds packet timestamps from the PHY
        self._chan_pktq = gr.msg_queue()          # holds packet channels from the PHY
        
        self.correlator = digital.correlate_access_code_bb(access_code, threshold)

        self.framer_sink = framer_sink_1(self._rcvd_pktq, self._time_pktq, self._chan_pktq)
        self.connect(self, self._demodulator, self.correlator, self.framer_sink)
        
        self._watcher = _queue_watcher_thread(self._rcvd_pktq, self._time_pktq, self._chan_pktq, callback, self._use_coding, self._logging, self._options)
Exemplo n.º 5
0
    def __init__(self):
        gr.hier_block2.__init__(self,
                                "proto_transceiver",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
#file sinks for debugging
        self.agc_out = gr.file_sink(itemsize = gr.sizeof_gr_complex,
                                    filename = "agc.dat")
#########################
#uplink blocks

        q_encoder = gr.msg_queue(100)
        self.tx_encoder = rfidbts.pie_encoder(samples_per_delimiter = 8, 
                                              samples_per_tari = 16,
                                              samples_per_pw = 8,
                                              samples_per_trcal = 53,
                                              samples_per_data1 = 32)
        self.tx_encoder.set_encoder_queue(q_encoder)
        rfidbts.cvar.rfid_mac.set_encoder_queue(q_encoder)
####################################
#downlink blocks
        q_blocker = gr.msg_queue(100)
        frame_size_rn16 = int((32 + 32 + 12) * 8 + int(75*0.4*1.024))
        self.TX_blocker = rfidbts.receive_gate(threshold = 0.15,     #bit above the noise floor
                                               off_max = 15)         #should not be in the off state for more than 13 us
        self.TX_blocker.set_gate_queue(q_blocker)
        rfidbts.cvar.rfid_mac.set_gate_queue(q_blocker)
        self.blocker = gr.dc_blocker_cc(D = 5, 
                                        long_form = True)
        self.agc = gr.agc_cc(rate = 5e-1, 
                             reference = 0.707, 
                             gain = 100.0,
                             max_gain = 1000.0)
        self.search = preamble_search(frame_size_rn16)
        self.half_symbols = symbol_mapper()
#        self.decoder = binary_diff_decoder()
        self.decoder = rfidbts.orthogonal_decode()
        self.framer = rfidbts.packetizer()
#frame the rn16 and send to message queue
#####################################
#connect uplink
        self.connect(self.tx_encoder, self)
#####################################
#connect downlink
        self.connect(self,
                     self.TX_blocker,
                     self.blocker,
                     self.agc,
                     self.search,
                     self.half_symbols,
                     self.decoder,
                     self.framer)
        self.connect(self.agc, self.agc_out)
    def __init__(self):
        gr.top_block.__init__(self, 'Message Blocks Test')

        # initialize the queues
        self.sink_queue = gr.msg_queue()
        self.source_queue = gr.msg_queue()

        # initialize the blocks
        self.msg_source = gr.message_source(gr.sizeof_char, self.source_queue)
        self.msg_sink = gr.message_sink(gr.sizeof_char, self.sink_queue, False)

        self.connect((self.msg_source, 0), (self.msg_sink, 0))
Exemplo n.º 7
0
    def __init__(self):
        gr.top_block.__init__(self)
        parser = OptionParser(option_class=eng_option)

        parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file")
        parser.add_option("-g", "--gain", type="eng_float", default=1.0)
        parser.add_option("-L", "--low-pass", type="eng_float", default=15e3, help="low pass cut-off", metavar="Hz")
        parser.add_option("-o", "--output-file", type="string", default="out.dat", help="specify the output file")
        parser.add_option("-s", "--sample-rate", type="int", default=48000, help="input sample rate")
        parser.add_option("-v", "--verbose", action="store_true", default=False, help="dump demodulation data")
        (options, args) = parser.parse_args()
 
        sample_rate = options.sample_rate
        sps = 10
        symbol_rate = 4800
        # output rate will be 48,000
        ntaps = 11 * sps

        channel_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN)

        IN = gr.file_source(gr.sizeof_short, options.input_file)
        OUT = gr.file_sink(gr.sizeof_char, options.output_file)

        CVT = gr.short_to_float()
        AMP = gr.multiply_const_ff(options.gain / 32767.0)

        symbol_decim = 1
        symbol_coeffs = gr.firdes.root_raised_cosine (1.0,        	# gain
                                          sample_rate ,  	# sampling rate
                                          symbol_rate,     # symbol rate
                                          0.20,     	# width of trans. band
                                          500) 		# filter type 
        SYMBOL_FILTER = gr.fir_filter_fff (symbol_decim, symbol_coeffs)
        self.msgq = gr.msg_queue(2)

        FSK4 = op25.fsk4_demod_ff(self.msgq, sample_rate, symbol_rate)

        levels = [ -2.0, 0.0, 2.0, 4.0 ]
        SLICER = repeater.fsk4_slicer_fb(levels)

        hostname = "127.0.0.1"
        port = 23456
        debug = 255
        do_imbe = False
        do_output = True
        do_msgq = False
        msgqd = gr.msg_queue(2)
        DECODER = repeater.p25_frame_assembler(hostname, port, debug, do_imbe, do_output, do_msgq, msgqd)

        self.connect(IN, CVT, AMP, SYMBOL_FILTER, FSK4, SLICER, DECODER, OUT)
Exemplo n.º 8
0
    def _setup_usrpx(self, options):
        self._u = uhd.usrp_sink(device_addr=options.args, stream_args=uhd.stream_args('fc32'))
        self._u.set_samp_rate(options.samp_rate)

        # Set the subdevice spec
        if(options.spec):
            self._u.set_subdev_spec(options.spec, 0)

        # Set the gain on the usrp from options
        if(options.gain):
            self._u.set_gain(options.gain)

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

        self.publish(DESC_KEY, lambda: str(self._u))
        self.publish(FREQ_RANGE_KEY, self._u.get_freq_range)
        self.publish(GAIN_RANGE_KEY, self._u.get_gain_range)
        self.publish(GAIN_KEY, self._u.get_gain)
        if self._verbose:
            print str(self._u)

        # Direct asynchronous notifications to callback function
        if options.show_async_msg:
            self.async_msgq = gr.msg_queue(0)
            self.async_src = uhd.amsg_source("", self.async_msgq)
            self.async_rcv = gru.msgq_runner(self.async_msgq, self.async_callback)
Exemplo n.º 9
0
    def __init__(self, input_is_real=False, baseband_freq=0, y_per_div=10,
                 y_divs=8, ref_level=50,
                 sample_rate=1, fft_size=512,
                 fft_rate=default_fft_rate,
                 average=False, avg_alpha=None, title='',
                 peak_hold=False, use_persistence=False, persist_alpha=0.2):

        # initialize common attributes
        self.baseband_freq = baseband_freq
        self.y_per_div=y_per_div
        self.y_divs = y_divs
        self.ref_level = ref_level
        self.sample_rate = sample_rate
        self.fft_size = fft_size
        self.fft_rate = fft_rate
        self.average = average
        if avg_alpha is None:
            self.avg_alpha = 2.0 / fft_rate
        else:
            self.avg_alpha = avg_alpha
        self.use_persistence = use_persistence
        self.persist_alpha = persist_alpha

        self.title = title
        self.peak_hold = peak_hold
        self.input_is_real = input_is_real
        self.msgq = gr.msg_queue(2)         # queue that holds a maximum of 2 messages
Exemplo n.º 10
0
    def test_003_t (self):
        # Annex O.3 example 2: whitening enabled
        pad = (0xff,) * 8
        src_data = pad + (0x55, 0x55, 0x55, 0x90, 0x4e, 0x08, 0x07, 0x4f, 0x70, 0xe5, 0x32, 0x6a, 0x62, 0x60) + pad
        src_data_list = hex_list_to_binary_list(src_data)
        expected_str = '\x40\x00\x56\x5d\x29\xfa\x28'

        rcvd_pktq = gr.msg_queue()

        src = blocks.vector_source_b(src_data_list)
        correlator = digital.correlate_access_code_bb('0101010101011001000001001110', 1)
        framer_sink = ieee802154g.framer_sink_mrfsk(rcvd_pktq)
        vsnk = blocks.vector_sink_b()

        self.tb.connect(src, correlator, framer_sink)
        self.tb.connect(correlator, vsnk)
        self.tb.run ()

        # check data
        self.assertEquals(1, rcvd_pktq.count())
        result_msg = rcvd_pktq.delete_head()
        fec = int(result_msg.type())
        self.assertEquals(0, fec)
        phr = int(result_msg.arg1())
        self.assertEquals(0x0807, phr)
        crc_ok = int(result_msg.arg2())
        self.assertEquals(1, crc_ok)
        self.assertEquals(expected_str, result_msg.to_string())
    def __init__(self,options,Freq):
	gr.top_block.__init__(self)
	if options.input_file == "":
	    self.IS_USRP2 = True
	else:
	    self.IS_USRP2 = False
	#self.min_freq = options.start
	#self.max_freq = options.stop
	self.min_freq = Freq.value-(3*10**6) # same as that of the transmitter bandwidth ie 6MHZ approx for a given value of decimation line option any more
	self.max_freq = Freq.value+(3*10**6)
	if self.min_freq > self.max_freq:
	    self.min_freq, self.max_freq = self.max_freq, self.min_freq # swap them
	    print "Start and stop frequencies order swapped!"
	self.fft_size = options.fft_size
	self.ofdm_bins = options.sense_bins
	# build graph
	s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
	mywindow = window.blackmanharris(self.fft_size)
	fft = gr.fft_vcc(self.fft_size, True, mywindow)
	power = 0
	for tap in mywindow:
	    power += tap*tap
	c2mag = gr.complex_to_mag_squared(self.fft_size)
	#log = gr.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size))
	# modifications for USRP2 
	if self.IS_USRP2:	
	    self.u = uhd.usrp_source(options.args,uhd.io_type.COMPLEX_FLOAT32,num_channels=1)		# Modified Line
	    # self.u.set_decim(options.decim)
	    # samp_rate = self.u.adc_rate()/self.u.decim()
	    samp_rate = 100e6/options.decim		# modified sampling rate
	    self.u.set_samp_rate(samp_rate)
	else:
	    self.u = gr.file_source(gr.sizeof_gr_complex,options.input_file, True)
	    samp_rate = 100e6 /options.decim		# modified sampling rate

	self.freq_step =0 #0.75* samp_rate
	self.min_center_freq = (self.min_freq + self.max_freq)/2
	
	global BW
	BW = self.max_freq - self.min_freq
	global size
	size=self.fft_size
	global ofdm_bins
	ofdm_bins = self.ofdm_bins
	global usr
	#global thrshold_inorder
	usr=samp_rate
	nsteps = 10 
	self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step)
	self.next_freq = self.min_center_freq
	tune_delay = max(0, int(round(options.tune_delay * samp_rate / self.fft_size))) # in fft_frames
	dwell_delay = max(1, int(round(options.dwell_delay * samp_rate / self.fft_size))) # in fft_frames
	self.msgq = gr.msg_queue(16)					# thread-safe message queue
	self._tune_callback = tune(self) 				# hang on to this to keep it from being GC'd
	stats = gr.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay,
				      dwell_delay)			# control scanning and record frequency domain statistics
	self.connect(self.u, s2v, fft,c2mag,stats)
	if options.gain is None:
	    g = self.u.get_gain_range()
	    options.gain = float(g.start()+g.stop())/2			# if no gain was specified, use the mid-point in dB
Exemplo n.º 12
0
    def __init__(self, input_is_real=False, baseband_freq=0, y_per_div=10, ref_level=50,
                 sample_rate=1, fac_size=512,
                 fac_rate=default_fac_rate,
                 average=False, avg_alpha=None, title='', peak_hold=False):

	self._item_size = gr.sizeof_gr_complex
	if input_is_real:
	    self._item_size = gr.sizeof_float

	gr.hier_block2.__init__(
			self,
			"Fast AutoCorrelation",
			gr.io_signature(1, 1, self._item_size),
			gr.io_signature(0, 0, 0),
		)

        # initialize common attributes
        self.baseband_freq = baseband_freq
        self.y_divs = 8
        self.y_per_div=y_per_div
        self.ref_level = ref_level
        self.sample_rate = sample_rate
        self.fac_size = fac_size
        self.fac_rate = fac_rate
        self.average = average
        if (avg_alpha is None) or (avg_alpha <= 0):
            self.avg_alpha = 0.20 / fac_rate	# averaging needed to be slowed down for very slow rates
        else:
            self.avg_alpha = avg_alpha
        self.title = title
        self.peak_hold = peak_hold
        self.input_is_real = input_is_real
        self.msgq = gr.msg_queue(2)         # queue that holds a maximum of 2 messages
	def __init__(self, access_code='', threshold=-1, callback=None, verbose=0):
		"""
		packet_demod constructor.
		@param access_code AKA sync vector
		@param threshold detect access_code with up to threshold bits wrong (0 -> use default)
		@param callback a function of args: ok, payload
		"""
		#access code
		if not access_code: #get access code
			access_code = packet_utils.default_access_code
		if not packet_utils.is_1_0_string(access_code):
			raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)
		self._access_code = access_code
		#threshold
		if threshold < 0: threshold = DEFAULT_THRESHOLD
		self._threshold = threshold
		#blocks
		msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT) #holds packets from the PHY
		correlator = digital.correlate_access_code_bb(self._access_code, self._threshold)
		framer_sink = logitech_27mhz_transceiver.framer_sink(msgq)

		#initialize hier2
		gr.hier_block2.__init__(
			self,
			"packet_decoder",
			gr.io_signature(1, 1, gr.sizeof_char), # Input signature
			gr.io_signature(0, 0, 0) # Output signature
		)
		#connect
		self.connect(self, correlator, framer_sink)
		#start thread
		_packet_decoder_thread(msgq, callback,verbose)
Exemplo n.º 14
0
    def __init__(self, port, gain, usrp_rate, lo_freq):
        gr.hier_block2.__init__(self, "tx_channel_usrp",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        msg_queue = gr.msg_queue(2)
        do_imbe = 1
        do_float = 0
        do_complex = 1
        decim = MAX_COMPLEX_RATE / usrp_rate
        # per-channel GR source block including these steps:
        # - receive audio chunks from asterisk via UDP
        # - imbe encode
        # - generate phase-modulated complex output stream (table lookup method)
        # - generates no power while no input received
        self.chan = repeater.chan_usrp(port, do_imbe, do_complex, do_float, gain, int(decim), msg_queue)

        # Local oscillator
        lo = gr.sig_source_c (usrp_rate,      # sample rate
                              gr.GR_SIN_WAVE, # waveform type
                              lo_freq,        #frequency
                              1.0,            # amplitude
                              0)              # DC Offset
        self.mixer = gr.multiply_cc ()
        self.connect (self.chan, (self.mixer, 0))
        self.connect (lo, (self.mixer, 1))
        self.connect (self.mixer, self)
Exemplo n.º 15
0
    def __init__(self, demodulator, access_code=None, callback=None, threshold=-1):
        """
	Hierarchical block for demodulating and deframing packets.

	The input is the complex modulated signal at baseband.
        Demodulated packets are sent to the handler.

        Args:
            demodulator: instance of demodulator class (gr_block or hier_block2) (complex baseband in)
            access_code: AKA sync vector (string of 1's and 0's)
            callback: function of two args: ok, payload (ok: bool; payload: string)
            threshold: detect access_code with up to threshold bits wrong (-1 -> use default) (int)
	"""

        gr.hier_block2.__init__(
            self, "demod_pkts", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)  # Input signature
        )  # Output signature

        self._demodulator = demodulator
        if access_code is None:
            access_code = packet_utils.default_access_code
        if not packet_utils.is_1_0_string(access_code):
            raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)
        self._access_code = access_code

        if threshold == -1:
            threshold = 12  # FIXME raise exception

        self._rcvd_pktq = gr.msg_queue()  # holds packets from the PHY
        self.correlator = digital.correlate_access_code_bb(access_code, threshold)

        self.framer_sink = digital.framer_sink_1(self._rcvd_pktq)
        self.connect(self, self._demodulator, self.correlator, self.framer_sink)

        self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
Exemplo n.º 16
0
def main():
    parser = OptionParser(option_class=eng_option)
    parser.add_option("-f", "--frequency", type="eng_float", default=929.5e6,
                      help="set receive center frequency to Hz", metavar="Hz")
    parser.add_option("-R", "--rx-subdev-spec", type="subdev",
                      help="select USRP Rx side A or B (default=first daughterboard found)")
    parser.add_option("-c", "--calibration", type="eng_float", default=0.0,
                      help="set frequency offset to Hz", metavar="Hz")
    parser.add_option("-g", "--gain", type="int",
                      help="set RF gain", metavar="dB")
    parser.add_option("-F", "--from-file", default=None,
                      help="Read from file instead of USRP")
    parser.add_option("-l", "--log", action="store_true", default=False,
                      help="log flowgraph to files (LOTS of data)")
    parser.add_option("-v", "--verbose", action="store_true", default=False,
                      help="display debug output")
    (options, args) = parser.parse_args()

    if options.verbose:
        print options

    queue = gr.msg_queue()
    tb = app_top_block(options, queue)
    runner = pager.queue_runner(queue)

    try:
        tb.run()
    except KeyboardInterrupt:
        pass

    runner.end()
Exemplo n.º 17
0
	def __init__(self, parent, title, vlen, decim,gsz):
		self._vlen = vlen
		self._parent = parent
		self._title = title
		print "Initing block: %s" % title

		self.plotQueue = Queue.Queue()
		self.win = matplotsink.matplotsink(parent,title, self.plotQueue,gsz)		

		self._item_size = self._size*self._vlen
		#init hier block
		gr.hier_block2.__init__(
			self, 'plot_sink',
			gr.io_signature(1, 1, self._item_size),
			gr.io_signature(0, 0, 0),
		)
		#create blocks		
		self._msgq = gr.msg_queue(2)
		message_sink = gr.message_sink(self._item_size, self._msgq, False)
		#connect
		self.connect(self, message_sink)
		#setup thread
		threading.Thread.__init__(self)
		self.setDaemon(True)
		self.start() 
Exemplo n.º 18
0
    def __init__(self, sps, channel_decim, channel_taps, options, usrp_rate, channel_rate, lo_freq):
        gr.hier_block2.__init__(self, "rx_channel_fm",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_float))

        chan = gr.freq_xlating_fir_filter_ccf(int(channel_decim), channel_taps, lo_freq, usrp_rate)

        symbol_decim = 1
        symbol_rate = 4800

        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)

        symbol_coeffs = gr.firdes_root_raised_cosine(1.0,
                                                     channel_rate,
                                                     symbol_rate, 
                                                     1.0,
                                                     51)
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        demod_fsk4 = fsk4.demod_ff(autotuneq, channel_rate, symbol_rate)
 
        self.connect (self, chan, fm_demod, symbol_filter, demod_fsk4, self)
Exemplo n.º 19
0
    def __init__(self, input_is_real=False, baseband_freq=0, y_per_div=10, sc_y_per_div=0.5, ref_level=50, sc_ref_level=20,
                 sample_rate=1, fft_size=512, fft_rate=15,
                 average=False, avg_alpha=None, title='', peak_hold=False, ofunc=None, xydfunc=None):

        # initialize common attributes
        self.baseband_freq = baseband_freq
        self.y_divs = 8
        self.y_per_div=y_per_div
        self.sc_y_per_div=sc_y_per_div
        self.ref_level = ref_level
        self.autoscale = False
        self.sc_ref_level = sc_ref_level
        self.sample_rate = sample_rate
        self.fft_size = fft_size
        self.fft_rate = fft_rate
        self.binwidth = float(sample_rate/fft_size)
        self.average = average
        self.ofunc = ofunc
        self.xydfunc = xydfunc
        self.ofunc = ofunc
        if avg_alpha is None:
            self.avg_alpha = 2.0 / fft_rate
        else:
            self.avg_alpha = avg_alpha
        self.title = title
        self.peak_hold = peak_hold
        self.input_is_real = input_is_real
        self.msgq = gr.msg_queue(2)         # queue that holds a maximum of 2 messages
Exemplo n.º 20
0
Arquivo: op25.py Projeto: RegWd/gr-baz
 def __init__(self, traffic_msgq=None, key=None):
     gr.hier_block2.__init__(self, "op25_decoder",
                           gr.io_signature(1, 1, gr.sizeof_float),
                           gr.io_signature(1, 1, gr.sizeof_float))
     
     self.traffic_msgq = traffic_msgq
     self.key = key
     
     if self.traffic_msgq is None:
         self.traffic_msgq = gr.msg_queue(2)
     
     self.slicer = None
     try:
         levels = [ -2.0, 0.0, 2.0, 4.0 ]
         self.slicer = _op25.fsk4_slicer_fb(levels)
         self.p25_decoder = _op25.decoder_bf()
         self.p25_decoder.set_msgq(self.traffic_msgq)
         if _verbose:
             print "Using new decoder_bf"
     except:
         try:
             self.p25_decoder = _op25.decoder_ff(self.traffic_msgq)   # LEGACY
             if _verbose:
                 print "Using legacy decoder_ff"
         except:
             raise Exception("Could not find a decoder to use")
     
     if (self.key is not None) and (len(self.key) > 0): # Relates to key string passed in from GRC block
         self.set_key(self.key)
     
     if self.slicer:
         self.connect(self, self.slicer, self.p25_decoder)
     else:
         self.connect(self, self.p25_decoder)
     self.connect(self.p25_decoder, self)
Exemplo n.º 21
0
    def xtest_004(self):
        vlen = 4
        tune = counter4(self, 1)
        tune_delay = 1
        dwell_delay = 2
        msgq = gr.msg_queue()

        src_data = tuple([float(x) for x in
                          ( 1,  2,  3,  4,
                            9,  6, 11,  8,
                            5, 10,  7, 12,
                            13, 14, 15, 16
                            )])

        expected_results = tuple([float(x) for x in
                                  ( 9, 10, 11, 12)])

        src = gr.vector_source_f(src_data, False)
        s2v = gr.stream_to_vector(gr.sizeof_float, vlen)
        stats = gr.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay)
        self.tb.connect(src, s2v, stats)
        self.tb.run()
        self.assertEqual(1, msgq.count())
        for i in range(1):
            m = parse_msg(msgq.delete_head())
            #print "m =", m.center_freq, m.data
            self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data)
Exemplo n.º 22
0
Arquivo: op25.py Projeto: RegWd/gr-baz
 def __init__(self, channel_rate, auto_tune_msgq=None):
     gr.hier_block2.__init__(self, "op25_fsk4",
                           gr.io_signature(1, 1, gr.sizeof_float),
                           gr.io_signature(1, 1, gr.sizeof_float))
     
     self.symbol_rate = SYMBOL_RATE
     
     #print "Channel rate:", channel_rate
     self.channel_rate = channel_rate
     self.auto_tune_msgq = auto_tune_msgq
     
     if self.auto_tune_msgq is None:
         self.auto_tune_msgq = gr.msg_queue(2)
     
     # C4FM demodulator
     #print "Symbol rate:", self.symbol_rate
     try:
         self.demod_fsk4 = _op25.fsk4_demod_ff(self.auto_tune_msgq, self.channel_rate, self.symbol_rate)
         if _verbose:
             print "Using new fsk4_demod_ff"
     except:
         try:
             self.demod_fsk4 = fsk4.demod_ff(self.auto_tune_msgq, self.channel_rate, self.symbol_rate)   # LEGACY
             if _verbose:
                 print "Using legacy fsk4.demod_ff"
         except:
             raise Exception("Could not find a FSK4 demodulator to use")
     
     self.connect(self, self.demod_fsk4, self)
Exemplo n.º 23
0
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        # hard-coded known symbol
        ks1 = known_symbols_4512_1[0:options.occupied_tones]
        ks2 = known_symbols_4512_2[0:options.occupied_tones]

        self._rcvd_pktq = gr.msg_queue()

        # accepts messages from the outside world
        self.ofdm_mapper = gr.ofdm_bpsk_mapper(4, options.occupied_tones, options.fft_length, ks1, ks2)
        self.ofdm_corr  = gr.ofdm_correlator(options.occupied_tones, options.fft_length, 0, ks1, ks2)
        self.ofdm_framer = gr.ofdm_frame_sink(self._rcvd_pktq, options.occupied_tones)
    
        if 0: # set to 1 to put the correlator in the path to take over the signalling
            self.connect((self.ofdm_mapper, 0), (self.ofdm_corr, 0))
            self.connect((self.ofdm_corr, 0), (self.ofdm_framer, 0))
            self.connect((self.ofdm_corr, 1), (self.ofdm_framer, 1))

            self.connect((self.ofdm_mapper,0), gr.file_sink(gr.sizeof_gr_complex*options.fft_length, "ofdm_mapper.dat"))
            self.connect((self.ofdm_corr,0), gr.file_sink(gr.sizeof_gr_complex*options.occupied_tones, "ofdm_corr.dat"))
            self.connect((self.ofdm_corr,1), gr.file_sink(gr.sizeof_char, "ofdm_sig.dat"))

        else:
            self.connect((self.ofdm_mapper, 0), (self.ofdm_framer, 0))
            self.connect((self.ofdm_mapper, 1), (self.ofdm_framer, 1))

            self.connect((self.ofdm_mapper,0), gr.file_sink(gr.sizeof_gr_complex*options.fft_length, "ofdm_mapper.dat"))
            self.connect((self.ofdm_mapper,1), gr.file_sink(gr.sizeof_char, "ofdm_sig.dat"))

        self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
Exemplo n.º 24
0
    def __init__(self, filename=None, capture=None, verbose=False, freq_error=-0.0021875):
        gr.top_block.__init__(self) 
        self.verbose = verbose
        self.rx_chips_min = 16
        self.chip_error_threshold = 10

        if None != filename:
            self.source = blocks.file_source(gr.sizeof_gr_complex, filename)
        else:
            self.source = osmosdr.source()
            #print self.source.get_gain_range().to_pp_string()
            self.source.set_sample_rate(1.6e6)
            self.source.set_center_freq(868.95e6, 0)
            self.source.set_freq_corr(0, 0)
            self.source.set_gain_mode(0, 0)
            # -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0
            self.source.set_gain(14, 0)
            self.source.set_if_gain(42, 0)

        if None != capture:
            self.sink = blocks.file_sink(gr.sizeof_gr_complex, capture)
        else:
            self.msgq = gr.msg_queue(4)
            self.sink = wmbus_phy1(msgq=self.msgq, verbose=verbose, freq_error=freq_error);
            self._watcher = _queue_watcher_thread(self.msgq, self.callback)
        
        self.connect(self.source, self.sink)
Exemplo n.º 25
0
    def __init__(self, istx, args, bandwidth, freq=None,
                 gain=None, spec=None, antenna=None):
        
        if(istx):
            self.u = uhd.usrp_sink(device_addr=args, stream_args=uhd.stream_args('fc32'))
            #self.u = uhd.usrp_sink(device_addr=args,
            #                       io_type=uhd.io_type.COMPLEX_FLOAT32,
            #                       num_channels=1)

	    # to monitor the events raised in case there was an underflow (U) or late-msg (L) problem #
            self._out_pktq = gr.msg_queue()
            self.u_amsg_source = uhd.amsg_source(args, self._out_pktq)

        else:
            self.u = uhd.usrp_source(device_addr=args, stream_args=uhd.stream_args('fc32'))

        self._args = args
        self._ant  = antenna
        self._spec = spec
        self._gain = self.set_gain(gain)
        self._freq = self.set_freq(freq)

        self._rate = self.set_sample_rate(bandwidth)

        # Set the subdevice spec
        if(spec):
            self.u.set_subdev_spec(spec, 0)

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

	time.sleep(1)
Exemplo n.º 26
0
    def __init__(self, *args, **kwargs):
        """
	Hierarchical block for O-QPSK demodulation.

	The input is the complex modulated signal at baseband.
        Demodulated packets are sent to the handler.

        @param callback:  function of two args: ok, payload
        @type callback: ok: bool; payload: string
        @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default)
        @type threshold: int

        See ieee802_15_4_demod for remaining parameters.
	"""
	try:
		self.callback = kwargs.pop('callback')
		self.threshold = kwargs.pop('threshold')
	except KeyError:
		pass

	gr.hier_block2.__init__(self, "ieee802_15_4_demod_pkts",
				gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input
				gr.io_signature(0, 0, 0))  # Output

        self._rcvd_pktq = gr.msg_queue()          # holds packets from the PHY
        self.ieee802_15_4_demod = ieee802_15_4.ieee802_15_4_demod(self, *args, **kwargs)
        self._packet_sink = ucla.ieee802_15_4_packet_sink(self._rcvd_pktq, self.threshold)

        print "GR: ieee802_15_4_pkt: Connecting demodulator and packet sink."
        self.connect(self, self.ieee802_15_4_demod, self._packet_sink)

        self._watcher = _queue_watcher_thread(self._rcvd_pktq, self.callback)
Exemplo n.º 27
0
    def __init__(self, mode, input_rate=0, context=None):
        assert input_rate > 0
        self.__input_rate = input_rate
        gr.hier_block2.__init__(
            self, 'RTTY demodulator',
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1))
        
        channel_filter = self.__make_channel_filter()

        self.__text = u''
        self.__char_queue = gr.msg_queue(limit=100)
        self.__char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True)

        self.connect(
            self,
            channel_filter,
            self.__make_demodulator(),
            self.__char_sink)
        
        self.connect(
            channel_filter,
            self.__make_audio_filter(),
            blocks.rotator_cc(rotator_inc(self.__demod_rate, 2000 + self.__spacing / 2)),
            blocks.complex_to_real(vlen=1),
            analog.agc2_ff(
                reference=dB(-10),
                attack_rate=8e-1,
                decay_rate=8e-1),
            self)
Exemplo n.º 28
0
    def __init__(self, access_code=None, threshold=-1):
        """
        Create a new packet deframer.
        @param access_code: AKA sync vector
        @type access_code: string of 1's and 0's
        @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default)
        @type threshold: int
        """

        gr.hier_block2.__init__(
            self,
            "demod_pkts2",
            gr.io_signature(1, 1, 1),
            gr.io_signature(1, 1, 1),
        )

        if not access_code:
            access_code = packet_utils.default_access_code
        if not packet_utils.is_1_0_string(access_code):
            raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,)

        if threshold == -1:
            threshold = 12              # FIXME raise exception

        msgq = gr.msg_queue(4)          # holds packets from the PHY
        self.correlator = gr_digital.correlate_access_code_bb(access_code, threshold)

        self.framer_sink = gr.framer_sink_1(msgq)
        self.connect(self, self.correlator, self.framer_sink)
        self._queue_to_blob = _queue_to_blob(msgq)
        self.connect(self._queue_to_blob, self)
Exemplo n.º 29
0
    def test_002_t (self):
        # CRC-16 test from section 5.2.1.9 in 802.15.4-2011
        pad = (0xff,) * 8
        src_data = pad + (0x55, 0x55, 0x90, 0x4e, 0x10, 0x05, 0x40, 0x00, 0x56, 0x27, 0x9e) + pad
        src_data_list = hex_list_to_binary_list(src_data)
        expected_str = '\x40\x00\x56\x27\x9e'

        rcvd_pktq = gr.msg_queue()

        src = blocks.vector_source_b(src_data_list)
        correlator = digital.correlate_access_code_bb('0101010101011001000001001110', 1)
        framer_sink = ieee802154g.framer_sink_mrfsk(rcvd_pktq)
        vsnk = blocks.vector_sink_b()

        self.tb.connect(src, correlator, framer_sink)
        self.tb.connect(correlator, vsnk)
        self.tb.run ()

        # check data
        self.assertEquals(1, rcvd_pktq.count())
        result_msg = rcvd_pktq.delete_head()
        fec = int(result_msg.type())
        self.assertEquals(0, fec)
        phr = int(result_msg.arg1())
        self.assertEquals(0x1005, phr)
        crc_ok = int(result_msg.arg2())
        self.assertEquals(1, crc_ok)
        self.assertEquals(expected_str, result_msg.to_string())
Exemplo n.º 30
0
  def publish_rx_spectrum(self,fftlen):
    ## RX Spectrum

    fftlen = 256
    my_window = window.hamming(fftlen) #.blackmanharris(fftlen)
    rxs_sampler = vector_sampler(gr.sizeof_gr_complex,fftlen)
    rxs_trigger = gr.vector_source_b(concatenate([[1],[0]*199]),True)
    rxs_window = blocks.multiply_const_vcc(my_window)
    rxs_spectrum = gr.fft_vcc(fftlen,True,[],True)
    rxs_mag = gr.complex_to_mag(fftlen)
    rxs_avg = gr.single_pole_iir_filter_ff(0.01,fftlen)
    rxs_logdb = gr.nlog10_ff(20.0,fftlen,-20*log10(fftlen))
    rxs_decimate_rate = gr.keep_one_in_n(gr.sizeof_float*fftlen,1)
    msgq = gr.msg_queue(5)
    rxs_msg_sink = gr.message_sink(gr.sizeof_float*fftlen,msgq,True)
    self.connect(rxs_trigger,(rxs_sampler,1))
    t = self.u if self.filter is None else self.filter
    self.connect(t,rxs_sampler,rxs_window,
                 rxs_spectrum,rxs_mag,rxs_avg,rxs_logdb, rxs_decimate_rate,
                 rxs_msg_sink)
    self.servants.append(corba_data_buffer_servant("spectrum",fftlen,msgq))

    print "RXS trigger unique id", rxs_trigger.unique_id()
    
    print "Publishing RX baseband under id: spectrum"
Exemplo n.º 31
0
    def __init__(self,
                 parent,
                 title='Eye Diagram',
                 sample_rate=1,
                 size=default_scopesink_size,
                 frame_decim=default_frame_decim,
                 samples_per_symbol=10,
                 num_plots=100,
                 sym_decim=20,
                 v_scale=default_v_scale,
                 t_scale=None,
                 num_inputs=1,
                 **kwargs):

        if t_scale == 0:
            t_scale = None
        if v_scale == 0:
            v_scale = default_v_scale

        gr.hier_block2.__init__(
            self, "datascope_sink_f",
            gr.io_signature(num_inputs, num_inputs, gr.sizeof_float),
            gr.io_signature(0, 0, 0))

        msgq = gr.msg_queue(2)  # message queue that holds at most 2 messages
        self.st = gr.message_sink(gr.sizeof_float, msgq, dont_block=1)
        self.connect((self, 0), self.st)

        self.win = datascope_window(
            datascope_win_info(
                msgq,
                sample_rate,
                frame_decim,
                v_scale,
                t_scale,
                #None,  # scopesink (not used)
                title=title),
            parent,
            samples_per_symbol=samples_per_symbol,
            num_plots=num_plots,
            sym_decim=sym_decim,
            size=size)
Exemplo n.º 32
0
    def __init__(self, options, context):
        gr.top_block.__init__(self)
        pubsub.__init__(self)
        self._options = options
        self._queue = gr.msg_queue()
        self._rate = int(options.rate)

        self._resample = None
        self._setup_source(options)

        self._rx_path = air_modes.rx_path(self._rate, options.threshold,
                                          self._queue, options.pmf,
                                          options.dcblock)

        #now subscribe to set various options via pubsub
        self.subscribe("freq", self.set_freq)
        self.subscribe("gain", self.set_gain)
        self.subscribe("rate", self.set_rate)
        self.subscribe("rate", self._rx_path.set_rate)
        self.subscribe("threshold", self._rx_path.set_threshold)
        self.subscribe("pmf", self._rx_path.set_pmf)

        self.publish("freq", self.get_freq)
        self.publish("gain", self.get_gain)
        self.publish("rate", self.get_rate)
        self.publish("threshold", self._rx_path.get_threshold)
        self.publish("pmf", self._rx_path.get_pmf)

        if self._resample is not None:
            self.connect(self._u, self._resample, self._rx_path)
        else:
            self.connect(self._u, self._rx_path)

        #Publish messages when they come back off the queue
        server_addr = ["inproc://modes-radio-pub"]
        if options.tcp is not None:
            server_addr += ["tcp://*:%i" % options.tcp]

        self._sender = air_modes.zmq_pubsub_iface(context,
                                                  subaddr=None,
                                                  pubaddr=server_addr)
        self._async_sender = gru.msgq_runner(self._queue, self.send)
Exemplo n.º 33
0
    def __init__(self,
                 parent,
                 title='',
                 sample_rate=1,
                 size=(495, 450),
                 frame_rate=5,
                 const_size=1024,
                 mod='DBPSK'):
        #init
        gr.hier_block2.__init__(
            self,
            "const_sink",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(0, 0, 0),
        )
        self.sd = blks2.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=frame_rate,
            vec_len=const_size,
        )
        self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)
        self.gain = gr.multiply_const_cc(utils.gain[mod])
        msgq = gr.msg_queue(2)
        sink = gr.message_sink(gr.sizeof_gr_complex * const_size, msgq, True)
        #connect
        self.connect(self, self.agc, self.gain, self.sd, sink)

        #controller
        def setter(p, k, x):
            p[k] = x

        self.controller = pubsub()
        #initial update
        common.input_watcher(msgq, self.controller, MSG_KEY)
        #create window
        self.win = const_window(parent=parent,
                                controller=self.controller,
                                size=size,
                                title=title,
                                msg_key=MSG_KEY)
        common.register_access_methods(self, self.win)
Exemplo n.º 34
0
    def __init__(self, rate): #TODO pass in chanlist
        gr.hier_block2.__init__(self,
                                "smartnet_ctrl_rx",
                                gr.io_signature(1,1,gr.sizeof_gr_complex),
                                gr.io_signature(0,0,0))

        self.set_assign_callback(None)
        self._queue = gr.msg_queue()
        self._async_sender = gru.msgq_runner(self._queue, self.msg_handler)

        self._syms_per_sec = 3600.
        self._sps = rate / self._syms_per_sec

        self._demod = scanner.fsk_demod(self._sps, 0.1)
        self._sof = digital.correlate_access_code_tag_bb("10101100",
                                                          0,
                                                         "smartnet_preamble")
        self._deinterleave = scanner.deinterleave()
        self._crc = scanner.crc(self._queue)
        self.connect(self, self._demod, self._sof, self._deinterleave, self._crc)
Exemplo n.º 35
0
    def __init__(self, rate): #TODO pass in chanlist
        gr.hier_block2.__init__(self,
                                "edacs_ctrl_rx",
                                gr.io_signature(1,1,gr.sizeof_gr_complex),
                                gr.io_signature(0,0,0))

        self.set_assign_callback(None)
        self._queue = gr.msg_queue()
        self._async_sender = gru.msgq_runner(self._queue, self.msg_handler)

        self._syms_per_sec = 9600.
        self._sps = rate / self._syms_per_sec

        self._demod = scanner.fsk_demod(self._sps, 0.575)
        self._invert = scanner.invert()
        self._sof = digital.correlate_access_code_tag_bb("010101010101010101010111000100100101010101010101",
                                                          0,
                                                         "edacs_preamble")
        self._rx = scanner.edacs_pkt_rx(self._queue)
        self.connect(self, self._demod, self._invert, self._sof, self._rx)
Exemplo n.º 36
0
 def __init__(self, packet_source=None, payload_length=0):
     if not payload_length: #get payload length
         payload_length = DEFAULT_PAYLOAD_LEN
     if payload_length%self._item_size_in != 0:  #verify that packet length is a multiple of the stream size
         raise ValueError, 'The payload length: "%d" is not a mutiple of the stream size: "%d".'%(payload_length, self._item_size_in)
     #initialize hier2
     gr.hier_block2.__init__(
         self,
         "ofdm_mod",
         gr.io_signature(1, 1, self._item_size_in), # Input signature
         gr.io_signature(1, 1, packet_source._hb.output_signature().sizeof_stream_item(0)) # Output signature
     )
     #create blocks
     msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT)
     msg_sink = blocks.message_sink(self._item_size_in, msgq, False) #False -> blocking
     #connect
     self.connect(self, msg_sink)
     self.connect(packet_source, self)
     #start thread
     _packet_encoder_thread(msgq, payload_length, packet_source.send_pkt)
Exemplo n.º 37
0
    def __init__(self, input_q, output_q, endpoint, **kwds):
        global my_input_q, my_output_q, my_recv_q, my_port
        host, port = endpoint.split(':')
        if my_port is not None:
            raise AssertionError('this server is already active on port %s' %
                                 my_port)
        my_input_q = input_q
        my_output_q = output_q
        my_port = int(port)

        my_recv_q = gr.msg_queue(10)

        SEND_BYTES = 1024
        NTHREADS = 10  # TODO: make #threads a function of #plots ?
        self.server = create_server(application,
                                    host=host,
                                    port=my_port,
                                    send_bytes=SEND_BYTES,
                                    expose_tracebacks=True,
                                    threads=NTHREADS)
Exemplo n.º 38
0
	def __init__(self, vlen, decim, callback):
		self._vlen = vlen
		self._callback = callback
		self._item_size = self._size*self._vlen
		#init hier block
		gr.hier_block2.__init__(
			self, 'variable_sink',
			gr.io_signature(1, 1, self._item_size),
			gr.io_signature(0, 0, 0),
		)
		#create blocks
		self._decimator = gr.keep_one_in_n(self._item_size, decim)
		self._msgq = gr.msg_queue(2)
		message_sink = gr.message_sink(self._item_size, self._msgq, False)
		#connect
		self.connect(self, self._decimator, message_sink)
		#setup thread
		threading.Thread.__init__(self)
		self.setDaemon(True)
		self.start() 
Exemplo n.º 39
0
    def __init__(self,
                 input_is_real=False,
                 baseband_freq=0,
                 y_per_div=10,
                 ref_level=50,
                 sample_rate=1,
                 fac_size=512,
                 fac_rate=default_fac_rate,
                 average=False,
                 avg_alpha=None,
                 title='',
                 peak_hold=False):

        self._item_size = gr.sizeof_gr_complex
        if input_is_real:
            self._item_size = gr.sizeof_float

        gr.hier_block2.__init__(
            self,
            "Fast AutoCorrelation",
            gr.io_signature(1, 1, self._item_size),
            gr.io_signature(0, 0, 0),
        )

        # initialize common attributes
        self.baseband_freq = baseband_freq
        self.y_divs = 8
        self.y_per_div = y_per_div
        self.ref_level = ref_level
        self.sample_rate = sample_rate
        self.fac_size = fac_size
        self.fac_rate = fac_rate
        self.average = average
        if (avg_alpha is None) or (avg_alpha <= 0):
            self.avg_alpha = 0.20 / fac_rate  # averaging needed to be slowed down for very slow rates
        else:
            self.avg_alpha = avg_alpha
        self.title = title
        self.peak_hold = peak_hold
        self.input_is_real = input_is_real
        self.msgq = gr.msg_queue(2)  # queue that holds a maximum of 2 messages
Exemplo n.º 40
0
    def __init__(self,
                 type='BER',
                 win_size=default_win_size,
                 bits_per_symbol=2):
        """
		Error rate constructor.
		@param type a string 'BER' or 'SER'
		@param win_size the number of samples to calculate over
		@param bits_per_symbol the number of information bits per symbol (BER only)
		"""
        #init
        gr.hier_block2.__init__(
            self,
            'error_rate',
            gr.io_signature(2, 2, gr.sizeof_char),
            gr.io_signature(1, 1, gr.sizeof_float),
        )
        assert type in ('BER', 'SER')
        self._max_samples = win_size
        self._bits_per_symbol = bits_per_symbol
        #setup message queue
        msg_source = gr.message_source(gr.sizeof_float, 1)
        self._msgq_source = msg_source.msgq()
        msgq_sink = gr.msg_queue(2)
        msg_sink = gr.message_sink(gr.sizeof_char, msgq_sink,
                                   False)  #False -> blocking
        inter = gr.interleave(gr.sizeof_char)
        #start thread
        self._num_errs = 0
        self._err_index = 0
        self._num_samps = 0
        self._err_array = numpy.zeros(self._max_samples, numpy.int8)
        if type == 'BER':
            input_watcher(msgq_sink, self._handler_ber)
        elif type == 'SER':
            input_watcher(msgq_sink, self._handler_ser)
        #connect
        self.connect(msg_source, self)
        self.connect((self, 0), (inter, 0))
        self.connect((self, 1), (inter, 1))
        self.connect(inter, msg_sink)
Exemplo n.º 41
0
	def __init__(self, vlen=1):
		"""!
		Queue sink base contructor.
		@param vlen the vector length
		"""
		self._vlen = vlen
		#initialize hier2
		gr.hier_block2.__init__(
			self, 
			"queue_sink",
			gr.io_signature(1, 1, self._item_size*self._vlen), # Input signature
			gr.io_signature(0, 0, 0) # Output signature
		)
		#create message sink
		self._msgq = gr.msg_queue(4)
		message_sink = blocks_swig0.message_sink(self._item_size*self._vlen, self._msgq, False) #False -> blocking
		#connect
		self.connect(self, message_sink)

		self.arr = None
		self.idx = 0					
Exemplo n.º 42
0
    def __init__(self,
                 if_rate	= None,
                 symbol_rate	= _def_symbol_rate):
        """
	Hierarchical block for P25 demodulation base class

        @param if_rate: sample rate of complex input channel
        @type if_rate: int
	"""
        self.if_rate = if_rate
        self.symbol_rate = symbol_rate
        self.bb_sink = None

        self.baseband_amp = blocks.multiply_const_ff(_def_bb_gain)
        coeffs = op25_c4fm_mod.c4fm_taps(sample_rate=self.if_rate, span=9, generator=op25_c4fm_mod.transfer_function_rx).generate()
        self.symbol_filter = filter.fir_filter_fff(1, coeffs)
        autotuneq = gr.msg_queue(2)
        self.fsk4_demod = op25.fsk4_demod_ff(autotuneq, self.if_rate, self.symbol_rate)

        levels = [ -2.0, 0.0, 2.0, 4.0 ]
        self.slicer = op25_repeater.fsk4_slicer_fb(levels)
Exemplo n.º 43
0
    def __init__(self, mode, input_rate=0, context=None):
        assert input_rate > 0
        self.__input_rate = input_rate
        gr.hier_block2.__init__(
            self, type(self).__name__,
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(1, 1, gr.sizeof_float))
        
        channel_filter = self.__make_channel_filter()

        self.__char_queue = gr.msg_queue(limit=100)
        self.__char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True)

        # The output of the channel filter is oversampled so we don't need to
        # interpolate for the audio monitor. So we'll downsample before going into
        # the demodulator.
        samp_per_sym = 8
        downsample = self.__demod_rate / samp_per_sym / self.__symbol_rate
        assert downsample % 1 == 0
        downsample = int(downsample)

        self.connect(
            self,
            channel_filter,
            blocks.keep_one_in_n(gr.sizeof_gr_complex, downsample),
            psk31_coherent_demodulator_cc(samp_per_sym=samp_per_sym),
            psk31_constellation_decoder_cb(
                varicode_decode=True,
                differential_decode=True),
            self.__char_sink)
        
        self.connect(
            channel_filter,
            blocks.rotator_cc(rotator_inc(self.__demod_rate, self.__audio_frequency)),
            blocks.complex_to_real(vlen=1),
            analog.agc2_ff(
                reference=dB(-10),
                attack_rate=8e-1,
                decay_rate=8e-1),
            self)
Exemplo n.º 44
0
    def __init__(self):
        gr.top_block.__init__(self, "CC430 Transmitter")

        self.sent_pkts = 0

        # 5555 5555 2c6e fd00 0071 da0b e2
        self.packet = chr(0x55) * 4  # preamble
        self.packet += chr(0x2c) + chr(0x6e)  # sync
        self.packet += chr(0xfc)  # length
        self.packet += chr(0x00) + chr(0x00) + chr(0x00)  # payload
        self.packet += chr(0x71) + chr(0xda) + chr(0x0b) + chr(
            0xe2)  # CRC (currently incorrect)

        # Variables
        self.samp_rate = samp_rate = 125e3
        self.f_center = f_center = 868e6
        self.bandwidth = bandwidth = 200e3
        self.gain = gain = 5

        self.msgq = msgq = gr.msg_queue()

        # Blocks
        self.uhd_sink = uhd.usrp_sink(
            device_addr="",
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_sink.set_samp_rate(samp_rate)
        self.uhd_sink.set_center_freq(f_center, 0)
        self.uhd_sink.set_gain(gain, 0)
        self.uhd_sink.set_bandwidth(bandwidth, 0)

        self.msg_src = gr.message_source(1, msgq)

        self.msk = level.msk_mod_bc(samples_per_symbol=2, bt=0.3)

        # Connections
        self.connect(self.msg_src, self.msk, self.uhd_sink)
Exemplo n.º 45
0
def main():
    parser = OptionParser(option_class=eng_option)
    parser.add_option("-f",
                      "--factor",
                      type="eng_float",
                      default=1.0,
                      help="multiply factor")
    parser.add_option("-i",
                      "--input-file",
                      type="string",
                      default="in.dat",
                      help="specify the input file")
    parser.add_option("-r",
                      "--repeat",
                      action="store_true",
                      default=False,
                      help="repeat input in a loop")
    parser.add_option("-v",
                      "--reverse",
                      action="store_true",
                      default=False,
                      help="reverse polarity")
    parser.add_option("-s", "--sample-rate", type="int", default=48000)
    parser.add_option("-O",
                      "--audio-output",
                      type="string",
                      default="",
                      help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
    (options, args) = parser.parse_args()

    queue = gr.msg_queue()
    tb = app_top_block(options, queue)
    try:
        tb.start()
        while 1:
            if not queue.empty_p():
                sys.stderr.write("main: q.delete_head()\n")
                msg = queue.delete_head()
    except KeyboardInterrupt:
        tb.stop()
Exemplo n.º 46
0
    def __init__(self, fft_len, sample_rate, tune_freq, average, rate, width,
                 height):
        gr.hier_block2.__init__(self, "ascii plot",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        self.fft_len = fft_len
        self.sample_rate = sample_rate
        self.average = average
        self.tune_freq = tune_freq
        self.rate = rate
        self.width = width
        self.height = height

        self.msgq = gr.msg_queue(2)

        #######BLOCKS#####
        self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
        self.one_in_n = blocks.keep_one_in_n(
            gr.sizeof_gr_complex * self.fft_len,
            max(1, int(self.sample_rate / self.fft_len / self.rate)))

        mywindow = window.blackmanharris(self.fft_len)
        self.fft = fft.fft_vcc(self.fft_len, True, (), True)

        self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
        self.avg = grfilter.single_pole_iir_filter_ff(1.0, self.fft_len)
        self.log = blocks.nlog10_ff(
            10,
            self.fft_len,
            -10 * math.log10(self.fft_len)  # Adjust for number of bins
            - 10 * math.log10(self.sample_rate))  # Adjust for sample rate

        self.sink = blocks.message_sink(gr.sizeof_float * self.fft_len,
                                        self.msgq, True)
        #####CONNECTIONS####
        self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2,
                     self.avg, self.log, self.sink)

        self._main = main_thread(self.msgq, self.fft_len, self.sample_rate,
                                 self.tune_freq, self.width, self.height)
Exemplo n.º 47
0
    def configure_metadata(self, config):
        meta_mod = config['module']
        if meta_mod.endswith('.py'):
            meta_mod = meta_mod[:-3]
        try:
            self.metadata = importlib.import_module(meta_mod)
        except:
            self.metadata = None
            sys.stderr.write(
                "Error: unable to import metadata module: %s\n%s\n" %
                (config['module'], sys.exc_info()[1]))

        idx = 0
        for stream in config['streams']:
            if 'stream_name' in stream and stream['stream_name'] != "":
                stream_name = stream['stream_name']
                if stream_name in self.meta_streams:
                    sys.stderr.write(
                        "Ignoring duplicate metadata stream #%d [%s]\n" %
                        (idx, stream_name))
                    break
                try:
                    meta_q = gr.msg_queue(10)
                    meta_s = self.metadata.meta_server(meta_q,
                                                       stream,
                                                       debug=self.verbosity)
                    self.meta_streams[stream_name] = (meta_s, meta_q)
                    sys.stderr.write(
                        "Configuring metadata stream #%d [%s]: %s\n" %
                        (idx, stream_name, stream['icecastServerAddress'] +
                         "/" + stream['icecastMountpoint']))
                except:
                    sys.stderr.write(
                        "Error configuring metadata stream #%d; %s\n" %
                        (idx, sys.exc_info()[1]))
                    #sys.exc_clear()
            else:
                sys.stderr.write("Ignoring unnamed metadata stream #%d\n" %
                                 idx)
            idx += 1
Exemplo n.º 48
0
    def __init__(self):
        gr.top_block.__init__(self, "Testbb")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.gr_head_0 = gr.head(gr.sizeof_char * 1, 1040)
        self.gr_rds_data_decoder_0_0 = rds.data_decoder(gr.msg_queue())
        self.gr_rds_data_encoder_1 = rds.data_encoder(
            "/media/dimitris/mywork/gr/dimitris/rds/trunk/src/utils/rds_data.xml"
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_rds_data_encoder_1, 0), (self.gr_head_0, 0))
        self.connect((self.gr_head_0, 0), (self.gr_rds_data_decoder_0_0, 0))
Exemplo n.º 49
0
    def __build_graph(self, source, capture_rate):
        # tell the scope the source rate
        self.spectrum.set_sample_rate(capture_rate)
        # channel filter
        self.channel_offset = 0.0
        channel_decim = capture_rate // self.channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2;
        trans_centre = trans_width + (trans_width / 2)
        coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN)
        self.channel_filter = gr.freq_xlating_fir_filter_ccf(channel_decim, coeffs, -9500.0, capture_rate)
        self.set_channel_offset(0.0, 0, self.spectrum.win._units)
        # power squelch
        squelch_db = -60
        self.squelch = gr.pwr_squelch_cc(squelch_db, 1e-3, 0, True)
        self.set_squelch_threshold(squelch_db)
        # FM demodulator
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        # symbol filter        
        symbol_decim = 1
        #symbol_coeffs = gr.firdes.root_raised_cosine(1.0, channel_rate, self.symbol_rate, 0.2, 500)
        # boxcar coefficients for "integrate and dump" filter
        samples_per_symbol = channel_rate // self.symbol_rate
        symbol_coeffs = (1.0/samples_per_symbol,)*samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, self.symbol_rate)
        reverser = gr.multiply_const_ff(-1.0)
        # for now no audio output
        sink = gr.null_sink(gr.sizeof_float)
        # connect it all up
        self.__connect([[source, self.channel_filter, self.squelch, fm_demod, symbol_filter, demod_fsk4, reverser, self.slicer, self.p25_decoder, sink],
                        [source, self.spectrum],
                        [symbol_filter, self.signal_scope],
                        [demod_fsk4, self.symbol_scope]])
Exemplo n.º 50
0
    def __init__(self, access_code='', threshold=-1, callback=None):
        """
        packet_demod constructor.
        
        Args:
            access_code: AKA sync vector
            threshold: detect access_code with up to threshold bits wrong (0 -> use default)
            callback: a function of args: ok, payload
        """
        #access code
        if not access_code:  #get access code
            access_code = packet_utils.default_access_code
        if not packet_utils.is_1_0_string(access_code):
            raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (
                access_code, )
        self._access_code = access_code
        #threshold
        if threshold < 0: threshold = DEFAULT_THRESHOLD
        self._threshold = threshold
        #blocks
        msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT)  #holds packets from the PHY
        correlator = digital.correlate_access_code_bb(self._access_code,
                                                      self._threshold)
        framer_sink = digital.framer_sink_1(msgq)
        #initialize hier2
        gr.hier_block2.__init__(
            self,
            "packet_decoder",
            gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
            gr.io_signature(1, 1, 1)  # Output signature
        )

        #connect
        self.connect(self, correlator, framer_sink)
        self.pktout = packet_decoder_out()
        self.connect(self.pktout, self)

        #start thread
        _packet_decoder_thread(msgq, self.pktout.callback)
Exemplo n.º 51
0
    def __init__(self, reactor, send, block, audio_rate):
        self._send = send
        self._queue = gr.msg_queue(limit=100)
        self.__running = [True]
        self._block = block
        self._block.add_audio_queue(self._queue, audio_rate)

        # We don't actually benefit specifically from using a SignalType in this context but it avoids reinventing vocabulary.
        signal_type = SignalType(
            kind='STEREO'
            if self._block.get_audio_queue_channels() == 2 else 'MONO',
            sample_rate=audio_rate)

        send(
            serialize({
                # Not used to discriminate, but it seems worth applying the convention in general.
                u'type': u'audio_stream_metadata',
                u'signal_type': signal_type,
            }))

        reactor.callInThread(_AudioStream_read_loop, reactor, self._queue,
                             self.__deliver, self.__running)
Exemplo n.º 52
0
    def __init__(self, packet_len=500):
        gr.hier_block2.__init__(self, "payload_source",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_char * 1))

        self.packet_len = packet_len

        # initialize the message queues
        self.source_queue = gr.msg_queue()

        ##################################################
        # Blocks
        self.msg_source = blocks.message_source(gr.sizeof_char * 1,
                                                self.source_queue)
        self.stream_to_tagged_stream_txpath = blocks.stream_to_tagged_stream(
            gr.sizeof_char, 1, packet_len, "packet_len")

        ##################################################
        # Connections
        #Data source
        self.connect(self.msg_source, self.stream_to_tagged_stream_txpath,
                     self)
Exemplo n.º 53
0
    def __init__(self, traffic_msgq=None, key=None):
        gr.hier_block2.__init__(self, "op25_decoder",
                                gr.io_signature(1, 1, gr.sizeof_float),
                                gr.io_signature(1, 1, gr.sizeof_float))

        self.traffic_msgq = traffic_msgq
        self.key = key

        if self.traffic_msgq is None:
            self.traffic_msgq = gr.msg_queue(2)

        self.slicer = None
        try:
            levels = [-2.0, 0.0, 2.0, 4.0]
            self.slicer = _op25.fsk4_slicer_fb(levels)
            self.p25_decoder = _op25.decoder_bf()
            self.p25_decoder.set_msgq(self.traffic_msgq)
            if _verbose:
                print "Using new decoder_bf"
        except:
            try:
                self.p25_decoder = _op25.decoder_ff(
                    self.traffic_msgq)  # LEGACY
                if _verbose:
                    print "Using legacy decoder_ff"
            except:
                raise Exception("Could not find a decoder to use")

        if (self.key is not None) and (
                len(self.key) >
                0):  # Relates to key string passed in from GRC block
            self.set_key(self.key)

        if self.slicer:
            self.connect(self, self.slicer, self.p25_decoder)
        else:
            self.connect(self, self.p25_decoder)
        self.connect(self.p25_decoder, self)
Exemplo n.º 54
0
    def __init__(self, mode, input_rate=0, context=None):
        assert input_rate > 0
        gr.hier_block2.__init__(
            self,
            'RTTY demodulator',
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
        )
        self.__text = u''

        baud = _DEFAULT_BAUD  # TODO param
        self.baud = baud

        demod_rate = 6000  # TODO optimize this value
        self.samp_rate = demod_rate  # TODO rename

        self.__channel_filter = MultistageChannelFilter(
            input_rate=input_rate,
            output_rate=demod_rate,
            cutoff_freq=self.__filter_high,
            transition_width=self.__transition)  # TODO optimize filter band
        self.__sharp_filter = grfilter.fir_filter_ccc(
            1,
            firdes.complex_band_pass(1.0, demod_rate, self.__filter_low,
                                     self.__filter_high, self.__transition,
                                     firdes.WIN_HAMMING))
        self.fsk_demod = RTTYFSKDemodulator(input_rate=demod_rate, baud=baud)
        self.__real = blocks.complex_to_real(vlen=1)
        self.__char_queue = gr.msg_queue(limit=100)
        self.char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue,
                                             True)

        self.connect(
            self, self.__channel_filter, self.__sharp_filter, self.fsk_demod,
            rtty.rtty_decode_ff(rate=demod_rate, baud=baud, polarity=False),
            self.char_sink)

        self.connect(self.__sharp_filter, self.__real, self)
Exemplo n.º 55
0
    def __init__(self,
                 input_is_real=False,
                 baseband_freq=0,
                 sample_rate=1,
                 fft_size=512,
                 fft_rate=default_fft_rate,
                 average=False,
                 avg_alpha=None,
                 title=''):

        # initialize common attributes
        self.baseband_freq = baseband_freq
        self.sample_rate = sample_rate
        self.fft_size = fft_size
        self.fft_rate = fft_rate
        self.average = average
        if avg_alpha is None:
            self.avg_alpha = 2.0 / fft_rate
        else:
            self.avg_alpha = avg_alpha
        self.title = title
        self.input_is_real = input_is_real
        self.msgq = gr.msg_queue(2)  # queue up to 2 messages
Exemplo n.º 56
0
    def test_002(self):

        code = tuple(string_to_1_0_list(default_access_code))
        access_code = to_1_0_string(code)
        header = tuple(2*[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]) # len=2
        pad = (0,) * 100
        src_data = code + header + (0,1,0,0,1,0,0,0) + (0,1,0,0,1,0,0,1) + pad
        expected_data = 'HI'

        rcvd_pktq = gr.msg_queue()

        src = blocks.vector_source_b(src_data)
        correlator = digital.correlate_access_code_bb(access_code, 0)
        framer_sink = digital.framer_sink_1(rcvd_pktq)
        vsnk = blocks.vector_sink_b()

        self.tb.connect(src, correlator, framer_sink)
        self.tb.connect(correlator, vsnk)
        self.tb.run()

        result_data = rcvd_pktq.delete_head()
        result_data = result_data.to_string()
        self.assertEqual(expected_data, result_data)
Exemplo n.º 57
0
    def __init__(self, port, gain, soundcard_rate):
        gr.hier_block2.__init__(self, "tx_channel_soundcard",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_float))

        msg_queue = gr.msg_queue(2)
        do_imbe = 1
        do_float = 1
        do_complex = 0
        if soundcard_rate == 96000:
            decim = 1
        else:
            decim = 2  # for 48000
        # per-channel GR source block including these steps:
        # - receive audio chunks from asterisk via UDP
        # - imbe encode
        # - generate float output stream (table lookup method)
        # - generates zero power while no input received
        self.chan = repeater.chan_usrp(port, do_imbe, do_complex, do_float,
                                       1.0, decim, msg_queue)
        self.amp = gr.multiply_const_ff(gain)

        self.connect(self.chan, self.amp, self)
Exemplo n.º 58
0
    def __init__(self, *args, **kwargs):
        """
	Hierarchical block for O-QPSK demodulation.

	The input is the complex modulated signal at baseband.
        Demodulated packets are sent to the handler.

        @param callback:  function of two args: ok, payload
        @type callback: ok: bool; payload: string
        @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default)
        @type threshold: int

        See ieee802_15_4_demod for remaining parameters.
	"""
        try:
            self.callback = kwargs.pop('callback')
            self.threshold = kwargs.pop('threshold')
            self.chan_num = kwargs.pop('channel')
        except KeyError:
            pass

        gr.hier_block2.__init__(
            self,
            "ieee802_15_4_demod_pkts",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input
            gr.io_signature(0, 0, 0))  # Output

        self._rcvd_pktq = gr.msg_queue()  # holds packets from the PHY
        self.ieee802_15_4_demod = ieee802_15_4.ieee802_15_4_demod(
            self, *args, **kwargs)
        self._packet_sink = ucla.ieee802_15_4_packet_sink(
            self._rcvd_pktq, self.threshold)

        self.connect(self, self.ieee802_15_4_demod, self._packet_sink)

        self._watcher = _queue_watcher_thread(self._rcvd_pktq, self.callback,
                                              self.chan_num)
    def __init__(self, fg, access_code=None, callback=None, threshold=-1, *args, **kwargs):
        """
	Hierarchical block for binary FSK demodulation.

	The input is the complex modulated signal at baseband.
        Demodulated packets are sent to the handler.

	@param fg: flow graph
	@type fg: flow graph
        @param access_code: 64-bit sync code
        @type access_code: string of length 8
        @param callback:  function of two args: ok, payload
        @type callback: ok: bool; payload: string
        @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default)
        @type threshold: int

        See cc1k_demod for remaining parameters.
	"""

        if access_code is None:
            #this is 0x999999995a5aa5a5
            access_code = chr(153) + chr(153) + chr(153) + chr(153) + chr(90) + chr(90) + chr(165) + chr(165)
        if not isinstance(access_code, str) or len(access_code) != 8:
            raise ValueError, "Invalid access_code '%r' len '%r'" % (access_code, len(access_code),)
        self._access_code = access_code

        self._rcvd_pktq = gr.msg_queue()          # holds packets from the PHY
        self.cc1k_demod = cc1k.cc1k_demod(fg, *args, **kwargs)
        self._packet_sink = ucla.sos_packet_sink(map(ord, access_code), self._rcvd_pktq, threshold)
        
        fg.connect(self.cc1k_demod, self._packet_sink)
        #filesink = gr.file_sink (gr.sizeof_char, "/tmp/rx.log")
        #fg.connect(self.cc1k_demod,filesink)
      
        gr.hier_block.__init__(self, fg, self.cc1k_demod, None)
        self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
Exemplo n.º 60
0
    def __init__(self,
                 parent,
                 title='',
                 sample_rate=1,
                 size=default_scopesink_size,
                 frame_decim=default_frame_decim,
                 v_scale=default_v_scale,
                 t_scale=None,
                 num_inputs=1,
                 **kwargs):

        gr.hier_block2.__init__(
            self, "scope_sink_f",
            gr.io_signature(num_inputs, num_inputs, gr.sizeof_float),
            gr.io_signature(0, 0, 0))

        msgq = gr.msg_queue(2)  # message queue that holds at most 2 messages
        self.guts = wxgui.oscope_sink_f(sample_rate, msgq)
        for i in range(num_inputs):
            self.connect((self, i), (self.guts, i))

        self.win = scope_window(
            win_info(msgq, sample_rate, frame_decim, v_scale, t_scale,
                     self.guts, title), parent)