1 | # |
---|
2 | # Copyright 2009 Free Software Foundation, Inc. |
---|
3 | # |
---|
4 | # This file is part of GNU Radio |
---|
5 | # |
---|
6 | # GNU Radio is free software; you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation; either version 3, or (at your option) |
---|
9 | # any later version. |
---|
10 | # |
---|
11 | # GNU Radio is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with GNU Radio; see the file COPYING. If not, write to |
---|
18 | # the Free Software Foundation, Inc., 51 Franklin Street, |
---|
19 | # Boston, MA 02110-1301, USA. |
---|
20 | # |
---|
21 | |
---|
22 | _parser_to_groups_dict = dict() |
---|
23 | class _parser_groups(object): |
---|
24 | def __init__(self, parser): |
---|
25 | self.usrpx_grp = parser.add_option_group("General USRP Options") |
---|
26 | self.usrp1_grp = parser.add_option_group("USRP1 Specific Options") |
---|
27 | self.usrp1exp_grp = parser.add_option_group("USRP1 Expert Options") |
---|
28 | self.usrp2_grp = parser.add_option_group("USRP2 Specific Options") |
---|
29 | |
---|
30 | import generic_usrp |
---|
31 | |
---|
32 | def _add_options(parser): |
---|
33 | """ |
---|
34 | Add options to manually choose between usrp or usrp2. |
---|
35 | Add options for usb. Add options common to source and sink. |
---|
36 | @param parser: instance of OptionParser |
---|
37 | @return the parser group |
---|
38 | """ |
---|
39 | #cache groups so they dont get added twice on tranceiver apps |
---|
40 | if not _parser_to_groups_dict.has_key(parser): _parser_to_groups_dict[parser] = _parser_groups(parser) |
---|
41 | pg = _parser_to_groups_dict[parser] |
---|
42 | #pick usrp or usrp2 |
---|
43 | pg.usrpx_grp.add_option("-u", "--usrpx", type="string", default=None, |
---|
44 | help="specify which usrp model: 1 for USRP, 2 for USRP2 [default=auto]") |
---|
45 | #fast usb options |
---|
46 | pg.usrp1exp_grp.add_option("-B", "--fusb-block-size", type="int", default=0, |
---|
47 | help="specify fast usb block size [default=%default]") |
---|
48 | pg.usrp1exp_grp.add_option("-N", "--fusb-nblocks", type="int", default=0, |
---|
49 | help="specify number of fast usb blocks [default=%default]") |
---|
50 | #lo offset |
---|
51 | pg.usrpx_grp.add_option("--lo-offset", type="eng_float", default=None, |
---|
52 | help="set LO Offset in Hz [default=automatic].") |
---|
53 | #usrp options |
---|
54 | pg.usrp1_grp.add_option("-w", "--which", type="int", default=0, |
---|
55 | help="select USRP board [default=%default]") |
---|
56 | #usrp2 options |
---|
57 | pg.usrp2_grp.add_option("-e", "--interface", type="string", default="eth0", |
---|
58 | help="Use USRP2 at specified Ethernet interface [default=%default]") |
---|
59 | pg.usrp2_grp.add_option("-a", "--mac-addr", type="string", default="", |
---|
60 | help="Use USRP2 at specified MAC address [default=None]") |
---|
61 | return pg |
---|
62 | |
---|
63 | def add_rx_options(parser): |
---|
64 | """ |
---|
65 | Add receive specific usrp options. |
---|
66 | @param parser: instance of OptionParser |
---|
67 | """ |
---|
68 | pg = _add_options(parser) |
---|
69 | pg.usrp1_grp.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, |
---|
70 | help="select USRP Rx side A or B") |
---|
71 | pg.usrpx_grp.add_option("--rx-gain", type="eng_float", default=None, metavar="GAIN", |
---|
72 | help="set receiver gain in dB [default=midpoint]. See also --show-rx-gain-range") |
---|
73 | pg.usrpx_grp.add_option("--show-rx-gain-range", action="store_true", default=False, |
---|
74 | help="print min and max Rx gain available on selected daughterboard") |
---|
75 | pg.usrpx_grp.add_option("-d", "--decim", type="intx", default=None, |
---|
76 | help="set fpga decimation rate to DECIM [default=%default]") |
---|
77 | |
---|
78 | def create_usrp_source(options): |
---|
79 | u = generic_usrp.generic_usrp_source_c( |
---|
80 | usrpx=options.usrpx, |
---|
81 | which=options.which, |
---|
82 | subdev_spec=options.rx_subdev_spec, |
---|
83 | interface=options.interface, |
---|
84 | mac_addr=options.mac_addr, |
---|
85 | fusb_block_size=options.fusb_block_size, |
---|
86 | fusb_nblocks=options.fusb_nblocks, |
---|
87 | lo_offset=options.lo_offset, |
---|
88 | gain=options.rx_gain, |
---|
89 | ) |
---|
90 | if options.show_rx_gain_range: |
---|
91 | print "Rx Gain Range: minimum = %g, maximum = %g, step size = %g"%tuple(u.gain_range()) |
---|
92 | return u |
---|
93 | |
---|
94 | def add_tx_options(parser): |
---|
95 | """ |
---|
96 | Add transmit specific usrp options. |
---|
97 | @param parser: instance of OptionParser |
---|
98 | """ |
---|
99 | pg = _add_options(parser) |
---|
100 | pg.usrp1_grp.add_option("-T", "--tx-subdev-spec", type="subdev", default=None, |
---|
101 | help="select USRP Rx side A or B") |
---|
102 | pg.usrpx_grp.add_option("--tx-gain", type="eng_float", default=None, metavar="GAIN", |
---|
103 | help="set transmitter gain in dB [default=midpoint]. See also --show-tx-gain-range") |
---|
104 | pg.usrpx_grp.add_option("--show-tx-gain-range", action="store_true", default=False, |
---|
105 | help="print min and max Tx gain available on selected daughterboard") |
---|
106 | pg.usrpx_grp.add_option("-i", "--interp", type="intx", default=None, |
---|
107 | help="set fpga interpolation rate to INTERP [default=%default]") |
---|
108 | |
---|
109 | def create_usrp_sink(options): |
---|
110 | u = generic_usrp.generic_usrp_sink_c( |
---|
111 | usrpx=options.usrpx, |
---|
112 | which=options.which, |
---|
113 | subdev_spec=options.tx_subdev_spec, |
---|
114 | interface=options.interface, |
---|
115 | mac_addr=options.mac_addr, |
---|
116 | fusb_block_size=options.fusb_block_size, |
---|
117 | fusb_nblocks=options.fusb_nblocks, |
---|
118 | lo_offset=options.lo_offset, |
---|
119 | gain=options.tx_gain, |
---|
120 | ) |
---|
121 | if options.show_tx_gain_range: |
---|
122 | print "Tx Gain Range: minimum = %g, maximum = %g, step size = %g"%tuple(u.gain_range()) |
---|
123 | return u |
---|