mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-30 06:00:36 +08:00
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:
@@ -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}");
|
||||
|
||||
Reference in New Issue
Block a user