From 1151d7634595b902857187a6f461b02fae1655c7 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 10 Aug 2017 20:23:11 +1000 Subject: [PATCH] AP_HAL_SITL: sim: namespace for specifying SITL devices from cmdline --- libraries/AP_HAL_SITL/SITL_State.cpp | 6 ++++++ libraries/AP_HAL_SITL/SITL_State.h | 4 ++++ libraries/AP_HAL_SITL/UARTDriver.cpp | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/libraries/AP_HAL_SITL/SITL_State.cpp b/libraries/AP_HAL_SITL/SITL_State.cpp index a2fe9d3d54..051ac0147b 100644 --- a/libraries/AP_HAL_SITL/SITL_State.cpp +++ b/libraries/AP_HAL_SITL/SITL_State.cpp @@ -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 diff --git a/libraries/AP_HAL_SITL/SITL_State.h b/libraries/AP_HAL_SITL/SITL_State.h index 89afe74b2e..3f6400b194 100644 --- a/libraries/AP_HAL_SITL/SITL_State.h +++ b/libraries/AP_HAL_SITL/SITL_State.h @@ -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; } diff --git a/libraries/AP_HAL_SITL/UARTDriver.cpp b/libraries/AP_HAL_SITL/UARTDriver.cpp index 918a7075d4..3dbc11b9bd 100644 --- a/libraries/AP_HAL_SITL/UARTDriver.cpp +++ b/libraries/AP_HAL_SITL/UARTDriver.cpp @@ -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); }