Changeset 358

Show
Ignore:
Timestamp:
07/21/09 17:34:55 (15 years ago)
Author:
sriram
Message:

Adding more changes to incorporate communication signal and spectrum sense

Location:
vtcross/branches/sriram
Files:
2 modified

Legend:

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

    r356 r358  
    6262        #temp = struct.unpack('!s', payload[3:10]) 
    6363        #print "printing the elements of packet",temp,"!!!!!!!!!!!\n" 
    64         if mode == "sync": 
    65         ##################################################### 
     64        ##################################################### 
     65        if mode == "sync": 
    6666                (sync_signal,) = struct.unpack('!s', payload[2])  
    6767                (sync_signal_red,) = struct.unpack('!s', payload[3])  #redundant sync bit 
     
    9292        ##################################################### 
    9393         
     94        ######################### traffic ############################ 
     95        if mode == "traffic": 
     96                if ok == True: 
     97                        comm = struct.unpack('!14s', data) 
     98                        print("received this ", comm)  
     99         
     100        ############################################################## 
     101         
     102 
     103 
    94104        n_rcvd += 1 
    95105        if ok: 
     
    227237    ch = int(random.choice('17')) 
    228238    while running: 
     239        ################################################sync mode#################################### 
    229240        if mode == "sync": 
    230241                #nbytes = int(1e6 * .0003) 
     
    298309                #myfile.close() 
    299310                #tb.wait() 
    300  
     311        ################################################end of sync mode#################################### 
     312 
     313        ################################################Communications mode#################################### 
    301314        if mode == "traffic": 
    302315                nbytes = 16 
     
    315328                                        break; 
    316329         
    317                         payload = struct.pack('!H', data_pktno & 0xffff) + data 
     330                         
     331                        payload = struct.pack('!14s', data) 
    318332                        #print "printing payload",payload,"**\n" 
    319333                                 
     
    333347                                mode = "sync" 
    334348                                 
    335                                  
     349        ################################################ end of Communications mode####################################          
    336350 
    337351 
  • vtcross/branches/sriram/benchmark_txrxnode2.py

    r320 r358  
    1212from transmit_path import transmit_path 
    1313from receive_path import receive_path 
    14 global sync_status 
     14global sync_status,mode 
    1515sync_status=False 
    1616 
     
    2828#//////main//////  
    2929 
    30 global n_rcvd, n_right,ch 
     30global n_rcvd, n_right,ch,traffic_flag 
    3131 
    3232def main(): 
    33     global n_rcvd, n_right,sync_status,pktno1,ch 
    34     pktno1 =0 
     33    global n_rcvd, n_right,sync_status,sync_pktno,ch,mode,traffic_flag 
     34    sync_pktno =0 
    3535    n_rcvd = 0 
    3636    n_right = 0 
     
    3939 
    4040    def rx_callback(ok, payload): 
    41         global n_rcvd, n_right,sync_status,pktno1,ch 
     41        global n_rcvd, n_right,sync_status,sync_pktno,ch,mode,traffic_flag 
    4242        #(pktno,) = struct.unpack('!H', payload[0:2]) 
    4343        print "inside rx callback" 
    44         if ok == True: 
    45             (sync_signal,) = struct.unpack('!s', payload[2])   
    46             (sync_signal_red,) = struct.unpack('!s', payload[3])  #redundant sync bit 
    47             (data_channel,) = struct.unpack('!s', payload[4]) 
    48             (data_channel_red,) = struct.unpack('!s', payload[5])  #redundant channel bit 
    49             print "printing the elements of packet  ",str(sync_signal),"  !!!!!!!!!!!  ",str(sync_signal_red)," !!!!!\n"      
    50             print "printing the channel  ",str(data_channel_red),"  !!!!!!!!!!!  ",str(data_channel_red)," !!!!!\n" 
    51             #if str(sync_signal) == 's' and str(sync_signal_red) == 's' and str(data_channel) == str(data_channel_red): 
    52             if str(data_channel) == str(ch): 
    53                 #print "inside if" 
    54                 sync_status = True 
    55                 #tb.stop() 
    56                 #print "received a sync packet on channel %s\n" %(data_channel) 
    57                 data = str('o'+'o'+str(data_channel)+str(data_channel)) 
    58                 #print "sending this data",data,"@@@@@\n" 
    59                 #pktno1=0 
    60                 ack_payload = struct.pack('!H', pktno1 & 0xffff) + data 
    61                 pktno1+=1 
    62                 #print "printing ack packet and sent pkt no ",ack_payload," ",pktno1,"\n" 
    63                 #print "printing the 3rd byte ",struct.unpack('!s', ack_payload[2]) ," \n" 
    64                 #k=0 
    65                 #while k < 10000: 
    66                 #print "inside while" 
    67                 send_pkt(tb,ack_payload) #sending back the acknowledgement 
    68                 #send_pkt(tb,ack_payload) #sending back the acknowledgement 
    69                 #send_pkt(tb,ack_payload) #sending back the acknowledgement 
    70                 #send_pkt(tb,ack_payload) #sending back the acknowledgement 
    71                 #send_pkt(tb,ack_payload) #sending back the acknowledgement 
    72                 #send_pkt(tb,ack_payload) #sending back the acknowledgement 
    73                 #send_pkt(tb,ack_payload) #sending back the acknowledgement 
    74                  
    75                 #k=k+1 
     44        ########################## sync ########################### 
     45        if mode == "sync": 
     46                if ok == True: 
     47                        (sync_signal,) = struct.unpack('!s', payload[2])   
     48                        (sync_signal_red,) = struct.unpack('!s', payload[3])  #redundant sync bit 
     49                        (data_channel,) = struct.unpack('!s', payload[4]) 
     50                        (data_channel_red,) = struct.unpack('!s', payload[5])  #redundant channel bit 
     51                        print "printing the elements of packet  ",str(sync_signal),"  !!!!!!!!!!!  ",str(sync_signal_red)," !!!!!\n"      
     52                        print "printing the channel  ",str(data_channel_red),"  !!!!!!!!!!!  ",str(data_channel_red)," !!!!!\n" 
     53                        #if str(sync_signal) == 's' and str(sync_signal_red) == 's' and str(data_channel) == str(data_channel_red): 
     54                        if str(data_channel) == str(ch): 
     55                                #print "inside if" 
     56                                sync_status = True 
     57                                #tb.stop() 
     58                                #print "received a sync packet on channel %s\n" %(data_channel) 
     59                                data = str('o'+'o'+str(data_channel)+str(data_channel)) 
     60                                #print "sending this data",data,"@@@@@\n" 
     61                                #sync_pktno=0 
     62                                ack_payload = struct.pack('!H', sync_pktno & 0xffff) + data 
     63                                sync_pktno+=1 
     64                                #print "printing ack packet and sent pkt no ",ack_payload," ",sync_pktno,"\n" 
     65                                #print "printing the 3rd byte ",struct.unpack('!s', ack_payload[2]) ," \n" 
     66                                #k=0 
     67                                #while k < 10000: 
     68                                #print "inside while" 
     69                                send_pkt(tb,ack_payload) #sending back the acknowledgement 
     70                                #k=k+1 
     71                                print "ok = %5s  sync_pktno = %4d  n_rcvd = %4d  n_right = %4d" % ( 
     72                                    ok, sync_pktno, n_rcvd, n_right) 
    7673                     
    77         n_rcvd += 1 
     74        ##################################################### 
     75         
     76        ######################### traffic ############################ 
     77        if mode == "traffic": 
     78                if ok == True: 
     79                        traffic_flag = True 
     80                        comm = struct.unpack('!14s', data) 
     81                        print("received this ", comm)  
     82         
     83        ############################################################## 
     84 
     85 
     86 
     87        n_rcvd += 1 
    7888        if ok: 
    7989            n_right += 1 
     
    178188    tb.start() 
    179189    #listening to random frequencies untill a match is found 
    180     check = True 
     190    running = True 
    181191    global ch 
    182     while check: 
    183         if sync_status != True: 
    184                 #print "inside while" 
    185                 #ch = random.randint(1, 7) 
    186                 ch = int(random.choice('17')) 
    187                 #ch = random.randint(6, 12) 
    188                 #ch = 1 
    189                 #hop_freq = float(1e6 * (400+(ch-1)*10))#setting the centre freq frequency for sending packets 
    190                 hop_freq = float(1e6 * (462.5625+(ch-1)*0.025)) 
    191                 #hop_freq = float(1e6 * (462.5625+(5-1)*0.05)) 
    192                 print "hop freq is",hop_freq,"@@@@\n" 
    193                 tb.txpath.set_freq(hop_freq) 
    194                 tb.rxpath.set_freq(hop_freq) 
    195                 time.sleep(0.05) 
    196                 #time.sleep(2) 
    197         else: 
    198                 print "inside lese of while check" 
    199                 #tb.stop() 
    200                 break 
    201     temp_variable = 2 
    202     if temp_variable == 2: 
    203         print "success" 
     192    while running: 
     193        ################################################sync mode#################################### 
     194        if mode == "sync": 
     195                if sync_status != True: 
     196                        #print "inside while" 
     197                        #ch = random.randint(1, 7) 
     198                        ch = int(random.choice('17')) 
     199                        #ch = random.randint(6, 12) 
     200                        #ch = 1 
     201                        #hop_freq = float(1e6 * (400+(ch-1)*10))#setting the centre freq frequency for sending packets 
     202                        hop_freq = float(1e6 * (462.5625+(ch-1)*0.025)) 
     203                        #hop_freq = float(1e6 * (462.5625+(5-1)*0.05)) 
     204                        print "hop freq is",hop_freq,"@@@@\n" 
     205                        tb.txpath.set_freq(hop_freq) 
     206                        tb.rxpath.set_freq(hop_freq) 
     207                        time.sleep(0.05) 
     208                        #time.sleep(2) 
     209                else: 
     210                        print "inside lese of while check" 
     211                        #tb.stop() 
     212                        break 
     213                temp_variable = 2 
     214                if temp_variable == 2: 
     215                        print "success" 
    204216     
    205     print "sync channel is found! and it is channel ",ch," \n"   
     217                print "sync channel is found! and it is channel ",ch," \n"   
     218                mode = "traffic" 
     219         
     220        ################################################end of sync mode#################################### 
     221 
     222        ################################################Communications mode####################################  
     223        if mode == "traffic": 
     224                time.sleep(0.4) 
     225                if traffic_flag != True 
     226                        mode = "sync" 
     227                nbytes = 14 
     228                pkt_size = 14 
     229                sync_pktno = 0 
     230                while n < nbytes: 
     231                        #print >> myfile, "inside while" 
     232                        if options_tx.from_file is None: 
     233                                #data = (pkt_size - 2) * chr(data_pktno & 0xff) #0xff is 255 
     234                                data = 'I am fine.....' #Sending this message 
     235                                #print >> myfile, data 
     236                                #print "printing data",data,"****\n" 
     237                        else: 
     238                                data = source_file.read(pkt_size - 2) 
     239                                if data == '': 
     240                                        break; 
     241         
     242                         
     243                        payload = struct.pack('!14s', data) 
     244                        #print "printing payload",payload,"**\n" 
     245                                 
     246                        send_pkt(tb,payload) 
     247                        #print "printing payload",payload,"**\n" 
     248                        n += len(payload) 
     249                        sys.stderr.write('.') 
     250                        if options_tx.discontinuous and data_pktno % 5 == 4: 
     251                                time.sleep(1) 
     252                        data_pktno += 1 
     253                        #print "before sleeping for 10 seconds and value of resend count is",resend_count 
     254                        #time.sleep(0.1) 
     255                        tb.rxpath.min_freq = hop_freq - 80e3  
     256                        tb.rxpath.max_freq = hop_freq + 80e3  
     257                        is_present = tb.rxpath.get_spec_stats(1e13,10) #check if primary user is present 
     258                        if is_present == True: #if primary user is present then get out of this communication channel, back to sync mode. 
     259                                mode = "sync" 
     260         
     261        ################################################ end of Communications mode####################################          
     262 
     263 
     264 
    206265    #var2  = 2 
    207266    #if var2 ==2: 
     
    215274 
    216275    #tb.wait() 
    217     tb.stop() 
     276    #tb.stop() 
    218277 
    219278if __name__ == '__main__':