Main MRPT website > C++ reference for MRPT 1.5.7
cmt2.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #ifndef _CMT2_H_2006_04_13
11 #define _CMT2_H_2006_04_13
12 
13 #ifndef _CMT_MONOLITHIC
14 # include "cmt1.h"
15 # include "cmtmessage.h"
16 # include "xsens_fifoqueue.h"
17 #endif
18 
19 namespace xsens {
20 
21 //////////////////////////////////////////////////////////////////////////////////////////
22 /////////////////////////////////// Support functions ///////////////////////////////////
23 //////////////////////////////////////////////////////////////////////////////////////////
24 
25 //! Find a valid message in the given buffer. If nothing is found, the function returns -1. Otherwise the index of the first character of the message is returned.
26 int32_t findValidMessage(const uint8_t* buffer, const uint16_t bufferLength);
27 
28 
29 //////////////////////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////// Cmt2s /////////////////////////////////////////
31 //////////////////////////////////////////////////////////////////////////////////////////
32 /*! \brief Mid-level serial communication class.
33 
34  The class uses CMT level 1, but does not inherit from it. If software needs to access
35  the level 1 component, it needs to be done through the getCmt1s() function.
36 */
37 class Cmt2s {
38 private:
39  //! This object cannot be copied, so this function is not implemented.
40  Cmt2s(const Cmt2s& ref);
41 
42  /*! \brief The message received function.
43 
44  This function is automatically called every time a complete message was read from the
45  connected COM port.
46  */
48  //! Custom, user supplied parameter for the OnMessageReceived callback function, passed as the first argument
50  //! Custom, user supplied parameter for the OnMessageReceived callback function, passed as the last argument
52 
53  /*! \brief The message sent function.
54 
55  This function is automatically called every time a complete message was sent to the
56  connected COM port.
57  */
59  //! Custom, user supplied parameter for the OnMessageSent callback function, passed as the first argument
61  //! Custom, user supplied parameter for the OnMessageSent callback function, passed as the last argument
63 
64 protected:
65  //! The baudrate that was last set to be used by the port
67  //! The CMT level 1 object that this class operates on
69  //! The last result of an operation
71  //! Buffer for reading data until a valid message is read. Should be rarely used.
73  //! The number of valid bytes in the readBuffer.
75  //! Timeout in ms for blocking operations
77  //! The timestamp at which to end an operation
79 public:
80  //! Default constructor, initialize all members to their default values.
81  Cmt2s();
82 
83  //! Destructor, de-initialize, free memory allocated for buffers, etc.
84  ~Cmt2s();
85 
86  //! Close the serial communication port.
87  XsensResultValue close(void);
88 
89  //! Return the baudrate that is currently being used by the port
91  /*! \brief Return a reference to the embedded Cmt1s object.
92 
93  Any manipulation of the object should be done through Cmt2s. Cmt2s integrity is
94  not guaranteed if the Cmt1s object is manipulated directly.
95  */
96  Cmt1s* getCmt1s(void) { return &m_cmt1s; }
97  //! Return the error code of the last operation.
99  //! Retrieve the port that the object is connected to.
100  XsensResultValue getPortNr(uint8_t& port) const;
101  XsensResultValue getPortNr(int32_t& port) const;
102  XsensResultValue getPortName(char *portname) const;
103  //! Return the current timeout value in ms.
104  uint32_t getTimeout(void) const { return m_timeout; }
105  //! Return whether the communication port is open or not.
106  bool isOpen (void) const { return (m_cmt1s.isOpen()); }
107  //! Open a communication channel to the given serial port name.
108  XsensResultValue open(const char *portName,
109  const uint32_t baudRate = CMT_DEFAULT_BAUD_RATE);
110 #ifdef _WIN32
111  //! Open a communication channel to the given COM port number.
112  XsensResultValue open(const uint32_t portNumber,
113  const uint32_t baudRate = CMT_DEFAULT_BAUD_RATE);
114 #endif
115  /*! \brief Read a message from the COM port.
116 
117  The function reads data from the embedded Cmt1s object. The data is then converted
118  into a Message object.
119  If an error occurred, a NULL pointer is returned and the error code can be
120  retrieved with getLastError().
121  */
123 
124  //! Set the callback function for when a message has been received or sent
126 
127  /*! \brief Set the default timeout value to use in blocking operations.
128 
129  This function sets the level 2 timeout value. The L1 value is set to half the given
130  timeout value.
131  */
133 
134  /*! \brief Wait for a message to arrive.
135 
136  The function waits for a message to arrive or until a timeout occurs.
137  If the msgId parameter is set to a value other than 0, the function will wait
138  until a message has arrived with that particular msgId.
139 
140  \note msgId 0 is the ReqDeviceID MID, but that is an outgoing only message. It is
141  illogical to wait for a message that will never be sent to the host. So 0 is a
142  safe value for the 'all' messages option.
143 
144  \note If an error message is received, the contents are stored in the m_lastResult
145  field and a NULL value is returned immediately.
146  */
147  XsensResultValue waitForMessage(Message* rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage);
148  /*! \brief Send a message over the COM port.
149 
150  The function attempts to write the message over the connected COM port.
151  \param msg The message to send.
152  */
154 };
155 
156 //////////////////////////////////////////////////////////////////////////////////////////
157 ///////////////////////////////////////// Cmt2f /////////////////////////////////////////
158 //////////////////////////////////////////////////////////////////////////////////////////
159 
160 /*! \brief The mid-level file communication class.
161 
162  The class uses CMT level 1, but does not inherit from it. If software needs to access
163  the level 1 component, it needs to be done through the getCmt1f() function.
164 */
165 class Cmt2f {
166 private:
167  //! This object cannot be copied, so this function is not implemented.
168  Cmt2f(const Cmt2f& ref);
169 
170 protected:
171  //! The Cmt1f object that is used for the low-level operations
173  //! The last result of an operation
175 
176  bool m_readOnly; //!< When set to true, the file is read-only and attempts to write to it will fail
177 
178 public:
179  //! Default constructor
180  Cmt2f();
181  //! Destructor.
182  ~Cmt2f();
183  //! Close the file.
184  XsensResultValue close(void);
185  //! Close the file and delete it.
187  //! Create a new file with level 2 header
188  XsensResultValue create(const char* filename);
189  //! Create a new file with level 2 header
190  XsensResultValue create(const wchar_t* filename);
191  //! Get a reference to the embedded Cmt1f object
192  Cmt1f* getCmt1f(void);
193 
194  //! Return the error code of the last operation.
195  XsensResultValue getLastResult(void) const;
196  //! Retrieve the filename that was last successfully opened.
197  XsensResultValue getName(char* filename) const;
198  //! Retrieve the filename that was last successfully opened.
199  XsensResultValue getName(wchar_t* filename) const;
200  //! Return whether the file is open or not.
201  bool isOpen(void) const;
202  //! Open a file and read the header
203  XsensResultValue open(const char* filename, const bool readOnly = false);
204  //! Open a file and read the header
205  XsensResultValue open(const wchar_t* filename, const bool readOnly = false);
206  //! Read the next message from the file, when msgId is non-zero, the first matching message will be returned
207  XsensResultValue readMessage(Message* msg, const uint8_t msgId = 0);
208  //! Get the current file size
209  CmtFilePos getFileSize(void);
210  //! Get the current read position
212  //! Set the read position to the given position
214  //! Write a message to the end of the file
216 };
217 
218 } // end of xsens namespace
219 
220 #endif // _CMT2_H_2006_04_13
__int64 CmtFilePos
Definition: cmtf.h:24
unsigned __int16 uint16_t
Definition: rptypes.h:46
Mid-level serial communication class.
Definition: cmt2.h:37
XsensResultValue open(const char *filename, const bool readOnly=false)
Open a file and read the header.
Definition: cmt2.cpp:708
CmtCallbackFunction m_onMessageReceived
The message received function.
Definition: cmt2.h:47
GLuint buffer
Definition: glext.h:3775
XsensResultValue getPortNr(uint8_t &port) const
Retrieve the port that the object is connected to.
Definition: cmt2.cpp:154
GLenum GLint ref
Definition: glext.h:3888
~Cmt2f()
Destructor.
Definition: cmt2.cpp:594
XsensResultValue setCallbackFunction(CmtCallbackSelector tp, int32_t instance, CmtCallbackFunction func, void *param)
Set the callback function for when a message has been received or sent.
Definition: cmt2.cpp:327
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: cmt2.h:98
#define CMT_DEFAULT_BAUD_RATE
The default baud rate of the Cmt1s serial communication.
Definition: cmtdef.h:798
CmtCallbackFunction m_onMessageSent
The message sent function.
Definition: cmt2.h:58
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
Definition: cmt2.cpp:687
uint32_t m_toEnd
The timestamp at which to end an operation.
Definition: cmt2.h:78
#define CMT2_DEFAULT_TIMEOUT
Timeout in ms for level 2.
Definition: cmtdef.h:807
Cmt1s m_cmt1s
The CMT level 1 object that this class operates on.
Definition: cmt2.h:68
XsensResultValue getPortName(char *portname) const
Definition: cmt2.cpp:143
unsigned char uint8_t
Definition: rptypes.h:43
int32_t m_onMessageReceivedInstance
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the first argu...
Definition: cmt2.h:49
The mid-level file communication class.
Definition: cmt2.h:165
void * m_onMessageSentParam
Custom, user supplied parameter for the OnMessageSent callback function, passed as the last argument...
Definition: cmt2.h:62
int32_t m_onMessageSentInstance
Custom, user supplied parameter for the OnMessageSent callback function, passed as the first argument...
Definition: cmt2.h:60
XsensResultValue close(void)
Close the file.
Definition: cmt2.cpp:601
XsensResultValue(__cdecl * CmtCallbackFunction)(int32_t, CmtCallbackSelector, void *, void *)
Definition: cmtdef.h:1091
Cmt1s * getCmt1s(void)
Return a reference to the embedded Cmt1s object.
Definition: cmt2.h:96
XsensResultValue
Xsens return values.
Definition: xsens_std.h:30
XsensResultValue closeAndDelete(void)
Close the file and delete it.
Definition: cmt2.cpp:615
CmtFilePos getReadPosition(void)
Get the current read position.
Definition: cmt2.cpp:815
Cmt2s()
Default constructor, initialize all members to their default values.
Definition: cmt2.cpp:111
XsensResultValue open(const char *portName, const uint32_t baudRate=CMT_DEFAULT_BAUD_RATE)
Open a communication channel to the given serial port name.
Definition: cmt2.cpp:174
XsensResultValue waitForMessage(Message *rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage)
Wait for a message to arrive.
Definition: cmt2.cpp:361
uint16_t m_readBufferCount
The number of valid bytes in the readBuffer.
Definition: cmt2.h:74
uint8_t m_readBuffer[CMT_DEFAULT_READ_BUFFER_SIZE]
Buffer for reading data until a valid message is read. Should be rarely used.
Definition: cmt2.h:72
void * m_onMessageReceivedParam
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the last argum...
Definition: cmt2.h:51
int32_t findValidMessage(const uint8_t *buffer, const uint16_t bufferLength)
Find a valid message in the given buffer. If nothing is found, the function returns -1...
Definition: cmt2.cpp:45
CmtFilePos getFileSize(void)
Get the current file size.
Definition: cmt2.cpp:808
XsensResultValue setReadPosition(CmtFilePos pos)
Set the read position to the given position.
Definition: cmt2.cpp:822
The low-level serial communication class.
Definition: cmt1.h:53
__int32 int32_t
Definition: rptypes.h:48
XsensResultValue close(void)
Close the serial communication port.
Definition: cmt2.cpp:129
Cmt1f * getCmt1f(void)
Get a reference to the embedded Cmt1f object.
Definition: cmt2.cpp:673
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: cmt2.cpp:680
XsensResultValue setTimeout(const uint32_t ms=CMT2_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
Definition: cmt2.cpp:349
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: cmt2.h:106
~Cmt2s()
Destructor, de-initialize, free memory allocated for buffers, etc.
Definition: cmt2.cpp:124
uint32_t getBaudrate(void)
Return the baudrate that is currently being used by the port.
Definition: cmt2.h:90
XsensResultValue writeMessage(Message *msg)
Send a message over the COM port.
Definition: cmt2.cpp:541
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt2.h:174
XsensResultValue create(const char *filename)
Create a new file with level 2 header.
Definition: cmt2.cpp:628
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: cmt1.h:133
The low-level file communication class.
Definition: cmt1.h:204
XsensResultValue readMessage(Message *msg, const uint8_t msgId=0)
Read the next message from the file, when msgId is non-zero, the first matching message will be retur...
Definition: cmt2.cpp:730
bool isOpen(void) const
Return whether the file is open or not.
Definition: cmt2.cpp:701
CmtCallbackSelector
Definition: cmtdef.h:1068
The namespace of all Xsens software since 2006.
Definition: cmt1.cpp:92
Cmt2f()
Default constructor.
Definition: cmt2.cpp:586
Cmt1f m_cmt1f
The Cmt1f object that is used for the low-level operations.
Definition: cmt2.h:172
uint32_t getTimeout(void) const
Return the current timeout value in ms.
Definition: cmt2.h:104
#define CMT_DEFAULT_READ_BUFFER_SIZE
The default size of the serial read buffer in bytes.
Definition: cmtdef.h:794
XsensResultValue writeMessage(const Message *msg)
Write a message to the end of the file.
Definition: cmt2.cpp:829
unsigned __int32 uint32_t
Definition: rptypes.h:49
GLfloat param
Definition: glext.h:3705
uint32_t m_baudrate
The baudrate that was last set to be used by the port.
Definition: cmt2.h:66
uint32_t m_timeout
Timeout in ms for blocking operations.
Definition: cmt2.h:76
bool m_readOnly
When set to true, the file is read-only and attempts to write to it will fail.
Definition: cmt2.h:176
Class for storing a single message.
Definition: cmtmessage.h:76
XsensResultValue readMessage(Message *rcv)
Read a message from the COM port.
Definition: cmt2.cpp:200
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt2.h:70
uint32_t getBaudrate(void) const
Return the baudrate that is currently being used by the port.
Definition: cmt1.h:121



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019