1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* ExtendedSerial.cpp
* The DMX through a UART plugin for ola
* Copyright (C) 2011 Rui Barreiros
* Copyright (C) 2014 Richard Ash
*/
#include "ola/io/ExtendedSerial.h"
#if HAVE_CONFIG_H
#include <config.h>
#endif // HAVE_CONFIG_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_STROPTS_H
// this provides ioctl() definition without conflicting with asm/termios.h
#include <stropts.h>
#endif // HAVE_STROPTS_H
#ifdef HAVE_ASM_TERMIOS_H
// use this not standard termios for custom baud rates
//
// On mips architectures, <asm/termios.h> sets some cpp macros which cause
// <cerrno> (included by <ostream>, used by <ola/Logging.h>) to not define
// ERANGE, EDOM, or EILSEQ, causing a spectacular compile failure there.
//
// Explicitly include <cerrno> now to avoid the issue.
#include <errno.h>
#include <asm/termios.h>
#endif // HAVE_ASM_TERMIOS_H
#include <ola/Logging.h>
namespace ola {
namespace io {
bool LinuxHelper::SetDmxBaud(int fd) {
#if defined(HAVE_STROPTS_H) && defined(HAVE_TERMIOS2)
static const int rate = 250000;
struct termios2 tio; // linux-specific terminal stuff
if (ioctl(fd, TCGETS2, &tio) < 0) {
return false;
}
tio.c_cflag &= ~CBAUD;
tio.c_cflag |= BOTHER;
tio.c_ispeed = rate;
tio.c_ospeed = rate; // set custom speed directly
if (ioctl(fd, TCSETS2, &tio) < 0) {
return false;
}
if (LogLevel() >= OLA_LOG_INFO) {
if (ioctl(fd, TCGETS2, &tio) < 0) {
OLA_INFO << "Error getting altered settings from port";
} else {
OLA_INFO << "Port speeds for " << fd << " are " << tio.c_ispeed
<< " in and " << tio.c_ospeed << " out";
}
}
return true;
#else
return false;
(void) fd;
#endif // defined(HAVE_STROPTS_H) && defined(HAVE_TERMIOS2)
}
} // namespace io
} // namespace ola
|