Changeset 356

Show
Ignore:
Timestamp:
07/21/09 12:20:32 (15 years ago)
Author:
sriram
Message:

Adding code for the communication channel..very much base line...need to test it

Files:
1 modified

Legend:

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

    r339 r356  
    3636        self.rxpath = receive_path(demod_class, rx_callback, options_rx) 
    3737        self.txpath = transmit_path(mod_class, options_tx) 
    38          
    39         ########connect for the spectrum sense######### 
    40         #default_min_freq = 462.4825e6 #80 Khz to the left of channel 1 (462.5625e6) in frs band  
    41         #default_max_freq = 462.6425e6 #80 Khz to the right of channel 1 (462.5625e6) in frs band  
    42         #self.sp_sense_path = spec_sense_path.spec_sense_top_block(default_min_freq,default_min_freq) 
    43         #self.connect(self.sp_sense_path.u, self.sp_sense_path.s2v, self.sp_sense_path.fft, self.sp_sense_path.c2mag, self.sp_sense_path.stats) 
    44  
    4538        self.connect(self.txpath); 
    4639        self.connect(self.rxpath); 
     
    6356        #print "inside rx callback" 
    6457        global n_rcvd, n_right, sync_status,mode,hop_freq 
    65         tb.rxpath.min_freq = hop_freq - 80e3  
    66         tb.rxpath.max_freq = hop_freq + 80e3  
    67         tb.rxpath.get_avg_power(10) 
     58        #tb.rxpath.min_freq = hop_freq - 80e3  
     59        #tb.rxpath.max_freq = hop_freq + 80e3  
     60        #tb.rxpath.get_spec_stats(1e13,20,2) 
    6861        (pktno,) = struct.unpack('!H', payload[0:2]) 
    6962        #temp = struct.unpack('!s', payload[3:10]) 
     
    8982                                        #data = 'o'+'o'+str(data_channel)+str(data_channel) 
    9083                                        #print "sending this data",data,"@@@@@\n" 
    91                                         #pktno=0 
    92                                         #ack_payload = struct.pack('!H', pktno & 0xffff) + data 
     84                                        #sync_pktno=0 
     85                                        #ack_payload = struct.pack('!H', sync_pktno & 0xffff) + data 
    9386                                        #print "printing the ack packet",ack_payload,"$$$$$\n" 
    9487                                        #k=0 
     
    199192 
    200193 
    201  
    202     ######################## adding another top block for usrp spectrum sense ######################## 
    203     #This is not needed anymore 
    204     #trials = 10 
    205      
    206     #tb_spec_sense = spec_sense_top_block(default_min_freq,default_min_freq) 
    207     #tb_spec_sense.subdev.select_rx_antenna('RX2') 
    208     #tb_spec_sense.start()              # start executing flow graph in another thread... 
    209     #avg = tb_spec_sense.get_avg_power(trials) 
    210     #print "printing the average power ",avg, "\n" 
    211     #tb_spec_sense.stop()    
    212      
    213  
    214     ################################################################################################## 
    215  
    216194    # build the graph 
    217195 
     
    225203 
    226204    tb.start() 
    227     #tb.rxpath.get_avg_power(10) #10 is the number of fft frames that we are looking at to determine the average power 
     205    #tb.rxpath.get_spec_stats(10) #10 is the number of fft frames that we are looking at to determine the average power 
    228206    # generate and send packets 
    229207    #print "printing megamytes",options_tx.megabytes,"  $$$$\n" 
     
    246224    running = True 
    247225    #resend_count= 0 #initializing resend count 
    248     #while running 
    249     if mode  == "sync": 
    250         #nbytes = int(1e6 * .0003) 
    251         #nbytes = int(1e6 * .0003) 
    252         nbytes = 6 
    253         pkt_size = 6 
    254         print "printing packet size",pkt_size,"pkt size\n" 
    255         while sync_status != True: 
    256                 #ch = random.randint(1, 7) 
    257                 #ch = int(random.choice('17')) 
    258                 #ch = random.randint(6,12) 
    259                 ch = 1 
    260                 hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets 
    261                 print "hop freq is ",hop_freq 
    262                  
    263                 #hop_freq = float(1e6 * (462.5625+(5-1)*0.05))#setting the centre freq frequency for sending packets 
    264                 tb.txpath.set_freq(hop_freq) 
    265                 tb.rxpath.set_freq(hop_freq) 
    266                 #print "inside while pppp printing sync channel",sync_status,"  done" 
    267                 #if sync_status == "True": 
    268                 #print "synchronization done..data channel is found" 
    269                 #break 
    270                 #else: 
    271                 #print "inside else1" 
    272                 n = 0 
    273                 pktno = 0 
    274                 print >> myfile, "out" 
    275                 while n < nbytes: 
    276                         print >> myfile, "inside while" 
    277                         if options_tx.from_file is None: 
    278                                 #data = (pkt_size - 2) * chr(pktno & 0xff) #0xff is 255 
    279                                 data = 's'+'s'+str(ch)+str(ch) #adding redundant bits for sync and channel 
    280                                 #print >> myfile, data 
    281                                 #print "printing data",data,"****\n" 
     226    sync_pktno = 0 
     227    ch = int(random.choice('17')) 
     228    while running: 
     229        if mode == "sync": 
     230                #nbytes = int(1e6 * .0003) 
     231                #nbytes = int(1e6 * .0003) 
     232                nbytes = 6 
     233                pkt_size = 6 
     234                data_pktno = 0  
     235                print "printing packet size",pkt_size,"pkt size\n" 
     236                while sync_status != True: 
     237                        #ch = random.randint(1, 7) 
     238                        ch = int(random.choice('17')) 
     239                         
     240                        #ch = random.randint(6,12) 
     241                        #ch = 1 
     242                        hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets 
     243                        tb.rxpath.min_freq = hop_freq - 80e3  
     244                        tb.rxpath.max_freq = hop_freq + 80e3  
     245                        is_present = tb.rxpath.get_spec_stats(1e13,1) #check if primary user is present 
     246                        if is_present == True: #if primary user is there then dont transmit on this channel 
     247                                continue  
     248                                         
     249                        #print "printing status ",status,"\n" 
     250                        #print "primary user present = ",is_present,"\n" 
     251                        #tb.rxpath.get_spec_stats(10)   
     252                        print "hop freq is ",hop_freq 
     253                         
     254                        #hop_freq = float(1e6 * (462.5625+(5-1)*0.05))#setting the centre freq frequency for sending packets 
     255                        tb.txpath.set_freq(hop_freq) 
     256                        tb.rxpath.set_freq(hop_freq) 
     257                        #print "inside while pppp printing sync channel",sync_status,"  done" 
     258                        #if sync_status == "True": 
     259                        #print "synchronization done..data channel is found" 
     260                        #break 
     261                        #else: 
     262                        #print "inside else1" 
     263                        n = 0 
     264                         
     265                        print >> myfile, "out" 
     266                        while n < nbytes: 
     267                                print >> myfile, "inside while" 
     268                                if options_tx.from_file is None: 
     269                                        #data = (pkt_size - 2) * chr(sync_pktno & 0xff) #0xff is 255 
     270                                        data = 's'+'s'+str(ch)+str(ch) #adding redundant bits for sync and channel 
     271                                        #print >> myfile, data 
     272                                        #print "printing data",data,"****\n" 
     273                                else: 
     274                                        data = source_file.read(pkt_size - 2) 
     275                                        if data == '': 
     276                                                break; 
     277         
     278                                payload = struct.pack('!H', sync_pktno & 0xffff) + data 
     279                                #print "printing payload",payload,"**\n" 
     280                                 
     281                                send_pkt(tb,payload) 
     282                                #print "printing payload",payload,"**\n" 
     283                                n += len(payload) 
     284                                sys.stderr.write('.') 
     285                                if options_tx.discontinuous and sync_pktno % 5 == 4: 
     286                                        time.sleep(1) 
     287                                sync_pktno += 1 
     288                                #print "before sleeping for 10 seconds and value of resend count is",resend_count 
     289         
     290 
     291                        time.sleep(0.05) 
     292                        #time.sleep(2) 
     293                        #resend_count += 1  
     294             
     295                print "sync channel found! and it is channel ",ch,"\n" 
     296                mode = "traffic" 
     297                 #send_pkt(tb,eof=True) 
     298                #myfile.close() 
     299                #tb.wait() 
     300 
     301        if mode == "traffic": 
     302                nbytes = 16 
     303                pkt_size = 16 
     304                sync_pktno = 0 
     305                while n < nbytes: 
     306                        #print >> myfile, "inside while" 
     307                        if options_tx.from_file is None: 
     308                                #data = (pkt_size - 2) * chr(data_pktno & 0xff) #0xff is 255 
     309                                data = 'Hi how are you' #Sending this message 
     310                                #print >> myfile, data 
     311                                #print "printing data",data,"****\n" 
    282312                        else: 
    283                                 data = source_file.read(pkt_size - 2) 
    284                                 if data == '': 
    285                                         break; 
    286  
    287                         payload = struct.pack('!H', pktno & 0xffff) + data 
     313                                data = source_file.read(pkt_size - 2) 
     314                                if data == '': 
     315                                        break; 
     316         
     317                        payload = struct.pack('!H', data_pktno & 0xffff) + data 
    288318                        #print "printing payload",payload,"**\n" 
    289                          
     319                                 
    290320                        send_pkt(tb,payload) 
    291321                        #print "printing payload",payload,"**\n" 
    292322                        n += len(payload) 
    293323                        sys.stderr.write('.') 
    294                         if options_tx.discontinuous and pktno % 5 == 4: 
    295                                 time.sleep(1) 
    296                         pktno += 1 
     324                        if options_tx.discontinuous and data_pktno % 5 == 4: 
     325                                time.sleep(1) 
     326                        data_pktno += 1 
    297327                        #print "before sleeping for 10 seconds and value of resend count is",resend_count 
    298  
    299                 tb.rxpath.min_freq = hop_freq - 80e3  
    300                 tb.rxpath.max_freq = hop_freq + 80e3  
    301                 tb.rxpath.get_avg_power(10) #10 is the number of fft frames that we are looking at to determine the average power 
    302  
    303                 time.sleep(0.05) 
    304                 #time.sleep(2) 
    305                 #resend_count += 1  
    306     print "sync channel found! and it is channel ",ch,"\n" 
    307     send_pkt(tb,eof=True) 
    308     #myfile.close() 
    309     tb.wait() 
    310      
     328                        #time.sleep(0.1) 
     329                        tb.rxpath.min_freq = hop_freq - 80e3  
     330                        tb.rxpath.max_freq = hop_freq + 80e3  
     331                        is_present = tb.rxpath.get_spec_stats(1e13,10) #check if primary user is present 
     332                        if is_present == True: #if primary user is present then get out of this communication channel, back to sync mode. 
     333                                mode = "sync" 
     334                                 
     335                                 
     336 
    311337 
    312338