[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10983 - gnuradio/branches/developers/jblum/digital
From: |
jblum |
Subject: |
[Commit-gnuradio] r10983 - gnuradio/branches/developers/jblum/digital |
Date: |
Wed, 6 May 2009 19:02:48 -0600 (MDT) |
Author: jblum
Date: 2009-05-06 19:02:48 -0600 (Wed, 06 May 2009)
New Revision: 10983
Modified:
gnuradio/branches/developers/jblum/digital/generic_usrp.py
Log:
Moved setup code into common/base class.
Error/warning for failed automatic setup.
Modified: gnuradio/branches/developers/jblum/digital/generic_usrp.py
===================================================================
--- gnuradio/branches/developers/jblum/digital/generic_usrp.py 2009-05-07
00:28:58 UTC (rev 10982)
+++ gnuradio/branches/developers/jblum/digital/generic_usrp.py 2009-05-07
01:02:48 UTC (rev 10983)
@@ -29,7 +29,8 @@
########################################################################
class _generic_usrp_base(object):
- def __init__(self, which=0, subdev_spec=None, interface="", mac_addr="",
fusb_block_size=0, fusb_nblocks=0, usrpx=None, lo_offset=None, gain=None):
+ def __init__(self, which=0, subdev_spec=None, interface="", mac_addr="",
+ fusb_block_size=0, fusb_nblocks=0, usrpx=None, lo_offset=None,
gain=None):
self._gain = gain
self._lo_offset = lo_offset
self._usrpx = usrpx
@@ -42,13 +43,29 @@
#fusb options
self._fusb_block_size = fusb_block_size
self._fusb_nblocks = fusb_nblocks
-
- def _post_setup_usrp(self):
+ #pick which usrp model
+ if self._usrpx == '1' or self._subdev_spec:
self._setup_usrpx(USRP1_TYPE)
+ elif self._usrpx == '2' or self._mac_addr:
self._setup_usrpx(USRP2_TYPE)
+ else: #automatic
+ try: self._setup_usrpx(USRP2_TYPE)
+ except:
+ try: self._setup_usrpx(USRP1_TYPE)
+ except: raise Exception, 'Failed to automatically setup a usrp
device.'
+ #post usrp setup
if self._lo_offset is not None:
self.set_lo_offset(self._lo_offset)
self.set_gain(self._gain)
self.set_auto_tr(True)
+ def _setup_usrpx(self, type):
+ """
+ Call the appropriate setup method.
+ @param type the usrp type constant
+ """
+ self._type = type
+ if self._type == USRP1_TYPE: self._setup_usrp1()
+ elif self._type == USRP2_TYPE: self._setup_usrp2()
+
def __str__(self):
if self._type == USRP1_TYPE: return self._subdev.side_and_name()
elif self._type == USRP2_TYPE:
@@ -58,9 +75,10 @@
def gain(self): return self._gain
def set_gain(self, gain=None):
- if gain is None:
- r = self.gain_range()
- gain = (r[0] + r[1])/2 # set gain to midpoint
+ #automatic gain calculation
+ r = self.gain_range()
+ if gain is None: gain = (r[0] + r[1])/2 # set gain to midpoint
+ #set gain for usrp
self._gain = gain
if self._type == USRP1_TYPE: return self._subdev.set_gain(gain)
elif self._type == USRP2_TYPE: return self._u.set_gain(gain)
@@ -87,8 +105,10 @@
if self._type == USRP1_TYPE: return self._subdev.set_auto_tr(enable)
def __del__(self):
- # Avoid weak reference error
- if self._type == USRP1_TYPE: del self._subdev
+ try: # Avoid weak reference error
+ del self._u
+ del self._subdev
+ except: pass
########################################################################
# generic usrp source
@@ -101,20 +121,11 @@
"""
def __init__(self, **kwargs):
- _generic_usrp_base.__init__(self, **kwargs)
gr.hier_block2.__init__(self, "generic_usrp_source",
gr.io_signature(0, 0, 0), # Input signature
gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
- #pick usrp or usrp2
- if self._usrpx == '1' or self._subdev_spec:
- self._setup_usrp1()
- elif self._usrpx == '2' or self._mac_addr:
- self._setup_usrp2()
- else: #automatic
- try: self._setup_usrp2()
- except: self._setup_usrp1()
+ _generic_usrp_base.__init__(self, **kwargs)
self.connect(self._u, self)
- self._post_setup_usrp()
####################################################################
# generic access methods
@@ -155,23 +166,13 @@
"""
def __init__(self, **kwargs):
- _generic_usrp_base.__init__(self, **kwargs)
gr.hier_block2.__init__(self, "generic_usrp_sink",
gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
gr.io_signature(0, 0, 0)) # Output signature
-
- #pick usrp or usrp2
- if self._usrpx == '1' or self._subdev_spec:
- self._setup_usrp1()
- elif self._usrpx == '2' or self._mac_addr:
- self._setup_usrp2()
- else: #automatic
- try: self._setup_usrp2()
- except: self._setup_usrp1()
+ _generic_usrp_base.__init__(self, **kwargs)
if self._type == USRP1_TYPE: #scale 0.0 to 1.0 input for usrp1
self.connect(self, gr.multiply_const_cc((2**15)-1), self._u)
elif self._type == USRP2_TYPE: self.connect(self, self._u)
- self._post_setup_usrp()
####################################################################
# generic access methods
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10983 - gnuradio/branches/developers/jblum/digital,
jblum <=