From 416feea9e4acbf4dd4a1f618229613aedb001bf0 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Tue, 27 Mar 2018 12:19:04 -0400 Subject: [PATCH] uORB print_message cleanup - indent field print with tabs instead of spaces - print a newline before printing a nested field - cmake add generator dependencies --- msg/CMakeLists.txt | 10 ++++++++-- msg/templates/uorb/msg.cpp.template | 13 +++++++++---- msg/tools/px_generate_uorb_topic_helper.py | 6 +++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/msg/CMakeLists.txt b/msg/CMakeLists.txt index 63abeaa5ef59..ba1405722ffc 100644 --- a/msg/CMakeLists.txt +++ b/msg/CMakeLists.txt @@ -165,7 +165,10 @@ add_custom_command(OUTPUT ${uorb_headers} -e templates/uorb -t ${CMAKE_CURRENT_BINARY_DIR}/tmp/headers -q - DEPENDS ${msg_files} templates/uorb/msg.h.template + DEPENDS + ${msg_files} + templates/uorb/msg.h.template + tools/px_generate_uorb_topic_files.py COMMENT "Generating uORB topic headers" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM @@ -182,7 +185,10 @@ add_custom_command(OUTPUT ${uorb_sources} -e templates/uorb -t ${CMAKE_CURRENT_BINARY_DIR}/tmp/sources -q - DEPENDS ${msg_files} templates/uorb/msg.cpp.template + DEPENDS + ${msg_files} + templates/uorb/msg.cpp.template + tools/px_generate_uorb_topic_files.py COMMENT "Generating uORB topic sources" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM diff --git a/msg/templates/uorb/msg.cpp.template b/msg/templates/uorb/msg.cpp.template index 2d92725be364..11764637a4bd 100644 --- a/msg/templates/uorb/msg.cpp.template +++ b/msg/templates/uorb/msg.cpp.template @@ -80,9 +80,14 @@ ORB_DEFINE(@multi_topic, struct @uorb_struct, @(struct_size-padding_end_size), _ void print_message(const @uorb_struct& message) { - printf(" @(uorb_struct)\n"); - printf("\ttimestamp: %" PRIu64 " (%.6f seconds ago)\n", message.timestamp, hrt_elapsed_time(&message.timestamp) / 1e6); + printf(" @(uorb_struct)\n"); + printf("\ttimestamp: %" PRIu64, message.timestamp); + if (message.timestamp != 0) { + printf(" (%.6f seconds ago)\n", hrt_elapsed_time(&message.timestamp) / 1e6); + } else { + printf("\n"); + } @[for field in sorted_fields]@ - @( print_field(field) ) -@[end for] + @( print_field(field) )@ +@[end for]@ } \ No newline at end of file diff --git a/msg/tools/px_generate_uorb_topic_helper.py b/msg/tools/px_generate_uorb_topic_helper.py index f810c87d8db2..2c0a4c79961f 100644 --- a/msg/tools/px_generate_uorb_topic_helper.py +++ b/msg/tools/px_generate_uorb_topic_helper.py @@ -205,7 +205,7 @@ def print_field(field): else: for i in range(array_length): - print("printf(\" " + field.type + " " + field.name + "[" + str(i) + "]\");") + print("printf(\"\\t" + field.type + " " + field.name + "[" + str(i) + "]\");") print(" print_message(message." + field.name + "[" + str(i) + "]);") return @@ -236,11 +236,11 @@ def print_field(field): field_name = "(double)" + field_name else: - print("printf(\" " + field.name + "\");") + print("printf(\"\\n\\t" + field.name + "\");") print("\tprint_message(message."+ field.name + ");") return - print("printf(\"\t" + field.name + ": " + c_type + "\\n\", " + field_name + ");" ) + print("printf(\"\\t" + field.name + ": " + c_type + "\\n\", " + field_name + ");" ) def print_field_def(field):