Skip to content
Snippets Groups Projects
Commit af6098b9 authored by Daniel Agar's avatar Daniel Agar Committed by Lorenz Meier
Browse files

uORB print_message add device_id pretty print

parent 7cc0e69f
No related branches found
No related tags found
No related merge requests found
......@@ -69,6 +69,7 @@ topic_fields = ["%s %s" % (convert_type(field.type), field.name) for field in so
#include <px4_defines.h>
#include <uORB/topics/@(topic_name).h>
#include <drivers/drv_hrt.h>
#include <lib/drivers/device/Device.hpp>
@# join all msg files in one line e.g: "float[3] position;float[3] velocity;bool armed"
@# This is used for the logger
......
......@@ -250,6 +250,10 @@ def print_field(field):
print("if (message.timestamp != 0) {\n\t\tPX4_INFO_RAW(\"\\t" + field.name + \
": " + c_type + " (%.6f seconds ago)\\n\", " + field_name + \
", hrt_elapsed_time(&message.timestamp) / 1e6);\n\t} else {\n\t\tPX4_INFO_RAW(\"\\n\");\n\t}" )
elif field.name == 'device_id':
print("char device_id_buffer[80];")
print("device::Device::device_id_print_buffer(device_id_buffer, sizeof(device_id_buffer), message.device_id);")
print("PX4_INFO_RAW(\"\\tdevice_id: %d (%s) \\n\", message.device_id, device_id_buffer);" )
else:
print("PX4_INFO_RAW(\"\\t" + field.name + ": " + c_type + "\\n\", " + field_name + ");" )
......
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment