| 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 "xssensorranges.h" |
| 34 |
#include <cassert> |
| 35 |
|
| 36 |
extern "C" { |
| 37 |
|
| 38 |
/* Find the A in hardware info of the product code |
| 39 |
|
| 40 |
Returns a pointer to the A. |
| 41 |
*/ |
| 42 |
static const char *findHardwareType(const char *productCode) |
| 43 |
{ |
| 44 |
if (findHardwareManufacturer(productCode) != HMT_MT) |
| 45 |
return nullptr; |
| 46 |
|
| 47 |
const char *A = strchr(productCode, 'A'); |
| 48 |
if (!A) |
| 49 |
return nullptr; |
| 50 |
const char *G = strchr(A, 'G'); |
| 51 |
if (!G) |
| 52 |
return nullptr; |
| 53 |
assert(G - A <= 3); |
| 54 |
return A; |
| 55 |
} |
| 56 |
|
| 57 |
/*! \brief Return the hardware manufacturer from \a productCode |
| 58 |
*/ |
| 59 |
HardwareManufacturerType findHardwareManufacturerC(const XsString* productCode) |
| 60 |
{ |
| 61 |
if (strstr(productCode->c_str(), "MT") != nullptr) |
| 62 |
return HMT_MT; |
| 63 |
|
| 64 |
return HMT_None; |
| 65 |
} |
| 66 |
|
| 67 |
/*! \brief Return the hardware type from \a productCode |
| 68 |
*/ |
| 69 |
void findHardwareTypeC(const XsString* productCode, XsString* resultValue) |
| 70 |
{ |
| 71 |
if (!resultValue) |
| 72 |
return; |
| 73 |
const char *hwt = findHardwareType(productCode->c_str()); |
| 74 |
if (!hwt) |
| 75 |
resultValue->clear(); |
| 76 |
else |
| 77 |
*resultValue = hwt; |
| 78 |
} |
| 79 |
|
| 80 |
/* Return the accelerometer range field */ |
| 81 |
static char accelerometerRangeField(const char *productCode) |
| 82 |
{ |
| 83 |
const char *hwi = findHardwareType(productCode); |
| 84 |
if (!hwi) |
| 85 |
return 0; |
| 86 |
return *(hwi + 1); |
| 87 |
} |
| 88 |
|
| 89 |
/* Return the gyroscope range field */ |
| 90 |
static char gyroscopeRangeField(const char *productCode) |
| 91 |
{ |
| 92 |
const char *hwi = findHardwareType(productCode); |
| 93 |
if (!hwi) |
| 94 |
return 0; |
| 95 |
const char *G = strchr(hwi, 'G'); |
| 96 |
if (!G) |
| 97 |
return 0; |
| 98 |
return *(G + 1); |
| 99 |
} |
| 100 |
|
| 101 |
/*! \brief The accelerometer range from product code \a productCode |
| 102 |
*/ |
| 103 |
double accelerometerRangeC(const XsString *productCode, int32_t hwVersionMajor) |
| 104 |
{ |
| 105 |
switch (findHardwareManufacturerC(productCode)) |
| 106 |
{ |
| 107 |
case HardwareManufacturerType::HMT_MT: |
| 108 |
switch(accelerometerRangeField(productCode->c_str())) |
| 109 |
{ |
| 110 |
case '1': return 100.0; |
| 111 |
case '2': return 20.0; |
| 112 |
case '3': return 17.0; |
| 113 |
case '5': return 50.0; |
| 114 |
case '6': return 60.0; |
| 115 |
case '7': return 160.0; |
| 116 |
case '8': |
| 117 |
{ |
| 118 |
if (hwVersionMajor < 3) |
| 119 |
return 180.0; |
| 120 |
else |
| 121 |
return 200.0; |
| 122 |
} |
| 123 |
default: return 10000.0; |
| 124 |
} |
| 125 |
|
| 126 |
default: |
| 127 |
return 10000.0; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
/*! \brief The actual accelerometer range from product code \a productCode |
| 132 |
|
| 133 |
This is a measured value and possibly larger than what accelerometerRange() returns. |
| 134 |
*/ |
| 135 |
double actualAccelerometerRangeC(const XsString *productCode, int32_t hwVersionMajor) |
| 136 |
{ |
| 137 |
switch (findHardwareManufacturerC(productCode)) |
| 138 |
{ |
| 139 |
case HardwareManufacturerType::HMT_MT: |
| 140 |
switch(accelerometerRangeField(productCode->c_str())) |
| 141 |
{ |
| 142 |
case '1': return 100.0; |
| 143 |
case '2': return 20.0; |
| 144 |
case '3': return 17.0; |
| 145 |
case '5': return 50.0; |
| 146 |
case '6': return 60.0; |
| 147 |
case '7': return 160.0; |
| 148 |
case '8': |
| 149 |
{ |
| 150 |
if (hwVersionMajor < 3) |
| 151 |
return 180.0; |
| 152 |
else |
| 153 |
return 200.0; |
| 154 |
} |
| 155 |
default: return 10000.0; |
| 156 |
} |
| 157 |
|
| 158 |
default: |
| 159 |
return 10000.0; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
/*! \brief The gyroscope range from product code \a productCode |
| 164 |
*/ |
| 165 |
double gyroscopeRangeC(const XsString *productCode) |
| 166 |
{ |
| 167 |
switch (findHardwareManufacturerC(productCode)) |
| 168 |
{ |
| 169 |
case HardwareManufacturerType::HMT_MT: |
| 170 |
switch(gyroscopeRangeField(productCode->c_str())) |
| 171 |
{ |
| 172 |
case '0': return 1000.0; |
| 173 |
case '1': return 150.0; |
| 174 |
case '2': return 1200.0; |
| 175 |
case '3': return 300.0; |
| 176 |
case '4': return 450.0; |
| 177 |
case '5': return 2500.0; |
| 178 |
case '6': return 1800.0; |
| 179 |
case '9': return 900.0; |
| 180 |
default: return 10000.0; |
| 181 |
} |
| 182 |
|
| 183 |
default: |
| 184 |
return 10000.0; |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/*! \brief The actual gyroscope range from product code \a productCode |
| 189 |
|
| 190 |
This is a measured value and possibly larger than what gyroscopeRange() returns. |
| 191 |
*/ |
| 192 |
double actualGyroscopeRangeC(const XsString *productCode) |
| 193 |
{ |
| 194 |
switch (findHardwareManufacturerC(productCode)) |
| 195 |
{ |
| 196 |
case HardwareManufacturerType::HMT_MT: |
| 197 |
switch(gyroscopeRangeField(productCode->c_str())) |
| 198 |
{ |
| 199 |
case '0': return 1000.0; |
| 200 |
case '1': return 180.0; |
| 201 |
case '2': return 1700.0; |
| 202 |
case '3': return 420.0; |
| 203 |
case '4': return 450.0; |
| 204 |
case '5': return 2500.0; |
| 205 |
case '6': return 2000.0; |
| 206 |
case '9': return 1080.0; |
| 207 |
default: return 10000.0; |
| 208 |
} |
| 209 |
|
| 210 |
default: |
| 211 |
return 10000.0; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
} |