包括< termios.h>和< asm/termios.h>在同一项目中 [英] Including <termios.h> and <asm/termios.h> in the same project

查看:377
本文介绍了包括< termios.h>和< asm/termios.h>在同一项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现的目标:我想为某些tty*映射的UART终端设置自定义的baud rate值.

What I want to achieve: I want to set custom baud rate values for some tty*-like UART-mapped terminals.

方法:到目前为止,我发现的唯一方法是使用位于<asm/termios>标头中的struct termios2结构(如

How: The only way I found by far is to use the struct termios2 structure which is located in<asm/termios> header (as mentioned here, first answer).

我的解决方案到目前为止效果很好,但是现在我需要使用一些功能:

My solution works very well by far, but now I need to use some functions:

speed_t cfgetispeed(const struct termios *);
int     tcdrain(int);
int     tcflow(int, int);
int     tcflush(int, int);
int     tcgetattr(int, struct termios *);
pid_t   tcgetsid(int);
int     tcsendbreak(int, int);
int     tcsetattr(int, int, struct termios *);

问题在于,在<asm/termios.h>中没有这样的功能,我需要包括<termios.h>以便能够使用它们.

The problem is that in <asm/termios.h> there are no such functions, and I need to include <termios.h> for being able to use them.

问题:如果我同时包含两个标头(<asm/termios.h><termios.h>),编译器将大声疾呼有关函数和结构的重新声明,他是对的.

Problem: If I include both headers (<asm/termios.h> and <termios.h>) the compiler will scream about functions and structure re-declaration, and he's right.

如何在不使用一些晦涩的实践的情况下解决此问题(例如将一个标头包装在名称空间中,如提到的

How can I solve this without using some obscure practice (like wrapping one of headers in a namespace, like mentioned here)?

推荐答案

我遇到了类似的问题-需要自定义波特率支持,并使用termios2TCGETS2BOTHER等定义,同时仍然使用传统的termios电话.我本能地将termios2内容包装在自己的编译单元中,没有任何问题.所以我的结构看起来像这样:

I had a similar issue - wanted custom baud rate support with definitions like termios2, TCGETS2 and BOTHER, while still making use of the traditional termios calls. I instinctively wrapped the termios2 stuff in its own compilation unit and had no problems. So my structure looks like this:

serial_driver.c/.h

#include <termios.h>
#include <fcntl.h>
#include <dirent.h>

int open_port(int fd, int baudrate, eParitySetting parity, int numStopBits)
{
  if(baudrate_is_non_standard(baudrate)
    setNonStandardBaudRateTermios(fd, baudrate, parity, numStopBits);
  else
    //all the normal tcgetattr/cfsetospeed/tcsetattr
}

int do_other_things(void)
{
  //all the normal tcsendbreak/tcflush/etc things
}

serial_driver_abr.c/.h

#include <asm/termios.h> /* asm gives us the all important BOTHER and TCGETS2 */
#include <fcntl.h>
#include <dirent.h>
#include <stropts.h> /* Oddly, for ioctl, because ioctl.h causes include dramas */

setNonStandardBaudRateTermios(int fd, int baudrate, eParitySetting parity, int numStopBits)
{
  //All the termios2/ioctl/TCGETS2/BOTHER things
}

对我来说很好.

这篇关于包括&lt; termios.h&gt;和&lt; asm/termios.h&gt;在同一项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