189 | | |
190 | | ################################################sync mode#################################### |
191 | | if mode == "sync": |
192 | | if sync_status != True: |
193 | | ch = int(random.choice([1,7,8,14])) |
194 | | if ch < 8: |
195 | | hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets |
196 | | else: |
197 | | hop_freq = float(1e6 * (467.5625+(ch-8)*0.025))#setting the centre freq frequency for sending packets |
| 190 | running = True |
| 191 | |
| 192 | while running: |
| 193 | |
| 194 | |
| 195 | ################################################sync mode#################################### |
| 196 | if mode == "sync": |
| 197 | if sync_status != True: |
| 198 | ch = int(random.choice([1,7,8,14])) |
| 199 | if ch < 8: |
| 200 | hop_freq = float(1e6 * (462.5625+(ch-1)*0.025))#setting the centre freq frequency for sending packets |
| 201 | else: |
| 202 | hop_freq = float(1e6 * (467.5625+(ch-8)*0.025))#setting the centre freq frequency for sending packets |
210 | | avg_energy = total_energy/1 |
211 | | print "printing hop frequency ",hop_freq,"and energy is ",avg_energy,"\n" |
212 | | if int(avg_energy) > 2e7: #if primary user is there then dont transmit on this channel |
213 | | #while |
214 | | continue |
215 | | #print "present" |
| 215 | avg_energy = total_energy/1 |
| 216 | print "printing hop frequency ",hop_freq,"and energy is ",avg_energy,"\n" |
| 217 | if int(avg_energy) > 2e7: #if primary user is there then dont transmit on this channel |
| 218 | #while |
| 219 | continue |
| 220 | #print "present" |
217 | | nbytes = 5 #int(1e6 * .0003) |
218 | | pkt_size = 5 |
219 | | n = 0 |
220 | | pktno = 0 |
221 | | while n < nbytes: |
222 | | if options_tx.from_file is None: |
223 | | #data = (pkt_size - 2) * chr(pktno & 0xff) #0xff is 255 |
224 | | data = 's'#+'s'+str(ch)+str(ch) #adding redundant bits for sync and channel |
225 | | else: |
226 | | data = source_file.read(pkt_size - 2) |
227 | | if data == '': |
228 | | break; |
229 | | |
230 | | payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data |
231 | | #print "printing payload",payload,"**\n" |
| 222 | nbytes = 5 #int(1e6 * .0003) |
| 223 | pkt_size = 5 |
| 224 | n = 0 |
| 225 | pktno = 0 |
| 226 | while n < nbytes: |
| 227 | if options_tx.from_file is None: |
| 228 | #data = (pkt_size - 2) * chr(pktno & 0xff) #0xff is 255 |
| 229 | data = 's'#+'s'+str(ch)+str(ch) #adding redundant bits for sync and channel |
| 230 | else: |
| 231 | data = source_file.read(pkt_size - 2) |
| 232 | if data == '': |
| 233 | break; |
| 234 | |
| 235 | payload = struct.pack('!HsH', pktno & 0xffff,data,ch & 0xffff) #+ data |
| 236 | #print "printing payload",payload,"**\n" |
233 | | send_pkt(tb,payload) |
234 | | #print "sending this data ",data,"\n" |
235 | | n += len(payload) |
236 | | sys.stderr.write('.') |
237 | | if options_tx.discontinuous and pktno % 5 == 4: |
238 | | time.sleep(1) |
239 | | pktno += 1 |
240 | | time.sleep(0.1) |
241 | | #resend_count += 1 |
242 | | else: |
243 | | print "sync channel found..channel ",ch,"\n" |
244 | | mode = "traffic" |
245 | | sync_status = False |
| 238 | send_pkt(tb,payload) |
| 239 | #print "sending this data ",data,"\n" |
| 240 | n += len(payload) |
| 241 | sys.stderr.write('.') |
| 242 | if options_tx.discontinuous and pktno % 5 == 4: |
| 243 | time.sleep(1) |
| 244 | pktno += 1 |
| 245 | time.sleep(0.1) |
| 246 | #resend_count += 1 |
| 247 | else: |
| 248 | print "sync channel found..channel ",ch,"\n" |
| 249 | mode = "traffic" |
| 250 | sync_status = False |
| 251 | break |