summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-12-09 13:17:24 -0800
committerJosh Blum <josh@joshknows.com>2010-12-09 13:17:24 -0800
commit0e693a62a89dc705c708cf50a8e5debec382e91f (patch)
tree90a826416dc00e413e6b9eff4e2f53845c6e24cd /host
parentcc639e876f326e958dace8438ae41b8cd9563780 (diff)
downloaduhd-0e693a62a89dc705c708cf50a8e5debec382e91f.tar.gz
uhd-0e693a62a89dc705c708cf50a8e5debec382e91f.tar.bz2
uhd-0e693a62a89dc705c708cf50a8e5debec382e91f.zip
usrp2: polished the multi-device addressing scheme and updated docs
Diffstat (limited to 'host')
-rw-r--r--host/docs/index.rst2
-rw-r--r--host/docs/usrp2.rst254
-rw-r--r--host/docs/usrp_nxxx.rst252
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp96
4 files changed, 331 insertions, 273 deletions
diff --git a/host/docs/index.rst b/host/docs/index.rst
index c491c5da6..6dac2680c 100644
--- a/host/docs/index.rst
+++ b/host/docs/index.rst
@@ -24,7 +24,7 @@ Application Notes
* `Device Identification Notes <./identification.html>`_
* `Firmware and FPGA Image Notes <./images.html>`_
* `USRP1 Application Notes <./usrp1.html>`_
-* `USRP2 and USRP-N Series Application Notes <./usrp_nxxx.html>`_
+* `USRP2 and N Series Application Notes <./usrp2.html>`_
* `Daughterboard Application Notes <./dboards.html>`_
* `Transport Application Notes <./transport.html>`_
diff --git a/host/docs/usrp2.rst b/host/docs/usrp2.rst
index af2df66c6..8e5743102 100644
--- a/host/docs/usrp2.rst
+++ b/host/docs/usrp2.rst
@@ -1,5 +1,255 @@
========================================================================
-UHD - USRP2 Application Notes
+UHD - USRP2 and N Series Application Notes
========================================================================
-* `USRP2 and USRP-N Series Application Notes <./usrp_nxxx.html>`_
+.. contents:: Table of Contents
+
+------------------------------------------------------------------------
+Load the images onto the SD card (USRP2 only)
+------------------------------------------------------------------------
+**Warning!**
+Use the usrp2_card_burner.py with caution. If you specify the wrong device node,
+you could overwrite your hard drive. Make sure that --dev= specifies the SD card.
+
+**Warning!**
+It is possible to use 3rd party SD cards with the USRP2.
+However, certain types of SD cards will not interface with the CPLD:
+
+* Cards can be SDHC, which is not a supported interface.
+* Cards can have unexpected timing characteristics.
+
+For these reasons, we recommend that you use the SD card that was supplied with the USRP2.
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Use the card burner tool (unix)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+::
+
+ sudo <prefix>/share/uhd/utils/usrp2_card_burner_gui.py
+
+ -- OR --
+
+ cd <prefix>/share/uhd/utils
+ sudo ./usrp2_card_burner.py --dev=/dev/sd<XXX> --fpga=<path_to_fpga_image>
+ sudo ./usrp2_card_burner.py --dev=/dev/sd<XXX> --fw=<path_to_firmware_image>
+
+Use the *--list* option to get a list of possible raw devices.
+The list result will filter out disk partitions and devices too large to be the sd card.
+The list option has been implemented on Linux, Mac OS X, and Windows.
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Use the card burner tool (windows)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+::
+
+ <path_to_python.exe> <prefix>/share/uhd/utils/usrp2_card_burner_gui.py
+
+
+------------------------------------------------------------------------
+Load the images onto the on-board flash (USRP-N Series only)
+------------------------------------------------------------------------
+The USRP-N Series can be reprogrammed over the network
+to update or change the firmware and FPGA images.
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Use the net burner tool (unix)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+::
+
+ cd <prefix>/share/uhd/utils
+ ./usrp_n2xx_net_burner.py --ip=<ip address> --fw=<path for firmware image>
+ ./usrp_n2xx_net_burner.py --ip=<ip address> --fpga=<path to FPGA image>
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Use the net burner tool (Windows)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+::
+
+ <path_to_python.exe> <prefix>/share/uhd/utils/usrp_n2xx_net_burner.py --ip=<ip address> --fw=<path for firmware image>
+ <path_to_python.exe> <prefix>/share/uhd/utils/usrp_n2xx_net_burner.py --ip=<ip address> --fpga=<path to FPGA image>
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Device recovery and bricking
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Its possible to put the device into an unusable state by loading bad images.
+Fortunately, the USRP-N Series can be booted into a safe (read-only) image.
+Once booted into the safe image, the user can once again load images onto the device.
+
+To boot into the safe image, hold down the reset button while power-cycling the device.
+The reset button is a pushbutton switch (S2) located inside the enclosure.
+
+------------------------------------------------------------------------
+Setup networking
+------------------------------------------------------------------------
+The USRP2 only supports gigabit ethernet,
+and will not work with a 10/100 Mbps interface.
+However, a 10/100 Mbps interface can be connected indirectly
+to a USRP2 through a gigabit ethernet switch.
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Setup the host interface
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+The USRP2 communicates at the IP/UDP layer over the gigabit ethernet.
+The default IP address of the USRP2 is **192.168.10.2**
+You will need to configure the host's ethernet interface with a static IP address to enable communication.
+An address of **192.168.10.1** and a subnet mask of **255.255.255.0** is recommended.
+
+**Note:**
+When using the UHD, if an IP address for the USRP2 is not specified,
+the software will use UDP broadcast packets to locate the USRP2.
+On some systems, the firewall will block UDP broadcast packets.
+It is recommended that you change or disable your firewall settings.
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Multiple device configuration
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+For maximum throughput, one ethernet interface per USRP2 is recommended,
+although multiple devices may be connected via a gigabit ethernet switch.
+In any case, each ethernet interface should have its own subnet,
+and the corresponding USRP2 device should be assigned an address in that subnet.
+Example:
+
+**Configuration for USRP2 device 0:**
+
+* Ethernet interface IPv4 address: 192.168.10.1
+* Ethernet interface subnet mask: 255.255.255.0
+* USRP2 device IPv4 address: 192.168.10.2
+
+**Configuration for USRP2 device 1:**
+
+* Ethernet interface IPv4 address: 192.168.20.1
+* Ethernet interface subnet mask: 255.255.255.0
+* USRP2 device IPv4 address: 192.168.20.2
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Change the USRP2's IP address
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+You may need to change the USRP2's IP address for several reasons:
+
+* to satisfy your particular network configuration
+* to use multiple USRP2s on the same host computer
+* to set a known IP address into USRP2 (in case you forgot)
+
+**Method 1:**
+To change the USRP2's IP address
+you must know the current address of the USRP2,
+and the network must be setup properly as described above.
+Run the following commands:
+::
+
+ cd <prefix>/share/uhd/utils
+ ./usrp_burn_mb_eeprom --args=<optional device args> --key=ip-addr --val=192.168.10.3
+
+**Method 2 (Linux Only):**
+This method assumes that you do not know the IP address of your USRP2.
+It uses raw ethernet packets to bypass the IP/UDP layer to communicate with the USRP2.
+Run the following commands:
+::
+
+ cd <prefix>/share/uhd/utils
+ sudo ./usrp2_recovery.py --ifc=eth0 --new-ip=192.168.10.3
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Debugging networking problems
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+**Disable the firewall:**
+If uhd_find_devices gives you nothing
+but uhd_find_devices --args addr=192.168.10.2 yeilds a discovered device,
+then your firewall may be blocking replies to UDP broadcast packets.
+
+**Ping the USRP2:**
+The USRP2 will reply to icmp echo requests.
+::
+
+ ping 192.168.10.2
+
+**Monitor the USRP2:**
+You can read the serial port on the rear of the USRP2
+to get debug verbose from the embedded microcontroller.
+Use a standard USB to 3.3v-level serial converter at 230400 baud.
+The microcontroller prints useful information about IP addresses,
+MAC addresses, control packets, and fast-path settings.
+
+**Monitor the host network traffic:**
+Use wireshark to monitor packets sent to and received from the USRP2.
+
+------------------------------------------------------------------------
+Addressing the device
+------------------------------------------------------------------------
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Single device configuration
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+In a single-device configuration,
+the USRP device must have a unique IPv4 address on the host computer.
+The USRP can be identified through its IPv4 address, resolvable hostname, or by other means.
+See the application notes on `device identification <./identification.html>`_.
+Use this addressing scheme with the *single_usrp* interface.
+
+Example device address string representation for a USRP2 with IPv4 address 192.168.10.2
+
+::
+
+ addr=192.168.10.2
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Multiple device configuration
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+In a multi-device configuration,
+each USRP device must have a unique IPv4 address on the host computer.
+The device address parameter keys must be suffixed with the device index.
+Each parameter key should be of the format <key><index>.
+Use this addressing scheme with the *multi_usrp* interface.
+
+* The order in which devices are indexed corresponds to the indexing of the transmit and receive channels.
+* The key indexing provides the same granularity of device identification as in the single device case.
+
+Example device address string representation for 2 USRP2s with IPv4 addresses 192.168.10.2 and 192.168.20.2
+::
+
+ addr0=192.168.10.2, addr1=192.168.20.2
+
+------------------------------------------------------------------------
+Hardware setup notes
+------------------------------------------------------------------------
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Front panel LEDs
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+The LEDs on the front panel can be useful in debugging hardware and software issues.
+The LEDs reveal the following about the state of the device:
+
+* **LED A:** transmitting
+* **LED B:** serdes link
+* **LED C:** receiving
+* **LED D:** firmware loaded
+* **LED E:** reference lock
+* **LED F:** CPLD loaded
+
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Ref Clock - 10MHz
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Using an external 10MHz reference clock, square wave will offer the best phase
+noise performance, but sinusoid is acceptable. The reference clock requires the following power level:
+
+* **USRP2** 5 to 15dBm
+* **N2XX** 0 to 15dBm
+
+
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+PPS - Pulse Per Second
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Using a PPS signal for timestamp synchronization requires a square wave signal with the following amplitude:
+
+* **USRP2** 5Vpp
+* **N2XX** 3.3 to 5Vpp
+
+Test the PPS input with the following app:
+
+* <args> are device address arguments (optional if only one USRP is on your machine)
+
+::
+
+ cd <prefix>/share/uhd/examples
+ ./test_pps_input --args=<args>
diff --git a/host/docs/usrp_nxxx.rst b/host/docs/usrp_nxxx.rst
index 575f0ff70..733078915 100644
--- a/host/docs/usrp_nxxx.rst
+++ b/host/docs/usrp_nxxx.rst
@@ -1,253 +1,5 @@
========================================================================
-UHD - USRP2 and USRP-N Series Application Notes
+UHD - USRP-N Series Application Notes
========================================================================
-.. contents:: Table of Contents
-
-------------------------------------------------------------------------
-Load the images onto the SD card (USRP2 only)
-------------------------------------------------------------------------
-**Warning!**
-Use the usrp2_card_burner.py with caution. If you specify the wrong device node,
-you could overwrite your hard drive. Make sure that --dev= specifies the SD card.
-
-**Warning!**
-It is possible to use 3rd party SD cards with the USRP2.
-However, certain types of SD cards will not interface with the CPLD:
-
-* Cards can be SDHC, which is not a supported interface.
-* Cards can have unexpected timing characteristics.
-
-For these reasons, we recommend that you use the SD card that was supplied with the USRP2.
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Use the card burner tool (unix)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
-
- sudo <prefix>/share/uhd/utils/usrp2_card_burner_gui.py
-
- -- OR --
-
- cd <prefix>/share/uhd/utils
- sudo ./usrp2_card_burner.py --dev=/dev/sd<XXX> --fpga=<path_to_fpga_image>
- sudo ./usrp2_card_burner.py --dev=/dev/sd<XXX> --fw=<path_to_firmware_image>
-
-Use the *--list* option to get a list of possible raw devices.
-The list result will filter out disk partitions and devices too large to be the sd card.
-The list option has been implemented on Linux, Mac OS X, and Windows.
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Use the card burner tool (windows)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
-
- <path_to_python.exe> <prefix>/share/uhd/utils/usrp2_card_burner_gui.py
-
-
-------------------------------------------------------------------------
-Load the images onto the on-board flash (USRP-N Series only)
-------------------------------------------------------------------------
-The USRP-N Series can be reprogrammed over the network
-to update or change the firmware and FPGA images.
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Use the net burner tool (unix)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
-
- cd <prefix>/share/uhd/utils
- ./usrp_n2xx_net_burner.py --ip=<ip address> --fw=<path for firmware image>
- ./usrp_n2xx_net_burner.py --ip=<ip address> --fpga=<path to FPGA image>
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Use the net burner tool (Windows)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
-
- <path_to_python.exe> <prefix>/share/uhd/utils/usrp_n2xx_net_burner.py --ip=<ip address> --fw=<path for firmware image>
- <path_to_python.exe> <prefix>/share/uhd/utils/usrp_n2xx_net_burner.py --ip=<ip address> --fpga=<path to FPGA image>
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Device recovery and bricking
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Its possible to put the device into an unusable state by loading bad images.
-Fortunately, the USRP-N Series can be booted into a safe (read-only) image.
-Once booted into the safe image, the user can once again load images onto the device.
-
-To boot into the safe image, hold down the reset button while power-cycling the device.
-The reset button is a pushbutton switch (S2) located inside the enclosure.
-
-------------------------------------------------------------------------
-Setup networking
-------------------------------------------------------------------------
-The USRP2 only supports gigabit ethernet,
-and will not work with a 10/100 Mbps interface.
-However, a 10/100 Mbps interface can be connected indirectly
-to a USRP2 through a gigabit ethernet switch.
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Setup the host interface
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-The USRP2 communicates at the IP/UDP layer over the gigabit ethernet.
-The default IP address of the USRP2 is **192.168.10.2**
-You will need to configure the host's ethernet interface with a static IP address to enable communication.
-An address of **192.168.10.1** and a subnet mask of **255.255.255.0** is recommended.
-
-**Note:**
-When using the UHD, if an IP address for the USRP2 is not specified,
-the software will use UDP broadcast packets to locate the USRP2.
-On some systems, the firewall will block UDP broadcast packets.
-It is recommended that you change or disable your firewall settings.
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Multiple device configuration
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-For maximum throughput, one ethernet interface per USRP2 is recommended,
-although multiple devices may be connected via a gigabit ethernet switch.
-In any case, each ethernet interface should have its own subnet,
-and the corresponding USRP2 device should be assigned an address in that subnet.
-Example:
-
-**Configuration for USRP2 device 0:**
-
-* Ethernet interface IPv4 address: 192.168.10.1
-* Ethernet interface subnet mask: 255.255.255.0
-* USRP2 device IPv4 address: 192.168.10.2
-
-**Configuration for USRP2 device 1:**
-
-* Ethernet interface IPv4 address: 192.168.20.1
-* Ethernet interface subnet mask: 255.255.255.0
-* USRP2 device IPv4 address: 192.168.20.2
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Change the USRP2's IP address
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-You may need to change the USRP2's IP address for several reasons:
-
-* to satisfy your particular network configuration
-* to use multiple USRP2s on the same host computer
-* to set a known IP address into USRP2 (in case you forgot)
-
-**Method 1:**
-To change the USRP2's IP address
-you must know the current address of the USRP2,
-and the network must be setup properly as described above.
-Run the following commands:
-::
-
- cd <prefix>/share/uhd/utils
- ./usrp_burn_mb_eeprom --args=<optional device args> --key=ip-addr --val=192.168.10.3
-
-**Method 2 (Linux Only):**
-This method assumes that you do not know the IP address of your USRP2.
-It uses raw ethernet packets to bypass the IP/UDP layer to communicate with the USRP2.
-Run the following commands:
-::
-
- cd <prefix>/share/uhd/utils
- sudo ./usrp2_recovery.py --ifc=eth0 --new-ip=192.168.10.3
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Debugging networking problems
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-**Disable the firewall:**
-If uhd_find_devices gives you nothing
-but uhd_find_devices --args addr=192.168.10.2 yeilds a discovered device,
-then your firewall may be blocking replies to UDP broadcast packets.
-
-**Ping the USRP2:**
-The USRP2 will reply to icmp echo requests.
-::
-
- ping 192.168.10.2
-
-**Monitor the USRP2:**
-You can read the serial port on the rear of the USRP2
-to get debug verbose from the embedded microcontroller.
-Use a standard USB to 3.3v-level serial converter at 230400 baud.
-The microcontroller prints useful information about IP addresses,
-MAC addresses, control packets, and fast-path settings.
-
-**Monitor the host network traffic:**
-Use wireshark to monitor packets sent to and received from the USRP2.
-
-------------------------------------------------------------------------
-Addressing the device
-------------------------------------------------------------------------
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Single device configuration
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-A USRP2 can be identified though its IPv4 address or resolvable hostname.
-The USRP2 device is referenced through the "addr" key in the device address.
-Use this addressing scheme with the *simple_usrp* interface.
-
-The device address string representation for a USRP2 with IPv4 address 192.168.10.2
-
-::
-
- addr=192.168.10.2
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Soft-MIMO configuration
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-In a soft-mimo configuration, each USRP2 must have a unique IPv4 address (per computer)
-and be attached to its own dedicated network port.
-The value for the addr key is a white-space separated list
-of IPv4 addresses or resolvable hostnames.
-The first address in the list will represent channel 0,
-the second channel 1, and so on...
-Use this addressing scheme with the *multi_usrp* interface.
-
-The device address string representation for 2 USRP2s with IPv4 addresses 192.168.10.2 and 192.168.20.2
-::
-
- addr=192.168.10.2 192.168.20.2
-
-------------------------------------------------------------------------
-Hardware setup notes
-------------------------------------------------------------------------
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Front panel LEDs
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-The LEDs on the front panel can be useful in debugging hardware and software issues.
-The LEDs reveal the following about the state of the device:
-
-* **LED A:** transmitting
-* **LED B:** undocumented
-* **LED C:** receiving
-* **LED D:** firmware loaded
-* **LED E:** reference lock
-* **LED F:** CPLD loaded
-
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Ref Clock - 10MHz
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Using an external 10MHz reference clock, square wave will offer the best phase
-noise performance, but sinusoid is acceptable. The reference clock requires the following power level:
-
-* **USRP2** 5 to 15dBm
-* **N2XX** 0 to 15dBm
-
-
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-PPS - Pulse Per Second
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Using a PPS signal for timestamp synchronization requires a square wave signal with the following amplitude:
-
-* **USRP2** 5Vpp
-* **N2XX** 3.3 to 5Vpp
-
-Test the PPS input with the following app:
-
-* <args> are device address arguments (optional if only one USRP is on your machine)
-
-::
-
- cd <prefix>/share/uhd/examples
- ./test_pps_input --args=<args>
-
+* `USRP2 and N Series Application Notes <./usrp2.html>`_
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 610e2f404..c3bbe4d65 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -27,6 +27,7 @@
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/regex.hpp>
#include <boost/bind.hpp>
#include <boost/asio.hpp> //htonl and ntohl
#include <iostream>
@@ -43,10 +44,76 @@ template <class T> std::string num2str(T num){
return boost::lexical_cast<std::string>(num);
}
+//! separate indexed device addresses into a vector of device addresses
+device_addrs_t sep_indexed_dev_addrs(const device_addr_t &dev_addr){
+ //------------ support old deprecated way and print warning --------
+ if (dev_addr.has_key("addr")){
+ std::vector<std::string> addrs = std::split_string(dev_addr["addr"]);
+ if (addrs.size() > 1){
+ device_addr_t fixed_dev_addr = dev_addr;
+ fixed_dev_addr.pop("addr");
+ for (size_t i = 0; i < addrs.size(); i++){
+ fixed_dev_addr[str(boost::format("addr%d") % i)] = addrs[i];
+ }
+ uhd::warning::post(
+ "addr = <space separated list of ip addresses> is deprecated.\n"
+ "To address a multi-device, use multiple <key><index> = <val>.\n"
+ "See the USRP-NXXX application notes. Two device example:\n"
+ " addr0 = 192.168.10.2\n"
+ " addr1 = 192.168.10.3\n"
+ );
+ return sep_indexed_dev_addrs(fixed_dev_addr);
+ }
+ }
+ //------------------------------------------------------------------
+ device_addrs_t dev_addrs;
+ BOOST_FOREACH(const std::string &key, dev_addr.keys()){
+ boost::cmatch matches;
+ if (not boost::regex_match(key.c_str(), matches, boost::regex("^(\\D+)(\\d*)$"))){
+ throw std::runtime_error("unknown key format: " + key);
+ }
+ std::string key_part(matches[1].first, matches[1].second);
+ std::string num_part(matches[2].first, matches[2].second);
+ size_t num = (num_part.empty())? 0 : boost::lexical_cast<size_t>(num_part);
+ dev_addrs.resize(std::max(num+1, dev_addrs.size()));
+ dev_addrs[num][key_part] = dev_addr[key];
+ }
+ return dev_addrs;
+}
+
+//! combine a vector in device addresses into an indexed device address
+device_addr_t combine_dev_addr_vector(const device_addrs_t &dev_addrs){
+ device_addr_t dev_addr;
+ for (size_t i = 0; i < dev_addrs.size(); i++){
+ BOOST_FOREACH(const std::string &key, dev_addrs[i].keys()){
+ dev_addr[str(boost::format("%s%d") % key % i)] = dev_addrs[i][key];
+ }
+ }
+ return dev_addr;
+}
+
/***********************************************************************
* Discovery over the udp transport
**********************************************************************/
-static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){
+static device_addrs_t usrp2_find(const device_addr_t &hint_){
+ //handle the multi-device discovery
+ device_addrs_t hints = sep_indexed_dev_addrs(hint_);
+ if (hints.size() > 1){
+ device_addrs_t found_devices;
+ BOOST_FOREACH(const device_addr_t &hint_i, hints){
+ device_addrs_t found_devices_i = usrp2_find(hint_i);
+ if (found_devices_i.size() != 1) throw std::runtime_error(str(boost::format(
+ "Could not resolve device hint \"%s\" to a single device."
+ ) % hint_i.to_string()));
+ found_devices.push_back(found_devices_i[0]);
+ }
+ return device_addrs_t(1, combine_dev_addr_vector(found_devices));
+ }
+
+ //initialize the hint for a single device case
+ UHD_ASSERT_THROW(hints.size() <= 1);
+ hints.resize(1); //in case it was empty
+ device_addr_t hint = hints[0];
device_addrs_t usrp2_addrs;
//return an empty list of addresses when type is set to non-usrp2
@@ -71,16 +138,6 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){
return usrp2_addrs;
}
- //if there are multiple addresses, just return good, dont test
- std::vector<std::string> addrs = std::split_string(hint["addr"]);
- if (addrs.size() > 1){
- device_addr_t new_addr;
- new_addr["type"] = "usrp2";
- new_addr["addr"] = hint["addr"];
- usrp2_addrs.push_back(new_addr);
- return usrp2_addrs;
- }
-
//create a udp transport to communicate
std::string ctrl_port = boost::lexical_cast<std::string>(USRP2_UDP_CTRL_PORT);
udp_simple::sptr udp_transport = udp_simple::make_broadcast(
@@ -106,9 +163,8 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){
new_addr["type"] = "usrp2";
new_addr["addr"] = ip_addr.to_string();
//Attempt to read the name from the EEPROM and perform filtering.
- //This operation can throw due to COMPAT mismatch. That is OK.
- //We will allow the device to be found and the COMPAT mismatch
- //will be thrown as an exception in the factory function.
+ //This operation can throw due to compatibility mismatch.
+ //In this case, the discovered device will be ignored.
try{
mboard_eeprom_t mb_eeprom = usrp2_iface::make(
udp_simple::make_connected(new_addr["addr"], num2str(USRP2_UDP_CTRL_PORT))
@@ -141,17 +197,17 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){
* Make
**********************************************************************/
static device::sptr usrp2_make(const device_addr_t &device_addr){
-
+sep_indexed_dev_addrs(device_addr);
//create a ctrl and data transport for each address
std::vector<udp_simple::sptr> ctrl_transports;
std::vector<zero_copy_if::sptr> data_transports;
- BOOST_FOREACH(const std::string &addr, std::split_string(device_addr["addr"])){
+ BOOST_FOREACH(const device_addr_t &dev_addr_i, sep_indexed_dev_addrs(device_addr)){
ctrl_transports.push_back(udp_simple::make_connected(
- addr, num2str(USRP2_UDP_CTRL_PORT)
+ dev_addr_i["addr"], num2str(USRP2_UDP_CTRL_PORT)
));
data_transports.push_back(udp_zero_copy::make(
- addr, num2str(USRP2_UDP_DATA_PORT), device_addr
+ dev_addr_i["addr"], num2str(USRP2_UDP_DATA_PORT), device_addr
));
}
@@ -217,8 +273,8 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){
//handle the get request conditioned on the key
switch(key.as<device_prop_t>()){
case DEVICE_PROP_NAME:
- if (_mboards.size() > 1) val = std::string("USRP-NXXX mimo device");
- else val = std::string("USRP-NXXX device");
+ if (_mboards.size() > 1) val = std::string("USRP2/N Series multi-device");
+ else val = std::string("USRP2/N Series device");
return;
case DEVICE_PROP_MBOARD: