USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-g6563c537
UHD and USRP Manual
sid.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 // Copyright 2018 Ettus Research, a National Instruments Company
4 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #ifndef INCLUDED_UHD_TYPES_SID_HPP
9 #define INCLUDED_UHD_TYPES_SID_HPP
10 
11 #include <uhd/config.hpp>
12 #include <stdint.h>
13 #include <iostream>
14 
15 namespace uhd {
75 {
76 public:
78  sid_t();
80  sid_t(uint32_t sid);
82  sid_t(uint8_t src_addr, uint8_t src_ep, uint8_t dst_addr, uint8_t dst_ep);
84  sid_t(const std::string&);
85 
87  std::string to_pp_string() const;
89  std::string to_pp_string_hex() const;
90 
92  bool is_set() const
93  {
94  return _set;
95  };
96 
97  // Getters
98  //
100  inline uint32_t get() const
101  {
102  return get_sid();
103  };
105  inline uint32_t get_sid() const
106  {
107  return _set ? _sid : 0;
108  };
110  inline uint32_t get_src() const
111  {
112  return (_sid >> 16) & 0xFFFF;
113  }
115  inline uint32_t get_dst() const
116  {
117  return _sid & 0xFFFF;
118  }
120  inline uint32_t get_src_addr() const
121  {
122  return (get_src() >> 8) & 0xFF;
123  }
125  inline uint32_t get_src_endpoint() const
126  {
127  return get_src() & 0xFF;
128  }
130  inline uint32_t get_src_xbarport() const
131  {
132  return (get_src_endpoint() >> 4) & 0xF;
133  }
135  inline uint32_t get_src_blockport() const
136  {
137  return (get_src_endpoint()) & 0xF;
138  }
140  inline uint32_t get_dst_addr() const
141  {
142  return (get_dst() >> 8) & 0xFF;
143  }
145  inline uint32_t get_dst_endpoint() const
146  {
147  return get_dst() & 0xFF;
148  }
150  inline uint32_t get_dst_xbarport() const
151  {
152  return (get_dst_endpoint() >> 4) & 0xF;
153  }
155  inline uint32_t get_dst_blockport() const
156  {
157  return (get_dst_endpoint()) & 0xF;
158  }
159 
160  // Setters
161 
163  void set(uint32_t new_sid)
164  {
165  set_sid(new_sid);
166  };
168  // Throws uhd::value_error if the string is not a valid SID
169  // representation.
170  void set_from_str(const std::string&);
171  void set_sid(uint32_t new_sid);
173  // (the first 16 Bits)
174  void set_src(uint32_t new_addr);
176  // (the last 16 Bits)
177  void set_dst(uint32_t new_addr);
178  void set_src_addr(uint32_t new_addr);
179  void set_src_endpoint(uint32_t new_addr);
180  void set_dst_addr(uint32_t new_addr);
181  void set_dst_endpoint(uint32_t new_addr);
182  void set_dst_xbarport(uint32_t new_xbarport);
183  void set_dst_blockport(uint32_t new_blockport);
184 
185  // Manipulators
186 
188  sid_t reversed() const;
189 
191  void reverse();
192 
193  // Overloaded operators
194 
195  sid_t operator=(const uint32_t new_sid)
196  {
197  set_sid(new_sid);
198  return *this;
199  }
200 
201  sid_t operator=(const sid_t& sid)
202  {
203  set_sid(sid.get_sid());
204  return *this;
205  }
206 
207  sid_t operator=(const std::string& sid_str)
208  {
209  set_from_str(sid_str);
210  return *this;
211  }
212 
213  bool operator==(const sid_t& sid) const
214  {
215  return (not _set and not sid.is_set()) or (_sid == sid.get_sid());
216  }
217 
218  bool operator==(uint32_t sid) const
219  {
220  return _set and _sid == sid;
221  }
222 
223  bool operator==(const std::string& sid_str) const
224  {
225  sid_t rhs(sid_str);
226  return *this == rhs;
227  }
228 
229  // overloaded type casts are tricky, but for now we'll need them
230  // for backward compatibility. consider them deprecated.
231 
233  // Use is_set() to check if the return value is valid.
234  operator uint32_t() const
235  {
236  return get();
237  }
238 
239  operator bool() const
240  {
241  return _set;
242  }
243 
244 private:
245  uint32_t _sid;
246  bool _set;
247 };
248 
250 inline std::ostream& operator<<(std::ostream& out, const sid_t& sid)
251 {
252  std::ios_base::fmtflags ff = out.flags();
253  if (ff & std::ios::hex) {
254  out << sid.to_pp_string_hex();
255  } else {
256  out << sid.to_pp_string();
257  }
258  return out;
259 }
260 
261 } // namespace uhd
262 
263 #endif /* INCLUDED_UHD_TYPES_SID_HPP */
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:49
uint32_t get_sid() const
Returns a 32-Bit representation of the SID if set, or zero otherwise.
Definition: sid.hpp:105
uint32_t get_dst_addr() const
Return 8-bit address of the destination.
Definition: sid.hpp:140
bool operator==(uint32_t sid) const
Definition: sid.hpp:218
sid_t operator=(const sid_t &sid)
Definition: sid.hpp:201
sid_t operator=(const std::string &sid_str)
Definition: sid.hpp:207
uint32_t get_src_addr() const
Return 8-bit address of the source.
Definition: sid.hpp:120
uint32_t get_dst_blockport() const
Return block port of the source.
Definition: sid.hpp:155
Definition: build_info.hpp:13
std::string to_pp_string() const
Return a decimal string representation of the SID.
uint32_t get_src_endpoint() const
Return endpoint of the source.
Definition: sid.hpp:125
uint32_t get_src() const
Return the 16-bit source address of this SID.
Definition: sid.hpp:110
uint32_t get_dst() const
Return the 16-bit destination address of this SID.
Definition: sid.hpp:115
Represents a stream ID (SID).
Definition: sid.hpp:74
uint32_t get_dst_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:150
bool operator==(const sid_t &sid) const
Definition: sid.hpp:213
#define UHD_API
Definition: config.h:68
bool operator==(const std::string &sid_str) const
Definition: sid.hpp:223
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:92
uint32_t get_dst_endpoint() const
Return endpoint of the destination.
Definition: sid.hpp:145
uint32_t get_src_blockport() const
Return block port of the source.
Definition: sid.hpp:135
std::string to_pp_string_hex() const
Return a hexadecimal string representation of the SID.
uint32_t get_src_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:130
sid_t operator=(const uint32_t new_sid)
Definition: sid.hpp:195