def init_sim(self, n): """ initialize simulation for n receivers. """ if n < 3: print 'Number of receivers %i is less than three.' % n print 'Simulation controller will not run.' print 'Now exiting.' sys.exit() self.data.set_rx_number(n) self.beacon = beacon() tx_loc = test_coords.get_tx_coords() self.data.set_tx_location(tx_loc) for i in range(n): rx_loc = alex_random.get_random_coord() self.data.set_rx_location(rx_loc) tof = self.geo_utils.time_of_flight(rx_loc, tx_loc) self.data.set_rx_time_delay(tof) id = i + 1 self.data.set_rx_team_id(id) if self.DEBUG: print 'tx_loc: ', tx_loc print 'rx_loc: ', rx_loc print 'time: ', repr(tof) print 'id: ', id
def init_sim(self,n): """ initialize simulation for n receivers. """ if n < 3: print 'Number of receivers %i is less than three.' %n print 'Simulation controller will not run.' print 'Now exiting.' sys.exit() self.data.set_rx_number(n) tx_loc = test_coords.get_tx_coords() self.data.set_tx_location(tx_loc) self.data.reset_rx_location() for i in range(n): rx_loc = alex_random.get_random_coord() print "\n\n\n\n\n\nstore location: ", rx_loc print '\n\n\n\n\n\n' self.data.set_rx_location(rx_loc) tof = self.geo_utils.time_of_flight(rx_loc,tx_loc) self.data.set_rx_time_delay(tof) id = i+1 self.data.set_rx_team_id(id) if self.DEBUG: print 'tx_loc: ', tx_loc print 'rx_loc: ', rx_loc print 'time: ', repr(tof) print 'id: ', id
# f = open('y_results','r') # b = f.readlines() # f.close() # b = [float(x.strip('\n')) for x in b] # i = 0 # while ( i < len(a) ): # x_results.append(a[i]) # y_results.append(b[i]) # i +=1 # coordinates tx = test_coords.get_tx_coords() rx1 = test_coords.get_boathouse_coords() rx2 = test_coords.get_uspto_coords() rx3 = test_coords.get_tcwhs_coords() rx4 = test_coords.get_lee_st_coords() main.tdoa_sim(tx,rx1,rx2,rx3) # intersection = main.tdoa_sim(tx,rx1,rx2,rx3) # x_results += intersection[0] # y_results += intersection[1] # plt.figure() # plt.plot(x_h1,y_h1,'b', # x_h2,y_h2,'g', # ) # plt.grid(True)
# s = repr(t_c) + '.' + time # print "unpack_time:" # print "s = repr(t_c) + '.' + repr(t_m).zfill(10): ", repr(s) # t = np.float128(s) # print "t = np.float128(s): ", repr(t) return t if __name__ == '__main__': import time import test_coords tx_loc = test_coords.get_tx_coords() print tx_loc x = pack_loc(tx_loc) print len(x) x = unpack_loc(x) print x # tx_loc_p = pack_loc(tx_loc) # tx_loc_unp = unpack_loc(tx_loc_p) # print tx_loc_unp # rx_time = np.float128(str('%.10f'%(time.time()))) # print 'rx_time:\n', repr(rx_time).zfill(10) # a1 = pack_time(rx_time) # t = unpack_time(a1)
def run(self): # administrivia ######################################################################## self.start_db() g = geo_utils() if ( options.backoff or options.drop ): stoch = sim_utils.stochastics() stoch.set_packet_error_rate(options.rate) stoch.set_max_delay(options.delay) tx = test_coords.get_tx_coords() field_radios = options.radios # iterations = options.iterations update_status = 0 i = 0 ######################################################################## while True: # for i in range(iterations): ii = i + 1 # beacon pkt num jj = i + 1 # field team pkt num # this part simulates the beacon transmission #################################################################### # print '( not (ii == 1) and options.backoff ): ', ( not (ii == 1) and # options.backoff ) if ( not (ii == 1) and options.backoff ): stoch.backoff() beacon_pkt_num = ii beacon_id = 42 b1 = struct.pack('!i', beacon_pkt_num) b2 = struct.pack('!i', beacon_id) beacon_payload = b1+b2 #################################################################### for k in range(field_radios): kk = k + 1 # team id # this part simulates the field team re-transmission ################################################################ # set the values field_radio_pkt_num = ii field_team_id = kk field_team_loc = self.get_location(ii,kk) field_team_time = sim_utils.time_of_flight(tx,field_team_loc) # pack the values f1 = struct.pack('!i', field_radio_pkt_num) f2 = struct.pack('!i', field_team_id) f3 = pack_utils.pack_loc(field_team_loc) f4 = pack_utils.pack_time(field_team_time) # build the payload field_team_payload = f1 + f2 + f3 + f4 + beacon_payload if ( options.drop and stoch.drop_packet() ): continue # drop packet # send the payload to hq self.write_db(field_team_payload) ################################################################ update_status += 1 #endfor update(update_status) i += 1 #endfor self.stop_db() sys.stdout.write('\nDone\n\n') sys.stdout.flush()
################################################################################ (t_c,) = struct.unpack('!I', payload[0:4]) (t_m,) = struct.unpack('!d', payload[4:12]) t = repr(np.float128(t_c) + np.float128(t_m)) return t ################################################################################ if __name__=='__main__': import time import test_coords tx_loc = test_coords.get_tx_coords() print tx_loc x = pack_loc(tx_loc) print len(x) x = unpack_loc(x) print x # tx_loc_p = pack_loc(tx_loc) # tx_loc_unp = unpack_loc(tx_loc_p) # print tx_loc_unp # rx_time = np.float128(str('%.10f'%(time.time()))) # print 'rx_time:\n', repr(rx_time).zfill(10)
(x_h2, y_h2) = self.geo_utils.hyperbola(rx1, rx3, tof_1, tof_3) return [x_h1, y_h1, x_h2, y_h2] if __name__ == '__main__': t0 = time.time() main = geolocate() h = hyperbola_writer() x_results = np.array([]) y_results = np.array([]) # coordinates tx = test_coords.get_tx_coords() rx1 = test_coords.get_boathouse_coords() rx2 = test_coords.get_uspto_coords() rx3 = test_coords.get_tcwhs_coords() rx4 = test_coords.get_lee_st_coords() # write hyperbolas to kml file ans = main.tdoa_sim(tx, rx1, rx2, rx3) h.write_hyperbola(ans) # ans = main.tdoa_sim(tx,rx1,rx3,rx4) # hyp_kml_writer.write_hyperbola(ans,'hyp2.kml') # ans = main.tdoa_sim(tx,rx2,rx3,rx4) # hyp_kml_writer.write_hyperbola(ans,'hyp3.kml')
def run(self): # administrivia ######################################################################## self.start_db() g = geo_utils() if (options.backoff or options.drop): stoch = sim_utils.stochastics() stoch.set_packet_error_rate(options.rate) stoch.set_max_delay(options.delay) tx = test_coords.get_tx_coords() field_radios = options.radios # iterations = options.iterations update_status = 0 i = 0 ######################################################################## while True: # for i in range(iterations): ii = i + 1 # beacon pkt num jj = i + 1 # field team pkt num # this part simulates the beacon transmission #################################################################### # print '( not (ii == 1) and options.backoff ): ', ( not (ii == 1) and # options.backoff ) if (not (ii == 1) and options.backoff): stoch.backoff() beacon_pkt_num = ii beacon_id = 42 b1 = struct.pack('!i', beacon_pkt_num) b2 = struct.pack('!i', beacon_id) beacon_payload = b1 + b2 #################################################################### for k in range(field_radios): kk = k + 1 # team id # this part simulates the field team re-transmission ################################################################ # set the values field_radio_pkt_num = ii field_team_id = kk field_team_loc = self.get_location(ii, kk) field_team_time = sim_utils.time_of_flight(tx, field_team_loc) # pack the values f1 = struct.pack('!i', field_radio_pkt_num) f2 = struct.pack('!i', field_team_id) f3 = pack_utils.pack_loc(field_team_loc) f4 = pack_utils.pack_time(field_team_time) # build the payload field_team_payload = f1 + f2 + f3 + f4 + beacon_payload if (options.drop and stoch.drop_packet()): continue # drop packet # send the payload to hq self.write_db(field_team_payload) ################################################################ update_status += 1 #endfor update(update_status) i += 1 #endfor self.stop_db() sys.stdout.write('\nDone\n\n') sys.stdout.flush()