def __init__(self, mod_class, demod_class, rx_callback, options): gr.top_block.__init__(self) # Get the modulation's bits_per_symbol args = mod_class.extract_kwargs_from_options(options) symbol_rate = options.bitrate / mod_class(**args).bits_per_symbol() self.source = uhd_receiver(options.rx_addr, symbol_rate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.rx_spec, options.rx_antenna, options.verbose) self.sink = uhd_transmitter(options.tx_addr, symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.rx_spec, options.rx_antenna, options.verbose) options.samples_per_symbol = self.source._sps self.txpath = transmit_path(mod_class, options) self.rxpath = receive_path(demod_class, rx_callback, options) self.connect(self.txpath, self.sink) self.connect(self.source, self.rxpath)
def __init__(self, node_type, node_index, mod_class, demod_class, rx_callback, options): gr.top_block.__init__(self) # is this node the sub node or head? self._node_type = node_type self._node_id = node_index # Get the modulation's bits_per_symbol args = mod_class.extract_kwargs_from_options(options) symbol_rate = options.bitrate / mod_class(**args).bits_per_symbol() # Automatically USRP devices discovery devices = uhd.find_devices_raw() n_devices = len(devices) addrs = [] if (n_devices == 0): sys.exit("no connected devices") elif (n_devices >= 1): for i in range(n_devices): addr_t = devices[i].to_string() #ex. 'type=usrp2,addr=192.168.10.109,name=,serial=E6R14U3UP' addrs.append(addr_t[11:30]) # suppose the addr is 192.168.10.xxx addrs[i] if (n_devices == 1 and self._node_type == CLUSTER_NODE): sys.exit("only one devices for the node, we need both communicator and sensor for cluster node") elif (n_devices > 1 and self._node_type == CLUSTER_HEAD): sys.exit("only one devices is need for cluster head") # Configure the devices to # 1 Communicator # N Sensors (N >= 1) # How to determin the Communicator? # we need to assure all the sensors to be sync with GPS, except the communicator # thus, the device with non-sync time will be assigned as communicator # Firstly, instantiate all the USRP receivers (including the sensors and the communicator) self.sensors = [] t = [] dt = [] time_src = [] role = [] for i in range(n_devices): self.sensors.append(uhd_sensor(addrs[i], options.sx_samprate, options.sx_freq, options.sx_gain, options.sx_spec, options.sx_antenna, options.verbose)) if self.sensors[i].u.get_time_source(0) == "none": self.sensors[i].u.set_time_source("mimo", 0) # Set the time source without GPS to MIMO cable self.sensors[i].u.set_clock_source("mimo",0) time_src.append(self.sensors[i].u.get_time_source(0)) time.sleep(4) # time to sync between mimo connected devices for i in range(n_devices): t.append(self.sensors[i].u.get_time_now().get_real_secs()) role.append("sensor") dt.append(1) if i > 0: for j in range(i): if (abs(t[j] - t[i]) < 0.1): # Find a pair of GPS synched devices dt[i] += 1 dt[j] += 1 # Find the communicator found_com = 0 print t print addrs print time_src print dt cind = 0 for i in range(n_devices): if found_com == 1: break if n_devices == 2: if self.sensors[i].u.get_time_source(0) == "mimo" and found_com == 0: cind = i found_com = 1 elif i == 1 and slef.sensors[i].u.get_time_source(0) == "gpsdo" and found_com == 0: cind = i found_com = 1 elif i == 1: sys.exit("configure error, no communicaotr found for 2 devices") elif (dt[i] != n_devices - 1 and dt[i] != 1) or (sum(dt) == n_devices): sys.exit("configure error or Not sync") elif dt[i] == 1 and found_com == 0: # We select this as communicator cind = i found_com = 1 if found_com == 1: del self.sensors[cind] # delete this devices from sensor list role[cind] = "com" self.source = uhd_receiver(addrs[cind], symbol_rate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.rx_spec, options.rx_antenna, options.verbose) self.sink = uhd_transmitter(addrs[cind], symbol_rate, options.samples_per_symbol, options.tx_freq, options.tx_gain, options.rx_spec, options.rx_antenna, options.verbose) del addrs[cind] # Ignore the addrs of communicator print role if found_com == 0: # no communicator found sys.exit("Configuration Error") # Setup the rest of USRPs as sensors if (self._node_type == CLUSTER_NODE and STREAM_OR_FINITE == 0): for i in range(n_devices - 1): filename = "%s_sensed.dat" %(addrs[i]) self.connect(self.sensors[i].u, gr.file_sink(gr.sizeof_gr_complex, filename)) options.samples_per_symbol = self.source._sps self.txpath = transmit_path(mod_class, options) self.rxpath = receive_path(demod_class, rx_callback, options) self.connect(self.txpath, self.sink) self.connect(self.source, self.rxpath)