From c728483a7ea1ff1126303e9e6681b6f6c28d0f53 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 21 Feb 2020 13:41:38 +1100 Subject: [PATCH] AP_HAL_SITL: add option to create uart connection to file --- libraries/AP_HAL_SITL/UARTDriver.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/AP_HAL_SITL/UARTDriver.cpp b/libraries/AP_HAL_SITL/UARTDriver.cpp index 38184208ea..cb896d1810 100644 --- a/libraries/AP_HAL_SITL/UARTDriver.cpp +++ b/libraries/AP_HAL_SITL/UARTDriver.cpp @@ -44,6 +44,7 @@ #endif #include +#include extern const AP_HAL::HAL& hal; @@ -85,6 +86,7 @@ void UARTDriver::begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace) mcast:239.255.145.50:14550 uart:/dev/ttyUSB0:57600 sim:ParticleSensor_SDS021: + file:/tmp/my-device-capture.BIN */ char *saveptr = nullptr; char *s = strdup(path); @@ -153,6 +155,16 @@ void UARTDriver::begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace) } else if (strcmp(devtype,"none") == 0) { // skipping port ::printf("Skipping port %s\n", args1); + } else if (strcmp(devtype, "file") == 0) { + if (_connected) { + AP::FS().close(_fd); + } + ::printf("FILE connection %s\n", args1); + _fd = AP::FS().open(args1, O_RDONLY); + if (_fd == -1) { + AP_HAL::panic("Failed to open (%s): %m", args1); + } + _connected = true; } else { AP_HAL::panic("Invalid device path: %s", path); }