mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 18:27:05 +08:00
listener: use PX4_INFO_RAW instead of printf
Ensures that clients will get the output of the listener.
This commit is contained in:
@@ -65,7 +65,7 @@ topic_fields = ["uint64_t timestamp"]+["%s %s" % (convert_type(field.type), fiel
|
|||||||
}@
|
}@
|
||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <cstdio>
|
#include <px4_log.h>
|
||||||
#include <px4_defines.h>
|
#include <px4_defines.h>
|
||||||
#include <uORB/topics/@(topic_name).h>
|
#include <uORB/topics/@(topic_name).h>
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
@@ -80,14 +80,14 @@ ORB_DEFINE(@multi_topic, struct @uorb_struct, @(struct_size-padding_end_size), _
|
|||||||
|
|
||||||
void print_message(const @uorb_struct& message)
|
void print_message(const @uorb_struct& message)
|
||||||
{
|
{
|
||||||
printf(" @(uorb_struct)\n");
|
PX4_INFO_RAW(" @(uorb_struct)\n");
|
||||||
printf("\ttimestamp: %" PRIu64, message.timestamp);
|
PX4_INFO_RAW("\ttimestamp: %" PRIu64, message.timestamp);
|
||||||
if (message.timestamp != 0) {
|
if (message.timestamp != 0) {
|
||||||
printf(" (%.6f seconds ago)\n", hrt_elapsed_time(&message.timestamp) / 1e6);
|
PX4_INFO_RAW(" (%.6f seconds ago)\n", hrt_elapsed_time(&message.timestamp) / 1e6);
|
||||||
} else {
|
} else {
|
||||||
printf("\n");
|
PX4_INFO_RAW("\n");
|
||||||
}
|
}
|
||||||
@[for field in sorted_fields]@
|
@[for field in sorted_fields]@
|
||||||
@( print_field(field) )@
|
@( print_field(field) )@
|
||||||
@[end for]@
|
@[end for]@
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ def print_field(field):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
for i in range(array_length):
|
for i in range(array_length):
|
||||||
print("printf(\"\\t" + field.type + " " + field.name + "[" + str(i) + "]\");")
|
print("PX4_INFO_RAW(\"\\t" + field.type + " " + field.name + "[" + str(i) + "]\");")
|
||||||
print(" print_message(message." + field.name + "[" + str(i) + "]);")
|
print(" print_message(message." + field.name + "[" + str(i) + "]);")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -242,11 +242,11 @@ def print_field(field):
|
|||||||
field_name = "(" + field_name + " ? \"True\" : \"False\")"
|
field_name = "(" + field_name + " ? \"True\" : \"False\")"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("printf(\"\\n\\t" + field.name + "\");")
|
print("PX4_INFO_RAW(\"\\n\\t" + field.name + "\");")
|
||||||
print("\tprint_message(message."+ field.name + ");")
|
print("\tprint_message(message."+ field.name + ");")
|
||||||
return
|
return
|
||||||
|
|
||||||
print("printf(\"\\t" + field.name + ": " + c_type + "\\n\", " + field_name + ");" )
|
print("PX4_INFO_RAW(\"\\t" + field.name + ": " + c_type + "\\n\", " + field_name + ");" )
|
||||||
|
|
||||||
|
|
||||||
def print_field_def(field):
|
def print_field_def(field):
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ print("""
|
|||||||
#include <px4_middleware.h>
|
#include <px4_middleware.h>
|
||||||
#include <px4_app.h>
|
#include <px4_app.h>
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
|
#include <px4_log.h>
|
||||||
#include <uORB/uORB.h>
|
#include <uORB/uORB.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -125,7 +126,7 @@ for index, (m, t) in enumerate(zip(messages, topics)):
|
|||||||
print("\t\tlistener<%s_s>(ORB_ID(%s), num_msgs, topic_instance, topic_interval);" % (m, t))
|
print("\t\tlistener<%s_s>(ORB_ID(%s), num_msgs, topic_instance, topic_interval);" % (m, t))
|
||||||
|
|
||||||
print("\t} else {")
|
print("\t} else {")
|
||||||
print("\t\t printf(\" Topic did not match any known topics\\n\");")
|
print("\t\t PX4_INFO_RAW(\" Topic did not match any known topics\\n\");")
|
||||||
print("\t}")
|
print("\t}")
|
||||||
|
|
||||||
print("}\n")
|
print("}\n")
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include <px4_middleware.h>
|
#include <px4_middleware.h>
|
||||||
#include <px4_app.h>
|
#include <px4_app.h>
|
||||||
#include <px4_config.h>
|
#include <px4_config.h>
|
||||||
|
#include <px4_log.h>
|
||||||
#include <uORB/uORB.h>
|
#include <uORB/uORB.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -54,7 +55,7 @@ template <typename T>
|
|||||||
void listener(const orb_id_t &id, unsigned num_msgs, unsigned topic_instance, unsigned topic_interval)
|
void listener(const orb_id_t &id, unsigned num_msgs, unsigned topic_instance, unsigned topic_interval)
|
||||||
{
|
{
|
||||||
if (orb_exists(id, topic_instance) != 0) {
|
if (orb_exists(id, topic_instance) != 0) {
|
||||||
printf("never published\n");
|
PX4_INFO_RAW("never published\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ void listener(const orb_id_t &id, unsigned num_msgs, unsigned topic_instance, un
|
|||||||
start_time = hrt_absolute_time();
|
start_time = hrt_absolute_time();
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
printf("\nTOPIC: %s instance %d #%d\n", id->o_name, topic_instance, i);
|
PX4_INFO_RAW("\nTOPIC: %s instance %d #%d\n", id->o_name, topic_instance, i);
|
||||||
|
|
||||||
T container;
|
T container;
|
||||||
|
|
||||||
@@ -92,7 +93,7 @@ void listener(const orb_id_t &id, unsigned num_msgs, unsigned topic_instance, un
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (hrt_elapsed_time(&start_time) > 2 * 1000 * 1000) {
|
if (hrt_elapsed_time(&start_time) > 2 * 1000 * 1000) {
|
||||||
printf("Waited for 2 seconds without a message. Giving up.\n");
|
PX4_INFO_RAW("Waited for 2 seconds without a message. Giving up.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user