root/vtcross/branches/sriram/power_check.py @ 362

Revision 362, 5.9 KB (checked in by sriram, 15 years ago)

correcting syntax errors

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#Transmission and reception, one ata a time on the same antena
3
4from gnuradio import gr, gru, modulation_utils
5from gnuradio import eng_notation
6from gnuradio.eng_option import eng_option
7from optparse import OptionParser
8from numpy import random
9import random, time, struct, sys, math
10import traceback
11# from current dir
12from transmit_path import transmit_path
13from receive_path import receive_path
14
15class my_top_block(gr.top_block):
16
17    def __init__(self, mod_class, demod_class,
18                 rx_callback, options_tx,options_rx):
19
20        gr.top_block.__init__(self)
21        self.rxpath = receive_path(demod_class, rx_callback, options_rx)
22        self.txpath = transmit_path(mod_class, options_tx)
23        self.connect(self.txpath);
24        self.connect(self.rxpath);
25
26
27def main():
28
29    def rx_callback(ok, payload):
30        #print "inside rx callback"
31        global n_rcvd, n_right, sync_status,mode,hop_freq
32
33
34
35    mods = modulation_utils.type_1_mods()
36    demods = modulation_utils.type_1_demods()
37
38    #setting up the tx options parser
39    parser_tx = OptionParser(option_class=eng_option, conflict_handler="resolve")
40    expert_grp_tx = parser_tx.add_option_group("Expert_tx")
41    print "printing Expert_tx group",expert_grp_tx,"printing Expert_tx group"
42    parser_tx.add_option("-m", "--modulation", type="choice", choices=mods.keys(),
43                      default='gmsk',
44                      help="Select modulation from: %s [default=%%default]"
45                            % (', '.join(mods.keys()),))
46
47    parser_tx.add_option("-s", "--size", type="eng_float", default=1500,
48                      help="set packet size [default=%default]")
49    parser_tx.add_option("-M", "--megabytes", type="eng_float", default=1.0,
50                      help="set megabytes to transmit [default=%default]")
51    parser_tx.add_option("","--discontinuous", action="store_true", default=False,
52                      help="enable discontinous transmission (bursts of 5 packets)")
53    parser_tx.add_option("","--from-file", default=None,
54                      help="use file for packet contents")
55    print "printing parser_tx",parser_tx,"printing parser_tx"
56    transmit_path.add_options(parser_tx, expert_grp_tx)
57
58    for mod in mods.values():
59        mod.add_options(expert_grp_tx)
60
61    (options_tx, args_tx) = parser_tx.parse_args ()
62
63    if len(args_tx) != 0:
64        parser_tx.print_help()
65        sys.exit(1)
66    ############# Setting some default values for tx side of the block
67    options_tx.tx_freq = 462.5625e6
68    options_tx.samples_per_symbol =  2
69    options_tx.modulation = 'dbpsk'
70    options_tx.fusb_block_size = 4096
71    options_tx.fusb_nblocks = 16
72    options_tx.bitrate = 0.0125e6
73    #############
74    if options_tx.tx_freq is None:
75        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
76        parser_tx.print_help(sys.stderr)
77        sys.exit(1)
78
79    if options_tx.from_file is not None:
80        source_file = open(options_tx.from_file, 'r')
81    print "printing modulation type",mods[options_tx.modulation],"**"
82    # build the graph
83    print "printing tx options",options_tx,"&&&&\n"
84    #tb = my_top_block(mods[options_tx.modulation], options_tx)
85
86    #r = gr.enable_realtime_scheduling()
87    #if r != gr.RT_OK:
88    #   print "Warning: failed to enable realtime scheduling"
89
90    #setting up rx options parser
91   
92    # Create Options Parser:
93    parser_rx = OptionParser (option_class=eng_option, conflict_handler="resolve")
94    print "printing parser_rx",parser_rx,"!!!!!\n"
95    print "after option parser"
96    expert_grp_rx = parser_rx.add_option_group("Expert_rx")
97    print "printing expert group rx",expert_grp_rx,"@@@@\n"
98    parser_rx.add_option("-m", "--modulation", type="choice", choices=demods.keys(),
99                      default='gmsk',
100                      help="Select modulation from: %s [default=%%default]"
101                            % (', '.join(demods.keys()),))
102    print "inside rx option parser"
103    receive_path.add_options(parser_rx, expert_grp_rx)
104
105    for mod in demods.values():
106        mod.add_options(expert_grp_rx)
107
108    (options_rx, args_rx) = parser_rx.parse_args ()
109
110    if len(args_rx) != 0:
111        parser_rx.print_help(sys.stderr)
112        sys.exit(1)
113    ############# Setting some default values for rx side of the block
114    options_rx.rx_freq = 462.5625e6 #setting default rx_freq value
115    options_rx.samples_per_symbol =  2
116    options_rx.modulation = 'dbpsk'
117    options_rx.fusb_block_size = 4096
118    options_rx.fusb_nblocks = 16
119    options_rx.bitrate = 0.0125e6
120    #############
121    if options_rx.rx_freq is None:
122        sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")
123        parser_rx.print_help(sys.stderr)
124        sys.exit(1)
125    print "printing rx options",options_rx,"&&&&\n"
126
127
128
129    ######################## adding another top block for usrp spectrum sense ########################
130    #This is not needed anymore
131    #trials = 10
132   
133    #tb_spec_sense = spec_sense_top_block(default_min_freq,default_min_freq)
134    #tb_spec_sense.subdev.select_rx_antenna('RX2')
135    #tb_spec_sense.start()              # start executing flow graph in another thread...
136    #avg = tb_spec_sense.get_avg_power(trials)
137    #print "printing the average power ",avg, "\n"
138    #tb_spec_sense.stop()   
139   
140
141    ##################################################################################################
142
143    # build the graph
144
145    tb = my_top_block(mods[options_tx.modulation],
146                     demods[options_rx.modulation],
147                     rx_callback,options_tx,
148                     options_rx)
149    r = gr.enable_realtime_scheduling()
150    if r != gr.RT_OK:
151       print "Warning: failed to enable realtime scheduling"
152
153    tb.start()
154    hop_freq = 462.5625e6
155    while True:
156          tb.rxpath.min_freq = hop_freq - 80e3
157          tb.rxpath.max_freq = hop_freq + 80e3
158          tb.rxpath.get_spec_stats(1e13,1)
159          time.sleep(0.4)
160
161
162
163
164
165
166if __name__ == '__main__':
167    #try:
168        main()
169    #except KeyboardInterrupt:
170     #   pass
Note: See TracBrowser for help on using the browser.