4 Transmit 2 signals, one out each daughterboard.
6 Outputs SSB (USB) signals on side A and side B at frequencies
7 specified on command line.
10 Side B is 350 + 440 Hz tones.
13 from gnuradio import gr
14 from gnuradio.eng_notation import num_to_str, str_to_num
15 from gnuradio import usrp
16 from gnuradio import audio
17 from gnuradio import blks
18 from gnuradio.eng_option import eng_option
19 from optparse import OptionParser
25 class example_signal_0(gr.hier_block):
29 def __init__(self, fg, sample_rate):
31 src = gr.sig_source_c (sample_rate, # sample rate
32 gr.GR_SIN_WAVE, # waveform type
37 gr.hier_block.__init__(self, fg, None, src)
40 class example_signal_1(gr.hier_block):
42 North American dial tone (350 + 440 Hz).
44 def __init__(self, fg, sample_rate):
46 src0 = gr.sig_source_c (sample_rate, # sample rate
47 gr.GR_SIN_WAVE, # waveform type
52 src1 = gr.sig_source_c (sample_rate, # sample rate
53 gr.GR_SIN_WAVE, # waveform type
58 fg.connect(src0, (sum, 0))
59 fg.connect(src1, (sum, 1))
61 gr.hier_block.__init__(self, fg, None, sum)
65 class my_graph(gr.flow_graph):
68 gr.flow_graph.__init__ (self)
70 usage="%prog: [options] side-A-tx-freq side-B-tx-freq"
71 parser = OptionParser (option_class=eng_option, usage=usage)
72 (options, args) = parser.parse_args ()
78 freq0 = str_to_num(args[0])
79 freq1 = str_to_num(args[1])
81 # ----------------------------------------------------------------
82 # Set up USRP to transmit on both daughterboards
84 self.u = usrp.sink_c(nchan=2) # say we want two channels
86 self.dac_rate = self.u.dac_rate() # 128 MS/s
87 self.usrp_interp = 400
88 self.u.set_interp_rate(self.usrp_interp)
89 self.usrp_rate = self.dac_rate / self.usrp_interp # 320 kS/s
91 # we're using both daughterboard slots, thus subdev is a 2-tuple
92 self.subdev = (self.u.db[0][0], self.u.db[1][0])
93 print "Using TX d'board %s" % (self.subdev[0].side_and_name(),)
94 print "Using TX d'board %s" % (self.subdev[1].side_and_name(),)
96 # set up the Tx mux so that
97 # channel 0 goes to Slot A I&Q and channel 1 to Slot B I&Q
98 self.u.set_mux(0xba98)
100 self.subdev[0].set_gain(self.subdev[0].gain_range()[1]) # set max Tx gain
101 self.subdev[1].set_gain(self.subdev[1].gain_range()[1]) # set max Tx gain
103 self.set_freq(0, freq0)
104 self.set_freq(1, freq1)
105 self.subdev[0].set_enable(True) # enable transmitter
106 self.subdev[1].set_enable(True) # enable transmitter
108 # ----------------------------------------------------------------
109 # build two signal sources, interleave them, amplify and connect them to usrp
111 sig0 = example_signal_0(self, self.usrp_rate)
112 sig1 = example_signal_1(self, self.usrp_rate)
114 intl = gr.interleave(gr.sizeof_gr_complex)
115 self.connect(sig0, (intl, 0))
116 self.connect(sig1, (intl, 1))
120 ifamp = gr.multiply_const_cc(if_gain)
123 self.connect(intl, ifamp, self.u)
126 def set_freq(self, side, target_freq):
128 Set the center frequency we're interested in.
130 @param side: 0 = side A, 1 = side B
131 @param target_freq: frequency in Hz
134 Tuning is a two step process. First we ask the front-end to
135 tune as close to the desired frequency as it can. Then we use
136 the result of that operation and our target_frequency to
137 determine the value for the digital up converter.
140 print "Tuning side %s to %sHz" % (("A", "B")[side], num_to_str(target_freq))
141 r = self.u.tune(self.subdev[side]._which, self.subdev[side], target_freq)
143 print " r.baseband_freq =", num_to_str(r.baseband_freq)
144 print " r.dxc_freq =", num_to_str(r.dxc_freq)
145 print " r.residual_freq =", num_to_str(r.residual_freq)
146 print " r.inverted =", r.inverted
156 if __name__ == '__main__':
159 except KeyboardInterrupt: