Debian Codegraph @

3rdparty/xspublic/xstypes/xsdatapacket.cpp

raw
1
2 // Copyright (c) 2003-2019 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32
33 #include "xsdatapacket.h"
34 #include "datapacket_p.h"
35 #include "xsmatrix3x3.h"
36 #include "xsvector.h"
37 #include "xsrssi.h"
38 #include "xsmath.h"
39 #include <string.h>
40
41 #define MAP (*thisPtr->d)
42
43 static const uint64_t coarseFactor = 10000ULL;
44
45 using namespace XsDataPacket_Private;
46
47 static void detach(XsDataPacket* thisPtr)
48 {
49 if (thisPtr->d->m_refCount == 1)
50 return;
51 DataPacketPrivate* old = thisPtr->d;
52 thisPtr->d = new DataPacketPrivate(*old);
53 if (--old->m_refCount == 0) // this can happen in some concurrent situations
54 delete old;
55 }
56
57 Variant* createVariant(XsDataIdentifier id)
58 {
59 // It may be faster to create a static map with construct functions instead of this switch, but this is a much simpler implementation
60 switch (id & XDI_FullTypeMask)
61 {
62 //XDI_TemperatureGroup = 0x0800,
63 case XDI_Temperature:
64 return new SimpleVariant<double>(id);
65 //case XDI_TimestampGroup :// 0x1000,
66 case XDI_UtcTime :// 0x1010,
67 return new XsTimeInfoVariant(id);
68 case XDI_PacketCounter :// 0x1020,
69 return new SimpleVariant<uint16_t>(id);
70 case XDI_Itow :// 0x1030,
71 return new SimpleVariant<uint32_t>(id);
72 case XDI_GnssAge :// 0x1040,
73 return new SimpleVariant<uint8_t>(id);
74 case XDI_PressureAge :// 0x1050,
75 return new SimpleVariant<uint8_t>(id);
76 case XDI_SampleTimeFine :// 0x1060,
77 case XDI_SampleTimeCoarse :// 0x1070,
78 return new SimpleVariant<uint32_t>(id);
79 case XDI_FrameRange :// 0x1080, // add for MTw (if needed)
80 return new XsRangeVariant(id);
81 case XDI_PacketCounter8 :// 0x1090,
82 return new SimpleVariant<uint8_t>(id);
83 case XDI_SampleTime64 :// 0x10A0,
84 return new SimpleVariant<uint64_t>(id);
85
86 //case XDI_OrientationGroup :// 0x2000,
87 case XDI_Quaternion :// 0x2010,
88 return new XsQuaternionVariant(id);
89 case XDI_RotationMatrix :// 0x2020,
90 return new XsMatrixVariant(id);
91 case XDI_EulerAngles :// 0x2030,
92 return new XsEulerVariant(id);
93
94 //case XDI_PressureGroup :// 0x3000,
95 case XDI_BaroPressure :// 0x3010,
96 return new SimpleVariant<uint32_t>(id);
97
98 //case XDI_AccelerationGroup :// 0x4000,
99 case XDI_DeltaV :// 0x4010,
100 case XDI_Acceleration :// 0x4020,
101 case XDI_FreeAcceleration :// 0x4030,
102 case XDI_AccelerationHR :// 0x4040,
103 return new XsVector3Variant(id);
104
105 //case XDI_PositionGroup :// 0x5000,
106 case XDI_AltitudeMsl :// 0x5010,
107 case XDI_AltitudeEllipsoid :// 0x5020,
108 return new SimpleVariant<double>(id);
109 case XDI_PositionEcef :// 0x5030,
110 return new XsVector3Variant(id);
111 case XDI_LatLon :// 0x5040,
112 return new XsVector2Variant(id);
113
114 //case XDI_SnapshotGroup :// 0xC800,
115 //case XDI_RetransmissionMask :// 0x0001,
116 //case XDI_RetransmissionFlag :// 0x0001,
117 case XDI_AwindaSnapshot :// 0xC810,
118 return new XsAwindaSnapshotVariant(id);
119 case XDI_FullSnapshot :// 0xC820,
120 return new XsFullSnapshotVariant(id);
121
122 //case XDI_GnssGroup :// 0x7000,
123 case XDI_GnssPvtData :// 0x7010,
124 return new XsRawGnssPvtDataVariant(id);
125 case XDI_GnssSatInfo :// 0x7020,
126 return new XsRawGnssSatInfoVariant(id);
127
128 //case XDI_AngularVelocityGroup :// 0x8000,
129 case XDI_RateOfTurn :// 0x8020,
130 case XDI_RateOfTurnHR :// 0x8040,
131 return new XsVector3Variant(id);
132 case XDI_DeltaQ :// 0x8030,
133 return new XsQuaternionVariant(id);
134
135 //case XDI_RawSensorGroup :// 0xA000,
136 //case XDI_RawUnsigned :// 0x0000, //!< Tracker produces unsigned raw values, usually fixed behavior
137 //case XDI_RawSigned :// 0x0001, //!< Tracker produces signed raw values, usually fixed behavior
138 case XDI_RawAccGyrMagTemp :// 0xA010,
139 return new XsScrDataVariant(id);
140
141 case XDI_RawGyroTemp :// 0xA020,
142 case XDI_RawAcc :// 0xA030,
143 case XDI_RawGyr :// 0xA040,
144 case XDI_RawMag :// 0xA050,
145 return new XsUShortVectorVariant(id);
146
147 case XDI_RawDeltaQ :// 0xA060,
148 return new XsQuaternionVariant(id);
149 case XDI_RawDeltaV :// 0xA070,
150 return new XsVector3Variant(id);
151
152 //case XDI_AnalogInGroup :// 0xB000,
153 case XDI_AnalogIn1 :// 0xB010,
154 case XDI_AnalogIn2 :// 0xB020,
155 return new SimpleVariant<uint16_t>(id);
156
157 //case XDI_MagneticGroup :// 0xC000,
158 case XDI_MagneticField :// 0xC020,
159 case XDI_MagneticFieldCorrected :// 0xC040,
160
161 //case XDI_VelocityGroup :// 0xD000,
162 case XDI_VelocityXYZ :// 0xD010,
163 return new XsVector3Variant(id);
164
165 //case XDI_StatusGroup :// 0xE000,
166 case XDI_StatusByte :// 0xE010,
167 return new SimpleVariant<uint8_t>(id);
168 case XDI_StatusWord :// 0xE020,
169 return new SimpleVariant<uint32_t>(id);
170 case XDI_Rssi :// 0xE040,
171 return new SimpleVariant<uint8_t>(id);
172 case XDI_DeviceId :// 0xE080,
173 return new SimpleVariant<uint32_t>(id);
174 case XDI_LocationId :// 0xE090
175 return new SimpleVariant<uint16_t>(id);
176
177 //case XDI_IndicationGroup :// 0x4800, // 0100.1000 -> bit reverse = 0001.0010 -> type 18
178 case XDI_TriggerIn1 :// 0x4810,
179 case XDI_TriggerIn2 :// 0x4820,
180 return new XsTriggerIndicationDataVariant(id);
181
182 case XDI_RawBlob :// 0xA080
183 return new XsByteArrayVariant(id);
184
185 case XDI_GloveSnapshot: // 0xC830
186 return new XsGloveSnapshotVariant(id);
187 case XDI_GloveData: // 0xC840
188 return new XsGloveDataVariant(id);
189
190 default:
191 //JLERRORG("Unknown id: " << id);
192 assert(0);
193 return nullptr;
194 }
195 }
196
197 XsUShortVector* rawVector(const XsDataPacket* thisPtr, XsUShortVector* returnVal, XsDataIdentifier id, XsUShortVector XsScrData::* field)
198 {
199 assert(returnVal);
200 auto it = MAP.find(XDI_RawAccGyrMagTemp);
201 if (it != MAP.end())
202 *returnVal = it->second->toDerived<XsScrDataVariant>().m_data.*field;
203 else
204 {
205 it = MAP.find(id);
206 if (it != MAP.end())
207 *returnVal = it->second->toDerived<XsUShortVectorVariant>().m_data;
208 }
209 return returnVal;
210 }
211
212 void setRawVector(XsDataPacket* thisPtr, const XsUShortVector* vec, XsDataIdentifier id, XsUShortVector XsScrData::* field)
213 {
214 detach(thisPtr);
215 auto it = MAP.find(XDI_RawAccGyrMagTemp);
216 if (it != MAP.end())
217 it->second->toDerived<XsScrDataVariant>().m_data.*field = *vec;
218 else
219 {
220 it = MAP.find(id);
221 if (it != MAP.end())
222 it->second->toDerived<XsUShortVectorVariant>().m_data = *vec;
223 else
224 MAP.insert(id, new XsUShortVectorVariant(id, *vec));
225 }
226 }
227
228 template <typename T, typename V>
229 T* genericGet(const XsDataPacket* thisPtr, T* returnVal, XsDataIdentifier id, T const& failValue = T())
230 {
231 assert(returnVal);
232 auto it = MAP.find(id);
233 if (it != MAP.end())
234 *returnVal = it->second->toDerived<V>().m_data;
235 else
236 *returnVal = failValue;
237 return returnVal;
238 }
239
240 template <typename T, typename V>
241 void genericSet(XsDataPacket* thisPtr, T const* val, XsDataIdentifier id)
242 {
243 detach(thisPtr);
244 assert(val);
245 auto it = MAP.find(id);
246 if (it != MAP.end())
247 {
248 it->second->toDerived<V>().m_data = *val;
249 it->second->setDataId(id);
250 }
251 else
252 MAP.insert(id, new V(id, *val));
253 }
254
255 template <typename T, typename V = SimpleVariant<T>>
256 struct GenericSimple {
257 static T get(const XsDataPacket* thisPtr, XsDataIdentifier id, T const& failValue = T())
258 {
259 auto it = MAP.find(id);
260 if (it != MAP.end())
261 return it->second->toDerived<V>().m_data;
262 return failValue;
263 }
264
265 static void set(XsDataPacket* thisPtr, T val, XsDataIdentifier id)
266 {
267 detach(thisPtr);
268 auto it = MAP.find(id);
269 if (it != MAP.end())
270 it->second->toDerived<V>().m_data = val;
271 else
272 MAP.insert(id, new V(id, val));
273 }
274 };
275
276 inline bool genericContains(const XsDataPacket* thisPtr, XsDataIdentifier id)
277 {
278 return MAP.find(id) != MAP.end();
279 }
280
281 /*! \cond XS_INTERNAL */
282 /*! \relates XsDataPacket
283 \brief Check if data item contains quaternion orientation data
284 \returns true if this packet contains quaternion orientation data
285 */
286 int XsDataPacket_containsOrientationQuaternion(const XsDataPacket* thisPtr)
287 {
288 return genericContains(thisPtr, XDI_Quaternion);
289 }
290
291 /*! \relates XsDataPacket
292 \brief Check if data item contains euler orientation data
293 \returns true if this packet contains euler orientation data
294 */
295 int XsDataPacket_containsOrientationEuler(const XsDataPacket* thisPtr)
296 {
297 return genericContains(thisPtr, XDI_EulerAngles);
298 }
299
300 /*! \relates XsDataPacket
301 \brief Check if data item contains matrix orientation data
302 \returns true if this packet contains matrix orientation data
303 */
304 int XsDataPacket_containsOrientationMatrix(const XsDataPacket* thisPtr)
305 {
306 return genericContains(thisPtr, XDI_RotationMatrix);
307 }
308
309 /*! \brief Returns quaternion that defines the rotation necessary to rotate from coordinate system
310 \a actual to \a desired when used as the left side in a quaternion multiplication
311 */
312 XsQuaternion preRotFromXdi(XsDataIdentifier actual, XsDataIdentifier desired)
313 {
314 static const XsQuaternion q_id(1, 0, 0, 0); // x -> x
315 static const XsQuaternion q_nwu2ned(0, 1, 0, 0); // nwu -> ned = 180 degrees x
316 static const XsQuaternion q_enu2nwu(1.4142135623730950488016887242097*0.5, 0, 0, -1.4142135623730950488016887242097*0.5); // enu -> nwu = 90 degrees z
317 static const XsQuaternion q_enu2ned(0, -1.4142135623730950488016887242097*0.5, -1.4142135623730950488016887242097*0.5, 0); // enu -> ned = 90 degrees z followed by 180 degrees x
318
319 static const XsQuaternion q_ned2nwu(0, -1, 0, 0);
320 static const XsQuaternion q_nwu2enu(1.4142135623730950488016887242097*0.5, 0, 0, 1.4142135623730950488016887242097*0.5);
321 static const XsQuaternion q_ned2enu(0, 1.4142135623730950488016887242097*0.5, 1.4142135623730950488016887242097*0.5, 0);
322
323 switch (desired & XDI_CoordSysMask)
324 {
325 default:
326 case XDI_CoordSysEnu:
327 switch (actual & XDI_CoordSysMask)
328 {
329 default:
330 case XDI_CoordSysEnu:
331 return q_id;
332
333 case XDI_CoordSysNed:
334 return q_ned2enu;
335
336 case XDI_CoordSysNwu:
337 return q_nwu2enu;
338 }
339
340 case XDI_CoordSysNed:
341 switch (actual & XDI_CoordSysMask)
342 {
343 default:
344 case XDI_CoordSysEnu:
345 return q_enu2ned;
346
347 case XDI_CoordSysNed:
348 return q_id;
349
350 case XDI_CoordSysNwu:
351 return q_nwu2ned;
352 }
353
354 case XDI_CoordSysNwu:
355 switch (actual & XDI_CoordSysMask)
356 {
357 default:
358 case XDI_CoordSysEnu:
359 return q_enu2nwu;
360
361 case XDI_CoordSysNed:
362 return q_ned2nwu;
363
364 case XDI_CoordSysNwu:
365 return q_id;
366 }
367 }
368 }
369
370 /*! \endcond */
371
372
373 /*! \class XsDataPacket
374 \brief Contains an interpreted data message. The class provides easy access to the contained
375 data through its many functions.
376 \sa cinterface For the C interface functions.
377 */
378
379 /*! \addtogroup cinterface C Interface
380 @{
381 */
382
383 extern "C" {
384
385 /*! \brief Inits a data packet, the packet will be empty after construction
386 */
387 void XsDataPacket_construct(XsDataPacket* thisPtr)
388 {
389 thisPtr->d = new DataPacketPrivate;
390 thisPtr->m_deviceId = 0;
391 thisPtr->m_toa = 0;
392 thisPtr->m_packetId = -1;
393 thisPtr->m_etos = 0;
394 }
395
396 /*! \brief Inits a data packet as a (referenced) copy of \a src
397 */
398 void XsDataPacket_copyConstruct(XsDataPacket* thisPtr, XsDataPacket const* src)
399 {
400 ++src->d->m_refCount;
401 thisPtr->d = src->d;
402 thisPtr->m_deviceId = src->m_deviceId;
403 thisPtr->m_toa = src->m_toa;
404 thisPtr->m_packetId = src->m_packetId;
405 thisPtr->m_etos = src->m_etos;
406 }
407
408 /*! \brief Clears and frees data in an XsDataPacket
409 */
410 void XsDataPacket_destruct(XsDataPacket* thisPtr)
411 {
412 if (thisPtr->d && --thisPtr->d->m_refCount == 0)
413 delete thisPtr->d;
414 thisPtr->d = nullptr;
415 }
416
417 /*! \brief Clears all data in an XsDataPacket
418 \param id The id to clear, supply XDI_None to clear the entire object
419 */
420 void XsDataPacket_clear(XsDataPacket* thisPtr, XsDataIdentifier id)
421 {
422 detach(thisPtr);
423 if (id == XDI_None)
424 {
425 XsDataPacket_destruct(thisPtr);
426 XsDataPacket_construct(thisPtr);
427 }
428 else
429 MAP.erase(id);
430 }
431
432 /*! \brief Copy the XsDataPacket to \a copy
433 \param copy The object to copy to
434 \param src The source to copy from
435 */
436 void XsDataPacket_copy(XsDataPacket* copy, XsDataPacket const* src)
437 {
438 if (copy->d != src->d)
439 {
440 ++src->d->m_refCount;
441 if (--copy->d->m_refCount == 0)
442 delete copy->d;
443 copy->d = src->d;
444 }
445 copy->m_deviceId = src->m_deviceId;
446 copy->m_toa = src->m_toa;
447 copy->m_packetId = src->m_packetId;
448 copy->m_etos = src->m_etos;
449 }
450
451 /*! \brief Swaps the XsDataPackets in \a thisPtr and \a other
452 \param other The object to swap with
453 */
454 void XsDataPacket_swap(XsDataPacket* thisPtr, XsDataPacket* other)
455 {
456 std::swap(thisPtr->d, other->d);
457 std::swap(thisPtr->m_deviceId, other->m_deviceId);
458 std::swap(thisPtr->m_toa, other->m_toa);
459 std::swap(thisPtr->m_packetId, other->m_packetId);
460 std::swap(thisPtr->m_etos, other->m_etos);
461 }
462
463 /*! \brief Returns whether the datapacket is empty
464 \return True when the XsDataPacket is empty
465 */
466 int XsDataPacket_empty(const XsDataPacket* thisPtr)
467 {
468 return 0 != MAP.empty();
469 }
470
471 /*! \brief Returns the number of individual items in the XsDataPacket
472 \return The number of individual items in the XsDataPacket
473 */
474 int XsDataPacket_itemCount(const XsDataPacket* thisPtr)
475 {
476 assert(thisPtr);
477 return (int) MAP.size();
478 }
479
480 /*! \brief Returns the dataformat of a specific data identifier in the packet
481
482 \param id : The XsDataIdentifier to query
483 \returns Returns XDI_None if the packet does not contain the dataidentifier, the data
484 format otherwise
485
486 \sa XsDataIdentifier
487 */
488 XsDataIdentifier XsDataPacket_dataFormat(const XsDataPacket* thisPtr, XsDataIdentifier id)
489 {
490 auto it = MAP.find(id);
491 if (it == MAP.end())
492 return XDI_None;
493 return it->second->dataId() & XDI_SubFormatMask;
494 }
495
496 /*! \brief helper for XsDataPacket_convertRawVector */
497 static XsReal signed_cast(uint16_t v)
498 {
499 return (int16_t)v;
500 }
501
502 /*! \brief helper for XsDataPacket_convertRawVector */
503 static XsReal unsigned_cast(uint16_t v)
504 {
505 return v;
506 }
507
508 /*! \brief The raw accelerometer component of a data item.
509
510 \param returnVal : An XsUShortVector to put the requested data in
511
512 \returns A XsUShortVector containing the x, y and z axis values in that order
513 */
514 XsUShortVector* XsDataPacket_rawAcceleration(const XsDataPacket* thisPtr, XsUShortVector* returnVal)
515 {
516 return rawVector(thisPtr, returnVal, XDI_RawAcc, &XsScrData::m_acc);
517 }
518
519 /*! \brief Check if data item contains Raw Accelerometer data
520 \returns true if this packet contains raw acceleration data
521 */
522 int XsDataPacket_containsRawAcceleration(const XsDataPacket* thisPtr)
523 {
524 return MAP.find(XDI_RawAccGyrMagTemp) != MAP.end() ||
525 MAP.find(XDI_RawAcc) != MAP.end();
526 }
527
528 /*! \brief Add/update raw accelerometer data for the item
529
530 \param vec : The data to update the XsDataPacket with
531
532 \details This will add the raw acceleration from \a vec to the data packet. If
533 the packet already contains raw acceleration, it will be replaced.
534 */
535 void XsDataPacket_setRawAcceleration(XsDataPacket* thisPtr, const XsUShortVector* vec)
536 {
537 setRawVector(thisPtr, vec, XDI_RawAcc, &XsScrData::m_acc);
538 }
539
540 /*! \brief The raw gyroscope component of a data item.
541
542 \param returnVal : An XsUShortVector to put the requested data in
543
544 \returns A XsUShortVector containing the x, y and z axis values in that order
545 */
546 XsUShortVector* XsDataPacket_rawGyroscopeData(const XsDataPacket* thisPtr, XsUShortVector* returnVal)
547 {
548 return rawVector(thisPtr, returnVal, XDI_RawGyr, &XsScrData::m_gyr);
549 }
550
551 /*! \brief Check if data item contains raw gyroscope data
552 \returns true if this packet contains raw gyroscope data
553 */
554 int XsDataPacket_containsRawGyroscopeData(const XsDataPacket* thisPtr)
555 {
556 return genericContains(thisPtr, XDI_RawAccGyrMagTemp) || genericContains(thisPtr, XDI_RawGyr);
557 }
558
559 /*! \brief Add/update raw gyroscope data for the item
560 \param vec The new data to set
561 */
562 void XsDataPacket_setRawGyroscopeData(XsDataPacket* thisPtr, const XsUShortVector* vec)
563 {
564 setRawVector(thisPtr, vec, XDI_RawGyr, &XsScrData::m_gyr);
565 }
566
567 /*! \brief The raw magnetometer component of a data item.
568
569 \param returnVal : An XsUShortVector to put the requested data in
570
571 \returns A XsUShortVector containing the x, y and z axis values in that order
572 */
573 XsUShortVector* XsDataPacket_rawMagneticField(const XsDataPacket* thisPtr, XsUShortVector* returnVal)
574 {
575 return rawVector(thisPtr, returnVal, XDI_RawMag, &XsScrData::m_mag);
576 }
577
578 /*! \brief Check if data item contains raw magnetometer data
579 \returns true if this packet contains raw magnetometer data
580 */
581 int XsDataPacket_containsRawMagneticField(const XsDataPacket* thisPtr)
582 {
583 return MAP.find(XDI_RawAccGyrMagTemp) != MAP.end() ||
584 MAP.find(XDI_RawMag) != MAP.end();
585 }
586
587 /*! \brief Add/update raw magnetometer data for the item
588 \param vec The new data to set
589 */
590 void XsDataPacket_setRawMagneticField(XsDataPacket* thisPtr, const XsUShortVector* vec)
591 {
592 setRawVector(thisPtr, vec, XDI_RawMag, &XsScrData::m_mag);
593 }
594
595 /*! \brief The raw temperature component of a data item.
596
597 \returns An uint16_t containing the raw temperature value
598 */
599 uint16_t XsDataPacket_rawTemperature(const XsDataPacket* thisPtr)
600 {
601 auto it = MAP.find(XDI_RawAccGyrMagTemp);
602 if (it != MAP.end())
603 return it->second->toDerived<XsScrDataVariant>().m_data.m_temp;
604 else
605 return 0;
606 }
607
608 /*! \brief Check if data item contains raw temperature data
609 \returns true if this packet contains raw temperature data
610 */
611 int XsDataPacket_containsRawTemperature(const XsDataPacket* thisPtr)
612 {
613 return MAP.find(XDI_RawAccGyrMagTemp) != MAP.end();
614 }
615
616 /*! \brief Add/update raw temperature data for the item
617 \param temp The new data to set
618 */
619 void XsDataPacket_setRawTemperature(XsDataPacket* thisPtr, uint16_t temp)
620 {
621 detach(thisPtr);
622 auto it = MAP.find(XDI_RawAccGyrMagTemp);
623 if (it != MAP.end())
624 {
625 it->second->toDerived<XsScrDataVariant>().m_data.m_temp = temp;
626 }
627 else
628 {
629 auto v = new XsScrDataVariant(XDI_RawAccGyrMagTemp);
630 v->m_data.m_temp = temp;
631 MAP.insert(XDI_RawAccGyrMagTemp, v);
632 }
633 }
634
635 /*! \brief The raw gyroscope temperature component of a data item.
636
637 \param returnVal : An XsUShortVector to put the requested data in
638
639 \returns A XsUShortVector containing the x, y and z axis values in that order
640 */
641 XsUShortVector* XsDataPacket_rawGyroscopeTemperatureData(const XsDataPacket* thisPtr, XsUShortVector* returnVal)
642 {
643 assert(returnVal);
644 auto it = MAP.find(XDI_RawGyroTemp);
645 if (it != MAP.end())
646 *returnVal = it->second->toDerived<XsUShortVectorVariant>().m_data;
647 return returnVal;
648 }
649
650 /*! \brief Check if data item contains raw gyroscope temperature data
651 \returns true if this packet contains raw gyroscope temperature data
652 */
653 int XsDataPacket_containsRawGyroscopeTemperatureData(const XsDataPacket* thisPtr)
654 {
655 return MAP.find(XDI_RawGyroTemp) != MAP.end();
656 }
657
658 /*! \brief Add/update raw gyroscope temperature data for the item
659 \param vec The new data to set
660 */
661 void XsDataPacket_setRawGyroscopeTemperatureData(XsDataPacket* thisPtr, const XsUShortVector* vec)
662 {
663 detach(thisPtr);
664 auto it = MAP.find(XDI_RawGyroTemp);
665 if (it != MAP.end())
666 it->second->toDerived<XsUShortVectorVariant>().m_data = *vec;
667 else
668 {
669 auto v = new XsUShortVectorVariant(XDI_RawGyroTemp);
670 v->m_data = *vec;
671 MAP.insert(XDI_RawGyroTemp, v);
672 }
673 }
674
675 /*! \brief Return the raw data component of a data item.
676 \param returnVal The object to store the requested data in
677 \return The raw data component of a data item.
678 */
679 XsScrData* XsDataPacket_rawData(const XsDataPacket* thisPtr, XsScrData* returnVal)
680 {
681 assert(returnVal);
682 auto it = MAP.find(XDI_RawAccGyrMagTemp);
683 if (it != MAP.end())
684 *returnVal = it->second->toDerived<XsScrDataVariant>().m_data;
685 else
686 {
687 for (XsSize i = 0; i < 3; ++i)
688 {
689 returnVal->m_acc[i] = 0;
690 returnVal->m_gyr[i] = 0;
691 returnVal->m_mag[i] = 0;
692 }
693 returnVal->m_temp = 0;
694 }
695 return returnVal; // not found
696 }
697
698 /*! \brief Check if data item contains raw data
699 \returns true if this packet contains raw data
700 */
701 int XsDataPacket_containsRawData(const XsDataPacket* thisPtr)
702 {
703 return genericContains(thisPtr, XDI_RawAccGyrMagTemp);
704 }
705
706 /*! \brief Add/update raw data for the item
707 \param data The new data to set
708 */
709 void XsDataPacket_setRawData(XsDataPacket* thisPtr, const XsScrData* data)
710 {
711 detach(thisPtr);
712 auto it = MAP.find(XDI_RawAccGyrMagTemp);
713 if (it != MAP.end())
714 it->second->toDerived<XsScrDataVariant>().m_data = *data;
715 else
716 {
717 auto v = new XsScrDataVariant(XDI_RawAccGyrMagTemp);
718 v->m_data = *data;
719 MAP.insert(XDI_RawAccGyrMagTemp, v);
720 }
721 }
722
723 /*! \brief The delta velocity (deltaV) component of a data item.
724 \param returnVal : The XsVector that the deltaV will be assigned to
725 \returns An XsVector containing the x, y and z axis values in that order
726 */
727 XsVector* XsDataPacket_velocityIncrement(const XsDataPacket* thisPtr, XsVector* returnVal)
728 {
729 return genericGet<XsVector, XsVector3Variant>(thisPtr, returnVal, XDI_DeltaV);
730 }
731
732 /*! \brief Check if data item contains delta velocity data
733 \returns true if this packet contains delta velocity data
734 */
735 int XsDataPacket_containsVelocityIncrement(const XsDataPacket* thisPtr)
736 {
737 return genericContains(thisPtr, XDI_DeltaV);
738 }
739
740 /*! \brief Add/update delta velocity data for the item
741 \param vec : The data to update the XsDataPacket with
742 */
743 void XsDataPacket_setVelocityIncrement(XsDataPacket* thisPtr, const XsVector* vec)
744 {
745 genericSet<XsVector, XsVector3Variant>(thisPtr, vec, XDI_DeltaV | XDI_SubFormatDouble);
746 }
747
748 /*! \brief The calibrated accelerometer component of a data item.
749
750 \param returnVal : The XsVector that the calibrated acceleration will be assigned to
751
752 \returns A XsVector containing the x, y and z axis values in that order
753 */
754 XsVector* XsDataPacket_calibratedAcceleration(const XsDataPacket* thisPtr, XsVector* returnVal)
755 {
756 return genericGet<XsVector, XsVector3Variant>(thisPtr, returnVal, XDI_Acceleration);
757 }
758
759 /*! \brief Check if data item contains calibrated accelerometer data
760 \returns true if this packet contains calibrated accelerometer data
761 */
762 int XsDataPacket_containsCalibratedAcceleration(const XsDataPacket* thisPtr)
763 {
764 return genericContains(thisPtr, XDI_Acceleration);
765 }
766
767 /*! \brief Add/update calibrated accelerometer data for the item
768 \param vec : The data to update the XsDataPacket with
769 */
770 void XsDataPacket_setCalibratedAcceleration(XsDataPacket* thisPtr, const XsVector* vec)
771 {
772 genericSet<XsVector, XsVector3Variant>(thisPtr, vec, XDI_Acceleration | XDI_SubFormatDouble);
773 }
774
775
776 /*! \brief The delta quaternion (deltaQ) component of a data item.
777 \param returnVal : The XsQuaternion that the deltaQ will be assigned to
778 \returns An XsQuaternion containing the deltaQ value
779 */
780 XsQuaternion* XsDataPacket_orientationIncrement(const XsDataPacket* thisPtr, XsQuaternion* returnVal)
781 {
782 return genericGet<XsQuaternion, XsQuaternionVariant>(thisPtr, returnVal, XDI_DeltaQ);
783 }
784
785 /*! \brief Check if data item contains delta quaternion data
786 \returns true if this packet contains delta quaternion data
787 */
788 int XsDataPacket_containsOrientationIncrement(const XsDataPacket* thisPtr)
789 {
790 return genericContains(thisPtr, XDI_DeltaQ);
791 }
792
793 /*! \brief Add/update delta quaternion data for the item
794 \param quat : The data to update the XsDataPacket with
795 */
796 void XsDataPacket_setOrientationIncrement(XsDataPacket* thisPtr, const XsQuaternion* quat)
797 {
798 genericSet<XsQuaternion, XsQuaternionVariant>(thisPtr, quat, XDI_DeltaQ | XDI_SubFormatDouble);
799 }
800
801 /*! \brief The calibrated gyroscope component of a data item.
802
803 \param returnVal : An XsVector to put the requested data in
804
805 \returns A XsUShortVector containing the x, y and z axis values in that order
806 */
807 XsVector* XsDataPacket_calibratedGyroscopeData(const XsDataPacket* thisPtr, XsVector* returnVal)
808 {
809 return genericGet<XsVector, XsVector3Variant>(thisPtr, returnVal, XDI_RateOfTurn);
810 }
811
812 /*! \brief Check if data item contains calibrated gyroscope data
813 \returns true if this packet contains calibrated gyroscope data
814 */
815 int XsDataPacket_containsCalibratedGyroscopeData(const XsDataPacket* thisPtr)
816 {
817 return genericContains(thisPtr, XDI_RateOfTurn);
818 }
819
820 /*! \brief Add/update calibrated gyroscope data for the item
821 \param vec : The data to update the XsDataPacket with
822 */
823 void XsDataPacket_setCalibratedGyroscopeData(XsDataPacket* thisPtr, const XsVector* vec)
824 {
825 genericSet<XsVector, XsVector3Variant>(thisPtr, vec, XDI_RateOfTurn | XDI_SubFormatDouble);
826 }
827
828 /*! \brief The calibrated magnetometer component of a data item.
829
830 \param returnVal : An XsVector to put the requested in
831
832 \returns A XsUShortVector containing the x, y and z axis values in that order
833 */
834 XsVector* XsDataPacket_calibratedMagneticField(const XsDataPacket* thisPtr, XsVector* returnVal)
835 {
836 return genericGet<XsVector, XsVector3Variant>(thisPtr, returnVal, XDI_MagneticField);
837 }
838
839 /*! \brief Check if data item contains calibrated magnetometer data
840 \returns true if this packet contains calibrated magnetometer data
841 */
842 int XsDataPacket_containsCalibratedMagneticField(const XsDataPacket* thisPtr)
843 {
844 return genericContains(thisPtr, XDI_MagneticField);
845 }
846
847 /*! \brief Add/update calibrated magnetometer data for the item
848 \param vec : The data to update the XsDataPacket with
849 */
850 void XsDataPacket_setCalibratedMagneticField(XsDataPacket* thisPtr, const XsVector* vec)
851 {
852 genericSet<XsVector, XsVector3Variant>(thisPtr, vec, XDI_MagneticField | XDI_SubFormatDouble);
853 }
854
855 /*! \brief Return the calibrated Data component of a data item.
856 \param returnVal Storage for the requested data
857 \returns Returns the supplied \a returnVal filled with the requested data
858 */
859 XsCalibratedData* XsDataPacket_calibratedData(const XsDataPacket* thisPtr, XsCalibratedData* returnVal)
860 {
861 assert(returnVal);
862
863 XsDataPacket_calibratedAcceleration(thisPtr, &returnVal->m_acc);
864 XsDataPacket_calibratedGyroscopeData(thisPtr, &returnVal->m_gyr);
865 XsDataPacket_calibratedMagneticField(thisPtr, &returnVal->m_mag);
866
867 return returnVal;
868 }
869
870 /*! \brief Check if data item contains calibrated Data
871 \returns Returns whether the packet contains calibrated data or not
872 \note Calibrated data is only present if *all* components are present.
873 */
874 int XsDataPacket_containsCalibratedData(const XsDataPacket* thisPtr)
875 {
876 // Note: calibrated data is only present if *all* components are present
877 return genericContains(thisPtr, XDI_Acceleration) &&
878 genericContains(thisPtr, XDI_RateOfTurn) &&
879 genericContains(thisPtr, XDI_MagneticField);
880 }
881
882 /*! \brief Add/update calibrated Data for the item
883 \param data : The data to update the XsDataPacket with
884 */
885 void XsDataPacket_setCalibratedData(XsDataPacket* thisPtr, const XsCalibratedData* data)
886 {
887 XsDataPacket_setCalibratedAcceleration(thisPtr, &data->m_acc);
888 XsDataPacket_setCalibratedGyroscopeData(thisPtr, &data->m_gyr);
889 XsDataPacket_setCalibratedMagneticField(thisPtr, &data->m_mag);
890 }
891
892 /*! \brief The corrected magnetometer component of a data item (ICC result).
893
894 \param returnVal : An XsVector to put the requested in
895
896 \returns A XsUShortVector containing the x, y and z axis values in that order
897 */
898 XsVector* XsDataPacket_correctedMagneticField(const XsDataPacket* thisPtr, XsVector* returnVal)
899 {
900 return genericGet<XsVector, XsVector3Variant>(thisPtr, returnVal, XDI_MagneticFieldCorrected);
901 }
902
903 /*! \brief Check if data item contains corrected magnetometer data (ICC result).
904 \returns true if this packet contains corrected magnetometer data
905 */
906 int XsDataPacket_containsCorrectedMagneticField(const XsDataPacket* thisPtr)
907 {
908 return genericContains(thisPtr, XDI_MagneticFieldCorrected);
909 }
910
911 /*! \brief Add/update corrected magnetometer data for the item (ICC result).
912 \param vec : The data to update the XsDataPacket with
913 */
914 void XsDataPacket_setCorrectedMagneticField(XsDataPacket* thisPtr, const XsVector* vec)
915 {
916 genericSet<XsVector, XsVector3Variant>(thisPtr, vec, XDI_MagneticFieldCorrected | XDI_SubFormatDouble);
917 }
918
919 /*! \brief Return the orientation component of a data item as a quaternion.
920
921 \param returnVal An %XsQuaternion to put the requested orientation in
922 \param coordinateSystem The coordinate system of the requested orientation. If this does not match
923 the stored coordinate system, it will be transformed to the requested orientation.
924
925 \returns An XsQuaternion containing the orientation data
926 */
927 XsQuaternion* XsDataPacket_orientationQuaternion(const XsDataPacket* thisPtr, XsQuaternion* returnVal, XsDataIdentifier coordinateSystem)
928 {
929 assert(returnVal);
930 auto it = MAP.find(XDI_Quaternion);
931 if (it != MAP.end())
932 {
933 *returnVal = it->second->toDerived<XsQuaternionVariant>().m_data;
934 XsDataIdentifier foundId = it->second->dataId();
935 if ((coordinateSystem & XDI_CoordSysMask) != (foundId & XDI_CoordSysMask))
936 {
937 XsQuaternion rot;
938 rot = preRotFromXdi(foundId, coordinateSystem);
939 XsQuaternion_multiply(&rot, returnVal, returnVal);
940 }
941 }
942 else if (XsDataPacket_containsOrientationMatrix(thisPtr))
943 {
944 XsMatrix3x3 m;
945 XsDataPacket_orientationMatrix(thisPtr, &m, coordinateSystem);
946 returnVal->fromRotationMatrix(m);
947 }
948 else if (XsDataPacket_containsOrientationEuler(thisPtr))
949 {
950 XsEuler eul;
951 XsDataPacket_orientationEuler(thisPtr, &eul, coordinateSystem);
952 returnVal->fromEulerAngles(eul);
953 }
954 //else
955 // memset(returnVal->m_data, 0, 4*sizeof(XsReal));
956
957 return returnVal;
958 }
959
960 /*! \brief Removes all orientations from the datapacket */
961 static void removeAllOrientations(XsDataPacket* thisPtr)
962 {
963 detach(thisPtr);
964 MAP.erase(XDI_Quaternion);
965 MAP.erase(XDI_RotationMatrix);
966 MAP.erase(XDI_EulerAngles);
967 }
968
969 /*! \brief Add/update quaternion orientation Data for the item
970 \param data The new data to set
971 \param coordinateSystem The coordinate system of the requested orientation.
972 */
973 void XsDataPacket_setOrientationQuaternion(XsDataPacket* thisPtr, const XsQuaternion* data, XsDataIdentifier coordinateSystem)
974 {
975 // always create a new one
976 removeAllOrientations(thisPtr);
977 MAP.insert(XDI_Quaternion, new XsQuaternionVariant(XDI_Quaternion | XDI_SubFormatDouble | (coordinateSystem & XDI_CoordSysMask), *data));
978 }
979
980 /*! \brief Return the orientation component of a data item as a euler angles.
981
982 \param returnVal An %XsEuler to put the requested orientation in
983 \param coordinateSystem The coordinate system of the requested orientation. If this does not match
984 the stored coordinate system, it will be transformed to the requested orientation.
985
986 \returns A %XsEuler containing the orientation data
987 */
988 XsEuler* XsDataPacket_orientationEuler(const XsDataPacket* thisPtr, XsEuler* returnVal, XsDataIdentifier coordinateSystem)
989 {
990 assert(returnVal);
991 auto it = MAP.find(XDI_EulerAngles);
992 if (it != MAP.end())
993 {
994 *returnVal = it->second->toDerived<XsEulerVariant>().m_data;
995 XsDataIdentifier foundId = it->second->dataId();
996 if ((coordinateSystem & XDI_CoordSysMask) != (foundId & XDI_CoordSysMask))
997 {
998 XsQuaternion rot, q;
999 rot = preRotFromXdi(foundId, coordinateSystem);
1000 XsQuaternion_fromEulerAngles(&q, returnVal);
1001 XsQuaternion_multiply(&rot, &q, &q);
1002 XsEuler_fromQuaternion(returnVal, &q);
1003 }
1004 }
1005 else if (XsDataPacket_containsOrientationMatrix(thisPtr))
1006 {
1007 XsMatrix3x3 m;
1008 XsDataPacket_orientationMatrix(thisPtr, &m, coordinateSystem);
1009 XsQuaternion q;
1010 q.fromRotationMatrix(m);
1011 returnVal->fromQuaternion(q);
1012 }
1013 else if (XsDataPacket_containsOrientationQuaternion(thisPtr))
1014 {
1015 XsQuaternion q;
1016 XsDataPacket_orientationQuaternion(thisPtr, &q, coordinateSystem);
1017 returnVal->fromQuaternion(q);
1018 }
1019 //else
1020 //{
1021 // returnVal->m_x = XsMath_zero;
1022 // returnVal->m_y = XsMath_zero;
1023 // returnVal->m_z = XsMath_zero;
1024 //}
1025
1026 return returnVal;
1027 }
1028
1029 /*! \brief Add/update quaternion orientation Data for the item
1030 \param data The new data to set
1031 \param coordinateSystem The coordinate system of the orientation.
1032 */
1033 void XsDataPacket_setOrientationEuler(XsDataPacket* thisPtr, const XsEuler* data, XsDataIdentifier coordinateSystem)
1034 {
1035 // always create a new one
1036 removeAllOrientations(thisPtr);
1037 MAP.insert(XDI_EulerAngles, new XsEulerVariant(XDI_EulerAngles | XDI_SubFormatDouble | (coordinateSystem & XDI_CoordSysMask), *data));
1038 }
1039
1040 /*! \brief Return the orientation component of a data item as a orientation matrix.
1041
1042 \param returnVal An %XsMatrix to put the requested orientation in
1043 \param coordinateSystem The coordinate system of the requested orientation. If this does not match
1044 the stored coordinate system, it will be transformed to the requested orientation.
1045
1046 \returns An %XsMatrix containing the orientation data
1047 */
1048 XsMatrix* XsDataPacket_orientationMatrix(const XsDataPacket* thisPtr, XsMatrix* returnVal, XsDataIdentifier coordinateSystem)
1049 {
1050 assert(returnVal);
1051 auto it = MAP.find(XDI_RotationMatrix);
1052 if (it != MAP.end())
1053 {
1054 *returnVal = it->second->toDerived<XsMatrixVariant>().m_data;
1055 XsDataIdentifier foundId = it->second->dataId();
1056 if ((coordinateSystem & XDI_CoordSysMask) != (foundId & XDI_CoordSysMask))
1057 {
1058 XsQuaternion rot, q;
1059 rot = preRotFromXdi(foundId, coordinateSystem);
1060 XsQuaternion_fromRotationMatrix(&q, returnVal);
1061 XsQuaternion_multiply(&rot, &q, &q);
1062 XsMatrix_fromQuaternion(returnVal, &q);
1063 }
1064 }
1065 else if (XsDataPacket_containsOrientationQuaternion(thisPtr))
1066 {
1067 XsQuaternion q;
1068 XsDataPacket_orientationQuaternion(thisPtr, &q, coordinateSystem);
1069 returnVal->fromQuaternion(q);
1070 }
1071 else if (XsDataPacket_containsOrientationEuler(thisPtr))
1072 {
1073 XsEuler eul;
1074 XsDataPacket_orientationEuler(thisPtr, &eul, coordinateSystem);
1075 XsQuaternion q;
1076 q.fromEulerAngles(eul);
1077 returnVal->fromQuaternion(q);
1078 }
1079 //else
1080 // memset(returnVal->m_data, 0, 4*sizeof(XsReal));
1081
1082 return returnVal;
1083 }
1084
1085 /*! \brief Add/update quaternion orientation Data for the item
1086 \param data The new data to set
1087 \param coordinateSystem The coordinate system of the orientation.
1088 */
1089 void XsDataPacket_setOrientationMatrix(XsDataPacket* thisPtr, const XsMatrix* data, XsDataIdentifier coordinateSystem)
1090 {
1091 // always create a new one
1092 removeAllOrientations(thisPtr);
1093 MAP.insert(XDI_RotationMatrix, new XsMatrixVariant(XDI_RotationMatrix | XDI_SubFormatDouble | (coordinateSystem & XDI_CoordSysMask), *data));
1094 }
1095
1096 /*! \brief Check if data item contains orientation Data of any kind
1097 \returns true if this packet contains orientation data
1098 */
1099 int XsDataPacket_containsOrientation(const XsDataPacket* thisPtr)
1100 {
1101 return genericContains(thisPtr, XDI_Quaternion) ||
1102 genericContains(thisPtr, XDI_EulerAngles) ||
1103 genericContains(thisPtr, XDI_RotationMatrix);
1104 }
1105
1106 /*! \brief Returns the data identifier of the first orientation data of any kind in the packet
1107 \returns The %XsDataIdentifier of the first orientation data of any kind in the packet
1108 */
1109 XsDataIdentifier XsDataPacket_orientationIdentifier(const XsDataPacket* thisPtr)
1110 {
1111 auto it = MAP.find(XDI_Quaternion);
1112 if (it != MAP.end())
1113 return it->second->dataId();
1114
1115 it = MAP.find(XDI_EulerAngles);
1116 if (it != MAP.end())
1117 return it->second->dataId();
1118
1119 it = MAP.find(XDI_RotationMatrix);
1120 if (it != MAP.end())
1121 return it->second->dataId();
1122
1123 return XDI_None;
1124 }
1125
1126 /*! \brief Returns the coordinate system of the first orientation data of any kind in the packet
1127 \returns The XsDataIdentifier of the coordinate system of the first orientation data of any kind in the packet
1128 */
1129 XsDataIdentifier XsDataPacket_coordinateSystemOrientation(const XsDataPacket* thisPtr)
1130 {
1131 return XsDataPacket_orientationIdentifier(thisPtr) & XDI_CoordSysMask;
1132 }
1133
1134 /*! \brief Check if data item contains pressure data
1135 \returns true if this packet contains pressure data
1136 */
1137 int XsDataPacket_containsPressure(const XsDataPacket* thisPtr)
1138 {
1139 return genericContains(thisPtr, XDI_BaroPressure);
1140 }
1141
1142 /*! \brief Check if data item contains pressure age data
1143 \returns true if this packet contains pressure age data
1144 */
1145 int XsDataPacket_containsPressureAge(const XsDataPacket* thisPtr)
1146 {
1147 return genericContains(thisPtr, XDI_PressureAge);
1148 }
1149
1150 /*! \brief The air pressure component of a data item.
1151
1152 \param returnVal : An XsPressure object to put the requested in
1153
1154 \returns An XsPressure object containing the pressure and if available the pressure age
1155 */
1156 XsPressure* XsDataPacket_pressure(const XsDataPacket* thisPtr, XsPressure* returnVal)
1157 {
1158 assert(returnVal);
1159 auto it = MAP.find(XDI_BaroPressure);
1160 if (it != MAP.end())
1161 {
1162 returnVal->m_pressure = it->second->toDerived<SimpleVariant<uint32_t>>().m_data;
1163 returnVal->m_pressureAge = 0;
1164 }
1165
1166 it = MAP.find(XDI_PressureAge);
1167 if (it != MAP.end())
1168 returnVal->m_pressureAge = it->second->toDerived<SimpleVariant<uint8_t>>().m_data;
1169
1170 return returnVal;
1171 }
1172
1173 /*! \brief Add/update pressure data for the item
1174 \param data The new data to set
1175 */
1176 void XsDataPacket_setPressure(XsDataPacket* thisPtr, const XsPressure* data)
1177 {
1178 GenericSimple<uint32_t>::set(thisPtr, (uint32_t) XsMath::doubleToLong(data->m_pressure), XDI_BaroPressure);
1179 GenericSimple<uint8_t>::set(thisPtr, data->m_pressureAge, XDI_PressureAge);
1180 }
1181
1182 /*! \brief Return the strapdown integration data component of a data item.
1183 \param returnVal Storage for the requested data
1184 \returns Returns the supplied \a returnVal filled with the requested data
1185 */
1186 XsSdiData* XsDataPacket_sdiData(const XsDataPacket* thisPtr, XsSdiData* returnVal)
1187 {
1188 assert(returnVal);
1189 auto it = MAP.find(XDI_DeltaQ);
1190 if (it != MAP.end())
1191 returnVal->setOrientationIncrement(it->second->toDerived<XsQuaternionVariant>().m_data);
1192
1193 it = MAP.find(XDI_DeltaV);
1194 if (it != MAP.end())
1195 returnVal->setVelocityIncrement(it->second->toDerived<XsVector3Variant>().m_data);
1196
1197 return returnVal;
1198 }
1199
1200 /*! \brief Check if data item contains strapdown integration data
1201 \returns Returns true if this packet contains sdi data
1202 */
1203 int XsDataPacket_containsSdiData(const XsDataPacket* thisPtr)
1204 {
1205 return genericContains(thisPtr, XDI_DeltaQ) &&
1206 genericContains(thisPtr, XDI_DeltaV);
1207 }
1208
1209 /*! \brief Add/update strapdown integration data for the item
1210 \param data The updated data
1211 */
1212 void XsDataPacket_setSdiData(XsDataPacket* thisPtr, const XsSdiData* data)
1213 {
1214 genericSet<XsQuaternion, XsQuaternionVariant>(thisPtr, &data->orientationIncrement(), XDI_DeltaQ | XDI_SubFormatDouble);
1215 genericSet<XsVector3, XsVector3Variant>(thisPtr, &data->velocityIncrement(), XDI_DeltaV | XDI_SubFormatDouble);
1216 }
1217
1218 /*! \brief Return the glove data component of a data item.
1219 \param returnVal Storage for the requested data
1220 \returns Returns the supplied \a returnVal filled with the requested data
1221 */
1222 XsGloveData* XsDataPacket_gloveData(const XsDataPacket* thisPtr, XsGloveData* returnVal)
1223 {
1224 return genericGet<XsGloveData, XsGloveDataVariant>(thisPtr, returnVal, XDI_GloveData);
1225 }
1226
1227 /*! \brief Check if data item contains glove data
1228 \returns Returns true if this packet contains sdi data
1229 */
1230 int XsDataPacket_containsGloveData(const XsDataPacket* thisPtr)
1231 {
1232 return genericContains(thisPtr, XDI_GloveData);
1233 }
1234
1235 /*! \brief Add/update strapdown integration data for the item
1236 \param data The updated data
1237 */
1238 void XsDataPacket_setGloveData(XsDataPacket* thisPtr, const XsGloveData* data)
1239 {
1240 genericSet<XsGloveData, XsGloveDataVariant>(thisPtr, data, XDI_GloveData);
1241 }
1242
1243 /*! \brief The device id of a data item.
1244
1245 \param returnVal an XsDeviceId object to put the requested data in
1246
1247 \returns An XsDeviceId object containing the requested device ID
1248 */
1249 XsDeviceId* XsDataPacket_storedDeviceId(const XsDataPacket* thisPtr, XsDeviceId* returnVal)
1250 {
1251 return genericGet<XsDeviceId, SimpleVariant<uint32_t>>(thisPtr, returnVal, XDI_DeviceId);
1252 }
1253
1254 /*! \brief Return non-zero if this data packet stores a device ID
1255 \returns non-zero (true) if a device ID is available, zero (false) otherwise
1256 */
1257 int XsDataPacket_containsStoredDeviceId(const XsDataPacket* thisPtr)
1258 {
1259 return genericContains(thisPtr, XDI_DeviceId);
1260 }
1261
1262 /*! \brief Add or update device id for the item
1263 \param data the device ID to store in the packet
1264 */
1265 void XsDataPacket_setStoredDeviceId(XsDataPacket* thisPtr, const XsDeviceId* data)
1266 {
1267 GenericSimple<uint32_t>::set(thisPtr, data->legacyDeviceId(), XDI_DeviceId);
1268 }
1269
1270 /*! \brief The location ID of a data item.
1271
1272 \returns The requested location ID
1273 */
1274 uint16_t XsDataPacket_storedLocationId(const XsDataPacket* thisPtr)
1275 {
1276 return GenericSimple<uint16_t>::get(thisPtr, XDI_LocationId);
1277 }
1278
1279 /*! \brief Return non-zero if this data packet stores a location ID
1280 \returns non-zero (true) if a location ID is available, zero (false) otherwise
1281 */
1282 int XsDataPacket_containsStoredLocationId(const XsDataPacket* thisPtr)
1283 {
1284 return genericContains(thisPtr, XDI_LocationId);
1285 }
1286
1287 /*! \brief Add or update location ID for the item
1288 \param data the location ID to store in the packet
1289 */
1290 void XsDataPacket_setStoredLocationId(XsDataPacket* thisPtr, uint16_t data)
1291 {
1292 GenericSimple<uint16_t>::set(thisPtr, data, XDI_LocationId);
1293 }
1294
1295 /*! \brief The temperature component of a data item.
1296 \returns A double containing the temperature value, -1000.0 if the packet does not contain temperature
1297 */
1298 double XsDataPacket_temperature(const XsDataPacket* thisPtr)
1299 {
1300 return GenericSimple<double>::get(thisPtr, XDI_Temperature);
1301 }
1302
1303 /*! \brief Check if data item contains temperature data
1304 \returns true if this packet contains temperature data
1305 */
1306 int XsDataPacket_containsTemperature(const XsDataPacket* thisPtr)
1307 {
1308 return genericContains(thisPtr, XDI_Temperature);
1309 }
1310
1311 /*! \brief Adds or updates the temperature data in the datapacket
1312 \details The \a temp is added to the datapacket. If the packet already contains
1313 temperature it is replaced with the new value.
1314 \param temperature : The temperature to set
1315 */
1316 void XsDataPacket_setTemperature(XsDataPacket* thisPtr, double temperature)
1317 {
1318 GenericSimple<double>::set(thisPtr, temperature, XDI_Temperature | XDI_SubFormatDouble);
1319 }
1320
1321 /*! \brief The analog in 1 component of a data item.
1322 \param returnVal : The XsAnalogInData object that the analog in 1 value will be assigned to
1323 \returns An XsAnalogInData containing the analog in 1 value
1324 */
1325 XsAnalogInData* XsDataPacket_analogIn1Data(const XsDataPacket* thisPtr, XsAnalogInData* returnVal)
1326 {
1327 return genericGet<XsAnalogInData, SimpleVariant<uint16_t>>(thisPtr, returnVal, XDI_AnalogIn1);
1328 }
1329
1330 /*! \brief Check if data item contains analog in 1 data
1331 \returns true if this packet contains analog in 1 data
1332 */
1333 int XsDataPacket_containsAnalogIn1Data(const XsDataPacket* thisPtr)
1334 {
1335 return genericContains(thisPtr, XDI_AnalogIn1);
1336 }
1337
1338 /*! \brief Add/update analog in 1 data for the item
1339 \param data The \a data is added to the datapacket. If the packet already contains
1340 analogin1 data, it is replaced with the new value
1341 */
1342 void XsDataPacket_setAnalogIn1Data(XsDataPacket* thisPtr, const XsAnalogInData* data)
1343 {
1344 GenericSimple<uint16_t>::set(thisPtr, data->m_data, XDI_AnalogIn1);
1345 }
1346
1347 /*! \brief The analog in 2 component of a data item.
1348 \param returnVal : The XsAnalogInData object that the analog in 2 value will be assigned to
1349 \returns An XsAnalogInData containing the analog in 2 value
1350 */
1351 XsAnalogInData* XsDataPacket_analogIn2Data(const XsDataPacket* thisPtr, XsAnalogInData* returnVal)
1352 {
1353 return genericGet<XsAnalogInData, SimpleVariant<uint16_t>>(thisPtr, returnVal, XDI_AnalogIn2);
1354 }
1355
1356 /*! \brief Check if data item contains analog in 2 data
1357 \returns true if this packet contains analog in 2 data
1358 */
1359 int XsDataPacket_containsAnalogIn2Data(const XsDataPacket* thisPtr)
1360 {
1361 return genericContains(thisPtr, XDI_AnalogIn2);
1362 }
1363
1364 /*! \brief Add/update analog in 2 data for the item
1365 \param data The \a data is added to the datapacket. If the packet already contains
1366 analogin1 data, it is replaced with the new value
1367 */
1368 void XsDataPacket_setAnalogIn2Data(XsDataPacket* thisPtr, const XsAnalogInData* data)
1369 {
1370 GenericSimple<uint16_t>::set(thisPtr, data->m_data, XDI_AnalogIn2);
1371 }
1372
1373 /*! \brief The position lat lon alt component of a data item.
1374
1375 \param returnVal : The XsVector to return the requested data in
1376
1377 \returns An XsVector containing the latitude, longitude and altitude values in that order
1378 */
1379 XsVector* XsDataPacket_positionLLA(const XsDataPacket* thisPtr, XsVector* returnVal)
1380 {
1381 assert(returnVal);
1382 returnVal->setSize(3);
1383
1384 XsVector latlon(2);
1385 genericGet<XsVector, XsVector2Variant>(thisPtr, &latlon, XDI_LatLon);
1386 if (!latlon.empty())
1387 {
1388 (*returnVal)[0] = latlon[0];
1389 (*returnVal)[1] = latlon[1];
1390 }
1391 else
1392 {
1393 (*returnVal)[0] = 0;
1394 (*returnVal)[1] = 0;
1395 }
1396 // This triggers a warning when XsReal is float, which is deliberately not silenced
1397 (*returnVal)[2] = GenericSimple<double>::get(thisPtr, XDI_AltitudeEllipsoid);
1398
1399 return returnVal;
1400 }
1401
1402 /*! \brief Check if data item contains position lat lon alt data
1403 \returns true if this packet contains position lat lon alt data
1404 */
1405 int XsDataPacket_containsPositionLLA(const XsDataPacket* thisPtr)
1406 {
1407 return genericContains(thisPtr, XDI_LatLon) &&
1408 genericContains(thisPtr, XDI_AltitudeEllipsoid);
1409 }
1410
1411 /*! \brief Add/update position lat lon alt data for the item
1412
1413 \param data : The XsVector that conrtains the Lat/Long/Alt data to store in the packet
1414 */
1415 void XsDataPacket_setPositionLLA(XsDataPacket* thisPtr, const XsVector* data)
1416 {
1417 XsVector latlon(2);
1418 latlon[0] = (*data)[0];
1419 latlon[1] = (*data)[1];
1420
1421 genericSet<XsVector, XsVector2Variant>(thisPtr, &latlon, XDI_LatLon | XDI_SubFormatDouble);
1422 GenericSimple<double>::set(thisPtr, (*data)[2], XDI_AltitudeEllipsoid | XDI_SubFormatDouble);
1423 }
1424
1425 /*! \brief The position latitude longitude component of a data item.
1426
1427 \param returnVal : The XsVector to return the requested data in
1428
1429 \returns An XsVector containing the latitude and longitude values in that order
1430 \sa XsDataPacket_containsLatitudeLongitude
1431 \sa XsDataPacket_positionLLA \sa XsDataPacket_altitude
1432 */
1433 XsVector* XsDataPacket_latitudeLongitude(const XsDataPacket* thisPtr, XsVector* returnVal)
1434 {
1435 return genericGet<XsVector, XsVector2Variant>(thisPtr, returnVal, XDI_LatLon);
1436 }
1437
1438 /*! \brief Check if data item contains position latitude longitude data
1439 \returns true if this packet contains position latitude longitude data
1440 \sa XsDataPacket_containsPositionLLA \sa XsDataPacket_containsAltitude
1441 */
1442 int XsDataPacket_containsLatitudeLongitude(const XsDataPacket* thisPtr)
1443 {
1444 return genericContains(thisPtr, XDI_LatLon);
1445 }
1446
1447 /*! \brief Add/update position latitude longitude data for the item
1448
1449 \param data : The XsVector that contains the latitude longitude data to store in the packet
1450 \sa XsDataPacket_setPositionLLA \sa XsDataPacket_setAltitude
1451 */
1452 void XsDataPacket_setLatitudeLongitude(XsDataPacket* thisPtr, const XsVector* data)
1453 {
1454 genericSet<XsVector, XsVector2Variant>(thisPtr, data, XDI_LatLon | XDI_SubFormatDouble);
1455 }
1456
1457 /*! \brief The position altitude component of a data item.
1458
1459 \returns The altitude stored in the packet or XsMath_infinity if no altitude is available
1460 \sa XsDataPacket_containsAltitude
1461 \sa XsDataPacket_positionLLA \sa XsDataPacket_latitudeLongitude
1462 */
1463 double XsDataPacket_altitude(const XsDataPacket* thisPtr)
1464 {
1465 return GenericSimple<double>::get(thisPtr, XDI_AltitudeEllipsoid);
1466 }
1467
1468 /*! \brief Check if data item contains position altitude data
1469 \returns true if this packet contains position altitude data
1470 \sa XsDataPacket_containsPositionLLA \sa XsDataPacket_containsLatitudeLongitude
1471 */
1472 int XsDataPacket_containsAltitude(const XsDataPacket* thisPtr)
1473 {
1474 return genericContains(thisPtr, XDI_AltitudeEllipsoid);
1475 }
1476
1477 /*! \brief Add/update altitude data for the item
1478 \param data : The altitude data to store in the packet
1479 \sa XsDataPacket_setPositionLLA \sa XsDataPacket_setLatitudeLongitude
1480 */
1481 void XsDataPacket_setAltitude(XsDataPacket* thisPtr, double data)
1482 {
1483 GenericSimple<double>::set(thisPtr, data, XDI_AltitudeEllipsoid | XDI_SubFormatDouble);
1484 }
1485
1486 /*! \brief The position altitude above MSL component of a data item.
1487
1488 \returns The altitude stored in the packet or XsMath_infinity if no altitude is available
1489 \sa XsDataPacket_containsAltitudeMsl
1490 */
1491 double XsDataPacket_altitudeMsl(const XsDataPacket* thisPtr)
1492 {
1493 return GenericSimple<double>::get(thisPtr, XDI_AltitudeMsl);
1494 }
1495
1496 /*! \brief Check if data item contains position altitude above MSL data
1497
1498 \returns true if this packet contains position altitude data
1499 */
1500 int XsDataPacket_containsAltitudeMsl(const XsDataPacket* thisPtr)
1501 {
1502 return genericContains(thisPtr, XDI_AltitudeMsl);
1503 }
1504
1505 /*! \brief Add/update altitude above MSL data for the item
1506
1507 \param data : The altitude data to store in the packet
1508 */
1509 void XsDataPacket_setAltitudeMsl(XsDataPacket* thisPtr, double data)
1510 {
1511 GenericSimple<double>::set(thisPtr, data, XDI_AltitudeMsl | XDI_SubFormatDouble);
1512 }
1513
1514 /*! \brief The velocity NWU component of a data item.
1515
1516 \param returnVal : The XsVector to put the data in
1517 \param coordinateSystem The coordinate system of the requested velocity. If this does not match
1518 the stored coordinate system, it will be transformed to the requested velocity.
1519 \returns A XsVector containing the x, y and z axis values in that order
1520 */
1521 XsVector* XsDataPacket_velocity(const XsDataPacket* thisPtr, XsVector* returnVal, XsDataIdentifier coordinateSystem)
1522 {
1523 assert(returnVal);
1524 auto it = MAP.find(XDI_VelocityXYZ);
1525 if (it != MAP.end())
1526 {
1527 *returnVal = it->second->toDerived<XsVector3Variant>().m_data;
1528 XsDataIdentifier actualCsys = (it->second->dataId() & XDI_CoordSysMask);
1529 XsDataIdentifier desiredCsys = (coordinateSystem & XDI_CoordSysMask);
1530 if (actualCsys != desiredCsys)
1531 {
1532 XsVector3 vel(*returnVal);
1533 XsVector& rv = *returnVal;
1534
1535 switch (desiredCsys)
1536 {
1537 case XDI_CoordSysEnu:
1538 {
1539 if (actualCsys == XDI_CoordSysNwu)
1540 {
1541 rv[0] = -vel[1];
1542 rv[1] = vel[0];
1543 rv[2] = vel[2];
1544 }
1545 else if (actualCsys == XDI_CoordSysNed)
1546 {
1547 rv[0] = vel[1];
1548 rv[1] = vel[0];
1549 rv[2] = -vel[2];
1550 }
1551 } break;
1552
1553 case XDI_CoordSysNwu:
1554 {
1555 if (actualCsys == XDI_CoordSysEnu)
1556 {
1557 rv[0] = vel[1];
1558 rv[1] = -vel[0];
1559 rv[2] = vel[2];
1560 }
1561 else if (actualCsys == XDI_CoordSysNed)
1562 {
1563 rv[0] = vel[0];
1564 rv[1] = -vel[1];
1565 rv[2] = -vel[2];
1566 }
1567 } break;
1568
1569 case XDI_CoordSysNed:
1570 {
1571 if (actualCsys == XDI_CoordSysEnu)
1572 {
1573 rv[0] = vel[1];
1574 rv[1] = vel[0];
1575 rv[2] = -vel[2];
1576 }
1577 else if (actualCsys == XDI_CoordSysNwu)
1578 {
1579 rv[0] = vel[0];
1580 rv[1] = -vel[1];
1581 rv[2] = -vel[2];
1582 }
1583 } break;
1584
1585 default:
1586 {
1587 rv[0] = vel[0];
1588 rv[1] = vel[1];
1589 rv[2] = vel[2];
1590 } break;
1591 }
1592 }
1593 }
1594
1595 return returnVal;
1596 }
1597
1598 /*! \brief Check if data item contains velocity NED data
1599 \returns true if this packet contains velocity NED data
1600 */
1601 int XsDataPacket_containsVelocity(const XsDataPacket* thisPtr)
1602 {
1603 return genericContains(thisPtr, XDI_VelocityXYZ);
1604 }
1605
1606 /*! \brief Add/update velocity NED data for the item
1607 \param data The new data to set
1608 \param coordinateSystem The coordinate system of the requested orientation.
1609 */
1610 void XsDataPacket_setVelocity(XsDataPacket* thisPtr, const XsVector* data, XsDataIdentifier coordinateSystem)
1611 {
1612 detach(thisPtr);
1613 auto it = MAP.find(XDI_VelocityXYZ);
1614 if (it != MAP.end())
1615 MAP.erase(it);
1616
1617 genericSet<XsVector, XsVector3Variant>(thisPtr, data, XDI_VelocityXYZ | XDI_SubFormatDouble | (coordinateSystem & XDI_CoordSysMask));
1618 }
1619
1620 /*! \brief Returns the data identifier of the first velocity data of any kind in the packet
1621 \returns The %XsDataIdentifier of the first velocity data of any kind in the packet
1622 */
1623 XsDataIdentifier XsDataPacket_velocityIdentifier(const XsDataPacket* thisPtr)
1624 {
1625 auto it = MAP.find(XDI_VelocityXYZ);
1626 if (it != MAP.end())
1627 return it->second->dataId();
1628 return XDI_None;
1629 }
1630
1631 /*! \brief Returns the coordinate system of the first velocity data of any kind in the packet
1632 \returns The XsDataIdentifier of the coordinate system of the first velocity data of any kind in the packet
1633 */
1634 XsDataIdentifier XsDataPacket_coordinateSystemVelocity(const XsDataPacket* thisPtr)
1635 {
1636 return XsDataPacket_velocityIdentifier(thisPtr) & XDI_CoordSysMask;
1637 }
1638
1639 /*! \brief The status component of a data item.
1640
1641 \returns An uint32_t containing the status value
1642 */
1643 uint32_t XsDataPacket_status(const XsDataPacket* thisPtr)
1644 {
1645 auto it = MAP.find(XDI_StatusWord);
1646 if (it != MAP.end())
1647 return it->second->toDerived<SimpleVariant<uint32_t>>().m_data;
1648
1649 it = MAP.find(XDI_StatusByte);
1650 if (it != MAP.end())
1651 return it->second->toDerived<SimpleVariant<uint8_t>>().m_data;
1652
1653 return 0;
1654 }
1655
1656 /*! \brief Check if data item contains detailed status data
1657 \returns true if this packet contains detailed status data
1658 */
1659 int XsDataPacket_containsDetailedStatus(const XsDataPacket* thisPtr)
1660 {
1661 return genericContains(thisPtr, XDI_StatusWord);
1662 }
1663
1664 /*! \brief Check if data item contains legacy status data
1665 \returns true if this packet contains legacy status data
1666 */
1667 int XsDataPacket_containsStatus(const XsDataPacket* thisPtr)
1668 {
1669 return genericContains(thisPtr, XDI_StatusWord) ||
1670 genericContains(thisPtr, XDI_StatusByte);
1671 }
1672
1673 /*! \brief Add/update status data for the item
1674 \param data The new data to set
1675 */
1676 void XsDataPacket_setStatusByte(XsDataPacket* thisPtr, uint8_t data)
1677 {
1678 detach(thisPtr);
1679 if (genericContains(thisPtr, XDI_StatusWord))
1680 {
1681 uint32_t word = GenericSimple<uint32_t>::get(thisPtr, XDI_StatusWord);
1682 word = ((word & (~0xFF)) | data);
1683 XsDataPacket_setStatus(thisPtr, word);
1684 }
1685 else
1686 GenericSimple<uint8_t>::set(thisPtr, data, XDI_StatusByte);
1687 }
1688
1689 /*! \brief Add/update status data for the item
1690 \param data The new data to set
1691 */
1692 void XsDataPacket_setStatus(XsDataPacket* thisPtr, uint32_t data)
1693 {
1694 detach(thisPtr);
1695 auto it = MAP.find(XDI_StatusByte);
1696 if (it != MAP.end())
1697 MAP.erase(it);
1698
1699 GenericSimple<uint32_t>::set(thisPtr, data, XDI_StatusWord);
1700 }
1701
1702 /*! \brief Returns the trigger indication data of a packet
1703 If the packet does not contain the requested data, the return val struct will be set to all zeroes
1704 \param[in] triggerId The trigger data identifier to add data for (e.g. XDI_TriggerIn1 or XDI_TriggerIn2)
1705 \param[out] returnVal pointer to the trigger indication data of a packet.
1706 \note returnVal should point to a buffer large enough to hold sizeof(XsTriggerIndicationData) bytes of data
1707 \returns Returns a pointer to the trigger indication data of a packet
1708 */
1709 XsTriggerIndicationData* XsDataPacket_triggerIndication(const XsDataPacket* thisPtr, XsDataIdentifier triggerId, XsTriggerIndicationData* returnVal)
1710 {
1711 return genericGet<XsTriggerIndicationData, XsTriggerIndicationDataVariant>(thisPtr, returnVal, triggerId);
1712 }
1713
1714 /*! \brief Check if data item contains trigger indication data
1715 \param[in] triggerId The trigger data identifier to check (e.g. XDI_TriggerIn1 or XDI_TriggerIn2)
1716 \returns true if this packet contains trigger indication data
1717 */
1718 int XsDataPacket_containsTriggerIndication(const XsDataPacket* thisPtr, XsDataIdentifier triggerId)
1719 {
1720 return genericContains(thisPtr, triggerId);
1721 }
1722
1723 /*! \brief Add/update trigger indication data for the item
1724 \param[in] triggerId The trigger data identifier to add data for (e.g. XDI_TriggerIn1 or XDI_TriggerIn2)
1725 \param[in] triggerIndicationData pointer the a XsTriggerIndicationData buffer containing the data to set
1726 */
1727 void XsDataPacket_setTriggerIndication(XsDataPacket* thisPtr, XsDataIdentifier triggerId, const XsTriggerIndicationData *triggerIndicationData)
1728 {
1729 genericSet<XsTriggerIndicationData, XsTriggerIndicationDataVariant>(thisPtr, triggerIndicationData, triggerId);
1730 }
1731
1732 /*! \brief Return the 8 bit packet counter of a packet
1733
1734 \details This function returns an 8 bit packet counter as used by some third party devices
1735
1736 \returns Returns the 8 bit packet counter of a packet
1737 */
1738 uint8_t XsDataPacket_packetCounter8(const XsDataPacket* thisPtr)
1739 {
1740 return GenericSimple<uint8_t>::get(thisPtr, XDI_PacketCounter8);
1741 }
1742
1743 /*! \brief Check if data item contains an 8 bit packet counter
1744 \returns true if this packet contains an 8 bit packet counter
1745 */
1746 int XsDataPacket_containsPacketCounter8(const XsDataPacket* thisPtr)
1747 {
1748 return genericContains(thisPtr, XDI_PacketCounter8);
1749 }
1750
1751 /*! \brief Add/update 8 bit packet counter data for the item
1752 \param counter The new data to set
1753 */
1754 void XsDataPacket_setPacketCounter8(XsDataPacket* thisPtr, uint8_t counter)
1755 {
1756 GenericSimple<uint8_t>::set(thisPtr, counter, XDI_PacketCounter8);
1757 }
1758
1759 /*! \brief Return the packet/frame counter of a packet
1760
1761 \details For strapdown integration data, this function will return the m_wlastFrameNumber
1762 For other data, this function will return the m_sc
1763
1764 This way there is a function that will always return the counter of a packet
1765
1766 \returns Returns the packet/frame counter of a packet
1767 */
1768 uint16_t XsDataPacket_packetCounter(const XsDataPacket* thisPtr)
1769 {
1770 auto it = MAP.find(XDI_PacketCounter);
1771 if (it != MAP.end())
1772 return it->second->toDerived<SimpleVariant<uint16_t>>().m_data;
1773
1774 it = MAP.find(XDI_FrameRange);
1775 if (it != MAP.end())
1776 return static_cast<uint16_t>(static_cast<unsigned int>(it->second->toDerived<XsRangeVariant>().m_data.last()));
1777
1778 return 0;
1779 }
1780
1781 /*! \brief Check if data item contains a packet counter
1782 \returns true if this packet contains a packet counter
1783 */
1784 int XsDataPacket_containsPacketCounter(const XsDataPacket* thisPtr)
1785 {
1786 return genericContains(thisPtr, XDI_PacketCounter) ||
1787 genericContains(thisPtr, XDI_FrameRange);
1788 }
1789
1790 /*! \brief Add/update packet counter data for the item
1791 \param counter The new data to set
1792 */
1793 void XsDataPacket_setPacketCounter(XsDataPacket* thisPtr, uint16_t counter)
1794 {
1795 GenericSimple<uint16_t>::set(thisPtr, counter, XDI_PacketCounter);
1796 MAP.erase(XDI_FrameRange);
1797 }
1798
1799 /*! \brief Return the fine sample time of a packet
1800
1801 \returns Returns the fine sample time of a packet
1802 */
1803 uint32_t XsDataPacket_sampleTimeFine(const XsDataPacket* thisPtr)
1804 {
1805 return GenericSimple<uint32_t>::get(thisPtr, XDI_SampleTimeFine);
1806 }
1807
1808 /*! \brief Check if data item XsDataPacket_contains a sample time fine
1809 \returns true if this packet XsDataPacket_contains a sample time fine
1810 */
1811 int XsDataPacket_containsSampleTimeFine(const XsDataPacket* thisPtr)
1812 {
1813 return genericContains(thisPtr, XDI_SampleTimeFine);
1814 }
1815
1816 /*! \brief Add/update sample tine fine data for the item
1817 \param counter The new data to set
1818 */
1819 void XsDataPacket_setSampleTimeFine(XsDataPacket* thisPtr, uint32_t counter)
1820 {
1821 GenericSimple<uint32_t>::set(thisPtr, counter, XDI_SampleTimeFine);
1822 auto it = MAP.find(XDI_SampleTime64);
1823 if (it != MAP.end())
1824 {
1825 auto& var = it->second->toDerived<SimpleVariant<uint64_t>>();
1826 var.m_data = coarseFactor*(var.m_data/coarseFactor) + (counter%coarseFactor);
1827 }
1828 }
1829
1830 /*! \brief Return the coarse sample time of a packet
1831 */
1832 uint32_t XsDataPacket_sampleTimeCoarse(const XsDataPacket* thisPtr)
1833 {
1834 return GenericSimple<uint32_t>::get(thisPtr, XDI_SampleTimeCoarse);
1835 }
1836
1837 /*! \brief Check if data item XsDataPacket_contains a sample time coarse
1838 \returns true if this packet XsDataPacket_contains a sample time coarse
1839 */
1840 int XsDataPacket_containsSampleTimeCoarse(const XsDataPacket* thisPtr)
1841 {
1842 return genericContains(thisPtr, XDI_SampleTimeCoarse);
1843 }
1844
1845 /*! \brief Add/update sample tine coarse data for the item
1846 \param counter The new data to set
1847 */
1848 void XsDataPacket_setSampleTimeCoarse(XsDataPacket* thisPtr, uint32_t counter)
1849 {
1850 GenericSimple<uint32_t>::set(thisPtr, counter, XDI_SampleTimeCoarse);
1851 auto it = MAP.find(XDI_SampleTime64);
1852 if (it != MAP.end())
1853 {
1854 auto& var = it->second->toDerived<SimpleVariant<uint64_t>>();
1855 var.m_data = (coarseFactor * counter) + (var.m_data % coarseFactor);
1856 }
1857 }
1858
1859 /*! \brief Return the full 64-bit sample time of a packet, combined from the fine and coarse sample times or received directly from the device. The 64-bit sample time runs at 10kHz.
1860 */
1861 uint64_t XsDataPacket_sampleTime64(const XsDataPacket* thisPtr)
1862 {
1863 auto it = MAP.find(XDI_SampleTime64);
1864 if (it != MAP.end())
1865 return it->second->toDerived<SimpleVariant<uint64_t>>().m_data;
1866
1867 uint64_t rv = 0;
1868
1869 bool hasSampletimeCoarse = false;
1870 it = MAP.find(XDI_SampleTimeCoarse);
1871 if (it != MAP.end())
1872 {
1873 hasSampletimeCoarse = true;
1874 rv += ((uint64_t) it->second->toDerived<SimpleVariant<uint32_t>>().m_data) * coarseFactor;
1875 }
1876
1877 it = MAP.find(XDI_SampleTimeFine);
1878 if (it != MAP.end())
1879 {
1880 uint32_t sampletimeFine = it->second->toDerived<SimpleVariant<uint32_t>>().m_data;
1881 if (hasSampletimeCoarse)
1882 sampletimeFine = sampletimeFine % coarseFactor;
1883 rv += sampletimeFine;
1884 }
1885
1886 return rv;
1887 }
1888
1889 /*! \brief Check if data item XsDataPacket contains a full 64-bit sample time
1890 \returns true if this packet XsDataPacket contains both a fine and coarse sample time
1891 */
1892 int XsDataPacket_containsSampleTime64(const XsDataPacket* thisPtr)
1893 {
1894 return genericContains(thisPtr, XDI_SampleTime64) ||
1895 (genericContains(thisPtr, XDI_SampleTimeCoarse) && genericContains(thisPtr, XDI_SampleTimeFine));
1896 }
1897
1898 /*! \brief Add/update sample tine coarse data for the item
1899 \param counter The new data to set
1900 */
1901 void XsDataPacket_setSampleTime64(XsDataPacket* thisPtr, uint64_t counter)
1902 {
1903 GenericSimple<uint64_t>::set(thisPtr, counter, XDI_SampleTime64);
1904 GenericSimple<uint32_t>::set(thisPtr, (uint32_t) (counter / coarseFactor), XDI_SampleTimeCoarse);
1905 GenericSimple<uint32_t>::set(thisPtr, (uint32_t) (counter % coarseFactor), XDI_SampleTimeFine);
1906 }
1907
1908 /*! \brief The utc time component of a data item.
1909 \param returnVal : The XsTimeInfo to return the requested data in
1910 \returns An XsTimeInfo containing the utc time value
1911 */
1912 XsTimeInfo* XsDataPacket_utcTime(const XsDataPacket* thisPtr, XsTimeInfo* returnVal)
1913 {
1914 return genericGet<XsTimeInfo, XsTimeInfoVariant>(thisPtr, returnVal, XDI_UtcTime);
1915 }
1916
1917 /*! \brief Check if data item contains utc time data
1918 \returns true if this packet contains utc time data
1919 */
1920 int XsDataPacket_containsUtcTime(const XsDataPacket* thisPtr)
1921 {
1922 return genericContains(thisPtr, XDI_UtcTime);
1923 }
1924
1925 /*! \brief Add/update utc time data for the item
1926 \param data The new data to set
1927 */
1928 void XsDataPacket_setUtcTime(XsDataPacket* thisPtr, const XsTimeInfo* data)
1929 {
1930 genericSet<XsTimeInfo, XsTimeInfoVariant>(thisPtr, data, XDI_UtcTime);
1931 }
1932
1933 /*! \brief The free acceleration component of a data item.
1934 \details Free acceleration is the acceleration with the local gravity vector subtracted.
1935 \param returnVal : An XsVector to put the requested in
1936
1937 \returns An XsVector containing the gravity acceleration
1938 */
1939 XsVector* XsDataPacket_freeAcceleration(const XsDataPacket* thisPtr, XsVector* returnVal)
1940 {
1941 return genericGet<XsVector, XsVector3Variant>(thisPtr, returnVal, XDI_FreeAcceleration);
1942 }
1943
1944 /*! \brief Check if data item contains free acceleration
1945 \details Free acceleration is the acceleration with the local gravity vector subtracted.
1946 \returns true if this packet contains free acceleration
1947 */
1948 int XsDataPacket_containsFreeAcceleration(const XsDataPacket* thisPtr)
1949 {
1950 return genericContains(thisPtr, XDI_FreeAcceleration);
1951 }
1952
1953 /*! \brief Add/update free acceleration data for the item
1954 \details Free acceleration is the acceleration with the local gravity vector subtracted.
1955 \param g A 3-component vector containing the new free acceleration
1956 */
1957 void XsDataPacket_setFreeAcceleration(XsDataPacket* thisPtr, const XsVector* g)
1958 {
1959 genericSet<XsVector, XsVector3Variant>(thisPtr, g, XDI_FreeAcceleration);
1960 }
1961
1962 /*! \brief Returns the frame range contained in the datapacket
1963
1964 \param returnVal : The XsRange object that will get the range from the packet
1965
1966 \returns Returns an XsRange object with the range from the packet
1967 */
1968 XsRange* XsDataPacket_frameRange(const XsDataPacket* thisPtr, XsRange* returnVal)
1969 {
1970 return genericGet<XsRange, XsRangeVariant>(thisPtr, returnVal, XDI_FrameRange);
1971 }
1972
1973 /*! \brief Returns whether the datapacket contains a framerange
1974
1975 \returns Whether the datapacket contains a framerange
1976 */
1977 int XsDataPacket_containsFrameRange(const XsDataPacket* thisPtr)
1978 {
1979 return genericContains(thisPtr, XDI_FrameRange);
1980 }
1981
1982 /*! \brief Sets or updates the frame range in the datapacket
1983
1984 \param r : The XsRange object that should be added to the packet
1985 */
1986 void XsDataPacket_setFrameRange(XsDataPacket* thisPtr, const XsRange* r)
1987 {
1988 genericSet<XsRange, XsRangeVariant>(thisPtr, r, XDI_FrameRange);
1989 MAP.erase(XDI_PacketCounter);
1990 }
1991
1992 /*! \brief Returns the rssi value contained in the datapacket
1993
1994 \returns Returns the rssi value contained in the datapacket
1995 */
1996 int XsDataPacket_rssi(const XsDataPacket* thisPtr)
1997 {
1998 return (int) (int8_t) GenericSimple<uint8_t>::get(thisPtr, XDI_Rssi, (uint8_t) XS_RSSI_UNKNOWN);
1999 }
2000
2001 /*! \brief Returns whether the datapacket contains an rssi value
2002
2003 \returns Whether the datapacket contains an rssi value
2004 */
2005 int XsDataPacket_containsRssi(const XsDataPacket* thisPtr)
2006 {
2007 return genericContains(thisPtr, XDI_Rssi);
2008 }
2009
2010 /*! \brief Sets or updates the rssi value in the datapacket
2011
2012 \param r : The rssi value that should be added to the packet
2013 */
2014 void XsDataPacket_setRssi(XsDataPacket* thisPtr, int r)
2015 {
2016 GenericSimple<uint8_t>::set(thisPtr, (uint8_t)(int8_t)r, XDI_Rssi);
2017 }
2018
2019 /*! \brief Returns a struct with RawGnssPvtData
2020 \param returnVal The object to store the requested data in
2021 \return a struct with RawGnssPvtData
2022 */
2023 XsRawGnssPvtData* XsDataPacket_rawGnssPvtData(const XsDataPacket* thisPtr, XsRawGnssPvtData* returnVal)
2024 {
2025 return genericGet<XsRawGnssPvtData, XsRawGnssPvtDataVariant>(thisPtr, returnVal, XDI_GnssPvtData);
2026 }
2027
2028 /*! \brief Returns 1 if data item contains RawGnssPvtData, 0 otherwise
2029 */
2030 int XsDataPacket_containsRawGnssPvtData(const XsDataPacket* thisPtr)
2031 {
2032 return genericContains(thisPtr, XDI_GnssPvtData);
2033 }
2034
2035 /*! \brief Sets or updates the RawGnssPvtData value in the datapacket
2036 \param r The new value that should be added to the packet
2037 */
2038 void XsDataPacket_setRawGnssPvtData(XsDataPacket* thisPtr, const XsRawGnssPvtData* r)
2039 {
2040 genericSet<XsRawGnssPvtData, XsRawGnssPvtDataVariant>(thisPtr, r, XDI_GnssPvtData);
2041 }
2042
2043
2044 /*! \brief Returns the age of the GNSS data (in samples)
2045 */
2046 uint8_t XsDataPacket_gnssAge(const XsDataPacket* thisPtr)
2047 {
2048 return GenericSimple<uint8_t>::get(thisPtr, XDI_GnssAge, 255);
2049 }
2050
2051 /*! \brief Returns 1 if data item contains GnssAge, 0 otherwise
2052 */
2053 int XsDataPacket_containsGnssAge(const XsDataPacket* thisPtr)
2054 {
2055 return genericContains(thisPtr, XDI_GnssAge);
2056 }
2057
2058 /*! \brief Sets or updates the GnssAge value in the datapacket
2059 \param age The new value that should be added to the packet
2060 */
2061 void XsDataPacket_setGnssAge(XsDataPacket* thisPtr, uint8_t age)
2062 {
2063 GenericSimple<uint8_t>::set(thisPtr, age, XDI_GnssAge);
2064 }
2065
2066 /*! \brief Returns a struct with RawGnssSatInfo
2067 \param returnVal The object to store the requested data in
2068 \return a struct with RawGnssSatInfo
2069 */
2070 XsRawGnssSatInfo* XsDataPacket_rawGnssSatInfo(const XsDataPacket* thisPtr, XsRawGnssSatInfo* returnVal)
2071 {
2072 return genericGet<XsRawGnssSatInfo, XsRawGnssSatInfoVariant>(thisPtr, returnVal, XDI_GnssSatInfo);
2073 }
2074
2075 /*! \brief Returns 1 if data item contains RawGnssPvtData, 0 otherwise
2076 */
2077 int XsDataPacket_containsRawGnssSatInfo(const XsDataPacket* thisPtr)
2078 {
2079 return genericContains(thisPtr, XDI_GnssSatInfo);
2080 }
2081
2082 /*! \brief Sets or updates the RawGnssSatInfo value in the datapacket
2083 \param data The new value that should be added to the packet
2084 */
2085 void XsDataPacket_setRawGnssSatInfo(XsDataPacket* thisPtr, const XsRawGnssSatInfo* data)
2086 {
2087 genericSet<XsRawGnssSatInfo, XsRawGnssSatInfoVariant>(thisPtr, data, XDI_GnssSatInfo);
2088 }
2089
2090 /*! \brief Merge the data items from \a other into the packet
2091
2092 \details The data items contained in XsDataPacket \a other will be added to
2093 this packet. Items that are already present will be
2094 overwritten depending on the value of \a overwrite.
2095
2096 \param other The XsDataPacket to read the data items from
2097 \param overwrite When set to true, existing items will be overwritten, otherwise they will not be modified
2098
2099 \returns Returns the updated data packet
2100 */
2101 XsDataPacket* XsDataPacket_merge(XsDataPacket* thisPtr, const XsDataPacket* other, int overwrite)
2102 {
2103 detach(thisPtr);
2104 bool over = !!overwrite;
2105 thisPtr->d->merge(*other->d, over);
2106
2107 // do additional handling for 'unique' items
2108 auto keepOne = [&](XsDataIdentifier id1, XsDataIdentifier id2)
2109 {
2110 if (genericContains(thisPtr, id1) &&
2111 genericContains(thisPtr, id2))
2112 {
2113 bool gc = genericContains(other, id1);
2114 if ((gc && !over) || (!gc && over)) // logical xor does not exist in C++, write it explicitly
2115 MAP.erase(id1);
2116 else
2117 MAP.erase(id2);
2118 }
2119 };
2120
2121 keepOne(XDI_Quaternion, XDI_RotationMatrix);
2122 keepOne(XDI_Quaternion, XDI_EulerAngles);
2123 keepOne(XDI_EulerAngles, XDI_RotationMatrix);
2124 keepOne(XDI_PacketCounter, XDI_FrameRange);
2125 keepOne(XDI_SampleTime64, XDI_SampleTimeCoarse);
2126 keepOne(XDI_SampleTime64, XDI_SampleTimeFine);
2127
2128 if (over)
2129 {
2130 thisPtr->m_deviceId = other->m_deviceId;
2131 thisPtr->m_toa = other->m_toa;
2132 thisPtr->m_packetId = other->m_packetId;
2133 thisPtr->m_etos = other->m_etos;
2134 }
2135
2136 return thisPtr;
2137 }
2138
2139 /*! \brief Overwrite the contents of the XsDataPacket with the contents of the supplied XsMessage
2140 \param msg The XsMessage to read from
2141 \note The packet is cleared before inserting new items
2142 */
2143 void XsDataPacket_setMessage(XsDataPacket* thisPtr, const XsMessage* msg)
2144 {
2145 XsDataPacket_clear(thisPtr, XDI_None);
2146
2147 XsSize offset = 0;
2148 XsSize sz = msg->getDataSize();
2149
2150 while (offset+3 <= sz) // minimum size of an item is 2(ID) + 1(size) + 0(minimum size)
2151 {
2152 XsDataIdentifier id = static_cast<XsDataIdentifier>(XsMessage_getDataShort(msg, offset));
2153 XsSize itemSize = XsMessage_getDataByte(msg, offset+2);
2154 if (offset + itemSize + 3 > sz)
2155 break; // the item is corrupt
2156
2157 Variant* var = createVariant(id);
2158 if (var)
2159 {
2160 itemSize = var->readFromMessage(*msg, offset+3, itemSize);
2161 MAP.insert(id, var);
2162 }
2163 offset += 3 + itemSize; // never use var->sizeInMsg() here, since it _may_ differ
2164 }
2165 if (offset < sz)
2166 {
2167 // if we get here then we detected some kind of corruption
2168 // so we should not trust anything we read
2169 XsDataPacket_clear(thisPtr, XDI_None);
2170 return;
2171 }
2172 }
2173
2174 /*! \brief Write the contents of the XsDataPacket to an XsMessage in MtData2 format
2175 \details The function will clear the message and add all items in the XsDataPacket as a standard MtData2 message.
2176 \param msg The message to write to
2177 */
2178 void XsDataPacket_toMessage(const XsDataPacket* thisPtr, XsMessage* msg)
2179 {
2180 msg->resizeData(0); // clear the data part while leaving header intact
2181 msg->setMessageId(XMID_MtData2);
2182
2183 XsSize offset = 0;
2184 msg->resizeData(2048); // prevent constant message resizing by pre-allocating a large message and later reducing its size
2185 for (auto const& i : MAP)
2186 {
2187 XsSize sz = i.second->sizeInMsg();
2188 if (sz < 255)
2189 {
2190 msg->setDataShort((uint16_t) i.second->dataId(), offset);
2191 msg->setDataByte((uint8_t)sz, offset+2);
2192 i.second->writeToMessage(*msg, offset+3);
2193 offset += 3+sz;
2194 }
2195 else
2196 {
2197 XsSize sz2 = sz;
2198 XsSize offset2 = offset;
2199 while (sz2 >= 255)
2200 {
2201 msg->setDataShort((uint16_t) i.second->dataId(), offset2);
2202 msg->setDataByte((uint8_t)255, offset2+2);
2203 offset2 += 258;
2204 sz2 -= 255;
2205 }
2206 msg->setDataShort((uint16_t) i.second->dataId(), offset2);
2207 msg->setDataByte((uint8_t)sz2, offset2+2); // note that this size may be 0
2208 i.second->writeToMessage(*msg, offset+3); // individual write functions should takke extended size into account
2209 offset = offset2+3+sz2;
2210 }
2211 }
2212 msg->resizeData(offset);
2213 }
2214
2215 /*! \brief Returns the Full Snapshot part of the XsDataPacket
2216 \details Full Snapshot is an internal format used by Xsens devices for high accuracy data transfer.
2217 In most cases XDA processing will remove this item from the XsDataPacket and replace it with items that
2218 are more directly usable.
2219 \param returnVal The object to store the requested data in. This must be a properly constructed object.
2220 \returns The supplied \a returnVal, filled with the requested data or cleared if it was not available
2221 */
2222 XsSnapshot* XsDataPacket_fullSnapshot(const XsDataPacket* thisPtr, XsSnapshot* returnVal)
2223 {
2224 return genericGet<XsSnapshot, XsFullSnapshotVariant>(thisPtr, returnVal, XDI_FullSnapshot);
2225 }
2226
2227 /*! \brief Returns true if the XsDataPacket contains Full Snapshot data
2228 \returns true if the XsDataPacket contains Full Snapshot data
2229 */
2230 int XsDataPacket_containsFullSnapshot(const XsDataPacket* thisPtr)
2231 {
2232 return genericContains(thisPtr, XDI_FullSnapshot);
2233 }
2234
2235 /*! \brief Sets the Awinda Snapshot part of the XsDataPacket
2236 \param data The new data to set
2237 \param retransmission When non-zero, the item is marked as a retransmitted packet
2238 */
2239 void XsDataPacket_setFullSnapshot(XsDataPacket* thisPtr, XsSnapshot const * data, int retransmission)
2240 {
2241 genericSet<XsSnapshot, XsFullSnapshotVariant>(thisPtr, data, XDI_FullSnapshot | (retransmission ? XDI_RetransmissionFlag : XDI_None));
2242 }
2243
2244 /*! \brief Returns the Awinda Snapshot part of the XsDataPacket
2245 \details Awinda Snapshot is an internal format used by Xsens devices for high accuracy data trasnfer.
2246 In most cases XDA processing will remove this item from the XsDataPacket and replace it with items that
2247 are more directly usable.
2248 \param returnVal The object to store the requested data in. This must be a properly constructed object.
2249 \returns The supplied \a returnVal, filled with the requested data or cleared if it was not available
2250 */
2251 XsSnapshot* XsDataPacket_awindaSnapshot(const XsDataPacket* thisPtr, XsSnapshot* returnVal)
2252 {
2253 return genericGet<XsSnapshot, XsAwindaSnapshotVariant>(thisPtr, returnVal, XDI_AwindaSnapshot);
2254 }
2255
2256 /*! \brief Returns true if the XsDataPacket contains Awinda Snapshot data
2257 \returns true if the XsDataPacket contains Awinda Snapshot data
2258 */
2259 int XsDataPacket_containsAwindaSnapshot(const XsDataPacket* thisPtr)
2260 {
2261 return genericContains(thisPtr, XDI_AwindaSnapshot);
2262 }
2263
2264 /*! \brief Sets the Awinda Snapshot part of the XsDataPacket
2265 \param data The new data to set
2266 \param retransmission When non-zero, the item is marked as a retransmitted packet
2267 */
2268 void XsDataPacket_setAwindaSnapshot(XsDataPacket* thisPtr, XsSnapshot const * data, int retransmission)
2269 {
2270 genericSet<XsSnapshot, XsAwindaSnapshotVariant>(thisPtr, data, XDI_AwindaSnapshot | (retransmission ? XDI_RetransmissionFlag : XDI_None));
2271 }
2272
2273 /*! \brief Returns true if the contained Awinda Snapshot is marked as a retransmission
2274 \returns true if the XsDataPacket contains Awinda Snapshot data and it is marked as a retransmission
2275 */
2276 int XsDataPacket_isAwindaSnapshotARetransmission(const XsDataPacket* thisPtr)
2277 {
2278 auto it = MAP.find(XDI_AwindaSnapshot);
2279 if (it == MAP.end())
2280 return false;
2281 return (it->second->dataId() & XDI_RetransmissionMask) == XDI_RetransmissionFlag;
2282 }
2283
2284 /*! \brief Returns the Glove Snapshot part of the XsDataPacket
2285 \details Glove Snapshot is an internal format used by Xsens devices for high accuracy data transfer.
2286 In most cases XDA processing will remove this item from the XsDataPacket and replace it with items that
2287 are more directly usable.
2288 \param returnVal The object to store the requested data in. This must be a properly constructed object.
2289 \returns The supplied \a returnVal, filled with the requested data or cleared if it was not available
2290 */
2291 XsGloveSnapshot* XsDataPacket_gloveSnapshot(const XsDataPacket* thisPtr, XsGloveSnapshot* returnVal)
2292 {
2293 return genericGet<XsGloveSnapshot, XsGloveSnapshotVariant>(thisPtr, returnVal, XDI_GloveSnapshot);
2294 }
2295
2296 /*! \brief Returns true if the XsDataPacket contains Glove Snapshot data
2297 \returns true if the XsDataPacket contains Glove Snapshot data
2298 */
2299 int XsDataPacket_containsGloveSnapshot(const XsDataPacket* thisPtr)
2300 {
2301 return genericContains(thisPtr, XDI_GloveSnapshot);
2302 }
2303
2304 /*! \brief Sets the Glove Snapshot part of the XsDataPacket
2305 \param data The new data to set
2306 \param retransmission When non-zero, the item is marked as a retransmitted packet
2307 */
2308 void XsDataPacket_setGloveSnapshot(XsDataPacket* thisPtr, XsGloveSnapshot const * data, int retransmission)
2309 {
2310 genericSet<XsGloveSnapshot, XsGloveSnapshotVariant>(thisPtr, data, XDI_GloveSnapshot | (retransmission ? XDI_RetransmissionFlag : XDI_None));
2311 }
2312
2313 /*! \brief Converts input vector \a input with data identifier \a id to output XsVector \a returnVal */
2314 static void convertRawVector(XsUShortVector const& input, XsDataIdentifier id, XsVector& returnVal)
2315 {
2316 XsReal (*caster)(uint16_t) = unsigned_cast;
2317 returnVal.setSize(3);
2318 if ((id & XDI_DataFormatMask) == XDI_RawSigned)
2319 caster = signed_cast;
2320 for (XsSize i = 0; i < 3; i++)
2321 returnVal[i] = caster(input[i]);
2322 }
2323
2324 /*! \returns the data component specified by \a id and \a field, converted to floating point values
2325 \param[in] id The data identifier of the data component
2326 \param[in] field Pointer to a member in XsScrData, pointing to the data to retrieve
2327 \param[out] returnVal the returned floating point values
2328 */
2329 static XsVector* convertedVector(const XsDataPacket* thisPtr, XsVector* returnVal, XsDataIdentifier id, XsUShortVector XsScrData::* field)
2330 {
2331 assert(returnVal);
2332
2333 XsUShortVector tmp;
2334
2335 auto it = MAP.find(XDI_RawAccGyrMagTemp);
2336 if (it != MAP.end())
2337 tmp = it->second->toDerived<XsScrDataVariant>().m_data.*field;
2338 else
2339 {
2340 it = MAP.find(id);
2341 if (it != MAP.end())
2342 tmp = it->second->toDerived<XsUShortVectorVariant>().m_data;
2343 }
2344
2345 convertRawVector(tmp, it->second->dataId(), *returnVal);
2346 return returnVal;
2347 }
2348
2349 /*! \brief The raw accelerometer component of a data item, converted to floating point values.
2350
2351 \param returnVal : An XsVector to put the requested data in
2352
2353 \returns A XsVector containing the x, y and z axis values in that order
2354 */
2355 XsVector* XsDataPacket_rawAccelerationConverted(const XsDataPacket* thisPtr, XsVector* returnVal)
2356 {
2357 return convertedVector(thisPtr, returnVal, XDI_RawAcc, &XsScrData::m_acc);
2358 }
2359
2360 /*! \brief The raw gyroscope component of a data item, converted to floating point values.
2361
2362 \param returnVal : An XsVector to put the requested data in
2363
2364 \returns A XsVector containing the x, y and z axis values in that order
2365 */
2366 XsVector* XsDataPacket_rawGyroscopeDataConverted(const XsDataPacket* thisPtr, XsVector* returnVal)
2367 {
2368 return convertedVector(thisPtr, returnVal, XDI_RawGyr, &XsScrData::m_gyr);
2369 }
2370
2371 /*! \brief The raw magnetometer component of a data item, converted to floating point values.
2372
2373 \param returnVal : An XsVector to put the requested data in
2374
2375 \returns A XsVector containing the x, y and z axis values in that order
2376 */
2377 XsVector* XsDataPacket_rawMagneticFieldConverted(const XsDataPacket* thisPtr, XsVector* returnVal)
2378 {
2379 return convertedVector(thisPtr, returnVal, XDI_RawMag, &XsScrData::m_mag);
2380 }
2381
2382 /*! \brief The raw gyroscope temperature component of a data item, converted to floating point values.
2383
2384 \param returnVal : An XsVector to put the requested data in
2385
2386 \returns A XsVector containing the x, y and z axis values in that order
2387 */
2388 XsVector* XsDataPacket_rawGyroscopeTemperatureDataConverted(const XsDataPacket* thisPtr, XsVector* returnVal)
2389 {
2390 assert(returnVal);
2391 auto it = MAP.find(XDI_RawGyroTemp);
2392 XsUShortVector tmp;
2393 if (it != MAP.end())
2394 tmp = it->second->toDerived<XsUShortVectorVariant>().m_data;
2395 convertRawVector(tmp, it->second->dataId(), *returnVal);
2396 return returnVal;
2397 }
2398
2399 /*! \brief Returns the raw blob part of the XsDataPacket
2400 \param returnVal The object to store the requested data in. This must be a properly constructed object.
2401 \returns The supplied \a returnVal, filled with the requested data or cleared if it was not available
2402 */
2403 XsByteArray* XsDataPacket_rawBlob(const XsDataPacket* thisPtr, XsByteArray* returnVal)
2404 {
2405 return genericGet<XsByteArray, XsByteArrayVariant>(thisPtr, returnVal, XDI_RawBlob);
2406 }
2407
2408 /*! \brief Returns true if the XsDataPacket contains raw blob data
2409 \returns true if the XsDataPacket contains raw blob data
2410 */
2411 int XsDataPacket_containsRawBlob(const XsDataPacket* thisPtr)
2412 {
2413 return genericContains(thisPtr, XDI_RawBlob);
2414 }
2415
2416 /*! \brief Sets the raw blob part of the XsDataPacket
2417 \param data The new data to set
2418 */
2419 void XsDataPacket_setRawBlob(XsDataPacket* thisPtr, const XsByteArray *data)
2420 {
2421 genericSet<XsByteArray, XsByteArrayVariant>(thisPtr, data, XDI_RawBlob);
2422 }
2423
2424 /*! \brief Returns AccelerationHR
2425 \param returnVal : An XsVector to put the requested in
2426 \returns A XsVector containing the x, y and z axis values in that order
2427 */
2428 XsVector* XsDataPacket_accelerationHR(const XsDataPacket* thisPtr, XsVector* returnVal)
2429 {
2430 return genericGet<XsVector, XsVector3Variant>(thisPtr, returnVal, XDI_AccelerationHR);
2431 }
2432
2433 /*! \brief Check if data item contains AccelerationHR
2434 \returns true if this packet contains AccelerationHR
2435 */
2436 int XsDataPacket_containsAccelerationHR(const XsDataPacket* thisPtr)
2437 {
2438 return genericContains(thisPtr, XDI_AccelerationHR);
2439 }
2440
2441 /*! \brief Add/update the AccelerationHR for the item
2442 \param vec A 3-component vector containing AccelerationHR
2443 */
2444 void XsDataPacket_setAccelerationHR(XsDataPacket* thisPtr, const XsVector* vec)
2445 {
2446 genericSet<XsVector, XsVector3Variant>(thisPtr, vec, XDI_AccelerationHR | XDI_SubFormatDouble);
2447 }
2448
2449 /*! \brief Returns RateOfTurnHR
2450 \param returnVal : An XsVector to put the requested in
2451 \returns A XsVector containing the x, y and z axis values in that order
2452 */
2453 XsVector* XsDataPacket_rateOfTurnHR(const XsDataPacket* thisPtr, XsVector* returnVal)
2454 {
2455 return genericGet<XsVector, XsVector3Variant>(thisPtr, returnVal, XDI_RateOfTurnHR);
2456 }
2457
2458 /*! \brief Check if data item contains RateOfTurnHR
2459 \returns true if this packet contains RateOfTurnHR
2460 */
2461 int XsDataPacket_containsRateOfTurnHR(const XsDataPacket* thisPtr)
2462 {
2463 return genericContains(thisPtr, XDI_RateOfTurnHR);
2464 }
2465
2466 /*! \brief Add/update the RateOfTurnHR for the item
2467 \param vec A 3-component vector containing RateOfTurnHR
2468 */
2469 void XsDataPacket_setRateOfTurnHR(XsDataPacket* thisPtr, const XsVector* vec)
2470 {
2471 genericSet<XsVector, XsVector3Variant>(thisPtr, vec, XDI_RateOfTurnHR | XDI_SubFormatDouble);
2472 }
2473
2474 /*! \brief Returns the number of private data items for all XsDataPacket combined currently in memory
2475 \details This is an internal value and should not be used for any other purpose.
2476 \return The current number of items.
2477 */
2478 int XsDataPacket_privateCount()
2479 {
2480 return DataPacketPrivate::creationDiff();
2481 }
2482
2483 } // extern "C"
2484
2485 /*! @} */