Changeset 356
- Timestamp:
- 07/21/09 12:20:32 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/branches/sriram/benchmark_txrxnode1.py
r339 r356 36 36 self.rxpath = receive_path(demod_class, rx_callback, options_rx) 37 37 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 band41 #default_max_freq = 462.6425e6 #80 Khz to the right of channel 1 (462.5625e6) in frs band42 #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 45 38 self.connect(self.txpath); 46 39 self.connect(self.rxpath); … … 63 56 #print "inside rx callback" 64 57 global n_rcvd, n_right, sync_status,mode,hop_freq 65 tb.rxpath.min_freq = hop_freq - 80e366 tb.rxpath.max_freq = hop_freq + 80e367 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) 68 61 (pktno,) = struct.unpack('!H', payload[0:2]) 69 62 #temp = struct.unpack('!s', payload[3:10]) … … 89 82 #data = 'o'+'o'+str(data_channel)+str(data_channel) 90 83 #print "sending this data",data,"@@@@@\n" 91 # pktno=092 #ack_payload = struct.pack('!H', pktno & 0xffff) + data84 #sync_pktno=0 85 #ack_payload = struct.pack('!H', sync_pktno & 0xffff) + data 93 86 #print "printing the ack packet",ack_payload,"$$$$$\n" 94 87 #k=0 … … 199 192 200 193 201 202 ######################## adding another top block for usrp spectrum sense ########################203 #This is not needed anymore204 #trials = 10205 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 216 194 # build the graph 217 195 … … 225 203 226 204 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 power205 #tb.rxpath.get_spec_stats(10) #10 is the number of fft frames that we are looking at to determine the average power 228 206 # generate and send packets 229 207 #print "printing megamytes",options_tx.megabytes," $$$$\n" … … 246 224 running = True 247 225 #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" 282 312 else: 283 284 285 286 287 payload = struct.pack('!H', pktno & 0xffff) + data313 data = source_file.read(pkt_size - 2) 314 if data == '': 315 break; 316 317 payload = struct.pack('!H', data_pktno & 0xffff) + data 288 318 #print "printing payload",payload,"**\n" 289 319 290 320 send_pkt(tb,payload) 291 321 #print "printing payload",payload,"**\n" 292 322 n += len(payload) 293 323 sys.stderr.write('.') 294 if options_tx.discontinuous and pktno % 5 == 4:295 296 pktno += 1324 if options_tx.discontinuous and data_pktno % 5 == 4: 325 time.sleep(1) 326 data_pktno += 1 297 327 #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 311 337 312 338