USRP Hardware Driver and USRP Manual  Version: 004.000.000.HEAD-0-g8773fb2c
UHD and USRP Manual
sid.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2014-2016 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_UHD_TYPES_SID_HPP
19 #define INCLUDED_UHD_TYPES_SID_HPP
20 
21 #include <uhd/config.hpp>
22 #include <iostream>
23 #include <stdint.h>
24 
25 namespace uhd {
78  class UHD_API sid_t
79  {
80  public:
82  sid_t();
84  sid_t(uint32_t sid);
86  sid_t(uint8_t src_addr, uint8_t src_ep, uint8_t dst_addr, uint8_t dst_ep);
88  sid_t(const std::string &);
89 
91  std::string to_pp_string() const;
93  std::string to_pp_string_hex() const;
94 
96  bool is_set() const { return _set; };
97 
98  // Getters
99  //
101  inline uint32_t get() const { return get_sid(); };
103  inline uint32_t get_sid() const { return _set ? _sid : 0; };
105  inline uint32_t get_src() const {
106  return (_sid >> 16) & 0xFFFF;
107  }
109  inline uint32_t get_dst() const {
110  return _sid & 0xFFFF;
111  }
113  inline uint32_t get_src_addr() const {
114  return (get_src() >> 8) & 0xFF;
115  }
117  inline uint32_t get_src_endpoint() const {
118  return get_src() & 0xFF;
119  }
121  inline uint32_t get_src_xbarport() const {
122  return (get_src_endpoint() >> 4) & 0xF;
123  }
125  inline uint32_t get_src_blockport() const {
126  return (get_src_endpoint()) & 0xF;
127  }
129  inline uint32_t get_dst_addr() const {
130  return (get_dst() >> 8) & 0xFF;
131  }
133  inline uint32_t get_dst_endpoint() const {
134  return get_dst() & 0xFF;
135  }
137  inline uint32_t get_dst_xbarport() const {
138  return (get_dst_endpoint() >> 4) & 0xF;
139  }
141  inline uint32_t get_dst_blockport() const {
142  return (get_dst_endpoint()) & 0xF;
143  }
144 
145  // Setters
146 
148  void set(uint32_t new_sid) { set_sid(new_sid); };
150  // Throws uhd::value_error if the string is not a valid SID
151  // representation.
152  void set_from_str(const std::string &);
153  void set_sid(uint32_t new_sid);
155  // (the first 16 Bits)
156  void set_src(uint32_t new_addr);
158  // (the last 16 Bits)
159  void set_dst(uint32_t new_addr);
160  void set_src_addr(uint32_t new_addr);
161  void set_src_endpoint(uint32_t new_addr);
162  void set_dst_addr(uint32_t new_addr);
163  void set_dst_endpoint(uint32_t new_addr);
164  void set_dst_xbarport(uint32_t new_xbarport);
165  void set_dst_blockport(uint32_t new_blockport);
166 
167  // Manipulators
168 
170  sid_t reversed() const;
171 
173  void reverse();
174 
175  // Overloaded operators
176 
177  sid_t operator = (const uint32_t new_sid) {
178  set_sid(new_sid);
179  return *this;
180  }
181 
182  sid_t operator = (sid_t &sid) {
183  set_sid(sid.get_sid());
184  return *this;
185  }
186 
187  sid_t operator = (const sid_t &sid) {
188  set_sid(sid.get_sid());
189  return *this;
190  }
191 
192  sid_t operator = (const std::string &sid_str) {
193  set_from_str(sid_str);
194  return *this;
195  }
196 
197  bool operator == (const sid_t &sid) const {
198  return (not _set and not sid.is_set()) or (_sid == sid.get_sid());
199  }
200 
201  bool operator == (uint32_t sid) const {
202  return _set and _sid == sid;
203  }
204 
205  bool operator == (const std::string &sid_str) const {
206  sid_t rhs(sid_str);
207  return *this == rhs;
208  }
209 
210  // overloaded type casts are tricky, but for now we'll need them
211  // for backward compatibility. consider them deprecated.
212 
214  // Use is_set() to check if the return value is valid.
215  operator uint32_t() const {
216  return get();
217  }
218 
219  operator bool() const {
220  return _set;
221  }
222 
223  private:
224  uint32_t _sid;
225  bool _set;
226  };
227 
229  inline std::ostream& operator<< (std::ostream& out, const sid_t &sid) {
230  std::ios_base::fmtflags ff = out.flags();
231  if (ff & std::ios::hex) {
232  out << sid.to_pp_string_hex();
233  } else {
234  out << sid.to_pp_string();
235  }
236  return out;
237  }
238 
239 } //namespace uhd
240 
241 #endif /* INCLUDED_UHD_TYPES_SID_HPP */
242 // vim: sw=4 et:
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:56
uint32_t get_sid() const
Returns a 32-Bit representation of the SID if set, or zero otherwise.
Definition: sid.hpp:103
uint32_t get_dst_addr() const
Return 8-bit address of the destination.
Definition: sid.hpp:129
uint32_t get_src_addr() const
Return 8-bit address of the source.
Definition: sid.hpp:113
uint32_t get_dst_blockport() const
Return block port of the source.
Definition: sid.hpp:141
Definition: build_info.hpp:25
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:117
uint32_t get_src() const
Return the 16-bit source address of this SID.
Definition: sid.hpp:105
uint32_t get_dst() const
Return the 16-bit destination address of this SID.
Definition: sid.hpp:109
Represents a stream ID (SID).
Definition: sid.hpp:78
uint32_t get_dst_xbarport() const
Return crossbar port of the source.
Definition: sid.hpp:137
#define UHD_API
Definition: config.h:73
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:96
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:133
uint32_t get_src_blockport() const
Return block port of the source.
Definition: sid.hpp:125
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:121