Index: /vtcross/branches/sriram/power_check.py
===================================================================
--- /vtcross/branches/sriram/power_check.py	(revision 349)
+++ /vtcross/branches/sriram/power_check.py	(revision 350)
@@ -13,14 +13,157 @@
 from receive_path import receive_path
 
+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);
+
+
 def main():
-	hop_freq = 462.5625e6
-	while True
-	    	tb.rxpath.min_freq = hop_freq - 80e3 
-    		tb.rxpath.max_freq = hop_freq + 80e3 
-		tb.rxpath.get_avg_power(10)
+
+    def rx_callback(ok, payload):
+        #print "inside rx callback"
+        global n_rcvd, n_right, sync_status,mode,hop_freq
+
+
+
+    mods = modulation_utils.type_1_mods()
+    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)
+    ############# Setting some default values for tx side of the block
+    options_tx.tx_freq = 462.5625e6 
+    options_tx.samples_per_symbol =  2
+    options_tx.modulation = 'dbpsk'
+    options_tx.fusb_block_size = 4096
+    options_tx.fusb_nblocks = 16
+    options_tx.bitrate = 0.0125e6
+    #############
+    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)
+    ############# Setting some default values for rx side of the block
+    options_rx.rx_freq = 462.5625e6 #setting default rx_freq value
+    options_rx.samples_per_symbol =  2
+    options_rx.modulation = 'dbpsk'
+    options_rx.fusb_block_size = 4096
+    options_rx.fusb_nblocks = 16
+    options_rx.bitrate = 0.0125e6
+    #############
+    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"
+
+
+
+    ######################## 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
+
+    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"
+
+    tb.start()
+    hop_freq = 462.5625e6
+    while True:
+	  tb.rxpath.min_freq = hop_freq - 80e3 
+    	  tb.rxpath.max_freq = hop_freq + 80e3 
+	  tb.rxpath.get_avg_power(10)
+
+
+
+
+
 
 if __name__ == '__main__':
-    try:
+    #try:
         main()
-    except KeyboardInterrupt:
-        pass
+    #except KeyboardInterrupt:
+     #   pass
