Skip to content

Commit cca58c9

Browse files
Add tdk-icm42670 to imu.yaml (#1338)
# Description - add `TDK-ICM42670` to imu.yaml --------- Co-authored-by: Jason Mobarak <[email protected]>
1 parent 8714c86 commit cca58c9

File tree

6 files changed

+39
-277
lines changed

6 files changed

+39
-277
lines changed

c/include/libsbp/imu_macros.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
#define SBP_IMU_AUX_IMU_TYPE_BOSCH_BMI160 (0)
7878
#define SBP_IMU_AUX_IMU_TYPE_ST_MICROELECTRONICS_ASM330LLH (1)
79+
#define SBP_IMU_AUX_IMU_TYPE_TDK_ICM_42670 (3)
7980
#define SBP_IMU_AUX_IMU_TYPE_MURATA_SCHA634_D03 (4)
8081
#define SBP_IMU_AUX_IMU_TYPE_TDK_IAM_20680HP (5)
8182
#define SBP_IMU_AUX_GYROSCOPE_RANGE_MASK (0xfu)

docs/sbp.pdf

-163 Bytes
Binary file not shown.

rust/sbp/src/messages/imu.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ pub mod msg_imu_aux {
162162
/// ST Microelectronics ASM330LLH
163163
StMicroelectronicsAsm330Llh = 1,
164164

165+
/// TDK ICM-42670
166+
TdkIcm42670 = 3,
167+
165168
/// Murata SCHA634-D03
166169
MurataScha634D03 = 4,
167170

@@ -176,6 +179,7 @@ pub mod msg_imu_aux {
176179
ImuType::StMicroelectronicsAsm330Llh => {
177180
f.write_str("ST Microelectronics ASM330LLH")
178181
}
182+
ImuType::TdkIcm42670 => f.write_str("TDK ICM-42670"),
179183
ImuType::MurataScha634D03 => f.write_str("Murata SCHA634-D03"),
180184
ImuType::TdkIam20680Hp => f.write_str("TDK IAM-20680HP"),
181185
}
@@ -188,6 +192,7 @@ pub mod msg_imu_aux {
188192
match i {
189193
0 => Ok(ImuType::BoschBmi160),
190194
1 => Ok(ImuType::StMicroelectronicsAsm330Llh),
195+
3 => Ok(ImuType::TdkIcm42670),
191196
4 => Ok(ImuType::MurataScha634D03),
192197
5 => Ok(ImuType::TdkIam20680Hp),
193198
i => Err(i),

sbpjson/javascript/SbpJson.js

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,25 +1943,11 @@ function uTCTimeToJson(value) {
19431943
return JSON.stringify(uncast(value, r("UTCTime")), null, 2);
19441944
}
19451945

1946-
function invalidValue(typ, val, key, parent = '') {
1947-
const prettyTyp = prettyTypeName(typ);
1948-
const parentText = parent ? ` on ${parent}` : '';
1949-
const keyText = key ? ` for key "${key}"` : '';
1950-
throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
1951-
}
1952-
1953-
function prettyTypeName(typ) {
1954-
if (Array.isArray(typ)) {
1955-
if (typ.length === 2 && typ[0] === undefined) {
1956-
return `an optional ${prettyTypeName(typ[1])}`;
1957-
} else {
1958-
return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
1959-
}
1960-
} else if (typeof typ === "object" && typ.literal !== undefined) {
1961-
return typ.literal;
1962-
} else {
1963-
return typeof typ;
1946+
function invalidValue(typ, val, key = '') {
1947+
if (key) {
1948+
throw Error(`Invalid value for key "${key}". Expected type ${JSON.stringify(typ)} but got ${JSON.stringify(val)}`);
19641949
}
1950+
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`, );
19651951
}
19661952

19671953
function jsonToJSProps(typ) {
@@ -1982,10 +1968,10 @@ function jsToJSONProps(typ) {
19821968
return typ.jsToJSON;
19831969
}
19841970

1985-
function transform(val, typ, getProps, key = '', parent = '') {
1971+
function transform(val, typ, getProps, key = '') {
19861972
function transformPrimitive(typ, val) {
19871973
if (typeof typ === typeof val) return val;
1988-
return invalidValue(typ, val, key, parent);
1974+
return invalidValue(typ, val, key);
19891975
}
19901976

19911977
function transformUnion(typs, val) {
@@ -1997,17 +1983,17 @@ function transform(val, typ, getProps, key = '', parent = '') {
19971983
return transform(val, typ, getProps);
19981984
} catch (_) {}
19991985
}
2000-
return invalidValue(typs, val, key, parent);
1986+
return invalidValue(typs, val);
20011987
}
20021988

20031989
function transformEnum(cases, val) {
20041990
if (cases.indexOf(val) !== -1) return val;
2005-
return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
1991+
return invalidValue(cases, val);
20061992
}
20071993

20081994
function transformArray(typ, val) {
20091995
// val must be an array with no invalid elements
2010-
if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
1996+
if (!Array.isArray(val)) return invalidValue("array", val);
20111997
return val.map(el => transform(el, typ, getProps));
20121998
}
20131999

@@ -2017,24 +2003,24 @@ function transform(val, typ, getProps, key = '', parent = '') {
20172003
}
20182004
const d = new Date(val);
20192005
if (isNaN(d.valueOf())) {
2020-
return invalidValue(l("Date"), val, key, parent);
2006+
return invalidValue("Date", val);
20212007
}
20222008
return d;
20232009
}
20242010

20252011
function transformObject(props, additional, val) {
20262012
if (val === null || typeof val !== "object" || Array.isArray(val)) {
2027-
return invalidValue(l(ref || "object"), val, key, parent);
2013+
return invalidValue("object", val);
20282014
}
20292015
const result = {};
20302016
Object.getOwnPropertyNames(props).forEach(key => {
20312017
const prop = props[key];
20322018
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
2033-
result[prop.key] = transform(v, prop.typ, getProps, key, ref);
2019+
result[prop.key] = transform(v, prop.typ, getProps, prop.key);
20342020
});
20352021
Object.getOwnPropertyNames(val).forEach(key => {
20362022
if (!Object.prototype.hasOwnProperty.call(props, key)) {
2037-
result[key] = transform(val[key], additional, getProps, key, ref);
2023+
result[key] = transform(val[key], additional, getProps, key);
20382024
}
20392025
});
20402026
return result;
@@ -2043,20 +2029,18 @@ function transform(val, typ, getProps, key = '', parent = '') {
20432029
if (typ === "any") return val;
20442030
if (typ === null) {
20452031
if (val === null) return val;
2046-
return invalidValue(typ, val, key, parent);
2032+
return invalidValue(typ, val);
20472033
}
2048-
if (typ === false) return invalidValue(typ, val, key, parent);
2049-
let ref = undefined;
2034+
if (typ === false) return invalidValue(typ, val);
20502035
while (typeof typ === "object" && typ.ref !== undefined) {
2051-
ref = typ.ref;
20522036
typ = typeMap[typ.ref];
20532037
}
20542038
if (Array.isArray(typ)) return transformEnum(typ, val);
20552039
if (typeof typ === "object") {
20562040
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
20572041
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
20582042
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
2059-
: invalidValue(typ, val, key, parent);
2043+
: invalidValue(typ, val);
20602044
}
20612045
// Numbers can be parsed by Date but shouldn't be.
20622046
if (typ === Date && typeof val !== "number") return transformDate(val);
@@ -2071,10 +2055,6 @@ function uncast(val, typ) {
20712055
return transform(val, typ, jsToJSONProps);
20722056
}
20732057

2074-
function l(typ) {
2075-
return { literal: typ };
2076-
}
2077-
20782058
function a(typ) {
20792059
return { arrayItems: typ };
20802060
}

0 commit comments

Comments
 (0)