Index: vtcross/branches/sriram/benchmark_txrxnode2.py
===================================================================
--- vtcross/branches/sriram/benchmark_txrxnode2.py	(revision 320)
+++ vtcross/branches/sriram/benchmark_txrxnode2.py	(revision 320)
@@ -0,0 +1,255 @@
+#!/usr/bin/env python
+#Transmission and reception, one ata a time on the same antena
+
+from gnuradio import gr, gru, modulation_utils
+from gnuradio import eng_notation
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+from numpy import random
+import random, time, struct, sys, math
+import traceback
+# from current dir
+from transmit_path import transmit_path
+from receive_path import receive_path
+global sync_status
+sync_status=False
+
+class my_top_block(gr.top_block):
+
+    def __init__(self, mod_class, demod_class,
+                 rx_callback, options_tx,options_rx):
+
+        gr.top_block.__init__(self)
+        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);
+   
+#//////main////// 
+
+global n_rcvd, n_right,ch
+
+def main():
+    global n_rcvd, n_right,sync_status,pktno1,ch
+    pktno1 =0
+    n_rcvd = 0
+    n_right = 0
+    def send_pkt(self, payload='', eof=False):
+        return self.txpath.send_pkt(payload, eof)
+
+    def rx_callback(ok, payload):
+        global n_rcvd, n_right,sync_status,pktno1,ch
+        #(pktno,) = struct.unpack('!H', payload[0:2])
+        print "inside rx callback"
+        if ok == True:
+	    (sync_signal,) = struct.unpack('!s', payload[2])  
+            (sync_signal_red,) = struct.unpack('!s', payload[3])  #redundant sync bit
+            (data_channel,) = struct.unpack('!s', payload[4])
+            (data_channel_red,) = struct.unpack('!s', payload[5])  #redundant channel bit
+	    print "printing the elements of packet  ",str(sync_signal),"  !!!!!!!!!!!  ",str(sync_signal_red)," !!!!!\n"     
+            print "printing the channel  ",str(data_channel_red),"  !!!!!!!!!!!  ",str(data_channel_red)," !!!!!\n"
+	    #if str(sync_signal) == 's' and str(sync_signal_red) == 's' and str(data_channel) == str(data_channel_red):
+	    if str(data_channel) == str(ch):
+            	#print "inside if"
+            	sync_status = True
+		#tb.stop()
+                #print "received a sync packet on channel %s\n" %(data_channel)
+	        data = str('o'+'o'+str(data_channel)+str(data_channel))
+                #print "sending this data",data,"@@@@@\n"
+		#pktno1=0
+	        ack_payload = struct.pack('!H', pktno1 & 0xffff) + data
+		pktno1+=1
+		#print "printing ack packet and sent pkt no ",ack_payload," ",pktno1,"\n"
+		#print "printing the 3rd byte ",struct.unpack('!s', ack_payload[2]) ," \n"
+                #k=0
+                #while k < 10000:
+		#print "inside while"
+	        send_pkt(tb,ack_payload) #sending back the acknowledgement
+		#send_pkt(tb,ack_payload) #sending back the acknowledgement
+		#send_pkt(tb,ack_payload) #sending back the acknowledgement
+		#send_pkt(tb,ack_payload) #sending back the acknowledgement
+		#send_pkt(tb,ack_payload) #sending back the acknowledgement
+		#send_pkt(tb,ack_payload) #sending back the acknowledgement
+		#send_pkt(tb,ack_payload) #sending back the acknowledgement
+		
+                #k=k+1
+ 		    
+        n_rcvd += 1
+        if ok:
+            n_right += 1
+
+        #print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % (
+        #    ok, pktno, n_rcvd, n_right)
+        #print "ok = %5s  n_rcvd = %4d  n_right = %4d" % (
+#            ok, 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(),
+                      default='gmsk',
+                      help="Select modulation from: %s [default=%%default]"
+                            % (', '.join(mods.keys()),))
+
+    parser_tx.add_option("-s", "--size", type="eng_float", default=1500,
+                      help="set packet size [default=%default]")
+    parser_tx.add_option("-M", "--megabytes", type="eng_float", default=1.0,
+                      help="set megabytes to transmit [default=%default]")
+    parser_tx.add_option("","--discontinuous", action="store_true", default=False,
+                      help="enable discontinous transmission (bursts of 5 packets)")
+    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)
+
+    for mod in mods.values():
+        mod.add_options(expert_grp_tx)
+
+    (options_tx, args_tx) = parser_tx.parse_args ()
+
+    if len(args_tx) != 0:
+        parser_tx.print_help()
+        sys.exit(1)
+
+    if options_tx.tx_freq is None:
+        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
+        parser_tx.print_help(sys.stderr)
+        sys.exit(1)
+
+    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"
+    #tb = my_top_block(mods[options_tx.modulation], options_tx)
+
+    #r = gr.enable_realtime_scheduling()
+    #if r != gr.RT_OK:
+    #   print "Warning: failed to enable realtime scheduling"
+
+    #setting up rx options parser
+   
+    # Create Options Parser:
+    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)
+
+    for mod in demods.values():
+        mod.add_options(expert_grp_rx)
+
+    (options_rx, args_rx) = parser_rx.parse_args ()
+
+    if len(args_rx) != 0:
+        parser_rx.print_help(sys.stderr)
+        sys.exit(1)
+
+    if options_rx.rx_freq is None:
+        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
+        parser_rx.print_help(sys.stderr)
+        sys.exit(1)
+    print "printing rx options",options_rx,"&&&&\n"
+    #options_rx.decim=128    #setting the decimation for receive path
+    
+# build the graph  
+
+    tb = my_top_block(mods[options_tx.modulation],
+                      demods[options_rx.modulation],
+                      rx_callback,options_tx,
+                      options_rx)
+    r = gr.enable_realtime_scheduling()
+    if r != gr.RT_OK:
+        print "Warning: failed to enable realtime scheduling"
+    print "printing the decimation ",options_rx.decim,"\n"
+    tb.start()
+    #listening to random frequencies untill a match is found
+    check = True
+    global ch
+    while check:
+    	if sync_status != True:
+        	#print "inside while"
+        	#ch = random.randint(1, 7)
+		ch = int(random.choice('17'))
+		#ch = random.randint(6, 12)
+		#ch = 1
+        	#hop_freq = float(1e6 * (400+(ch-1)*10))#setting the centre freq frequency for sending packets
+		hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))
+		#hop_freq = float(1e6 * (462.5625+(5-1)*0.05))
+        	print "hop freq is",hop_freq,"@@@@\n"
+        	tb.txpath.set_freq(hop_freq)
+        	tb.rxpath.set_freq(hop_freq)
+		time.sleep(0.05)
+		#time.sleep(2)
+	else:
+		print "inside lese of while check"
+		#tb.stop()
+		break
+    temp_variable = 2
+    if temp_variable == 2:
+        print "success"
+    
+    print "sync channel is found! and it is channel ",ch," \n"  
+    #var2  = 2
+    #if var2 ==2:
+    #    print "just checking this bug"
+    
+ 
+    # generate and send packets
+    #print "printing megamytes",options_tx.megabytes,"  $$$$\n"
+    #myfile = file("log.txt", 'w')
+    #traceback.print_tb(traceback,None,myfile)
+
+    #tb.wait()
+    tb.stop()
+
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+   
+
+
+
+
