APM:Libraries
RCOutput_Tap_Linux.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Intel Corporation. All rights reserved.
3  *
4  * This file is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This file is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include <AP_HAL/AP_HAL.h>
18 
19 #if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
20 
21 #include "RCOutput_Tap.h"
22 
23 #include <asm/termbits.h>
24 #include <string.h>
25 #include <sys/ioctl.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 
29 namespace ap {
30 
32 {
33  struct termios2 tc;
34 
35  if (_uart_fd < 0) {
36  return false;
37  }
38 
39  memset(&tc, 0, sizeof(tc));
40  if (ioctl(_uart_fd, TCGETS2, &tc) == -1) {
41  return false;
42  }
43 
44  /* speed is configured by c_[io]speed */
45  tc.c_cflag &= ~CBAUD;
46  tc.c_cflag |= BOTHER;
47  tc.c_ispeed = speed;
48  tc.c_ospeed = speed;
49 
50  if (ioctl(_uart_fd, TCSETS2, &tc) == -1) {
51  return false;
52  }
53 
54  if (ioctl(_uart_fd, TCFLSH, TCIOFLUSH) == -1) {
55  return false;
56  }
57 
58  return true;
59 }
60 
61 }
62 
63 #endif
bool _uart_set_speed(int speed)