Debian Codegraph @

3rdparty/xspublic/xstypes/xsdeviceid.c

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 "xsdeviceid.h"
34 #include "xsstring.h"
35 #include "xsdid.h"
36 #include <stdio.h>
37 #include <stdlib.h>
38
39 /*! \class XsDeviceId
40 \brief Contains an Xsens device ID and provides operations for determining the type of device
41 */
42
43 /*! \addtogroup cinterface C Interface
44 @{
45 */
46
47 /*! \returns The legacy bit used to identify legacy or new XsDeviceId format */
48 uint64_t XsDeviceId_legacyBit(const struct XsDeviceId *thisPtr)
49 {
50 (void)thisPtr;
51 return XS_DID64_BIT;
52 }
53
54 /*! \brief Test if the device ID represents a legacy device identification */
55 int XsDeviceId_isLegacyDeviceId(const struct XsDeviceId *thisPtr)
56 {
57 return ((thisPtr->m_deviceId & 0x0000000080000000) == 0);
58 }
59
60 /*! \brief Test if the device ID represents an Mti 1-series device */
61 int XsDeviceId_isMtiX(const struct XsDeviceId* thisPtr)
62 {
63 if (XsDeviceId_isLegacyDeviceId(thisPtr))
64 {
65 return ((thisPtr->m_deviceId & XS_DID_TYPEH_MASK) == XS_DID_TYPEH_MT_X_MPU);
66 }
67 else
68 {
69 if (memcmp(thisPtr->m_productCode, "MTi-", 4) != 0)
70 return 0;
71 int deviceFamily = atoi(&thisPtr->m_productCode[4]);
72 return ((deviceFamily != 0) && (deviceFamily < 10));
73 }
74 }
75
76 /*! \brief Test if the device ID represents an Mti 10-series device */
77 int XsDeviceId_isMtiX0(const struct XsDeviceId* thisPtr)
78 {
79 if (XsDeviceId_isLegacyDeviceId(thisPtr))
80 {
81 return ((thisPtr->m_deviceId & XS_DID_TYPEH_MASK) == XS_DID_TYPEH_MT_X0);
82 }
83 else
84 {
85 if (memcmp(thisPtr->m_productCode, "MTi-", 4) != 0)
86 return 0;
87 int deviceFamily = atoi(&thisPtr->m_productCode[4]);
88 return ((deviceFamily != 0) && ((deviceFamily >= 10) && (deviceFamily < 100)));
89 }
90 }
91
92 /*! \brief Test if the device ID represents an Mti 100-series device */
93 int XsDeviceId_isMtiX00(const struct XsDeviceId* thisPtr)
94 {
95 if (XsDeviceId_isLegacyDeviceId(thisPtr))
96 {
97 return ((thisPtr->m_deviceId & XS_DID_TYPEH_MASK) == XS_DID_TYPEH_MT_X00);
98 }
99 else
100 {
101 if (memcmp(thisPtr->m_productCode, "MTi-", 4) != 0)
102 return 0;
103 int deviceFamily = atoi(&thisPtr->m_productCode[4]);
104 if ((deviceFamily != 0) && (deviceFamily >= 100 && deviceFamily <= 300))
105 {
106 return 1;
107 }
108 else if (memcmp(thisPtr->m_productCode, "MTi-G-", 6) == 0)
109 {
110 deviceFamily = atoi(&thisPtr->m_productCode[6]);
111 if ((deviceFamily != 0) && (deviceFamily >= 100))
112 return 1;
113 }
114 }
115 return 0;
116 }
117
118 /*! \brief Test if the device ID represents an Mtig 700 device */
119 int XsDeviceId_isMtigX00(const struct XsDeviceId* thisPtr)
120 {
121 if (XsDeviceId_isLegacyDeviceId(thisPtr))
122 {
123 return ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_700) &&
124 ((thisPtr->m_deviceId &~XS_DID_TYPEL_COMM_MASK) < XS_DID_MK4TYPE_MT_710_RANGE_START);
125 }
126 else
127 {
128 if (memcmp(thisPtr->m_productCode, "MTi-G-", 6) != 0)
129 return 0;
130
131 int deviceFamily = atoi(&thisPtr->m_productCode[6]);
132 return ((deviceFamily != 0) && (deviceFamily == 700));
133 }
134 }
135
136 /*! \brief Test if the device ID represents an Mtig 710 device */
137 int XsDeviceId_isMtigX10(const struct XsDeviceId* thisPtr)
138 {
139 if (XsDeviceId_isLegacyDeviceId(thisPtr))
140 {
141 return ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_700) &&
142 ((thisPtr->m_deviceId & ~XS_DID_TYPEL_COMM_MASK) >= XS_DID_MK4TYPE_MT_710_RANGE_START);
143 }
144 else
145 {
146 if (memcmp(thisPtr->m_productCode, "MTi-G-", 6) != 0)
147 return 0;
148
149 int deviceFamily = atoi(&thisPtr->m_productCode[6]);
150 return ((deviceFamily != 0) && (deviceFamily == 710));
151 }
152 }
153
154 /*! \brief Test if the device ID represents an MTi-600 series device */
155 int XsDeviceId_isMti6X0(const struct XsDeviceId* thisPtr)
156 {
157 if (XsDeviceId_isLegacyDeviceId(thisPtr))
158 {
159 return 0;
160 }
161 else
162 {
163 if (memcmp(thisPtr->m_productCode, "MTi-", 4) != 0)
164 return 0;
165
166 int deviceFamily = atoi(&thisPtr->m_productCode[4]);
167 return ((deviceFamily != 0) && ((deviceFamily >= 600) && (deviceFamily < 700)));
168 }
169 }
170
171 /*! \brief Test if the device ID represents an Glove series device */
172 int XsDeviceId_isGlove(const struct XsDeviceId* thisPtr)
173 {
174 if (XsDeviceId_isLegacyDeviceId(thisPtr))
175 {
176 return 0;
177 }
178 else
179 {
180 if (memcmp(thisPtr->m_productCode, "Glove", 5) != 0)
181 return 0;
182
183 return 1;
184 }
185 }
186
187 /*! \brief Test if this device ID represents an MTw */
188 int XsDeviceId_isMtw(const struct XsDeviceId* thisPtr)
189 {
190 return XsDeviceId_isMtw2(thisPtr);
191 }
192
193 /*! \brief Test if this device ID represents an MTw2. */
194 int XsDeviceId_isMtw2(const struct XsDeviceId* thisPtr)
195 {
196 if (XsDeviceId_isLegacyDeviceId(thisPtr))
197 {
198 return XS_DID_MTW2(thisPtr->m_deviceId);
199 }
200 else
201 {
202 return (memcmp(thisPtr->m_productCode, "MTw2", 4) == 0);
203 }
204 }
205
206 /*! \brief Test if this device ID represents an MTx */
207 int XsDeviceId_isMtx(const struct XsDeviceId* thisPtr)
208 {
209 return XsDeviceId_isMtx2(thisPtr);
210 }
211
212 /*! \brief Test if this device ID represents an MTx2 */
213 int XsDeviceId_isMtx2(const struct XsDeviceId* thisPtr)
214 {
215 if (XsDeviceId_isLegacyDeviceId(thisPtr))
216 {
217 return XS_DID_MTX2(thisPtr->m_deviceId);
218 }
219 else
220 {
221 return (memcmp(thisPtr->m_productCode, "MTx2", 4) == 0);
222 }
223 }
224
225 /*! \brief Test if this device ID represents a bodypack device. */
226 int XsDeviceId_isBodyPack(const struct XsDeviceId* thisPtr)
227 {
228 if (XsDeviceId_isLegacyDeviceId(thisPtr))
229 {
230 return XS_DID_BODYPACK(thisPtr->m_deviceId) || (thisPtr->m_deviceId == XS_DID_ABMCLOCKMASTER);
231 }
232 else
233 {
234 return (memcmp(thisPtr->m_productCode, "BodyPack", 8) == 0);
235 }
236 }
237
238 /*! \brief Test if this device ID represents a Wireless Master device (Awinda Station, Awinda Dongle, Awinda OEM). */
239 int XsDeviceId_isWirelessMaster(const struct XsDeviceId* thisPtr)
240 {
241 if (XsDeviceId_isLegacyDeviceId(thisPtr))
242 {
243 return ((thisPtr->m_deviceId & XS_DID_TYPEH_MASK) == XS_DID_TYPEH_AWINDAMASTER) &&
244 !XsDeviceId_isBodyPack(thisPtr) &&
245 !XsDeviceId_isSyncStationX(thisPtr);
246 }
247 else
248 {
249 return (memcmp(thisPtr->m_productCode, "AW-", 3) == 0);
250 }
251 }
252
253 /*! \brief Test if this device ID represents an awinda device. */
254 int XsDeviceId_isAwindaX(const struct XsDeviceId* thisPtr)
255 {
256 return XsDeviceId_isAwinda2(thisPtr);
257 }
258
259 /*! \brief Test if this device ID represents an Awinda Station.
260 */
261 int XsDeviceId_isAwindaXStation(const struct XsDeviceId* thisPtr)
262 {
263 return XsDeviceId_isAwinda2Station(thisPtr);
264 }
265
266 /*! \brief Test if this device ID represents an Awinda Dongle. */
267 int XsDeviceId_isAwindaXDongle(const struct XsDeviceId* thisPtr)
268 {
269 return XsDeviceId_isAwinda2Dongle(thisPtr);
270 }
271
272 /*! \brief Test if this device ID represents an Awinda OEM board. */
273 int XsDeviceId_isAwindaXOem(const struct XsDeviceId* thisPtr)
274 {
275 return XsDeviceId_isAwinda2Oem(thisPtr);
276 }
277
278 /*! \brief Test if this device ID represents an awinda2 device. */
279 int XsDeviceId_isAwinda2(const struct XsDeviceId* thisPtr)
280 {
281 if (XsDeviceId_isLegacyDeviceId(thisPtr))
282 {
283 return XS_DID_AWINDA2(thisPtr->m_deviceId);
284 }
285 else
286 {
287 return (memcmp(thisPtr->m_productCode, "AW-", 3) == 0);
288 }
289 }
290
291 /*! \brief Test if this device ID represents an Awinda2 Station.
292 */
293 int XsDeviceId_isAwinda2Station(const struct XsDeviceId* thisPtr)
294 {
295 if (XsDeviceId_isLegacyDeviceId(thisPtr))
296 {
297 return XS_DID_AWINDA2_STATION(thisPtr->m_deviceId);
298 }
299 else
300 {
301 return memcmp(thisPtr->m_productCode, "AW-A2", 5) == 0;
302 }
303 }
304
305 /*! \brief Test if this device ID represents an Awinda2 Dongle. */
306 int XsDeviceId_isAwinda2Dongle(const struct XsDeviceId* thisPtr)
307 {
308 if (XsDeviceId_isLegacyDeviceId(thisPtr))
309 {
310 return XS_DID_AWINDA2_DONGLE(thisPtr->m_deviceId);
311 }
312 else
313 {
314 return memcmp(thisPtr->m_productCode, "AW-DNG2", 7) == 0;
315 }
316 }
317
318 /*! \brief Test if this device ID represents an Awinda2 OEM board. */
319 int XsDeviceId_isAwinda2Oem(const struct XsDeviceId* thisPtr)
320 {
321 return XS_DID_AWINDA2_OEM(thisPtr->m_deviceId);
322 }
323
324 /*! \brief Test if this device ID represents a SyncStation. */
325 int XsDeviceId_isSyncStationX(const struct XsDeviceId* thisPtr)
326 {
327 return XS_DID_SYNCSTATION(thisPtr->m_deviceId);
328 }
329
330 /*! \brief Test if this device ID represents a SyncStation v2. */
331 int XsDeviceId_isSyncStation2(const struct XsDeviceId* thisPtr)
332 {
333 return XS_DID_SYNCSTATION2(thisPtr->m_deviceId);
334 }
335
336 /*! \brief Test if this device ID represents a Hardware In the Loop test device. */
337 int XsDeviceId_isHilDevice(const struct XsDeviceId* thisPtr)
338 {
339 if (XsDeviceId_isLegacyDeviceId(thisPtr))
340 {
341 return 0;
342 }
343 else
344 {
345 if (strcmp(thisPtr->m_productCode, "HILDEVICE") != 0)
346 return 0;
347 return 1;
348 }
349 }
350
351 /*! \brief Test if this device ID represents an IMU. */
352 int XsDeviceId_isImu(const struct XsDeviceId* thisPtr)
353 {
354 if (XsDeviceId_isLegacyDeviceId(thisPtr))
355 {
356 return (((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_1_MPU) ||
357 ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_10) ||
358 ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_100));
359 }
360 else
361 {
362 if (memcmp(thisPtr->m_productCode, "MTi-", 4) != 0)
363 return 0;
364
365 int deviceFamily = thisPtr->m_productCode[4] - '0';
366 if (deviceFamily == 0)
367 return 0;
368
369 if (deviceFamily == 6)
370 deviceFamily = thisPtr->m_productCode[5] - '0';
371
372 return (deviceFamily == 1);
373 }
374 }
375
376 /*! \brief Test if this device ID represents a VRU. */
377 int XsDeviceId_isVru(const struct XsDeviceId* thisPtr)
378 {
379 if (XsDeviceId_isLegacyDeviceId(thisPtr))
380 {
381 return (((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_2_MPU) ||
382 ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_20) ||
383 ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_200));
384 }
385 else
386 {
387 if (memcmp(thisPtr->m_productCode, "MTi-", 4) != 0)
388 return 0;
389
390 int deviceFamily = thisPtr->m_productCode[4] - '0';
391 if (deviceFamily == 0)
392 return 0;
393
394 if (deviceFamily == 6)
395 deviceFamily = thisPtr->m_productCode[5] - '0';
396
397 return (deviceFamily == 2);
398 }
399 }
400
401 /*! \brief Test if this device ID represents an AHRS. */
402 int XsDeviceId_isAhrs(const struct XsDeviceId* thisPtr)
403 {
404 if (XsDeviceId_isLegacyDeviceId(thisPtr))
405 {
406 return (((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_3_MPU) ||
407 ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_30) ||
408 ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_300));
409 }
410 else
411 {
412 if (memcmp(thisPtr->m_productCode, "MTi-", 4) != 0)
413 return 0;
414
415 int deviceFamily = thisPtr->m_productCode[4] - '0';
416 if (deviceFamily == 0)
417 return 0;
418
419 if (deviceFamily == 6)
420 deviceFamily = thisPtr->m_productCode[5] - '0';
421
422 return (deviceFamily == 3);
423 }
424 }
425
426 /*! \brief Test if this device ID represents an GNSS (capable) device. */
427 int XsDeviceId_isGnss(const struct XsDeviceId* thisPtr)
428 {
429 if (XsDeviceId_isLegacyDeviceId(thisPtr))
430 {
431 return (((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_700) ||
432 ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_7_MPU));
433 }
434 else
435 {
436 if (memcmp(thisPtr->m_productCode, "MTi-", 4) != 0)
437 return 0;
438
439 int deviceFamily = atoi(&thisPtr->m_productCode[4]);
440 if (deviceFamily == 7)
441 {
442 return 1;
443 }
444 else if (deviceFamily == 670)
445 {
446 return 1;
447 }
448 else
449 {
450 if (memcmp(thisPtr->m_productCode, "MTi-G-", 6) != 0)
451 return 0;
452
453 deviceFamily = atoi(&thisPtr->m_productCode[6]);
454 return (deviceFamily == 700 || deviceFamily == 710);
455 }
456 }
457 }
458
459 /*! \brief Test if this device ID represents any of the container devices such as Bodypack and Awinda Station
460 */
461 int XsDeviceId_isContainerDevice(const struct XsDeviceId* thisPtr)
462 {
463 return XsDeviceId_isBodyPack(thisPtr) ||
464 XsDeviceId_isWirelessMaster(thisPtr);
465 }
466
467 /*! \brief Test if this device ID represents an MT device (any Mti, Mtig, Mtx or Mtw) */
468 int XsDeviceId_isMt(const struct XsDeviceId* thisPtr)
469 {
470 return (XsDeviceId_isMti(thisPtr) || XsDeviceId_isMtig(thisPtr) || XsDeviceId_isMtw(thisPtr) || XsDeviceId_isMtx(thisPtr));
471 }
472
473 /*! \brief Test if this device ID represents an MTi device (1, 10 or 100 series, 1 includes MTi-7) */
474 int XsDeviceId_isMti(const struct XsDeviceId* thisPtr)
475 {
476 return (XsDeviceId_isMtiX(thisPtr) || XsDeviceId_isMtiX0(thisPtr) || XsDeviceId_isMtiX00(thisPtr) || XsDeviceId_isMti6X0(thisPtr));
477 }
478
479 /*! \brief Test if this device ID represents an MTig device (700 or 710 series) */
480 int XsDeviceId_isMtig(const struct XsDeviceId* thisPtr)
481 {
482 return (XsDeviceId_isMtigX00(thisPtr) || XsDeviceId_isMtigX10(thisPtr));
483 }
484
485 /*! \brief Test if this device ID represents an Mk4 generation MT device */
486 int XsDeviceId_isMtMark4(const struct XsDeviceId* thisPtr)
487 {
488 if (XsDeviceId_isLegacyDeviceId(thisPtr))
489 return (XsDeviceId_isMtiX0(thisPtr) || XsDeviceId_isMtiX00(thisPtr)) && ((thisPtr->m_deviceId & XS_DID_TYPEL_MK5) != XS_DID_TYPEL_MK5);
490 else
491 return (XsDeviceId_isMtiX0(thisPtr) || XsDeviceId_isMtiX00(thisPtr)) && thisPtr->m_hardwareVersion < 0x300;
492 }
493
494 /*! \brief Test if this device ID represents an Mk5 generation MT device */
495 int XsDeviceId_isMtMark5(const struct XsDeviceId* thisPtr)
496 {
497 if (XsDeviceId_isLegacyDeviceId(thisPtr))
498 return (XsDeviceId_isMtiX0(thisPtr) || XsDeviceId_isMtiX00(thisPtr)) && ((thisPtr->m_deviceId & XS_DID_TYPEL_MK5) == XS_DID_TYPEL_MK5);
499 else
500 return (XsDeviceId_isMtiX0(thisPtr) || XsDeviceId_isMtiX00(thisPtr)) && thisPtr->m_hardwareVersion >= 0x300;
501 }
502
503 //------------------------------------------------------------------------------------------------------------
504 //------------------------------------------------------------------------------------------------------------
505 //------------------------------------------------------------------------------------------------------------
506 //------------------------------------------------------------------------------------------------------------
507
508 /*! \brief Get a string with a readable representation of this device ID. */
509 void XsDeviceId_toString(const XsDeviceId* thisPtr, XsString* str)
510 {
511 if (XsDeviceId_isLegacyDeviceId(thisPtr))
512 {
513 char device[9];
514 sprintf(device, "%08" PRINTF_INT32_MODIFIER "X", (uint32_t)thisPtr->m_deviceId);
515 XsString_assign(str, 8, device);
516 }
517 else
518 {
519 char device[17];
520 XsSize n = (XsSize) (ptrdiff_t) sprintf(device, "%010" PRINTF_INT64_MODIFIER "X", thisPtr->m_deviceId);
521 XsString_assign(str, n, device);
522 }
523 }
524
525 /*! \brief Read a device ID from the supplied string.
526 \param str The string to interpret
527 */
528 void XsDeviceId_fromString(XsDeviceId* thisPtr, const XsString *str)
529 {
530 uint64_t tmp = 0;
531 int count = 0;
532 if (!thisPtr || !str || !str->m_data)
533 return;
534 int result = sscanf(str->m_data, "%" PRINTF_INT64_MODIFIER "x%n", &tmp, &count);
535 if (result == 1)
536 thisPtr->m_deviceId = tmp;
537 }
538
539 /*! \brief Get a string with a readable representation of this device ID. Either full or as a type
540 \param makeType Boolean whether the deviceid is changed to a type instead of the full deviceid
541 \param str The string to write to
542 */
543 void XsDeviceId_toDeviceTypeString(const XsDeviceId* thisPtr, XsString* str, int makeType)
544 {
545 XsDeviceId deviceType = XSDEVICEID_INITIALIZER;
546 if (makeType)
547 XsDeviceId_deviceType(thisPtr, 1, &deviceType);
548 else
549 deviceType = *thisPtr;
550 char device[50];
551 XsSize n;
552 if (thisPtr->m_hardwareVersion == 0)
553 n = (XsSize) (ptrdiff_t) sprintf(device, "%s_%08X.%08X", deviceType.m_productCode, (uint32_t)deviceType.m_deviceId, thisPtr->m_productVariant);
554 else
555 n = (XsSize) (ptrdiff_t) sprintf(device, "%s_%08X.%08X.%d_%d", deviceType.m_productCode, (uint32_t)deviceType.m_deviceId, thisPtr->m_productVariant, (uint8_t)((thisPtr->m_hardwareVersion & 0xFF00) >> 8), (uint8_t)(thisPtr->m_hardwareVersion & 0xFF));
556 XsString_assign(str, n, device);
557 }
558
559 /*! \brief Read a device ID from the supplied string.
560 \param str The string to interpret
561 */
562 void XsDeviceId_fromDeviceTypeString(XsDeviceId* thisPtr, const XsString *str)
563 {
564 uint32_t id = 0;
565 int hwRevH = 0, hwRevL = 0;
566 uint32_t variant;
567 char productCode[24];
568 if (!thisPtr || !str || !str->m_data)
569 return;
570 int result = sscanf(str->m_data, "%24[^_]_%08X.%08X.%d_%d", productCode, &id, &variant, &hwRevH, &hwRevL);
571 if (result == 5 || result == 3)
572 {
573 thisPtr->m_deviceId = id;
574 thisPtr->m_hardwareVersion = (uint16_t)((uint16_t)hwRevH << 8) + (uint16_t)hwRevL;
575 thisPtr->m_productVariant = variant;
576 strcpy(thisPtr->m_productCode, productCode);
577 }
578 }
579
580 /*! \brief Test if the device ID is a valid id (not 0).
581 */
582 int XsDeviceId_isValid(const struct XsDeviceId* thisPtr)
583 {
584 if (XsDeviceId_isLegacyDeviceId(thisPtr))
585 return thisPtr->m_deviceId != 0;
586 else
587 return thisPtr->m_productCode[0] != 0 && thisPtr->m_deviceId != 0;
588 }
589
590 /*! \brief Swap the contents of \a a with those of \a b
591 */
592 void XsDeviceId_swap(XsDeviceId* a, XsDeviceId* b)
593 {
594 XsDeviceId tmp = *a;
595 *a = *b;
596 *b = tmp;
597 }
598
599 /*! \brief Returns true if this is equal to \a other or this is a type-specifier that matches \a other
600 \param other The deviceid to compare this deviceid to
601 \return True if the deviceids are equal or the type-specifier matches
602 */
603 int XsDeviceId_contains(XsDeviceId const* thisPtr, XsDeviceId const* other)
604 {
605 if (thisPtr == other)
606 return 1;
607 if (thisPtr->m_deviceId == other->m_deviceId)
608 return 1;
609 if (thisPtr->m_deviceId & XS_DID_ID_MASK) // NOTE: This produces incorrect results for device ids ending with 0000. See MVN-3876
610 return 0;
611 XsDeviceId typeThis, typeOther;
612 XsDeviceId_deviceType(thisPtr, 1, &typeThis);
613 XsDeviceId_deviceType(other, 1, &typeOther);
614 if (XsDeviceId_isLegacyDeviceId(thisPtr))
615 return typeThis.m_deviceId == typeOther.m_deviceId;
616 else
617 {
618 if (strcmp(typeThis.m_productCode, typeOther.m_productCode) == 0)
619 return 1;
620 }
621
622 return 0;
623 }
624
625 /*! \brief Returns true if the ID is just a device type, not an actual device ID
626 */
627 int XsDeviceId_isType(XsDeviceId const* thisPtr)
628 {
629 // true when we have a valid type (not a broadcast) and a 0 ID
630 if (XsDeviceId_isLegacyDeviceId(thisPtr))
631 return !(thisPtr->m_deviceId & XS_DID_ID_MASK);
632 else
633 return !(thisPtr->m_deviceId & ~XS_DID64_BIT);
634 }
635
636 /*! \brief Returns the name of the type of device identified by this id
637 */
638 void XsDeviceId_typeName(XsDeviceId const* thisPtr, XsString* str)
639 {
640 if (!str)
641 return;
642
643 if (!thisPtr)
644 {
645 XsString_assignCharArray(str, "invalid");
646 return;
647 }
648
649 if (XsDeviceId_isAwinda2Station(thisPtr))
650 XsString_assignCharArray(str, "Awinda Station v2");
651 else if(XsDeviceId_isAwinda2Dongle(thisPtr))
652 XsString_assignCharArray(str, "Awinda Dongle v2");
653 else if(XsDeviceId_isAwinda2Oem(thisPtr))
654 XsString_assignCharArray(str, "Awinda OEM v2");
655 else if (XsDeviceId_isMtw2(thisPtr))
656 XsString_assignCharArray(str, "MTw2");
657 else if (XsDeviceId_isMtx2(thisPtr))
658 XsString_assignCharArray(str, "MTx2");
659 else if (XsDeviceId_isBodyPack(thisPtr))
660 XsString_assignCharArray(str, "Bodypack");
661 else if (XsDeviceId_isSyncStation2(thisPtr))
662 XsString_assignCharArray(str, "Sync Station v2");
663 else if (XsDeviceId_isMti6X0(thisPtr))
664 {
665 if (XsDeviceId_isImu(thisPtr))
666 XsString_assignCharArray(str, "MTi-610");
667 else if (XsDeviceId_isVru(thisPtr))
668 XsString_assignCharArray(str, "MTi-620");
669 else if (XsDeviceId_isAhrs(thisPtr))
670 XsString_assignCharArray(str, "MTi-630");
671 else if (XsDeviceId_isGnss(thisPtr))
672 XsString_assignCharArray(str, "MTi-670");
673 }
674 else if (XsDeviceId_isMtMk4_1(thisPtr))
675 XsString_assignCharArray(str, "MTi-1");
676 else if (XsDeviceId_isMtMk4_2(thisPtr))
677 XsString_assignCharArray(str, "MTi-2");
678 else if (XsDeviceId_isMtMk4_3(thisPtr))
679 XsString_assignCharArray(str, "MTi-3");
680 else if (XsDeviceId_isMtMk4_7(thisPtr))
681 XsString_assignCharArray(str, "MTi-7");
682 else if (XsDeviceId_isMtMk4_10(thisPtr))
683 XsString_assignCharArray(str, "MTi-10");
684 else if (XsDeviceId_isMtMk4_20(thisPtr))
685 XsString_assignCharArray(str, "MTi-20");
686 else if (XsDeviceId_isMtMk4_30(thisPtr))
687 XsString_assignCharArray(str, "MTi-30");
688 else if (XsDeviceId_isMtMk4_100(thisPtr))
689 XsString_assignCharArray(str, "MTi-100");
690 else if (XsDeviceId_isMtMk4_200(thisPtr))
691 XsString_assignCharArray(str, "MTi-200");
692 else if (XsDeviceId_isMtMk4_300(thisPtr))
693 XsString_assignCharArray(str, "MTi-300");
694 else if ( XsDeviceId_isMtMk4_400(thisPtr))
695 XsString_assignCharArray(str, "MTi-400");
696 else if (XsDeviceId_isMtMk4_500(thisPtr))
697 XsString_assignCharArray(str, "MTi-500");
698 else if (XsDeviceId_isMtMk4_710(thisPtr))
699 XsString_assignCharArray(str, "MTi-G-710");
700 else if (XsDeviceId_isMtMk4_700(thisPtr))
701 XsString_assignCharArray(str, "MTi-G-700");
702 else if (XsDeviceId_isMtMk4_800(thisPtr))
703 XsString_assignCharArray(str, "MTi-G-800");
704 else if (XsDeviceId_isMtMk4_900(thisPtr))
705 XsString_assignCharArray(str, "MTi-G-900");
706 else
707 XsString_assignCharArray(str, "Unknown");
708 }
709
710 /*! \brief Returns the type of device identified by this id
711 */
712 void XsDeviceId_type(struct XsDeviceId const* thisPtr, struct XsDeviceId* type)
713 {
714 if (!type)
715 return;
716 if (!XsDeviceId_isLegacyDeviceId(thisPtr))
717 {
718 type->m_deviceId = XS_DID64_BIT;
719 XsString typeName = XsString_INITIALIZER;
720 XsDeviceId_typeName(thisPtr, &typeName);
721 strcpy(type->m_productCode, typeName.m_data);
722 }
723 else
724 type->m_deviceId = thisPtr->m_deviceId & XS_DID_FULLTYPE_MASK;
725 }
726
727 /*! \brief Returns the device type identified by this id (eg 10, 300 and Awinda2 Master)
728 */
729 void XsDeviceId_deviceType(struct XsDeviceId const* thisPtr, int detailed, struct XsDeviceId* type)
730 {
731 if (!type)
732 return;
733 if (!XsDeviceId_isLegacyDeviceId(thisPtr))
734 {
735 if (XsDeviceId_isMti6X0(thisPtr))
736 {
737 type->m_deviceId = XS_DID64_BIT;
738 strncpy(type->m_productCode, thisPtr->m_productCode, 7);
739 type->m_productCode[7] = 0;
740 if (detailed)
741 {
742 type->m_hardwareVersion = thisPtr->m_hardwareVersion;
743 type->m_productVariant = thisPtr->m_productVariant;
744 }
745 else
746 {
747 type->m_hardwareVersion = 0;
748 type->m_productVariant = 0;
749 }
750 }
751 }
752 else
753 {
754 XsDeviceId_deviceTypeMask(thisPtr, detailed, type);
755 type->m_deviceId = thisPtr->m_deviceId & type->m_deviceId;
756 strcpy(type->m_productCode, thisPtr->m_productCode);
757 }
758 }
759
760 /*! \brief Returns the mask which can be used to get the detailed device type (eg 10, 300 and Awinda2 Master)
761 */
762 void XsDeviceId_deviceTypeMask(struct XsDeviceId const* thisPtr, int detailed, struct XsDeviceId* type)
763 {
764 if (XsDeviceId_isLegacyDeviceId(thisPtr))
765 {
766 if (XsDeviceId_isMtMk4_X(thisPtr))
767 type->m_deviceId = (XS_DID_TYPEH_MASK | (detailed ? (XS_DID_GPH_MASK | XS_DID_GPL_MASK | XS_DID_TYPEL_MASK) : 0));
768 else if (XsDeviceId_isMtMk4(thisPtr))
769 type->m_deviceId = (XS_DID_TYPEH_MASK | (detailed ? (XS_DID_GPH_MASK | XS_DID_GPL_MASK | XS_DID_TYPEL_MK5) : 0));
770 else if (XsDeviceId_isAwindaX(thisPtr))
771 type->m_deviceId = (XS_DID_TYPEH_MASK | (detailed ? (XS_DID_GPH_MASK | XS_DID_GPL_MASK) : 0));
772 else if (XsDeviceId_isSyncStationX(thisPtr))
773 type->m_deviceId = (XS_DID_TYPEH_MASK | (detailed ? (XS_DID_GPH_MASK | XS_DID_GPL_MASK) : 0));
774 else if (XsDeviceId_isMtw(thisPtr) || XsDeviceId_isMtx(thisPtr))
775 type->m_deviceId = (XS_DID_TYPE_MASK | (detailed ? (XS_DID_GPH_MASK | XS_DID_GPL_MASK) : 0));
776 else if (thisPtr->m_deviceId == XS_DID_ABMCLOCKMASTER)
777 type->m_deviceId = XS_DID_ABMCLOCKMASTER;
778 else
779 type->m_deviceId = XS_DID_TYPEH_MASK;
780 }
781 else
782 type->m_deviceId = XS_DID64_BIT;
783 }
784
785 //============================================================================================================
786 //============================================================================================================
787 //==== Deprecated methods follow =====
788 //============================================================================================================
789 //============================================================================================================
790
791 /*! \brief Test if this device ID represents an MTMk4.
792 \returns True if it is an MTMk4.
793 \deprecated If the purpose is to check for a Mk4, Mk5 or 1-series device use: isMti() || isMtig(). If the purpose is to detect actual Mk4 (10,100,7x0) use isMtMark4()
794 */
795 int XsDeviceId_isMtMk4(const struct XsDeviceId* thisPtr)
796 {
797 return (XsDeviceId_isMtMk4_X(thisPtr) ||
798 XsDeviceId_isMtMk4_X0(thisPtr) ||
799 XsDeviceId_isMtMk4_X00(thisPtr));
800 }
801
802 /*! \brief Test if this device ID represents an MTMk4 1 series.
803 \returns True if it is an MTMk4 1 series.
804 \deprecated Use isMtiX()
805 */
806 int XsDeviceId_isMtMk4_X(const struct XsDeviceId* thisPtr)
807 {
808 return XsDeviceId_isMtiX(thisPtr);
809 }
810
811 /*! \brief Test if this device ID represents an MTMk4 1.
812 \returns True if it is an MTMk4 1.
813 \deprecated Use isMtiX() and isImu()
814 */
815 int XsDeviceId_isMtMk4_1(const struct XsDeviceId* thisPtr)
816 {
817 return XsDeviceId_isMtiX(thisPtr) && XsDeviceId_isImu(thisPtr);
818 }
819
820 /*! \brief Test if this device ID represents an MTMk4 2.
821 \returns True if it is an MTMk4 2.
822 \deprecated Use isMtiX() and isVru()
823 */
824 int XsDeviceId_isMtMk4_2(const struct XsDeviceId* thisPtr)
825 {
826 return XsDeviceId_isMtiX(thisPtr) && XsDeviceId_isVru(thisPtr);
827 }
828
829 /*! \brief Test if this device ID represents an MTMk4 3.
830 \returns True if it is an MTMk4 3.
831 \deprecated Use isMtiX() and isAhrs()
832 */
833 int XsDeviceId_isMtMk4_3(const struct XsDeviceId* thisPtr)
834 {
835 return XsDeviceId_isMtiX(thisPtr) && XsDeviceId_isAhrs(thisPtr);
836 }
837
838 /*! \brief Test if this device ID represents an MTMk4 7.
839 \returns True if it is an MTMk4 7.
840 \deprecated Use isMtiX() and isGnss()
841 */
842 int XsDeviceId_isMtMk4_7(const struct XsDeviceId* thisPtr)
843 {
844 return XsDeviceId_isMtiX(thisPtr) && XsDeviceId_isGnss(thisPtr);
845 }
846
847 /*! \brief Test if this device ID represents an MTMk4 10 series.
848 \returns True if it is an MTMk4 10 series.
849 \deprecated Use isMtiX0()
850 */
851 int XsDeviceId_isMtMk4_X0(const struct XsDeviceId* thisPtr)
852 {
853 return XsDeviceId_isMtiX0(thisPtr);
854 }
855
856 /*! \brief Test if this device ID represents an MTMk4 10.
857 \returns True if it is an MTMk4 10.
858 \deprecated Use isMtiX0() and isImu()
859 */
860 int XsDeviceId_isMtMk4_10(const struct XsDeviceId* thisPtr)
861 {
862 return XsDeviceId_isMtiX0(thisPtr) && XsDeviceId_isImu(thisPtr);
863 }
864
865 /*! \brief Test if this device ID represents an MTMk4 20.
866 \returns True if it is an MTMk4 20.
867 \deprecated Use isMtiX0() and isVru()
868 */
869 int XsDeviceId_isMtMk4_20(const struct XsDeviceId* thisPtr)
870 {
871 return XsDeviceId_isMtiX0(thisPtr) && XsDeviceId_isVru(thisPtr);
872 }
873
874 /*! \brief Test if this device ID represents an MTMk4 30.
875 \returns True if it is an MTMk4 30.
876 \deprecated Use isMtiX0() and isAhrs()
877 */
878 int XsDeviceId_isMtMk4_30(const struct XsDeviceId* thisPtr)
879 {
880 return XsDeviceId_isMtiX0(thisPtr) && XsDeviceId_isAhrs(thisPtr);
881 }
882
883 /*! \brief Test if this device ID represents an MTMk4 100 series (including 700 and 710)
884 \returns True if it is an MTMk4 100 series.
885 \deprecated Use isMtiX00() || isMtig() to detect all 100's and 7x0's
886 */
887 int XsDeviceId_isMtMk4_X00(const struct XsDeviceId* thisPtr)
888 {
889 return XsDeviceId_isMtiX00(thisPtr);
890 }
891
892 /*! \brief Test if this device ID represents an MTMk4 100.
893 \returns True if it is an MTMk4 100.
894 \deprecated Use isMtiX00() and isImu()
895 */
896 int XsDeviceId_isMtMk4_100(const struct XsDeviceId* thisPtr)
897 {
898 return XsDeviceId_isMtiX00(thisPtr) && XsDeviceId_isImu(thisPtr);
899 }
900
901 /*! \brief Test if this device ID represents an MTMk4 200.
902 \returns True if it is an MTMk4 200.
903 \deprecated Use isMtiX00() and isVru()
904 */
905 int XsDeviceId_isMtMk4_200(const struct XsDeviceId* thisPtr)
906 {
907 return XsDeviceId_isMtiX00(thisPtr) && XsDeviceId_isVru(thisPtr);
908 }
909
910 /*! \brief Test if this device ID represents an MTMk4 300.
911 \returns True if it is an MTMk4 300.
912 \deprecated Use isMtiX00() and isAhrs()
913 */
914 int XsDeviceId_isMtMk4_300(const struct XsDeviceId* thisPtr)
915 {
916 return XsDeviceId_isMtiX00(thisPtr) && XsDeviceId_isAhrs(thisPtr);
917 }
918
919 /*! \brief Test if this device ID represents an MTMk4 400.
920 \returns True if it is an MTMk4 400.
921 \deprecated Will be removed
922 */
923 int XsDeviceId_isMtMk4_400(const struct XsDeviceId* thisPtr)
924 {
925 return ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_400);
926 }
927
928 /*! \brief Test if this device ID represents an MTMk4 500.
929 \returns True if it is an MTMk4 500.
930 \deprecated Will be removed
931 */
932 int XsDeviceId_isMtMk4_500(const struct XsDeviceId* thisPtr)
933 {
934 return ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_500);
935 }
936
937 /*! \brief Test if this device ID represents an MTMk4 600.
938 \returns True if it is an MTMk4 600.
939 \deprecated Will be removed
940 */
941 int XsDeviceId_isMtMk4_600(const struct XsDeviceId* thisPtr)
942 {
943 return ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_600);
944 }
945
946 /*! \brief Test if this device ID represents an MTMk4 700.
947 \returns True for all 700 and 710's (Mk4 and Mk5).
948 \deprecated use isGnss() to check for Gnss capabilities,
949 use isMtig() to check for either 700 or 710,
950 use isMtigX00() or isMtigX10() to discern between 700 and 710,
951 use isMtMark4() or isMtMark5() to discern between Mark 4 and Mark 5
952 */
953 int XsDeviceId_isMtMk4_700(const struct XsDeviceId* thisPtr)
954 {
955 return XsDeviceId_isMtigX00(thisPtr) || XsDeviceId_isMtigX10(thisPtr);
956 }
957
958 /*! \brief Test if this device ID represents either an MTMk4 710 or Mk5 710.
959 \returns True if it is either an MTMk4 710 or Mk5 710.
960 \deprecated use isGnss() to check for Gnss capabilities, use isMtig() to check for either 700 or 710, use isMtigX00() or isMtigX10() to discern between 700 and 710
961 */
962 int XsDeviceId_isMtMk4_710(const struct XsDeviceId* thisPtr)
963 {
964 return XsDeviceId_isMtigX10(thisPtr);
965 }
966
967 /*! \brief Test if this device ID represents an MTMk4 800.
968 \returns True if it is an MTMk4 800.
969 \deprecated Will be removed
970 */
971 int XsDeviceId_isMtMk4_800(const struct XsDeviceId* thisPtr)
972 {
973 return ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_800);
974 }
975
976 /*! \brief Test if this device ID represents an MTMk4 900.
977 \returns True if it is an MTMk4 900.
978 \deprecated Will be removed
979 */
980 int XsDeviceId_isMtMk4_900(const struct XsDeviceId* thisPtr)
981 {
982 return ((thisPtr->m_deviceId & XS_DID_MK4TYPE_MASK) == XS_DID_MK4TYPE_MT_900);
983 }
984
985 /*! \brief Test if this device ID represents an MTMk5.
986 \returns True if it is an MTMk5.
987 \deprecated Use isMtMark5()
988 */
989 int XsDeviceId_isMtMk5(const struct XsDeviceId* thisPtr)
990 {
991 return XsDeviceId_isMtMark5(thisPtr);
992 }
993
994 /*! \brief Test if this device ID represents an MTMk5 10 series.
995 \returns True if it is an MTMk5 10 series.
996 \deprecated Use isMtMark5() && isMtiX0()
997 */
998 int XsDeviceId_isMtMk5_X0(const struct XsDeviceId* thisPtr)
999 {
1000 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_X0(thisPtr);
1001 }
1002
1003 /*! \brief Test if this device ID represents an MTMk5 10.
1004 \returns True if it is an MTMk5 10.
1005 \deprecated Use isMtMark5() && isMtiX0() && isImu()
1006 */
1007 int XsDeviceId_isMtMk5_10(const struct XsDeviceId* thisPtr)
1008 {
1009 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_10(thisPtr);
1010 }
1011
1012 /*! \brief Test if this device ID represents an MTMk5 20.
1013 \returns True if it is an MTMk5 20.
1014 \deprecated Use isMtMark5() && isMtiX0() && isVru()
1015 */
1016 int XsDeviceId_isMtMk5_20(const struct XsDeviceId* thisPtr)
1017 {
1018 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_20(thisPtr);
1019 }
1020
1021 /*! \brief Test if this device ID represents an MTMk5 30.
1022 \returns True if it is an MTMk5 30.
1023 \deprecated Use isMtMark5() && isMtiX0() && isAhrs()
1024 */
1025 int XsDeviceId_isMtMk5_30(const struct XsDeviceId* thisPtr)
1026 {
1027 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_30(thisPtr);
1028 }
1029
1030 /*! \brief Test if this device ID represents an MTMk5 100 series.
1031 \returns True if it is an MTMk5 100 series.
1032 \deprecated Use isMtMark5() && (isMtiX00() || isMtig())
1033 */
1034 int XsDeviceId_isMtMk5_X00(const struct XsDeviceId* thisPtr)
1035 {
1036 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_X00(thisPtr);
1037 }
1038
1039 /*! \brief Test if this device ID represents an MTMk5 100.
1040 \returns True if it is an MTMk5 100.
1041 \deprecated Use isMtMark5() && isMtiX00() && isImu()
1042 */
1043 int XsDeviceId_isMtMk5_100(const struct XsDeviceId* thisPtr)
1044 {
1045 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_100(thisPtr);
1046 }
1047
1048 /*! \brief Test if this device ID represents an MTMk5 200.
1049 \returns True if it is an MTMk5 200.
1050 \deprecated Use isMtMark5() && isMtiX00() && isVru()
1051 */
1052 int XsDeviceId_isMtMk5_200(const struct XsDeviceId* thisPtr)
1053 {
1054 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_200(thisPtr);
1055 }
1056
1057 /*! \brief Test if this device ID represents an MTMk5 300.
1058 \returns True if it is an MTMk5 300.
1059 \deprecated Use isMtMark5() && isMtiX00() && isAhrs()
1060 */
1061 int XsDeviceId_isMtMk5_300(const struct XsDeviceId* thisPtr)
1062 {
1063 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_300(thisPtr);
1064 }
1065
1066 /*! \brief Test if this device ID represents an MTMk5 710.
1067 \returns True if it is an MTMk5 710.
1068 \deprecated Use (isMtMark5() && isMtigX10())
1069 */
1070 int XsDeviceId_isMtMk5_710(const struct XsDeviceId* thisPtr)
1071 {
1072 return XsDeviceId_isMtMk5(thisPtr) && XsDeviceId_isMtMk4_710(thisPtr);
1073 }
1074
1075 /*! @} */