Index: vtcross/branches/sriram/benchmark_txrxnode1.py
===================================================================
--- vtcross/branches/sriram/benchmark_txrxnode1.py	(revision 327)
+++ vtcross/branches/sriram/benchmark_txrxnode1.py	(revision 330)
@@ -7,6 +7,6 @@
 from gnuradio import optfir, window
 from gnuradio import usrp
-from gnuradio.eng_option import eng_option
-from usrpm import usrp_dbid
+#from gnuradio.eng_option import eng_option
+#from usrpm import usrp_dbid
 ##########
 from gnuradio.eng_option import eng_option
@@ -18,4 +18,5 @@
 from transmit_path import transmit_path
 from receive_path import receive_path
+import spec_sense_path
 
 global sync_status
@@ -35,243 +36,12 @@
         self.rxpath = receive_path(demod_class, rx_callback, options_rx)
 	self.txpath = transmit_path(mod_class, options_tx)
-	self.connect(self.txpath);
-	self.connect(self.rxpath);
-
-
-##################### Spectrum sense specific classes###########################################################
-class tune(gr.feval_dd):
-    """
-    This class allows C++ code to callback into python.
-    """
-    def __init__(self, tb):
-        gr.feval_dd.__init__(self)
-        self.tb = tb
-
-    def eval(self, ignore):
-        """
-        This method is called from gr.bin_statistics_f when it wants to change
-        the center frequency.  This method tunes the front end to the new center
-        frequency, and returns the new frequency as its result.
-        """
-        try:
-            # We use this try block so that if something goes wrong from here 
-            # down, at least we'll have a prayer of knowing what went wrong.
-            # Without this, you get a very mysterious:
-            #
-            #   terminate called after throwing an instance of 'Swig::DirectorMethodException'
-            #   Aborted
-            #
-            # message on stderr.  Not exactly helpful ;)
-
-            new_freq = self.tb.set_next_freq()
-            return new_freq
-
-        except Exception, e:
-            print "tune: Exception: ", e
-
-
-class parse_msg(object):
-    def __init__(self, msg):
-        self.center_freq = msg.arg1()
-        self.vlen = int(msg.arg2())
-        assert(msg.length() == self.vlen * gr.sizeof_float)
-
-        # FIXME consider using Numarray or NumPy vector
-        t = msg.to_string()
-        self.raw_data = t
-        self.data = struct.unpack('%df' % (self.vlen,), t)
-
-
-class spec_sense_top_block(gr.top_block):
-
-    def __init__(self,min_f,max_f):
-        gr.top_block.__init__(self)
-
-        usage = "usage: %prog [options] min_freq max_freq"
-        parser = OptionParser(option_class=eng_option, usage=usage)
-        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0,0),
-                          help="select USRP Rx side A or B (default=A)")
-        parser.add_option("-g", "--gain", type="eng_float", default=None,
-                          help="set gain in dB (default is midpoint)")
-        parser.add_option("", "--tune-delay", type="eng_float", default=1e-3, metavar="SECS",
-                          help="time to delay (in seconds) after changing frequency [default=%default]")
-        parser.add_option("", "--dwell-delay", type="eng_float", default=10e-3, metavar="SECS",
-                          help="time to dwell (in seconds) at a given frequncy [default=%default]")
-        parser.add_option("-F", "--fft-size", type="int", default=256,
-                          help="specify number of FFT bins [default=%default]")
-        parser.add_option("-d", "--decim", type="intx", default=16,
-                          help="set decimation to DECIM [default=%default]")
-        parser.add_option("", "--real-time", action="store_true", default=False,
-                          help="Attempt to enable real-time scheduling")
-        parser.add_option("-B", "--fusb-block-size", type="int", default=0,
-                          help="specify fast usb block size [default=%default]")
-        parser.add_option("-N", "--fusb-nblocks", type="int", default=0,
-                          help="specify number of fast usb blocks [default=%default]")
-
-        (options, args) = parser.parse_args()
-        #if len(args) != 2:
-         #   parser.print_help()
-         #   sys.exit(1)
-
-        #self.min_freq = eng_notation.str_to_num(args[0])
-	self.min_freq = float(min_f) # setting min and max frequency inside the init rather than taking it from the command line
-        #self.max_freq = eng_notation.str_to_num(args[1])
-	self.max_freq = float(max_f)
-
-        if self.min_freq > self.max_freq:
-            self.min_freq, self.max_freq = self.max_freq, self.min_freq   # swap them
-
-	self.fft_size = options.fft_size
-
-
-        if not options.real_time:
-            realtime = False
-        else:
-            # Attempt to enable realtime scheduling
-            r = gr.enable_realtime_scheduling()
-            if r == gr.RT_OK:
-                realtime = True
-            else:
-                realtime = False
-                print "Note: failed to enable realtime scheduling"
-
-        # If the user hasn't set the fusb_* parameters on the command line,
-        # pick some values that will reduce latency.
-
-        if 1:
-            if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
-                if realtime:                        # be more aggressive
-                    options.fusb_block_size = gr.prefs().get_long('fusb', 'rt_block_size', 1024)
-                    options.fusb_nblocks    = gr.prefs().get_long('fusb', 'rt_nblocks', 16)
-                else:
-                    options.fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096)
-                    options.fusb_nblocks    = gr.prefs().get_long('fusb', 'nblocks', 16)
-    
-        #print "fusb_block_size =", options.fusb_block_size
-	#print "fusb_nblocks    =", options.fusb_nblocks
-
-        # build graph
-        
-        self.u = usrp.source_c(fusb_block_size=options.fusb_block_size,
-                               fusb_nblocks=options.fusb_nblocks)
-
-
-        adc_rate = self.u.adc_rate()                # 64 MS/s
-        usrp_decim = options.decim
-        self.u.set_decim_rate(usrp_decim)
-        usrp_rate = adc_rate / usrp_decim
-
-        self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
-        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
-        print "Using RX d'board %s" % (self.subdev.side_and_name(),)
-
-
-	s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
-
-        mywindow = window.blackmanharris(self.fft_size)
-        fft = gr.fft_vcc(self.fft_size, True, mywindow)
-        power = 0
-        for tap in mywindow:
-            power += tap*tap
-            
-        c2mag = gr.complex_to_mag_squared(self.fft_size)
-	print "print c2mag ",c2mag,"\n"
-        # FIXME the log10 primitive is dog slow
-        log = gr.nlog10_ff(10, self.fft_size,
-                           -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size))
-		
-        # Set the freq_step to 75% of the actual data throughput.
-        # This allows us to discard the bins on both ends of the spectrum.
-
-        self.freq_step = 0.75 * usrp_rate
-        self.min_center_freq = self.min_freq + self.freq_step/2
-        nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step)
-        self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step)
-
-        self.next_freq = self.min_center_freq
-        
-        tune_delay  = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size)))  # in fft_frames
-        dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames
-
-        self.msgq = gr.msg_queue(16)
-        self._tune_callback = tune(self)        # hang on to this to keep it from being GC'd
-        stats = gr.bin_statistics_f(self.fft_size, self.msgq,
-                                    self._tune_callback, tune_delay, dwell_delay)
-
-        # FIXME leave out the log10 until we speed it up
-	#self.connect(self.u, s2v, fft, c2mag, log, stats)
-	self.connect(self.u, s2v, fft, c2mag, stats)
-
-        if options.gain is None:
-            # if no gain was specified, use the mid-point in dB
-            g = self.subdev.gain_range()
-            options.gain = float(g[0]+g[1])/2
-
-        self.set_gain(options.gain)
-	print "gain =", options.gain
-
-
-    def set_next_freq(self):
-        target_freq = self.next_freq
-        self.next_freq = self.next_freq + self.freq_step
-        if self.next_freq >= self.max_center_freq:
-            self.next_freq = self.min_center_freq
-
-        if not self.set_freq(target_freq):
-            print "Failed to set frequency to", target_freq
-
-        return target_freq
-                          
-
-    def set_freq(self, target_freq):
-        """
-        Set the center frequency we're interested in.
-
-        @param target_freq: frequency in Hz
-        @rypte: bool
-
-        Tuning is a two step process.  First we ask the front-end to
-        tune as close to the desired frequency as it can.  Then we use
-        the result of that operation and our target_frequency to
-        determine the value for the digital down converter.
-        """
-        return self.u.tune(0, self.subdev, target_freq)
-
-
-    def set_gain(self, gain):
-        self.subdev.set_gain(gain)
-
-    def set_min_max_freq(self,minimum,maximum):# setting min and max frequency 
-	self.min_freq = float(minimum) 
-        self.max_freq = float(maximum)
-
-    def get_avg_power(self,trials):
-	power_sum = 0 #sum of powers(each power value is determined by adding the 'fft square' points..these fft square points are essentially points from  the PSD curve...and adding them gives us the power contained in the spectrum)
-        counter = 0
-	_trials = int(trials)
-    	while counter < _trials :
-
-   		# Get the next message sent from the C++ code (blocking call).
-    		# It contains the center frequency and the mag squared of the fft
-    		m = parse_msg(self.msgq.delete_head())
-    		print "printing mag sq of fft ",sum(m.data),"\n"
-    		#if sum(m.data) > 1e12:
-		power_sum = power_sum + sum(m.data)
-        	# Print center freq so we know that something is happening...
-        	#print m.center_freq
-		counter +=1
-        	# FIXME do something useful with the data...
-        
-        	# m.data are the mag_squared of the fft output (they are in the
-       		# standard order.  I.e., bin 0 == DC.)
-        	# You'll probably want to do the equivalent of "fftshift" on them
-        	# m.raw_data is a string that contains the binary floats.
-        	# You could write this as binary to a file.
-
-    	avg_power = power_sum/_trials
-    	print "printing average power ",avg_power,"\n"
-	return avg_power
-
-######################## end of spectrum sense specific classes #############################################################
+	
+	########connect for the spectrum sense#########
+	default_min_freq = 462.4825e6 #80 Khz to the left of channel 1 (462.5625e6) in frs band 
+    	default_max_freq = 462.6425e6 #80 Khz to the right of channel 1 (462.5625e6) in frs band 
+	self.sp_sense_path = spec_sense_path.spec_sense_top_block(default_min_freq,default_min_freq)
+	self.connect(self.sp_sense_path.u, self.sp_sense_path.s2v, self.sp_sense_path.fft, self.sp_sense_path.c2mag, self.sp_sense_path.stats)
+	#self.connect(self.txpath);
+	#self.connect(self.rxpath);
 
 	
@@ -362,7 +132,9 @@
         sys.exit(1)
     ############# Setting some default values for tx side of the block
