diff --git a/libraries/AP_HAL_Linux/UARTDriver.cpp b/libraries/AP_HAL_Linux/UARTDriver.cpp index 600abda93f..c47825290e 100644 --- a/libraries/AP_HAL_Linux/UARTDriver.cpp +++ b/libraries/AP_HAL_Linux/UARTDriver.cpp @@ -28,6 +28,7 @@ #include "UDPDevice.h" #include "ConsoleDevice.h" #include "TCPClientDevice.h" +#include "TCPServerDevice.h" extern const AP_HAL::HAL& hal; @@ -71,24 +72,22 @@ void LinuxUARTDriver::begin(uint32_t b, uint16_t rxS, uint16_t txS) if (device_path == NULL) { return; } - - switch (_parseDevicePath(device_path)){ + + switch (_parseDevicePath(device_path)) { case DEVICE_TCP: { - _device = new TCPClientDevice(_ip, _base_port); - _device->open(); - _connected = false; + _tcp_start_connection(); break; - } + } case DEVICE_UDP: { _udp_start_connection(); _flow_control = FLOW_CONTROL_ENABLE; break; - } + } - case DEVICE_SERIAL: + case DEVICE_SERIAL: { if (!_serial_start_connection()) { break; /* Whatever it might mean */ @@ -255,6 +254,23 @@ void LinuxUARTDriver::_udp_start_connection(void) _packetise = true; } +void LinuxUARTDriver::_tcp_start_connection(void) +{ + if (_flag != NULL) { + if (!strcmp(_flag, "wait")) { + _device = new TCPServerDevice(_ip, _base_port); + } else { + _device = new TCPClientDevice(_ip, _base_port); + } + } else { + _device = new TCPClientDevice(_ip, _base_port); + } + + if (_device->open()) { + _connected = true; + } +} + /* shutdown a UART */ diff --git a/libraries/AP_HAL_Linux/UARTDriver.h b/libraries/AP_HAL_Linux/UARTDriver.h index b2ee005261..79d169918d 100644 --- a/libraries/AP_HAL_Linux/UARTDriver.h +++ b/libraries/AP_HAL_Linux/UARTDriver.h @@ -48,6 +48,7 @@ private: void _allocate_buffers(uint16_t rxS, uint16_t txS); void _deallocate_buffers(); void _udp_start_connection(void); + void _tcp_start_connection(void); bool _serial_start_connection(void); enum device_type {