Statistics
| Branch: | Tag: | Revision:

root / host / utils / usrp_serial_burner.cpp @ 7b066a45

History | View | Annotate | Download (2.4 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
#include <uhd/utils/safe_main.hpp>
19
#include <uhd/device.hpp>
20
#include <uhd/usrp/device_props.hpp>
21
#include <boost/program_options.hpp>
22
#include <boost/format.hpp>
23
#include <iostream>
24

    
25
namespace po = boost::program_options;
26

    
27
int UHD_SAFE_MAIN(int argc, char *argv[]){
28
    po::options_description desc("Allowed options");
29
    desc.add_options()
30
        ("help", "help message")
31
        ("old", po::value<std::string>(), "old USRP serial number (optional)")
32
        ("new", po::value<std::string>(), "new USRP serial number")
33
    ;
34

    
35
    po::variables_map vm;
36
    po::store(po::parse_command_line(argc, argv, desc), vm);
37
    po::notify(vm); 
38

    
39
    //print the help message
40
    if (vm.count("help")){
41
        std::cout << boost::format("USRP serial burner %s") % desc << std::endl;
42
        return ~0;
43
    }
44

    
45
    if(vm.count("new") == 0) {
46
        std::cout << "error: must input --new arg" << std::endl;
47
        return ~0;
48
    }
49

    
50
    //load the options into the address
51
    uhd::device_addr_t device_addr;
52
    device_addr["type"] = "usrp1";
53
    if(vm.count("old")) device_addr["serial"] = vm["old"].as<std::string>();
54

    
55
    //find and create a control transport to do the writing.
56

    
57
    uhd::device_addrs_t found_addrs = uhd::device::find(device_addr);
58

    
59
    if (found_addrs.size() == 0){
60
        std::cerr << "No USRP devices found" << std::endl;
61
        return ~0;
62
    }
63

    
64
    for (size_t i = 0; i < found_addrs.size(); i++){
65
        uhd::device::sptr dev = uhd::device::make(found_addrs[i]);
66
        wax::obj mb = (*dev)[uhd::usrp::DEVICE_PROP_MBOARD];
67
        std::cout << "Writing serial number..." << std::endl;
68
        mb[std::string("serial")] = vm["new"].as<std::string>();
69
    }
70

    
71

    
72
    std::cout << "Power-cycle the usrp for the changes to take effect." << std::endl;
73
    return 0;
74
}