CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/decode_devid.py
Views: 1798
1
#!/usr/bin/env python
2
'''
3
decode a device ID, such as used for COMPASS_DEV_ID, INS_ACC_ID etc
4
5
To understand the devtype you should look at the backend headers for
6
the sensor library, such as libraries/AP_Compass/AP_Compass_Backend.h
7
'''
8
9
import sys
10
import optparse
11
12
def num(s):
13
try:
14
return int(s)
15
except ValueError:
16
return int(s, 16)
17
18
19
parser = optparse.OptionParser("decode_devid.py")
20
parser.add_option("-C", "--compass", action='store_true', help='decode compass IDs')
21
parser.add_option("-I", "--imu", action='store_true', help='decode IMU IDs')
22
parser.add_option("-B", "--baro", action='store_true', help='decode barometer IDs')
23
parser.add_option("-A", "--airspeed", action='store_true', help='decode airspeed IDs')
24
25
opts, args = parser.parse_args()
26
27
if len(args) == 0:
28
print("Please supply a device ID")
29
sys.exit(1)
30
31
devid=num(args[0])
32
33
bus_type=devid & 0x07
34
bus=(devid>>3) & 0x1F
35
address=(devid>>8)&0xFF
36
devtype=(devid>>16)
37
38
bustypes = {
39
1: "I2C",
40
2: "SPI",
41
3: "DRONECAN",
42
4: "SITL",
43
5: "MSP",
44
6: "SERIAL",
45
}
46
47
compass_types = {
48
0x01 : "DEVTYPE_HMC5883_OLD",
49
0x07 : "DEVTYPE_HMC5883",
50
0x02 : "DEVTYPE_LSM303D",
51
0x04 : "DEVTYPE_AK8963 ",
52
0x05 : "DEVTYPE_BMM150 ",
53
0x06 : "DEVTYPE_LSM9DS1",
54
0x08 : "DEVTYPE_LIS3MDL",
55
0x09 : "DEVTYPE_AK09916",
56
0x0A : "DEVTYPE_IST8310",
57
0x0B : "DEVTYPE_ICM20948",
58
0x0C : "DEVTYPE_MMC3416",
59
0x0D : "DEVTYPE_QMC5883L",
60
0x0E : "DEVTYPE_MAG3110",
61
0x0F : "DEVTYPE_SITL",
62
0x10 : "DEVTYPE_IST8308",
63
0x11 : "DEVTYPE_RM3100_OLD",
64
0x12 : "DEVTYPE_RM3100",
65
0x13 : "DEVTYPE_MMC5883",
66
0x14 : "DEVTYPE_AK09918",
67
0x15 : "DEVTYPE_AK09915",
68
0x16 : "DEVTYPE_QMC5883P",
69
0x17 : "DEVTYPE_BMM350",
70
0x18 : "DEVTYPE_IIS2MDC",
71
}
72
73
imu_types = {
74
0x09 : "DEVTYPE_BMI160",
75
0x10 : "DEVTYPE_L3G4200D",
76
0x11 : "DEVTYPE_ACC_LSM303D",
77
0x12 : "DEVTYPE_ACC_BMA180",
78
0x13 : "DEVTYPE_ACC_MPU6000",
79
0x16 : "DEVTYPE_ACC_MPU9250",
80
0x17 : "DEVTYPE_ACC_IIS328DQ",
81
0x21 : "DEVTYPE_GYR_MPU6000",
82
0x22 : "DEVTYPE_GYR_L3GD20",
83
0x24 : "DEVTYPE_GYR_MPU9250",
84
0x25 : "DEVTYPE_GYR_I3G4250D",
85
0x26 : "DEVTYPE_GYR_LSM9DS1",
86
0x27 : "DEVTYPE_INS_ICM20789",
87
0x28 : "DEVTYPE_INS_ICM20689",
88
0x29 : "DEVTYPE_INS_BMI055",
89
0x2A : "DEVTYPE_SITL",
90
0x2B : "DEVTYPE_INS_BMI088",
91
0x2C : "DEVTYPE_INS_ICM20948",
92
0x2D : "DEVTYPE_INS_ICM20648",
93
0x2E : "DEVTYPE_INS_ICM20649",
94
0x2F : "DEVTYPE_INS_ICM20602",
95
0x30 : "DEVTYPE_INS_ICM20601",
96
0x31 : "DEVTYPE_INS_ADIS1647x",
97
0x32 : "DEVTYPE_INS_SERIAL",
98
0x33 : "DEVTYPE_INS_ICM40609",
99
0x34 : "DEVTYPE_INS_ICM42688",
100
0x35 : "DEVTYPE_INS_ICM42605",
101
0x36 : "DEVTYPE_INS_ICM40605",
102
0x37 : "DEVTYPE_INS_IIM42652",
103
0x38 : "DEVTYPE_INS_BMI270",
104
0x39 : "DEVTYPE_INS_BMI085",
105
0x3A : "DEVTYPE_INS_ICM42670",
106
0x3B : "DEVTYPE_INS_ICM45686",
107
0x3C : "DEVTYPE_INS_SCHA63T",
108
0x3D : "DEVTYPE_INS_IIM42653",
109
}
110
111
baro_types = {
112
0x01 : "DEVTYPE_BARO_SITL",
113
0x02 : "DEVTYPE_BARO_BMP085",
114
0x03 : "DEVTYPE_BARO_BMP280",
115
0x04 : "DEVTYPE_BARO_BMP388",
116
0x05 : "DEVTYPE_BARO_DPS280",
117
0x06 : "DEVTYPE_BARO_DPS310",
118
0x07 : "DEVTYPE_BARO_FBM320",
119
0x08 : "DEVTYPE_BARO_ICM20789",
120
0x09 : "DEVTYPE_BARO_KELLERLD",
121
0x0A : "DEVTYPE_BARO_LPS2XH",
122
0x0B : "DEVTYPE_BARO_MS5611",
123
0x0C : "DEVTYPE_BARO_SPL06",
124
0x0D : "DEVTYPE_BARO_DRONECAN",
125
0x0E : "DEVTYPE_BARO_MSP",
126
0x0F : "DEVTYPE_BARO_ICP101XX",
127
0x10 : "DEVTYPE_BARO_ICP201XX",
128
0x11 : "DEVTYPE_BARO_MS5607",
129
0x12 : "DEVTYPE_BARO_MS5837",
130
0x13 : "DEVTYPE_BARO_MS5637",
131
0x14 : "DEVTYPE_BARO_BMP390",
132
0x15 : "DEVTYPE_BARO_BMP581",
133
}
134
135
airspeed_types = {
136
0x01 : "DEVTYPE_AIRSPEED_SITL",
137
0x02 : "DEVTYPE_AIRSPEED_MS4525",
138
0x03 : "DEVTYPE_AIRSPEED_MS5525",
139
0x04 : "DEVTYPE_AIRSPEED_DLVR",
140
0x05 : "DEVTYPE_AIRSPEED_MSP",
141
0x06 : "DEVTYPE_AIRSPEED_SDP3X",
142
0x07 : "DEVTYPE_AIRSPEED_DRONECAN",
143
0x08 : "DEVTYPE_AIRSPEED_ANALOG",
144
0x09 : "DEVTYPE_AIRSPEED_NMEA",
145
0x0A : "DEVTYPE_AIRSPEED_ASP5033",
146
}
147
148
decoded_devname = ""
149
150
if opts.compass:
151
decoded_devname = compass_types.get(devtype, "UNKNOWN")
152
153
if opts.imu:
154
decoded_devname = imu_types.get(devtype, "UNKNOWN")
155
156
if opts.baro:
157
decoded_devname = baro_types.get(devtype, "UNKNOWN")
158
159
if opts.airspeed:
160
decoded_devname = airspeed_types.get(devtype, "UNKNOWN")
161
162
if bus_type == 3:
163
#dronecan devtype represents sensor_id
164
print("bus_type:%s(%u) bus:%u address:%u(0x%x) sensor_id:%u(0x%x) %s" % (
165
bustypes.get(bus_type,"UNKNOWN"), bus_type,
166
bus, address, address, devtype-1, devtype-1, decoded_devname))
167
else:
168
print("bus_type:%s(%u) bus:%u address:%u(0x%x) devtype:%u(0x%x) %s" % (
169
bustypes.get(bus_type,"UNKNOWN"), bus_type,
170
bus, address, address, devtype, devtype, decoded_devname))
171
172