Show
Ignore:
Timestamp:
07/29/09 16:10:39 (15 years ago)
Author:
trnewman
Message:

Fleshed out DSA reference implementation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/cognitive_engines/DSA_CE/examples/gnuradio-examples/dsa.py

    r390 r391  
    3939def main(): 
    4040 
    41         global n_rcvd, n_right,sync_status,mode,ch,traffic_flag,n_attempts,return_flag 
     41        global stats_array, count_array, time_array, n_rcvd, n_right,sync_status,mode,ch,traffic_flag,n_attempts,return_flag 
    4242        n_rcvd = 0 
    4343        n_right = 0 
    4444        n_attempts = 5 
    4545        return_flag = 0 
     46 
     47        count_array = [ 0, 0, 0, 0, 0] 
     48        time_array = [ 0, 0, 0, 0, 0] 
     49        stats_array = [ 0, 0, 0, 0, 0] 
     50 
    4651 
    4752        def send_pkt(self, payload='', eof=False): 
     
    6368                return real_channel 
    6469 
     70        def get_average_time(channel,absent_time): 
     71 
     72                global count_array, time_array 
     73 
     74                count_array[channel] = count_array[channel] + 1 
     75                average_time = (time_array[channel] + absent_time) / count_array[channel]        
     76         
     77                return average_time 
     78 
    6579        def get_freq(hop_freq,probe_level,absent_time): 
    6680 
     
    7690                        channel = 4 
    7791 
    78                 p = Parameter(1) 
    7992                currentParameters = Parameter(1) 
    80                 o = Observable(1) 
    81  
     93                currentParameters[0].name = "channel" 
     94                currentParameters[0].value = channel 
     95 
     96                o = Observable(2) 
    8297                o[0].value = probe_level 
    8398                o[0].name = "energy" 
    84  
    85                 currentParameters[0].name = "channel" 
    86                 currentParameters[0].value = channel; 
    87  
    88                 p = GetOptimalParameters(o,1,currentParameters,1); 
    89                 print p[0].value 
     99                 
     100                o[1].value = absent_time  
     101                o[1].name = "communication_time" 
     102                 
     103                # If time == 0 then we are scanning and we dont want to  
     104                #  use this time in the averaging process. 
     105 
     106                if absent_time != 0: 
     107                    UpdateParameterPerformance(currentParameters,1,o,1) 
     108 
     109                else: 
     110                    # Get the average communication time 
     111                    average_time = get_average_time(channel, absent_time) 
     112                    o[1].value = average_time  
     113                    o[1].name = "communication_time" 
     114                    UpdateParameterPerformance(currentParameters,1,o,2) 
     115 
     116                p = Parameter(1) 
     117                p = GetOptimalParameters(o,2,currentParameters,1); 
    90118                 
    91119                channel = get_real_channel(int(p[0].value)) 
     
    96124                        hop_freq = float(1e6 * (467.5625+(channel-8)*0.025))#setting the centre freq frequency for sending packets       
    97125 
     126                stats_array[int(p[0].value)] = stats_array[int(p[0].value)] + 1 
     127                print "Stats:: 1..",stats_array[1]," 2..",stats_array[2]," 3..",stats_array[3]," 4..",stats_array[4]  
    98128                return channel,hop_freq #returning the channel number and hop frequency 
    99129         
     
    154184 
    155185        parser_tx = OptionParser(option_class=eng_option, conflict_handler="resolve") 
    156         expert_grp_tx = parser_tx.add_option_group("Expert_tx") 
    157  
     186        parser_tx.add_option("", "--vtcross", action="store_true", default=False, 
     187                                help="Use the CROSS engine for DSA decisions: default is random.") 
     188   
    158189        parser_tx.add_option("-m", "--modulation", type="choice", choices=mods.keys(), 
    159190                        default='gmsk', 
     
    166197                        help="set megabytes to transmit [default=%default]") 
    167198        parser_tx.add_option("","--discontinuous", action="store_true", default=False, 
    168                         help="enable discontinous transmission (bursts of 5 packets)") 
     199                        help="enable discontinous transmission (bursts of 5 packets)")  
    169200        parser_tx.add_option("","--from-file", default=None, 
    170201                        help="use file for packet contents") 
    171          
     202  
     203        expert_grp_tx = parser_tx.add_option_group("Expert_tx") 
     204 
    172205        transmit_path.add_options(parser_tx, expert_grp_tx) 
    173206 
    174207        for mod in mods.values(): 
    175208                mod.add_options(expert_grp_tx) 
     209 
    176210 
    177211        (options_tx, args_tx) = parser_tx.parse_args () 
     
    188222        options_tx.fusb_nblocks = 16 
    189223        options_tx.bitrate = 0.0125e6 
    190         ############# 
     224        ############# 
    191225 
    192226        if options_tx.tx_freq is None: 
     
    195229                sys.exit(1) 
    196230 
    197         if options_tx.from_file is not None: 
    198                 source_file = open(options_tx.from_file, 'r') 
     231        #if options_tx.from_file is not None: 
     232        #       source_file = open(options_tx.from_file, 'r') 
    199233             
    200234        parser_rx = OptionParser (option_class=eng_option, conflict_handler="resolve") 
    201235        expert_grp_rx = parser_rx.add_option_group("Expert_rx") 
    202         parser_rx.add_option("-m", "--modulation", type="choice", choices=demods.keys(), 
    203                         default='gmsk', 
    204                         help="Select modulation from: %s [default=%%default]" 
    205                                 % (', '.join(demods.keys()),)) 
     236        #parser_rx.add_option("-m", "--modulation", type="choice", choices=demods.keys(), 
     237        #               default='gmsk', 
     238        #               help="Select modulation from: %s [default=%%default]" 
     239        #                       % (', '.join(demods.keys()),)) 
    206240         
    207241        receive_path.add_options(parser_rx, expert_grp_rx) 
    208242 
    209         for mod in demods.values(): 
    210                 mod.add_options(expert_grp_rx) 
     243        #for mod in demods.values(): 
     244        #       mod.add_options(expert_grp_rx) 
    211245 
    212246        (options_rx, args_rx) = parser_rx.parse_args () 
    213247 
    214         if len(args_rx) != 0: 
    215                 parser_rx.print_help(sys.stderr) 
    216                 sys.exit(1) 
     248        #if len(args_rx) != 0: 
     249        #       parser_rx.print_help(sys.stderr) 
     250        #       sys.exit(1) 
    217251        ############# Setting some default values for rx side of the block 
    218252        options_rx.rx_freq = 462.5625e6 #setting default rx_freq value 
     
    224258        ############# 
    225259 
    226         if options_rx.rx_freq is None: 
    227                 sys.stderr.write("You must specify -f FREQ or --freq FREQ\n") 
    228                 parser_rx.print_help(sys.stderr) 
    229                 sys.exit(1) 
     260        #if options_rx.rx_freq is None: 
     261        #       sys.stderr.write("You must specify -f FREQ or --freq FREQ\n") 
     262        #       parser_rx.print_help(sys.stderr) 
     263        #       sys.exit(1) 
    230264         
    231265        # build the graph 
     
    248282 
    249283        # Scan all channels first for inital data 
     284        time.sleep(0.1) 
    250285 
    251286        while running: