From 73578a593fe4d41ca98b6ae1d588743dc091079a Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Sun, 9 Dec 2018 12:19:05 +0100 Subject: [PATCH] simulator: bring -t argument back The -t argument had been deleted because I didn't realize that it was actually being used. Therefore, this brings it back and we now use -c for TCP. --- ROMFS/px4fmu_common/init.d-posix/rcS | 2 +- src/modules/simulator/simulator.cpp | 54 ++++++++++++++++------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/ROMFS/px4fmu_common/init.d-posix/rcS b/ROMFS/px4fmu_common/init.d-posix/rcS index 81d458ca62..3e87dece35 100644 --- a/ROMFS/px4fmu_common/init.d-posix/rcS +++ b/ROMFS/px4fmu_common/init.d-posix/rcS @@ -182,7 +182,7 @@ sh "$autostart_file" dataman start replay tryapplyparams -simulator start -s -t $simulator_tcp_port +simulator start -s -c $simulator_tcp_port tone_alarm start gyrosim start accelsim start diff --git a/src/modules/simulator/simulator.cpp b/src/modules/simulator/simulator.cpp index 339c7f09f6..51f897af8b 100644 --- a/src/modules/simulator/simulator.cpp +++ b/src/modules/simulator/simulator.cpp @@ -157,7 +157,7 @@ int Simulator::start(int argc, char *argv[]) port = atoi(argv[4]); } - if (argc == 5 && strcmp(argv[3], "-t") == 0) { + if (argc == 5 && strcmp(argv[3], "-c") == 0) { ip = InternetProtocol::TCP; port = atoi(argv[4]); } @@ -175,6 +175,7 @@ int Simulator::start(int argc, char *argv[]) } else { _instance->initializeSensorData(); + _instance->_initialized = true; } return 0; @@ -187,11 +188,12 @@ int Simulator::start(int argc, char *argv[]) static void usage() { - PX4_WARN("Usage: simulator {start -[sp] [-u udp_port / -t tcp_port] |stop}"); + PX4_WARN("Usage: simulator {start -[spt] [-u udp_port / -c tcp_port] |stop}"); PX4_WARN("Simulate raw sensors: simulator start -s"); PX4_WARN("Publish sensors combined: simulator start -p"); PX4_WARN("Connect using UDP: simulator start -u udp_port"); - PX4_WARN("Connect using TCP: simulator start -t tcp_port"); + PX4_WARN("Connect using TCP: simulator start -c tcp_port"); + PX4_WARN("Dummy unit test data: simulator start -t"); } __BEGIN_DECLS @@ -202,27 +204,35 @@ extern "C" { int simulator_main(int argc, char *argv[]) { - if (argc == 5 && strcmp(argv[1], "start") == 0) { + if (argc > 2 && strcmp(argv[1], "start") == 0) { + if (strcmp(argv[2], "-s") == 0 || + strcmp(argv[2], "-p") == 0 || + strcmp(argv[2], "-t") == 0) { - if (g_sim_task >= 0) { - PX4_WARN("Simulator already started"); - return 0; - } - - g_sim_task = px4_task_spawn_cmd("simulator", - SCHED_DEFAULT, - SCHED_PRIORITY_DEFAULT, - 1500, - Simulator::start, - argv); - - while (true) { - if (Simulator::getInstance() && Simulator::getInstance()->isInitialized()) { - break; - - } else { - system_sleep(1); + if (g_sim_task >= 0) { + PX4_WARN("Simulator already started"); + return 0; } + + g_sim_task = px4_task_spawn_cmd("simulator", + SCHED_DEFAULT, + SCHED_PRIORITY_DEFAULT, + 1500, + Simulator::start, + argv); + + while (true) { + if (Simulator::getInstance() && Simulator::getInstance()->isInitialized()) { + break; + + } else { + system_sleep(1); + } + } + + } else { + usage(); + return 1; } } else if (argc == 2 && strcmp(argv[1], "stop") == 0) {