USRP Hardware Driver and USRP Manual  Version: 003.010.002.HEAD-0-gbd6e21dc
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 <stdint.h>
23 #include <boost/shared_ptr.hpp>
24 #include <iostream>
25 
26 namespace uhd {
85  class UHD_API sid_t
86  {
87  public:
89  sid_t();
91  sid_t(uint32_t sid);
93  sid_t(uint8_t src_addr, uint8_t src_ep, uint8_t dst_addr, uint8_t dst_ep);
95  sid_t(const std::string &);
96 
98  std::string to_pp_string() const;
100  std::string to_pp_string_hex() const;
101 
103  bool is_set() const { return _set; };
104 
105  // Getters
106  //
108  UHD_INLINE uint32_t get() const { return get_sid(); };
110  UHD_INLINE uint32_t get_sid() const { return _set ? _sid : 0; };
112  UHD_INLINE uint32_t get_src() const {
113  return (_sid >> 16) & 0xFFFF;
114  }
116  UHD_INLINE uint32_t get_dst() const {
117  return _sid & 0xFFFF;
118  }
120  UHD_INLINE uint32_t get_src_addr() const {
121  return (get_src() >> 8) & 0xFF;
122  }
124  UHD_INLINE uint32_t get_src_endpoint() const {
125  return get_src() & 0xFF;
126  }
128  UHD_INLINE uint32_t get_src_xbarport() const {
129  return (get_src_endpoint() >> 4) & 0xF;
130  }
132  UHD_INLINE uint32_t get_src_blockport() const {
133  return (get_src_endpoint()) & 0xF;
134  }
136  UHD_INLINE uint32_t get_dst_addr() const {
137  return (get_dst() >> 8) & 0xFF;
138  }
140  UHD_INLINE uint32_t get_dst_endpoint() const {
141  return get_dst() & 0xFF;
142  }
144  UHD_INLINE uint32_t get_dst_xbarport() const {
145  return (get_dst_endpoint() >> 4) & 0xF;
146  }
148  UHD_INLINE uint32_t get_dst_blockport() const {
149  return (get_dst_endpoint()) & 0xF;
150  }
151 
152  // Setters
153 
155  void set(uint32_t new_sid) { set_sid(new_sid); };
157  // Throws uhd::value_error if the string is not a valid SID
158  // representation.
159  void set_from_str(const std::string &);
160  void set_sid(uint32_t new_sid);
162  // (the first 16 Bits)
163  void set_src(uint32_t new_addr);
165  // (the last 16 Bits)
166  void set_dst(uint32_t new_addr);
167  void set_src_addr(uint32_t new_addr);
168  void set_src_endpoint(uint32_t new_addr);
169  void set_dst_addr(uint32_t new_addr);
170  void set_dst_endpoint(uint32_t new_addr);
171  void set_dst_xbarport(uint32_t new_xbarport);
172  void set_dst_blockport(uint32_t new_blockport);
173 
174  // Manipulators
175 
177  sid_t reversed();
178 
180  void reverse();
181 
182  // Overloaded operators
183 
184  sid_t operator = (uint32_t new_sid) {
185  set_sid(new_sid);
186  return *this;
187  }
188 
189  sid_t operator = (sid_t &sid) {
190  set_sid(sid.get_sid());
191  return *this;
192  }
193 
194  sid_t operator = (const std::string &sid_str) {
195  set_from_str(sid_str);
196  return *this;
197  }
198 
199  bool operator == (const sid_t &sid) const {
200  return (not _set and not sid.is_set()) or (_sid == sid.get_sid());
201  }
202 
203  bool operator == (uint32_t sid) const {
204  return _set and _sid == sid;
205  }
206 
207  bool operator == (const std::string &sid_str) const {
208  sid_t rhs(sid_str);
209  return *this == rhs;
210  }
211 
212  // overloaded type casts are tricky, but for now we'll need them
213  // for backward compatibility. consider them deprecated.
214 
216  // Use is_set() to check if the return value is valid.
217  operator uint32_t() const {
218  return get();
219  }
220 
221  operator bool() const {
222  return _set;
223  }
224 
225  private:
226  uint32_t _sid;
227  bool _set;
228  };
229 
231  UHD_INLINE std::ostream& operator<< (std::ostream& out, const sid_t &sid) {
232  std::ios_base::fmtflags ff = out.flags();
233  if (ff & std::ios::hex) {
234  out << sid.to_pp_string_hex();
235  } else {
236  out << sid.to_pp_string();
237  }
238  return out;
239  }
240 
241 } //namespace uhd
242 
243 #endif /* INCLUDED_UHD_TYPES_SID_HPP */
244 // vim: sw=4 et:
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:56
UHD_INLINE uint32_t get_dst_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:144
UHD_INLINE uint32_t get_src_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:128
UHD_INLINE uint32_t get_src() const
Return the 16-bit source address of this SID.
Definition: sid.hpp:112
UHD_INLINE uint32_t get_dst_addr() const
Return 8-bit address of the destination.
Definition: sid.hpp:136
UHD_INLINE uint32_t get_sid() const
Returns a 32-Bit representation of the SID if set, or zero otherwise.
Definition: sid.hpp:110
UHD_INLINE uint32_t get_dst() const
Return the 16-bit destination address of this SID.
Definition: sid.hpp:116
UHD_INLINE uint32_t get_src_blockport() const
Return block port of the source.
Definition: sid.hpp:132
Definition: build_info.hpp:25
UHD_INLINE uint32_t get_src_addr() const
Return 8-bit address of the source.
Definition: sid.hpp:120
std::string to_pp_string() const
Return a decimal string representation of the SID.
UHD_INLINE uint32_t get_src_endpoint() const
Return endpoint of the source.
Definition: sid.hpp:124
Represents a stream ID (SID).
Definition: sid.hpp:85
#define UHD_INLINE
Definition: config.h:63
#define UHD_API
Definition: config.h:73
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:103
UHD_INLINE uint32_t get_dst_endpoint() const
Return endpoint of the destination.
Definition: sid.hpp:140
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.
UHD_INLINE uint32_t get_dst_blockport() const
Return block port of the source.
Definition: sid.hpp:148