usbinterface.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 USBINTERFACE_H
66 #define USBINTERFACE_H
67 
68 #include <xstypes/xstime.h>
69 
70 #include <stdlib.h>
71 #include <stdio.h>
72 #ifdef _WIN32
73  #include <windows.h>
74  //# include <sys/types.h>
75 #else
76  #include <termios.h>
77  // these are not required by level 1, but to keep the higher levels platform-independent they are put here
78  #include <string.h>
79  #include <stddef.h>
80 #endif
81 
82 #include "streaminterface.h"
83 #include <stdio.h>
84 
85 struct XsPortInfo;
86 
88 
90 {
92 
93 public:
94  UsbInterface();
95  ~UsbInterface();
96 
97  XsResultValue open(const XsPortInfo& portInfo, XsFilePos readBufSize = 0, XsFilePos writeBufSize = 0, PortOptions = PO_XsensDefaults) override;
98  XsResultValue close(void);
99  XsResultValue closeUsb(void);
100  XsResultValue flushData(void);
101 
102  bool isOpen(void) const;
103  uint8_t usbBus() const;
104  uint8_t usbAddress() const;
105 
106  XsResultValue getLastResult(void) const;
107 
109  uint32_t getTimeout(void) const;
110 
111  void setRawIo(bool enable);
112  bool getRawIo(void);
113 
114  XsResultValue writeData(const XsByteArray& data, XsFilePos* written = NULL) override;
115  XsResultValue readData(XsFilePos maxLength, XsByteArray& data) override;
117 
118  XsResultValue writeData(XsFilePos length, const void* data, XsFilePos* written = NULL);
119  XsResultValue readData(XsFilePos maxLength, void* data, XsFilePos* length = NULL);
120  XsResultValue waitForData(XsFilePos maxLength, void* data, XsFilePos* length = NULL);
121 
122  void getPortName(XsString& portname) const;
123 
125 };
126 
127 #endif
UsbInterface::~UsbInterface
~UsbInterface()
Destructor, de-initializes, frees memory allocated for buffers, etc.
Definition: usbinterface.cpp:429
XsByteArray
A list of uint8_t values.
UsbInterface::usbBus
uint8_t usbBus() const
The USB bus number this device is on (libusb/linux only)
Definition: usbinterface.cpp:1084
StreamInterface
A stream interface.
Definition: streaminterface.h:75
UsbInterface::getLastResult
XsResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: usbinterface.cpp:566
UsbInterface::close
XsResultValue close(void)
Close the USB communication port.
Definition: usbinterface.cpp:449
UsbInterface::waitForData
XsResultValue waitForData(XsFilePos maxLength, void *data, XsFilePos *length=NULL)
Wait for data to arrive or a timeout to occur.
Definition: usbinterface.cpp:978
UsbInterface::writeData
XsResultValue writeData(const XsByteArray &data, XsFilePos *written=NULL) override
Write the data to the USB port.
Definition: usbinterface.cpp:1014
UsbInterface::getPortName
void getPortName(XsString &portname) const
Retrieve the port name that was last successfully opened.
Definition: usbinterface.cpp:1112
UsbInterface::getRawIo
bool getRawIo(void)
Retrieves the state of the RAWIO mode of the USB interface.
Definition: usbinterface.cpp:955
IoInterface::PortOptions
PortOptions
Options for flow control and stopbits which must be used when opening a port.
Definition: iointerface.h:130
XsResultValue
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:82
streaminterface.h
UsbInterface::closeUsb
XsResultValue closeUsb(void)
Close the USB communication port.
Definition: usbinterface.cpp:460
UsbInterface::usbAddress
uint8_t usbAddress() const
The address of the device (libusb/linux only)
Definition: usbinterface.cpp:1098
uint32_t
unsigned int uint32_t
Definition: pstdint.h:485
XsPortInfo
Contains a descriptor for opening a communication port to an Xsens device.
Definition: xsportinfo.h:128
UsbInterfacePrivate
Private object for UsbInterface.
Definition: usbinterface.cpp:90
IoInterface::PO_XsensDefaults
@ PO_XsensDefaults
Definition: iointerface.h:138
UsbInterface::getTimeout
uint32_t getTimeout(void) const
Return the current timeout value.
Definition: usbinterface.cpp:572
UsbInterface::flushData
XsResultValue flushData(void)
Flush all data in the buffers to and from the device.
Definition: usbinterface.cpp:529
UsbInterface::setTimeout
XsResultValue setTimeout(uint32_t ms)
Set the default timeout value to use in blocking operations.
Definition: usbinterface.cpp:912
UsbInterface::readData
XsResultValue readData(XsFilePos maxLength, XsByteArray &data) override
Read data from the USB port and put it into the data buffer.
Definition: usbinterface.cpp:824
UsbInterface::UsbInterface
UsbInterface()
Default constructor, initializes all members to their default values.
Definition: usbinterface.cpp:400
UsbInterface::XSENS_DISABLE_COPY
XSENS_DISABLE_COPY(UsbInterface)
xstime.h
UsbInterface::setRawIo
void setRawIo(bool enable)
Sets the RAWIO mode of the USB interface.
Definition: usbinterface.cpp:937
UsbInterface::open
XsResultValue open(const XsPortInfo &portInfo, XsFilePos readBufSize=0, XsFilePos writeBufSize=0, PortOptions=PO_XsensDefaults) override
Open a communication channel to the given USB port name.
Definition: usbinterface.cpp:584
IoInterface::waitForData
virtual XsResultValue waitForData(XsFilePos maxLength, XsByteArray &data)
Wait for data to arrive or a timeout to occur.
Definition: iointerface.cpp:107
UsbInterface
An IoInterface for dealing specifically with Xsens USB devices.
Definition: usbinterface.h:89
UsbInterface::d
UsbInterfacePrivate * d
Definition: usbinterface.h:91
XsFilePos
int64_t XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:102
XsString
A 0-terminated managed string of characters.
UsbInterface::isOpen
bool isOpen(void) const
Return whether the USB communication port is open or not.
Definition: usbinterface.cpp:578


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