MRPT  1.9.9
cmt3.cpp
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 
10 /*! \file cmt3.cpp
11 
12  For information about objects in this file, see the appropriate header:
13  \ref Cmt3.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-28, 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 "cmt3.h"
35 #include <cmath>
36 #include "xsens_janitors.h"
37 
38 #ifdef _LOG_CMT3
39 #define CMT3LOG CMTLOG
40 #define CMT3EXITLOG \
41  JanitorLogFunc<XsensResultValue, uint32_t> _cmtExitLog( \
42  CMTLOG, "L3: " __FUNCTION__ " returns %u\n", m_lastResult);
43 #else
44 #define CMT3LOG(...)
45 #define CMT3EXITLOG
46 #endif
47 
48 #ifdef _LOG_CMT3_DATA
49 #define CMT3LOGDAT CMTLOG
50 #define CMT3EXITLOGDAT \
51  JanitorLogFunc<XsensResultValue, uint32_t> _cmtExitLog( \
52  CMTLOG, "L3: " __FUNCTION__ " returns %u\n", m_lastResult);
53 #else
54 #define CMT3LOGDAT(...)
55 #define CMT3EXITLOGDAT
56 #endif
57 
58 #define CMT3F_DEVINFO_SIZE (sizeof(CmtDeviceId) + sizeof(CmtDataFormat))
59 
60 //////////////////////////////////////////////////////////////////////////////////////////
61 //////////////////////////////////// Support classes
62 ///////////////////////////////////////
63 //////////////////////////////////////////////////////////////////////////////////////////
64 
65 void CmtDeviceConfiguration::readFromMessage(const void* message)
66 {
67  xsens::Message msg((const uint8_t*)message, 0);
68 
72  m_syncinMode = msg.getDataShort(8);
74  m_syncinOffset = msg.getDataLong(12);
75  memcpy(m_date, msg.getDataBuffer(16), 8);
76  memcpy(m_time, msg.getDataBuffer(24), 8);
80 
81  for (uint16_t i = 0; i < m_numberOfDevices; ++i)
82  {
83  m_deviceInfo[i].m_deviceId = msg.getDataLong(98 + i * 20);
84  m_deviceInfo[i].m_dataLength = msg.getDataShort(102 + i * 20);
85  m_deviceInfo[i].m_outputMode = msg.getDataShort(104 + i * 20);
86  m_deviceInfo[i].m_outputSettings = msg.getDataLong(106 + i * 20);
87  memcpy(m_deviceInfo[i].m_reserved, msg.getDataBuffer(110 + i * 20), 8);
88  }
89 }
90 
91 //////////////////////////////////////////////////////////////////////////////////////////
92 // Compute the period and skip factor.
94  uint16_t& period, uint16_t& skip) const
95 {
96  if (m_sampleFrequency == 0)
97  {
98  period = 0;
99  skip = 0;
100  return;
101  }
102  if (m_sampleFrequency >= 512)
103  {
104  period = 225;
105  skip = 0;
106  return;
107  }
108 
109  int32_t freq, sf = m_sampleFrequency;
110 
111  // first try the simple ones
112  skip = 0;
113  freq = sf;
114  while (freq < 100)
115  {
116  ++skip;
117  freq += sf;
118  }
119 
120  period = (uint16_t)(115200 / freq);
121 }
122 
123 //////////////////////////////////////////////////////////////////////////////////////////
124 // Return the real sample frequency in Hz
126 {
127  uint16_t skip, period;
128  getPeriodAndSkipFactor(period, skip);
129  return (115200.0 / ((1.0 + (double)skip) * (double)period));
130 }
131 
132 //////////////////////////////////////////////////////////////////////////////////////////
133 // Compute sample frequency from the period and skip factor.
135 {
136  m_sampleFrequency = (uint16_t)floor(
137  (115200.0 / ((1.0 + (double)skip) * (double)period)) + 0.5);
138 }
139 
140 //////////////////////////////////////////////////////////////////////////////////////////
141 // Compute sample frequency from the period and skip factor.
143 {
144  return m_outputMode == dev.m_outputMode &&
147 }
148 
149 //////////////////////////////////////////////////////////////////////////////////////////
150 // Return the real sample frequency in Hz
152 {
153  if (m_skip != 0xFFFF)
154  return (115200.0 / ((1.0 + (double)m_skip) * (double)m_period));
155  else
156  return (115200.0 / ((double)m_period));
157 }
158 
159 //////////////////////////////////////////////////////////////////////////////////////////
160 // Return the sample frequency in Hz
162 {
163  if (m_skip != 0xFFFF)
164  return (uint16_t)floor(
165  (115200.0 / ((1.0 + (double)m_skip) * (double)m_period)) + 0.5);
166  else
167  return (uint16_t)floor((115200.0 / ((double)m_period)) + 0.5);
168 }
169 
171 {
172  if (frequency == 0)
173  {
174  m_period = 0;
175  m_skip = 0;
176  return;
177  }
178  if (frequency >= 512)
179  {
180  m_period = 225;
181  m_skip = 0;
182  return;
183  }
184 
185  int32_t freq, sf = frequency;
186 
187  // first try the simple ones
188  m_skip = 0;
189  freq = sf;
190  while (freq < 100)
191  {
192  ++m_skip;
193  freq += sf;
194  }
195 
196  m_period = (uint16_t)(115200 / freq);
197 }
198 
199 //////////////////////////////////////////////////////////////////////////////////////////
200 // Compute sample frequency from the period and skip factor.
202 {
203  return m_outputMode == dev.m_outputMode &&
205  m_period == dev.m_period && m_skip == dev.m_skip;
206 }
207 
208 //////////////////////////////////////////////////////////////////////////////////////////
209 // Common part of a data request function
210 #define DO_DATA_REQUEST_BID(req, bid) \
211  Message snd(req, 0); \
212  Message rcv; \
213  if (bid == CMT_BID_INVALID || bid == CMT_BID_BROADCAST) \
214  return (m_lastResult = XRV_INVALIDID); \
215  if (!m_readFromFile) \
216  { \
217  snd.setBusId(bid); \
218  m_serial.writeMessage(&snd); \
219  if ((m_lastResult = \
220  m_serial.waitForMessage(&rcv, req + 1, 0, true)) != XRV_OK) \
221  return m_lastResult; \
222  if (m_logging) m_logFile.writeMessage(&rcv); \
223  if (rcv.getMessageId() == CMT_MID_ERROR) \
224  { \
225  m_lastHwErrorDeviceId = m_config.m_masterDeviceId; \
226  if (rcv.getDataSize() >= 2) \
227  { \
228  uint8_t biddy = rcv.getDataByte(1); \
229  getDeviceId(biddy, m_lastHwErrorDeviceId); \
230  } \
231  return m_lastResult = m_lastHwError = \
232  (XsensResultValue)rcv.getDataByte(); \
233  } \
234  } \
235  else \
236  while (1) \
237  { \
238  if ((m_lastResult = m_logFile.readMessage(&rcv, req + 1)) != \
239  XRV_OK) \
240  return m_lastResult; \
241  if (rcv.getBusId() == bid || \
242  (rcv.getBusId() == 1 && bid == CMT_BID_MASTER)) \
243  break; \
244  }
245 
246 #define DO_DATA_REQUEST(req) \
247  uint8_t bid = getBusIdInternal(deviceId); \
248  DO_DATA_REQUEST_BID(req, bid);
249 
250 //////////////////////////////////////////////////////////////////////////////////////////
251 // Common part of a serial data set function
252 #define DO_DATA_SET_BID(req, size, type, data, bid) \
253  Message snd(req, size); \
254  Message rcv; \
255  snd.setData##type(data); \
256  if (bid == CMT_BID_BROADCAST) \
257  { \
258  for (uint8_t i = 0; i < m_config.m_numberOfDevices; ++i) \
259  { \
260  snd.setBusId(i + 1); \
261  m_serial.writeMessage(&snd); \
262  m_lastResult = m_serial.waitForMessage(&rcv, req + 1, 0, true); \
263  if (m_lastResult != XRV_OK) return m_lastResult; \
264  if (m_logging) m_logFile.writeMessage(&rcv); \
265  if (rcv.getMessageId() == CMT_MID_ERROR) \
266  { \
267  m_lastHwErrorDeviceId = m_config.m_masterDeviceId; \
268  if (rcv.getDataSize() >= 2) \
269  { \
270  uint8_t biddy = rcv.getDataByte(1); \
271  getDeviceId(biddy, m_lastHwErrorDeviceId); \
272  } \
273  return m_lastResult = m_lastHwError = \
274  (XsensResultValue)rcv.getDataByte(); \
275  } \
276  } \
277  } \
278  else \
279  { \
280  snd.setBusId(bid); \
281  m_serial.writeMessage(&snd); \
282  m_lastResult = m_serial.waitForMessage(&rcv, req + 1, 0, true); \
283  if (m_lastResult != XRV_OK) return m_lastResult; \
284  if (m_logging) m_logFile.writeMessage(&rcv); \
285  if (rcv.getMessageId() == CMT_MID_ERROR) \
286  { \
287  m_lastHwErrorDeviceId = m_config.m_masterDeviceId; \
288  if (rcv.getDataSize() >= 2) \
289  { \
290  uint8_t biddy = rcv.getDataByte(1); \
291  getDeviceId(biddy, m_lastHwErrorDeviceId); \
292  } \
293  return m_lastResult = m_lastHwError = \
294  (XsensResultValue)rcv.getDataByte(); \
295  } \
296  }
297 
298 #define DO_DATA_SET(req, size, type, data) \
299  uint8_t bid = getBusIdInternal(deviceId); \
300  if (bid == CMT_BID_INVALID) return (m_lastResult = XRV_INVALIDID); \
301  DO_DATA_SET_BID(req, size, type, data, bid);
302 
303 #define HANDLE_ERR_RESULT \
304  if (rcv.getMessageId() == CMT_MID_ERROR) \
305  { \
306  m_lastHwErrorDeviceId = m_config.m_masterDeviceId; \
307  if (rcv.getDataSize() >= 2) \
308  { \
309  uint8_t biddy = rcv.getDataByte(1); \
310  getDeviceId(biddy, m_lastHwErrorDeviceId); \
311  } \
312  return m_lastResult = m_lastHwError = \
313  (XsensResultValue)rcv.getDataByte(0); \
314  }
315 
316 //////////////////////////////////////////////////////////////////////////////////////////
317 ///////////////////////////////////////// Cmt3
318 ////////////////////////////////////////////
319 //////////////////////////////////////////////////////////////////////////////////////////
320 
321 namespace xsens
322 {
323 //////////////////////////////////////////////////////////////////////////////////////////
324 // Default constructor, initializes all members to their default values.
326 {
328  m_rtcInitialized = false;
329  m_useRtc = true;
330  m_measuring = false;
334  m_readFromFile = false;
335  // m_sampleFrequency = 100.0;
338  memset(m_eMtsData, 0, sizeof(m_eMtsData));
339  memset(&m_config, 0, sizeof(m_config));
340  m_logging = false;
341 
342  clearHwError();
343 }
344 
345 //////////////////////////////////////////////////////////////////////////////////////////
346 // Destructor, de-initializes, frees memory allocated for buffers, etc.
348 {
349  m_serial.close();
350  m_logFile.close();
351  for (uint32_t i = 0; i < CMT_MAX_DEVICES_PER_PORT; ++i)
352  {
353  CHKFREENUL(m_eMtsData[i]);
354  }
355 }
356 
357 //////////////////////////////////////////////////////////////////////////////////////////
358 // Close the serial communication port.
359 XsensResultValue Cmt3::closePort(bool gotoConfigFirst)
360 {
361  CMT3LOG("L3: closePort\n");
362  CMT3EXITLOG;
363 
364  if (m_measuring && gotoConfigFirst) gotoConfig();
365  CMT3LOG("L3: Closing L2 port\n");
366  m_serial.close();
367  m_measuring = false;
368  if (m_logFile.isOpen())
369  {
370  m_readFromFile = true;
371  m_logging = false;
372  }
373  return m_lastResult = XRV_OK;
374 }
375 
376 //////////////////////////////////////////////////////////////////////////////////////////
378 {
379  if (!m_rtcInitialized)
380  {
381  m_rtcStart = pack->m_toa;
382  m_rtcLastSc = pack->getSampleCounter();
385  mode.m_period = m_period;
386  mode.m_skip = m_skip;
387  m_rtcMsPerSample = 1000.0 / mode.getRealSampleFrequency();
388  pack->m_rtc = m_rtcStart;
389  m_rtcInitialized = true;
390  }
391  else
392  {
393  CmtMtTimeStamp sc = pack->getSampleCounter();
394  CmtMtTimeStamp scdiff = sc - m_rtcLastSc;
395  m_rtcLastSc = sc;
396  m_rtcCount += scdiff;
397  pack->m_rtc =
398  m_rtcStart +
399  (TimeStamp)floor(m_rtcMsPerSample * (double)m_rtcCount + 0.5);
400  }
401 }
402 
403 #if 0
404 obsolete:
405 //////////////////////////////////////////////////////////////////////////////////////////
406 // Get the state (enabled/disabled) of the AMD algorithm
407 XsensResultValue Cmt3::getAmdState(bool& state, const CmtDeviceId deviceId)
408 {
409  CMT3LOG("L3: getAmdState %08x\n",deviceId);
410  CMT3EXITLOG;
411 
413  state = (rcv.getDataShort() != 0);
414  return m_lastResult = XRV_OK;
415 }
416 #endif
417 
418 //////////////////////////////////////////////////////////////////////////////////////////
419 // Get the XM batery level
421 {
422  CMT3LOG("L3: getBatteryLevel\n");
423  CMT3EXITLOG;
424 
426  level = rcv.getDataByte();
427  return m_lastResult = XRV_OK;
428 }
429 
430 //////////////////////////////////////////////////////////////////////////////////////////
431 // Get the baudrate that is currently being used by the port
433 {
434  CMT3LOG("L3: getBaudrate\n");
435  CMT3EXITLOG;
436 
437  if (!m_serial.isOpen()) return m_lastResult = XRV_NOPORTOPEN;
438  baudrate = m_baudrate;
439  return m_lastResult = XRV_OK;
440 }
441 
442 //////////////////////////////////////////////////////////////////////////////////////////
443 // Get the state of the bluetooth communication, on (true) or off (false)
445 {
446  CMT3LOG("L3: getBluetoothState\n");
447  CMT3EXITLOG;
448 
450  enabled =
451  (rcv.getDataByte() == 0); // invert the result as it is a disable field
452  return m_lastResult = XRV_OK;
453 }
454 
455 //////////////////////////////////////////////////////////////////////////////////////////
456 // Retrieve the BusId of a device.
458  uint8_t& busId, const CmtDeviceId deviceId) const
459 {
460  CMT3LOG("L3: getBusId %08x\n", deviceId);
461  CMT3EXITLOG;
462 
464  {
465  busId = CMT_BID_MASTER;
466  return m_lastResult = XRV_OK;
467  }
468 
469  for (uint16_t i = 0; i <= m_config.m_numberOfDevices; ++i)
471  {
472  busId = i + 1;
473  return m_lastResult = XRV_OK;
474  }
475  return m_lastResult = XRV_NOTFOUND;
476 }
477 
478 //////////////////////////////////////////////////////////////////////////////////////////
480 {
481  if (devId == CMT_DID_MASTER) return CMT_BID_MASTER;
482 
483  if (devId == CMT_DID_BROADCAST) return CMT_BID_BROADCAST;
484 
485  if (m_config.m_masterDeviceId == devId) return CMT_BID_MASTER;
486 
487  for (uint16_t i = 0; i <= m_config.m_numberOfDevices; ++i)
488  {
489  if (m_config.m_deviceInfo[i].m_deviceId == devId)
490  return (uint8_t)(i + 1);
491  }
492  return CMT_BID_INVALID;
493 }
494 
495 //////////////////////////////////////////////////////////////////////////////////////////
496 // Retrieve the XM bus power state.
498 {
499  CMT3LOG("L3: getBusPowerState\n");
500  CMT3EXITLOG;
501 
503  enabled =
504  (rcv.getDataShort() !=
505  0); // invert the result as it is a disable field
506  return m_lastResult = XRV_OK;
507 }
508 
509 //////////////////////////////////////////////////////////////////////////////////////////
510 Cmt2f* Cmt3::getCmt2f(void) { return &m_logFile; }
511 //////////////////////////////////////////////////////////////////////////////////////////
512 Cmt2s* Cmt3::getCmt2s(void) { return &m_serial; }
513 //////////////////////////////////////////////////////////////////////////////////////////
514 // Retrieve the complete device configuration of a device.
516 {
517  CMT3LOG("L3: getConfiguration\n");
518  CMT3EXITLOG;
519 
520  if (!(m_serial.isOpen() || m_logFile.isOpen()))
522 
523  memcpy(&configuration, &m_config, sizeof(CmtDeviceConfiguration));
524 
525  if (m_logging)
526  {
527  // fake the message receipt
528  Message msg(
532 
539  memcpy(msg.getDataBuffer(16), m_config.m_date, 8);
540  memcpy(msg.getDataBuffer(24), m_config.m_time, 8);
544 
545  for (uint16_t i = 0; i < m_config.m_numberOfDevices; ++i)
546  {
547  msg.setDataLong(m_config.m_deviceInfo[i].m_deviceId, 98 + i * 20);
548  msg.setDataShort(
549  m_config.m_deviceInfo[i].m_dataLength, 102 + i * 20);
550  msg.setDataShort(
551  m_config.m_deviceInfo[i].m_outputMode, 104 + i * 20);
552  msg.setDataLong(
553  m_config.m_deviceInfo[i].m_outputSettings, 106 + i * 20);
554  memcpy(
555  msg.getDataBuffer(110 + i * 20),
557  }
558 
559  msg.recomputeChecksum();
560 
562  }
563  return m_lastResult = XRV_OK;
564 }
565 
566 //////////////////////////////////////////////////////////////////////////////////////////
567 // Retrieve the number of bytes that are in a data message as sent by the
568 // device.
571 {
572  CMT3LOG("L3: getDataLength %08x\n", deviceId);
573  CMT3EXITLOG;
574 
576  length = rcv.getDataShort(); // the sensor returns this value as a int16_t
577  return m_lastResult = XRV_OK;
578 }
579 
580 //////////////////////////////////////////////////////////////////////////////////////////
581 // Return the number of connected devices. Returns 0 if not connected.
583 {
584  CMT3LOG("L3: getDeviceCount\n");
585  if (m_serial.isOpen() || m_logFile.isOpen())
586  {
587  if (isXm())
588  return m_config.m_numberOfDevices + 1;
589  else
591  }
592  return 0;
593 }
594 
595 //////////////////////////////////////////////////////////////////////////////////////////
596 // Retrieve the CmtDeviceId of the device at the given BusId
598  const uint8_t busId, CmtDeviceId& deviceId) const
599 {
600  CMT3LOG("L3: getDeviceId %u\n", (uint32_t)busId);
601  CMT3EXITLOG;
602 
603  if (busId == CMT_BID_MASTER || busId == 0)
605  else
606  {
607  if (busId > m_config.m_numberOfDevices)
608  return m_lastResult = XRV_INVALIDID;
610  }
611  return m_lastResult = XRV_OK;
612 }
613 
614 //////////////////////////////////////////////////////////////////////////////////////////
615 // Retrieve the complete device output mode of a device.
618 {
619  CMT3LOG("L3: getDeviceMode %08x\n", deviceId);
620  CMT3EXITLOG;
621 
622  CmtDeviceMode2 mode2;
623  XsensResultValue rv;
624  rv = getDeviceMode2(mode2, deviceId);
625  if (rv == XRV_OK)
626  {
627  mode.m_outputMode = mode2.m_outputMode;
628  mode.m_outputSettings = mode2.m_outputSettings;
629  mode.m_sampleFrequency = mode2.getSampleFrequency();
630  }
631  return rv;
632 }
633 
634 //////////////////////////////////////////////////////////////////////////////////////////
635 // Retrieve the complete device output mode of a device.
638 {
639  CMT3LOG("L3: getDeviceMode2 %08x\n", deviceId);
640  CMT3EXITLOG;
641 
643  if (bid == CMT_BID_INVALID) return m_lastResult = XRV_INVALIDID;
644  if (bid == 0) return m_lastResult = XRV_INVALIDID;
645  if (bid == CMT_BID_MASTER) bid = 1;
646 
647  mode.m_period = m_period;
648  mode.m_skip = m_skip;
649  // mode.m_sampleFrequency = (uint16_t) floor(m_sampleFrequency+0.5);
650  mode.m_outputMode = m_config.m_deviceInfo[bid - 1].m_outputMode;
651  mode.m_outputSettings = m_config.m_deviceInfo[bid - 1].m_outputSettings;
652 
653  return m_lastResult = XRV_OK;
654 }
655 
656 //////////////////////////////////////////////////////////////////////////////////////////
657 // Retrieve the eMts data of the specified sensor(s)
659 {
660  CMT3LOG("L3: getEMtsData %p %08x\n", buffer, deviceId);
661  CMT3EXITLOG;
662 
664  if (bid == CMT_BID_INVALID) return m_lastResult = XRV_INVALIDID;
665  if (!m_readFromFile && !m_serial.isOpen())
666  return m_lastResult = XRV_NOPORTOPEN;
667  if (m_readFromFile && !m_logFile.isOpen())
668  return m_lastResult = XRV_NOFILEOPEN;
669  if (buffer == nullptr) return m_lastResult = XRV_NULLPTR;
670 
671  if (bid == CMT_BID_BROADCAST)
672  {
674  auto* buf = (uint8_t*)buffer;
675  // loop over devices and request emts data for all of them
676  for (uint32_t dev = 0; dev < m_config.m_numberOfDevices; ++dev)
677  if (getEMtsData(
678  buf + dev * CMT_EMTS_SIZE,
680  return m_lastResult;
681  // CMT3LOG("L3: getEMtsData (%08x) returns
682  // %d\n",deviceId,(int32_t)m_lastResult);
683  return m_lastResult;
684  }
685 
686  uint8_t dataIndex;
687 
688  if (isXm())
689  {
690  if (bid == CMT_BID_MASTER)
691  {
692  // CMT3LOG("L3: getEMtsData (%08x) returns
693  // XRV_INVALIDID\n",deviceId);
694  return m_lastResult = XRV_INVALIDID;
695  }
696  dataIndex = bid - 1;
697  }
698  else
699  dataIndex = 0; // when we have a single MT, we should use bank 0
700 
701  if (m_eMtsData[dataIndex] == nullptr)
702  {
703  m_eMtsData[dataIndex] = malloc(CMT_EMTS_SIZE);
704 
705 // Xbus requires small data packets
706 #if 0
707  if (isXm())
708  {
709  Message msg(CMT_MID_REQEMTS,3);
710  Message rcv;
711  uint8_t* tme = (uint8_t*) m_eMtsData[dataIndex];
712  memset(tme,0,CMT_EMTS_SIZE); // clear eMTS data
713  msg.setBusId(bid);
714  msg.setDataByte(0,0); // read bank 0
715  uint16_t emtPos = 0;
716  for (uint8_t page=0;page < 4;++page) // read all 4 pages, one at a time
717  {
718  msg.setDataByte(page,1);
719  for (uint8_t part=0;part < 4;++part, ++emtPos)
720  {
721  if (!m_readFromFile)
722  {
723  msg.setDataByte(part,2);
724  m_serial.writeMessage(&msg);
726  }
727  else
729 
730  if (m_lastResult != XRV_OK)
731  {
732  FREENUL(m_eMtsData[dataIndex]);
733  //CMT3LOG("L3: getEMtsData (%08x) returns %d\n",deviceId,(int32_t)m_lastResult);
734  return m_lastResult;
735  }
736  if (!m_readFromFile && m_logging)
737  m_logFile.writeMessage(&rcv);
738  if (rcv.getMessageId() == CMT_MID_ERROR)
739  {
741  if (rcv.getDataSize() >= 2)
742  {
743  uint8_t biddy = rcv.getDataByte(1);
745  }
747  FREENUL(m_eMtsData[dataIndex]);
748  //CMT3LOG("L3: getEMtsData (%08x) returns %d\n",deviceId,(int32_t)m_lastResult);
749  return m_lastResult;
750  }
751 
752  memcpy(tme+(emtPos*66),rcv.getDataBuffer(),66);
753  }
754  }
755  } // if (isXm())
756  else // single MT, ask in one packet
757  {
758 #endif
759  Message msg(CMT_MID_REQEMTS, 2);
760  Message rcv;
761  memset(m_eMtsData[dataIndex], 0, CMT_EMTS_SIZE); // clear eMTS data
762  msg.setBusId(bid);
763  msg.setDataByte(0, 0); // read bank 0
764  msg.setDataByte(255, 1); // read all pages
765 
766  if (!m_readFromFile)
767  {
768  m_serial.writeMessage(&msg);
769  m_lastResult =
770  m_serial.waitForMessage(&rcv, CMT_MID_EMTSDATA, 0, false);
771  }
772  else
774  if (m_lastResult != XRV_OK)
775  {
776  FREENUL(m_eMtsData[dataIndex]);
777  // CMT3LOG("L3: getEMtsData (%08x) returns
778  // %d\n",deviceId,(int32_t)m_lastResult);
779  return m_lastResult;
780  }
782  if (rcv.getMessageId() == CMT_MID_ERROR)
783  {
785  if (rcv.getDataSize() >= 2)
786  {
787  uint8_t biddy = rcv.getDataByte(1);
789  }
791  FREENUL(m_eMtsData[dataIndex]);
792  // CMT3LOG("L3: getEMtsData (%08x) returns
793  // %d\n",deviceId,(int32_t)m_lastResult);
794  return m_lastResult;
795  }
796 
797  memcpy(m_eMtsData[dataIndex], rcv.getDataBuffer(), CMT_EMTS_SIZE);
798 #if 0
799  }
800 #endif
801  }
802  else if (m_logging)
803  {
804  // fake the message receipt
806  msg.setBusId(bid);
807  msg.setDataBuffer(
808  (const uint8_t*)m_eMtsData[dataIndex], 0, CMT_EMTS_SIZE);
810  }
811 
812  memcpy(buffer, m_eMtsData[dataIndex], CMT_EMTS_SIZE);
813  // CMT3LOG("L3: getEMtsData (%08x) returns XRV_OK\n",deviceId);
814  return m_lastResult = XRV_OK;
815 }
816 
817 //////////////////////////////////////////////////////////////////////////////////////////
818 // Retrieve the error mode
820 {
821  CMT3LOG("L3: getErrorMode %08x\n", deviceId);
822  CMT3EXITLOG;
823 
824  if (isXm())
825  {
827  mode = rcv.getDataShort();
828  }
829  else
830  {
832  mode = rcv.getDataShort();
833  }
834  return m_lastResult = XRV_OK;
835 }
836 
837 #if 0
838 obsolete:
839 //////////////////////////////////////////////////////////////////////////////////////////
840 // Retrieve the filter settings of a device.
841 XsensResultValue Cmt3::getFilterSettings(CmtFilterSettings& settings, const CmtDeviceId deviceId)
842 {
843  Message snd;
844  Message rcv;
846  if (bid == CMT_BID_INVALID)
847  return (m_lastResult = XRV_INVALIDID);
848 
849  bool xm = isXm();
850 
851  if (xm && deviceId == m_config.m_masterDeviceId)
853 
854  if (!xm)
855  bid = CMT_BID_MASTER;
856 
857  // first setting: gain
858  snd.setBusId(bid);
859  snd.setDataByte(0);
861  m_serial.writeMessage(&snd);
863  if (m_lastResult != XRV_OK)
864  return m_lastResult;
865  if (m_logging)
866  m_logFile.writeMessage(&rcv);
868  settings.m_gain = rcv.getDataFloat(1);
869 
870  // second setting: weighting
871  snd.setBusId(bid);
872  snd.setDataByte(1);
874  m_serial.writeMessage(&snd);
876  if (m_lastResult != XRV_OK)
877  return m_lastResult;
878  if (m_logging)
879  m_logFile.writeMessage(&rcv);
881  settings.m_weighting = rcv.getDataFloat(1);
882 
883  return m_lastResult = XRV_OK;
884 }
885 #endif
886 
887 //////////////////////////////////////////////////////////////////////////////////////////
888 // Retrieve the firmware revision of a device.
890  CmtVersion& revision, const CmtDeviceId deviceId)
891 {
892  CMT3LOG("L3: getFirmwareRevision %08x\n", deviceId);
893  CMT3EXITLOG;
894 
896 
897  revision.m_major = rcv.getDataByte(0);
898  revision.m_minor = rcv.getDataByte(1);
899  revision.m_revision = rcv.getDataByte(2);
900 
901  return m_lastResult = XRV_OK;
902 }
903 
904 //////////////////////////////////////////////////////////////////////////////////////////
905 // Retrieve the heading offset of a device. The range is -pi to +pi.
907 {
908  CMT3LOG("L3: getHeading %08x\n", deviceId);
909  CMT3EXITLOG;
910 
912  heading = rcv.getDataFloat();
913  return m_lastResult = XRV_OK;
914 }
915 
916 //////////////////////////////////////////////////////////////////////////////////////////
917 // Retrieve the location ID of a device. The buffer should be at least 20 bytes.
919  uint16_t& locationId, const CmtDeviceId deviceId)
920 {
921  CMT3LOG("L3: getLocationId %08x\n", deviceId);
922  CMT3EXITLOG;
923 
925  locationId = rcv.getDataShort();
926  return m_lastResult = XRV_OK;
927 }
928 
929 //////////////////////////////////////////////////////////////////////////////////////////
930 // Retrieve the current log file read position
932 {
933  CMT3LOG("L3: getLogFileReadPosition\n");
934  CMT3EXITLOG;
935 
936  if (m_logFile.isOpen())
937  {
938  pos = m_logFile.getReadPosition();
939  return m_lastResult = XRV_OK;
940  }
941  pos = 0;
942  return m_lastResult = XRV_NOFILEOPEN;
943 }
944 
945 //////////////////////////////////////////////////////////////////////////////////////////
946 // Retrieve the size of the log file
948 {
949  CMT3LOG("L3: getLogFileSize\n");
950  CMT3EXITLOG;
951 
952  if (m_logFile.isOpen())
953  {
955  return m_lastResult = XRV_OK;
956  }
957  size = 0;
958  return m_lastResult = XRV_NOFILEOPEN;
959 }
960 
961 //////////////////////////////////////////////////////////////////////////////////////////
962 // Retrieve the name of the open log file or an empty string if no logfile is
963 // open
965 {
966  CMT3LOG("L3: getLogFileName (char)\n");
967  CMT3EXITLOG;
968 
969  if (m_logFile.isOpen()) return m_lastResult = m_logFile.getName(filename);
970  filename[0] = '\0';
971  return m_lastResult = XRV_NOFILEOPEN;
972 }
973 
974 //////////////////////////////////////////////////////////////////////////////////////////
975 // Retrieve the name of the open log file or an empty string if no logfile is
976 // open
978 {
979  CMT3LOG("L3: getLogFileName (wchar_t)\n");
980  CMT3EXITLOG;
981 
982  if (m_logFile.isOpen()) return m_lastResult = m_logFile.getName(filename);
983  filename[0] = L'\0';
984  return m_lastResult = XRV_NOFILEOPEN;
985 }
986 
987 //////////////////////////////////////////////////////////////////////////////////////////
988 // Return the magnetic declination. The range is -pi to +pi.
990  double& declination, const CmtDeviceId deviceId)
991 {
992  CMT3LOG("L3: getMagneticDeclination %08x\n", deviceId);
993  CMT3EXITLOG;
994 
996  declination = rcv.getDataFloat();
997  return m_lastResult = XRV_OK;
998 }
999 
1000 //////////////////////////////////////////////////////////////////////////////////////////
1001 // Return the device Id of the first device (master)
1003 {
1004  CMT3LOG("L3: getMasterId\n");
1005 
1006  if (m_serial.isOpen() || m_logFile.isOpen())
1007  return m_config.m_masterDeviceId;
1008  return 0;
1009 }
1010 
1011 //////////////////////////////////////////////////////////////////////////////////////////
1012 // Return the nr of connected MTs (excludes XMs)
1014 {
1015  CMT3LOGDAT("L3: getMtCount\n");
1016 
1017  if (m_serial.isOpen() || m_logFile.isOpen())
1018  return m_config.m_numberOfDevices;
1019  return 0;
1020 }
1021 
1022 //////////////////////////////////////////////////////////////////////////////////////////
1023 // Retrieve the CmtDeviceId of the MT device with the given index
1025  const uint8_t index, CmtDeviceId& deviceId) const
1026 {
1027  CMT3LOG("L3: getMtDeviceId %u\n", (uint32_t)index);
1028  CMT3EXITLOG;
1029 
1031  return m_lastResult = XRV_INVALIDPARAM;
1033  return m_lastResult = XRV_OK;
1034 }
1035 
1036 //////////////////////////////////////////////////////////////////////////////////////////
1037 // Retrieve the port that the object is connected to.
1039 {
1040  CMT3LOG("L3: getPortNr\n");
1041  CMT3EXITLOG;
1042 
1043  return m_lastResult = m_serial.getPortNr(port);
1044 }
1045 
1046 //////////////////////////////////////////////////////////////////////////////////////////
1047 // Retrieve the product code of a device. The buffer should be at least 21
1048 // bytes.
1050  char* productCode, const CmtDeviceId deviceId)
1051 {
1052  CMT3LOG("L3: getProductCode %p %08x\n", productCode, deviceId);
1053  CMT3EXITLOG;
1054 
1056 
1057  uint16_t len = rcv.getDataSize();
1058  memcpy(productCode, rcv.getDataBuffer(), len);
1059  productCode[len] = '\0';
1060 
1061  return m_lastResult = XRV_OK;
1062 }
1063 
1064 //////////////////////////////////////////////////////////////////////////////////////////
1065 // Retrieve the sample frequency of the devices on the bus.
1067 {
1068  CMT3LOG("L3: getSampleFrequency\n");
1070  mode.m_period = m_period;
1071  mode.m_skip = m_skip;
1072 
1073  return mode.getSampleFrequency();
1074 }
1075 
1076 //////////////////////////////////////////////////////////////////////////////////////////
1077 // Get the baudrate that is reported for the serial connection
1079 {
1080  CMT3LOG("L3: getSerialBaudrate\n");
1081  CMT3EXITLOG;
1082 
1084  switch (rcv.getDataByte())
1085  {
1086  case CMT_BAUDCODE_9K6:
1087  baudrate = CMT_BAUD_RATE_9600;
1088  break;
1089  // case CMT_BAUDCODE_14K4:
1090  // baudrate = CMT_BAUD_RATE_14K4;
1091  // break;
1092  case CMT_BAUDCODE_19K2:
1093  baudrate = CMT_BAUD_RATE_19K2;
1094  break;
1095  // case CMT_BAUDCODE_28K8:
1096  // baudrate = CMT_BAUD_RATE_28K8;
1097  // break;
1098  case CMT_BAUDCODE_38K4:
1099  baudrate = CMT_BAUD_RATE_38K4;
1100  break;
1101  case CMT_BAUDCODE_57K6:
1102  baudrate = CMT_BAUD_RATE_57K6;
1103  break;
1104  // case CMT_BAUDCODE_76K8:
1105  // baudrate = CMT_BAUD_RATE_76K8;
1106  // break;
1107  case CMT_BAUDCODE_115K2:
1108  baudrate = CMT_BAUD_RATE_115K2;
1109  break;
1110  case CMT_BAUDCODE_230K4:
1111  baudrate = CMT_BAUD_RATE_230K4;
1112  break;
1113  case CMT_BAUDCODE_460K8:
1114  baudrate = CMT_BAUD_RATE_460K8;
1115  break;
1116  case CMT_BAUDCODE_921K6:
1117  baudrate = CMT_BAUD_RATE_921K6;
1118  break;
1119  default:
1121  }
1122  return m_lastResult = XRV_OK;
1123 }
1124 
1125 //////////////////////////////////////////////////////////////////////////////////////////
1126 // Retrieve the inbound synchronization settings of a device.
1128 {
1129  CMT3LOG("L3: getSyncInSettings\n");
1130  CMT3EXITLOG;
1131 
1133  Message rcv;
1134 
1135  snd.setBusId(CMT_BID_MASTER);
1136 
1138  m_serial.writeMessage(&snd);
1139  m_lastResult =
1141  if (m_lastResult != XRV_OK) return m_lastResult;
1142  if (m_logging) m_logFile.writeMessage(&rcv);
1144  settings.m_mode = rcv.getDataShort(1);
1145 
1147  m_serial.writeMessage(&snd);
1148  m_lastResult =
1150  if (m_lastResult != XRV_OK) return m_lastResult;
1151  if (m_logging) m_logFile.writeMessage(&rcv);
1153  settings.m_skipFactor = rcv.getDataShort(1);
1154 
1156  m_serial.writeMessage(&snd);
1157  m_lastResult =
1159  if (m_lastResult != XRV_OK) return m_lastResult;
1160  if (m_logging) m_logFile.writeMessage(&rcv);
1162  settings.m_offset = rcv.getDataLong(1);
1163 
1164  // convert the offset to ns
1165  settings.m_offset = (uint32_t)(
1166  (((double)settings.m_offset) * CMT_SYNC_CLOCK_TICKS_TO_NS) + 0.5);
1167 
1168  return m_lastResult = XRV_OK;
1169 }
1170 
1171 //////////////////////////////////////////////////////////////////////////////////////////
1172 // Retrieve the inbound synchronization mode of a device.
1174 {
1175  CMT3LOG("L3: getSyncInMode\n");
1176  CMT3EXITLOG;
1177 
1179  Message rcv;
1180 
1181  snd.setBusId(CMT_BID_MASTER);
1182 
1184  m_serial.writeMessage(&snd);
1185  m_lastResult =
1187  if (m_lastResult != XRV_OK) return m_lastResult;
1188  if (m_logging) m_logFile.writeMessage(&rcv);
1190  mode = rcv.getDataShort(1);
1191 
1192  return m_lastResult = XRV_OK;
1193 }
1194 
1195 //////////////////////////////////////////////////////////////////////////////////////////
1196 // Retrieve the inbound synchronization skip factor of a device.
1198 {
1199  CMT3LOG("L3: getSyncInSkipFactor\n");
1200  CMT3EXITLOG;
1201 
1203  Message rcv;
1204 
1205  snd.setBusId(CMT_BID_MASTER);
1206 
1208  m_serial.writeMessage(&snd);
1209  m_lastResult =
1211  if (m_lastResult != XRV_OK) return m_lastResult;
1212  if (m_logging) m_logFile.writeMessage(&rcv);
1214  skipFactor = rcv.getDataShort(1);
1215 
1216  return m_lastResult = XRV_OK;
1217 }
1218 
1219 //////////////////////////////////////////////////////////////////////////////////////////
1220 // Retrieve the inbound synchronization offset of a device.
1222 {
1223  CMT3LOG("L3: getSyncInOffset\n");
1224  CMT3EXITLOG;
1225 
1227  Message rcv;
1228 
1229  snd.setBusId(CMT_BID_MASTER);
1230 
1232  m_serial.writeMessage(&snd);
1233  m_lastResult =
1235  if (m_lastResult != XRV_OK) return m_lastResult;
1236  if (m_logging) m_logFile.writeMessage(&rcv);
1238  offset = rcv.getDataLong(1);
1239 
1240  // convert the offset to ns
1241  offset = (uint32_t)((((double)offset) * CMT_SYNC_CLOCK_TICKS_TO_NS) + 0.5);
1242 
1243  return m_lastResult = XRV_OK;
1244 }
1245 
1246 //////////////////////////////////////////////////////////////////////////////////////////
1247 // Get the synchronization mode of the XM
1249 {
1250  CMT3LOG("L3: getSyncMode\n");
1251  CMT3EXITLOG;
1252 
1254  mode = rcv.getDataByte();
1255  return m_lastResult = XRV_OK;
1256 }
1257 
1258 //////////////////////////////////////////////////////////////////////////////////////////
1259 // Retrieve the outbound synchronization settings of a device.
1261 {
1262  CMT3LOG("L3: getSyncOutSettings\n");
1263  CMT3EXITLOG;
1264 
1266  Message rcv;
1267 
1268  snd.setBusId(CMT_BID_MASTER);
1269 
1271  m_serial.writeMessage(&snd);
1272  m_lastResult =
1274  if (m_lastResult != XRV_OK) return m_lastResult;
1275  if (m_logging) m_logFile.writeMessage(&rcv);
1277  settings.m_mode = rcv.getDataShort(1);
1278 
1280  m_serial.writeMessage(&snd);
1281  m_lastResult =
1283  if (m_lastResult != XRV_OK) return m_lastResult;
1284  if (m_logging) m_logFile.writeMessage(&rcv);
1286  settings.m_skipFactor = rcv.getDataShort(1);
1287 
1289  m_serial.writeMessage(&snd);
1290  m_lastResult =
1292  if (m_lastResult != XRV_OK) return m_lastResult;
1293  if (m_logging) m_logFile.writeMessage(&rcv);
1295  settings.m_offset = rcv.getDataLong(1);
1296 
1298  m_serial.writeMessage(&snd);
1299  m_lastResult =
1301  if (m_lastResult != XRV_OK) return m_lastResult;
1302  if (m_logging) m_logFile.writeMessage(&rcv);
1304  settings.m_pulseWidth = rcv.getDataLong(1);
1305 
1306  // convert the offset and pulse width to ns
1307  settings.m_offset = (uint32_t)(
1308  (((double)settings.m_offset) * CMT_SYNC_CLOCK_TICKS_TO_NS) + 0.5);
1309  settings.m_pulseWidth = (uint32_t)(
1310  (((double)settings.m_pulseWidth) * CMT_SYNC_CLOCK_TICKS_TO_NS) + 0.5);
1311 
1312  return m_lastResult = XRV_OK;
1313 }
1314 
1315 //////////////////////////////////////////////////////////////////////////////////////////
1316 // Retrieve the outbound synchronization mode of a device.
1318 {
1319  CMT3LOG("L3: getSyncOutMode\n");
1320  CMT3EXITLOG;
1321 
1323  Message rcv;
1324 
1325  snd.setBusId(CMT_BID_MASTER);
1326 
1328  m_serial.writeMessage(&snd);
1329  m_lastResult =
1331  if (m_lastResult != XRV_OK) return m_lastResult;
1332  if (m_logging) m_logFile.writeMessage(&rcv);
1334  mode = rcv.getDataShort(1);
1335 
1336  return m_lastResult = XRV_OK;
1337 }
1338 
1339 //////////////////////////////////////////////////////////////////////////////////////////
1340 // Retrieve the outbound synchronization pulse width of a device.
1342 {
1343  CMT3LOG("L3: getSyncOutPulseWidth\n");
1344  CMT3EXITLOG;
1345 
1347  Message rcv;
1348 
1349  snd.setBusId(CMT_BID_MASTER);
1350 
1352  m_serial.writeMessage(&snd);
1353  m_lastResult =
1355  if (m_lastResult != XRV_OK) return m_lastResult;
1356  if (m_logging) m_logFile.writeMessage(&rcv);
1358  pulseWidth = rcv.getDataLong(1);
1359 
1360  // convert the pulse width to ns
1361  pulseWidth =
1362  (uint32_t)((((double)pulseWidth) * CMT_SYNC_CLOCK_TICKS_TO_NS) + 0.5);
1363 
1364  return m_lastResult = XRV_OK;
1365 }
1366 
1367 //////////////////////////////////////////////////////////////////////////////////////////
1368 // Retrieve the outbound synchronization skip factor of a device.
1370 {
1371  CMT3LOG("L3: getSyncOutSkipFactor\n");
1372  CMT3EXITLOG;
1373 
1375  Message rcv;
1376 
1377  snd.setBusId(CMT_BID_MASTER);
1378 
1380  m_serial.writeMessage(&snd);
1381  m_lastResult =
1383  if (m_lastResult != XRV_OK) return m_lastResult;
1384  if (m_logging) m_logFile.writeMessage(&rcv);
1386  skipFactor = rcv.getDataShort(1);
1387 
1388  return m_lastResult = XRV_OK;
1389 }
1390 
1391 //////////////////////////////////////////////////////////////////////////////////////////
1392 // Retrieve the outbound synchronization offset of a device.
1394 {
1395  CMT3LOG("L3: getSyncOutOffset\n");
1396  CMT3EXITLOG;
1397 
1399  Message rcv;
1400 
1401  snd.setBusId(CMT_BID_MASTER);
1402 
1404  m_serial.writeMessage(&snd);
1405  m_lastResult =
1407  if (m_lastResult != XRV_OK) return m_lastResult;
1408  if (m_logging) m_logFile.writeMessage(&rcv);
1410  offset = rcv.getDataLong(1);
1411 
1412  // convert the offset to ns
1413  offset = (uint32_t)((((double)offset) * CMT_SYNC_CLOCK_TICKS_TO_NS) + 0.5);
1414 
1415  return m_lastResult = XRV_OK;
1416 }
1417 
1418 //////////////////////////////////////////////////////////////////////////////////////////
1420 //////////////////////////////////////////////////////////////////////////////////////////
1422 //////////////////////////////////////////////////////////////////////////////////////////
1423 // Retrieve the UTC time of the last received sample
1425 {
1426  CMT3LOG("L3: getUtcTime %08x\n", deviceId);
1427  CMT3EXITLOG;
1428 
1430 
1431  utc.m_nano = rcv.getDataLong(0);
1432  utc.m_year = rcv.getDataShort(4);
1433  utc.m_month = rcv.getDataByte(6);
1434  utc.m_day = rcv.getDataByte(7);
1435  utc.m_hour = rcv.getDataByte(8);
1436  utc.m_minute = rcv.getDataByte(9);
1437  utc.m_second = rcv.getDataByte(10);
1438  utc.m_valid = rcv.getDataByte(11);
1439 
1440  // if (utc.m_valid == 0)
1441  // return m_lastResult = XRV_INVALID_TIME;
1442 
1443  return m_lastResult = XRV_OK;
1444 }
1445 
1446 //////////////////////////////////////////////////////////////////////////////////////////
1447 // Get the dual-mode output settings of the XM
1449 {
1450  CMT3LOG("L3: getXmOutputMode\n");
1451  CMT3EXITLOG;
1452 
1454  mode = rcv.getDataByte();
1455  return m_lastResult = XRV_OK;
1456 }
1457 
1458 //////////////////////////////////////////////////////////////////////////////////////////
1459 // Place all connected sensors into Configuration Mode.
1461 {
1462  CMT3LOG(
1463  "L3: gotoConfig port %u\n", (uint32_t)m_serial.getCmt1s()->getPortNr());
1464  CMT3EXITLOG;
1465 
1467  Message rcv;
1468  int32_t tries = 0;
1469 
1470  srand((unsigned int)timeStampNow());
1471 
1473  snd.setBusId(CMT_BID_MASTER);
1474  while (tries++ < m_gotoConfigTries)
1475  {
1476  m_serial.getCmt1s()->flushData(); // special case for goto config. we
1477  // want the buffer to be empty
1478  CMT3LOG("L3: Attempt to goto config %d\n", tries);
1479  m_serial.writeMessage(&snd);
1480  m_lastResult =
1482  if (m_lastResult == XRV_TIMEOUTNODATA) break;
1483  if (m_lastResult == XRV_OK)
1484  {
1485  if (m_logging) m_logFile.writeMessage(&rcv);
1486  if (rcv.getMessageId() == CMT_MID_ERROR)
1487  {
1489  if (rcv.getDataSize() >= 2)
1490  {
1491  uint8_t biddy = rcv.getDataByte(1);
1493  }
1495  (XsensResultValue)rcv.getDataByte(0);
1496  CMT3LOG(
1497  "L3: Goto config failed, error received %d: %s\n",
1500  return m_lastResult;
1501  }
1502  CMT3LOG("L3: Goto config succeeded\n");
1503  m_measuring = false;
1505  return m_lastResult = XRV_OK;
1506  }
1508  msleep(((long)rand() * 10) / RAND_MAX);
1509  }
1512  CMT3LOG(
1513  "L3: Goto config returns %d: %s\n", (int32_t)m_lastResult,
1515  return m_lastResult;
1516 }
1517 
1518 //////////////////////////////////////////////////////////////////////////////////////////
1519 // Place all connected sensors into Measurement Mode.
1521 {
1522  CMT3LOG(
1523  "L3: gotoMeasurement port %u\n",
1525  CMT3EXITLOG;
1526 
1528  Message rcv;
1529 
1530  snd.setBusId(CMT_BID_MASTER);
1531 
1532  m_serial.writeMessage(&snd);
1533  m_lastResult =
1535  if (m_lastResult != XRV_OK) return m_lastResult;
1536  if (m_logging) m_logFile.writeMessage(&rcv);
1538 
1539  m_rtcInitialized = false;
1540  m_measuring = true;
1542  return (m_lastResult = XRV_OK);
1543 }
1544 
1546 {
1547  CMT3LOG(
1548  "L3: initBus port %u\n", (uint32_t)m_serial.getCmt1s()->getPortNr());
1549  CMT3EXITLOG;
1550 
1552  return m_lastResult =
1553  XRV_OK; // m_serial.waitForMessage(&rcv,CMT_MID_INITBUSRESULTS);
1554 }
1555 
1556 //////////////////////////////////////////////////////////////////////////////////////////
1557 // Return whether the main device is an Xbus Master or not.
1558 bool Cmt3::isXm(void) const
1559 {
1560  return (
1562 }
1563 
1564 //////////////////////////////////////////////////////////////////////////////////////////
1565 // Open a communication channel to the given serial port name.
1566 XsensResultValue Cmt3::openPort(const char* portName, const uint32_t baudRate)
1567 {
1568  CMT3LOG(
1569  "L3: openPort Opening port %s @baud %d, timeoutC=%u, timeoutM=%u\n",
1570  portName, baudRate, m_timeoutConf, m_timeoutMeas);
1571  CMT3EXITLOG;
1572 
1573  if (m_logFile.isOpen()) return m_lastResult = XRV_ALREADYOPEN;
1574 
1576  if ((m_lastResult = m_serial.open(portName, baudRate)) != XRV_OK)
1577  return m_lastResult;
1578 
1579  CMT3LOG("L3: openPort: Low level port opened, gotoConfig\n");
1580 
1581  m_baudrate = baudRate;
1582  m_rtcInitialized = false;
1583  m_measuring = true; // required for faster operation of refreshCache
1584  m_logging = false;
1585 
1586  // place the device in config mode
1587  if (gotoConfig() != XRV_OK)
1588  {
1589  CMT3LOG(
1590  "L3: openPort: gotoConfig failed: [%d]%s\n", m_lastResult,
1592  m_serial.close();
1593  return XRV_CONFIGCHECKFAIL;
1594  }
1595 
1596  CMT3LOG("L3: openPort: gotoConfig succeeded, requesting initBus\n");
1597  Message snd, rcv;
1598 
1599  if (initBus() != XRV_OK)
1600  {
1601  CMT3LOG(
1602  "L3: openPort: initBus failed: [%d]%s\n", m_lastResult,
1604  m_serial.close();
1605  return XRV_CONFIGCHECKFAIL;
1606  }
1607 
1608  CMT3LOG("L3: openPort: initBus succeeded, cleaning up the cache\n");
1609  if (refreshCache() != XRV_OK)
1610  {
1611  m_serial.close();
1612  CMT3LOG(
1613  "L3: openPort: refreshCache failed: [%d]%s\n", m_lastResult,
1615  return XRV_CONFIGCHECKFAIL;
1616  }
1617 
1618  CMT3LOG("L3: openPort: returning OK\n");
1619  return m_lastResult = XRV_OK;
1620 }
1621 
1622 #ifdef _WIN32
1623 //////////////////////////////////////////////////////////////////////////////////////////
1624 // Open a communication channel to the given COM port number.
1626  const uint32_t portNumber, const uint32_t baudRate)
1627 {
1628  // open the port
1629  CMT3LOG(
1630  "L3: openPort Opening port %d @baud %d, timeoutC=%u, timeoutM=%u\n",
1631  (int32_t)portNumber, baudRate, m_timeoutConf, m_timeoutMeas);
1632  CMT3EXITLOG;
1633 
1634  if (m_logFile.isOpen()) return m_lastResult = XRV_ALREADYOPEN;
1635 
1636  m_serial.setTimeout(m_timeoutConf); // then update L2 (and L1)
1637  if ((m_lastResult = m_serial.open(portNumber, baudRate)) != XRV_OK)
1638  return m_lastResult;
1639 
1640  CMT3LOG("L3: openPort: Low level port opened, gotoConfig\n");
1641 
1642  m_baudrate = baudRate;
1643  m_rtcInitialized = false;
1644  m_measuring = true; // required for faster operation of refreshCache
1645  m_logging = false;
1646 
1647  // place the device in config mode
1648  if (gotoConfig() != XRV_OK)
1649  {
1650  CMT3LOG(
1651  "L3: openPort: gotoConfig failed: [%d]%s\n", m_lastResult,
1653  m_serial.close();
1654  return XRV_CONFIGCHECKFAIL;
1655  }
1656 
1657  CMT3LOG("L3: openPort: gotoConfig succeeded, requesting initBus\n");
1658  Message snd, rcv;
1659 
1660  if (initBus() != XRV_OK)
1661  {
1662  CMT3LOG(
1663  "L3: openPort: initBus failed: [%d]%s\n", m_lastResult,
1665  m_serial.close();
1666  return XRV_CONFIGCHECKFAIL;
1667  }
1668 
1669  CMT3LOG("L3: openPort: initBus succeeded, cleaning up the cache\n");
1670  if (refreshCache() != XRV_OK)
1671  {
1672  m_serial.close();
1673  CMT3LOG(
1674  "L3: openPort: refreshCache failed: [%d]%s\n", m_lastResult,
1676  return XRV_CONFIGCHECKFAIL;
1677  }
1678 
1679  CMT3LOG("L3: openPort: returning OK\n");
1680  return m_lastResult = XRV_OK;
1681 }
1682 #endif
1683 
1684 //////////////////////////////////////////////////////////////////////////////////////////
1685 // Get the MessageId of the next logged message
1687 {
1688  CMT3LOG("L3: peekLogMessageId started\n");
1689  CMT3EXITLOG;
1690 
1692 
1693  Message msg;
1694 
1698 
1699  if (m_lastResult != XRV_OK)
1700  {
1701  CMT3LOG("L3: peekLogMessageId, no messages to be read\n");
1702  return m_lastResult;
1703  }
1704  messageId = msg.getMessageId();
1705  CMT3LOG(
1706  "L3: peekLogMessageId found msg with ID %02x\n", (int32_t)messageId);
1707  return m_lastResult = XRV_OK;
1708 }
1709 
1710 //////////////////////////////////////////////////////////////////////////////////////////
1711 // Retrieve a data message.
1713 {
1714  CMT3LOGDAT("L3: readDataPacket %p %u\n", pack, acceptOther ? 1 : 0);
1716 
1717  if (!m_readFromFile)
1718  {
1719  while (true)
1720  {
1722  if (m_lastResult != XRV_OK)
1723  {
1724  CMT3LOGDAT("L3: readDataPacket, no data messages to be read\n");
1725  return m_lastResult;
1726  }
1727  if (m_logging) m_logFile.writeMessage(&pack->m_msg);
1728  if (pack->m_msg.getMessageId() == CMT_MID_MTDATA)
1729  {
1730  pack->setXbus(
1733  false);
1735  for (uint16_t i = 0; i < m_config.m_numberOfDevices; ++i)
1736  pack->setDataFormat(
1739  pack->m_toa = timeStampNow();
1740  if (m_useRtc) fillRtc(pack);
1741  CMT3LOGDAT("L3: readDataPacket, data message read\n");
1742  return m_lastResult = XRV_OK;
1743  }
1744  else if (pack->m_msg.getMessageId() == CMT_MID_ERROR)
1745  {
1747  if (pack->m_msg.getDataSize() >= 2)
1748  {
1749  uint8_t biddy = pack->m_msg.getDataByte(1);
1751  }
1752  return m_lastResult = m_lastHwError =
1754  }
1755  CMT3LOGDAT(
1756  "L3: readDataPacket, non-data message read: %2x\n",
1757  (int32_t)pack->m_msg.getMessageId());
1758  if (acceptOther)
1759  {
1760  CMT3LOGDAT("L3: accepting other message\n");
1761  return m_lastResult = XRV_OTHER;
1762  }
1763  }
1764  }
1765  else
1766  {
1767  while (true)
1768  {
1770  if (m_lastResult != XRV_OK)
1771  {
1772  CMT3LOGDAT("L3: readDataPacket, no data messages to be read\n");
1773  return m_lastResult;
1774  }
1775  if (pack->m_msg.getMessageId() == CMT_MID_MTDATA)
1776  {
1777  pack->setXbus(
1780  false);
1782  for (uint16_t i = 0; i < m_config.m_numberOfDevices; ++i)
1783  pack->setDataFormat(
1786  pack->m_toa = timeStampNow();
1787  if (m_useRtc) fillRtc(pack);
1788  CMT3LOGDAT("L3: readDataPacket, data message read\n");
1789  return m_lastResult = XRV_OK;
1790  }
1791  else if (pack->m_msg.getMessageId() == CMT_MID_ERROR)
1792  {
1794  if (pack->m_msg.getDataSize() >= 2)
1795  {
1796  uint8_t biddy = pack->m_msg.getDataByte(1);
1798  }
1799  return m_lastResult = m_lastHwError =
1801  }
1802  CMT3LOGDAT(
1803  "L3: readDataPacket, non-data message read: %2x\n",
1804  (int32_t)pack->m_msg.getMessageId());
1805  if (acceptOther)
1806  {
1807  CMT3LOGDAT("L3: accepting other message\n");
1808  return m_lastResult = XRV_OTHER;
1809  }
1810  }
1811  }
1812 }
1813 
1814 //////////////////////////////////////////////////////////////////////////////////////////
1815 // Request a data message and wait for it to arrive.
1817 {
1818  CMT3LOGDAT("L3: requestData %p\n", pack);
1820 
1821  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
1822  Message snd(CMT_MID_REQDATA);
1823  m_serial.writeMessage(&snd);
1824  return readDataPacket(pack);
1825 }
1826 
1827 //////////////////////////////////////////////////////////////////////////////////////////
1828 // Reset all connected sensors.
1830 {
1831  CMT3LOG("L3: reset\n");
1832  CMT3EXITLOG;
1833 
1834  Message snd(CMT_MID_RESET, 0);
1835  Message rcv;
1836  snd.setBusId(CMT_BID_MASTER);
1837  m_serial.writeMessage(&snd);
1839  if (m_lastResult != XRV_OK) return m_lastResult;
1840  if (m_logging) m_logFile.writeMessage(&rcv);
1841  m_measuring = true;
1842  refreshCache();
1843  return m_lastResult = XRV_OK;
1844 }
1845 
1846 //////////////////////////////////////////////////////////////////////////////////////////
1847 //! Perform an orientation reset on a device.
1849  const CmtResetMethod method, const CmtDeviceId deviceId)
1850 {
1851  CMT3LOG("L3: resetOrientation %u %08x\n", (uint32_t)method, deviceId);
1852  CMT3EXITLOG;
1853 
1854  DO_DATA_SET(
1856  (uint16_t)method);
1857  return m_lastResult = XRV_OK;
1858 }
1859 
1860 //////////////////////////////////////////////////////////////////////////////////////////
1861 //! Restore the factory defaults of a device.
1863 {
1864  CMT3LOG("L3: restoreFactoryDefaults %08x\n", deviceId);
1865  CMT3EXITLOG;
1866 
1868  return m_lastResult = XRV_OK;
1869 }
1870 
1871 #if 0
1872 obsolete:
1873 //////////////////////////////////////////////////////////////////////////////////////////
1874 // Set the state (enabled/disabled) of the AMD algorithm
1875 XsensResultValue Cmt3::setAmdState (const bool state, const CmtDeviceId deviceId)
1876 {
1877  CMT3LOG("L3: setAmdState %u %08x\n",state?1:0,deviceId);
1878  CMT3EXITLOG;
1879 
1880  uint16_t dat = ((state)?1:0);
1882  return m_lastResult = XRV_OK;
1883 }
1884 #endif
1885 
1886 //////////////////////////////////////////////////////////////////////////////////////////
1887 // Set the baudrate and reconnect at the new baudrate if successful.
1888 XsensResultValue Cmt3::setBaudrate(const uint32_t baudrate, bool reconnect)
1889 {
1890  CMT3LOG("L3: setBaudrate %u %u\n", baudrate, reconnect ? 1 : 0);
1891  CMT3EXITLOG;
1892 
1893  uint8_t tmp;
1894  switch (baudrate)
1895  {
1896  case CMT_BAUD_RATE_9600:
1897  tmp = CMT_BAUDCODE_9K6;
1898  break;
1899  // case CMT_BAUD_RATE_14K4:
1900  // tmp = CMT_BAUDCODE_14K4;
1901  // break;
1902  case CMT_BAUD_RATE_19K2:
1903  tmp = CMT_BAUDCODE_19K2;
1904  break;
1905  // case CMT_BAUD_RATE_28K8:
1906  // tmp = CMT_BAUDCODE_28K8;
1907  // break;
1908  case CMT_BAUD_RATE_38K4:
1909  tmp = CMT_BAUDCODE_38K4;
1910  break;
1911  case CMT_BAUD_RATE_57K6:
1912  tmp = CMT_BAUDCODE_57K6;
1913  break;
1914  // case CMT_BAUD_RATE_76K8:
1915  // tmp = CMT_BAUDCODE_76K8;
1916  // break;
1917  case CMT_BAUD_RATE_115K2:
1918  tmp = CMT_BAUDCODE_115K2;
1919  break;
1920  case CMT_BAUD_RATE_230K4:
1921  tmp = CMT_BAUDCODE_230K4;
1922  break;
1923  case CMT_BAUD_RATE_460K8:
1924  tmp = CMT_BAUDCODE_460K8;
1925  break;
1926  case CMT_BAUD_RATE_921K6:
1927  tmp = CMT_BAUDCODE_921K6;
1928  break;
1929  default:
1931  }
1932 
1933  if (baudrate != m_baudrate)
1934  {
1937 
1938  if (reconnect)
1939  {
1940  CMT3LOG("L3: sending reset for reconnect\n");
1941  // Reset devices on this port and reopen port @ new baudrate
1942  Message sndReset(CMT_MID_RESET, 0);
1943  Message rcvReset;
1944  sndReset.setBusId(CMT_BID_MASTER);
1945  m_serial.writeMessage(&sndReset);
1946  m_lastResult =
1947  m_serial.waitForMessage(&rcvReset, CMT_MID_RESETACK, 0, false);
1948  if (m_lastResult != XRV_OK) return m_lastResult;
1949  if (m_logging) m_logFile.writeMessage(&rcvReset);
1950  bool wasMeasuring = m_measuring;
1951  m_measuring = true;
1952 
1953  CMT3LOG("L3: reopening port at new baud rate\n");
1954 #ifdef _WIN32
1955  int32_t port;
1956  m_serial.getPortNr(port);
1957  closePort(false);
1958  m_lastResult = openPort(port, baudrate);
1959 #else
1960  char portname[32];
1961  m_serial.getPortName(portname);
1962  closePort(false);
1963  m_lastResult = openPort(portname, baudrate);
1964 #endif
1965  if (m_lastResult != XRV_OK) return m_lastResult;
1966  if (wasMeasuring) gotoMeasurement();
1967  return m_lastResult;
1968  }
1969  }
1970 
1971  return m_lastResult = XRV_OK;
1972 }
1973 
1974 //////////////////////////////////////////////////////////////////////////////////////////
1975 // Set the state of the bluetooth communication to on (true) or off (false)
1977 {
1978  CMT3LOG("L3: setBluetoothState %u\n", enabled ? 1 : 0);
1979  CMT3EXITLOG;
1980 
1981  uint8_t dat = (enabled ? 0 : 1);
1984  return m_lastResult = XRV_OK;
1985 }
1986 
1987 //////////////////////////////////////////////////////////////////////////////////////////
1988 // Switch the XM bus power on or off.
1990 {
1991  CMT3LOG("L3: setBusPowerState %u\n", enabled ? 1 : 0);
1992  CMT3EXITLOG;
1993 
1994  uint16_t tmp = enabled ? 1 : 0;
1996  return m_lastResult = XRV_OK;
1997 }
1998 
1999 //////////////////////////////////////////////////////////////////////////////////////////
2000 // Set the complete device output mode of a device.
2002  const CmtDeviceMode& mode, bool force, const CmtDeviceId deviceId)
2003 {
2004  CMT3LOG(
2005  "L3: setDeviceMode %04x %08x %u %u %08x\n", (uint32_t)mode.m_outputMode,
2006  (uint32_t)mode.m_outputSettings, (uint32_t)mode.m_sampleFrequency,
2007  force ? 1 : 0, deviceId);
2008  CMT3EXITLOG;
2009 
2010  CmtDeviceMode2 mode2;
2011  mode2.m_outputMode = mode.m_outputMode;
2012  mode2.m_outputSettings = mode.m_outputSettings;
2013  mode2.setSampleFrequency(mode.m_sampleFrequency);
2014 
2015  return setDeviceMode2(mode2, force, deviceId);
2016 }
2017 
2018 //////////////////////////////////////////////////////////////////////////////////////////
2019 // Set the complete device output mode of a device.
2021  const CmtDeviceMode2& mode, bool force, const CmtDeviceId deviceId)
2022 {
2023  CMT3LOG(
2024  "L3: setDeviceMode2 %04x %08x %u %u %u %08x\n",
2025  (uint32_t)mode.m_outputMode, (uint32_t)mode.m_outputSettings,
2026  (uint32_t)mode.m_period, (uint32_t)mode.m_skip, force ? 1 : 0,
2027  deviceId);
2028  CMT3EXITLOG;
2029 
2030  Message snd;
2031  Message rcv;
2033  if (bid == CMT_BID_INVALID) return (m_lastResult = XRV_INVALIDID);
2034 
2035  // uint16_t period, skip;
2036  // mode.getPeriodAndSkipFactor(period, skip);
2037  uint16_t xperiod;
2038  // bool changed = false;
2039 
2040  bool xm = isXm();
2041  if (bid == CMT_BID_BROADCAST)
2042  {
2043  if (xm)
2044  {
2045  // set the device modes of all connected devices first
2046  for (uint16_t i = 0; i < m_config.m_numberOfDevices; ++i)
2048  mode, force, m_config.m_deviceInfo[i].m_deviceId)) !=
2049  XRV_OK)
2050  return m_lastResult;
2051  }
2052  bid = CMT_BID_MASTER;
2053  }
2054 
2055  // set sample frequency if this is an Xbus Master or the primary device
2057  {
2058  m_period = mode.m_period;
2059  m_skip = mode.m_skip;
2060  // m_sampleFrequency = (double) mode.getSampleFrequency();
2061  snd.setBusId(CMT_BID_MASTER);
2062  if (xm)
2063  xperiod = mode.m_period * (mode.m_skip + 1);
2064  else
2065  xperiod = mode.m_period;
2066 
2067  if (force || m_config.m_samplingPeriod != xperiod)
2068  {
2069  CMT3LOG(
2070  "L3: setDeviceMode setting device %08x period to %u\n",
2071  deviceId, (uint32_t)xperiod);
2072  // changed = true;
2073  snd.setDataShort(xperiod);
2075  m_serial.writeMessage(&snd);
2076  m_lastResult =
2078  if (m_lastResult != XRV_OK) return m_lastResult;
2079  if (m_logging) m_logFile.writeMessage(&rcv);
2081  m_config.m_samplingPeriod = xperiod; // update device info
2082  }
2083 
2084  if (!xm && (force || m_config.m_outputSkipFactor != mode.m_skip))
2085  {
2086  CMT3LOG(
2087  "L3: setDeviceMode setting MT %08x skip factor to %u\n",
2088  deviceId, (uint32_t)mode.m_skip);
2089  // changed = true;
2090  snd.setDataShort(mode.m_skip);
2092  m_serial.writeMessage(&snd);
2094  &rcv, CMT_MID_REQOUTPUTSKIPFACTORACK, 0, true);
2095  if (m_lastResult != XRV_OK) return m_lastResult;
2096  if (m_logging) m_logFile.writeMessage(&rcv);
2098  m_config.m_outputSkipFactor = mode.m_skip; // update device info
2099  }
2100  }
2101 
2102  // set the output mode and settings if this device is not an Xbus Master
2104  {
2105  if (bid == CMT_BID_BROADCAST || bid == CMT_BID_MASTER)
2106  {
2107  snd.setBusId(CMT_BID_MASTER);
2108  bid = 1;
2109  }
2110  else
2111  snd.setBusId(bid);
2112 
2113  if (force || m_config.m_deviceInfo[bid - 1].m_outputMode !=
2114  (uint16_t)mode.m_outputMode)
2115  {
2116  CMT3LOG(
2117  "L3: setDeviceMode setting MT %08x output mode to %04X\n",
2118  deviceId, (uint32_t)mode.m_outputMode);
2119  // changed = true;
2120  snd.resizeData(2);
2122  snd.setDataShort((uint16_t)mode.m_outputMode);
2123  m_serial.writeMessage(&snd);
2125  &rcv, CMT_MID_REQOUTPUTMODEACK, 0, true);
2126  if (m_lastResult != XRV_OK) return m_lastResult;
2127  if (m_logging) m_logFile.writeMessage(&rcv);
2130  (uint16_t)mode.m_outputMode; // update device info
2131  }
2132 
2133  auto settings = (uint32_t)mode.m_outputSettings;
2134  if (xm) settings &= ~(uint32_t)CMT_OUTPUTSETTINGS_TIMESTAMP_MASK;
2135 
2136  if (force ||
2137  m_config.m_deviceInfo[bid - 1].m_outputSettings != settings)
2138  {
2139  CMT3LOG(
2140  "L3: setDeviceMode setting MT %08x output settings to %08X\n",
2141  deviceId, (uint32_t)settings);
2142  // changed = true;
2144  snd.setDataLong(settings);
2145  m_serial.writeMessage(&snd);
2147  &rcv, CMT_MID_REQOUTPUTSETTINGSACK, 0, true);
2148  if (m_lastResult != XRV_OK) return m_lastResult;
2149  if (m_logging) m_logFile.writeMessage(&rcv);
2152  settings; // update device info
2153  }
2154  }
2155 
2156  return m_lastResult = XRV_OK;
2157 }
2158 
2159 //////////////////////////////////////////////////////////////////////////////////////////
2160 // Retrieve the error mode
2162 {
2163  CMT3LOG("L3: setErrorMode %u\n", (uint32_t)mode);
2164  CMT3EXITLOG;
2165 
2166  uint8_t mid;
2167  if (isXm())
2168  mid = CMT_MID_REQXMERRORMODE;
2169  else
2170  mid = CMT_MID_REQERRORMODE;
2171 
2173  return m_lastResult = XRV_OK;
2174 }
2175 
2176 //////////////////////////////////////////////////////////////////////////////////////////
2177 // Set the number of times the gotoConfig function will attempt gotoConfig
2178 // before failing
2180 {
2181  CMT3LOG("L3: setGotoConfigTries %u\n", (uint32_t)tries);
2182  CMT3EXITLOG;
2183 
2184  m_gotoConfigTries = tries;
2185  return m_lastResult = XRV_OK;
2186 }
2187 
2188 //////////////////////////////////////////////////////////////////////////////////////////
2189 // Set the heading offset of a device. The valid range is -pi to +pi.
2191  const double heading, const CmtDeviceId deviceId)
2192 {
2193  CMT3LOG("L3: setHeading %f %08x\n", heading, deviceId);
2194  CMT3EXITLOG;
2195 
2196  DO_DATA_SET(CMT_MID_REQHEADING, CMT_LEN_HEADING, Float, (float)heading);
2197  return m_lastResult = XRV_OK;
2198 }
2199 
2200 //////////////////////////////////////////////////////////////////////////////////////////
2201 // Set the location ID of a device. The buffer should be no more than 20 bytes.
2203  uint16_t locationId, const CmtDeviceId deviceId)
2204 {
2205  CMT3LOG("L3: setLocationId %u %08x\n", (uint32_t)locationId, deviceId);
2206  CMT3EXITLOG;
2207 
2209  return m_lastResult = XRV_OK;
2210 }
2211 
2212 //////////////////////////////////////////////////////////////////////////////////////////
2213 // Set the magnetic declination offset of a device. The valid range is -pi to
2214 // +pi.
2216  const double declination, const CmtDeviceId deviceId)
2217 {
2218  CMT3LOG("L3: setMagneticDeclination %f %08x\n", declination, deviceId);
2219  CMT3EXITLOG;
2220 
2221  DO_DATA_SET(
2223  (float)declination);
2224  return m_lastResult = XRV_OK;
2225 }
2226 
2227 //////////////////////////////////////////////////////////////////////////////////////////
2228 // Switch the XM off
2230 {
2231  CMT3LOG("L3: setXmPowerOff\n");
2232  CMT3EXITLOG;
2233 
2234  if (!isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2235  Message snd(CMT_MID_XMPWROFF, 0);
2236  snd.setBusId(CMT_BID_MASTER);
2237  return m_lastResult = m_serial.writeMessage(&snd);
2238 }
2239 
2240 //////////////////////////////////////////////////////////////////////////////////////////
2241 // Set the inbound synchronization settings of a device.
2243 {
2244  CMT3LOG(
2245  "L3: setSyncInSettings %u %u %u\n", (uint32_t)settings.m_mode,
2246  settings.m_offset, (uint32_t)settings.m_skipFactor);
2247  CMT3EXITLOG;
2248 
2249  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2250 
2252  Message rcv;
2253 
2254  snd.setBusId(CMT_BID_MASTER);
2255 
2257  snd.setDataShort(settings.m_mode, 1);
2258  m_serial.writeMessage(&snd);
2259  m_lastResult =
2261  if (m_lastResult != XRV_OK) return m_lastResult;
2262  if (m_logging) m_logFile.writeMessage(&rcv);
2264 
2266  snd.setDataShort(settings.m_skipFactor, 1);
2267  m_serial.writeMessage(&snd);
2268  m_lastResult =
2270  if (m_lastResult != XRV_OK) return m_lastResult;
2271  if (m_logging) m_logFile.writeMessage(&rcv);
2273 
2275  snd.setDataLong(
2276  (uint32_t)(
2277  ((double)settings.m_offset) * CMT_SYNC_CLOCK_NS_TO_TICKS + 0.5),
2278  1);
2279  m_serial.writeMessage(&snd);
2280  m_lastResult =
2282  if (m_lastResult == XRV_OK)
2283  {
2284  if (m_logging) m_logFile.writeMessage(&rcv);
2286  }
2287 
2288  return m_lastResult;
2289 }
2290 
2291 //////////////////////////////////////////////////////////////////////////////////////////
2292 // Set the inbound synchronization mode of a device.
2294 {
2295  CMT3LOG("L3: setSyncInMode %u\n", (uint32_t)mode);
2296  CMT3EXITLOG;
2297 
2298  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2299 
2301  Message rcv;
2302 
2303  snd.setBusId(CMT_BID_MASTER);
2304 
2306  snd.setDataShort(mode, 1);
2307  m_serial.writeMessage(&snd);
2308  m_lastResult =
2310  if (m_lastResult != XRV_OK) return m_lastResult;
2311  if (m_logging) m_logFile.writeMessage(&rcv);
2313 
2314  return m_lastResult;
2315 }
2316 
2317 //////////////////////////////////////////////////////////////////////////////////////////
2318 // Set the inbound synchronization skip factor of a device.
2320 {
2321  CMT3LOG("L3: setSyncInSettings %u\n", skipFactor);
2322  CMT3EXITLOG;
2323 
2324  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2325 
2327  Message rcv;
2328 
2329  snd.setBusId(CMT_BID_MASTER);
2330 
2332  snd.setDataShort(skipFactor, 1);
2333  m_serial.writeMessage(&snd);
2334  m_lastResult =
2336  if (m_lastResult != XRV_OK) return m_lastResult;
2337  if (m_logging) m_logFile.writeMessage(&rcv);
2339 
2340  return m_lastResult;
2341 }
2342 
2343 //////////////////////////////////////////////////////////////////////////////////////////
2344 // Set the inbound synchronization offset of a device.
2346 {
2347  CMT3LOG("L3: setSyncInSettings %u\n", offset);
2348  CMT3EXITLOG;
2349 
2350  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2351 
2353  Message rcv;
2354 
2355  snd.setBusId(CMT_BID_MASTER);
2356 
2358  snd.setDataLong(
2359  (uint32_t)(((double)offset) * CMT_SYNC_CLOCK_NS_TO_TICKS + 0.5), 1);
2360  m_serial.writeMessage(&snd);
2361  m_lastResult =
2363  if (m_lastResult == XRV_OK)
2364  {
2365  if (m_logging) m_logFile.writeMessage(&rcv);
2367  }
2368 
2369  return m_lastResult;
2370 }
2371 
2372 //////////////////////////////////////////////////////////////////////////////////////////
2373 // Set the synchronization mode of the XM
2375 {
2376  CMT3LOG("L3: setSyncMode %u\n", (uint32_t)mode);
2377  CMT3EXITLOG;
2378 
2379  if (!isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2380 
2383  return m_lastResult = XRV_OK;
2384 }
2385 
2386 //////////////////////////////////////////////////////////////////////////////////////////
2387 // Set the outbound synchronization settings of a device.
2389 {
2390  CMT3LOG(
2391  "L3: setSyncOutSettings %u %u %u %u\n", (uint32_t)settings.m_mode,
2392  settings.m_offset, (uint32_t)settings.m_pulseWidth,
2393  (uint32_t)settings.m_skipFactor);
2394  CMT3EXITLOG;
2395 
2396  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2397 
2399  Message rcv;
2400 
2401  snd.setBusId(CMT_BID_MASTER);
2402 
2404  snd.setDataShort(settings.m_mode, 1);
2405  m_serial.writeMessage(&snd);
2406  m_lastResult =
2408  if (m_lastResult != XRV_OK) return m_lastResult;
2409  if (m_logging) m_logFile.writeMessage(&rcv);
2411 
2413  snd.setDataShort(settings.m_skipFactor, 1);
2414  m_serial.writeMessage(&snd);
2415  m_lastResult =
2417  if (m_lastResult != XRV_OK) return m_lastResult;
2418  if (m_logging) m_logFile.writeMessage(&rcv);
2420 
2422  snd.setDataLong(
2423  (uint32_t)(
2424  ((double)settings.m_offset) * CMT_SYNC_CLOCK_NS_TO_TICKS + 0.5),
2425  1);
2426  m_serial.writeMessage(&snd);
2427  m_lastResult =
2429  if (m_lastResult != XRV_OK) return m_lastResult;
2430  if (m_logging) m_logFile.writeMessage(&rcv);
2432 
2434  snd.setDataLong(
2435  (uint32_t)(
2436  ((double)settings.m_pulseWidth) * CMT_SYNC_CLOCK_NS_TO_TICKS + 0.5),
2437  1);
2438  m_serial.writeMessage(&snd);
2439  m_lastResult =
2441  if (m_lastResult != XRV_OK) return m_lastResult;
2442  if (m_logging) m_logFile.writeMessage(&rcv);
2444 
2445  return m_lastResult = XRV_OK;
2446 }
2447 
2448 //////////////////////////////////////////////////////////////////////////////////////////
2449 // Set the outbound synchronization mode of a device.
2451 {
2452  CMT3LOG("L3: setSyncOutSettings %u\n", (uint32_t)mode);
2453  CMT3EXITLOG;
2454 
2455  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2456 
2458  Message rcv;
2459 
2460  snd.setBusId(CMT_BID_MASTER);
2461 
2463  snd.setDataShort(mode, 1);
2464  m_serial.writeMessage(&snd);
2465  m_lastResult =
2467  if (m_lastResult != XRV_OK) return m_lastResult;
2468  if (m_logging) m_logFile.writeMessage(&rcv);
2470 
2471  return m_lastResult = XRV_OK;
2472 }
2473 
2474 //////////////////////////////////////////////////////////////////////////////////////////
2475 // Set the outbound synchronization pulse width of a device.
2477 {
2478  CMT3LOG("L3: setSyncOutSettings %u\n", pulseWidth);
2479  CMT3EXITLOG;
2480 
2481  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2482 
2484  Message rcv;
2485 
2486  snd.setBusId(CMT_BID_MASTER);
2487 
2489  snd.setDataLong(
2490  (uint32_t)(((double)pulseWidth) * CMT_SYNC_CLOCK_NS_TO_TICKS + 0.5), 1);
2491  m_serial.writeMessage(&snd);
2492  m_lastResult =
2494  if (m_lastResult != XRV_OK) return m_lastResult;
2495  if (m_logging) m_logFile.writeMessage(&rcv);
2497 
2498  return m_lastResult = XRV_OK;
2499 }
2500 
2501 //////////////////////////////////////////////////////////////////////////////////////////
2502 // Set the outbound synchronization skip factor of a device.
2504 {
2505  CMT3LOG("L3: setSyncOutSettings %u\n", skipFactor);
2506  CMT3EXITLOG;
2507 
2508  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2509 
2511  Message rcv;
2512 
2513  snd.setBusId(CMT_BID_MASTER);
2514 
2516  snd.setDataShort(skipFactor, 1);
2517  m_serial.writeMessage(&snd);
2518  m_lastResult =
2520  if (m_lastResult != XRV_OK) return m_lastResult;
2521  if (m_logging) m_logFile.writeMessage(&rcv);
2523 
2524  return m_lastResult = XRV_OK;
2525 }
2526 
2527 //////////////////////////////////////////////////////////////////////////////////////////
2528 // Set the outbound synchronization offset of a device.
2530 {
2531  CMT3LOG("L3: setSyncOutSettings %u\n", offset);
2532  CMT3EXITLOG;
2533 
2534  if (isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2535 
2537  Message rcv;
2538 
2539  snd.setBusId(CMT_BID_MASTER);
2540 
2542  snd.setDataLong(
2543  (uint32_t)(((double)offset) * CMT_SYNC_CLOCK_NS_TO_TICKS + 0.5), 1);
2544  m_serial.writeMessage(&snd);
2545  m_lastResult =
2547  if (m_lastResult != XRV_OK) return m_lastResult;
2548  if (m_logging) m_logFile.writeMessage(&rcv);
2550 
2551  return m_lastResult = XRV_OK;
2552 }
2553 
2554 //////////////////////////////////////////////////////////////////////////////////////////
2555 // Set the configuration mode timeout value in ms.
2557 {
2558  CMT3LOG("L3: setTimeoutConfig %u\n", timeout);
2559  CMT3EXITLOG;
2560 
2561  m_timeoutConf = timeout;
2563  return m_lastResult = XRV_OK;
2564 }
2565 
2566 //////////////////////////////////////////////////////////////////////////////////////////
2567 // Set the measurement mode timeout value in ms.
2569 {
2570  CMT3LOG("L3: setTimeoutMeasurement %u\n", timeout);
2571  CMT3EXITLOG;
2572 
2573  m_timeoutMeas = timeout;
2575  return m_lastResult = XRV_OK;
2576 }
2577 
2578 //////////////////////////////////////////////////////////////////////////////////////////
2579 // Set the dual-mode output settings of the XM
2581 {
2582  CMT3LOG("L3: setXmOutputMode %u\n", (uint32_t)mode);
2583  CMT3EXITLOG;
2584 
2585  if (!isXm()) return m_lastResult = XRV_INVALIDOPERATION;
2586 
2589  return m_lastResult = XRV_OK;
2590 }
2591 
2592 //////////////////////////////////////////////////////////////////////////////////////////
2594 {
2595  CMT3LOG("L3: refreshCache %d\n", file ? 1 : 0);
2596  CMT3EXITLOG;
2597 
2598  if (m_serial.isOpen() && (!file || !m_logFile.isOpen()))
2599  {
2600  // clear eMts cache
2601  for (uint32_t i = 0; i < CMT_MAX_DEVICES_PER_PORT; ++i)
2602  {
2603  CHKFREENUL(m_eMtsData[i]);
2604  }
2605 
2606  // port open, go to configuration mode
2607  if (m_measuring && gotoConfig() != XRV_OK)
2608  return m_lastResult; // m_lastResult is already set by gotoConfig()
2609 
2610  // now in configuration mode, read device information
2611  CMT3LOG(
2612  "L3: refreshCache Device in configuration mode, reading device "
2613  "information\n");
2614 
2615  Message snd;
2616  Message rcv;
2617 
2618  // all information is in the Configuration message
2620  m_serial.writeMessage(&snd);
2622  &rcv, CMT_MID_CONFIGURATION, 0, false)) != XRV_OK)
2623  return m_lastResult;
2624  if (m_logging) m_logFile.writeMessage(&rcv);
2626 
2629  // CmtDeviceMode2 mode;
2630  // mode.setPeriodAndSkipFactor(m_config.m_samplingPeriod,m_config.m_outputSkipFactor);
2631  // mode.m_period = m_config.m_samplingPeriod;
2632  // mode.m_skip = m_config.m_outputSkipFactor;
2633  // m_sampleFrequency = mode.getRealSampleFrequency();
2634 
2635  return m_lastResult = XRV_OK;
2636  }
2637  else if (m_logFile.isOpen() && (file || !m_serial.isOpen()))
2638  {
2639  // clear eMts cache
2640  for (uint32_t i = 0; i < CMT_MAX_DEVICES_PER_PORT; ++i)
2641  {
2642  CHKFREENUL(m_eMtsData[i]);
2643  }
2644 
2645  // now in configuration mode, read device information
2646  CMT3LOG(
2647  "L3: refreshCache Reading device configuration information from "
2648  "file\n");
2649 
2650  Message rcv;
2651 
2652  if ((m_lastResult =
2654  return m_lastResult;
2656 
2659  // CmtDeviceMode2 mode;
2660  // mode.setPeriodAndSkipFactor(m_config.m_samplingPeriod,m_config.m_outputSkipFactor);
2661  // mode.m_period = m_config.m_samplingPeriod;
2662  // mode.m_skip = m_config.m_outputSkipFactor;
2663  // m_sampleFrequency = mode.getRealSampleFrequency();
2664 
2665  return m_lastResult = XRV_OK;
2666  }
2667  else
2669 }
2670 
2671 //////////////////////////////////////////////////////////////////////////////////////////
2672 // Wait for a data message to arrive.
2674 {
2675  CMT3LOGDAT("L3: waitForDataMessage %p\n", pack);
2677 
2679 
2680  uint32_t toEnd =
2682  while (toEnd >= getTimeOfDay())
2683  {
2684  m_lastResult =
2685  m_serial.waitForMessage(&pack->m_msg, CMT_MID_MTDATA, 0, true);
2686  if (m_lastResult == XRV_OK)
2687  {
2688  if (m_logging) m_logFile.writeMessage(&pack->m_msg);
2689  if (pack->m_msg.getMessageId() == CMT_MID_ERROR)
2690  {
2692  if (pack->m_msg.getDataSize() >= 2)
2693  {
2694  uint8_t biddy = pack->m_msg.getDataByte(1);
2696  }
2697  return m_lastResult = m_lastHwError =
2699  }
2700 
2702  for (uint16_t i = 0; i < m_config.m_numberOfDevices; ++i)
2703  pack->setDataFormat(
2706  pack->m_toa = timeStampNow();
2707  if (m_useRtc) fillRtc(pack);
2708 
2709  return m_lastResult = XRV_OK;
2710  }
2711  }
2712  return m_lastResult; // = XRV_TIMEOUT;
2713 }
2714 
2715 //////////////////////////////////////////////////////////////////////////////////////////
2716 XsensResultValue Cmt3::createLogFile(const char* filename, bool startLogging)
2717 {
2718  CMT3LOG(
2719  "L3: createLogFile \"%s\" %u\n", filename ? filename : "",
2720  startLogging ? 1 : 0);
2721  CMT3EXITLOG;
2722 
2723  if (!m_serial.isOpen()) return m_lastResult = XRV_NOPORTOPEN;
2724  if (m_logFile.isOpen()) return m_lastResult = XRV_ALREADYOPEN;
2725  m_lastResult = m_logFile.create(filename);
2726  if (m_lastResult == XRV_OK)
2727  {
2728  m_logging = true;
2729  CmtDeviceConfiguration config;
2730  if (getConfiguration(config) == XRV_OK)
2731  {
2732  void* buffer =
2733  malloc(CMT_EMTS_SIZE * (m_config.m_numberOfDevices + 1));
2735  free(buffer);
2736  m_logging = startLogging;
2737  }
2738  }
2739 
2740  if (m_lastResult != XRV_OK)
2741  {
2743  m_logging = false;
2744  }
2745  return m_lastResult;
2746 }
2747 
2748 //////////////////////////////////////////////////////////////////////////////////////////
2749 XsensResultValue Cmt3::createLogFile(const wchar_t* filename, bool startLogging)
2750 {
2751  CMT3LOG(
2752  "L3: createLogFile \"%S\" %u\n", filename ? filename : L"",
2753  startLogging ? 1 : 0);
2754  CMT3EXITLOG;
2755 
2756  if (!m_serial.isOpen()) return m_lastResult = XRV_NOPORTOPEN;
2757  if (m_logFile.isOpen()) return m_lastResult = XRV_ALREADYOPEN;
2758  m_lastResult = m_logFile.create(filename);
2759  if (m_lastResult == XRV_OK)
2760  {
2761  m_logging = true;
2762  CmtDeviceConfiguration config;
2763  if (getConfiguration(config) == XRV_OK)
2764  {
2765  void* buffer =
2766  malloc(CMT_EMTS_SIZE * (m_config.m_numberOfDevices + 1));
2768  free(buffer);
2769  m_logging = startLogging;
2770  }
2771  }
2772 
2773  if (m_lastResult != XRV_OK)
2774  {
2776  m_logging = false;
2777  }
2778  return m_lastResult;
2779 }
2780 
2781 //////////////////////////////////////////////////////////////////////////////////////////
2783 {
2784  CMT3LOG("L3: closeLogFile %u\n", del ? 1 : 0);
2785  CMT3EXITLOG;
2786 
2787  m_logging = false;
2788  if (!m_logFile.isOpen()) return m_lastResult = XRV_NOFILEOPEN;
2789  if (del)
2791  else
2792  return m_lastResult = m_logFile.close();
2793 }
2794 
2795 //////////////////////////////////////////////////////////////////////////////////////////
2796 bool Cmt3::isLogFileOpen(const char* filename) const
2797 {
2798  CMT3LOG("L3: isLogFileOpen \"%s\"\n", filename ? filename : "");
2799 
2800  if (m_logFile.isOpen())
2801  {
2802  if (filename != nullptr && filename[0] != 0)
2803  {
2804  char fn[CMT_MAX_FILENAME_LENGTH];
2805  m_logFile.getName(fn);
2806  if (_strnicmp(filename, fn, CMT_MAX_FILENAME_LENGTH) != 0)
2807  return false;
2808  }
2809  return true;
2810  }
2811  return false;
2812 }
2813 
2814 //////////////////////////////////////////////////////////////////////////////////////////
2815 bool Cmt3::isLogFileOpen(const wchar_t* filename) const
2816 {
2817  CMT3LOG("L3: isLogFileOpen \"%S\"\n", filename ? filename : L"");
2818 
2819  if (m_logFile.isOpen())
2820  {
2821  if (filename != nullptr && filename[0] != L'\0')
2822  {
2823  wchar_t fn[CMT_MAX_FILENAME_LENGTH];
2824  m_logFile.getName(fn);
2825  if (_wcsnicmp(filename, fn, CMT_MAX_FILENAME_LENGTH) != 0)
2826  return false;
2827  }
2828  return true;
2829  }
2830  return false;
2831 }
2832 
2833 //////////////////////////////////////////////////////////////////////////////////////////
2835 {
2836  CMT3LOG("L3: openLogFile \"%s\"\n", filename ? filename : "");
2837  CMT3EXITLOG;
2838 
2839  m_logging = false;
2841  if (m_logFile.isOpen()) return m_lastResult = XRV_ALREADYOPEN;
2842  m_lastResult = m_logFile.open(filename, true);
2843  if (m_lastResult == XRV_OK)
2844  {
2845  if (refreshCache() == XRV_OK)
2846  m_readFromFile = true;
2847  else
2848  {
2849  m_logFile.close();
2850  m_readFromFile = false;
2851  }
2852  }
2853  return m_lastResult;
2854 }
2855 
2856 //////////////////////////////////////////////////////////////////////////////////////////
2857 XsensResultValue Cmt3::openLogFile(const wchar_t* filename)
2858 {
2859  CMT3LOG("L3: openLogFile \"%S\"\n", filename ? filename : L"");
2860  CMT3EXITLOG;
2861 
2862  m_logging = false;
2864  if (m_logFile.isOpen()) return m_lastResult = XRV_ALREADYOPEN;
2865  m_lastResult = m_logFile.open(filename, true);
2866  if (m_lastResult == XRV_OK)
2867  {
2868  if (refreshCache() == XRV_OK)
2869  m_readFromFile = true;
2870  else
2871  {
2872  m_logFile.close();
2873  m_readFromFile = false;
2874  }
2875  }
2876  return m_lastResult;
2877 }
2878 
2879 //////////////////////////////////////////////////////////////////////////////////////////
2881 {
2882  CMT3LOG("L3: setDataSource %s\n", readFromFile ? "file" : "port");
2883  CMT3EXITLOG;
2884 
2885  if (readFromFile)
2886  {
2887  m_logging = false;
2888  if (m_logFile.isOpen())
2889  {
2890  m_readFromFile = true;
2891  return m_lastResult = XRV_OK;
2892  }
2893  m_readFromFile = false;
2895  }
2896  if (m_serial.isOpen())
2897  {
2898  m_readFromFile = false;
2899  return m_lastResult = XRV_OK;
2900  }
2901  if (m_logFile.isOpen())
2902  {
2903  m_readFromFile = true;
2905  }
2906  m_readFromFile = false;
2908 }
2909 
2910 //////////////////////////////////////////////////////////////////////////////////////////
2912 {
2913  CMT3LOG("L3: setLogMode %u\n", active ? 1 : 0);
2914  CMT3EXITLOG;
2915 
2916  if (active && (m_readFromFile || !m_logFile.isOpen()))
2917  return m_lastResult = XRV_NOFILEOPEN;
2918  m_logging = active;
2919  return m_lastResult = XRV_OK;
2920 }
2921 
2922 //////////////////////////////////////////////////////////////////////////////////////////
2924 {
2925  CMT3LOG("L3: resetLogFileReadPos\n");
2926  CMT3EXITLOG;
2927 
2929 }
2930 
2931 //////////////////////////////////////////////////////////////////////////////////////////
2933 {
2934  CMT3LOG("L3: writeMessageToLogFile\n");
2935  CMT3EXITLOG;
2936 
2937  if (!m_logFile.isOpen()) return m_lastResult = XRV_NOFILEOPEN;
2938 
2939  return m_lastResult = m_logFile.writeMessage(&msg);
2940 }
2941 
2942 //////////////////////////////////////////////////////////////////////////////////////////
2944  CmtScenario* scenarios, const CmtDeviceId deviceId)
2945 {
2946  CMT3LOG("L3: getAvailableScenarios %p %08x\n", scenarios, deviceId);
2947  CMT3EXITLOG;
2948 
2950 
2951  char tp = 0;
2952  switch (deviceId & CMT_DID_TYPEH_MASK)
2953  {
2954  case CMT_DID_TYPEH_MTIG:
2955  tp = '6';
2956  break;
2957  case CMT_DID_TYPEH_MTI_MTX:
2958  tp = '3';
2959  break;
2960  }
2961 
2962  for (int i = 0; i < CMT_MAX_SCENARIOS_IN_MT; ++i)
2963  {
2964  scenarios[i].m_type =
2965  rcv.getDataByte(0 + i * (1 + 1 + CMT_LEN_SCENARIOLABEL));
2966  scenarios[i].m_version =
2967  rcv.getDataByte(1 + i * (1 + 1 + CMT_LEN_SCENARIOLABEL));
2968  memcpy(
2969  scenarios[i].m_label,
2970  rcv.getDataBuffer(2 + i * (1 + 1 + CMT_LEN_SCENARIOLABEL)),
2972  scenarios[i].m_label[CMT_LEN_SCENARIOLABEL] = 0;
2973  scenarios[i].m_filterType = tp;
2974  }
2975  return m_lastResult = XRV_OK;
2976 }
2977 
2979  uint8_t& scenarioType, uint8_t& scenarioVersion, const CmtDeviceId deviceId)
2980 {
2981  CMT3LOG("L3: getScenario %08x\n", deviceId);
2982  CMT3EXITLOG;
2983 
2985  scenarioType = rcv.getDataByte(1);
2986  scenarioVersion = rcv.getDataByte(0);
2987  return m_lastResult = XRV_OK;
2988 }
2989 
2991  const uint8_t scenarioType, const CmtDeviceId deviceId)
2992 {
2993  CMT3LOG("L3: setScenario %u %08x\n", (uint32_t)scenarioType, deviceId);
2994  CMT3EXITLOG;
2995 
2996  auto scenario = (uint16_t)scenarioType;
2998  return m_lastResult = XRV_OK;
2999 }
3000 
3002  double& magnitude, const CmtDeviceId deviceId)
3003 {
3004  CMT3LOG("L3: getGravityMagnitude %08x\n", deviceId);
3005  CMT3EXITLOG;
3006 
3008  magnitude = rcv.getDataFloat(0);
3009  return m_lastResult = XRV_OK;
3010 }
3011 
3013  const double magnitude, const CmtDeviceId deviceId)
3014 {
3015  CMT3LOG("L3: setGravityMagnitude %f %08x\n", magnitude, deviceId);
3016  CMT3EXITLOG;
3017 
3018  DO_DATA_SET(
3020  (float)magnitude);
3021  return m_lastResult = XRV_OK;
3022 }
3023 
3025  CmtVector& arm, const CmtDeviceId deviceId)
3026 {
3027  CMT3LOG("L3: getGpsLeverArm %08x\n", deviceId);
3028  CMT3EXITLOG;
3029 
3031  arm.m_data[0] = rcv.getDataFloat(0);
3032  arm.m_data[1] = rcv.getDataFloat(4);
3033  arm.m_data[2] = rcv.getDataFloat(8);
3034  return m_lastResult = XRV_OK;
3035 }
3036 
3039 {
3040  CMT3LOG("L3: getGpsStatus %08x\n", deviceId);
3041  CMT3EXITLOG;
3042 
3044  for (uint16_t i = 0; i < CMT_MAX_SVINFO; ++i)
3045  {
3046  status.m_svInfo[i].m_id = rcv.getDataByte(i * 5 + 2);
3047  status.m_svInfo[i].m_navigationStatus = rcv.getDataByte(i * 5 + 3);
3048  status.m_svInfo[i].m_signalQuality = rcv.getDataByte(i * 5 + 4);
3049  status.m_svInfo[i].m_signalStrength = rcv.getDataByte(i * 5 + 5);
3050  }
3051  return m_lastResult = XRV_OK;
3052 }
3053 
3055  const CmtVector& arm, const CmtDeviceId deviceId)
3056 {
3057  CMT3LOG(
3058  "L3: setGpsLeverArm [%f %f %f] %08x\n", arm.m_data[0], arm.m_data[1],
3059  arm.m_data[2], deviceId);
3060  CMT3EXITLOG;
3061 
3063  if (bid == CMT_BID_INVALID || bid == CMT_BID_BROADCAST)
3064  return (m_lastResult = XRV_INVALIDID);
3065 
3067  Message rcv;
3068  snd.setDataFloat((float)arm.m_data[0], 0);
3069  snd.setDataFloat((float)arm.m_data[1], 4);
3070  snd.setDataFloat((float)arm.m_data[2], 8);
3071 
3072  snd.setBusId(bid);
3073  m_serial.writeMessage(&snd);
3074  m_lastResult =
3076  if (m_lastResult != XRV_OK) return m_lastResult;
3077  if (m_logging) m_logFile.writeMessage(&rcv);
3078  if (rcv.getMessageId() == CMT_MID_ERROR)
3079  {
3081  if (rcv.getDataSize() >= 2)
3082  {
3083  uint8_t biddy = rcv.getDataByte(1);
3085  }
3086  return m_lastResult = m_lastHwError =
3088  }
3089  return m_lastResult = XRV_OK;
3090 }
3091 
3093 {
3094  CMT3LOG("L3: storeXkfState %08x\n", deviceId);
3095  CMT3EXITLOG;
3096 
3098  if (bid == CMT_BID_INVALID || bid == CMT_BID_BROADCAST)
3099  return (m_lastResult = XRV_INVALIDID);
3100 
3102  Message rcv;
3103 
3104  snd.setBusId(bid);
3105  m_serial.writeMessage(&snd);
3106  m_lastResult =
3108  if (m_lastResult != XRV_OK) return m_lastResult;
3109  if (m_logging) m_logFile.writeMessage(&rcv);
3110  if (rcv.getMessageId() == CMT_MID_ERROR)
3111  {
3113  if (rcv.getDataSize() >= 2)
3114  {
3115  uint8_t biddy = rcv.getDataByte(1);
3117  }
3118  return m_lastResult = m_lastHwError =
3120  }
3121  return m_lastResult = XRV_OK;
3122 }
3123 
3124 } // namespace xsens
#define CMT_MID_REQAVAILABLESCENARIOS
Definition: cmtdef.h:272
void fillRtc(Packet *pack)
Internal function to compute the RTC value.
Definition: cmt3.cpp:377
#define CMT_MID_REQBTDISABLE
Definition: cmtdef.h:129
XsensResultValue initBus(void)
Perform an initBus request.
Definition: cmt3.cpp:1545
void readFromMessage(const void *message)
Definition: cmt3.cpp:65
#define CMT_MID_REQGPSLEVERARM
Definition: cmtdef.h:290
uint32_t getDataLong(const uint16_t offset=0) const
Return the current value of the data as an uint32_t (32 bits).
Definition: cmtmessage.cpp:322
A structure for storing the firmware version.
Definition: cmtdef.h:936
Operation was performed successfully.
Definition: xsens_std.h:35
char m_filterType
The type of filter this scenario is intended for &#39;3&#39;: XKF-3, &#39;6&#39;: XKF-6.
Definition: cmtdef.h:1115
CmtDeviceId getMasterId(void)
Definition: cmt3.cpp:1002
XsensResultValue getSyncOutSkipFactor(uint16_t &skipFactor)
Retrieve the outbound synchronization skip factor of an MT device.
Definition: cmt3.cpp:1369
uint16_t m_period
Definition: cmtdef.h:1055
XsensResultValue getSyncMode(uint8_t &mode)
Retrieve the sync mode of the Xbus Master.
Definition: cmt3.cpp:1248
XsensResultValue getMagneticDeclination(double &declination, const CmtDeviceId deviceId=CMT_DID_MASTER)
Return the stored magnetic declination.
Definition: cmt3.cpp:989
#define CMT_GOTO_CONFIG_TRIES
Definition: cmtdef.h:772
#define CMT_MID_REQSYNCOUTSETTINGSACK
Definition: cmtdef.h:188
XsensResultValue getPortNr(uint8_t &port) const
Return the device Id of an MT device.
Definition: cmt3.cpp:1038
#define DO_DATA_REQUEST_BID(req, bid)
Definition: cmt3.cpp:210
double m_rtcMsPerSample
ms per sample = 1000 / sample frequency.
Definition: cmt3.h:49
uint8_t m_type
The type of the scenario.
Definition: cmtdef.h:1103
XsensResultValue setSyncOutSkipFactor(const uint16_t skipFactor)
Set the outbound synchronization skip factor of an MT device.
Definition: cmt3.cpp:2503
#define CMT_PARAM_SYNCOUT_SKIPFACTOR
Definition: cmtdef.h:596
uint16_t m_skip
The skip factor of the port.
Definition: cmt3.h:55
__int64 CmtFilePos
Definition: cmtf.h:25
TimeStamp m_toa
Time of arrival.
Definition: cmtpacket.h:82
uint8_t m_day
Definition: cmtdef.h:993
TimeStamp m_rtcStart
The start of the RTC counter, the time of arrival of sample 0.
Definition: cmt3.h:57
unsigned __int16 uint16_t
Definition: rptypes.h:47
Mid-level serial communication class.
Definition: cmt2.h:41
#define CMT_LEN_SYNCMODE
Definition: cmtdef.h:148
XsensResultValue setBusPowerState(const bool enabled)
Switch the Xbus Master bus power on or off.
Definition: cmt3.cpp:1989
uint32_t getDeviceCount(void) const
Retrieve total device count.
Definition: cmt3.cpp:582
XsensResultValue getGpsLeverArm(CmtVector &arm, const CmtDeviceId deviceId=CMT_DID_MASTER)
Get the currently used GPS lever arm.
Definition: cmt3.cpp:3024
XsensResultValue openPort(const char *portName, const uint32_t baudRate=CMT_DEFAULT_BAUD_RATE)
Definition: cmt3.cpp:1566
XsensResultValue setSyncOutPulseWidth(const uint32_t pulseWidth)
Set the outbound synchronization pulse width of an MT device.
Definition: cmt3.cpp:2476
#define CMT_MID_CONFIGURATION
Definition: cmtdef.h:118
XsensResultValue open(const char *filename, const bool readOnly=false)
Open a file and read the header.
Definition: cmt2.cpp:750
#define CMT_MID_SETGPSLEVERARM
Definition: cmtdef.h:292
#define CMT_MID_REQBATLEVEL
Definition: cmtdef.h:247
XsensResultValue getGpsStatus(CmtGpsStatus &status, const CmtDeviceId deviceId=CMT_DID_MASTER)
Request the status of the GPS satellites in orbit.
Definition: cmt3.cpp:3037
uint8_t m_version
The version of the scenario.
Definition: cmtdef.h:1105
bool m_readFromFile
Indicates whether to read from the log file or from the serial port.
Definition: cmt3.h:82
#define XSENS_MS_PER_DAY
The number of milliseconds in a normal day.
Definition: xsens_time.h:21
#define CMT_MID_REQOUTPUTMODE
Definition: cmtdef.h:161
uint8_t m_valid
When set to 1, the time is valid, when set to 2, the time part is valid, but the date may not be vali...
Definition: cmtdef.h:1000
unsigned char Byte
Definition: zconf.h:265
#define CMT_MID_REQPERIODACK
Definition: cmtdef.h:101
XsensResultValue refreshCache(const bool file=false)
Update device information stored on host PC.
Definition: cmt3.cpp:2593
void resizeData(const uint16_t newSize)
Resize the data area to the given size.
Definition: cmtmessage.cpp:424
#define CMT_MID_GOTOMEASUREMENT
Definition: cmtdef.h:123
#define CMT_LEN_RESETORIENTATION
Definition: cmtdef.h:492
XsensResultValue getSyncOutPulseWidth(uint32_t &pulseWidth)
Retrieve the outbound synchronization pulse width of an MT device.
Definition: cmt3.cpp:1341
#define CMT_MID_XMPWROFF
Definition: cmtdef.h:477
XsensResultValue getBatteryLevel(uint8_t &level)
Get an Xbus Master&#39;s battery level.
Definition: cmt3.cpp:420
#define CMT_MID_REQSYNCOUTSETTINGS
Definition: cmtdef.h:187
Cmt2f * getCmt2f(void)
Return a reference to the embedded Cmt2f (logfile) object.
Definition: cmt3.cpp:510
#define CMT_BAUD_RATE_230K4
Definition: cmtdef.h:751
GLuint buffer
Definition: glext.h:3928
XsensResultValue getLogFileReadPosition(CmtFilePos &pos)
Retrieve the read position of the log file.
Definition: cmt3.cpp:931
XsensResultValue getDeviceId(const uint8_t busId, CmtDeviceId &deviceId) const
Retrieve the DeviceId of a device given its Bus ID.
Definition: cmt3.cpp:597
#define CMT_MID_REQOUTPUTSKIPFACTORACK
Definition: cmtdef.h:174
uint16_t m_skipFactor
Definition: cmtdef.h:966
XsensResultValue getPortNr(uint8_t &port) const
Retrieve the port that the object is connected to.
Definition: cmt2.cpp:144
#define CMT_MAX_FILENAME_LENGTH
Definition: cmtdef.h:926
uint32_t m_offset
Offset in ns.
Definition: cmtdef.h:968
XsensResultValue setDeviceMode(const CmtDeviceMode &mode, bool force, const CmtDeviceId deviceId=CMT_DID_MASTER)
Set the complete output mode of a device.
Definition: cmt3.cpp:2001
XsensResultValue readDataPacket(Packet *pack, bool acceptOther=false)
Retrieve a data message.
Definition: cmt3.cpp:1712
bool m_logging
Indicates whether to write all received messages to the logfile or not, automatically set to true by ...
Definition: cmt3.h:87
A structure for storing sync out settings.
Definition: cmtdef.h:963
XsensResultValue getDeviceMode(CmtDeviceMode &mode, const CmtDeviceId deviceId=CMT_DID_MASTER)
Return device mode.
Definition: cmt3.cpp:616
uint8_t m_minor
Definition: cmtdef.h:939
uint16_t m_syncinMode
Definition: cmtdef.h:870
int _strnicmp(const char *str, const char *subStr, size_t count) noexcept
An OS-independent version of strnicmp.
Definition: os.cpp:346
#define CMT_BAUD_RATE_9600
Definition: cmtdef.h:744
uint8_t m_reservedForClient[32]
Definition: cmtdef.h:876
uint32_t m_rtcCount
The long sample counter (normal counter wraps at 64k).
Definition: cmt3.h:59
XsensResultValue restoreFactoryDefaults(const CmtDeviceId deviceId=CMT_DID_MASTER)
Restore the device to factory default settings.
Definition: cmt3.cpp:1862
GLintptr offset
Definition: glext.h:3936
#define CMT_MID_REQFWREV
Definition: cmtdef.h:125
#define CMT_MID_REQSYNCMODE
Definition: cmtdef.h:146
XsensResultValue resetLogFileReadPos(void)
Restart reading from the start of the open log file.
Definition: cmt3.cpp:2923
XsensResultValue getLastResult(void) const
Return the error code of the last operation.
Definition: cmt2.h:112
XsensResultValue setSyncInMode(const uint16_t mode)
Set the inbound synchronization mode of an MT device.
Definition: cmt3.cpp:2293
XsensResultValue getLocationId(uint16_t &locationId, const CmtDeviceId deviceId=CMT_DID_MASTER)
Return the location ID of a sensor.
Definition: cmt3.cpp:918
#define CMT_DID_TYPEH_MASK
Definition: cmtdef.h:82
bool m_rtcInitialized
Indicates if the rtc is initialised or not.
Definition: cmt3.h:84
bool isLogFileOpen(const char *filename) const
Return whether or not(true or false) the supplied file is open.
Definition: cmt3.cpp:2796
uint16_t m_gotoConfigTries
The number of times a goto config is attempted before the function fails.
Definition: cmt3.h:74
#define DO_DATA_SET(req, size, type, data)
Definition: cmt3.cpp:298
#define CMT_DID_TYPEH_MTI_MTX
Definition: cmtdef.h:85
#define CMT_MID_STOREXKFSTATE
Definition: cmtdef.h:262
XsensResultValue gotoMeasurement(void)
Place all connected devices into Measurement Mode.
Definition: cmt3.cpp:1520
double getRealSampleFrequency(void) const
Return the real sample frequency in Hz.
Definition: cmt3.cpp:151
uint16_t getDataSize(void) const
Return the length of the data part of the message.
Definition: cmtmessage.cpp:352
A structure for storing UTC Time values.
Definition: cmtdef.h:988
XsensResultValue reset(void)
Request a data.
Definition: cmt3.cpp:1829
uint16_t m_itemCount
The number of data items in the message.
Definition: cmtpacket.h:76
XsensResultValue getSyncInOffset(uint32_t &offset)
Retrieve the inbound synchronization offset of an MT device.
Definition: cmt3.cpp:1221
#define CMT_MID_REQUTCTIME
Definition: cmtdef.h:266
XsensResultValue getMtDeviceId(const uint8_t index, CmtDeviceId &deviceId) const
Definition: cmt3.cpp:1024
uint8_t m_month
Definition: cmtdef.h:992
#define CMT_DID_BROADCAST
Definition: cmtdef.h:928
uint8_t m_hour
Definition: cmtdef.h:994
A structure for storing sync in settings.
Definition: cmtdef.h:944
#define CMT_LEN_OPMODE
Definition: cmtdef.h:136
uint16_t getSampleCounter(const uint16_t index=0) const
Return the Sample Counter component of the packet.
Definition: cmtpacket.cpp:1217
#define CMT_MID_REQGPSSTATUS
Definition: cmtdef.h:494
uint32_t m_pulseWidth
Pulse width in ns.
Definition: cmtdef.h:970
XsensResultValue getSyncInSettings(CmtSyncInSettings &settings)
Retrieve the inbound synchronization settings of the master MT device.
Definition: cmt3.cpp:1127
TimeStamp timeStampNow(void)
Definition: xsens_time.cpp:101
#define CMT_LEN_AMD
Definition: cmtdef.h:487
#define CMT_MID_EMTSDATA
Definition: cmtdef.h:1296
#define CMT_MID_REQSYNCINSETTINGSACK
Definition: cmtdef.h:180
uint32_t m_offset
Offset in ns.
Definition: cmtdef.h:949
XsensResultValue writeMessageToLogFile(const Message &msg)
Definition: cmt3.cpp:2932
XsensResultValue setErrorMode(const uint16_t mode)
Set the error mode of the device.
Definition: cmt3.cpp:2161
uint16_t getMtCount(void) const
Return the device Id of the first.
Definition: cmt3.cpp:1013
XsensResultValue getName(char *filename) const
Retrieve the filename that was last successfully opened.
Definition: cmt2.cpp:733
GLenum GLsizei len
Definition: glext.h:4756
#define CMT_MID_SETGPSLEVERARMACK
Definition: cmtdef.h:293
#define CMT_MID_REQBAUDRATE
Definition: cmtdef.h:140
#define CMT_MID_REQDATA
Definition: cmtdef.h:304
XsensResultValue setXmPowerOff(void)
Switch the connected Xbus Master.
Definition: cmt3.cpp:2229
uint16_t getDataShort(const uint16_t offset=0) const
Return the current value of the data as an uint16_t (16 bits).
Definition: cmtmessage.cpp:338
#define CMT_BAUD_RATE_57K6
Definition: cmtdef.h:749
XsensResultValue setDeviceMode2(const CmtDeviceMode2 &mode, bool force, const CmtDeviceId deviceId=CMT_DID_MASTER)
Set the complete output mode2 of a device.
Definition: cmt3.cpp:2020
void getPeriodAndSkipFactor(uint16_t &period, uint16_t &skip) const
Compute the period and skip factor.
Definition: cmt3.cpp:93
#define CMT_MID_GOTOMEASUREMENTACK
Definition: cmtdef.h:124
XsensResultValue getConfiguration(CmtDeviceConfiguration &configuration)
Get device configuration.
Definition: cmt3.cpp:515
#define CMT_MID_REQAMD
Definition: cmtdef.h:485
uint16_t m_year
Definition: cmtdef.h:991
void recomputeChecksum(void)
Compute the checksum field and fill it.
Definition: cmtmessage.h:270
XsensResultValue getSyncOutSettings(CmtSyncOutSettings &settings)
Retrieve the outbound synchronization settings of the master MT device.
Definition: cmt3.cpp:1260
uint16_t m_skipFactor
Definition: cmtdef.h:947
#define HANDLE_ERR_RESULT
Definition: cmt3.cpp:303
XsensResultValue getHeading(double &heading, const CmtDeviceId deviceId=CMT_DID_MASTER)
Return the heading offset.
Definition: cmt3.cpp:906
XsensResultValue getPortName(char *portname) const
Definition: cmt2.cpp:134
bool isXm(void) const
Return whether the main device is an Xbus Master or not.
Definition: cmt3.cpp:1558
#define CMT3EXITLOGDAT
Definition: cmt3.cpp:55
A structure containing MT data + timestamp and formatting information.
Definition: cmtpacket.h:24
XsensResultValue closeLogFile(bool del=false)
Close an open log file.
Definition: cmt3.cpp:2782
void clearHwError(void)
Reset the hardware error code.
Definition: cmt3.h:248
unsigned char uint8_t
Definition: rptypes.h:44
bool operator==(const CmtDeviceMode &dev) const
Check if all fields of the two structures are equal.
Definition: cmt3.cpp:142
Cmt2s * getCmt2s(void)
Return a reference to the embedded Cmt2s (comm port) object.
Definition: cmt3.cpp:512
XsensResultValue setBaudrate(const uint32_t baudrate, bool reconnect=true)
Set the baudrate and possibly reconnect.
Definition: cmt3.cpp:1888
XsensResultValue getAvailableScenarios(CmtScenario *scenarios, const CmtDeviceId deviceId=CMT_DID_MASTER)
Write the specified message to the open.
Definition: cmt3.cpp:2943
XsensResultValue getBusId(uint8_t &busId, const CmtDeviceId deviceId=CMT_DID_MASTER) const
Retrieve the BusId of a device.
Definition: cmt3.cpp:457
Cmt3()
Default constructor, initializes all members to their default values.
Definition: cmt3.cpp:325
XsensResultValue setDataSource(bool readFromFile)
Set whether to read from comm port or file.
Definition: cmt3.cpp:2880
XsensResultValue setSyncOutSettings(const CmtSyncOutSettings &settings)
Set the outbound synchronization settings of an MT device.
Definition: cmt3.cpp:2388
XsensResultValue setMagneticDeclination(const double declination, const CmtDeviceId deviceId=CMT_DID_MASTER)
Set the stored magnetic declination.
Definition: cmt3.cpp:2215
#define CMT_MID_REQMAGNETICDECLINATION
Definition: cmtdef.h:228
uint8_t getBusIdInternal(const CmtDeviceId devId) const
Find a device Id in the list and return its busId.
Definition: cmt3.cpp:479
TimeStamp m_rtc
Sample time in ms, based on the sample counter.
Definition: cmtpacket.h:80
Structure containing a full device configuration as returned by the ReqConfig message.
Definition: cmtdef.h:865
XsensResultValue setGpsLeverArm(const CmtVector &arm, const CmtDeviceId deviceId=CMT_DID_MASTER)
Set the currently used GPS lever arm.
Definition: cmt3.cpp:3054
XsensResultValue setXmOutputMode(const uint8_t mode)
Set the dual-output mode of the XM.
Definition: cmt3.cpp:2580
XsensResultValue requestData(Packet *pack)
Definition: cmt3.cpp:1816
#define CMT_DID_MASTER
Definition: cmtdef.h:929
#define CMT_MID_REQXMERRORMODE
Definition: cmtdef.h:209
The mid-level file communication class.
Definition: cmt2.h:193
uint32_t m_syncinOffset
Definition: cmtdef.h:872
#define CMT_MID_RESET
Definition: cmtdef.h:472
#define CMT_MID_BUSPWR
Definition: cmtdef.h:110
#define CMT_DEFAULT_PERIOD
Definition: cmtdef.h:776
CmtOutputMode m_outputMode
Definition: cmtdef.h:1006
void msleep(uint32_t ms)
A platform-independent sleep routine.
Definition: xsens_time.cpp:82
float getDataFloat(const uint16_t offset=0) const
Return the current value of the data as a float (32 bits).
Definition: cmtmessage.cpp:180
uint32_t m_baudrate
The baudrate that was last set to be used by the port.
Definition: cmt3.h:63
#define CMT_MID_REQERRORMODE
Definition: cmtdef.h:196
#define CMT_LEN_STOREXKFSTATE
Definition: cmtdef.h:263
uint16_t m_samplingPeriod
Definition: cmtdef.h:868
XsensResultValue getLogFileName(char *filename)
Retrieve the name of the open log file or an empty string if no logfile is open.
Definition: cmt3.cpp:964
XsensResultValue openLogFile(const char *filename)
Open a log file for input.
Definition: cmt3.cpp:2834
bool operator==(const CmtDeviceMode2 &dev) const
Check if all fields of the two structures are equal.
Definition: cmt3.cpp:201
GLuint index
Definition: glext.h:4068
XsensResultValue close(void)
Close the file.
Definition: cmt2.cpp:665
#define DO_DATA_SET_BID(req, size, type, data, bid)
Definition: cmt3.cpp:252
uint16_t m_mode
Definition: cmtdef.h:965
#define CMT_DID_TYPEH_MTIG
Definition: cmtdef.h:86
#define CMT3EXITLOG
Definition: cmt3.cpp:45
Cmt1s * getCmt1s(void)
Return a reference to the embedded Cmt1s object.
Definition: cmt2.h:110
#define CMT_MID_REQPRODUCTCODE
Definition: cmtdef.h:152
#define CMT_LEN_ERRORMODE
Definition: cmtdef.h:198
#define CMT_LEN_GRAVITYMAGNITUDE
Definition: cmtdef.h:288
XsensResultValue getErrorMode(uint16_t &mode, const CmtDeviceId deviceId=CMT_DID_MASTER)
Return the error mode of the device.
Definition: cmt3.cpp:819
XsensResultValue setGravityMagnitude(const double magnitude, const CmtDeviceId deviceId=CMT_DID_MASTER)
Set the currently used magnitude of the gravity vector.
Definition: cmt3.cpp:3012
#define CMT_MID_REQOUTPUTMODEACK
Definition: cmtdef.h:162
struct CmtDeviceConfiguration::_devInfo m_deviceInfo[CMT_MAX_DEVICES_PER_PORT]
uint16_t m_numberOfDevices
Definition: cmtdef.h:877
XsensResultValue getScenario(uint8_t &scenarioType, uint8_t &scenarioVersion, const CmtDeviceId deviceId=CMT_DID_MASTER)
Get the currently active scenario from a Motion Tracker.
Definition: cmt3.cpp:2978
XsensResultValue
Xsens return values.
Definition: xsens_std.h:31
#define CMT_OUTPUTSETTINGS_TIMESTAMP_MASK
Definition: cmtdef.h:647
#define CMT_BAUDCODE_115K2
Definition: cmtdef.h:506
#define CMT_MID_REQFILTERSETTINGSACK
Definition: cmtdef.h:481
XsensResultValue createLogFile(const char *filename, bool startLogging=false)
Create a log file for incoming messages.
Definition: cmt3.cpp:2716
CmtDeviceId m_lastHwErrorDeviceId
Contains the Device ID of the device that caused the last hardware error.
Definition: cmt3.h:92
#define CMT_MID_REQHEADING
Definition: cmtdef.h:222
#define CMT_MAX_SCENARIOS_IN_MT
Definition: cmtdef.h:1095
#define CMT_MID_REQSYNCINSETTINGS
Definition: cmtdef.h:179
#define CMT_EMTS_SIZE
Definition: cmtdef.h:1297
XsensResultValue closeAndDelete(void)
Close the file and delete it.
Definition: cmt2.cpp:678
uint32_t m_timeoutMeas
The measurement mode timeout.
Definition: cmt3.h:67
CmtFilePos getReadPosition(void)
Get the current read position.
Definition: cmt2.cpp:856
uint16_t m_skip
Definition: cmtdef.h:1056
#define CMT_MID_ERROR
Definition: cmtdef.h:474
Cmt2s m_serial
The (optional) CMT level 2 serial object that this class operates on.
Definition: cmt3.h:44
XsensResultValue getUtcTime(CmtUtcTime &utc, const CmtDeviceId deviceId)
Return the UTC time of the last received sample.
Definition: cmt3.cpp:1424
void setSampleFrequency(uint16_t freq)
Compute the period and skip factor from a sample frequency.
Definition: cmt3.cpp:170
XsensResultValue getSyncInMode(uint16_t &mode)
Retrieve the inbound synchronization mode of an MT device.
Definition: cmt3.cpp:1173
double getRealSampleFrequency(void) const
Return the real sample frequency in Hz.
Definition: cmt3.cpp:125
#define CMT_PARAM_SYNCOUT_OFFSET
Definition: cmtdef.h:597
#define CMT_MID_REQSCENARIO
Definition: cmtdef.h:277
uint64_t TimeStamp
A real-time timestamp (ms)
Definition: xsens_time.h:24
#define CMT_MID_REQCONFIGURATION
Definition: cmtdef.h:117
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
#define CMT_BAUD_RATE_38K4
Definition: cmtdef.h:748
#define CMT_MID_RESTOREFACTORYDEF
Definition: cmtdef.h:120
#define CMT_BAUD_RATE_460K8
Definition: cmtdef.h:752
XsensResultValue waitForMessage(Message *rcv, const uint8_t msgId, uint32_t timeoutOverride, bool acceptErrorMessage)
Wait for a message to arrive.
Definition: cmt2.cpp:381
#define CMT_MID_SETMAGNETICDECLINATION
Definition: cmtdef.h:231
#define CMT_LEN_HEADING
Definition: cmtdef.h:224
void setDataFloat(const float data, const uint16_t offset=0)
Write a float (32 bits) into the data buffer.
Definition: cmtmessage.cpp:559
#define CMT_MID_SETGRAVITYMAGNITUDE
Definition: cmtdef.h:286
#define CMT_BAUDCODE_230K4
Definition: cmtdef.h:507
XsensResultValue setSyncOutOffset(const uint32_t offset)
Set the outbound synchronization offset of an MT device.
Definition: cmt3.cpp:2529
#define CMT_LEN_SCENARIOLABEL
Definition: cmtdef.h:270
XsensResultValue getSerialBaudrate(uint32_t &baudrate)
Return the baud rate used for serial communication.
Definition: cmt3.cpp:1078
#define CMT_MID_REQOUTPUTSKIPFACTOR
Definition: cmtdef.h:173
#define CMT_BAUDCODE_57K6
Definition: cmtdef.h:504
XsensResultValue storeXkfState(const CmtDeviceId deviceId=CMT_DID_MASTER)
Store important components of the XKF filter state to non-volatile memory.
Definition: cmt3.cpp:3092
uint32_t getTimeoutConfig(void) const
Return the configuration mode timeout.
Definition: cmt3.cpp:1419
#define CMT_LEN_LOCATIONID
Definition: cmtdef.h:236
~Cmt3()
Destructor, de-initializes, frees memory allocated for buffers, etc.
Definition: cmt3.cpp:347
void setDataLong(const uint32_t data, const uint16_t offset=0)
Write an uint32_t (32 bits) into the data buffer.
Definition: cmtmessage.cpp:690
#define CMT_BID_BROADCAST
Definition: cmtdef.h:1293
uint8_t m_time[8]
Definition: cmtdef.h:874
XsensResultValue getProductCode(char *productCode, const CmtDeviceId deviceId=CMT_DID_MASTER)
Return product code.
Definition: cmt3.cpp:1049
XsensResultValue getDataLength(uint32_t &length, const CmtDeviceId deviceId=CMT_DID_MASTER)
Retrieve data size.
Definition: cmt3.cpp:569
#define CMT_PARAM_SYNCIN_OFFSET
Definition: cmtdef.h:581
#define CMT_CONF_BLOCKLEN
Definition: cmtdef.h:553
#define CMT_LEN_BTDISABLE
Definition: cmtdef.h:131
XsensResultValue setTimeoutMeasurement(const uint32_t timeout=CMT3_DEFAULT_TIMEOUT_MEAS)
Set the measurement mode timeout.
Definition: cmt3.cpp:2568
#define CMT_PARAM_SYNCIN_SKIPFACTOR
Definition: cmtdef.h:580
#define CMT_LEN_BAUDRATE
Definition: cmtdef.h:142
#define CMT3LOG(...)
Definition: cmt3.cpp:44
CmtOutputSettings m_outputSettings
Definition: cmtdef.h:1007
#define CMT_PARAM_SYNCIN_MODE
Definition: cmtdef.h:579
double m_data[3]
Definition: cmtdef.h:1251
CmtFilePos getFileSize(void)
Get the current file size.
Definition: cmt2.cpp:853
uint32_t m_timeoutConf
The config mode timeout.
Definition: cmt3.h:65
XsensResultValue setReadPosition(CmtFilePos pos)
Set the read position to the given position.
Definition: cmt2.cpp:859
#define CMT_MID_INITBUS
Definition: cmtdef.h:97
uint8_t * getDataBuffer(const uint16_t offset=0)
Return a pointer to the data buffer.
Definition: cmtmessage.h:157
uint8_t m_minute
Definition: cmtdef.h:995
char m_label[CMT_LEN_SCENARIOLABEL+1]
The label of the scenario.
Definition: cmtdef.h:1107
XsensResultValue getSyncOutMode(uint16_t &mode)
Retrieve the outbound synchronization mode of an MT device.
Definition: cmt3.cpp:1317
#define CMT_LEN_SETSCENARIO
Definition: cmtdef.h:282
A structure for storing device modes using period and skip factor (new default)
Definition: cmtdef.h:1051
GLint mode
Definition: glext.h:5753
__int32 int32_t
Definition: rptypes.h:49
uint16_t m_sampleFrequency
Definition: cmtdef.h:1008
#define CMT_BAUDCODE_460K8
Definition: cmtdef.h:508
#define CMT3_DEFAULT_TIMEOUT_MEAS
The default timeout value for L3 data reading.
Definition: cmtdef.h:809
uint8_t getMessageId(void) const
Return the current value of the m_messageId field.
Definition: cmtmessage.h:236
void setPeriodAndSkipFactor(uint16_t period, uint16_t skip)
Compute the sample frequency from a period and skip factor.
Definition: cmt3.cpp:134
XsensResultValue getEMtsData(void *buffer, const CmtDeviceId deviceId=CMT_DID_MASTER)
Retrieve the eMts data of the specified sensor(s).
Definition: cmt3.cpp:658
#define CMT_BID_INVALID
Definition: cmtdef.h:1294
XsensResultValue setLocationId(uint16_t locationId, const CmtDeviceId deviceId=CMT_DID_MASTER)
Set the location ID of a sensor.
Definition: cmt3.cpp:2202
bool m_measuring
Keeps track of whether the connected device is measuring or being configured.
Definition: cmt3.h:77
XsensResultValue close(void)
Close the serial communication port.
Definition: cmt2.cpp:120
XsensResultValue setTimeoutConfig(const uint32_t timeout=CMT3_DEFAULT_TIMEOUT_CONF)
Set the configuration mode timeout.
Definition: cmt3.cpp:2556
const uint8_t * getMessageStart(void) const
Return the start of the message buffer.
Definition: cmtmessage.h:241
bool setDataFormat(const CmtDataFormat &format, const uint16_t index=0)
Definition: cmtpacket.cpp:80
XsensResultValue setSyncInSettings(const CmtSyncInSettings &settings)
Set the inbound synchronization settings of an MT device.
Definition: cmt3.cpp:2242
uint8_t getPortNr(void) const
Retrieve the port number that was last successfully opened.
Definition: cmt1.h:143
#define CMT_MID_GOTOCONFIGACK
Definition: cmtdef.h:298
#define CMT_BAUDCODE_38K4
Definition: cmtdef.h:503
CmtMtTimeStamp m_rtcLastSc
The last received sample counter, used to determine wrap-around.
Definition: cmt3.h:61
XsensResultValue setTimeout(const uint32_t ms=CMT2_DEFAULT_TIMEOUT)
Set the default timeout value to use in blocking operations.
Definition: cmt2.cpp:369
XsensResultValue m_lastResult
The last result of an operation.
Definition: cmt3.h:69
bool isOpen(void) const
Return whether the communication port is open or not.
Definition: cmt2.h:120
#define DO_DATA_REQUEST(req)
Definition: cmt3.cpp:246
bool m_useRtc
Indicates if the RTC should be computed or not (to save CPU time).
Definition: cmt3.h:96
#define CMT3_CONFIG_TIMEOUT
The timeout value for "goto config"-message acknowledgement.
Definition: cmtdef.h:803
#define CMT_MID_REQGRAVITYMAGNITUDE
Definition: cmtdef.h:284
XsensResultValue writeMessage(Message *msg)
Send a message over the COM port.
Definition: cmt2.cpp:597
XsensResultValue m_lastHwError
Contains the last error reported by hardware.
Definition: cmt3.h:89
XsensResultValue create(const char *filename)
Create a new file with level 2 header.
Definition: cmt2.cpp:690
#define CMT_MID_REQEMTS
Definition: cmtdef.h:1295
#define CMT3LOGDAT(...)
Definition: cmt3.cpp:54
uint8_t m_revision
Definition: cmtdef.h:940
XsensResultValue setSyncInSkipFactor(const uint16_t skipFactor)
Set the inbound synchronization skip factor of an MT device.
Definition: cmt3.cpp:2319
GLuint GLsizei GLsizei * length
Definition: glext.h:4079
#define CMT_MID_REQDATALENGTH
Definition: cmtdef.h:114
#define CMT_DEFAULT_SKIP
Definition: cmtdef.h:777
#define CMT_BAUD_RATE_115K2
Definition: cmtdef.h:750
XsensResultValue setSyncMode(const uint8_t mode)
Set the sync mode of the Xbus Master.
Definition: cmt3.cpp:2374
GLint level
Definition: glext.h:3606
uint32_t getTimeoutMeasurement(void) const
Return the measurement mode timeout.
Definition: cmt3.cpp:1421
uint16_t getSampleFrequency(void)
Return current sample frequency.
Definition: cmt3.cpp:1066
#define CMT_MID_REQLOCATIONID
Definition: cmtdef.h:234
XsensResultValue setBluetoothState(const bool enabled)
Set the Bluetooth state of the Xbus Master.
Definition: cmt3.cpp:1976
_u8 status
Definition: rplidar_cmd.h:19
#define CMT_MID_STOREXKFSTATEACK
Definition: cmtdef.h:264
#define CMT_LEN_MAGNETICDECLINATION
Definition: cmtdef.h:230
const char * xsensResultText(const XsensResultValue result)
Definition: xsens_std.cpp:13
#define CMT_BAUDCODE_921K6
Definition: cmtdef.h:509
uint8_t getDataByte(const uint16_t offset=0) const
Return the current value of the data as an unsigned byte (8 bits).
Definition: cmtmessage.h:171
CmtResetMethod
Definition: cmtdef.h:835
uint8_t m_second
Definition: cmtdef.h:996
uint32_t m_nano
Definition: cmtdef.h:990
XsensResultValue waitForDataMessage(Packet *pack)
Wait for a data message to arrive.
Definition: cmt3.cpp:2673
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:770
#define CMT_DID_TYPEH_XM
Definition: cmtdef.h:84
bool isOpen(void) const
Return whether the file is open or not.
Definition: cmt2.cpp:747
#define CMT_LEN_GPSLEVERARM
Definition: cmtdef.h:294
uint16_t m_mode
Definition: cmtdef.h:946
void setXbus(bool xbus, bool convert=false)
Definition: cmtpacket.cpp:109
#define CMT_MID_RESETORIENTATION
Definition: cmtdef.h:490
XsensResultValue getDeviceMode2(CmtDeviceMode2 &mode, const CmtDeviceId deviceId=CMT_DID_MASTER)
Return device mode2.
Definition: cmt3.cpp:636
XsensResultValue setLogMode(bool active)
Set the logging mode.
Definition: cmt3.cpp:2911
The namespace of all Xsens software since 2006.
Definition: cmt1.cpp:95
XsensResultValue peekLogMessageId(uint8_t &messageId)
Open a communication channel to.
Definition: cmt3.cpp:1686
void setDataBuffer(const uint8_t *data, const uint16_t offset=0, const uint16_t count=0)
Write a string of bytes into the data buffer.
Definition: cmtmessage.cpp:505
CmtDeviceConfiguration m_config
The configuration of the connected devices.
Definition: cmt3.h:102
XsensResultValue resetOrientation(const CmtResetMethod method, const CmtDeviceId deviceId=CMT_DID_MASTER)
Perform an orientation reset on a device.
Definition: cmt3.cpp:1848
XsensResultValue getFirmwareRevision(CmtVersion &revision, const CmtDeviceId deviceId=CMT_DID_MASTER)
Return Firmware revision.
Definition: cmt3.cpp:889
uint8_t m_date[8]
Definition: cmtdef.h:873
XsensResultValue getSyncInSkipFactor(uint16_t &skipFactor)
Retrieve the inbound synchronization skip factor of an MT device.
Definition: cmt3.cpp:1197
CmtOutputSettings m_outputSettings
Definition: cmtdef.h:1054
#define CMT_SYNC_CLOCK_TICKS_TO_NS
Definition: cmtdef.h:576
XsensResultValue getLogFileSize(CmtFilePos &size)
Retrieve the size of the open log file in bytes.
Definition: cmt3.cpp:947
XsensResultValue getBluetoothState(bool &enabled)
Get the state of the bluetooth communication.
Definition: cmt3.cpp:444
XsensResultValue closePort(bool gotoConfigFirst=true)
Close the communication port.
Definition: cmt3.cpp:359
void setMessageId(const uint8_t msgId)
Set the new value of the m_messageId field and update the checksum.
Definition: cmtmessage.cpp:726
XsensResultValue setScenario(const uint8_t scenarioType, const CmtDeviceId deviceId=CMT_DID_MASTER)
Specify the scenario to use in the sensor.
Definition: cmt3.cpp:2990
void setBusId(const uint8_t busId)
Set the new value of the m_busId field and update the checksum.
Definition: cmtmessage.cpp:496
#define CMT_PARAM_SYNCOUT_PULSEWIDTH
Definition: cmtdef.h:598
#define CMT_MID_REQOUTPUTSETTINGS
Definition: cmtdef.h:167
GLsizeiptr size
Definition: glext.h:3934
#define CMT_PARAM_SYNCOUT_MODE
Definition: cmtdef.h:595
#define CMT_MID_REQOUTPUTSETTINGSACK
Definition: cmtdef.h:168
#define CMT_BAUD_RATE_921K6
Definition: cmtdef.h:753
#define CMT_SYNC_CLOCK_NS_TO_TICKS
Definition: cmtdef.h:575
void * m_eMtsData[CMT_MAX_DEVICES_PER_PORT]
Cached eMTS data.
Definition: cmt3.h:98
XsensResultValue getBusPowerState(bool &enabled)
Get the state of the Xbus power.
Definition: cmt3.cpp:497
uint16_t getSampleFrequency(void) const
Return the sample frequency in Hz.
Definition: cmt3.cpp:161
A structure for storing device modes.
Definition: cmtdef.h:1004
uint32_t m_masterDeviceId
Definition: cmtdef.h:867
CmtOutputMode m_outputMode
Definition: cmtdef.h:1053
#define CMT_BAUD_RATE_19K2
Definition: cmtdef.h:746
XsensResultValue writeMessage(const Message *msg)
Write a message to the end of the file.
Definition: cmt2.cpp:866
unsigned __int32 uint32_t
Definition: rptypes.h:50
#define CMT_MID_GOTOCONFIG
Definition: cmtdef.h:297
XsensResultValue setSyncInOffset(const uint32_t offset)
Set the inbound synchronization offset of an MT device.
Definition: cmt3.cpp:2345
#define CMT_MID_RESETACK
Definition: cmtdef.h:473
XsensResultValue getBaudrate(uint32_t &baudrate)
Get the baudrate used by a port.
Definition: cmt3.cpp:432
#define CMT_MAX_DEVICES_PER_PORT
Definition: cmtdef.h:774
uint32_t getTimeOfDay(tm *date_, time_t *secs_)
A platform-independent clock.
Definition: xsens_time.cpp:34
#define deviceId
Definition: CIMUXSens.cpp:40
#define CMT_BAUDCODE_9K6
Definition: cmtdef.h:499
uint32_t CmtDeviceId
The type of a Device Id.
Definition: cmtdef.h:854
#define CMT_BID_MASTER
Definition: cmtdef.h:61
uint8_t m_major
Definition: cmtdef.h:938
#define CMT_BAUDCODE_19K2
Definition: cmtdef.h:501
#define CMT_LEN_BUSPWR
Definition: cmtdef.h:111
XsensResultValue setHeading(const double heading, const CmtDeviceId deviceId=CMT_DID_MASTER)
Set the heading offset.
Definition: cmt3.cpp:2190
XsensResultValue setSyncOutMode(const uint16_t mode)
Set the outbound synchronization mode of an MT device.
Definition: cmt3.cpp:2450
uint16_t CmtMtTimeStamp
An MT timestamp (sample count)
Definition: cmtdef.h:924
A structure for storing scenario information.
Definition: cmtdef.h:1099
uint8_t m_reservedForHost[32]
Definition: cmtdef.h:875
#define CMT_MID_MTDATA
Definition: cmtdef.h:300
#define CMT_MID_REQPERIOD
Definition: cmtdef.h:100
uint16_t m_syncinSkipFactor
Definition: cmtdef.h:871
XsensResultValue getXmOutputMode(uint8_t &mode)
Return the dual-output mode of the XM.
Definition: cmt3.cpp:1448
void setDataByte(const uint8_t data, const uint16_t offset=0)
Write an unsigned byte (8 bits) into the data buffer.
Definition: cmtmessage.cpp:523
XsensResultValue gotoConfig(void)
Place all connected devices into Configuration Mode.
Definition: cmt3.cpp:1460
Class for storing a single message.
Definition: cmtmessage.h:83
uint16_t m_period
The sample period of the port.
Definition: cmt3.h:53
#define CMT3_DEFAULT_TIMEOUT_CONF
The default timeout value for L3 configuration settings.
Definition: cmtdef.h:811
#define CMT_MID_SETSCENARIO
Definition: cmtdef.h:280
XsensResultValue setGotoConfigTries(const uint16_t tries)
Set the number of times the gotoConfig function will attempt a gotoConfig before failing.
Definition: cmt3.cpp:2179
#define CMT_MID_REQOPMODE
Definition: cmtdef.h:134
Cmt2f m_logFile
The (optional) CMT level 2 logfile object that this class operates on.
Definition: cmt3.h:47
XsensResultValue flushData(void)
Flush all data to be transmitted / received.
Definition: cmt1.cpp:308
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
Definition: os.cpp:358
XsensResultValue getGravityMagnitude(double &magnitude, const CmtDeviceId deviceId=CMT_DID_MASTER)
Retrieve the currently used magnitude of the gravity vector.
Definition: cmt3.cpp:3001
#define CMT_MAX_SVINFO
Definition: cmtdef.h:1275
void setDataShort(const uint16_t data, const uint16_t offset=0)
Write an uint16_t (16 bits) into the data buffer.
Definition: cmtmessage.cpp:710
XsensResultValue getSyncOutOffset(uint32_t &offset)
Retrieve the outbound synchronization offset of an MT device.
Definition: cmt3.cpp:1393
XsensResultValue readMessage(Message *rcv)
Read a message from the COM port.
Definition: cmt2.cpp:192
#define CMT_MID_REQFILTERSETTINGS
Definition: cmtdef.h:480
Message m_msg
The message.
Definition: cmtpacket.h:78
uint16_t m_outputSkipFactor
Definition: cmtdef.h:869



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