simulator: fix TCP on Cygwin-Windows

It turns out that `sendto` does not work for TCP on Cygwin-Windows,
instead we need to use `send`. This required some refactoring since we
need to have the internet protocol and the port stored as a member
variable.

This should fix that lockstep SITL simulation was not working on
Windows.
This commit is contained in:
Julian
2018-12-26 13:02:12 +01:00
committed by Julian Oes
parent 2a7fe22a04
commit 3e87013936
3 changed files with 44 additions and 24 deletions
+16 -9
View File
@@ -149,29 +149,26 @@ int Simulator::start(int argc, char *argv[])
if (_instance) {
drv_led_start();
InternetProtocol ip = InternetProtocol::UDP;
unsigned port = 14560;
if (argc == 5 && strcmp(argv[3], "-u") == 0) {
ip = InternetProtocol::UDP;
port = atoi(argv[4]);
_instance->set_ip(InternetProtocol::UDP);
_instance->set_port(atoi(argv[4]));
}
if (argc == 5 && strcmp(argv[3], "-c") == 0) {
ip = InternetProtocol::TCP;
port = atoi(argv[4]);
_instance->set_ip(InternetProtocol::TCP);
_instance->set_port(atoi(argv[4]));
}
if (argv[2][1] == 's') {
_instance->initializeSensorData();
#ifndef __PX4_QURT
// Update sensor data
_instance->pollForMAVLinkMessages(false, ip, port);
_instance->pollForMAVLinkMessages(false);
#endif
} else if (argv[2][1] == 'p') {
// Update sensor data
_instance->pollForMAVLinkMessages(true, ip, port);
_instance->pollForMAVLinkMessages(true);
} else {
_instance->initializeSensorData();
@@ -186,6 +183,16 @@ int Simulator::start(int argc, char *argv[])
}
}
void Simulator::set_ip(InternetProtocol ip)
{
_ip = ip;
}
void Simulator::set_port(unsigned port)
{
_port = port;
}
static void usage()
{
PX4_WARN("Usage: simulator {start -[spt] [-u udp_port / -c tcp_port] |stop}");