Skip to content

Commit

Permalink
uORB print_message cleanup
Browse files Browse the repository at this point in the history
 - indent field print with tabs instead of spaces
 - print a newline before printing a nested field
 - cmake add generator dependencies
  • Loading branch information
dagar committed Mar 28, 2018
1 parent c4c4441 commit 416feea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 8 additions & 2 deletions msg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions msg/templates/uorb/msg.cpp.template
Original file line number Diff line number Diff line change
Expand Up @@ -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]@
}
6 changes: 3 additions & 3 deletions msg/tools/px_generate_uorb_topic_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 416feea

Please sign in to comment.