Index: /vtcross/branches/sriram/dsa.py
===================================================================
--- /vtcross/branches/sriram/dsa.py	(revision 384)
+++ /vtcross/branches/sriram/dsa.py	(revision 385)
@@ -13,7 +13,11 @@
 from transmit_path import transmit_path
 from receive_path import receive_path
-global sync_status,mode,ch,traffic_flag
+
+global sync_status,mode,ch,traffic_flag,n_rcvd, n_right
 sync_status = False
-mode = "sync"#default mode is sync
+#Defining modes of operation
+# sync: the two nodes are trying to rendezvous on a common channel
+# traffic: the two node are communicating information to each other
+mode = "sync" #Default mode is sync
 traffic_flag = False
 class my_top_block(gr.top_block):
@@ -28,8 +32,7 @@
 		self.connect(self.rxpath);
 
-global n_rcvd, n_right
 
 def main():
-	print "inside main"
+
    	global n_rcvd, n_right,sync_status,mode,ch,traffic_flag,n_attempts,return_flag
     	n_rcvd = 0
@@ -37,4 +40,5 @@
 	n_attempts = 5
 	return_flag = 0
+
     	def send_pkt(self, payload='', eof=False):
         	return self.txpath.send_pkt(payload, eof)
@@ -52,7 +56,7 @@
 
 	def rx_callback(ok, payload):
-		print "inside rx callback\n"
+		
 		global n_rcvd, n_right,sync_status,mode,ch,traffic_flag
-    		##############################################################
+    		########################## sync ####################################
 		if mode == "sync":
 			if ok:
@@ -60,24 +64,22 @@
        				(sync_signal,) = struct.unpack('!s', payload[2]) 
         			(data_channel,) = struct.unpack('!H', payload[3:5])
-        			print "printing the elements of packet  ",sync_signal,"  !!!!!!!!!!!  ",data_channel," !!!!!\n"  
-				  
+        							  
         			if str(sync_signal) == 'o' and str(data_channel) == str(ch):
-        				#print "inside if2"
-        				sync_status = True
+        				
+					sync_status = True
 					#tb.stop()
-					#print "after tb stop ans sync status is ",sync_status," sync status\n"
-                   		
+					                   		
 				if str(sync_signal) == 's' and str(data_channel) == str(ch): 
+					
 					sync_status = True
-					print "received a sync packet on channel %s\n" %(data_channel)
-	       				data = 'o'
+					data = 'o'
                				pktno=0
 	       				ack_payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data
 		      			send_pkt(tb,ack_payload) #sending back the acknowledgement
-			else:
-				print "sync packet not ok\n"
-		##############################################################
+			#else:
+			#	print "sync packet not ok\n"
+		###################################################################
     		
-		######################### traffic ############################
+		######################### traffic #################################
 		if mode == "traffic":
 			if ok: 
@@ -86,15 +88,10 @@
 					traffic_flag = True
 					comm = struct.unpack('!14s', payload[1:15])
-					print("received this ", comm) 
 					data = 'dI am fine.....' #Sending this message
 					payload = struct.pack('!15s', data)
 					send_pkt(tb,payload)
 				
-				#(data_header,) = struct.unpack('!s', payload[0])
-				#if data_header == 'd':
-				#	comm = struct.unpack('!14s', payload[1:15])
-				#	print("received this ", comm) 
-			else:
-				print "data packet not ok\n"
+			#else:
+			#	print "data packet not ok\n"
 		##############################################################
 
@@ -105,15 +102,15 @@
         	#print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
         	#    ok, pktno, n_rcvd, n_right)
-		#print "sync_status is ",sync_status," @@\n"
+		
 
     	mods = modulation_utils.type_1_mods()
-    	#print "printing mods",mods,"$$$$\n"
     	demods = modulation_utils.type_1_demods()
 
     	#setting up the tx options parser
+
     	parser_tx = OptionParser(option_class=eng_option, conflict_handler="resolve")
     	expert_grp_tx = parser_tx.add_option_group("Expert_tx")
-    	#print "printing Expert_tx group",expert_grp_tx,"printing Expert_tx group"
-   	parser_tx.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
+
+    	parser_tx.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
                       	default='gmsk',
                       	help="Select modulation from: %s [default=%%default]"
@@ -128,5 +125,5 @@
     	parser_tx.add_option("","--from-file", default=None,
                       	help="use file for packet contents")
-    	print "printing parser_tx",parser_tx,"printing parser_tx"
+    	
     	transmit_path.add_options(parser_tx, expert_grp_tx)
 
@@ -156,18 +153,12 @@
     	if options_tx.from_file is not None:
         	source_file = open(options_tx.from_file, 'r')
