3 # Copyright 2005,2006,2007 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
24 Transmit 2 signals, one out each daughterboard.
26 Outputs SSB (USB) signals on side A and side B at frequencies
27 specified on command line.
29 Side A is 600 Hz tone.
30 Side B is 350 + 440 Hz tones.
33 from gnuradio import gr
34 from gnuradio.eng_notation import num_to_str, str_to_num
35 from gnuradio import usrp
36 from gnuradio import audio
37 from gnuradio import blks2
38 from gnuradio.eng_option import eng_option
39 from optparse import OptionParser
40 from usrpm import usrp_dbid
45 class example_signal_0(gr.hier_block2):
49 def __init__(self, sample_rate):
50 gr.hier_block2.__init__(self, "example_signal_0",
51 gr.io_signature(0, 0, 0), # Input signature
52 gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
54 src = gr.sig_source_c (sample_rate, # sample rate
55 gr.GR_SIN_WAVE, # waveform type
60 self.connect(src, self)
63 class example_signal_1(gr.hier_block2):
65 North American dial tone (350 + 440 Hz).
67 def __init__(self, sample_rate):
68 gr.hier_block2.__init__(self, "example_signal_1",
69 gr.io_signature(0, 0, 0), # Input signature
70 gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
72 src0 = gr.sig_source_c (sample_rate, # sample rate
73 gr.GR_SIN_WAVE, # waveform type
78 src1 = gr.sig_source_c (sample_rate, # sample rate
79 gr.GR_SIN_WAVE, # waveform type
84 self.connect(src0, (sum, 0))
85 self.connect(src1, (sum, 1))
86 self.connect(sum, self)
88 class my_top_block(gr.top_block):
91 gr.top_block.__init__(self)
93 usage="%prog: [options] side-A-tx-freq side-B-tx-freq"
94 parser = OptionParser (option_class=eng_option, usage=usage)
95 (options, args) = parser.parse_args ()
101 freq0 = str_to_num(args[0])
102 freq1 = str_to_num(args[1])
104 # ----------------------------------------------------------------
105 # Set up USRP to transmit on both daughterboards
107 self.u = usrp.sink_c(nchan=2) # say we want two channels
109 self.dac_rate = self.u.dac_rate() # 128 MS/s
110 self.usrp_interp = 400
111 self.u.set_interp_rate(self.usrp_interp)
112 self.usrp_rate = self.dac_rate / self.usrp_interp # 320 kS/s
114 # we're using both daughterboard slots, thus subdev is a 2-tuple
115 self.subdev = (self.u.db(0, 0), self.u.db(1, 0))
116 print "Using TX d'board %s" % (self.subdev[0].side_and_name(),)
117 print "Using TX d'board %s" % (self.subdev[1].side_and_name(),)
119 # set up the Tx mux so that
120 # channel 0 goes to Slot A I&Q and channel 1 to Slot B I&Q
121 self.u.set_mux(0xba98)
123 self.subdev[0].set_gain(self.subdev[0].gain_range()[1]) # set max Tx gain
124 self.subdev[1].set_gain(self.subdev[1].gain_range()[1]) # set max Tx gain
126 self.set_freq(0, freq0)
127 self.set_freq(1, freq1)
128 self.subdev[0].set_enable(True) # enable transmitter
129 self.subdev[1].set_enable(True) # enable transmitter
131 # ----------------------------------------------------------------
132 # build two signal sources, interleave them, amplify and connect them to usrp
134 sig0 = example_signal_0(self.usrp_rate)
135 sig1 = example_signal_1(self.usrp_rate)
137 intl = gr.interleave(gr.sizeof_gr_complex)
138 self.connect(sig0, (intl, 0))
139 self.connect(sig1, (intl, 1))
143 ifamp = gr.multiply_const_cc(if_gain)
146 self.connect(intl, ifamp, self.u)
149 def set_freq(self, side, target_freq):
151 Set the center frequency we're interested in.
153 @param side: 0 = side A, 1 = side B
154 @param target_freq: frequency in Hz
157 Tuning is a two step process. First we ask the front-end to
158 tune as close to the desired frequency as it can. Then we use
159 the result of that operation and our target_frequency to
160 determine the value for the digital up converter.
163 print "Tuning side %s to %sHz" % (("A", "B")[side], num_to_str(target_freq))
164 r = self.u.tune(self.subdev[side].which(), self.subdev[side], target_freq)
166 print " r.baseband_freq =", num_to_str(r.baseband_freq)
167 print " r.dxc_freq =", num_to_str(r.dxc_freq)
168 print " r.residual_freq =", num_to_str(r.residual_freq)
169 print " r.inverted =", r.inverted
179 if __name__ == '__main__':
182 except KeyboardInterrupt: