MRPT  1.9.9
int_xsdatapacket.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 #include "int_xsdatapacket.h"
10 #include <xsens/xsbusid.h>
11 #include <xsens/xsdatapacket.h>
12 #include <xsens/xsgpspvtdata.h>
13 #include <xsens/xsmessage.h>
14 #include <xsens/xstypesconfig.h>
15 #include "legacydatapacket.h"
16 #include "mtwsdidata.h"
17 #include "packetfixeddata.h"
18 
19 // lint -esym(1512, XsDataPacket)
20 /*! \internal
21  \brief Hack class to access internals of XsDataPacket in C++
22 */
24 {
25  // lint --e(1511, 1509, 1536)
26  public:
27  //! \brief \copybrief XsDataPacket::m_msg
28  inline XsMessage& msg() { return m_msg; }
29  //! \brief \copybrief XsDataPacket::m_legacyMsg
30  inline XsMessage& legacyMsg() { return m_legacyMsg; }
31  //! \brief \copybrief XsDataPacket::m_deviceId
32  inline XsDeviceId& deviceId() { return m_deviceId; }
33  //! \brief \copybrief XsDataPacket::m_lastFoundId
35  //! \brief \copybrief XsDataPacket::m_lastFoundOffset
36  inline int& lastFoundOffset() { return m_lastFoundOffset; }
37  //! \brief \copybrief XsDataPacket::m_itemCount
38  inline uint16_t& itemCount() { return m_itemCount; }
39  //! \brief \copybrief XsDataPacket::m_originalMessageLength
41  //! \brief \copybrief XsDataPacket::m_toa
42  inline XsTimeStamp& toa() { return m_toa; }
43  //! \brief \copybrief XsDataPacket::m_packetId
44  inline XsTimeStamp& packetId() { return m_packetId; }
45 };
46 
47 /*! \class XsDataPacket
48  \brief Contains data received from a device or read from a file
49 
50  This class is used by XDA for easy access to data contained in a message. It
51  analyzes its internal
52  XsMessage upon contruction to give access to the individual contained pieces
53  of data.
54  New data can also be added to the %XsDataPacket or updated if it already
55  existed.
56 */
57 extern "C"
58 {
59  void validatePacket(XsDataPacket* thisPtr);
60 
62  struct XsDataPacket* thisPtr, struct LegacyDataPacket const* pack,
63  int index)
64  {
65  assert(pack);
66 
67  auto* hacket = (InternalDataPacket*)thisPtr;
68 
69  hacket->legacyMsg() = pack->message();
70 
71  if (!pack->isXbusSystem()) index = 0;
72 
73  hacket->message().clear();
74  if (pack->isXbusSystem())
75  hacket->message().setBusId(index + 1);
76  else
77  hacket->message().setBusId(XS_BID_MASTER);
78 
79  hacket->message().setMessageId(XMID_MtData2);
80  // hacket->m_legacyMsg = pack->message();
81  hacket->deviceId() = pack->deviceId(index);
82  hacket->itemCount() = 1;
83  hacket->toa() = pack->timeOfArrival();
84  hacket->originalMessageLength() =
85  (uint16_t)pack->originalMessage().getDataSize();
86  hacket->packetId() = pack->largePacketCounter();
87  PacketInfo info = pack->packetInfo(index);
90  switch (format.m_outputSettings & XOS_Dataformat_Mask)
91  {
93  di = XDI_SubFormatFloat;
94  break;
97  break;
100  break;
102  di = XDI_SubFormatFp1220;
103  break;
104  default:
105  di = XDI_None;
106  break;
107  }
108  if (pack->containsRawData(index))
109  hacket->setRawData(pack->rawData(index));
110  if (pack->rawTemperatureChannelCount(index) == 4)
111  {
112  XsUShortVector rawGyroTemperatures;
113  rawGyroTemperatures[0] = pack->rawTemperature(index, 1);
114  rawGyroTemperatures[1] = pack->rawTemperature(index, 2);
115  rawGyroTemperatures[2] = pack->rawTemperature(index, 3);
116  hacket->setRawGyroscopeTemperatureData(rawGyroTemperatures);
117  }
119  hacket->setCalibratedAcceleration(
122  {
123  // Special copy to preserve watermarking
124  hacket->message().setDataShort(
125  XDI_RateOfTurn | di, hacket->message().getDataSize());
126  hacket->message().setDataByte(
127  3 * hacket->getFPValueSize(di),
128  hacket->message().getDataSize());
129  hacket->itemCount()++;
130  hacket->message().setDataBuffer(
131  hacket->legacyMsg().getDataBuffer(info.m_calGyr),
132  3 * hacket->getFPValueSize(di),
134  }
136  hacket->setCalibratedMagneticField(
139  hacket->setOrientationQuaternion(
141  (format.m_outputSettings & XOS_Coordinates_Ned)
143  : XDI_CoordSysNwu);
144  if (pack->containsOrientationEuler(index))
145  hacket->setOrientationEuler(
146  pack->orientationEuler(index),
147  (format.m_outputSettings & XOS_Coordinates_Ned)
149  : XDI_CoordSysNwu);
150  if (pack->containsOrientationMatrix(index))
151  hacket->setOrientationMatrix(
152  pack->orientationMatrix(index),
153  (format.m_outputSettings & XOS_Coordinates_Ned)
155  : XDI_CoordSysNwu);
156  if (pack->containsPositionLLA(index))
157  hacket->setPositionLLA(pack->positionLLA(index));
158  if (pack->containsVelocity(index))
159  hacket->setVelocity(
160  pack->velocity(index),
161  (format.m_outputSettings & XOS_Coordinates_Ned)
163  : XDI_CoordSysNwu);
164  if (pack->containsStatus(index))
165  {
166  bool isDetailed = true;
167  uint32_t status = pack->status(index, &isDetailed);
168 
169  // For MTw's only, the status needs to be swapEndian32-ed
170  if (hacket->deviceId().isMtw())
171  {
173  }
174 
175  if (isDetailed)
176  {
177  hacket->setStatus(status);
178  }
179  else
180  {
181  hacket->setStatusByte((uint8_t)status);
182  }
183  }
184  if (pack->containsGpsPvtData())
185  {
186  XsPressure tmp;
187  tmp.m_pressure =
188  pack->gpsPvtData(index).m_pressure * 2.0; // Convert to Pascal
190  hacket->setPressure(tmp);
191  XsGpsPvtData pvt;
192  pvt = pack->gpsPvtData(index);
193  hacket->setGpsPvtData(pvt);
194  }
195  if (pack->containsUtcTime(index))
196  {
197  XsUtcTime time = pack->utcTime(index);
198  hacket->setUtcTime(time);
199  }
200  if (pack->containsMtwSdiData(index))
201  {
202  // not yet converted:
203  // uint8_t m_timeSync;
204  // XsVector3 m_currentBias;
205 
206  MtwSdiData mtwsdi = pack->mtwSdiData(index);
207  hacket->deviceId() = mtwsdi.m_deviceId;
208  {
209  // Special copy to preserve watermarking
210  hacket->message().setDataShort(
211  XDI_DeltaQ | di, hacket->message().getDataSize());
212  hacket->message().setDataByte(
213  4 * hacket->getFPValueSize(di),
214  hacket->message().getDataSize());
215  hacket->itemCount()++;
216  hacket->message().setDataBuffer(
217  hacket->legacyMsg().getDataBuffer(
219  4 * hacket->getFPValueSize(di),
221 
222  hacket->message().setDataShort(
223  XDI_DeltaV | di, hacket->message().getDataSize());
224  hacket->message().setDataByte(
225  3 * hacket->getFPValueSize(di),
226  hacket->message().getDataSize());
227  hacket->itemCount()++;
228  hacket->message().setDataBuffer(
229  hacket->legacyMsg().getDataBuffer(
230  info.m_wVelocityIncrement),
231  3 * hacket->getFPValueSize(di),
233  }
234 
235  // if (mtwsdi.m_aidingData)
236  hacket->setCalibratedMagneticField(mtwsdi.m_magnetoMeter);
237  if (mtwsdi.m_barometer)
238  {
239  XsPressure tmp;
240  tmp.m_pressure = mtwsdi.m_barometer *
241  100.0; // convert from millibar to pascal
242  tmp.m_pressureAge = mtwsdi.m_barometer ? 0 : 255;
243  hacket->setPressure(tmp);
244  }
245  hacket->setFrameRange(XsRange(
246  (int)mtwsdi.m_firstFrameNumber, (int)mtwsdi.m_lastFrameNumber));
247  hacket->setRssi(mtwsdi.m_rssi);
248  }
249  if (pack->containsTemperature(index))
250  hacket->setTemperature(pack->temperature(index));
251  if (pack->containsPacketCounter(index))
252  hacket->setPacketCounter(pack->packetCounter(index));
253 
254  // enable this when you experience weird crashes in XsByteArray_destruct
255  // or XsDataPacket_destruct validatePacket(thisPtr);
256  }
257 
258 } // extern "C"
bool containsMtwSdiData(int32_t index=0) const
Check if data item contains strapdown integration data.
XsMessage & msg()
The message that contains the data.
MtwSdiData mtwSdiData(int32_t index=0) const
Return the strapdown integration (SDI) data component of a data item.
XsScrData rawData(int32_t index=0) const
Return the Raw Data component of a data item.
uint16_t rawTemperature(int32_t index=0, int channel=0) const
Return the Raw Temperature component of a data item.
bool containsOrientationMatrix(int32_t index=0) const
Check if data item contains Matrix Orientation data.
unsigned __int16 uint16_t
Definition: rptypes.h:47
XsDataIdentifier & lastFoundId()
Last found data identifer, speeds up searches.
XsDeviceId & deviceId()
The device Id to which the message belongs.
XsUtcTime utcTime(int32_t index=0) const
Return the UTC Time component of the packet.
bool containsOrientationEuler(int32_t index=0) const
Check if data item contains Euler Orientation data.
bool containsRawData(int32_t index=0) const
Check if data item contains Raw Data.
XsTimeStamp & toa()
Time of arrival (live packets only)
A vector containing 3 short values.
uint16_t m_originalMessageLength
Length of the original message payload.
uint8_t m_pressureAge
The age of the pressure measurement in packets.
Definition: xsgpspvtdata.h:43
Class to store strapdown integration data.
Definition: mtwsdidata.h:19
#define swapEndian32(src)
Definition: cmtmessage.h:77
int rawTemperatureChannelCount(int32_t index=0) const
Returns the number of available Raw Temperature channels.
uint16_t & itemCount()
The number of data items in the message.
XsEuler orientationEuler(int32_t index=0) const
Return the Orientation component of a data item as Euler angles.
XsDataIdentifier
Defines the data identifiers.
XsTimeStamp m_toa
Time of arrival (live packets only)
double temperature(int32_t index=0, int channel=0) const
Return the Temperature component of a data item.
uint8_t m_pressureAge
Age of pressure data in samples.
Definition: xspressure.h:22
XsVector positionLLA(int32_t index=0) const
Return the Position Lat Lon Alt component of a data item.
unsigned char uint8_t
Definition: rptypes.h:44
XsDeviceId m_deviceId
The ID of the device that generated the data.
Definition: mtwsdidata.h:22
XsDataFormat dataFormat(int32_t index=0) const
Returns the data format of the device with the given index.
double m_pressure
Pressure in Pascal.
Definition: xspressure.h:20
void validatePacket(XsDataPacket *thisPtr)
uint16_t m_firstFrameNumber
The first frame number of the SDI interval.
Definition: mtwsdidata.h:27
uint16_t m_calGyr
Offset of calibrated gyroscope data.
bool containsCalibratedAcceleration(int32_t index=0) const
Check if data item contains Calibrated Accelerometer data.
Contains offset information about data in the packet.
int64_t largePacketCounter(void) const
Return the 64-bit sample counter associated with this packet.
Structure for storing a single message.
Definition: xsmessage.h:202
uint16_t m_itemCount
The number of data items in the message.
double m_barometer
The barometer value during the interval.
Definition: mtwsdidata.h:40
XsGpsPvtData gpsPvtData(int32_t index=0) const
Return the Gps PVT data component of a data item.
GLuint index
Definition: glext.h:4068
uint16_t m_wVelocityIncrement
Offset of MTw SDI velocity increment data.
bool containsCalibratedMagneticField(int32_t index=0) const
Check if data item contains Calibrated Magnetometer data.
int8_t m_rssi
The Received Signal Strength Indication (RSSI) of the message.
Definition: mtwsdidata.h:44
XsDataIdentifier m_lastFoundId
Last found data identifer, speeds up searches.
bool containsUtcTime(int32_t index=0) const
Check if data item contains UTC Time.
XsDeviceId deviceId(int32_t index) const
Returns the device ID of the device with the given index.
Class for managing timestamps in a unified way.
Definition: xstimestamp.h:56
bool containsCalibratedGyroscopeData(int32_t index=0) const
Check if data item contains Calibrated Gyroscope data.
XsVector3 m_magnetoMeter
The magnetometer values during the interval.
Definition: mtwsdidata.h:42
int m_lastFoundOffset
Offset of last found data identifier, speeds up searches.
int & lastFoundOffset()
Offset of last found data identifier, speeds up searches.
XsQuaternion orientationQuaternion(int32_t index=0) const
Return the Orientation component of a data item as a Quaternion.
XsMessage originalMessage(void) const
Returns the original message as it was received, without computed and added data (except for SDI inte...
XsDeviceId m_deviceId
The device Id to which the message belongs.
uint16_t m_lastFrameNumber
The last frame number of the SDI interval.
Definition: mtwsdidata.h:30
uint16_t m_pressure
The pressure measurement in units of 2 Pascal, only valid if m_pressureAge is not 255...
Definition: xsgpspvtdata.h:39
bool containsPacketCounter(int32_t index=0) const
Check if data item contains Sample Counter.
Contains an MTData XsMessage and supports functions for extracting contained data.
A structure for storing data formats.
Definition: xsdataformat.h:17
XsMessage message(void) const
Returns a copy of the XsMessage contained by the object, including computed and added data...
A structure for storing UTC Time values.
Definition: xsutctime.h:15
PacketInfo packetInfo(int32_t index) const
Returns the packet info for the index&#39;th device in the packet.
bool containsPositionLLA(int32_t index=0) const
Check if data item contains Position Lat Lon Alt.
uint16_t packetCounter(int32_t index=0) const
Return the Sample Counter component of the packet.
uint32_t status(int32_t index, bool *outIsDetailed) const
Return the Status component of a data item.
XsMessage & legacyMsg()
Optional legacy MtData message as received (for logging the received data only)
XsMessage m_msg
The message that contains the data.
bool containsOrientationQuaternion(int32_t index=0) const
Check if data item contains Quaternion Orientation data.
struct XsRange XsRange
Definition: xsrange.h:91
_u8 status
Definition: rplidar_cmd.h:19
uint16_t & originalMessageLength()
Length of the original message payload.
Contains data received from a device or read from a file.
Definition: xsdatapacket.h:315
XsMessage m_legacyMsg
Optional legacy MtData message as received (for logging the received data only)
XsVector calibratedAcceleration(int32_t index=0) const
Return the Calibrated Accelerometer component of a data item.
GLenum GLsizei GLenum format
Definition: glext.h:3535
uint16_t m_wOrientationIncrement
Offset of MTw SDI orientation increment data.
bool containsVelocity(int32_t index=0) const
Check if data item contains Velocity.
bool containsStatus(int32_t index=0) const
Check if data item contains Status.
XsMatrix orientationMatrix(int32_t index=0) const
Return the Orientation component of a data item as an Orientation Matrix.
unsigned __int32 uint32_t
Definition: rptypes.h:50
XsVector calibratedMagneticField(int32_t index=0) const
Return the Calibrated Magnetometer component of a data item.
bool containsTemperature(int32_t index=0, int channel=0) const
Check if data item contains Temperature data.
XsTimeStamp m_packetId
64 bit packet id, based on, depending on availability: (1) packet counter (2) sample time (3) arrival...
bool containsGpsPvtData(int32_t index=0) const
Check if data item contains Gps PVT Data.
XsVector velocity(int32_t index=0) const
Return the Velocity component of a data item.
bool isXbusSystem(void) const
Returns whether the xbus flag is set or not.
void XsDataPacket_assignFromXsLegacyDataPacket(struct XsDataPacket *thisPtr, struct LegacyDataPacket const *pack, int index)
XsTimeStamp timeOfArrival(void) const
Returns the Time Of Arrival value as stored in the object.
Data from the GPS unit of a legacy MTi-G.
Definition: xsgpspvtdata.h:35
Pressure data.
Definition: xspressure.h:17
#define XS_BID_MASTER
The bus identifier of the master device.
Definition: xsbusid.h:17
XsTimeStamp & packetId()
64 bit packet id, based on, depending on availability: (1) packet counter (2) sample time (3) arrival...
XSTYPES_DLL_API int XsDataPacket_itemOffsetExact(const XsDataPacket *thisPtr, XsDataIdentifier id)



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