xsscanner.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 XSSCANNER_H
66 #define XSSCANNER_H
67 
68 #include "xscontrollerconfig.h"
69 #include <xstypes/xsbaud.h>
70 
71 //AUTO namespace xstypes {
72 struct XsPortInfoArray;
73 //AUTO }
74 
75 //AUTO namespace xscontroller {
76 struct XsUsbHubInfo;
77 //AUTO }
78 
79 #ifdef __cplusplus
81 #include <xstypes/xsintarray.h>
82 #include <xstypes/xsstringarray.h>
83 #include "xsusbhubinfo.h"
84 #include <xstypes/xsstring.h>
85 #include <sstream>
86 extern "C" {
87 #endif
88 struct XsPortInfo;
89 
91 typedef void (*XsScanLogCallbackFunc)(struct XsString const*);
92 
93 XDA_DLL_API void XsScanner_scanPorts(struct XsPortInfoArray* ports, XsBaudRate baudrate, int singleScanTimeout, int ignoreNonXsensDevices, int detectRs485);
94 XDA_DLL_API int XsScanner_scanPort(struct XsPortInfo* port, XsBaudRate baudrate, int singleScanTimeout, int detectRs485);
95 XDA_DLL_API void XsScanner_enumerateSerialPorts(struct XsPortInfoArray* ports, int ignoreNonXsensDevices);
96 XDA_DLL_API void XsScanner_filterResponsiveDevices(struct XsPortInfoArray* ports, XsBaudRate baudrate, int singleScanTimeout, int detectRs485);
98 XDA_DLL_API void XsScanner_scanUsbHub(struct XsUsbHubInfo* hub, const struct XsPortInfo* port);
103 
104 #ifdef __cplusplus
105 } // extern "C"
106 
107 class XsScanner
108 {
109 public:
118  static inline XsPortInfoArray scanPorts(XsBaudRate baudrate = XBR_Invalid, int singleScanTimeout = 100, bool ignoreNonXsensDevices = true, bool detectRs485 = false)
119  {
120  XsPortInfoArray ports;
121  XsScanner_scanPorts(&ports, baudrate, singleScanTimeout, ignoreNonXsensDevices ? 1 : 0, detectRs485 ? 1 : 0);
122  return ports;
123  }
124 
126  static inline bool XSNOCOMEXPORT scanPort(XsPortInfo& port, XsBaudRate baudrate = XBR_Invalid, int singleScanTimeout = 100, bool detectRs485 = false)
127  {
128  return 0 != XsScanner_scanPort(&port, baudrate, singleScanTimeout, detectRs485 ? 1 : 0);
129  }
130 
139  static inline XsPortInfo scanPort(const XsString& portName, XsBaudRate baudrate = XBR_Invalid, int singleScanTimeout = 100, bool detectRs485 = false)
140  {
141  XsPortInfo pi(portName, baudrate);
142  if (scanPort(pi, baudrate, singleScanTimeout, detectRs485))
143  return pi;
144 
145  return XsPortInfo();
146  }
147 
156  static inline XsPortInfoArray scanComPortList(const XsStringArray& portList, const XsIntArray& portLinesOptionsList = XsIntArray(), XsBaudRate baudrate = XBR_Invalid, int singleScanTimeout = 100)
157  {
158  XsPortInfoArray pInfoArray;
159 
160  if (!portLinesOptionsList.empty() && (portLinesOptionsList.size() != portList.size()))
161  return pInfoArray;
162 
163  for (XsIntArray::size_type idxPort = 0; idxPort < portList.size(); ++idxPort)
164  {
165  const XsPortLinesOptions portLinesOptions = portLinesOptionsList.empty() ? XPLO_All_Ignore : static_cast<XsPortLinesOptions>(portLinesOptionsList[idxPort]);
166 
167  XsPortInfo portInfo(portList[idxPort], baudrate, portLinesOptions);
168 
169  if (scanPort(portInfo, baudrate, singleScanTimeout, (portLinesOptions == XPLO_All_Clear))) // XPLO_All_Clear == both RTS/DTR to 0 (RS485).
170  pInfoArray.push_back(portInfo);
171  }
172  return pInfoArray;
173  }
174 
179  static inline XsPortInfoArray enumerateSerialPorts(bool ignoreNonXsensDevices = true)
180  {
181  XsPortInfoArray ports;
182  XsScanner_enumerateSerialPorts(&ports, ignoreNonXsensDevices ? 1 : 0);
183  return ports;
184  }
185 
195  static inline XsPortInfoArray filterResponsiveDevices(const XsPortInfoArray& ports, XsBaudRate baudrate = XBR_Invalid, int singleScanTimeout = 100, bool detectRs485 = false)
196  {
197  XsPortInfoArray filtered(ports);
198  XsScanner_filterResponsiveDevices(&filtered, baudrate, singleScanTimeout, detectRs485 ? 1 : 0);
199  return filtered;
200  }
201 
206  static inline XsPortInfoArray enumerateUsbDevices(void)
207  {
208  XsPortInfoArray ports;
210  return ports;
211  }
212 
218  static inline XsUsbHubInfo scanUsbHub(const XsPortInfo& port)
219  {
220  XsUsbHubInfo hub;
221  XsScanner_scanUsbHub(&hub, &port);
222  return hub;
223  }
224 
229  static inline XsPortInfoArray enumerateNetworkDevices(void)
230  {
231  XsPortInfoArray ports;
233  return ports;
234  }
235 
240  static inline XsPortInfoArray enumerateBluetoothDevices(void)
241  {
242  XsPortInfoArray ports;
244  return ports;
245  }
246 
250  static inline void abortScan(void)
251  {
253  }
254 
261  static inline void XSNOCOMEXPORT setScanLogCallback(XsScanLogCallbackFunc cb)
262  {
264  }
265 };
266 
267 #endif
268 
269 #endif
XsScanner_setScanLogCallback
XDA_DLL_API void XsScanner_setScanLogCallback(XsScanLogCallbackFunc cb)
Set a callback function for scan log progress and problem reporting.
Definition: xsscanner.cpp:131
xsstring.h
XsScanner::XsScanner_scanPorts
void XsScanner_scanPorts(XsPortInfoArray *ports, XsBaudRate baudrate, int singleScanTimeout, int ignoreNonXsensDevices, int detectRs485)
Scan all ports for Xsens devices.
Definition: xsscanner.cpp:144
xsusbhubinfo.h
XsScanner_enumerateNetworkDevices
XDA_DLL_API void XsScanner_enumerateNetworkDevices(struct XsPortInfoArray *ports)
Definition: xsscanner.cpp:237
XsIntArray
A list of XsInt values.
XsScanner_enumerateBluetoothDevices
XDA_DLL_API void XsScanner_enumerateBluetoothDevices(struct XsPortInfoArray *ports)
Definition: xsscanner.cpp:251
XsScanner::XsScanner_abortScan
void XsScanner_abortScan(void)
Abort the currently running port scan(s)
Definition: xsscanner.cpp:268
xsstringarray.h
XsScanner::XsScanner_scanPort
int XsScanner_scanPort(XsPortInfo *port, XsBaudRate baudrate, int singleScanTimeout, int detectRs485)
Scan a single port for Xsens devices.
Definition: xsscanner.cpp:158
XsStringArray
A list of XsString values.
XsScanLogCallbackFunc
void(* XsScanLogCallbackFunc)(struct XsString const *)
Defines the callback type that can be supplied to XsScanner_setScanLogCallback.
Definition: xsscanner.h:91
XDA_DLL_API
#define XDA_DLL_API
Definition: xscontrollerconfig.h:161
XsScanner::XsScanner_scanUsbHub
void XsScanner_scanUsbHub(XsUsbHubInfo *hub, const XsPortInfo *port)
Determine the USB hub that port is attached to.
Definition: xsscanner.cpp:225
XsPortInfo
struct XsPortInfo XsPortInfo
Definition: xsportinfo.h:83
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
XsScanner_enumerateSerialPorts
XDA_DLL_API void XsScanner_enumerateSerialPorts(struct XsPortInfoArray *ports, int ignoreNonXsensDevices)
List all serial ports without scanning.
Definition: xsscanner.cpp:165
XsScanner
Provides static functionality for scanning for Xsens devices.
XPLO_All_Clear
@ XPLO_All_Clear
Definition: xsportinfo.h:122
XsUsbHubInfo
A structure that wraps USB hub information.
Definition: xsusbhubinfo.h:99
XsPortInfoArray
A list of XsPortInfo values.
XsIntArray
struct XsIntArray XsIntArray
Definition: xsintarray.h:80
xsbaud.h
XsScanner::XsScanner_enumerateUsbDevices
void XsScanner_enumerateUsbDevices(XsPortInfoArray *ports)
List all compatible USB ports without scanning.
Definition: xsscanner.cpp:204
XPLO_All_Ignore
@ XPLO_All_Ignore
Definition: xsportinfo.h:123
XsScanner::XsScanner_filterResponsiveDevices
void XsScanner_filterResponsiveDevices(XsPortInfoArray *ports, XsBaudRate baudrate, int singleScanTimeout, int detectRs485)
Scan the supplied ports for Xsens devices.
Definition: xsscanner.cpp:178
XBR_Invalid
XBR_Invalid
Not a valid baud rate.
Definition: xsbaudrate.h:126
XsString
A 0-terminated managed string of characters.
xsportinfoarray.h
xscontrollerconfig.h
xsintarray.h


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