| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#ifndef XSPORTINFO_H |
| 34 |
#define XSPORTINFO_H |
| 35 |
|
| 36 |
#include "xstypesconfig.h" |
| 37 |
#include "pstdint.h" |
| 38 |
#include "xsdeviceid.h" |
| 39 |
#include "xsbaud.h" |
| 40 |
#include "xsstring.h" |
| 41 |
#include <stdio.h> |
| 42 |
|
| 43 |
#define XSENS_VENDOR_ID 0x2639 |
| 44 |
#define FTDI_VENDOR_ID 0x0403 // needed for Xsens USB-serial converters |
| 45 |
|
| 46 |
#ifdef __cplusplus |
| 47 |
extern "C" { |
| 48 |
#endif |
| 49 |
|
| 50 |
#ifndef __cplusplus |
| 51 |
typedef struct XsPortInfo XsPortInfo; |
| 52 |
#else |
| 53 |
struct XsPortInfo; |
| 54 |
#endif |
| 55 |
|
| 56 |
XSTYPES_DLL_API void XsPortInfo_clear(XsPortInfo* thisPtr); |
| 57 |
XSTYPES_DLL_API int XsPortInfo_empty(XsPortInfo const* thisPtr); |
| 58 |
XSTYPES_DLL_API int XsPortInfo_portNumber(XsPortInfo const* thisPtr); |
| 59 |
XSTYPES_DLL_API int XsPortInfo_isUsb(XsPortInfo const* thisPtr); |
| 60 |
XSTYPES_DLL_API int XsPortInfo_isNetwork(XsPortInfo const* thisPtr); |
| 61 |
XSTYPES_DLL_API const char* XsPortInfo_networkServiceName(XsPortInfo const* thisPtr); |
| 62 |
XSTYPES_DLL_API int XsPortInfo_usbBus(XsPortInfo const* thisPtr); |
| 63 |
XSTYPES_DLL_API int XsPortInfo_usbAddress(XsPortInfo const* thisPtr); |
| 64 |
XSTYPES_DLL_API void XsPortInfo_swap(XsPortInfo* a, struct XsPortInfo* b); |
| 65 |
|
| 66 |
#ifdef __cplusplus |
| 67 |
} |
| 68 |
#endif |
| 69 |
|
| 70 |
#if defined(_MSC_VER) |
| 71 |
#pragma warning(push) |
| 72 |
#pragma warning(disable : 4996) |
| 73 |
#endif |
| 74 |
|
| 75 |
typedef enum XsPortLinesOptions |
| 76 |
{ |
| 77 |
XPLO_Invalid = 0, |
| 78 |
|
| 79 |
XPLO_RTS_Set = 1, |
| 80 |
XPLO_RTS_Clear = (1 << 1), |
| 81 |
XPLO_RTS_Ignore = (1 << 2), |
| 82 |
|
| 83 |
XPLO_DTR_Set = (1 << 3), |
| 84 |
XPLO_DTR_Clear = (1 << 4), |
| 85 |
XPLO_DTR_Ignore = (1 << 5), |
| 86 |
|
| 87 |
XPLO_All_Set = XPLO_RTS_Set | XPLO_DTR_Set, |
| 88 |
XPLO_All_Clear = XPLO_RTS_Clear | XPLO_DTR_Clear, |
| 89 |
XPLO_All_Ignore = XPLO_RTS_Ignore | XPLO_DTR_Ignore, |
| 90 |
|
| 91 |
XPLO_RtsCtsFlowControl = (1 << 6) |
| 92 |
} XsPortLinesOptions; |
| 93 |
|
| 94 |
struct XsPortInfo { |
| 95 |
#ifdef __cplusplus |
| 96 |
|
| 97 |
XsPortInfo() |
| 98 |
: m_deviceId(0) |
| 99 |
, m_baudrate(XBR_Invalid) |
| 100 |
, m_linesOptions(XPLO_All_Ignore) |
| 101 |
, m_vid(0) |
| 102 |
, m_pid(0) |
| 103 |
{ |
| 104 |
m_portName[0] = '\0'; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
explicit XsPortInfo(const XsString& portname, XsBaudRate baudRate = XBR_Invalid, XsPortLinesOptions linesOptions = XPLO_All_Ignore) |
| 113 |
: m_deviceId(0) |
| 114 |
, m_baudrate(baudRate) |
| 115 |
, m_linesOptions(linesOptions) |
| 116 |
, m_vid(0) |
| 117 |
, m_pid(0) |
| 118 |
{ |
| 119 |
if (portname.size() < 255) |
| 120 |
strcpy(m_portName, portname.c_str()); |
| 121 |
else |
| 122 |
m_portName[0] = '\0'; |
| 123 |
} |
| 124 |
|
| 125 |
#ifndef XSENS_NO_PORT_NUMBERS |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
explicit XsPortInfo(int portNr, XsBaudRate baudRate = XBR_Invalid, XsPortLinesOptions linesOptions = XPLO_All_Ignore) |
| 133 |
: m_deviceId(0) |
| 134 |
, m_baudrate(baudRate) |
| 135 |
, m_linesOptions(linesOptions) |
| 136 |
, m_vid(0) |
| 137 |
, m_pid(0) |
| 138 |
{ |
| 139 |
sprintf(m_portName, "COM%d", portNr); |
| 140 |
} |
| 141 |
#endif |
| 142 |
|
| 143 |
|
| 144 |
inline void clear() |
| 145 |
{ |
| 146 |
XsPortInfo_clear(this); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
inline bool empty() const |
| 151 |
{ |
| 152 |
return XsPortInfo_empty(this) != 0; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
inline bool operator > (const XsPortInfo& p) const { return strcmp(m_portName, p.m_portName) > 0; } |
| 157 |
|
| 158 |
|
| 159 |
inline bool operator < (const XsPortInfo& p) const { return strcmp(m_portName, p.m_portName) < 0; } |
| 160 |
|
| 161 |
|
| 162 |
inline bool operator == (const XsPortInfo& p) const { return strcmp(m_portName, p.m_portName) == 0; } |
| 163 |
|
| 164 |
|
| 165 |
inline bool operator == (const char *port) const { return strcmp(m_portName, port) == 0; } |
| 166 |
|
| 167 |
|
| 168 |
inline int portNumber() const |
| 169 |
{ |
| 170 |
return XsPortInfo_portNumber(this); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
inline XsString portName() const |
| 176 |
{ |
| 177 |
return XsString(m_portName); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
inline void setPortName(const XsString& portName_) |
| 183 |
{ |
| 184 |
strncpy(m_portName, portName_.c_str(), 256); |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
inline bool isUsb() const |
| 189 |
{ |
| 190 |
return XsPortInfo_isUsb(this) != 0; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
inline bool isNetwork() const |
| 195 |
{ |
| 196 |
return XsPortInfo_isNetwork(this) != 0; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
inline XsString networkServiceName() const |
| 201 |
{ |
| 202 |
return XsString(XsPortInfo_networkServiceName(this)); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
inline int usbBus() const |
| 207 |
{ |
| 208 |
return XsPortInfo_usbBus(this); |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
inline int usbAddress() const |
| 213 |
{ |
| 214 |
return XsPortInfo_usbAddress(this); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
inline XsBaudRate baudrate() const |
| 220 |
{ |
| 221 |
return m_baudrate; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
inline void setBaudrate(XsBaudRate baudrate_) |
| 227 |
{ |
| 228 |
m_baudrate = baudrate_; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
inline XsDeviceId deviceId() const |
| 234 |
{ |
| 235 |
return m_deviceId; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
inline void setDeviceId(XsDeviceId deviceId_) |
| 241 |
{ |
| 242 |
m_deviceId = deviceId_; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
inline XsPortLinesOptions linesOptions() const |
| 248 |
{ |
| 249 |
return m_linesOptions; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
inline void setLinesOptions(XsPortLinesOptions linesOptions) |
| 255 |
{ |
| 256 |
m_linesOptions = linesOptions; |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
inline void getVidPid(uint16_t& vid, uint16_t& pid) const |
| 262 |
{ |
| 263 |
vid = m_vid; |
| 264 |
pid = m_pid; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
inline void setVidPid(uint16_t vid, uint16_t pid) |
| 270 |
{ |
| 271 |
m_vid = vid; |
| 272 |
m_pid = pid; |
| 273 |
} |
| 274 |
|
| 275 |
private: |
| 276 |
#endif |
| 277 |
|
| 278 |
XsDeviceId m_deviceId; |
| 279 |
char m_portName[256]; |
| 280 |
XsBaudRate m_baudrate; |
| 281 |
XsPortLinesOptions m_linesOptions; |
| 282 |
uint16_t m_vid, m_pid; |
| 283 |
}; |
| 284 |
|
| 285 |
#if defined(_MSC_VER) |
| 286 |
#pragma warning(pop) |
| 287 |
#endif |
| 288 |
|
| 289 |
#if defined(__cplusplus) && !defined(XSENS_NO_STL) |
| 290 |
#include <ostream> |
| 291 |
namespace std |
| 292 |
{ |
| 293 |
template<typename _CharT, typename _Traits> |
| 294 |
basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& o, XsPortInfo const& xpi) |
| 295 |
{ |
| 296 |
if (xpi.isUsb()) |
| 297 |
o << "usb "; |
| 298 |
o << "port " << xpi.portName(); |
| 299 |
if (xpi.baudrate() != XBR_Invalid) |
| 300 |
o << " at " << xpi.baudrate() << " bps"; |
| 301 |
if (xpi.deviceId() != 0) |
| 302 |
o << " (" << xpi.deviceId() << ")"; |
| 303 |
return o; |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
#endif |
| 308 |
|
| 309 |
|
| 310 |
#endif |