uORB print_message add device_id pretty print

This commit is contained in:
Daniel Agar
2018-09-02 21:13:10 +02:00
committed by Lorenz Meier
parent 7cc0e69fcd
commit af6098b9ea
3 changed files with 44 additions and 0 deletions
+39
View File
@@ -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 */