FpgaManager
Software API Documentation
FpgaManager_Types.h
1 #pragma once
2 
3 // ================================================================================
4 // PUBLIC INCLUDES
5 // ================================================================================
6 
7 #include <cstdio>
8 #include <string>
9 #include <ostream>
10 #include <iomanip>
11 
18 
19 // ================================================================================
20 // NAMESPACE
21 // ================================================================================
22 
23 namespace enclustra {
24 namespace fpgamanager {
25 namespace types {
26 
27 // ================================================================================
28 // API URL
29 // ================================================================================
30 
34 struct ApiUrl
35 {
39  enum class Protocol
40  {
41  Unknown,
42  UDP,
43  USB2,
44  USB3,
45  PCIe
46  };
47 
53  static ApiUrl UDP(const std::string& ipString);
60  static ApiUrl FX3(int vendor, int product);
68  static ApiUrl FX3(int vendor, int product, int index);
73  static ApiUrl FX3Default();
79  static ApiUrl FTDI(const std::string& serialNo);
84  static ApiUrl PCIeDefault();
90  static ApiUrl PCIe(int deviceIndex);
91 
97  static ApiUrl Parse(const std::string& url);
98 
103  const std::string& str() const;
108  Protocol protocol() const;
109 
110 private:
111  ApiUrl(Protocol protocol, const std::string& url);
112  std::string _url;
113  Protocol _protocol;
114 };
115 
116 // ================================================================================
117 // DURATION
118 // ================================================================================
119 
123 struct Duration
124 {
129  static Duration Zero();
135  static Duration FromSeconds(unsigned value);
141  static Duration FromMilliseconds(unsigned value);
146  operator uint32_t() const;
147 
154  Duration();
155 private:
156  Duration(uint32_t);
157  uint32_t _milliseconds;
158 };
159 
160 // ================================================================================
161 // VERSION
162 // ================================================================================
163 
169 template<typename T, std::size_t N>
170 struct Version
171 {
175  T value[N];
176 
182  bool operator ==(const Version<T, N>& that) const
183  {
184  for (std::size_t idx = 0; idx < N; ++idx)
185  if (value[idx] != that.value[idx])
186  return false;
187  return true;
188  }
189 
195  T& operator[](int idx)
196  {
197  return value[idx];
198  }
199 
205  const T& operator[](int idx) const
206  {
207  return value[idx];
208  }
209 };
210 
218 template<std::size_t N>
219 std::ostream& operator<<(std::ostream& lhs, const Version<uint8_t, N>& rhs)
220 {
221  for (std::size_t idx = 0; idx < N; ++idx)
222  {
223  if (idx) lhs << '.' << std::setw(2) << std::setfill('0');
224  lhs << static_cast<int>(rhs.value[idx]);
225  }
226 
227  return lhs;
228 }
229 
238 template<typename T, std::size_t N>
239 std::ostream& operator<<(std::ostream& lhs, const Version<T, N>& rhs)
240 {
241  for (std::size_t idx = 0; idx < N; ++idx)
242  {
243  if (idx) lhs << '.' << std::setw(2) << std::setfill('0');
244  lhs << rhs.value[idx];
245  }
246 
247  return lhs;
248 }
249 
250 // ================================================================================
251 // DETAILS
252 // ================================================================================
253 
258 {
263 };
264 
271 std::ostream& operator<<(std::ostream& lhs, const ApiDetails& rhs);
272 
273 
274 // ================================================================================
275 // TRAILER
276 // ================================================================================
277 
278 }
279 }
280 }
281 
Version type
Definition: FpgaManager_Types.h:170
static ApiUrl FX3(int vendor, int product)
Create an USB3 FX3 Transport URL based on FX3 vendor and product id.
const std::string & str() const
String representation of the Device URL
FPGA Manager device URL
Definition: FpgaManager_Types.h:34
T value[N]
version contents
Definition: FpgaManager_Types.h:175
static Duration FromMilliseconds(unsigned value)
Returns a duration of milliseconds
static Duration FromSeconds(unsigned value)
Returns a duration of seconds
static ApiUrl Parse(const std::string &url)
Create an URL object based on a FPGA Manager URL string
bool operator==(const Version< T, N > &that) const
Equality comparison.
Definition: FpgaManager_Types.h:182
T & operator[](int idx)
Indexer.
Definition: FpgaManager_Types.h:195
static ApiUrl UDP(const std::string &ipString)
Create an UDP Transport URL based on an IP Address
Protocol
Transport Protocol
Definition: FpgaManager_Types.h:39
Represents a time duration
Definition: FpgaManager_Types.h:123
static ApiUrl FTDI(const std::string &serialNo)
Create an USB2 FTDI Transport URL based on the FTDI serial number
Definition: FpgaManager.h:28
Details of the current API
Definition: FpgaManager_Types.h:257
types::Version< uint8_t, 3 > wrapper_version
Version of the C++ wrapper
Definition: FpgaManager_Types.h:260
static Duration Zero()
Returns a duration of zero
const T & operator[](int idx) const
Indexer.
Definition: FpgaManager_Types.h:205
static ApiUrl PCIe(int deviceIndex)
Create a PCIe Transport URL based on the device index
Protocol protocol() const
Transport Protocol of the Device URL
types::Version< uint8_t, 2 > base_dll_version
Version of the FPGA Manager API DLL
Definition: FpgaManager_Types.h:262
static ApiUrl PCIeDefault()
The default PCIe device URL
static ApiUrl FX3Default()
The default FX3 URL for Enclustra Reference Designs