Index: /vtcross/branches/sriram/dsa.py
===================================================================
--- /vtcross/branches/sriram/dsa.py	(revision 378)
+++ /vtcross/branches/sriram/dsa.py	(revision 379)
@@ -30,4 +30,5 @@
 
 def main():
+	print "inside main"
    	global n_rcvd, n_right,sync_status,mode,ch,traffic_flag
     	n_rcvd = 0
@@ -77,5 +78,5 @@
        		n_rcvd += 1
         	if ok:
-            	n_right += 1
+            		n_right += 1
 
         	#print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
@@ -187,67 +188,78 @@
     	running = True
     	global ch
-
-	################################################sync mode####################################
-	if mode == "sync":
-		if sync_status != True:
-	    		ch = int(random.choice([1,7,8,14]))
-	    		if ch < 8:
-				hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets
-	    		else:
-				hop_freq = float(1e6 * (467.5625+(ch-8)*0.025))#setting the centre freq frequency for sending packets
+	running = True
+    
+   	while running:
+
+
+		################################################sync mode####################################
+		if mode == "sync":
+			if sync_status != True:
+	    			ch = int(random.choice([1,7,8,14]))
+	    			if ch < 8:
+					hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets
+	    			else:
+					hop_freq = float(1e6 * (467.5625+(ch-8)*0.025))#setting the centre freq frequency for sending packets
 	    		
 	    
-	    		tb.txpath.set_freq(hop_freq)
-	    		tb.rxpath.set_freq(hop_freq)
+	    			tb.txpath.set_freq(hop_freq)
+	    			tb.rxpath.set_freq(hop_freq)
         		
-			k = 0
-			total_energy = 0 
-			while k <  1:
-				ch_energy = tb.rxpath.probe.level() #check if primary user is present
-				total_energy = total_energy + ch_energy
-				k+=1
+				k = 0
+				total_energy = 0 
+				while k <  1:
+					ch_energy = tb.rxpath.probe.level() #check if primary user is present
+					total_energy = total_energy + ch_energy
+					k+=1
 			
-			avg_energy = total_energy/1
-			print "printing hop frequency ",hop_freq,"and energy is ",avg_energy,"\n"
-			if int(avg_energy) > 2e7: #if primary user is there then dont transmit on this channel
-				#while 
-				continue
-				#print "present"
+				avg_energy = total_energy/1
+				print "printing hop frequency ",hop_freq,"and energy is ",avg_energy,"\n"
+				if int(avg_energy) > 2e7: #if primary user is there then dont transmit on this channel
+					#while 
+					continue
+					#print "present"
 			
-			nbytes = 5 #int(1e6 * .0003)
-			pkt_size = 5
-	    		n = 0
-	    		pktno = 0
-    	    		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
-	        		else:
-            	    			data = source_file.read(pkt_size - 2)
-            	    			if data == '':
-                        			break;
-
-                		payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data
-	        		#print "printing payload",payload,"**\n"
+				nbytes = 5 #int(1e6 * .0003)
+				pkt_size = 5
+	    			n = 0
+	    			pktno = 0
+    	    			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
+	        			else:
+            	    				data = source_file.read(pkt_size - 2)
+            	    				if data == '':
+                        				break;
+
+                			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)
-                		sys.stderr.write('.')
-                		if options_tx.discontinuous and pktno % 5 == 4:
-                    			time.sleep(1)
-                			pktno += 1
-	    		time.sleep(0.1)
-            	#resend_count += 1 
-		else:
-			print "sync channel found..channel ",ch,"\n"  
-			mode = "traffic"
-			sync_status = False
+                			send_pkt(tb,payload)
+					#print "sending this data ",data,"\n"
+                			n += len(payload)
+                			sys.stderr.write('.')
+                			if options_tx.discontinuous and pktno % 5 == 4:
+                    				time.sleep(1)
+                				pktno += 1
+	    			time.sleep(0.1)
+            		#resend_count += 1 
+			else:
+				print "sync channel found..channel ",ch,"\n"  
+				mode = "traffic"
+				sync_status = False
+				break
 	################################################end of sync mode####################################
 
 
 
-
-
-
-
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass
+
+
+
+
+		
