Changeset 506

Show
Ignore:
Timestamp:
11/02/09 18:18:37 (14 years ago)
Author:
sriram
Message:

Try again after rendezvous fails..changed a code a little for this

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/cross-examples/python/gnuradio-examples/benchmark_dsa.py

    r505 r506  
    4343    cross_import = False 
    4444 
    45 global sync_status,mode,ch,traffic_flag,n_rcvd, n_right 
    46 global ticker_start,time_right_now #measuring duration over which no packet is sent 
    47 ticker_start = datetime.now() 
    48 #no_packet_stop_time = False 
    49 global no_packet_period #allowed duration for no packet 
    50 no_packet_period = 3 
     45global sync_status,mode,ch,data_packet_delivery_count,n_rcvd, n_right 
    5146sync_status = False 
    5247 
     
    5550# traffic: the two node are communicating information to each other 
    5651mode = "sync" #Default mode is sync 
    57 traffic_flag = False 
     52data_packet_delivery_count = 0 
    5853 
    5954class my_top_block(gr.top_block): 
     
    7267 
    7368    global stats_array, count_array, time_array, n_rcvd 
    74     global n_right, sync_status, mode, ch, traffic_flag 
     69    global n_right, sync_status, mode, ch, data_packet_delivery_count 
    7570    global n_attempts, return_flag, crossShellHost, crossShellPort 
    76     global ticker_start,time_right_now,no_packet_period 
    77  
    78     
     71    data_packet_delivery_count_previous = 0 
    7972    n_rcvd = 0 
    8073    n_right = 0 
     
    175168    def rx_callback(ok, payload): 
    176169         
    177         global n_rcvd, n_right,sync_status,mode,ch,traffic_flag,ticker_start 
    178  
    179         ticker_start = datetime.now() 
    180         #print "inside callback" 
    181         #print "ticker_start ",ticker_start 
     170        global n_rcvd, n_right,sync_status,mode,ch,data_packet_delivery_count 
    182171        ########################## sync #################################### 
    183172        if mode == "sync": 
     
    201190        ######################### traffic ################################# 
    202191        if mode == "traffic": 
    203          
    204          
    205          
    206                  
    207192            if ok:  
    208193                (data_header,) = struct.unpack('!s', payload[0]) 
    209194                if data_header == 'd': 
    210                     traffic_flag = True 
     195                    data_packet_delivery_count = data_packet_delivery_count +1 
    211196                    comm = struct.unpack('!14s', payload[1:15]) 
    212197                    data = 'dI am fine.....' #Sending this message 
     
    329314         
    330315    # build the graph 
    331         print "printing modulation scheme",demods[options_rx.modulation] 
     316 
    332317    tb = my_top_block(mods[options_tx.modulation], 
    333318                      demods[options_rx.modulation], 
     
    352337        ################################################sync mode#################################### 
    353338        if mode == "sync": 
    354             if sync_status != True: 
     339            if sync_status != True: 
    355340                     
    356341                if return_flag == 0: 
     
    394379                n_attempts_counter = 0 
    395380                mode = "traffic" 
    396                 traffic_flag = False 
     381                data_packet_delivery_count = 0 
    397382                sync_status="False" 
    398383                start_time = datetime.now() #measuring the time for which the primary user is away 
     
    425410                time.sleep(0.2 + 0.05*int(random.choice([0,1,2,3]))) 
    426411 
    427                 if traffic_flag != True: 
     412                if data_packet_delivery_count == data_packet_delivery_count_previous: #checking if the data packet delivery has stagnated 
    428413                    n_attempts_counter += 1 
    429414                    if n_attempts_counter > n_attempts: #get out of the data channel as it seems that the other node is still trying to rendezvous 
    430415                        mode = "sync" 
    431416                        continue 
    432  
    433                 #ch_energy = tb.rxpath.probe.level() #check if primary user is present 
    434                 time_right_now = datetime.now() 
    435                 #print "inside traffic , ticker_start",ticker_start 
    436                 packet_delay = (time_right_now - ticker_start).seconds 
    437                 #print "packet_delay ",packet_delay 
    438                 if packet_delay >= no_packet_period: 
    439                         stop_time = datetime.now()     
    440                         _elapsed_time  = start_time - stop_time 
    441                         elapsed_time = _elapsed_time.seconds 
    442                         print "\n[[ No data packets:  Evacuating Current Channel ]]\n" 
    443                         print "\n[[ Scanning channels for network nodes ]]\n" 
    444                         mode = "sync" 
    445                         mode = "sync" 
    446                         return_flag = 1 
    447                  
    448  
    449                 #if int(ch_energy) > 1.5e8: #if primary user is there then dont transmit on this channel 
    450                  
     417                else: 
     418                    data_packet_delivery_count_previous = 0 
     419                    data_packet_delivery_count = 0 
     420 
     421                data_packet_delivery_count_previous = data_packet_delivery_count 
     422                ch_energy = tb.rxpath.probe.level() #check if primary user is present 
     423                if int(ch_energy) > 1.8e8: #if primary user is there then dont transmit on this channel 
     424                    stop_time = datetime.now()     
     425                    _elapsed_time  = start_time - stop_time 
     426                    elapsed_time = _elapsed_time.seconds 
     427                    print "\n[[ Primary User Detected:  Evacuating Current Channel ]]\n" 
     428                    print "\n[[ Scanning channels for network nodes ]]\n" 
     429                    mode = "sync" 
     430                    return_flag = 1 
    451431                 
    452432