USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-gaea0e2de
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  sid_t(const sid_t& sid) {
88  set_sid(sid.get_sid());
89  }
90 
92  std::string to_pp_string() const;
94  std::string to_pp_string_hex() const;
95 
97  bool is_set() const
98  {
99  return _set;
100  };
101 
102  // Getters
103  //
105  inline uint32_t get() const
106  {
107  return get_sid();
108  };
110  inline uint32_t get_sid() const
111  {
112  return _set ? _sid : 0;
113  };
115  inline uint32_t get_src() const
116  {
117  return (_sid >> 16) & 0xFFFF;
118  }
120  inline uint32_t get_dst() const
121  {
122  return _sid & 0xFFFF;
123  }
125  inline uint32_t get_src_addr() const
126  {
127  return (get_src() >> 8) & 0xFF;
128  }
130  inline uint32_t get_src_endpoint() const
131  {
132  return get_src() & 0xFF;
133  }
135  inline uint32_t get_src_xbarport() const
136  {
137  return (get_src_endpoint() >> 4) & 0xF;
138  }
140  inline uint32_t get_src_blockport() const
141  {
142  return (get_src_endpoint()) & 0xF;
143  }
145  inline uint32_t get_dst_addr() const
146  {
147  return (get_dst() >> 8) & 0xFF;
148  }
150  inline uint32_t get_dst_endpoint() const
151  {
152  return get_dst() & 0xFF;
153  }
155  inline uint32_t get_dst_xbarport() const
156  {
157  return (get_dst_endpoint() >> 4) & 0xF;
158  }
160  inline uint32_t get_dst_blockport() const
161  {
162  return (get_dst_endpoint()) & 0xF;
163  }
164 
165  // Setters
166 
168  void set(uint32_t new_sid)
169  {
170  set_sid(new_sid);
171  };
173  // Throws uhd::value_error if the string is not a valid SID
174  // representation.
175  void set_from_str(const std::string&);
176  void set_sid(uint32_t new_sid);
178  // (the first 16 Bits)
179  void set_src(uint32_t new_addr);
181  // (the last 16 Bits)
182  void set_dst(uint32_t new_addr);
183  void set_src_addr(uint32_t new_addr);
184  void set_src_endpoint(uint32_t new_addr);
185  void set_dst_addr(uint32_t new_addr);
186  void set_dst_endpoint(uint32_t new_addr);
187  void set_dst_xbarport(uint32_t new_xbarport);
188  void set_dst_blockport(uint32_t new_blockport);
189 
190  // Manipulators
191 
193  sid_t reversed() const;
194 
196  void reverse();
197 
198  // Overloaded operators
199 
200  sid_t operator=(const uint32_t new_sid)
201  {
202  set_sid(new_sid);
203  return *this;
204  }
205 
206  sid_t operator=(const sid_t& sid)
207  {
208  set_sid(sid.get_sid());
209  return *this;
210  }
211 
212  sid_t operator=(const std::string& sid_str)
213  {
214  set_from_str(sid_str);
215  return *this;
216  }
217 
218  bool operator==(const sid_t& sid) const
219  {
220  return (not _set and not sid.is_set()) or (_sid == sid.get_sid());
221  }
222 
223  bool operator==(uint32_t sid) const
224  {
225  return _set and _sid == sid;
226  }
227 
228  bool operator==(const std::string& sid_str) const
229  {
230  sid_t rhs(sid_str);
231  return *this == rhs;
232  }
233 
234  // overloaded type casts are tricky, but for now we'll need them
235  // for backward compatibility. consider them deprecated.
236 
238  // Use is_set() to check if the return value is valid.
239  operator uint32_t() const
240  {
241  return get();
242  }
243 
244  operator bool() const
245  {
246  return _set;
247  }
248 
249 private:
250  uint32_t _sid;
251  bool _set;
252 };
253 
255 inline std::ostream& operator<<(std::ostream& out, const sid_t& sid)
256 {
257  std::ios_base::fmtflags ff = out.flags();
258  if (ff & std::ios::hex) {
259  out << sid.to_pp_string_hex();
260  } else {
261  out << sid.to_pp_string();
262  }
263  return out;
264 }
265 
266 } // namespace uhd
267 
268 #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:110
uint32_t get_dst_addr() const
Return 8-bit address of the destination.
Definition: sid.hpp:145
bool operator==(uint32_t sid) const
Definition: sid.hpp:223
sid_t operator=(const sid_t &sid)
Definition: sid.hpp:206
sid_t operator=(const std::string &sid_str)
Definition: sid.hpp:212
uint32_t get_src_addr() const
Return 8-bit address of the source.
Definition: sid.hpp:125
uint32_t get_dst_blockport() const
Return block port of the source.
Definition: sid.hpp:160
Definition: build_info.hpp:13
sid_t(const sid_t &sid)
Copy a sid.
Definition: sid.hpp:87
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:130
uint32_t get_src() const
Return the 16-bit source address of this SID.
Definition: sid.hpp:115
uint32_t get_dst() const
Return the 16-bit destination address of this SID.
Definition: sid.hpp:120
Represents a stream ID (SID).
Definition: sid.hpp:74
uint32_t get_dst_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:155
bool operator==(const sid_t &sid) const
Definition: sid.hpp:218
#define UHD_API
Definition: config.h:68
bool operator==(const std::string &sid_str) const
Definition: sid.hpp:228
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
uint32_t get_dst_endpoint() const
Return endpoint of the destination.
Definition: sid.hpp:150
uint32_t get_src_blockport() const
Return block port of the source.
Definition: sid.hpp:140
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:135
sid_t operator=(const uint32_t new_sid)
Definition: sid.hpp:200