Changeset 379

Show
Ignore:
Timestamp:
07/27/09 14:14:46 (15 years ago)
Author:
sriram
Message:

Correcting some syntax errors

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/branches/sriram/dsa.py

    r378 r379  
    3030 
    3131def main(): 
     32        print "inside main" 
    3233        global n_rcvd, n_right,sync_status,mode,ch,traffic_flag 
    3334        n_rcvd = 0 
     
    7778                n_rcvd += 1 
    7879                if ok: 
    79                 n_right += 1 
     80                        n_right += 1 
    8081 
    8182                #print "ok = %5s  pktno = %4d  n_rcvd = %4d  n_right = %4d" % ( 
     
    187188        running = True 
    188189        global ch 
    189  
    190         ################################################sync mode#################################### 
    191         if mode == "sync": 
    192                 if sync_status != True: 
    193                         ch = int(random.choice([1,7,8,14])) 
    194                         if ch < 8: 
    195                                 hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets 
    196                         else: 
    197                                 hop_freq = float(1e6 * (467.5625+(ch-8)*0.025))#setting the centre freq frequency for sending packets 
     190        running = True 
     191     
     192        while running: 
     193 
     194 
     195                ################################################sync mode#################################### 
     196                if mode == "sync": 
     197                        if sync_status != True: 
     198                                ch = int(random.choice([1,7,8,14])) 
     199                                if ch < 8: 
     200                                        hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets 
     201                                else: 
     202                                        hop_freq = float(1e6 * (467.5625+(ch-8)*0.025))#setting the centre freq frequency for sending packets 
    198203                         
    199204             
    200                         tb.txpath.set_freq(hop_freq) 
    201                         tb.rxpath.set_freq(hop_freq) 
     205                                tb.txpath.set_freq(hop_freq) 
     206                                tb.rxpath.set_freq(hop_freq) 
    202207                         
    203                         k = 0 
    204                         total_energy = 0  
    205                         while k <  1: 
    206                                 ch_energy = tb.rxpath.probe.level() #check if primary user is present 
    207                                 total_energy = total_energy + ch_energy 
    208                                 k+=1 
     208                                k = 0 
     209                                total_energy = 0  
     210                                while k <  1: 
     211                                        ch_energy = tb.rxpath.probe.level() #check if primary user is present 
     212                                        total_energy = total_energy + ch_energy 
     213                                        k+=1 
    209214                         
    210                         avg_energy = total_energy/1 
    211                         print "printing hop frequency ",hop_freq,"and energy is ",avg_energy,"\n" 
    212                         if int(avg_energy) > 2e7: #if primary user is there then dont transmit on this channel 
    213                                 #while  
    214                                 continue 
    215                                 #print "present" 
     215                                avg_energy = total_energy/1 
     216                                print "printing hop frequency ",hop_freq,"and energy is ",avg_energy,"\n" 
     217                                if int(avg_energy) > 2e7: #if primary user is there then dont transmit on this channel 
     218                                        #while  
     219                                        continue 
     220                                        #print "present" 
    216221                         
    217                         nbytes = 5 #int(1e6 * .0003) 
    218                         pkt_size = 5 
    219                         n = 0 
    220                         pktno = 0 
    221                         while n < nbytes: 
    222                                 if options_tx.from_file is None: 
    223                                         #data = (pkt_size - 2) * chr(pktno & 0xff) #0xff is 255 
    224                                         data = 's'#+'s'+str(ch)+str(ch) #adding redundant bits for sync and channel 
    225                                 else: 
    226                                         data = source_file.read(pkt_size - 2) 
    227                                         if data == '': 
    228                                                 break; 
    229  
    230                                 payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data 
    231                                 #print "printing payload",payload,"**\n" 
     222                                nbytes = 5 #int(1e6 * .0003) 
     223                                pkt_size = 5 
     224                                n = 0 
     225                                pktno = 0 
     226                                while n < nbytes: 
     227                                        if options_tx.from_file is None: 
     228                                                #data = (pkt_size - 2) * chr(pktno & 0xff) #0xff is 255 
     229                                                data = 's'#+'s'+str(ch)+str(ch) #adding redundant bits for sync and channel 
     230                                        else: 
     231                                                data = source_file.read(pkt_size - 2) 
     232                                                if data == '': 
     233                                                        break; 
     234 
     235                                        payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data 
     236                                        #print "printing payload",payload,"**\n" 
    232237         
    233                                 send_pkt(tb,payload) 
    234                                 #print "sending this data ",data,"\n" 
    235                                 n += len(payload) 
    236                                 sys.stderr.write('.') 
    237                                 if options_tx.discontinuous and pktno % 5 == 4: 
    238                                         time.sleep(1) 
    239                                         pktno += 1 
    240                         time.sleep(0.1) 
    241                 #resend_count += 1  
    242                 else: 
    243                         print "sync channel found..channel ",ch,"\n"   
    244                         mode = "traffic" 
    245                         sync_status = False 
     238                                        send_pkt(tb,payload) 
     239                                        #print "sending this data ",data,"\n" 
     240                                        n += len(payload) 
     241                                        sys.stderr.write('.') 
     242                                        if options_tx.discontinuous and pktno % 5 == 4: 
     243                                                time.sleep(1) 
     244                                                pktno += 1 
     245                                time.sleep(0.1) 
     246                        #resend_count += 1  
     247                        else: 
     248                                print "sync channel found..channel ",ch,"\n"   
     249                                mode = "traffic" 
     250                                sync_status = False 
     251                                break 
    246252        ################################################end of sync mode#################################### 
    247253 
    248254 
    249255 
    250  
    251  
    252  
    253  
     256if __name__ == '__main__': 
     257    try: 
     258        main() 
     259    except KeyboardInterrupt: 
     260        pass 
     261 
     262 
     263 
     264 
     265