Main MRPT website > C++ reference for MRPT 1.5.9
cmt1.cpp
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 /*! \file Cmt1.cpp
11 
12  For information about objects in this file, see the appropriate header:
13  \ref Cmt1.h
14 
15  \section FileCopyright Copyright Notice
16  Copyright (C) Xsens Technologies B.V., 2006. All rights reserved.
17 
18  This source code is intended for use only by Xsens Technologies BV and
19  those that have explicit written permission to use it from
20  Xsens Technologies BV.
21 
22  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
23  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
25  PARTICULAR PURPOSE.
26 
27  \section FileChangelog Changelog
28  \par 2006-04-12, v0.0.1
29  \li Job Mulder: Created
30  \par 2006-07-21, v0.1.0
31  \li Job Mulder: Updated file for release 0.1.0
32 */
33 
34 #include "cmt1.h"
35 #include <errno.h>
36 
37 #include <mrpt/config.h> // For HAVE_MALLOC_H
38 
39 #ifndef _WIN32
40 # include <unistd.h> // close
41 # include <sys/ioctl.h> // ioctl
42 # include <fcntl.h> // open, O_RDWR
43 # include <string.h> // strcpy
44 
45 /* Jerome Monceaux : bilock@gmail.com
46  * Add a specific case for apple
47  */
48 #ifdef HAVE_MALLOC_H
49 # include <malloc.h>
50 #elif defined(HAVE_MALLOC_MALLOC_H)
51 # include <malloc/malloc.h>
52 #endif
53 
54 # include <stdarg.h> // va_start, etc...
55 # include <sys/param.h>
56 // We have to redefine PATH_MAX from 4096 to CMT_MAX_FILENAME_LENGTH to mainain compatibility
57 // The PATH_MAX definition is used by realpath() to determine the maximum path length. According
58 // to the realpath (3) man page, the function is best avoided and it might be necessary to
59 // write a custom function for it (couldn't find a proper replacement).
60 # undef PATH_MAX
61 # define PATH_MAX CMT_MAX_FILENAME_LENGTH
62 # include <stdlib.h>
63 #else
64 # include <stdio.h> // fseek
65 # include <io.h>
66 #endif
67 
68 #ifndef _CRT_SECURE_NO_DEPRECATE
69 # define _CRT_SECURE_NO_DEPRECATE
70 # ifdef _WIN32
71 # pragma warning(disable:4996)
72 # endif
73 #endif
74 
75 #ifdef _WIN32
76 # ifdef _MSC_VER
77 # define FSEEK(x) _fseeki64(m_handle, x, SEEK_SET)
78 # define FSEEK_R(x) _fseeki64(m_handle, x, SEEK_END)
79 # define FTELL() _ftelli64(m_handle)
80 # else
81 # define FSEEK(x) fseek(m_handle, x, SEEK_SET)
82 # define FSEEK_R(x) fseek(m_handle, x, SEEK_END)
83 # define FTELL() ftell(m_handle)
84 # endif
85 #else
86 # define FSEEK(x) fseeko(m_handle, x, SEEK_SET)
87 # define FSEEK_R(x) fseeko(m_handle, x, SEEK_END)
88 # define FTELL() ftello(m_handle)
89 #endif
90 
91 // The namespace of all Xsens software since 2006.
92 namespace xsens {
93 
94 #ifndef _WIN32
95 int _wcsnicmp(const wchar_t* s1, const wchar_t* s2,int count)
96 {
97  for (int i = 0; i < count; ++i, ++s1, ++s2)
98  if (*s1 == L'\0')
99  if (*s2 == L'\0')
100  return 0;
101  else
102  return -1;
103  else
104  if (*s2 == L'\0')
105  return 1;
106  else
107  if (*s1 < *s2)
108  return -1;
109  else if (*s1 > *s2)
110  return 1;
111  return 0;
112 }
113 #endif
114 
115 
116 #if defined(_DEBUG) || defined(_LOG_ALWAYS)
117  #if !defined(_LOG_TO_DBVIEW)
118  #ifdef _LOG_TO_STDOUT
119  #else // !dbview && !stdout
120  FILE* debug_log_fp = NULL;
121  int32_t debug_log_valid = 0;
122 
123  FILE* debug_qlog_fp = NULL;
124  int32_t debug_qlog_valid = 0;
125  #endif
126  #endif
127 
128 // write to a log file/screen/debug-stream
129 void CMTLOG(const char *str, ...)
130 {
131  #ifdef _LOG_TO_STDOUT
132  va_list ptr;
133  va_start(ptr,str);
134  vprintf(str,ptr);
135  #else
136  #ifdef _LOG_TO_DBVIEW
137  char buf[2048];
138 
139  va_list ptr;
140  va_start(ptr,str);
141  vsprintf(buf,str,ptr);
142 
143  OutputDebugString(buf);
144  #else
145  if (debug_log_valid == 0)
146  {
147  debug_log_fp = fopen("debug_log_cmt.log","w");
148  if (debug_log_fp != NULL)
149  debug_log_valid = 1;
150  else
151  debug_log_valid = -1;
152  }
153  if (debug_log_valid == 1)
154  {
155  char buf[2048];
156 
157  va_list ptr;
158  va_start(ptr,str);
159  int32_t sz = vsprintf_s(buf,str,ptr);
160 
161  uint32_t nw = getTimeOfDay();
162  fprintf(debug_log_fp,"%5u.%03u %s",nw/1000,nw%1000,buf);
163  //fwrite(buf,1,sz,debug_log_fp);
164  fflush(debug_log_fp);
165  }
166  #endif
167  #endif
168 }
169 #endif
170 
171 // maybe log to nothing at this level
172 #ifdef _LOG_CMT1
173  #define CMT1LOG CMTLOG
174 #else
175  #define CMT1LOG(...)
176 #endif
177 
178 //////////////////////////////////////////////////////////////////////////////////////////
179 ///////////////////////////////////////// Cmt1s /////////////////////////////////////////
180 //////////////////////////////////////////////////////////////////////////////////////////
181 
182 //////////////////////////////////////////////////////////////////////////////////////////
183 // Default constructor, initializes all members to their default values.
185  m_onBytesReceived(NULL)
186 {
187  m_port = 0;
188  m_isOpen = false;
191  m_endTime = 0;
192  m_baudrate = 0;
193 
194  #ifdef _LOG_RX_TX
195  rx_log = NULL;
196  tx_log = NULL;
197  #endif
198 }
199 
200 //////////////////////////////////////////////////////////////////////////////////////////
201 // Destructor, de-initializes, frees memory allocated for buffers, etc.
203 {
204  close();
205 }
206 
207 //////////////////////////////////////////////////////////////////////////////////////////
208 // Close the serial communication port.
210 {
211  #ifdef _LOG_RX_TX
212  if (rx_log != NULL)
213  fclose(rx_log);
214  if (tx_log != NULL)
215  fclose(tx_log);
216  rx_log = NULL;
217  tx_log = NULL;
218  #endif
219  if (!m_isOpen)
220  return m_lastResult = XRV_NOPORTOPEN;
221 
222  #ifdef _WIN32
223  ::FlushFileBuffers(m_handle);
224  // read all data before closing the handle, a Flush is not enough for FTDI devices unfortunately
225  // we first need to set the COMM timeouts to instantly return when no more data is available
226  COMMTIMEOUTS cto;
227  ::GetCommTimeouts(m_handle,&cto);
228  cto.ReadIntervalTimeout = MAXDWORD;
229  cto.ReadTotalTimeoutConstant = 0;
230  cto.ReadTotalTimeoutMultiplier = 0;
231  ::SetCommTimeouts(m_handle,&cto);
232  char buffer[1024];
233  DWORD length;
234  do {
235  ::ReadFile(m_handle, buffer, 1024, &length, NULL);
236  } while (length > 0);
237  ::CloseHandle(m_handle);
238  #else
239  ::close(m_handle);
240  #endif
241  m_isOpen = false;
242  m_endTime = 0;
243 
244  return m_lastResult = XRV_OK;
245 }
246 
247 //////////////////////////////////////////////////////////////////////////////////////////
248 // Manipulate the Serial control lines
250 {
251  if (!m_isOpen)
252  return (m_lastResult = XRV_NOPORTOPEN);
253 #ifdef _WIN32
254  BOOL rv = 0;
255  if (mask & CMT_CONTROL_DTR)
256  {
257  if (state & CMT_CONTROL_DTR)
258  rv = EscapeCommFunction(m_handle,SETDTR);
259  else
260  rv = EscapeCommFunction(m_handle,CLRDTR);
261  }
262 
263  if (mask & CMT_CONTROL_RTS)
264  {
265  if (state & CMT_CONTROL_RTS)
266  rv = EscapeCommFunction(m_handle,SETRTS);
267  else
268  rv = EscapeCommFunction(m_handle,CLRRTS);
269  }
270  if (rv)
271  return m_lastResult = XRV_OK;
272  else
273  return m_lastResult = XRV_ERROR;
274 #else
275  bool rv = true;
276  int32_t status;
277  if (mask & CMT_CONTROL_DTR)
278  {
279  if (ioctl(m_handle, TIOCMGET, &status) == -1)
280  {
281  if (state & CMT_CONTROL_DTR) status |= TIOCM_DTR;
282  else status &= ~TIOCM_DTR;
283  rv = (ioctl(m_handle, TIOCMSET, &status) == -1);
284  }
285  else
286  rv = false;
287  }
288  if (rv && (mask & CMT_CONTROL_RTS))
289  {
290  if (ioctl(m_handle, TIOCMGET, &status) == -1)
291  {
292  if (state & CMT_CONTROL_RTS) status |= TIOCM_RTS;
293  else status &= ~TIOCM_RTS;
294  rv = (ioctl(m_handle, TIOCMSET, &status) == -1);
295  }
296  else
297  rv = false;
298  }
299  if (rv)
300  return m_lastResult = XRV_OK;
301  else
302  return m_lastResult = XRV_ERROR;
303 #endif
304 }
305 
306 //////////////////////////////////////////////////////////////////////////////////////////
307 // Flush all data to be transmitted / received.
309 {
310  #ifdef _WIN32
311  // Remove any 'old' data in buffer
312  PurgeComm(m_handle, PURGE_TXCLEAR | PURGE_RXCLEAR);
313  #else
314  tcflush(m_handle, TCIOFLUSH);
315  #endif
316  m_endTime = 0;
317  return (m_lastResult = XRV_OK);
318 }
319 
320 //////////////////////////////////////////////////////////////////////////////////////////
321 // Open a communication channel to the given serial port name.
322 XsensResultValue Cmt1s::open( const char *portName,
323  const uint32_t baudRate,
324  uint32_t readBufSize,
325  uint32_t writeBufSize)
326 {
327  MRPT_UNUSED_PARAM(readBufSize); MRPT_UNUSED_PARAM(writeBufSize);
328  m_endTime = 0;
329 
330  CMT1LOG("L1: Open port %s at %d baud\n", portName, baudRate);
331 
332  if (m_isOpen)
333  {
334  CMT1LOG("L1: Port already open\n");
335  return (m_lastResult = XRV_ALREADYOPEN);
336  }
337  m_baudrate = baudRate;
338 
339 #ifdef _WIN32
340  char winPortName[32];
341 
342  // Open port
343  sprintf(winPortName, "\\\\.\\%s", portName);
344  m_handle = CreateFileA(winPortName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
345  OPEN_EXISTING, 0, NULL);
346  if (m_handle == INVALID_HANDLE_VALUE)
347  {
348  CMT1LOG("L1: Port cannot be opened\n");
350  }
351 
352  // Once here, port is open
353  m_isOpen = true;
354 
355  //Get the current state & then change it
356  GetCommState(m_handle, &m_commState); // Get current state
357 
358  m_commState.BaudRate = baudRate; // Setup the baud rate
359  m_commState.Parity = NOPARITY; // Setup the Parity
360  m_commState.ByteSize = 8; // Setup the data bits
361  m_commState.StopBits = TWOSTOPBITS; // Setup the stop bits
362  m_commState.fDsrSensitivity = FALSE; // Setup the flow control
363  m_commState.fOutxCtsFlow = FALSE; // NoFlowControl:
364  m_commState.fOutxDsrFlow = FALSE;
365  m_commState.fOutX = FALSE;
366  m_commState.fInX = FALSE;
367  if (!SetCommState(m_handle, (LPDCB)&m_commState)) {// Set new state
368  // Bluetooth ports cannot always be opened with 2 stopbits
369  // Now try to open port with 1 stopbit.
370  m_commState.StopBits = ONESTOPBIT;
371  if (!SetCommState(m_handle, (LPDCB)&m_commState)) {
372  CloseHandle(m_handle);
373  m_handle = INVALID_HANDLE_VALUE;
374  m_isOpen = false;
376  }
377  }
378  m_port = atoi(&portName[3]);
379  sprintf(m_portname, "%s", portName);
380 
382 
383  // Other initialization functions
384  EscapeCommFunction(m_handle, SETRTS); // Enable RTS (for Xbus Master use)
385  // Set DTR (Calibration sensors need DTR to startup, won't hurt otherwise
386  EscapeCommFunction(m_handle, SETDTR);
387  SetupComm(m_handle,readBufSize,writeBufSize); // Set queue size
388 
389  // Remove any 'old' data in buffer
390  //PurgeComm(m_handle, PURGE_TXCLEAR | PURGE_RXCLEAR);
391  PurgeComm(m_handle, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
392 #else // !_WIN32
393  // Open port
394  m_handle = ::open(portName, O_RDWR | O_NOCTTY);
395  // O_RDWR: Read+Write
396  // O_NOCTTY: Raw input, no "controlling terminal"
397  // O_NDELAY: Don't care about DCD signal
398 
399  if (m_handle < 0) {
400  // Port not open
402  }
403 
404  // Once here, port is open
405  m_isOpen = true;
406 
407  /* Start configuring of port for non-canonical transfer mode */
408  // Get current options for the port
409  tcgetattr(m_handle, &m_commState);
410 
411  // Set baudrate.
412  cfsetispeed(&m_commState, baudRate);
413  cfsetospeed(&m_commState, baudRate);
414 
415  // Enable the receiver and set local mode
416  m_commState.c_cflag |= (CLOCAL | CREAD);
417  // Set character size to data bits and set no parity Mask the characte size bits
418  m_commState.c_cflag &= ~(CSIZE|PARENB);
419  m_commState.c_cflag |= CS8; // Select 8 data bits
420  m_commState.c_cflag |= CSTOPB; // send 2 stop bits
421  // Disable hardware flow control
422  m_commState.c_cflag &= ~CRTSCTS;
423  m_commState.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
424  // Disable software flow control
425  m_commState.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
426  // Set Raw output
427  m_commState.c_oflag &= ~OPOST;
428  // Timeout 0.001 sec for first byte, read minimum of 0 bytes
429  m_commState.c_cc[VMIN] = 0;
430  m_commState.c_cc[VTIME] = (m_timeout+99)/100; // 1
431 
432  // Set the new options for the port
433  tcsetattr(m_handle,TCSANOW, &m_commState);
434 
435  m_port = 0;
436  sprintf(m_portname, "%s", portName);
437 
438  tcflush(m_handle, TCIOFLUSH);
439 
440  // setting RTS and DTR; RTS for Xbus Master, DTR for calibration sensors
441  int cmbits;
442  if (ioctl(m_handle, TIOCMGET, &cmbits) < 0)
443  {
444  return (m_lastResult = XRV_ERROR);
445  }
446 
447  cmbits |= TIOCM_RTS|TIOCM_DTR;
448 
449  if (ioctl(m_handle, TIOCMSET, &cmbits) < 0)
450  {
451  return (m_lastResult = XRV_ERROR);
452  }
453 #endif // !_WIN32
454 
455  CMT1LOG("L1: Port opened\n");
456  return (m_lastResult = XRV_OK);
457 }
458 
459 #ifdef _WIN32
460 //////////////////////////////////////////////////////////////////////////////////////////
461 // Open a communication channel to the given COM port number.
463  const uint32_t baudRate,
464  uint32_t readBufSize,
465  uint32_t writeBufSize)
466 {
467  char comFileName[32];
468 
469  // Create file name
470  sprintf(comFileName, "COM%u", portNumber);
471 
472  return Cmt1s::open(comFileName, baudRate, readBufSize, writeBufSize);
473 }
474 #endif
475 
476 //////////////////////////////////////////////////////////////////////////////////////////
477 // Read data from the serial port and put it into the data buffer.
479  uint32_t* length)
480 {
481  CMT1LOG("L1: readData, maxlength=%u, length=%p\n",maxLength,length);
482  uint32_t ln;
483  if (length == NULL)
484  length = &ln;
485 
486  if (!m_isOpen)
487  return (m_lastResult = XRV_NOPORTOPEN);
488 
489 #ifdef _WIN32
490  BOOL rres = ::ReadFile(m_handle, data, maxLength, (DWORD*)length, NULL);
491  if (m_onBytesReceived != NULL && *length > 0)
492  {
493  CmtBinaryData* bytes = (CmtBinaryData*) malloc(sizeof(CmtBinaryData));
494  bytes->m_size = *length;
495  bytes->m_portNr = m_port;
496  memcpy(bytes->m_data,data,*length);
497 #ifdef _LOG_CALLBACKS
498  CMTLOG("C1: onBytesReceived(%d,(%d,%d),%p)\n",(int32_t) m_onBytesReceivedInstance, (int32_t) bytes->m_size, (int32_t) bytes->m_portNr, m_onBytesReceivedParam);
499 #endif
501  }
502 
503  if (!rres)
504  {
505  CMT1LOG("L1: readData, ReadFile returned error %u\n",::GetLastError());
506  return (m_lastResult = XRV_ERROR);
507  }
508 #else
509  *length = read(m_handle, data, maxLength);
510 #endif
511 
512 #ifdef _LOG_RX_TX
513  if (*length > 0)
514  {
515  if (rx_log == NULL)
516  {
517  char fname[CMT_MAX_FILENAME_LENGTH];
518  sprintf(fname,"rx_%03d_%d.log",(int32_t) m_port,m_baudrate);
519  rx_log = fopen(fname,"wb");
520  }
521  fwrite(data,1,*length,rx_log);
522  }
523 #endif
524 
525  CMT1LOG((length[0]?"L1: readData returned success, read %u of %u bytes, first: %02x\n":"L1: readData returned success, read %u bytes\n"),length[0],maxLength,data[0]);
526  return (m_lastResult = XRV_OK);
527 }
528 
529 //////////////////////////////////////////////////////////////////////////////////////////
530 // Set the callback function for when bytes have been received
532 {
534  {
535  m_onBytesReceived = func;
536  m_onBytesReceivedInstance = instance;
538  return m_lastResult = XRV_OK;
539  }
541 }
542 
543 //////////////////////////////////////////////////////////////////////////////////////////
544 // Set the default timeout value to use in blocking operations.
546 {
547  CMT1LOG("L1: Setting timeout to %u ms\n",ms);
548 
549  m_timeout = ms;
550 #ifdef _WIN32
551  // Set COM timeouts
552  COMMTIMEOUTS commTimeouts;
553 
554  GetCommTimeouts(m_handle,&commTimeouts); // Fill CommTimeouts structure
555 
556  // immediate return if data is available, wait 1ms otherwise
557  if (m_timeout > 0)
558  {
559  commTimeouts.ReadIntervalTimeout = 0;
560  commTimeouts.ReadTotalTimeoutConstant = m_timeout; // ms time
561  commTimeouts.ReadTotalTimeoutMultiplier = 0;
562  commTimeouts.WriteTotalTimeoutConstant = m_timeout;
563  commTimeouts.WriteTotalTimeoutMultiplier = 0;
564  }
565  else
566  {
567  // immediate return whether data is available or not
568  commTimeouts.ReadIntervalTimeout = MAXDWORD;
569  commTimeouts.ReadTotalTimeoutConstant = 0;
570  commTimeouts.ReadTotalTimeoutMultiplier = 0;
571  commTimeouts.WriteTotalTimeoutConstant = 0;
572  commTimeouts.WriteTotalTimeoutMultiplier = 0;
573  }
574 
575  SetCommTimeouts(m_handle, &commTimeouts); // Set CommTimeouts structure
576 #else
577  // Timeout 0.1 sec for first byte, read minimum of 0 bytes
578  m_commState.c_cc[VMIN] = 0;
579  m_commState.c_cc[VTIME] = (m_timeout+99)/100; // ds time
580 
581  // Set the new options for the port if it is open
582  if (m_isOpen)
583  tcsetattr(m_handle,TCSANOW, &m_commState);
584 #endif
585  return (m_lastResult = XRV_OK);
586 }
587 
588 //////////////////////////////////////////////////////////////////////////////////////////
589 // Wait for data to arrive or a timeout to occur.
592 {
593  CMT1LOG("L1: waitForData, mto=%u, length=%p\n",m_timeout,length);
594  uint32_t timeout = m_timeout;
595 
596  uint32_t ln;
597  if (length == NULL)
598  length = &ln;
599  uint32_t eTime = getTimeOfDay(NULL) + timeout;
600  uint32_t newLength = 0;
601 
602  *length = 0;
603  while ((*length < maxLength) && (getTimeOfDay() <= eTime))
604  {
605  readData(maxLength - *length, data + *length, &newLength);
606  *length += newLength;
607  }
608  CMT1LOG("L1: waitForData result: read %u of %u bytes\n",length[0],maxLength);
609 
610  if (length[0] < maxLength)
611  return (m_lastResult = XRV_TIMEOUT);
612  else
613  return (m_lastResult = XRV_OK);
614 }
615 
616 //////////////////////////////////////////////////////////////////////////////////////////
617 // Write the data to the serial port.
619  uint32_t* written)
620 {
621  uint32_t bytes;
622  if (written == NULL)
623  written = &bytes;
624 
625  if (!m_isOpen)
626  return (m_lastResult = XRV_NOPORTOPEN);
627 
628 #ifdef _WIN32
629  if (WriteFile(m_handle, data, length, (DWORD*)written, NULL))
630  {
631 #ifdef _LOG_RX_TX
632  if (written[0] > 0)
633  {
634  if (tx_log == NULL)
635  {
636  char fname[CMT_MAX_FILENAME_LENGTH];
637  sprintf(fname,"tx_%03d_%d.log",(int32_t) m_port,m_baudrate);
638  tx_log = fopen(fname,"wb");
639  }
640  fwrite(data,1,*written,tx_log);
641  }
642 #endif
643  return (m_lastResult = XRV_OK);
644  }
645  else
646  return (m_lastResult = XRV_ERROR);
647 #else
648  *written = write(m_handle, data, length);
649 // if (*written == length)
650  return (m_lastResult = XRV_OK);
651 // else
652 // return (m_lastResult = XRV_ERROR);
653 #endif
654 }
655 
656 //////////////////////////////////////////////////////////////////////////////////////////
657 ///////////////////////////////////////// Cmt1f /////////////////////////////////////////
658 //////////////////////////////////////////////////////////////////////////////////////////
659 
660 //////////////////////////////////////////////////////////////////////////////////////////
661 // Default constructor, initializes all members to their default values.
663 {
664  m_readPos = 0;
665  m_writePos = 0;
667  m_reading = true;
668  m_isOpen = false;
669  m_filename[0] = '\0';
670  m_fileSize = 0;
671  m_readOnly = false;
672  m_unicode = false;
673 }
674 
675 //////////////////////////////////////////////////////////////////////////////////////////
676 // Destructor.
678 {
679  close();
680 }
681 
682 //////////////////////////////////////////////////////////////////////////////////////////
683 // Write data to the end of the file.
685 {
686  if (!m_isOpen)
687  return m_lastResult = XRV_NOFILEOPEN;
688  if (m_readOnly)
689  return m_lastResult = XRV_READONLY;
690 
691  if (m_reading || m_writePos != m_fileSize)
692  {
693  m_reading = false;
694  FSEEK_R(0);
695  }
696  fwrite(data, 1, length, m_handle);
697  m_writePos = FTELL();
699 
700  return (m_lastResult = XRV_OK);
701 }
702 
703 //////////////////////////////////////////////////////////////////////////////////////////
704 // Close the file.
706 {
707  if (m_isOpen)
708  {
709  #ifdef _WIN32
710  fflush(m_handle);
711  fclose(m_handle);
712  #else
713  ::fflush(m_handle);
715  #endif
716  }
717  m_isOpen = false;
718  m_readPos = 0;
719  m_writePos = 0;
720  m_reading = true;
721  m_fileSize = 0;
722  m_readOnly = false;
723 
724  return m_lastResult = XRV_OK;
725 }
726 
727 //////////////////////////////////////////////////////////////////////////////////////////
728 // Close the file and delete it.
730 {
731  if (m_isOpen)
732  {
733  #ifdef _WIN32
734  fflush(m_handle);
735  fclose(m_handle);
736  #else
737  ::fflush(m_handle);
739  #endif
740  if (m_readOnly)
742  else
743  {
744 #ifdef _WIN32
745  if (m_unicode)
746  {
747  if (_wremove(m_filename_w) != 0)
749  else
751  }
752  else
753 #endif
754  {
755 #ifdef _WIN32
756  if (_unlink(m_filename) != 0)
757 #else
758  if (unlink(m_filename) != 0)
759 #endif
761  else
763  }
764  }
765  }
766  else
768 
769  m_isOpen = false;
770  m_readPos = 0;
771  m_writePos = 0;
772  m_reading = true;
773  m_fileSize = 0;
774  m_readOnly = false;
775 
776  return m_lastResult;
777 }
778 
779 //////////////////////////////////////////////////////////////////////////////////////////
780 // Create a new file.
781 XsensResultValue Cmt1f::create (const char* filename)
782 {
783  if (m_isOpen)
784  return m_lastResult = XRV_ALREADYOPEN;
785 
786  //! \test does this work for non-existing files? Or do we need a check and create?
787  m_handle = fopen(filename, "w+b"); // open for update (r/w)
788  if (m_handle == NULL)
790 
791  #ifdef _WIN32
792  if (_fullpath(m_filename,filename,CMT_MAX_FILENAME_LENGTH) == NULL)
793  {
794  fclose(m_handle);
795  remove(filename);
797  }
798  #else
799  // based on the assumption that this doesn't concern the serial port, handle
800  // it the same way using realpath(). Apparently realpath() doesn't require a
801  // maximum length. One would possibly want to write a wrapper for it.
802  if (realpath(filename, m_filename) == NULL)
803  {
804  fclose(m_handle);
805  remove(filename);
807  }
808  #endif
810  m_unicode = false;
811 
812  m_isOpen = true;
813  m_readPos = 0;
814  m_writePos = 0;
815  m_fileSize = 0;
816  m_reading = true;
817  m_readOnly = false;
818  return m_lastResult = XRV_OK;
819 }
820 
821 //////////////////////////////////////////////////////////////////////////////////////////
822 // Create a new file.
823 XsensResultValue Cmt1f::create (const wchar_t* filename)
824 {
825  if (m_isOpen)
826  return m_lastResult = XRV_ALREADYOPEN;
827 
828 #ifdef _WIN32
829  //! \test does this work for non-existing files? Or do we need a check and create?
830  m_handle = _wfopen(filename, L"w+b"); // open for update (r/w)
831  if (m_handle == NULL)
833 
834  if (_wfullpath(m_filename_w,filename,CMT_MAX_FILENAME_LENGTH) == NULL)
835  {
836  fclose(m_handle);
837  _wremove(filename);
839  }
841 
842  m_isOpen = true;
843  m_readPos = 0;
844  m_writePos = 0;
845  m_fileSize = 0;
846  m_reading = true;
847  m_readOnly = false;
848 #else
849  MRPT_UNUSED_PARAM(filename);
850  char tFilename[CMT_MAX_FILENAME_LENGTH*2];
851  wcstombs(tFilename,m_filename_w,CMT_MAX_FILENAME_LENGTH);
852  XsensResultValue res = create(tFilename);
853  if (res != XRV_OK)
854  return res;
855 #endif
856  m_unicode = true;
857  return m_lastResult = XRV_OK;
858 }
859 
860 //////////////////////////////////////////////////////////////////////////////////////////
861 // Delete the given data from the file.
863 {
864  if (!m_isOpen)
865  return m_lastResult = XRV_NOFILEOPEN;
866  if (m_readOnly)
867  return m_lastResult = XRV_READONLY;
868 
869  gotoWrite();
870 
871  CmtFilePos wPos = start;
872  CmtFilePos rPos = wPos + length;
873 
874  size_t read1;
875  CmtFilePos endPos = (start + (CmtFilePos) length);
876  if (endPos < m_fileSize)
877  {
878  CmtFilePos remaining = m_fileSize - endPos;
879  char buffer[512];
880 
881  // copy data
882  FSEEK(rPos);
883 
884  while (remaining > 0)
885  {
886  if (remaining >= 512)
887  read1 = fread(buffer,1,512,m_handle);
888  else
889  read1 = fread(buffer,1,(size_t) remaining,m_handle);
890 
891  remaining -= read1;
892  rPos += read1;
893 
894  // write block to the correct position
895  FSEEK(wPos);
896  wPos += fwrite(buffer, 1, read1, m_handle);
897  FSEEK(rPos);
898  }
899  m_fileSize -= length;
900  }
901  else
902  {
903  m_fileSize = start;
904  }
905 
906 #ifdef _WIN32
907  int32_t rv = _chsize(_fileno(m_handle),(int32_t) m_fileSize);
908 #else
909  int32_t rv = (ftruncate(fileno(m_handle),(int32_t) m_fileSize) == 0);
910 #endif
911  int32_t eno = 0;
912  if (rv != 0)
913  eno = errno;
914  m_writePos = start;
915  FSEEK(wPos);
916  if (rv != 0)
917  {
918  switch(eno)
919  {
920  case EACCES:
921  return m_lastResult = XRV_BUSY;
922  case EBADF:
924  case ENOSPC:
925  return m_lastResult = XRV_OUTOFMEMORY;
926  case EINVAL:
928  default:
929  return m_lastResult = XRV_ERROR;
930  }
931  }
932 
933  return m_lastResult = XRV_OK;
934 }
935 
936 //////////////////////////////////////////////////////////////////////////////////////////
937 // Find a string of bytes in the file
938 XsensResultValue Cmt1f::find (const void* needleV, const uint32_t needleLength, CmtFilePos& pos)
939 {
940  if (!m_isOpen)
941  return m_lastResult = XRV_NOFILEOPEN;
942 
943  const char* needle = (const char*) needleV;
944 
945  gotoRead();
946 
947  pos = 0;
948 
949  char buffer[512];
950  uint32_t bufferPos, needlePos = 0;
951  size_t readBytes;
952  if (m_readPos & 0x1FF) // read a block of data
953  readBytes = fread(buffer,1,(512-((size_t) m_readPos & 0x1FF)),m_handle);
954  else
955  readBytes = fread(buffer,1,512,m_handle); // read a block of data
956 
957  while (readBytes > 0)
958  {
959  m_readPos += readBytes;
960  bufferPos = 0;
961 
962  while (bufferPos < readBytes && needlePos < needleLength)
963  {
964  if (buffer[bufferPos] == needle[needlePos])
965  {
966  // found a byte
967  ++needlePos;
968  }
969  else
970  {
971  if (needlePos > 0)
972  needlePos = 0;
973  else
974  if (buffer[bufferPos] == needle[0])
975  {
976  // found a byte
977  needlePos = 1;
978  }
979  }
980  ++bufferPos;
981  }
982  if (needlePos < needleLength)
983  readBytes = fread(buffer,1,512,m_handle); // read next block
984  else
985  {
986  m_readPos = m_readPos + bufferPos - readBytes - needleLength; // or without needleLength
987  pos = m_readPos; // - needleLength;
988  FSEEK(m_readPos);
989  return m_lastResult = XRV_OK;
990  }
991  }
992  return m_lastResult = XRV_ENDOFFILE;
993 }
994 
995 //////////////////////////////////////////////////////////////////////////////////////////
996 // Flush all data to be written.
998 {
999  fflush(m_handle);
1000 
1001  return m_lastResult = XRV_OK;
1002 }
1003 
1004 //////////////////////////////////////////////////////////////////////////////////////////
1005 // Retrieve the filename that was last successfully opened.
1006 XsensResultValue Cmt1f::getName(char* filename) const
1007 {
1008  strcpy(filename, m_filename);
1009  return m_lastResult = XRV_OK;
1010 }
1011 
1012 //////////////////////////////////////////////////////////////////////////////////////////
1013 // Retrieve the filename that was last successfully opened.
1014 XsensResultValue Cmt1f::getName(wchar_t* filename) const
1015 {
1016 #ifdef _WIN32
1017  wcscpy(filename, m_filename_w);
1018 #else
1019  mbstowcs(filename, m_filename, CMT_MAX_FILENAME_LENGTH);
1020 #endif
1021  return m_lastResult = XRV_OK;
1022 }
1023 
1024 //////////////////////////////////////////////////////////////////////////////////////////
1025 // Change from writing to reading mode
1027 {
1028  if (m_reading)
1029  return;
1030 
1031  FSEEK(m_readPos);
1032  m_reading = true;
1033 }
1034 
1035 //////////////////////////////////////////////////////////////////////////////////////////
1036 // Change from reading to writing mode
1038 {
1039  if (!m_reading)
1040  return;
1041 
1042  FSEEK(m_writePos);
1043  m_reading = false;
1044 }
1045 
1046 //////////////////////////////////////////////////////////////////////////////////////////
1047 // Insert the given data into the file.
1049 {
1050  if (!m_isOpen)
1051  return m_lastResult = XRV_NOFILEOPEN;
1052  if (m_readOnly)
1053  return m_lastResult = XRV_READONLY;
1054 
1055  gotoWrite();
1056 
1057  CmtFilePos rPos = start;
1058  CmtFilePos wPos = rPos + length;
1059 
1060  size_t read1, read2;
1061  CmtFilePos remaining = m_fileSize - start;
1062  size_t bsize = (length > 512)?length:512;
1063  char* buffer1 = (char*) malloc(bsize);
1064  char* buffer2 = (char*) malloc(bsize);
1065  char* btemp;
1066 
1067  // copy data
1068  FSEEK(rPos);
1069 
1070  if (remaining >= (CmtFilePos) bsize)
1071  read1 = fread(buffer1,1,bsize,m_handle);
1072  else
1073  read1 = fread(buffer1,1,(size_t) remaining,m_handle);
1074 
1075  remaining -= read1;
1076  rPos += read1;
1077 
1078  while(remaining > 0)
1079  {
1080  // move data to correct buffer
1081  read2 = read1;
1082  btemp = buffer1; buffer1 = buffer2; buffer2 = btemp;
1083 
1084  // read next block
1085  if (remaining >= (CmtFilePos) bsize)
1086  read1 = fread(buffer1,1,bsize,m_handle);
1087  else
1088  read1 = fread(buffer1,1,(size_t) remaining,m_handle);
1089 
1090  remaining -= read1;
1091  rPos += read1;
1092 
1093  // write block to the correct position
1094  FSEEK(wPos);
1095  wPos += fwrite(buffer2, 1, read2, m_handle);
1096  FSEEK(rPos);
1097  }
1098 
1099  FSEEK(wPos);
1100  wPos += fwrite(buffer1, 1, read1, m_handle);
1101 
1102  FSEEK(start);
1103  m_writePos = start + fwrite(data, 1, length, m_handle);
1104  m_fileSize += length;
1105 
1106  free(buffer1);
1107  free(buffer2);
1108  return m_lastResult = XRV_OK;
1109 }
1110 
1111 //////////////////////////////////////////////////////////////////////////////////////////
1112 // Open a file.
1113 XsensResultValue Cmt1f::open(const char* filename, const bool create, const bool readOnly)
1114 {
1115  if (m_isOpen)
1116  return m_lastResult = XRV_ALREADYOPEN;
1117 
1118  //! \test does this work for non-existing files? Or do we need a check and create?
1119  m_readOnly = readOnly;
1120  if (readOnly)
1121  m_handle = fopen(filename, "rb"); // open for read only (r)
1122  else
1123  m_handle = fopen(filename, "r+b"); // open for update (r/w)
1124  if (m_handle == NULL)
1125  {
1126  if (create)
1127  m_handle = fopen(filename, "w+b"); // create for update (r/w)
1128  else
1129  {
1130  m_handle = fopen(filename, "rb"); // open for read only (r)
1131  m_readOnly = true;
1132  }
1133  }
1134  if (m_handle == NULL)
1136 
1137  #ifdef _WIN32
1138  if (_fullpath(m_filename,filename,CMT_MAX_FILENAME_LENGTH) == NULL)
1139  {
1140  fclose(m_handle);
1141  return m_lastResult = XRV_INVALIDPARAM;
1142  }
1143  #else
1144  // use the same trick again.
1145  if (realpath(filename, m_filename) == NULL)
1146  {
1147  fclose(m_handle);
1148  return m_lastResult = XRV_INVALIDPARAM;
1149  }
1150  #endif
1152  m_unicode = false;
1153 
1154  m_isOpen = true;
1155  m_readPos = 0;
1156  m_writePos = 0;
1157  m_reading = true;
1158  FSEEK_R(0);
1159  m_fileSize = FTELL();
1160  FSEEK(0);
1161  return (m_lastResult = XRV_OK);
1162 }
1163 
1164 //////////////////////////////////////////////////////////////////////////////////////////
1165 // Open a file.
1166 XsensResultValue Cmt1f::open(const wchar_t* filename, const bool create, const bool readOnly)
1167 {
1168  if (m_isOpen)
1169  return m_lastResult = XRV_ALREADYOPEN;
1170 
1171 #ifdef _WIN32
1172  //! \test does this work for non-existing files? Or do we need a check and create?
1173  m_readOnly = readOnly;
1174  if (readOnly)
1175  m_handle = _wfopen(filename, L"rb"); // open for read only (r)
1176  else
1177  m_handle = _wfopen(filename, L"r+b"); // open for update (r/w)
1178  if (m_handle == NULL)
1179  {
1180  if (create)
1181  m_handle = _wfopen(filename, L"w+b"); // create for update (r/w)
1182  else
1183  {
1184  m_handle = _wfopen(filename, L"rb"); // open for read only (r)
1185  m_readOnly = true;
1186  }
1187  }
1188  if (m_handle == NULL)
1190 
1191  if (_wfullpath(m_filename_w,filename,CMT_MAX_FILENAME_LENGTH) == NULL)
1192  {
1193  fclose(m_handle);
1194  return m_lastResult = XRV_INVALIDPARAM;
1195  }
1197 
1198  m_isOpen = true;
1199  m_readPos = 0;
1200  m_writePos = 0;
1201  m_reading = true;
1202  FSEEK_R(0);
1203  m_fileSize = FTELL();
1204  FSEEK(0);
1205 #else
1206  char tFilename[CMT_MAX_FILENAME_LENGTH*2];
1207  wcstombs(tFilename,filename,CMT_MAX_FILENAME_LENGTH*2);
1208  XsensResultValue res = open(tFilename,create,readOnly);
1209  if (res != XRV_OK)
1210  return res;
1211 #endif
1212  m_unicode = true;
1213  return m_lastResult = XRV_OK;
1214 }
1215 
1216 //////////////////////////////////////////////////////////////////////////////////////////
1217 // Read data from the file and put it into the data buffer.
1219 {
1220  if (!m_isOpen)
1221  return m_lastResult = XRV_NOFILEOPEN;
1222 
1223  if (maxLength == 0)
1224  return m_lastResult = XRV_OK;
1225 
1226  uint32_t len;
1227  if (length == NULL)
1228  length = &len;
1229 
1230  gotoRead();
1231 
1232  length[0] = (uint32_t) fread(data,1,maxLength,m_handle);
1233  if (length[0] == 0)
1234  return (m_lastResult = XRV_ENDOFFILE);
1235 
1236  m_readPos += length[0];
1237  return m_lastResult = XRV_OK;
1238 }
1239 
1240 //////////////////////////////////////////////////////////////////////////////////////////
1241 // Read data from the file until the terminator and put it into the data buffer.
1242 XsensResultValue Cmt1f::readData (const uint32_t maxLength, const char terminator, void* dataV, uint32_t* length)
1243 {
1244  if (!m_isOpen)
1245  return m_lastResult = XRV_NOFILEOPEN;
1246 
1247  uint32_t len;
1248  if (length == NULL)
1249  length = &len;
1250 
1251  char* data = (char*) dataV;
1252  int32_t readChar;
1253 
1254  gotoRead();
1255 
1256  *length = 0;
1257  readChar = (uint32_t) fgetc(m_handle);
1258 
1259  while (!feof(m_handle) && !ferror(m_handle))
1260  {
1261  data[*length] = (char) readChar;
1262  ++(*length);
1263  ++m_readPos;
1264 
1265  if (((char) readChar == terminator) || ((*length) >= maxLength))
1266  return m_lastResult = XRV_OK;
1267  }
1268  return m_lastResult = XRV_ENDOFFILE;
1269 }
1270 
1271 //////////////////////////////////////////////////////////////////////////////////////////
1272 // Set the new absolute read position
1274 {
1275  if (!m_isOpen)
1276  return m_lastResult = XRV_NOFILEOPEN;
1277 
1278  if (m_readPos != pos)
1279  {
1280  m_readPos = pos;
1281  if (m_reading)
1282  FSEEK(m_readPos);
1283  }
1284 
1285  return m_lastResult = XRV_OK;
1286 }
1287 
1288 //////////////////////////////////////////////////////////////////////////////////////////
1289 // Set the new absolute write position
1291 {
1292  if (!m_isOpen)
1293  return m_lastResult = XRV_NOFILEOPEN;
1294  if (m_readOnly)
1295  return m_lastResult = XRV_READONLY;
1296 
1297  if (pos == -1)
1298  {
1299  if (m_reading)
1300  m_reading = false;
1301  FSEEK_R(0);
1302  m_writePos = FTELL();
1303  }
1304  else
1305  {
1306  if (m_writePos != pos)
1307  {
1308  m_writePos = pos;
1309  if (!m_reading)
1310  FSEEK(m_writePos);
1311  }
1312  }
1313 
1314  return m_lastResult = XRV_OK;
1315 }
1316 
1317 //////////////////////////////////////////////////////////////////////////////////////////
1318 // Write data to the file.
1320 {
1321  if (!m_isOpen)
1322  return m_lastResult = XRV_NOFILEOPEN;
1323  if (m_readOnly)
1324  return m_lastResult = XRV_READONLY;
1325 
1326  gotoWrite();
1327  m_writePos += fwrite(data, 1, length, m_handle);
1328 
1329  if (m_writePos > m_fileSize)
1331 
1332  return m_lastResult = XRV_OK;
1333 }
1334 
1335 } // end of xsens namespace
int32_t m_onBytesReceivedInstance
Custom, user supplied parameter for the OnBytesReceived callback function, passed as the first argume...
Definition: cmt1.h:70
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
Definition: os.cpp:358
Operation was performed successfully.
Definition: xsens_std.h:32
GLuint GLuint GLsizei count
Definition: glext.h:3512
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
Definition: os.cpp:255
GLenum GLint GLuint mask
Definition: glext.h:3888
Cmt1s()
Default constructor, initializes all members to their default values.
Definition: cmt1.cpp:184
__int64 CmtFilePos
Definition: cmtf.h:24
#define FTELL()
Definition: cmt1.cpp:83
XsensResultValue appendData(const uint32_t length, const void *data)
Write data to the end of the file.
Definition: cmt1.cpp:684
XsensResultValue setReadPos(const CmtFilePos pos)
Set the new absolute read position.
Definition: cmt1.cpp:1273
A timeout occurred.
Definition: xsens_std.h:60
XsensResultValue writeData(const uint32_t length, const uint8_t *data, uint32_t *written)
Write the data to the serial port.
Definition: cmt1.cpp:618
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
Definition: cmt1.cpp:1006
int BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:272
CmtCallbackFunction m_onBytesReceived
The bytes received function.
Definition: cmt1.h:68
GLuint buffer
Definition: glext.h:3775
void gotoRead(void)
Change from writing to reading mode.
Definition: cmt1.cpp:1026
#define CMT_MAX_FILENAME_LENGTH
Definition: cmtdef.h:915
#define CMTLOG(...)
Definition: cmt1.h:38
uint32_t m_baudrate
The baudrate that was last set to be used by the port.
Definition: cmt1.h:75
XsensResultValue readData(const uint32_t maxLength, void *data, uint32_t *length)
Read data from the file and put it into the data buffer.
Definition: cmt1.cpp:1218
XsensResultValue writeData(const uint32_t length, const void *data)
Write data to the file.
Definition: cmt1.cpp:1319
The specified i/o device can not be opened.
Definition: xsens_std.h:69
XsensResultValue closeAndDelete(void)
Close the file and delete it.
Definition: cmt1.cpp:729
The specified i/o device can not be opened.
Definition: xsens_std.h:70
CmtControlLine
Definition: cmtdef.h:821
int BASE_IMPEXP fprintf(FILE *fil, const char *format,...) MRPT_NO_THROWS MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:412
char m_portname[257]
Definition: cmt1.h:84
XsensResultValue deleteData(const CmtFilePos start, const uint32_t length)
Delete the given data from the file.
Definition: cmt1.cpp:862
char BASE_IMPEXP * strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS
An OS-independent version of strcpy.
Definition: os.cpp:296
int BOOL
Definition: xstypedefs.h:62
GLenum GLsizei len
Definition: glext.h:4349
uint32_t getTimeOfDay(tm *date_, time_t *secs_)
A platform-independent clock.
Definition: xsens_time.cpp:29
No internal memory available.
Definition: xsens_std.h:63
unsigned char uint8_t
Definition: rptypes.h:43
CmtFilePos m_readPos
The last read position in the file.
Definition: cmt1.h:215
XsensResultValue open(const char *filename, const bool create, const bool readOnly)
Open a file.
Definition: cmt1.cpp:1113
End of file is reached.
Definition: xsens_std.h:72
FILE * m_handle
The file handle.
Definition: cmt1.h:211
XsensResultValue setTimeout(const uint32_t ms=CMT1_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
Definition: cmt1.cpp:545
Tried to change a read-only value.
Definition: xsens_std.h:75
XsensResultValue insertData(const CmtFilePos start, const uint32_t length, const void *data)
Insert the given data into the file.
Definition: cmt1.cpp:1048
char m_filename[CMT_MAX_FILENAME_LENGTH]
Contains the name of the file that was last successfully opened.
Definition: cmt1.h:221
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define FALSE
Definition: jmorecfg.h:227
No serial port opened for reading/writing.
Definition: xsens_std.h:92
XsensResultValue(__cdecl * CmtCallbackFunction)(int32_t, CmtCallbackSelector, void *, void *)
Definition: cmtdef.h:1091
#define CMT1LOG(...)
Definition: cmt1.cpp:175
XsensResultValue
Xsens return values.
Definition: xsens_std.h:30
XsensResultValue waitForData(const uint32_t maxLength, uint8_t *data, uint32_t *length=NULL)
Wait for data to arrive or a timeout to occur.
Definition: cmt1.cpp:590
XsensResultValue find(const void *needle, const uint32_t needleLength, CmtFilePos &pos)
Find a string of bytes in the file.
Definition: cmt1.cpp:938
XsensResultValue open(const char *portName, const uint32_t baudRate=CMT_DEFAULT_BAUD_RATE, uint32_t readBufSize=CMT_DEFAULT_READ_BUFFER_SIZE, uint32_t writeBufSize=CMT_DEFAULT_WRITE_BUFFER_SIZE)
Open a communcation channel to the given serial port name.
Definition: cmt1.cpp:322
XsensResultValue readData(const uint32_t maxLength, uint8_t *data, uint32_t *length=NULL)
Read data from the serial port and put it into the data buffer.
Definition: cmt1.cpp:478
CmtFilePos m_fileSize
Contains the size of the file.
Definition: cmt1.h:213
~Cmt1s()
Destructor, de-initializes, frees memory allocated for buffers, etc.
Definition: cmt1.cpp:202
Cmt1f()
Default constructor, initializes all members to their default values.
Definition: cmt1.cpp:662
wchar_t m_filename_w[CMT_MAX_FILENAME_LENGTH]
Contains the name of the file that was last successfully opened using unicode.
Definition: cmt1.h:223
bool m_isOpen
Indicates if the file is open or not.
Definition: cmt1.h:225
XsensResultValue close(void)
Close the file.
Definition: cmt1.cpp:705
XsensResultValue escape(const CmtControlLine mask, const CmtControlLine state)
Manipulate the Serial control lines.
Definition: cmt1.cpp:249
#define FSEEK_R(x)
Definition: cmt1.cpp:82
void gotoWrite(void)
Change from reading to writing mode.
Definition: cmt1.cpp:1037
#define FSEEK(x)
Definition: cmt1.cpp:81
bool m_unicode
Indicates if we&#39;re using the unicode filename or the regular filename.
Definition: cmt1.h:227
#define CMT1_DEFAULT_TIMEOUT
The default timeout value for blocking CMT1s operations in ms.
Definition: cmtdef.h:805
bool m_isOpen
Indicates if the port is open or not.
Definition: cmt1.h:79
CmtFilePos m_writePos
The last write position in the file.
Definition: cmt1.h:217
~Cmt1f()
Destructor.
Definition: cmt1.cpp:677
__int32 int32_t
Definition: rptypes.h:48
XsensResultValue setCallbackFunction(CmtCallbackSelector tp, int32_t instance, CmtCallbackFunction func, void *param)
Set the callback function for when bytes have been received.
Definition: cmt1.cpp:531
HANDLE m_handle
The serial port handle.
Definition: cmt1.h:92
bool m_reading
Indicates whether the last operation was a read or write operation.
Definition: cmt1.h:233
void * m_onBytesReceivedParam
Custom, user supplied parameter for the OnBytesReceived callback function, passed as the last argumen...
Definition: cmt1.h:72
uint32_t m_endTime
The time at which an operation will end in ms, used by several functions.
Definition: cmt1.h:77
GLuint GLsizei GLsizei * length
Definition: glext.h:3900
Invalid instance called.
Definition: xsens_std.h:79
An invalid parameter is supplied.
Definition: xsens_std.h:53
_u8 status
Definition: rplidar_cmd.h:21
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt1.h:81
CmtCallbackSelector
Definition: cmtdef.h:1068
int BASE_IMPEXP int BASE_IMPEXP vsprintf(char *buf, size_t bufSize, const char *format, va_list args) MRPT_NO_THROWS
An OS-independent version of vsprintf (Notice the bufSize param, which may be ignored in some compile...
Definition: os.cpp:214
int BASE_IMPEXP sprintf(char *buf, size_t bufSize, const char *format,...) MRPT_NO_THROWS 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
The namespace of all Xsens software since 2006.
Definition: cmt1.cpp:92
bool m_readOnly
Indicates if the file was opened in read-only mode.
Definition: cmt1.h:235
uint32_t m_timeout
Definition: cmt1.h:88
A generic error occurred.
Definition: xsens_std.h:58
XsensResultValue create(const char *filename)
Open an empty file.
Definition: cmt1.cpp:781
XsensResultValue close(void)
Close the serial communication port.
Definition: cmt1.cpp:209
GLsizei maxLength
Definition: glext.h:4504
GLuint res
Definition: glext.h:6298
Callback function, called when bytes have been read from a port.
Definition: cmtdef.h:1073
GLuint start
Definition: glext.h:3512
uint8_t m_port
The opened COM port nr.
Definition: cmt1.h:83
unsigned __int32 uint32_t
Definition: rptypes.h:49
GLfloat param
Definition: glext.h:3705
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3520
XsensResultValue setWritePos(const CmtFilePos pos=-1)
Set the new absolute write position.
Definition: cmt1.cpp:1290
An I/O device is already opened with this object.
Definition: xsens_std.h:71
Busy processing, try again later.
Definition: xsens_std.h:78
uint8_t m_data[CMT_MAXMSGLEN]
Definition: cmtdef.h:1086
uint8_t m_portNr
Definition: cmtdef.h:1087
DCB m_commState
Stored settings about the serial port.
Definition: cmt1.h:91
No file opened for reading/writing.
Definition: xsens_std.h:91
XsensResultValue flushData(void)
Flush all data to be written. This function writes any remaining data immediately and does not return...
Definition: cmt1.cpp:997
XsensResultValue flushData(void)
Flush all data to be transmitted / received.
Definition: cmt1.cpp:308
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt1.h:219
int32_t m_size
Definition: cmtdef.h:1085



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