root / host / utils / uhd_burn_db_eeprom.cpp @ d1d6c859
History | View | Annotate | Download (3.86 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
|
| 19 |
#include <uhd/utils/safe_main.hpp> |
| 20 |
#include <uhd/device.hpp> |
| 21 |
#include <uhd/types/dict.hpp> |
| 22 |
#include <uhd/usrp/dboard_id.hpp> |
| 23 |
#include <uhd/usrp/device_props.hpp> |
| 24 |
#include <uhd/usrp/mboard_props.hpp> |
| 25 |
#include <uhd/usrp/dboard_props.hpp> |
| 26 |
#include <boost/program_options.hpp> |
| 27 |
#include <boost/lexical_cast.hpp> |
| 28 |
#include <boost/format.hpp> |
| 29 |
#include <boost/assign.hpp> |
| 30 |
#include <iostream> |
| 31 |
#include <sstream> |
| 32 |
|
| 33 |
using namespace uhd; |
| 34 |
using namespace uhd::usrp; |
| 35 |
namespace po = boost::program_options;
|
| 36 |
|
| 37 |
//used with lexical cast to parse a hex string
|
| 38 |
template <class T> struct to_hex{ |
| 39 |
T value; |
| 40 |
operator T() const {return value;} |
| 41 |
friend std::istream& operator>>(std::istream& in, to_hex& out){ |
| 42 |
in >> std::hex >> out.value; |
| 43 |
return in;
|
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
int UHD_SAFE_MAIN(int argc, char *argv[]){ |
| 48 |
//command line variables
|
| 49 |
std::string args, db_name, unit;
|
| 50 |
static const uhd::dict<std::string, mboard_prop_t> unit_to_db_prop = boost::assign::map_list_of |
| 51 |
("RX", MBOARD_PROP_RX_DBOARD) ("TX", MBOARD_PROP_TX_DBOARD) |
| 52 |
; |
| 53 |
|
| 54 |
po::options_description desc("Allowed options");
|
| 55 |
desc.add_options() |
| 56 |
("help", "help message") |
| 57 |
("args", po::value<std::string>(&args)->default_value(""), "device address args [default = \"\"]") |
| 58 |
("db", po::value<std::string>(&db_name)->default_value(""), "dboard name [default = \"\"]") |
| 59 |
("unit", po::value<std::string>(&unit)->default_value(""), "which unit [RX or TX]") |
| 60 |
("id", po::value<std::string>(), "dboard id to burn (hex string), omit for readback") |
| 61 |
; |
| 62 |
|
| 63 |
po::variables_map vm; |
| 64 |
po::store(po::parse_command_line(argc, argv, desc), vm); |
| 65 |
po::notify(vm); |
| 66 |
|
| 67 |
//print the help message
|
| 68 |
if (vm.count("help")){ |
| 69 |
std::cout << boost::format("UHD Burn DB EEPROM %s") % desc << std::endl;
|
| 70 |
std::cout << boost::format( |
| 71 |
"Omit the id argument to perform readback,\n"
|
| 72 |
"Or specify a new id to burn into the eeprom.\n"
|
| 73 |
) << std::endl; |
| 74 |
return ~0; |
| 75 |
} |
| 76 |
|
| 77 |
//check inputs
|
| 78 |
if (not unit_to_db_prop.has_key(unit)){ |
| 79 |
std::cout << "Error: specify RX or TX for unit" << std::endl;
|
| 80 |
return ~0; |
| 81 |
} |
| 82 |
|
| 83 |
//make the device and extract the dboard w/ property
|
| 84 |
device::sptr dev = device::make(args); |
| 85 |
wax::obj dboard = (*dev)[DEVICE_PROP_MBOARD][named_prop_t(unit_to_db_prop[unit], db_name)]; |
| 86 |
std::string prefix = (db_name == "")? unit : (unit + ":" + db_name); |
| 87 |
|
| 88 |
//read the current dboard id from eeprom
|
| 89 |
if (vm.count("id") == 0){ |
| 90 |
std::cout << boost::format("Getting dbid on %s dboard...") % prefix << std::endl;
|
| 91 |
dboard_id_t id = dboard[DBOARD_PROP_DBOARD_ID].as<dboard_id_t>(); |
| 92 |
std::cout << boost::format(" Current dbid: %s") % dboard_id::to_string(id) << std::endl;
|
| 93 |
} |
| 94 |
|
| 95 |
//write a new dboard id to eeprom
|
| 96 |
else{
|
| 97 |
dboard_id_t id = boost::lexical_cast<to_hex<dboard_id_t> >(vm["id"].as<std::string>()); |
| 98 |
std::cout << boost::format("Setting dbid on %s dboard...") % prefix << std::endl;
|
| 99 |
std::cout << boost::format(" New dbid: %s") % dboard_id::to_string(id) << std::endl;
|
| 100 |
dboard[DBOARD_PROP_DBOARD_ID] = id; |
| 101 |
} |
| 102 |
|
| 103 |
std::cout << " Done" << std::endl << std::endl;
|
| 104 |
return 0; |
| 105 |
} |