USRP Hardware Driver and USRP Manual  Version: 3.15.0.0-4+b1satnogs1
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  {
89  set_sid(sid.get_sid());
90  }
91 
93  std::string to_pp_string() const;
95  std::string to_pp_string_hex() const;
96 
98  bool is_set() const
99  {
100  return _set;
101  };
102 
103  // Getters
104  //
106  inline uint32_t get() const
107  {
108  return get_sid();
109  };
111  inline uint32_t get_sid() const
112  {
113  return _set ? _sid : 0;
114  };
116  inline uint32_t get_src() const
117  {
118  return (_sid >> 16) & 0xFFFF;
119  }
121  inline uint32_t get_dst() const
122  {
123  return _sid & 0xFFFF;
124  }
126  inline uint32_t get_src_addr() const
127  {
128  return (get_src() >> 8) & 0xFF;
129  }
131  inline uint32_t get_src_endpoint() const
132  {
133  return get_src() & 0xFF;
134  }
136  inline uint32_t get_src_xbarport() const
137  {
138  return (get_src_endpoint() >> 4) & 0xF;
139  }
141  inline uint32_t get_src_blockport() const
142  {
143  return (get_src_endpoint()) & 0xF;
144  }
146  inline uint32_t get_dst_addr() const
147  {
148  return (get_dst() >> 8) & 0xFF;
149  }
151  inline uint32_t get_dst_endpoint() const
152  {
153  return get_dst() & 0xFF;
154  }
156  inline uint32_t get_dst_xbarport() const
157  {
158  return (get_dst_endpoint() >> 4) & 0xF;
159  }
161  inline uint32_t get_dst_blockport() const
162  {
163  return (get_dst_endpoint()) & 0xF;
164  }
165 
166  // Setters
167 
169  void set(uint32_t new_sid)
170  {
171  set_sid(new_sid);
172  };
174  // Throws uhd::value_error if the string is not a valid SID
175  // representation.
176  void set_from_str(const std::string&);
177  void set_sid(uint32_t new_sid);
179  // (the first 16 Bits)
180  void set_src(uint32_t new_addr);
182  // (the last 16 Bits)
183  void set_dst(uint32_t new_addr);
184  void set_src_addr(uint32_t new_addr);
185  void set_src_endpoint(uint32_t new_addr);
186  void set_dst_addr(uint32_t new_addr);
187  void set_dst_endpoint(uint32_t new_addr);
188  void set_dst_xbarport(uint32_t new_xbarport);
189  void set_dst_blockport(uint32_t new_blockport);
190 
191  // Manipulators
192 
194  sid_t reversed() const;
195 
197  void reverse();
198 
199  // Overloaded operators
200 
201  sid_t operator=(const uint32_t new_sid)
202  {
203  set_sid(new_sid);
204  return *this;
205  }
206 
207  sid_t operator=(const sid_t& sid)
208  {
209  set_sid(sid.get_sid());
210  return *this;
211  }
212 
213  sid_t operator=(const std::string& sid_str)
214  {
215  set_from_str(sid_str);
216  return *this;
217  }
218 
219  bool operator==(const sid_t& sid) const
220  {
221  return (not _set and not sid.is_set()) or (_sid == sid.get_sid());
222  }
223 
224  bool operator==(uint32_t sid) const
225  {
226  return _set and _sid == sid;
227  }
228 
229  bool operator==(const std::string& sid_str) const
230  {
231  sid_t rhs(sid_str);
232  return *this == rhs;
233  }
234 
235  // overloaded type casts are tricky, but for now we'll need them
236  // for backward compatibility. consider them deprecated.
237 
239  // Use is_set() to check if the return value is valid.
240  operator uint32_t() const
241  {
242  return get();
243  }
244 
245  operator bool() const
246  {
247  return _set;
248  }
249 
250 private:
251  uint32_t _sid;
252  bool _set;
253 };
254 
256 inline std::ostream& operator<<(std::ostream& out, const sid_t& sid)
257 {
258  std::ios_base::fmtflags ff = out.flags();
259  if (ff & std::ios::hex) {
260  out << sid.to_pp_string_hex();
261  } else {
262  out << sid.to_pp_string();
263  }
264  return out;
265 }
266 
267 } // namespace uhd
268 
269 #endif /* INCLUDED_UHD_TYPES_SID_HPP */
Represents a stream ID (SID).
Definition: sid.hpp:75
sid_t reversed() const
Swaps dst and src address and returns the new SID.
uint32_t get_dst_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:156
uint32_t get_dst_addr() const
Return 8-bit address of the destination.
Definition: sid.hpp:146
void set_dst(uint32_t new_addr)
Set the destination address of this SID.
void set_dst_addr(uint32_t new_addr)
bool operator==(uint32_t sid) const
Definition: sid.hpp:224
uint32_t get_src_addr() const
Return 8-bit address of the source.
Definition: sid.hpp:126
void set_dst_xbarport(uint32_t new_xbarport)
bool operator==(const std::string &sid_str) const
Definition: sid.hpp:229
void set_dst_blockport(uint32_t new_blockport)
sid_t()
Create an unset SID.
sid_t(uint8_t src_addr, uint8_t src_ep, uint8_t dst_addr, uint8_t dst_ep)
Create a sid_t object from its four components.
uint32_t get_dst_endpoint() const
Return endpoint of the destination.
Definition: sid.hpp:151
uint32_t get_dst_blockport() const
Return block port of the source.
Definition: sid.hpp:161
bool operator==(const sid_t &sid) const
Definition: sid.hpp:219
sid_t operator=(const uint32_t new_sid)
Definition: sid.hpp:201
std::string to_pp_string_hex() const
Return a hexadecimal string representation of the SID.
sid_t(uint32_t sid)
Create a sid_t object from a 32-Bit SID value.
void set(uint32_t new_sid)
Alias for set_sid()
Definition: sid.hpp:169
void reverse()
Swaps dst and src in-place. This modifies the current SID.
void set_sid(uint32_t new_sid)
uint32_t get_sid() const
Returns a 32-Bit representation of the SID if set, or zero otherwise.
Definition: sid.hpp:111
sid_t operator=(const sid_t &sid)
Definition: sid.hpp:207
uint32_t get_src_blockport() const
Return block port of the source.
Definition: sid.hpp:141
sid_t(const std::string &)
Convert a string representation of a SID into its numerical representation.
sid_t(const sid_t &sid)
Copy a sid.
Definition: sid.hpp:87
uint32_t get() const
Alias for get_sid()
Definition: sid.hpp:106
void set_src(uint32_t new_addr)
Set the source address of this SID.
void set_src_addr(uint32_t new_addr)
void set_from_str(const std::string &)
Convert a string representation of a SID into a numerical one.
uint32_t get_src() const
Return the 16-bit source address of this SID.
Definition: sid.hpp:116
uint32_t get_src_endpoint() const
Return endpoint of the source.
Definition: sid.hpp:131
sid_t operator=(const std::string &sid_str)
Definition: sid.hpp:213
std::string to_pp_string() const
Return a decimal string representation of the SID.
bool is_set() const
Returns true if this actually holds a valid SID.
Definition: sid.hpp:98
uint32_t get_dst() const
Return the 16-bit destination address of this SID.
Definition: sid.hpp:121
void set_src_endpoint(uint32_t new_addr)
uint32_t get_src_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:136
void set_dst_endpoint(uint32_t new_addr)
#define UHD_API
Definition: config.h:68
Definition: build_info.hpp:13
UHD_API std::ostream & operator<<(std::ostream &os, filter_info_base &f)