Changeset 384
- Timestamp:
- 07/27/09 18:57:37 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/branches/sriram/dsa.py
r383 r384 8 8 from numpy import random 9 9 import random, time, struct, sys, math 10 from datetime import datetime 10 11 11 12 # from current dir … … 31 32 def main(): 32 33 print "inside main" 33 global n_rcvd, n_right,sync_status,mode,ch,traffic_flag,n_attempts 34 global n_rcvd, n_right,sync_status,mode,ch,traffic_flag,n_attempts,return_flag 34 35 n_rcvd = 0 35 36 n_right = 0 36 37 n_attempts = 5 38 return_flag = 0 37 39 def send_pkt(self, payload='', eof=False): 38 40 return self.txpath.send_pkt(payload, eof) 39 41 42 def get_freq(hop_freq,probe_level,absent_time): 43 44 channel = int(random.choice([1,7,8,14])) 45 if channel < 8: 46 hop_freq = float(1e6 * (462.5625+(channel-1)*0.025))#setting the centre freq frequency for sending packets 47 else: 48 hop_freq = float(1e6 * (467.5625+(channel-8)*0.025))#setting the centre freq frequency for sending packets 49 50 return channel,hop_freq #returning the channel number and hop frequency 51 40 52 41 53 def rx_callback(ok, payload): … … 129 141 130 142 ############# Setting some default values for tx side of the block 131 options_tx.tx_freq = 4 70e6#462.5625e6143 options_tx.tx_freq = 462.5625e6 132 144 options_tx.samples_per_symbol = 2 133 145 options_tx.modulation = 'dbpsk' … … 169 181 sys.exit(1) 170 182 ############# Setting some default values for rx side of the block 171 options_rx.rx_freq = 4 70e6#462.5625e6 #setting default rx_freq value183 options_rx.rx_freq = 462.5625e6 #setting default rx_freq value 172 184 options_rx.samples_per_symbol = 2 173 185 options_rx.modulation = 'dbpsk' … … 200 212 global ch 201 213 running = True 202 214 ch_energy = tb.rxpath.probe.level() #setting initial value 215 hop_freq = options_tx.tx_freq # = options_rx.rx_freq...same for tx and rx side 203 216 while running: 204 205 217 206 218 ################################################sync mode#################################### 207 219 if mode == "sync": 208 220 if sync_status != True: 209 ch = int(random.choice([1,7,8,14]))210 if ch < 8:211 hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets212 213 hop_freq = float(1e6 * (467.5625+(ch-8)*0.025))#setting the centre freq frequency for sending packets214 215 216 221 222 if return_flag == 0: 223 ch,hop_freq = get_freq(hop_freq,ch_energy,0) 224 else: 225 ch,hop_freq = get_freq(hop_freq,ch_energy,elapsed_time) 226 return_flag = 0 227 228 tb.txpath.set_freq(hop_freq) 217 229 tb.rxpath.set_freq(hop_freq) 218 219 k = 0 220 total_energy = 0 221 while k < 1: 222 ch_energy = tb.rxpath.probe.level() #check if primary user is present 223 total_energy = total_energy + ch_energy 224 k+=1 225 226 avg_energy = total_energy/1 227 print "printing hop frequency ",hop_freq,"and energy is ",avg_energy,"\n" 228 if int(avg_energy) > 2e7: #if primary user is there then dont transmit on this channel 230 231 ch_energy = tb.rxpath.probe.level() #check if primary user is present 232 233 print "printing hop frequency ",hop_freq,"and energy is ",ch_energy,"\n" 234 if int(ch_energy) > 1.5e8: #if primary user is there then dont transmit on this channel 229 235 #while 230 236 continue 231 237 #print "present" 232 233 nbytes = 5 #int(1e6 * .0003)238 239 nbytes = 5 #int(1e6 * .0003) 234 240 pkt_size = 5 235 241 n = 0 … … 262 268 traffic_flag = False 263 269 sync_status="False" 270 start_time = datetime.now() #measuring the time for which the primary user is away 264 271 265 272 ################################################end of sync mode#################################### … … 297 304 data_pktno += 1 298 305 #print "before sleeping for 10 seconds and value of resend count is",resend_count 299 time.sleep(0. 1+ 0.05*int(random.choice([0,1,2,3])))306 time.sleep(0.2 + 0.05*int(random.choice([0,1,2,3]))) 300 307 301 308 if traffic_flag != True: … … 307 314 ch_energy = tb.rxpath.probe.level() #check if primary user is present 308 315 print "channel energy is ",ch_energy,"\n" 309 if int(ch_energy) > 2e7: #if primary user is there then dont transmit on this channel 316 if int(ch_energy) > 1.5e8: #if primary user is there then dont transmit on this channel 317 stop_time = datetime.now() 318 _elapsed_time = start_time - stop_time 319 elapsed_time = _elapsed_time.seconds 310 320 mode = "sync" 321 return_flag = 1 311 322 312 323