xsportinfo.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef XSPORTINFO_H
66 #define XSPORTINFO_H
67 
68 #include "xstypesconfig.h"
69 #include "pstdint.h"
70 #include "xsdeviceid.h"
71 #include "xsbaud.h"
72 #include "xsstring.h"
73 #include <stdio.h>
74 
75 #define XSENS_VENDOR_ID 0x2639
76 #define FTDI_VENDOR_ID 0x0403 // needed for Xsens USB-serial converters
77 
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81 
82 #ifndef __cplusplus
83 typedef struct XsPortInfo XsPortInfo;
84 #else
85 struct XsPortInfo;
86 #endif
87 
89 XSTYPES_DLL_API int XsPortInfo_empty(XsPortInfo const* thisPtr);
91 XSTYPES_DLL_API int XsPortInfo_isUsb(XsPortInfo const* thisPtr);
94 XSTYPES_DLL_API const char* XsPortInfo_networkServiceName(XsPortInfo const* thisPtr);
95 XSTYPES_DLL_API const char* XsPortInfo_bluetoothAddress(XsPortInfo const* thisPtr);
96 XSTYPES_DLL_API int XsPortInfo_usbBus(XsPortInfo const* thisPtr);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #if defined(_MSC_VER)
105  #pragma warning(push)
106  #pragma warning(disable : 4996)
107 #endif
108 
109 typedef enum XsPortLinesOptions
110 {
112 
114  XPLO_RTS_Clear = (1 << 1),
115  XPLO_RTS_Ignore = (1 << 2),
116 
117  XPLO_DTR_Set = (1 << 3),
118  XPLO_DTR_Clear = (1 << 4),
119  XPLO_DTR_Ignore = (1 << 5),
120 
124 
127 
129 {
130 #ifdef __cplusplus
131 
132  XsPortInfo()
133  : m_deviceId(0)
136  , m_vid(0)
137  , m_pid(0)
138  {
139  memset(m_portName, '\0', 256);
140  }
141 
147  explicit XsPortInfo(const XsString& portname, XsBaudRate baudRate = XBR_Invalid, XsPortLinesOptions linesOptions = XPLO_All_Ignore)
148  : m_deviceId(0)
149  , m_baudrate(baudRate)
150  , m_linesOptions(linesOptions)
151  , m_vid(0)
152  , m_pid(0)
153  {
154  memset(m_portName, '\0', 256);
155  if (portname.size() < 255)
156  strcpy(m_portName, portname.c_str());
157  }
158 
159 #ifndef XSENS_NO_PORT_NUMBERS
160 
166  explicit XsPortInfo(int portNr, XsBaudRate baudRate = XBR_Invalid, XsPortLinesOptions linesOptions = XPLO_All_Ignore)
167  : m_deviceId(0)
168  , m_baudrate(baudRate)
169  , m_linesOptions(linesOptions)
170  , m_vid(0)
171  , m_pid(0)
172  {
173  memset(m_portName, 0, 256);
174  sprintf(m_portName, "COM%d", portNr);
175  }
176 #endif
177 
179  inline void clear()
180  {
181  XsPortInfo_clear(this);
182  }
183 
185  inline bool empty() const
186  {
187  return XsPortInfo_empty(this) != 0;
188  }
189 
191  inline bool operator > (const XsPortInfo& p) const
192  {
193  return strcmp(m_portName, p.m_portName) > 0;
194  }
195 
197  inline bool operator < (const XsPortInfo& p) const
198  {
199  return strcmp(m_portName, p.m_portName) < 0;
200  }
201 
203  inline bool operator == (const XsPortInfo& p) const
204  {
205  return strcmp(m_portName, p.m_portName) == 0;
206  }
207 
209  inline bool operator == (const char* port) const
210  {
211  return strcmp(m_portName, port) == 0;
212  }
213 
215  inline int portNumber() const
216  {
217  return XsPortInfo_portNumber(this);
218  }
219 
222  inline XsString portName() const
223  {
224  return XsString(m_portName);
225  }
226 
229  inline char const* portName_c_str() const
230  {
231  return m_portName;
232  }
233 
236  inline void setPortName(const XsString& portName_)
237  {
238  strncpy(m_portName, portName_.c_str(), 256);
239  }
240 
242  inline bool isUsb() const
243  {
244  return XsPortInfo_isUsb(this) != 0;
245  }
246 
248  inline bool isBluetooth() const
249  {
250  return XsPortInfo_isBluetooth(this) != 0;
251  }
252 
254  inline bool isNetwork() const
255  {
256  return XsPortInfo_isNetwork(this) != 0;
257  }
258 
260  inline XsString networkServiceName() const
261  {
263  }
264 
266  inline XsString bluetoothAddress() const
267  {
269  }
270 
272  inline int usbBus() const
273  {
274  return XsPortInfo_usbBus(this);
275  }
276 
278  inline int usbAddress() const
279  {
280  return XsPortInfo_usbAddress(this);
281  }
282 
285  inline XsBaudRate baudrate() const
286  {
287  return m_baudrate;
288  }
289 
292  inline void setBaudrate(XsBaudRate baudrate_)
293  {
294  m_baudrate = baudrate_;
295  }
296 
299  inline XsDeviceId deviceId() const
300  {
301  return m_deviceId;
302  }
303 
306  inline void setDeviceId(XsDeviceId deviceId_)
307  {
308  m_deviceId = deviceId_;
309  }
310 
313  inline XsPortLinesOptions linesOptions() const
314  {
315  return m_linesOptions;
316  }
317 
320  inline void setLinesOptions(XsPortLinesOptions linesOptions)
321  {
322  m_linesOptions = linesOptions;
323  }
324 
327  inline void getVidPid(uint16_t& vid, uint16_t& pid) const
328  {
329  vid = m_vid;
330  pid = m_pid;
331  }
332 
335  inline void setVidPid(uint16_t vid, uint16_t pid)
336  {
337  m_vid = vid;
338  m_pid = pid;
339  }
340 
341 private:
342 #endif
343 
345  char m_portName[256];
348  uint16_t m_vid, m_pid;
349 };
350 
351 #if defined(_MSC_VER)
352  #pragma warning(pop)
353 #endif
354 
355 #if defined(__cplusplus) && !defined(XSENS_NO_STL)
356 #include <ostream>
357 namespace std
358 {
359 template<typename _CharT, typename _Traits>
360 basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& o, XsPortInfo const& xpi)
361 {
362  if (xpi.isUsb())
363  o << "usb ";
364  o << "port " << xpi.portName();
365  if (xpi.baudrate() != XBR_Invalid)
366  o << " at " << xpi.baudrate() << " bps";
367  if (xpi.deviceId() != 0)
368  o << " (" << xpi.deviceId() << ")";
369  return o;
370 }
371 }
372 
373 #endif
374 
375 
376 #endif
XsString
struct XsString XsString
Definition: xsstring.h:87
xsstring.h
XsPortInfo::XsPortInfo_usbAddress
int XsPortInfo_usbAddress(const struct XsPortInfo *thisPtr)
The usb address.
Definition: xsportinfo.c:186
XsPortInfo::XsPortInfo_networkServiceName
const char * XsPortInfo_networkServiceName(const struct XsPortInfo *thisPtr)
Returns the network service name of this port.
Definition: xsportinfo.c:151
XPLO_DTR_Clear
@ XPLO_DTR_Clear
Definition: xsportinfo.h:118
XsPortInfo::m_linesOptions
XsPortLinesOptions m_linesOptions
The hardware flow control lines options for the port.
Definition: xsportinfo.h:347
XsPortInfo::m_vid
uint16_t m_vid
Definition: xsportinfo.h:348
XsPortInfo::XsPortInfo_usbBus
int XsPortInfo_usbBus(const struct XsPortInfo *thisPtr)
The usb bus.
Definition: xsportinfo.c:170
XsPortInfo::m_deviceId
XsDeviceId m_deviceId
The device Id of main Xsens device detected on the port.
Definition: xsportinfo.h:344
XsPortInfo::XsPortInfo_empty
int XsPortInfo_empty(const struct XsPortInfo *thisPtr)
Returns true if the XsPortInfo object is empty.
Definition: xsportinfo.c:92
XsPortInfo::m_baudrate
XsBaudRate m_baudrate
The baudrate at which an Xsens device was detected, may be XBR_Invalid for pure USB ports.
Definition: xsportinfo.h:346
XsPortInfo::XsPortInfo_portNumber
int XsPortInfo_portNumber(const struct XsPortInfo *thisPtr)
The port number.
Definition: xsportinfo.c:102
operator==
bool operator==(const XsFilterProfile &lhs, const XsFilterProfile &rhs)
Returns true if lhs has the same type as rhs.
Definition: scenariomatchpred.h:81
XsPortInfo
struct XsPortInfo XsPortInfo
Definition: xsportinfo.h:83
XsPortInfo::XsPortInfo_bluetoothAddress
const char * XsPortInfo_bluetoothAddress(const struct XsPortInfo *thisPtr)
Returns the bluetooth address.
Definition: xsportinfo.c:160
XsBaudRate
enum XsBaudRate XsBaudRate
Communication speed.
Definition: xsbaud.h:81
XPLO_RTS_Ignore
@ XPLO_RTS_Ignore
Definition: xsportinfo.h:115
XsPortInfo
Contains a descriptor for opening a communication port to an Xsens device.
Definition: xsportinfo.h:128
XsPortLinesOptions
XsPortLinesOptions
Definition: xsportinfo.h:109
XsPortInfo::m_pid
uint16_t m_pid
The USB Vendor Id and Hardware Id of this connection, when available.
Definition: xsportinfo.h:348
XsPortInfo::m_portName
char m_portName[256]
The port name.
Definition: xsportinfo.h:345
XPLO_All_Clear
@ XPLO_All_Clear
Definition: xsportinfo.h:122
xsdeviceid.h
XPLO_DTR_Set
@ XPLO_DTR_Set
Definition: xsportinfo.h:117
xstypesconfig.h
XsDeviceId
Contains an Xsens device ID and provides operations for determining the type of device.
Definition: xsdeviceid.h:192
pstdint.h
XPLO_All_Set
@ XPLO_All_Set
Definition: xsportinfo.h:121
XsPortInfo::XsPortInfo_clear
void XsPortInfo_clear(XsPortInfo *thisPtr)
Initializes the object to the empty state.
Definition: xsportinfo.c:80
std
xsbaud.h
XsPortInfo::XsPortInfo_isNetwork
int XsPortInfo_isNetwork(const struct XsPortInfo *thisPtr)
Returns true if this port info object contains a network device.
Definition: xsportinfo.c:142
XPLO_RtsCtsFlowControl
@ XPLO_RtsCtsFlowControl
Definition: xsportinfo.h:125
XSTYPES_DLL_API
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:65
XsPortInfo_swap
XSTYPES_DLL_API void XsPortInfo_swap(XsPortInfo *a, struct XsPortInfo *b)
Swap the contents of a with those of b.
Definition: xsportinfo.c:201
XPLO_Invalid
@ XPLO_Invalid
Definition: xsportinfo.h:111
XPLO_RTS_Clear
@ XPLO_RTS_Clear
Definition: xsportinfo.h:114
operator<<
std::ostream & operator<<(std::ostream &os, JlHexLogger< char > const &hex)
Definition: journaller.cpp:388
XsPortInfo::XsPortInfo_isUsb
int XsPortInfo_isUsb(const struct XsPortInfo *thisPtr)
Returns true if this port info object contains a USB device.
Definition: xsportinfo.c:120
XPLO_RTS_Set
@ XPLO_RTS_Set
Definition: xsportinfo.h:113
XPLO_All_Ignore
@ XPLO_All_Ignore
Definition: xsportinfo.h:123
XBR_Invalid
XBR_Invalid
Not a valid baud rate.
Definition: xsbaudrate.h:126
XsString
A 0-terminated managed string of characters.
XsPortInfo::XsPortInfo_isBluetooth
int XsPortInfo_isBluetooth(const struct XsPortInfo *thisPtr)
Returns true if this port info object contains a bluetooth device.
Definition: xsportinfo.c:133
XPLO_DTR_Ignore
@ XPLO_DTR_Ignore
Definition: xsportinfo.h:119


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20