USRP Hardware Driver and USRP Manual  Version: 003.009.000-0-gcd88f80f
UHD and USRP Manual
sid.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014 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 #ifndef INCLUDED_UHD_TYPES_SID_HPP
19 #define INCLUDED_UHD_TYPES_SID_HPP
20 
21 #include <uhd/config.hpp>
22 #include <boost/cstdint.hpp>
23 #include <boost/shared_ptr.hpp>
24 #include <iostream>
25 
26 namespace uhd {
79  class UHD_API sid_t
80  {
81  public:
83  sid_t();
85  sid_t(boost::uint32_t sid);
87  sid_t(boost::uint8_t src_addr, boost::uint8_t src_ep, boost::uint8_t dst_addr, boost::uint8_t dst_ep);
89  sid_t(const std::string &);
90 
92  std::string to_pp_string() const;
94  std::string to_pp_string_hex() const;
95 
97  bool is_set() const { return _set; };
98 
99  // Getters
100  //
102  UHD_INLINE boost::uint32_t get() const { return get_sid(); };
104  UHD_INLINE boost::uint32_t get_sid() const { return _set ? _sid : 0; };
106  UHD_INLINE boost::uint32_t get_src() const {
107  return (_sid >> 16) & 0xFFFF;
108  }
110  UHD_INLINE boost::uint32_t get_dst() const {
111  return _sid & 0xFFFF;
112  }
114  UHD_INLINE boost::uint32_t get_src_addr() const {
115  return (get_src() >> 8) & 0xFF;
116  }
118  UHD_INLINE boost::uint32_t get_src_endpoint() const {
119  return get_src() & 0xFF;
120  }
122  UHD_INLINE boost::uint32_t get_src_xbarport() const {
123  return (get_src_endpoint() >> 4) & 0xF;
124  }
126  UHD_INLINE boost::uint32_t get_src_blockport() const {
127  return (get_src_endpoint()) & 0xF;
128  }
130  UHD_INLINE boost::uint32_t get_dst_addr() const {
131  return (get_dst() >> 8) & 0xFF;
132  }
134  UHD_INLINE boost::uint32_t get_dst_endpoint() const {
135  return get_dst() & 0xFF;
136  }
138  UHD_INLINE boost::uint32_t get_dst_xbarport() const {
139  return (get_dst_endpoint() >> 4) & 0xF;
140  }
142  UHD_INLINE boost::uint32_t get_dst_blockport() const {
143  return (get_dst_endpoint()) & 0xF;
144  }
145 
146  // Setters
147 
149  void set(boost::uint32_t new_sid) { set_sid(new_sid); };
151  // Throws uhd::value_error if the string is not a valid SID
152  // representation.
153  void set_from_str(const std::string &);
154  void set_sid(boost::uint32_t new_sid);
156  // (the first 16 Bits)
157  void set_src(boost::uint32_t new_addr);
159  // (the last 16 Bits)
160  void set_dst(boost::uint32_t new_addr);
161  void set_src_addr(boost::uint32_t new_addr);
162  void set_src_endpoint(boost::uint32_t new_addr);
163  void set_dst_addr(boost::uint32_t new_addr);
164  void set_dst_endpoint(boost::uint32_t new_addr);
165  void set_dst_xbarport(boost::uint32_t new_xbarport);
166  void set_dst_blockport(boost::uint32_t new_blockport);
167 
168  // Manipulators
169 
171  sid_t reversed();
172 
174  void reverse();
175 
176  // Overloaded operators
177 
178  sid_t operator = (boost::uint32_t new_sid) {
179  set_sid(new_sid);
180  return *this;
181  }
182 
183  sid_t operator = (sid_t &sid) {
184  set_sid(sid.get_sid());
185  return *this;
186  }
187 
188  sid_t operator = (const std::string &sid_str) {
189  set_from_str(sid_str);
190  return *this;
191  }
192 
193  bool operator == (const sid_t &sid) const {
194  return (not _set and not sid.is_set()) or (_sid == sid.get_sid());
195  }
196 
197  bool operator == (boost::uint32_t sid) const {
198  return _set and _sid == sid;
199  }
200 
201  bool operator == (const std::string &sid_str) const {
202  sid_t rhs(sid_str);
203  return *this == rhs;
204  }
205 
206  // overloaded type casts are tricky, but for now we'll need them
207  // for backward compatibility. consider them deprecated.
208 
210  // Use is_set() to check if the return value is valid.
211  operator boost::uint32_t() const {
212  return get();
213  }
214 
215  operator bool() const {
216  return _set;
217  }
218 
219  private:
220  boost::uint32_t _sid;
221  bool _set;
222  };
223 
225  UHD_INLINE std::ostream& operator<< (std::ostream& out, const sid_t &sid) {
226  std::ios_base::fmtflags ff = out.flags();
227  if (ff & std::ios::hex) {
228  out << sid.to_pp_string_hex();
229  } else {
230  out << sid.to_pp_string();
231  }
232  return out;
233  }
234 
235 } //namespace uhd
236 
237 #endif /* INCLUDED_UHD_TYPES_SID_HPP */
238 // vim: sw=4 et:
UHD_INLINE boost::uint32_t get_dst_blockport() const
Return block port of the source.
Definition: sid.hpp:142
UHD_INLINE boost::uint32_t get_src() const
Return the 16-bit source address of this SID.
Definition: sid.hpp:106
UHD_INLINE boost::uint32_t get_src_addr() const
Return 8-bit address of the source.
Definition: sid.hpp:114
UHD_INLINE boost::uint32_t get_dst() const
Return the 16-bit destination address of this SID.
Definition: sid.hpp:110
UHD_INLINE boost::uint32_t get_src_endpoint() const
Return endpoint of the source.
Definition: sid.hpp:118
Range reversed(const Range &range)
Definition: algorithm.hpp:56
UHD_INLINE boost::uint32_t get_dst_addr() const
Return 8-bit address of the destination.
Definition: sid.hpp:130
Definition: convert.hpp:28
std::string to_pp_string() const
Return a decimal string representation of the SID.
Represents a stream ID (SID).
Definition: sid.hpp:79
UHD_INLINE boost::uint32_t get_src_blockport() const
Return block port of the source.
Definition: sid.hpp:126
UHD_INLINE boost::uint32_t get_dst_endpoint() const
Return endpoint of the destination.
Definition: sid.hpp:134
#define UHD_INLINE
Definition: config.h:56
UHD_INLINE boost::uint32_t get_src_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:122
#define UHD_API
Definition: config.h:66
UHD_INLINE boost::uint32_t get_sid() const
Returns a 32-Bit representation of the SID if set, or zero otherwise.
Definition: sid.hpp:104
UHD_API std::ostream & operator<<(std::ostream &os, filter_info_base &f)
bool is_set() const
Returns true if this actually holds a valid SID.
Definition: sid.hpp:97
UHD_INLINE boost::uint32_t get_dst_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:138
UHD_API bool operator==(const time_spec_t &, const time_spec_t &)
Implement equality_comparable interface.
std::string to_pp_string_hex() const
Return a hexadecimal string representation of the SID.