xssensorranges.cpp
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 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 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #include "xssensorranges.h"
66 #include <cassert>
67 
68 extern "C" {
69 
70  /* Find the A in hardware info of the product code
71 
72  Returns a pointer to the A.
73  */
74  static const char* findHardwareType(const char* productCode)
75  {
76  if (findHardwareManufacturer(productCode) != HMT_MT)
77  return nullptr;
78 
79  const char* A = strchr(productCode, 'A');
80  if (!A)
81  return nullptr;
82  const char* G = strchr(A, 'G');
83  if (!G)
84  return nullptr;
85  assert(G - A <= 3);
86  return A;
87  }
88 
92  {
93  if (strstr(productCode->c_str(), "MT") != nullptr)
94  return HMT_MT;
95 
96  return HMT_None;
97  }
98 
101  void findHardwareTypeC(const XsString* productCode, XsString* resultValue)
102  {
103  if (!resultValue)
104  return;
105  const char* hwt = findHardwareType(productCode->c_str());
106  if (!hwt)
107  resultValue->clear();
108  else
109  *resultValue = hwt;
110  }
111 
112  /* Return the accelerometer range field */
113  static char accelerometerRangeField(const char* productCode)
114  {
115  const char* hwi = findHardwareType(productCode);
116  if (!hwi)
117  return 0;
118  return *(hwi + 1);
119  }
120 
121  /* Return the gyroscope range field */
122  static char gyroscopeRangeField(const char* productCode)
123  {
124  const char* hwi = findHardwareType(productCode);
125  if (!hwi)
126  return 0;
127  const char* G = strchr(hwi, 'G');
128  if (!G)
129  return 0;
130  return *(G + 1);
131  }
132 
135  double accelerometerRangeC(const XsString* productCode, int32_t hwVersionMajor)
136  {
137  switch (findHardwareManufacturerC(productCode))
138  {
140  switch (accelerometerRangeField(productCode->c_str()))
141  {
142  case '1':
143  return 100.0;
144  case '2':
145  return 20.0;
146  case '3':
147  return 17.0;
148  case '5':
149  return 50.0;
150  case '6':
151  return 60.0;
152  case '7':
153  return 160.0;
154  case '8':
155  {
156  if (hwVersionMajor < 3)
157  return 180.0;
158  else
159  return 200.0;
160  }
161  default:
162  return 10000.0;
163  }
164 
165  default:
166  return 10000.0;
167  }
168  }
169 
174  double actualAccelerometerRangeC(const XsString* productCode, int32_t hwVersionMajor)
175  {
176  switch (findHardwareManufacturerC(productCode))
177  {
179  switch (accelerometerRangeField(productCode->c_str()))
180  {
181  case '1':
182  return 100.0;
183  case '2':
184  return 20.0;
185  case '3':
186  return 17.0;
187  case '5':
188  return 50.0;
189  case '6':
190  return 60.0;
191  case '7':
192  return 160.0;
193  case '8':
194  {
195  if (hwVersionMajor < 3)
196  return 180.0;
197  else
198  return 200.0;
199  }
200  default:
201  return 10000.0;
202  }
203 
204  default:
205  return 10000.0;
206  }
207  }
208 
211  double gyroscopeRangeC(const XsString* productCode)
212  {
213  switch (findHardwareManufacturerC(productCode))
214  {
216  switch (gyroscopeRangeField(productCode->c_str()))
217  {
218  case '0':
219  return 1000.0;
220  case '1':
221  return 150.0;
222  case '2':
223  return 1200.0;
224  case '3':
225  return 300.0;
226  case '4':
227  return 450.0;
228  case '5':
229  return 2500.0;
230  case '6':
231  return 1800.0;
232  case '9':
233  return 900.0;
234  default:
235  return 10000.0;
236  }
237 
238  default:
239  return 10000.0;
240  }
241  }
242 
247  double actualGyroscopeRangeC(const XsString* productCode)
248  {
249  switch (findHardwareManufacturerC(productCode))
250  {
252  switch (gyroscopeRangeField(productCode->c_str()))
253  {
254  case '0':
255  return 1000.0;
256  case '1':
257  return 180.0;
258  case '2':
259  return 1700.0;
260  case '3':
261  return 420.0;
262  case '4':
263  return 450.0;
264  case '5':
265  return 2500.0;
266  case '6':
267  return 2000.0;
268  case '9':
269  return 1080.0;
270  default:
271  return 10000.0;
272  }
273 
274  default:
275  return 10000.0;
276  }
277  }
278 
279 }
actualAccelerometerRangeC
double actualAccelerometerRangeC(const XsString *productCode, int32_t hwVersionMajor)
The actual accelerometer range from product code productCode.
Definition: xssensorranges.cpp:174
findHardwareType
static const char * findHardwareType(const char *productCode)
Definition: xssensorranges.cpp:74
HMT_MT
@ HMT_MT
Definition: xssensorranges.h:77
actualGyroscopeRangeC
double actualGyroscopeRangeC(const XsString *productCode)
The actual gyroscope range from product code productCode.
Definition: xssensorranges.cpp:247
xssensorranges.h
findHardwareTypeC
void findHardwareTypeC(const XsString *productCode, XsString *resultValue)
Return the hardware type from productCode.
Definition: xssensorranges.cpp:101
accelerometerRangeC
double accelerometerRangeC(const XsString *productCode, int32_t hwVersionMajor)
The accelerometer range from product code productCode.
Definition: xssensorranges.cpp:135
HardwareManufacturerType
HardwareManufacturerType
Definition: xssensorranges.h:75
gyroscopeRangeField
static char gyroscopeRangeField(const char *productCode)
Definition: xssensorranges.cpp:122
accelerometerRangeField
static char accelerometerRangeField(const char *productCode)
Definition: xssensorranges.cpp:113
HMT_None
@ HMT_None
Definition: xssensorranges.h:78
int32_t
signed int int32_t
Definition: pstdint.h:515
gyroscopeRangeC
double gyroscopeRangeC(const XsString *productCode)
The gyroscope range from product code productCode.
Definition: xssensorranges.cpp:211
XsString
A 0-terminated managed string of characters.
findHardwareManufacturerC
HardwareManufacturerType findHardwareManufacturerC(const XsString *productCode)
Return the hardware manufacturer from productCode.
Definition: xssensorranges.cpp:91


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20