USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-gdca39145
UHD and USRP Manual
sid.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 //
4 // SPDX-License-Identifier: GPL-3.0
5 //
6 
7 #ifndef INCLUDED_UHD_TYPES_SID_HPP
8 #define INCLUDED_UHD_TYPES_SID_HPP
9 
10 #include <uhd/config.hpp>
11 #include <iostream>
12 #include <stdint.h>
13 
14 namespace uhd {
73  class UHD_API sid_t
74  {
75  public:
77  sid_t();
79  sid_t(uint32_t sid);
81  sid_t(uint8_t src_addr, uint8_t src_ep, uint8_t dst_addr, uint8_t dst_ep);
83  sid_t(const std::string &);
84 
86  std::string to_pp_string() const;
88  std::string to_pp_string_hex() const;
89 
91  bool is_set() const { return _set; };
92 
93  // Getters
94  //
96  inline uint32_t get() const { return get_sid(); };
98  inline uint32_t get_sid() const { return _set ? _sid : 0; };
100  inline uint32_t get_src() const {
101  return (_sid >> 16) & 0xFFFF;
102  }
104  inline uint32_t get_dst() const {
105  return _sid & 0xFFFF;
106  }
108  inline uint32_t get_src_addr() const {
109  return (get_src() >> 8) & 0xFF;
110  }
112  inline uint32_t get_src_endpoint() const {
113  return get_src() & 0xFF;
114  }
116  inline uint32_t get_src_xbarport() const {
117  return (get_src_endpoint() >> 4) & 0xF;
118  }
120  inline uint32_t get_src_blockport() const {
121  return (get_src_endpoint()) & 0xF;
122  }
124  inline uint32_t get_dst_addr() const {
125  return (get_dst() >> 8) & 0xFF;
126  }
128  inline uint32_t get_dst_endpoint() const {
129  return get_dst() & 0xFF;
130  }
132  inline uint32_t get_dst_xbarport() const {
133  return (get_dst_endpoint() >> 4) & 0xF;
134  }
136  inline uint32_t get_dst_blockport() const {
137  return (get_dst_endpoint()) & 0xF;
138  }
139 
140  // Setters
141 
143  void set(uint32_t new_sid) { set_sid(new_sid); };
145  // Throws uhd::value_error if the string is not a valid SID
146  // representation.
147  void set_from_str(const std::string &);
148  void set_sid(uint32_t new_sid);
150  // (the first 16 Bits)
151  void set_src(uint32_t new_addr);
153  // (the last 16 Bits)
154  void set_dst(uint32_t new_addr);
155  void set_src_addr(uint32_t new_addr);
156  void set_src_endpoint(uint32_t new_addr);
157  void set_dst_addr(uint32_t new_addr);
158  void set_dst_endpoint(uint32_t new_addr);
159  void set_dst_xbarport(uint32_t new_xbarport);
160  void set_dst_blockport(uint32_t new_blockport);
161 
162  // Manipulators
163 
165  sid_t reversed() const;
166 
168  void reverse();
169 
170  // Overloaded operators
171 
172  sid_t operator = (const uint32_t new_sid) {
173  set_sid(new_sid);
174  return *this;
175  }
176 
177  sid_t operator = (sid_t &sid) {
178  set_sid(sid.get_sid());
179  return *this;
180  }
181 
182  sid_t operator = (const sid_t &sid) {
183  set_sid(sid.get_sid());
184  return *this;
185  }
186 
187  sid_t operator = (const std::string &sid_str) {
188  set_from_str(sid_str);
189  return *this;
190  }
191 
192  bool operator == (const sid_t &sid) const {
193  return (not _set and not sid.is_set()) or (_sid == sid.get_sid());
194  }
195 
196  bool operator == (uint32_t sid) const {
197  return _set and _sid == sid;
198  }
199 
200  bool operator == (const std::string &sid_str) const {
201  sid_t rhs(sid_str);
202  return *this == rhs;
203  }
204 
205  // overloaded type casts are tricky, but for now we'll need them
206  // for backward compatibility. consider them deprecated.
207 
209  // Use is_set() to check if the return value is valid.
210  operator uint32_t() const {
211  return get();
212  }
213 
214  operator bool() const {
215  return _set;
216  }
217 
218  private:
219  uint32_t _sid;
220  bool _set;
221  };
222 
224  inline std::ostream& operator<< (std::ostream& out, const sid_t &sid) {
225  std::ios_base::fmtflags ff = out.flags();
226  if (ff & std::ios::hex) {
227  out << sid.to_pp_string_hex();
228  } else {
229  out << sid.to_pp_string();
230  }
231  return out;
232  }
233 
234 } //namespace uhd
235 
236 #endif /* INCLUDED_UHD_TYPES_SID_HPP */
237 // vim: sw=4 et:
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:45
uint32_t get_sid() const
Returns a 32-Bit representation of the SID if set, or zero otherwise.
Definition: sid.hpp:98
uint32_t get_dst_addr() const
Return 8-bit address of the destination.
Definition: sid.hpp:124
uint32_t get_src_addr() const
Return 8-bit address of the source.
Definition: sid.hpp:108
uint32_t get_dst_blockport() const
Return block port of the source.
Definition: sid.hpp:136
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:112
uint32_t get_src() const
Return the 16-bit source address of this SID.
Definition: sid.hpp:100
uint32_t get_dst() const
Return the 16-bit destination address of this SID.
Definition: sid.hpp:104
Represents a stream ID (SID).
Definition: sid.hpp:73
uint32_t get_dst_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:132
#define UHD_API
Definition: config.h:62
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:91
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:128
uint32_t get_src_blockport() const
Return block port of the source.
Definition: sid.hpp:120
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:116