Example #1
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")

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

        ##################################################
        # Blocks
        ##################################################
        self.digital_crc32_bb_0 = digital.crc32_bb(False, "packet_len")
        self.blocks_tag_debug_1 = blocks.tag_debug(gr.sizeof_char*1, "Pre-CRC", ""); self.blocks_tag_debug_1.set_display(True)
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "Post-CRC", ""); self.blocks_tag_debug_0.set_display(True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, 100, "packet_len")
        self.blocks_head_0 = blocks.head(gr.sizeof_char*1, 100*5)
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 255, 1000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_head_0, 0))
        self.connect((self.blocks_head_0, 0), (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.digital_crc32_bb_0, 0))
        self.connect((self.digital_crc32_bb_0, 0), (self.blocks_tag_debug_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.blocks_tag_debug_1, 0))
Example #2
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Joystick 101")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 48000

		##################################################
		# Blocks
		##################################################
		self.openavionics_joystick_interface_0 = openavionics.joystick_interface()
		self.openavionics_audio_ptt_0 = openavionics.audio_ptt()
		self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_float*1, "")
		self.blocks_message_debug_0 = blocks.message_debug()
		self.audio_source_0 = audio.source(samp_rate, "", True)

		##################################################
		# Connections
		##################################################
		self.connect((self.openavionics_audio_ptt_0, 0), (self.blocks_tag_debug_0, 0))
		self.connect((self.audio_source_0, 0), (self.openavionics_audio_ptt_0, 0))

		##################################################
		# Asynch Message Connections
		##################################################
		self.msg_connect(self.openavionics_joystick_interface_0, "out", self.openavionics_audio_ptt_0, "in2")
		self.msg_connect(self.openavionics_joystick_interface_0, "out", self.blocks_message_debug_0, "print")
    def test_003_every (self):
        self.tb = gr.top_block ()
        self.rate = 99999999999
        self.interval = 1
        self.duration = 4321

        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1, [])
        self.utag = timing_utils.add_usrp_tags_c(1090e6, self.rate, 0, .98765)
        self.tags = timing_utils.tag_uhd_offset_c(self.rate, self.interval)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex*1, "", "");
        self.tag_dbg.set_display(False)
        self.tb.connect((self.src, 0), (self.utag, 0))
        self.tb.connect((self.utag, 0), (self.tags, 0))
        self.tb.connect((self.tags, 0), (self.tag_dbg, 0))
        e_n_tags = int(ceil(1.0*self.duration / self.interval)) + 3

        self.tb.run ()

        tags = self.tag_dbg.current_tags()
        tprev = None
        for t in tags:
            if pmt.eq(t.key, pmt.intern("rx_time_offset")):
                self.assertAlmostEqual(self.rate, pmt.to_double(pmt.tuple_ref(t.value, 3)),-4)
                self.assertEqual(t.offset, pmt.to_uint64(pmt.tuple_ref(t.value, 2)))
                self.assertTrue((pmt.to_uint64(pmt.tuple_ref(t.value, 2)) / (1.0*self.interval)).is_integer())
                if tprev is not None:
                    tcur = pmt.to_uint64(pmt.tuple_ref(t.value, 0)) + pmt.to_double(pmt.tuple_ref(t.value, 1))
                    self.assertAlmostEqual(tcur-tprev, 1.0*self.interval / self.rate)
                    tprev = tcur
                else:
                    tprev = pmt.to_uint64(pmt.tuple_ref(t.value, 0)) + pmt.to_double(pmt.tuple_ref(t.value, 1))
        self.assertEqual(self.tag_dbg.num_tags(), e_n_tags)
        self.tb = None
	def test_002_t (self):
		# set up fg
		in_data = range(20)
		vlen_in = 5
		
		crop_x = (2,4)
		crop_y = (1,4)
		
		src = blocks.vector_source_c(in_data)
		s2v = blocks.stream_to_vector(8,vlen_in)
		s2ts = blocks.stream_to_tagged_stream(8,vlen_in,len(in_data)/vlen_in,'packet_len')
		crop = radar.crop_matrix_vcvc(vlen_in,crop_x,crop_y)
		v2s = blocks.vector_to_stream(8,crop_x[1]-crop_x[0])
		snk = blocks.vector_sink_c()
		debug = blocks.tag_debug(8,'debug')
		
		self.tb.connect(src,s2v,s2ts,crop,v2s,snk)
		self.tb.connect(v2s,debug)
		self.tb.run ()
		# check data
		ref_data = (7,8,12,13,17,18)
		out_data = snk.data()
		print "INDATA:", in_data
		print "REF: ", ref_data
		print "OUTPUT:", out_data
		for k in range(len(out_data)):
			self.assertEqual(out_data[k].real,ref_data[k])
Example #5
0
    def test_003_t (self):
        src_data = ( 1,  2,  3,  4,  5,  6,  7,  8,  9,  10)
        trg_data = ( 0,  0,  0,  0, 10,  0,  0,  0,  0,   0)

        # Blocks
        src_data = blocks.vector_source_c(src_data)
        src_trig = blocks.vector_source_i(trg_data)

        op = marmote.peak_tagger_cc(
            threshold = 2,
            lookahead = 3,
            delay = 1
        )

        snk_tag = blocks.tag_debug(gr.sizeof_gr_complex, "peak tagger QA")
        snk_data = blocks.vector_sink_c()

        # Connections
        self.tb.connect(src_data, (op,0))
        self.tb.connect(src_trig, (op,1))
        self.tb.connect(op, snk_tag)
        self.tb.connect(op, snk_data)

        self.tb.run()

        # Check data
        x = snk_tag.current_tags()
        y = snk_data.data()

        self.assertEqual(6, y[x[0].offset])
    def test_002_tags(self): 
        start_time = 0.1
        self.duration = 125000
        tnow = time.time()
        
        src_tag = gr.tag_utils.python_to_tag([0, pmt.intern("wall_clock_time"), pmt.from_double(tnow - 10000), pmt.intern("test_002_tags")])
        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1, [src_tag])
        self.throttle = blocks.throttle(gr.sizeof_gr_complex*1, 250000)
        self.dut = timing_utils.system_time_diff_c(True, True, False)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex*1, '', "");
        
        self.tb.connect((self.src, 0), (self.throttle, 0))
        self.tb.connect((self.throttle, 0), (self.dut, 0))
        self.tb.connect((self.dut, 0), (self.tag_dbg, 0))
        
        self.tb.start()
        time.sleep(.01)
        
        tags = self.tag_dbg.current_tags();
        print("Dumping tags")
        for t in tags:
            print( 'Tag:' , t.key, ' ', t.value )
            if pmt.eq(t.key, pmt.intern("wall_clock_time")):
                time_tag = t;
        
        if time_tag:
            self.assertAlmostEqual( tnow, pmt.to_double(time_tag.value), delta=60 )
        else:
            self.assertTrue( False )

        time.sleep(.1)
        self.tb.stop()
Example #7
0
 def setUp (self):
     self.tb = gr.top_block ()
     
     self.N_rb_dl = N_rb_dl = 6
     self.key = "symbol"
     self.out_key = "subframe"
     self.msg_buf_name = "cell_id"
     n_carriers = 12*N_rb_dl
     n_cfi_vec = 16
     intu = np.zeros(n_carriers,dtype=np.complex)
     
     self.src0 = blocks.vector_source_c( intu, False, n_carriers)
     self.src1 = blocks.vector_source_c( intu, False, n_carriers)
     self.src2 = blocks.vector_source_c( intu, False, n_carriers)
     
     self.demux = lte.pcfich_demux_vcvc(N_rb_dl, self.key, self.out_key, self.msg_buf_name)
             
     self.snk0 = blocks.vector_sink_c(n_cfi_vec)
     self.snk1 = blocks.vector_sink_c(n_cfi_vec)
     self.snk2 = blocks.vector_sink_c(n_cfi_vec)
     
     self.tag = blocks.tag_debug(n_cfi_vec * 8, "TAG")
     
     self.tb.connect(self.src0, (self.demux,0) )
     self.tb.connect( (self.demux,0), self.snk0)
     self.tb.connect(self.src1, (self.demux,1) )
     self.tb.connect( (self.demux,1), self.snk1)
     self.tb.connect(self.src2, (self.demux,2) )
     self.tb.connect( (self.demux,2), self.snk2)
     self.tb.connect( (self.demux,0), self.tag)
Example #8
0
 def test_001_t (self):
     tx_data = range(256)*1000
     src = blocks.vector_source_f(tx_data, False)
     but = west.timestamp_tagger_ff(4, 1000)
     sink = blocks.tag_debug(4, "dbg_sink", "timestamp")
     sink.set_display(True)
     self.tb.connect(src, but, sink)
     self.tb.run ()
Example #9
0
 def test_001(self):
     # Just run some data through and make sure it doesn't puke.
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     src = blocks.vector_source_i(src_data)
     op = blocks.tag_debug(gr.sizeof_int, "tag QA")
     self.tb.connect(src, op)
     self.tb.run()
     x = op.current_tags()
Example #10
0
 def test_001(self):
     # Just run some data through and make sure it doesn't puke.
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     src = blocks.vector_source_i(src_data)
     op = blocks.tag_debug(gr.sizeof_int, "tag QA")
     self.tb.connect(src, op)
     self.tb.run()
     x = op.current_tags()
Example #11
0
    def test_002_t(self):
        # Generate frames with AWGN and test SNR estimation
        sample_rate = 10.0e6
        frame_duration = 1.0e-3
        test_duration = 0.1 * frame_duration
        snr = 10
        scale_value = 15.0
        samples_per_frame = int(round(frame_duration * sample_rate))
        samples_per_test = int(round(test_duration * sample_rate))
        random_samples_skip = 0  #np.random.randint(samples_per_frame)
        preamble_seq = zadoffchu(63, 1, 0)
        preamble_pwr_sum = np.sum(np.abs(preamble_seq)**2)

        print "***** Start test 002 *****"
        framer = specmonitor.framer_c(sample_rate, frame_duration,
                                      preamble_seq)
        awgn = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0 / snr)
        add = blocks.add_cc()
        scaler = blocks.multiply_const_vcc([complex(scale_value)])
        mag2 = blocks.complex_to_mag_squared()
        mavg = blocks.moving_average_ff(
            len(preamble_seq), 1.0 / len(preamble_seq)
        )  # i need to divide by the preamble size in case the preamble seq has amplitude 1 (sum of power is len)
        sqrtavg = blocks.transcendental("sqrt")

        # I have to compensate the amplitude of the input signal (scale) either through a feedback normalization loop that computes the scale, or manually (not practical)
        # additionally I have to scale down by the len(preamble)==sum(abs(preamble)^2) because the cross-corr does not divide by the preamble length
        #scaler2 = blocks.multiply_const_vcc([complex(1.0)/scale_value/len(preamble_seq)]) # if no feedback normalization loop, I have to scale the signal compensating additionally the scaling factor
        corr_est = specmonitor.corr_est_norm_cc(
            preamble_seq, 1, 0)  #digital.corr_est_cc(preamble_seq, 1, 0)
        tag_db = blocks.tag_debug(gr.sizeof_gr_complex, "tag debugger")
        head = blocks.head(gr.sizeof_gr_complex, samples_per_test)
        dst = blocks.vector_sink_c()

        skiphead = blocks.skiphead(gr.sizeof_float, random_samples_skip)
        skiphead2 = blocks.skiphead(gr.sizeof_gr_complex, random_samples_skip)
        skiphead3 = blocks.skiphead(gr.sizeof_gr_complex, random_samples_skip)
        debug_vec = blocks.vector_sink_f()
        debug_vec2 = blocks.vector_sink_c()
        debug_vec3 = blocks.vector_sink_c()

        self.tb.connect(framer, (add, 0))
        self.tb.connect(awgn, (add, 1))
        self.tb.connect(add, scaler)
        self.tb.connect(scaler, mag2, mavg, sqrtavg)

        self.tb.connect(scaler, corr_est)
        self.tb.connect(corr_est, tag_db)
        self.tb.connect(corr_est, head, dst)

        self.tb.connect(sqrtavg, skiphead, debug_vec)
        self.tb.connect(scaler, skiphead2, debug_vec2)

        self.tb.run()
        result_data = dst.data()
        debug_vec_data = debug_vec.data()
        debug_vec_data2 = debug_vec2.data()
        debug_vec_data3 = debug_vec3.data()
Example #12
0
    def setUp(self):
        self.tb = gr.top_block()
        self.p2s = pdu.pdu_to_stream_c(pdu.EARLY_BURST_APPEND, 64)
        self.vs = blocks.vector_sink_c(1)
        self.tag_debug = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")
        self.tag_debug.set_display(True)

        self.tb.connect((self.p2s, 0), (self.vs, 0))
        self.tb.connect((self.p2s, 0), (self.tag_debug, 0))
Example #13
0
    def __init__(self, psr_threshold, exit_on_success=False):
        gr.hier_block2.__init__(self,
                                "downlink_trigger_c",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))

        self.psr_threshold = self._ensure_safe_threshold(psr_threshold)
        self.exit_on_success = exit_on_success

        self.pss0 = ltetrigger.pss(N_id_2=0, psr_threshold=self.psr_threshold)
        self.pss1 = ltetrigger.pss(N_id_2=1, psr_threshold=self.psr_threshold)
        self.pss2 = ltetrigger.pss(N_id_2=2, psr_threshold=self.psr_threshold)
        self.sss0 = ltetrigger.sss(N_id_2=0)
        self.sss1 = ltetrigger.sss(N_id_2=1)
        self.sss2 = ltetrigger.sss(N_id_2=2)
        self.mib0 = ltetrigger.mib(exit_on_success=self.exit_on_success)
        self.mib1 = ltetrigger.mib(exit_on_success=self.exit_on_success)
        self.mib2 = ltetrigger.mib(exit_on_success=self.exit_on_success)
        self.tag0 = blocks.tag_debug(gr.sizeof_gr_complex, "mib0")
        self.tag1 = blocks.tag_debug(gr.sizeof_gr_complex, "mib1")
        self.tag2 = blocks.tag_debug(gr.sizeof_gr_complex, "mib2")
        self.tag0.set_display(False)
        self.tag1.set_display(False)
        self.tag2.set_display(False)

        self.connect(self, self.pss0, self.sss0, self.mib0, self.tag0)
        self.connect(self, self.pss1, self.sss1, self.mib1, self.tag1)
        self.connect(self, self.pss2, self.sss2, self.mib2, self.tag2)

        drop_port_id = "drop"
        self.message_port_register_hier_in(drop_port_id)
        self.message_port_register_hier_out(drop_port_id)

        self.msg_connect(self.mib0, drop_port_id, self, drop_port_id)
        self.msg_connect(self.mib1, drop_port_id, self, drop_port_id)
        self.msg_connect(self.mib2, drop_port_id, self, drop_port_id)

        track_port_id = "track"
        self.message_port_register_hier_in(track_port_id)
        self.message_port_register_hier_out(track_port_id)

        self.msg_connect(self.mib0, track_port_id, self, track_port_id)
        self.msg_connect(self.mib1, track_port_id, self, track_port_id)
        self.msg_connect(self.mib2, track_port_id, self, track_port_id)
Example #14
0
    def test_000(self):
        # Just run some data through and make sure it doesn't puke.
        src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

        src = pdu.pdu_to_tagged_stream(gr.types.byte_t)
        snk3 = pdu.tagged_stream_to_pdu(gr.types.byte_t)
        snk2 = blocks.vector_sink_b()
        snk = blocks.tag_debug(1, "test")
        snk.set_display(False)

        dbg = blocks.message_debug()

        # Test that the right number of ports exist.
        pi = snk3.message_ports_in()
        po = snk3.message_ports_out()
        # system port is defined automatically
        self.assertEqual(pmt.length(pi), 1)
        self.assertEqual(pmt.length(po), 1)

        self.tb.connect(src, snk)
        self.tb.connect(src, snk2)
        self.tb.connect(src, snk3)
        self.tb.msg_connect(snk3, "pdus", dbg, "store")

        # make our reference and message pmts
        port = pmt.intern("pdus")
        msg = pmt.cons(pmt.PMT_NIL, pmt.make_u8vector(16, 0xFF))

        # post the message
        src.to_basic_block()._post(port, msg)
        src.to_basic_block()._post(
            pmt.intern("system"), pmt.cons(pmt.intern("done"),
                                           pmt.from_long(1)))

        self.tb.start()
        self.tb.wait()

        # Get the vector of data from the vector sink
        result_data = snk2.data()

        # Get the vector of data from the message sink
        # Convert the message PMT as a pair into its vector
        result_msg = dbg.get_message(0)
        msg_vec = pmt.cdr(result_msg)
        # pmt.print(msg_vec)

        # Convert the PMT vector into a Python list
        msg_data = []
        for i in range(16):
            msg_data.append(pmt.u8vector_ref(msg_vec, i))

        actual_data = 16 * [
            0xFF,
        ]
        self.assertEqual(actual_data, list(result_data))
        self.assertEqual(actual_data, msg_data)
 def setUp(self):
     self.tb = gr.top_block()
     self.tb_null = gr.top_block()
     self.usrp = uhd.usrp_source(device_addr="",
                                 stream_args=uhd.stream_args("fc32"))
     null = blocks.null_sink(gr.sizeof_gr_complex)
     self.tb_null.connect(self.usrp, null)
     self.tag_debug = blocks.tag_debug(gr.sizeof_gr_complex, "Tag debug")
     self.tag_debug.set_display(False)
     self.vsink = blocks.vector_sink_c()
    def __init__(self):
        gr.top_block.__init__(self, "Rx Ofdm")

        ##################################################
        # Variables
        ##################################################
        self.tx_gain = tx_gain = 60
        self.samp_rate = samp_rate = 500e3
        self.packet_len = packet_len = 60
        self.len_tag_key = len_tag_key = "packet_len"
        self.freq = freq = 2.4e9
        self.fft_len = fft_len = 120

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("addr=192.168.10.2", "")),
            uhd.stream_args(cpu_format="fc32", channels=range(1)),
        )
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_center_freq(2.4e9, 0)
        self.uhd_usrp_source_0.set_gain(0, 0)
        self.uhd_usrp_source_0.set_antenna("RX2", 0)
        self.uhd_usrp_source_0.set_auto_dc_offset(True, 0)
        self.uhd_usrp_source_0.set_auto_iq_balance(True, 0)
        self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc(
            interpolation=1, decimation=2, taps=None, fractional_bw=None)
        self.digital_ofdm_rx_0 = digital.ofdm_rx(
            fft_len=fft_len,
            cp_len=32,
            frame_length_tag_key="frame_" + len_tag_key,
            packet_length_tag_key=len_tag_key,
            bps_header=1,
            bps_payload=2,
            debug_log=False,
            scramble_bits=False,
        )
        self.blocks_tag_debug_0_0 = blocks.tag_debug(gr.sizeof_char * 1, "",
                                                     "")
        self.blocks_tag_debug_0_0.set_display(True)
        self.blocks_file_sink_0 = blocks.file_sink(
            gr.sizeof_char * 1, "/home/GNURadio-Files/file_rx.txt", True)
        self.blocks_file_sink_0.set_unbuffered(True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.digital_ofdm_rx_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.digital_ofdm_rx_0, 0),
                     (self.blocks_tag_debug_0_0, 0))
        self.connect((self.rational_resampler_xxx_0_0, 0),
                     (self.digital_ofdm_rx_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.rational_resampler_xxx_0_0, 0))
