QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4SensorDevice.cc
Go to the documentation of this file.
1#include "PX4SensorDevice.h"
2
3#include <string_view>
4
5#include <QtCore/QCoreApplication>
6
7namespace {
8
9struct SensorDeviceType
10{
11 quint8 type;
12 std::string_view name;
13};
14
15// DroneCAN sensors have no entry, they show as the bus
16constexpr SensorDeviceType kSensorDeviceTypes[] = {
17 {0x01, "HMC5883"}, {0x03, "MAGSIM"}, {0x04, "AK8963"}, {0x05, "LIS3MDL"}, {0x06, "IST8310"},
18 {0x07, "RM3100"}, {0x08, "QMC5883L"}, {0x09, "AK09916"}, {0x0A, "VCM1193L"}, {0x0B, "IST8308"},
19 {0x0D, "MMC5983MA"}, {0x0E, "IIS2MDC"}, {0x0F, "QMC5883P"}, {0x10, "AF9838"}, {0x11, "LSM303D"},
20 {0x12, "LSM6DSV"}, {0x14, "SIM"}, {0x15, "SIM"}, {0x21, "MPU6000"}, {0x22, "L3GD20"},
21 {0x24, "MPU9250"}, {0x25, "ICM20649"}, {0x26, "ICM42688P"}, {0x27, "ICM40609D"}, {0x28, "ICM20948"},
22 {0x29, "ICM42605"}, {0x2A, "ICM42670P"}, {0x2B, "IIM42652"}, {0x2C, "IAM20680HP"}, {0x2D, "ICM42686P"},
23 {0x2E, "IIM42653"}, {0x33, "MPU6050"}, {0x34, "ICM45686"}, {0x35, "MPU6050"}, {0x36, "MPU6500"},
24 {0x37, "BMI270"}, {0x38, "ICM20602"}, {0x3A, "ICM20608G"}, {0x3C, "ICM20689"}, {0x3D, "MS5611"},
25 {0x3E, "MS5607"}, {0x3F, "BMP280"}, {0x40, "LPS25H"}, {0x41, "BMI055"}, {0x42, "BMI055"},
26 {0x43, "BMM150"}, {0x44, "LSM9DS1"}, {0x45, "LSM9DS1"}, {0x46, "ETS3"}, {0x47, "MS4515"},
27 {0x48, "MS4525DO"}, {0x49, "MS5525DSO"}, {0x4A, "SDP31"}, {0x4B, "SDP32"}, {0x4C, "SDP33"},
28 {0x4D, "TCBP001TA"}, {0x4E, "MS5837"}, {0x4F, "SPL06"}, {0x50, "LPS33HW"}, {0x51, "MPL3115A2"},
29 {0x52, "FXOS8701C"}, {0x54, "FXAS2100C"}, {0x57, "ADIS16448"}, {0x58, "ADIS16470"}, {0x59, "ADIS16477"},
30 {0x5A, "ADIS16507"}, {0x5B, "SCH16T"}, {0x5C, "ADIS16607"}, {0x5D, "ADIS1650X"}, {0x5E, "ADIS1657X"},
31 {0x5F, "MPC2520"}, {0x60, "LPS22HB"}, {0x61, "LSM303AGR"}, {0x62, "LSM303AGR"}, {0x63, "ADIS16497"},
32 {0x65, "BAROSIM"}, {0x66, "BMI088"}, {0x67, "BMP388"}, {0x68, "DPS310"}, {0x6A, "BMI088"},
33 {0x6C, "BMI085"}, {0x6D, "BMI085"}, {0x6E, "BMP390"}, {0x6F, "BMP581"}, {0xB7, "ICP101XX"},
34 {0xB8, "ICP201XX"}, {0xE4, "ASP5033"}, {0xE5, "BMM350"}, {0xE6, "AUAV"}, {0xE7, "AUAV"},
35 {0xE8, "SPA06"}, {0xF2, "AK09940A"},
36};
37
38// Layout of the firmware's DeviceStructure bitfield
39constexpr quint32 kBusTypeMask = 0x7;
40constexpr int kDeviceTypeShift = 16;
41constexpr quint32 kDeviceTypeMask = 0xFF;
42
43enum SensorBusType : quint32
44{
45 SensorBusUnknown = 0,
46 SensorBusI2c = 1,
47 SensorBusSpi = 2,
48 SensorBusDroneCan = 3,
49 SensorBusSimulation = 4,
50 SensorBusSerial = 5,
51 SensorBusMavlink = 6,
52};
53
54quint8 sensorDeviceType(quint32 deviceId)
55{
56 return static_cast<quint8>((deviceId >> kDeviceTypeShift) & kDeviceTypeMask);
57}
58
59} // namespace
60
61QString PX4SensorDevice::name(quint32 deviceId)
62{
63 const quint8 type = sensorDeviceType(deviceId);
64 for (const SensorDeviceType& entry : kSensorDeviceTypes) {
65 if (entry.type == type) {
66 return QString::fromLatin1(entry.name.data(), static_cast<qsizetype>(entry.name.size()));
67 }
68 }
69 return QString();
70}
71
72QString PX4SensorDevice::busName(quint32 deviceId)
73{
74 switch (deviceId & kBusTypeMask) {
75 case SensorBusI2c:
76 return QStringLiteral("I2C");
77 case SensorBusSpi:
78 return QStringLiteral("SPI");
79 case SensorBusDroneCan:
80 return QStringLiteral("DroneCAN");
81 case SensorBusSimulation:
82 return QCoreApplication::translate("PX4SensorDevice", "Simulation");
83 case SensorBusSerial:
84 return QStringLiteral("Serial");
85 case SensorBusMavlink:
86 return QStringLiteral("MAVLink");
87 default:
88 return QString();
89 }
90}
91
92QString PX4SensorDevice::description(quint32 deviceId)
93{
94 if (deviceId == 0) {
95 return QString();
96 }
97
98 const QString chip = name(deviceId);
99 const QString bus = busName(deviceId);
100 if (chip.isEmpty() && bus.isEmpty()) {
101 return QStringLiteral("0x%1").arg(deviceId, 8, 16, QLatin1Char('0'));
102 }
103 if (chip.isEmpty()) {
104 return bus;
105 }
106 return bus.isEmpty() ? chip : QStringLiteral("%1 · %2").arg(chip, bus);
107}
static QString busName(quint32 deviceId)
Bus the sensor is on ("SPI", "I2C", "DroneCAN" ...), or an empty string when unknown.
static QString description(quint32 deviceId)
Chip name and bus for display, such as "ICM42688P · SPI". Empty for the unset device ID 0.
static QString name(quint32 deviceId)
Sensor chip name, or an empty string when the device type is not known.