diff --git a/CMakeLists.txt b/CMakeLists.txt index aa3dc83f..deb5ce96 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ check_function_exists(pthread_setname_np HAVE_PTHREAD_SETNAME_NP) check_function_exists(pselect HAVE_PSELECT) check_function_exists(ppoll HAVE_PPOLL) check_include_file(linux/serial.h HAVE_LINUX_SERIAL -DHAVE_LINUX_SERIAL=1) +check_include_file(dev/usb/uftdiio.h HAVE_FREEBSD_UFTDI -DHAVE_FREEBSD_UFTDI=1) check_function_exists(argp_parse HAVE_ARGP) if(NOT HAVE_ARGP) find_library(LIB_ARGP argp) diff --git a/config.h.cmake b/config.h.cmake index 5e88633c..b194d390 100755 --- a/config.h.cmake +++ b/config.h.cmake @@ -16,6 +16,9 @@ /* Defined if linux/serial.h is available. */ #cmakedefine HAVE_LINUX_SERIAL +/* Defined if dev/usb/uftdiio.h is available. */ +#cmakedefine HAVE_FREEBSD_UFTDI + /* Defined if pthread_setname_np is available. */ #cmakedefine HAVE_PTHREAD_SETNAME_NP diff --git a/configure.ac b/configure.ac index 08bed21d..420f2053 100755 --- a/configure.ac +++ b/configure.ac @@ -35,7 +35,7 @@ AC_SUBST(EXTRA_LIBS) AC_CHECK_FUNC([pselect], [AC_DEFINE(HAVE_PSELECT, [1], [Defined if pselect() is available.])]) AC_CHECK_FUNC([ppoll], [AC_DEFINE(HAVE_PPOLL, [1], [Defined if ppoll() is available.])]) -AC_CHECK_HEADER([linux/serial.h], [AC_DEFINE(HAVE_LINUX_SERIAL, [1], [Defined if linux/serial.h is available.])]) +AC_CHECK_HEADER([dev/usb/uftdiio.h], [AC_DEFINE(HAVE_FREEBSD_UFTDI, [1], [Defined if dev/usb/uftdiio.h is available.])]) AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [enable code coverage tracking]), [CXXFLAGS+=" -coverage -O0"], []) AC_ARG_WITH(contrib, AS_HELP_STRING([--without-contrib], [disable inclusion of contributed sources]), [], [with_contrib=yes]) diff --git a/src/lib/ebus/device.cpp b/src/lib/ebus/device.cpp index b9f541d9..bfc85469 100755 --- a/src/lib/ebus/device.cpp +++ b/src/lib/ebus/device.cpp @@ -30,6 +30,9 @@ #ifdef HAVE_LINUX_SERIAL # include #endif +#ifdef HAVE_FREEBSD_UFTDI +# include +#endif #include #ifdef HAVE_PPOLL # include @@ -192,7 +195,7 @@ result_t SerialDevice::open() { struct termios newSettings; // open file descriptor - m_fd = ::open(m_name, O_RDWR | O_NOCTTY); + m_fd = ::open(m_name, O_RDWR | O_NOCTTY | O_NDELAY); if (m_fd < 0) { return RESULT_ERR_NOTFOUND; @@ -215,13 +218,24 @@ result_t SerialDevice::open() { } #endif +#ifdef HAVE_FREEBSD_UFTDI + int param = 0; + // flush tx/rx and set low latency on uftdi device + if (ioctl(m_fd, UFTDIIOC_GET_LATENCY, ¶m) == 0) { + ioctl(m_fd, UFTDIIOC_RESET_IO, ¶m); + param = 1; + ioctl(m_fd, UFTDIIOC_SET_LATENCY, ¶m); + } +#endif + // save current settings tcgetattr(m_fd, &m_oldSettings); // create new settings memset(&newSettings, 0, sizeof(newSettings)); - newSettings.c_cflag |= (B2400 | CS8 | CLOCAL | CREAD); + cfsetspeed(&newSettings, B2400); + newSettings.c_cflag |= (CS8 | CLOCAL | CREAD); newSettings.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // non-canonical mode newSettings.c_iflag |= IGNPAR; // ignore parity errors newSettings.c_oflag &= ~OPOST; @@ -234,7 +248,10 @@ result_t SerialDevice::open() { tcflush(m_fd, TCIFLUSH); // activate new settings of serial device - tcsetattr(m_fd, TCSAFLUSH, &newSettings); + if (tcsetattr(m_fd, TCSAFLUSH, &newSettings)) { + close(); + return RESULT_ERR_DEVICE; + } // set serial device into blocking mode fcntl(m_fd, F_SETFL, fcntl(m_fd, F_GETFL) & ~O_NONBLOCK); diff --git a/src/lib/ebus/device.h b/src/lib/ebus/device.h index 7c555f8f..f306bbc7 100755 --- a/src/lib/ebus/device.h +++ b/src/lib/ebus/device.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/src/lib/utils/tcpsocket.h b/src/lib/utils/tcpsocket.h index 4d0dcb1b..fd82b225 100755 --- a/src/lib/utils/tcpsocket.h +++ b/src/lib/utils/tcpsocket.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include