AP_HAL_SITL: sim: namespace for specifying SITL devices from cmdline

This commit is contained in:
Peter Barker 2017-08-10 20:23:11 +10:00 committed by Randy Mackay
parent a5a36c04d1
commit 1151d76345
3 changed files with 17 additions and 0 deletions

View File

@ -191,6 +191,12 @@ void SITL_State::wait_clock(uint64_t wait_time_usec)
}
}
#define streq(a, b) (!strcmp(a, b))
int SITL_State::sim_fd(const char *name, const char *arg)
{
AP_HAL::panic("unknown simulated device: %s", name);
}
#ifndef HIL_MODE
/*
check for a SITL RC input packet

View File

@ -52,6 +52,10 @@ public:
return _base_port;
}
// create a file desciptor attached to a virtual device; type of
// device is given by name parameter
int sim_fd(const char *name, const char *arg);
bool use_rtscts(void) const {
return _use_rtscts;
}

View File

@ -67,6 +67,7 @@ void UARTDriver::begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace)
tcp:0:wait // tcp listen on use base_port + 0
tcpclient:192.168.2.15:5762
uart:/dev/ttyUSB0:57600
sim:ParticleSensor_SDS021:
*/
char *saveptr = nullptr;
char *s = strdup(path);
@ -89,6 +90,12 @@ void UARTDriver::begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace)
_uart_path = strdup(args1);
_uart_baudrate = baudrate;
_uart_start_connection();
} else if (strcmp(devtype, "sim") == 0) {
::printf("SIM connection %s:%s\n", args1, args2);
if (!_connected) {
_connected = true;
_fd = _sitlState->sim_fd(args1, args2);
}
} else {
AP_HAL::panic("Invalid device path: %s", path);
}