Statistics
| Branch: | Tag: | Revision:

root / host / lib / usrp / dboard_id.cpp @ d8d74942

History | View | Annotate | Download (2.02 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/usrp/dboard_id.hpp>
19
#include <boost/lexical_cast.hpp>
20
#include <boost/format.hpp>
21
#include <sstream>
22
#include <iostream>
23

    
24
using namespace uhd::usrp;
25

    
26
dboard_id_t::dboard_id_t(boost::uint16_t id){
27
    _id = id;
28
}
29

    
30
dboard_id_t dboard_id_t::none(void){
31
    return dboard_id_t();
32
}
33

    
34
dboard_id_t dboard_id_t::from_uint16(boost::uint16_t uint16){
35
    return dboard_id_t(uint16);
36
}
37

    
38
boost::uint16_t dboard_id_t::to_uint16(void) const{
39
    return _id;
40
}
41

    
42
//used with lexical cast to parse a hex string
43
template <class T> struct to_hex{
44
    T value;
45
    operator T() const {return value;}
46
    friend std::istream& operator>>(std::istream& in, to_hex& out){
47
        in >> std::hex >> out.value;
48
        return in;
49
    }
50
};
51

    
52
dboard_id_t dboard_id_t::from_string(const std::string &string){
53
    if (string.substr(0, 2) == "0x"){
54
        return dboard_id_t::from_uint16(boost::lexical_cast<to_hex<boost::uint16_t> >(string));
55
    }
56
    return dboard_id_t::from_uint16(boost::lexical_cast<boost::uint16_t>(string));
57
}
58

    
59
std::string dboard_id_t::to_string(void) const{
60
    return str(boost::format("0x%04x") % this->to_uint16());
61
}
62

    
63
//Note: to_pp_string is implemented in the dboard manager
64
//because it needs access to the dboard registration table
65

    
66
bool uhd::usrp::operator==(const dboard_id_t &lhs, const dboard_id_t &rhs){
67
    return lhs.to_uint16() == rhs.to_uint16();
68
}