44 | | if ok == True: |
45 | | (sync_signal,) = struct.unpack('!s', payload[2]) |
46 | | (sync_signal_red,) = struct.unpack('!s', payload[3]) #redundant sync bit |
47 | | (data_channel,) = struct.unpack('!s', payload[4]) |
48 | | (data_channel_red,) = struct.unpack('!s', payload[5]) #redundant channel bit |
49 | | print "printing the elements of packet ",str(sync_signal)," !!!!!!!!!!! ",str(sync_signal_red)," !!!!!\n" |
50 | | print "printing the channel ",str(data_channel_red)," !!!!!!!!!!! ",str(data_channel_red)," !!!!!\n" |
51 | | #if str(sync_signal) == 's' and str(sync_signal_red) == 's' and str(data_channel) == str(data_channel_red): |
52 | | if str(data_channel) == str(ch): |
53 | | #print "inside if" |
54 | | sync_status = True |
55 | | #tb.stop() |
56 | | #print "received a sync packet on channel %s\n" %(data_channel) |
57 | | data = str('o'+'o'+str(data_channel)+str(data_channel)) |
58 | | #print "sending this data",data,"@@@@@\n" |
59 | | #pktno1=0 |
60 | | ack_payload = struct.pack('!H', pktno1 & 0xffff) + data |
61 | | pktno1+=1 |
62 | | #print "printing ack packet and sent pkt no ",ack_payload," ",pktno1,"\n" |
63 | | #print "printing the 3rd byte ",struct.unpack('!s', ack_payload[2]) ," \n" |
64 | | #k=0 |
65 | | #while k < 10000: |
66 | | #print "inside while" |
67 | | send_pkt(tb,ack_payload) #sending back the acknowledgement |
68 | | #send_pkt(tb,ack_payload) #sending back the acknowledgement |
69 | | #send_pkt(tb,ack_payload) #sending back the acknowledgement |
70 | | #send_pkt(tb,ack_payload) #sending back the acknowledgement |
71 | | #send_pkt(tb,ack_payload) #sending back the acknowledgement |
72 | | #send_pkt(tb,ack_payload) #sending back the acknowledgement |
73 | | #send_pkt(tb,ack_payload) #sending back the acknowledgement |
74 | | |
75 | | #k=k+1 |
| 44 | ########################## sync ########################### |
| 45 | if mode == "sync": |
| 46 | if ok == True: |
| 47 | (sync_signal,) = struct.unpack('!s', payload[2]) |
| 48 | (sync_signal_red,) = struct.unpack('!s', payload[3]) #redundant sync bit |
| 49 | (data_channel,) = struct.unpack('!s', payload[4]) |
| 50 | (data_channel_red,) = struct.unpack('!s', payload[5]) #redundant channel bit |
| 51 | print "printing the elements of packet ",str(sync_signal)," !!!!!!!!!!! ",str(sync_signal_red)," !!!!!\n" |
| 52 | print "printing the channel ",str(data_channel_red)," !!!!!!!!!!! ",str(data_channel_red)," !!!!!\n" |
| 53 | #if str(sync_signal) == 's' and str(sync_signal_red) == 's' and str(data_channel) == str(data_channel_red): |
| 54 | if str(data_channel) == str(ch): |
| 55 | #print "inside if" |
| 56 | sync_status = True |
| 57 | #tb.stop() |
| 58 | #print "received a sync packet on channel %s\n" %(data_channel) |
| 59 | data = str('o'+'o'+str(data_channel)+str(data_channel)) |
| 60 | #print "sending this data",data,"@@@@@\n" |
| 61 | #sync_pktno=0 |
| 62 | ack_payload = struct.pack('!H', sync_pktno & 0xffff) + data |
| 63 | sync_pktno+=1 |
| 64 | #print "printing ack packet and sent pkt no ",ack_payload," ",sync_pktno,"\n" |
| 65 | #print "printing the 3rd byte ",struct.unpack('!s', ack_payload[2]) ," \n" |
| 66 | #k=0 |
| 67 | #while k < 10000: |
| 68 | #print "inside while" |
| 69 | send_pkt(tb,ack_payload) #sending back the acknowledgement |
| 70 | #k=k+1 |
| 71 | print "ok = %5s sync_pktno = %4d n_rcvd = %4d n_right = %4d" % ( |
| 72 | ok, sync_pktno, n_rcvd, n_right) |
182 | | while check: |
183 | | if sync_status != True: |
184 | | #print "inside while" |
185 | | #ch = random.randint(1, 7) |
186 | | ch = int(random.choice('17')) |
187 | | #ch = random.randint(6, 12) |
188 | | #ch = 1 |
189 | | #hop_freq = float(1e6 * (400+(ch-1)*10))#setting the centre freq frequency for sending packets |
190 | | hop_freq = float(1e6 * (462.5625+(ch-1)*0.025)) |
191 | | #hop_freq = float(1e6 * (462.5625+(5-1)*0.05)) |
192 | | print "hop freq is",hop_freq,"@@@@\n" |
193 | | tb.txpath.set_freq(hop_freq) |
194 | | tb.rxpath.set_freq(hop_freq) |
195 | | time.sleep(0.05) |
196 | | #time.sleep(2) |
197 | | else: |
198 | | print "inside lese of while check" |
199 | | #tb.stop() |
200 | | break |
201 | | temp_variable = 2 |
202 | | if temp_variable == 2: |
203 | | print "success" |
| 192 | while running: |
| 193 | ################################################sync mode#################################### |
| 194 | if mode == "sync": |
| 195 | if sync_status != True: |
| 196 | #print "inside while" |
| 197 | #ch = random.randint(1, 7) |
| 198 | ch = int(random.choice('17')) |
| 199 | #ch = random.randint(6, 12) |
| 200 | #ch = 1 |
| 201 | #hop_freq = float(1e6 * (400+(ch-1)*10))#setting the centre freq frequency for sending packets |
| 202 | hop_freq = float(1e6 * (462.5625+(ch-1)*0.025)) |
| 203 | #hop_freq = float(1e6 * (462.5625+(5-1)*0.05)) |
| 204 | print "hop freq is",hop_freq,"@@@@\n" |
| 205 | tb.txpath.set_freq(hop_freq) |
| 206 | tb.rxpath.set_freq(hop_freq) |
| 207 | time.sleep(0.05) |
| 208 | #time.sleep(2) |
| 209 | else: |
| 210 | print "inside lese of while check" |
| 211 | #tb.stop() |
| 212 | break |
| 213 | temp_variable = 2 |
| 214 | if temp_variable == 2: |
| 215 | print "success" |
205 | | print "sync channel is found! and it is channel ",ch," \n" |
| 217 | print "sync channel is found! and it is channel ",ch," \n" |
| 218 | mode = "traffic" |
| 219 | |
| 220 | ################################################end of sync mode#################################### |
| 221 | |
| 222 | ################################################Communications mode#################################### |
| 223 | if mode == "traffic": |
| 224 | time.sleep(0.4) |
| 225 | if traffic_flag != True |
| 226 | mode = "sync" |
| 227 | nbytes = 14 |
| 228 | pkt_size = 14 |
| 229 | sync_pktno = 0 |
| 230 | while n < nbytes: |
| 231 | #print >> myfile, "inside while" |
| 232 | if options_tx.from_file is None: |
| 233 | #data = (pkt_size - 2) * chr(data_pktno & 0xff) #0xff is 255 |
| 234 | data = 'I am fine.....' #Sending this message |
| 235 | #print >> myfile, data |
| 236 | #print "printing data",data,"****\n" |
| 237 | else: |
| 238 | data = source_file.read(pkt_size - 2) |
| 239 | if data == '': |
| 240 | break; |
| 241 | |
| 242 | |
| 243 | payload = struct.pack('!14s', data) |
| 244 | #print "printing payload",payload,"**\n" |
| 245 | |
| 246 | send_pkt(tb,payload) |
| 247 | #print "printing payload",payload,"**\n" |
| 248 | n += len(payload) |
| 249 | sys.stderr.write('.') |
| 250 | if options_tx.discontinuous and data_pktno % 5 == 4: |
| 251 | time.sleep(1) |
| 252 | data_pktno += 1 |
| 253 | #print "before sleeping for 10 seconds and value of resend count is",resend_count |
| 254 | #time.sleep(0.1) |
| 255 | tb.rxpath.min_freq = hop_freq - 80e3 |
| 256 | tb.rxpath.max_freq = hop_freq + 80e3 |
| 257 | is_present = tb.rxpath.get_spec_stats(1e13,10) #check if primary user is present |
| 258 | if is_present == True: #if primary user is present then get out of this communication channel, back to sync mode. |
| 259 | mode = "sync" |
| 260 | |
| 261 | ################################################ end of Communications mode#################################### |
| 262 | |
| 263 | |
| 264 | |