diff options
author | Douglas Anderson <danderson@ntia.doc.gov> | 2017-02-12 15:52:19 -0800 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2017-02-26 18:21:22 -0800 |
commit | 9e625c4821f4c63421b3d3747c0c4f358fef6c5f (patch) | |
tree | 41dedbe053417be7314cdce15d64fbbb89db4d8d /gr-uhd | |
parent | e5aabcc6a4a9335f3ef8abf5f89104b626e9364d (diff) |
python3: update non-GRC components to use python2 or python3
Diffstat (limited to 'gr-uhd')
-rw-r--r-- | gr-uhd/apps/uhd_app.py | 20 | ||||
-rw-r--r-- | gr-uhd/apps/uhd_siggen_base.py | 20 | ||||
-rw-r--r-- | gr-uhd/grc/gen_uhd_usrp_blocks.py | 1042 | ||||
-rw-r--r-- | gr-uhd/python/uhd/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-uhd/python/uhd/__init__.py | 21 | ||||
-rw-r--r-- | gr-uhd/python/uhd/qa_uhd.py | 4 |
6 files changed, 559 insertions, 550 deletions
diff --git a/gr-uhd/apps/uhd_app.py b/gr-uhd/apps/uhd_app.py index f9b08a6457..893919337f 100644 --- a/gr-uhd/apps/uhd_app.py +++ b/gr-uhd/apps/uhd_app.py @@ -24,6 +24,8 @@ USRP Helper Module: Common tasks for uhd-based apps. """ from __future__ import print_function +from __future__ import division +from __future__ import unicode_literals import sys import time import argparse @@ -176,17 +178,17 @@ class UHDApp(object): # Set the subdevice spec: args.spec = self.normalize_subdev_sel(args.spec) if args.spec: - for mb_idx in xrange(self.usrp.get_num_mboards()): + for mb_idx in range(self.usrp.get_num_mboards()): if isinstance(args.spec, list): self.usrp.set_subdev_spec(args.spec[mb_idx], mb_idx) else: self.usrp.set_subdev_spec(args.spec, mb_idx) # Set the clock and/or time source: if args.clock_source is not None: - for mb_idx in xrange(self.usrp.get_num_mboards()): + for mb_idx in range(self.usrp.get_num_mboards()): self.usrp.set_clock_source(args.clock_source, mb_idx) if args.time_source is not None: - for mb_idx in xrange(self.usrp.get_num_mboards()): + for mb_idx in range(self.usrp.get_num_mboards()): self.usrp.set_time_source(args.time_source, mb_idx) # Sampling rate: self.usrp.set_samp_rate(args.samp_rate) @@ -246,7 +248,7 @@ class UHDApp(object): self.usrp.set_time_unknown_pps(uhd.time_spec()) cmd_time = self.usrp.get_time_now() + uhd.time_spec(COMMAND_DELAY) try: - for mb_idx in xrange(self.usrp.get_num_mboards()): + for mb_idx in range(self.usrp.get_num_mboards()): self.usrp.set_command_time(cmd_time, mb_idx) command_time_set = True except RuntimeError: @@ -259,7 +261,7 @@ class UHDApp(object): )) exit(1) if command_time_set: - for mb_idx in xrange(self.usrp.get_num_mboards()): + for mb_idx in range(self.usrp.get_num_mboards()): self.usrp.clear_command_time(mb_idx) self.vprint("Syncing channels...".format(prefix=self.prefix)) time.sleep(COMMAND_DELAY) @@ -294,7 +296,7 @@ class UHDApp(object): """ Safely tune all channels to freq. """ - self.vprint("Tuning all channels to {freq} MHz.".format(freq=freq/1e6)) + self.vprint("Tuning all channels to {freq} MHz.".format(freq=freq / 1e6)) # Set frequency (tune request takes lo_offset): if hasattr(self.args, 'lo_offset') and self.args.lo_offset is not None: treq = uhd.tune_request(freq, self.args.lo_offset) @@ -321,7 +323,7 @@ class UHDApp(object): if len(self.channels) > 1 and not skip_sync: cmd_time = self.usrp.get_time_now() + uhd.time_spec(COMMAND_DELAY) try: - for mb_idx in xrange(self.usrp.get_num_mboards()): + for mb_idx in range(self.usrp.get_num_mboards()): self.usrp.set_command_time(cmd_time, mb_idx) command_time_set = True except RuntimeError: @@ -334,12 +336,12 @@ class UHDApp(object): )) exit(1) if command_time_set: - for mb_idx in xrange(self.usrp.get_num_mboards()): + for mb_idx in range(self.usrp.get_num_mboards()): self.usrp.clear_command_time(mb_idx) self.vprint("Syncing channels...".format(prefix=self.prefix)) time.sleep(COMMAND_DELAY) self.freq = self.usrp.get_center_freq(0) - self.vprint("First channel has freq: {freq} MHz.".format(freq=self.freq/1e6)) + self.vprint("First channel has freq: {freq} MHz.".format(freq=self.freq / 1e6)) @staticmethod def setup_argparser( diff --git a/gr-uhd/apps/uhd_siggen_base.py b/gr-uhd/apps/uhd_siggen_base.py index cc699dd145..98dda1084b 100644 --- a/gr-uhd/apps/uhd_siggen_base.py +++ b/gr-uhd/apps/uhd_siggen_base.py @@ -24,6 +24,8 @@ Provide a base flow graph for USRP signal generators. """ from __future__ import print_function +from __future__ import division +from __future__ import unicode_literals import math try: from uhd_app import UHDApp @@ -124,7 +126,7 @@ class USRPSiggen(gr.top_block, pubsub, UHDApp): """ When sampling rate is updated, also update the signal sources. """ - self.vprint("Setting sampling rate to: {rate} Msps".format(rate=samp_rate/1e6)) + self.vprint("Setting sampling rate to: {rate} Msps".format(rate=samp_rate / 1e6)) self.usrp.set_samp_rate(samp_rate) samp_rate = self.usrp.get_samp_rate() if self[TYPE_KEY] in (analog.GR_SIN_WAVE, analog.GR_CONST_WAVE): @@ -137,7 +139,7 @@ class USRPSiggen(gr.top_block, pubsub, UHDApp): self._src2.set_sampling_freq(self[WAVEFORM_FREQ_KEY]*2*math.pi/self[SAMP_RATE_KEY]) else: return True # Waveform not yet set - self.vprint("Set sample rate to: {rate} Msps".format(rate=samp_rate/1e6)) + self.vprint("Set sample rate to: {rate} Msps".format(rate=samp_rate / 1e6)) return True def set_waveform_freq(self, freq): @@ -184,14 +186,14 @@ class USRPSiggen(gr.top_block, pubsub, UHDApp): self._src1 = analog.sig_source_c(self[SAMP_RATE_KEY], analog.GR_SIN_WAVE, self[WAVEFORM_FREQ_KEY], - self[AMPLITUDE_KEY]/2.0, + self[AMPLITUDE_KEY] / 2.0, 0) if self[WAVEFORM2_FREQ_KEY] is None: self[WAVEFORM2_FREQ_KEY] = -self[WAVEFORM_FREQ_KEY] self._src2 = analog.sig_source_c(self[SAMP_RATE_KEY], analog.GR_SIN_WAVE, self[WAVEFORM2_FREQ_KEY], - self[AMPLITUDE_KEY]/2.0, + self[AMPLITUDE_KEY] / 2.0, 0) self._src = blocks.add_cc() self.connect(self._src1, (self._src, 0)) @@ -213,7 +215,7 @@ class USRPSiggen(gr.top_block, pubsub, UHDApp): self.connect(self._src1, self._src2, self._src) else: raise RuntimeError("[UHD-SIGGEN] Unknown waveform waveform_type") - for chan in xrange(len(self.channels)): + for chan in range(len(self.channels)): self.connect(self._src, (self.usrp, chan)) if self.extra_sink is not None: self.connect(self._src, self.extra_sink) @@ -226,7 +228,7 @@ class USRPSiggen(gr.top_block, pubsub, UHDApp): self.vprint("Tone 1: %sHz" % (n2s(self[WAVEFORM_FREQ_KEY]),)) self.vprint("Tone 2: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]),)) elif waveform_type == "sweep": - self.vprint("Sweeping across %sHz to %sHz" % (n2s(-self[WAVEFORM_FREQ_KEY]/2.0), n2s(self[WAVEFORM_FREQ_KEY]/2.0))) + self.vprint("Sweeping across %sHz to %sHz" % (n2s(-self[WAVEFORM_FREQ_KEY] / 2.0), n2s(self[WAVEFORM_FREQ_KEY] / 2.0))) self.vprint("Sweep rate: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]),)) self.vprint("TX amplitude:", self[AMPLITUDE_KEY]) @@ -240,8 +242,8 @@ class USRPSiggen(gr.top_block, pubsub, UHDApp): if self[TYPE_KEY] in (analog.GR_SIN_WAVE, analog.GR_CONST_WAVE, analog.GR_GAUSSIAN, analog.GR_UNIFORM): self._src.set_amplitude(amplitude) elif self[TYPE_KEY] == "2tone": - self._src1.set_amplitude(amplitude/2.0) - self._src2.set_amplitude(amplitude/2.0) + self._src1.set_amplitude(amplitude / 2.0) + self._src2.set_amplitude(amplitude / 2.0) elif self[TYPE_KEY] == "sweep": self._src.set_k(amplitude) else: @@ -293,7 +295,7 @@ def main(): print(ex) exit(1) tb.start() - raw_input('[UHD-SIGGEN] Press Enter to quit:\n') + eval(input('[UHD-SIGGEN] Press Enter to quit:\n')) tb.stop() tb.wait() diff --git a/gr-uhd/grc/gen_uhd_usrp_blocks.py b/gr-uhd/grc/gen_uhd_usrp_blocks.py index e99de0d7d0..8d16c4e936 100644 --- a/gr-uhd/grc/gen_uhd_usrp_blocks.py +++ b/gr-uhd/grc/gen_uhd_usrp_blocks.py @@ -21,27 +21,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA MAIN_TMPL = """\ <?xml version="1.0"?> <block> - <name>UHD: USRP $sourk.title()</name> - <key>uhd_usrp_$(sourk)</key> - <flags>throttle</flags> - <import>from gnuradio import uhd</import> - <import>import time</import> - <make>uhd.usrp_$(sourk)( - ",".join((\$dev_addr, \$dev_args)), - uhd.stream_args( - cpu_format="\$type", - \#if \$otw() - otw_format=\$otw, - \#end if - \#if \$stream_args() - args=\$stream_args, - \#end if - \#if \$stream_chans() - channels=\$stream_chans, - \#else - channels=range(\$nchan), - \#end if - ),$lentag_arg + <name>UHD: USRP $sourk.title()</name> + <key>uhd_usrp_$(sourk)</key> + <flags>throttle</flags> + <import>from gnuradio import uhd</import> + <import>import time</import> + <make>uhd.usrp_$(sourk)( + ",".join((\$dev_addr, \$dev_args)), + uhd.stream_args( + cpu_format="\$type", + \#if \$otw() + otw_format=\$otw, + \#end if + \#if \$stream_args() + args=\$stream_args, + \#end if + \#if \$stream_chans() + channels=\$stream_chans, + \#else + channels=range(\$nchan), + \#end if + ),$lentag_arg ) \#if \$clock_rate() self.\$(id).set_clock_rate(\$clock_rate, uhd.ALL_MBOARDS) @@ -75,309 +75,309 @@ self.\$(id).set_normalized_gain(\$gain$(n), $n) \#else self.\$(id).set_gain(\$gain$(n), $n) \#end if - \#if \$ant$(n)() + \#if \$ant$(n)() self.\$(id).set_antenna(\$ant$(n), $n) - \#end if - \#if \$bw$(n)() + \#end if + \#if \$bw$(n)() self.\$(id).set_bandwidth(\$bw$(n), $n) - \#end if + \#end if #if $sourk == 'source' - \#if \$lo_export$(n)() and not \$hide_lo_controls() + \#if \$lo_export$(n)() and not \$hide_lo_controls() self.\$(id).set_lo_export_enabled(\$lo_export$(n), uhd.ALL_LOS, $n) - \#end if + \#end if \#if \$lo_source$(n)() and not \$hide_lo_controls() self.\$(id).set_lo_source(\$lo_source$(n), uhd.ALL_LOS, $n) - \#end if - \#if \$dc_offs_enb$(n)() + \#end if + \#if \$dc_offs_enb$(n)() self.\$(id).set_auto_dc_offset(\$dc_offs_enb$(n), $n) - \#end if - \#if \$iq_imbal_enb$(n)() + \#end if + \#if \$iq_imbal_enb$(n)() self.\$(id).set_auto_iq_balance(\$iq_imbal_enb$(n), $n) - \#end if + \#end if #end if \#end if #end for </make> - <callback>set_samp_rate(\$samp_rate)</callback> - #for $n in range($max_nchan) - <callback>set_center_freq(\$center_freq$(n), $n)</callback> - <callback>\#if \$norm_gain${n}() + <callback>set_samp_rate(\$samp_rate)</callback> + #for $n in range($max_nchan) + <callback>set_center_freq(\$center_freq$(n), $n)</callback> + <callback>\#if \$norm_gain${n}() self.\$(id).set_normalized_gain(\$gain$(n), $n) \#else self.\$(id).set_gain(\$gain$(n), $n) \#end if - </callback> - <callback>\#if not \$hide_lo_controls() + </callback> + <callback>\#if not \$hide_lo_controls() set_lo_source(\$lo_source$(n), uhd.ALL_LOS, $n) \#end if - </callback> + </callback> <callback>\#if not \$hide_lo_controls() set_lo_export_enabled(\$lo_export$(n), uhd.ALL_LOS, $n) \#end if - </callback> - <callback>set_antenna(\$ant$(n), $n)</callback> - <callback>set_bandwidth(\$bw$(n), $n)</callback> - #end for - <param> - <name>$(direction.title())put Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Complex float32</name> - <key>fc32</key> - <opt>type:fc32</opt> - </option> - <option> - <name>Complex int16</name> - <key>sc16</key> - <opt>type:sc16</opt> - </option> - <option> - <name>VITA word32</name> - <key>item32</key> - <opt>type:s32</opt> - </option> - </param> - <param> - <name>Wire Format</name> - <key>otw</key> - <value></value> - <type>string</type> - <hide> - \#if \$otw() - none - \#else - part - \#end if - </hide> - <option> - <name>Automatic</name> - <key></key> - </option> - <option> - <name>Complex int16</name> - <key>sc16</key> - </option> - <option> - <name>Complex int12</name> - <key>sc12</key> - </option> - <option> - <name>Complex int8</name> - <key>sc8</key> - </option> - </param> - <param> - <name>Stream args</name> - <key>stream_args</key> - <value></value> - <type>string</type> - <hide> - \#if \$stream_args() - none - \#else - part - \#end if - </hide> - <option> - <name>peak=0.003906</name> - <key>peak=0.003906</key> - </option> - </param> - <param> - <name>Stream channels</name> - <key>stream_chans</key> - <value>[]</value> - <type>int_vector</type> - <hide> - \#if \$stream_chans() - none - \#else - part - \#end if - </hide> - </param> - <param> - <name>Device Address</name> - <key>dev_addr</key> - <value>""</value> - <type>string</type> - <hide> - \#if \$dev_addr() - none - \#else - part - \#end if - </hide> - </param> - <param> - <name>Device Arguments</name> - <key>dev_args</key> - <value>""</value> - <type>string</type> - <hide> - \#if \$dev_args() - none - \#else - part - \#end if - </hide> - </param> - <param> - <name>Sync</name> - <key>sync</key> - <value></value> - <type>enum</type> - <hide>\#if \$sync() then 'none' else 'part'#</hide> - <option> - <name>unknown PPS</name> - <key>sync</key> - </option> - <option> - <name>PC Clock</name> - <key>pc_clock</key> - </option> - <option> - <name>don't sync</name> - <key></key> - </option> - </param> - <param> - <name>Clock Rate (Hz)</name> - <key>clock_rate</key> - <value>0.0</value> - <type>real</type> - <hide>\#if \$clock_rate() then 'none' else 'part'#</hide> - <option> - <name>Default</name> - <key>0.0</key> - </option> - <option> - <name>200 MHz</name> - <key>200e6</key> - </option> - <option> - <name>184.32 MHz</name> - <key>184.32e6</key> - </option> - <option> - <name>120 MHz</name> - <key>120e6</key> - </option> - <option> - <name>30.72 MHz</name> - <key>30.72e6</key> - </option> - </param> - <param> - <name>Num Mboards</name> - <key>num_mboards</key> - <value>1</value> - <type>int</type> - <hide>part</hide> - #for $m in range(1, $max_mboards+1) - <option> - <name>$(m)</name> - <key>$m</key> - </option> - #end for - </param> - #for $m in range($max_mboards) - <param> - <name>Mb$(m): Clock Source</name> - <key>clock_source$(m)</key> - <value></value> - <type>string</type> - <hide> - \#if not \$num_mboards() > $m - all - \#elif \$clock_source$(m)() - none - \#else - part - \#end if - </hide> - <option><name>Default</name><key></key></option> - <option><name>Internal</name><key>internal</key></option> - <option><name>External</name><key>external</key></option> - <option><name>MIMO Cable</name><key>mimo</key></option> - <option><name>O/B GPSDO</name><key>gpsdo</key></option> - </param> - <param> - <name>Mb$(m): Time Source</name> - <key>time_source$(m)</key> - <value></value> - <type>string</type> - <hide> - \#if not \$num_mboards() > $m - all - \#elif \$time_source$(m)() - none - \#else - part - \#end if - </hide> - <option><name>Default</name><key></key></option> - <option><name>External</name><key>external</key></option> - <option><name>MIMO Cable</name><key>mimo</key></option> - <option><name>O/B GPSDO</name><key>gpsdo</key></option> - </param> - <param> - <name>Mb$(m): Subdev Spec</name> - <key>sd_spec$(m)</key> - <value></value> - <type>string</type> - <hide> - \#if not \$num_mboards() > $m - all - \#elif \$sd_spec$(m)() - none - \#else - part - \#end if - </hide> - </param> - #end for - <param> - <name>Num Channels</name> - <key>nchan</key> - <value>1</value> - <type>int</type> - #for $n in range(1, $max_nchan+1) - <option> - <name>$(n)</name> - <key>$n</key> - </option> - #end for - </param> - <param> - <name>Samp Rate (Sps)</name> - <key>samp_rate</key> - <value>samp_rate</value> - <type>real</type> - </param> - $params - <check>$max_nchan >= \$nchan</check> - <check>\$nchan > 0</check> - <check>$max_mboards >= \$num_mboards</check> - <check>\$num_mboards > 0</check> - <check>\$nchan >= \$num_mboards</check> - <check>(not \$stream_chans()) or (\$nchan == len(\$stream_chans))</check> - #for $n in range($max_nchan) - <check>(\$norm_gain${n} and \$gain${n} >= 0 and \$gain${n} <= 1) or not \$norm_gain${n}</check> - #end for - <sink> - <name>command</name> - <type>message</type> - <optional>1</optional> - <hide>\$hide_cmd_port</hide> - </sink> - <$sourk> - <name>$direction</name> - <type>\$type.type</type> - <nports>\$nchan</nports> - </$sourk> - <doc> + </callback> + <callback>set_antenna(\$ant$(n), $n)</callback> + <callback>set_bandwidth(\$bw$(n), $n)</callback> + #end for + <param> + <name>$(direction.title())put Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex float32</name> + <key>fc32</key> + <opt>type:fc32</opt> + </option> + <option> + <name>Complex int16</name> + <key>sc16</key> + <opt>type:sc16</opt> + </option> + <option> + <name>VITA word32</name> + <key>item32</key> + <opt>type:s32</opt> + </option> + </param> + <param> + <name>Wire Format</name> + <key>otw</key> + <value></value> + <type>string</type> + <hide> + \#if \$otw() + none + \#else + part + \#end if + </hide> + <option> + <name>Automatic</name> + <key></key> + </option> + <option> + <name>Complex int16</name> + <key>sc16</key> + </option> + <option> + <name>Complex int12</name> + <key>sc12</key> + </option> + <option> + <name>Complex int8</name> + <key>sc8</key> + </option> + </param> + <param> + <name>Stream args</name> + <key>stream_args</key> + <value></value> + <type>string</type> + <hide> + \#if \$stream_args() + none + \#else + part + \#end if + </hide> + <option> + <name>peak=0.003906</name> + <key>peak=0.003906</key> + </option> + </param> + <param> + <name>Stream channels</name> + <key>stream_chans</key> + <value>[]</value> + <type>int_vector</type> + <hide> + \#if \$stream_chans() + none + \#else + part + \#end if + </hide> + </param> + <param> + <name>Device Address</name> + <key>dev_addr</key> + <value>""</value> + <type>string</type> + <hide> + \#if \$dev_addr() + none + \#else + part + \#end if + </hide> + </param> + <param> + <name>Device Arguments</name> + <key>dev_args</key> + <value>""</value> + <type>string</type> + <hide> + \#if \$dev_args() + none + \#else + part + \#end if + </hide> + </param> + <param> + <name>Sync</name> + <key>sync</key> + <value></value> + <type>enum</type> + <hide>\#if \$sync() then 'none' else 'part'#</hide> + <option> + <name>unknown PPS</name> + <key>sync</key> + </option> + <option> + <name>PC Clock</name> + <key>pc_clock</key> + </option> + <option> + <name>don't sync</name> + <key></key> + </option> + </param> + <param> + <name>Clock Rate (Hz)</name> + <key>clock_rate</key> + <value>0.0</value> + <type>real</type> + <hide>\#if \$clock_rate() then 'none' else 'part'#</hide> + <option> + <name>Default</name> + <key>0.0</key> + </option> + <option> + <name>200 MHz</name> + <key>200e6</key> + </option> + <option> + <name>184.32 MHz</name> + <key>184.32e6</key> + </option> + <option> + <name>120 MHz</name> + <key>120e6</key> + </option> + <option> + <name>30.72 MHz</name> + <key>30.72e6</key> + </option> + </param> + <param> + <name>Num Mboards</name> + <key>num_mboards</key> + <value>1</value> + <type>int</type> + <hide>part</hide> + #for $m in range(1, $max_mboards+1) + <option> + <name>$(m)</name> + <key>$m</key> + </option> + #end for + </param> + #for $m in range($max_mboards) + <param> + <name>Mb$(m): Clock Source</name> + <key>clock_source$(m)</key> + <value></value> + <type>string</type> + <hide> + \#if not \$num_mboards() > $m + all + \#elif \$clock_source$(m)() + none + \#else + part + \#end if + </hide> + <option><name>Default</name><key></key></option> + <option><name>Internal</name><key>internal</key></option> + <option><name>External</name><key>external</key></option> + <option><name>MIMO Cable</name><key>mimo</key></option> + <option><name>O/B GPSDO</name><key>gpsdo</key></option> + </param> + <param> + <name>Mb$(m): Time Source</name> + <key>time_source$(m)</key> + <value></value> + <type>string</type> + <hide> + \#if not \$num_mboards() > $m + all + \#elif \$time_source$(m)() + none + \#else + part + \#end if + </hide> + <option><name>Default</name><key></key></option> + <option><name>External</name><key>external</key></option> + <option><name>MIMO Cable</name><key>mimo</key></option> + <option><name>O/B GPSDO</name><key>gpsdo</key></option> + </param> + <param> + <name>Mb$(m): Subdev Spec</name> + <key>sd_spec$(m)</key> + <value></value> + <type>string</type> + <hide> + \#if not \$num_mboards() > $m + all + \#elif \$sd_spec$(m)() + none + \#else + part + \#end if + </hide> + </param> + #end for + <param> + <name>Num Channels</name> + <key>nchan</key> + <value>1</value> + <type>int</type> + #for $n in range(1, $max_nchan+1) + <option> + <name>$(n)</name> + <key>$n</key> + </option> + #end for + </param> + <param> + <name>Samp Rate (Sps)</name> + <key>samp_rate</key> + <value>samp_rate</value> + <type>real</type> + </param> + $params + <check>$max_nchan >= \$nchan</check> + <check>\$nchan > 0</check> + <check>$max_mboards >= \$num_mboards</check> + <check>\$num_mboards > 0</check> + <check>\$nchan >= \$num_mboards</check> + <check>(not \$stream_chans()) or (\$nchan == len(\$stream_chans))</check> + #for $n in range($max_nchan) + <check>(\$norm_gain${n} and \$gain${n} >= 0 and \$gain${n} <= 1) or not \$norm_gain${n}</check> + #end for + <sink> + <name>command</name> + <type>message</type> + <optional>1</optional> + <hide>\$hide_cmd_port</hide> + </sink> + <$sourk> + <name>$direction</name> + <type>\$type.type</type> + <nports>\$nchan</nports> + </$sourk> + <doc> The UHD USRP $sourk.title() Block: Device Address: @@ -452,31 +452,31 @@ to determine transmit burst lengths. See the UHD manual for more detailed documentation: http://uhd.ettus.com - </doc> + </doc> </block> """ PARAMS_TMPL = """ <param> - <name>Ch$(n): Center Freq (Hz)</name> - <key>center_freq$(n)</key> - <value>0</value> - <type>real</type> - <hide>\#if \$nchan() > $n then 'none' else 'all'#</hide> - <tab>RF Options</tab> - </param> - <param> - <name>Ch$(n): Gain Value</name> - <key>gain$(n)</key> - <value>0</value> - <type>float</type> - <hide>\#if \$nchan() > $n then 'none' else 'all'#</hide> - <tab>RF Options</tab> - </param> - <param> - <name>Ch$(n): Gain Type</name> - <key>norm_gain$(n)</key> - <value>False</value> - <type>bool</type> + <name>Ch$(n): Center Freq (Hz)</name> + <key>center_freq$(n)</key> + <value>0</value> + <type>real</type> + <hide>\#if \$nchan() > $n then 'none' else 'all'#</hide> + <tab>RF Options</tab> + </param> + <param> + <name>Ch$(n): Gain Value</name> + <key>gain$(n)</key> + <value>0</value> + <type>float</type> + <hide>\#if \$nchan() > $n then 'none' else 'all'#</hide> + <tab>RF Options</tab> + </param> + <param> + <name>Ch$(n): Gain Type</name> + <key>norm_gain$(n)</key> + <value>False</value> + <type>bool</type> <hide>\#if \$nchan() <= $n all \#elif bool(\$norm_gain${n}()) @@ -484,227 +484,227 @@ PARAMS_TMPL = """ <param> \#else part \#end if</hide> - <option> - <name>Absolute (dB)</name> - <key>False</key> - </option> - <option> - <name>Normalized</name> - <key>True</key> - </option> - <tab>RF Options</tab> - </param> - <param> - <name>Ch$(n): Antenna</name> - <key>ant$(n)</key> - <value></value> - <type>string</type> - <hide> - \#if not \$nchan() > $n - all - \#elif \$ant$(n)() - none - \#else - part - \#end if - </hide> - <option> - <name>TX/RX</name> - <key>TX/RX</key> - </option> + <option> + <name>Absolute (dB)</name> + <key>False</key> + </option> + <option> + <name>Normalized</name> + <key>True</key> + </option> + <tab>RF Options</tab> + </param> + <param> + <name>Ch$(n): Antenna</name> + <key>ant$(n)</key> + <value></value> + <type>string</type> + <hide> + \#if not \$nchan() > $n + all + \#elif \$ant$(n)() + none + \#else + part + \#end if + </hide> + <option> + <name>TX/RX</name> + <key>TX/RX</key> + </option> #if $sourk == 'source' - <option> - <name>RX2</name> - <key>RX2</key> - </option> + <option> + <name>RX2</name> + <key>RX2</key> + </option> #end if - <tab>RF Options</tab> - </param> - <param> - <name>Ch$(n): Bandwidth (Hz)</name> - <key>bw$(n)</key> - <value>0</value> - <type>real</type> - <hide> - \#if not \$nchan() > $n - all - \#elif \$bw$(n)() - none - \#else - part - \#end if - </hide> - <tab>RF Options</tab> - </param> + <tab>RF Options</tab> + </param> + <param> + <name>Ch$(n): Bandwidth (Hz)</name> + <key>bw$(n)</key> + <value>0</value> + <type>real</type> + <hide> + \#if not \$nchan() > $n + all + \#elif \$bw$(n)() + none + \#else + part + \#end if + </hide> + <tab>RF Options</tab> + </param> #if $sourk == 'source' - <param> - <name>Ch$(n): LO Source</name> - <key>lo_source$(n)</key> - <value>internal</value> - <type>string</type> - <hide> - \#if not \$nchan() > $n - all - \#elif \$hide_lo_controls() - all - \#else - none - \#end if - </hide> - <option> - <name>Internal</name> - <key>internal</key> - </option> - <option> - <name>External</name> - <key>external</key> - </option> - <option> - <name>Companion</name> - <key>companion</key> - </option> - <tab>RF Options</tab> - </param> + <param> + <name>Ch$(n): LO Source</name> + <key>lo_source$(n)</key> + <value>internal</value> + <type>string</type> + <hide> + \#if not \$nchan() > $n + all + \#elif \$hide_lo_controls() + all + \#else + none + \#end if + </hide> + <option> + <name>Internal</name> + <key>internal</key> + </option> + <option> + <name>External</name> + <key>external</key> + </option> + <option> + <name>Companion</name> + <key>companion</key> + </option> + <tab>RF Options</tab> + </param> #end if #if $sourk == 'source' - <param> - <name>Ch$(n): LO Export</name> - <key>lo_export$(n)</key> - <value>False</value> - <type>bool</type> - <hide> - \#if not \$nchan() > $n - all - \#elif \$hide_lo_controls() - all - \#else - none - \#end if - </hide> - <option> - <name>True</name> - <key>True</key> - </option> - <option> - <name>False</name> - <key>False</key> - </option> - <tab>RF Options</tab> - </param> + <param> + <name>Ch$(n): LO Export</name> + <key>lo_export$(n)</key> + <value>False</value> + <type>bool</type> + <hide> + \#if not \$nchan() > $n + all + \#elif \$hide_lo_controls() + all + \#else + none + \#end if + </hide> + <option> + <name>True</name> + <key>True</key> + </option> + <option> + <name>False</name> + <key>False</key> + </option> + <tab>RF Options</tab> + </param> #end if #if $sourk == 'source' - <param> - <name>Ch$(n): Enable DC Offset Correction</name> - <key>dc_offs_enb$(n)</key> - <value>""</value> - <type>raw</type> - <hide> - \#if not \$nchan() > $n - all - \#else - part - \#end if - </hide> - <tab>FE Corrections</tab> - </param> - <param> - <name>Ch$(n): Enable IQ Imbalance Correction</name> - <key>iq_imbal_enb$(n)</key> - <value>""</value> - <type>raw</type> - <hide> - \#if not \$nchan() > $n - all - \#else - part - \#end if - </hide> - <tab>FE Corrections</tab> - </param> + <param> + <name>Ch$(n): Enable DC Offset Correction</name> + <key>dc_offs_enb$(n)</key> + <value>""</value> + <type>raw</type> + <hide> + \#if not \$nchan() > $n + all + \#else + part + \#end if + </hide> + <tab>FE Corrections</tab> + </param> + <param> + <name>Ch$(n): Enable IQ Imbalance Correction</name> + <key>iq_imbal_enb$(n)</key> + <value>""</value> + <type>raw</type> + <hide> + \#if not \$nchan() > $n + all + \#else + part + \#end if + </hide> + <tab>FE Corrections</tab> + </param> #end if """ SHOW_CMD_PORT_PARAM = """ - <param> - <name>Show Command Port</name> - <key>hide_cmd_port</key> - <value>False</value> - <type>enum</type> - <hide>part</hide> - <option> - <name>Yes</name> - <key>False</key> - </option> - <option> - <name>No</name> - <key>True</key> - </option> - <tab>Advanced</tab> - </param> + <param> + <name>Show Command Port</name> + <key>hide_cmd_port</key> + <value>False</value> + <type>enum</type> + <hide>part</hide> + <option> + <name>Yes</name> + <key>False</key> + </option> + <option> + <name>No</name> + <key>True</key> + </option> + <tab>Advanced</tab> + </param> """ SHOW_LO_CONTROLS_PARAM = """ - <param> - <name>Show LO Controls</name> - <key>hide_lo_controls</key> - <value>True</value> - <type>bool</type> - <hide>part</hide> - <option> - <name>Yes</name> - <key>False</key> - </option> - <option> - <name>No</name> - <key>True</key> - </option> - <tab>Advanced</tab> - </param> + <param> + <name>Show LO Controls</name> + <key>hide_lo_controls</key> + <value>True</value> + <type>bool</type> + <hide>part</hide> + <option> + <name>Yes</name> + <key>False</key> + </option> + <option> + <name>No</name> + <key>True</key> + </option> + <tab>Advanced</tab> + </param> """ TSBTAG_PARAM = """ <param> - <name>TSB tag name</name> - <key>len_tag_name</key> - <value></value> - <type>string</type> - <hide>\#if len(str(\$len_tag_name())) then 'none' else 'part'#</hide> - </param>""" + <name>TSB tag name</name> + <key>len_tag_name</key> + <value></value> + <type>string</type> + <hide>\#if len(str(\$len_tag_name())) then 'none' else 'part'#</hide> + </param>""" TSBTAG_ARG = """ - #if $len_tag_name() - $len_tag_name, - #end if""" + #if $len_tag_name() + $len_tag_name, + #end if""" def parse_tmpl(_tmpl, **kwargs): - from Cheetah import Template - return str(Template.Template(_tmpl, kwargs)) + from Cheetah import Template + return str(Template.Template(_tmpl, kwargs)) max_num_mboards = 8 max_num_channels = max_num_mboards*4 if __name__ == '__main__': - import sys - for file in sys.argv[1:]: - if file.endswith ('source.xml'): - sourk = 'source' - direction = 'out' - elif file.endswith ('sink.xml'): - sourk = 'sink' - direction = 'in' - else: raise Exception, 'is %s a source or sink?'%file + import sys + for file in sys.argv[1:]: + if file.endswith ('source.xml'): + sourk = 'source' + direction = 'out' + elif file.endswith ('sink.xml'): + sourk = 'sink' + direction = 'in' + else: raise Exception('is %s a source or sink?'%file) - params = ''.join([parse_tmpl(PARAMS_TMPL, n=n, sourk=sourk) for n in range(max_num_channels)]) - params += SHOW_CMD_PORT_PARAM - params += SHOW_LO_CONTROLS_PARAM - if sourk == 'sink': - params += TSBTAG_PARAM - lentag_arg = TSBTAG_ARG - else: lentag_arg = '' - open(file, 'w').write(parse_tmpl(MAIN_TMPL, - lentag_arg=lentag_arg, - max_nchan=max_num_channels, - max_mboards=max_num_mboards, - params=params, - sourk=sourk, - direction=direction, - )) + params = ''.join([parse_tmpl(PARAMS_TMPL, n=n, sourk=sourk) for n in range(max_num_channels)]) + params += SHOW_CMD_PORT_PARAM + params += SHOW_LO_CONTROLS_PARAM + if sourk == 'sink': + params += TSBTAG_PARAM + lentag_arg = TSBTAG_ARG + else: lentag_arg = '' + open(file, 'w').write(parse_tmpl(MAIN_TMPL, + lentag_arg=lentag_arg, + max_nchan=max_num_channels, + max_mboards=max_num_mboards, + params=params, + sourk=sourk, + direction=direction, + )) diff --git a/gr-uhd/python/uhd/CMakeLists.txt b/gr-uhd/python/uhd/CMakeLists.txt index ee69e8eb7d..e736edebf0 100644 --- a/gr-uhd/python/uhd/CMakeLists.txt +++ b/gr-uhd/python/uhd/CMakeLists.txt @@ -44,6 +44,6 @@ include(GrTest) file(GLOB py_qa_test_files "qa_*.py") foreach(py_qa_test_file ${py_qa_test_files}) get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) - GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) + GR_ADD_TEST(${py_qa_test_name} ${QA_PYTHON_EXECUTABLE} -B ${py_qa_test_file}) endforeach(py_qa_test_file) endif(ENABLE_TESTING) diff --git a/gr-uhd/python/uhd/__init__.py b/gr-uhd/python/uhd/__init__.py index 6d7f232466..ad342ee30d 100644 --- a/gr-uhd/python/uhd/__init__.py +++ b/gr-uhd/python/uhd/__init__.py @@ -25,17 +25,20 @@ Used to send and receive data between the Ettus Research, LLC product line. ''' +from __future__ import absolute_import +from __future__ import unicode_literals + ######################################################################## # Prepare uhd swig module to make it more pythonic ######################################################################## def _prepare_uhd_swig(): try: - import uhd_swig + from . import uhd_swig except ImportError: import os dirname, filename = os.path.split(os.path.abspath(__file__)) __path__.append(os.path.join(dirname, "..", "..", "swig")) - import uhd_swig + from . import uhd_swig #some useful typedefs for the user setattr(uhd_swig, 'freq_range_t', uhd_swig.meta_range_t) @@ -50,7 +53,7 @@ def _prepare_uhd_swig(): def __float__(self): return self.target_freq def __init__(self, *args, **kwargs): super(tune_request_t, self).__init__(*args) - for key, val in kwargs.iteritems(): setattr(self, key, val) + for key, val in list(kwargs.items()): setattr(self, key, val) setattr(uhd_swig, 'tune_request_t', tune_request_t) #Make the python tune request object inherit from string @@ -64,14 +67,14 @@ def _prepare_uhd_swig(): def __init__(self, *args, **kwargs): super(device_addr_t, self).__init__(*args) if args and isinstance(args[0], device_addr_t): - for key in args[0].keys(): self[key] = args[0][key] + for key in list(args[0].keys()): self[key] = args[0][key] setattr(uhd_swig, 'device_addr_t', device_addr_t) #make the streamer args take **kwargs on init class stream_args_t(uhd_swig.stream_args_t): def __init__(self, *args, **kwargs): super(stream_args_t, self).__init__(*args) - for key, val in kwargs.iteritems(): + for key, val in list(kwargs.items()): #for some reason, i cant assign a list in the constructor #but what i can do is append the elements individually if key == 'channels': @@ -97,7 +100,7 @@ def _prepare_uhd_swig(): def find_devices(*args, **kwargs): def to_pythonized_dev_addr(dev_addr): new_dev_addr = uhd_swig.device_addr_t() - for key in dev_addr.keys(): new_dev_addr[key] = dev_addr.get(key) + for key in list(dev_addr.keys()): new_dev_addr[key] = dev_addr.get(key) return new_dev_addr return __builtins__['map'](to_pythonized_dev_addr, uhd_swig.find_devices_raw(*args, **kwargs)) setattr(uhd_swig, 'find_devices', find_devices) @@ -114,11 +117,11 @@ def _prepare_uhd_swig(): ): try: if len(args) > index: args[index] = cast(args[index]) - if kwargs.has_key(key): kwargs[key] = cast(kwargs[key]) + if key in kwargs: kwargs[key] = cast(kwargs[key]) except: pass #dont pass kwargs, it confuses swig, map into args list: for key in ('device_addr', 'stream_args', 'io_type', 'num_channels', 'msgq'): - if kwargs.has_key(key): args.append(kwargs[key]) + if key in kwargs: args.append(kwargs[key]) return old_constructor(*args) return constructor_interceptor setattr(uhd_swig, attr, constructor_factory(getattr(uhd_swig, attr))) @@ -133,4 +136,4 @@ def _prepare_uhd_swig(): # Initialize this module with the contents of uhd swig ######################################################################## _prepare_uhd_swig() -from uhd_swig import * +from .uhd_swig import * diff --git a/gr-uhd/python/uhd/qa_uhd.py b/gr-uhd/python/uhd/qa_uhd.py index 4df0d4273e..bab029a9a8 100644 --- a/gr-uhd/python/uhd/qa_uhd.py +++ b/gr-uhd/python/uhd/qa_uhd.py @@ -20,6 +20,8 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function + from gnuradio import gr, gr_unittest, uhd class test_uhd(gr_unittest.TestCase): @@ -50,7 +52,7 @@ class test_uhd(gr_unittest.TestCase): sa = uhd.stream_args_t() sa.channels.append(1) sa.channels.append(0) - print sa.channels + print(sa.channels) self.assertEqual(len(sa.channels), 2) self.assertEqual(sa.channels[0], 1) self.assertEqual(sa.channels[1], 0) |