mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 22:33:37 +08:00
uORB print_message add device_id pretty print
This commit is contained in:
committed by
Lorenz Meier
parent
7cc0e69fcd
commit
af6098b9ea
@@ -148,6 +148,24 @@ public:
|
||||
*/
|
||||
DeviceBusType get_device_bus_type() const { return _device_id.devid_s.bus_type; }
|
||||
|
||||
static const char *get_device_bus_string(DeviceBusType bus)
|
||||
{
|
||||
switch (bus) {
|
||||
case DeviceBusType_I2C:
|
||||
return "I2C";
|
||||
|
||||
case DeviceBusType_SPI:
|
||||
return "SPI";
|
||||
|
||||
case DeviceBusType_UAVCAN:
|
||||
return "UAVCAN";
|
||||
|
||||
case DeviceBusType_UNKNOWN:
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bus address of the device.
|
||||
*
|
||||
@@ -184,6 +202,27 @@ public:
|
||||
uint32_t devid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Print decoded device id string to a buffer.
|
||||
*
|
||||
* @param buffer buffer to write to
|
||||
* @param length buffer length
|
||||
* @param id The device id.
|
||||
* @param return number of bytes written
|
||||
*/
|
||||
static int device_id_print_buffer(char *buffer, int length, uint32_t id)
|
||||
{
|
||||
DeviceId dev_id;
|
||||
dev_id.devid = id;
|
||||
|
||||
int num_written = snprintf(buffer, length, "Type: 0x%02X, %s:%d (0x%02X)", dev_id.devid_s.devtype,
|
||||
get_device_bus_string(dev_id.devid_s.bus_type), dev_id.devid_s.bus, dev_id.devid_s.address);
|
||||
|
||||
buffer[length - 1] = 0; // ensure 0-termination
|
||||
|
||||
return num_written;
|
||||
}
|
||||
|
||||
protected:
|
||||
union DeviceId _device_id; /**< device identifier information */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user