-    	print "printing modulation type",mods[options_tx.modulation],"**"
-    	# build the graph
-    	print "printing tx options",options_tx,"&&&&\n"
-    
+    	    
     	parser_rx = OptionParser (option_class=eng_option, conflict_handler="resolve")
-    	print "printing parser_rx",parser_rx,"!!!!!\n"
-    	print "after option parser"
     	expert_grp_rx = parser_rx.add_option_group("Expert_rx")
-    	print "printing expert group rx",expert_grp_rx,"@@@@\n"
     	parser_rx.add_option("-m", "--modulation", type="choice", choices=demods.keys(),
                       	default='gmsk',
                       	help="Select modulation from: %s [default=%%default]"
                             	% (', '.join(demods.keys()),))
-    	print "inside rx option parser"
+    	
     	receive_path.add_options(parser_rx, expert_grp_rx)
 
@@ -193,6 +184,5 @@
         	parser_rx.print_help(sys.stderr)
         	sys.exit(1)
-    	print "printing rx options",options_rx,"&&&&\n"
-
+    	
 	# build the graph
 
@@ -206,10 +196,7 @@
     
     	tb.start()
-    	#tb.rxpath.disconnect(tb.rxpath.u, tb.rxpath.s2v,tb.rxpath.fft, tb.rxpath.c2mag, tb.rxpath.stats)
-    	#tb.rxpath.connect(tb.rxpath.u, tb.rxpath.s2v)
+
     	#listening to random frequencies untill a match is found
     	running = True
-    	global ch
-	running = True
     	ch_energy = tb.rxpath.probe.level() #setting initial value
 	hop_freq = options_tx.tx_freq #  = options_rx.rx_freq...same for tx and rx side
@@ -231,9 +218,6 @@
 				ch_energy = tb.rxpath.probe.level() #check if primary user is present
 				
-				print "printing hop frequency ",hop_freq,"and energy is ",ch_energy,"\n"
 				if int(ch_energy) > 1.5e8: #if primary user is there then dont transmit on this channel
-					#while 
 					continue
-					#print "present"
 				
 	    			nbytes = 5 #int(1e6 * .0003)
@@ -243,6 +227,5 @@
     	    			while n < nbytes:
                 			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
+                    				data = 's'
 	        			else:
             	    				data = source_file.read(pkt_size - 2)
@@ -251,9 +234,7 @@
 
                 			payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data
-	        			#print "printing payload",payload,"**\n"
-	
+	        				
                 			send_pkt(tb,payload)
-					print "sending this data ",data,"\n"
-                			n += len(payload)
+					n += len(payload)
                 			sys.stderr.write('.')
                 			if options_tx.discontinuous and pktno % 5 == 4:
@@ -261,5 +242,5 @@
                 				pktno += 1
 	    			time.sleep(0.1)
-            		#resend_count += 1 
+            		
 			else:
 				print "sync channel found..channel ",ch,"\n"  
@@ -274,6 +255,5 @@
 		################################################Communications mode#################################
 		if mode == "traffic":
-			print "Inside traffic mode"
-					
+							
 			nbytes = 15
     	    		pkt_size = 15
@@ -281,10 +261,8 @@
 			n = 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 = 'dHi how are you' #Sending this message
-	        			#print >> myfile, data
-                			#print "printing data",data,"****\n"
+                 			data = 'dHi how are you' #Sending this message
+	        			
                 		else:
             		    		data = source_file.read(pkt_size - 2)
@@ -294,8 +272,7 @@
 			
                 		payload = struct.pack('!15s', data)
-	       			#print "printing payload",payload,"**\n"
-				
+	       							
                 		send_pkt(tb,payload)
-				print "printing payload",data,"**\n"
+				#print "printing payload",data,"**\n"
                 		n += len(payload)
                 		sys.stderr.write('.')
@@ -303,6 +280,5 @@
                 			time.sleep(1)
                 		data_pktno += 1
-	    			#print "before sleeping for 10 seconds and value of resend count is",resend_count
-				time.sleep(0.2 + 0.05*int(random.choice([0,1,2,3])))
+	    			time.sleep(0.2 + 0.05*int(random.choice([0,1,2,3])))
 
 				if traffic_flag != True:
@@ -313,13 +289,13 @@
 
 				ch_energy = tb.rxpath.probe.level() #check if primary user is present
-				print "channel energy is ",ch_energy,"\n"
+				
             			if int(ch_energy) > 1.5e8: #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 "primary user detected..moving out of this channel\n"
 					mode = "sync"
 					return_flag = 1
                 
-
 
 if __name__ == '__main__':
