From 270d29000e9903d9b18d22bb79d8682a6d89a8b0 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Mon, 2 Nov 2020 14:20:42 -0330 Subject: [PATCH] And so it begins again; bump version number to 6.5_pre Move some serial port code directly into portNames(); meant to do this for 6.4, oh well. --- src/common/Version.hxx | 2 +- src/macos/SerialPortMACOS.cxx | 24 ++++++++++-------------- src/macos/SerialPortMACOS.hxx | 9 --------- src/unix/SerialPortUNIX.cxx | 24 ++++++++++-------------- src/unix/SerialPortUNIX.hxx | 9 --------- 5 files changed, 21 insertions(+), 47 deletions(-) diff --git a/src/common/Version.hxx b/src/common/Version.hxx index a0eb84a14..2d6bf8db8 100644 --- a/src/common/Version.hxx +++ b/src/common/Version.hxx @@ -18,7 +18,7 @@ #ifndef VERSION_HXX #define VERSION_HXX -#define STELLA_VERSION "6.4" +#define STELLA_VERSION "6.5_pre" #define STELLA_BUILD "6238" #endif diff --git a/src/macos/SerialPortMACOS.cxx b/src/macos/SerialPortMACOS.cxx index 745fdc8fc..85fba0032 100644 --- a/src/macos/SerialPortMACOS.cxx +++ b/src/macos/SerialPortMACOS.cxx @@ -99,32 +99,28 @@ StringList SerialPortMACOS::portNames() { StringList ports; + // Check if port is valid; for now that means if it can be opened + // Eventually we may extend this to do more intensive checks + auto isPortValid = [](const string& port) { + int handle = open(port.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); + if(handle > 0) close(handle); + return handle > 0; + }; + // Get all possible devices in the '/dev' directory FilesystemNode::NameFilter filter = [](const FilesystemNode& node) { return BSPF::startsWithIgnoreCase(node.getPath(), "/dev/cu.usb"); }; FSList portList; - portList.reserve(16); + portList.reserve(5); FilesystemNode dev("/dev/"); dev.getChildren(portList, FilesystemNode::ListMode::All, filter, false); // Add only those that can be opened for(const auto& port: portList) - if(isValid(port.getPath())) + if(isPortValid(port.getPath())) ports.emplace_back(port.getPath()); return ports; } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool SerialPortMACOS::isValid(const string& port) const -{ - // For now, we can only detect whether the port could be opened - // Eventually we may extend this to do more intensive checks - int handle = open(port.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); - if(handle > 0) - close(handle); - - return handle > 0; -} diff --git a/src/macos/SerialPortMACOS.hxx b/src/macos/SerialPortMACOS.hxx index f16d9ddcd..ea55ddc3d 100644 --- a/src/macos/SerialPortMACOS.hxx +++ b/src/macos/SerialPortMACOS.hxx @@ -69,15 +69,6 @@ class SerialPortMACOS : public SerialPort */ StringList portNames() override; - private: - /** - Tests whether this port can be opened, and is a valid - serial port. - - @return True if valid, else false - */ - bool isValid(const string& port) const; - private: // File descriptor for serial connection int myHandle{0}; diff --git a/src/unix/SerialPortUNIX.cxx b/src/unix/SerialPortUNIX.cxx index 1f7449cec..4ecc11a25 100644 --- a/src/unix/SerialPortUNIX.cxx +++ b/src/unix/SerialPortUNIX.cxx @@ -102,33 +102,29 @@ StringList SerialPortUNIX::portNames() { StringList ports; + // Check if port is valid; for now that means if it can be opened + // Eventually we may extend this to do more intensive checks + auto isPortValid = [](const string& port) { + int handle = open(port.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); + if(handle > 0) close(handle); + return handle > 0; + }; + // Get all possible devices in the '/dev' directory FilesystemNode::NameFilter filter = [](const FilesystemNode& node) { return BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyACM") || BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyUSB"); }; FSList portList; - portList.reserve(16); + portList.reserve(5); FilesystemNode dev("/dev/"); dev.getChildren(portList, FilesystemNode::ListMode::All, filter, false); // Add only those that can be opened for(const auto& port: portList) - if(isValid(port.getPath())) + if(isPortValid(port.getPath())) ports.emplace_back(port.getPath()); return ports; } - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool SerialPortUNIX::isValid(const string& port) const -{ - // For now, we can only detect whether the port could be opened - // Eventually we may extend this to do more intensive checks - int handle = open(port.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); - if(handle > 0) - close(handle); - - return handle > 0; -} diff --git a/src/unix/SerialPortUNIX.hxx b/src/unix/SerialPortUNIX.hxx index 44b508b94..640ee9b85 100644 --- a/src/unix/SerialPortUNIX.hxx +++ b/src/unix/SerialPortUNIX.hxx @@ -70,15 +70,6 @@ class SerialPortUNIX : public SerialPort */ StringList portNames() override; - private: - /** - Tests whether this port can be opened, and is a valid - serial port. - - @return True if valid, else false - */ - bool isValid(const string& port) const; - private: // File descriptor for serial connection int myHandle{0};