USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-ga1b5c4ae
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 <iostream>
13 #include <stdint.h>
14 
15 namespace uhd {
74  class UHD_API sid_t
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 { return _set; };
93 
94  // Getters
95  //
97  inline uint32_t get() const { return get_sid(); };
99  inline uint32_t get_sid() const { return _set ? _sid : 0; };
101  inline uint32_t get_src() const {
102  return (_sid >> 16) & 0xFFFF;
103  }
105  inline uint32_t get_dst() const {
106  return _sid & 0xFFFF;
107  }
109  inline uint32_t get_src_addr() const {
110  return (get_src() >> 8) & 0xFF;
111  }
113  inline uint32_t get_src_endpoint() const {
114  return get_src() & 0xFF;
115  }
117  inline uint32_t get_src_xbarport() const {
118  return (get_src_endpoint() >> 4) & 0xF;
119  }
121  inline uint32_t get_src_blockport() const {
122  return (get_src_endpoint()) & 0xF;
123  }
125  inline uint32_t get_dst_addr() const {
126  return (get_dst() >> 8) & 0xFF;
127  }
129  inline uint32_t get_dst_endpoint() const {
130  return get_dst() & 0xFF;
131  }
133  inline uint32_t get_dst_xbarport() const {
134  return (get_dst_endpoint() >> 4) & 0xF;
135  }
137  inline uint32_t get_dst_blockport() const {
138  return (get_dst_endpoint()) & 0xF;
139  }
140 
141  // Setters
142 
144  void set(uint32_t new_sid) { set_sid(new_sid); };
146  // Throws uhd::value_error if the string is not a valid SID
147  // representation.
148  void set_from_str(const std::string &);
149  void set_sid(uint32_t new_sid);
151  // (the first 16 Bits)
152  void set_src(uint32_t new_addr);
154  // (the last 16 Bits)
155  void set_dst(uint32_t new_addr);
156  void set_src_addr(uint32_t new_addr);
157  void set_src_endpoint(uint32_t new_addr);
158  void set_dst_addr(uint32_t new_addr);
159  void set_dst_endpoint(uint32_t new_addr);
160  void set_dst_xbarport(uint32_t new_xbarport);
161  void set_dst_blockport(uint32_t new_blockport);
162 
163  // Manipulators
164 
166  sid_t reversed() const;
167 
169  void reverse();
170 
171  // Overloaded operators
172 
173  sid_t operator = (const uint32_t new_sid) {
174  set_sid(new_sid);
175  return *this;
176  }
177 
178  sid_t operator = (sid_t &sid) {
179  set_sid(sid.get_sid());
180  return *this;
181  }
182 
183  sid_t operator = (const 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 == (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 uint32_t() const {
212  return get();
213  }
214 
215  operator bool() const {
216  return _set;
217  }
218 
219  private:
220  uint32_t _sid;
221  bool _set;
222  };
223 
225  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 Range reversed(const Range &range)
Definition: algorithm.hpp:46
uint32_t get_sid() const
Returns a 32-Bit representation of the SID if set, or zero otherwise.
Definition: sid.hpp:99
uint32_t get_dst_addr() const
Return 8-bit address of the destination.
Definition: sid.hpp:125
uint32_t get_src_addr() const
Return 8-bit address of the source.
Definition: sid.hpp:109
uint32_t get_dst_blockport() const
Return block port of the source.
Definition: sid.hpp:137
Definition: build_info.hpp:14
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:113
uint32_t get_src() const
Return the 16-bit source address of this SID.
Definition: sid.hpp:101
uint32_t get_dst() const
Return the 16-bit destination address of this SID.
Definition: sid.hpp:105
Represents a stream ID (SID).
Definition: sid.hpp:74
uint32_t get_dst_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:133
#define UHD_API
Definition: config.h:63
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
UHD_API bool operator==(const time_spec_t &, const time_spec_t &)
Implement equality_comparable interface.
uint32_t get_dst_endpoint() const
Return endpoint of the destination.
Definition: sid.hpp:129
uint32_t get_src_blockport() const
Return block port of the source.
Definition: sid.hpp:121
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:117