Example #17
0
 def test_bb_skip_prefix(self):
     pad = (0, ) * 64
     src_data = (0, 1, 1, 1, 1, 0, 0, 1, 1) + pad + (0, ) * 7
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_tag_bb("0011", 0, "sync")
     dst = blocks.tag_debug(gr.sizeof_char, "sync")
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.current_tags()
     self.assertEqual(len(result_data), 1)
     self.assertEqual(result_data[0].offset, 9)
 def test_001(self):
     pad = (0,) * 64
     src_data = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0,) * 7
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_tag_bb("1011", 0, "sync")
     dst = blocks.tag_debug(1, "sync")
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.current_tags()
     self.assertEqual(len(result_data), 2)
     self.assertEqual(result_data[0].offset, 4)
     self.assertEqual(result_data[1].offset, 9)
Example #19
0
 def test_ff_skip_prefix(self):
     pad = (0, ) * 64
     src_bits = (0, 1, 1, 1, 1, 0, 0, 1, 1) + pad + (0, ) * 7
     src_data = [2.0 * x - 1.0 for x in src_bits]
     src = blocks.vector_source_f(src_data)
     op = digital.correlate_access_code_tag_ff("0011", 0, "sync")
     dst = blocks.tag_debug(gr.sizeof_float, "sync")
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.current_tags()
     self.assertEqual(len(result_data), 1)
     self.assertEqual(result_data[0].offset, 9)
Example #20
0
 def test_bb_immediate(self):
     """Test that packets at start of stream match"""
     pad = (0, ) * 64
     src_data = (0, 0, 1, 1) + pad + (0, ) * 7
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_tag_bb("0011", 0, "sync")
     dst = blocks.tag_debug(gr.sizeof_char, "sync")
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.current_tags()
     self.assertEqual(len(result_data), 1)
     self.assertEqual(result_data[0].offset, 4)
Example #21
0
    def test_000(self):
        # Just run some data through and make sure it doesn't puke.
        src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

        src = blocks.pdu_to_tagged_stream(blocks.byte_t)
        snk3 = blocks.tagged_stream_to_pdu(blocks.byte_t)
        snk2 = blocks.vector_sink_b()
        snk = blocks.tag_debug(1, "test")
        snk.set_display(False)

        dbg = blocks.message_debug()

        # Test that the right number of ports exist.
        pi = snk3.message_ports_in()
        po = snk3.message_ports_out()
        self.assertEqual(pmt.length(pi), 0)
        self.assertEqual(pmt.length(po), 1)

        self.tb.connect(src, snk)
        self.tb.connect(src, snk2)
        self.tb.connect(src, snk3)
        self.tb.msg_connect(snk3, "pdus", dbg, "store")
        self.tb.start()

        # make our reference and message pmts
        port = pmt.intern("pdus")
        msg = pmt.cons( pmt.PMT_NIL, pmt.make_u8vector(16, 0xFF))

        # post the message
        src.to_basic_block()._post(port, msg) # eww, what's that smell?

        while dbg.num_messages() < 1:
            time.sleep(0.1)
        self.tb.stop()
        self.tb.wait()

        # Get the vector of data from the vector sink
        result_data = snk2.data()

        # Get the vector of data from the message sink
        # Convert the message PMT as a pair into its vector
        result_msg = dbg.get_message(0)
        msg_vec = pmt.cdr(result_msg)
        #pmt.print(msg_vec)

        # Convert the PMT vector into a Python list
        msg_data = []
        for i in xrange(16):
            msg_data.append(pmt.u8vector_ref(msg_vec, i))

        actual_data = 16*[0xFF,]
        self.assertEqual(actual_data, list(result_data))
        self.assertEqual(actual_data, msg_data)
Example #22
0
    def setUp(self):
        self.tb = gr.top_block()
        self.emitter = pdu_utils.message_emitter(pmt.PMT_NIL)
        self.p2b = pdu_utils.pdu_to_bursts_c(
            pdu_utils.EARLY_BURST_BEHAVIOR__APPEND, 64)
        self.vs = blocks.vector_sink_c(1)
        self.tag_debug = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")
        self.tag_debug.set_display(True)

        self.tb.msg_connect((self.emitter, 'msg'), (self.p2b, 'bursts'))
        self.tb.connect((self.p2b, 0), (self.vs, 0))
        self.tb.connect((self.p2b, 0), (self.tag_debug, 0))
 def test_001(self):
     pad = (0, ) * 64
     src_data = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0, ) * 7
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_tag_bb("1011", 0, "sync")
     dst = blocks.tag_debug(1, "sync")
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.current_tags()
     self.assertEqual(len(result_data), 2)
     self.assertEqual(result_data[0].offset, 4)
     self.assertEqual(result_data[1].offset, 9)
 def test_003(self):
     pad = (0,) * 64
     src_bits = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0,) * 7
     src_data = [2.0*x - 1.0 for x in src_bits]
     src = blocks.vector_source_f(src_data)
     op = digital.correlate_access_code_tag_ff("1011", 0, "sync")
     dst = blocks.tag_debug(gr.sizeof_float, "sync")
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.current_tags()
     self.assertEqual(len(result_data), 2)
     self.assertEqual(result_data[0].offset, 4)
     self.assertEqual(result_data[1].offset, 9)
Example #25
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2048000
        self.parameters = parameters = dab_step.parameters.dab_parameters(
            1, samp_rate)
        self.modulated_prs = modulated_prs = dab_step.make_prs.modulate_prs(
            samp_rate, True)

        ##################################################
        # Blocks
        ##################################################
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               '')
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(222064000 * 1 + 178352000 * 0, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(10, 0)
        self.osmosdr_source_0.set_if_gain(20, 0)
        self.osmosdr_source_0.set_bb_gain(20, 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)

        self.dab_step_tune_timer_0 = dab_step.tune_timer()
        self.dab_step_dab_sync_cpp_0 = dab_step.dab_sync_cpp(
            samp_rate, parameters.fft_length, parameters.cp_length,
            modulated_prs)
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_gr_complex * 1,
                                                   '', "")
        self.blocks_tag_debug_0.set_display(True)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex * 1)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.dab_step_tune_timer_0, 'command'),
                         (self.osmosdr_source_0, 'command'))
        self.connect((self.dab_step_dab_sync_cpp_0, 0),
                     (self.blocks_tag_debug_0, 0))
        self.connect((self.dab_step_dab_sync_cpp_0, 0),
                     (self.dab_step_tune_timer_0, 0))
        self.connect((self.dab_step_tune_timer_0, 0),
                     (self.blocks_null_sink_0, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.dab_step_dab_sync_cpp_0, 0))
Example #26
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 100

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_f(
        	self.GetWin(),
        	baseband_freq=0,
        	dynamic_range=140,
        	ref_level=-50,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Waterfall Plot",
        )
        self.Add(self.wxgui_waterfallsink2_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
        	self.GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=-50,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT Plot",
        	peak_hold=True,
        )
        self.Add(self.wxgui_fftsink2_0.win)
        self.mseed_seedlink_f_0 = mseed.seedlink_f("10.0.0.15", 18000, "FR_ILLK:HHZ")
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_float*1, "", ""); self.blocks_tag_debug_0.set_display(True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.mseed_seedlink_f_0, 0), (self.blocks_tag_debug_0, 0))    
        self.connect((self.mseed_seedlink_f_0, 0), (self.wxgui_fftsink2_0, 0))    
        self.connect((self.mseed_seedlink_f_0, 0), (self.wxgui_waterfallsink2_0, 0))    
Example #27
0
    def test_1(self):
        '''
      Very rough test to ensure that the block can be instantiated and
      data can be run
      '''
        samp_rate = samp_rate = 32000
        freq = freq = samp_rate / 10

        ##################################################
        # Blocks
        ##################################################
        block_buffer = sandia_utils.block_buffer(gr.sizeof_gr_complex, 10000,
                                                 samp_rate, True)
        throttle = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate / 20,
                                   True)
        tag_debug = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")
        tag_debug.set_display(True)
        probe_rate = blocks.probe_rate(gr.sizeof_gr_complex * 1, 500.0, 0.15)
        message_debug = blocks.message_debug()
        source = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq, .7,
                                     0, 0)

        ##################################################
        # Connections
        ##################################################
        self.tb.msg_connect((probe_rate, 'rate'), (message_debug, 'store'))
        self.tb.connect((source, 0), (block_buffer, 0))
        self.tb.connect((throttle, 0), (probe_rate, 0))
        self.tb.connect((throttle, 0), (tag_debug, 0))
        self.tb.connect((block_buffer, 0), (throttle, 0))

        # data
        src_data = (1, 1, 2, 2, 3, 3)
        expected_result = (1 + 1j, 2 + 2j, 3 + 3j)

        # execute
        self.tb.start()

        # allow it to run 2 seconds
        time.sleep(3)

        # get number of messages
        nmessages = message_debug.num_messages()

        # should have gotten at least one message
        self.assertTrue(nmessages > 0)

        # clean up
        self.tb.stop()
        self.tb.wait()
Example #28
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Joystick 101")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 48000

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
            self.GetWin(),
            title="Scope Plot",
            sample_rate=samp_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.win)
        self.openavionics_joystick_interface_0 = openavionics.joystick_interface(
        )
        self.openavionics_audio_ptt_0 = openavionics.audio_ptt()
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_float * 1, "")
        self.audio_sink_0 = audio.sink(48000, "", True)
        self.analog_sig_source_x_0 = analog.sig_source_f(
            samp_rate, analog.GR_COS_WAVE, 1000, 0.2, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.openavionics_audio_ptt_0, 0),
                     (self.blocks_tag_debug_0, 0))
        self.connect((self.openavionics_audio_ptt_0, 0),
                     (self.wxgui_scopesink2_0, 0))
        self.connect((self.openavionics_audio_ptt_0, 0),
                     (self.audio_sink_0, 0))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.openavionics_audio_ptt_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.openavionics_joystick_interface_0, "out",
                         self.openavionics_audio_ptt_0, "in2")
Example #29
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")

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

        ##################################################
        # Blocks
        ##################################################
        self.digital_crc32_bb_0 = digital.crc32_bb(False, "packet_len")
        self.blocks_tag_debug_1 = blocks.tag_debug(gr.sizeof_char * 1,
                                                   "Pre-CRC", "")
        self.blocks_tag_debug_1.set_display(True)
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char * 1,
                                                   "Post-CRC", "")
        self.blocks_tag_debug_0.set_display(True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(
            gr.sizeof_char, 1, 100, "packet_len")
        self.blocks_head_0 = blocks.head(gr.sizeof_char * 1, 100 * 5)
        self.analog_random_source_x_0 = blocks.vector_source_b(
            map(int, numpy.random.randint(0, 255, 1000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_random_source_x_0, 0),
                     (self.blocks_head_0, 0))
        self.connect((self.blocks_head_0, 0),
                     (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0),
                     (self.digital_crc32_bb_0, 0))
        self.connect((self.digital_crc32_bb_0, 0),
                     (self.blocks_tag_debug_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0),
                     (self.blocks_tag_debug_1, 0))
Example #30
0
    def __init__(self):
        gr.top_block.__init__(self, "Polar Code")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Polar Code")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "polar_code")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.Kw = Kw = 70*8
        self.samp_rate = samp_rate = 32000
        self.packetlength = packetlength = "packet_len"
        self.length_tag_key = length_tag_key = "packet_len"
        self.id_user = id_user = 2
        self.SNRw = SNRw = 3
        self.SNRs = SNRs = 8
        self.Nbfiles = Nbfiles = 20
        self.NbStrgUsers = NbStrgUsers = 2
        self.NbChuncks = NbChuncks = 100
        self.N = N = 2048
        self.Ks = Ks = 2*Kw

        ##################################################
        # Blocks
        ##################################################
        self.projectCACHE_polarEnc_b_0 = projectCACHE.polarEnc_b(N, Kw, Ks, SNRw, SNRs, Nbfiles, NbChuncks, NbStrgUsers, id_user, "packet_len")
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, 'TX', ""); self.blocks_tag_debug_0.set_display(True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.projectCACHE_polarEnc_b_0, 0), (self.blocks_tag_debug_0, 0))    
Example #31
0
 def test_002(self):
     code = tuple(string_to_1_0_list(default_access_code))
     access_code = to_1_0_string(code)
     pad = (0, ) * 64
     #print code
     #print access_code
     src_data = code + (1, 0, 1, 1) + pad
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_tag_bb(access_code, 0, "sync")
     dst = blocks.tag_debug(gr.sizeof_char, "sync")
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.current_tags()
     self.assertEqual(len(result_data), 1)
     self.assertEqual(result_data[0].offset, len(code))
 def test_002(self):
     code = tuple(string_to_1_0_list(default_access_code))
     access_code = to_1_0_string(code)
     pad = (0,) * 64
     #print code
     #print access_code
     src_data = code + (1, 0, 1, 1) + pad
     src = blocks.vector_source_b(src_data)
     op = digital.correlate_access_code_tag_bb(access_code, 0, "sync")
     dst = blocks.tag_debug(gr.sizeof_char, "sync")
     self.tb.connect(src, op, dst)
     self.tb.run()
     result_data = dst.current_tags()
     self.assertEqual(len(result_data), 1)
     self.assertEqual(result_data[0].offset, len(code))
    def __init__(self, snr_val, verbose=False):
        gr.top_block.__init__(self, name="SNR estimation accuracy test")
        zc_seq_len = 503  #199

        sample_rate = 1e6
        frame_duration = 2.0e-3
        test_duration = 1.5 * frame_duration
        samples_per_frame = int(round(frame_duration * sample_rate))
        samples_per_test = int(round(test_duration * sample_rate))
        n_samples_snr_estim = zc_seq_len  #int(round(samples_per_frame/20))
        random_samples_skip = np.random.randint(
            samples_per_frame / 2) + samples_per_frame / 2
        preamble_seq = zadoffchu.generate_sequence(zc_seq_len, 1, 0)
        preamble_pwr_sum = np.sum(np.abs(preamble_seq)**2)
        sigma_val = 1 / float(10.0**(snr_val / 20.0))
        thres = 0.25

        # if samples_per_test-random_samples_skip+2*preamble_seq.size+n_samples_snr_estim >= samples_per_test:
        #     print "The test duration is not long enough"
        #     exit()

        self.framer = specmonitor.framer_c(sample_rate, frame_duration,
                                           preamble_seq)
        self.awgn = analog.noise_source_c(analog.GR_GAUSSIAN, sigma_val)
        self.add = blocks.add_cc()
        self.skiphead = blocks.skiphead(gr.sizeof_gr_complex,
                                        random_samples_skip)
        self.corr_est = specmonitor.corr_est_norm_cc(
            preamble_seq, 1, 0,
            thres)  #digital.corr_est_cc(preamble_seq, 1, 0)
        self.snr_est = specmonitor.framer_snr_est_cc(n_samples_snr_estim,
                                                     preamble_seq.size)
        if verbose is True:
            self.tag_db = blocks.tag_debug(gr.sizeof_gr_complex,
                                           "tag debugger")
        self.head = blocks.head(gr.sizeof_gr_complex, samples_per_test)
        self.dst = blocks.vector_sink_c()

        self.connect(self.framer, (self.add, 0))
        self.connect(self.awgn, (self.add, 1))
        self.connect(self.add, self.skiphead)
        self.connect(self.skiphead, self.head)
        self.connect(self.head, self.corr_est)
        self.connect(self.corr_est, self.snr_est)
        if verbose is True:
            self.connect(self.snr_est, self.tag_db)
        self.connect(self.snr_est, self.dst)
    def __init__(self):
        gr.top_block.__init__(self, name="Corr Norm")
        sample_rate = 1e6
        total_samples = 10000
        preamble_seq = np.array([1, 1, -1, 1])
        preamble_seq /= len(preamble_seq)

        self.vector_source = blocks.vector_source_c(preamble_seq * 4, True)
        self.head = blocks.head(gr.sizeof_gr_complex, total_samples)
        self.corr_est = specmonitor.corr_est_norm_cc(preamble_seq, 1, 0)
        self.tag_db = blocks.tag_debug(gr.sizeof_gr_complex, "tag debugger")
        self.dst = blocks.vector_sink_c()

        self.connect(self.vector_source, self.head)
        self.connect(self.head, self.corr_est)
        self.connect(self.corr_est, self.tag_db)
        self.connect(self.corr_est, self.dst)
    def test_001_instantiate(self):
        self.tb = gr.top_block()
        self.rate = 250000
        self.interval = 173
        self.duration = 9000

        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1,
                                          [])
        self.dut = timing_utils.system_time_tagger_c(7000)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")

        self.tb.connect((self.src, 0), (self.dut, 0))
        self.tb.connect((self.dut, 0), (self.tag_dbg, 0))

        # set up fg
        self.tb.run()
        time.sleep(0.05)
