commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r5568 - gnuradio/branches/developers/jcorgan/snd/gr-so


From: jcorgan
Subject: [Commit-gnuradio] r5568 - gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python
Date: Tue, 29 May 2007 21:09:35 -0600 (MDT)

Author: jcorgan
Date: 2007-05-29 21:09:35 -0600 (Tue, 29 May 2007)
New Revision: 5568

Modified:
   gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python/sounder.py
   
gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python/usrp_sounder.py
Log:
Work in progress.

Modified: 
gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python/sounder.py
===================================================================
--- gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python/sounder.py   
2007-05-30 00:34:51 UTC (rev 5567)
+++ gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python/sounder.py   
2007-05-30 03:09:35 UTC (rev 5568)
@@ -66,8 +66,9 @@
             raise RuntimeError("Failed to set transmitter frequency.")
 
 class sounder_rx:
-    def 
__init__(self,subdev_spec=None,length=1,msgq=None,loopback=False,verbose=False,debug=False):
+    def 
__init__(self,subdev_spec=None,gain=None,length=1,msgq=None,loopback=False,verbose=False,debug=False):
        self._subdev_spec = subdev_spec
+        self._gain = gain
         self._length = length
         self._msgq = msgq
        self._loopback = loopback
@@ -84,6 +85,7 @@
             if self._verbose:
                print "Using", self._subdev.name(), "for sounder receiver."
 
+        self.set_gain(self._gain)
         self._vblen = gr.sizeof_gr_complex*self._length
        if self._debug:
             print "Generating impulse vectors of length", self._length, "byte 
length", self._vblen
@@ -99,6 +101,16 @@
         if result == False:
             raise RuntimeError("Failed to set receiver frequency.")
 
+    def set_gain(self, gain):
+        self._gain = gain
+        if self._gain is None:
+            # if no gain was specified, use the mid-point in dB
+            g = self._subdev.gain_range()
+            self._gain = float(g[0]+g[1])/2
+        if self._verbose:
+            print "Setting receiver gain to", gain
+        self._subdev.set_gain(self._gain)
+
     def start(self):
         if self._debug:
             print "Starting receiver flow graph."
@@ -120,12 +132,13 @@
 
 class sounder:
     def 
__init__(self,transmit=False,receive=False,loopback=False,rx_subdev_spec=None,
-                 
frequency=0.0,degree=10,length=1,msgq=None,verbose=False,debug=False):
+                 
frequency=0.0,rx_gain=None,degree=12,length=1,msgq=None,verbose=False,debug=False):
         self._transmit = transmit
         self._receive = receive
         self._loopback = loopback
         self._rx_subdev_spec = rx_subdev_spec
         self._frequency = frequency
+        self._rx_gain = rx_gain
         self._degree = degree
         self._length = length
         self._msgq = msgq
@@ -143,7 +156,7 @@
             self._u = self._trans._u
             
        if self._receive:
-            self._rcvr = 
sounder_rx(subdev_spec=self._rx_subdev_spec,length=self._length,
+            self._rcvr = 
sounder_rx(subdev_spec=self._rx_subdev_spec,length=self._length,gain=self._rx_gain,
                                    
msgq=self._msgq,loopback=self._loopback,verbose=self._verbose, 
                                    debug=self._debug)
            self._u = self._rcvr._u # either receiver or transmitter object 
will do

Modified: 
gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python/usrp_sounder.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python/usrp_sounder.py  
    2007-05-30 00:34:51 UTC (rev 5567)
+++ 
gnuradio/branches/developers/jcorgan/snd/gr-sounder/src/python/usrp_sounder.py  
    2007-05-30 03:09:35 UTC (rev 5568)
@@ -25,6 +25,7 @@
 from gnuradio import eng_notation
 from gnuradio.eng_option import eng_option
 from optparse import OptionParser
+import numpy
 import sys
 
 n2s = eng_notation.num_to_str
@@ -33,6 +34,8 @@
     parser = OptionParser(option_class=eng_option)
     parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
                       help="select USRP Rx side A or B")
+    parser.add_option("-g", "--gain", type="eng_float", default=None,
+                      help="set gain in dB (default is midpoint)")
     parser.add_option("-f", "--frequency", type="eng_float", default=0.0,
                       help="set frequency to FREQ in Hz, default is %default", 
metavar="FREQ")
     parser.add_option("-d", "--degree", type="int", default=12,
@@ -74,8 +77,9 @@
            
     msgq = gr.msg_queue()
     s = 
sounder(transmit=options.transmit,receive=options.receive,loopback=options.loopback,
-                
rx_subdev_spec=options.rx_subdev_spec,frequency=options.frequency,degree=options.degree,
-                
length=length,msgq=msgq,verbose=options.verbose,debug=options.debug)
+                
rx_subdev_spec=options.rx_subdev_spec,frequency=options.frequency,rx_gain=options.gain,
+                
degree=options.degree,length=length,msgq=msgq,verbose=options.verbose,
+                debug=options.debug)
     s.start()
 
     if options.receive:
@@ -89,7 +93,10 @@
                rec = msg.to_string()[:length*gr.sizeof_gr_complex]
                if options.debug:
                    print "Received impulse vector of length", len(rec)
-               f.write(rec)
+                recarray = numpy.fromstring(rec, dtype=numpy.complex64)
+                imparray = recarray[::-1]
+                data = imparray.tostring()
+               f.write(data)
                
         except KeyboardInterrupt:
             pass





reply via email to

[Prev in Thread] Current Thread [Next in Thread]