Index: vtcross/trunk/src/cross-examples/python/gnuradio-examples/benchmark_dsa.py
===================================================================
--- vtcross/trunk/src/cross-examples/python/gnuradio-examples/benchmark_dsa.py	(revision 505)
+++ vtcross/trunk/src/cross-examples/python/gnuradio-examples/benchmark_dsa.py	(revision 506)
@@ -43,10 +43,5 @@
     cross_import = False
 
-global sync_status,mode,ch,traffic_flag,n_rcvd, n_right
-global ticker_start,time_right_now #measuring duration over which no packet is sent
-ticker_start = datetime.now()
-#no_packet_stop_time = False
-global no_packet_period #allowed duration for no packet
-no_packet_period = 3
+global sync_status,mode,ch,data_packet_delivery_count,n_rcvd, n_right
 sync_status = False
 
@@ -55,5 +50,5 @@
 # traffic: the two node are communicating information to each other
 mode = "sync" #Default mode is sync
-traffic_flag = False
+data_packet_delivery_count = 0
 
 class my_top_block(gr.top_block):
@@ -72,9 +67,7 @@
 
     global stats_array, count_array, time_array, n_rcvd
-    global n_right, sync_status, mode, ch, traffic_flag
+    global n_right, sync_status, mode, ch, data_packet_delivery_count
     global n_attempts, return_flag, crossShellHost, crossShellPort
-    global ticker_start,time_right_now,no_packet_period
-
-   
+    data_packet_delivery_count_previous = 0
     n_rcvd = 0
     n_right = 0
@@ -175,9 +168,5 @@
     def rx_callback(ok, payload):
         
-        global n_rcvd, n_right,sync_status,mode,ch,traffic_flag,ticker_start
-
-	ticker_start = datetime.now()
-	#print "inside callback"
-	#print "ticker_start ",ticker_start
+        global n_rcvd, n_right,sync_status,mode,ch,data_packet_delivery_count
         ########################## sync ####################################
         if mode == "sync":
@@ -201,12 +190,8 @@
         ######################### traffic #################################
         if mode == "traffic":
-	
-	
-	
-		
             if ok: 
                 (data_header,) = struct.unpack('!s', payload[0])
                 if data_header == 'd':
-                    traffic_flag = True
+                    data_packet_delivery_count = data_packet_delivery_count +1
                     comm = struct.unpack('!14s', payload[1:15])
                     data = 'dI am fine.....' #Sending this message
@@ -329,5 +314,5 @@
         
     # build the graph
-	print "printing modulation scheme",demods[options_rx.modulation]
+
     tb = my_top_block(mods[options_tx.modulation],
                       demods[options_rx.modulation],
@@ -352,5 +337,5 @@
         ################################################sync mode####################################
         if mode == "sync":
-            if sync_status != True:
+	    if sync_status != True:
                     
                 if return_flag == 0:
@@ -394,5 +379,5 @@
                 n_attempts_counter = 0
                 mode = "traffic"
-                traffic_flag = False
+                data_packet_delivery_count = 0
                 sync_status="False"
                 start_time = datetime.now() #measuring the time for which the primary user is away
@@ -425,28 +410,23 @@
                 time.sleep(0.2 + 0.05*int(random.choice([0,1,2,3])))
 
-                if traffic_flag != True:
+                if data_packet_delivery_count == data_packet_delivery_count_previous: #checking if the data packet delivery has stagnated
                     n_attempts_counter += 1
                     if n_attempts_counter > n_attempts: #get out of the data channel as it seems that the other node is still trying to rendezvous
                         mode = "sync"
                         continue
-
-                #ch_energy = tb.rxpath.probe.level() #check if primary user is present
-		time_right_now = datetime.now()
-		#print "inside traffic , ticker_start",ticker_start
-                packet_delay = (time_right_now - ticker_start).seconds
-		#print "packet_delay ",packet_delay
-		if packet_delay >= no_packet_period:
-			stop_time = datetime.now()    
-                	_elapsed_time  = start_time - stop_time
-                	elapsed_time = _elapsed_time.seconds
-                	print "\n[[ No data packets:  Evacuating Current Channel ]]\n"
-                	print "\n[[ Scanning channels for network nodes ]]\n"
-                	mode = "sync"
-                	mode = "sync"
-                	return_flag = 1
-                
-
-		#if int(ch_energy) > 1.5e8: #if primary user is there then dont transmit on this channel
-                
+		else:
+		    data_packet_delivery_count_previous = 0
+		    data_packet_delivery_count = 0
+
+		data_packet_delivery_count_previous = data_packet_delivery_count
+                ch_energy = tb.rxpath.probe.level() #check if primary user is present
+                if int(ch_energy) > 1.8e8: #if primary user is there then dont transmit on this channel
+                    stop_time = datetime.now()    
+                    _elapsed_time  = start_time - stop_time
+                    elapsed_time = _elapsed_time.seconds
+                    print "\n[[ Primary User Detected:  Evacuating Current Channel ]]\n"
+                    print "\n[[ Scanning channels for network nodes ]]\n"
+                    mode = "sync"
+                    return_flag = 1
                 
 