Example #36
0
    def test_roundtrip_offset_initial_capture(self):
        """Test that if the first capture segment has an offset, then
        it gets correctly offset and output when roundtripped from a
        source to a sink"""

        # generate a file
        data, meta_json, filename, meta_file = self.make_file("offset")

        # drop the first 4 samples
        adjust_size = 4
        with open(meta_file, "r+") as f:
            fdata = json.load(f)
            fdata['captures'][0]["core:sample_start"] = adjust_size
            fdata['captures'][0]["core:frequency"] = 2.4e9
            f.seek(0)
            json.dump(fdata, f, indent=4)
            f.truncate()

        data_start_size = os.path.getsize(filename)

        out_data_file, out_json_file = self.temp_file_names()
        file_source = sigmf.source(filename, "cf32_le")
        file_sink = sigmf.sink("cf32_le", out_data_file)
        tagd = blocks.tag_debug(gr.sizeof_gr_complex, "test")
        tb = gr.top_block()
        tb.connect(file_source, file_sink)
        tb.connect(file_source, tagd)
        tb.start()
        tb.wait()

        data_end_size = os.path.getsize(out_data_file)
        # end data size should be smaller
        dropped_samples = adjust_size * 2 * 4
        self.assertEqual(data_start_size - dropped_samples,
                         data_end_size, "Wrong data size")

        with open(out_json_file, "r") as f:
            meta = json.load(f)
            print(meta)
            self.assertEqual(len(meta["annotations"]), 0,
                             "Shouldn't be any annotations in file")
            self.assertEqual(len(meta["captures"]), 1,
                             "Should only be 1 capture segment in file")
            self.assertEqual(
                meta["captures"][0]["core:frequency"],
                2.4e9, "frequency tag is missing")
    def __init__(self, snr_val, cfo=0, sto=0, verbose=False):
        gr.top_block.__init__(self, name="CFO estimation test")
        zc_seq_len = 503  #199
        sample_rate = 1e6
        frame_duration = 2.0e-3
        test_duration = 1.5 * frame_duration
        sigma_val = 1 / float(10.0**(snr_val / 20.0))
        thres = 0.25

        samples_per_frame = int(round(frame_duration * sample_rate))
        samples_per_test = int(round(test_duration * sample_rate))
        n_samples_snr_estim = zc_seq_len
        random_samples_skip = np.random.randint(
            samples_per_frame / 2) + samples_per_frame / 2
        preamble_seq = zadoffchu.generate_sequence(zc_seq_len, 1, 0)
        preamble_pwr_sum = np.sum(np.abs(preamble_seq)**2)

        self.framer = specmonitor.framer_c(sample_rate, frame_duration,
                                           preamble_seq)
        self.channel = channels.channel_model(sigma_val, cfo, sto, [1 + 1j])
        self.skiphead = blocks.skiphead(gr.sizeof_gr_complex,
                                        random_samples_skip)
        self.corr_est = specmonitor.corr_est_norm_cc(
            preamble_seq, 1, 0,
            thres)  #digital.corr_est_cc(preamble_seq, 1, 0)
        self.snr_est = specmonitor.framer_snr_est_cc(n_samples_snr_estim,
                                                     preamble_seq.size)
        if verbose is True:
            self.tag_db = blocks.tag_debug(gr.sizeof_gr_complex,
                                           "tag debugger")
        self.head = blocks.head(gr.sizeof_gr_complex, samples_per_test)
        self.dst = blocks.vector_sink_c()
        self.dst2 = blocks.vector_sink_c()

        self.connect(self.framer, self.channel)
        self.connect(self.channel, self.skiphead)
        # self.connect(self.framer,self.skiphead)
        self.connect(self.skiphead, self.head)
        self.connect(self.head, self.corr_est)
        self.connect(self.corr_est, self.snr_est)
        self.connect((self.corr_est, 1), self.dst2)
        if verbose is True:
            self.connect(self.snr_est, self.tag_db)
        self.connect(self.snr_est, self.dst)
    def test_004_onlyusrp (self):
        self.tb = gr.top_block ()
        self.rate = 250000
        self.interval = 0
        self.duration = 4532

        self.src = blocks.vector_source_c(list(range(self.duration)), False, 1, [])
        self.utag = timing_utils.add_usrp_tags_c(1090e6, self.rate, 0, .98765)
        self.tags = timing_utils.tag_uhd_offset_c(self.rate, self.interval)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex*1, "", "");
        self.tag_dbg.set_display(False)
        self.tb.connect((self.src, 0), (self.utag, 0))
        self.tb.connect((self.utag, 0), (self.tags, 0))
        self.tb.connect((self.tags, 0), (self.tag_dbg, 0))
        e_n_tags = 4

        self.tb.run ()
        self.assertEqual(self.tag_dbg.num_tags(), e_n_tags)
        self.tb = None
Example #39
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Joystick 101")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 48000

		##################################################
		# Blocks
		##################################################
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.openavionics_joystick_interface_0 = openavionics.joystick_interface()
		self.openavionics_audio_ptt_0 = openavionics.audio_ptt()
		self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_float*1, "")
		self.audio_sink_0 = audio.sink(48000, "", True)
		self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 0.2, 0)

		##################################################
		# Connections
		##################################################
		self.connect((self.openavionics_audio_ptt_0, 0), (self.blocks_tag_debug_0, 0))
		self.connect((self.openavionics_audio_ptt_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.openavionics_audio_ptt_0, 0), (self.audio_sink_0, 0))
		self.connect((self.analog_sig_source_x_0, 0), (self.openavionics_audio_ptt_0, 0))

		##################################################
		# Asynch Message Connections
		##################################################
		self.msg_connect(self.openavionics_joystick_interface_0, "out", self.openavionics_audio_ptt_0, "in2")
    def test_002_t(self):
        # set up fg
        sample_rate = 1e6
        frame_duration = 1.0e-3
        test_duration = 2 * frame_duration
        snr = 100
        zc_seq_len = 71

        samples_per_frame = int(round(frame_duration * sample_rate))
        samples_per_test = int(round(test_duration * sample_rate))
        n_samples_snr_estim = zc_seq_len  #samples_per_frame/20
        random_samples_skip = 0  #np.random.randint(samples_per_frame)
        preamble_seq = zadoffchu.generate_sequence(zc_seq_len, 1, 0)
        preamble_pwr_sum = np.sum(np.abs(preamble_seq)**2)

        print "***** Start test 002 *****"
        framer = specmonitor.framer_c(sample_rate, frame_duration,
                                      preamble_seq)
        awgn = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0 / snr)
        add = blocks.add_cc()
        corr_est = specmonitor.corr_est_norm_cc(
            preamble_seq, 1, 0)  #digital.corr_est_cc(preamble_seq, 1, 0)
        snr_est = specmonitor.framer_snr_est_cc(n_samples_snr_estim,
                                                preamble_seq.size)
        tag_db = blocks.tag_debug(gr.sizeof_gr_complex, "tag debugger")
        head = blocks.head(gr.sizeof_gr_complex, samples_per_test)
        dst = blocks.vector_sink_c()

        self.tb.connect(framer, (add, 0))
        self.tb.connect(awgn, (add, 1))
        self.tb.connect(add, corr_est)
        self.tb.connect(corr_est, snr_est)
        self.tb.connect(snr_est, tag_db)
        self.tb.connect(snr_est, head)
        self.tb.connect(head, dst)

        self.tb.run()
        x_data = dst.data()

        print "The final SNR is: ", snr_est.SNRdB()

        plt.plot(10 * np.log10(np.abs(x_data)**2))
        plt.show()
Example #41
0
    def test_rx_time_pad_left(self):
        # data
        src_data = (0, ) * 8 * 100
        offsets = [16]
        for step in range(17, 24):
            offsets.append(offsets[-1] + step)
        print("offsets = {}".format(offsets))

        # generate tag list
        rx_time = pmt.make_tuple(pmt.from_uint64(1), pmt.from_double(.234))
        time_tag = gr.tag_utils.python_to_tag(
            [1, pmt.intern("rx_time"), rx_time,
             pmt.intern("time_stamper")])
        tags = [time_tag]
        for offset in offsets:
            tags.append(
                gr.tag_utils.python_to_tag([
                    offset,
                    pmt.intern("BURST"),
                    pmt.from_uint64(0),
                    pmt.intern("test_simple_source")
                ]))

        expected_result = (0x0, ) * 5

        # blocks
        src = blocks.vector_source_b(src_data, False, 1, tags)
        tbb = sandia_utils.tagged_bits_to_bytes("BURST", False, 2, 1)
        dst = blocks.vector_sink_b()
        tag_dbg = blocks.tag_debug(gr.sizeof_char * 1, '', "")
        tag_dbg.set_display(True)

        self.tb.connect(src, tbb)
        self.tb.connect(tbb, tag_dbg)
        self.tb.connect(tbb, dst)

        # execute
        self.tb.run()
        result_data = dst.data()

        # assert - should get both a BURST and burst_time tag at offsets = [2,5,8,11,14,17,20,23]
        print("test rx_time got {}, expected {}".format(
            result_data, expected_result))
Example #42
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="tun_source Test")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Blocks
        ##################################################
        self.orcatun_tun_source_b_0 = orcatun.tun_source_b("tun3", "packet_len", True)
        self.blocks_tagged_stream_to_pdu_0 = blocks.tagged_stream_to_pdu(blocks.byte_t, "packet_len")
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "tun_source_debug", ""); self.blocks_tag_debug_0.set_display(True)
        self.blocks_message_debug_0 = blocks.message_debug()

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_tagged_stream_to_pdu_0, 'pdus'), (self.blocks_message_debug_0, 'print_pdu'))    
        self.connect((self.orcatun_tun_source_b_0, 0), (self.blocks_tag_debug_0, 0))    
        self.connect((self.orcatun_tun_source_b_0, 0), (self.blocks_tagged_stream_to_pdu_0, 0))    
    def test_002_update(self):
        start_time = 0.1
        self.duration = 125000
        self.src = blocks.vector_source_c(range(self.duration), False, 1, [])
        self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, 250000)
        self.utag = timing_utils.add_usrp_tags_c(1090e6, 250000, 0, start_time)
        self.tag_dbg = blocks.tag_debug(gr.sizeof_gr_complex * 1, '', "")
        self.tb.connect((self.src, 0), (self.throttle, 0))
        self.tb.connect((self.throttle, 0), (self.utag, 0))
        self.tb.connect((self.utag, 0), (self.tag_dbg, 0))
        self.tb.start()
        time.sleep(.01)

        self.utag.update_tags(
            self.makeDict(freq=1091e6,
                          rate=260000,
                          epoch_int=0,
                          epoch_frac=start_time + .3))
        time.sleep(.1)
        self.tb.stop()
Example #44
0
    def test_001(self):
        src_data  = ( 1,  2,  3,  4,  5,  6,  7,  8,  9,  10)
        trg_data = (-1, -1,  1,  1, -1, -1,  1,  1, -1,  -1)
        src = blocks.vector_source_i(src_data)
        trg = blocks.vector_source_s(trg_data)
        op  = blocks.burst_tagger(gr.sizeof_int)
        snk = blocks.tag_debug(gr.sizeof_int, "burst tagger QA")
        self.tb.connect(src, (op,0))
        self.tb.connect(trg, (op,1))
        self.tb.connect(op, snk)
        self.tb.run()

        x = snk.current_tags()
        self.assertEqual(2, x[0].offset)
        self.assertEqual(4, x[1].offset)
        self.assertEqual(6, x[2].offset)
        self.assertEqual(8, x[3].offset)

        self.assertEqual(True,  pmt.to_bool(x[0].value))
        self.assertEqual(False, pmt.to_bool(x[1].value))
        self.assertEqual(True,  pmt.to_bool(x[2].value))
        self.assertEqual(False, pmt.to_bool(x[3].value))
Example #45
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

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

        ##################################################
        # Blocks
        ##################################################
        self.tagutils_tag_at_offset_xx_0 = tagutils.tag_at_offset_ff("test_tag", [0,8675,8940,100000], 35, False)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_float*1, "", ""); self.blocks_tag_debug_0.set_display(True)
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.tagutils_tag_at_offset_xx_0, 0))
        self.connect((self.tagutils_tag_at_offset_xx_0, 0), (self.blocks_tag_debug_0, 0))
Example #46
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.down_sampling = down_sampling = 16
        self.sample_rate = sample_rate = 250e3*down_sampling
        self.preamble_len_tag = preamble_len_tag = gr.tag_utils.python_to_tag((0, pmt.intern("packet_len"), pmt.from_long(8), pmt.intern("src")))
        self.f1_bp_taps = f1_bp_taps = [-0.008489873260259628, 0.017516516149044037, -0.02309376560151577, 3.1378305752533504e-17, 0.06292477995157242, -0.12457011640071869, 0.1126808300614357, -3.387264241990756e-17, -0.14707811176776886, 0.21481703221797943, -0.14707811176776886, -3.387264241990756e-17, 0.1126808300614357, -0.12457011640071869, 0.06292477995157242, 3.1378305752533504e-17, -0.02309376560151577, 0.017516516149044037, -0.008489873260259628]
        self.f0_bp_taps = f0_bp_taps =  [0.008489873260259628, 0.017516516149044037, 0.02309376560151577, -1.1766864243609758e-17, -0.06292477995157242, -0.12457011640071869, -0.1126808300614357, 3.387264241990756e-17, 0.14707811176776886, 0.21481703221797943, 0.14707811176776886, 3.387264241990756e-17, -0.1126808300614357, -0.12457011640071869, -0.06292477995157242, -1.1766864243609758e-17, 0.02309376560151577, 0.017516516149044037, 0.008489873260259628]

        ##################################################
        # Blocks
        ##################################################
        self.rad1o_id_compare_select_fb_0 = rad1o_id.compare_select_fb()
        self.qtgui_time_sink_x_0 = qtgui.time_sink_c(
        	1024, #size
        	sample_rate/down_sampling, #samp_rate
        	"", #name
        	2 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)
        
        self.qtgui_time_sink_x_0.set_y_label("Amplitude", "")
        
        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_time_sink_x_0.disable_legend()
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        
        for i in xrange(2*2):
            if len(labels[i]) == 0:
                if(i % 2 == 0):
                    self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2))
                else:
                    self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_number_sink_0 = qtgui.number_sink(
                gr.sizeof_char,
                0,
                qtgui.NUM_GRAPH_HORIZ,
        	1
        )
        self.qtgui_number_sink_0.set_update_time(0.10)
        self.qtgui_number_sink_0.set_title("")
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        units = ["", "", "", "", "",
                  "", "", "", "", ""]
        colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")]
        factor = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        for i in xrange(1):
            self.qtgui_number_sink_0.set_min(i, -1)
            self.qtgui_number_sink_0.set_max(i, 1)
            self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1])
            if len(labels[i]) == 0:
                self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i))
            else:
                self.qtgui_number_sink_0.set_label(i, labels[i])
            self.qtgui_number_sink_0.set_unit(i, units[i])
            self.qtgui_number_sink_0.set_factor(i, factor[i])
        
        self.qtgui_number_sink_0.enable_autoscale(False)
        self._qtgui_number_sink_0_win = sip.wrapinstance(self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_number_sink_0_win)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	sample_rate/down_sampling, #bw
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(False)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_freq_sink_x_0.disable_legend()
        
        if complex == type(float()):
          self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "dark blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self.fir_filter_xxx_1_0 = filter.fir_filter_fff(down_sampling/2, (1, ))
        self.fir_filter_xxx_1_0.declare_sample_delay(0)
        self.fir_filter_xxx_1 = filter.fir_filter_fff(down_sampling/2, (1, ))
        self.fir_filter_xxx_1.declare_sample_delay(0)
        self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(down_sampling/2, (f1_bp_taps))
        self.fir_filter_xxx_0_0.declare_sample_delay(0)
        self.fir_filter_xxx_0 = filter.fir_filter_ccc(down_sampling/2, (f0_bp_taps))
        self.fir_filter_xxx_0.declare_sample_delay(0)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf(([0.5, 1.5]), 1)
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=100e-2,
        	frequency_offset=1e-4,
        	epsilon=1.0,
        	taps=(1.0 + 1.0j, ),
        	noise_seed=0,
        	block_tags=True
        )
        self.blocks_vector_source_x_1 = blocks.vector_source_b((0,0), True, 1, [])
        self.blocks_vector_source_x_0 = blocks.vector_source_b([0,0], True, 1, [preamble_len_tag])
        self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux(gr.sizeof_char*1, "packet_len", 0)
        self.blocks_tagged_stream_align_1 = blocks.tagged_stream_align(gr.sizeof_char*1, "packet_len")
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "packet_length", ""); self.blocks_tag_debug_0.set_display(False)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, 64, "packet_len")
        self.blocks_repeat_0 = blocks.repeat(gr.sizeof_char*1, 16)
        self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((0.7, ))
        self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared(1)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
        self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(2*pi/4)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_frequency_modulator_fc_0, 0), (self.channels_channel_model_0, 0))    
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.fir_filter_xxx_1, 0))    
        self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.fir_filter_xxx_1_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.fir_filter_xxx_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.fir_filter_xxx_0_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_freq_sink_x_0, 0))    
        self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.blocks_repeat_0, 0))    
        self.connect((self.blocks_repeat_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))    
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.blocks_tagged_stream_mux_0, 1))    
        self.connect((self.blocks_tagged_stream_align_1, 0), (self.blocks_tagged_stream_mux_0, 0))    
        self.connect((self.blocks_tagged_stream_mux_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0))    
        self.connect((self.blocks_tagged_stream_mux_0, 0), (self.blocks_tag_debug_0, 0))    
        self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_tagged_stream_align_1, 0))    
        self.connect((self.blocks_vector_source_x_1, 0), (self.blocks_stream_to_tagged_stream_0, 0))    
        self.connect((self.channels_channel_model_0, 0), (self.blocks_multiply_const_vxx_0, 0))    
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.analog_frequency_modulator_fc_0, 0))    
        self.connect((self.fir_filter_xxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))    
        self.connect((self.fir_filter_xxx_0, 0), (self.qtgui_time_sink_x_0, 0))    
        self.connect((self.fir_filter_xxx_0_0, 0), (self.blocks_complex_to_mag_squared_0_0, 0))    
        self.connect((self.fir_filter_xxx_0_0, 0), (self.qtgui_time_sink_x_0, 1))    
        self.connect((self.fir_filter_xxx_1, 0), (self.rad1o_id_compare_select_fb_0, 0))    
        self.connect((self.fir_filter_xxx_1_0, 0), (self.rad1o_id_compare_select_fb_0, 1))    
        self.connect((self.rad1o_id_compare_select_fb_0, 0), (self.qtgui_number_sink_0, 0))    