-    options_tx.tx_freq = 462.5625e6 #setting default tx_freq value
+    options_tx.tx_freq = 462.5625e6 
     options_tx.samples_per_symbol =  2
     options_tx.modulation = 'dbpsk'
+    options_tx.fusb_block_size = 4096
+    options_tx.fusb_nblocks = 16
     #############
     if options_tx.tx_freq is None:
@@ -409,4 +181,6 @@
     options_rx.samples_per_symbol =  2
     options_rx.modulation = 'dbpsk'
+    options_rx.fusb_block_size = 4096
+    options_rx.fusb_nblocks = 16
     #############
     if options_rx.rx_freq is None:
@@ -420,12 +194,11 @@
     ######################## adding another top block for usrp spectrum sense ########################
     trials = 10
-    default_min_freq = 462.4825e6 #80 Khz to the left of channel 1 (462.5625e6) in frs band 
-    default_max_freq = 462.6425e6 #80 Khz to the right of channel 1 (462.5625e6) in frs band 
-    tb_spec_sense = spec_sense_top_block(default_min_freq,default_min_freq)
-    tb_spec_sense.subdev.select_rx_antenna('RX2')
-    tb_spec_sense.start()              # start executing flow graph in another thread...
-    avg = tb_spec_sense.get_avg_power(trials)
-    print "printing the average power ",avg, "\n"
-    tb_spec_sense.stop()   
+    
+    #tb_spec_sense = spec_sense_top_block(default_min_freq,default_min_freq)
+    #tb_spec_sense.subdev.select_rx_antenna('RX2')
+    #tb_spec_sense.start()              # start executing flow graph in another thread...
+    #avg = tb_spec_sense.get_avg_power(trials)
+    #print "printing the average power ",avg, "\n"
+    #tb_spec_sense.stop()   
     
 
