xsportinfo.c
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 #include "xsportinfo.h"
66 #include <ctype.h>
67 #include <string.h> // strlen
68 #include <stdlib.h> // atoi
69 
81 {
82  thisPtr->m_baudrate = XBR_Invalid;
83  thisPtr->m_deviceId.m_deviceId = 0;
84  thisPtr->m_deviceId.m_productCode[0] = '\0';
85  thisPtr->m_portName[0] = '\0';
87 }
88 
92 int XsPortInfo_empty(const struct XsPortInfo* thisPtr)
93 {
94  return (thisPtr->m_portName[0] == '\0');
95 }
96 
102 int XsPortInfo_portNumber(const struct XsPortInfo* thisPtr)
103 {
104  size_t i;
105 
106  if (XsPortInfo_empty(thisPtr))
107  return 0;
108 
109  for (i = 0; i < strlen(thisPtr->m_portName); i++)
110  {
111  if (isdigit(thisPtr->m_portName[i]))
112  return atoi(&thisPtr->m_portName[i]);
113  }
114  return 0;
115 }
116 
120 int XsPortInfo_isUsb(const struct XsPortInfo* thisPtr)
121 {
122 #ifdef XSENS_WINDOWS
123  return strncmp("\\\\?\\usb", thisPtr->m_portName, 7) == 0;
124 #else
125  return strncmp("USB", thisPtr->m_portName, 3) == 0; // libusb devices start with USB
126 #endif
127 }
128 
133 int XsPortInfo_isBluetooth(const struct XsPortInfo* thisPtr)
134 {
135  return strncmp("BT:", thisPtr->m_portName, 3) == 0;
136 }
137 
142 int XsPortInfo_isNetwork(const struct XsPortInfo* thisPtr)
143 {
144  return strncmp("NET:", thisPtr->m_portName, 4) == 0;
145 }
146 
151 const char* XsPortInfo_networkServiceName(const struct XsPortInfo* thisPtr)
152 {
153  return &thisPtr->m_portName[4];
154 }
155 
160 const char* XsPortInfo_bluetoothAddress(const struct XsPortInfo* thisPtr)
161 {
162  return &thisPtr->m_portName[3];
163 }
164 
170 int XsPortInfo_usbBus(const struct XsPortInfo* thisPtr)
171 {
172 #ifndef XSENS_WINDOWS
173  if (XsPortInfo_isUsb(thisPtr))
174  return atoi(&thisPtr->m_portName[3]);
175 #else
176  (void) thisPtr;
177 #endif
178  return 0;
179 }
180 
186 int XsPortInfo_usbAddress(const struct XsPortInfo* thisPtr)
187 {
188 #ifndef XSENS_WINDOWS
189  if (XsPortInfo_isUsb(thisPtr))
190  return atoi(&thisPtr->m_portName[7]);
191 #else
192  (void) thisPtr;
193 #endif
194  return 0;
195 }
196 
201 void XsPortInfo_swap(struct XsPortInfo* a, struct XsPortInfo* b)
202 {
203  int i;
204  char c;
205  XsPortLinesOptions pLineOpts;
206  uint16_t u;
207 
208  XsBaudRate t = a->m_baudrate;
209  a->m_baudrate = b->m_baudrate;
210  b->m_baudrate = t;
211 
213 
214  for (i = 0; i < 256; ++i)
215  {
216  c = a->m_portName[i];
217  a->m_portName[i] = b->m_portName[i];
218  b->m_portName[i] = c;
219  }
220 
221  pLineOpts = a->m_linesOptions;
223  b->m_linesOptions = pLineOpts;
224 
225  u = a->m_vid;
226  a->m_vid = b->m_vid;
227  b->m_vid = u;
228 
229  u = a->m_pid;
230  a->m_pid = b->m_pid;
231  b->m_pid = u;
232 }
233 
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
XsDeviceId::m_productCode
char m_productCode[XSDEVICEID_PRODUCT_CODE_LEN]
The productcode of a device.
Definition: xsdeviceid.h:906
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
XsDeviceId_swap
void XsDeviceId_swap(XsDeviceId *a, XsDeviceId *b)
Swap the contents of a with those of b.
Definition: xsdeviceid.c:813
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.h
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
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
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
XsPortInfo::XsPortInfo_clear
void XsPortInfo_clear(XsPortInfo *thisPtr)
Initializes the object to the empty state.
Definition: xsportinfo.c:80
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
XsPortInfo_swap
void XsPortInfo_swap(struct XsPortInfo *a, struct XsPortInfo *b)
Swap the contents of a with those of b.
Definition: xsportinfo.c:201
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
XsDeviceId::m_deviceId
uint64_t m_deviceId
The serialnumber of a device.
Definition: xsdeviceid.h:905
XPLO_All_Ignore
@ XPLO_All_Ignore
Definition: xsportinfo.h:123
XBR_Invalid
XBR_Invalid
Not a valid baud rate.
Definition: xsbaudrate.h:126
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


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