Example #47
0
    def __init__(self, seed, samp_rate, noise_amp, modulation, delay, samples_to_receive, freq, rx_id):
        gr.hier_block2.__init__(self, "ModulatorBlock",
                       gr.io_signature(0, 0, 0),
                       gr.io_signature(1, 1, gr.sizeof_gr_complex))

        # Timing tag: This is preserved and updated:
        timing_tag = gr.tag_t()
        timing_tag.offset = 0
        timing_tag.key = pmt.string_to_symbol('rx_time')
        timing_tag.value = pmt.to_pmt((float(seed), 0.6))
        timing_tag.srcid = pmt.string_to_symbol(str('gr uhd usrp source1'))
        # Rx freq tags:
        #print "In source emulation (before tag)" 
        #print freq
        rx_freq_tag = gr.tag_t()
        rx_freq_tag.offset = 0
        rx_freq_tag.key = pmt.string_to_symbol('rx_freq')
        rx_freq_tag.value = pmt.from_double(freq)
        rx_freq_tag.srcid = pmt.string_to_symbol(str('gr uhd usrp source1'))
        # Samp_rate tags:
        rx_rate_tag = gr.tag_t()
        rx_rate_tag.offset = 0
        rx_rate_tag.key = pmt.string_to_symbol('rx_rate')
        rx_rate_tag.value = pmt.from_double(samp_rate)
        rx_rate_tag.srcid = pmt.string_to_symbol(str('gr uhd usrp source1'))

        add = blocks.add_vcc(1, )

        tag_debug = blocks.tag_debug(gr.sizeof_gr_complex*1, "", "")
        tag_debug.set_display(True)
    
        #if modulation == "bpsk":
        #    mod = digital.psk.psk_mod(
        #      constellation_points=2,
        #      mod_code="none",
        #      differential=True,
        #      samples_per_symbol=2,
        #      excess_bw=0.1,
        #      verbose=False,
        #      log=False,
        #      )
        #else:
        #    mod = grc_blks2.packet_mod_b(digital.ofdm_mod(
        #                    options=grc_blks2.options(
        #                            modulation="qpsk",
        #                            fft_length=4096,
        #                            occupied_tones=200,
        #                            cp_length=0,
        #                            pad_for_usrp=False,
        #                            log=None,
        #                            verbose=None,
        #                    ),
        #            ),
        #            payload_length=0,
        #    )
        #print "in source emulation(after_tag)"
        #print  pmt.to_double(rx_freq_tag.value)
        pulse_width = 4
        np.random.seed(seed=seed)
        
        tx_vector = np.reshape(np.matlib.repmat(np.random.randint(0,2,(5*samples_to_receive)/pulse_width)*2-1,pulse_width,1).T,[1,5*samples_to_receive])[0].tolist()
        # delay signal vector -> insert zeros at beginnig; nothing happens if signal has not reached the receiver:
        tx_vector_delayed = np.hstack((np.zeros(delay),tx_vector))
        #tx_vector_delayed = tx_vector_delayed[:600]
        self.vector_source = blocks.vector_source_c(tx_vector_delayed, False, 1, (timing_tag, rx_freq_tag, rx_rate_tag)) 
        #clip first 600 samples
        self.head = blocks.head(gr.sizeof_gr_complex*1, samples_to_receive + 300)
        # skiphead= blocks.skiphead(gr.sizeof_gr_complex*1,delay)
        throttle = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_amp, -seed)
        # connects
        #self.connect(vector_source, mod, (add,0))
        self.connect(self.vector_source, (add,0))
        self.connect(noise, (add,1))
        self.connect(add, throttle, self.head, self)
        self.connect(add, tag_debug)
        '''
Example #48
0
    def __init__(self, options):
	grc_wxgui.top_block_gui.__init__(self, title="DSSDR")

	self.initialized = False
	self.stopped = False

	self.options = copy.copy(options)
	self._constellation = digital.constellation_bpsk()
	self._excess_bw = options.excess_bw
	self._phase_bw = options.phase_bw
	self._freq_bw = options.freq_bw
	self._timing_bw = options.timing_bw
	self._if_freq = options.if_freq
	self._timing_max_dev= 1.5
	self._demod_class = digital.bpsk_demod  # the demodulator_class we're using
	self._chbw_factor = options.chbw_factor # channel filter bandwidth factor
	self._samples_per_second = 2e6
	self._nav_samples_per_second = 16e6
	self._down_decim = 1
	self._down_samples_per_second = self._scope_sample_rate = self._samples_per_second/self._down_decim
	self._up_samples_per_second = 1e6
	self._asm_threshold = 0
	self._access_code = None
	self._tm_packet_id = 4
	self._timestamp_id = 5
	self._down_bitrate = options.bitrate
	self._up_bitrate = options.up_bitrate
	self._up_samples_per_symbol = self._up_samples_per_second/self._up_bitrate
	self._samples_per_symbol = self._samples_per_second/self._down_decim/self._down_bitrate
	self._down_sub_freq = options.down_sub_freq
	self._up_sub_freq = 25e3
	self._tm_len = 8920
	self._up_tm_len = 8920
	self._coding_method = options.coding_method
	self._up_coding_method = 'None'
	self._up_subcarrier = 'Square'
	self._rs_i = 1
	self._ccsds_channel = 38
	self._uhd_carrier_offset = 10e3
	self._turn_div = 749
	self._turn_mult = 880
	self._modulation_index = 'pi/3'
	self._up_modulation_index = 1.047
	self._max_carrier_offset = 0.1
	self._dssdr_mixer_freq = options.rf_freq
	self._up_coding_rate = '1'
	self._down_coding_rate = '1'
	self._down_conv_en = "False"
	self._down_randomizer_en = options.down_randomizer_en
	self._down_manchester_en = options.down_manchester_en
	self._up_conv_en = "False"
	self._up_idle_sequence = "\\x55"
	self._down_default_gain = 64
	self._up_default_gain = 44
	self._up_en = True

        if self._access_code is None:
            self._access_code = packet_utils.default_access_code

	#Construct the lookup table for parameter-setting functions
	self.param_setters = {
		"DSSDR_CHANNEL": self.setChannel,
		"DSSDR_LO_FREQ": self.setLOFreq,
		"DSSDR_REF_FREQ": self.setRefFreq,
		"DSSDR_TURN_MULT": self.setTurnMult,
		"DSSDR_TURN_DIV": self.setTurnDiv,
		"DSSDR_UP_GAIN": self.setUpGain,
		"DSSDR_DOWN_GAIN": self.setDownGain,
		"DSSDR_UP_BITRATE": self.setUpBitrate,
		"DSSDR_DOWN_BITRATE": self.setDownBitrate,
		"DSSDR_DOWN_SAMPLE_RATE": self.setSampRate,
		"DSSDR_UP_SUB_FREQ": self.setUpSubFreq,
		"DSSDR_DOWN_SUB_FREQ": self.setDownSubFreq,
		"DSSDR_DOPPLER_REPORT": self.dopplerReport,
		"DSSDR_PN_RANGE": self.rangePN,
		"DSSDR_SEQUENTIAL_RANGE": self.rangeSequential,
		"DSSDR_DOWN_CODING_METHOD": self.setDownCodingMethod,
		"DSSDR_UP_CODING_METHOD": self.setUpCodingMethod,
		"DSSDR_DOWN_TM_LEN": self.setTMLen,
		"DSSDR_UP_TM_LEN": self.setUpTMLen,
		"DSSDR_DOWN_MOD_IDX": self.setDownModulationIndex,
		"DSSDR_UP_MOD_IDX": self.setUpModulationIndex,
		"DSSDR_DOWN_CONV_EN": self.setDownConvEn,
		"DSSDR_UP_CONV_EN": self.setUpConvEn,
		"DSSDR_ASM_TOL": self.setASMThreshold,
		"DSSDR_UP_SWEEP": self.freqSweep,
		"DSSDR_UP_IDLE": self.setUpIdleSequence,
		"DSSDR_UP_EN": self.setUpEn,
		"DSSDR_SYNC_TIME": self.syncSDRTime,
		"DSSDR_UP_SWEEP": self.freqSweep,
		"DSSDR_DOWN_ACQUIRE": self.acquireCarrier,
		"DSSDR_INPUT_SELECT": self.setPanelSelect,
		"DSSDR_REF_SELECT": self.setRefSelect,
		"DSSDR_PPS_SELECT": self.setPPSSelect
	}

	#TODO:Add status fields for things like DSSDR_REF_LOCK

	self._dssdr_channels = {
		3: [7149597994, 8400061729],
		4: [7150753857, 8401419752],
		5: [7151909723, 8402777779],
		6: [7153065586, 8404135802],
		7: [7154221449, 8405493825],
		8: [7155377316, 8406851853],
		9: [7156533179, 8408209877],
		10: [7157689045, 8409567903],
		11: [7158844908, 8410925927],
		12: [7160000771, 8412283950],
		13: [7161156637, 8413641977],
		14: [7162312500, 8415000000],
		15: [7163468363, 8416358023],
		16: [7164624229, 8417716050],
		17: [7165780092, 8419074073],
		18: [7166935955, 8420432097],
		19: [7168091821, 8421790123],
		20: [7169247684, 8423148147],
		21: [7170403551, 8424506175],
		22: [7171559414, 8425864198],
		23: [7172715277, 8427222221],
		24: [7173871143, 8428580248],
		25: [7175027006, 8429938271],
		26: [7176182869, 8431296295],
		27: [7177338735, 8432654321],
		28: [7178494598, 8434012345],
		29: [7179650464, 8435370372],
		30: [7180806327, 8436728395],
		31: [7181962190, 8438086418],
		32: [7183118057, 8439444446],
		33: [7184273920, 8440802469],
		34: [7185429783, 8442160493],
		35: [7186585649, 8443518520],
		36: [7187741512, 8444876543],
		37: [7188897378, 8446234570],
		38: [7190000000, 8450000000],
	}

	#FLOWGRAPH STUFF
	if options.test == True:
		self.u = blks2.tcp_source(
			itemsize=gr.sizeof_gr_complex*1,
			addr="",
			port=12905,
			server=True
		)
	elif options.fromfile == True:
		self.u2 = blocks.file_meta_source("iq_in.dat")
		self.u = blocks.throttle(gr.sizeof_gr_complex*1, self._samples_per_second)
	elif options.frombitlog == True:
		self.u3 = blocks.file_source(gr.sizeof_char, "bitstream_recording.in", True)
		self.u2 = blocks.uchar_to_float()
		self.u1 = blocks.throttle(gr.sizeof_float*1, self._down_bitrate)
		self.u = blocks.add_const_ff(-0.5)
	else:
		self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32'))
		self.u.set_clock_source("external")
		self.u.set_time_source("external")
		self.u.set_samp_rate(self._samples_per_second)
		self.u.set_antenna("RX2")
		self.u.set_gain(self._down_default_gain)

		self.frontend = dfi.dssdrFrontendInterface(self.u)

	if options.debug_pps == True:
		self.debug_pps = blocks.tag_debug(gr.sizeof_gr_complex, "debug-pps", "rx_time")

	if options.tofile == True:
		self.u_tx = blocks.file_meta_sink(gr.sizeof_gr_complex, "iq_out.dat", self._up_samples_per_second)
	elif options.tonull == True:
		self.u_tx = blocks.null_sink(gr.sizeof_gr_complex)
	else:
		self.u_tx = uhd.usrp_sink(device_addr=options.args, stream_args=uhd.stream_args('fc32'))
		self.u_tx.set_clock_source("external")
		self.u_tx.set_time_source("external")
		self.u_tx.set_samp_rate(self._up_samples_per_second)
		self.u_tx.set_antenna("TX/RX")
		self.u_tx.set_gain(self._up_default_gain)

	#GUI STUFF
	if options.graphics == True:
		self.nb0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "RX")
		self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "TX")
		self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Nav")
		self.Add(self.nb0)
		self.constellation_scope = scopesink2.scope_sink_c(
			self.nb0.GetPage(0).GetWin(),
			title="Scope Plot",
			sample_rate=self._scope_sample_rate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
			trig_mode=wxgui.TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
	        self.nb0.GetPage(0).Add(self.constellation_scope.win)
		#self.constellation_scope.win.set_marker('plus')
		self._scope_is_fft = False
		self.time_scope = scopesink2.scope_sink_f(
			self.nb0.GetPage(0).GetWin(),
			title="Scope Plot",
			sample_rate=self._scope_sample_rate,
			v_scale=0,
			v_offset=0,
			t_scale=.005,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=wxgui.TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.nb0.GetPage(0).Add(self.time_scope.win)
		self.nb0.GetPage(0).GetWin()._box.Hide(self.time_scope.win)
		self.fft_scope = fftsink2.fft_sink_c(
			self.nb0.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=10,
			y_divs=10,
			ref_level=0,
			ref_scale=2.0,
			sample_rate=self._scope_sample_rate,
			fft_size=1024,
		 	fft_rate=15,
			average=False,
			avg_alpha=None,
			title="FFT Plot",
			peak_hold=False,
		)
		self.nb0.GetPage(0).Add(self.fft_scope.win)
		self.nb0.GetPage(0).GetWin()._box.Hide(self.fft_scope.win)
	
		self.row1_sizer = wx.BoxSizer(wx.HORIZONTAL)
		self.recording_onoff_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value='Off',
			callback=self.setRecording,
			label="IQ Recording",
			choices=['Off','On'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.front_panel_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value='RF',
			callback=self.setPanelSelect,
			label="Input Select",
			choices=['RF','IF'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.ref_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value='Internal',
			callback=self.setRefSelect,
			label="Ref Select",
			choices=['Internal','External'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.pps_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value='Internal',
			callback=self.setPPSSelect,
			label="PPS Select",
			choices=['Internal','External'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)

		self.sync_button = forms.button(
			parent=self.nb0.GetPage(0).GetWin(),
			value='Sync to PPS',
			callback=self.syncSDRTime,
			choices=['Sync to PPS'],
			style=wx.RA_HORIZONTAL,
		)
		self.ref_locked_text = forms.static_text(
			parent=self.nb0.GetPage(0).GetWin(),
			value="",
			callback=self.setRefLocked,
			label="",
			converter=forms.str_converter(),
		)
		self.row1_sizer.Add(self.recording_onoff_chooser, flag=wx.ALIGN_CENTER)
		self.row1_sizer.Add(self.front_panel_chooser, flag=wx.ALIGN_CENTER)
		self.row1_sizer.Add(self.ref_chooser, flag=wx.ALIGN_CENTER)
		self.row1_sizer.Add(self.pps_chooser, flag=wx.ALIGN_CENTER)
		self.row1_sizer.Add(self.sync_button, flag=wx.ALIGN_CENTER)
		self.row1_sizer.Add(self.ref_locked_text, flag=wx.ALIGN_CENTER)
		self.nb0.GetPage(0).Add(self.row1_sizer)
		self.complex_scope_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value='Constellation',
			callback=self.setComplexScopeStyle,
			label="Complex Scope",
			choices=['Constellation','FFT'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.nb0.GetPage(0).Add(self.complex_scope_chooser)
		self.scope_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value='USRP',
			callback=self.setScopePoint,
			label="Scope Probe Point",
			choices=['USRP','Carrier Tracking','Sub-Carrier Costas','Sub-Carrier Sync','Data Sync'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.nb0.GetPage(0).Add(self.scope_chooser)
		self._bitrate_text_box = forms.text_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._down_bitrate,
			callback=self.setDownBitrate,
			label="Symbol Rate",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(0).Add(self._bitrate_text_box)
		self._samprate_text_box = forms.text_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._samples_per_second,
			callback=self.setSampRate,
			label="Sampling Rate",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(0).Add(self._samprate_text_box)
		self._subcfreq_text_box = forms.text_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._down_sub_freq,
			callback=self.setDownSubFreq,
			label="Downlink Subcarrier Frequency",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(0).Add(self._subcfreq_text_box)
		self._mod_index_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._modulation_index,
			callback=self.setDownModulationIndex,
			label="Modulation Index",
			choices=['pi/2', 'pi/3'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.nb0.GetPage(0).Add(self._mod_index_chooser)
		self._pktlen_text_box = forms.text_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._tm_len,
			callback=self.setTMLen,
			label="Downlink Packet Length (bits)",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(0).Add(self._pktlen_text_box)
		self._coding_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._coding_method,
			callback=self.setDownCodingMethod,
			label="Coding",
			choices=['None', 'RS', 'Turbo 1/2', 'Turbo 1/3', 'Turbo 1/4', 'Turbo 1/6'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.nb0.GetPage(0).Add(self._coding_chooser)
		self._down_conv_check_box = forms.check_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._down_conv_en,
			callback=self.setDownConvEn,
			label="Convolutional Decode",
			true="True",
			false="False",
		)
		self.nb0.GetPage(0).Add(self._down_conv_check_box)
		self._down_randomizer_check_box = forms.check_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._down_randomizer_en,
			callback=self.setDownRandomizerEn,
			label="De-randomizer",
			true=True,
			false=False,
		)
		self.nb0.GetPage(0).Add(self._down_randomizer_check_box)
		self._down_manchester_check_box = forms.check_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._down_manchester_en,
			callback=self.setDownManchesterEn,
			label="Manchester Decode",
			true=True,
			false=False,
		)
		self.nb0.GetPage(0).Add(self._down_manchester_check_box)
		self._pktlen_text_box = forms.text_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._asm_threshold,
			callback=self.setASMThreshold,
			label="ASM Error Tolerance (bits)",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(0).Add(self._pktlen_text_box)
		self._coding_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._rs_i,
			callback=self.setRSI,
			label="Reed-Solomon Interleaving Depth",
			choices=[1,5],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.nb0.GetPage(0).Add(self._coding_chooser)
		self._ccsds_chan_text_box = forms.text_box(
			parent=self.nb0.GetPage(0).GetWin(),
			value=self._ccsds_channel,
			callback=self.setChannel,
			label="CCSDS Channel",
			converter=forms.int_converter(),
		)
		self.nb0.GetPage(0).Add(self._ccsds_chan_text_box)
		self.setChannel(self._ccsds_channel)
	
		if options.test == True or options.fromfile == True or options.frombitlog == True:
			glow = 0.0
			ghigh = 1.0
			cur_g = 0.5
		else:
			g = self.u.get_gain_range()
			cur_g = self._down_default_gain
		
			# some configurations don't have gain control
			if g.stop() <= g.start():
				glow = 0.0
				ghigh = 1.0
		
			else:
				glow = g.start()
				ghigh = g.stop()
		
		self._uhd_gain_slider = wx.BoxSizer(wx.HORIZONTAL)
		form.slider_field(
			parent=self.nb0.GetPage(0).GetWin(),
			sizer=self._uhd_gain_slider,
			label="USRP RX Gain",
			weight=3,
			min=int(glow), 
			max=int(ghigh),
			value=cur_g,
			callback=self.setDownGain
		)
		self.nb0.GetPage(0).Add(self._uhd_gain_slider)

		#TX chain GUI components
		if options.test == True or options.tofile == True or options.tonull == True:
			gtxlow = 0.0
			gtxhigh = 1.0
			cur_gtx = 0.5
		else:
			gtx = self.u_tx.get_gain_range()
			cur_gtx = self._up_default_gain
		
			# some configurations don't have gain control
			if gtx.stop() <= gtx.start():
				gtxlow = 0.0
				gtxhigh = 1.0
		
			else:
				gtxlow = gtx.start()
				gtxhigh = gtx.stop()

		self._up_en_chooser = forms.check_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value='True',
			callback=self.setUpEn,
			label="TX Enable",
			true='True',
			false='False',
		)
		self.nb0.GetPage(1).Add(self._up_en_chooser)

		self._uhd_tx_gain_slider = wx.BoxSizer(wx.HORIZONTAL)
		form.slider_field(
			parent=self.nb0.GetPage(1).GetWin(),
			sizer=self._uhd_tx_gain_slider,
			label="USRP TX Gain",
			weight=3,
			min=int(gtxlow), 
			max=int(gtxhigh),
			value=cur_gtx,
			callback=self.setUpGain
		)
		self.nb0.GetPage(1).Add(self._uhd_tx_gain_slider)
		self._subcfreq_up_text_box = forms.text_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._up_sub_freq,
			callback=self.setUpSubFreq,
			label="Uplink Subcarrier Frequency",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(1).Add(self._subcfreq_up_text_box)
		self._up_bitrate_text_box = forms.text_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._up_bitrate,
			callback=self.setUpBitrate,
			label="Uplink Bitrate",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(1).Add(self._up_bitrate_text_box)
		self._up_data_text_box = forms.text_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value="1234ABCD",
			callback=self.txData,
			label="TX Data",
			converter=forms.str_converter(),
		)
		self.nb0.GetPage(1).Add(self._up_data_text_box)
		self._up_mod_index_chooser = forms.text_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._up_modulation_index,
			callback=self.setUpModulationIndex,
			label="Uplink Modulation Index",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(1).Add(self._up_mod_index_chooser)
		self._up_coding_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._up_coding_method,
			callback=self.setUpCodingMethod,
			label="Coding",
			choices=['None', 'RS'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.nb0.GetPage(1).Add(self._up_coding_chooser)
		self._subcarrier_chooser = forms.radio_buttons(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._up_subcarrier,
			callback=self.setUpSubcarrier,
			label="Subcarrier Type",
			choices=['Square','Sine'],
			labels=[],
			style=wx.RA_HORIZONTAL,
		)
		self.nb0.GetPage(1).Add(self._subcarrier_chooser)
		self._up_conv_check_box = forms.check_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._up_conv_en,
			callback=self.setUpConvEn,
			label="Convolutional Encode",
			true="True",
			false="False",
		)
		self.nb0.GetPage(1).Add(self._up_conv_check_box)
		self._up_pktlen_text_box = forms.text_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._up_tm_len,
			callback=self.setUpTMLen,
			label="Uplink Packet Length (bits)",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(1).Add(self._up_pktlen_text_box)
		self._uhd_offset_text_box = forms.text_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._uhd_carrier_offset,
			callback=self.setUHDCarrierOffset,
			label="USRP Offset Frequency (Hz)",
			converter=forms.float_converter(),
		)
		self.nb0.GetPage(1).Add(self._uhd_offset_text_box)
		self._sweep_gen_text_box = forms.text_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value="rf2_1",
			callback=self.freqSweep,
			label="Frequency Sweep Profile",
			converter=forms.str_converter(),
		)
		self.nb0.GetPage(1).Add(self._sweep_gen_text_box)
		self._idle_sequence_text_box = forms.text_box(
			parent=self.nb0.GetPage(1).GetWin(),
			value=self._up_idle_sequence,
			callback=self.setUpIdleSequence,
			label="Uplink Idle Sequence",
			converter=forms.str_converter(),
		)
		self.nb0.GetPage(1).Add(self._idle_sequence_text_box)
		self._pn_ranging_text_box = forms.text_box(
			parent=self.nb0.GetPage(2).GetWin(),
			value="",
			callback=self.rangePN,
			label="Queue PN Ranging",
			converter=forms.str_converter(),
		)
		self.nb0.GetPage(2).Add(self._pn_ranging_text_box)
		self._sequential_ranging_text_box = forms.text_box(
			parent=self.nb0.GetPage(2).GetWin(),
			value="",
			callback=self.rangeSequential,
			label="Queue Sequential Ranging",
			converter=forms.str_converter(),
		)
		self.nb0.GetPage(2).Add(self._sequential_ranging_text_box)
		self.row2_sizer = wx.BoxSizer(wx.HORIZONTAL)
		self.freq_acq_button = forms.button(
			parent=self.nb0.GetPage(2).GetWin(),
			value='Acquire Carrier Offset',
			callback=self.acquireCarrier,
			choices=['Acquire Carrier Offset'],
			style=wx.RA_HORIZONTAL,
		)
		self.carrier_offset_text = forms.static_text(
			parent=self.nb0.GetPage(2).GetWin(),
			value="",
			label="",
			converter=forms.str_converter(),
		)
		self.row2_sizer.Add(self.freq_acq_button, flag=wx.ALIGN_CENTER)
		self.row2_sizer.Add(self.carrier_offset_text, flag=wx.ALIGN_CENTER)
		self.nb0.GetPage(2).Add(self.row2_sizer)


	self.file_sink = blocks.file_meta_sink(gr.sizeof_gr_complex, "iq_recording.dat", self._samples_per_second)
	self.file_sink.close()
	self.iq_recording_ctr = 0

	# Selection logic to switch between recording and normal flowgraph routes
	# NOTE: u_valve logic is implemented backwards in GNURadio....
	#self.u_valve = blks2.valve(
	#	item_size=gr.sizeof_gr_complex,
	#	open=False
	#)

	# Temporary code used to verify coherent turnaround
	self.turnaround_mixer = blocks.multiply_cc()
	self.turnaround_mixer_source = analog.sig_source_c(self._down_samples_per_second, analog.GR_SIN_WAVE, -25e3, 1.0)
	self.turnaround_iir = filter.single_pole_iir_filter_cc(0.0001)
	self.turnaround_null = blocks.null_sink(gr.sizeof_float)

	# PLL and associated carrier for tracking carrier frequency if residual carrier is used
	self.carrier_tracking = sdrp.pll_freq_acq_cc(math.pi/2000, math.pi, -math.pi, int(options.acq_samples))
	self.imag_to_float = blocks.complex_to_imag()

	#Suppressed carrier requires costas after subcarrier mixer
	self.subcarrier_costas = digital.costas_loop_cc(0.001, 2)
	self.real_to_float = blocks.complex_to_real()

	#Square wave subcarrier sync
	self.subcarrier_sync = sdrp.square_sub_tracker_ff(0.001, 2*self._down_sub_freq/self._down_samples_per_second*1.0001, 2*self._down_sub_freq/self._down_samples_per_second*0.9999)

	#Data sync
	self.data_sync = sdrp.square_data_tracker_ff(0.001, self._down_bitrate/self._down_samples_per_second*1.001, self._down_bitrate/self._down_samples_per_second*0.999)

	#Data framing
	self.soft_correlator = sdrp.correlate_soft_access_tag_ff(conv_packed_binary_string_to_1_0_string('\x1A\xCF\xFC\x1D'), self._asm_threshold, "asm_corr")
	self.conv_decoder = sdrp.ccsds_tm_conv_decoder("asm_corr")
	self.de_randomizer = sdrp.ccsds_tm_derandomizer("asm_corr")
	self.tm_framer = sdrp.ccsds_tm_framer(self._tm_packet_id, self._timestamp_id, "asm_corr", "rx_time", self._down_bitrate)
	self.tm_framer.setFrameLength(self._tm_len)

	self._current_scope_block = None
	self._current_scoped_block = self.u
	self._current_scoped_block_port = 0

	self._recording = 'Off'

	#TX path in flowgraph
	self.pkt_gen_msgq = gr.msg_queue(10)
        self.pkt_gen = sdrp.ccsds_tm_tx(self._tm_packet_id, self._timestamp_id, 1.0, 16, self.pkt_gen_msgq)
	self.conj = blocks.conjugate_cc()

	#Sweep generator for transponder lock
	self.sweep_gen = sdrp.sweep_generator_cc(self._up_samples_per_second)

	# DSSDR subcarrier mixer (either 25 kHz or 0 kHz depending on baud rate)
	self.up_subcarrier_mixer = blocks.multiply_ff()
	self.subcarrier_mixer_source_tx = analog.sig_source_f(self._up_samples_per_second, analog.GR_SQR_WAVE, 25e3, 2.0, -1.0)
	self.phase_mod_tx = analog.phase_modulator_fc(self._up_modulation_index)
	self.tx_attenuator = blocks.multiply_const_cc((0.1+0.0j))

	#Add in bit recorder if needed
	if self.options.bitlog:
		self.bit_slicer = digital.binary_slicer_fb()
		self.bit_recorder = blocks.file_sink(1, "bitstream_recording.out")


	self.setDownCodingMethod(self._coding_method)
	self.setUpCodingMethod("None")
	self.setUpSubcarrier(self._up_subcarrier)
	self.setDownBitrate(self._down_bitrate)
	self.setUpBitrate(self._up_bitrate)
	self.setDownModulationIndex(self._modulation_index)
	self.setUpModulationIndex(self._up_modulation_index)
	self.setDownConvEn(self._down_conv_en)
	self.setUpConvEn(self._up_conv_en)
	self.setUpIdleSequence(self._up_idle_sequence)
	self.setDownRandomizerEn(self._down_randomizer_en)
	self.setDownManchesterEn(self._down_manchester_en)

	#Connection to outside world
	self.socket_pdu = blocks.socket_pdu("TCP_SERVER", "127.0.0.1", "12902", 10000)
	self.sdrp_interpreter = sdrp.sdrp_packet_interpreter()
	self.msg_connect(self.tm_framer, "tm_frame_out", self.sdrp_interpreter, "sdrp_pdu_in")
	self.msg_connect(self.sdrp_interpreter, "socket_pdu_out", self.socket_pdu, "pdus")
	self.msg_connect(self.socket_pdu, "pdus", self.sdrp_interpreter, "socket_pdu_in")
	self.msg_connect(self.sdrp_interpreter,"sdrp_pdu_out", self.pkt_gen, "ccsds_tx_msg_in")

	if options.test == False and options.fromfile == False and options.frombitlog == False:
		_threading.Thread(target=self.watchRef).start()

	self.initialized = True
	print "DS-SDR Initialized"
Example #49
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="OFDM Rx")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.occupied_carriers = occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),)
		self.length_tag_name = length_tag_name = "frame_len"
		self.sync_word2 = sync_word2 = (0, 0, 0, 0, 0, 1, 1, -1.0, -1, 1.0, 1, 1.0, -1, -1.0, -1, 1.0, 1, -1.0, 1, 1.0, 1, -1.0, -1, -1.0, -1, 1.0, -1, 1.0, -1, 1.0, 1, -1.0, 0, 1.0, 1, -1.0, 1, 1.0, -1, -1.0, 1, -1.0, -1, -1.0, 1, 1.0, 1, -1.0, 1, 1.0, -1, 1.0, -1, -1.0, -1, 1.0, 1, -1.0, 0, 0, 0, 0, 0, 0)
		self.sync_word1 = sync_word1 = (0, 0, 0, 0, 0, 0, 0, -1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, -1.0, 0, 1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, -1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 0, 0, 0, 0, 0)
		self.samp_rate = samp_rate = 3200000
		self.pilot_symbols = pilot_symbols = ((1, 1, 1, -1,),)
		self.pilot_carriers = pilot_carriers = ((-21, -7, 7, 21,),)
		self.payload_mod = payload_mod = digital.constellation_qpsk()
		self.header_mod = header_mod = digital.constellation_bpsk()
		self.header_formatter = header_formatter = digital.packet_header_ofdm(occupied_carriers, 1, length_tag_name)
		self.fft_len = fft_len = 64

		##################################################
		# Blocks
		##################################################
		self.gr_delay_0 = gr.delay(gr.sizeof_gr_complex*1, fft_len+fft_len/4)
		self.fft_vxx_0_0 = fft.fft_vcc(fft_len, True, (), True, 1)
		self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (), True, 1)
		self.digital_packet_headerparser_b_0 = digital.packet_headerparser_b(header_formatter.formatter())
		self.digital_ofdm_sync_sc_cfb_0 = digital.ofdm_sync_sc_cfb(fft_len, fft_len/4, False)
		self.digital_ofdm_serializer_vcc_1 = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, "length_tag_key", "", 1, "", True)
		self.digital_ofdm_serializer_vcc_0 = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, length_tag_name, "", 0, "", True)
		self.digital_ofdm_frame_equalizer_vcvc_0_0 = digital.ofdm_frame_equalizer_vcvc(digital.ofdm_equalizer_simpledfe(fft_len, header_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols).base(), fft_len/4, length_tag_name, True, 0)
		self.digital_ofdm_frame_equalizer_vcvc_0 = digital.ofdm_frame_equalizer_vcvc(digital.ofdm_equalizer_simpledfe(fft_len, header_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols, 2).base(), fft_len/4, "length_tag_key", False, 0)
		self.digital_ofdm_chanest_vcvc_0 = digital.ofdm_chanest_vcvc((sync_word1), (sync_word2), 2, 0, -1, False)
		self.digital_header_payload_demux_0 = digital.header_payload_demux(3, fft_len, fft_len/4, length_tag_name, "", True, gr.sizeof_gr_complex)
		self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb(header_mod.base())
		self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(payload_mod.base())
		self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "Rx Packets")
		self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
		self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 1, 0)
		self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(-2.0/fft_len)

		##################################################
		# Connections
		##################################################
		self.connect((self.digital_ofdm_frame_equalizer_vcvc_0_0, 0), (self.digital_ofdm_serializer_vcc_0, 0))
		self.connect((self.digital_header_payload_demux_0, 0), (self.fft_vxx_0, 0))
		self.connect((self.fft_vxx_0, 0), (self.digital_ofdm_chanest_vcvc_0, 0))
		self.connect((self.digital_ofdm_chanest_vcvc_0, 0), (self.digital_ofdm_frame_equalizer_vcvc_0_0, 0))
		self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.digital_packet_headerparser_b_0, 0))
		self.connect((self.digital_ofdm_serializer_vcc_0, 0), (self.digital_constellation_decoder_cb_0_0, 0))
		self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_tag_debug_0, 0))
		self.connect((self.fft_vxx_0_0, 0), (self.digital_ofdm_frame_equalizer_vcvc_0, 0))
		self.connect((self.digital_ofdm_frame_equalizer_vcvc_0, 0), (self.digital_ofdm_serializer_vcc_1, 0))
		self.connect((self.digital_header_payload_demux_0, 1), (self.fft_vxx_0_0, 0))
		self.connect((self.digital_ofdm_serializer_vcc_1, 0), (self.digital_constellation_decoder_cb_0, 0))
		self.connect((self.blocks_throttle_0, 0), (self.digital_ofdm_sync_sc_cfb_0, 0))
		self.connect((self.blocks_throttle_0, 0), (self.gr_delay_0, 0))
		self.connect((self.analog_noise_source_x_0, 0), (self.blocks_throttle_0, 0))
		self.connect((self.analog_frequency_modulator_fc_0, 0), (self.blocks_multiply_xx_0, 0))
		self.connect((self.digital_ofdm_sync_sc_cfb_0, 0), (self.analog_frequency_modulator_fc_0, 0))
		self.connect((self.gr_delay_0, 0), (self.blocks_multiply_xx_0, 1))
		self.connect((self.digital_ofdm_sync_sc_cfb_0, 1), (self.digital_header_payload_demux_0, 1))
		self.connect((self.blocks_multiply_xx_0, 0), (self.digital_header_payload_demux_0, 0))

		##################################################
		# Asynch Message Connections
		##################################################
		self.msg_connect(self.digital_packet_headerparser_b_0, "header_data", self.digital_header_payload_demux_0, "header_data")
Example #50
0
    def __init__(self):
        gr.top_block.__init__(self, "Ofdm02")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Ofdm02")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "ofdm02")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.timing = timing = 1.0001
        self.samp_rate = samp_rate = 100000
        self.packet_len = packet_len = 50
        self.noise = noise = 0.01
        self.len_tag_key = len_tag_key = "packet_len"
        self.freq = freq = 0.01
        self.fft_len = fft_len = 128

        ##################################################
        # Blocks
        ##################################################
        self._timing_layout = Qt.QVBoxLayout()
        self._timing_tool_bar = Qt.QToolBar(self)
        self._timing_layout.addWidget(self._timing_tool_bar)
        self._timing_tool_bar.addWidget(Qt.QLabel("Timing Offset"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._timing_counter = qwt_counter_pyslot()
        self._timing_counter.setRange(0.999, 1.001, 0.0001)
        self._timing_counter.setNumButtons(2)
        self._timing_counter.setValue(self.timing)
        self._timing_tool_bar.addWidget(self._timing_counter)
        self._timing_counter.valueChanged.connect(self.set_timing)
        self._timing_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._timing_slider.setRange(0.999, 1.001, 0.0001)
        self._timing_slider.setValue(self.timing)
        self._timing_slider.setMinimumWidth(200)
        self._timing_slider.valueChanged.connect(self.set_timing)
        self._timing_layout.addWidget(self._timing_slider)
        self.top_grid_layout.addLayout(self._timing_layout, 2,0,1,1)
        self._noise_layout = Qt.QVBoxLayout()
        self._noise_tool_bar = Qt.QToolBar(self)
        self._noise_layout.addWidget(self._noise_tool_bar)
        self._noise_tool_bar.addWidget(Qt.QLabel("Noise Voltage"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._noise_counter = qwt_counter_pyslot()
        self._noise_counter.setRange(0, 3, 0.01)
        self._noise_counter.setNumButtons(2)
        self._noise_counter.setValue(self.noise)
        self._noise_tool_bar.addWidget(self._noise_counter)
        self._noise_counter.valueChanged.connect(self.set_noise)
        self._noise_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._noise_slider.setRange(0, 3, 0.01)
        self._noise_slider.setValue(self.noise)
        self._noise_slider.setMinimumWidth(200)
        self._noise_slider.valueChanged.connect(self.set_noise)
        self._noise_layout.addWidget(self._noise_slider)
        self.top_grid_layout.addLayout(self._noise_layout, 1,0,1,1)
        self._freq_layout = Qt.QVBoxLayout()
        self._freq_tool_bar = Qt.QToolBar(self)
        self._freq_layout.addWidget(self._freq_tool_bar)
        self._freq_tool_bar.addWidget(Qt.QLabel("Frequency Offset"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._freq_counter = qwt_counter_pyslot()
        self._freq_counter.setRange(-1, 1, 0.01)
        self._freq_counter.setNumButtons(2)
        self._freq_counter.setValue(self.freq)
        self._freq_tool_bar.addWidget(self._freq_counter)
        self._freq_counter.valueChanged.connect(self.set_freq)
        self._freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._freq_slider.setRange(-1, 1, 0.01)
        self._freq_slider.setValue(self.freq)
        self._freq_slider.setMinimumWidth(200)
        self._freq_slider.valueChanged.connect(self.set_freq)
        self._freq_layout.addWidget(self._freq_slider)
        self.top_grid_layout.addLayout(self._freq_layout, 1,1,1,1)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
                1 #number of inputs
        )
        self.qtgui_waterfall_sink_x_0.set_update_time(0.10)
        self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 0,1,1,1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-80, 10)
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,1,1)
        self.digital_ofdm_tx_0 = digital.ofdm_tx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  packet_length_tag_key=len_tag_key,
        	  bps_header=1,
        	  bps_payload=2,
        	  rolloff=0,
        	  debug_log=False,
        	  scramble_bits=False
        	 )
        self.digital_ofdm_rx_0 = digital.ofdm_rx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  frame_length_tag_key='frame_'+"rx_len",
        	  packet_length_tag_key="rx_len",
        	  bps_header=1,
        	  bps_payload=2,
        	  debug_log=False,
        	  scramble_bits=False
        	 )
        self.channels_fading_model_0 = channels.fading_model( 8, 10.0/samp_rate, False, 4.0, 0 )
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=noise,
        	frequency_offset=freq,
        	epsilon=timing,
        	taps=(1.0, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "", ""); self.blocks_tag_debug_0.set_display(True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, len_tag_key)
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 1000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.digital_ofdm_tx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.digital_ofdm_tx_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.channels_fading_model_0, 0))
        self.connect((self.channels_fading_model_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.digital_ofdm_rx_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.digital_ofdm_rx_0, 0), (self.blocks_tag_debug_0, 0))
Example #51
0
    def __init__(self):
        gr.top_block.__init__(self, "Ofdm05")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Ofdm05")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "ofdm05")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.timing = timing = 1.0001
        self.samp_rate = samp_rate = 7.68e6
        self.q_offset = q_offset = 0
        self.phase_noise = phase_noise = 0
        self.packet_len = packet_len = 50
        self.noise = noise = 1.2
        self.len_tag_key = len_tag_key = "packet_len"
        self.iq_ph = iq_ph = 0
        self.iq_mag = iq_mag = 0
        self.i_offset = i_offset = 0
        self.freq = freq = 0.01
        self.fft_len = fft_len = 128
        self.dist3 = dist3 = 0
        self.dist2 = dist2 = 0

        ##################################################
        # Blocks
        ##################################################
        self._timing_layout = Qt.QVBoxLayout()
        self._timing_label = Qt.QLabel("Timing Offset")
        self._timing_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._timing_slider.setRange(0.999, 1.001, 0.0001)
        self._timing_slider.setValue(self.timing)
        self._timing_slider.setMinimumWidth(200)
        self._timing_slider.valueChanged.connect(self.set_timing)
        self._timing_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._timing_layout.addWidget(self._timing_label)
        self._timing_layout.addWidget(self._timing_slider)
        self.top_grid_layout.addLayout(self._timing_layout, 1,2,1,1)
        self._q_offset_layout = Qt.QVBoxLayout()
        self._q_offset_label = Qt.QLabel("Quadrature Offset")
        self._q_offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._q_offset_slider.setRange(-1, 1, 0.01)
        self._q_offset_slider.setValue(self.q_offset)
        self._q_offset_slider.setMinimumWidth(200)
        self._q_offset_slider.valueChanged.connect(self.set_q_offset)
        self._q_offset_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._q_offset_layout.addWidget(self._q_offset_label)
        self._q_offset_layout.addWidget(self._q_offset_slider)
        self.top_grid_layout.addLayout(self._q_offset_layout, 2,3,1,1)
        self._phase_noise_layout = Qt.QVBoxLayout()
        self._phase_noise_label = Qt.QLabel("Phase Noise")
        self._phase_noise_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._phase_noise_slider.setRange(0, 40, 0.5)
        self._phase_noise_slider.setValue(self.phase_noise)
        self._phase_noise_slider.setMinimumWidth(200)
        self._phase_noise_slider.valueChanged.connect(self.set_phase_noise)
        self._phase_noise_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._phase_noise_layout.addWidget(self._phase_noise_label)
        self._phase_noise_layout.addWidget(self._phase_noise_slider)
        self.top_grid_layout.addLayout(self._phase_noise_layout, 1,3,1,1)
        self._noise_layout = Qt.QVBoxLayout()
        self._noise_label = Qt.QLabel("Noise Voltage")
        self._noise_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._noise_slider.setRange(0, 2, 0.01)
        self._noise_slider.setValue(self.noise)
        self._noise_slider.setMinimumWidth(200)
        self._noise_slider.valueChanged.connect(self.set_noise)
        self._noise_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._noise_layout.addWidget(self._noise_label)
        self._noise_layout.addWidget(self._noise_slider)
        self.top_grid_layout.addLayout(self._noise_layout, 1,0,1,1)
        self._iq_ph_layout = Qt.QVBoxLayout()
        self._iq_ph_label = Qt.QLabel("IQ Phase Imbalance")
        self._iq_ph_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._iq_ph_slider.setRange(-3.14, 3.14, 0.01)
        self._iq_ph_slider.setValue(self.iq_ph)
        self._iq_ph_slider.setMinimumWidth(200)
        self._iq_ph_slider.valueChanged.connect(self.set_iq_ph)
        self._iq_ph_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._iq_ph_layout.addWidget(self._iq_ph_label)
        self._iq_ph_layout.addWidget(self._iq_ph_slider)
        self.top_grid_layout.addLayout(self._iq_ph_layout, 2,1,1,1)
        self._iq_mag_layout = Qt.QVBoxLayout()
        self._iq_mag_label = Qt.QLabel("IQ Mag. Imbalance")
        self._iq_mag_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._iq_mag_slider.setRange(0, 1, 0.01)
        self._iq_mag_slider.setValue(self.iq_mag)
        self._iq_mag_slider.setMinimumWidth(200)
        self._iq_mag_slider.valueChanged.connect(self.set_iq_mag)
        self._iq_mag_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._iq_mag_layout.addWidget(self._iq_mag_label)
        self._iq_mag_layout.addWidget(self._iq_mag_slider)
        self.top_grid_layout.addLayout(self._iq_mag_layout, 2,0,1,1)
        self._i_offset_layout = Qt.QVBoxLayout()
        self._i_offset_label = Qt.QLabel("Inphase Offset")
        self._i_offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._i_offset_slider.setRange(-1, 1, 0.01)
        self._i_offset_slider.setValue(self.i_offset)
        self._i_offset_slider.setMinimumWidth(200)
        self._i_offset_slider.valueChanged.connect(self.set_i_offset)
        self._i_offset_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._i_offset_layout.addWidget(self._i_offset_label)
        self._i_offset_layout.addWidget(self._i_offset_slider)
        self.top_grid_layout.addLayout(self._i_offset_layout, 2,2,1,1)
        self._freq_layout = Qt.QVBoxLayout()
        self._freq_label = Qt.QLabel("Frequency Offset")
        self._freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._freq_slider.setRange(-1, 1, 0.01)
        self._freq_slider.setValue(self.freq)
        self._freq_slider.setMinimumWidth(200)
        self._freq_slider.valueChanged.connect(self.set_freq)
        self._freq_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._freq_layout.addWidget(self._freq_label)
        self._freq_layout.addWidget(self._freq_slider)
        self.top_grid_layout.addLayout(self._freq_layout, 1,1,1,1)
        self._dist3_layout = Qt.QVBoxLayout()
        self._dist3_label = Qt.QLabel("Third Order Dist")
        self._dist3_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._dist3_slider.setRange(0, 0.1, 0.0001)
        self._dist3_slider.setValue(self.dist3)
        self._dist3_slider.setMinimumWidth(200)
        self._dist3_slider.valueChanged.connect(self.set_dist3)
        self._dist3_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._dist3_layout.addWidget(self._dist3_label)
        self._dist3_layout.addWidget(self._dist3_slider)
        self.top_grid_layout.addLayout(self._dist3_layout, 3,1,1,1)
        self._dist2_layout = Qt.QVBoxLayout()
        self._dist2_label = Qt.QLabel("2nd Order Dist.")
        self._dist2_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._dist2_slider.setRange(0, 0.1, 0.0001)
        self._dist2_slider.setValue(self.dist2)
        self._dist2_slider.setMinimumWidth(200)
        self._dist2_slider.valueChanged.connect(self.set_dist2)
        self._dist2_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._dist2_layout.addWidget(self._dist2_label)
        self._dist2_layout.addWidget(self._dist2_slider)
        self.top_grid_layout.addLayout(self._dist2_layout, 3,0,1,1)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
                1 #number of inputs
        )
        self.qtgui_waterfall_sink_x_0.set_update_time(0.10)
        self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 0,2,1,2)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-80, 10)
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,1,2)
        self.digital_ofdm_tx_0 = digital.ofdm_tx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  packet_length_tag_key=len_tag_key,
        	  bps_header=1,
        	  bps_payload=2,
        	  rolloff=0,
        	  debug_log=False,
        	  scramble_bits=False
        	 )
        self.digital_ofdm_rx_0 = digital.ofdm_rx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  frame_length_tag_key='frame_'+"rx_len",
        	  packet_length_tag_key="rx_len",
        	  bps_header=1,
        	  bps_payload=2,
        	  debug_log=False,
        	  scramble_bits=False
        	 )
        self.channels_impairments_0 = channels.impairments(phase_noise, iq_mag, iq_ph, q_offset, i_offset, 0, dist2, dist3)
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=noise,
        	frequency_offset=freq,
        	epsilon=timing,
        	taps=(1.0, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "", "packet_num"); self.blocks_tag_debug_0.set_display(True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, len_tag_key)
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 1000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.digital_ofdm_tx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.channels_impairments_0, 0), (self.digital_ofdm_rx_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.digital_ofdm_tx_0, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.channels_impairments_0, 0))
        self.connect((self.channels_impairments_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.channels_impairments_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.digital_ofdm_rx_0, 0), (self.blocks_tag_debug_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.channels_channel_model_0, 0))
Example #52
0
 def __init__(self, fft_len=_def_fft_len, cp_len=_def_cp_len,
              frame_length_tag_key=_def_frame_length_tag_key,
              packet_length_tag_key=_def_packet_length_tag_key,
              packet_num_tag_key=_def_packet_num_tag_key,
              occupied_carriers=_def_occupied_carriers,
              pilot_carriers=_def_pilot_carriers,
              pilot_symbols=_def_pilot_symbols,
              bps_header=1,
              bps_payload=1,
              sync_word1=None,
              sync_word2=None,
              debug_log=False,
              scramble_bits=False
              ):
     gr.hier_block2.__init__(self, "ofdm_rx",
                 gr.io_signature(1, 1, gr.sizeof_gr_complex),
                 gr.io_signature(1, 1, gr.sizeof_char))
     ### Param init / sanity check ########################################
     self.fft_len           = fft_len
     self.cp_len            = cp_len
     self.frame_length_tag_key    = frame_length_tag_key
     self.packet_length_tag_key   = packet_length_tag_key
     self.occupied_carriers = occupied_carriers
     self.bps_header        = bps_header
     self.bps_payload       = bps_payload
     n_sync_words = 1
     if sync_word1 is None:
         self.sync_word1 = _make_sync_word1(fft_len, occupied_carriers, pilot_carriers)
     else:
         if len(sync_word1) != self.fft_len:
             raise ValueError("Length of sync sequence(s) must be FFT length.")
         self.sync_word1 = sync_word1
     self.sync_word2 = ()
     if sync_word2 is None:
         self.sync_word2 = _make_sync_word2(fft_len, occupied_carriers, pilot_carriers)
         n_sync_words = 2
     elif len(sync_word2):
         if len(sync_word2) != fft_len:
             raise ValueError("Length of sync sequence(s) must be FFT length.")
         self.sync_word2 = sync_word2
         n_sync_words = 2
     if scramble_bits:
         self.scramble_seed = 0x7f
     else:
         self.scramble_seed = 0x00 # We deactivate the scrambler by init'ing it with zeros
     ### Sync ############################################################
     sync_detect = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     delay = blocks.delay(gr.sizeof_gr_complex, fft_len+cp_len)
     oscillator = analog.frequency_modulator_fc(-2.0 / fft_len)
     mixer = blocks.multiply_cc()
     hpd = digital.header_payload_demux(
         n_sync_words+1,       # Number of OFDM symbols before payload (sync + 1 sym header)
         fft_len, cp_len,      # FFT length, guard interval
         frame_length_tag_key, # Frame length tag key
         "",                   # We're not using trigger tags
         True                  # One output item is one OFDM symbol (False would output complex scalars)
     )
     self.connect(self, sync_detect)
     self.connect(self, delay, (mixer, 0), (hpd, 0))
     self.connect((sync_detect, 0), oscillator, (mixer, 1))
     self.connect((sync_detect, 1), (hpd, 1))
     if debug_log:
         self.connect((sync_detect, 0), blocks.file_sink(gr.sizeof_float, 'freq-offset.dat'))
         self.connect((sync_detect, 1), blocks.file_sink(gr.sizeof_char, 'sync-detect.dat'))
     ### Header demodulation ##############################################
     header_fft           = fft.fft_vcc(self.fft_len, True, (), True)
     chanest              = digital.ofdm_chanest_vcvc(self.sync_word1, self.sync_word2, 1)
     header_constellation = _get_constellation(bps_header)
     header_equalizer     = digital.ofdm_equalizer_simpledfe(
         fft_len,
         header_constellation.base(),
         occupied_carriers,
         pilot_carriers,
         pilot_symbols,
         symbols_skipped=0,
     )
     header_eq = digital.ofdm_frame_equalizer_vcvc(
             header_equalizer.base(),
             cp_len,
             self.frame_length_tag_key,
             True,
             1 # Header is 1 symbol long
     )
     header_serializer = digital.ofdm_serializer_vcc(
             fft_len, occupied_carriers,
             self.frame_length_tag_key
     )
     header_demod     = digital.constellation_decoder_cb(header_constellation.base())
     header_formatter = digital.packet_header_ofdm(
             occupied_carriers, 1,
             packet_length_tag_key,
             frame_length_tag_key,
             packet_num_tag_key,
             bps_header,
             bps_payload,
             scramble_header=scramble_bits
     )
     header_parser = digital.packet_headerparser_b(header_formatter.formatter())
     self.connect(
             (hpd, 0),
             header_fft,
             chanest,
             header_eq,
             header_serializer,
             header_demod,
             header_parser
     )
     self.msg_connect(header_parser, "header_data", hpd, "header_data")
     if debug_log:
         self.connect((chanest, 1),      blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'channel-estimate.dat'))
         self.connect((chanest, 0),      blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'post-hdr-chanest.dat'))
         self.connect((chanest, 0),      blocks.tag_debug(gr.sizeof_gr_complex * fft_len, 'post-hdr-chanest'))
         self.connect(header_eq,         blocks.file_sink(gr.sizeof_gr_complex * fft_len, 'post-hdr-eq.dat'))
         self.connect(header_serializer, blocks.file_sink(gr.sizeof_gr_complex,           'post-hdr-serializer.dat'))
         self.connect(header_descrambler, blocks.file_sink(1,                             'post-hdr-demod.dat'))
     ### Payload demod ####################################################
     payload_fft = fft.fft_vcc(self.fft_len, True, (), True)
     payload_constellation = _get_constellation(bps_payload)
     payload_equalizer = digital.ofdm_equalizer_simpledfe(
             fft_len,
             payload_constellation.base(),
             occupied_carriers,
             pilot_carriers,
             pilot_symbols,
             symbols_skipped=1, # (that was already in the header)
             alpha=0.1
     )
     payload_eq = digital.ofdm_frame_equalizer_vcvc(
             payload_equalizer.base(),
             cp_len,
             self.frame_length_tag_key
     )
     payload_serializer = digital.ofdm_serializer_vcc(
             fft_len, occupied_carriers,
             self.frame_length_tag_key,
             self.packet_length_tag_key,
             1 # Skip 1 symbol (that was already in the header)
     )
     payload_demod = digital.constellation_decoder_cb(payload_constellation.base())
     self.payload_descrambler = digital.additive_scrambler_bb(
         0x8a,
         self.scramble_seed,
         7,
         0, # Don't reset after fixed length
         bits_per_byte=8, # This is after packing
         reset_tag_key=self.packet_length_tag_key
     )
     payload_pack = blocks.repack_bits_bb(bps_payload, 8, self.packet_length_tag_key, True)
     self.crc = digital.crc32_bb(True, self.packet_length_tag_key)
     self.connect(
             (hpd, 1),
             payload_fft,
             payload_eq,
             payload_serializer,
             payload_demod,
             payload_pack,
             self.payload_descrambler,
             self.crc,
             self
     )
     if debug_log:
         self.connect((hpd, 1),           blocks.tag_debug(gr.sizeof_gr_complex*fft_len, 'post-hpd'))
         self.connect(payload_fft,        blocks.file_sink(gr.sizeof_gr_complex*fft_len, 'post-payload-fft.dat'))
         self.connect(payload_eq,         blocks.file_sink(gr.sizeof_gr_complex*fft_len, 'post-payload-eq.dat'))
         self.connect(payload_serializer, blocks.file_sink(gr.sizeof_gr_complex,         'post-payload-serializer.dat'))
         self.connect(payload_demod,      blocks.file_sink(1,                            'post-payload-demod.dat'))
         self.connect(payload_pack,       blocks.file_sink(1,                            'post-payload-pack.dat'))
         self.connect(crc,                blocks.file_sink(1,                            'post-payload-crc.dat'))
Example #53
0
    def __init__(self):
        gr.top_block.__init__(self, "Test Rx Time")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Test Rx Time")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "test_rx_time")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 500e3

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_source_0 = uhd.usrp_source(
        	device_addr="",
        	stream_args=uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_center_freq(400e6, 0)
        self.uhd_usrp_source_0.set_gain(0, 0)
        self.digital_header_payload_demux_0 = digital.header_payload_demux(
        	  5,
        	  1,
        	  0,
        	  "frame_len",
        	  "",
        	  False,
        	  gr.sizeof_gr_complex,
        	  "rx_time",
                  int(samp_rate),
                  (),
            )
        self.blocks_vector_source_x_0 = blocks.vector_source_b((0, 0, 0, 1,) + (0,) * 9999, True, 1, [])
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_gr_complex*1, "Header Info", ""); self.blocks_tag_debug_0.set_display(True)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_message_strobe_0 = blocks.message_strobe(pmt.from_long(100), 10)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.uhd_usrp_source_0, 0), (self.digital_header_payload_demux_0, 0))
        self.connect((self.blocks_vector_source_x_0, 0), (self.digital_header_payload_demux_0, 1))
        self.connect((self.digital_header_payload_demux_0, 0), (self.blocks_tag_debug_0, 0))
        self.connect((self.digital_header_payload_demux_0, 1), (self.blocks_null_sink_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.blocks_message_strobe_0, "strobe", self.digital_header_payload_demux_0, "header_data")
Example #54
0
    def __init__(self):
        gr.top_block.__init__(self, "Ofdm03")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Ofdm03")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "ofdm03")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.timing = timing = 1.0001
        self.samp_rate = samp_rate = 32000
        self.packet_len = packet_len = 50
        self.noise = noise = 0.01
        self.len_tag_key = len_tag_key = "packet_len"
        self.freq = freq = 0.01
        self.fft_len = fft_len = 128

        ##################################################
        # Blocks
        ##################################################
        self._timing_layout = Qt.QVBoxLayout()
        self._timing_tool_bar = Qt.QToolBar(self)
        self._timing_layout.addWidget(self._timing_tool_bar)
        self._timing_tool_bar.addWidget(Qt.QLabel("Timing Offset"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._timing_counter = qwt_counter_pyslot()
        self._timing_counter.setRange(0.999, 1.001, 0.0001)
        self._timing_counter.setNumButtons(2)
        self._timing_counter.setValue(self.timing)
        self._timing_tool_bar.addWidget(self._timing_counter)
        self._timing_counter.valueChanged.connect(self.set_timing)
        self._timing_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._timing_slider.setRange(0.999, 1.001, 0.0001)
        self._timing_slider.setValue(self.timing)
        self._timing_slider.setMinimumWidth(200)
        self._timing_slider.valueChanged.connect(self.set_timing)
        self._timing_layout.addWidget(self._timing_slider)
        self.top_grid_layout.addLayout(self._timing_layout, 2,0,1,1)
        self._noise_layout = Qt.QVBoxLayout()
        self._noise_tool_bar = Qt.QToolBar(self)
        self._noise_layout.addWidget(self._noise_tool_bar)
        self._noise_tool_bar.addWidget(Qt.QLabel("Noise Voltage"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._noise_counter = qwt_counter_pyslot()
        self._noise_counter.setRange(0, 1, 0.01)
        self._noise_counter.setNumButtons(2)
        self._noise_counter.setValue(self.noise)
        self._noise_tool_bar.addWidget(self._noise_counter)
        self._noise_counter.valueChanged.connect(self.set_noise)
        self._noise_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._noise_slider.setRange(0, 1, 0.01)
        self._noise_slider.setValue(self.noise)
        self._noise_slider.setMinimumWidth(200)
        self._noise_slider.valueChanged.connect(self.set_noise)
        self._noise_layout.addWidget(self._noise_slider)
        self.top_grid_layout.addLayout(self._noise_layout, 1,0,1,1)
        self._freq_layout = Qt.QVBoxLayout()
        self._freq_tool_bar = Qt.QToolBar(self)
        self._freq_layout.addWidget(self._freq_tool_bar)
        self._freq_tool_bar.addWidget(Qt.QLabel("Frequency Offset"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._freq_counter = qwt_counter_pyslot()
        self._freq_counter.setRange(-1, 1, 0.01)
        self._freq_counter.setNumButtons(2)
        self._freq_counter.setValue(self.freq)
        self._freq_tool_bar.addWidget(self._freq_counter)
        self._freq_counter.valueChanged.connect(self.set_freq)
        self._freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._freq_slider.setRange(-1, 1, 0.01)
        self._freq_slider.setValue(self.freq)
        self._freq_slider.setMinimumWidth(200)
        self._freq_slider.valueChanged.connect(self.set_freq)
        self._freq_layout.addWidget(self._freq_slider)
        self.top_grid_layout.addLayout(self._freq_layout, 1,1,1,1)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
                1 #number of inputs
        )
        self.qtgui_waterfall_sink_x_0.set_update_time(0.10)
        self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 0,1,1,1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-80, 10)
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,1,1)
        self.digital_ofdm_tx_0 = digital.ofdm_tx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  packet_length_tag_key=len_tag_key,
        	  bps_header=1,
        	  bps_payload=2,
        	  rolloff=0,
        	  debug_log=False,
        	  scramble_bits=False
        	 )
        self.digital_ofdm_rx_0 = digital.ofdm_rx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  frame_length_tag_key='frame_'+"rx_len",
        	  packet_length_tag_key="rx_len",
        	  bps_header=1,
        	  bps_payload=2,
        	  debug_log=False,
        	  scramble_bits=False
        	 )
        self.channels_selective_fading_model_0 = channels.selective_fading_model( 8, 10.0/samp_rate, False, 4.0, 0, (-0.0025, -0.00125, 0.0, 0.00125, 0.0025, 0.00375, 0.005, 0.00625, 0.0075, 0.00875, 0.01, 0.01125, 0.0125, 0.015, 0.01625, 0.0175, 0.01875, 0.02, 0.02125, 0.0225, 0.02375, 0.025, 0.0275, 0.02875, 0.03, 0.03125, 0.0325, 0.03375, 0.035, 0.03625, 0.0375, 0.03875, 0.04, 0.04125, 0.0425, 0.04375, 0.045, 0.04625, 0.0475, 0.05125, 0.0525, 0.055, 0.05625, 0.0575, 0.06, 0.06375, 0.065, 0.06625, 0.0675, 0.06875, 0.0725, 0.08, 0.08125, 0.085, 0.08625, 0.0875, 0.08875, 0.09125, 0.0925, 0.09375, 0.095, 0.09875, 0.1, 0.1075, 0.10875, 0.11, 0.11125, 0.13125, 0.1325), (0.16529889, 0.46954084, 0.58274825, 0.24561255, 0.50459457, 0.69767633, 1.0, 0.77724474, 0.48675226, 0.46954084, 0.21267289, 0.19090106, 0.31600413, 0.45293801, 0.8057353, 0.64920938, 0.50459457, 0.1978987, 0.35204369, 0.54226525, 0.31600413, 0.15945397, 0.2204686, 0.35204369, 0.37832563, 0.37832563, 0.36494815, 0.2204686, 0.17763933, 0.45293801, 0.52309091, 0.52309091, 0.46954084, 0.35204369, 0.40656966, 0.25461568, 0.23692776, 0.32758753, 0.1978987, 0.21267289, 0.2204686, 0.19090106, 0.24561255, 0.17135806, 0.21267289, 0.16529889, 0.2204686, 0.30483032, 0.33959553, 0.18415085, 0.18415085, 0.22855006, 0.2940516, 0.19090106, 0.17135806, 0.18415085, 0.1978987, 0.17763933, 0.15945397, 0.26394884, 0.24561255, 0.21267289, 0.19090106, 0.17763933, 0.2204686, 0.21267289, 0.17135806, 0.17135806, 0.16529889), 8 )
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=noise,
        	frequency_offset=freq,
        	epsilon=timing,
        	taps=(1.0, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "", ""); self.blocks_tag_debug_0.set_display(True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, len_tag_key)
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 1000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.digital_ofdm_rx_0, 0), (self.blocks_tag_debug_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.digital_ofdm_tx_0, 0))
        self.connect((self.digital_ofdm_tx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.channels_selective_fading_model_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.digital_ofdm_rx_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.channels_selective_fading_model_0, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_stream_to_tagged_stream_0, 0))
Example #55
0
 def __init__(self,len_tag_key, samp_rate, enable_crc):
     gr.hier_block2.__init__(self,
         "frame_decoder",
         gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
         gr.io_signature(1, 1, gr.sizeof_char)) # Output signature
         
     self.len_tag_key = len_tag_key
     self.samp_rate = samp_rate
     
     # Set correlator. FIXME Modifiable access code
     self.digital_correlate_access_code_tag_bb_0 \
         = digital.correlate_access_code_tag_bb(
         "1010110011011101101001001110001011110010100011000010000011111100",
          0, "access")
     
     self.digital_header_payload_demux_0 = digital.header_payload_demux(
 	  32,           # header size
 	  1,            # bits per symbol
 	  0,            # guard interval
 	  len_tag_key, # length tag key
 	  "access",     # trigger tag key
 	  False,        # no idea
 	  gr.sizeof_char, # item format
 	  "rx_time",    # timing tag key (irrelevant)
           samp_rate, # sample rate
           (""),     # special tag keys
     )
     
     self.digital_packet_headerparser_b_default_0  \
         = digital.packet_headerparser_b(32, len_tag_key)
     
     self.blocks_repack_bits_bb_0  \
         = blocks.repack_bits_bb(1, 8, len_tag_key, 
                                 False, gr.GR_MSB_FIRST)
     if enable_crc:
         self.digital_crc32_bb_0  \
             = digital.crc32_bb(True, len_tag_key, True)
     
     # Debug
     self.tag_debug_correlator = blocks.tag_debug(gr.sizeof_char*1, 
                                 "Access code found.", "access");
     #self.tag_debug_header = blocks.tag_debug(gr.sizeof_char*1, 
     #                            "Header correctly obtained", len_tag_key);
     self.tag_debug_packet = blocks.tag_debug(gr.sizeof_char*1, 
                                 "Packet correctly obtained.", len_tag_key);
     
     # Debug Message after the header was found 
     #self.blocks_message_debug_0 = blocks.message_debug()
     #self.blocks_tagged_stream_to_pdu_0 \
     #    = blocks.tagged_stream_to_pdu(blocks.byte_t, len_tag_key)
     
     # PDU Tag Multiplier
     self.multiplay_length = orcatun.multiply_length_pdu(len_tag_key)
     
     ##################################################
     # Connections
     ##################################################
     
     # Correlator to Header/Payload Demux
     # Correlator triggers the HPD with stream tags
     self.connect((self.digital_correlate_access_code_tag_bb_0, 0), 
                  (self.digital_header_payload_demux_0, 0))
     
     self.connect((self.digital_correlate_access_code_tag_bb_0, 0),
                  (self.tag_debug_correlator,0))
     
     # HPD to Header Parser
     # Extracts the information from the header...
     self.connect((self.digital_header_payload_demux_0, 0), 
                  (self.digital_packet_headerparser_b_default_0, 0))
     
     # ... and pass it back to the HPD
     #self.msg_connect((self.digital_packet_headerparser_b_default_0, 
     #                  'header_data'), 
     #                 (self.digital_header_payload_demux_0, 
     #                  'header_data'))
     self.msg_connect((self.digital_packet_headerparser_b_default_0,
                       'header_data'),
                      (self.multiplay_length, 'in'))
     self.msg_connect((self.multiplay_length, 'out'),
                      (self.digital_header_payload_demux_0, 
                       'header_data'))
     
     
     # HPD payload to Repacker
     self.connect((self.digital_header_payload_demux_0, 1), 
                  (self.blocks_repack_bits_bb_0, 0))
     
     # Repacker to Stream CRC32
     # to check the CRC
     if enable_crc:
         self.connect((self.blocks_repack_bits_bb_0, 0), 
                      (self.digital_crc32_bb_0, 0))
     
     
     # Connect input and output
     self.connect((self,0), (self.digital_correlate_access_code_tag_bb_0, 0))
     if enable_crc:
         self.connect((self.digital_crc32_bb_0, 0), (self,0))
     else:
         self.connect((self.blocks_repack_bits_bb_0, 0), (self,0))
     
     
     # Debug
     if enable_crc:
         self.connect((self.digital_crc32_bb_0, 0), (self.tag_debug_packet, 0))
Example #56
0
    def __init__(self):
        gr.top_block.__init__(self, "Ofdm Rx")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Ofdm Rx")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "ofdm_rx")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.tune_offset = tune_offset = 500e3
        self.samp_rate = samp_rate = 500000
        self.len_tag_key = len_tag_key = "packet_len"
        self.fft_len = fft_len = 128
        self.decimation = decimation = 4

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	1024, #size
        	samp_rate, #samp_rate
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)
        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_TAG, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "rx_len")
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
        self.osmosdr_source_0.set_sample_rate(samp_rate*decimation)
        self.osmosdr_source_0.set_center_freq(400e6-tune_offset, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(0, 0)
        self.osmosdr_source_0.set_gain(10, 0)
        self.osmosdr_source_0.set_if_gain(20, 0)
        self.osmosdr_source_0.set_bb_gain(20, 0)
        self.osmosdr_source_0.set_antenna("", 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)
          
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(decimation, (firdes.low_pass(1.0, samp_rate*decimation, 300e3, 100e3)), tune_offset, samp_rate*decimation)
        self.digital_ofdm_rx_0 = digital.ofdm_rx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  frame_length_tag_key='frame_'+"rx_len",
        	  packet_length_tag_key="rx_len",
        	  bps_header=1,
        	  bps_payload=2,
        	  debug_log=False,
        	  scramble_bits=True
        	 )
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "Rx Packets", ""); self.blocks_tag_debug_0.set_display(True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_uchar_to_float_0, 0), (self.qtgui_time_sink_x_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.digital_ofdm_rx_0, 0))
        self.connect((self.digital_ofdm_rx_0, 0), (self.blocks_uchar_to_float_0, 0))
        self.connect((self.digital_ofdm_rx_0, 0), (self.blocks_tag_debug_0, 0))
        self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
Example #57
0
    def __init__(self):
        gr.top_block.__init__(self, "Ofdm00")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Ofdm00")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "ofdm00")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 100000
        self.packet_len = packet_len = 50
        self.len_tag_key = len_tag_key = "packet_len"
        self.fft_len = fft_len = 128

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-80, 10)
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self.digital_ofdm_tx_0 = digital.ofdm_tx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  packet_length_tag_key=len_tag_key,
        	  bps_header=1,
        	  bps_payload=2,
        	  rolloff=0,
        	  debug_log=False,
        	  scramble_bits=False
        	 )
        self.digital_ofdm_rx_0 = digital.ofdm_rx(
        	  fft_len=fft_len, cp_len=fft_len/4,
        	  frame_length_tag_key='frame_'+"rx_len",
        	  packet_length_tag_key="rx_len",
        	  bps_header=1,
        	  bps_payload=2,
        	  debug_log=False,
        	  scramble_bits=False
        	 )
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "", ""); self.blocks_tag_debug_0.set_display(True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, len_tag_key)
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 1000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.digital_ofdm_tx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.digital_ofdm_tx_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.digital_ofdm_rx_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.digital_ofdm_rx_0, 0), (self.blocks_tag_debug_0, 0))
Example #58
0
    def __init__(
        self, ipp1="127.0.0.1", ipp2="127.0.0.1", ipp3="127.0.0.1", ipp4="127.0.0.1", iptx="127.0.0.1", samp_rate=1000
    ):
        gr.top_block.__init__(self, "OFDM Rx")

        ##################################################
        # Parameters
        ##################################################
        self.ipp1 = ipp1
        self.ipp2 = ipp2
        self.ipp3 = ipp3
        self.ipp4 = ipp4
        self.iptx = iptx
        self.samp_rate = samp_rate

        ##################################################
        # Variables
        ##################################################
        self.pilot_symbols = pilot_symbols = ((1, 1, 1, -1),)
        self.pilot_carriers = pilot_carriers = ((-21, -7, 7, 21),)
        self.payload_mod = payload_mod = digital.constellation_qpsk()
        self.packet_length_tag_key = packet_length_tag_key = "packet_len"
        self.occupied_carriers = occupied_carriers = (
            range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),
        )
        self.length_tag_key = length_tag_key = "frame_len"
        self.header_mod = header_mod = digital.constellation_bpsk()
        self.fft_len = fft_len = 64
        self.sync_word2 = sync_word2 = [
            0j,
            0j,
            0j,
            0j,
            0j,
            0j,
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            0j,
            (1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            (-1 + 0j),
            0j,
            0j,
            0j,
            0j,
            0j,
        ]
        self.sync_word1 = sync_word1 = [
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
        ]
        self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_simpledfe(
            fft_len, payload_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols, 1
        )
        self.packet_len = packet_len = 96
        self.header_formatter = header_formatter = digital.packet_header_ofdm(
            occupied_carriers,
            n_syms=1,
            len_tag_key=packet_length_tag_key,
            frame_len_tag_key=length_tag_key,
            bits_per_header_sym=header_mod.bits_per_symbol(),
            bits_per_payload_sym=payload_mod.bits_per_symbol(),
            scramble_header=False,
        )
        self.header_equalizer = header_equalizer = digital.ofdm_equalizer_simpledfe(
            fft_len, header_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols
        )

        ##################################################
        # Blocks
        ##################################################
        self.zeromq_push_sink_0_0_1_0_0 = zeromq.push_sink(gr.sizeof_char, 1, "tcp://" + ipp3 + ":55530", 100, True)
        self.zeromq_push_sink_0_0_1_0 = zeromq.push_sink(
            gr.sizeof_gr_complex, 64, "tcp://" + ipp2 + ":55521", 100, True
        )
        self.zeromq_push_sink_0_0_1 = zeromq.push_sink(gr.sizeof_gr_complex, 64, "tcp://" + ipp2 + ":55520", 100, True)
        self.zeromq_push_sink_0_0_0 = zeromq.push_sink(gr.sizeof_char, 1, "tcp://" + ipp1 + ":55511", 100, True)
        self.zeromq_push_sink_0_0 = zeromq.push_sink(gr.sizeof_gr_complex, 1, "tcp://" + ipp1 + ":55510", 100, True)
        self.zeromq_push_sink_0 = zeromq.push_sink(gr.sizeof_gr_complex, 1, "tcp://" + iptx + ":55500", 100, True)
        self.zeromq_pull_source_0_0_0_0_0_0 = zeromq.pull_source(
            gr.sizeof_gr_complex, 64, "tcp://" + ipp2 + ":55521", 100, True
        )
        self.zeromq_pull_source_0_0_0_0_0 = zeromq.pull_source(
            gr.sizeof_gr_complex, 64, "tcp://" + ipp2 + ":55520", 100, True
        )
        self.zeromq_pull_source_0_0_0_0 = zeromq.pull_source(gr.sizeof_char, 1, "tcp://" + ipp3 + ":55530", 100, True)
        self.zeromq_pull_source_0_0_0 = zeromq.pull_source(gr.sizeof_char, 1, "tcp://" + ipp1 + ":55511", 100, True)
        self.zeromq_pull_source_0_0 = zeromq.pull_source(gr.sizeof_gr_complex, 1, "tcp://" + ipp1 + ":55510", 100, True)
        self.zeromq_pull_source_0 = zeromq.pull_source(gr.sizeof_gr_complex, 1, "tcp://" + iptx + ":55500", 100, True)
        self.my_random_source_limit_rate_0 = my.random_source_limit_rate(1000)
        self.my_number_sync_timestamp_0 = my.number_sync_timestamp()
        self.fft_vxx_1 = fft.fft_vcc(fft_len, True, (), True, 1)
        self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (()), True, 1)
        self.digital_packet_headerparser_b_0 = digital.packet_headerparser_b(header_formatter.base())
        self.digital_ofdm_tx_0 = digital.ofdm_tx(
            fft_len=fft_len,
            cp_len=fft_len / 4,
            packet_length_tag_key=packet_length_tag_key,
            occupied_carriers=occupied_carriers,
            pilot_carriers=pilot_carriers,
            pilot_symbols=pilot_symbols,
            sync_word1=sync_word1,
            sync_word2=sync_word2,
            bps_header=1,
            bps_payload=2,
            rolloff=0,
            debug_log=True,
            scramble_bits=False,
        )
        self.digital_ofdm_sync_sc_cfb_0 = digital.ofdm_sync_sc_cfb(fft_len, fft_len / 4, False)
        self.digital_ofdm_serializer_vcc_payload = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key, packet_length_tag_key, 1, "", True
        )
        self.digital_ofdm_serializer_vcc_header = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key, "", 0, "", True
        )
        self.digital_ofdm_frame_equalizer_vcvc_1 = digital.ofdm_frame_equalizer_vcvc(
            payload_equalizer.base(), fft_len / 4, length_tag_key, True, 0
        )
        self.digital_ofdm_frame_equalizer_vcvc_0 = digital.ofdm_frame_equalizer_vcvc(
            header_equalizer.base(), fft_len / 4, length_tag_key, True, 1
        )
        self.digital_ofdm_chanest_vcvc_0 = digital.ofdm_chanest_vcvc((sync_word1), (sync_word2), 1, 0, 3, False)
        self.digital_header_payload_demux_0 = digital.header_payload_demux(
            3, fft_len, fft_len / 4, length_tag_key, "", True, gr.sizeof_gr_complex, "rx_time", samp_rate, ()
        )
        self.digital_crc32_bb_0 = digital.crc32_bb(True, packet_length_tag_key, True)
        self.digital_constellation_decoder_cb_1 = digital.constellation_decoder_cb(payload_mod.base())
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(header_mod.base())
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=0.1,
            frequency_offset=0 * 1.0 / fft_len,
            epsilon=1.0,
            taps=(1.0,),
            noise_seed=0,
            block_tags=True,
        )
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True)
        self.blocks_tag_debug_1 = blocks.tag_debug(gr.sizeof_char * 1, "Rx Bytes", "")
        self.blocks_tag_debug_1.set_display(True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(
            gr.sizeof_char, 1, packet_len, packet_length_tag_key
        )
        self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(
            payload_mod.bits_per_symbol(), 8, packet_length_tag_key, True, gr.GR_LSB_FIRST
        )
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, fft_len + fft_len / 4)
        self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(-2.0 / fft_len)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect(
            (self.digital_packet_headerparser_b_0, "header_data"), (self.digital_header_payload_demux_0, "header_data")
        )
        self.connect((self.analog_frequency_modulator_fc_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0), (self.zeromq_push_sink_0_0, 0))
        self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_crc32_bb_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.digital_ofdm_tx_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.zeromq_push_sink_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.digital_constellation_decoder_cb_0, 0), (self.zeromq_push_sink_0_0_1_0_0, 0))
        self.connect((self.digital_constellation_decoder_cb_1, 0), (self.blocks_repack_bits_bb_0, 0))
        self.connect((self.digital_crc32_bb_0, 0), (self.blocks_tag_debug_1, 0))
        self.connect((self.digital_crc32_bb_0, 0), (self.my_number_sync_timestamp_0, 0))
        self.connect((self.digital_header_payload_demux_0, 0), (self.zeromq_push_sink_0_0_1, 0))
        self.connect((self.digital_header_payload_demux_0, 1), (self.zeromq_push_sink_0_0_1_0, 0))
        self.connect((self.digital_ofdm_chanest_vcvc_0, 0), (self.digital_ofdm_frame_equalizer_vcvc_0, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_0, 0), (self.digital_ofdm_serializer_vcc_header, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_1, 0), (self.digital_ofdm_serializer_vcc_payload, 0))
        self.connect((self.digital_ofdm_serializer_vcc_header, 0), (self.digital_constellation_decoder_cb_0, 0))
        self.connect((self.digital_ofdm_serializer_vcc_payload, 0), (self.digital_constellation_decoder_cb_1, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 0), (self.analog_frequency_modulator_fc_0, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 1), (self.zeromq_push_sink_0_0_0, 0))
        self.connect((self.digital_ofdm_tx_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.digital_ofdm_chanest_vcvc_0, 0))
        self.connect((self.fft_vxx_1, 0), (self.digital_ofdm_frame_equalizer_vcvc_1, 0))
        self.connect((self.my_random_source_limit_rate_0, 0), (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.zeromq_pull_source_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.zeromq_pull_source_0, 0), (self.digital_ofdm_sync_sc_cfb_0, 0))
        self.connect((self.zeromq_pull_source_0_0, 0), (self.digital_header_payload_demux_0, 0))
        self.connect((self.zeromq_pull_source_0_0_0, 0), (self.digital_header_payload_demux_0, 1))
        self.connect((self.zeromq_pull_source_0_0_0_0, 0), (self.digital_packet_headerparser_b_0, 0))
        self.connect((self.zeromq_pull_source_0_0_0_0_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.zeromq_pull_source_0_0_0_0_0_0, 0), (self.fft_vxx_1, 0))
Example #59
0
    def test_001(self):
        N = 1000
	outfile = "test_out.dat"

        detached = False
        samp_rate = 200000
        key = pmt.intern("samp_rate")
        val = pmt.from_double(samp_rate)
        extras = pmt.make_dict()
        extras = pmt.dict_add(extras, key, val)
        extras_str = pmt.serialize_str(extras)

        data = sig_source_c(samp_rate, 1000, 1, N)
        src  = blocks.vector_source_c(data)
        fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile,
                                     samp_rate, 1,
                                     blocks.GR_FILE_FLOAT, True,
                                     1000000, extras_str, detached)
        fsnk.set_unbuffered(True)

	self.tb.connect(src, fsnk)
	self.tb.run()
        fsnk.close()

        handle = open(outfile, "rb")
        header_str = handle.read(parse_file_metadata.HEADER_LENGTH)
        if(len(header_str) == 0):
            self.assertFalse()

        try:
            header = pmt.deserialize_str(header_str)
        except RuntimeError:
            self.assertFalse()

        info = parse_file_metadata.parse_header(header, False)

        extra_str = handle.read(info["extra_len"])
        self.assertEqual(len(extra_str) > 0, True)

        handle.close()

        try:
            extra = pmt.deserialize_str(extra_str)
        except RuntimeError:
            self.assertFalse()

        extra_info = parse_file_metadata.parse_extra_dict(extra, info, False)

        self.assertEqual(info['rx_rate'], samp_rate)
        self.assertEqual(pmt.to_double(extra_info['samp_rate']), samp_rate)


        # Test file metadata source
        src.rewind()
        fsrc = blocks.file_meta_source(outfile, False)
        vsnk = blocks.vector_sink_c()
        tsnk = blocks.tag_debug(gr.sizeof_gr_complex, "QA")
        ssnk = blocks.vector_sink_c()
        self.tb.disconnect(src, fsnk)
        self.tb.connect(fsrc, vsnk)
        self.tb.connect(fsrc, tsnk)
        self.tb.connect(src, ssnk)
        self.tb.run()

        fsrc.close() 
        # Test to make sure tags with 'samp_rate' and 'rx_rate' keys
        # were generated and received correctly.
        tags = tsnk.current_tags()
        for t in tags:
            if(pmt.eq(t.key, pmt.intern("samp_rate"))):
                self.assertEqual(pmt.to_double(t.value), samp_rate)
            elif(pmt.eq(t.key, pmt.intern("rx_rate"))):
                self.assertEqual(pmt.to_double(t.value), samp_rate)

        # Test that the data portion was extracted and received correctly.
        self.assertComplexTuplesAlmostEqual(vsnk.data(), ssnk.data(), 5)

	os.remove(outfile)