34 #include "microRTPS_transport.h" 43 #include <px4_platform_common/px4_config.h> 44 #include <px4_platform_common/getopt.h> 45 #include <px4_platform_common/cli.h> 46 #include <px4_platform_common/module.h> 47 #include <px4_platform_common/posix.h> 48 #include <px4_platform_common/tasks.h> 49 #include <px4_platform_common/time.h> 60 PRINT_MODULE_USAGE_NAME(
"micrortps_client",
"communication");
61 PRINT_MODULE_USAGE_COMMAND(
"start");
63 PRINT_MODULE_USAGE_PARAM_STRING(
't',
"UART",
"UART|UDP",
"Transport protocol",
true);
64 PRINT_MODULE_USAGE_PARAM_STRING(
'd',
"/dev/ttyACM0",
"<file:dev>",
"Select Serial Device",
true);
65 PRINT_MODULE_USAGE_PARAM_INT(
'b', 460800, 9600, 3000000,
"Baudrate (can also be p:<param_name>)",
true);
66 PRINT_MODULE_USAGE_PARAM_INT(
'p', -1, 1, 1000,
"Poll timeout for UART in ms",
true);
67 PRINT_MODULE_USAGE_PARAM_INT(
'l', 10000, -1, 100000,
"Limit number of iterations until the program exits (-1=infinite)",
69 PRINT_MODULE_USAGE_PARAM_INT(
'w', 1, 1, 1000,
"Time in ms for which each iteration sleeps",
true);
70 PRINT_MODULE_USAGE_PARAM_INT(
'r', 2019, 0, 65536,
"Select UDP Network Port for receiving (local)",
true);
71 PRINT_MODULE_USAGE_PARAM_INT(
's', 2020, 0, 65536,
"Select UDP Network Port for sending (remote)",
true);
72 PRINT_MODULE_USAGE_PARAM_STRING(
'i',
"127.0.0.1",
"<x.x.x.x>",
"Select IP address (remote)",
true);
74 PRINT_MODULE_USAGE_COMMAND(
"stop");
75 PRINT_MODULE_USAGE_COMMAND(
"status");
82 const char *myoptarg =
nullptr;
84 while ((ch = px4_getopt(argc, argv,
"t:d:l:w:b:p:r:s:i:", &myoptind, &myoptarg)) != EOF) {
90 case 'd':
if (
nullptr != myoptarg) strcpy(
_options.
device, myoptarg);
break;
92 case 'l':
_options.
loops = strtol(myoptarg,
nullptr, 10);
break;
102 case 'i':
if (
nullptr != myoptarg) strcpy(
_options.
ip, myoptarg);
break;
112 PX4_ERR(
"poll timeout too low, using 1 ms");
121 PX4_INFO(
"EXITING...");
129 PX4_INFO(
"UART transport: device: %s; baudrate: %d; sleep: %dms; poll: %dms",
136 PX4_INFO(
"UDP transport: ip address: %s; recv port: %u; send port: %u; sleep: %dms",
143 PX4_INFO(
"EXITING...");
148 PX4_INFO(
"EXITING...");
153 struct timespec begin;
157 uint64_t total_read = 0, received = 0;
163 px4_clock_gettime(CLOCK_REALTIME, &end);
165 double elapsed_secs =
static_cast<double>(end.tv_sec - begin.tv_sec + (end.tv_nsec - begin.tv_nsec) / 1e9);
167 PX4_INFO(
"RECEIVED: %" PRIu64
" messages in %d LOOPS, %" PRIu64
" bytes in %.03f seconds - %.02fKB/s",
168 received, loop, total_read, elapsed_secs, static_cast<double>(total_read / (1e3 * elapsed_secs)));
174 PX4_INFO(
"Stopped!");
190 if (!strcmp(argv[1],
"start")) {
192 PX4_INFO(
"Already running");
198 SCHED_PRIORITY_DEFAULT,
201 (
char *
const *)argv);
204 PX4_WARN(
"Could not start task");
212 if (!strcmp(argv[1],
"status")) {
214 PX4_INFO(
"Not running");
223 if (!strcmp(argv[1],
"stop")) {
225 PX4_INFO(
"Not running");
static int micrortps_start(int argc, char *argv[])
Transport_node * transport_node
void micrortps_start_topics(struct timespec &begin, uint64_t &total_read, uint64_t &received, int &loop)
static int parse_options(int argc, char *argv[])
static void usage(const char *name)
__EXPORT int micrortps_client_main(int argc, char *argv[])