MRPT  1.9.9
xsportinfo.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef XSPORTINFO_H
10 #define XSPORTINFO_H
11 
12 #include <stdio.h>
13 #include "pstdint.h"
14 #include "xsbaud.h"
15 #include "xsdeviceid.h"
16 #include "xsstring.h"
17 #include "xstypesconfig.h"
18 
19 #ifdef __cplusplus
20 extern "C"
21 {
22 #endif
23 
24 #ifndef __cplusplus
25  typedef struct XsPortInfo XsPortInfo;
26 #else
27 struct XsPortInfo;
28 #endif
29 
31  XSTYPES_DLL_API int XsPortInfo_empty(XsPortInfo const* thisPtr);
33  XSTYPES_DLL_API int XsPortInfo_isUsb(XsPortInfo const* thisPtr);
34  XSTYPES_DLL_API int XsPortInfo_usbBus(XsPortInfo const* thisPtr);
37 
38 #ifdef __cplusplus
39 }
40 #endif
41 
42 #if defined(_MSC_VER)
43 #pragma warning(push)
44 #pragma warning(disable : 4996)
45 #endif
46 
47 struct XsPortInfo
48 {
49 #ifdef __cplusplus
50  /*! \brief Default constructor, creates an empty port info object */
52  {
53  m_portName[0] = '\0';
54  }
55 
56  /*! \brief Named constructor, initializes the object to the supplied \a
57  portname and optional \a baudRate
58  \param portname The name of the port, maximum 255 characters
59  \param baudRate The baud rate to configure for the port, for scanning
60  XBR_Invalid may be used to scan all known baud rates
61  */
62  explicit XsPortInfo(
63  const XsString& portname, XsBaudRate baudRate = XBR_Invalid)
64  : m_deviceId(0), m_baudrate(baudRate)
65  {
66  if (portname.size() < 255)
67  strcpy(m_portName, portname.c_str());
68  else
69  m_portName[0] = '\0';
70  }
71 
72 #ifndef XSENS_NO_PORT_NUMBERS
73  /*! \brief Port number constructor, initializes the port to have
74  COM<portNumber> as its name and the optional \a baudRate for a baud rate
75  \param portNr The number of the COM port
76  \param baudRate The baud rate to configure for the port, for scanning
77  XBR_Invalid may be used to scan all known baud rates
78  \note Numbered COM ports are only available on Windows platforms.
79  */
80  explicit XsPortInfo(int portNr, XsBaudRate baudRate = XBR_Invalid)
81  : m_deviceId(0), m_baudrate(baudRate)
82  {
83  sprintf(m_portName, "COM%d", portNr);
84  }
85 #endif
86 
87  /*! \brief \copybrief XsPortInfo_clear */
88  inline void clear() { XsPortInfo_clear(this); }
89  /*! \brief \copybrief XsPortInfo_empty */
90  inline bool empty() const { return XsPortInfo_empty(this) != 0; }
91  /*! \brief greater than operator, used for sorting the list. */
92  inline bool operator>(const XsPortInfo& p) const
93  {
94  return strcmp(m_portName, p.m_portName) > 0;
95  }
96 
97  /*! \brief less than operator, used for sorting the list. */
98  inline bool operator<(const XsPortInfo& p) const
99  {
100  return strcmp(m_portName, p.m_portName) < 0;
101  }
102 
103  /*! \brief equality operator, used for finding items in a list. */
104  inline bool operator==(const XsPortInfo& p) const
105  {
106  return strcmp(m_portName, p.m_portName) == 0;
107  }
108 
109  /*! \brief equality operator, used for finding items in a list. */
110  inline bool operator==(const char* port) const
111  {
112  return strcmp(m_portName, port) == 0;
113  }
114 
115  /*! \copydoc XsPortInfo_portNumber */
116  inline int portNumber() const { return XsPortInfo_portNumber(this); }
117  /*! \brief The port name
118  */
119  inline XsString portName() const { return XsString(m_portName); }
120  /*! \brief Set the port name
121  */
122  inline void setPortName(const XsString& portName_)
123  {
124  strncpy(m_portName, portName_.c_str(), 256);
125  }
126 
127  /*! \brief \copybrief XsPortInfo_isUsb */
128  inline bool isUsb() const { return XsPortInfo_isUsb(this) != 0; }
129  /*! \copydoc XsPortInfo_usbBus */
130  inline int usbBus() const { return XsPortInfo_usbBus(this); }
131  /*! \copydoc XsPortInfo_usbAddress */
132  inline int usbAddress() const { return XsPortInfo_usbAddress(this); }
133  /*! \brief The baudrate
134  */
135  inline XsBaudRate baudrate() const { return m_baudrate; }
136  /*! \brief Set the baudrate
137  */
138  inline void setBaudrate(XsBaudRate baudrate_) { m_baudrate = baudrate_; }
139  /*! \brief The device ID
140  */
141  inline XsDeviceId deviceId() const { return m_deviceId; }
142  /*! \brief Set the device ID
143  */
144  inline void setDeviceId(XsDeviceId deviceId_) { m_deviceId = deviceId_; }
145 
146  private:
147 #endif
148 
149  /** The device Id of main Xsens device detected on the port */
151  /** The port name */
152  char m_portName[256];
153  /** The baudrate at which an Xsens device was detected, may be XBR_Invalid
154  * for pure USB ports */
156 };
157 
158 #if defined(_MSC_VER)
159 #pragma warning(pop)
160 #endif
161 
162 #endif // file guard
XSTYPES_DLL_API int XsPortInfo_usbAddress(XsPortInfo const *thisPtr)
XSTYPES_DLL_API int XsPortInfo_empty(XsPortInfo const *thisPtr)
char m_portName[256]
The port name.
Definition: xsportinfo.h:152
XSTYPES_DLL_API void XsPortInfo_clear(XsPortInfo *thisPtr)
XSTYPES_DLL_API void XsPortInfo_swap(XsPortInfo *a, struct XsPortInfo *b)
XsBaudRate m_baudrate
The baudrate at which an Xsens device was detected, may be XBR_Invalid for pure USB ports...
Definition: xsportinfo.h:155
Not a valid baud rate.
Definition: xsbaudrate.h:30
XSTYPES_DLL_API int XsPortInfo_isUsb(XsPortInfo const *thisPtr)
GLubyte GLubyte b
Definition: glext.h:6372
bool empty() const
Definition: ts_hash_map.h:190
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
Definition: TCamera.cpp:202
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:9
XsDeviceId m_deviceId
The device Id of main Xsens device detected on the port.
Definition: xsportinfo.h:150
struct XsPortInfo XsPortInfo
Definition: xsportinfo.h:25
XSTYPES_DLL_API int XsPortInfo_portNumber(XsPortInfo const *thisPtr)
struct XsString XsString
Definition: xsstring.h:35
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
Definition: os.cpp:299
bool operator<(const COccupancyGridMap2D::TPairLikelihoodIndex &e1, const COccupancyGridMap2D::TPairLikelihoodIndex &e2)
XsBaudRate
Communication speed.
Definition: xsbaudrate.h:27
#define deviceId
Definition: CIMUXSens.cpp:40
GLubyte GLubyte GLubyte a
Definition: glext.h:6372
GLfloat GLfloat p
Definition: glext.h:6398
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:182
XSTYPES_DLL_API int XsPortInfo_usbBus(XsPortInfo const *thisPtr)
int sprintf(char *buf, size_t bufSize, const char *format,...) noexcept MRPT_printf_format_check(3
An OS-independent version of sprintf (Notice the bufSize param, which may be ignored in some compiler...
Definition: os.cpp:191



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019