def __init__(self, filenames, dev_addrs, onebit, iq, noise, mix, gain, fs, fc, unint, sync_pps): gr.top_block.__init__(self) if mix: raise NotImplementedError("TODO: Hilbert remix mode not implemented.") uhd_sinks = [ uhd.usrp_sink(",".join( [addr, "send_frame_size=32768,num_send_frames=128"]), uhd.stream_args( cpu_format="fc32", otwformat="sc8", channels=[0])) for addr in dev_addrs] for sink in uhd_sinks: sink.set_clock_rate(fs*2, uhd.ALL_MBOARDS) sink.set_samp_rate(fs) sink.set_center_freq(fc, 0) sink.set_gain(gain, 0) # TODO Use offset tuning? if sync_pps: sink.set_clock_source("external") # 10 MHz sink.set_time_source("external") # PPS if unint: if noise or onebit or not iq: raise NotImplementedError("TODO: RX channel-interleaved mode only " "supported for noiseless 8-bit complex.") BLOCK_N=16*1024*1024 demux = blocks.vector_to_streams(2, len(uhd_sinks)) self.connect(blocks.file_source(2*len(uhd_sinks)*BLOCK_N, filenames[0], False), blocks.vector_to_stream(2*len(uhd_sinks), BLOCK_N), demux) for ix, sink in enumerate(uhd_sinks): self.connect((demux, ix), blocks.vector_to_stream(1, 2), blocks.interleaved_char_to_complex(), # [-128.0, +127.0] blocks.multiply_const_cc(1.0/1024), # [-0.125, 0.125) # blocks.vector_to_stream(8, 16*1024), sink) else: file_srcs = [blocks.file_source(gr.sizeof_char*1, f, False) for f in filenames] for src, sink in zip(file_srcs, uhd_sinks): if iq: node = blocks.multiply_const_cc(1.0/1024) if onebit: self.connect(src, blocks.unpack_k_bits_bb(8), blocks.char_to_short(), # [0, 1] -> [0, 256] blocks.add_const_ss(-128), # [-128, +128], blocks.interleaved_short_to_complex(), # [ -128.0, +128.0] node) # [-0.125, +0.125] else: self.connect(src, # [-128..127] blocks.interleaved_char_to_complex(), # [-128.0, +127.0] node) # [-0.125, +0.125) else: node = blocks.float_to_complex(1) if onebit: self.connect(src, blocks.unpack_k_bits_bb(8), # [0, 1] -> [-0.125, +0.125] blocks.char_to_float(vlen=1, scale=4), blocks.add_const_vff((-0.125, )), node) else: self.connect(src, # [-128..127] -> [-0.125, +0.125) blocks.char_to_float(vlen=1, scale=1024), node) if noise: combiner = blocks.add_vcc(1) self.connect(node, combiner, sink) self.connect(analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise, -222, 8192), (combiner, 1)) else: self.connect(node, sink) print "Setting clocks..." if sync_pps: time.sleep(1.1) # Ensure there's been an edge. TODO: necessary? last_pps_time = uhd_sinks[0].get_time_last_pps() while last_pps_time == uhd_sinks[0].get_time_last_pps(): time.sleep(0.1) print "Got edge" [sink.set_time_next_pps(uhd.time_spec(round(time.time())+1)) for sink in uhd_sinks] time.sleep(1.0) # Wait for edge to set the clocks else: # No external PPS/10 MHz. Just set each clock and accept some skew. t = time.time() [sink.set_time_now(uhd.time_spec(time.time())) for sink in uhd_sinks] if len(uhd_sinks) > 1: print "Uncabled; loosely synced only. Initial skew ~ %.1f ms" % ( (time.time()-t) * 1000) t_start = uhd.time_spec(time.time() + 1.5) [sink.set_start_time(t_start) for sink in uhd_sinks] print "ready"
def __init__(self, filenames, dev_addrs, dual, onebit, iq, noise, mix, gain, fs, fc, unint, sync_pps): gr.top_block.__init__(self) if mix: raise NotImplementedError("TODO: Hilbert remix mode not implemented.") if dual: channels = [0, 1] else: channels = [0] uhd_sinks = [ uhd.usrp_sink(",".join( [addr, "send_frame_size=32768,num_send_frames=128"]), uhd.stream_args( cpu_format="fc32", otwformat="sc8", channels=channels)) for addr in dev_addrs] for sink in uhd_sinks: a = sink.get_usrp_info() for each in a.keys(): print each + " : " + a.get(each) sink.set_clock_rate(fs, uhd.ALL_MBOARDS) sink.set_samp_rate(fs) sink.set_center_freq(fc, 0) sink.set_gain(gain, 0) if dual: sink.set_center_freq(fc, 1) sink.set_gain(gain, 1) sink.set_subdev_spec("A:B A:A", 0) # TODO Use offset tuning? if sync_pps: sink.set_clock_source("external") # 10 MHz sink.set_time_source("external") # PPS if unint: if noise or onebit or not iq: raise NotImplementedError("TODO: RX channel-interleaved mode only " "supported for noiseless 8-bit complex.") BLOCK_N = 16*1024*1024 demux = blocks.vector_to_streams(2, len(uhd_sinks)) self.connect(blocks.file_source(2*len(uhd_sinks)*BLOCK_N, filenames[0], False), blocks.vector_to_stream(2*len(uhd_sinks), BLOCK_N), demux) for ix, sink in enumerate(uhd_sinks): self.connect((demux, ix), blocks.vector_to_stream(1, 2), blocks.interleaved_char_to_complex(), # [-128.0, +127.0] blocks.multiply_const_cc(1.0/1024), # [-0.125, 0.125) # blocks.vector_to_stream(8, 16*1024), sink) else: for i, filename in enumerate(filenames): src = blocks.file_source(gr.sizeof_char*1, filename, False) if dual: channel = i % 2 sink = uhd_sinks[i/2] else: channel = 0 sink = uhd_sinks[i] if iq: node = blocks.multiply_const_cc(1.0/1024) if onebit: self.connect(src, blocks.unpack_k_bits_bb(8), blocks.char_to_short(), # [0, 1] -> [0, 256] blocks.add_const_ss(-128), # [-128, +128], blocks.interleaved_short_to_complex(), # [ -128.0, +128.0] node) # [-0.125, +0.125] else: self.connect(src, # [-128..127] blocks.interleaved_char_to_complex(), # [-128.0, +127.0] node) # [-0.125, +0.125) else: node = blocks.float_to_complex(1) if onebit: self.connect(src, blocks.unpack_k_bits_bb(8), # [0, 1] -> [-0.125, +0.125] blocks.char_to_float(vlen=1, scale=4), blocks.add_const_vff((-0.125, )), node) else: self.connect(src, # [-128..127] -> [-0.125, +0.125) blocks.char_to_float(vlen=1, scale=1024), node) if noise: combiner = blocks.add_vcc(1) self.connect((node, 0), (combiner, 0), (sink, channel)) self.connect(analog.fastnoise_source_c(analog.GR_GAUSSIAN, noise, -222, 8192), (combiner, 1)) else: self.connect((node, 0), (sink, channel)) print "Setting clocks..." if sync_pps: time.sleep(1.1) # Ensure there's been an edge. TODO: necessary? last_pps_time = uhd_sinks[0].get_time_last_pps() while last_pps_time == uhd_sinks[0].get_time_last_pps(): time.sleep(0.1) print "Got edge" [sink.set_time_next_pps(uhd.time_spec(round(time.time())+1)) for sink in uhd_sinks] time.sleep(1.0) # Wait for edge to set the clocks else: # No external PPS/10 MHz. Just set each clock and accept some skew. t = time.time() [sink.set_time_now(uhd.time_spec(time.time())) for sink in uhd_sinks] if len(uhd_sinks) > 1: print "Uncabled; loosely synced only. Initial skew ~ %.1f ms" % ( (time.time()-t) * 1000) t_start = uhd.time_spec(time.time() + 1.5) [sink.set_start_time(t_start) for sink in uhd_sinks] print "ready"
def test_add_const_ss(self): src_data = [1, 2, 3, 4, 5] expected_result = [6, 7, 8, 9, 10] op = blocks.add_const_ss(5) self.help_ss((src_data,), expected_result, op)
def test_add_const_ss(self): src_data = (1, 2, 3, 4, 5) expected_result = (6, 7, 8, 9, 10) op = blocks.add_const_ss(5) self.help_ss((src_data, ), expected_result, op)
def test_add_const_ss(self): src_data = (1, 2, 3, 4, 5) expected_result = (6, 7, 8, 9, 10) op = blocks.add_const_ss(5) self.help_ss((src_data,), expected_result, op)