Index: /vtcross/branches/sriram/benchmark_txrxnode1.py
===================================================================
--- /vtcross/branches/sriram/benchmark_txrxnode1.py	(revision 339)
+++ /vtcross/branches/sriram/benchmark_txrxnode1.py	(revision 356)
@@ -36,11 +36,4 @@
         self.rxpath = receive_path(demod_class, rx_callback, options_rx)
 	self.txpath = transmit_path(mod_class, options_tx)
-	
-	########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);
@@ -63,7 +56,7 @@
         #print "inside rx callback"
         global n_rcvd, n_right, sync_status,mode,hop_freq
-	tb.rxpath.min_freq = hop_freq - 80e3 
-        tb.rxpath.max_freq = hop_freq + 80e3 
-	tb.rxpath.get_avg_power(10)
+	#tb.rxpath.min_freq = hop_freq - 80e3 
+        #tb.rxpath.max_freq = hop_freq + 80e3 
+	#tb.rxpath.get_spec_stats(1e13,20,2)
         (pktno,) = struct.unpack('!H', payload[0:2])
         #temp = struct.unpack('!s', payload[3:10])
@@ -89,6 +82,6 @@
                     			#data = 'o'+'o'+str(data_channel)+str(data_channel)
                     			#print "sending this data",data,"@@@@@\n"
-                    			#pktno=0
-                    			#ack_payload = struct.pack('!H', pktno & 0xffff) + data
+                    			#sync_pktno=0
+                    			#ack_payload = struct.pack('!H', sync_pktno & 0xffff) + data
                     			#print "printing the ack packet",ack_payload,"$$$$$\n"
                     			#k=0
@@ -199,19 +192,4 @@
 
 
-
-    ######################## adding another top block for usrp spectrum sense ########################
-    #This is not needed anymore
-    #trials = 10
-    
-    #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()   
-    
-
-    ##################################################################################################
-
     # build the graph
 
@@ -225,5 +203,5 @@
 
     tb.start()
-    #tb.rxpath.get_avg_power(10) #10 is the number of fft frames that we are looking at to determine the average power
+    #tb.rxpath.get_spec_stats(10) #10 is the number of fft frames that we are looking at to determine the average power
     # generate and send packets
     #print "printing megamytes",options_tx.megabytes,"  $$$$\n"
@@ -246,67 +224,115 @@
     running = True
     #resend_count= 0 #initializing resend count
