Merge pull request #3190 from farhaven/master

Implement serial port baudrate selection for OpenBSD
This commit is contained in:
Alessandro Ranellucci 2016-03-13 15:37:13 +01:00
commit ff0a947364

View file

@ -8,14 +8,15 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#if defined(__APPLE__) || defined(__linux) || defined(__OpenBSD__)
#include <termios.h>
#endif
#if __APPLE__ #if __APPLE__
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <termios.h>
#include <IOKit/serial/ioss.h> #include <IOKit/serial/ioss.h>
#endif #endif
#ifdef __linux #ifdef __linux
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <termios.h>
#include <linux/serial.h> #include <linux/serial.h>
#endif #endif
@ -99,8 +100,7 @@ GCodeSender::set_baud_rate(unsigned int baud_rate)
speed_t newSpeed = baud_rate; speed_t newSpeed = baud_rate;
ioctl(handle, IOSSIOSPEED, &newSpeed); ioctl(handle, IOSSIOSPEED, &newSpeed);
::tcsetattr(handle, TCSANOW, &ios); ::tcsetattr(handle, TCSANOW, &ios);
#endif #elif __linux
#ifdef __linux
termios ios; termios ios;
::tcgetattr(handle, &ios); ::tcgetattr(handle, &ios);
::cfsetispeed(&ios, B38400); ::cfsetispeed(&ios, B38400);
@ -121,6 +121,13 @@ GCodeSender::set_baud_rate(unsigned int baud_rate)
} }
ioctl(handle, TIOCSSERIAL, &ss); ioctl(handle, TIOCSSERIAL, &ss);
printf("< set_baud_rate: %u\n", baud_rate);
#elif __OpenBSD__
struct termios ios;
::tcgetattr(handle, &ios);
::cfsetspeed(&ios, baud_rate);
if (::tcsetattr(handle, TCSAFLUSH, &ios) != 0)
printf("Failed to set baud rate: %s\n", strerror(errno));
#else #else
//throw invalid_argument ("OS does not currently support custom bauds"); //throw invalid_argument ("OS does not currently support custom bauds");
#endif #endif