Changeset 506 for vtcross/trunk/src/cross-examples
- Timestamp:
- 11/02/09 18:18:37 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/cross-examples/python/gnuradio-examples/benchmark_dsa.py
r505 r506 43 43 cross_import = False 44 44 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 45 global sync_status,mode,ch,data_packet_delivery_count,n_rcvd, n_right 51 46 sync_status = False 52 47 … … 55 50 # traffic: the two node are communicating information to each other 56 51 mode = "sync" #Default mode is sync 57 traffic_flag = False 52 data_packet_delivery_count = 0 58 53 59 54 class my_top_block(gr.top_block): … … 72 67 73 68 global stats_array, count_array, time_array, n_rcvd 74 global n_right, sync_status, mode, ch, traffic_flag69 global n_right, sync_status, mode, ch, data_packet_delivery_count 75 70 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 79 72 n_rcvd = 0 80 73 n_right = 0 … … 175 168 def rx_callback(ok, payload): 176 169 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 182 171 ########################## sync #################################### 183 172 if mode == "sync": … … 201 190 ######################### traffic ################################# 202 191 if mode == "traffic": 203 204 205 206 207 192 if ok: 208 193 (data_header,) = struct.unpack('!s', payload[0]) 209 194 if data_header == 'd': 210 traffic_flag = True195 data_packet_delivery_count = data_packet_delivery_count +1 211 196 comm = struct.unpack('!14s', payload[1:15]) 212 197 data = 'dI am fine.....' #Sending this message … … 329 314 330 315 # build the graph 331 print "printing modulation scheme",demods[options_rx.modulation] 316 332 317 tb = my_top_block(mods[options_tx.modulation], 333 318 demods[options_rx.modulation], … … 352 337 ################################################sync mode#################################### 353 338 if mode == "sync": 354 339 if sync_status != True: 355 340 356 341 if return_flag == 0: … … 394 379 n_attempts_counter = 0 395 380 mode = "traffic" 396 traffic_flag = False381 data_packet_delivery_count = 0 397 382 sync_status="False" 398 383 start_time = datetime.now() #measuring the time for which the primary user is away … … 425 410 time.sleep(0.2 + 0.05*int(random.choice([0,1,2,3]))) 426 411 427 if traffic_flag != True:412 if data_packet_delivery_count == data_packet_delivery_count_previous: #checking if the data packet delivery has stagnated 428 413 n_attempts_counter += 1 429 414 if n_attempts_counter > n_attempts: #get out of the data channel as it seems that the other node is still trying to rendezvous 430 415 mode = "sync" 431 416 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 451 431 452 432