Changeset 365
- Timestamp:
- 07/23/09 11:02:27 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/branches/sriram/benchmark_txrxnode1.py
r359 r365 54 54 55 55 56 #print "inside rx callback"56 print "inside rx callback" 57 57 global n_rcvd, n_right, sync_status,mode,hop_freq 58 58 #tb.rxpath.min_freq = hop_freq - 80e3 59 59 #tb.rxpath.max_freq = hop_freq + 80e3 60 60 #tb.rxpath.get_spec_stats(1e13,20,2) 61 (pktno,) = struct.unpack('!H', payload[0:2])62 61 #temp = struct.unpack('!s', payload[3:10]) 63 62 #print "printing the elements of packet",temp,"!!!!!!!!!!!\n" 64 63 ##################################################### 65 64 if mode == "sync": 66 (sync_signal,) = struct.unpack('!s', payload[2]) 67 (sync_signal_red,) = struct.unpack('!s', payload[3]) #redundant sync bit 68 (data_channel,) = struct.unpack('!s', payload[4]) 69 (data_channel_red,) = struct.unpack('!s', payload[5]) #redundant channel bit 70 #print "printing the elements of packet ",sync_signal," !!!!!!!!!!! ",sync_signal_red," !!!!!\n" 71 #print "printing the channel ",data_channel_red," !!!!!!!!!!! ",data_channel_red," !!!!!\n" 72 if ok: #== True :# and str(sync_signal) == 'o' and str(sync_signal_red) == 'o': 73 #print "inside if" 74 if ok: #== True: #str(data_channel) == str(data_channel_red): 75 #print "inside if1$$$$$" 76 if str(data_channel) == str(ch): 77 #print "inside if2" 78 sync_status = True 79 #tb.stop() 80 #print "after tb stop ans sync status is ",sync_status," sync status\n" 81 #print "received a sync packet on channel %s\n" %(data_channel) 82 #data = 'o'+'o'+str(data_channel)+str(data_channel) 83 #print "sending this data",data,"@@@@@\n" 84 #sync_pktno=0 85 #ack_payload = struct.pack('!H', sync_pktno & 0xffff) + data 86 #print "printing the ack packet",ack_payload,"$$$$$\n" 87 #k=0 88 #while k < 10000: 89 #print "inside while" 90 #send_pkt(tb,ack_payload) #sending back the acknowledgement 91 #k=k+1 65 if ok: 66 (pktno,) = struct.unpack('!H', payload[0:2]) 67 (sync_signal,) = struct.unpack('!s', payload[2]) 68 (sync_signal_red,) = struct.unpack('!s', payload[3]) #redundant sync bit 69 (data_channel,) = struct.unpack('!s', payload[4]) 70 (data_channel_red,) = struct.unpack('!s', payload[5]) #redundant channel bit 71 #print "printing the elements of packet ",sync_signal," !!!!!!!!!!! ",sync_signal_red," !!!!!\n" 72 #print "printing the channel ",data_channel_red," !!!!!!!!!!! ",data_channel_red," !!!!!\n" 73 #== True :# and str(sync_signal) == 'o' and str(sync_signal_red) == 'o': 74 if str(data_channel) == str(ch): 75 #print "inside if2" 76 sync_status = True 77 #tb.stop() 78 #print "after tb stop ans sync status is ",sync_status," sync status\n" 79 #print "received a sync packet on channel %s\n" %(data_channel) 80 #data = 'o'+'o'+str(data_channel)+str(data_channel) 81 #print "sending this data",data,"@@@@@\n" 82 #sync_pktno=0 83 #ack_payload = struct.pack('!H', sync_pktno & 0xffff) + data 84 #print "printing the ack packet",ack_payload,"$$$$$\n" 85 #k=0 86 #while k < 10000: 87 #print "inside while" 88 #send_pkt(tb,ack_payload) #sending back the acknowledgement 89 #k=k+1 92 90 ##################################################### 93 91 94 92 ######################### traffic ############################ 95 93 if mode == "traffic": 96 (data_header,) = struct.unpack('!s', payload[0]) 97 if ok and data_header == 'd': 98 comm = struct.unpack('!14s', data) 99 print("received this ", comm) 94 print "Mode is ",mode,"received traffic packet\n" 95 if ok: 96 (data_header,) = struct.unpack('!s', payload[0]) 97 if data_header == 'd': 98 (comm,) = struct.unpack('!14s', payload[1:15]) 99 print "received this ", comm,"\n" 100 else : 101 print"not ok" 100 102 101 103 ############################################################## … … 236 238 #resend_count= 0 #initializing resend count 237 239 sync_pktno = 0 238 ch = int(random.choice('17'))240 #ch = int(random.choice('17')) 239 241 while running: 240 242 ################################################sync mode#################################### … … 245 247 pkt_size = 6 246 248 data_pktno = 0 247 print "printing packet size",pkt_size,"pkt size\n"249 #print "printing packet size",pkt_size,"pkt size\n" 248 250 while sync_status != True: 249 251 #ch = random.randint(1, 7) 250 ch = int(random.choice(' 17'))252 ch = int(random.choice('37')) 251 253 252 254 #ch = random.randint(6,12) 253 255 #ch = 1 254 256 hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets 257 print "hop freq is ",hop_freq 255 258 tb.rxpath.min_freq = hop_freq - 80e3 256 259 tb.rxpath.max_freq = hop_freq + 80e3 257 260 is_present = tb.rxpath.get_spec_stats(1e13,1) #check if primary user is present 258 261 if is_present == True: #if primary user is there then dont transmit on this channel 262 print "Cant use this channel..Primary user detected\n" 259 263 continue 260 264 … … 262 266 #print "primary user present = ",is_present,"\n" 263 267 #tb.rxpath.get_spec_stats(10) 264 print "hop freq is ",hop_freq268 265 269 266 270 #hop_freq = float(1e6 * (462.5625+(5-1)*0.05))#setting the centre freq frequency for sending packets … … 277 281 print >> myfile, "out" 278 282 while n < nbytes: 279 print >> myfile, "inside while"283 #print >> myfile, "inside while" 280 284 if options_tx.from_file is None: 281 285 #data = (pkt_size - 2) * chr(sync_pktno & 0xff) #0xff is 255 … … 318 322 pkt_size = 15 319 323 sync_pktno = 0 324 n = 0 320 325 while n < nbytes: 321 326 #print >> myfile, "inside while" … … 335 340 336 341 send_pkt(tb,payload) 342 time.sleep(0.5) 337 343 #print "printing payload",payload,"**\n" 338 344 n += len(payload) … … 342 348 data_pktno += 1 343 349 #print "before sleeping for 10 seconds and value of resend count is",resend_count 344 #time.sleep(0.1)350 345 351 tb.rxpath.min_freq = hop_freq - 80e3 346 352 tb.rxpath.max_freq = hop_freq + 80e3 347 is_present = tb.rxpath.get_spec_stats(1e13,1 0) #check if primary user is present353 is_present = tb.rxpath.get_spec_stats(1e13,1) #check if primary user is present 348 354 if is_present == True: #if primary user is present then get out of this communication channel, back to sync mode. 349 355 mode = "sync" 350 356 sync_status = False 357 print "Moving out of this channel..Primary user detected\n" 351 358 ################################################ end of Communications mode#################################### 352 359