From 24bd27b90d06820d858c008cff915319873321c5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 23 Mar 2010 20:44:50 -0700 Subject: Reorganized apps dir into utils and examples dir. The files get installed into the pkg data directory. --- host/CMakeLists.txt | 10 ++-- host/README | 8 ++- host/apps/CMakeLists.txt | 26 --------- host/apps/discover_usrps.cpp | 70 ------------------------ host/apps/uhd_rx_timed_samples.cpp | 91 ------------------------------- host/apps/usrp2_burner.cpp | 84 ---------------------------- host/apps/usrp2_recovery.py | 52 ------------------ host/examples/CMakeLists.txt | 20 +++++++ host/examples/rx_timed_samples.cpp | 91 +++++++++++++++++++++++++++++++ host/include/uhd/CMakeLists.txt | 2 +- host/include/uhd/transport/CMakeLists.txt | 2 +- host/include/uhd/usrp/CMakeLists.txt | 2 +- host/uhd.pc.in | 2 +- host/utils/CMakeLists.txt | 26 +++++++++ host/utils/discover_usrps.cpp | 70 ++++++++++++++++++++++++ host/utils/usrp2_burner.cpp | 84 ++++++++++++++++++++++++++++ host/utils/usrp2_recovery.py | 52 ++++++++++++++++++ 17 files changed, 359 insertions(+), 333 deletions(-) delete mode 100644 host/apps/CMakeLists.txt delete mode 100644 host/apps/discover_usrps.cpp delete mode 100644 host/apps/uhd_rx_timed_samples.cpp delete mode 100644 host/apps/usrp2_burner.cpp delete mode 100755 host/apps/usrp2_recovery.py create mode 100644 host/examples/CMakeLists.txt create mode 100644 host/examples/rx_timed_samples.cpp create mode 100644 host/utils/CMakeLists.txt create mode 100644 host/utils/discover_usrps.cpp create mode 100644 host/utils/usrp2_burner.cpp create mode 100755 host/utils/usrp2_recovery.py (limited to 'host') diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 2f5d03f7d..148ba2d00 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -34,8 +34,9 @@ INCLUDE(CPack) #include after setting vars ######################################################################## SET(RUNTIME_DIR bin) SET(LIBRARY_DIR lib) -SET(RESOURCE_DIR share) -SET(HEADER_DIR include) +SET(INCLUDE_DIR include) +SET(PKG_DATA_DIR share/uhd) +MESSAGE(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}") ######################################################################## # Local Include Dir @@ -74,7 +75,7 @@ ENDIF(WIN32) # Setup Boost ######################################################################## SET(Boost_ADDITIONAL_VERSIONS "1.42.0" "1.42") -FIND_PACKAGE(Boost 1.36 REQUIRED +FIND_PACKAGE(Boost 1.36 REQUIRED COMPONENTS date_time filesystem program_options @@ -126,7 +127,8 @@ INSTALL( ######################################################################## # Add the subdirectories ######################################################################## -ADD_SUBDIRECTORY(apps) +ADD_SUBDIRECTORY(examples) ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(test) +ADD_SUBDIRECTORY(utils) diff --git a/host/README b/host/README index f19275c41..cdca42cd0 100644 --- a/host/README +++ b/host/README @@ -6,21 +6,25 @@ The hardware driver for Ettus Research products. ######################################################################## # Supported USRP Motherboards ######################################################################## -USRP2 - gigabit ethernet +USRP2 - udp over gigabit ethernet ######################################################################## # Supported USRP Daughterboards ######################################################################## Basic RX Basic TX +LF RX +LF TX ######################################################################## # CMake Instructions ######################################################################## -cd +cd uhd/host mkdir build cd build cmake ../ make make test sudo make install + +For a custom prefix, use: cmake -DCMAKE_INSTALL_PREFIX= ../ diff --git a/host/apps/CMakeLists.txt b/host/apps/CMakeLists.txt deleted file mode 100644 index f31206e1a..000000000 --- a/host/apps/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# -# Copyright 2010 Ettus Research LLC -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -ADD_EXECUTABLE(discover_usrps discover_usrps.cpp) -TARGET_LINK_LIBRARIES(discover_usrps uhd) -INSTALL(TARGETS discover_usrps RUNTIME DESTINATION ${RUNTIME_DIR}) - -ADD_EXECUTABLE(usrp2_burner usrp2_burner.cpp) -TARGET_LINK_LIBRARIES(usrp2_burner uhd) - -ADD_EXECUTABLE(uhd_rx_timed_samples uhd_rx_timed_samples.cpp) -TARGET_LINK_LIBRARIES(uhd_rx_timed_samples uhd) diff --git a/host/apps/discover_usrps.cpp b/host/apps/discover_usrps.cpp deleted file mode 100644 index d670d1651..000000000 --- a/host/apps/discover_usrps.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int main(int argc, char *argv[]){ - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("addr", po::value(), "resolvable network address") - ("node", po::value(), "path to linux device node") - ; - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("Discover USRPs %s") % desc << std::endl; - return ~0; - } - - //load the options into the address - uhd::device_addr_t device_addr; - if (vm.count("addr")){ - device_addr["addr"] = vm["addr"].as(); - } - if (vm.count("node")){ - device_addr["node"] = vm["node"].as(); - } - - //discover the usrps and print the results - uhd::device_addrs_t device_addrs = uhd::device::discover(device_addr); - - if (device_addrs.size() == 0){ - std::cerr << "No USRP Devices Found" << std::endl; - return ~0; - } - - for (size_t i = 0; i < device_addrs.size(); i++){ - std::cout << "--------------------------------------------------" << std::endl; - std::cout << "-- USRP Device " << i << std::endl; - std::cout << "--------------------------------------------------" << std::endl; - std::cout << device_addrs[i] << std::endl << std::endl; - uhd::device::make(device_addrs[i]); //test make - } - - return 0; -} diff --git a/host/apps/uhd_rx_timed_samples.cpp b/host/apps/uhd_rx_timed_samples.cpp deleted file mode 100644 index 97f75647e..000000000 --- a/host/apps/uhd_rx_timed_samples.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#include -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int main(int argc, char *argv[]){ - //variables to be set by po - std::string transport_args; - int seconds_in_future; - size_t total_num_samps; - - //setup the program options - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("args", po::value(&transport_args)->default_value(""), "simple uhd transport args") - ("secs", po::value(&seconds_in_future)->default_value(3), "number of seconds in the future to receive") - ("nsamps", po::value(&total_num_samps)->default_value(1000), "total number of samples to receive") - ; - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("UHD RX Timed Samples %s") % desc << std::endl; - return ~0; - } - - //create a usrp device - std::cout << std::endl; - std::cout << boost::format("Creating the usrp device with: %s...") - % transport_args << std::endl; - uhd::simple_device::sptr sdev = uhd::simple_device::make(transport_args); - uhd::device::sptr dev = sdev->get_device(); - std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; - - //set properties on the device - double rx_rate = sdev->get_rx_rates()[4]; //pick some rate - std::cout << boost::format("Setting RX Rate: %f Msps...") % (rx_rate/1e6) << std::endl; - sdev->set_rx_rate(rx_rate); - std::cout << boost::format("Setting device timestamp to 0...") << std::endl; - sdev->set_time_now(uhd::time_spec_t(0)); - - //setup streaming - std::cout << std::endl; - std::cout << boost::format("Begin streaming %u seconds in the future...") - % seconds_in_future << std::endl; - sdev->set_streaming_at(uhd::time_spec_t(seconds_in_future)); - - //loop until total number of samples reached - size_t num_acc_samps = 0; //number of accumulated samples - while(num_acc_samps < total_num_samps){ - uhd::rx_metadata_t md; - std::complex buff[1000]; - size_t num_rx_samps = dev->recv(boost::asio::buffer(buff, sizeof(buff)), md, "32fc"); - if (num_rx_samps == 0) continue; //wait for packets with contents - - std::cout << boost::format("Got packet: %u samples, %u secs, %u ticks") - % num_rx_samps % md.time_spec.secs % md.time_spec.ticks << std::endl; - - num_acc_samps += num_rx_samps; - } - - //finished, stop streaming - sdev->set_streaming(false); - std::cout << std::endl << "Done!" << std::endl << std::endl; - - return 0; -} diff --git a/host/apps/usrp2_burner.cpp b/host/apps/usrp2_burner.cpp deleted file mode 100644 index 941e71d0c..000000000 --- a/host/apps/usrp2_burner.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int main(int argc, char *argv[]){ - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("addr", po::value(), "resolvable network address") - ("new-ip", po::value(), "new ip address (optional)") - ("new-mac", po::value(), "new mac address (optional)") - ; - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("USRP2 Burner %s") % desc << std::endl; - return ~0; - } - - //load the options into the address - uhd::device_addr_t device_addr; - if (vm.count("addr")){ - device_addr["addr"] = vm["addr"].as(); - } - else{ - std::cerr << "Error: missing addr option" << std::endl; - return ~0; - } - - //create a usrp2 device - uhd::device::sptr u2_dev = uhd::usrp::usrp2::make(device_addr); - //FIXME usees the default mboard for now (until the mimo link is supported) - wax::obj u2_mb = (*u2_dev)[uhd::DEVICE_PROP_MBOARD]; - - //try to set the new ip (if provided) - if (vm.count("new-ip")){ - std::cout << "Burning a new ip address into the usrp2 eeprom:" << std::endl; - std::string old_ip = u2_mb[std::string("ip-addr")].as(); - std::cout << boost::format(" Old IP Address: %s") % old_ip << std::endl; - std::string new_ip = vm["new-ip"].as(); - std::cout << boost::format(" New IP Address: %s") % new_ip << std::endl; - u2_mb[std::string("ip-addr")] = new_ip; - std::cout << " Done" << std::endl; - } - - //try to set the new mac (if provided) - if (vm.count("new-mac")){ - std::cout << "Burning a new mac address into the usrp2 eeprom:" << std::endl; - std::string old_mac = u2_mb[std::string("mac-addr")].as(); - std::cout << boost::format(" Old MAC Address: %s") % old_mac << std::endl; - std::string new_mac = vm["new-mac"].as(); - std::cout << boost::format(" New MAC Address: %s") % new_mac << std::endl; - u2_mb[std::string("mac-addr")] = new_mac; - std::cout << " Done" << std::endl; - } - - std::cout << "Power-cycle the usrp2 for the changes to take effect." << std::endl; - return 0; -} diff --git a/host/apps/usrp2_recovery.py b/host/apps/usrp2_recovery.py deleted file mode 100755 index 48c1121cb..000000000 --- a/host/apps/usrp2_recovery.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python - -""" -The usrp2 recovery app: - -When the usrp2 has an unknown or bad ip address in its eeprom, -it may not be possible to communicate with the usrp2 over ip/udp. - -This app will send a raw ethernet packet to bypass the ip layer. -The packet will contain a known ip address to burn into eeprom. -Because the recovery packet is sent with a broadcast mac address, -only one usrp2 should be present on the interface upon execution. - -This app requires super-user privileges and only works on linux. -""" - -import socket -import struct -import optparse - -BCAST_MAC_ADDR = 'ff:ff:ff:ff:ff:ff' -RECOVERY_ETHERTYPE = 0xbeee -IP_RECOVERY_CODE = 'addr' - -def mac_addr_repr_to_binary_string(mac_addr): - return ''.join(map(lambda x: chr(int(x, 16)), mac_addr.split(':'))) - -if __name__ == '__main__': - parser = optparse.OptionParser(usage='usage: %prog [options]\n'+__doc__) - parser.add_option('--ifc', type='string', help='ethernet interface name [default=%default]', default='eth0') - parser.add_option('--new-ip', type='string', help='ip address to set [default=%default]', default='192.168.10.2') - (options, args) = parser.parse_args() - - #create the raw socket - print "Opening raw socket on interface:", options.ifc - soc = socket.socket(socket.PF_PACKET, socket.SOCK_RAW) - soc.bind((options.ifc, RECOVERY_ETHERTYPE)) - - #create the recovery packet - print "Loading packet with ip address:", options.new_ip - packet = struct.pack( - '!6s6sH4s4s', - mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), - mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), - RECOVERY_ETHERTYPE, - IP_RECOVERY_CODE, - socket.inet_aton(options.new_ip), - ) - - print "Sending packet (%d bytes)"%len(packet) - soc.send(packet) - print "Done" diff --git a/host/examples/CMakeLists.txt b/host/examples/CMakeLists.txt new file mode 100644 index 000000000..242857625 --- /dev/null +++ b/host/examples/CMakeLists.txt @@ -0,0 +1,20 @@ +# +# Copyright 2010 Ettus Research LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +ADD_EXECUTABLE(rx_timed_samples rx_timed_samples.cpp) +TARGET_LINK_LIBRARIES(rx_timed_samples uhd) +INSTALL(TARGETS rx_timed_samples RUNTIME DESTINATION ${PKG_DATA_DIR}/examples) diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp new file mode 100644 index 000000000..97f75647e --- /dev/null +++ b/host/examples/rx_timed_samples.cpp @@ -0,0 +1,91 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int main(int argc, char *argv[]){ + //variables to be set by po + std::string transport_args; + int seconds_in_future; + size_t total_num_samps; + + //setup the program options + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("args", po::value(&transport_args)->default_value(""), "simple uhd transport args") + ("secs", po::value(&seconds_in_future)->default_value(3), "number of seconds in the future to receive") + ("nsamps", po::value(&total_num_samps)->default_value(1000), "total number of samples to receive") + ; + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("UHD RX Timed Samples %s") % desc << std::endl; + return ~0; + } + + //create a usrp device + std::cout << std::endl; + std::cout << boost::format("Creating the usrp device with: %s...") + % transport_args << std::endl; + uhd::simple_device::sptr sdev = uhd::simple_device::make(transport_args); + uhd::device::sptr dev = sdev->get_device(); + std::cout << boost::format("Using Device: %s") % sdev->get_name() << std::endl; + + //set properties on the device + double rx_rate = sdev->get_rx_rates()[4]; //pick some rate + std::cout << boost::format("Setting RX Rate: %f Msps...") % (rx_rate/1e6) << std::endl; + sdev->set_rx_rate(rx_rate); + std::cout << boost::format("Setting device timestamp to 0...") << std::endl; + sdev->set_time_now(uhd::time_spec_t(0)); + + //setup streaming + std::cout << std::endl; + std::cout << boost::format("Begin streaming %u seconds in the future...") + % seconds_in_future << std::endl; + sdev->set_streaming_at(uhd::time_spec_t(seconds_in_future)); + + //loop until total number of samples reached + size_t num_acc_samps = 0; //number of accumulated samples + while(num_acc_samps < total_num_samps){ + uhd::rx_metadata_t md; + std::complex buff[1000]; + size_t num_rx_samps = dev->recv(boost::asio::buffer(buff, sizeof(buff)), md, "32fc"); + if (num_rx_samps == 0) continue; //wait for packets with contents + + std::cout << boost::format("Got packet: %u samples, %u secs, %u ticks") + % num_rx_samps % md.time_spec.secs % md.time_spec.ticks << std::endl; + + num_acc_samps += num_rx_samps; + } + + //finished, stop streaming + sdev->set_streaming(false); + std::cout << std::endl << "Done!" << std::endl << std::endl; + + return 0; +} diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index 3d00462cf..84e7b441b 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -32,5 +32,5 @@ INSTALL(FILES types.hpp utils.hpp wax.hpp - DESTINATION ${HEADER_DIR}/uhd + DESTINATION ${INCLUDE_DIR}/uhd ) diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt index 7f5db2128..75b07c540 100644 --- a/host/include/uhd/transport/CMakeLists.txt +++ b/host/include/uhd/transport/CMakeLists.txt @@ -21,5 +21,5 @@ INSTALL(FILES udp_simple.hpp udp_zero_copy.hpp vrt.hpp - DESTINATION ${HEADER_DIR}/uhd/transport + DESTINATION ${INCLUDE_DIR}/uhd/transport ) diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt index 4e0a92365..bab01fdeb 100644 --- a/host/include/uhd/usrp/CMakeLists.txt +++ b/host/include/uhd/usrp/CMakeLists.txt @@ -23,5 +23,5 @@ INSTALL(FILES dboard_manager.hpp usrp1e.hpp usrp2.hpp - DESTINATION ${HEADER_DIR}/uhd/usrp + DESTINATION ${INCLUDE_DIR}/uhd/usrp ) diff --git a/host/uhd.pc.in b/host/uhd.pc.in index 59ba623f5..2a34e9cfd 100644 --- a/host/uhd.pc.in +++ b/host/uhd.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} libdir=${prefix}/@LIBRARY_DIR@ -includedir=${prefix}/@HEADER_DIR@ +includedir=${prefix}/@INCLUDE_DIR@ Name: @CPACK_PACKAGE_NAME@ Description: Universal Hardware Driver diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt new file mode 100644 index 000000000..9ac3f3a52 --- /dev/null +++ b/host/utils/CMakeLists.txt @@ -0,0 +1,26 @@ +# +# Copyright 2010 Ettus Research LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +ADD_EXECUTABLE(discover_usrps discover_usrps.cpp) +TARGET_LINK_LIBRARIES(discover_usrps uhd) +INSTALL(TARGETS discover_usrps RUNTIME DESTINATION ${RUNTIME_DIR}) + +ADD_EXECUTABLE(usrp2_burner usrp2_burner.cpp) +TARGET_LINK_LIBRARIES(usrp2_burner uhd) +INSTALL(TARGETS usrp2_burner RUNTIME DESTINATION ${PKG_DATA_DIR}/utils) + +INSTALL(FILES usrp2_recovery.py DESTINATION ${PKG_DATA_DIR}/utils) diff --git a/host/utils/discover_usrps.cpp b/host/utils/discover_usrps.cpp new file mode 100644 index 000000000..d670d1651 --- /dev/null +++ b/host/utils/discover_usrps.cpp @@ -0,0 +1,70 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int main(int argc, char *argv[]){ + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("addr", po::value(), "resolvable network address") + ("node", po::value(), "path to linux device node") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("Discover USRPs %s") % desc << std::endl; + return ~0; + } + + //load the options into the address + uhd::device_addr_t device_addr; + if (vm.count("addr")){ + device_addr["addr"] = vm["addr"].as(); + } + if (vm.count("node")){ + device_addr["node"] = vm["node"].as(); + } + + //discover the usrps and print the results + uhd::device_addrs_t device_addrs = uhd::device::discover(device_addr); + + if (device_addrs.size() == 0){ + std::cerr << "No USRP Devices Found" << std::endl; + return ~0; + } + + for (size_t i = 0; i < device_addrs.size(); i++){ + std::cout << "--------------------------------------------------" << std::endl; + std::cout << "-- USRP Device " << i << std::endl; + std::cout << "--------------------------------------------------" << std::endl; + std::cout << device_addrs[i] << std::endl << std::endl; + uhd::device::make(device_addrs[i]); //test make + } + + return 0; +} diff --git a/host/utils/usrp2_burner.cpp b/host/utils/usrp2_burner.cpp new file mode 100644 index 000000000..941e71d0c --- /dev/null +++ b/host/utils/usrp2_burner.cpp @@ -0,0 +1,84 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int main(int argc, char *argv[]){ + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("addr", po::value(), "resolvable network address") + ("new-ip", po::value(), "new ip address (optional)") + ("new-mac", po::value(), "new mac address (optional)") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("USRP2 Burner %s") % desc << std::endl; + return ~0; + } + + //load the options into the address + uhd::device_addr_t device_addr; + if (vm.count("addr")){ + device_addr["addr"] = vm["addr"].as(); + } + else{ + std::cerr << "Error: missing addr option" << std::endl; + return ~0; + } + + //create a usrp2 device + uhd::device::sptr u2_dev = uhd::usrp::usrp2::make(device_addr); + //FIXME usees the default mboard for now (until the mimo link is supported) + wax::obj u2_mb = (*u2_dev)[uhd::DEVICE_PROP_MBOARD]; + + //try to set the new ip (if provided) + if (vm.count("new-ip")){ + std::cout << "Burning a new ip address into the usrp2 eeprom:" << std::endl; + std::string old_ip = u2_mb[std::string("ip-addr")].as(); + std::cout << boost::format(" Old IP Address: %s") % old_ip << std::endl; + std::string new_ip = vm["new-ip"].as(); + std::cout << boost::format(" New IP Address: %s") % new_ip << std::endl; + u2_mb[std::string("ip-addr")] = new_ip; + std::cout << " Done" << std::endl; + } + + //try to set the new mac (if provided) + if (vm.count("new-mac")){ + std::cout << "Burning a new mac address into the usrp2 eeprom:" << std::endl; + std::string old_mac = u2_mb[std::string("mac-addr")].as(); + std::cout << boost::format(" Old MAC Address: %s") % old_mac << std::endl; + std::string new_mac = vm["new-mac"].as(); + std::cout << boost::format(" New MAC Address: %s") % new_mac << std::endl; + u2_mb[std::string("mac-addr")] = new_mac; + std::cout << " Done" << std::endl; + } + + std::cout << "Power-cycle the usrp2 for the changes to take effect." << std::endl; + return 0; +} diff --git a/host/utils/usrp2_recovery.py b/host/utils/usrp2_recovery.py new file mode 100755 index 000000000..48c1121cb --- /dev/null +++ b/host/utils/usrp2_recovery.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +""" +The usrp2 recovery app: + +When the usrp2 has an unknown or bad ip address in its eeprom, +it may not be possible to communicate with the usrp2 over ip/udp. + +This app will send a raw ethernet packet to bypass the ip layer. +The packet will contain a known ip address to burn into eeprom. +Because the recovery packet is sent with a broadcast mac address, +only one usrp2 should be present on the interface upon execution. + +This app requires super-user privileges and only works on linux. +""" + +import socket +import struct +import optparse + +BCAST_MAC_ADDR = 'ff:ff:ff:ff:ff:ff' +RECOVERY_ETHERTYPE = 0xbeee +IP_RECOVERY_CODE = 'addr' + +def mac_addr_repr_to_binary_string(mac_addr): + return ''.join(map(lambda x: chr(int(x, 16)), mac_addr.split(':'))) + +if __name__ == '__main__': + parser = optparse.OptionParser(usage='usage: %prog [options]\n'+__doc__) + parser.add_option('--ifc', type='string', help='ethernet interface name [default=%default]', default='eth0') + parser.add_option('--new-ip', type='string', help='ip address to set [default=%default]', default='192.168.10.2') + (options, args) = parser.parse_args() + + #create the raw socket + print "Opening raw socket on interface:", options.ifc + soc = socket.socket(socket.PF_PACKET, socket.SOCK_RAW) + soc.bind((options.ifc, RECOVERY_ETHERTYPE)) + + #create the recovery packet + print "Loading packet with ip address:", options.new_ip + packet = struct.pack( + '!6s6sH4s4s', + mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), + mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), + RECOVERY_ETHERTYPE, + IP_RECOVERY_CODE, + socket.inet_aton(options.new_ip), + ) + + print "Sending packet (%d bytes)"%len(packet) + soc.send(packet) + print "Done" -- cgit v1.2.3