-    #while running
-    if mode  == "sync":
-    	#nbytes = int(1e6 * .0003)
-	#nbytes = int(1e6 * .0003)
-	nbytes = 6
-    	pkt_size = 6
-    	print "printing packet size",pkt_size,"pkt size\n"
-    	while sync_status != True:
-		#ch = random.randint(1, 7)
-		#ch = int(random.choice('17'))
-		#ch = random.randint(6,12)
-		ch = 1
-	    	hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets
-		print "hop freq is ",hop_freq
-		
-		#hop_freq = float(1e6 * (462.5625+(5-1)*0.05))#setting the centre freq frequency for sending packets
-	    	tb.txpath.set_freq(hop_freq)
-	    	tb.rxpath.set_freq(hop_freq)
-        	#print "inside while pppp printing sync channel",sync_status,"  done"
-		#if sync_status == "True":
-            	#print "synchronization done..data channel is found"
-	    	#break
-		#else:
-	    	#print "inside else1"
-	    	n = 0
-	    	pktno = 0
-		print >> myfile, "out"
-    	    	while n < nbytes:
-                        print >> myfile, "inside while"
-                	if options_tx.from_file is None:
-                    		#data = (pkt_size - 2) * chr(pktno & 0xff) #0xff is 255
-                    		data = 's'+'s'+str(ch)+str(ch) #adding redundant bits for sync and channel
-	            		#print >> myfile, data
-                    		#print "printing data",data,"****\n"
+    sync_pktno = 0
+    ch = int(random.choice('17'))
+    while running:
+    	if mode == "sync":
+    		#nbytes = int(1e6 * .0003)
+		#nbytes = int(1e6 * .0003)
+		nbytes = 6
+    		pkt_size = 6
+		data_pktno = 0 
+    		print "printing packet size",pkt_size,"pkt size\n"
+    		while sync_status != True:
+			#ch = random.randint(1, 7)
+			ch = int(random.choice('17'))
+			
+			#ch = random.randint(6,12)
+			#ch = 1
+		    	hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets
+			tb.rxpath.min_freq = hop_freq - 80e3 
+    		    	tb.rxpath.max_freq = hop_freq + 80e3 
+			is_present = tb.rxpath.get_spec_stats(1e13,1) #check if primary user is present
+			if is_present == True: #if primary user is there then dont transmit on this channel
+				continue 
+					
+			#print "printing status ",status,"\n"
+			#print "primary user present = ",is_present,"\n"
+			#tb.rxpath.get_spec_stats(10)  
+			print "hop freq is ",hop_freq
+			
+			#hop_freq = float(1e6 * (462.5625+(5-1)*0.05))#setting the centre freq frequency for sending packets
+	    		tb.txpath.set_freq(hop_freq)
+	    		tb.rxpath.set_freq(hop_freq)
+        		#print "inside while pppp printing sync channel",sync_status,"  done"
+			#if sync_status == "True":
+            		#print "synchronization done..data channel is found"
+	    		#break
+			#else:
+	    		#print "inside else1"
+	    		n = 0
+	    		
+			print >> myfile, "out"
+    	    		while n < nbytes:
+                	        print >> myfile, "inside while"
+                		if options_tx.from_file is None:
+                	    		#data = (pkt_size - 2) * chr(sync_pktno & 0xff) #0xff is 255
+                	    		data = 's'+'s'+str(ch)+str(ch) #adding redundant bits for sync and channel
+	        	    		#print >> myfile, data
+                	    		#print "printing data",data,"****\n"
+                		else:
+            		    		data = source_file.read(pkt_size - 2)
+            		    		if data == '':
+                	        		break;
+	
+                		payload = struct.pack('!H', sync_pktno & 0xffff) + data
+	       			#print "printing payload",payload,"**\n"
+				
+                		send_pkt(tb,payload)
+				#print "printing payload",payload,"**\n"
+                		n += len(payload)
+                		sys.stderr.write('.')
+                		if options_tx.discontinuous and sync_pktno % 5 == 4:
+                	    		time.sleep(1)
+                		sync_pktno += 1
+	    			#print "before sleeping for 10 seconds and value of resend count is",resend_count
+	
+
+	            	time.sleep(0.05)
+			#time.sleep(2)
+	            	#resend_count += 1 
+	    
+		print "sync channel found! and it is channel ",ch,"\n"
+	    	mode = "traffic"
+	   	 #send_pkt(tb,eof=True)
+	    	#myfile.close()
+	    	#tb.wait()
+
+    	if mode == "traffic":
+		nbytes = 16
+    	    	pkt_size = 16
+		sync_pktno = 0
+		while n < nbytes:
+                	#print >> myfile, "inside while"
+               		if options_tx.from_file is None:
+                 		#data = (pkt_size - 2) * chr(data_pktno & 0xff) #0xff is 255
+                		data = 'Hi how are you' #Sending this message
+	        		#print >> myfile, data
+                		#print "printing data",data,"****\n"
                 	else:
-            	    		data = source_file.read(pkt_size - 2)
-            	    		if data == '':
-                        		break;
-
-                	payload = struct.pack('!H', pktno & 0xffff) + data
+            		    	data = source_file.read(pkt_size - 2)
+            		    	if data == '':
+                	        	break;
+	
+                	payload = struct.pack('!H', data_pktno & 0xffff) + data
 	       		#print "printing payload",payload,"**\n"
-			
+				
                 	send_pkt(tb,payload)
 			#print "printing payload",payload,"**\n"
                 	n += len(payload)
                 	sys.stderr.write('.')
-                	if options_tx.discontinuous and pktno % 5 == 4:
-                    		time.sleep(1)
-                	pktno += 1
+                	if options_tx.discontinuous and data_pktno % 5 == 4:
+                		time.sleep(1)
+                	data_pktno += 1
 	    		#print "before sleeping for 10 seconds and value of resend count is",resend_count
-
-		tb.rxpath.min_freq = hop_freq - 80e3 
-        	tb.rxpath.max_freq = hop_freq + 80e3 
-		tb.rxpath.get_avg_power(10) #10 is the number of fft frames that we are looking at to determine the average power
-
-            	time.sleep(0.05)
-		#time.sleep(2)
-            	#resend_count += 1 
-    print "sync channel found! and it is channel ",ch,"\n"
-    send_pkt(tb,eof=True)
-    #myfile.close()
-    tb.wait()
-    
+			#time.sleep(0.1)
+			tb.rxpath.min_freq = hop_freq - 80e3 
+    		    	tb.rxpath.max_freq = hop_freq + 80e3 
+			is_present = tb.rxpath.get_spec_stats(1e13,10) #check if primary user is present
+			if is_present == True: #if primary user is present then get out of this communication channel, back to sync mode.
+				mode = "sync"
+				
+				
+
 
 
