forked from Archive/PX4-Autopilot
generate_listener.py: add a timeout of 2 seconds
abort if within 2s there is no new message published
This commit is contained in:
parent
1269dfbc43
commit
9259406a29
|
@ -106,6 +106,7 @@ print("""
|
|||
* Tool for listening to topics when running flight stack on linux.
|
||||
*/
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <px4_middleware.h>
|
||||
#include <px4_app.h>
|
||||
#include <px4_config.h>
|
||||
|
@ -125,6 +126,14 @@ print("""
|
|||
#define PRId64 "lld"
|
||||
#endif
|
||||
|
||||
static bool check_timeout(const hrt_abstime& time) {
|
||||
if (hrt_elapsed_time(&time) > 2*1000*1000) {
|
||||
printf("Waited for 2 seconds without a message. Giving up.\\n");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
""")
|
||||
for m in messages:
|
||||
print("#include <uORB/topics/%s.h>" % m)
|
||||
|
@ -155,10 +164,12 @@ for index,m in enumerate(messages[1:]):
|
|||
print("\t\tmemset(&container, 0, sizeof(container));")
|
||||
print("\t\tbool updated;")
|
||||
print("\t\tunsigned i = 0;")
|
||||
print("\t\thrt_abstime start_time = hrt_absolute_time();")
|
||||
print("\t\twhile(i < num_msgs) {")
|
||||
print("\t\t\torb_check(sub,&updated);")
|
||||
print("\t\t\tif (i == 0) { updated = true; } else { usleep(500); }")
|
||||
print("\t\t\tif (updated) {")
|
||||
print("\t\t\tstart_time = hrt_absolute_time();")
|
||||
print("\t\t\ti++;")
|
||||
print("\t\t\tprintf(\"\\nTOPIC: %s #%%d\\n\", i);" % m)
|
||||
print("\t\t\torb_copy(ID,sub,&container);")
|
||||
|
@ -203,6 +214,10 @@ for index,m in enumerate(messages[1:]):
|
|||
print("\t\t\tprintf(\"%s: %%u\\n\",(unsigned)container.%s);" % (item[1], item[1]))
|
||||
elif item[0] == "bool":
|
||||
print("\t\t\tprintf(\"%s: %%s\\n\",container.%s ? \"True\" : \"False\");" % (item[1], item[1]))
|
||||
print("\t\t\t} else {")
|
||||
print("\t\t\t\tif (check_timeout(start_time)) {")
|
||||
print("\t\t\t\t\tbreak;")
|
||||
print("\t\t\t\t}")
|
||||
print("\t\t\t}")
|
||||
print("\t\t}")
|
||||
print("\t} else {")
|
||||
|
|
Loading…
Reference in New Issue