MRPT  1.9.9
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-2018, 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 
26 //! Find a valid message in the given buffer. If nothing is found, the function
27 //! returns -1. Otherwise the index of the first character of the message is
28 //! returned.
29 int32_t findValidMessage(const uint8_t* buffer, const uint16_t bufferLength);
30 
31 //////////////////////////////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////// Cmt2s
33 ////////////////////////////////////////////
34 //////////////////////////////////////////////////////////////////////////////////////////
35 /*! \brief Mid-level serial communication class.
36 
37  The class uses CMT level 1, but does not inherit from it. If software needs
38  to access
39  the level 1 component, it needs to be done through the getCmt1s() function.
40 */
41 class Cmt2s
42 {
43  private:
44  //! This object cannot be copied, so this function is not implemented.
45  Cmt2s(const Cmt2s& ref);
46 
47  /*! \brief The message received function.
48 
49  This function is automatically called every time a complete message was
50  read from the
51  connected COM port.
52  */
54  //! Custom, user supplied parameter for the OnMessageReceived callback
55  //! function, passed as the first argument
57  //! Custom, user supplied parameter for the OnMessageReceived callback
58  //! function, passed as the last argument
60 
61  /*! \brief The message sent function.
62 
63  This function is automatically called every time a complete message was
64  sent to the
65  connected COM port.
66  */
68  //! Custom, user supplied parameter for the OnMessageSent callback function,
69  //! passed as the first argument
71  //! Custom, user supplied parameter for the OnMessageSent callback function,
72  //! passed as the last argument
74 
75  protected:
76  //! The baudrate that was last set to be used by the port
78  //! The CMT level 1 object that this class operates on
80  //! The last result of an operation
82  //! Buffer for reading data until a valid message is read. Should be rarely
83  //! used.
85  //! The number of valid bytes in the readBuffer.
87  //! Timeout in ms for blocking operations
89  //! The timestamp at which to end an operation
91 
92  public:
93  //! Default constructor, initialize all members to their default values.
94  Cmt2s();
95 
96  //! Destructor, de-initialize, free memory allocated for buffers, etc.
97  ~Cmt2s();
98 
99  //! Close the serial communication port.
100  XsensResultValue close(void);
101 
102  //! Return the baudrate that is currently being used by the port
104  /*! \brief Return a reference to the embedded Cmt1s object.
105 
106  Any manipulation of the object should be done through Cmt2s. Cmt2s
107  integrity is
108  not guaranteed if the Cmt1s object is manipulated directly.
109  */
110  Cmt1s* getCmt1s(void) { return &m_cmt1s; }
111  //! Return the error code of the last operation.
113  //! Retrieve the port that the object is connected to.
114  XsensResultValue getPortNr(uint8_t& port) const;
115  XsensResultValue getPortNr(int32_t& port) const;
116  XsensResultValue getPortName(char* portname) const;
117  //! Return the current timeout value in ms.
118  uint32_t getTimeout(void) const { return m_timeout; }
119  //! Return whether the communication port is open or not.
120  bool isOpen(void) const { return (m_cmt1s.isOpen()); }
121  //! Open a communication channel to the given serial port name.
123  const char* portName, const uint32_t baudRate = CMT_DEFAULT_BAUD_RATE);
124 #ifdef _WIN32
125  //! Open a communication channel to the given COM port number.
127  const uint32_t portNumber,
128  const uint32_t baudRate = CMT_DEFAULT_BAUD_RATE);
129 #endif
130  /*! \brief Read a message from the COM port.
131 
132  The function reads data from the embedded Cmt1s object. The data is then
133  converted
134  into a Message object.
135  If an error occurred, a nullptr pointer is returned and the error code
136  can be
137  retrieved with getLastError().
138  */
140 
141  //! Set the callback function for when a message has been received or sent
144  void* param);
145 
146  /*! \brief Set the default timeout value to use in blocking operations.
147 
148  This function sets the level 2 timeout value. The L1 value is set to
149  half the given
150  timeout value.
151  */
153 
154  /*! \brief Wait for a message to arrive.
155 
156  The function waits for a message to arrive or until a timeout occurs.
157  If the msgId parameter is set to a value other than 0, the function will
158  wait
159  until a message has arrived with that particular msgId.
160 
161  \note msgId 0 is the ReqDeviceID MID, but that is an outgoing only
162  message. It is
163  illogical to wait for a message that will never be sent to the host. So
164  0 is a
165  safe value for the 'all' messages option.
166 
167  \note If an error message is received, the contents are stored in the
168  m_lastResult
169  field and a nullptr value is returned immediately.
170  */
172  Message* rcv, const uint8_t msgId, uint32_t timeoutOverride,
173  bool acceptErrorMessage);
174  /*! \brief Send a message over the COM port.
175 
176  The function attempts to write the message over the connected COM port.
177  \param msg The message to send.
178  */
180 };
181 
182 //////////////////////////////////////////////////////////////////////////////////////////
183 ///////////////////////////////////////// Cmt2f
184 ////////////////////////////////////////////
185 //////////////////////////////////////////////////////////////////////////////////////////
186 
187 /*! \brief The mid-level file communication class.
188 
189  The class uses CMT level 1, but does not inherit from it. If software needs
190  to access
191  the level 1 component, it needs to be done through the getCmt1f() function.
192 */
193 class Cmt2f
194 {
195  private:
196  //! This object cannot be copied, so this function is not implemented.
197  Cmt2f(const Cmt2f& ref);
198 
199  protected:
200  //! The Cmt1f object that is used for the low-level operations
202  //! The last result of an operation
204 
205  /** When set to true, the file is read-only and attempts to write to it will
206  * fail */
208 
209  public:
210  //! Default constructor
211  Cmt2f();
212  //! Destructor.
213  ~Cmt2f();
214  //! Close the file.
215  XsensResultValue close(void);
216  //! Close the file and delete it.
218  //! Create a new file with level 2 header
219  XsensResultValue create(const char* filename);
220  //! Create a new file with level 2 header
221  XsensResultValue create(const wchar_t* filename);
222  //! Get a reference to the embedded Cmt1f object
223  Cmt1f* getCmt1f(void);
224 
225  //! Return the error code of the last operation.
226  XsensResultValue getLastResult(void) const;
227  //! Retrieve the filename that was last successfully opened.
228  XsensResultValue getName(char* filename) const;
229  //! Retrieve the filename that was last successfully opened.
230  XsensResultValue getName(wchar_t* filename) const;
231  //! Return whether the file is open or not.
232  bool isOpen(void) const;
233  //! Open a file and read the header
234  XsensResultValue open(const char* filename, const bool readOnly = false);
235  //! Open a file and read the header
236  XsensResultValue open(const wchar_t* filename, const bool readOnly = false);
237  //! Read the next message from the file, when msgId is non-zero, the first
238  //! matching message will be returned
239  XsensResultValue readMessage(Message* msg, const uint8_t msgId = 0);
240  //! Get the current file size
241  CmtFilePos getFileSize(void);
242  //! Get the current read position
244  //! Set the read position to the given position
246  //! Write a message to the end of the file
248 };
249 
250 } // end of xsens namespace
251 
252 #endif // _CMT2_H_2006_04_13
__int64 CmtFilePos
Definition: cmtf.h:25
unsigned __int16 uint16_t
Definition: rptypes.h:44
Mid-level serial communication class.
Definition: cmt2.h:41
XsensResultValue open(const char *filename, const bool readOnly=false)
Open a file and read the header.
Definition: cmt2.cpp:752
CmtCallbackFunction m_onMessageReceived
The message received function.
Definition: cmt2.h:53
GLuint buffer
Definition: glext.h:3917
XsensResultValue getPortNr(uint8_t &port) const
Retrieve the port that the object is connected to.
Definition: cmt2.cpp:144
GLenum GLint ref
Definition: glext.h:4050
~Cmt2f()
Destructor.
Definition: cmt2.cpp:664
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:346
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: cmt2.h:112
#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:67
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
Definition: cmt2.cpp:735
uint32_t m_toEnd
The timestamp at which to end an operation.
Definition: cmt2.h:90
#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:79
XsensResultValue getPortName(char *portname) const
Definition: cmt2.cpp:134
unsigned char uint8_t
Definition: rptypes.h:41
int32_t m_onMessageReceivedInstance
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the first argu...
Definition: cmt2.h:56
The mid-level file communication class.
Definition: cmt2.h:193
void * m_onMessageSentParam
Custom, user supplied parameter for the OnMessageSent callback function, passed as the last argument...
Definition: cmt2.h:73
int32_t m_onMessageSentInstance
Custom, user supplied parameter for the OnMessageSent callback function, passed as the first argument...
Definition: cmt2.h:70
XsensResultValue close(void)
Close the file.
Definition: cmt2.cpp:667
Cmt1s * getCmt1s(void)
Return a reference to the embedded Cmt1s object.
Definition: cmt2.h:110
XsensResultValue
Xsens return values.
Definition: xsens_std.h:31
XsensResultValue closeAndDelete(void)
Close the file and delete it.
Definition: cmt2.cpp:680
XsensResultValue(__cdecl * CmtCallbackFunction)(int32_t, CmtCallbackSelector, void *, void *)
Definition: cmtdef.h:1160
CmtFilePos getReadPosition(void)
Get the current read position.
Definition: cmt2.cpp:858
Cmt2s()
Default constructor, initialize all members to their default values.
Definition: cmt2.cpp:108
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:162
XsensResultValue waitForMessage(Message *rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage)
Wait for a message to arrive.
Definition: cmt2.cpp:382
uint16_t m_readBufferCount
The number of valid bytes in the readBuffer.
Definition: cmt2.h:86
uint8_t m_readBuffer[CMT_DEFAULT_READ_BUFFER_SIZE]
Buffer for reading data until a valid message is read.
Definition: cmt2.h:84
void * m_onMessageReceivedParam
Custom, user supplied parameter for the OnMessageReceived callback function, passed as the last argum...
Definition: cmt2.h:59
int32_t findValidMessage(const uint8_t *buffer, const uint16_t bufferLength)
Find a valid message in the given buffer.
Definition: cmt2.cpp:45
CmtFilePos getFileSize(void)
Get the current file size.
Definition: cmt2.cpp:855
XsensResultValue setReadPosition(CmtFilePos pos)
Set the read position to the given position.
Definition: cmt2.cpp:861
The low-level serial communication class.
Definition: cmt1.h:57
__int32 int32_t
Definition: rptypes.h:46
XsensResultValue close(void)
Close the serial communication port.
Definition: cmt2.cpp:120
Cmt1f * getCmt1f(void)
Get a reference to the embedded Cmt1f object.
Definition: cmt2.cpp:729
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: cmt2.cpp:732
XsensResultValue setTimeout(const uint32_t ms=CMT2_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
Definition: cmt2.cpp:370
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: cmt2.h:120
~Cmt2s()
Destructor, de-initialize, free memory allocated for buffers, etc.
Definition: cmt2.cpp:119
uint32_t getBaudrate(void)
Return the baudrate that is currently being used by the port.
Definition: cmt2.h:103
XsensResultValue writeMessage(Message *msg)
Send a message over the COM port.
Definition: cmt2.cpp:599
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt2.h:203
XsensResultValue create(const char *filename)
Create a new file with level 2 header.
Definition: cmt2.cpp:692
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: cmt1.h:154
The low-level file communication class.
Definition: cmt1.h:240
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:772
bool isOpen(void) const
Return whether the file is open or not.
Definition: cmt2.cpp:749
CmtCallbackSelector
Definition: cmtdef.h:1120
The namespace of all Xsens software since 2006.
Definition: cmt1.cpp:95
Cmt2f()
Default constructor.
Definition: cmt2.cpp:656
Cmt1f m_cmt1f
The Cmt1f object that is used for the low-level operations.
Definition: cmt2.h:201
uint32_t getTimeout(void) const
Return the current timeout value in ms.
Definition: cmt2.h:118
#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:868
unsigned __int32 uint32_t
Definition: rptypes.h:47
GLfloat param
Definition: glext.h:3831
uint32_t m_baudrate
The baudrate that was last set to be used by the port.
Definition: cmt2.h:77
uint32_t m_timeout
Timeout in ms for blocking operations.
Definition: cmt2.h:88
bool m_readOnly
When set to true, the file is read-only and attempts to write to it will fail.
Definition: cmt2.h:207
Class for storing a single message.
Definition: cmtmessage.h:83
XsensResultValue readMessage(Message *rcv)
Read a message from the COM port.
Definition: cmt2.cpp:192
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt2.h:81
uint32_t getBaudrate(void) const
Return the baudrate that is currently being used by the port.
Definition: cmt1.h:139



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020