An IoInterface for dealing specifically with Xsens USB devices.
Definition at line 34 of file usbinterface.h.
#include <xSens_MT4/xcommunication/include/xsens/usbinterface.h>
Public Member Functions | |
UsbInterface () | |
Default constructor, initializes all members to their default values. More... | |
~UsbInterface () | |
Destructor, de-initializes, frees memory allocated for buffers, etc. More... | |
XsResultValue | open (const XsPortInfo &portInfo, uint32_t readBufSize=0, uint32_t writeBufSize=0) |
Open a communication channel to the given USB port name. More... | |
XsResultValue | close (void) |
Close the USB communication port. More... | |
XsResultValue | closeUsb (void) |
Close the USB communication port. More... | |
XsResultValue | flushData (void) |
Flush all data in the buffers to and from the device. More... | |
bool | isOpen (void) const |
Return whether the USB communication port is open or not. More... | |
uint8_t | usbBus () const |
The USB bus number this device is on (libusb/linux only) More... | |
uint8_t | usbAddress () const |
The address of the device (libusb/linux only) More... | |
XsResultValue | getLastResult (void) const |
Return the error code of the last operation. More... | |
XsResultValue | setTimeout (uint32_t ms) |
Set the default timeout value to use in blocking operations. More... | |
uint32_t | getTimeout (void) const |
Return the current timeout value. More... | |
void | setRawIo (bool enable) |
Sets the RAWIO mode of the USB interface. More... | |
bool | getRawIo (void) |
Retrieves the state of the RAWIO mode of the USB interface. More... | |
virtual XsResultValue | writeData (const XsByteArray &data, XsSize *written=NULL) |
Write the data to the USB port. More... | |
virtual XsResultValue | readData (XsSize maxLength, XsByteArray &data) |
Read data from the USB port and put it into the data buffer. More... | |
XsResultValue | writeData (XsSize length, const void *data, XsSize *written=NULL) |
Write the data to the USB port. More... | |
XsResultValue | readData (XsSize maxLength, void *data, XsSize *length=NULL) |
Read data from the serial port and put it into the data buffer. More... | |
XsResultValue | waitForData (XsSize maxLength, void *data, XsSize *length=NULL) |
Wait for data to arrive or a timeout to occur. More... | |
void | getPortName (XsString &portname) const |
Retrieve the port name that was last successfully opened. More... | |
virtual XsResultValue | waitForData (XsSize maxLength, XsByteArray &data) |
Wait for data to arrive or a timeout to occur. More... | |
virtual XsResultValue | open (const XsString &filename, bool createNew, bool readOnly) |
Open a file. More... | |
virtual XsResultValue | waitForData (XsSize maxLength, XsByteArray &data) |
Wait for data to arrive or a timeout to occur. More... | |
virtual void | cancelIo (void) const |
Cancel any pending io requests. More... | |
virtual XsResultValue | appendData (const XsByteArray &bdata) |
Write data to the end of the file. More... | |
virtual XsResultValue | closeAndDelete (void) |
Close the file and delete it. More... | |
virtual XsResultValue | create (const XsString &filename) |
Create an empty file. More... | |
virtual XsResultValue | deleteData (XsFilePos start, XsSize length) |
Delete the given data from the file. More... | |
virtual XsResultValue | find (const XsByteArray &needleV, XsFilePos &pos) |
Find a string of bytes in the file. More... | |
virtual XsFilePos | getFileSize (void) const |
Return the size of the file. More... | |
virtual XsResultValue | getName (XsString &filename) const |
Retrieve the filename that was last successfully opened. More... | |
virtual XsFilePos | getReadPosition (void) const |
Return the current read position. More... | |
virtual XsFilePos | getWritePosition (void) const |
Return the current write position. More... | |
virtual XsResultValue | insertData (XsFilePos start, const XsByteArray &data) |
Insert the given data into the file. More... | |
virtual bool | isReadOnly (void) const |
Return whether the file is readonly or not. More... | |
virtual XsResultValue | setReadPosition (XsFilePos pos) |
Set the new absolute read position. More... | |
virtual XsResultValue | setWritePosition (XsFilePos pos=-1) |
Set the new absolute write position. More... | |
Private Attributes | |
UsbInterfacePrivate * | d |
UsbInterface::UsbInterface | ( | ) |
Default constructor, initializes all members to their default values.
Definition at line 385 of file usbinterface.cpp.
References d, FALSE, UsbInterfacePrivate::m_dataInEndPoint, UsbInterfacePrivate::m_dataOutEndPoint, UsbInterfacePrivate::m_deviceHandle, UsbInterfacePrivate::m_endTime, UsbInterfacePrivate::m_lastResult, UsbInterfacePrivate::m_portname, UsbInterfacePrivate::m_timeout, TRUE, and XRV_OK.
UsbInterface::~UsbInterface | ( | ) |
Destructor, de-initializes, frees memory allocated for buffers, etc.
Definition at line 417 of file usbinterface.cpp.
References closeUsb(), and d.
|
virtualinherited |
Write data to the end of the file.
The function writes the given data to the file at the end. The current write position is also moved to the end of the file.
bdata | The byte data to append to the file |
Reimplemented in IoInterfaceFile.
Definition at line 79 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
Cancel any pending io requests.
Reimplemented in SerialInterface.
Definition at line 72 of file iointerface.cpp.
|
virtual |
Close the USB communication port.
Implements IoInterface.
Definition at line 434 of file usbinterface.cpp.
References closeUsb().
|
virtualinherited |
Close the file and delete it.
Reimplemented in IoInterfaceFile.
Definition at line 85 of file iointerface.cpp.
References XRV_INVALIDOPERATION.
XsResultValue UsbInterface::closeUsb | ( | void | ) |
Close the USB communication port.
Definition at line 445 of file usbinterface.cpp.
References XsLibUsb::attach_kernel_driver, XsLibUsb::close, d, mrpt::system::os::fclose(), flushData(), XsLibUsb::get_device, UsbInterfacePrivate::getContextManager(), isOpen(), UsbInterfacePrivate::m_dataInEndPoint, UsbInterfacePrivate::m_dataOutEndPoint, UsbInterfacePrivate::m_deviceHandle, UsbInterfacePrivate::m_endTime, UsbInterfacePrivate::m_interface, UsbInterfacePrivate::m_interfaceCount, UsbInterfacePrivate::m_lastResult, UsbInterfacePrivate::UsbContext::m_libUsb, xsens::msleep(), XsLibUsb::release_interface, XsLibUsb::unref_device, XRV_NOPORTOPEN, and XRV_OK.
Referenced by close(), and ~UsbInterface().
|
virtualinherited |
Create an empty file.
filename | The desired (path+)name of the file |
Reimplemented in IoInterfaceFile.
Definition at line 90 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtualinherited |
Delete the given data from the file.
The function erases the given data from the file at the given write position. This operation may take a while to complete, but is faster than insertData.
The write position is not changed and the read position is checked for validity upon function exit.
start | The offset of the first byte to delete |
length | The total number of bytes to delete |
Reimplemented in IoInterfaceFile.
Definition at line 96 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtualinherited |
Find a string of bytes in the file.
The function searches from the current read position until the given needle
is found. If the needle is not found, XsResultValue::NOT_FOUND is returned. The function will update the seek position to the first character of the found needle.
needleV | The byte string to find. |
pos | The position where needleV was found. This will point to the first character of the found needleV. |
Reimplemented in IoInterfaceFile.
Definition at line 103 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtual |
Flush all data in the buffers to and from the device.
Implements IoInterface.
Definition at line 512 of file usbinterface.cpp.
References d, UsbInterfacePrivate::getContextManager(), UsbInterfacePrivate::m_dataInEndPoint, UsbInterfacePrivate::m_deviceHandle, UsbInterfacePrivate::m_endTime, UsbInterfacePrivate::m_lastResult, and XRV_OK.
Referenced by closeUsb(), and open().
Return the size of the file.
Reimplemented in IoInterfaceFile.
Definition at line 110 of file iointerface.cpp.
|
virtual |
Return the error code of the last operation.
Implements IoInterface.
Definition at line 545 of file usbinterface.cpp.
References d, and UsbInterfacePrivate::m_lastResult.
|
virtualinherited |
Retrieve the filename that was last successfully opened.
filename | The XsString which will contain the filename. |
Reimplemented in IoInterfaceFile.
Definition at line 115 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
Retrieve the port name that was last successfully opened.
Definition at line 1089 of file usbinterface.cpp.
References d, and UsbInterfacePrivate::m_portname.
bool UsbInterface::getRawIo | ( | void | ) |
Retrieves the state of the RAWIO mode of the USB interface.
Definition at line 931 of file usbinterface.cpp.
References d.
Return the current read position.
Reimplemented in IoInterfaceFile.
Definition at line 121 of file iointerface.cpp.
Return the current timeout value.
Implements StreamInterface.
Definition at line 551 of file usbinterface.cpp.
References d, and UsbInterfacePrivate::m_timeout.
Return the current write position.
Reimplemented in IoInterfaceFile.
Definition at line 126 of file iointerface.cpp.
|
virtualinherited |
Insert the given data into the file.
The function writes the given data to the file at the current write position. This operation may take a while to complete.
The write position is placed at the end of the inserted data.
start | The offset in the file to write the first byte |
data | The data to insert in the file |
Reimplemented in IoInterfaceFile.
Definition at line 131 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtual |
Return whether the USB communication port is open or not.
Implements IoInterface.
Definition at line 557 of file usbinterface.cpp.
References d, and UsbInterfacePrivate::m_deviceHandle.
Referenced by closeUsb(), open(), readData(), and writeData().
|
virtualinherited |
Return whether the file is readonly or not.
Reimplemented in IoInterfaceFile.
Definition at line 138 of file iointerface.cpp.
|
virtual |
Open a communication channel to the given USB port name.
Reimplemented from IoInterface.
Definition at line 563 of file usbinterface.cpp.
References XsLibUsb::attach_kernel_driver, XsLibUsb::claim_interface, XsLibUsb::close, d, XsLibUsb::detach_kernel_driver, FALSE, flushData(), XsLibUsb::free_config_descriptor, XsLibUsb::free_device_list, XsLibUsb::get_active_config_descriptor, XsLibUsb::get_device_address, XsLibUsb::get_device_descriptor, XsLibUsb::get_device_list, UsbInterfacePrivate::getContextManager(), isOpen(), JLALERT, JLDEBUG, XsLibUsb::kernel_driver_active, UsbInterfacePrivate::libusbErrorToXrv(), UsbInterfacePrivate::m_dataInEndPoint, UsbInterfacePrivate::m_dataOutEndPoint, UsbInterfacePrivate::m_deviceHandle, UsbInterfacePrivate::m_endTime, UsbInterfacePrivate::m_interface, UsbInterfacePrivate::m_interfaceCount, UsbInterfacePrivate::m_lastResult, UsbInterfacePrivate::UsbContext::m_libUsb, UsbInterfacePrivate::m_portname, XsLibUsb::open, XsLibUsb::ref_device, XsLibUsb::release_interface, setTimeout(), mrpt::system::os::sprintf(), XsLibUsb::unref_device, XRV_ALREADYOPEN, XRV_ERROR, XRV_INPUTCANNOTBEOPENED, XRV_OK, XRV_PORTNOTFOUND, XSENS_INVALID_THREAD, XsPortInfo_usbAddress(), XsPortInfo_usbBus(), and xsStartThread.
|
virtualinherited |
Open a file.
filename | The name of the file to open |
createNew | When true, the file will be created if it doesn't exist yet |
readOnly | When true, the file will be marked as read only for IoInterfaceFile, preventing accidental writes to the file. |
Reimplemented in IoInterfaceFile.
Definition at line 143 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtual |
Read data from the USB port and put it into the data buffer.
This function reads up to maxLength bytes from the port (non-blocking) and puts it into the data buffer.
maxLength | The maximum amount of data read. |
data | The buffer that will store the received data. |
Implements IoInterface.
Definition at line 810 of file usbinterface.cpp.
Referenced by waitForData().
XsResultValue UsbInterface::readData | ( | XsSize | maxLength, |
void * | data, | ||
XsSize * | length = NULL |
||
) |
Read data from the serial port and put it into the data buffer.
This function reads up to maxLength bytes from the USB port (non-blocking) and puts it into the data buffer.
maxLength | The maximum number of bytes to read. |
data | Pointer to a buffer that will store the received data. |
length | The number of bytes placed into data . |
Definition at line 828 of file usbinterface.cpp.
References XsLibUsb::bulk_transfer, d, mrpt::system::os::fopen(), UsbInterfacePrivate::getContextManager(), isOpen(), JLTRACE, UsbInterfacePrivate::libusbErrorToString(), UsbInterfacePrivate::libusbErrorToXrv(), UsbInterfacePrivate::m_dataInEndPoint, UsbInterfacePrivate::m_deviceHandle, UsbInterfacePrivate::m_lastResult, UsbInterfacePrivate::UsbContext::m_libUsb, UsbInterfacePrivate::m_timeout, mrpt::system::os::memcpy(), mrpt::system::os::sprintf(), usbAddress(), usbBus(), XRV_NOPORTOPEN, XRV_OK, and XS_MAX_FILENAME_LENGTH.
void UsbInterface::setRawIo | ( | bool | enable | ) |
Sets the RAWIO mode of the USB interface.
enable | : If true will enable RAW IO mode |
Definition at line 913 of file usbinterface.cpp.
References d, JLDEBUG, UsbInterfacePrivate::m_lastResult, void(), and XRV_OK.
|
virtualinherited |
Set the new absolute read position.
The read position is checked against the filesize first.
pos | The new read position |
Reimplemented in IoInterfaceFile.
Definition at line 151 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtual |
Set the default timeout value to use in blocking operations.
This function sets the value of m_timeout. There is no infinity value. The value 0 means that the default value is used.
ms | The desired timeout in milliseconds |
Implements StreamInterface.
Definition at line 888 of file usbinterface.cpp.
References d, FALSE, JLDEBUG, UsbInterfacePrivate::m_lastResult, UsbInterfacePrivate::m_timeout, and XRV_OK.
Referenced by open().
|
virtualinherited |
Set the new absolute write position.
The write position is checked against the filesize first.
pos | The new write position |
Reimplemented in IoInterfaceFile.
Definition at line 157 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
uint8_t UsbInterface::usbAddress | ( | ) | const |
The address of the device (libusb/linux only)
Definition at line 1075 of file usbinterface.cpp.
References d, XsLibUsb::get_device, XsLibUsb::get_device_address, UsbInterfacePrivate::getContextManager(), UsbInterfacePrivate::m_deviceHandle, and UsbInterfacePrivate::UsbContext::m_libUsb.
Referenced by readData(), and writeData().
uint8_t UsbInterface::usbBus | ( | ) | const |
The USB bus number this device is on (libusb/linux only)
Definition at line 1061 of file usbinterface.cpp.
References d, XsLibUsb::get_bus_number, XsLibUsb::get_device, UsbInterfacePrivate::getContextManager(), UsbInterfacePrivate::m_deviceHandle, and UsbInterfacePrivate::UsbContext::m_libUsb.
Referenced by readData(), and writeData().
XsResultValue IoInterface::waitForData |
Wait for data to arrive or a timeout to occur.
The function waits until maxLength
data is available or until a timeout occurs. The function returns success if data is available or XsResultValue::TIMEOUT if a timeout occurred. A timeout value of 0 indicates that the default timeout stored in the class should be used.
maxLength | The maximum number of bytes to read before returning |
data | The buffer to put the read data in. |
Definition at line 65 of file iointerface.cpp.
XsResultValue UsbInterface::waitForData | ( | XsSize | maxLength, |
void * | data, | ||
XsSize * | length = NULL |
||
) |
Wait for data to arrive or a timeout to occur.
The function waits until maxLength
data is available or until a timeout occurs. The function returns success if data is available or XsResultValue::TIMEOUT if a timeout occurred. A timeout value of 0 indicates that the default timeout stored in the class should be used.
maxLength | The maximum number of bytes to wait for |
data | A buffer that will be filled with the read data. It must be able to contain at least maxLength bytes. |
length | An optional pointer to storage for the actual number of bytes read. |
Definition at line 954 of file usbinterface.cpp.
References d, xsens::getTimeOfDay(), JLTRACE, UsbInterfacePrivate::m_lastResult, UsbInterfacePrivate::m_timeout, readData(), XRV_OK, and XRV_TIMEOUT.
|
virtualinherited |
Wait for data to arrive or a timeout to occur.
The function waits until maxLength
data is available or until a timeout occurs. The function returns success if data is available or XsResultValue::TIMEOUT if a timeout occurred. A timeout value of 0 indicates that the default timeout stored in the class should be used.
maxLength | The maximum number of bytes to read before returning |
data | The buffer to put the read data in. |
Reimplemented in SerialInterface.
Definition at line 65 of file iointerface.cpp.
References void(), and XRV_INVALIDOPERATION.
|
virtual |
Write the data to the USB port.
The function writes the given data to the connected USB port. The default timeout is respected in this operation.
data | The data to be written |
written | An optional pointer to storage for the actual number of bytes that were written |
Implements IoInterface.
Definition at line 990 of file usbinterface.cpp.
XsResultValue UsbInterface::writeData | ( | XsSize | length, |
const void * | data, | ||
XsSize * | written = NULL |
||
) |
Write the data to the USB port.
The function writes the given data to the connected USB port. The default timeout is respected in this operation.
length | The number of bytes to write. |
data | A pointer to a memory buffer that contains the bytes to send |
written | An optional pointer to storage for the actual number of bytes that were written |
Definition at line 1004 of file usbinterface.cpp.
References XsLibUsb::bulk_transfer, d, mrpt::system::os::fopen(), UsbInterfacePrivate::getContextManager(), isOpen(), JLALERT, UsbInterfacePrivate::libusbErrorToString(), UsbInterfacePrivate::libusbErrorToXrv(), UsbInterfacePrivate::m_dataOutEndPoint, UsbInterfacePrivate::m_deviceHandle, UsbInterfacePrivate::m_lastResult, UsbInterfacePrivate::UsbContext::m_libUsb, mrpt::system::os::sprintf(), usbAddress(), usbBus(), XRV_NOPORTOPEN, XRV_OK, and XS_MAX_FILENAME_LENGTH.
|
private |
Definition at line 70 of file usbinterface.h.
Referenced by closeUsb(), flushData(), getLastResult(), getPortName(), getRawIo(), getTimeout(), isOpen(), open(), readData(), setRawIo(), setTimeout(), usbAddress(), usbBus(), UsbInterface(), waitForData(), writeData(), and ~UsbInterface().
Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020 |