Changeset 364
- Timestamp:
- 07/23/09 11:00:07 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/branches/sriram/benchmark_txrxnode2.py
r361 r364 29 29 30 30 global n_rcvd, n_right,ch,traffic_flag 31 traffic_flag = False 31 32 32 33 def main(): … … 76 77 ######################### traffic ############################ 77 78 if mode == "traffic": 78 (data_header,) = struct.unpack('!s', payload[0]) 79 if ok and data_header == 'd': 80 traffic_flag = True 81 comm = struct.unpack('!14s', data) 82 print("received this ", comm) 79 80 if ok: 81 print "received a packet" 82 (data_header,) = struct.unpack('!s', payload[0]) 83 if data_header == 'd': 84 traffic_flag = True 85 (comm,) = struct.unpack('!14s', payload[1:15]) 86 print "received this ", comm,"\n" 87 data = 'dI am fine.....' #Sending this message 88 payload = struct.pack('!15s', data) 89 send_pkt(tb,payload) 90 91 else: 92 print "not ok" 83 93 84 94 ############################################################## … … 212 222 #print "inside while" 213 223 #ch = random.randint(1, 7) 214 ch = int(random.choice(' 17'))224 ch = int(random.choice('37')) 215 225 #ch = random.randint(6, 12) 216 226 #ch = 1 217 227 #hop_freq = float(1e6 * (400+(ch-1)*10))#setting the centre freq frequency for sending packets 218 228 hop_freq = float(1e6 * (462.5625+(ch-1)*0.025)) 229 tb.rxpath.min_freq = hop_freq - 80e3 230 tb.rxpath.max_freq = hop_freq + 80e3 231 is_present = tb.rxpath.get_spec_stats(1e13,1) #check if primary user is present 232 print "hop freq is",hop_freq,"@@@@\n" 233 if is_present == True: #if primary user is there then dont transmit on this channel 234 print "Cant use this channel..Primary user detected\n" 235 continue 219 236 #hop_freq = float(1e6 * (462.5625+(5-1)*0.05)) 220 print "hop freq is",hop_freq,"@@@@\n"237 221 238 tb.txpath.set_freq(hop_freq) 222 239 tb.rxpath.set_freq(hop_freq) … … 225 242 else: 226 243 print "inside lese of while check" 227 check_sync == 0 244 check_sync = 0 245 traffic_flag = False 228 246 print "sync channel is found! and it is channel ",ch," \n" 229 247 mode = "traffic" … … 241 259 if mode == "traffic": 242 260 print "Inside traffic mode" 261 ##################### for ensuring sync ##################### 243 262 if check_sync == 0: 244 263 time.sleep(0.4) 245 264 if traffic_flag != True: 246 265 mode = "sync" 266 sync_status=False 247 267 continue 248 268 else: 249 269 check_sync == 1 250 nbytes = 15 251 pkt_size = 15 252 sync_pktno = 0 253 while n < nbytes: 254 #print >> myfile, "inside while" 255 if options_tx.from_file is None: 256 #data = (pkt_size - 2) * chr(data_pktno & 0xff) #0xff is 255 257 data = 'dI am fine.....' #Sending this message 258 #print >> myfile, data 259 #print "printing data",data,"****\n" 260 else: 261 data = source_file.read(pkt_size - 2) 262 if data == '': 263 break; 264 265 266 payload = struct.pack('!15s', data) 270 ############################################################ 271 272 #nbytes = 15 273 #pkt_size = 15 274 #data_pktno = 0 275 #n = 0 276 #while n < nbytes: 277 # #print >> myfile, "inside while" 278 # if options_tx.from_file is None: 279 # #data = (pkt_size - 2) * chr(data_pktno & 0xff) #0xff is 255 280 # data = 'dI am fine.....' #Sending this message 281 # #print >> myfile, data 282 # #print "printing data",data,"****\n" 283 # else: 284 # data = source_file.read(pkt_size - 2) 285 # if data == '': 286 # break; 287 # 288 # 289 # payload = struct.pack('!15s', data) 267 290 #print "printing payload",payload,"**\n" 268 291 269 send_pkt(tb,payload) 292 # send_pkt(tb,payload) 293 # time.sleep(0.5) 270 294 #print "printing payload",payload,"**\n" 271 n += len(payload)272 sys.stderr.write('.')273 if options_tx.discontinuous and data_pktno % 5 == 4:274 time.sleep(1)275 data_pktno += 1295 # n += len(payload) 296 # sys.stderr.write('.') 297 # if options_tx.discontinuous and data_pktno % 5 == 4: 298 # time.sleep(1) 299 # data_pktno += 1 276 300 #print "before sleeping for 10 seconds and value of resend count is",resend_count 277 #time.sleep(0.1) 278 tb.rxpath.min_freq = hop_freq - 80e3 279 tb.rxpath.max_freq = hop_freq + 80e3 280 is_present = tb.rxpath.get_spec_stats(1e13,10) #check if primary user is present 281 if is_present == True: #if primary user is present then get out of this communication channel, back to sync mode. 282 mode = "sync" 283 301 302 tb.rxpath.min_freq = hop_freq - 80e3 303 tb.rxpath.max_freq = hop_freq + 80e3 304 is_present = tb.rxpath.get_spec_stats(1e13,10) #check if primary user is present 305 if is_present == True: #if primary user is present then get out of this communication channel, back to sync mode. 306 mode = "sync" 307 sync_status=False 308 print "Moving out of this channel..Primary user detected\n" 309 time.sleep(0.5) 284 310 ################################################ end of Communications mode#################################### 285 311