Simulator: Added remote host option (#15443)

* Added an option to the Simulator module to connect to remote Gazebo servers.

This is usefull when the Gazebo simulation is running on a different host than the PX4 instance.
For example, we are running instances of PX4 with a companion application in multiple Dockers, for swarming simulations, which then connect to a remote Gazebo server.

A "-t" input argument has been added and can be called from the rcS startup script as: simulator start -t "192.168.178.122" $simulator_tcp_port

* _tcp_remote_ipaddr defaults to nullptr. This way testing against nullptr it can be determined if localhost or remote host is desired by the user.
* Documented the option in usage().

Signed-off-by: Peter Blom <peterblom.mail@gmail.com>
This commit is contained in:
Muesli_Reep
2021-01-10 18:37:37 +01:00
committed by GitHub
parent 763c3b8fda
commit fe7908feb0
3 changed files with 15 additions and 0 deletions
@@ -51,6 +51,7 @@
#include <pthread.h>
#include <sys/socket.h>
#include <termios.h>
#include <arpa/inet.h>
#include <limits>
@@ -673,6 +674,10 @@ void Simulator::run()
_myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
_myaddr.sin_port = htons(_port);
if (_tcp_remote_ipaddr != nullptr) {
_myaddr.sin_addr.s_addr = inet_addr(_tcp_remote_ipaddr);
}
if (_ip == InternetProtocol::UDP) {
if ((_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {